code_file1
stringlengths 87
4k
| code_file2
stringlengths 85
4k
|
---|---|
#include<bits/stdc++.h>
#define int long long
using namespace std;
int b,c,ans;
signed main()
{
scanf("%lld%lld",&b,&c);
int que=c/2,ko=(c-1)/2,ko2=(c-2)/2;
// b=abs(b);
int l1=b-que,r1=b+ko2;
int l2=-b-ko,r2=-b+ko;
if(l1<=r2) printf("%lld\n",max(r1,r2)-min(l1,l2)+1);
else printf("%lld\n",r1-l1+1+r2-l2+1);
return 0;
} | #include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>
#define FOR_LT(i, beg, end) for (decltype(end) i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (decltype(end) i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (decltype(beg) i = beg; end <= i; i--)
#define REP(n) for (decltype(n) repeat_index = 0; repeat_index < n; repeat_index++)
using namespace std;
template<typename T, size_t S>
T minval(const T(&vals)[S])
{
T val = numeric_limits<T>::max();
FOR_LT(i, 0, S) {
val = min(val, vals[i]);
}
return val;
}
template<typename T, size_t S>
T maxval(const T(&vals)[S])
{
T val = numeric_limits<T>::min();
FOR_LT(i, 0, S) {
val = max(val, vals[i]);
}
return val;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(20);
int n, k; cin >> n >> k;
string s; cin >> s;
if (s.size() & 1) {
s = s + s;
}
REP(k) {
FOR_LT(i, 0, s.size() / 2) {
if (s[i * 2] == s[i * 2 + 1]) {
s[i] = s[i * 2];
continue;
}
bool hand[3] = {};
FOR_LT(j, 0, 2) {
switch(s[i * 2 + j]) {
case 'R': hand[0] = true; break;
case 'P': hand[1] = true; break;
case 'S': hand[2] = true; break;
}
}
FOR_LT(j, 0, 3) {
if (!hand[j]) {
switch (j) {
case 0: s[i] = 'S'; break;
case 1: s[i] = 'R'; break;
case 2: s[i] = 'P'; break;
}
}
}
}
FOR_LT(i, 0, s.size() / 2) {
s[s.size() / 2 + i] = s[i];
}
}
cout << s[0] << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
short M, H;
int main()
{
cin>>M>>H;
if(H%M) cout<<"No\n";
else cout<<"Yes\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
int main() {
ll A, B;
cin >> A >> B;
if(B % A == 0) {
cout << "Yes";
}
else {
cout << "No";
}
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
int a;
cin >> a;
if(a >= 0) cout << a << endl;
else cout << 0 << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define all(x) x.begin(),x.end()
template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }
const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }
const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
x += y;
if( x >= m )
x -= m;
}
template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
x -= y;
if( x < 0 )
x += m;
}
int main()
{
#ifdef gupta_samarth
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fastio();
int x;
cin>>x;
cout<<( x >= 0 ? x : 0 );
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MN LLONG_MIN
#define MX LLONG_MAX
#define UL ULLONG_MAX
#define pb push_back
#define e "\n"
#define iff(u,v) if(abs(u-v)<1e-9)
#define vi vector<long long>v,v1,v2;
#define pi 3.1415926536
#define fix cout<<fixed; cout<<setprecision(10);
#define dc ll i,j,k,n,m,len,ans=0,mx=-1,mn,sum=0; string s,t; bool flag=false;
void solve()
{
dc; cin>>n; m=n; ++m; k=1;
while(k<=m)
{
m-=k; ++k; sum++;
}
cout<<n-sum+1<<e;
}
int main()
{
//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//int t; cin>>t; while(t--)solve();
solve();
}
| #include<bits/stdc++.h>
using namespace std;
#define ff first
#define brn "\n"
#define ss second
#define mk make_pair
#define int long long
#define pb push_back
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(x) int x; cin>>x; while(x--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define so(a,n) sort(a,a+n)
#define rso(a,n) sort(a,a+n),reverse(a,a+n)
#define all(v) (v).begin(),(v).end()
#define ps(x,y) fixed<<setprecision(y)<<x
#define sz size();
#define p_sieve 10000007
const int maxn = 1e3 + 5;
const int modulo=1000000007;
#define mod 1000000009;
const double pi=3.14159;
void solve()
{
int n;cin>>n;
int i=1;
while((i*(i+1))/2<=(n+1))i++;
cout<<(n+1-i)+1;
}
//########################---------code ends here------------------########################################################
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//prime_sieve();
// w(t)
solve();
}
|
#include <bits/stdc++.h>
#define task "triangles"
#define pb push_back
#define pll pair<ll, ll>
#define pii pair< pll, ll>
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
const int N = 2e5+5;
const ll mod = 1e5;
const ll ex = 1e5;
ll n, m, t, k, tong, a[N][5], b[N], T, ans, c[N], d[32][3], h[N], lo;
vector<ll> adj[N], kq;
string s, res;
bool check(ll x)
{
memset(d, 0, sizeof(d));
for(int i = 1; i <= n; i ++)
{
k = 0;
for(int j = 0; j <= 4; j ++)
{
if(a[i][j] >= x)k |= (1<<j);
}
b[i] = k;
d[k][0] = 1;
//cout << b[i] <<" ";
}
for(int i = (1<<5)-1; i >= 0; i --)
{
for(int j = 0; j < 5; j ++)
{
if((i >> j) & 1)d[(i^(1<<j))][0] |= d[i][0];
}
}
for(int l = 1; l <= 2;l ++)
{
for(int i = (1<<5) - 1; i >= 0; i --)
{
for(int j = 1; j <= n ; j ++)
{
k = i ^ b[j];
k = i & k;
d[i][l] |= d[k][l-1];
}
for(int j = 0; j < 5; j ++)
{
if((i >> j) & 1)d[(i^(1<<j))][l] |= d[i][l];
}
}
}
return d[(1<<5)-1][2] == 1;
}
void sol()
{
deque<char> q;
cin >> s;
for(int i = 0; i < s.length(); i ++)
{
char c = s[i];
if(c == 'R')k ^= 1;
else
{
if(k == 0)
{
q.pb(c);
}
else
{
q.push_front(c);
}
}
}
string res;
//cout << k << " ";
if(k == 0)
{
while(!q.empty())
{
if(!res.empty() && q.front() == res.back())
{
q.pop_front();
res.pop_back();
continue;
}
res += q.front();
q.pop_front();
}
}
else
{
while(!q.empty())
{
if(!res.empty() && q.back() == res.back())
{
q.pop_back();
res.pop_back();
continue;
}
res += q.back();
q.pop_back();
}
}
cout << res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen(task".in", "r"))
freopen(task".in", "r", stdin),
freopen(task".out", "w", stdout);
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
/*
3 4
1 (
3 )
2 )
3 )
-1 0 1 0 -1
*/
| #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);}
void Cout(ll x) {cout << x << endl; exit(0);}
const ll inf = 1e18;
// 計算量(logN)
ll gcd(ll a, ll b) {
if (a%b == 0) return b;
else return gcd(b, a%b);
}
int main() {
ll N; cin >> N;
vector<ll> A(N);
rep(i,N) cin >> A[i];
ll L = inf;
map<ll,ll> t;
rep(i,N) {
ll a = A[i];
chmin(L,a);
for (ll j=1; j*j<=a; j++) {
if (a%j) continue;
ll x = j, y = a/j;
if (t[x]==0) t[x] = a;
else t[x] = gcd(t[x],a);
if (t[y]==0) t[y] = a;
else t[y] = gcd(t[y],a);
}
}
ll ans = 0;
for (auto p : t) {
ll x = p.first, y = p.second;
if (x>L) break;
if (x!=y) continue;
ans++;
}
cout << ans << endl;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,j,n) for(ll i=j;i<n;i++)
#define scn(a) scanf("%lld",&a)
#define scns(a,b) scanf("%lld %lld",&a,&b)
#define print(a) printf("%lld\n",a)
#define vec vector<ll>
#define pb push_back
#define pairs pair<ll,ll>
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define tc ll it;scanf("%lld",&it); while(it--)
#define inf 1e18
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int mod = 1e9+7;
const int N = 2e5+5;
int main()
{
ll n,ans=0;
cin>>n;
map<ll,ll> m;
ll a[n];
rep(i,0,n)
{
cin>>a[i];
m[a[i]%200]++;
}
for(auto t:m)
{
if(t.s>1)
ans+=((t.s-1)*t.s/2);
}
cout<<ans;
}
| ///====================== TEMPLATE STARTS HERE =====================///
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define POPCOUNT __builtin_popcountll
#define Set(N,p) ((N)|((1LL)<<(p)))
#define Reset(N,p) ((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define LL long long
#define LLU long long unsigned int
typedef pair < int, int > pii;
typedef pair < LL, LL > pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pll> vll;
#ifdef s_da_sailor
#define line cout << "\n===================\n"
#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " = " << arg1 << "\n";
}
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 line
#define trace(...)
#endif // s_da_sailor
inline LL gcd ( LL a, LL b ) {
a = ABS ( a ); b = ABS ( b );
while ( b ) { a = a % b; swap ( a, b ); } return a;
}
LL ext_gcd ( LL A, LL B, LL *X, LL *Y ){
LL x2, y2, x1, y1, x, y, r2, r1, q, r;
x2 = 1; y2 = 0;
x1 = 0; y1 = 1;
for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) {
q = r2 / r1;
r = r2 % r1;
x = x2 - (q * x1);
y = y2 - (q * y1);
}
*X = x2; *Y = y2;
return r2;
}
inline LL modInv ( LL a, LL m ) {
LL x, y;
ext_gcd( a, m, &x, &y );
x %= m;
if ( x < 0 ) x += m;
return x;
}
inline LL bigmod ( LL a, LL p, LL m ) {
LL res = 1 % m, x = a % m;
while ( p ) {
if ( p & 1 ) res = ( res * x ) % m;
x = ( x * x ) % m; p >>= 1; /// For bigmod2 multiply here using mulmod
}
return res;
}
//int knightDir[8][2] = { {-2,1},{-1,2},{1,2},{2,1},{2,-1},{-1,-2},{1,-2},{-2,-1} };
//int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
//int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1},{-1,-1},{1,1},{1,-1},{-1,1}};
const LL inf = 2147383647;
const LL mod = 1000000007;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-11;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// For generating random numbers
///====================== TEMPLATE ENDS HERE =====================///
LL nod(LL n) {
LL ret = 0;
while(n>0) {
n /= 10;
ret++;
}
return ret;
}
void solve() {
LL n;
cin >> n;
LL dig = nod(n);
LL curr = 9LL, ret = 0, temp = 0;
for(LL i=1; i<dig; i++) {
ret += (curr * ((i-1LL)/3LL) );
temp += curr;
curr *= 10;
}
LL extra = n-temp;
ret += ( extra * ((dig-1LL)/3LL) );
cout << ret << endl;
}
int main () {
#ifdef s_da_sailor
freopen ( "input.txt", "r", stdin );
//freopen ( "output.txt", "w", stdout );
#endif // s_da_sailor
fast_cin;
solve();
return 0;
}
|
#include "iostream"
using namespace std;
#include "string"
#include "vector"
#include "unordered_set"
#include "map"
#include "stack"
#include "algorithm"
#include "queue"
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl '\n'
#define vi vector<int>
int Gcd(int a, int b) {
if(b == 0)
return a;
return Gcd(b, a % b);
}
int32_t main() {
boost;
int n;
cin >> n;
vi a(n);
for(int &i : a)
cin >> i;
int mini = *min_element(a.begin(), a.end());
map<int, int> mp;
for(int &i : a) {
for(int j = 1; j * j <= i; j++) {
if(i % j == 0) {
mp[j] = Gcd(mp[j], i);
mp[i / j] = Gcd(mp[i / j], i);
}
}
}
int ans = 0;
for(auto x : mp) {
if(x.ff <= mini && x.ff == x.ss)
ans++;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
int GCD(int x, int y){
if(x == 0 && y == 0) return 0;
if(x>y){
int swap = x;
x = y;
y = swap;
}
while(true){
if(y%x==0){
return x;
}else{
int amari = y%x;
y = x;
x = amari;
}
}
}
vector<ll> yakusuu_rekkyo(ll n){
vector<ll> divisors;
for(ll i = 1; i <= n; i++){
if(i * i > n)break;
if(i * i == n){
divisors.push_back(i);
break;
}else if(n % i == 0){
divisors.push_back(i);
divisors.push_back(n/i);
}
}
sort(divisors.begin(), divisors.end());
return divisors;
}
int main() {
int n; cin >> n;
int a[n] = {};
rep(i,n) cin >> a[i];
sort(a,a+n);
set<int> se;
rep(i,n){
vector<ll> v = yakusuu_rekkyo(a[i]);
rep(j,v.size()) se.insert(v[j]);
}
int ans = 0;
for(auto x: se){
if(x > a[0]) continue;
int now = -1;
rep(i,n){
if(a[i] % x == 0){
if(now == -1){
now = a[i];
}else{
now = GCD(now, a[i]);
}
}
}
if(now == x) ans++;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define MAX_N (200000 + 5)
#define LL long long
using namespace std;
const int mod = 998244353;
int n, m;
int inv[MAX_N];
int p[MAX_N], tot;
bool is[MAX_N];
int pw[MAX_N], f[MAX_N];
int main() {
scanf("%d%d", &n, &m);
inv[1] = 1;
for (int i = 2; i <= m; ++i) inv[i] = (LL)(mod - mod / i) * inv[mod % i] % mod;
for (int i = 2; i <= m; ++i) {
if (!is[i]) p[++tot] = i, pw[i] = 1, f[i] = n;
for (int j = 1; i * p[j] <= m; ++j) {
is[i * p[j]] = 1;
if (i % p[j]) {
pw[i * p[j]] = 1;
f[i * p[j]] = (LL)f[i] * n % mod;
}
else {
pw[i * p[j]] = pw[i] + 1;
f[i * p[j]] = (LL)f[i] * (n + pw[i]) % mod * inv[pw[i] + 1] % mod;
break;
}
}
}
int ans = 1;
for (int i = 2; i <= m; ++i) ans = (ans + f[i]) % mod;
printf("%d", ans);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
long long int MOD = 998244353;
long long int power(long long int b, long long int e) {
if (e == 0)
return 1;
long long int temp = power(b, e / 2);
if (e % 2 == 0)
return temp * temp % MOD;
return (temp * temp) % MOD * b % MOD;
}
long long int inv(long long int n) {
return power(n, MOD - 2);
}
const int N = 200200;
long long int f[N], rf[N];
long long int choose(long long int n, long long int r) {
if (r < 0 || r > n) return 0;
return (f[n] * rf[r]) % MOD * rf[n - r] % MOD;
}
void solve() {
int n,m; cin >> n >> m;
if (n == 1) {
cout << m;
return;
}
f[0] = 1;
for (int i = 1; i < N; i++)
f[i] = f[i - 1] * i % MOD;
rf[N - 1] = inv(f[N - 1]);
for (int i = N - 1; i > 0; i--)
rf[i - 1] = rf[i] * i % MOD;
vector<vector<long long int>> dp(m + 1, vector<long long int>(20));
dp[1][0] = 1;
for (int k = 0; k < 19; k++) {
for (int i = 1; i <= m; i++) {
if (dp[i][k] == 0) continue;
for (int j = 2 * i; j <= m; j += i) {
dp[j][k + 1] += dp[i][k];
dp[j][k + 1] %= MOD;
}
}
}
long long int ans = 0;
for (int i = 0; i <= min(n, 19); i++) {
long long int total = 0;
for (int j = 1; j <= m; j++) {
total += dp[j][i];
total %= MOD;
}
ans += total * choose(n, i);
ans %= MOD;
}
cout << ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t; t = 1;
while (t--) {
solve();
}
return 0;
} |
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const double pi = acos(-1);
int n, xa, ya, xb, yb;
struct Point{
double x, y;
Point(double x = 0, double y = 0):x(x),y(y){}
};
typedef Point Vector;
Vector Rotate(Vector A, double rad){//rad为弧度 且为逆时针旋转的角
return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
}
int main()
{
scanf("%d%d%d%d%d", &n, &xa, &ya, &xb, &yb);
double xmid = (xa + xb) / 2.0;
double ymid = (ya + yb) / 2.0;
Vector v(xa - xmid, ya - ymid);
Vector ans = Rotate(v, 2 * pi / n);
printf("%.9lf %.9lf\n", ans.x + xmid, ans.y + ymid);
return 0;
}
| #include <bits/stdc++.h>
#define ull unsigned long long
#define int long long
#define ll long long
#define fr(i, n) for (int i = 0; i < n; i++)
#define frf(i, j, n) for (int i = j; i <= n; i++)
#define frd(i, n) for (int i = n; i >= 0; i--)
#define mp(i, j) make_pair(i, j)
#define pb(x) push_back(x)
#define INF 1e18
#define all(x) (x).begin(), x.end()
#define int64_t 64
using namespace std;
typedef pair<int, int> pi;
const int MAX = 1e6 + 1;
// typedef vector<vector<ll>> matrix;
const ll PRIME = 1e9 + 7;
#define PI 3.14159265
// typedef pair<int, pair<int, int>> ppi;
// const ll MAX = 1e6 + 1;
int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
int h,w,x,b;
int a[16][16],ans;
void go(int x,int b)
{
if(x==0 && b==0)
{
ans++;
}
int I,J;
bool flag=0;
fr(i,h)
{
fr(j,w)
{
if(a[i][j]==-1)
{
I=i;
J=j;
flag=1;
break;
}
}
if(flag)break;
}
if(x>0 && a[I][J]==-1 && J+1<w &&a[I][J+1]==-1)
{
a[I][J+1]=1;
a[I][J]=1;
go(x-1,b);
a[I][J+1]=-1;
a[I][J]=-1;
}
if(x>0 && a[I][J]==-1 && I+1<h &&a[I+1][J]==-1)
{
a[I+1][J]=1;
a[I][J]=1;
go(x-1,b);
a[I+1][J]=-1;
a[I][J]=-1;
}
if(b>0 && a[I][J]==-1 )
{
a[I][J]=1;
go(x,b-1);
a[I][J]=-1;
}
}
void solve()
{
cin>>h>>w>>x>>b;
memset(a,-1,sizeof(a));
go(x,b);
cout<<ans;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
t = 1;
// cin >> t;
// int k=1;
while (t--)
{
// cout << "Case #" << k++ << ": ";
solve();
}
} |
#include<stdio.h>
#include<string.h>
// helpful functions
#define fl(i,n) for(int i = 0; i < n; i++)
#define fls(i,a,b) for(int i = a; i <= b; i++) // flexible for loop
#define fls2(i,a,b) for(int i = a; i >= b; i--) // flexible for loop 2
#define afl(i,a,n) int a[n]; for(int i = 0; i < n; i++) scanf("%d", &a[i])
// printers
#define iprint(x) printf("%d\n", x)
#define lprint(x) printf("%lld\n", x)
#define fprint(x) printf("%.f\n", x)
#define dprint(x) printf("%.lf\n", x)
#define cprint(x) printf("%c\n", x)
#define sprint(x) printf("%s\n", x)
// scanners
#define iscan(x) scanf("%d", &x)
#define lscan(x) scanf("%lld", &x)
#define fscan(x) scanf("%f", &x)
#define dscan(x) scanf("%lf", &x)
#define cscan(x) scanf("%c\n", &x)
#define scan(x) scanf("%s", x)
// special scanners
#define escan(x) scanf("%[^\n]", x)
// quick scanners
#define qs(x) int x; scanf("%d", &x)
#define ls(x) long long x; scanf("%lld", &x)
#define fs(x) float x; scanf("%f", &x)
#define ds(x) double x; scanf("%lf", &x)
#define cs(x) char x; scanf("%lf", &x)
#define ss(x,n) char x[n]; scanf("%s", &x)
#define es(x,n) char x[n]; scanf("%[^\n]", &x)
typedef long long ll;
typedef double db;
int main()
{
qs(a); qs(b); qs(c); qs(d);
iprint(a*d - b*c);
} | #include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int a[20],b[110],n;bool bk[20];ll Ans=5e18;
void dfs(int k){
if(k>15){
bool PD=true;
for(int i=1;i<=n;i++){
bool pd=false;
for(int j=1;j<=15;j++)
if(bk[j]&&b[i]%a[j]==0) {pd=true;break;}
if(!pd) {PD=false;break;}
}
if(PD){
ll Sum=1;
for(int i=1;i<=15;i++)
if(bk[i]) Sum*=a[i];
if(Ans>Sum) Ans=Sum;
}
return ;
}
bk[k]=true;dfs(k+1);
bk[k]=false;dfs(k+1);
}
int main()
{
a[1]=2;a[2]=3;a[3]=5;a[4]=7;a[5]=11;
a[6]=13;a[7]=17;a[8]=19;a[9]=23;a[10]=29;
a[11]=31;a[12]=37;a[13]=41;a[14]=43;a[15]=47;
memset(bk,false,sizeof(bk));
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&b[i]);
dfs(1);
printf("%lld\n",Ans);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll N;
cin >> N;
ll M = floor(sqrt(N));
vector<bool> isExp(M+1, true);
ll cnt = 0;
isExp[0] = false;
for (ll i=2; i<=M; i++) {
if (isExp[i]) {
for (ll j=2; pow(i,j)<=N; j++) {
cnt++;
if (pow(i,j)<=M) {
isExp[pow(i,j)] = false;
}
}
}
}
cout << N - cnt << endl;
}
| #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
ll n;
cin >> n;
set<ll> s;
for (ll a = 2; a*a <= n; ++a){
ll x = a*a;
while (x <= n) {
s.insert(x);
x *= a;
}
}
cout << n-s.size() << endl;
}
|
// YATIN KWATRA
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#define ll long long
#define ar array
#define sz(v) (int)(v.size())
#define inf 1e18
#define int ll
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define fo(i,a,b) for(int i = a; i<=b ; i++)
#define rfo(i,a,b) for(int i = a; i>=b ; i--)
#define vii vector<int>
#define pq priority_queue
#define uomii unordered_map<int,int,best_hash>
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define pob pop_back
#define ff first
#define ss second
#define pii pair<int,int>
#define mii map<int,int>
#define vvii vector<vii>
#define mod 1000000007
#define MIN -1e9
#define pi 3.1415926535897932384626433832795
#define cz(x) 63 - __builtin_clzll(x)
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
struct best_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
const int N = 3e3 + 1;
int dp[N][N];
int v[N];
vii has[N][N]; // pos for remainder j from after i
int n;
int ways(int pos, int k) {
if (pos == n + 1) return 1;
int &ans = dp[pos][k];
if (ans != -1) return ans;
ans = 0;
// now go to next k+1 or k
int rem = v[pos - 1] % k;
int idx = lower_bound(all(has[k][rem]), pos) - has[k][rem].begin();
if (idx < sz(has[k][rem])) {
int to = has[k][rem][idx];
if (to < n) ans = (ways(to + 1, k) + ways(to + 1, k + 1)) % mod;
else ans = ways(to + 1, k);
}
return ans;
}
void solve()
{
cin >> n;
fo(i, 1, n) cin >> v[i];
memset(dp, -1, sizeof(dp));
fo(i, 1, n) {
int sum = 0;
fo(j, 1, n) {
sum += v[j];
has[i][sum % i].pb(j);
}
}
fo(i, 1, n) v[i] += v[i - 1];
cout << ways(1, 1);
}
signed main() {
FIO
int t;
t = 1;
//cin >> t;
fo(i, 0, t - 1) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define M 1005
#define LL long long
const LL mod = 1000000007;
int n;
LL f[M];
char Caa, Cab, Cba, Cbb;
inline LL qkpow (LL x, LL y){
LL res = 1;
while (y){
if (y & 1)
res = res * x % mod;
x = x * x % mod;
y >>= 1;
}
return res;
}
signed main (){
scanf ("%d\n%c\n%c\n%c\n%c", &n, &Caa, &Cab, &Cba, &Cbb);
if (n == 3 || n == 2){
printf ("1\n");
return 0;
}
f[1] = 2, f[2] = 3;
for (int i = 3; i <= n; i ++)
f[i] = (f[i - 1] + f[i - 2]) % mod;
if (Cab == 'B'){
if (Cbb == 'B')
printf ("1\n");
else{
if (Cba == 'A'){
printf ("%lld\n", qkpow (2, n - 3));
}
else{
printf ("%lld\n", f[n - 3]);
}
}
}
else{
if (Caa == 'A')
printf ("1\n");
else{
if (Cba == 'B'){
printf ("%lld\n", qkpow (2, n - 3));
}
else{
printf ("%lld\n", f[n - 3]);
}
}
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<ll,ll>
#define vi vector<ll>
#define mii map<ll,ll>
#define pqi priority_queue<ll> //max pq
#define pqd priority_queue<ll,vi,greater<ll> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define MOD 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define pw(b,p) pow(b,p) + 0.1
#define f(i,k,n) for(ll i=k;i<n;i++)
#define fd(i,start,end) for(ll i=start;i>=end;i--)
ll power(ll a, ll b, ll mod) {ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a % mod; a = a * a % mod;} return res;}
ll power(ll a, ll b) {ll res = 1; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a ; a = a * a;} return res;}
ll min( ll a, ll b) { return (a < b) ? a : b;}
ll max(ll a, ll b) {return (a > b) ? a : b;}
ll gcd (ll a, ll b) {if (a == 0) return b; return gcd(b % a, a);}
void bwayne()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output2.txt", "w", stdout);
#endif
}
// ll n;
// cin >> n;
// vi a(n);
// f(i, 0, n) {
// cin >> a[i];
// }
// vector<vi> a(n,vector<vi>(m,0));
// f(i,0,n){
// f(j,0,m){
// cin>>a[i][j];
// }
// }
void printNcR(ll n, ll r)
{
// p holds the value of n*(n-1)*(n-2)...,
// k holds the value of r*(r-1)...
long long p = 1, k = 1;
// C(n, r) == C(n, n-r),
// choosing the smaller value
if (n - r < r)
r = n - r;
if (r != 0) {
while (r) {
p *= n;
k *= r;
// gcd of p, k
long long m = gcd(p, k);
// dividing by gcd, to simplify
// product division by their gcd
// saves from the overflow
p /= m;
k /= m;
n--;
r--;
}
// k should be simplified to 1
// as C(n, r) is a natural number
// (denominator should be 1 ) .
}
else
p = 1;
// if our approach is correct p = ans and k =1
cout << p ;
}
void solve() {
ll l;
cin >> l;
l -= 12;
printNcR(l + 11, 11);
}
int main()
{
bwayne();// remember
ll t = 1;
// cin >> t;
for (ll tt = 1; tt <= t; tt++)
{
// cout << "Case #" << tt << ": ";
solve();
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>
using namespace std;
//using namespace atcoder;
#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[";
REP(i, SZ(v)) {
if (i) os << ", ";
os << v[i];
}
return os << "]";
}
template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "(" << p.first << " " << p.second << ")";
}
template<class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template<class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;
// edit
void solve() {
int N;
cin >> N;
vector<ll> A(N);
REP(i, N) cin >> A[i];
vector<ll> S(N);
map<ll, ll> ce, co;
co[0]++;
REP(i, N) {
if (i == 0) S[i] = A[i];
else S[i] = A[i] - S[i - 1];
// else S[i] = S[i - 1] + A[i];
if (i % 2 == 0) {
ce[S[i]]++;
} else {
co[S[i]]++;
}
}
ll ans = 0;
set<ll> app_ce, app_co, app;
for (auto e : ce) {
app_ce.insert(e.first);
app.insert(e.first);
}
for (auto e : co) {
app_co.insert(e.first);
app.insert(e.first);
}
for (auto e : app_ce) {
ll val = ce[e];
ll add = (val * val - val) / 2;
ans += add;
}
for (auto e : app_co) {
ll val = co[e];
ll add = (val * val - val) / 2;
ans += add;
}
for (auto e : app_ce) {
if (ce.count(e) == 0 || co.count(-e) == 0) continue;
ll add = ce[e] * co[-e];
ans += add;
}
cout << ans << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
// std::ifstream in("input.txt");
// std::cin.rdbuf(in.rdbuf());
solve();
return 0;
}
|
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn=2e5+10;
const int mod=998244353;
int n,ans=1,now,f[maxn],v[maxn];
int read(int x=0,bool f=0,char ch=getchar()){
for(;ch<'0' || ch>'9';ch=getchar()) f=ch=='-';
for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+(ch&15);
return f?-x:x;
}
int main(){
n=read();
for(int i=1;i<=n;++i) f[i]=read();
for(int i=1;i<=n;++i){
if(!v[i]){
++now;
int x=i;
while(!v[x]) v[x]=now,x=f[x];
if(v[x]==now) ans=ans*2%mod;
}
}
printf("%d\n",(ans+mod-1)%mod);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
template <int MOD>
struct ModInt {
int _v;
ModInt(int64_t v = 0) {
if (v < 0) v = v % MOD + MOD;
if (v >= MOD) v %= MOD;
_v = int(v);
}
ModInt(uint64_t v) {
if (v >= MOD) v %= MOD;
_v = int(v);
}
ModInt(int v) : ModInt(int64_t(v)) {}
ModInt(unsigned v) : ModInt(uint64_t(v)) {}
ModInt& operator++() {
++_v;
if (_v == MOD) _v = 0;
return *this;
}
ModInt& operator--() {
if (_v == 0) _v = MOD;
--_v;
return *this;
}
ModInt& operator+=(const ModInt& rhs) {
_v += rhs._v;
if (_v >= MOD) _v -= MOD;
return *this;
}
ModInt& operator-=(const ModInt& rhs) {
_v -= rhs._v;
if (_v < 0) _v += MOD;
return *this;
}
ModInt& operator*=(const ModInt& rhs) {
int64_t z = _v;
z *= rhs._v;
_v = z % MOD;
return *this;
}
ModInt operator++(int) { ModInt before = *this; ++*this; return before; }
ModInt operator--(int) { ModInt before = *this; --*this; return before; }
friend ModInt operator*(const ModInt &a, const ModInt &b) { return ModInt(a) *= b; }
friend ModInt operator+(const ModInt &a, const ModInt &b) { return ModInt(a) += b; }
friend ModInt operator-(const ModInt &a, const ModInt &b) { return ModInt(a) -= b; }
friend bool operator==(const ModInt &a, const ModInt &b) { return a.val == b.val; }
friend bool operator!=(const ModInt &a, const ModInt &b) { return a.val != b.val; }
friend bool operator<(const ModInt &a, const ModInt &b) { return a.val < b.val; }
friend bool operator>(const ModInt &a, const ModInt &b) { return a.val > b.val; }
friend bool operator<=(const ModInt &a, const ModInt &b) { return a.val <= b.val; }
friend bool operator>=(const ModInt &a, const ModInt &b) { return a.val >= b.val; }
friend ostream& operator<<(ostream &os, const ModInt& a) { return os << a._v; }
};
const int MOD = 998244353;
using mod_int = ModInt<MOD>;
int main() {
int N;
cin >> N;
vector<vector<int>> g(N);
for (int i = 0; i < N; ++i) {
int x;
cin >> x;
--x; // Convert to 0-based indexing.
g[i].push_back(x);
g[x].push_back(i);
}
function<void(int, vector<bool>&)> visitComponentDFS;
visitComponentDFS = [&] (int u, vector<bool>& visited) {
visited[u] = true;
for (int v : g[u]) {
if (!visited[v]) {
visitComponentDFS(v, visited);
}
}
};
mod_int num = 1;
vector<bool> visited(N, false);
int num_cc = 0;
for (int i = 0; i < N; ++i) {
if (!visited[i]) {
++num_cc;
visitComponentDFS(i, visited);
}
}
while (num_cc > 0) {
num *= 2;
--num_cc;
}
num -= 1;
cout << num << endl;
} |
#include <bits/stdc++.h>
using namespace std;
int N, a[505];
void solve() {
cin >> N;
for (int i = 1; i <= N; i++) cin >> a[i];
vector<int> ans;
for (int stp = 1; stp <= N * N; stp++) {
bool flg = 1;
for (int i = 2; i <= N && flg; i++) flg &= a[i - 1] < a[i];
if (flg) break;
int cur = (stp & 1) ? 1 : 2;
for (int i = cur; i < N; i += 2)
if (a[i] > a[i + 1]) cur = i;
swap(a[cur], a[cur + 1]);
ans.push_back(cur);
}
printf("%lu\n", ans.size());
for (int i : ans) printf("%d ", i);
putchar('\n');
}
int main () {
#ifndef ONLINE_JUDGE
freopen("cpp.in", "r", stdin);
#endif
int T; cin >> T;
while (T--) solve();
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//#include <atcoder/convolution>
//#include <atcoder/modint>
//using Modint = atcoder::modint998244353;
using namespace std;
typedef long long ll;
void ex_gcd(ll a, ll b, ll &d, ll &x, ll &y) {
if (!b) {
d = a;
x = 1;
y = 0;
} else {
ex_gcd(b, a % b, d, y, x);
y -= a / b * x;
}
}
ll inv(ll a, ll n) {
ll d, x, y;
ex_gcd(a, n, d, x, y);
return d == 1 ? (x % n + n) % (n / d) : -1;
}
ll gcd(ll x, ll y) {
if (y == 0) return x;
return gcd(y, x % y);
}
const int maxn = 505;
const int mod = 998244353;
int a[maxn];
int pos[maxn];
int main() {
#ifdef suiyuan2009
freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
int T;
cin>>T;
while(T--){
int n;
cin>>n;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
pos[a[i]] = i;
}
int cur=1;
vector<int>ans;
for(int i=n;i>=4;i--){
if(pos[i]==i)continue;
if((pos[i]&1)!=cur){
if(i==4&&pos[4]==3){
int idx = pos[i];
swap(a[idx-1], a[idx]);
cur = 1-cur;
ans.push_back(idx-1);
pos[a[idx-1]] = idx-1;
pos[a[idx]] = idx;
}
for(int j=1;j<i;j++){
if(a[j]!=i&&a[j+1]!=i&&(j&1)==cur){
swap(a[j], a[j+1]);
cur = 1 - cur;
ans.push_back(j);
pos[a[j]] = j;
pos[a[j+1]] = j+1;
break;
}
}
}
for(int j=pos[i];j<i;j++){
ans.push_back(j);
cur = 1-cur;
swap(a[j], a[j+1]);
pos[a[j]] = j;
pos[a[j+1]] = j+1;
}
}
if(n==2){
if(!(a[1]==1&&a[2]==2)){
ans.push_back(1);
cur = 1 - cur;
swap(a[1], a[2]);
pos[a[1]] = 1;
pos[a[2]] = 2;
}
} else {
while(!(a[1]==1&&a[2]==2&&a[3]==3)){
int tmp = 2 - cur;
ans.push_back(tmp);
cur = 1-cur;
swap(a[tmp], a[tmp+1]);
pos[a[tmp]] = tmp;
pos[a[tmp+1]] = tmp+1;
}
}
cout<<ans.size()<<endl;
for(int i=0;i<ans.size();i++){
if(i)printf(" ");
printf("%d", ans[i]);
}
cout<<endl;
}
return 0;
} |
#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using PIL = pair<int,ll>;
using PLI = pair<ll,int>;
using PLL = pair<ll,ll>;
using Graph = vector<vector<int>>;
using Cost_Graph = vector<vector<PIL>>;
template<class T> bool chmin(T &a, T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b){a=b;return 1;}return 0;}
template<class T> void show_vec(T v) {for (int i=0;i<v.size();i++) cout<<v[i]<<endl;}
template<class T> void show_pair(T p) {cout<<p.first<<" "<<p.second<<endl;}
template<class T> bool judge_digit(T bit,T i) {return (((bit&(1LL<<i))!=0)?1:0);}
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ROUNDUP(a,b) ((a+b-1)/b)
#define YESNO(T) cout<<(T?"YES":"NO")<<endl
#define yesno(T) cout<<(T?"yes":"no")<<endl
#define YesNo(T) cout<<(T?"Yes":"No")<<endl
const int INFint = 1 << 29;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007LL;
const vector<int> h_idx4 = {-1, 0,0,1};
const vector<int> w_idx4 = { 0,-1,1,0};
const vector<int> h_idx8 = {-1,-1,-1, 0,0, 1,1,1};
const vector<int> w_idx8 = {-1, 0, 1,-1,1,-1,0,1};
vector<ll> result;
struct Point {
int pi,pj;
};
string calc_path(Point s,Point t){
int di = t.pi - s.pi, dj = t.pj - s.pj;
// cout << di << " " << dj << endl;
string res;
if (di > 0){
for (int i = 0; i < di; i++){
res.push_back('D');
}
}
else{
for (int i = 0; i < -di; i++){
res.push_back('U');
}
}
if (dj > 0){
for (int i = 0; i < dj; i++){
res.push_back('R');
}
}
else{
for (int i = 0; i < -dj; i++){
res.push_back('L');
}
}
return res;
}
void input_point(Point &s,Point &t){
cin >> s.pi >> s.pj >> t.pi >> t.pj;
return;
}
void input_score(){
ll x;
cin >> x;
result.push_back(x);
return;
}
void output_part(string s){
cout << s << endl;
}
void solve_part(){
Point s,t;
input_point(s,t);
string res = calc_path(s,t);
output_part(res);
input_score();
}
void solve(){
for (int i = 0; i < 1000; i++){
solve_part();
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
solve();
return 0;
} | #include <iostream>
#include <vector>
int main()
{
for (int query = 0; query < 1000; query++)
{
int si, sj, ti, tj;
std::cin >> si >> sj >> ti >> tj;
for (int i = 0; i < std::max(si - ti, 0); i++)
{
std::cout << 'U';
}
for (int i = 0; i < std::max(ti - si, 0); i++)
{
std::cout << 'D';
}
for (int i = 0; i < std::max(sj - tj, 0); i++)
{
std::cout << 'L';
}
for (int i = 0; i < std::max(tj - sj, 0); i++)
{
std::cout << 'R';
}
std::cout << std::endl;
int response;
std::cin >> response;
}
return 0;
}
|
#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
#define enviar {ios_base::sync_with_stdio(false);}
#define aiuda {cin.tie(NULL); cout.tie(NULL);}
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) ;F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
#define exacto(v) cout << setprecision(v) << fixed;
#define ll long long
#define lld long double
#define eb emplace_back
#define em emplace
#define ef emplace_front
#define f first
#define s second
#define big greater<ll>()
#define bpc(x) __builtin_popcount(x)
#define bpc2(x) __builtin_clz(x)
#define DIE(args...) {print(args); return;}
#define ar(v) array<int,v>
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x).size()
#define meminf(v) memset(v, 0x3f , sizeof(v))
#define mem(v,x) memset(v , x , sizeof v);
#define ai(a, n) for (int ele = 0; ele < n; ele++) cin >> a[ele];
#define ao(a, n) {for (int ele = 0; ele < (n); ele++) { if (ele) cout << " "; cout << a[ele]; } cout << '\n';}
#define readgraph(list, edges) for (int i = 0; i < edges; i++) {int n1, n2; cin >> n1 >> n2; n1--; n2--; list[n1].eb(n2); list[n2].eb(n1);}
template <typename T>
struct combinator {
T t_;
combinator(T&& t) : t_(std::forward<T>(t)) {}
template <typename... Args>
auto operator () (Args&&... args) const
{
return t_(*this, std::forward<Args>(args)...);
}
};
template<class T> bool umin(T& a, const T& b) { return b<a?a=b, 1:0; }
template<class T> bool umax(T& a, const T& b) { return a<b?a=b, 1:0; }
string to_string(bool b) {return b?"true":"false"; }
string to_string(char c) { return string(1, c);}
string to_string(const char* s) { return string(s); }
string to_string(string s) { return s; }
template<class T> string to_string(T v) { bool f=1; string res; EACH(x, v) { if(!f) res+=' '; f=0; res+=to_string(x); } return res; }
template<class A> void write(A x) { cout << to_string(x); }
void print() { write("\n"); }
template<class H, class... T> void print(const H& h, const T&... t) { write(h); if(sizeof...(t)) write(' '); print(t...); }
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef priority_queue<int, std::vector<int>, std::greater<int>> priomin;
const ll mod = 998244353;
const ll maxsize =3e5 + 10;
const ll inf = 0x3f3f3f3f3f3f3f3f ;
// size, caracter
ll c[maxsize];
bool sieve[100];
vll primes(100);
ll m;
void solve()
{
for(ll i =2; i <= 72 ; i++)
{
if (sieve[i]) continue;
primes[m++] = i;
for(ll j = i*i; j <= 72 ; j+=i)
{
sieve[j] = true;
}
}
ll a, b;
cin >> a >> b;
//m--;
vll dp(1<<m , 0);
dp[0] = 1;
for( ll i = a; i <= b ; i++)
{
ll mask = 0;
FOR(j , m)
{
if (i%primes[j] == 0 ) mask |= 1<<j;
}
FOR(k , 1<<m)
{
if ((k & mask) == 0)
{
dp[k | mask] += dp[k];
}
}
}
// FOR(i , m) print(primes[i]);
ll ans = 0;
FOR(i , 1<<20 ) ans += dp[i];
print(ans);
}
int main(){
enviar aiuda
int tc = 1;
//cin >> tc;
while(tc--) solve();
return 0;
}
| //Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
int isprime[N];
ll dp[(1<<21)+10];
void solve()
{
ll a,b;
cin>>a>>b;
vl primes;
for(int i=2;i<=72;i++)
{
if(isprime[i]==i)
primes.pb(i);
}
dp[0]=1;
ll fun[100]={0};
int cnt=0;
for(ll x=a;x<=b;x++)
{
int mask=0;
for(int i=0;i<primes.size();i++)
{
if(x%primes[i]==0)
{
mask+=(1<<i);
}
}
fun[x-a]=mask;
if(mask==0)
cnt++;
}
dp[0]=(1ll<<cnt);
ll ans=dp[0];
for(int i=1;i<(1<<(primes.size()));i++)
{
int consider=0;
for(ll j=0;j<60;j++)
{
if((i&(1ll<<j))!=0)
{
consider=j;
break;
}
}
for(ll k=a;k<=b;k++)
{
int mask=0;
mask=fun[k-a];
if((mask&i)==mask && (mask&(1<<consider))!=0)
{
dp[i]+=dp[i^mask];
}
}
ans+=dp[i];
}
cout<<ans<<'\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T=1;
//cin>>T;
for(int i=1;i<N;i++)
isprime[i]=i;
for(int i=2;i<N;i++)
{
if(isprime[i]!=i)
continue;
for(int j=i;j<N;j+=i)
isprime[j]=i;
}
int t=0;
while(t++<T)
{
//cout<<"Case #"<<t<<":"<<' ';
solve();
//cout<<'\n';
}
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
} |
/* � Ashiq Uddin Pranto
Department of Computer Science and Engineering
BATCH 27
University Of Rajshahi,Bangladesh
*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define FOR(x,y) for(ll i=x;i<=y;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define matrix(x) vector<vector<x>>
#define vss vector<string>
#define PI (2*acos(0.0))
#define sqr(x) ((x)*(x))
#define sf(a) scanf("%d",&a)
#define sfl(a) scanf("%lld",&a)
#define sff(a,b) scanf("%d %d",&a,&b)
#define sffl(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b) memset(a, b, sizeof(a))
#define ff first
#define ss second
#define lcm(a, b) ((a)*((b)/__gcd(a,b)))
#define all(a) a.begin(),a.end()
#define readfile freopen("input.txt","r",stdin);
#define writefile freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define gap " "
#define mx 104
#define inf (ll)1e9
#define WHITE 1
#define GRAY 2
#define BLACK 3
#define EMPTY_VALUE -1
#define mod 1000000007
#define MOD(a,b) (a%b + b)%b
using namespace std;
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
void eff()
{
ll n,k;
sffl(n,k);
vll a(n);
map<ll,ll>cnt;
for(ll i=0;i<n;i++)
{
sfl(a[i]);
cnt[a[i]]++;
}
// debug(cnt);
ll boxmax;
auto x = cnt.begin();
if(x->first==0)
{
boxmax = min(k,x->second);
}
else
{
printf("0\n");
return;
}
ll i=0;
ll ans = 0;
ll lastfirst = 0;
for(auto x: cnt)
{
if(abs(lastfirst-x.first)>=2)
{
ans+=i*(boxmax);
cout<<ans<<endl;
return;
}
if(x.second <boxmax)
{
ans+=i*(boxmax-x.second);
boxmax = x.second;
}
lastfirst = x.first;
i++;
}
// auto last = cnt.rbegin();
ans+=i*(boxmax);
cout<<ans<<endl;
}
int main()
{
// fastio
// ll test ;
// sfl(test);
// for(ll i=0;i<test;i++)
// {
// printf("Case %lld: ",i+1);
eff();
// }
// cout<<check(81);
return 0;
}
| //g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt
#include <iostream> //
#include <vector> //
#include <algorithm> //
#include <queue> //
#include <string> //
#include <functional> //
#include <set> //
#include <map> //
#include <random> //
#include <ctime> //
#include <bitset> //
#include <cassert>
// #include <atcoder/all>
// using namespace atcoder;
// g++ t.cpp -o t -I .
#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
using P=pair<ll,ll>;
const ll M = 998244353;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
ll mod_pow(ll x, ll a, ll m) { ll an = 1; while(a > 0) { if (a&1) an = an * x % m; x = x * x % m; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;} bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
ll gcd(ll a, ll b) {if (b==0) return a; else return gcd(b, a%b);}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};
int main() {
ll n,k; cin>>n>>k;
ll a[n]; for(int i=0;i<n;i++) cin>>a[i];
ll b[n+1]={}; for(int i=0;i<n;i++) b[a[i]]++;
ll an=0;
for(int i=0;i<k;i++) {
//for(int j=0;j<=n;j++)cout<<b[i]<<" ";cout<<endl;
for(int j=0;j<=n;j++) {
if (b[j]==0) {
an+=j; break;
} else {
b[j]--;
}
}
//cout<<an<<endl;
}
cout<<an<<endl;
}
// ・配列の大きさok? ・priority_queueはgreater? ・debug消した?
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……
// Thank you for making problems and running the contest
|
//abc185 b
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main() {
int n,m,t;
cin >> n >> m >> t;
int last_time = 0;
int max = n;
string ans = "Yes";
for(int i=0 ; i<m ; i++){
int a,b;
cin >> a >> b;
n -= a-last_time;
if(n < 1){
ans = "No";
}
if(n + b - a <= max){
n += b - a;
}else{
n = max;
}
last_time = b;
if(i == m-1){
n -= t - b;
if(n < 1){
ans = "No";
}
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using P=pair<int64_t,int>;
int main(){
int N,K;
cin >> N >> K;
vector<P> vp;
for(int i=0;i<N;i++){
int64_t A;
int B;
cin >> A >> B;
vp.emplace_back(A,B);
}
sort(vp.begin(),vp.end());
int64_t m=K;
for(int i=0;i<N;i++){
auto &p=vp.at(i);
if(m>=p.first){
m+=p.second;
}else{
break;
}
}
cout << m << endl;
return 0;
}
|
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
ll p[maxn];
bool cmp(ll a,ll b){
return a>b;
}
int main(){
int n;
cin>>n;
ll sum=0;
for(int i=0;i<n;i++){
ll a,b;
cin>>a>>b;
sum+=a;
p[i]=2*a+b;
}
sort(p,p+n,cmp);
int ans=0;
ll sumb=0;
for(int i=0;i<n;i++){
sumb+=p[i];
ans++;
if(sum<sumb)
break;
}
cout<<ans<<endl;
return 0;
} | #include <bits/stdc++.h>
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprrev(i, a, b) for (int i = b - 1; i >= a; i--) // [a, b)
#define reprev(i, n) reprrev(i, 0, n)
#define _GLIBCXX_DEBUG
using ll = long long;
using ull = unsigned long long;
template <class T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
const ll mod = 1e9 + 7;
const ll INF = 1e18;
void chmod(ll &M)
{
if (M >= mod)
M %= mod;
else if (M < 0)
{
M += (abs(M) / mod + 1) * mod;
M %= mod;
}
}
ll modpow(ll x, ll n)
{
if (n == 0)
return 1;
ll res = modpow(x, n / 2);
if (n % 2 == 0)
return res * res % mod;
else
return res * res % mod * x % mod;
}
int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };
long long GCD(long long a, long long b)
{
if (b == 0)
return a;
else
return GCD(b, a % b);
}
using namespace std;
int main() {
int N; cin >> N;
ll A = 0;
vector<pair<ll, ll>> P(N);
vector<ll> sum(N);
rep(i, N) {
cin >> P[i].first >> P[i].second;
A += P[i].first;
ll s = 2*P[i].first + P[i].second;
sum[i] = s;
}
sort(sum.rbegin(), sum.rend());
vector<ll> S(N+1, 0);
rep(i, N) {
S[i+1] = S[i] + sum[i];
}
auto it = lower_bound(S.begin(), S.end(), A+1);
ll ans = it - S.begin();
cout << ans << endl;
} |
/* What we know is a drop , but what we don't know is an ocean !*/
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fall(a) a.begin(),a.end()
#define sz(x) (int)x.size()
#define szs(x) (int)x.length()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fs first
#define ss second
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef queue<int> qin;
typedef queue<char> qch;
typedef deque<ll> dqll;
typedef deque<int> dqint;
typedef deque<char> dqch;
typedef priority_queue<ll> pqll;
typedef priority_queue<int> pqin;
typedef priority_queue<char> pqch;
typedef map<ll,ll> mpll;
typedef map<int,int> mpin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;
const ll MOD=1000000007;
const long double PI=3.1415926535897932384626433832795;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}
ll mpwr(ll b,ll p){ll res=1;while(p){if(p&1) {res=(res*b)%MOD; p--;}else{b=(b*b)%MOD; p>>=1;}}return res;}
int msb (int n) {return 31-__builtin_clz(n);}
ll msbl (ll n) {return 63-__builtin_clzll(n);}
int lsb (int n) {return __builtin_ctz(n);}
ll lsbl (ll n) {return __builtin_ctzll(n);}
int setbit (int n) {return __builtin_popcount(n);}
ll setbitl (ll n) {return __builtin_popcountll(n);}
const int maxn = 3005;
ll dp [maxn][maxn];
int main()
{
ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
ll n; cin>>n;
vll a (n);
F (i,0,n,1) cin>>a[i];
F (i,0,n,1) {
F (j,0,n,1) dp[i][j]=0;
}
F (i,0,n,1) dp[i][1]=1;
F (j,2,n+1,1) {
ll s=0;
vll sum (n,0);
F (i,0,n,1) {
s=(s+a[i])%j;
dp[i][j]=sum[s];
sum[s]=(sum[s]+dp[i][j-1])%MOD;
}
}
ll ans=0;
F (i,1,n+1,1) ans=(ans+dp[n-1][i])%MOD;
cout<<ans;
return 0;
}
/*Maybe you are searching among the branches for what only appears in the roots.*/ | #include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010000
#define EPS 1e-9
#define F first
#define S second
#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"
#define N 500010
typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;
template <typename T>
bool chmax(T &a, const T& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
if (a > b) {
a = b;
return true;
}
return false;
}
struct Node{
vector<PII> edges;//first=cost,second=index
bool visit;
int cost;
};
vector<Node> mp(N);
void dijkstra(int st,int n){
rep(i,n){
mp[i].visit=false;
mp[i].cost= INF;
}
priority_queue<PII> q;
mp[st].cost=0;
rep(i,mp[st].edges.size() ){
mp[mp[st].edges[i].S].cost=mp[st].edges[i].F;
q.push({-mp[st].edges[i].F,mp[st].edges[i].S});
}
mp[st].visit=true;
while(!q.empty() ){
PII p=q.top();
int u=p.S;
q.pop();
if(mp[u].cost < -p.F) continue;
mp[u].visit=true;
rep(i,mp[u].edges.size() ){
int v=mp[u].edges[i].S;
if(!mp[v].visit){
if(mp[v].cost> mp[u].cost+mp[u].edges[i].F){
mp[v].cost=mp[u].cost+mp[u].edges[i].F;
q.push({-mp[v].cost,v});
}
}
}
}
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
int r,c;
cin>>r>>c;
int A[r][c-1],B[r-1][c];
rep(i,r) rep(j,c-1) cin>>A[i][j];
rep(i,r-1) rep(j,c) cin>>B[i][j];
rep(i,r){
rep(j,c){
int mn=(i*c)+j,mx=250000+mn;
if(j<c-1) mp[mn].edges.push_back({A[i][j],mn+1});
if(j>0) mp[mn].edges.push_back({A[i][j-1],mn-1});
if(i<r-1) mp[mn].edges.push_back({B[i][j],mn+c});
mp[mn].edges.push_back({1,mx});
if(mx-c >= 250000) mp[mx].edges.push_back({1,mx-c});
mp[mx].edges.push_back({0,mn});
}
}
dijkstra(0,250000+(r*c) );
/*rep(i,r){
rep(j,c){
cout<<mp[(i*c)+j].cost<<" ";
}
cout<<endl;
}*/
cout<<mp[r*c-1].cost<<endl;
return 0;
}
|
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <complex>
using namespace std;
#define all(v) v.begin(),v.end()
#define GS std::greater<int>()
#define FOR(i,l,r) for(Int i=(l);i<(r);i++)
#define DCOUT cout<<fixed<<setprecision(15) //DCOUT<<d<<endl;
#define ROUNDUP(a,b) ((a)+((b)-1))/(b)
#define TDVEC(name,type,h,w) vector<vector<type>>name((h),vector<type>(w))
#define P pair<Int,Int>
#define MOD 1000000007
#define MOD2 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define PI 3.1415926535897932384626433832795028
#define itn int
#define space ' '
typedef long long Int;
typedef unsigned long long uInt;
typedef long double ld;
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 main(){
Int a,b,c,d;cin>>a>>b>>c>>d;
cout<<a*d-b*c<<endl;
return 0;
} | #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rrep(i,n) for(ll i=n-1; i>=0; i--)
#define fi first
#define se second
#define pcnt __builtin_popcountll
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
string zero_padding(int val, int nf){ ostringstream sout;sout << setfill('0') << setw(nf) << val; return sout.str();};
const ld eps = 1e-10;
ull mo = 1000000007;
ld PI=asin(1)*2;
//using namespace atcoder;
vector<vector<PlP>> G(100010);
int main(){
ll N,M;
cin >> N >> M;
vector<ll> A(M), B(M), C(M), D(M);
rep(i,M){
cin >> A[i] >> B[i] >> C[i] >> D[i];
A[i]--; B[i]--;
}
rep(i,M){
G[A[i]].push_back({C[i],{D[i],B[i]}});
G[B[i]].push_back({C[i],{D[i],A[i]}});
}
vector<ll> d1(N,1e18);
priority_queue<Pll, vector<Pll>, greater<Pll>> que;
que.push(Pll(0,0));
while(!que.empty()){
ll t = que.top().fi;
ll v = que.top().se;
que.pop();
if(d1[v] <= t) continue;
//if(d1[v] != 1e18) continue;
d1[v] = t;
for(auto& p:G[v]){
ll c = p.fi;
ll d = p.se.fi;
ll u = p.se.se;
ll rd1 = max(ll(sqrt(ld(d))-1),ll(t));
ll rd2 = max(ll(sqrt(ld(d))),ll(t));
ll tt1 = ll(rd1) + c + ll(d/(rd1+1));
ll tt2 = ll(rd2) + c + ll(d/(rd2+1));
// cout << L << " " << R << " " << r1 << " " << r2 << endl;
que.push(Pll(min(tt1,tt2),u));
}
}
if(d1[N-1] == 1e18){
drop(-1);
}
cout << d1[N-1] << endl;
}
|
//デバッグ用オプション:-fsanitize=undefined,address
//コンパイラ最適化
#pragma GCC optimize("Ofast")
//インクルードなど
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
using vint = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vbool = vector<bool>;
template <class T> using arr = vector<vector<T>>;
//マクロ
// forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
// FORAは範囲for文(使いにくかったら消す)
#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 = b - 1; i >= ll(a); i--)
#define FORA(i, I) for (const auto &i : I)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF 1000000000000 // 10^12:∞
#define MOD 1000000007 // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b; // aをbで更新
return true;
}
return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b; // aをbで更新
return true;
}
return false;
}
template <class T> void pl(T x) { cout << x << " "; }
template <class T> void pr(T x) { cout << x << endl; }
template <class T> void prvec(const vector<T> &a) {
REP(i, a.size() - 1) { cout << a[i] << " "; }
pr(a[a.size() - 1]);
}
template <class T> void prarr(const arr<T> &a) {
REP(i, a.size())
if (a[i].empty())
pr("");
else
prvec(a[i]);
}
using P = pair<ll, ll>;
void prp(const P &p) { cout << p.first << " " << p.second << endl; }
struct Constants {
ll N;
Constants() { cin >> N; }
} C;
struct Args {
vll a, b, p;
vll ids;
Args() : a(C.N), b(C.N), p(C.N), ids(C.N) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
REP(i, C.N) cin >> a.at(i);
REP(i, C.N) cin >> b.at(i);
REP(i, C.N) {
cin >> p.at(i);
--p.at(i);
}
REP(i, C.N) ids.at(i) = i;
sort(ALL(ids), [&](ll l, ll r) { return a.at(l) < a.at(r); });
}
} args;
struct Solver {
bool ok;
vector<P> ans;
Solver() : ok(true), ans() {}
//
void solve() {
vll cur(C.N);
REP(i, C.N) {
cur.at(args.p.at(i)) = i;
}
FORA(id, args.ids) {
ll target = cur.at(id);
if (target == id) {
continue;
}
if (args.a.at(id) <= args.b.at(args.p.at(id))) {
ok = false;
return;
}
if (args.a.at(target) <= args.b.at(args.p.at(target))) {
ok = false;
return;
}
ans.push_back({id + 1, target + 1});
swap(args.p.at(id), args.p.at(target));
cur.at(args.p.at(id)) = id;
cur.at(args.p.at(target)) = target;
}
}
void output() {
if (!ok) {
pr(-1);
return;
}
pr(ans.size());
FORA(p, ans) prp(p);
}
} s;
int main() {
s.solve();
s.output();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
using vp=vector<P>;
using vvp=vector<vp>;
const int inf=1e9+7;
const ll INF=9e18/2;
const long double PI = acosl(-1.0);
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
bool pair_comp(const pair<long,long> &A,const pair<long,long> &B){if(A.first==B.first)return A.second>B.second;return A.first<B.first;}//F昇→S降
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
ll dp[1<<19];//dp[s]:=前からsの時、条件を満たす数
int main(){//cout<<fixed<<setprecision(20);
ll n,m;
cin>>n>>m;
vll x(m),y(m),z(m);
rep(i,0,m){
cin>>x[i]>>y[i]>>z[i];
y[i]--;
}
dp[0]=1;
rep(i,1,1<<n){
int t=__builtin_popcount(i);
vin sum(n,0);//sum[j]:=j以下の総数
rep(j,0,n)if(i&(1<<j))sum[j]++;
rep(j,1,n)sum[j]+=sum[j-1];
rep(j,0,n){
if(!(i&(1<<j)))continue;
bool ok=true;
rep(k,0,m){
if(x[k]<t)continue;
if(sum[y[k]]>z[k]){
ok=false;
break;
}
}
if(ok)dp[i]+=dp[i&(~(1<<j))];
}
}
cout<<dp[(1<<n)-1]<<endl;
} |
/*
@Author
Sujeet Kushwaha
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int>
#define vp vector<pair<long long int ,long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define iter vector<int>::iterator
#define pa pair<long long int ,long long int>
#define f(a,b) for(int a=0;a<b;a++)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ll mul(ll a,ll b)
// {
// return (a%mod*b%mod)%mod;
// }
// ll add(ll a,ll b)
// {
// ll res=a+b;
// if(res>=mod)
// {
// res-=mod;
// }
// return res;
// }
// ll sub(ll a,ll b)
// {
// ll res=a-b;
// if(res<0)
// res+=mod;
// return res;
// }
// ll powmod(ll a, ll b)
// {
// ll res = 1;
// while (b) {
// if (b&1) {
// res =mul(res,a);
// }
// b >>= 1;
// a=mul(a,a);
// }
// return res;
// }
// ll modinv(ll a)
// {
// return powmod(a, mod - 2);
// }
// unordered_map<ll,ll>facti;
// ll fact(ll n)
// {
// if(n==0)return 1;
// if(n<=1)return 1;
// if(facti[n]!=0)return facti[n];
// return facti[n]=mul(n,fact(n-1));
// }
// ll ncr(ll n,ll r)
// {
// ll h=fact(n);
// ll v=fact(r);
// ll j=fact(n-r);
// v=mul(v,j);
// v=powmod(v,mod-2);
// return mul(h,v);
// }
// int fastread(){
// int x=0;
// int c = getchar_unlocked();
// while(c<48)
// c = getchar_unlocked();
// while(c>=48){
// x = x*10 + (c - 48);
// c = getchar_unlocked();
// }
// return x;
// }
// bool comp(pa a,pa b)
// {
// if(a.F==b.F)
// {
// return v[a.S]<v[b.S];
// }
// returna.S<b.S;
// }
const int N = 2e5 + 10;
vector<pa>g[N];
ll dp[N];
void dfs(ll v,ll par=-1)
{
for(pa d:g[v])
{
if(d.first-par)
{
dp[d.first]=dp[v]^d.second;
dfs(d.first,v);
}
}
}
void solve()
{
ll n;
cin>>n;
f(i,n-1)
{
ll x,y,w;
cin>>x>>y>>w;
x--,y--;
g[x].pb({y,w});
g[y].pb({x,w});
}
dfs(0);
ll ans=0;
f(j,60)
{
ll ones,zeros;
ones=zeros=0;
f(i,n)
{
if(dp[i]&(1ll<<j))
{
ones++;
}
else
{
zeros++;
}
}
zeros*=ones;
zeros%=mod;
ans+=((1ll<<j)%mod*zeros%mod);
ans%=mod;
}
cout<<ans<<endl;
}
int main() {
fast;
fast_input;
fast_output;
// ll t;
// cin>>t;
// while(t--)
// {
solve();
// }
return 0;
} | #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
ll c=a%i_7;
if(c>=0)return c;
return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
struct Ni{
ll w,v;
ll flag;
};
bool comp(Ni x, Ni y){
if(x.v>y.v){
return true;
}else if(x.v<y.v){
return false;
}
return x.w<y.w;
}
int main(){fastio
ll n,m,q;cin>>n>>m>>q;
ll w[n+1],v[n+1];
Ni ni[n+1];
rep(i,1,n){
cin>>w[i]>>v[i];
ni[i].w=w[i];
ni[i].v=v[i];
ni[i].flag=i;
}
sort(ni+1,ni+(n+1),comp);
ll x[m+1];
rep(i,1,m){
cin>>x[i];
}
rep(qi,1,q){
ll l,r;cin>>l>>r;
bool valid[m+1];rep(i,1,m)valid[i]=true;
rep(i,l,r){
valid[i]=false;
}
ll res=0;
rep(i,1,n){
ll now=0;
rep(j,1,m){
if(!valid[j])continue;
if(x[j] < ni[i].w)continue;
if(now!=0 && x[now] <= x[j])continue;
now=j;
}
if(now==0)continue;
res += ni[i].v;
valid[now] = false;
}
cout<<res<<endl;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
cout<<21-a-b-c<<endl;
return 0;
} | //#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define forr(i,n) for(int i=0;i<n;i++)
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define CASE(t) ll t; cin>>t; while(t--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vi vector<ll>
#define cs(ele) cout<<ele<<'\n'
#define pii pair<ll,ll>
#define MAXN 100001
#define all(d) d.begin(),d.end()
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
const ll mod=1e9 +7;
//const ll mod=998244353;
//ll Mod(ll n){return ((n%mod)+mod)%mod;}
//ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=mod(res*x);x=mod(x*x);y=mod(y>>1);}return mod(res);}
void fast(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
ll f[200005];
ll invfact[200005];
ll power(ll x,ll y){
ll res=1;
while(y>0){
if(y&1){
res=(res*x)%mod;
}
x=(x*x)%mod;
y>>=1;
}
return res;
}
void precal(){
f[0]=1;
invfact[0]=1;
for(int i=1;i<200005;i++){
f[i]=(f[i-1]*i)%mod;
invfact[i]=power(f[i],mod-2);
}
}
ll ncr(ll n,ll k){
if(n<k||n<0||k<0){
return 0;
}
return ((f[n]*invfact[k])%mod*invfact[n-k])%mod;
}
bool prime[10000011];
void primenumbers(ll n)
{
memset(prime, true, sizeof(prime));
for (ll p=2; p*p<=n; p++)
{
if (prime[p] == true)
{
for (ll i=p*p; i<=n; i += p)
prime[i] = false;
}
}
}
ll modI(ll a, ll m)
{
ll m0=m,y=0,x=1;
if(m==1) return 0;
while(a>1)
{
ll q=a/m;
ll t=m;
m=a%m;
a=t;
t=y;
y=x-q*y;
x=t;
}
if(x<0) x+=m0;
return x;
}
int spf[MAXN];
void sieve()
{
spf[1] = 1;
for (int i=2; i<MAXN; i++)
spf[i] = i;
for (int i=4; i<MAXN; i+=2)
spf[i] = 2;
for (int i=3; i*i<MAXN; i++)
{
if (spf[i] == i)
{
for (int j=i*i; j<MAXN; j+=i)
if (spf[j]==j)
spf[j] = i;
}
}
}
vector<int> getFactorization(int x)
{
vector<int> ret;
while (x != 1)
{
ret.push_back(spf[x]);
x = x / spf[x];
}
return ret;
}
bool isSubsetSum(vi s, int n, int sum)
{
bool subset[n + 1][sum + 1];
for (int i = 0; i <= n; i++)
subset[i][0] = true;
for (int i = 1; i <= sum; i++)
subset[0][i] = false;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= sum; j++) {
if (j < s[i - 1])
subset[i][j] = subset[i - 1][j];
if (j >= s[i - 1])
subset[i][j] = subset[i - 1][j]
|| subset[i - 1][j - s[i - 1]];
}
}
return subset[n][sum];
}
//------------------------------------------------------------------------------------
void solve(){
ll a,b,c;
cin>>a>>b>>c;
cout<<21-a-b-c;
}
int main() {
fast();
// CASE(t)
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int inf = 1001001001;
ll INF = 1001001001001001001;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define rep(i, n) FOR(i, 0, n)
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
ll MOD = 1000000007;
using P = pair<ll, ll>;
struct UnionFind{
vector<int> par;
UnionFind(int N):par(N) {
for (int i = 0; i < N; i++) par[i] = i;
}
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;
par[x] = y;
}
bool same(int x, int y) {
return find(x) == find(y);
}
};
int main() {
ll N, M;cin >> N >> M;
vector<ll> A(N), B(N);
UnionFind tree(N);
rep(i, N) cin >> A[i];
rep(i, N) cin >> B[i];
rep(i, M) {
int c, d;cin >> c >> d;
c--;d--;
tree.unite(c, d);
}
ll count[N];
rep(i, N) count[i] = 0;
rep(i, N) {
count[tree.find(i)] += B[i]-A[i];
}
bool can = true;
rep(i, N) {
if (count[i]!=0) {
can = false;
break;
}
}
if (can) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
| #include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=200005;
int n,m,k,a[N],b[N],c[N],sa[N],sb[N];
vector<int>e[N];
void dfs(int u)
{
sa[c[u]]+=a[u];
sb[c[u]]+=b[u];
for(auto v:e[u])
{
if(!c[v])
{
c[v]=c[u];
dfs(v);
}
}
}
signed main()
{
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
cin>>b[i];
for(int i=1;i<=m;i++)
{
int u,v;
cin>>u>>v;
e[u].push_back(v);
e[v].push_back(u);
}
for(int i=1;i<=n;i++)
{
if(!c[i])
{
k++;
c[i]=k;
dfs(i);
if(sa[k]!=sb[k])
{
cout<<"No"<<endl;
return 0;
}
}
}
cout<<"Yes"<<endl;
return 0;
} |
#include <math.h>
#include <assert.h>
#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>
template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& v) {
return is >> v.first >> v.second;
}
template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
for (T& i: v) {
is >> i;
}
return is;
}
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& v) {
return os << v.first << " " << v.second;
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
int n = (int) v.size();
for (int i = 0; i < n; ++i) {
os << v[i] << (i == n - 1 ? "" : " ");
}
return os;
}
template <typename X>
void in(X& x) {
std::cin >> x;
}
template <typename X, typename Y>
void in(X& x, Y& y) {
in(x); in(y);
}
template <typename X, typename Y, typename Z>
void in(X& x, Y& y, Z& z) {
in(x); in(y, z);
}
template <typename X, typename Y, typename Z, typename W>
void in(X& x, Y& y, Z& z, W& w) {
in(x); in(y, z, w);
}
template <typename T>
void out(const T H) {
std::cout << (H);
}
template <typename T1, typename... T2>
void out(const T1 H, const T2... T) {
std::cout << (H) << " "; out(T...);
}
template <typename T>
void eout(const char *s, const T H) {
std::cerr << s << "=" << H << "\n";
}
template <typename T1, typename... T2>
void eout(const char *s, const T1 H, const T2... T) {
while (*s != ',') std::cerr << *s++;
std::cerr << "=" << H << " | "; eout(++s, T...);
}
#define nl std::cout << "\n"
#ifdef LOCAL
#define err(args...) eout(#args, args)
#else
#define err(args...) 42
#endif
#define rep(i, n) for (int i = 0 ; i < (n); ++i)
#define per(i, n) for (int i = (n) - 1; i > -1; --i)
#define repr(i, l, r) for (int i = (l); i < (r); ++i)
#define sz(v) ((int) v.size())
#define all(v) (v).begin(), (v).end()
#define lla(v) (v).rbegin(), (v).rend()
#define no std::cout << "NO\n"
#define yes std::cout << "YES\n"
const int INF = 2147483647;
const long long int LNF = 9223372036854775807LL;
using ll = long long int;
using vl = std::vector<ll>;
using vi = std::vector<int>;
using vb = std::vector<bool>;
using ii = std::pair<int, int>;
using iii = std::pair< ii, int>;
using vii = std::vector<ii>;
const int N = 505050;
const int MD = 998244353;
int solve();
int main() {
std::ios_base::sync_with_stdio(0); std::cin.tie(0);
//int t; in(t); repr(tc, 1, t + 1)
solve();
return 0;
}
int f(int a) {
return (ll) a*(a+1)/2 % MD;
}
int solve() {
int a, b, c;
in(a, b, c);
err(a, b, c);
out(((ll) f(a)*f(b) % MD)*f(c) % MD);
return 0;
}
| #include<bits/stdc++.h>
#define int long long
using namespace std;
const int MOD=998244353;
signed main() {
int a,b,c;
cin>>a>>b>>c;
int A=a*(a+1)/2,B=b*(b+1)/2,C=c*(c+1)/2;
A%=MOD,B%=MOD,C%=MOD;
cout<<((A*B)%MOD*C)%MOD;
return 0;
}
|
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
//#define int long long
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PI = pair<pair<int,int>,int>;
using PL = pair<long long, long long>;
using PLL = pair<pair<long long, long long>, long long>;
using Pxy = pair<double, double>;
using Tiib = tuple<int, int, bool>;
const int INF = 1001001007;
const long long mod = 1000000007LL;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
rep(i,ar.size()-1) cout << ar[i] << " ";
cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
rep(i,ar.size()){
rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
cout << ar[i][ar[0].size()-1] << endl;
}
}
template <typename S>
bool range(S a, S b, S x){
return (a <= x && x < b);
}
void yes(){
cout << "Yes" << endl;
}
void no (){
cout << "No" << endl;
}
ll cel (ll a, ll b){
if (a % b == 0) return a / b;
else return a / b + 1;
}
ll gcds(ll a, ll b){
ll c = a % b;
while (c != 0){
a = b;
b = c;
c = a % b;
}
return b;
}
int main(){
int n, mm; cin >> n >> mm;
int m = abs(mm);
if (n == 1) {cout << 1 << " " << 2 << endl; return 0;}
if (n - m <= 1 || mm < 0) {cout << -1 << endl; return 0;}
vector<P> ans;
if (mm > 0){
ans.emplace_back(P(1,1 + 2 * (m+1)));
rep(i,m){
ans.emplace_back(P(2+i*2,3+i*2));
}
ans.emplace_back(P(2+m*2,4+m*2));
rep(i,n-m-2){
ans.emplace_back(P(3 + 2*(m+1) + i*2, 4 + 2*(m+1) + i*2));
}
rep(i,n) cout << ans[i].first << " " << ans[i].second << endl;
}
else {
rep(i,n){
cout << 1 + 2 * i << " " << 2 + 2 * i << endl;
}
}
} | #include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ch() getchar()
#define pc(x) putchar(x)
template<typename T>inline void read(T&x){
int f;char c;
for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;
for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;
}
template<typename T>inline void write(T x){
static char q[64];int cnt=0;
if(!x)pc('0');if(x<0)pc('-'),x=-x;
while(x)q[cnt++]=x%10+'0',x/=10;
while(cnt--)pc(q[cnt]);
}
int main(){
int n,m;read(n),read(m);
if(n==1&&m==0)puts("1 2");
else if(m>n-2||m<0)puts("-1");
else if(m==0){
for(int i=1;i<=n;++i)
write(i),pc(' '),write(i+n),pc('\n');
}
else{
const int Base=300000;
for(int i=1;i<=m+1;++i)
write(i*2-1+Base),pc(' '),write(i*2+Base),pc('\n');
int l=0,r=(m+1)*2+1;
for(int i=m+2;i<=n;++i)
write((l--)+Base),pc(' '),write((r++)+Base),pc('\n');
}
return 0;
}
|
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define eps (double)(1e-9)
#define pi (double) acos(-1)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
#define P pair<ll, ll>
random_device rnd;
mt19937 mt(rnd());
uniform_int_distribution<> rand100(0, mod);
int rand_int(int l, int u){
return l + rand100(mt) % (u-l+1);
}
struct edge{
ll to, cost, cnt;
};
using Graph = vector<vector<edge>>;
Graph G(30*30);
vector<ll> prv;
vector<ll> dis;
vector<string> anss;
void dijkstra(int s){
int N = G.size();
priority_queue<P, vector<P>, greater<P>> pq;
dis.resize(N);
prv.resize(N);
rep(i, N)dis[i] = inf;
rep(i, N)prv[i] = -1;
dis[s] = 0;
pq.emplace(dis[s], s);
while(!pq.empty()){
P p = pq.top();
pq.pop();
int v = p.second;
if(dis[v] < p.first)continue;
for(auto &e : G[v]){
ll now = e.cost;
if(e.cnt != -1)now = (e.cost + e.cnt - 1) / e.cnt;
if(dis[e.to] > dis[v] + now){
dis[e.to] = dis[v] + now;
prv[e.to] = v;
pq.emplace(dis[e.to], e.to);
}
}
}
}
map<pair<int, int>, string> mp;
string get_path(int t) {
vector<int> path;
for (int cur = t; cur != -1; cur = prv[cur]) {
path.push_back(cur);
}
reverse(path.begin(), path.end());
string ret;
REP(i, path.size()-1){
if(path[i]-path[i-1] == 1)ret += "R";
else if(path[i]-path[i-1] == -1)ret += "L";
else if(path[i]-path[i-1] == 30)ret += "D";
else if(path[i]-path[i-1] == -30)ret += "U";
else ret += mp[{path[i-1], path[i]}];
}
return ret;
}
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
void solve(){
rep(x, 30)rep(y, 30){
rep(i, 4){
int nx = x + dx[i];
int ny = y + dy[i];
if(nx < 0 || nx >= 30 || ny < 0 || ny >= 30)continue;
G[x*30+y].push_back({nx*30+ny, 3000, -1});
}
}
rep(_, 1000){
int si, sj, ti, tj;
cin >> si >> sj >> ti >> tj;
dijkstra(si*30+sj);
string path = get_path(ti*30+tj);
cout << get_path(ti*30+tj) << endl;
//anss.push_back(get_path(ti*30+tj));
int ans;
cin >> ans;
//double now; cin >> now;
int x = si, y = sj;
int s = path.size();
rep(i, path.size()){
int nx = x, ny = y;
if(path[i] == 'U')nx--;
if(path[i] == 'D')nx++;
if(path[i] == 'L')ny--;
if(path[i] == 'R')ny++;
int idx = -1;
rep(j, G[x*30+y].size())if(G[x*30+y][j].to == nx*30+ny)idx = j;
if(G[x*30+y][idx].cnt == -1){
G[x*30+y][idx].cnt = 0;
G[x*30+y][idx].cost = 0;
}
assert(s <= 60);
G[x*30+y][idx].cnt += max(0, 3601 - s*s);
G[x*30+y][idx].cost += ans/s * max(0, 3601 - s*s);
x = nx; y = ny;
}
}
}
int main(){
solve();
//for(auto s : anss)cout << s << endl;
} | #include <bits/stdc++.h>
using namespace std;
//---------------- 定数 ----------------
// [X_MIN, X_MAX], [Y_MIN, Y_MAX]
#define X_MIN 0
#define X_MAX 29
#define Y_MIN 0
#define Y_MAX 29
#define QUERY 1000
// -------- util function --------
int rand_int(){
static unsigned long long x=123456789, y=362436069, z=521288629, w=88675123;
unsigned long long t = (x^(x << 11));
x=y; y=z; z=w;
return (w=(w^(w>>19))^(t^(t>>8)));
}
// -------------------------------
// 座標(y, x)を扱うクラス
struct Point{
int x, y;
//Point(int y, int x): x(x), y(y);
};
struct Query{
Point start, end;
string ans;
// クエリを開始する処理
void init(){
cin >> start.y >> start.x >> end.y >> end.x;
}
// クエリの答えを出力する処理
void submit(){
int point;
cout << ans << endl;
cin >> point;
return;
}
void solve(){
Point now = start;
int flag = -1;
if(flag == -1) flag = rand_int() % 2;
while(now.y != end.y || now.x != end.x){
if(now.y == end.y) flag = 1;
if(now.x == end.x) flag = 0;
if(flag == 0){
if(now.y < end.y){
ans.push_back('D');
now.y++;
}else{
ans.push_back('U');
now.y--;
}
}else{
if(now.x < end.x){
ans.push_back('R');
now.x++;
}else{
ans.push_back('L');
now.x--;
}
}
}
}
};
int main(){
for(int q = 0;q < QUERY;q++){
Query query;
query.init();
query.solve();
query.submit();
}
return 0;
}
|
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set> // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric> // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip> // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>
#include <random>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main()
{
ll n;
cin >> n;
vector<ll> a(n);
vector<ll> b(n);
vector<ll> p(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
rep(i, n) cin >> p[i];
rep(i, n) p[i]--;
vector<ll> q(n);
rep(i, n)
{
q[p[i]] = i;
}
vector<pair<ll, ll>> answer;
vector<pair<ll, ll>> people;
rep(i, n) people.push_back(pair<ll, ll>{a[i], i});
sort(people.begin(), people.end());
rep(i, n)
{
if (people[i].second != p[people[i].second])
{
// 注目してる人の番号(Aさん)
ll person = people[i].second;
// Aさんが持ってる荷物の番号
ll nimotsu = p[person];
// 「Aさんが持つべき荷物」を持ってる人(Bさん)の番号
ll aite = q[person];
// Bさんが持っている荷物の番号
ll nimotsuB = p[aite];
if (a[person] <= b[nimotsu])
{
cout << -1 << endl;
return 0;
}
// AさんとBさんの荷物を入れ替える
answer.push_back(pair<ll, ll>{person, aite});
ll temp = p[person]; // ==nimotsu
p[person] = p[aite]; // ==person
p[aite] = temp; // ==nimotsu
ll temp2 = q[nimotsu];
q[nimotsu] = q[nimotsuB];
q[nimotsuB] = temp2;
}
}
cout << answer.size() << endl;
for (pair<ll, ll> z : answer)
{
cout << z.first + 1 << ' ' << z.second + 1 << endl;
}
return 0;
} |
//#include <atcoder/maxflow.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <iterator>
#include <random>
#include <chrono>
#include <complex>
#include <bitset>
#include <fstream>
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
typedef long long ll;
//using namespace __gnu_pbds;
//using namespace atcoder;
using namespace std;
const ll modd = (1000LL * 1000LL * 1000LL + 7LL);
//const ll modd = 998244353;
ll binary_search(function<bool(ll)> func, ll start, ll end) {
/* func:int ->bool
returns smallest int x where func(x) evaluates to true, searches in [start,end), it is assumed the values are false, .. , false, true ...
*/
if (end <= start) { return end; } // has to be here, otherwise func(end-1) in next line could be a problem
if (!func(end-1)) { return end; }
while (end-start>1) {
ll mid = (start+end)/2;
if (func(mid)) { end = mid; } else { start = mid; }
}
if (func(start)) { return start; } else { return end; }
};
int main(int argc, char *argv[]) {
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<int> rand_gen(0, modd); // rand_gen(rng) gets the rand no
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.precision(12);
// readint(test_cases);
int test_cases = 1;
forr(t, 1, test_cases) {
readll(a); readll(b); readll(c); readll(d);
if (b>=c*d) {
cout << -1 << endl;
continue;
}
cout << binary_search([a,b,c,d](ll x) {
return a+b*x<=d*c*x;
}, 0, 10+a/(d*c-b)) << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }
#define ll long long
vector<int>read_array(int n){
vector<int>a(n);
for(int i = 0; i < n; i++)cin >> a[i];
return a;
}
void test_case(){
int n;
cin >> n;
int tax = (double)1.08 * n;
if(tax < 206){
cout << "Yay!" << endl;
}else if(tax == 206){
cout << "so-so" << endl;
}else{
cout << ":(" << endl;
}
}
int main(){
test_case();
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
void solveA() {
int n;
cin>>n;
int tax=1.08*n;
if(tax<206) cout<<"Yay!"<<endl;
else if(tax==206) cout<<"so-so"<<endl;
else cout<<":("<<endl;
}
ll Nat(ll n) {
return (n*(n+1))/2;
}
void solveB() {
ll n;
cin>>n;
ll z=n*2;
ll sq=(ll)sqrt(z);
while(Nat(sq)<n) {
sq++;
}
cout<<sq<<endl;
}
void solveC() {
int n;
cin>>n;
unordered_map<ll,ll> mp;
ll val,ans=0;
for(int i=1; i<=n; i++) {
cin>>val;
mp[val]++;
ans+=(i-mp[val]);
}
cout<<ans<<endl;
}
int main() {
solveA();
return 0;
}
|
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <random>
#include <chrono>
/* #include <atcoder/all> */
/* using namespace atcoder; */
using namespace std;
void debug_out(){ cout << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cout << H << " ";
debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
/* const ll MOD = 998244353; */
const ll INF = (1<<30)-1;
const ll INFLL = 1ll<<60;
const double PI = acos(-1);
struct INIT { INIT(){
cin.tie(0); ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
}}INIT;
signed main() {
int sx, sy, gx, gy;
cin >> sx >> sy >> gx >> gy;
if(sx == gx) cout << sx << "\n";
else{
int x = gx-sx;
int y = sy+gy;
ld t = (ld)x/y;
cout << t*sy+sx << "\n";
}
return 0;
}
| #include <stdio.h>
int main()
{
double sx,sy,gx,gy;
double a, b, ans;
scanf("%lf %lf %lf %lf", &sx, &sy, &gx, &gy);
a = -((gy + sy) / (gx - sx));
b = sy - a * sx;
ans = -b / a;
printf("%lf", ans);
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define pll pair<ll,ll>
#define vll vector<long long>
#define f first
#define s second
long long mod = 1e9+7;
typedef vector<map<char,int>> vmci;
int diry[] = {-1,-1,-1,0,0,1,1,1};
int dirx[] = {-1,0,1,-1,1,-1,0,1};
ll pow(ll x, ll y, ll p) {
ll res = 1;
x %= p;
if(x == 0) {
return 0;
}
while(y > 0) {
if(y & 1) {
res = (res * x) % p;
}
y >>= 1;
x = (x * x) % p;
}
return res;
}
long long int power(int base, int exp)
{
if (exp == 0)
return 1;
else if (exp == 1)
return base;
else
{
long long int calc;
if (exp % 2 == 0)
{
calc = power(base, exp/2);
calc *= calc;
}
else
{
calc = base*power(base, exp-1);
}
return calc;
}
}
void seg_sieve(ll max,ll arr[]){
ll i,j;
for(i=2;i*i<=max;i++){
if(arr[i]==0){
for(j=i*i;j<=max;j+=i)
arr[j]=1;
}
}
}
float distance(int x,int y,int a,int b){
return sqrt(pow(x-a,2) + pow(y-b,2));
}
struct noob{
int l,r,ind;
noob(){
l=-1,r=-1,ind=-1;
}
noob(int a,int b,int c){
l=a,r=b,ind=c;
}
};
bool comp1(noob &a,noob &b){
return a.l<b.l;
}
bool comp2(pll &a,pll &b){
return a.first>b.first;
}
bool isPrime(ll n)
{
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (ll i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t=1;
// cin>>t;
int ulti=1;
while(t--){
int n,x; cin>>n>>x;
string arr; cin>>arr;
for(int i=0;i<n;i++){
if(arr[i]=='x' and x>0) x--;
else if(arr[i]=='o') x++;
}
cout<<x;
}
} | #include <iostream>
#include <string.h>
using namespace std;
int main()
{
int size, intial = 0;
char s;
cin >> size >> intial;
for (int i = 0;i < size;i++)
{
cin >> s;
if (s == 'o')
{
intial++;
}
else if (s == 'x')
{
if (intial != 0)
{
intial--;
}
}
}
cout << intial << endl;
return 0;
}
|
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define LD long double
#define ST string
#define BS bitset
#define PA pair<LL,LL>
#define VE vector
#define VL VE<LL>
#define VP VE<PA>
#define VVL VE<VL>
#define VVVL VE<VVL>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define BPL __builtin_popcountll
#define FOR(i,a,n) for(i=a;i<n;++i)
#define FORR(i,a,n) for(i=n-1;i>=a;--i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) FORR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define UBn(a,n) upper_bound(ALL(a),n)-a.begin()
#define LB(a,n) *lower_bound(ALL(a),n)
#define LBn(a,n) lower_bound(ALL(a),n)-a.begin()
#define INF 1000000000000000003
#define PI 3.14159265358979323846264338327950288
//#define MOD 1000000007
#define MOD 998244353
#define ERR 1e-10
#define coutl cout<<fixed<<setprecision(15)
#define FAST cin.tie(0);ios::sync_with_stdio(false)
void Yn(LL a){if(a)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void YN(LL a){if(a)cout<<"YES"<<endl;else cout<<"NO"<<endl;}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL dig(LL n){LL ret=0;while(n)n/=10,++ret;return ret;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
LL cmod(LL a,LL m){if(a%m<0)return a%m+abs(m);else return a%m;}
LL DIV(LL a,LL d,LL m){LL l=m,x=1,y=0,k;while(l){k=d/l;d-=k*l;swap(l,d);x-=k*y;swap(x,y);}return cmod(a*cmod(x,m),m);}
LL POW(LL a,LL n,LL m){LL ans=1;while(n>0){if(n&1)ans=ans*a%m;a=a*a%m;n>>=1;}return ans;}
VL fact,finv,inv;
void comi(LL n){LL i;fact.resize(max(2LL,n+1));finv.resize(max(2LL,n+1));inv.resize(max(2LL,n+1));fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[0]=inv[1]=1;FOR(i,2,n+1){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(PA a,PA b){if(a.SE!=b.SE)return a.SE<b.SE;return a.FI<b.FI;}
template<typename T>bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>void vout(VE<T> &v){LL i;rep(i,v.size()){cout<<v[i];if(i<v.size()-1)cout<<" ";}cout<<endl;}
template<typename T>void v2out(VE<VE<T>> &v){for(auto a:v)vout(a);}
VL dvsr(LL n){VL ret;for(LL i=1;i*i<=n;++i){if(n%i==0){ret.PB(i);if(i*i!=n)ret.PB(n/i);}}SORT(ret);return ret;}
int main(){
FAST;
LL i,ans=0,N;
cin>>N;
VL v=dvsr(N);
for(LL z:v){
if(z&1)ans+=2;
//if(z%2==0&&)
}
cout<<ans<<endl;
}
| #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define _USE_MATH_DEFINES
#define _MATH_DEFINES_DEFINED
using namespace __gnu_pbds;
using namespace std;
template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define ll long long int
#define pb push_back
#define eb emplace_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
typedef vector<vector<ll>> vvll;
#define M_PI 3.14159265358979323846
#define br "\n"
#define ff first
#define ss second
#define debug(a...) cout<<#a<<": ";for(auto it:a)cout<<it<<" ";cout<<endl;
#define working cout << "Working till here" << endl;
#define MAXIM 1000101
const ll MAX = 2e5 + 1;
ll mod = 1e9 + 7;
void solve(){
ll a,b;
cin >> a >> b;
if(a > b){
ll s = 0;
rep(i,1,a + 1){
cout << i << " ";
s += i;
}
rep(i,1,b){
cout << -1*i << " ";
s -= i;
}
cout << -1*s << " ";
}
else{
ll s = 0;
rep(i,1,b + 1){
cout << -1*i << " ";
s -= i;
}
rep(i,1,a){
cout << i << " ";
s += i;
}
cout << -1*s << " ";
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
ll t = 1;
// cin >> t;
rep(i,0,t){
// cout << "Case #" << i + 1 << ": ";
solve();
// test();
}
} |
#include<iostream>
#include<bits/stdc++.h>
#define m_p make_pair
#define fi first
#define se second
#define pb push_back
typedef long long ll;
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define crap ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;
#define INF 1000000
#define vll vector<ll>
const int M = 1e9+7;
ll fastpower(ll x,ll n,ll M)
{
if(n==0)
return 1;
else if(n%2 == 0) //n is even
return fastpower((x*x)%M,n/2,M);
else //n is odd
return (x*fastpower((x*x)%M,(n-1)/2,M))%M;
}
ll GCD(ll A, ll B) {
if(B==0)
return A;
else
return GCD(B, A % B);
}
bool vowl(char c)
{
return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';
}
ll modInverse(ll A,ll M)// when M is prime
{
return fastpower(A,M-2,M);
}
void sieve(ll N) {
bool isPrime[N+1];
for(ll i = 0; i <= N;++i) {
isPrime[i] = true;
}
isPrime[0] = false;
isPrime[1] = false;
for(ll i = 2; i * i <= N; ++i) {
if(isPrime[i] == true) { //Mark all the multiples of i as composite numbers
for(ll j = i * i; j <= N ;j += i)
isPrime[j] = false;
}
}
}
vector<ll> factorize(ll n) {
vector<ll> res;
for (ll i = 2; i * i <= n; ++i) {
while (n % i == 0) {
res.push_back(i);
n /= i;
}
}
if (n != 1) {
res.push_back(n);
}
return res;
}
int main()
{
crap;
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ll n;
cin>>n;
string s[n];
set<string> d;
string ans;int flag=0;
f(i,n)
{
cin>>s[i];
if(s[i][0]!='!')d.insert(s[i]);
}
f(i,n)
{
if(s[i][0]=='!')
{
string y=s[i].substr(1);
auto it=d.find(y);
if(it!=d.end())
{
ans=y;flag=1;
}
}
}
if(flag)
cout<<ans<<endl;
else
cout<<"satisfiable"<<endl;
return 0;
} | #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>
#include<map>
#include<cassert>
using namespace std;
#define ll long long
#define reps(i, a, b) for(int i = a; i < b; i++)
#define rreps(i, a, b) for(int i = a-1; i >= b; i--)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) rreps(i, n, 0)
#define P pair<int, int>
#define vec vector<int>
#define mat vector<vector<int> >
const ll mod = 1000000007;
const int INF = 1001001001;
int main(){
int n;
cin >> n;
vec a(100001);
a[1] = 1;
reps(i, 2, 100001){
for (int j = 2; j * j <= i; j++){
if(i % j == 0){
a[i] = a[i/j] + 1;
break;
}
}
if(a[i] == 0){
a[i] = 2;
}
}
reps(i, 1, n+1){
cout << a[i] << " ";
}cout << endl;
} |
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int A[N];
int main()
{
int n;
cin>>n;
for(int i=0; i<n; i++)
cin>>A[i];
int ans = 1<<30;
for(int bit=0; bit< (1<<(n-1)); bit++)
{
int o = 0, x = 0;
for(int j=0; j<n; j++)
{
o |= A[j];
if(bit>>j & 1 || j == n-1)
x ^= o, o = 0;
}
ans = min(ans, x);
}
cout<< ans <<endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second
#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x) cerr << "[" << #x << "]: " << x << "\n";
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using pl = pair<ll, ll>;
ld const PI = 4*atan((ld)1);
template<int MOD = 998'244'353>
struct Mint
{
int val;
Mint() : val(0) {}
Mint(ll _val) : val((int)(_val % MOD)) { if (val < 0) val += MOD; }
Mint& operator+= (const Mint &rhs) { val += rhs.val; if (val >= MOD) val -= MOD; return *this; }
Mint& operator-= (const Mint &rhs) { val -= rhs.val; if (val < 0) val += MOD; return *this; }
Mint& operator*= (const Mint &rhs) { val = (int)((ll) val * rhs.val % MOD); return *this; }
friend Mint fpow(Mint x, ll y)
{
Mint res = 1;
for (; y > 0; y >>= 1, x *= x)
{
if (y & 1)
res *= x;
}
return res;
}
friend Mint inverse(Mint x) { return fpow(x, MOD-2); }
Mint& operator/= (const Mint &rhs) { return *this *= inverse(rhs); }
friend Mint operator+ (Mint a, const Mint &b) { return a += b; }
friend Mint operator- (Mint a, const Mint &b) { return a -= b; }
friend Mint operator- (Mint a) { return 0 - a; }
friend Mint operator* (Mint a, const Mint &b) { return a *= b; }
friend Mint operator/ (Mint a, const Mint &b) { return a /= b; }
friend ostream& operator<< (ostream &os, const Mint &a) { return os << a.val; }
friend bool operator== (const Mint &a, const Mint &b) { return a.val == b.val; }
friend bool operator!= (const Mint &a, const Mint &b) { return a.val != b.val; }
};
const int MAX = 107;
int n;
int w[MAX];
Mint<> dp[MAX][MAX * MAX]; //dp[a][b], pick a items such that the weigh sum is exactly b
Mint<> fact[MAX];
int main()
{
fastio;
fact[0] = 1;
for (int i = 1; i < MAX; ++i)
fact[i] = i * fact[i-1];
cin >> n;
int sum = 0;
for (int i = 0; i < n; ++i)
cin >> w[i], sum += w[i];
if (sum & 1)
{
cout << 0 << '\n';
return 0;
}
dp[0][0] = 1;
for (int i = 0; i < n; ++i)
{
for (int a = n-1; a >= 0; --a)
{
for (int b = 10000; b >= 0; --b)
{
dp[a+1][b + w[i]] += dp[a][b];
}
}
}
Mint<> res = 0;
for (int i = 1; i <= n; ++i)
{
res += dp[i][sum/2] * fact[i] * fact[n-i];
}
cout << res << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
main()
{
int a[3];
cin>>a[0]>>a[1]>>a[2];
sort(a,a+3);
cout<<(a[2]+a[1]);
}
| #include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
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 ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;
const long long MOD = 1000000007;
int main() {
int a, b, c; cin >> a >> b >> c;
vector<int> v;
v.push_back(a);
v.push_back(b);
v.push_back(c);
sort(ALL(v));
cout << v[1] + v[2] << endl;
return 0;
} |
#define rep(i, n) for (int i = 0; i < n; i++)
#define All(a) a.begin(), a.end()
#define us unordered_set
#define eb emplace_back
#define pb push_back
#define ll long long
#define vt vector
#define mod 1000000007
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vt<vt<int>> c(n, vt<int>(n));
rep(i, n) rep(j, n) cin >> c[i][j];
string ans = "Yes";
int min_c = mod, min_i = 0;
rep(i, n) {
if (c[i][0] < min_c) {
min_i = i;
min_c = c[i][0];
}
}
for (int i = 1; i < n; i++) {
int dif = c[i][0] - c[i - 1][0];
for (int j = 1; j < n; j++)
if (c[i][j] - c[i - 1][j] != dif) ans = "No";
}
cout << ans << endl;
if (ans == "No") return 0;
rep(i, n) cout << c[i][0] - min_c << ' ';
cout << endl;
rep(i, n) cout << c[min_i][i] << ' ';
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("O3")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
const ll INF = (1LL<<60);
template<class T> bool chmin(T &a, const T b){
if(a > b) {a = b; return true;}
else return false;
}
template<class T> bool chmax(T &a, const T b){
if(a < b) {a = b; return true;}
else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
if(!v.empty()){
for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
std::cout<<v.back();
}
if(endline) std::cout<<std::endl;
}
void no(){
cout<<"No"<<endl;
exit(0);
}
void yes(vec &a, vec &b){
cout<<"Yes"<<endl;
my_printv(a);
my_printv(b);
exit(0);
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin>>N;
if(N == 1){
cin>>A;
vec a(1, A), b(1, 0);
yes(a, b);
}
mat c(N, vec(N));
rep(i, N) rep(j, N) cin>>c[i][j];
vec a(N), b(N);
rep(i, N) a[i] = c[i][0];
b[0] = 0;
reps(j, 1, N){
b[j] = c[0][j] - c[0][0];
rep(i, N) {
if (b[j] != c[i][j] - c[i][0]) no();
}
}
ll minus = *min_element(ALL(b));
rep(j, N) b[j] -= minus;
minus = *min_element(ALL(a));
rep(i, N) a[i] -= minus;
ll d = c[0][0] - (a[0] + b[0]);
if(d < 0) no();
else {
rep(i, N) a[i] += d;
yes(a, b);
}
} |
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <algorithm>
using namespace std;
int main() {
int n,m,q;
cin>>n>>m>>q;
vector<pair<int,int>> cargos_base;
for(int i=0;i<n;i++){
int buf_w,buf_v;
cin>>buf_w>>buf_v;
std::pair<int,int> p = std::make_pair(buf_v,buf_w);
cargos_base.push_back(p);
}
sort(cargos_base.begin(),cargos_base.end());
vector<int> allBoxes;
for(int i=0;i<m;i++){
int buf_x;
cin>>buf_x;
allBoxes.push_back(buf_x);
}
for(int iq=0;iq<q;iq++){
int l,r;
cin>>l>>r;
vector<int> boxes;
//cout<<"usable : ";
for(int i=0;i<l-1;i++){
boxes.push_back(allBoxes[i]);
//cout<<allBoxes[i]<<" ";
}
for(int i=r;i<m;i++){
boxes.push_back(allBoxes[i]);
//cout<<allBoxes[i]<<" ";
}
sort(boxes.begin(),boxes.end());
vector<pair<int,int>> cargos(cargos_base);
int shipped = 0;
while(!boxes.empty() && !cargos.empty()){
pair<int,int> cargo = cargos.back();
cargos.pop_back();
int value = cargo.first;
int weight = cargo.second;
for(auto ibox=boxes.begin();ibox!=boxes.end();ibox++){
int size = *ibox;
if(weight<=size){
shipped+=value;
boxes.erase(ibox);
break;
}
}
}
cout<<shipped<<endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
int main()
{
FAST/**/
ll n,m,q;
cin>>n>>m>>q;
pii arr[n];
rep(n)
cin>>arr[i].ff>>arr[i].ss, swap(arr[i].ff, arr[i].ss);
sort(arr, arr+n);
ll lim[m];
rep(m)
cin>>lim[i];
rep(q)
{
ll l,r;
cin>>l>>r;
ll m1 = m - (r-l+1);
multiset<ll> box;
for(ll i=0;i<m;i++)
if(i<l-1 || i>=r)
box.insert(lim[i]);
ll ans = 0;
for(ll i=n-1;i>-1;i--)
{
auto it = box.lower_bound(arr[i].ss);
if(it == box.end())
continue;
ans+=arr[i].ff;
box.erase(it);
}
cout<<ans<<'\n';
}
return 0;
}
|
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
int n;
std::cin >> n;
std::vector<int> a(n);
for (int i = 0; i < n; ++i) std::cin >> a[i];
if (n % 2 == 1) {
std::cout << "Second\n";
} else {
std::sort(a.begin(), a.end());
bool win = false;
for (int i = 0; i < n; i += 2) win |= a[i] != a[i + 1];
std::cout << (win ? "First" : "Second") << "\n";
}
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
const long long int MOD = 998244353;
void solve() {
int n; cin >> n;
vector<int> a(n);
long long int sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
if (sum % 2) {
cout << 0;
return;
}
vector<long long int> f(n + 1, 1);
vector<vector<long long int>> dp(sum + 1, vector<long long int>(n + 1, 0));
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
f[i] = f[i - 1] * i % MOD;
for (int i = 0; i < n; i++) {
for (int j = n; j > 0; j--) {
for (int k = sum; k >= a[i]; k--) {
dp[k][j] += dp[k - a[i]][j - 1];
dp[k][j] %= MOD;
}
}
}
long long int ans = 0;
for (int i = 0; i <= n; i++) {
ans += dp[sum / 2][i] * f[i] % MOD * f[n - i] % MOD;
ans %= MOD;
}
cout << ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
} |
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n ; i++)
int main(){
int a,b,c;
cin >> a >> b >> c;
int min = a;
if(b < min) min = b;
if(c < min) min = c;
cout << a + b + c - min << endl;
}
| #include<bits/stdc++.h>
using namespace std;
int main()
{
int a[4] = {0};
for(int i=0;i<3;i++) cin >> a[i];
sort(a+0,a+3);
cout << a[2] + a[1];
} |
/*
Created by: Amit Kumar at 22:29 on 16 Mar 21
*/
#include <bits/stdc++.h>
#ifdef LOCAL
#include "debug.h"
#else
#define db(...)
#endif
using namespace std;
#define ll long long
#define mod 1000000007
#define S(x, n) memset(x, n, sizeof(x));
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define NIL -1
const int MAXN = 1e5 + 1;
long long power(long long x, long long y, long long md)
{
long long res = 1;
x = x % md;
while (y > 0)
{
if (y & 1)
res = (res * x) % md;
y = y >> 1;
x = (x * x) % md;
}
return res;
}
void solve()
{
int n;
cin >> n;
string t;
cin >> t;
string s;
cin >> s;
// true for Takahasi
vector<vector<bool>> dp(n + 1, vector<bool>(7, 0));
dp[n][0] = true;
for (int i = n - 1; i >= 0; i--)
{
if (s[i] == 'A')
{
for (int j = 0; j < 7; j++)
{
dp[i][j] = dp[i + 1][(j * 10) % 7] && dp[i + 1][((j * 10) + t[i] - '0') % 7];
}
}
else
{
for (int j = 0; j < 7; j++)
{
dp[i][j] = dp[i + 1][(j * 10) % 7] || dp[i + 1][((j * 10) + t[i] - '0') % 7];
}
}
}
db(dp);
if (dp[0][0])
cout << "Takahashi\n";
else
cout << "Aoki\n";
}
int main()
{
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
auto started = std::chrono::high_resolution_clock::now();
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
t = 1;
//cin >> t;
for (int I = 1; I <= t; I++)
{
#ifdef LOCAL
cerr << "TestCase " << I << "\n";
#endif
solve();
}
#ifdef LOCAL
auto done = std::chrono::high_resolution_clock::now();
cerr << "Time = " << std::chrono::duration_cast<std::chrono::milliseconds>(done - started).count() << " ms\n";
#endif
return 0;
} | /*
Author: Nguyen Tan Bao
Status:
Idea:
*/
#include <bits/stdc++.h>
#define FI first
#define SE second
#define ALL(a) a.begin(), a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define TRAV(x, a) for (auto &x : a)
using namespace std;
using ll = long long; using ld = double;
using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<ld, ld>;
using cd = complex<ld>; using vcd = vector<cd>;
using vi = vector<int>; using vl = vector<ll>;
using vd = vector<ld>; using vs = vector<string>;
using vpi = vector<pi>; using vpl = vector<pl>; using vpd = vector<pd>; // vector<pair>
template<class T> using min_pq = priority_queue<T, vector<T>, greater<T> >;
template<class T> inline int ckmin(T& a, const T& val) { return val < a ? a = val, 1 : 0; }
template<class T> inline int ckmax(T& a, const T& val) { return a < val ? a = val, 1 : 0; }
template<class T> void remDup(vector<T>& v) { sort(ALL(v)); v.erase(unique(ALL(v)), end(v)); }
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { return x == 0 ? 0 : 31-__builtin_clz(x); } // floor(log2(x))
constexpr int p2(int x) { return 1<<x; }
constexpr int msk2(int x) { return p2(x)-1; }
ll ceilDiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
ll floorDiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); } // divide a by b rounded down
void setPrec(int x) { cout << fixed << setprecision(x); }
// TO_STRING
#define ts to_string
string ts(char c) { return string(1, c); }
string ts(const char* s) { return (string) s; }
string ts(string s) { return s; }
string ts(bool b) { return ts((int)b); }
template<class T> string ts(complex<T> c) { stringstream ss; ss << c; return ss.str(); }
template<class T> using V = vector<T>;
string ts(V<bool> v) {string res = "{"; FOR(i,0,SZ(v)-1) res += char('0'+v[i]); res += "}"; return res; }
template<size_t sz> string ts(bitset<sz> b) { string res = ""; FOR(i,0,SZ(b)-1) res += char('0'+b[i]); return res; }
template<class T, class U> string ts(pair<T,U> p);
template<class T> string ts(T v) { // containers with begin(), end()
bool fst = 1; string res = "";
for (const auto& x: v) { if (!fst) res += " "; fst = 0; res += ts(x); }
return res;
}
template<class T, class U> string ts(pair<T,U> p) { return "("+ts(p.FI)+", "+ts(p.SE)+")"; }
// OUTPUT
template<class T> void pr(T x) { cout << ts(x); }
template<class T, class ...U> void pr(const T& t, const U&... u) { pr(t); pr(u...); }
void ps() { pr("\n"); } // print w/ spaces
template<class T, class ...U> void ps(const T& t, const U&... u) { pr(t); if (sizeof...(u)) pr(" "); ps(u...); }
// DEBUG
void DBG() { cerr << "]" << endl; }
template<class T, class ...U> void DBG(const T& t, const U&... u) { cerr << ts(t); if (sizeof...(u)) cerr << ", "; DBG(u...); }
#define dbg(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#define chk(...) if (!(__VA_ARGS__)) cerr << "Line(" << __LINE__ << ") -> function(" \
<< __FUNCTION__ << ") -> CHK FAILED: (" << #__VA_ARGS__ << ")" << "\n", exit(0);
const ld PI = acos(-1.0);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
const ld EPS = 1e-9;
const ll MODBASE = 1000000007LL;
const int INF = 0x3f3f3f3f;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
int n;
cin >> n;
int l = 1, r = 1000;
FOR(i,1,n) {
int u;
cin >> u;
ckmax(l, u);
}
FOR(i,1,n) {
int u;
cin >> u;
ckmin(r, u);
}
// dbg(l, r);
if (l > r) cout << 0;
else cout << r-l+1;
return 0;
}
|
#include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#include <bitset>
using namespace std;
#define rep(i,n,m) for(ll (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll mod = 998244353;
void bitadd(ll a,ll w, vector<ll>& bit){
a += 1;
ll x = a;
if (a == 0){
exit(1);
}
while (x <= (bit.size()-1)){
bit[x] = (bit[x] + w) % mod;
x += (x & (-x));
}
return;
}
ll bitsum(ll a,vector<ll>& bit){
a += 1;
ll ret = 0;
ll x = a;
if (a == 0){
exit(1);
}
while (x > 0){
ret = (ret + bit[x]) % mod;
x -= (x & (-x));
}
return ret;
}
int main(){
ll N,K;
cin >> N >> K;
vector<vector<ll>> dp(N-K+5,vector<ll> (2*(N-K+5)));
bitadd(min(2*(N-K+3),K), 1 ,dp[0]);
rep(i,1,N-K+1){
rep(j,0,i){
ll now = ((bitsum(2*(N-K+3),dp[j]) - bitsum((i-j-1),dp[j])) + mod) % mod;
bitadd(min((i-j)*2,2*(N-K+3)) , now , dp[i]);
}
}
cout << (bitsum(2*(N-K+3),dp[N-K]) % mod) << endl;
} | #include <iostream>
const int M = 998244353;
int dp[3005][3005];
int main()
{
int n, m, i, j, k;
while (scanf("%d%d", &n, &m) == 2)
{
// dp[i][j] different ways of collecting total value j with i things
// dp[i][j] = dp[i][j*2] + dp[i-1][j*2-1*2] + ... + dp[0][j*2-i*2]
dp[0][0] = 1;
for (i=1; i<=n; i++)
{
dp[i][0] = 0;
for (j=i; j>=1; j--)
{
// i-k >= 2j-2k
// => k >= 2j-i
k = j+j - i;
if (k < 0)
{
k = 0;
}
dp[i][j] = dp[i-k][j+j-k-k];
if (j-2 >= 0)
{
dp[i][j] = (dp[i][j] + dp[i-1][j-2]) % M;
}
}
}
printf("%d\n", (dp[n][m]+M-dp[n-1][m-2])%M);
}
return 0;
} |
#include <iostream>
#include <utility>
#include <algorithm>
#include <unordered_map>
using namespace std;
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
unordered_map<int, pair<int, int>> dp;
int N, K;
cin >> N >> K;
while (K > 0)
{
if (dp.find(N) != dp.end())
N = dp[N].first - dp[N].second;
else
{
string &&tmp = to_string(N);
sort(tmp.begin(), tmp.end());
int &&small = stoi(tmp);
reverse(tmp.begin(), tmp.end());
int &&big = stoi(tmp);
dp[N] = pair<int, int>(big, small);
N = big - small;
if (N == 0)
break;
}
K--;
}
cout << N << '\n';
return 0;
} | #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <cassert>
#include <stack>
#include <numeric>
#include <iomanip>
#include <limits>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<ll, ll> Pll;
typedef std::pair<double, double> Pdd;
#define rip(_i, _n, _s) for (int _i = (_s); _i < (int)(_n); _i++)
#define all(_l) _l.begin(), _l.end()
#define rall(_l) _l.rbegin(), _l.rend()
#define MM << " " <<
template<typename _T>
using MaxHeap = std::priority_queue<_T>;
template<typename _T>
using MinHeap = std::priority_queue<_T, std::vector<_T>, std::greater<_T>>;
template<typename _T>
inline bool chmax(_T &_l, const _T _b) {
if (_l < _b) {
_l = _b;
return true;
}
return false;
}
template<typename _T>
inline bool chmin(_T &_l, const _T _b) {
if (_l > _b) {
_l = _b;
return true;
}
return false;
}
template<typename _T>
void vdeb(const std::vector<_T> &bb) {
for (unsigned int i = 0;i < bb.size();i++) {
if (i == bb.size() - 1) std::cout << bb[i];
else std::cout << bb[i] << ' ';
}
std::cout << '\n';
}
template<typename _T>
void vdeb(const std::vector<std::vector<_T>> &bb) {
for (unsigned int i = 0;i < bb.size();i++) {
// std::cout << i << ' ';
vdeb(bb[i]);
}
std::cout << '\n';
}
using namespace std;
int main() {
int n; cin >> n;
vector<Pii> s(n), t(n);
rip(i,n,0) {
cin >> s[i].first >> s[i].second;
}
rip(i,n,0) {
cin >> t[i].first >> t[i].second;
}
if(n == 1) {
cout << "Yes" << endl;
return 0;
}
auto dist = [&](Pii &x, Pii &y) -> int {
return (x.first-y.first)*(x.first-y.first) + (x.second-y.second)*(x.second-y.second);
};
auto area = [&](Pii x, Pii y) -> int {
return x.first*y.second-x.second*y.first;
};
auto minu = [](Pii x, Pii y) {
return make_pair(x.first-y.first, x.second-y.second);
};
auto dataset = [&](vector<Pii> &da, int a, int b) -> vector<Pii> {
vector<Pii> ret;
Pii x = minu(da[a], da[b]);
ret.reserve(n-2);
rip(i,n,0) {
if(i == a || i ==b) continue;
ret.push_back({dist(da[i], da[b]), area(x, minu(da[i], da[b]))});
}
sort(all(ret));
return ret;
};
auto base = dataset(s, 0, 1);
// vdeb(base);
rip(i,n,0) rip(j,n,0) {
if(i == j || dist(s[0], s[1]) != dist(t[i], t[j])) continue;
auto tmp = dataset(t, i, j);
// vdeb(tmp);
if(base == tmp) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pvllvll pair <vector <ll>, vector <ll> >
#define ld long double
#define veci vector <int>
#define vecll vector <ll>
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;
void solve() {
int n;
cin >> n;
vector <pii> a(n);
for(auto &it : a) cin >> it.f >> it.s;
for(int i = 0; i < n; ++i) {
for(int j = i + 1; j < n; ++j) {
for(int k = j + 1; k < n; ++k) {
if((a[i].f - a[j].f) * (a[k].s - a[j].s) == (a[k].f - a[j].f) * (a[i].s - a[j].s)) {
cout << "Yes";
return;
}
}
}
}
cout << "No";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
///cin >> T;
while(T--) solve(), cout << '\n';
return 0;
}
| #include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define min3(a,b,c) min(min((a),(b)),(c))
#define min4(a,b,c,d) min(min((a),(b)),min((c),(d)))
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define S second
#define F first
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define PI 3.14159265358979323846;
#define MOD 1000000007
using namespace std;
int main()
{
FAST;
int n;
cin >> n;
vector <ll> v(n);
ll s_a = 0;
for(int i = 0; i < n; i++)
{
ll a, b;
cin >> a >> b;
s_a -= a;
v[i] = 2 * a + b;
}
sort(v.rbegin(), v.rend());
int c = 0;
for(int i = 0; i < n; i++)
{
if(s_a > 0)
{
break;
}
s_a += v[i];
c += 1;
}
cout << c << "\n";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int Mxn = 1e5;
int a[Mxn], n;
void solve() {
ll N;
cin >> N;
for (ll i = 1; i <= 100000; ++i) {
if ((i * i + i) >= 2 * N) {
cout << i ;
return;
}
}
}
int main() {
int t = 1;
//cin >> t;
while (t--) {
solve();
}
} | #include<bits/stdc++.h>
using namespace std;
#define int long long
#define test int x; cin>>x; while(x--)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i,a,b) for(int i = a; i < b; i++)
#define fe(i,a,b) for(int i = a; i <= b; i++)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
int32_t main(){
int n;
cin >> n;
//cout << sqrt(n) << "\n";
for(int i = 1,j = (int)sqrt(n); i <= (int)sqrt(n),j <= n; i++,j++){
int sum = ((i*(i+1))/2);
int sum1 = ((j*(j+1))/2);
if(sum >= n){
cout << i;
break;
}
if(sum1 >= n){
cout << j;
break;
}
}
} |
// KNOW NOTHING!
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fall(a) a.begin(),a.end()
#define sz(x) (int)x.size()
#define szs(x) (int)x.length()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef queue<int> qin;
typedef deque<ll> dqll;
typedef deque<int> dqint;
typedef priority_queue<ll> pqll;
typedef priority_queue<int> pqin;
typedef map<ll,ll> mpll;
typedef map<int,int> mpin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;
const ll MOD=1000000007;
const long double PI=3.1415926535897932384626433832795;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}
ll mpwr(ll b,ll p){ll res=1;while(p){if(p&1) {res=(res*b)%MOD; p--;}else{b=(b*b)%MOD; p>>=1;}}return res;}
int msb (int n) {return 31-__builtin_clz(n);}
ll msbl (ll n) {return 63-__builtin_clzll(n);}
int lsb (int n) {return __builtin_ctz(n);}
ll lsbl (ll n) {return __builtin_ctzll(n);}
int setbit (int n) {return __builtin_popcount(n);}
ll setbitl (ll n) {return __builtin_popcountll(n);}
int main()
{
/*
freopen ("input.txt","r","stdin");
freopen ("output.txt","w","stdout");
*/
ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
ll n; cin>>n;
mpll mp;
F (i,0,n,1) {
int a ; cin>>a;
++mp[a%200];
}
ll cnt=0;
for (auto i : mp) {
cnt+=((i.ss)*(i.ss-1))/2;
}
cout<<cnt;
return 0;
}
/* What we know is a drop , but what we don't know is an ocean !*/ | #include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>
#include <hash_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define lp(i,a,n) for(ll i=a;i<n;i++)
#define lp2(i,n,a) for(ll i=a-1;i>=n;i--)
#define all(arr,n) arr,arr+n
#define allv(v) (v).begin(),(v).end()
#define rallv(v) (v).rbegin(),(v).rend()
#define m_p make_pair
#define ll long long
#define pii pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define sz(x) (int)x.size()
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define f first
#define s second
#define mem(dp,n) memset(dp,n,sizeof dp)
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightX[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightY[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
s += ',';
vector<string> res;
while(!s.empty()) {
res.push_back(s.substr(0, s.find(',')));
s = s.substr(s.find(',') + 1);
}
return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
stringstream ss; ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=1e5+1,oo=0x3f3f3f3f,MOD=1e9+7;
const long double PI = acos(-1),eps=1e-9;
void solve(){
ll n,w;
cin>>n>>w;
cout<<n/w<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast();
int t=1;
//cin>>t;
while(t--)
solve();
return 0;
} |
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
template<class T1, class T2> bool umin(T1& a, T2 b) { return a > b ? (a = b, true) : false; }
template<class T1, class T2> bool umax(T1& a, T2 b) { return a < b ? (a = b, true) : false; }
template<class T> void clear(T& a) { T().swap(a); }
const int N = 2e2 + 5, inf = 1 << 30;
int n, m, _, k;
int v[N];
bool f[N >> 1][N >> 1];
int main() {
IOS; cin >> n;
bool flag = 0;
rep(i, 1, n) {
int a, b; cin >> a >> b; --a, --b;
if (a == -2 && b == -2) continue;
if (a == -2) { if (v[b]) flag = 1; v[b] = -N; }
else if (b == -2) { if (v[a]) flag = 1; v[a] = N; }
else {
if (b <= a) flag = 1;
if (v[a] || v[b]) flag = 1;
v[a] = b - a; v[b] = a - b;
}
}
if (flag) { cout << "No"; return 0; }
rep(i, 1, n)
rep(j, 0, n - i) {
if (!f[j][i + j]) rep(k, j + 1, i + j - 1) if (f[j][k] && f[k][j + i]) { f[j][i + j] = 1; break; }
if (!f[j][i + j]) {
f[j][i + j] = 1;
rep(k, j << 1, (j << 1) + i - 1)
if (!(v[k] == i & v[k + i] == -i) && !(v[k] == N && !v[k + i]) && !(!v[k] && v[k + i] == -N) && !(!v[k] && !v[k + i])) {
f[j][i + j] = 0;
break;
}
}
}
if (f[0][n]) cout << "Yes";
else cout << "No";
return 0;
} | /*
In the name of ALLAH
Author : Raashid Anwar
*/
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int M1 = 998244353;
const int M2 = 1000000007;
mt19937 rng((uint64_t)chrono::steady_clock::now().time_since_epoch().count());
void solve() {
int n;
cin >> n;
vector <int> l(n), r(n);
map <int, set <int>> mp;
for (int i = 0; i < n; i++) {
cin >> l[i] >> r[i];
mp[l[i]].insert(i);
mp[r[i]].insert(i);
}
vector <int> dp(n + n + 1, 0);
dp[0] = 1;
for (int li = 1; li < n + n; li++) {
for (int k = 1; li + k - 1 + k <= n + n; k++) {
//out << " ====> { " << li << ", " << k << " } <====\n";
if (dp[li - 1]) {
if (dp[li + k - 1 + k])
continue;
dp[li + k - 1 + k] = 1;
for (int i = li; i < li + k && dp[li + k - 1 + k]; i++) {
set <int> s;
for (int x : mp[i])
s.insert(x);
for (int x : mp[i + k])
s.insert(x);
dp[li + k - 1 + k] &= ((int)s.size() <= 1);
for (int x : s) {
if (l[x] != -1 && l[x] != i)
dp[li + k - 1 + k] = 0;
if (r[x] != -1 && r[x] != i + k)
dp[li + k - 1 + k] = 0;
}
}
//cout << "{ " << li << ", " << li + k - 1 + k << " } ==> " << dp[li + k - 1 + k] << "\n";
}
}
}
cout << (dp[n + n]? "Yes": "No") << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int i = a; i <= (n); ++i)
#define repD(i, a, n) for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a) memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxc = 400019;
vector <set <pii>> c(maxc);
int main() {
cin.sync_with_stdio(0); cin.tie(0);
cin.exceptions(cin.failbit);
int n; cin >> n;
vi a(n), b(n); rep(i,n) cin >> a[i] >> b[i];
int ans = 0;
rep(i,n) c[a[i]].insert(mp(i,0));
rep(i,n) c[b[i]].insert(mp(i,1));
queue <int> que;
rep(i,maxc){
if(sz(c[i]) == 1) que.push(i);
}
while(!que.empty()){
int f = que.front();
que.pop();
if(sz(c[f])){
ans++;
pii aa = *c[f].begin();
c[f].erase(aa);
aa.snd = 1 - aa.snd;
int ff = (aa.snd == 0) ? a[aa.fst] : b[aa.fst];
c[ff].erase(aa);
if(sz(c[ff]) == 1) que.push(ff);
}
}
rep(i,maxc){
if(sz(c[i])) ans++;
}
cout << ans << endl;
return 0;
}
| #include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int N = 4e5 + 1;
ll parent[N], edges[N], sz[N];
ll findset(ll a){
if(a == parent[a]){
return a;
}
return parent[a] = findset(parent[a]);
}
void unionset(ll a, ll b){
a = findset(a);
b = findset(b);
if(a == b){
edges[a]++;
return;
}
sz[a] += sz[b];
parent[b] = a;
edges[a] += edges[b] + 1;
}
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
fast;
ll T = 1, i, j;
//cin >> T;
while (T--) {
ll n;
cin >> n;
for(i = 1; i < N; i++){
parent[i] = i;
sz[i] = 1;
}
for(i = 0; i < n; i++){
ll a, b;
cin >> a >> b;
if(1){
unionset(a ,b);
}
}
ll ans = 0;
set<ll> diffs;
for(i = 1; i < N; i++){
diffs.insert(findset(i));
}
for(auto i : diffs){
ans += min(edges[i], sz[i]);
}
cout << ans << endl;
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
template<typename T> void dbg_a(const T *a,int l,int r){cerr<<" {";for(int i = l;i<r;i++) cerr<<a[i]<<", ";cerr<<a[r]<<"}"<<endl;}
typedef long long ll;
#define int ll
inline int read(){
int f(1),r(0);char c(getchar());
while(c<'0'||c>'9'){if(c == '-') f = -1; c = getchar();}
while(c>='0'&&c<='9'){ r = (r<<1) + (r<<3) + c - '0';c = getchar();}
return f*r;
}
void read(int &x){ x = read();}
template<class Head, class... Tail> void read(Head &head, Tail &... tail) { read(head); read(tail...); }
typedef pair<int,int> PII;
#define fi first
#define se second
#define mst(a,b) memset(a,b,sizeof(a))
#define For(i,a,b) for(int i = a;i<=b;i++)
#define For_(i,a,b) for(int i = a;i>=b;i--)
#define _for(i,a) for(int i = 0;i<a;i++)
#define Sum(a,l,r) accumulate(a + l,a + r + 1,0)
#define All(x) x.begin(),x.end()
// For(i,1,n) For(j,1,m) printf("f[%lld][%lld] = %lld\n",i,j,f[i][j]);
const ll INF = 0x3f3f3f3f3f3f3f3f;
//const int INF = 0x3f3f3f3f;
const int N = 100 + 6,M = N*2 + 6;
const int mod = 1e9+7;
struct Mat{
int val[105][105]; //自行设置大小
int height,width;
void clear(){
memset(val,0,sizeof(val));
}
Mat() {}
Mat(int height,int width) : height(height),width(width) { //用于初始化
clear();
}
Mat operator *(const Mat &B){ // A * B
Mat ret(this->height,B.width);
for(int i = 1;i <= this->height;i++){
for(int k = 1;k<=this->width;++k){
if(this->val[i][k] == 0) continue;
for(int j = 1;j<=B.width;j++){
ret.val[i][j] = (ret.val[i][j] + this->val[i][k]*B.val[k][j]%mod)%mod;//注意需不需要取模
}
}
}
return ret;
}
Mat pow(int n){
Mat ret(this->height,this->width),base = (*this);
for(int i = 1;i<=height;i++){
ret.val[i][i] = 1;
}
while(n){
if(n & 1) ret = ret * base;
base = base * base;
n >>= 1;
}
return ret;
}
void resize(int he,int wi){//不太好用
this->width = wi;
this->height = he;
}
static Mat I(int siz){//单位矩阵I
Mat ret(siz,siz);
for(int i = 1;i<=siz;i++){
ret.val[i][i] = 1;
}
return ret;
}
};
int mpow(int x,int k){
int res = 1;
while(k){
if(k & 1) res = (ll)res * x % mod;
x = (ll)x * x%mod;
k >>=1;
}
return res;
}
int n,m,k;
PII edge[N*N];
int deg[N];
void solve(){
read(n,m,k);
Mat a(n,n),ans(1,n);
For(i,1,n) ans.val[1][i] = read();
For(i,1,m){
int x = read(),y = read();
edge[i] = {x,y};
deg[x]++,deg[y]++;
}
int inv2m = mpow(2*m,mod-2);
For(i,1,m){
auto [x,y] = edge[i];
a.val[x][y] = inv2m;
a.val[y][x] = inv2m;
}
For(i,1,n){
a.val[i][i] = (2*m - deg[i])*inv2m%mod;
}
a = a.pow(k);
// For(i,1,n) {cout<<"\n";For(j,1,n) cout<<a.val[i][j]<<" ";}
// cout<<"\n";
ans = ans*a;
For(i,1,n){
cout<<ans.val[1][i]<<"\n";
}
}
signed main(){
int T = 1;
//T = read();
while(T--) solve();
return 0;
} | // first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN reverse replace stringstream string::npos length substr front priority_queue
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::vector<ll> vi;
typedef pair<ll, ll> pi;
#define ull unsigned long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define boht_tez ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN ll(1e5 + 123)
#define MAXINP ll (1e3 + 123)
#define MAX_SIZE 100000000
#define DOD(i) cout<<setprecision(i)<<fixed<<
#define MOD 1000000007ll
#define pi 3.1415926536
int main()
{
#ifndef ONLINE_JUDGE
// for getting input from input.tx
freopen("input1.txt", "r", stdin);
// for writing output to output.txt
freopen("output1.txt", "w", stdout);
#endif
ll t = 1 ;
//cin >> t;
while (t--) {
ll x, y;
cin >> x >> y;
//cout << x << " " << y;
if (x == 1 && y == 2 ) {
cout << 0;
}
if (y == 1 && x == 2) {
cout << 0;
}
if (x == 1 && y == 0) {
cout << 2;
}
if (y == 1 && x == 0) {
cout << 2;
}
if ( x == 0 && y == 2 ) {
cout << 1;
}
if (y == 0 && x == 2) {
cout << 1;
}
if (x == y) {
cout << x;
}
}
} |
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
#include <cstdint>
#include <string>
#include <sstream>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using P=pair<ll,ll>;
const int INF=1001001001;
const int mod=1e9+7;
void solve(){
ll t,n;
cin>>t>>n;
int p=100+t;
set<ll>st;
rep(i,100){st.insert(p*i/100);}
vector<ll>b;
rep(i,p*100/100){
if(!st.count(i)){
b.push_back(i);
}
}
ll x=(n-1)/t,y=(n-1)%t;
ll ans=p*x+b[y];
cout<<ans<<endl;
}
int main(){
solve();
return 0;
}
| #pragma GCC optimize("Ofast")
#if 1
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
using ll = int64_t;
using db = double;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
constexpr char newl = '\n';
constexpr double eps = 1e-10;
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define show(x) cerr << #x << " = " << (x) << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo(x) cout<<((x)?"Yes":"No")<<newl;
#define YESNO(x) cout<<((x)?"YES":"NO")<<newl;
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
template<class A, class B> using umap = unordered_map<A, B>;
template<class A> using uset = unordered_set<A>;
template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
F0R(j, sz(v)) i >> v[j];
return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) {
o << "(" << v.first << "," << v.second << ")";
return o;
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
F0R(i, v.size()) {
o << v[i] << ' ';
}
o << newl;
return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
for (auto e : v) {
o << e << ' ';
}
o << newl;
return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
for (auto& p : m) {
o << p.first << ": " << p.second << newl;
}
o << newl;
return o;
}
// INSERT ABOVE HERE
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N; cin >> N;
int day = 1;
while ((1 + day) * day / 2 < N) day++;
cout << day;
}
#endif
|
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
const int MOD = 998244353;
const int N = 5005;
int P[N][N];
int power(int x, int y) {
if (P[x][y] != -1) return P[x][y];
if (y < 0) return 0;
int u = x;
int v = y;
int res = 1;
while (y) {
if (y % 2) res = res * x % MOD;
y >>= 1;
x = x * x % MOD;
}
return P[u][v] = res;
}
int32_t main() {
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) P[i][j] = -1;
}
int64_t res = 0;
for (int h = 1; h <= m; h++) {
for (int l = 1; l <= n; l++) {
if (l == n) {
res += (power(m - h + 1, l) - power(m - h, l) + MOD) % MOD;
res %= MOD;
} else {
res += (n - l - 1) * (power(m - h + 1, l) - power(m - h, l) + MOD) % MOD * power(h - 1, 2) % MOD * power(m, n - l - 2) % MOD;
res %= MOD;
res += 2 * (power(m - h + 1, l) - power(m - h, l) + MOD) % MOD * (h - 1) % MOD * power(m, n - l - 1) % MOD;
res %= MOD;
}
}
}
cout << res << '\n';
return 0;
}
| #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;
constexpr int P = 1000000007;
char s[2000][2001];
int a[2000][2000];
int b[2000][2000];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int h, w;
cin >> h >> w;
for (int i = 0; i < h; i++) {
cin >> s[i];
}
for (int i = 0; i < h; i++) {
int k = 0;
for (int j = 0; j <= w; j++) {
if (j == w || s[i][j] == '#') {
for (int l = j - k; l < j; l++) {
a[i][l] = k;
}
k = 0;
} else {
k++;
}
}
}
for (int j = 0; j < w; j++) {
int k = 0;
for (int i = 0; i <= h; i++) {
if (i == h || s[i][j] == '#') {
for (int l = i - k; l < i; l++) {
b[l][j] = k;
}
k = 0;
} else {
k++;
}
}
}
vector<int> x(h * w + 1);
x[0] = 1;
for (int i = 1; i <= h * w; i++) {
x[i] = x[i - 1] * 2 % P;
}
ll r = 0;
int l = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (s[i][j] == '#') continue;
l++;
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (s[i][j] == '#') continue;
int k = a[i][j] + b[i][j] - 1;
r += (ll)x[l - k] * (x[k] - 1) % P;
}
}
r %= P;
if (r < 0) r += P;
cout << r << endl;
//マスの立場で考えると、この範囲に明かりが一つでもあるか
return 0;
} |
#include <bits/stdc++.h>
#include<sstream>
#include<string>
#include<vector>
#include <set>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define decimal(ans,w) cout<<fixed<<setprecision(w)<<ans
long long M=1000000007;
using namespace std;
ll fact[10000];
ll power(ll x, unsigned ll y, unsigned ll m)
{
if (y == 0)
return 1;
ll p = power(x, y / 2, m) % m;
p = (p * p) % m;
return (y % 2 == 0) ? p : (x * p) % m;
}
unsigned long long modInverse(unsigned long long n,
ll p)
{
return power(n, p - 2, p);
}
unsigned long long nCrModPFermat(unsigned long long n,
ll r, ll p)
{
// If n<r, then nCr should return 0
if (n < r)
return 0;
// Base case
if (r == 0)
return 1;
return (fact[n] * modInverse(fact[r], p) % p
* modInverse(fact[n - r], p) % p)
% p;
}
int32_t main()
{
IOS
string s;
cin>>s;
ll n=s.length(),x=0;
deque<char>t;
for(ll i=0;i<n;i++)
{
if(s[i]=='R')
{
x^=1;
}
else if(x)t.push_front(s[i]);
else t.push_back(s[i]);
}
if(x)reverse(t.begin(),t.end());
string s1;
for(auto it:t)
{
if(s1.length()>0 && s1.back()==it)
{
s1.pop_back();
}
else s1.push_back(it);
}
cout<<s1;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
int x[10];
int main() {
string s;
cin >> s;
deque<char> d;
int rev = 0; //1 is hanten
int cnt = 0;
rep(i,s.size()) {
if (s[i] == 'R') rev = ~rev;
else if (d.empty()) d.push_back(s[i]);
else {
if (rev) {
if (s[i] != d.front()) {
d.push_front(s[i]);
} else {
d.pop_front();
}
} else {
if (s[i] != d.back()) {
d.push_back(s[i]);
}else {
d.pop_back();
}
}
}
}
string t = "";
// cout << d.size() << endl;
rep(i,d.size()) t += d[i];
if (rev) reverse(t.begin(), t.end());
cout << t << endl;
} |
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
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; }
__attribute__ ((constructor))
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(10);
}
int main(){
int x, y;
cin >> x >> y;
if(min(x,y) + 3 > max(x,y)){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(a,n) for (int a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
ll t,n;
ll f(ll A){
return (100+t)*A/100;
}
bool check(ll x){
if(f(x)-x<=n)return true;
else return false;
}
ll BinarySearch(){
ll ok = 0;
ll ng = 1e16;
while(abs(ok-ng)>1){
ll mid = (ok+ng)/2;
if(check(mid))ok=mid;
else ng=mid;
}
return ok;
}
int main(){
cin >> t >> n;
n--;
cout << f(BinarySearch()) + 1 << endl;
return 0;
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using namespace std;
int main() {
int N, D, H;
cin >> N >> D >> H;
double ans = 0.0;
rep(i, N) {
int d, h;
cin >> d >> h;
ans = max(ans, h - (H*1.0-h)/(D-d) * d);
}
cout << ans << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define int double
int32_t main(){
int n,d,h;cin>>n>>d>>h;
vector<pair<int,int>>v;
for(long long i=0;i<n;i++){
int a,b;cin>>a>>b;
v.push_back(make_pair(a,b));
}
int minval=INT_MAX;
for(long long i=0;i<n;i++){
minval=min(minval,atan((h-v[i].second)/(d-v[i].first)));
}
// minval=abs(minval * (180/3.14159));
int ans=tan(minval)*d;
// cout<<ans<<endl;
int c=0.0;
ans=max(c,h-ans);
if(ans==0) cout<<"0.0";
else cout<<ans<<endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
const int mn=2e5+7,mod=1e9+7;
char s[mn];
int a[mn],k,vis[20];
long long f[mn][20];
int main()
{
scanf("%s",s+1);
scanf("%d",&k);
int n=strlen(s+1);
for(int i=1;i<=n;++i) {
if(s[i]>='A') a[i]=s[i]-'A'+10;
else a[i]=s[i]-'0';
}
f[1][1]=a[1]-1;
int tot=0;
for(int i=1;i<n;++i) {
if(!vis[a[i]]) {
vis[a[i]]=1;tot++;
}
for(int j=1;j<=min(i,16);++j) {
f[i+1][j]=(f[i+1][j]+j*f[i][j])%mod;
if(j<16) f[i+1][j+1]=(f[i+1][j+1]+f[i][j]*(16-j))%mod;
}
for(int j=0;j<a[i+1];++j) {
if(vis[j]) f[i+1][tot]++;
else f[i+1][tot+1]++;
}
f[i+1][1]=(f[i+1][1]+15)%mod;
}
if(!vis[a[n]]) tot++;
if(k==tot) f[n][k]++;
cout<<f[n][k]%mod;
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
const int MOD = 1000000007;
vector<long long> fac, finv, inv;
void InitializeCombination(int COMMAX){
fac.push_back(1LL);
fac.push_back(1LL);
finv.push_back(1LL);
finv.push_back(1LL);
inv.push_back(0LL); //Though 0^(-1) cannot be defined, there should be some number in inv[0]
inv.push_back(1LL);
for (int i = 2; i <= COMMAX; i++){
fac.push_back(fac[i-1] * (long long)i % (long long)MOD);
inv.push_back((long long)MOD - inv[MOD%i] * (long long)(MOD/i) % (long long)MOD);
finv.push_back(finv[i-1] * inv[i] % (long long)MOD);
}
}
long long Combination(int n, int r){
if (n < r) return 0LL;
if (n < 0 || r < 0) return 0LL;
return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD;
}
long long InvCombination(int n, int r){
if (n < r) return 0LL;
if (n < 0 || r < 0) return 0LL;
return finv[n] * (fac[r] * fac[n-r] % MOD) % MOD;
}
int HexCharToInt(char C){
if((C>='0')&&(C<='9'))return C-'0';
return C-'A'+10;
}
int main(void){
string strN;
int K;
long long res = 0LL;
cin >> strN >> K;
vector<vector<long long>> numHex(1, vector<long long>(K+1, 0LL));
int lenN = (int)strN.size();
InitializeCombination(16);
numHex.push_back({});
for(int i=0; i<=K; i++)numHex[1].push_back(i == 1 ? 16LL : 0LL);
for(int i=2; i<=lenN; i++){
numHex.push_back({});
for(int j=0; j<=K; j++){
if((j==0)||(j>i)){
numHex[i].push_back(0LL);
}else{
numHex[i].push_back((numHex[i-1][j]*j%MOD+numHex[i-1][j-1]*(17-j)%MOD)%MOD);
}
}
}
for(int i=1; i<lenN; i++){
res += numHex[i][K]*15%MOD*inv[16]%MOD;
res %= MOD;
}
set<int> setSpecies;
int numSpecies = 0;
for(int i=0; i<lenN; i++){
int Ni = HexCharToInt(strN[i]);
for(int j=0; j<Ni; j++){
if((i==0)&&(j==0))continue;
set<int> nxtSpecies = setSpecies;
nxtSpecies.insert(j);
int nxtNum = (int)nxtSpecies.size();
if(nxtNum > K)continue;
if(i<lenN-1){
for(int k=K-nxtNum; k<=K; k++){
res += numHex[lenN-i-1][k]*Combination(nxtNum, nxtNum+k-K)%MOD*Combination(16-nxtNum, K-nxtNum)%MOD*InvCombination(16, k)%MOD;
res %= MOD;
}
}else{
if(nxtNum==K){
res++;
res %= MOD;
}
}
}
setSpecies.insert(Ni);
numSpecies = (int)setSpecies.size();
if(numSpecies > K)break;
}
if(numSpecies == K)res = (res + 1) % MOD;
cout << res << endl;
return 0;
} |
#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define endl "\n"
using namespace std;
const int max_n = 1010;
const int max_k = 405;
const int Mod = 1e9+7;
const int inf = 2e18;
int n,m;
int a[max_n],b[max_n];
int dp[max_n][max_n];
int solve(int i,int j){
if(i>=n) return (m-j);
if(j>=m) return (n-i);
if(dp[i][j]!=-1) return dp[i][j];
int t1=inf,t2=inf,t3=inf,t4=inf;
if(a[i]==b[j]){
t1=solve(i+1,j+1);
}
t2=solve(i+1,j+1)+1;
t3=solve(i+1,j)+1;
t4=solve(i,j+1)+1;
int ans = min(min(t1,t2),min(t3,t4));
dp[i][j]=ans;
return ans;
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
memset(dp,-1,sizeof(dp));
cin>>n>>m;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<m;i++) cin>>b[i];
cout<<solve(0,0)<<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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order // k th index
#define ook order_of_key // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY \
int test; \
scanf("%d", &test); \
for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;
ll rdn(int y, int m, int d) {
/* Rata Die day one is 0001-01-01 */
if (m < 3)
y--, m += 12;
return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
mt19937 R(chrono::system_clock().now().time_since_epoch().count());
int A[1009], B[1009];
int dp[1009][1009];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> A[i];
}
for (int i = 1; i <= m; i++) {
cin >> B[i];
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (!i || !j) {
dp[i][j] = i + j;
} else {
dp[i][j] = dp[i - 1][j] + 1;
dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + (A[i] == B[j] ? 0 : 1));
}
}
}
cout << dp[n][m] << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
const long long inf = 1100000000000000000;
#define maxn 1000005
#define mod 1000000007 //998244353
#define int long long
#define PB push_back
#define F first
#define S second
#define vi vector<int>
#define rep(i,a,b) for( int i = a; i < b; i++ )
#define rep1(i,a,b) for( int i = a; i <= b; i++)
#define repd(i,a,b) for( int i = a; i >= b; --i)
#define sz(x) (int)((x).size())
#define all(c) (c).begin(),(c).end()
#define allr(v) v.rbegin(),v.rend()
#define mem(a,x) memset(a,x,sizeof(a))
#define dbg(a) cout << #a << " is " << (a); cout << "\n";
//...
int a, b, c;
bool ck(){
return a*a + b*b < c*c;
}
void solve(){
cin>>a>>b>>c;
if(ck())
cout<<"Yes";
else
cout<<"No";
}
signed main(){
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int T=1; //cin>>T;
while(T--){
solve(); cout<<'\n';
}
return 0;
} | /*input
10 3
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(double i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=3e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define MP make_pair
ll mult(ll a,ll b){
ll res=0LL;
while(b){
if(b&1) res=(res+a)%MOD;
a=(a+a)%MOD;
b>>=1;
}
return res%MOD;
}
ll mypow(ll a,ll b){
ll res=1LL;
while(b){
if(b&1) res=res*a%MOD;
a=a*a%MOD;
b>>=1;
}
return res;
}
int32_t main(){
ios::sync_with_stdio(false),cin.tie(0);
int a,b;
cin>>a>>b;
cout<<(a/b);
} |
/* Author VS_CODE */
#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb emplace_back
using namespace std;
void online()
{
#ifndef ONLINE_JUDGE
freopen("input","r",stdin);
freopen("output","w",stdout);
#endif
}
/* CODE STARTS HERE */
const int N = 2e5+7;
int ans=0;
void solve()
{
int n;
cin>>n;
int A[n],B[n];
for(int i=0;i<n;i++)
cin>>A[i];
for(int i=0;i<n;i++)
cin>>B[i];
int b=1e9+7;
int a=0;
for(auto i:A)
a=max(i,a);
for(auto i:B)
b=min(i,b);
cout<<max(0,b-a+1);
}
/* CODE ENDS HERE AND MAIN STARTS */
int main()
{
// online();
// int t;cin>>t;while(t--)
solve();
} | /*
I love the sound you make when you shut up.
*/
#include <bits/stdc++.h>
using namespace std;
#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;
/*-------typedefs------*/
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
using ll = long long;
using pi = pair<int, int>;
/*-----in and out--------*/
#define pf(a) cout << a << endl
#define forIn(arr, num) for(int i = 0; i < num; i++) cin >> arr[i];
#define vpnt(ans) for(int i = 0; i < int(ans.size()); i++) cout << ans[i] << (i + 1 < int(ans.size()) ? ' ' : '\n');
/*---useful defines------*/
#define sz(x) (int)(x).size()
#define pb push_back
#define mem(a, b) memset(a,(b), sizeof(a))
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
/*----- the binary answer of life-----*/
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
/*---checking and pushing-----*/
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
/*---- FAST I/O and file read ---*/
void go() {
ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
}
/*-------- test-case stuff--------------*/
#define ssolve solve();
#define msolve int T;cin >> T;while(T--) {solve();}
#define mcsolve int T;cin >> T;for(int tt = 1;tt <= T;tt++) {cout << "Case #" << tt << ": ";solve();}
/*-------- movement in a 2D array ------*/
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
/*----------------------------------------------------------------*/
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
/*-------------- Push your limits here ---------------------------*/
void solve() {
int n;
cin >> n;
vector<int> a(n);
forIn(a, n);
vector<int> b(n);
forIn(b, n);
int cnt = 0;
for(int i = 1;i <= 1000;i++) {
bool flag = true;
for(int j = 0;j < n;j++) {
if(i < a[j] || i > b[j]) {
flag = false;
break;
}
}
if(flag) cnt++;
}
pf(cnt);
}
int main() {
go();
ssolve
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
int N, M;
cin >> N >> M;
vector<int> A(M), B(M);
rep(i, M) { cin >> A[i] >> B[i]; }
int K;
cin >> K;
vector<int> C(K), D(K);
rep(i, K) { cin >> C[i] >> D[i]; }
int res = 0;
for (int mask = 0; mask < (1 << K); mask++) {
vector<bool> dishes(N + 1);
rep(i, K) {
if (mask & (1 << i)) {
dishes[C[i]] = true;
} else {
dishes[D[i]] = true;
}
}
int cnt = 0;
rep(i, M) {
if (dishes[A[i]] && dishes[B[i]]) {
cnt++;
}
}
res = max(res, cnt);
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=1000000000+5;
const int N=1e5+5;
const ll oo=1e18+5;
const ll mod=1e9+7;
map<int,pair<int,int>> get(int n,int L){
vector<int> v{0};
for(int i=1;i<=n+1;++i){
int x=L+1;
if(i<=n) cin>>x;
v.push_back(x-i);
}
map<int,pair<int,int>> interval;
for(int i=0;i<(int)v.size();++i){
if(!i||v[i]!=v[i-1]){
interval[v[i]].first=i;
}
interval[v[i]].second=i;
}
return interval;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
int n,L;
cin>>n>>L;
auto a=get(n,L);
auto b=get(n,L);
//~ cout<<"a : "<<endl;
//~ for(auto x:a){
//~ cout<<"("<<x.first<<")["<<x.second.first<<","<<x.second.second<<"]"<<endl;
//~ }
//~ cout<<"b : "<<endl;
//~ for(auto x:b){
//~ cout<<"("<<x.first<<")["<<x.second.first<<","<<x.second.second<<"]"<<endl;
//~ }
ll ans=0;
for(auto x:b){
int val=x.first;
if(!a.count(val)){
return cout<<-1,0;
}
ans+=max(0,a[val].first -b[val].first)+max(0,b[val].second-a[val].second);
}
cout<<ans;
return 0;
}
|
#include<bits/stdc++.h>
#define I return
#define LOVE 0
#define TIANYUAN ;
using namespace std;
const int N=1000007;
int n,q;
char s[N];
int a[N],b[N];
int t;
bool flag=false;
int main()
{
cin>>n;
scanf("%s",s);
for(int i=1;i<=n;i++)
{
a[i]=i;
b[i]=n+i;
}
cin>>q;
for(int i=1;i<=q;i++)
{
cin>>t;
int x,y;
if(t==1)
{
cin>>x>>y;
if(!flag)
{
if(x>n)
{
if(y>n)
swap(b[x-n],b[y-n]);
else
swap(b[x],a[y]);
}
else
{
if(y>n)
swap(a[x],b[y-n]);
else
swap(a[x],a[y]);
}
}
else
{
if(x>n)
{
if(y>n)
swap(a[x-n],a[y-n]);
else
swap(a[x],b[y]);
}
else
{
if(y>n)
swap(b[x],a[y-n]);
else
swap(b[x],b[y]);
}
}
}
if(t==2)
{
cin>>x>>y;
if(flag==true)
flag=false;
else
flag=true;
}
}
if(!flag)
{
for(int i=1;i<=n;i++)
cout<<s[a[i]-1];
for(int i=1;i<=n;i++)
cout<<s[b[i]-1];
}
else
{
for(int i=1;i<=n;i++)
cout<<s[b[i]-1];
for(int i=1;i<=n;i++)
cout<<s[a[i]-1];
}
I LOVE TIANYUAN
} | #include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mp make_pair
#define pb push_back
#define pll pair<LL,LL>
#define pii pair<int,int>
#define y second
#define x first
#define LL long long
#define ULL unsigned long long
#define sqr(x) ((x)*(x))
#define pi acos(-1)
#define pdd pair<double,double>
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
LL mod=1e9+7;
LL f_pow(LL a,LL b){
LL res=1,temp=a;
while(b){
if(b&1)res=res*temp%mod;
temp=temp*temp%mod;
b>>=1;
}
return res;
}
void solve(){
int n;
scanf("%d",&n);
char c[2][2];
for(int i = 0;i<2;i++){
for(int j =0;j<2;j++){
scanf(" %c",&c[i][j]);
}
}
if(n<=3){
printf("1\n");
return;
}
if(c[0][1]=='A'){
if(c[0][0]=='A')printf("1\n");
else{
if(c[1][0]=='B'){
printf("%d\n",f_pow(2,n-3));
}
else{
int f[1005];
f[0]=1;
f[1]=1;
for(int i=2;i<=n-2;i++){
f[i]=(f[i-1]+f[i-2])%mod;
}
printf("%lld\n",(f[n-3]+f[n-4])%mod);
}
}
}
else{
if(c[1][1]=='B')printf("1\n");
else{
if(c[1][0]=='A'){
printf("%d\n",f_pow(2,n-3));
}
else{
int f[1005];
f[0]=1;
f[1]=1;
for(int i=2;i<=n-2;i++){
f[i]=(f[i-1]+f[i-2])%mod;
}
printf("%lld\n",(f[n-3]+f[n-4])%mod);
}
}
}
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--){
solve();
}
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = (2e5) + 5;
ll a[N];
ll ac[N];
ll ac2[N];
multiset<ll> ms;
multiset<ll> :: iterator it;
int n;
int main() {
ios::sync_with_stdio(!cin.tie(0));
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
ac[0] = a[0];
for (int i = 1; i < n; ++i) {
ac[i] = ac[i - 1] + a[i];
}
ac2[0] = ac[0];
for (int i = 1; i < n; ++i) {
ac2[i] = ac2[i - 1] + ac[i];
}
for (int i = 0; i < n - 1; ++i) {
ms.insert(-ac2[i]);
}
ll mx = 0;
for (int i = 0; i < n; ++i) {
ll x = -*ms.begin();
mx = max(mx, ac[i] + x);
if (i - 1 >= 0) {
ms.erase(-ac2[i - 1]);
}
}
cout << mx << "\n";
return 0;
}
| /*
Problem name: -
Difficulty level: -
Techniques: -
Hints: -
Written by Thalyson
*/
#include <bits/stdc++.h>
using namespace std;
#define vi vector< int >
#define vii vector< pair<int,int> >
#define vvi vector<vector< int > >
#define vvii vector<vector< pair<int,int> > >
#define int int64_t
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define sortv(V) sort(all(V))
#define reversev(V) reverse(all(V))
#define uniquev(V) sortv(V),(V).erase(unique(all(V)),(V).end())
#define pb push_back
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define debug(x) cout << #x << " is " << x << "\n";
// Trace dinâmico (parameter pack (c++11))
template<typename T>
void println(T a) { cout << a << "\n"; }
template<typename T, typename... Args>
void println(T a, Args... args) { cout << a << " "; println(args...); }
template<typename T>
void print(T a) { cout << a; }
template<typename T, typename... Args>
void print(T a, Args... args) { cout << a << " "; print(args...); }
template<typename T>
void printv(T a, string last="\n") {
for(auto el: a)
print(el, "");
print(last);
}
template<typename T>
void scanv(T &a) {
for(auto &el: a)
cin >> el;
}
//Constants
#define EPS 1e-6
#define oo int(1LL<<60)
#define endl '\n'
//Directions ^>v<
const int dx4[4] = {-1, 0, 1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1};
//Main
int N, M, K, CASES;
main(){
std::ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(9) << fixed;
cin >> N;
int cur = 0;
int ans = 0;
int sum = 0;
int great = 0;
for(int i = 0; i < N; i++){
int value;
cin >> value;
sum += value;
great = max(great, sum);
ans = max(ans, cur+great);
cur += sum;
}
println(ans);
/*
Before submit:
Check the corners cases
Check solution restrictions
For implementation solutions
Check the flow of the variables
*/
}
|
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<(n);i++)
#define rep2(i,n,m) for(ll i=n;i<(m);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
void YES(int a){
if(a) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
void Yes(int a){
if(a) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
//#include <atcoder/all>
//using namespace atcoder;
//typedef modint998244353 mint;
int a_max=200200;
const ll mod=998244353;
VL fac(a_max),finv(a_max),inv(a_max);
ll modpow(ll a,ll n){
ll res=1;
while(n){
if(n&1) res=res*a%mod;
a=a*a%mod;
n>>=1;
}
return res;
}
ll modinv(ll a){
return modpow(a,mod-2);
}
void init(){
fac[0]=fac[1]=1;
finv[0]=finv[1]=1;
inv[1]=1;
rep(i,a_max){
if(i>1){
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(ll n,ll k){
if(n<k) return 0;
if(n<0||k<0) return 0;
return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(){
ll N,M;
cin>>N>>M;
VVL X(15,VL(5050,-1));
X[0][0]=1;
init();
rep1(i,15){
ll T=(1ll<<(14-i));
rep(j,5050){
if(X[i-1][j]!=-1){
rep(k,N+1){
if(k%2) continue;
if(j+T*k<=5000){
if(X[i][j+T*k]==-1) X[i][j+T*k]=X[i-1][j]*com(N,k)%mod;
else (X[i][j+T*k]+=X[i-1][j]*com(N,k)%mod)%=mod;
}
}
}
}
}
if(X[14][M]!=-1) cout<<X[14][M]<<endl;
else cout<<0<<endl;
}
| #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;
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 { 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;
}
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;}
struct combination {
vector<mint> fact, ifact;
combination(int n):fact(n+1),ifact(n+1) {
assert(n < mod);
fact[0] = 1;
for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n) return 0;
return fact[n]*ifact[k]*ifact[n-k];
}
} c(200005);
void solve(){
int n,m;
cin>>n>>m;
vector<mint>dp(m+1);
dp[0]=1;
for(int i=2;i<=m;i+=2){
for(int j=0;j<=n;j+=2){
if(i-j>=0){dp[i]+=dp[(i-j)/2]*c(n,j);}
}
}
cout<<dp[m]<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
} |
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <unordered_map>
#include <cstdlib>
#include <numeric>
#include <set>
using namespace std;
int main () {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
sort(A.begin(), A.end());
string ans = "Yes";
for (int i = 0; i < N; i++) {
if (A.at(i) != i + 1) {
ans = "No";
break;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(intt i=0;i<(intt)(n);i++)
#define repm(i,n) for(intt i=(intt)(n)-1;i>=0;i--)
#define rept(i,n) for(intt i=1;i<(intt)(n);i++)
#define reptm(i,n) for(intt i=(intt)(n);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define siz(s) (s).size()
#define fof(i,a,b) for(intt i=a;i<b;i++)
#define bitfor(bit,N) for (int bit = 0; bit < (1 << (intt)(N); ++bit)
#define eb emplace_back
using intt = int64_t;
using ldou = long double;
using vi=vector<int>;
using vt=vector<intt>;
using vc=vector<char>;
using vs=vector<string>;
using vd=vector<ldou>;
using vb=vector<bool>;
using vvi=vector<vi>;
using vvt=vector<vt>;
using vvc=vector<vc>;
using vvs=vector<string>;
using vvd=vector<vd>;
using pa=pair<intt,intt>;
using vpa=vector<pa>;
using mapt=map<intt,intt>;
using vmap=vector<mapt>;
using Graph = vector<vector<int>>; // グラフ型
intt gcd(intt a,intt b){if(a%b==0){return b;}else{return gcd(b,a%b);}}//最大公約数
intt lcm(intt a,intt b){return a*b/gcd(a,b);}//最小公倍数
intt sum(const long &a,const long &b){return(a+b)*(b-a+1)/2;}//合計
vector<long long>yakusu(long long N){vector<long long>res;for(long long i=1;i*i<=N;++i){if(N%i==0){res.push_back(i);if(N/i!=i)res.push_back(N/i);}}sort(res.begin(),res.end());return res;}//約数全部
intt sumi(intt n){int x=0;while(n>=10){x+=n%10;n/=10;}x+=n;return x;}//各桁の和
bool sque(long long N){long long r=(long long)floor(sqrt((long double)N));return(r*r)==N;}//平方数
intt max(intt a,intt b){if(a>b){return a;}else{return b;}}
intt min(intt a,intt b){if(a>b){return b;}else{return a;}}
#include <cmath>
bool integ(double x){return std::floor(x)==x;}
vector<intt> ruiseki(intt n,vector<intt> a){vector<intt>s(n+1,0);for(intt i=0;i<n;++i){s[i+1]=s[i]+a[i];}return s;}
void strsort(vector<string>&S){map<int,int>SwapInd;int maxi=0;for(int i=0;i<S.size();i++){if(S[i].size()>maxi)maxi=S[i].size();}for(int i=0;i<maxi;i++){int k=maxi-i;int sort_num=0;for(int j=0;j<S.size();j++){if(S[j].size()>=k){SwapInd[j]=1;sort_num++;}}int swapped=0;for(int j=0;j<S.size();j++){if(SwapInd[j]==1&&j<S.size()-sort_num){if(SwapInd[S.size()-sort_num+swapped]==0){iter_swap(S.begin()+j,S.begin()+S.size()-sort_num+swapped);}else{while(SwapInd[S.size()-sort_num+swapped]!=0){swapped++;if(S.size()-sort_num+swapped>=S.size()){break;}if(S.size()-sort_num+swapped<S.size()){iter_swap(S.begin()+j,S.begin()+S.size()-sort_num+swapped);}}}
SwapInd[j]=0;SwapInd[S.size()-sort_num+swapped]=0;swapped++;}}vector<string>WhatSorted(sort_num);vector<pair<int,int>>char_and_index(sort_num);for(int j=0;j<sort_num;j++){if(S[S.size()-sort_num+j][k-1]>=65&&S[S.size()-sort_num+j][k-1]<=90){char_and_index[j].first=(int)S[S.size()-sort_num+j][k-1]+32;}else{char_and_index[j].first=(int)S[S.size()-sort_num+j][k-1];}char_and_index[j].second=j;WhatSorted[j]=S[S.size()-sort_num+j];}stable_sort(char_and_index.begin(),char_and_index.end());for(int j=0;j<sort_num;j++){S[S.size()-sort_num+j]=WhatSorted[char_and_index[j].second];}}}
intt fac(intt k){intt sum=1;for(intt i=1;i<=k;++i){sum*=i;}return sum;}
vector<bool> seen;
void dfs(const Graph &G,int v){seen[v]=true;for(auto next_v:G[v]){if(seen[next_v])continue;dfs(G,next_v);}}//DFS
intt mini=INT64_MAX;
intt maxi=INT64_MIN;
intt zero=0;
intt cnt=0;
intt su=0;
intt ans;
intt n;
string s;
Graph g;
int main() {
cout << fixed << setprecision(20);
cin>>n;
vi a(n);
rep(i,n){
cin>>a[i];
}
sort(all(a));
rep(i,n){
if(a[i]-1!=i){
cout<<"No"<<endl;
return 0;
}
}
cout<<"Yes"<<endl;
} |
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <iostream>
#include <stdio.h>
#include <time.h>
using namespace std;
typedef long long ll;
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define MOD 1000000007
void abc(int x1, int y1, int x2, int y2, ll &a, ll &b, ll &c){
a = y2 - y1;
b = x1 - x2;
c = (long long)x2 * y1 - (long long)x1 * y2;
}
double distpl(int x, int y, int a, int b, long long c){
if(a == 0 && b == 0)return -1.0;
long long n = llabs((long long)a * x + (long long)b * y + c);
return (double)n / sqrt(a * a + b * b);
}
int main(){
ll n;
cin>>n;
vector<pair<ll,ll> > vp;
rep(i,0,n){
ll a,b;
cin>>a>>b;
vp.pb(mp(a,b));
}
ll flag = 0;
rep(i,0,vp.sz){
rep(j,i+1,vp.sz){
rep(k,j+1,vp.sz){
ll a,b,c;
abc(vp[i].fi,vp[i].se,vp[j].fi,vp[j].se,a,b,c);
if(distpl(vp[k].fi,vp[k].se,a,b,c)==0.){
flag = 1;
}
}
}
}
if(flag==1){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int ans = 0;
vector<vector<int>> point(n, vector<int>(2));
for (int i=0; i<n; i++){
cin >> point[i][0] >> point[i][1];
}
for (int j=0; j<n; j++){
for (int k=j+1; k<n; k++){
for (int l=0; l<n; l++){
if (l == j){
continue;
}
else if (l == k){
continue;
}
else if ((point[j][0] - point[k][0]) == 0){
if (point[k][0] == point[l][0]){
ans += 1;
}
else{
continue;
}
}
else{
if ((point[j][1] - point[k][1])*(point[l][0]-point[j][0])%(point[j][0] - point[k][0]) == 0){
int y;
y = (point[j][1] - point[k][1])*(point[l][0]-point[j][0])/(point[j][0] - point[k][0]) + point[j][1];
if (y == point[l][1]){
ans += 1;
}
}
}
}
}
}
if (ans == 0){
cout << "No" << endl;
}
else{
cout << "Yes" << endl;
}
} |
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<int,int>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define INF 1e17
class Prime {
// n以下の素数を列挙する
public:
const int n;
vector<bool> is_prime;
vector<int> primes;
Prime(int size) : n(size), is_prime(n+1, true) {
is_prime[0] = false;
is_prime[1] = false;
for (int i = 2; i <= n; ++i) {
if (!is_prime[i]) continue;
primes.push_back(i);
int tmp = 2*i;
while (tmp <= n) {
is_prime[tmp] = false;
tmp += i;
}
}
}
bool check(int x) { return is_prime[x]; }
};
int main(){
ll n;
cin>>n;
ll x[n];
rep(i,n){
cin>>x[i];
}
vector<set<ll>> yakusu(n);
vector<int> primes;
rep(i,n){
for(ll j=1;j*j<=x[i];j++){
if(x[i]%j==0){
if(j!=1)yakusu[i].insert(j);
yakusu[i].insert(x[i]/j);
}
}
}
Prime prime(50);
for (int p : prime.primes) {
primes.push_back(p);
}
int num = primes.size();
ll ans = INF;
for(int i=1;i<1<<num;i++){
ll koho = 1;
for(int j=0;j<num;j++){
if(i&1<<j)koho*=primes[j];
}
bool sodenai = true;
for(int k=0;k<n;k++){
bool check = false;
for(auto di:yakusu[k]){
if(koho%di==0)check=true;
}
if(!check)sodenai=false;
}
if(sodenai){
if(ans==INF)ans=koho;
if(ans>koho)ans=koho;
}
}
cout<<ans<<endl;
} | #include<algorithm>
#include<cstdio>
#include<map>
typedef long long ll;
std::map<ll,ll>mp;
ll n,k;
ll now;
bool looped;
int zc[18],zcnt;
ll get(ll x,bool rev){
zcnt=0;
while(x){
zc[++zcnt]=x%10;
x/=10;
}
std::sort(zc+1,zc+zcnt+1);
if(rev)std::reverse(zc+1,zc+zcnt+1);
ll res=0;
for(int i=zcnt;i;i--)res=(res<<3)+(res<<1)+zc[i];
return res;
}
signed main(){
mp.clear();
scanf("%lld%lld",&n,&k);
now=n;
mp[now]=k;
while(k){
// printf("k=%lld\n",k);
k--;
now=get(now,false)-get(now,true);
// puts("ok");
if(mp[now]&&!looped){
ll len=k-mp[now];
k%=len;
looped=true;
}
mp[now]=k;
}
printf("%lld",now);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
if (a < b) a = b;
}
signed main() {
int n, m;
cin >> n >> m;
int mx = 0;
int w[n];
rep(i, n) {
cin >> w[i];
chmax(mx, w[i]);
}
bool flag = false;
pair<int, int> a[m];
rep(i, m) {
cin >> a[i].second >> a[i].first;
if (a[i].first < mx) flag = true;
}
if (flag) {
cout << -1 << endl;
return 0;
}
sort(a, a + m);
rep(i, m - 1) {
chmax(a[i + 1].second, a[i].second);
}
int ans = INF;
vector<int> v(n);
iota(ALL(v), 0);
do {
int ww[n];
rep(i, n) {
ww[i] = w[v[i]];
}
vector<pair<int, int>> G[n];
for (int cur = 0; cur < n; cur++) {
int sum = ww[cur];
for (int to = cur + 1; to < n; to++) {
sum += ww[to];
int idx = lower_bound(a, a + m, pair<int, int>(sum, 0)) - a;
idx--;
if (idx < 0)
G[cur].emplace_back(to, 0);
else
G[cur].emplace_back(to, a[idx].second);
}
}
int dp[n] = {};
for (int v = 0; v < n; v++) {
for (auto p : G[v]) {
chmax(dp[p.first], dp[v] + p.second);
}
}
ans = min(ans, dp[n - 1]);
} while (next_permutation(ALL(v)));
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
scanf("%d%d",&n,&m);
if(m==0){
for(int i=1;i<=n;i++)printf("%d %d\n",2*i,2*i+1);
}
else if(m==n||m==-n||m==n-1||m==1-n)printf("-1");
else{
int k=5e7;
if(m>=0){
printf("%d %d\n",1,k);
for(int i=1;i<=1+m;i++)printf("%d %d\n",i<<1,i<<1|1);
for(int i=0;i+m+2<n;i++)printf("%d %d\n",k+i*2+1,k+i*2+2);
}
else{
printf("-1");
/* m=-m;
printf("%d %d\n",k,2*k);
for(int i=1;i<=1+m;i++)printf("%d %d\n",2*k-2*i,2*k-2*i+1);
for(int i=0;i+m+2<n;i++)printf("%d %d\n",2*i+1,2*i+2);
*/
}
}
} |
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <functional>
#include <cstring>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <complex>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define itn int
#define nit int
#define ll long long
#define ms multiset
#define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i)
#define re register
#define ri re int
#define il inline
#define pii pair<int,int>
#define cp complex<double>
//#pra gma G CC opti mize(3)
using namespace std;
using std::bitset;
//using namespace __gnu_pbds;
const double Pi=acos(-1);
namespace fastIO {
template<class T>
inline void read(T &x) {
x=0;
bool fu=0;
char ch=0;
while(ch>'9'||ch<'0') {
ch=getchar();
if(ch=='-')fu=1;
}
while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar();
if(fu)x=-x;
}
inline int read() {
int x=0;
bool fu=0;
char ch=0;
while(ch>'9'||ch<'0') {
ch=getchar();
if(ch=='-')fu=1;
}
while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar();
return fu?-x:x;
}
char _n_u_m_[40];
template<class T>
inline void write(T x ) {
if(x==0) {
putchar('0');
return;
}
T tmp = x > 0 ? x : -x ;
if( x < 0 ) putchar('-') ;
register int cnt = 0 ;
while( tmp > 0 ) {
_n_u_m_[ cnt ++ ] = tmp % 10 + '0' ;
tmp /= 10 ;
}
while( cnt > 0 ) putchar(_n_u_m_[ -- cnt ]) ;
}
template<class T>
inline void write(T x ,char ch) {
write(x);
putchar(ch);
}
}
using namespace fastIO;
int n,m,x[100002],y[1000002],p[100002];
int mp[1002][1002];
vector<int>g[100002];
struct node {
int pos,c;
} s[102];
bool cmp(node x,node y){
return x.c>y.c;
}bool vis[102];
inline void dfs(int pos){
vis[pos]=1;
F(i,0,g[pos].size()-1){if(s[g[pos][i]].c==s[pos].c)
if(!vis[g[pos][i]]){
mp[pos][g[pos][i]]=mp[g[pos][i]][pos]=pos;
dfs(g[pos][i]);
}else{
if(!mp[pos][g[pos][i]])mp[pos][g[pos][i]]=mp[g[pos][i]][pos]=pos;
}
}
}
int main() {
cin>>n>>m;
F(i,1,m) {
read(x[i]);
read(y[i]);
g[x[i]].push_back(y[i]);
g[y[i]].push_back(x[i]);
}
F(i,1,n)s[i]=(node) {
i,read()
};
F(i,1,n)if(!vis[i])dfs(i);
F(i,1,n)
{
F(j,0,g[i].size()-1){
if(s[g[i][j]].c<s[i].c){
mp[i][g[i][j]]=mp[g[i][j]][i]=i;
}
}
}F(i,1,m){
if(mp[x[i]][y[i]]==x[i]){
puts("->");
}else{
puts("<-");
}
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std ;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define debug(x) cerr << #x << " -> " << x << "\n"
#define here cerr << "here\n"
#define MP make_pair
#define F first
#define S second
typedef long long ll ;
typedef pair<int ,int> pii ;
constexpr int MAXN = 1e5 + 13 ;
constexpr int MOD = 1e2 + 10 ;
constexpr ll INF = 1e18 ;
struct Edge {
int u ,v ;
};
int n ,m ,vis[MOD][MOD] ,c[MAXN] ,u ,v ,ans[MOD][MOD] ;
vector <int> G[MAXN] ;
Edge E[MAXN] ;
void dfs(int u){
for (auto v : G[u]){
if (c[v] == c[u] && !vis[u][v]){
vis[u][v] = 1 ,vis[v][u] = 1 ;
ans[u][v] = 1 ;
dfs(v) ;
}
}
}
int main (){
fast_io ;
cin >> n >> m ;
for (int i = 0 ;i < m ;i++){
cin >> E[i].u >> E[i].v ;
G[E[i].u].push_back(E[i].v) ;
G[E[i].v].push_back(E[i].u) ;
}
for (int i = 1; i <= n; i++){
cin >> c[i] ;
}
for (int i = 1; i <= n; i++){
dfs(i) ;
}
for (int i = 0; i < m; i++){
if (c[E[i].u] > c[E[i].v] || ans[E[i].u][E[i].v]){
cout << "->\n" ;
}
else {
cout << "<-\n" ;
}
}
return 0 ;
}
/*
2 2 2 1 3
2 2 2 3 1
*/
|
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>
#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;
int H, W;
pair<int, int> Next(int r, int c)
{
if (c == W)
{
return { r + 1, 1 };
}
else
{
return { r, c + 1 };
}
}
LLONG Count(
int r, int c, int remA, int remB,
set<pair<int, int>>& used)
{
auto[nR, nC] = Next(r, c);
// 使用済みは飛ばす
if (used.count({ r, c }))
{
if (r == H && c == W)
{
return 1;
}
return Count(nR, nC, remA, remB, used);
}
// A を使い切ったら残りの敷き方は1通り
if (remA == 0)
{
return 1;
}
// A を使い切れなかったら0通り
if (r == H && c == W && remA != 0)
{
return 0;
}
LLONG ret = 0;
if (remA > 0)
{
// 縦にAを敷く場合
if (r < H && !used.count({ r + 1, c }))
{
used.insert({ r + 1, c });
ret += Count(nR, nC, remA - 1, remB, used);
used.erase({ r + 1, c });
}
// 横にAを敷く場合
if (c < W && !used.count({ r, c + 1 }))
{
used.insert({ r, c + 1 });
ret += Count(nR, nC, remA - 1, remB, used);
used.erase({ r, c + 1 });
}
}
if (remB > 0)
{
ret += Count(nR, nC, remA, remB - 1, used);
}
return ret;
}
int main()
{
int A, B; cin >> H >> W >> A >> B;
set<pair<int, int>> used;
cout << Count(1, 1, A, B, used) << endl;
}
| //#include <atcoder/maxflow.hpp>
#include <memory>
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
#include <complex>
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
typedef long long ll;
using namespace std;
//using namespace atcoder;
//ll modd = 1000 * 1000 * 1000 + 7;
ll modd = 998244353;
int main() {
ios_base::sync_with_stdio(false);
cout.precision(17);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<int> rand_gen(0, modd); // rand_gen(rng) gets the rand no
// auto start = chrono::steady_clock::now();
// readint(test_cases);
int test_cases = 1;
forr(t, 1, test_cases) {
readll(a); readll(b); readll(c);
ll ans = ((a*(a+1))/2) % modd;
ans *= ((b*(b+1))/2) % modd; ans %= modd;
ans *= ((c*(c+1))/2) % modd; ans %= modd;
cout << ans << endl;
}
return 0;
}
// auto stop = chrono::steady_clock::now();
// auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
// cout << "Duration: " << duration.count() << endl;
|
#include<bits/stdc++.h>
using namespace std;
void solve()
{
int a,b;
cin>>a>>b;
cout<<(2*a+100)-b;
}
int main()
{
// int tc;
// cin>>tc;
// while(tc--)
// {
// solve();
// }
solve();
} | #include<bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define ll long long
#define M 998244353
#define pb push_back
#define p_q priority_queue
#define pii pair<ll,ll>
#define vi vector<ll>
#define vii vector<pii>
#define mi map<ll,ll>
#define mii map<pii,ll>
#define all(a) (a).begin(),(a).end()
#define sz(x) (ll)x.size()
#define endl '\n'
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b)) / gcd((a),(b))
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define rep(i, begin, end) for (int i=begin;i<end;i++)
#define repd(i, begin, end) for (int i=end-1;i>=begin;i--)
#define ini(a,n,b) for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a) __builtin_popcountll(a)
#define hell 1000000007
#define re resize
const int INF=1e18;
const int N=300005;
int powm(int a,int b)
{
int res=1;
while(b)
{
if(b&1)
res=(res*a)%M;
a=(a*a)%M;
b>>=1;
}
return res;
}
signed main(void)
{ios
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);freopen("answer.txt", "w", stdout);
#endif
int a,b;
cin>>a>>b;
cout<<2*a+100-b<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using LD = long double;
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }
void Main(){
int h, w; cin >> h >> w;
vvi a(h, vi(w));
int mn = 1e9;
ll tot = 0;
rep(i, h)rep(j, w){
cin >> a[i][j];
chmin(mn, a[i][j]);
tot += a[i][j];
}
tot -= mn * h * w;
cout << tot << endl;
return;
}
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
} | #pragma GCC optimize("Ofast")
//#pragma GCC target ("sse4")
//https://atcoder.jp/contests/abc191/submissions/19973170
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);
ll mod_pow(ll x, ll n, ll m = mod) {
if (n < 0) {
ll res = mod_pow(x, -n, m);
return mod_pow(res, m - 2, m);
}
if (abs(x) >= m)x %= m;
if (x < 0)x += m;
ll res = 1;
while (n) {
if (n & 1)res = res * x % m;
x = x * x % m; n >>= 1;
}
return res;
}
struct modint {
ll n;
modint() :n(0) { ; }
modint(ll m) :n(m) {
if (n >= mod)n %= mod;
else if (n < 0)n = (n % mod + mod) % mod;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
if (n == 0)return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 2;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[a - b];
}
int gcd(int a, int b) {
if (a < b)swap(a, b);
while (b) {
int r = a % b; a = b; b = r;
}
return a;
}
void solve() {
int n; cin >> n;
vector<int> a(n);
rep(i, n)cin >> a[i];
sort(all(a));
vector<int> ds;
rep(i, n) {
for (int j = 1; j <= 32000; j++) {
if (a[i] % j == 0) {
if(j<=a[0])
ds.push_back(j);
if(a[i]/j<=a[0])
ds.push_back(a[i] / j);
}
}
}
unordered_set<int>us;
for(auto & x:ds)us.insert(x);
ds.clear();
for(auto & x:us)ds.push_back(x);
//sort(all(ds));
//ds.erase(unique(all(ds)), ds.end());
int ans = 0;
for (int d : ds) {
if (d > a[0])break;
int g = 0;
rep(j, n) {
if (a[j] % d == 0)g = gcd(g, a[j]);
}
if (g == d)ans++;
}
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
//init_f();
//init();
//expr();
//int t; cin >> t; rep(i,t)
//expr();
solve();
return 0;
} |
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
using namespace std;
int t;
int l,r;
int main(){
scanf("%d",&t);
while(t--){
scanf("%d %d",&l,&r);
int ed=r-l;
ll ans=0;
if(ed>=l) ans+=(ll)(r-l*2+2)*(r-l*2+1)/2;
else ans=0;
printf("%lld\n",ans);
}
return 0;
}
//i:r-l-i+1
//3,
| #include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i,j,n) for(long long i = j ; i < n ; ++i)
#define ones(x) __builtin_popcount(x)
#define endl '\n'
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef deque<int> di;
typedef deque<long long> dll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
/*typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
const ll N = 5e5 + 100;
const ll M = 1e5 + 100;
const ll inf = 1e9;
void solve(){
ll l,r; cin >> l >> r;
if(r < 2*l){
cout << 0 << endl;
return;
}
ll x = r -(2*l-1);
cout << (x*(x+1))/2 << endl;
}
int main(){
fastio;
int t; cin >> t;
while(t--) solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 10;
int n, x[maxn], y[maxn], fa[maxn];
double l, r = 100, ans;
int find(int x) {
if (x == fa[x]) return x; else return fa[x] = find(fa[x]);
}
void merge(int x, int y) {
int kk = find(x), cc = find(y);
if (kk != cc) fa[cc] = kk;
}
bool check(double r) {
for (int i = 1; i <= n + 2; ++i) fa[i] = i;
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
if (sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])) <= r * 2)
merge(i, j);
for (int i = 1; i <= n; ++i)
if (abs(y[i] + 100) <= r * 2)
merge(i, n + 1);
for (int i = 1; i <= n; ++i)
if (abs(y[i] - 100) <= r * 2)
merge(i, n + 2);
if (find(n + 1) != find(n + 2)) return 1; else return 0;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d%d", &x[i], &y[i]);
while (r - l >= (1e-5)) {
double mid = (l + r) / 2;
if (check(mid)) {
ans = mid;
l = mid;
}
else r = mid;
}
printf("%.4lf\n", ans);
return 0;
} | //
// main.cpp
//
#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <inttypes.h>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// #include <atcoder/dsu>
// using namespace atcoder;
// using mint = modint1000000007;
// using mint = modint998244353;
// using mint = modint;
using namespace std;
using ll = int64_t;
using ull = uint64_t;
[[maybe_unused]] constexpr ll LL_MAX = numeric_limits<ll>::max();
[[maybe_unused]] constexpr ll LL_MIN = numeric_limits<ll>::min();
[[maybe_unused]] constexpr ull ULL_MAX = numeric_limits<ull>::max();
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)
template<typename T>
void chmin(T& x, T y) {
x = min(x, y);
}
template<typename T>
void chmax(T& x, T y) {
x = max(x, y);
}
ll csum(ll x, ll y) {
if (x > 0 && y > 0 && x > LL_MAX - y) {
return LL_MAX;
}
if (x < 0 && y < 0 && x < LL_MIN - y) {
return LL_MIN;
}
return x + y;
}
ll readi() {
ll ret;
scanf("%" PRId64 "", &ret);
return ret;
}
vector<ll> readvi(ll n) {
vector<ll> ret(n);
rep(i, 0, n) { ret[i] = readi(); }
return ret;
}
double readf() {
double ret;
scanf("%lf", &ret);
return ret;
}
string reads() {
string s;
cin >> s;
return s;
}
void writei(ll x) {
printf("%" PRId64 "\n", x);
}
void writevi(const vector<ll>& xs) {
rep(i,0,xs.size()) {
if (i < xs.size() - 1) {
printf("%" PRId64 " ", xs[i]);
} else {
printf("%" PRId64 "\n", xs[i]);
}
}
}
void writes(const string& s) {
cout << s.c_str() << endl;
}
void writef(double x) {
printf("%.10f\n", x);
}
template<typename T>
vector<T> make_vec_nd(T init, ll size) {
return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
auto inner = make_vec_nd(init, rest...);
return vector<decltype(inner)>(size, inner);
}
struct UnionFind {
vector<size_t> parent;
vector<size_t> rank;
size_t find_parent(size_t x) {
if (parent[x] == x) {
return x;
} else {
parent[x] = find_parent(parent[x]);
return parent[x];
}
}
explicit UnionFind(size_t size) {
parent.resize(size);
rank.resize(size);
for (size_t i = 0; i < size; i++) {
parent[i] = i;
rank[i] = 0;
}
}
virtual ~UnionFind() {}
void unite(size_t x, size_t y) {
size_t px = find_parent(x);
size_t py = find_parent(y);
if (px == py) {
return;
}
if (rank[px] < rank[py]) {
parent[px] = py;
} else if (rank[px] > rank[py]) {
parent[py] = px;
} else { // rank[px] == rank[py]
parent[py] = px;
rank[px]++;
}
}
bool is_same(size_t x, size_t y) {
return find_parent(x) == find_parent(y);
}
unordered_map<size_t, set<size_t>> create_map_parent_to_elements() {
unordered_map<size_t, set<size_t>> ans;
for (size_t i = 0; i < parent.size(); i++) {
ans[find_parent(i)].insert(i);
}
return ans;
}
};
struct P {
double x;
double y;
double dist(const P& rhs) const {
double sq = (x - rhs.x) * (x - rhs.x) + (y - rhs.y) * (y - rhs.y);
return sqrt(sq);
}
};
int main() {
ll N = readi();
vector<P> pts(N);
rep(i,0,N) {
pts[i].x = readi();
pts[i].y = readi();
}
double good = 0.0;
double bad = 100.0;
while (bad - good > 1.0e-5) {
double mid = (good + bad) / 2;
UnionFind tree(N + 2);
rep(i,0,N) {
P a = pts[i];
rep(j,i+1,N) {
P b = pts[j];
if (a.dist(b) < 2*mid) {
tree.unite(i, j);
}
}
if (a.y + 100 < 2*mid) {
tree.unite(i, N);
}
if (100 - a.y < 2*mid) {
tree.unite(i, N+1);
}
}
if (tree.is_same(N, N+1)) {
bad = mid;
} else {
good = mid;
}
}
writef(good);
}
|
#include <bits/stdc++.h>
//#include <atcoder/modint>
//#include <atcoder/math>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPP(i, n) for(int i = 1; i <= n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
long long c = a % i_7;
if(c >= 0) return c;
return c + i_7;
}
long long po(long a, long b){
if(b == 0) return 1;
long long z = po(a , b / 2);
z = mod(z * z);
if(b % 2 != 0) z = mod(a * z);
return z;
}
bool prime_(int n){
if(n == 1){
return false;
}else if(n == 2){
return true;
}else{
for(int i = 2; i <= std::sqrt(n); i++) if(n % i == 0) return false;
return true;
}
}
long long gcd_(long long a, long long b){
if(a < b) std::swap(a,b);
if(a % b == 0) return b;
else return gcd_(b, a % b);
}
long long lcm_(long long x, long long y){
return (x / gcd_(x,y)) * y;
}
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//using mint = modint998244353;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;
vector<vector<int>> G;
vector<int> in_t, out_t;
vector<vector<int>> d_in_t;
int now;
void dfs(int v = 0, int depth = 0){
in_t[v] = now++;
d_in_t[depth].push_back(in_t[v]);
for(int nxt: G[v]) dfs(nxt, depth + 1);
out_t[v] = now++;
return;
}
int main(){
//using namespace std;
int n;
cin>>n;
G.resize(n);
int p[n];
for(int i = 1; i < n; i++){
cin>>p[i];
p[i]--;
G[p[i]].push_back(i);
}
in_t.resize(n); out_t.resize(n);
d_in_t.resize(n);
now = 0;
dfs();
REP(depth, n) sort(ALL(d_in_t[depth]));
int Q;
cin>>Q;
REP(_, Q){
int u, d;
cin>>u>>d;
u--;
//sort(ALL(d_in_t[d]));
int l = lower_bound(ALL(d_in_t[d]), in_t[u]) - d_in_t[d].begin();
int r = lower_bound(ALL(d_in_t[d]), out_t[u]) - d_in_t[d].begin();
int ans = r - l;
cout << ans << endl;
}
return 0;
} | //REMEMBERING THE PAST , CAN AVOID REPEAT THE SAME
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define inf 10000000000000000
typedef long long ll;
#define mp make_pair
#define f first
#define s second
// DP o Trees::http://cfrp.azurewebsites.net/blog/entry/20935
ll GCD(ll a,ll b){
ll maxi=max(a,b);
ll mini=min(a,b);
while(maxi && mini){
ll t=mini;
mini=maxi%mini;
maxi=t;
}
return max(maxi,mini);
}
ll power(ll x,ll y){
ll res=1;
while (y){
if (y & 1){
res=(res*x);
}
x=(x*x);
y=y>>1;
}
return res;
}
ll ncr(ll x, ll y){
ll ans=1;
y=(y > x-y? x-y: y);
for(ll i=0; i<y; i++){
ans=(ans*(x-i));
ans=(ans/(i+1));
}
return ans;
}
int lower_bound(vector<int> &v,int x){
int l=0,n=v.size(),r=n-1,mid;
int ans=0;
while (l<=r){
mid=l+(r-l)/2;
if (v[mid]>=x){
ans=mid;
r=mid-1;
}
else{
l=mid+1;
}
}
return ans;
}
int upper_bound(vector<int> &v,int x){
int l=0,n=v.size(),r=n-1,mid;
int ans=n;
while (l<=r){
mid=l+(r-l)/2;
if (v[mid]>x){
ans=mid;
r=mid-1;
}
else{
l=mid+1;
}
}
return ans;
}
vector<int> tree[200005];
vector<int> tree1[200005];
int dist[200005];
int in[200005];
int out[200005];
int maxi=0;
int timer=0;
void dfs(int u,int par){
if(par!=-1){
dist[u]=dist[par]+1;
maxi=max(maxi,dist[u]);
}
in[u]=++timer;
tree1[dist[u]].push_back(u);
for(int v:tree[u]){
if(par!=v){
dfs(v,u);
}
}
out[u]=++timer;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,p;
cin>>n;
for(int i=2;i<=n;i++){
cin>>p;
tree[i].push_back(p);
tree[p].push_back(i);
}
memset(dist,0,sizeof(dist));
dfs(1,-1);
int q;
cin>>q;
while(q--){
int u,d;
cin>>u>>d;
if(d>maxi || dist[u]>d){
cout<<"0\n";
}
else{
vector<int> nodes=tree1[d];
int n1=nodes.size(),l=0,r=n1-1,ans1=-1,ans2=-1,mid;
while(l<=r){
mid=l+(r-l)/2;
if(in[nodes[mid]]>=in[u]){
ans1=mid;
r=mid-1;
}
else{
l=mid+1;
}
}
if(ans1==-1){
cout<<"0\n";
continue;
}
l=0;r=n1-1;
while(l<=r){
mid=l+(r-l)/2;
if(in[nodes[mid]]<=out[u]){
ans2=mid;
l=mid+1;
}
else{
r=mid-1;
}
}
if(ans2==-1 || ans1>ans2){
cout<<"0\n";
continue;
}
cout<<ans2-ans1+1<<"\n";
}
}
return 0;
} |
#include <iostream>
using namespace std;
int main(){
int n,m;
cin >> n >> m;
cout << (m % n? "No":"Yes") << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int n;
string s;
int solve();
int main() {
cin >> n >> s;
cout << solve() << endl;
return 0;
}
int solve() {
if (s[0] != s[n - 1]) return 1;
for (int i = 2; i < n; ++i)
if (s[0] != s[i - 1] && s[0] != s[i]) return 2;
return -1;
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FILL0(x) memset(x, 0, sizeof(x))
#define FILL1(x) memset(x, -1, sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template <class T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
if (b < a)
{
a = b;
return 1;
}
return 0;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
int h, w, n, m;
cin >> h >> w >> n >> m;
int grid[h][w];
FILL0(grid);
rep(i, n)
{
int a, b;
cin >> a >> b;
a--;
b--;
grid[a][b] = 1;
}
rep(i, m)
{
int c, d;
cin >> c >> d;
c--;
d--;
grid[c][d] = -1;
}
int grid2[h][w];
rep(i, h)
{
rep(j, w)
{
grid2[i][j]=grid[i][j];
}
}
rep(i, h)
{
ll light = 0;
rep(j, w)
{
if (grid2[i][j] == 0)
{
grid2[i][j] = light;
}
else if (grid2[i][j] == 1)
{
light = 1;
}
else //-1のとき
{
light = 0;
}
}
light = 0;
for (int j = w - 1; j > -1; j--)
{
if (grid2[i][j] == 0)
{
grid2[i][j] = light;
}
else if (grid2[i][j] == 1)
{
light = 1;
}
else //-1のとき
{
light = 0;
}
}
}
rep(j, w)
{
ll light = 0;
rep(i, h)
{
if (grid[i][j] == 0)
{
grid[i][j] = light;
}
else if (grid[i][j] == 1)
{
light = 1;
}
else //-1のとき
{
light = 0;
}
}
light = 0;
for (int i = h - 1; i > -1; i--)
{
if (grid[i][j] == 0)
{
grid[i][j] = light;
}
else if (grid[i][j] == 1)
{
light = 1;
}
else //-1のとき
{
light = 0;
}
}
}
ll ans = 0;
rep(i, h)
{
rep(j, w)
{
if (grid[i][j] == 1 || grid2[i][j]==1)
{
ans++;
}
}
}
cout << ans << endl;
return 0;
}
| #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<vector>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
template<typename T>
using vec = vector<T>;
#define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
void solve(){
}
vec<P> edges[111111];
vec<i64> ans;
i64 n;
void dfs(i64 now){
for(auto v:edges[now]){
i64 to = v.first;
i64 val = v.second;
if(ans[to] != 0)continue;
if(val != ans[now]){
ans[to] = val;
}else{
i64 V = val - 1;
if(V == 0)V = n;
ans[to] = V;
}
dfs(to);
}
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 m;
cin >> n >> m;
ans.resize(n);
rep(i,m){
i64 a,b,c;
cin >> a >> b >> c;
a--;
b--;
edges[a].push_back({b,c});
edges[b].push_back({a,c});
}
ans[0] = 1;
dfs(0);
rep(i,n){
cout << ans[i] << endl;
}
} |
#include<bits/stdc++.h>
using namespace std;
int a,b,ans;
int main() {
scanf("%d %d",&a,&b);
for(int i=1;i<=200000;i++) {
int k=a/i,now;
if(a%i==0) now=i*k;
else now=i*(k+1);
if(a<=now&&now<=b&&a<=now+i&&now+i<=b) ans=i;
}
printf("%d\n",ans);
} | // Author : Jad Isaac
// ID: jadDebugs
// TASK: -----
// LANG: C++
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int, int>
int getMaxGCD(vector<int> arr, int n) {
int high = 0;
for (int i = 0; i < n; i++)
high = max(high, arr[i]);
int divisors[high + 1] = {0};
for (int i = 0; i < n; i++) {
for (int j = 1; j*j <= arr[i]; j++) {
if (arr[i] % j == 0) {
divisors[j]++;
if (j != arr[i] / j)
divisors[arr[i] / j]++;
}
}
}
for (int i = high; i >= 1; i--) {
if (divisors[i] > 1)
return i;
}
return -1;
}
void setIO(string name = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
}
int main()
{
setIO("");
int a, b; cin >> a >> b;
vector<int> arr(b-a+1);
for (int i = a; i <= b; i++)
arr[i-a] = i;
cout << getMaxGCD(arr, b-a+1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve(vector<int64_t> p) {
const int64_t N = p.size();
vector<int64_t> ans;
while (true) {
int64_t target = 0;
while (target < N && p[target] == target) {
//すでに整頓済みだったら終わり
target++;
continue;
}
if (target == N) {
break;
;
}
//整列
//現在位置を探す
int64_t curr_pos = 0;
while (p[curr_pos] != target) {
curr_pos++;
}
if (curr_pos == target) {
break;
}
if (ans.size() % 2 == 0) {
//偶数番目の位置を選んでスワップ可能
if (curr_pos % 2 == 0) {
int64_t i = (p.size() % 2 == 0 ? p.size() - 2 : p.size() - 3);
swap(p[i], p[i + 1]);
ans.push_back(i + 1);
} else {
curr_pos--;
swap(p[curr_pos], p[curr_pos + 1]);
ans.push_back(curr_pos + 1);
}
} else {
//奇数番目の位置を選んでスワップ可能
if (curr_pos % 2 == 1) {
int64_t i = (p.size() % 2 == 0 ? p.size() - 3 : p.size() - 2);
swap(p[i], p[i + 1]);
ans.push_back(i + 1);
} else {
curr_pos--;
swap(p[curr_pos], p[curr_pos + 1]);
ans.push_back(curr_pos + 1);
}
}
}
for (int64_t i = 0; i < N; i++) {
assert(p[i] == i);
}
cout << ans.size() << endl;
assert(ans.size() <= N * N);
for (int64_t i = 0; i < ans.size(); i++) {
cout << ans[i] << " \n"[i == ans.size() - 1];
assert(i % 2 == 1 || (ans[i] % 2 == 1 && 1 <= ans[i] && ans[i] <= N - 1));
assert(i % 2 == 0 || (ans[i] % 2 == 0 && 2 <= ans[i] && ans[i] <= N - 1));
}
}
int main() {
int64_t T;
cin >> T;
while (T--) {
int64_t N;
cin >> N;
vector<int64_t> p(N);
for (int64_t& i : p) {
cin >> i;
i--;
}
solve(p);
}
} | #include<bits/stdc++.h>
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define int long long int
#define pb push_back
#define mpp make_pair
#define F first
#define S second
#define vec vector <int>
#define pr vector<pair<int,int>>
#define vecv vector <vec>
#define vecs vector <string>
#define vecc vector <char>
#define pi 3.141592653589793238
#define mod 1000000007
#define Mod 998244353
#define inf 1e16
#define precise(i) cout<<fixed << setprecision(i);
#define endl "\n"
#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;
#define one cout<<-1<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl;
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl;
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(a) a.begin(),a.end()
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define show_nl(a) for(auto xyz:a)cout<<xyz<<endl;
#define loop(a) for(auto xyz:a)
#define f(i,a,b) for(int i=a;i<b;i++)
#define rf(i,a,b) for(int i=b;i>=a;i--)
const long double eps = 1e-8;
#define lb lower_bound //THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS >= OUR VALUE
#define ub upper_bound //THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS > OUR VALUE
using namespace std;
void solve(){
int n;
cin>>n;
int arr[n];
f(i,0,n)cin>>arr[i];
sort(arr,arr+n);
f(i,1,n+1){
if(arr[i-1]!=i){
no;
return;
}
}
yes;
}
signed main() {
fastio;
int t=1;
while(t--){
solve();
}
} |
#include <bits/stdc++.h>
#define pb push_back
#define sz size()
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <long long> vll;
const int MOD = 1e9 + 7;
const int maxn = 2e5 + 7;
bool cmp(pii a, pii b){
if(a.first > b.first)return true;
else if(a.first == b.first){
if(a.second >= b.second)return false;
else return true;
}
else return false;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
vector <pii> uw(n);
for(int i = 0; i < n; i++){
cin >> uw[i].second >> uw[i].first;
}
vector <int> x(m);
for(int i = 0; i < m; i++){
cin >> x[i];
}
sort(uw.begin(), uw.end());
// for(int i = 0; i < n; i++){
// cout << uw[i].first << ' ' << uw[i].second << '\n';
// }
while(q--){
int l, r;
cin >> l >> r;
l--;
r--;
vector <bool> used(m, false);
int ans = 0;
for(int i = n - 1; i >= 0; i--){
int cursz = uw[i].second;
int curw = uw[i].first;
int mn = MOD;
int mn_ind = -1;
for(int j = 0; j < m; j++){
if(!used[j] && !(j >= l && j <= r) && x[j] >= cursz){
if(mn > x[j]){
mn_ind = j;
mn = x[j];
}
}
}
if(mn_ind != -1){
ans += curw;
used[mn_ind] = true;
}
}
cout << ans << '\n';
}
return 0;
} | #include <bits/stdc++.h>
using ull = unsigned long long int;
using ll = long long;
using ld = long double;
using pii = std::pair<int,int>;
using pll = std::pair<ll, ll>;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using vpll = std::vector<pll>;
using namespace std;
#define rep(i,j) for(int (i)=0;(i)<(j);(i)++)
#define drep(i,j) for(int (i)=(j);(i) >= 0;(i)--)
template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}
template<class T> inline void pri(T a){cout << a << endl;}
template<class Z> using vec = vector<Z>;
template<class T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
inline void IN(void){
return;
}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
cin >> first;
IN(rest...);
return;
}
inline void OUT(void){
cout << endl;
return;
}
template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
cout << first << " " ;
OUT(rest...);
return;
}
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
const int INF = int(1e9);
const long long int INFL = (long long int)1e18;
int n,m,k;
string S;
int ans;
void solve()
{
int N,M,Q; IN(N,M,Q);
vpii lug(N);
vi box(M);
rep(i,N)
{
IN(lug[i].second,lug[i].first);
}
rep(i,M)IN(box[i]);
sort(lug.begin(),lug.end());
reverse(lug.begin(),lug.end());
bool used[M+1];
rep(_,Q)
{
ll ans = 0;
int l,r;
IN(l,r);
l--;
memset(used,0,sizeof(used));
for(int i=l;i<r;i++)used[i] = 1;
rep(i,N)
{
int id = -1;
ll w = INF;
rep(j,M)
{
if(used[j])continue;
if(lug[i].second <= box[j])
{
if(w > box[j])
{
w = box[j];
id = j;
}
}
}
if(id == -1)
{
continue;
}
ans += lug[i].first;
used[id] = 1;
}
cout << ans << endl;
}
}
signed main (int argc, char* argv[])
{
cin.tie(0);
ios::sync_with_stdio(false);
int cases=1;
//IN(cases);
while(cases--)solve();
//pri(ans);
//for(auto c : ans){cout << c << endl;}
//cout << fixed << setprecision(15) << ans << endl;
return 0;
} |
#include <iostream>
using namespace std;
int main(){
int a,b;
cin >> a >> b;
cout << (a+b)/2 << " " << (a-b)/2 << "\n";
}
| /*
これを入れて実行
g++ code.cpp
./a.out
*/
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
return f.second > s.second;
}
ll gcd(ll a, ll b){
if (b == 0)return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b){
return a / gcd(a, b) * b;
}
ll conbinationMemo[100][100];
void cmemoInit(){
rep(i, 100){
rep(j, 100){
conbinationMemo[i][j] = -1;
}
}
}
ll nCr(ll n, ll r){
if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
if(r == 0 || r == n){
return 1;
} else if(r == 1){
return n;
}
return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
ll nPr(ll n, ll r){
r = n - r;
ll ret = 1;
for (ll i = n; i >= r + 1; i--) ret *= i;
return ret;
}
//-----------------------ここから-----------
int main(void){
ll a, b;
cin >> a >> b;
for(ll i = -1000; i < 1000; i++){
for(ll j = -1000; j < 1000; j ++){
if(i + j == a && i - j == b){
cout << i << " " << j << endl;
return 0;
}
}
}
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); i++)
#define rep2(i,n) for (int i=0; i<(n)-1; i++)
using ll = long long;
using P = pair<int,int>;
int main() {
int t; cin >> t;
rep(i,t) {
ll n; cin >> n;
if(n%4 == 0) cout << "Even" << endl;
else if(n%4 == 2) cout << "Same" << endl;
else cout << "Odd" << endl;
}
} | #define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<climits>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<list>
#include<functional>
using namespace std;
#define MAX(A,B) ((A)>(B)?(A):(B))
#define MIN(A,B) ((A)<(B)?(A):(B))
#define LP(I,S,G) for (long long int I = S; I < G; I++)
#define IN(X) for (int i = 0; i < X.size(); i++)cin >> X[i]
#define OUT(X) for (int i = 0; i < X.size(); i++)cout << X[i]<<" "
#define SORT(X) sort(X.begin(), X.end())
#define CSORT(X,Y) sort(X.begin(), X.end(),Y)
#define COPY(X,Y) copy(X.begin(), X.end(), Y.begin())
#define ALL(X,Y) for (auto X = Y.begin(); X != Y.end(); X++)
template<class I1, class I2>
istream& operator>>(istream& s, pair<I1, I2>& in) {
s >> in.first >> in.second;
return s;
}
long long int M = pow(10, 9) + 7;
int main(void) {
string s;
cin >> s;
stack<char> ans;
LP(i, 0, s.size()) {
switch (s[i]) {
case '0':
ans.push('0');
break;
case '1':
ans.push('1');
break;
case '6':
ans.push('9');
break;
case '8':
ans.push('8');
break;
case '9':
ans.push('6');
}
}
while (ans.size() != 0) {
cout << ans.top();
ans.pop();
}
return 0;
} |
/* بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ
( إِنِ الْحُكْمُ إِلَّا لِلَّهِ )
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef unsigned long long ull;
typedef long double ld;
const long double pi=acos(-1);
#define x first
#define y second
#define read(n,a) for(int i=0;i<n;i++)cin>>a[i];
#define rep(i,z,n) for(ll i=z;i<n;i++)
#define rrep(i,z,n) for(ll i=z-1;i>=n;i--)
#define all(v) v.begin(),v.end()
#define clr(v,d) memset(v,d,sizeof(v));
ll a[3002][5];
ll b[200002];
//int dx[] = {0, 0, 1,1, 1,-1,-1,-1};
//int dy[] = {1,-1, 0,1,-1, 0,1 ,-1};
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
string s, ss;
ll n,m,k,w;
ll ans ,ans1;
ll mod = 1e9 +7;
bool can(ll x)
{
set<int>s;
rep(i,0,n)
{
int bit = 0;
rep(j,0,5)bit<<=1 , bit|=a[i][j]>=x;
s.insert(bit);
}
for(auto i : s)for(auto j : s )for(auto k : s)if( (i|j|k) == 31)return 1;
return 0;
}
int main()
{
cin.tie(0);
cin.sync_with_stdio(0);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int t=1;
//cin>>t;
while(t--)
{
cin>>n;
rep(i,0,n)rep(j,0,5)cin>>a[i][j];
ll l = 0 , r= 1e9 , md;
while(l<=r)
{
md=(l+r)/2;
if(can(md))ans=md,l=md+1;
else r=md-1;
}
cout<<ans;
}
return 0;
}
| #include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define pdd pair<double,double>
#define pii pair<int,int>
#define pll pair<LL,LL>
#define mp make_pair
#define LL long long
#define ULL unsigned long long
#define sqr(x) ((x)*(x))
#define pi acosl(-1)
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
#define Point pdd
#define Polygon vector<Point>
#define Line pair<Point,Point>
void solve() {
LL A, B, W;
cin >> A >> B >> W;
W *= 1000;
LL mn = INT_MAX, mx = INT_MIN;
for(LL i = 1; i <= W; i++){
LL avg = W / i, left = W % i;
if(avg < A || (left && avg >= B) || avg > B){
continue;
}
mn = min(i, mn);
mx = max(i, mx);
}
if(mn == INT_MAX){
cout << "UNSATISFIABLE";
}else{
cout << mn << ' ' << mx;
}
}
int main() {
// solve();
int T = 1;
//cin >> T;
for (int i = 0; i < T; ++i) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define re return
#define all(a) a.begin(),a.end()
#define int long long
#define Type int
#define rept(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) rept(i,0,a)
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
vector<int>val;
int l[200005],r[200005],cst[200005];
int n,c;
int use[400005],un[400005],st[400005],tot[400005];
int ans;
void input(){
cin>>n>>c;
rep(i,n){
cin>>l[i]>>r[i]>>cst[i];
val.pb(l[i]),val.pb(r[i]+1);
}
sort(all(val));
val.erase(unique(all(val)),val.end());
rep(i,n){
l[i]=lower_bound(all(val),l[i])-val.begin();
r[i]=lower_bound(all(val),r[i]+1)-val.begin();
st[l[i]]+=cst[i];
st[r[i]]-=cst[i];
}
int k=st[0];
rept(i,1,sz(val)){
int n_cst=min(c,k)*(val[i]-val[i-1]);
k+=st[i];
ans+=n_cst;
}
cout<<ans;
}
signed main()
{
input();
re 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define endl "\n"
void solve(){
ll n,c;
cin>>n>>c;
vector<pair<ll,ll>> arr;
for(ll i=0;i<n;i++){
ll a,b,k;
cin>>a>>b>>k;
arr.push_back({a,k});
arr.push_back({b+1,-k});
}
sort(arr.begin(),arr.end());
ll ans=0,sum=0,t=0;
for(auto [x,y]:arr){
if(x!=t){
ans += min(c,sum)*(x-t);
t=x;
}
sum+=y;
}
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll tc=1;
// cin>>tc;
for(ll t=1;t<=tc;t++){
// cout<<"Case #"<<t<<": ";
solve();
}
} |
#include <bits/stdc++.h>
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define ps(x, y) fixed << setprecision(y) << x
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vp;
// Global
const int INF = 1e18;
void solve() {
int n;
cin >> n;
vi res;
for(int i = 1; i <= sqrt(n); i++) {
if(n % i == 0) {
res.emplace_back(i);
if(n / i != i)
res.emplace_back(n / i);
}
}
sort(all(res));
for(auto &i: res)
cout << i << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
} | //Coded By Vishal Mourya - The Legendary Coder
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define f(var,a,b) for(ll var = a ; var < b ; var++ )
#define fr(var,a,b) for(ll var = a ; var > b ; var-- )
#define fasthoja ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int main(void){
fasthoja;
ll x; cin >> x;
if( x >= 0 ) cout << x << "\n";
else cout << "0\n";
return 0;
} |
#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include "bits/stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define int long long int
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
//typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update>
// ost;
#define rep(i,l,r) for (int i = (l); i < (r); i++)
#define here cout << " Hey!!\n";
#define pb push_back
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define sz(a) (int)((a).size())
#define sq(x) ((x)*(x))
template <typename T>
void etch(T V) {
for (auto x : V) cout << x << ' ' ;
cout << '\n';
}
vector<string> vec_splitter(string s) {
s += ',';
vector<string> res;
while(!s.empty()) {
res.push_back(s.substr(0, s.find(',')));
s = s.substr(s.find(',') + 1);
}
return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
stringstream ss; ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int N = 1500+5;
const int INF = 1000111000111000111LL;
const ld EPS = 1e-12;
const ld PI = 3.141592653589793116;
int a[N][N], vis[N][N][2], col[N][N];
int h, w, n, m;
void travH (int x, int y)
{
for (int ny = y + 1; ny < w; ny++) {
if (vis[x][ny][0] or a[x][ny] == -1) {
break;
} else {
vis[x][ny][0] = col[x][ny] = 1;
}
}
for (int ny = y - 1; ny >= 0; ny--) {
if (vis[x][ny][0] or a[x][ny] == -1) {
break;
} else {
vis[x][ny][0] = col[x][ny] = 1;
}
}
}
void travV (int x, int y)
{
for (int nx = x - 1; nx >= 0; nx--) {
if (vis[nx][y][1] or a[nx][y] == -1) {
break;
} else {
vis[nx][y][1] = col[nx][y] = 1;
}
}
for (int nx = x + 1; nx < h; nx++) {
if (vis[nx][y][1] or a[nx][y] == -1) {
break;
} else {
vis[nx][y][1] = col[nx][y] = 1;
}
}
}
int32_t main()
{
SYNC
cin >> h >> w >> n >> m;
rep(i,0,n) {
int x, y; cin >> x >> y;
x--, y--;
a[x][y] = 1;
}
rep(i,0,m) {
int x, y; cin >> x >> y;
x--, y--;
a[x][y] = -1;
}
rep(i,0,h) {
rep(j,0,w) {
if (a[i][j] == 1) {
col[i][j] = 1;
travV(i, j);
travH(i, j);
}
}
}
// rep(i,0,h) {
// rep(j,0,w) {
// cout << a[i][j] << ' ';
// } cout << '\n';
// }
// cout << '\n';
// rep(i,0,h) {
// rep(j,0,w) {
// cout << col[i][j] << ' ';
// } cout << '\n';
// }
int ans = 0;
rep(i,0,h) {
rep(j,0,w) {
ans += col[i][j];
}
}
cout << ans;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
bool _DD = false;
#define _D(a)if(_DD)cout<<#a<<':'<<a<<" | ";
#define DBG(a){_D(a);if(_DD)cout<<'\n';}
#define DBG2(a,b){_D(a);_D(b);if(_DD)cout<<'\n';}
#define DBG3(a,b,c){_D(a);_D(b);_D(c);if(_DD)cout<<'\n';}
#define DBG4(a,b,c,d){_D(a);_D(b);_D(c);_D(d);if(_DD)cout<<'\n';}
#define DBG5(a,b,c,d,e){_D(a);_D(b);_D(c);_D(d);_D(e);if(_DD)cout<<'\n';}
#define DBG6(a,b,c,d,e,f){_D(a);_D(b);_D(c);_D(d);_D(e);_D(f);if(_DD)cout<<'\n';}
#define PB push_back
#define EB emplace_back
#define btoe(v) (v).begin(),(v).end()
#define etob(v) (v).rbegin(),(v).rend()
#define F first
#define S second
#define SZ size()
typedef unsigned long long int ulli;
typedef long long int lli;
typedef long double ldbl;
#define f(i,a,b) for(int i=(a); i<(b); ++i)
#define fr(i,a,b) for(int i=(a); i>(b); --i)
#define fl(i,a,b) for(lli i=(a); i<(b); ++i)
#define flr(i,a,b) for(lli i=(a); i>(b); --i)
#define w(x) lli x; cin>>x; while(x--)
#define inpn(n,v,T) T n; cin>>n; vector<T> v(n); fl(i,0,n) cin>>v[i];
#define inp(n,v,T) vector<T> v(n); fl(i,0,n) cin>>v[i];
typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<pii> vpii;typedef vector<vector<pii>> vvpii;typedef pair<lli,lli> plli;typedef vector<lli> vlli;typedef vector<vlli> vvlli;typedef vector<plli> vplli;typedef vector<vector<plli>> vvplli;typedef vector<bool> vb;typedef vector<vb> vvb;typedef vector<string> vs;typedef vector<vector<string>> vvs; typedef vector<char> vc; typedef vector<vc> vvc;
#define unmp unordered_map
const lli PRIME = 1000000007ll;
const lli PRIME2 = 998244353ll;
inline void debugORfast(bool a=0,bool b=1){
if(a) _DD=1;
if(b){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
}
//Question Link
int main(int argc,char* argv[])
{
if(argc>1 and strcmp(argv[1],"1")==0) debugORfast(1,1);
else debugORfast(0,1);
int n; cin>>n;
int len = (1<<n);
inp(len,v,int);
vb vis(len,false);
f(i,0,n-1){
int fir = -1;
int ptr = 0;
while(ptr<len){
if(vis[ptr]==false){
if(fir==-1){
fir=ptr;
}else{
int val1 = v[fir];
int val2 = v[ptr];
if(val1>val2){
vis[ptr] = true;
}else{
vis[fir] = true;
}
fir=-1;
}
}
++ptr;
}
}
//f(i,0,vis.SZ) cout<<vis[i]<<' '; cout<<endl;
int ansid=-1,ansval=1e9+1;
f(i,0,len){
if(!vis[i] and v[i]<ansval){
ansval = v[i];
ansid = i;
}
}
cout<<ansid+1<<endl;
return 0;
}
|
#include <bits/stdc++.h>
namespace {
using namespace std;
#define int long long
template<typename T>
inline bool whitespace(const vector<T> &) { return false; }
template<typename T>
inline bool whitespace(const T &) { return true; }
inline bool whitespace(const char) { return false; }
template<typename F, typename S>
inline bool whitespace(const pair<F, S> &) { return false; }
template<typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
os << p.first << (whitespace(p.second) ? " " : "") << p.second << "\n";
return os;
}
template<typename F, typename S>
istream &operator>>(istream &is, pair<F, S> &p) {
is >> p.first >> p.second;
return is;
}
template<typename T>
istream &operator>>(istream &is, vector<T> &v) {
for (T &t : v) is >> t;
return is;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
for (const T &t : v) os << t << (whitespace(t) ? " " : "");
os << "\n";
return os;
}
template<typename T>
istream &operator>>(istream &is, deque<T> &v) {
for (T &t : v) is >> t;
return is;
}
template<typename T>
ostream &operator<<(ostream &os, const deque<T> &v) {
for (const T &t : v) os << t << (whitespace(t) ? " " : "");
os << "\n";
return os;
}
class exit_exception : exception {
};
void answer() {}
template<typename First, typename... Args>
void answer(First &&val, Args &&... ans) {
cout << val << "\n";
answer(ans...);
throw exit_exception();
}
struct autoint {
int x;
autoint(int i) : x(i) {}
autoint() { cin >> x; }
operator int() { return x; }
int operator--() { return --x; }
int operator--(signed) { return x--; }
int operator++() { return ++x; }
int operator++(signed) { return x++; }
};
}
void solve();
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int t = 1;
// cin >> t;
do { try { solve(); } catch (exit_exception &) {}} while (--t);
return 0;
}
void solve() {
autoint h, w;
vector<vector<pair<int, int>>> graph(h * w + 26);
vector<vector<char>> board(h, vector<char>(w));
cin >> board;
int start = 0, finish = 0;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (board[i][j] == 'S') start = i * w + j;
if (board[i][j] == 'G') finish = i * w + j;
vector<int> dx{-1, 0, 1, 0};
vector<int> dy{0, -1, 0, 1};
for (int k = 0; k < 4; ++k) {
int x = i + dx[k], y = j + dy[k];
if (x < 0 || x == h || y < 0 || y == w) continue;
if (board[x][y] == '#' || board[i][j] == '#') continue;
graph[i * w + j].emplace_back(x * w + y, 2);
graph[x * w + y].emplace_back(i * w + j, 2);
}
if ('a' <= (board[i][j]) && board[i][j] <= 'z') graph[i * w + j].emplace_back(h * w + board[i][j] - 'a', 1);
if ('a' <= (board[i][j]) && board[i][j] <= 'z') graph[h * w + board[i][j] - 'a'].emplace_back(i * w + j, 1);
}
}
queue<int> bfs;
bfs.push(start);
vector<int> dist(graph.size(), 1e9);
dist[start] = 0;
while (!bfs.empty()) {
int cur = bfs.front();
bfs.pop();
for (auto next : graph[cur]) {
if (dist[next.first] > dist[cur] + next.second) {
dist[next.first] = dist[cur] + next.second;
bfs.push(next.first);
}
}
}
cout << (dist[finish] == 1e9 ? -1 : dist[finish] / 2) << '\n';
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
const int INF = 5e6;
int di[4] = {1, 0, -1, 0};
int dj[4] = {0, 1, 0, -1};
int main() {
int h, w;
cin >> h >> w;
vector<string> s(h);
rep(i,h) cin >> s[i];
// vector dist(h, vector(w, INF));
vector<vector<int>> dist(h, vector<int>(w, INF));
queue<P> q;
rep(i,h)rep(j,w) {
if (s[i][j] == 'S') {
q.emplace(i,j);
dist[i][j] = 0;
}
}
vector<vector<P>> warps(256);
rep(i,h)rep(j,w) warps[s[i][j]].emplace_back(i,j);
while (!q.empty()) {
auto [i,j] = q.front(); q.pop();
if (s[i][j] == 'G') {
cout << dist[i][j] << endl;
return 0;
}
rep(v,4) {
int ni = i + di[v], nj = j + dj[v];
if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
if (s[ni][nj] == '#') continue;
if (dist[ni][nj] != INF) continue;
dist[ni][nj] = dist[i][j] + 1;
q.emplace(ni,nj);
}
if (islower(s[i][j])) {
for (P p : warps[s[i][j]]) {
int ni = p.first, nj = p.second;
if (dist[ni][nj] != INF) continue;
dist[ni][nj] = dist[i][j] + 1;
q.emplace(ni,nj);
}
warps[s[i][j]] = vector<P>();
}
}
cout << -1 << endl;
return 0;
}
|
/*
author: Taka007
2021.04.11 start
*/
#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
using namespace std;
int64_t Fac(int k) // Definition of "Factorial"
{
return(k==0 ? 1 : k*Fac(k-1));
}
int sum(int l) // Definition of "Sum total"
{
return l*(l+1)/2;
}
int64_t Abs(int m) // Definition of "Absolute value"
{
if(m>=0)
{
return m;
}
else
{
return m*(-1);
}
}
int main(){
int n;
cin>>n;
int answer;
answer=(n-1);
cout<<answer<<endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define ll long long
using namespace std;
using P = pair<int, int>;
int main(){
int n;
cin >> n;
if(n==1) cout << 0 << endl;
else{
cout << n-1 << endl;
}
} |
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end
int main(){
int n,L;
cin>>n>>L;
vector<int> a(n+2),b(n+2);
rep(i,1,n+1)cin>>a[i];
rep(i,1,n+1)cin>>b[i];
a[n+1]=a[n+1]=L+1;
map<int,vector<int>> pos;
rep(i,0,n+2)pos[a[i]-i].push_back(i);
ll res=0;
rep(i,1,n+1){
if(a[i]==b[i])continue;
int x=b[i]-i;
if(x<0 or pos[x].empty()){
puts("-1");
return 0;
}
if(a[i]<b[i]){
if(b[i]==b[i+1]-1){
res++;
continue;
}
int j=pos[x].front();
res+=j-i;
}
else{
if(b[i]==b[i-1]+1){
res++;
continue;
}
int j=pos[x].back();
res+=i-j;
}
}
cout<<res<<'\n';
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using lc = complex<double>;
template<class T>bool chmin(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
int main(void) {
constexpr ll MOD = 1e9 + 7;
constexpr double PI = acos(-1);
cout << fixed << setprecision(32);
cin.tie(0); ios::sync_with_stdio(false);
ll n, l;
cin >> n >> l;
vector<ll> a(n+2), b(n+2);
for(ll i=0; i<n; i++) cin >> a[i+1];
for(ll i=0; i<n; i++) cin >> b[i+1];
a[0] = b[0] = 0;
a[n+1] = b[n+1] = l+1;
n+=2;
ll res = 0;
/* { */
/* ll i = 0; */
/* while(i<n && a[i]>=b[i]) i++; */
/* while(i<n && a[i]<=b[i]) i++; */
/* if(i != n) goto ng; */
/* } */
cerr << "1st" << endl;
{
for(ll i=0; i<n-1; i++) {
if(a[i] < b[i]) {
ll j = upper_bound(a.begin(), a.end(), b[i]) - a.begin();
while(j<n && !(j-i == a[j]-b[i])) j++;
if(j == n) goto ng;
cerr << i << ' ' << j << endl;
res += j-i;
while(i<j && b[i+1] == b[i]+1) i++;
}
}
}
cerr << "2nd" << endl;
{
for(ll i=0; i<n; i++)
a[i] = l+1 - a[i], b[i] = l+1 - b[i];
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
for(ll i=0; i<n-1; i++) {
if(a[i] < b[i]) {
ll j = upper_bound(a.begin(), a.end(), b[i]) - a.begin();
while(j<n && !(j-i == a[j]-b[i])) j++;
if(j == n) goto ng;
cerr << i << ' ' << j << endl;
res += j-i;
while(i<j && b[i+1] == b[i]+1) i++;
}
}
}
cout << res << endl;
return 0;
ng:
cout << -1 << endl;
return 0;
} |
#include <iostream>
#include <iomanip>
#include <cctype>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
#define ll long long
using namespace std;
int main() {
ios::sync_with_stdio(false);
ll n; cin >> n;
ll sum = 0;
vector<ll> a(n); rep(i, n) cin >> a[i];
sort(ALL(a), greater<int>());
rep(i, n - 1){
sum += a[i] * (n - i - 1);
sum -= a[i + 1] * (i + 1);
}
cout << sum << "\n";
return 0;
} | // #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) std::begin(x), std::end(x)
using namespace std;
void dump_func()
{
cerr << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&h, Tail &&... t)
{
cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...);
}
#define dump(...) \
cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), \
cerr << "*/\n\n";
typedef long long ll;
const double G = 0.577215;
const ll INF = 10000000;
ll solve(ll n, ll m, vector<ll> a)
{
map<ll, int> count;
ll tmp = 0;
auto reset = [&]() {
while (count.find(tmp) != count.end())
tmp++;
};
auto decl = [&](ll t) {
assert(count.find(t) != count.end());
count[t] -= 1;
if (count[t] == 0) {
count.erase(t);
if (t < tmp)
tmp = t;
}
};
auto incl = [&](ll t) {
count[t] += 1;
if (t == tmp)
reset();
};
REP(i, m)
{
incl(a[i]);
}
ll res = tmp;
REP3(i, m, n)
{
if (res == 0)
break;
incl(a[i]);
decl(a[i - m]);
res = min(tmp, res);
}
return res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, m;
cin >> n >> m;
vector<ll> a(n);
REP(i, n) cin >> a[i];
ll res = solve(n, m, a);
cout << res << '\n';
return 0;
}
|
#include <stdio.h>
int main(void) {
int n, i;
scanf("%d", &n);
for (i = 1; i <= n; ++i) {
printf("%d %d\n",((i << 1) - 1) % n + 1, (i << 1) % n + 1);
}
return 0;
} | #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//optimal subsequences-2 technocup round-3 2020
using namespace std;
using namespace __gnu_pbds;
const int N=2e5+10;
//#define d double
#define F first
#define S second
#define ll long long int
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(6)
const int M=1e9+7;
//const int M=998244353;
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
//#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)
#define pi pair<ll,ll>
//int MOD=998244353;
//const int MOD=1e9+7;
#define endl "\n"
const double PI = 3.141592653589793238460;
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
//ll d1=304933,d2=4395853;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//bitset<N>bs;
//bitset<512>bb[512];
//vector<vector<int>>arr;
//#ifndef ONLINE_JUDGE
//freopen("input.txt", "r" , stdin);
//freopen("output.txt", "w", stdout);
//#endif
ll MOD;
ll power(ll a,ll b)
{
ll res=1;
if(a==1)return 1;
for(;b>0;b>>=1)
{
if(b&1)res=(res*a);
if(res>MOD)res%=MOD;
a=(a*a);
if(a>MOD)a=a%MOD;
}
return res;
}
bool isPrime[3000000+1];
vector<ll>prime;
vector<int>divisor;
void seive2(int limit)
{
divisor=vector<int>(limit+1,0);
for(int i=2;i<=limit;i++)
{
if(divisor[i]==0)
{
divisor[i]=i;
if(i*1ll*i<=limit)
for(int j=i*i;j<=limit;j+=i)divisor[j]=i;
}
}
}
void seive(int limit)
{
isPrime[0]=isPrime[1]=1;
for(int i=2;i*i<=limit;i++)
{
if(!isPrime[i])
for(int j=i*i;j<=limit;j+=i)
{
isPrime[j]=1;
}
}
for(int i=2;i<=limit;i++)if(!isPrime[i])prime.pb(i);
}
#define pii pair<ll,pi>
ll pt[200010],sz[200010],wt[200010];
int finds(int x)
{
while(pt[x]!=x)
{
pt[x]=pt[pt[x]];
x=pt[x];
}
return pt[x];
}
bool unions(int x,int y)
{
int px=finds(x),py=finds(y);
if(px==py)return 0;
if(sz[px]>sz[py])swap(px,py);
pt[px]=py;
sz[py]+=sz[px];
wt[py]+=wt[px];
return 1;
}
ll bit[200100];
ll query(ll bit[],int x)
{
ll ans=0;
for(int i=x;i>0;i-=(i&(-i))){
ans+=bit[i];
}
return ans;
}
void update(ll bit[],int x,ll val)
{
for(int i=x;i>0;i-=(i&(-i)))
bit[i]+=val;
}
void update2(ll bit[],int x,ll val)
{
for(int i=x;i<=600005;i+=(i&(-i)))
bit[i]+=val;
}
ll query2(ll sum[],int x)
{
ll ans=0;
for(int i=x;i<=200005;i+=(i&(-i)))
ans+=sum[i];
return ans;
}
void dfs(int s,vector<int>&v,vector<int>&P,int visited[])
{
visited[s]=1;
v.pb(s);
int x=P[s];
if(!visited[x])
{
dfs(x,v,P,visited);
}
}
set<ll>st;
void recur(int i,ll no)
{
if(no>=10000)return;
if(i==prime.size())
{
st.insert(no);
return;
}
ll p=no;
recur(i+1,p);
for(int j=0;j<=20;j++)
{
p*=prime[i];
if(p>10000)break;
recur(i+1,p);
}
}
void solve()
{
ll n;cin>>n;
ll sv=n;
seive(100000);
st.insert(6);
st.insert(10);
st.insert(15);
vector<ll>v;
v.pb(6);
v.pb(10);
v.pb(15);
recur(0,6);
recur(0,10);
recur(0,15);
//cout<<st.size()<<endl;
for(auto it:st)
{
if(it!=6 and it!=10 and it!=15)
{
v.pb(it);
}
}
for(int i=0;i<n;i++)cout<<v[i]<<' ';
}
int main()
{
//FastIO;
int t=1;
// cin>>t;
for(int i=1;i<=t;i++)
{
// cout<<"Case #"<<i<<": ";
solve();
//if(i!=t)cout<<endl;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define pii pair<int,int>
#define all(a) a.begin(),a.end()
int bp(int x, int n){
int res = 1;
while(n){
if(n&1) res = res * x;
x *= x; n >>= 1;
}
return res;
}
void solve(){
int n; cin >> n;
for(int i = 1; bp(3,i) <= n; i++){
int x = bp(3,i);
for(int j = 1; bp(5,j) <= n; j++){
int y = bp(5,j);
if(x + y == n){
cout << i << ' ' << j;
return ;
}
}
}
cout << -1;
}
int32_t main(){
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);freopen("answer.txt", "w", stdout);
#endif
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
| //#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <array>
#include <unordered_map>
#include<unordered_set>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<complex>
#include<fstream>
#include<assert.h>
#include<stdio.h>
using namespace std;
#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-16;
signed main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<pii> F(N);
rep(i, 0, N)
{
cin >> F[i].first >> F[i].second;
}
int add = 0;
int UP = INF, DOWN = -INF;
int cons = INF;
rrep(i, 0, N)
{
if (F[i].second == 1)
{
UP -= F[i].first;
DOWN -= F[i].first;
add += F[i].first;
}
if (F[i].second == 2)
{
chmax(DOWN, F[i].first);
if (UP <= DOWN)
{
cons = UP + add;
break;
}
}
if (F[i].second == 3)
{
chmin(UP, F[i].first);
if (UP <= DOWN)
{
cons = DOWN + add;
break;
}
}
}
int Q;
cin >> Q;
rep(i, 0, Q)
{
int x;
cin >> x;
if (cons != INF)
{
cout << cons << endl;
}
else
{
cout << min(UP, max(DOWN, x)) + add << endl;
}
}
return 0;
} |
#include <bits/stdc++.h>
#define fi first
#define se second
#define DB double
#define U unsigned
#define P std::pair
#define LL long long
#define LD long double
#define pb emplace_back
#define MP std::make_pair
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const int MAXN = 2e5 + 5;
int n,m,mid,ans;
std::vector<int> G[MAXN];
int f[MAXN],g[MAXN];
inline void dfs(int v,int fa=0){
f[v] = 1e9;g[v] = -1e9;
for(auto x:G[v]){
if(x == fa) continue;
dfs(x,v);
f[v] = std::min(f[v],f[x]+1);
g[v] = std::max(g[v],g[x]+1);
}
if(f[v] > mid) g[v] = std::max(g[v],0);
if(f[v]+g[v] <= mid) g[v] = -1e9;
if(g[v] == mid) ++ans,g[v] = -1e9,f[v] = 0;
}
inline bool chk(int x){
mid = x;ans = 0;dfs(1);
if(g[1] != -1e9) ++ans;
return ans <= m;
}
int main(){
scanf("%d%d",&n,&m);
FOR(i,2,n){
int u,v;scanf("%d%d",&u,&v);
G[u].pb(v);G[v].pb(u);
}
int l = 0,r = n,ans = -1;
while(l <= r){
int mid = (l + r) >> 1;
if(chk(mid)) ans = mid,r = mid-1;
else l = mid+1;
}
printf("%d\n",ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long
const int N = 200001;
int n, k;
vector <int> v[N];
pair <int, int> dfs(int node, int pnode, int f){
int cnt = 0;
int neg = 0, pos = 0;
for(auto &i : v[node]){
if(i == pnode) continue;
auto c = dfs(i, node, f);
cnt += c.first;
if(c.second < 0) neg = max(neg, -c.second);
else pos = max(pos, c.second);
}
if(pos <= neg - 1) return make_pair(cnt, -(neg - 1));
if(pos == f) return make_pair(cnt + 1, -f);
return make_pair(cnt, pos + 1);
}
int calc(int mid){
auto p = dfs(1, 0, mid);
return p.first + (p.second > 0);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for(int i = 0 ; i < n - 1 ; i++){
int x, y;
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
int l = 1, r = n;
while(l <= r){
int mid = (l + r) / 2;
if(calc(mid) <= k) r = mid - 1;
else l = mid + 1;
}
cout << l << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int A, B;
cin >> A >> B;
cout << 100*(1.0-(double)B/A) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
ll sum=0;
while (t--)
{
ll a, b;
cin>>a>>b;
ll s1=0, s2=0;
if(a!=1)
s1=(a*(a-1))/2;
s2=(b*(b+1))/2;
sum+=(s2-s1);
}
cout<<sum;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
string b[100000];
int n,a[100000],c[10000],m;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>b[i];
cin>>a[i];
c[i]=a[i];
}
sort(c,c+n);
for(int j=1;j<=n;j++){
if(c[n-2]==a[j]){
m=j;
}
}
cout<<b[m]<<endl;;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
signed main(void)
{
int n; cin >> n;
int ans[3000] = {6, 10, 15};
int i = 3;
reps (j, 16, 1000000)
{
if (j%6&&j%10&&j%15) continue;
ans[i] = j;
i++;
if (i > 2505) break;
}
rep (j, n) cout << ans[j] << ' ';
cout << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
vector<vector<int> > v;
for (int i = 0; 8 * i < 1000; i++) {
vector<int> temp(10, 0);
int cnt = 3, cur = 8 * i;
while (cnt)
temp[cur % 10]++, cur /= 10, cnt--;
v.push_back(temp);
}
string s;
cin >> s;
if (s.size() < 3) {
int cur = stoi(s);
if (cur < 10) {
if (cur == 8)
cout << "Yes";
else cout << "No";
return ;
}
int first = cur / 10, second = cur % 10;
if ((first * 10 + second) % 8 == 0 || (second * 10 + first) % 8 == 0) {
cout << "Yes";
return ;
}
cout << "No";
return ;
}
vector<int> cnt(10, 0);
for (auto u : s)
cnt[u - '0']++;
for (auto u : v) {
bool ok = 1;
for (int i = 0; i < 10; i++)
ok &= (u[i] <= cnt[i]);
if (ok) {
cout << "Yes";
return ;
}
}
cout << "No";
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
// int t; cin >> t;
// while (t--)
solve();
} | #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("inline")
// #include<bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
string dfs(int n,string s){
if(n == 1)return s;
while(n%3!=1){
string t;
for(int i=1;i<n;i++){
if(s[i]==s[i-1])t+=s[i];
else {
int x = 'R'+'W'+'B';
x -= s[i] + s[i-1];
t += (char)x;
}
}
swap(t,s);
n--;
}
string t;
for(int i=0;i<n;i+=3)t+=s[i];
return dfs((int)t.size(),t);
}
int main(){
int n;
cin>>n;
string s;
cin>>s;
cout << dfs(n,s) << endl;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e3+5;
const int mod=998244353;
int n,m;
int dp[15][N];
int fac[N],invf[N];
inline int po(int x,int k){
int ret=1;
while(k){
if(k&1) ret=1ll*ret*x%mod;
x=1ll*x*x%mod;
k>>=1;
}
return ret;
}
inline int C(int x,int k){
if(x<k) return 0;
return 1ll*fac[x]*invf[k]%mod*invf[x-k]%mod;
}
int main(){
int i,j,k;
fac[0]=1;
for(i=1;i<N;i++) fac[i]=1ll*fac[i-1]*i%mod;
invf[N-1]=po(fac[N-1],mod-2);
for(i=N-2;i>=0;i--) invf[i]=ll(i+1)*invf[i+1]%mod;
cin>>n>>m;
dp[0][0]=1;
for(i=0;(1<<i)<=m;i++){
for(j=0;j*(1<<i)<=m&&j<=n;j+=2){
for(k=j*(1<<i);k<=m;k++)
dp[i+1][k]=(dp[i+1][k]+1ll*dp[i][k-j*(1<<i)]*C(n,j))%mod;
}
}
cout<<dp[i][m];
return 0;
} | #include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 998244353
#define inf 1000000000000000
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
ll powa(ll a, ll b, ll c)
{
a%=c;
if(a<0)
a+=c;
ll res = 1;
while(b>0)
{
if(b&1)
res*=a, res%=c;
a*=a, a%=c;
b>>=1;
}
return res;
}
ll root = 31;
ll root_1;
ll root_pw = (1ll << 23);
void fft(vector<ll> & a, bool invert) {
ll n = a.size();
for (ll i = 1, j = 0; i < n; i++) {
ll bit = n >> 1;
for (; j & bit; bit >>= 1)
j ^= bit;
j ^= bit;
if (i < j)
swap(a[i], a[j]);
}
for (ll len = 2; len <= n; len <<= 1) {
ll wlen = invert ? root_1 : root;
for (ll i = len; i < root_pw; i <<= 1)
wlen = (ll)(1LL * wlen * wlen % mod);
for (ll i = 0; i < n; i += len) {
ll w = 1;
for (ll j = 0; j < len / 2; j++) {
ll u = a[i+j], v = (ll)(1LL * a[i+j+len/2] * w % mod);
a[i+j] = u + v < mod ? u + v : u + v - mod;
a[i+j+len/2] = u - v >= 0 ? u - v : u - v + mod;
w = (ll)(1LL * w * wlen % mod);
}
}
}
if (invert) {
ll n_1 = powa(n,mod-2,mod);
for (ll & x : a)
x = (ll)(1LL * x * n_1 % mod);
}
}
vector<ll> multiply(vector<ll> const& a, vector<ll> const& b) {
vector<ll> fa(a.begin(), a.end()), fb(b.begin(), b.end());
ll n = 1;
while (n < a.size() + b.size())
n <<= 1;
fa.resize(n);
fb.resize(n);
while(root_pw>n)
{
root_pw>>=1;
root*=root;
root%=mod;
}
//cout<<"root = "<<root<<"\n";
root_1 = powa(root,mod-2,mod);
fft(fa, false);
fft(fb, false);
for (ll i = 0; i < n; i++)
fa[i] *= fb[i], fa[i]%=mod;
fft(fa, true);
root = 31;
root_pw = (1ll << 23);
return fa;
}
ll norm(ll a)
{
a%=mod;
if(a<0)
a+=mod;
return a;
}
ll add(ll a, ll b)
{
a = norm(a);
b = norm(b);
return norm(a+b);
}
ll mul(ll a, ll b)
{
a = norm(a);
b = norm(b);
return norm(a*b);
}
ll sub(ll a, ll b)
{
a = norm(a);
b = norm(b);
return norm(a-b);
}
ll divi(ll a, ll b)
{
b = powa(b,mod-2,mod);
return mul(a,b);
}
#define N 200005
ll fact[N];
ll ifact[N];
ll ncr(ll n, ll r)
{
if(r>n)
return 0;
ll ans = fact[n];
ans*=ifact[r];
ans%=mod;
ans*=ifact[n-r];
ans%=mod;
return ans;
}
#define N1 14
int main()
{
FAST/**/
fact[0] = 1;
for(ll i=1;i<N;i++)
fact[i] = fact[i-1]*i, fact[i]%=mod;
for(ll i=0;i<N;i++)
ifact[i] = powa(fact[i],mod-2,mod);
ll n,m;
cin>>n>>m;
vector<ll> poly(1,1);
for(ll i=0;i<14;i++)
{
vector<ll> poly1(m+1,0);
ll temp = powa(2,i,mod);
for(ll cnt = 0; cnt <= n && cnt <= m/temp; cnt += 2)
{
ll id = cnt*temp;
poly1[id] = ncr(n,cnt);
//cout<<"coeff = "<<poly1[id]<<'\n';
}
poly = multiply(poly, poly1);
while(poly.size()>1 && poly.size()>m+1)
poly.pop_back();
}
ll ans = 0;
if(poly.size()>m)
ans = poly[m];
cout<<ans<<"\n";
return 0;
}
|
// I SELL YOU...!
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(18);
}
const ll INF = 1e15;
ll n,m,maxw=0;
signed main(){
init_io();
cin >> n >> m;
vector<ll> w(n),l(m+1),v(m+1),use(n);
vector<P> lv(m);
for(int i=0;i<n;i++){
cin >> w[i];
maxw = max(maxw,w[i]);
use[i] = i;
}
for(int i=0;i<m;i++){
cin >> lv[i].first >> lv[i].second;
}
sort(lv.begin(),lv.end());
for(int i=m-1;i>=0;i--){
l[i+1] = lv[i].first;
v[i] = lv[i].second;
if(i!=m-1){
v[i] = min(v[i],v[i+1]);
}
}
l[0] = 0;
v[m] = INF;
if(maxw > v[0]){
cout << -1 << endl;
return 0;
}
ll ans = INF;
do{
vector<ll> d(n,0);
for(int i=1;i<n;i++){
ll sum = w[use[i]];
for(int j=i-1;j>=0;j--){
sum += w[use[j]];
auto itr = lower_bound(v.begin(),v.end(),sum);
ll idx = distance(v.begin(),itr);
d[i] = max(d[i],d[j]+l[idx]);
}
}
ans = min(ans,d[n-1]);
}while(next_permutation(use.begin(),use.end()));
cout << ans << endl;
}
| #include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>
#include <ctype.h>
using namespace std;
typedef long long ll;
const int INF = (1<<30)-1;
const ll LINF = 1e18;
#define rep(i, n) for (int i = 0; i < n; i++)
template<class T>
bool chmax(T &a, T b) {if (a < b) {a = b;return true;}else return false;}
template<class T>
bool chmin(T &a, T b) {if (a > b) {a = b;return true;}else return false;}
vector<vector<ll> > memo;
map<ll,ll> mp;
set<pair<ll,ll> > st;
ll func(int i, int j, vector<ll> &s, set<pair<ll,ll> > &st) {
if (memo[i][j] != -1)
return memo[i][j];
auto ite = st.lower_bound(make_pair(s[j+1]-s[i], 0));
ite--;
ll res = mp[ite->first];
for (int k = i+1; k < j; k++)
chmax(res, func(i, k, s, st)+func(k, j, s, st));
return memo[i][j] = res;
}
int main() {
int n, m; cin >> n >> m;
vector<ll> w(n), l(m), v(m);
ll mx = 0;
rep(i, n) {
cin >> w[i];
chmax(mx, w[i]);
}
rep(i, m) {
cin >> l[i] >> v[i];
st.insert(make_pair(v[i], l[i]));
if (mp.count(v[i]))
mp[v[i]] = max(mp[v[i]], l[i]);
else
mp[v[i]] = l[i];
if (v[i] < mx) {
cout << -1 << endl;
return 0;
}
}
mp[0] = 0;
auto pre = mp.begin();
for (auto ite = mp.begin(); ite != mp.end(); ite++) {
if (ite->first == 0) continue;
ite->second = max(ite->second, pre->second);
pre++;
}
st.insert(make_pair(0,0));
sort(w.begin(), w.end());
ll ans = LINF;
do {
vector<ll> s(n+1, 0);
memo.assign(n, vector<ll>(n, -1));
rep(i, n) s[i+1] = s[i] + w[i];
chmin(ans, func(0, n-1, s, st));
} while (next_permutation(w.begin(), w.end()));
cout << ans << endl;
return 0;
}
//小数点精度
//cout << fixed << std::setprecision(15) << y << endl; |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
const int mod = 1e9 + 7;
//const int mod = 998244353;
const int inf = 1e9;
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int m, h;
cin >> m >> h;
if (h % m) cout << "No\n";
else cout << "Yes\n";
} | #include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#include <bitset>
#define INF 100000000000
#define N 200000
#define ll long long
using namespace std;
int main(){
int n,w;
cin>>n>>w;
int ans = n / w;
cout<<ans<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define cm (1 << 17)
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
if (ci - cn == cm) {
fread(cn, 1, cm, stdin);
ci = cn;
}
return *ci++;
}
inline int getint() {
int A = 0;
while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
return A;
}
static struct FastOutput {
static constexpr int BUF_SIZE = 1 << 20;
char buf[BUF_SIZE];
size_t buf_pos = 0;
static constexpr int TMP_SIZE = 1 << 20;
char tmp[TMP_SIZE];
FILE* out = stdout;
inline void put_char(char c) {
buf[buf_pos++] = c;
if (buf_pos == BUF_SIZE) {
fwrite(buf, 1, buf_pos, out);
buf_pos = 0;
}
}
~FastOutput() { fwrite(buf, 1, buf_pos, out); }
inline FastOutput& operator<<(char c) {
put_char(c);
return *this;
}
inline FastOutput& operator<<(const char* s) {
while (*s) {
put_char(*s++);
}
return *this;
}
inline FastOutput& operator<<(const string& s) {
for (int i = 0; i < (int)s.size(); i++) {
put_char(s[i]);
}
return *this;
}
template <typename T>
inline char* integer_to_string(T n) {
// beware of TMP_SIZE
char* p = tmp + TMP_SIZE - 1;
if (n == 0) {
*--p = '0';
} else {
bool is_negative = false;
if (n < 0) {
is_negative = true;
n = -n;
}
while (n > 0) {
*--p = (char)('0' + n % 10);
n /= 10;
}
if (is_negative) {
*--p = '-';
}
}
return p;
}
template <typename T>
inline typename enable_if<is_integral<T>::value, char*>::type stringify(T n) {
return integer_to_string(n);
}
#if !defined(_WIN32) || defined(_WIN64)
inline char* stringify(__int128 n) { return integer_to_string(n); }
#endif
template <typename T>
inline typename enable_if<is_floating_point<T>::value, char*>::type stringify(T n) {
sprintf(tmp, "%.17f", n);
return tmp;
}
template <typename T>
inline FastOutput& operator<<(const T& n) {
auto p = stringify(n);
for (; *p != 0; p++) {
put_char(*p);
}
return *this;
}
} fast_output;
#define cout fast_output
int main() {
// cin.tie(0)->sync_with_stdio(0);
ll n = getint();
vector<ll> a(n), b(n);
vector<vector<ll>> g(n);
for (ll i = 0; i < n - 1; i++) {
a[i] = getint() - 1;
b[i] = getint() - 1;
g[a[i]].push_back(b[i]);
g[b[i]].push_back(a[i]);
}
vector<ll> ans(n), depth(n);
function<void(ll, ll)> Dfs = [&](ll u, ll d) {
depth[u] = d;
for (ll e : g[u]) {
if (e != d) {
ans[e] += ans[u];
Dfs(e, u);
}
}
};
Dfs(0, 0);
ll q = getint();
while (q--) {
ll t = getint(), e = getint() - 1, x = getint();
ll u = a[e], v = b[e];
if (t == 2) swap(u, v);
if (depth[u] == v) {
ans[u] += x;
} else {
ans[0] += x;
ans[v] -= x;
}
}
Dfs(0, 0);
for (ll e : ans) {
cout << e << '\n';
}
}
| // 4-10-2020
// FUN WITH CODE -> GON
// Don't be frustrated
// codeforces
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define nes ios_base :: sync_with_stdio(0); cin.tie(0); cout<<fixed; cout.precision(20);
#define f4(i,k,n) for(int i=k;i<n;++i)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define inf LLONG_MAX
#define dbvi vector<vector<int>>
#define dbvl vector<vector<ll>>
using namespace std;
ll const mo=1e9+7;
ll mod(ll k){
return (k+mo)%mo;
}
ll addmod(ll a,ll b){
return mod(mod(a)+mod(b));
}
ll mulmod(ll a,ll b){
return mod(mod(a)*mod(b));
}
ll submod(ll a,ll b){
return mod(a%mo-b%mo+mo)%mo;
}
int cntpw(ll n){
int cnt=0;
while(n>0){
++cnt;
n/=10;
}
return cnt;
}
void solve(){
int n;
cin>>n;
vector<int>v(n);
for(int i=0;i<n;++i) cin>>v[i];
set<int>se;
int pr=0;
for(int i=0;i<n;++i){
if(pr!=v[i]){
se.insert(v[i]);
cout<<pr<<"\n";
}
else{
++pr;
while(se.count(pr)){
++pr;
}
cout<<pr<<"\n";
//se.insert(pr);
}
}
}
int main(){
nes;
int t=1;
//cin>>t;
for(int i=1;i<=t;++i){
//cout<<"Case #"<<i<<": ";
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
template<typename T>
using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;
const bool DEBUG = 0;
const int MAXN = 100005;
ii solve(ll n, ll m)
{
if(n==0) return {0,1};
if(n&1)
{
ii tmp=solve(n-1, m);
ll k=tmp.F, r=tmp.S;
return {((10*k)%m + (10*r/m)%m)%m, (10*r)%m};
}
else
{
ii tmp=solve(n/2, m);
ll k=tmp.F, r=tmp.S;
return {((2LL*k*r)%m + (r*r/m)%m)%m, (r*r)%m};
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
ll n,m; cin>>n>>m;
cout<<solve(n,m).F<<'\n';
return 0;
}
| /* in the name of Anton */
/*
Compete against Yourself.
Author - Aryan (@aryanc403)
Atcoder library - https://atcoder.github.io/ac-library/production/document_en/
*/
#ifdef ARYANC403
#include <header.h>
#else
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize ("-ffloat-store")
#include<bits/stdc++.h>
#define dbg(args...) 42;
#endif
using namespace std;
#define fo(i,n) for(i=0;i<(n);++i)
#define repA(i,j,n) for(i=(j);i<=(n);++i)
#define repD(i,j,n) for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) ((lli)(x).size())
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"
typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;
const auto start_time = std::chrono::high_resolution_clock::now();
void aryanc403()
{
#ifdef ARYANC403
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end_time-start_time;
cerr<<"Time Taken : "<<diff.count()<<"\n";
#endif
}
const lli INF = 0xFFFFFFFFFFFFFFFL;
lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}
class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{ return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y )); }};
void add( map<lli,lli> &m, lli x,lli cnt=1)
{
auto jt=m.find(x);
if(jt==m.end()) m.insert({x,cnt});
else jt->Y+=cnt;
}
void del( map<lli,lli> &m, lli x,lli cnt=1)
{
auto jt=m.find(x);
if(jt->Y<=cnt) m.erase(jt);
else jt->Y-=cnt;
}
bool cmp(const ii &a,const ii &b)
{
return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}
const lli mod = 1000000007L;
// const lli maxN = 1000000007L;
lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
lli m;
string s;
vi a;
//priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .
int main(void) {
ios_base::sync_with_stdio(false);cin.tie(NULL);
// freopen("txt.in", "r", stdin);
// freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{
cin>>n>>m;
vector<vi> a(n,vi(m,0));
vector<vi> dp(n,vi(m,0));
fo(i,n)
{
cin>>s;
fo(j,m){
if(s[j]=='+')
a[i][j]=1;
else
a[i][j]=-1;
}
}
dbg(a);
repD(i,n-1,0) repD(j,m-1,0){
if(i==n-1&&j==m-1)
continue;
if(i==n-1){
dp[i][j]=a[i][j+1]-dp[i][j+1];
continue;
}
if(j==m-1){
dp[i][j]=a[i+1][j]-dp[i+1][j];
continue;
}
dp[i][j]=max(a[i+1][j]-dp[i+1][j],a[i][j+1]-dp[i][j+1]);
}
dbg(a);
const lli ans=dp[0][0];
if(ans==0){
cout<<"Draw"<<endl;
return 0;
}
if(ans>0){
cout<<"Takahashi"<<endl;
return 0;
}
if(ans<0){
cout<<"Aoki"<<endl;
return 0;
}
} aryanc403();
return 0;
}
|
Subsets and Splits