code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
/*
|| Shree Ganeshay Namah ||
|| Jai Shree Ram ||
|| Nabh Sparsham Diptam ||
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define block 180
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f1 first
#define s1 second
#define pb push_back
// to floor a/b you can do a/b and to ceiling a/b you can do (a+b-1)/b
int jai_shree_ram()
{
return 1;
}
int shree_ganeshay_namah()
{
return 1;
}
ll power(ll x,ll y)
{
ll r=1;
while(y>0)
{
if(y%2!=0)
r=(r * x);
x=(x* x);
y=y/2;
}
return r;
}
ll ncr(ll n,ll k)
{
ll c[k+1];
memset(c,0,sizeof(c));
c[0]=1;
for(ll i=1;i<=n;i++)
{
for(ll j=min(i,k);j>0;j--)
c[j]=(c[j]%mod + c[j-1]%mod)%mod;
}
return c[k];
}
bool prime[1001];
void sieve()
{
ll i,j;
memset(prime,true,sizeof(prime));
prime[0]=false;
prime[1]=false;
for(i=2;i<=sqrt(100);i++)
{
if(prime[i])
{
for(j=i*i;j<=100;j=j+i)
prime[j]=false;
}
}
}
//Start of Matrix Exponentiation Code
void mat_mul(ll F[2][2],ll M[2][2]) {
ll a = ((F[0][0]%mod * M[0][0]%mod)%mod + (F[0][1]%mod * M[1][0]%mod)%mod)%mod;
ll b = ((F[0][0]%mod * M[0][1]%mod)%mod + (F[0][1]%mod * M[1][1]%mod)%mod)%mod;
ll c = ((F[1][0]%mod * M[0][0]%mod)%mod + (F[1][1]%mod * M[1][0]%mod)%mod)%mod;
ll d = ((F[1][0]%mod * M[0][1]%mod)%mod + (F[1][1]%mod * M[1][1]%mod)%mod)%mod;
F[0][0] = a;
F[0][1] = b;
F[1][0] = c;
F[1][1] = d;
}
void mpower(ll F[2][2], ll n) {
if (n == 0 || n == 1)
return;
ll M[2][2] = {{1,1},{1,0}};
mpower(F, n / 2);
mat_mul(F, F);
if (n % 2 != 0)
mat_mul(F, M);
}
ll fib_mat(ll n) {
ll F[2][2] = {{1,1},{1,0}};
if (n == 0)
return 0;
mpower(F, n - 1);
return F[0][0]%mod;
}
//End of Matrix Exponentiation
/*
Segment Tree
ll ar[200005];
ll st[800005];
void build(ll si,ll ss,ll se)
{
if(ss==se)
{
st[si]=ar[ss];
return ;
}
ll mid=(ss+se)/2;
build(2*si,ss,mid);
build(2*si+1,mid+1,se);
st[si]=(st[2*si]+st[2*si+1]);
}
ll query(ll si,ll ss,ll se,ll l,ll r)
{
if(l<=ss && se<=r)
return st[si];
if(l>se || r<ss)
return 0;
ll mid=(ss+se)/2;
ll x=query(2*si,ss,mid,l,r);
ll y=query(2*si+1,mid+1,se,l,r);
return x+y;
}
void update(ll si,ll ss,ll se,ll qi)
{
if(ss==se)
{
st[si]=ar[ss];
return;
}
ll mid=(ss+se)/2;
if(qi<=mid)
update(2*si,ss,mid,qi);
else
update(2*si+1,mid+1,se,qi);
st[si]=st[2*si]+st[2*si+1];
}
*/
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n;
cin>>n;
if(n>=0)
cout<<n;
else
cout<<0;
return 0;
}
| #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;
#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 << ((it != d.b) ? ", " : "") << *it;
}
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main() {
ios_base::sync_with_stdio(false);
int x;
cin >> x;
x = max(x, 0);
cout << x << endl;
} |
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath>
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>
#include <map>
using namespace std;
#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define v_in(v) for(auto&& i : v) cin >> i
#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)
#define ALL(v) v.begin(),v.end()
#define PI 3.14159265358979323846
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
bool is_prime(int n){
if (n <= 1) return false;
if (n == 2) return true;
if (n % 2 == 0) return false;
const int limit = min(((int)sqrt(n))+1,n);
for(int i = 3;i <= limit;i+=2){
if (n % i == 0){
return false;
}
}
return true;
}
//[2,limit]
vector<int> primenumbers(int limit){
vector<int> primes;
for(int i = 2;i <= limit;i++){
if(is_prime(i)){
primes.push_back(i);
}
}
return primes;
}
vector<ll> all_divisors (ll n){
if (n <= 0) return vll();
vll lt_or_eq_sqrt(0); //sqrt以下の約数が入る
vll gt_sqrt(0); //sqrt超過の約数が入る
for(ll i = 1, square_n = sqrt(n);i <= square_n;i++){
if(n % i == 0){
//昇順に入る
lt_or_eq_sqrt.push_back(i);
if(i != n / i){
//降順に入る
gt_sqrt.push_back(n / i);
}
}
}
reverse(ALL(gt_sqrt));
lt_or_eq_sqrt.insert(lt_or_eq_sqrt.end(),ALL(gt_sqrt));
return lt_or_eq_sqrt;
}
int main(void){
FAST_IO
ll n;
cin >> n;
auto v = all_divisors(n);
for(ll i : v){
cout << i << endl;
}
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<long long> enum_divisors(long long N) {
vector<long long> res;
for (long long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
// 重複しないならば i の相方である N/i も push
if (N/i != i) res.push_back(N/i);
}
}
// 小さい順に並び替える
sort(res.begin(), res.end());
return res;
}
int main() {
long long N;
cin >> N;
const auto &res = enum_divisors(N);
for (int i = 0; i < res.size(); ++i) cout << res[i] << "\n";
cout << endl;
} |
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#include <cctype>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
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; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
int main()
{
ll n, a, b; cin >> n >> a >> b;
cout << n - a + b << endl;
system("pause");
}
| #include <bits/stdc++.h>
using namespace std;
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
# define int long long
# define ll long long
#define pb push_back
const int N = 300005,mod = 1e9 + 7;
ll help(ll n,ll m)
{
ll ans=1;
for(ll a=m+1;a<=n;a++)
{
ans*=a;
ans/=(a-m);
}
return ans;
}
signed main(){
gok
int a,b,k;
cin>>a>>b>>k;
k--;
vector<int> v;
int rem = b;
for(int i=1;i<=a+b;i++)
{
int c2 = rem;
int tot = a+b-i+1;
int c1 = tot-c2;
int tm = help(tot-1,c2);
// cout<<tm<<" "<<i<<endl;
if(rem>0 && tm<=k)
{
k -= tm;
v.pb(i);
//cout<<i<<endl;
rem--;
}
}
// cout<<rem<<endl;
int idd = a+b;
while(rem>0 && rem--)
v.pb(idd--);
sort(v.begin(),v.end());
string res="";
int idx=1;
for(int i=1;i<=a+b;i++)
{
if(v[idx-1]==i)
{
res.pb('b');
idx++;
}
else
res.pb('a');
}
cout<<res;
}
|
#include <array>
#include <cstddef>
#include <cstdint>
constexpr std::size_t bsr64(std::uint64_t c) noexcept {
#ifdef __GNUC__
return 63 - __builtin_clzll(c);
#else
constexpr std::array<std::size_t, 64> table = {
0, 1, 2, 7, 3, 13, 8, 27, 4, 33, 14, 36, 9, 49, 28, 19,
5, 25, 34, 17, 15, 53, 37, 55, 10, 46, 50, 39, 29, 42, 20, 57,
63, 6, 12, 26, 32, 35, 48, 18, 24, 16, 52, 54, 45, 38, 41, 56,
62, 11, 31, 47, 23, 51, 44, 40, 61, 30, 22, 43, 60, 21, 59, 58};
c |= c >> 1;
c |= c >> 2;
c |= c >> 4;
c |= c >> 8;
c |= c >> 16;
c |= c >> 32;
return table[((c >> 1) + 1) * 0x218A7A392DD9ABFULL >> 58 & 0x3F];
#endif
}
#include <array>
#include <cstddef>
#include <cstdint>
constexpr std::size_t bsf64(const std::uint64_t c) noexcept {
#ifdef __GNUC__
return __builtin_ctzll(c);
#else
constexpr std::array<std::size_t, 64> table = {
0, 1, 2, 7, 3, 13, 8, 27, 4, 33, 14, 36, 9, 49, 28, 19,
5, 25, 34, 17, 15, 53, 37, 55, 10, 46, 50, 39, 29, 42, 20, 57,
63, 6, 12, 26, 32, 35, 48, 18, 24, 16, 52, 54, 45, 38, 41, 56,
62, 11, 31, 47, 23, 51, 44, 40, 61, 30, 22, 43, 60, 21, 59, 58};
return table[(c & ~c + 1) * 0x218A7A392DD9ABFULL >> 58 & 0x3F];
#endif
}
#include <algorithm>
#include <array>
#include <cstdint>
#include <iostream>
#include <limits>
int main() {
using i64 = std::int64_t;
using u64 = std::uint64_t;
const auto distance = [](u64 a, u64 b) { return a < b ? b - a : a - b; };
u64 X, Y;
std::cin >> X >> Y;
if (X >= Y) {
std::cout << X - Y << std::endl;
return 0;
}
u64 ans = std::numeric_limits<u64>::max();
const auto update = [&](u64 t) { ans = std::min(ans, t); };
const auto check = [&](u64 step) {
const u64 ctz = bsf64(Y);
if (step <= ctz) {
update(distance(X, Y >> step) + step);
return;
}
step -= ctz + 1;
const u64 Y_ = Y >> (ctz + 1);
const u64 stm = ~(~u64(0) << step);
struct elem_t {
u64 cost;
u64 mask;
};
const auto base = [&](const u64 mat_base, const u64 add) {
std::array<std::array<elem_t, 3>, 3> mat = {};
for (int i = 0; i < 3; ++i) {
mat[i][std::min(i + 1, 2)].mask |= mat_base & stm;
mat[i][std::max(i - 1, 0)].mask |= ~mat_base & stm;
mat[i][i].mask |= ~stm;
}
mat[0][1].cost = mat_base & stm;
mat[1][2].cost = mat_base & stm;
const auto iterate = [&](const u64 w, const u64 mask) {
std::array<std::array<elem_t, 3>, 3> sq = {};
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
for (int k = 0; k < 3; ++k) {
u64 temp = (mat[i][j].mask & mask) & (mat[j][k].mask >> w & mask);
temp |= temp << w;
sq[i][k].mask |= temp;
sq[i][k].cost |=
((mat[i][j].cost & mask) + (mat[j][k].cost >> w & mask)) &
temp;
}
}
}
mat = sq;
};
u64 w = 1;
for (; w < step; w *= 2) {
iterate(w, ~u64(0) / ((u64(1) << w) + 1));
}
u64 res = 0;
for (int i = 0; i < 3; ++i) {
res |= mat[1][i].cost & (w * 2 - 1);
}
update(res + ctz + 2 + step + distance(X, (Y_ >> step) + add));
};
base(Y_, 0);
base(~Y_, 1);
};
const i64 bsrY = bsr64(Y);
for (i64 i = bsrY - 2; i <= bsrY + 1; ++i) {
if (0 <= i && i < 64) {
check(i);
}
}
const i64 diff = bsrY - bsr64(X);
for (i64 i = diff - 1; i <= diff + 1; ++i) {
if (0 <= i && i < 64) {
check(i);
}
}
std::cout << ans << std::endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef pair<int,lld> pil;
typedef pair<lld,int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
if(0<=y&&y<n&&0<=x&&x<m) return true;
return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
void solve(int tc){
lld x,y;
cin >> x >> y;
if(x==y){
printf("0");
}else if(y<x){
printf("%lld",x-y);
}else{
lld rans = 1e18;
lld k = 1,e = 0;
while(k*x<=3e18){
lld tot = abs(y - k*x);
lld ans = e + (tot/k);
tot %= k;
while(tot){
if((tot&3)==3){
tot++;
ans++;
}
else if(tot&1){
tot--;
ans++;
}
tot /= 2;
}
rans = min(rans,ans);
k *= 2;
e++;
}
printf("%lld\n",rans);
}
}
int main(void){
/*
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
*/
int tc = 1;
/*
scanf("%d",&tc);
*/
for(int test_number=1;test_number<=tc;test_number++){
solve(test_number);
}
return 0;
} |
#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
long long dp[1000][1000];
vector<int>to[1000][26];
bool memo[1000][1000];
typedef pair<long long, pair<int, int>> P;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
rep(i, M) {
int a, b; char c;
cin >> a >> b >> c;
a--; b--;
to[a][c - 'a'].push_back(b);
to[b][c - 'a'].push_back(a);
memo[a][b] = true;
memo[b][a] = true;
}
rep(i, N) {
rep(j, N) {
dp[i][j] = LINF;
}
}
dp[0][N - 1] = 0;
priority_queue<P, vector<P>, greater<P> > q;//小さいもの順
q.push({ 0,{0,N - 1} });
long long ans = LINF;
while (!q.empty()) {
auto tmp = q.top();
q.pop();
long long cost = tmp.first;
long long x1 = tmp.second.first;
long long x2 = tmp.second.second;
//cout << cost << " " << x1 << " " << x2 << endl;
if (cost > dp[x1][x2]) {
continue;
}
if (x1 == x2) {
ans = min(ans, cost);
continue;
}
if (memo[x1][x2]) {
ans = min(ans, cost + 1);
continue;
}
rep(i, 26) {
if ((to[x1][i].size()) && (to[x2][i].size())) {
//cout << to[x1][i].size() << " " << to[x2][i].size() << endl;
rep(j, to[x1][i].size()) {
rep(k, to[x2][i].size()) {
long long newcost = cost + 2;
int next0 = min(to[x1][i][j], to[x2][i][k]);
int next1 = max(to[x1][i][j], to[x2][i][k]);
//cout << next0 << " " << next1 << endl;
if (newcost < dp[next0][next1]) {
//cout << next0 << "push" << next1 << endl;
dp[next0][next1] = newcost;
q.push({ newcost,{next0,next1} });
}
}
}
}
}
}
if (ans == LINF) {
ans = -1;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using si = set<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<int,int>
#define PLL pair<ll,ll>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define reciv(v,n) vll (v)((n)); rep(i,0,(n))cin>>v[i]
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) ll x;cin >> x
#define cci(x,y) ll x,y;cin >> x >> y
#define co(x) cout << x << endl
#define pb push_back
#define eb emplace_back
#define rz resize
#define pu push
#define sz(x) int(x.size())
#define vij v[i][j]
// ll p = 1e9+7;
// ll p = 998244353;
// n do -> n*pi/180
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl
#define YN cout<<"YES"<<endl;else cout<<"NO"<<endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}
int main(){
cci(x,y);
cii(z);
int ans=0;
rev(i,2e6,0){
if(z*y>x*i){
ans=i;
break;
}
}
co(ans);
} |
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
int main(){
ll t; cin>>t;
ll a;
for(int i = 0; i<t; i++){
cin>>a;
if(a%4==0){
cout<<"Even"<<endl;
}
else if(a%2==0){
cout<<"Same"<<endl;
}
if(a%2!=0){
cout<<"Odd"<<endl;
}
}
}
| /** Created by: Humberto Yusta
Codeforces User: humbertoyusta
Country: Cuba */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline","03") // Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero=upper") // Enable AVX
//#pragma GCC target("avx2") // Enable AVX
//#pragma comment(linker, "/STACK:1024000000,1024000000") // Increase stack limit
//#pragma GCC target("sse,sse2,sse,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") // I don't know what it is
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 1000010;
const int mod = 1000000007;
const int mod2 = 998244353;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 1ll * mod * mod;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long , null_type , less<long long> , rb_tree_tag , tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
if( !e ) return 1;
if( e & 1 ) return qpow(b,e-1) * b % mod;
int pwur = qpow(b,e>>1);
return pwur * pwur % mod;
}
int modinv(int x){ return qpow(x,mod-2); }
bool isprime(int x){
for(int i=2; i*i<=x; i++)
if( x % i == 0 )
return false;
return true;
}
/// My Code -------------------------------------------------
int tc;
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cout.setf(ios::fixed); cout.precision(10);
srand(time(NULL));
//freopen("a.in","r",stdin);
//freopen("a.in","w",stdout);
cin >> tc;
while( tc-- ){
int n;
cin >> n;
if( n % 4 == 0 ){
cout << "Even\n";
continue;
}
if( n % 2 == 0 ){
cout << "Same\n";
continue;
}
cout << "Odd\n";
}
return 0;
}
|
#include <bits/stdc++.h>
#define INF 1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i < b; i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long long int lli;
typedef vector<int> vi;
typedef unordered_map<int,int> umi ;
typedef unordered_set<int> usi ;
typedef pair<int,int> pi;
#include <bits/stdc++.h>
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
//declare here -------------------------------------------------------------
const int N =2e3+1 ;
vector<pair<int,int>> adj[N] ;
priority_queue<pi> q ;
int n,m ;
vi visited(n+1) ;
int mybfs(int x){
visited.assign(n+1,0) ;
//debug(visited) ;
//debug(adj[x],x);
q= priority_queue<pi>() ;
for(auto X:adj[x]){
q.push( MP(- X.F , X.S)) ;
}
while(!q.empty()){
auto temp =q.top() ;
q.pop() ;
if(visited[temp.S]) continue ;
//debug(x,temp.S, temp.F) ;
visited[temp.S] =true ;
if(temp.S== x) return -temp.F ;
for(auto X:adj[temp.S]){
q.push({temp.F - X.F , X.S}) ;
}
}
return -1 ;
}
// solve here --------------------------------------------------------------
void solve(){
cin>>n>>m ;
int u,v,w;
REP(i,0,m){
cin>>u>>v>>w ;
adj[u].PB(MP(w,v)) ;
}
REP(i,1,n+1){
cout<<mybfs(i)<<"\n" ;
}
}
//------------------------------------------------------------------
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
long long test =1 ;
//cin>>test ;
while(test--){
solve() ;
cout<<"\n" ;
}
return 0 ;
} | #include <bits/stdc++.h>
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
//const long long MOD = 998244353;
const long long LINF = 1e18;
using namespace std;
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible" ) << endl
#define dump(x) cout << #x << " = " << (x) << endl
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define COUT(x) cout<<(x)<<endl
#define SCOUT(x) cout<<(x)<<" "
#define VECCOUT(x) for(auto&youso_: (x) )cout<<right<<setw(10)<<youso_<<" ";cout<<endl
#define ENDL cout<<endl
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define mp make_pair
#define PQ priority_queue<long long>
#define PQG priority_queue<long long,V,greater<long long>>
typedef long long ll;
typedef vector<long long> vl;
typedef vector<long long> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef pair<long long, long long> pll;
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
cin>>head;
CINT(move(tail)...);
}
template<class T>
void mod(T &x) {
x %= MOD;
x += MOD;
x %= MOD;
}
ll GCD(ll a, ll b) {
if(b == 0) return a;
else return GCD(b, a%b);
}
ll extGCD(ll a, ll b, ll &x, ll &y) {
if(b == 0) {
x = 1;
y = 0;
return a;
}
ll d = extGCD(b, a%b, y, x);
y -= a/b*x;
return d;
}
void Main() {
LCIN(T);
for(int i = 0; i < T; i++) {
LCIN(N, S, K);
// cout << "–––––––––––––" << endl;
if((N - S)%GCD(N, K)) {
cout << -1 << endl;
} else {
ll x, y;
ll a = extGCD(K, N, x, y), b;
S = N - S;
ll s = S;
ll M = ((S*y)%K - K)%K;
ll tm = S*x - N*((M - S*y)/K);
// cout << "N:" << N << endl;
// cout << "S:" << S << endl;
// cout << "K:" << K << endl;
// cout << "M:" << M << endl;
// cout << "x:" << x << endl;
// cout << "y:" << y << endl;
// cout << "a:" << a << endl;
cout << tm/a << endl;
}
}
}
int main() {
cout << fixed << setprecision(15);
Main();
return 0;
} |
#include<iostream>
using namespace std;
int main(){
int n,w;
cin>>n>>w;
cout<<n/w;
} | #include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long ll;
// DP o Trees::http://cfrp.azurewebsites.net/blog/entry/20935
//********************TRIE******************
struct TrieNode{
struct TrieNode*child[26];
int end=0;
};
struct TrieNode* getnode(){
struct TrieNode* temp=new TrieNode();
for(int i=0;i<26;i++){
temp->child[i]=NULL;
}
return temp;
}
void insert(struct TrieNode* root,string s){
struct TrieNode* temp=root;
for(int i=0;i<s.size();i++){
if(!temp->child[s[i]-'a']){
temp->child[s[i]-'a']=getnode();
}
temp=temp->child[s[i]-'a'];
}
temp->end++;
}
bool search(struct TrieNode*root,string s){
struct TrieNode* temp=root;
for(int i=0;i<s.size();i++){
if(!temp->child[s[i]-'a']){
return false;
}
temp=temp->child[s[i]-'a'];
}
return temp->end;
}
//********************Trie*************
ll GCD(int a,int b){
int maxi=max(a,b);
int mini=min(a,b);
while(maxi && mini){
int 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;
}
int minarr(int arr[],int n){
int d=arr[0];
for(int i=1;i<n;i++){
d=d<arr[i]?d:arr[i];
}
return d;
}
int lower_bound(int v[],int x,int n){
int l=0,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(int v[],int x,int n){
int l=0,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;
}
int maxarr(int arr[],int n){
int d=arr[0];
for(int i=1;i<n;i++){
d=d>arr[i]?d:arr[i];
}
return d;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int a,b;
cin>>a>>b;
cout<<2*a-b+100<<"\n";
return 0;
} |
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 5010
#define mod 998244353
#define LL long long
const int w=15;
int n,m,fac[N],ifac[N],f[20][N];
inline int quick_pow(int x,int b)
{
int ret=1;
while(b)
{
if(b&1) ret=(LL)ret*x%mod;
x=(LL)x*x%mod,b>>=1;
}
return ret;
}
inline int inv(int x) {return quick_pow(x,mod-2);}
void init(int n)
{
fac[0]=1;
for(int i=1;i<=n;++i)
fac[i]=(LL)fac[i-1]*i%mod;
ifac[n]=inv(fac[n]);
for(int i=n;i;--i)
ifac[i-1]=(LL)ifac[i]*i%mod;
}
inline int C(int n,int m)
{
return n<m?0:(LL)fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
inline void add(int &a,int b) {a+=b;if(a>=mod) a-=mod;}
int main()
{
scanf("%d %d",&n,&m);
init(n),f[0][0]=1;
for(int i=0;i<w;++i)
for(int k=0;(1<<i)*k<=m;k+=2)
for(int j=0;j+(1<<i)*k<=m;++j)
add(f[i+1][j+(1<<i)*k],(LL)f[i][j]*C(n,k)%mod);
printf("%d",f[w][m]);
return 0;
} | #include <bits/stdc++.h>
#define int long long
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;
inline int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {if (ch == '-') w = -1; ch = getchar();}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
int const MAXN = 2e5 + 10, mod = 1e9 + 7;
int n, m, T, dp[MAXN][2], cnt[MAXN][2], a[MAXN];
// cnt[i][0] +, cnt[i][1] -
// dp[i][0] +, dp[i][1] -
signed main() {
n = read();
for (int i = 1; i <= n; ++i) a[i] = read();
cnt[1][0] = 1, dp[1][0] = a[1];
for (int i = 2; i <= n; ++i) {
cnt[i][0] = cnt[i - 1][1] + cnt[i - 1][0];
cnt[i][0] %= mod;
cnt[i][1] = cnt[i - 1][0];
cnt[i][1] %= mod;
dp[i][0] = dp[i - 1][0] + dp[i - 1][1] + a[i] * cnt[i][0];
dp[i][0] %= mod;
dp[i][1] = dp[i - 1][0] - a[i] * cnt[i][1];
dp[i][1] %= mod;
}
cout << ((dp[n][0] + dp[n][1] )% mod + mod) % mod;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 1e6 + 100;
int T;
int main() {
int a, b;
cin >> a >> b;
cout << (a + b) / 2 << " " << a - (a + b) / 2 << endl;
return 0;
} | #include <iostream>
using namespace std;
int A,B;
int main(){
cin>>A>>B;
cout<<2*A+100-B;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI 3.14159265358979323846
#define trace1(x) cout<<#x<<": "<<x<<endl
#define trace2(x, y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return a * b / gcd(a, b); }
int bpow(int a,int b)
{
int res = 1;
while (b > 0) {
if (b & 1)res = ((res) * (a));
a = ((a) * (a));
b >>= 1;
}
return res;
}
void go()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
}
signed main()
{
fast_io
go();
int a,b;cin>>a>>b;
if(a==b){
cout << a;
return 0;
}
map<int,int> mp;
mp[0]++;
mp[1]++;
mp[2]++;
mp[a]--;
mp[b]--;
if(mp[0]==0)
mp.erase(0);
if(mp[1]==0)
mp.erase(1);
if(mp[2]==0)
mp.erase(2);
auto it=*mp.begin();
cout << it.first << "\n";
}
| #include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define trace(x) cerr<<#x<<" : "<<x<<endl;
void solve()
{
int a, b;
cin >> a >> b;
if(a==b)
{
cout << a;
}
else
{
if(a==0 && b==1)
cout << 2;
if(a==1 && b==0)
cout << 2;
else if(a==0 && b==2)
cout << 1;
if(a==2 && b==0)
cout << 1;
else if(a==1 && b==2)
cout << 0;
else if(a==2 && b==1)
cout << 0;
}
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
//cin>>t;
for(int i=0;i<t;i++) solve();
return 0;
} |
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <string>
#include <iomanip>
#include <iostream>
#include <map>
#include <unordered_map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define fi first
#define sc second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsort(v) sort(v.rbegin(),v.rend())
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
// const int MOD = 998244353;
const int MOD = 1e9+7;
const int MAX = 2147483647; // 1<<31-1
const int MIN = -2147483648; // 1<<31
const ll INF = 1e18;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
#define ts to_string
string ts(char c) { return string(1, c); }
string ts(bool b) { return b ? "0" : "1"; }
string ts(const char* s) { return (string)s; }
string ts(string s) { return s; }
template<class A, class B> string ts(pair<A, B> p) {
return "("+ts(p.fi)+", "+ts(p.sc)+")";
}
template<class T> string ts(T v) { // containers with begin(), end()
string res = "";
for (const auto& x: v) {
res += ts(x) + " ";
}
return res;
}
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
cerr << ts(h); if (sizeof...(t)) cerr << ", ";
DBG(t...);
}
#ifdef LOCAL
#include "../../snippits/debugger.cpp"
#define dbg(...) cerr << "L(" << __LINE__ << "): [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#define print_segtree(...) 0
#endif
const vector<vector<int>> dirs = { {0,1},{1,0},{-1,0},{0,-1} };
// distance from origin
struct cmp {
bool operator()(const pii& lhs, const pii& rhs) const {
return (abs(lhs.fi)+abs(lhs.sc))<((abs(rhs.fi)+abs(rhs.sc)));
}
};
// getline(cin, str) for getting a line of string
// call cin.ignore() BETWEEEN cin >> x and getline()!!!
// don't mod before you sort!!!
// clear global state
// remember to %= the result!
// INITIALIZE CORRECTLY, ARE YOU DOING (i,0,*N+1*) WHEN NEEDED?
// PRIORITY QUEUES ARE SORTED BIG TO SMALL
// NEVER assign element to a reference and then pop!!!!!
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1;
cin >> t;
ll res = 0;
while (t--) {
int a, b;
cin >> a >> b;
res += 1LL*(a+b)*(b-a+1)/2;
}
cout << res << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){
int n;
std::cin >> n;
ll ans=0;
rep(i,n){
ll a,b;
std::cin >> a>>b;
ll add=(a+b)*(b-a+1)/2;
ans+=add;
}
std::cout << ans << '\n';
return 0;
}
|
#include<bits/stdc++.h>
#include<vector>
#include <iostream>
using namespace std;
using ll = long long;
int main()
{
int x, y;
cin >> x >> y;
if (x != y){
cout << 3 - x - y << endl;
}else{
cout << x << endl;
}
return 0;
} |
//
#include <iostream>
#include <string>
using namespace std;
int main() {
int x, y;
cin >> x >> y;
if (x == y)
cout << x << "\n";
else {
if ((x + 1) % 3 != y) {
cout << ((x+1) % 3) << "\n";
}
else {
cout << ((y+1) % 3) << "\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);
int main() {
int h,w; cin >> h >> w;
vector<string> s(h);
REP(i,h) cin >> s[i];
vecvecl dp(h,vecl(w)), x(h+1,vecl(w+1)), y(h+1,vecl(w+1)), z(h+1,vecl(w+1));
dp[0][0] = 1;
REP(i,h) REP(j,w) {
if(s[i][j] != '#') dp[i][j] += x[i][j] + y[i][j] + z[i][j];
dp[i][j] %= MOD;
if(j+1 < w) {
if(s[i][j+1] != '#') x[i][j+1] = x[i][j] + dp[i][j];
else x[i][j] = 0;
}
x[i][j+1] %= MOD;
if(i+1 < h) if(s[i+1][j] != '#') y[i+1][j] = y[i][j] + dp[i][j]; else y[i+1][j] = 0;
y[i+1][j] %= MOD;
if(i+1 < h && j+1 < w) if(s[i+1][j+1] != '#') z[i+1][j+1] = z[i][j] + dp[i][j]; else z[i+1][j+1] = 0;
z[i+1][j+1] %= MOD;
}
cout << dp[h-1][w-1] << endl;
}
| #include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
int main(){
ll i,j,H,W,r_yoko;;
cin >> H >> W;
vector<vector<ll>> dp(H,vector<ll>(W));
vector<vector<char>> mp(H,vector<char>(W));
dp.at(0).at(0) = 1;
for(i=0;i<H;++i){
for(j=0;j<W;++j){
cin >> mp.at(i).at(j);
}
}
vector<ll> r_nana(H+W-1);
vector<ll> r_tate(W);
for(i=0;i<H;++i){
r_yoko = 0;
for(j=0;j<W;++j){
if(mp.at(i).at(j)=='#'){
r_yoko = 0;
r_tate.at(j)=0;
r_nana.at(j-i+H-1)=0;
continue;
}
dp.at(i).at(j) += r_yoko+r_tate.at(j);
dp.at(i).at(j) += r_nana.at(j-i+H-1);
dp.at(i).at(j) %= MOD;
r_tate.at(j) += dp.at(i).at(j);
r_tate.at(j) %= MOD;
r_yoko += dp.at(i).at(j);
r_yoko %= MOD;
r_nana.at(j-i+H-1) += dp.at(i).at(j);
r_nana.at(j-i+H-1) %= MOD;
}
}
cout << dp.at(H-1).at(W-1) << endl;
return 0;
} |
#include <iostream>
#include <algorithm>
#include <vector>
#define flush fflush(stdout)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod1 = (int)1e9 + 7, mod2 = (int)998244353;
const int INF = (int)1e9;
const int di[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dj[8] = {0, 1, 0, -1, -1, 1, -1, 1};
#define rep0(i, n) for (i = 0; i < n; i++)
#define rep1(i, a, b) for (i = a; i < b; i++)
int main(void){
int i, j;
int n, a[100003] = {};
cin >> n;
rep1(i, 1, n + 1){
a[i] = 1;
}
rep1(i, 1, n + 1){
if (a[i] == 0){
a[i] = 1;
}
j = i * 2;
while (j <= n){
if (a[j] == a[i]){
a[j] = a[i] + 1;
}
j += i;
}
}
rep1(i, 1, n + 1){
cout << a[i] << ((i == n)? endl : ' ');
}
return (0);
} | #include<bits/stdc++.h>
using namespace std;
// 素因数分解
template <typename T>
map<T, T> prime_factor(T n) {
map<T, T> ret;
for (T i = 2; i * i <= n; i++) {
T tmp = 0;
while (n % i == 0) {
tmp++;
n /= i;
}
ret[i] = tmp;
}
if (n != 1) ret[n] = 1;
return ret;
}
template <typename T>
T divisor_num(T N) {
map<T, T> pf = prime_factor(N);
T ret = 1;
for (auto p : pf) {
ret += p.second;
}
return ret;
}
int main(){
int n;
cin>>n;
int count=0;
cout<<1<<" ";
for (int i=2;i<=n;i++){
cout<<divisor_num(i)<<" ";
}
} |
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
//#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <time.h>
//#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
#include <sstream> // std::stringstream
#include <bitset> // std::bitset<N>
//#include <type_traits>
//#include <atcoder/scc>
#define rep(i,n) for(int i=0;i<n;i++)
#define llrep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=b-1;i>=a;i--)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<ll,ll>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define ALL(a) (a).begin(),(a).end()
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
double pi = 3.141592653589793;
using namespace std;
int n;
vll a, b, c, d;
ll dis1(int i, int j) {
return (a[i] - a[j]) * (a[i] - a[j]) + (b[i] - b[j]) * (b[i] - b[j]);
}
ll dis2(int i, int j) {
return (c[i] - c[j]) * (c[i] - c[j]) + (d[i] - d[j]) * (d[i] - d[j]);
}
double angle1(int i, int j) {
double radian = atan2(a[j] - a[i], b[j] - b[i]);
return radian;
}
double angle2(int i, int j) {
double radian = atan2(c[j] - c[i], d[j] - d[i]);
return radian;
}
double rotex(int x, int y, double angle) {
return x * cos(angle) - y * sin(angle);
}
double rotey(int x, int y, double angle) {
return x * sin(angle) + y * cos(angle);
}
int main() {
cin >> n;
if (n == 1) {
cout << "Yes" << endl;
return 0;
}
a.resize(n);
b.resize(n);
c.resize(n);
d.resize(n);
rep(i, n) {
cin >> a[i] >> b[i];
}
rep(i, n) {
cin >> c[i] >> d[i];
}
rep(i, n) {
rep(j, n) {
//0 -> i 1->jに対応する
if (i == j) continue;
if (dis1(0, 1) != dis2(i, j)) continue;
//回転角度
double angle = angle1(0, 1) - angle2(i, j);
auto newx1 = rotex(a[1], b[1], angle);
auto newy1 = rotey(a[1], b[1], angle);
//auto newx1 = a[1] * cos(angle) - b[1] * sin(angle);
//auto newy1 = a[1] * sin(angle) + b[1] * cos(angle);
double q = c[j] - newx1;
double r = d[j] - newy1;;
vector<int> use(n);
/*use[0] = 0;
use[1] = 0;*/
bool F = 1;
rep(k, n) {
auto newx = rotex(a[k], b[k], angle) + q;
auto newy = rotey(a[k], b[k], angle) + r;
bool flg = 0;
rep(m, n) {
if (abs(newx - c[m]) < 0.0000001 && abs(newy - d[m]) < 0.0000001 && use[m] == 0) {
use[m] = 1;
flg = 1;
}
}
if (!flg) {
F = 0;
}
}
if (F == 1) {
cout << "Yes" << endl;
return 0;
}
}
}
cout << "No" << endl;
}
| #include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int A[4];
int main() {
INCANT;
rep(i, 4) cin >> A[i];
sort(A, A+4);
string ans = A[0]+A[3]==A[2]+A[1] || A[3] == A[2]+A[1]+A[0]?"Yes":"No";
cout << ans << "\n";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
void yes(){ cout << "yes" << endl; }
void Yes(){ cout << "Yes" << endl; }
void YES(){ cout << "YES" << endl; }
void no(){ cout << "no" << endl; }
void No(){ cout << "No" << endl; }
void NO(){ cout << "NO" << endl; }
void print(string str){ cout << str << endl;}
#define rep(i, n)for(int i=0; i<n; i++)
#define ll long long
ll inf = 1000000007;
ll INF = 1000000000000000007;
int main(){
ll x, y;
cin >> x >> y;
//
if(x == y){
cout << x << endl;
return 0;
}
cout << 3-(x+y) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main()
{
int n,x,count = 0;
cin >> n >> x;
x *= 100;
int v[n], p[n];
for (int i = 0; i < n; i++)
cin >> v[i] >> p[i];
for (int i = 0; i < n; i++)
{
v[i] *= p[i];
x -= v[i];
count++;
if (x < 0)
{
cout << count << endl;
return (0);
}
}
cout << -1 << endl;
return (0);
} |
//#define _GLIBCXX_DEB // Iterator safety; out-of-bounds access for Containers, etc.
//#pragma GCC optimize "trapv" // abort() on (signed) integer overflow.
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define mod 1000000007
#define deb(x) cout << #x << "=" << x << "\n"
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << "\n"
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.1415926535897932384626
#define INF 1000000000
#define no_of_digits(n) floor(log10(n)) + 1
#define bits(n) __builtin_popcount(n)
#define lsb(n) __builtin_clz(n) // count leading zeroes before 1
#define rsb(n) __builtin_ctz(n) // count trailing zeroes before 1
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
ll g = gcd(a, b);
return a / g * b;
}
int sum_of_digits(int a)
{
int s = 0;
while (a > 0)
{
s += a % 10;
a /= 10;
}
return s;
}
string toBinary(int n)
{
string r;
while (n != 0)
{
r = (n % 2 == 0 ? "0" : "1") + r;
n /= 2;
}
return r;
}
int binaryToDecimal(string n)
{
string num = n;
int dec_value = 0;
int base = 1;
int len = num.length();
for (int i = len - 1; i >= 0; i--)
{
if (num[i] == '1')
dec_value += base;
base = base * 2;
}
return dec_value;
}
ll add(ll a, ll b, ll m = mod)
{
if (a >= m)
a %= m;
if (b >= m)
b %= m;
if (a < 0)
a += m;
if (b < 0)
b += m;
ll res = a + b;
if (res >= m or res <= -m)
res %= m;
if (res < 0)
res += m;
return res;
}
ll mul(ll a, ll b, ll m = mod)
{
if (a >= m)
a %= m;
if (b >= m)
b %= m;
if (a < 0)
a += m;
if (b < 0)
b += m;
ll res = a * b;
if (res >= m or res <= -m)
res %= m;
if (res < 0)
res += m;
return res;
}
ll pow_mod(ll a, ll b, ll m = mod)
{
ll res = 1LL;
a = a % m;
while (b)
{
if (b & 1)
res = mul(res, a, m);
b >>= 1;
a = mul(a, a, m);
}
return res;
}
ll fastexp(ll a, ll b)
{
ll res = 1LL;
while (b)
{
if (b & 1)
res = res * a;
b >>= 1;
a *= a;
}
return res;
}
void solve()
{
string s;
cin>>s;
s='a'+s;
for(int i=1;i<s.length();i++)
{
if(i&1)
{
if(!islower(s[i]))
{
cout<<"No\n";
return;
}
}
else
{
if(!isupper(s[i]))
{
cout<<"No\n";
return;
}
}
}
cout<<"Yes\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input1.txt", "r", stdin);
// for writing output to output.txt
freopen("output1.txt", "w", stdout);
#endif
int t = 1;
//cin >> t;
while (t--)
{
solve();
}
return 0;
} | #include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200008
#define mod 1000000007
#define f first
#define s second
ll arr[sz+10],brr[sz+10];
char c[sz];
int main()
{
int t=1;
//scanf("%d",&t);
while(t--)
{
int n;
scanf("%s",&c);
n=strlen(c);
int cnt=0;
for(int i=0;i<n;i++)
{
if(i%2 && c[i]>='a' && c[i]<='z')
cnt++;
if(i%2==0 && c[i]>='A' && c[i]<='Z')
cnt++;
}
printf("%s\n",cnt?"No":"Yes");
}
return 0;
}
|
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
//#include<atcoder/scc>
using namespace std;
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
const double EPS = 1e-10;
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
int n,m;
vector<vector<Pi>> G;
vector<int> ans;
vector<bool> visited;
void dfs(int u){
visited[u] = true;
for(auto v : G[u]){
if(visited[v.first]) continue;
if(ans[u] != v.second) ans[v.first] = v.second;
else ans[v.first] = n+1-v.second;
dfs(v.first);
}
}
int main(){
cin >> n >> m;
G.resize(n);
ans.resize(n);
visited.resize(n,false);
rep(i,m){
int u,v,c; cin >> u >> v >> c;
u--; v--;
G[u].emplace_back(v,c);
G[v].emplace_back(u,c);
}
ans[0] = G[0][0].second;
dfs(0);
rep(i,n){
cout << ans[i] << endl;
}
}
| #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> II;
void solve(long long N, long long M, std::vector<int> &u, std::vector<int> &v, std::vector<int> &c) {
vector<vector<II>> edges(N);
vector<int> color(N, -1), used(N + 1);
for (int i = 0; i < M; ++i) {
edges[u[i]].emplace_back(II(v[i], c[i]));
edges[v[i]].emplace_back(II(u[i], c[i]));
}
vector<int> q;
q.emplace_back(0);
while (!q.empty()) {
vector<int> nq;
for (auto from : q) {
for (auto kv : edges[from]) {
int to = kv.first, col = kv.second;
if (color[to] >= 0) continue;
if (color[from] == col) {
for (col = 1; col <= N; ++col) {
if (color[from] != col) {
break;
}
}
}
color[to] = col;
used[col] = 1;
nq.emplace_back(to);
}
}
q = nq;
}
for (int i = 1; i <= N; ++i) {
if (!used[i]) {
color[0] = i;
break;
}
}
for (int i = 0; i < N; ++i) {
cout << color[i] << endl;
}
}
int main() {
long long N;
std::cin >> N;
long long M;
std::cin >> M;
std::vector<int> u(M), v(M), c(M);
for (int i = 0; i < M; i++) {
std::cin >> u[i]; u[i]--;
std::cin >> v[i]; v[i]--;
std::cin >> c[i]; // c[i]--;
}
solve(N, M, u, v, c);
return 0;
}
|
#include <iostream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <tuple>
#include <stdlib.h>
#include <stdio.h>
#include <set>
#include <limits>
#include <iomanip>
#include <cstring> //memset
using namespace std;
#define ll long long
#define imi INT_MIN
#define ima INT_MAX
#define llmi LLONG_MIN
#define llma LLONG_MAX
#define dmi (double)llmi
#define dma (double)llma
#define forn(i,a,b) for(ll i = a; i < b; i++)
#define forn2(i,a,b) for(ll i = a; i >= b; i--)
#define fork(i,a,b,k) for(ll i = a; i <= b; i+=k)
#define fork2(i,a,b,k) for(ll i = a; i>=b; i-=k)
#define vl vector<ll>
#define eb emplace_back
#define ef emplace_front
#define ppf pop_front
#define ppb pop_back
#define gt greater<int>()
#define w(t) while(t--)
const int nmax = 2e5+1;
const int mod = 1e9+7;
const double eps = 1e-9;
bool checkPR(ll n) {
ll tmp = sqrt(n);
if(n == 2 || n == 3) return 1;
if(n <= 1 || n == 4) return 0;
if(n%2 == 0 || n%3 == 0) return 0;
fork(i,5,tmp,6) {
if(n%i == 0 || n%(i+2) == 0) return 0;
}
return 1;
}
bool checkSQ(ll n) {
ll tmp = trunc(sqrt(n));
return tmp*tmp == n;
}
int gcd(ll a, ll b) {
if(b == 0) return a;
return gcd(b, a%b);
}
int sumD(ll n) {
int ans = 0;
while(n) {
ans += n%10;
n /= 10;
}
return ans;
}
int cntD(ll n) {
int ans = 0;
while(n) {
ans++;
n/=10;
}
return ans;
}
void setP(int n) {
cout << setprecision(n) << fixed;
}
bool pr[(int)1e6];
void eratos(ll n) {
forn(i,2,sqrt(n)) {
if(!pr[i]) fork(j, i*i, n, i) pr[j] = 1;
}
}
int cntDiv(ll n) {
int ans = 0;
forn(i,1,trunc(sqrt(n))+1) {
if(n%i == 0) ans += 2;
}
if(checkSQ(n)) ans--;
return ans;
}
ll fastMul(ll base, ll p) {
if(p == 1) return base;
ll tmp = fastMul(base, p/2) % mod;
ll res = (tmp*tmp) % mod;
if(p&1) res = (res*base) % mod;
return res;
}
double fastMul(double base, ll p) {
if(p == 1) return base;
double tmp = fastMul(base, p/2);
double res = tmp*tmp;
if(p&1) res *= base;
return res;
}
ll iMod(ll n) {
return fastMul(n, mod-2);
}
struct key {
ll v, pos;
};
struct itv {
ll b, e, pos;
};
bool ss1(key p, key q) {
return p.v < q.v;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
double m,n,x,y,z,t,l;
string s,s1,s2;
cin >> n >> x;
vl v;
forn(i,0,n) {
cin >> y;
if(x != y) v.eb(y);
}
for(auto i: v) cout << i << " ";
} | //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#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()
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n,x;
cin >> n >> x;
vector<int> a(n);
rep(i,n) cin >> a[i];
rep(i,n){
if(a[i]!=x)cout << a[i] << endl;
}
} |
#include<bits/stdc++.h>
#define int long long
#define uc getchar()
#define ph putchar
#define R register
#define CN const
#define rint register int
#define cint const int
#define pe ph('\n')
#define ps ph(' ')
using namespace std;
cint inf=998244353;
cint mix=1e6+5;
inline int in();
inline void out(rint x);
int n=in(),m=in(),ct=1;
int hea[mix],nxt[mix],tor[mix];
int ans[mix],val[mix];
inline void adedge(rint x,rint y){
nxt[++ct]=hea[x],tor[hea[x]=ct]=y;
nxt[ct^=1]=hea[y],tor[hea[y]=ct]=x;
val[ct]=val[ct^1]=in();
}
inline void dfs(rint x){
for(rint u,i=hea[x];i;i=nxt[i])
if(!ans[u=tor[i]]){
if(val[i]!=ans[x])ans[u]=val[i];
else ans[u]=(val[i]%n)+1;
dfs(u);
}
}
#undef int
int main() {
#define int long long
for(rint i=1;i<=m;++i)
adedge(in(),in());
dfs(ans[1]=1);
for(rint i=1;i<=n;++i)
out(ans[i]),pe;
}
inline int in() {
rint x=0;
R char s=uc;
R bool f=0;
while((s<'0'||s>'9')&&s!='-')s=uc;
if(s=='-')f=1,s=uc;
while(s>='0'&&s<='9')(x*=10)+=(s^48),s=uc;
return f?-x:x;
}
inline void out(rint x) {
if(x<0)ph('-'),x=-x;
rint y=x/10;
if(y)out(y);
ph((x-y*10)^48);
} | #define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll mod;
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1ll, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
ll modinv(ll a) { ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }u %= mod; if (u < 0) u += mod; return u; }
vector<vector<pair<int, int>>> G;
vector<int> la;
int n;
void sim(int v) {
for (auto e : G[v]) {
if (la[e.first] == 0) {
if (e.second != la[v])la[e.first] = e.second;
else la[e.first] = la[v] % n + 1;
sim(e.first);
}
}
}
int main() {
int m, a, b, c;
cin >> n >> m;
G.resize(n);
la.resize(n);
rep(i, 0, m) {
cin >> a >> b >> c;
a--, b--;
G[a].push_back({ b, c });
G[b].push_back({ a, c });
}
la[0] = 1;
sim(0);
for (auto v : la)printf("%d\n", v);
return 0;
} |
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for(i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define at(s,pos) *(s.find_by_order(pos))
#define set_ind(s,val) s.order_of_key(val)
long long int M = 1e9 + 7 ;
long long int inf = 9 * 1e18;
const double PI = acos(-1);
//CLOCK
ll begtime = clock();
#define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//CLOCK ENDED
ll n, m;
// modular exponentiation
ll binpow(ll val, ll deg)
{
if (deg < 0)
return 0;
if (!deg)
return 1 % M;
if (deg & 1)
return binpow(val, deg - 1) * val % M;
ll res = binpow(val, deg >> 1);
return (res * res) % M;
}
//binomial
ll modinv(ll n) {
return binpow(n, M - 2);
}
#define tll tuple<ll,ll,ll>
int main() {
// your code goes here
IOS;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll i, j, t, k, x, y, z, N;
ll q;
cin >> n >> q;
vector<ll> vec;
rep(i, n) {
cin >> x;
vec.pb(x);
}
vector<pll> query;
rep(i, q) {
cin >> x;
query.pb({x, i});
}
vector<pll> out;
sortv(query);
ll last = 0;
k = 0;
j = 0;
for (auto u : vec) {
ll rem = u - last - 1;
while (j < query.size()) {
if (query[j].fi <= k + rem) {
out.push_back({query[j].se, last + query[j].fi - k});
}
else break;
j++;
}
last = u;
k += rem;
}
while (j < query.size()) {
out.push_back({query[j].se, last + query[j].fi - k});
j++;
}
sortv(out);
for (auto u : out) {
cout << u.se << '\n';
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
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; }
#define MAX_LL 1000000000000000000
#define MAX_INT 1000000000
#define alfa "abcdefghijklmnopqrstuvwxyz"
#define pi 3.141592653589793
// vector<> dp(100010,1000000000000000)
using p = pair<int,int>;
using graph = vector<vector<int>> ;
int main () {
int n,q;cin >> n >> q;
vector<ll> v (n);
for (ll &i : v)cin >> i;
vector<ll> s (n+1);// 配列の間の個数うの合計
s[0]=v[0]-1;
for (int i = 1; i < n; i++) {
s[i]=s[i-1]+(v[i]-v[i-1]-1);
}
//for (ll i:s)cout << i << endl;
s[n]=MAX_LL*1.3;
for (int i = 0; i < q; i++) {
bool ok = 0;
ll k;cin >> k;
ll t=lower_bound(s.begin(),s.end(),k)-s.begin();
if (t==n)cout << k-s[n-1]+v[n-1] << endl;
else cout << v[t]-1-(s[t]-k) << endl;
}
} |
#include<bits/stdc++.h>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<list>
#include<stack>
#define me(a,b) memset(a,b,sizeof(a));
#define ios ios::sync_with_stdio(0); cin.tie(0),cout.tie(0);
using namespace std;
typedef long long ll;
const int N = 1e7+7;
const double eps = 1e-7;
const double pi=3.1415926;
const ll mod =1000003;
int main(){
ll a,b,c;
int x,y,z;
cin>>a>>b;
ll arr[200005];
ios
for(int i=0;i<200005;i++){
arr[i]=0;
}
for(int i=1;i<=a;i++){
cin>>x>>y>>z;
arr[x]+=z;
arr[y]-=z;
}
ll sum=0;
for(int i=0;i<200005;i++){
sum+=arr[i];
if(sum>b){
cout<<"No";
return 0;
}
}
cout<<"Yes";
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int main() {
int n, m; cin >> n >> m;
int a[n], b[m];
rep(i, n) cin >> a[i];
rep(i, m) cin >> b[i];
set<int> ans;
rep(i, n){
bool flag = true;
rep(j, m){
if(a[i] == b[j]) flag = false;
}
if(flag) ans.insert(a[i]);
}
rep(j, m){
bool flag = true;
rep(i, n){
if(a[i] == b[j]) flag = false;
}
if(flag) ans.insert(b[j]);
}
for(auto x:ans) cout << x << ' ';
cout << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
struct StDish
{
StDish() : m_nDish1(0), m_nDish2(0) { }
int m_nDish1;
int m_nDish2;
};
void input(int& rnDishSiz, vector<StDish>& rvoCond,
vector<StDish>& rvoPutDish)
{
int nCondSiz;
cin >> rnDishSiz >> nCondSiz;
rvoCond.resize(nCondSiz);
for (StDish& roCond : rvoCond)
{
cin >> roCond.m_nDish1 >> roCond.m_nDish2;
--roCond.m_nDish1; --roCond.m_nDish2;
}
int nPutDishSiz;
cin >> nPutDishSiz;
rvoPutDish.resize(nPutDishSiz);
for (StDish& roPutDish : rvoPutDish)
{
cin >> roPutDish.m_nDish1 >> roPutDish.m_nDish2;
--roPutDish.m_nDish1; --roPutDish.m_nDish2;
}
}
int calcMeetCond(const vector<StDish>& cnrvoCond,
const vector<int>& cnrvnSelDish)
{
int nMeetCond = 0;
for (StDish oCond : cnrvoCond)
if ( cnrvnSelDish[ oCond.m_nDish1 ] &&
cnrvnSelDish[ oCond.m_nDish2 ] )
++nMeetCond;
return nMeetCond;
}
int calcMaxMeetCond(int nDishSiz, const vector<StDish>& cnrvoCond,
const vector<StDish>& cnrvoPutDish)
{
int nMaxMeetCond = 0;
for (int nBit = 0; nBit < ( 1 << cnrvoPutDish.size() ); ++nBit)
{
vector<int> vnSelDish(nDishSiz);
for (int nEach = 0; nEach < cnrvoPutDish.size(); ++nEach)
if ( nBit & ( 1 << nEach ) )
vnSelDish[ cnrvoPutDish[nEach].m_nDish2 ] = 1;
else
vnSelDish[ cnrvoPutDish[nEach].m_nDish1 ] = 1;
int nMeetCond = calcMeetCond(cnrvoCond, vnSelDish);
nMaxMeetCond = max(nMaxMeetCond, nMeetCond);
}
return nMaxMeetCond;
}
int main()
{
int nDishSiz;
vector<StDish> voCond, voPutDish;
input(nDishSiz, voCond, voPutDish);
cout << calcMaxMeetCond(nDishSiz, voCond, voPutDish) << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(t) int x;cin>>x;while(x--)
#define pi 2*acos(0.0)
#define bg begin()
#define ed end()
#define all(x) x.begin(),x.end()
#define sortarr(x) sort(x,x+arrsize(x))
#define arrsize(x) sizeof(x)/sizeof(x[0])
#define sortall(x) sort(all(x))
#define formn(m,n) for(m;m<=n;m++)
#define el endl
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define REP(i,a,b) for (int i=a;i<=b;i++)
#define sq(a) (a)*(a)
//solution
int solve(){
set<int> aset;
int n;
cin>>n;
int arr[n],arr2[n];
int c=0,res=0;
int min1=0,min2=0;
REP(i,0,n-1){ cin>>arr[i]; if(arr[i]>min1){min1=arr[i];}}
REP(i,0,n-1){ cin>>arr2[i]; if(arr2[i]>min2){min2=arr2[i];}}
if(min1<min2){
min1 = min2;
}
REP(i,1,min1){
REP(j,0,n-1){
if(i>= arr[j] && i<= arr2[j]){
c=1;
}else{
c=0;
break;
}
}
if(c==1) res++;
c=0;
}
cout<<res;
return 0;
}
//end solution
int main(){
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int) x.size()
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define FOR(i, a, b) for(auto i=(a); i<(b); i++)
#define ROF(i, a, b) for(auto i=(b)-1; i>=(a); i--)
#define F0R(i, n) FOR(i, 0, n)
#define R0F(i, n) ROF(i, 0, n)
using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using pll=pair<ll, ll>;
using vi=vector<int>;
using vl=vector<ll>;
using vpii=vector<pii>;
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 b>a?a=b,1:0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mxN=2e5+10;
const int MOD=1e9+7;
const ll infLL=1e18;
const ld eps=1e-6;
oset<int> o;
int n;
int a[mxN], b[mxN];
map<int, vi> proc;
ll ans;
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
F0R(i, n)
cin >> a[i], a[i]+=i, proc[a[i]].pb(i);
F0R(i, n)
cin >> b[i], b[i]+=i;
for(auto&x:proc) reverse(all(x.s));
F0R(i, n)
o.insert(i);
F0R(i, n){
if(siz(proc[b[i]])==0){
cout << "-1\n"; return 0;
}
int v=proc[b[i]].back(); proc[b[i]].pop_back();
// cout << "V: " << v << endl;
// for(auto x:o) cout << x << ' ';
// cout << endl;
ans+=o.order_of_key(v);
o.erase(v);
}
cout << ans << "\n";
return 0;
}
| #include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int t[55][55];
int p[55][55];
bool bo[2600] = { false };
int b1[4];
int b2[4];
int b3[4] = { 1,-1,0,0 };
int b4[4] = { 0,0,1,-1 };
int b5[4] = { 0,1,2,3 };
int main() {
int x, y;
cin >> x >> y;
stack<pair<int, int>> s;
s.push(make_pair(x, y));
for (int i = 0; i < 50; i++) {
for (int j = 0; j < 50; j++) {
cin >> t[i][j];
}
}
bo[t[x][y]] = true;
for (int i = 0; i < 50; i++) {
for (int j = 0; j < 50; j++) {
cin >> p[i][j];
}
}
string ans = "";
int score = -1000000007;
do {
for (int i = 0; i < 4; i++) {
b1[i] = b3[b5[i]];
b2[i] = b4[b5[i]];
}
string ans1 = "";
int score1 = 0;
while (1) {
int nx = s.top().first;
int ny = s.top().second;
bool bo1 = false;
for (int i = 0; i < 4; i++) {
if (nx + b1[i] < 0 || nx + b1[i] >= 50 || ny + b2[i] < 0 || ny + b2[i] >= 50)continue;
if (!bo[t[nx + b1[i]][ny + b2[i]]]) {
bo[t[nx + b1[i]][ny + b2[i]]] = true;
s.push(make_pair(nx + b1[i], ny + b2[i]));
bo1 = true;
break;
}
}
if (!bo1) {
score1 += p[nx][ny];
while (s.size() > 1) {
s.pop();
if (nx == s.top().first + 1) {
ans1 += 'D';
}
if (nx == s.top().first - 1) {
ans1 += 'U';
}
if (ny == s.top().second + 1) {
ans1 += 'R';
}
if (ny == s.top().second - 1) {
ans1 += 'L';
}
nx = s.top().first;
ny = s.top().second;
score1 += p[nx][ny];
}
reverse(ans1.begin(), ans1.end());
if (score < score1) {
ans = ans1;
score = score1;
}
break;
}
}
while (!s.empty()) {
s.pop();
}
s.push(make_pair(x, y));
for (int i = 0; i <= 2500; i++) {
bo[i] = false;
}
bo[t[x][y]] = true;
} while (next_permutation(b5, b5 + 4));
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
// using mint2 = modint998244353;
typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;
//const Int mod = 998244353;
typedef struct {
int64_t to, weight;
} edge;
Int dx[] = {0, 1, 0, -1, -1, 1, -1, 1};
Int dy[] = {1, 0, -1, 0, -1, -1, 1, 1};
template<class T>
istream &operator>>(istream &is, vector<T> &v) {
for (auto &e : v) {
is >> e;
}
return is;
}
bool print_space_enable = false;
void print() {
std::cout << '\n';
print_space_enable = false;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
if (print_space_enable) std::cout << " ";
std::cout << fixed << setprecision(15) << head;
print_space_enable = true;
print(std::forward<Tail>(tail)...);
}
template<typename T>
void print(vector<T> v) {
for (size_t i = 0; i < v.size(); i++) {
if (i > 0) std::cout << " ";
std::cout << v[i];
}
std::cout << '\n';
}
template<class T>
vector<T> make_vec(size_t n, T val) {
return vector<T>(n, val);
}
template<class... Ts>
auto make_vec(size_t n, Ts... ts) {
return vector<decltype(make_vec(ts...))>(n, make_vec(ts...));
}
bool is_overflow(Int a, Int b) {
return a > INF / b;
}
void solve() {
Int t, n;
cin >> t >> n;
n *= 100;
double a = (n - 1) / t;
double b = a * (100.0 + (double)t) / 100.0;
Int res = ceil(b);
print(res);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
//Int _t; cin >> _t; while (_t--) solve();
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int64_t t;cin>>t;
int64_t N;cin>>N;
int64_t ans=N*100+t-1;
ans/=t;
cout<<(ans+N-1)<<"\n";
return 0;
}
|
#include <iostream>
#include <stdio.h>
#include <climits>
#include <vector>
#include <queue>
#include <array>
//martin02
using namespace std;
int main() {
long long int k, n, m;
scanf("%lld %lld %lld", &k, &n, &m);
vector<long long int> a(k);
vector<long long int> b(k);
priority_queue<array<long double, 2>> pq;
for (int i = 0; i < k; i++) {
scanf("%lld", &a.at(i));
}
long long int r = m;
for (int i = 0; i < k; i++) {
b.at(i) = (m * a.at(i)) / n;
r -= b.at(i);
pq.push({ (long double)a.at(i) / (long double)n - (long double)b.at(i) / (long double)m, (long double) i });
}
while (r != 0) {
array<long double, 2> f = pq.top();
pq.pop();
b.at(f.at(1)) += 1;
pq.push({ (long double)a.at(f.at(1)) / (long double)n - (long double)b.at(f.at(1)) / (long double)m, f.at(1) });
r--;
}
for (int i = 0; i < k; i++) {
printf("%lld ", b.at(i));
}
printf("\n");
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <chrono>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define int long long
#define fin cin
#define fout cout
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
#define all(x) x.begin(), x.end()
#define left vadia
#define right puta
using namespace std;
void setIO(string s) {
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
typedef pair<ll, ll> pii;
typedef vector<vector<char>> mat;
typedef pair<int, string> pis;
const ll mod = 1e9+7;
const int MAXN = 1e4+5;
typedef vector<int> vi;
typedef pair<int, pair<int, int>> piii;
int32_t main() {
int tot = 0, ans = 0, kek = 0;
int n;
cin >> n;
vi v(n);
for(int &i : v)
cin >> i;
for(int i = 2; i <= 1000; kek = 0, i++) {
for(int &j : v) {
kek += (j % i == 0);
}
if(kek > tot) tot = kek, ans = i;
}
cout << ans << endl;
}
|
//@formatter:off
#include<bits/stdc++.h>
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(i,n) for (ll i = 0; i < ll(n); ++i)
#define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i)
#define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d)
#define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(i,n) for (ll i = ll(n)-1; i >= 0; i--)
#define rrep2(i,n,t) for (ll i = ll(n)-1; i >= (ll)t; i--)
#define rrep3(i,n,t,d) for (ll i = ll(n)-1; i >= (ll)t; i-=d)
#define rrep(...) overload4(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define popcount(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#ifdef __LOCAL
#define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; }
#else
#define debug(...) void(0)
#endif
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;
using LP = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vs = vector<string>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vp = vector<P>;
using vvp = vector<vector<P>>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
template<class T> void vecout(const vector<T> &v,char div='\n') { rep(i,v.size()) cout<<v[i]<<(i==int(v.size()-1)?'\n':div);}
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
void scan(){}
template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); }
template<class T> void print(const T& t){ cout << t << '\n'; }
template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); }
template<class... T> void fin(const T&... a) { print(a...); exit(0); }
struct Init_io {
Init_io() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout << boolalpha << fixed << setprecision(15);
}
} init_io;
const string yes[] = {"no","yes"};
const string Yes[] = {"No","Yes"};
const string YES[] = {"NO","YES"};
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on
int main() {
LL(a, b);
rrep(i, b + 1) {
ll mn = (a + i - 1) / i * i;
mn += i;
if (mn <= b) fin(i);
}
}
| #include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<ll,ll>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = (1 << 30) - 1;
const ll INFL = 1LL << 60;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
int main(){
VI a(3);
REP(i, 3)cin >> a[i];
sort(ALL(a));
cout << a[1] + a[2] << endl;
} |
#include<iostream>
#include<cstdio>
using namespace std;
struct Edge{
int to,nxt;
}e[400005];
int n,k,h[200005],num,f[200005],g[200005],cnt;
void add(int u,int v){
e[++num].to=v;
e[num].nxt=h[u];
h[u]=num;
}
void dfs(int u,int fa,int lim){
int i,v;
f[u]=1e9;
g[u]=0;
for(i=h[u];i;i=e[i].nxt){
v=e[i].to;
if(v!=fa){
dfs(v,u,lim);
f[u]=min(f[u],f[v]+1);
g[u]=max(g[u],g[v]+1);
}
}
if(f[u]+g[u]<=lim)
g[u]=-1e9;
if(g[u]>=lim)
++cnt,f[u]=0,g[u]=-1e9;
}
bool judge(int lim){
cnt=0;
dfs(1,0,lim);
return (cnt+(g[1]>=0))<=k;
}
int solve(){
int l=1,r=n,mid,res;
while(l<=r){
mid=(l+r)>>1;
if(judge(mid))
r=mid-1,res=mid;
else
l=mid+1;
}
return res;
}
int main(){
ios::sync_with_stdio(false);
int i,u,v;
cin>>n>>k;
for(i=1;i<n;i++){
cin>>u>>v;
add(u,v);add(v,u);
}
cout<<solve()<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------
int N,K,V;
vector<int> E[202020];
int need[202020],aff[202020];
int num;
void dfs(int cur,int pre) {
need[cur]=0;
aff[cur]=-1;
FORR(e,E[cur]) if(e!=pre) {
dfs(e,cur);
if(aff[e]>=0) aff[cur]=max(aff[cur],aff[e]-1);
if(need[e]>=0) need[cur]=max(need[cur],need[e]+1);
}
if(aff[cur]>=need[cur]) {
need[cur]=-1;
}
else {
if(need[cur]>=V) {
need[cur]=-1;
aff[cur]=V;
num++;
}
else {
aff[cur]=-1;
}
}
}
int ok(int v) {
if(v<=0) return 0;
V=v;
num=0;
dfs(0,0);
if(need[0]>=0) num++;
return num<=K;
}
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N>>K;
FOR(i,N-1) {
cin>>x>>y;
E[x-1].push_back(y-1);
E[y-1].push_back(x-1);
}
int ret=N;
for(j=20;j>=0;j--) if(ok(ret-(1<<j))) ret-=1<<j;
cout<<ret<<endl;
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int main() {
ios::sync_with_stdio(0), cin.tie(0);
char c, d; cin >> c >> d;
if(c == 'Y') if(d >= 97) d -= 32;
cout << d;
} | #include<bits/stdc++.h>
#define FastRead \
ios_base::sync_with_stdio(false); \
cin.tie(0);
#define ll long long
#define endl "\n"
#define f for
#define ml ll t,g; cin>>t; f(g=0;g<t;g++)
#define pi acos(-1)
using namespace std;
bool cmp(const pair<string,ll> &a,
const pair<string,ll> &b)
{
if(a.second!=b.second)
return (a.second > b.second);
else
return (a.first < b.first);
}
int main()
{
FastRead
ll a,b;
cin>>a>>b;
cout<<((2*a)+100)-b;
return 0;
}
|
#include <bits/stdc++.h>
typedef long long ll;
const int N = 100;
const int S = N * N;
const int P = 998244353;
inline int norm(int x) {if (x >= P) x -= P; return x;}
inline int reduce(int x) {if (x < 0) x += P; return x;}
inline void add(int &x, int y) {if ((x += y) >= P) x -= P;}
inline void sub(int &x, int y) {if ((x -= y) < 0) x += P;}
int mpow(int b, int p) {
int r = 1;
for (; p; p >>= 1, b = (ll)b * b % P)
if (p & 1) r = (ll)r * b % P;
return r;
}
int fct[N + 5];
int f[N + 5][N + 5][2*S + 5], w[N + 5], n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &w[i]);
fct[0] = 1; for (int i = 1; i <= n; i++) fct[i] = (ll)fct[i - 1] * i % P;
f[0][0][S] = 1;
for (int i = 0; i < n; i++) for (int j = 0; i + j < n; j++) {
int p = w[i + j + 1];
for (int k = p; k <= (S << 1); k++) add(f[i + 1][j][k], f[i][j][k - p]);
for (int k = (S << 1) - p; k >= 0; k--) add(f[i][j + 1][k], f[i][j][k + p]);
}
int ans = 0;
for (int i = 0; i <= n; i++) ans = (ans + (ll)fct[i] * fct[n - i] % P * f[i][n - i][S]) % P;
printf("%d\n", ans);
} | #define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define MOD 998244353
long long pow_mod(long long x, long long y) {
int res = 1;
while (y) {
if (y & 1)res = (res * x) % MOD;
y >>= 1;
x = (x * x) % MOD;
}
return res;
}
long long inv_mod(long long a) {
return pow_mod(a,MOD-2);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
rep(i, n)cin >> a[i];
map<int, int> mp;
rep(i, n) {
mp[a[i]]++;
}
int cnt = 0;
long long sum = 0;
for (auto p : mp) {
long long c = p.first * pow_mod(2, cnt) % MOD * (pow_mod(2, p.second) - 1) % MOD;
sum += c;
cnt += p.second;
}
sum %= MOD;
long long ans = 0;
long long inv2 = inv_mod(2);
for (auto p : mp) {
sum -= p.first * (pow_mod(2, p.second) - 1) % MOD;
sum *= pow_mod(inv2, p.second);
sum = (sum % MOD + MOD) % MOD;
ans += p.first * (pow_mod(2, p.second) - 1) %MOD * sum % MOD;
}
for (auto p : mp) ans += (long long)p.first * p.first % MOD * (pow_mod(2, p.second) - 1) % MOD;
ans = (ans % MOD + MOD) % MOD;
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
#define eps 1e-9
#define MOD1 998244353
#define MOD2 1000000007
#define INV_2 499122177
#define INF 1000000000
#define PI 3.14159265358979323846
using namespace std;
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int a, b, w;
cin >> a >> b >> w;
w*=1000;
if(w < a || ((b-a)*(w/a)) < (w%a))
cout << "UNSATISFIABLE\n";
else
{
int x=0;
if(w%b)
x++;
cout << w/b + x << ' ';
cout << w/a << '\n';
}
}
//size | // 2021-03-14 18:10:57
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
// clang-format on
const ll inf = 1e18;
void answer() {
ll a, b, w;
cin >> a >> b >> w;
w *= 1000;
ll l = inf, r = -inf;
REPC(i, 1, 1000000) {
if (a * i <= w && w <= b * i) {
chmin(l, ll(i));
chmax(r, ll(i));
}
}
if (l == inf) {
cout << "UNSATISFIABLE" << '\n';
} else {
cout << l << ' ' << r << '\n';
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
answer();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int N, M;
int a[MAXN][2];
vector <pair <int, int>> adj[MAXN];
int bio[MAXN], ans[MAXN];
int c[MAXN];
void load() {
scanf("%d%d", &N, &M);
for (int i = 0; i < M; i++)
for (int j = 0; j < 2; j++)
scanf("%d", a[i] + j);
for (int i = 1; i <= N; i++)
scanf("%d", c + i);
}
void dfs(int x, int p) {
bio[x] = 1;
for (auto it : adj[x]) {
int nxt = a[it.first][it.second];
if (nxt == p || bio[nxt] == 2)
continue;
ans[it.first] = it.second;
if (!bio[nxt])
dfs(nxt, x);
}
bio[x] = 2;
}
void solve() {
for (int i = 0; i < M; i++)
if (c[a[i][0]] != c[a[i][1]])
ans[i] = c[a[i][0]] > c[a[i][1]];
else
for (int j = 0; j < 2; j++)
adj[a[i][j]].push_back({i, j ^ 1});
for (int i = 1; i <= N; i++)
if (!bio[i])
dfs(i, 0);
for (int i = 0; i < M; i++)
printf("%s\n", ans[i] ? "->" : "<-");
}
int main() {
load();
solve();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int n,m;
vector<vector<int>>a;
vector<pair<int,int>>ds;
int b[104][104];
const int nmax=1e6;
int c[nmax+4];
int mau[105];
int cha[105];
int hang[105];
vector<pair<int,int>>kq;
void dfs(int u)
{
mau[u]=1;
for(int i=0; i<a[u].size(); ++i)
{
int v=a[u][i];
// cout<<v<<' ';
if(!mau[v]&&c[u]==c[v])
{
b[u][v]=1;
cha[v]=u;
hang[v]=hang[u]+1;
dfs(v);
}
}
}
int main()
{
//ifstream cin("chuyen.inp");
//ofstream cout("chuyen.out");
cin>>n>>m;
a.assign(n+1,vector<int>());
for(int i=1; i<=m; ++i)
{
int x,y;
cin>>x>>y;
a[x].push_back(y);
a[y].push_back(x);
kq.push_back({x,y});
}
for(int i=1; i<=n; ++i)
{
cin>>c[i];
ds.push_back({c[i],i});
}
for(int i=1; i<=n; ++i)
{
if(!mau[i])
dfs(i);
}
for(int i=0; i<m; ++i)
{
int x=kq[i].first;
int y=kq[i].second;
if(c[x]==c[y])
{
if(cha[y]==x||(cha[x]!=y&&hang[x]>hang[y]))
cout<<"->"<<'\n';
else
cout<<"<-"<<'\n';
//continue;
}
else
{
if(c[x]>c[y])
cout<<"->"<<'\n';
else
cout<<"<-"<<'\n';
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int,int>;
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=int(a);i<=(int)(b);i++)
#define per(i,a,b) for(int i=int(a);i>=(int)(b);i--)
const int mod = 1e9+7;
const int maxn = 2e5+10;
const int inf = 0x3f3f3f3f;
int main() {
#ifndef WA_DEBUG
ios::sync_with_stdio(false);cin.tie(nullptr);
#endif
int _;
cin>>_;
while(_--) {
ll n,s,k;
cin>>n>>s>>k;
s=n-s;
if(s%__gcd(k,n)) {
cout<<-1<<'\n';
continue;
}
ll x,y;
function<ll(ll,ll,ll &,ll &)> Exgcd=[&](ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1;
y = 0;
return a;
}
ll d = Exgcd(b, a % b, x, y);
ll t = x;
x = y;
y = t - (a / b) * y;
return d;
};
Exgcd(k,n,x,y);
x*=s/__gcd(k,n);
y*=s/__gcd(k,n);
ll lc=k*n/__gcd(k,n);
ll tmp=lc/n,up=abs(y);
//cout<<x<<' '<<y<<' '<<tmp<<'\n';
if(y>0) {
ll num=up/tmp;
if(up%tmp) num++;
x+=(lc/k*num);
}
else {
ll num=up/tmp;
x-=(lc/k*num);
}
cout<<x<<'\n';
}
return 0;
}
| // Jai Shree Ram
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define max2(a,b) (a>b)?a:b
#define mi2(a,b) (a<=b)?a:b
#define fori(i,n) for(ll i=0;i<(ll)n;i++)
#define ford(i,n) for(ll i=n;i>=0;i--)
#define pll pair<ll,ll>
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
#define MAXI 1e15
#define MAX_LIMIT 500001
void solve()
{
ll n,m;
cin>>n>>m;
vector<vector<ll>> adj(n+1);
fori(i,m)
{
ll a,b;
cin>>a>>b;
adj[a].pb(b);
}
ll ans=0;
for(int i=1;i<=n;i++)
{
stack<ll> st;
vector<bool> visited(n+1,0);
vector<ll> covered(n+1,0);
visited[i]=1;
st.push(i);
while(!st.empty())
{
ll tmp=st.top();
visited[tmp]=1;
bool fl=0;
for(int j=covered[tmp];j<adj[tmp].size();j++)
{
if(!visited[adj[tmp][j]])
{
fl=1;
covered[tmp]=j;
st.push(adj[tmp][j]);
visited[tmp]=1;
break;
}
}
if(!fl)
{
ans++;
st.pop();
}
}
}
cout<<ans<<"\n";
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll T;
T=1;
//cin>>T;
fori(_,T)
{
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rrep(i,n) for (int i = 1; i <= (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
const long long INF = 1LL << 60;
const int dh[4] = {1,-1,0,0};
const int dw[4] = {0,0,1,-1};
const int MOD = 1000000009;
void add(ll &a, ll b) {a = (a+b) % MOD;}
int main() {
ll N; cin >> N;
ll a = 3;
ll ai = 1;
while(N >= a) {
ll tmp = N - a;
ll b = 5,bi = 1;
while (tmp >= b) {
if (tmp - b == 0) {
cout << ai << " " << bi << endl;
return 0;
}
b *= 5;
bi++;
}
a *= 3;
ai++;
}
cout << -1 << endl;
}
| #include<bits/stdc++.h>
using namespace std;
#define fastt ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug printf("\n<<CameHere>>\n")
#define mem(x,y) memset(x, y, sizeof(x))
#define all(qz) qz.begin(),qz.end()
#define rall(qz) qz.rbegin(),qz.rend()
#define inf 1000000000000000000
#define mod 1000000007
#define Sqr(x) ((x)*(x))
#define ll long long
#define mk make_pair
#define pb push_back
#define pi acos(-1.0)
#define cos(a) cos(a*pi/180)
#define sin(a) sin(a*pi/180)
#define tan(a) tan(a*pi/180)
#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll ppow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}
/*---------AL ASAD NUR RIYAD------------*/
int main()
{
fastt
ll n;
cin>>n;
vector<ll> v;
ll cnt=1;
for(ll i=1;i<40;i++){
cnt=cnt*3;
v.push_back(cnt);
//cout<<cnt<<endl;
}
for(ll i=0;i<v.size();i++){
ll x=n-v[i];
if(x>0){
ll y=0;
while(x%5==0){
x/=5;
y++;
}
if(x==1&&y!=0){
cout<<i+1<<" "<<y<<endl;
return 0;
}
}
}
cout<<-1<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
namespace SimpleModInt {
constexpr int md = (int)1e9 + 7;
inline int norm(long long a) {
return (a % md + md) % md;
}
inline int add(int a, int b) {
a += b;
if (a >= md) a -= md;
return a;
}
inline int sub(int a, int b) {
a -= b;
if (a < 0) a += md;
return a;
}
inline int mul(int a, int b) {
return (int)((long long)a * b % md);
}
inline int powmod(int a, long long b) {
int res = 1;
while (b > 0) {
if (b & 1) res = mul(res, a);
a = mul(a, a);
b >>= 1;
}
return res;
}
inline int inv(int a) {
a %= md;
if (a < 0) a += md;
int b = md, u = 0, v = 1;
while (a) {
int t = b / a;
b -= t * a; swap(a, b);
u -= t * v; swap(u, v);
}
assert(b == 1);
if (u < 0) u += md;
return u;
}
}
using namespace SimpleModInt;
struct matrix {
int n, m;
vector<vector<int>> a;
matrix() {}
matrix(vector<vector<int>> k) {
n = k.size();
m = k[0].size();
a = k;
}
matrix operator* (const matrix& c) const {
int n = a.size();
int m = c.a[0].size();
vector<vector<int>> b(n, vector<int>(m, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
for (int k = 0; k < a[i].size(); k++) {
b[i][j] = add(b[i][j], mul(a[i][k], c.a[k][j]));
}
}
}
return matrix(b);
}
matrix powmod(long long k) {
k--;
vector<vector<int>> res = a;
vector<vector<int>> b = a;
while (k > 0) {
if (k & 1) res = (matrix(res) * matrix(b)).a;
b = (matrix(b) * matrix(b)).a;
k >>= 1;
}
return matrix(res);
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int INV2 = inv(2);
int n, m, k;
cin >> n >> m >> k;
int INVM = inv(m);
vector<vector<int>> g(n);
vector<vector<int>> c(n, vector<int>(n, 0));
vector<int> a(n);
for (auto& i : a) cin >> i;
if (!k) {
for (auto i : a) {
cout << i << "\n";
}
return 0;
}
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
--u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
for (int i = 0; i < n; i++) {
c[i][i] = mul((m - g[i].size()) + mul(INV2, g[i].size()), INVM);
for (auto to : g[i]) {
c[i][to] = mul(INVM, INV2);
}
}
auto res = matrix(c).powmod(k);
for (int i = 0; i < n; i++) {
int val = 0;
for (int j = 0; j < n; j++) {
val = add(val, mul(a[j], res.a[i][j]));
}
cout << val << "\n";
}
return 0;
} | #include<bits/stdc++.h>
#define db double
#define reg register
#define LL long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ull unsigned long long
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
#define erep(i,a) for(int i=head[a];i;i=e[i].nxt)
using namespace std;
bool Handsome;
inline void Mi(int &x,int y){if(x>y && (x=y));}
inline void Mx(int &x,int y){if(x<y && (x=y));}
const int M=105,P=1e9+7,INV=5e8+4;
int n,m,mv,k,A[M];
void Add(int &x,int y){
x+=y;
if(x>=P)x-=P;
if(x<0)x+=P;
}
int FAST(int x,int y){
int res=1;
for(;y;y>>=1){
if(y&1)res=1ll*res*x%P;
x=1ll*x*x%P;
}
return res;
}
struct Mtx{
int a[M][M];
Mtx (){memset(a,0,sizeof(a));}
Mtx operator * (const Mtx x)const{
Mtx y;
rep(i,1,n)rep(j,1,n)rep(k,1,n)
Add(y.a[i][k],1ll*a[i][j]*x.a[j][k]%P);
return y;
}
void Print(){
rep(i,1,n){
int x=0;
rep(j,1,n)Add(x,1ll*a[i][j]*A[j]%P);
printf("%d\n",x);
}
}
}f,res;
bool Most;
int main(){
// printf("%.2lfMB\n",(&Most-&Handsome)/1024.0/1024.0);
scanf("%d%d%d",&n,&m,&k);
mv=FAST(m,P-2);
rep(i,1,n)scanf("%d",&A[i]);
rep(i,1,n)f.a[i][i]=res.a[i][i]=1;
rep(i,1,m){
int x,y;scanf("%d%d",&x,&y);
Add(f.a[x][y],1ll*mv*INV%P);
Add(f.a[x][x],-1ll*mv*INV%P);
Add(f.a[y][x],1ll*mv*INV%P);
Add(f.a[y][y],-1ll*mv*INV%P);
}
for(;k;k>>=1){
if(k&1)res=res*f;
f=f*f;
}
res.Print();
return 0;
} |
//BY: YASH JAIN, CF: yashjain0333
#include <bits/stdc++.h>
using namespace std;
#define May_the_fork_be_with_you ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define rall(v) v.rbegin(),v.rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define deb(x) cout<<#x<<": "<<x<<endl;
#define debn(x) cout<<#x<<": "<<x<<" ";
#define MOD 1000000007
#define INF 1e18
#define ll long long
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define int long long
#define N 100005
#define sq(x) ((x)*(x))
typedef vector<int> vi;
ll gcd(ll a, ll b) {if (!b)return a; return gcd(b, a % b);}
ll power(ll x, ll y, ll p = INF) {ll res = 1; x %= p; while (y > 0) {if (y & 1)res = (res * x) % p; y = y >> 1; x = (x * x) % p;} return res;}
void solve() {
int n; cin >> n;
int res = 0;
int l = 1, r = sqrt(2 * n + 2), comp = 2 * n + 2;
// deb(comp)
while (r > l) {
int m = l + (r - l) / 2;
int x = sq(m) + m;
// debn(m) deb(x)
if (x <= comp) l = m + 1;
else r = m;
}
if ((l * (l + 1)) <= 2 * (n + 1)) cout << n + 1 - l;
else cout << n + 1 - (l - 1);
}
int32_t main() {
#ifndef ONLINE_JUDGE
// for geting input form input.txt
freopen("input.txt", "r", stdin);
// for wrting output to output.txt
freopen("output.txt", "w", stdout);
#endif
May_the_fork_be_with_you
int t = 1;
// cin >> t;
cout << fixed << setprecision(12);
while (t--) {
solve();
}
cerr << "Time Taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int N, Q;
const int maxn = 2e5 + 5;
typedef long long ll;
inline ll read()
{
ll x = 0;
int s = 1;
char c = getchar();
while (c < 48 || c > 57)
{
if (c == '-')
s = -1;
c = getchar();
}
while (c >= 48 && c <= 57)
{
x = (x << 3) + (x << 1) + c - '0';
c = getchar();
}
return x * s;
}
int main()
{
int N, Q;
N = read();
ll a, t;
ll l = -1e9, r = 1e9, b = 0;
for (int i = 0; i < N; i++)
{
a = read();
t = read();
if (t == 1)
{
l += a;
r += a;
b += a;
}
else if (t == 2)
{
l = max(l, a);
r = max(r, a);
}
else
{
l = min(l, a);
r = min(r, a);
}
}
Q = read();
while (Q--)
{
ll x = read() + b;
if (x < l)
cout << l;
else if (x > r)
cout << r;
else
cout << x;
cout << ' ';
}
} |
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
#define fi first
#define se second
const int N = 2e5 + 5;
const int INF = 2e9;
const lint LINF = 9e18;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
cout << ((n + 99) / 100) << "\n";
} | #define ll long long
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#define tll tuple<ll ,ll ,ll , ll>
#define tri tuple<ll ,ll ,ll>
#define pll pair<ll ,ll>
//#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>
ll pi = acos(-1) ;
ll z = 998244353 ;
ll inf = 100000000000;
ll p1 = 37 ;
ll p2 = 53 ;
ll mod1 = 202976689 ;
ll mod2 = 203034253 ;
ll fact[100] ;
ll gdp(ll a , ll b){return (a - (a%b)) ;}
ll ld(ll a , ll b){if(a < 0) return -1*gdp(abs(a) , b) ; if(a%b == 0) return a ; return (a + (b - a%b)) ;} // least number >=a divisible by b
ll gd(ll a , ll b){if(a < 0) return(-1 * ld(abs(a) , b)) ; return (a - (a%b)) ;} // greatest number <= a divisible by b
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll e_gcd(ll a , ll b , ll &x , ll &y){ if(b > a) return e_gcd(b , a , y , x) ; if(b == 0){x = 1 ; y = 0 ; return a ;}
ll x1 , y1 ; e_gcd(b , a%b , x1 , y1) ; x = y1 ; y = (x1 - ((a/b) * y1)) ; return e_gcd(b , a%b , x1 , y1) ;}
ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
ll min(ll a , ll b){if(a < b) return a ; return b ;}
ll left(ll i){return ((2*i)+1) ;}
ll right(ll i){return ((2*i) + 2) ;}
ll ncr(ll n , ll r){if(n < r) return 0 ; return ((((fact[n] * inverse(fact[r] , z)) % z) * inverse(fact[n-r] , z)) % z);}
void swap(ll&a , ll&b){ll c = a ; a = b ; b = c ; return ;}
//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);
using namespace std ;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val) no. of elements strictly less than val
// s.find_by_order(i) itertor to ith element (0 indexed)
//__builtin_popcount(n) -> returns number of set bits in n
void solve()
{
ll n ;
cin >> n ;
cout << (n+99)/100 << endl ;
return ;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
/*#ifndef ONLINE_JUDGE
freopen("inputf.txt" , "r" , stdin) ;
freopen("outputf.txt" , "w" , stdout) ;
freopen("errorf.txt" , "w" , stderr) ;
#endif*/
ll t ;
//cin >> t ;
t = 1 ;
for(ll x = 1 ; x <= t ; x++)
{
solve() ;
}
//cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
bool ans=true;
cin>>N;
vector<int> a(N);
for(int i=0;i<N;i++) cin>>a.at(i);
sort(a.begin(),a.end());
for(int i=1;i<=N;i++) if(a[i-1]!=i) ans=false;
if(ans) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} | #include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define pb push_back
#define ll long long
#define mk make_pair
#define endl '\n'
#define M 1000000007
ull dp[101][101];
ull nCr(ull n,ull r)
{
if(n==r)return dp[n][r]=1;
if(r==1)return dp[n][r]=n;
if(r==0)return dp[n][r]=1;
if(dp[n][r])return dp[n][r];
return dp[n][r]=nCr(n-1,r-1)+nCr(n-1,r);
}
ll mod(ll x)
{
return ((x%M+M)%M); // x will be negative or positive
}
ll add(ll a,ll b)
{
return mod((mod(a)+mod(b)));
}
ll mul(ll a,ll b)
{
return mod(mod(a)*mod(b));
}
bool cmp(const pair<ll,ll>&p1, pair<ll,ll>&p2)
{
if(p1.first>p2.first)return 1;
else if(p1.first==p2.first)return (p1.second<p2.second);
else return 0;
}
bool is_balanced(char first,char second )
{
return ((first=='('&& second==')')||(first=='{' && second=='}') || (first=='[' && second==']'));
}
int main()
{
ll test=1;
//cin>>test;
while(test--)
{
ll n;
cin>>n;
ll a[n];
set<ll>s;
for(ll i=0;i<n;i++)
{
cin>>a[i];
s.insert(a[i]);
}
if(s.size()==n)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
//Alhamdulillah...
|
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
if (a==b)
cout<<c;
else if (b==c)
cout<<a;
else if (a==c)
cout<<b;
else
cout<<0;
return 0;
} | // #define ONLINE_JUDGE
// _
// (_)
// _ __ ___ __ _ _ ___ _ __ _ __ ___
//| '_ ` _ \ / _` | |/ _ \| '__| '__/ _ \
//| | | | | | (_| | | (_) | | | | | (_) |
//|_| |_| |_|\__,_| |\___/|_| |_| \___/
// _/ |
// |__/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef tree<
pll,//
null_type,
less<pll>,//
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define majorro cout.precision(20); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define forn(i, n) for(ll (i) = 0; (i) < (n); ++(i))
#define fornm(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define rfornm(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define readvec(vector, n) {ll temp_vec_val;forn(inc, n){cin >> temp_vec_val;vector.push_back(temp_vec_val);}}
#define printvec(vector, delimeter) {ll length_of_vector=vector.size(); forn(elementvec, length_of_vector){cout << vector[elementvec] << delimeter;}}
#define all(vector) (vector).begin(), (vector).end()
#define rall(vector) (vector).rbegin(), (vector).rend()
#define endl "\n"
#define sz(something) (ll)something.size()
struct pair_hash
{
template <class T1, class T2>
size_t operator() (const pair<T1, T2>& pair) const
{
return hash<T1>()(pair.first) ^ hash<T2>()(pair.second);
}
};
const ld EPS = 1e-8;
const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1e18;
const ld pi = 2.0*acos(0.0);
ll n, m, k, p, q, t, sum=0, cnt=0;
ll mx = -INF;
ll mn = INF;
bool flag = 0;
vll v;
string s = "", s1, s2;
char c;
void solve()
{
ll a[3];
cin >> a[0] >> a[1] >> a[2];
sort(a,a+3);
if(a[0]==a[1]) cout << a[2];
else if(a[1]==a[2]) cout << a[0];
else cout << 0;
}
int main()
{
#if defined ACMP
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#elif !defined ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
majorro
solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define stp(var, init, end) for (auto var = init; var < end; ++var)
#define stpe(var, init, end) for (auto var = init; var <= end; ++var)
#define ll long long
int main(void)
{
int n, rnum = 0, gnum = 0, bnum = 0;
cin >> n;
vector<ll> rdogs;
vector<ll> gdogs;
vector<ll> bdogs;
ll ina;
char inc;
stp(i, 0, 2 * n)
{
cin >> ina >> inc;
if (inc == 'R')
{
rdogs.emplace_back(ina);
++rnum;
}
else if (inc == 'G')
{
gdogs.emplace_back(ina);
++gnum;
}
else if (inc == 'B')
{
bdogs.emplace_back(ina);
++bnum;
}
}
sort(rdogs.begin(), rdogs.end());
sort(gdogs.begin(), gdogs.end());
sort(bdogs.begin(), bdogs.end());
/*
cout << "R: ";
stp(i, 0, rnum)
{
cout << rdogs[i] << " ";
}
cout << "\n";
cout << "G: ";
stp(i, 0, gnum)
{
cout << gdogs[i] << " ";
}
cout << "\n";
cout << "B: ";
stp(i, 0, bnum)
{
cout << bdogs[i] << " ";
}
cout << "\n\n";
*/
if (rnum % 2 == 0 && gnum % 2 == 0 && bnum % 2 == 0)
{
//cout << "even\n";
cout << 0;
}
else
{
ll rgmin = 10000000000000000ll, gbmin = 10000000000000000ll, brmin = 10000000000000000ll;
if (gnum > 0)
{
stp(i, 0, rnum)
{
auto iter = lower_bound(gdogs.begin(), gdogs.end(), rdogs[i]);
if (iter == gdogs.begin())
rgmin = min(rgmin, abs(rdogs[i] - *iter));
else if (iter == gdogs.end())
rgmin = min(rgmin, abs(rdogs[i] - *(iter - 1)));
else
rgmin = min(rgmin, min(abs(rdogs[i] - *iter), abs(rdogs[i] - *(iter - 1))));
}
}
if (bnum > 0)
{
stp(i, 0, gnum)
{
auto iter = lower_bound(bdogs.begin(), bdogs.end(), gdogs[i]);
if (iter == bdogs.begin())
gbmin = min(gbmin, abs(gdogs[i] - *iter));
else if (iter == bdogs.end())
gbmin = min(gbmin, abs(gdogs[i] - *(iter - 1)));
else
gbmin = min(gbmin, min(abs(gdogs[i] - *iter), abs(gdogs[i] - *(iter - 1))));
}
}
if (rnum > 0)
{
stp(i, 0, bnum)
{
auto iter = lower_bound(rdogs.begin(), rdogs.end(), bdogs[i]);
if (iter == rdogs.begin())
brmin = min(brmin, abs(bdogs[i] - *iter));
else if (iter == rdogs.end())
brmin = min(brmin, abs(bdogs[i] - *(iter - 1)));
else
brmin = min(brmin, min(abs(bdogs[i] - *iter), abs(bdogs[i] - *(iter - 1))));
}
}
if (rnum % 2 == 1 && gnum % 2 == 1)
{
if (bnum > 0)
cout << min(rgmin, gbmin + brmin);
else
cout << rgmin;
}
else if (gnum % 2 == 1 && bnum % 2 == 1)
{
if (rnum > 0)
cout << min(gbmin, brmin + rgmin);
else
cout << gbmin;
}
else if (bnum % 2 == 1 && rnum % 2 == 1)
{
if (gnum > 0)
cout << min(brmin, rgmin + gbmin);
else
cout << brmin;
}
}
return 0;
} | #include <bits/stdc++.h>
#define rei register int
using namespace std;
int K;
int cnt[11],qpow[11];
string S,T;
double ans;
int score(string A){
memset(cnt,0,sizeof(cnt)); int res = 0;
for(rei i = 0;i < A.size();++i) ++cnt[A[i] - '0'];
for(rei i = 1;i <= 9;++i) res += i * qpow[cnt[i]];
return res;
} void solve(string A,string B){
int scoreA = score(A),scoreB = score(B);
if(scoreA > scoreB){
// cerr << A[4] << " " << B[4] << endl;
double P = 1;
memset(cnt,0,sizeof(cnt));
for(rei i = 1;i <= 9;++i) cnt[i] = K;
for(rei i = 0;i < A.size() - 1;++i) --cnt[A[i] - '0'];
for(rei i = 0;i < B.size() - 1;++i) --cnt[B[i] - '0'];
int now = 9 * K - 8;
P *= (double)cnt[A[4] - '0'] / (double)now;--now,--cnt[A[4] - '0'];
P *= (double)cnt[B[4] - '0'] / (double)now;--now,--cnt[B[4] - '0'];
// printf("%.10lf\n",P);
ans += P;
}
}
int main(){
cin >> K; cin >> S >> T;
qpow[0] = 1;
for(rei i = 1;i <= 9;++i) qpow[i] = qpow[i - 1] * 10;
for(rei i = 1;i <= 9;++i)
for(rei j = 1;j <= 9;++j){
S[4] = '0' + i,T[4] = '0' + j;
solve(S,T);
} printf("%.10lf",ans); return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define INF LONG_MAX/3
//#define DIV 1000000007
//#define DIV 998244353
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//pos, C, D;
vector<tuple<ll, ll, ll> > to[100005];
ll cal(double c, double d, double curtime) {
double s = 0;
double e = 1000000000;
while(s + 5 < e) {
double diff = e - s;
double p0 = s + diff/3;
double p1 = s + 2*(diff/3);
double cost0 = p0 + c + (d/(curtime + p0 + 1));
double cost1 = p1 + c + (d/(curtime + p1 + 1));
if(cost0 < cost1) {
e = p1;
} else {
s = p0;
}
}
ll ret = INF;
for(ll x = max(0LL, (ll)s - 10); x <= s + 20; x++) {
ll cost0 = x + c + (d/(curtime + x + 1));
chmin(ret, cost0);
}
return ret;
}
int main(){
ll N, M;
cin >> N >> M;
rep(i, M) {
ll a, b, c, d;
cin >> a >> b >> c >> d;
a--;b--;
to[a].push_back({b, c, d});
to[b].push_back({a, c, d});
}
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll> > >Q;
Q.push(make_pair(0, 0));
vector<ll> dis(N, -1);
while(!Q.empty()) {
ll cost = Q.top().first;
ll pos = Q.top().second;
Q.pop();
if(dis[pos] != -1) continue;
dis[pos] = cost;
for(auto item: to[pos]) {
ll next, c, d;
tie(next, c, d) = item;
ll minicost = cal(c, d, cost);
//cout << "pos = " << pos << " next = " << next << " cost = " << cost << " mini = " << minicost << endl;
Q.push({cost + minicost, next});
}
}
cout << dis[N-1] << endl;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sys/types.h>
#include <unistd.h>
#include <vector>
#pragma region macros
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) _range(i, 0, n)
#define _range(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)
#define _rrep(i, n) _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)
#define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)
#pragma endregion macros
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
return (b < a) ? (a = b, 1) : 0;
}
using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R &r) {
return (r > EPS) - (r < -EPS);
}
inline R sq(R x) {
return sqrt(max(x, 0.0L));
}
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const pid_t pid = getpid();
// Problem Specific Parameter:
int n, k;
const int limit = 200010;
vector<int> graph[limit];
int used[limit];
using state = struct {
bool covered;
int dist;
};
state dfs(int v, int p, int thr) {
vector<int> children;
for (auto &u: graph[v]) {
if (u == p) {
continue;
}
children.push_back(u);
}
if (children.empty()) {
return {0, 0};
}
int farthest = 0;
int closest = 1 << 20;
for (auto &u: children) {
const state cur = dfs(u, v, thr);
if (cur.covered) {
chmin(closest, cur.dist + 1);
} else {
chmax(farthest, cur.dist + 1);
}
}
if (farthest + closest <= thr) {
return {1, closest};
} else if (farthest >= thr) {
used[v] = 1;
return {1, 0};
} else {
return {0, farthest};
}
}
bool check(int thr) {
rep(i, n) {
used[i] = 0;
}
const state ret = dfs(0, -1, thr);
if (ret.covered == 0) {
used[0] = 1;
}
int cnt = 0;
rep(i, n) {
cnt += used[i];
}
return (cnt <= k);
}
int main(void) {
cin >> n >> k;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--, b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
int low = 0, high = n;
while (high - low > 1) {
const int mid = (low + high) / 2;
if (check(mid)) {
high = mid;
} else {
low = mid;
}
}
cout << high << endl;
return 0;
} |
// CTRL+ALT+M
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define int long long int
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
#define vpi vector<pair<int,int>>
#define pii pair<int,int>
#define pb push_back
#define inf 1e18
#define ff first
#define ss second
#define deb(x) cout<<#x<<" "<<x<<endl;
#define all(x) x.begin(),x.end()
#define endl "\n"
const int maxn=1e5;
//*! look for binary search see if dp can fit or dp with bs
//*? Set or Priority_queue
//*! Number is upto 10^5 check if a[maxn] gives something
//*? Graph Question depedencies Topo sort
//todo For a Tree its shortest Path in dfs is same as in bfs if it is acyclic
// *! Bridge Detection:: From Backedge we take low[u]=min(low[u],tin[x])
// *! Bridge Detection:: From Child we take low[u]=min(low[u],low[x])
// *! Bridge Detection:: this is a bridge if(low[x]>tin[u])
// vi adj[maxn];
// int visited[maxn];
int dp[20][10];
int solve(int s,int n,string & p,int sum)
{
if(s>=n)
{
if(sum==0)
{
return 0;
}
return INT_MAX;
}
if(dp[s][sum]!=-1)
{
return dp[s][sum];
}
int l=sum+(p[s]-'0');
l=l%3;
int op1=solve(s+1,n,p,l);
int op2=1+solve(s+1,n,p,sum);
return dp[s][sum]=min(op1,op2);
}
void runcases(int T)
{
string s;
cin>>s;
int n=s.size();
memset(dp,-1,sizeof(dp));
int f=solve(0,n,s,0);
if(f==n)
{
cout<<-1<<endl;
}else cout<<f<<endl;
//cout<<"Case #"<<T<<": ";
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T = 1;
//cin >> T;
for (int t=1;t<=T; t++) {
runcases(t);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
//cin>>t;
while(t--)
{
string s;
cin>>s;
int n = s.length(),sum=0;
vector<int> c(3,0);
if(n==1)
{
if(int(s[0]-'0')%3==0)cout<<"0";
else cout<<"-1";
continue;
}
for(int i=0;i<n;i++)
{
int a = int(s[i]-'0')%3;
c[a]++;
sum+=a;
}
sum = sum%3;
if(sum==0)cout<<"0";
else if(sum==2)
{
if(c[2]>0){cout<<"1";continue;}
if(c[1]>1 && n>2){cout<<"2";continue;}
cout<<"-1";
}
else
{
if(c[1]>0)cout<<"1";
else if(n>2 && c[2]>1)cout<<"2";
else
cout<<"-1";
}
}
return 0;
}
|
//wtrl,everybody hangbeat me
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,pii> piiii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef queue<char> qc;
typedef queue<string> qs;
typedef vector<char> vc;
typedef vector<string> vs;
typedef map<char,int> mpci;
typedef map<int,int> mpii;
typedef map<string,int> mpsi;
typedef set<int> sei;
typedef set<char> sec;
typedef set<string> ses;
typedef stack<ll> si;
typedef stack<char> sc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pll> vpll;
typedef vector<pdd> vdd;
typedef unsigned int uint;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vii> vvii;
/*=====================================================================*/
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define all(s) (s).begin(),(s).end()
#define fi first
#define se second
#define be begin
#define en end
#define m_p make_pair
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<=n;i++)
#define ford(i,p,n) for(int i=n;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define zero(a) memset(a,0,sizeof(a))
#define number(a,num) memeset(a,num,sizeof(a))
#define INF 1e9
#define PI acos(-1)
/*=====================================================================*/
string int_to_string(ll n)
{
string s="";
while(n)
{
ll now=n%10;
s+=now+'0';
n/=10;
}
reverse(s.begin(),s.end());
return s;
}
ll string_to_int(string s)
{
ll n=0;
rep(i,s.size())
{
n*=10;
n+=s[i]-'0';
}
return n;
}
/*======================================================================*/
ll lcm(int a,int b)
{
return a/__gcd(a,b)*b;
}
bool prime(int n)
{
if(n==0||n==1)
return false;
for(int i=2;i*i<=n;i++)
if(n%i==0)
return false;
return true;
}
string turn(int n,int k)
{
string s="";
while(n)
{
s+=(char)(n%k+'0');
n/=k;
}
reverse(s.begin(),s.end());
return s;
}
const string turn16(int n)
{
string s="";
while(n!=0)
{
if(n%16>9)
s+=(char)('A'+n%16-10);
else
s+=(char)('0'+n%16);
n/=16;
}
reverse(s.begin(),s.end());
return s;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
/*======================================================================*/
int main()
{
std::ios::sync_with_stdio(false);
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/
/*====================================================================*/
int n;
cin>>n;
cout<<(1<<n)-1<<endl;
forn(i,1,(1<<n)-1)
{
forn(j,1,(1<<n))
{
cout<<(__builtin_popcount(i&j)&1?'A':'B');
}
cout<<endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define bit(n,k) ((n>>k)&1) //nのk bit目
#define vec(T) vector<T>
#define vvec(T) vector<vector<T>>
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e9;
//---整数pow x^y----
ll powll(ll x, ll y){
assert(y>=0);
ll res = 1;
while(y){
if(y&1) res *= x;
x *= x;
y >>= 1;
}
return res;
}
//------------------------------------------------
struct Solver{
int N,s;
vvec(int) ans;
void f(vec(int) a){
ans.push_back(a);
if(a[0]!=a[1]) return;
vec(int) b1(s),b2(s);
rep(i,s/2){
b1[i] = a[i*2];
b2[i] = a[i*2];
}
rep(i,s/2){
b1[s/2+i] = a[i*2];
b2[s/2+i] = -a[i*2];
}
f(b1);
f(b2);
return;
}
void solve(){
cin >> N;
s = powll(2,N);
vec(int) a0(s,-1);
rep(i,s/2) a0[i]=1;
//ans.push_back(a0);
f(a0);
int K = ans.size();
cout << K << endl;
rep(ki,K){
rep(i,s-1){
if(ans[ki][i]==1) cout << "A";
else cout << "B";
}
if(ans[ki][s-1]==1) cout << "A" << endl;
else cout << "B" << endl;
}
}
};
int main(){
int testcasenum=1;
//cin >> testcasenum;
rep1(ti,testcasenum){
Solver solver;
solver.solve();
}
return 0;
} |
#include<bits/stdc++.h>
#define pii pair<int,int>
#define eps 1e-7
#define equals(a,b) (fabs(a - b) < eps)
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
const ll MOD = 1e9 + 7;
ll rd(){
ll x = 0;
int f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
struct PSegmentTree{
struct Node{
int l,r,d;
Node *ls,*rs;
};
int a[maxn];
Node pool[maxn * 30],*rt[maxn];
int top;
Node* build(int l,int r){
Node *p = pool + (++top);
p -> l = l,p -> r = r;
if(l == r) {
p -> d = a[l];
return p;
}
int mid = l + r >> 1;
p -> ls = build(l,mid);
p -> rs = build(mid + 1,r);
return p;
}
Node* copyNode(Node* rt){
Node* p = pool + (++top);
pool[top] = *rt;
return p;
}
Node* change(Node* rt,int id,int x){
Node* p = copyNode(rt);
if(p -> l == p -> r) {
p -> d = x;
return p;
}
int mid = p -> l + p -> r >> 1;
if(id <= mid) p -> ls = change(p -> ls,id,x);
else p -> rs = change(p -> rs,id,x);
return p;
}
int query(Node* rt,int id){
if(rt -> l == rt -> r) {
return rt -> d;
}
int mid = rt -> l + rt -> r >> 1;
if(id <= mid) return query(rt -> ls,id);
else return query(rt -> rs,id);
}
};
struct Edge{
int to;
ll t,k;
};
int main(){
int n = rd();
int m = rd();
int x = rd();
int y = rd();
x--;
y--;
vector<vector<Edge>> e(n);
while(m--){
int a = rd();
int b = rd();
int c = rd();
int d = rd();
a--;
b--;
e[a].push_back({b,c,d});
e[b].push_back({a,c,d});
}
vector<ll> dis(n,1e18);
dis[x] = 0;
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
q.emplace(0,x);
while(!q.empty()){
ll d = q.top().fi;
int u = q.top().se;
q.pop();
if(dis[u] != d) continue;
for(auto v:e[u]) {
ll tmp = ((d + v.k - 1) / v.k) * v.k + v.t;
if(tmp < dis[v.to]) {
dis[v.to] = tmp;
q.emplace(tmp,v.to);
}
}
}
if(dis[y] == 1e18) cout << -1 << '\n';
else cout << dis[y];
} | #include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define p_q priority_queue
#define m_p make_pair
#define pb push_back
#define ld long double
#define F first
#define S second
#define ull unsigned long long
#define mod 1000000007
#define md 998244353
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define int ll
using namespace std;
inline void read(int &x)
{
short negative=1;
x=0;
char c=getchar();
while(c<'0' || c>'9')
{
if(c=='-')
negative=-1;
c=getchar();
}
while(c>='0' && c<='9')
x=(x<<3)+(x<<1)+(c^48),c=getchar();
x*=negative;
}
ll qpow(ll n,ll k){
ll ans=1;
while(k){
if(k%2){
ans*=n;
ans%=mod;
}
n*=n;
n%=mod;
k/=2;
}
return ans;
}
string iots(int n)
{
string s="";
while(n)
{
int now=n%10;
s+=now+'0';
n/=10;
}
reverse(s.begin(),s.end());
return s;
}
int stoi(string s)
{
int n=0;
rep(i,s.size())
{
n*=10;
n+=s[i]-'0';
}
return n;
}
int n;
int val[100100];
vector<int>sons[100100];
int sz[100100];
void dfs(int u)
{
val[u]=1;
sz[u]=1;
rep(i,sons[u].size())
{
dfs(sons[u][i]);
sz[u]+=sz[sons[u][i]];
}
int sum=0;
vector<int>vv;
vv.clear();
rep(i,sons[u].size())
{
int v=sons[u][i];
if(sz[v]%2==0)
{
if(val[v]<0)
{
val[u]+=val[v];
}
else
{
sum+=val[v];
}
}
else vv.pb(val[v]);
}
sort(vv.begin(),vv.end());
if(vv.size()%2==0)
{
val[u]+=sum;
}
else
{
val[u]-=sum;
}
rep(i,vv.size())
{
if(i%2==0)
{
val[u]+=vv[i];
}
else
{
val[u]-=vv[i];
}
}
}
signed main()
{
ios::sync_with_stdio(0);
cin>>n;
rep(i,n-1)
{
int fa;
cin>>fa;
fa--;
int u=i+1;
sons[fa].pb(u);
}
dfs(0);
cout<<(val[0]+n)/2<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
const int N = 105;
int n;
pair<double,double> a[N];
pii dsu[N];
double dis[N][N];
int find(int x)
{
if(dsu[x].F == x) return x;
return dsu[x].F = find(dsu[x].F);
}
void merge(int x,int y)
{
int p = find(x);
int q = find(y);
if(p == q) return;
if(dsu[p].S > dsu[q].S) swap(p,q);
dsu[q].S+=dsu[p].S;
dsu[p].F = dsu[q].F;
}
//n is upper
//n+1 is lower
bool check(double r)
{
f(i,n+2) dsu[i] = {i,1};
f(i,n) f(j,n)
if(dis[i][j] <= r ) merge(i,j);
f(i,n) if(100 - a[i].S <= r) merge(i,n);
f(i,n) if(a[i].S + 100 <= r) merge(i,n+1);
return find(n) != find(n+1);
}
signed main()
{
fast;
cin >> n;
f(i,n) cin >> a[i].F >> a[i].S;
vector<double> go;
f(i,n) f(j,n) dis[i][j] = sqrt(
(a[i].F - a[j].F)*(a[i].F - a[j].F ) + (a[i].S - a[j].S)*(a[i].S - a[j].S));
f(i,n) f(j,n) go.pb(dis[i][j]);
f(i,n) go.pb((100 - a[i].S));
f(i,n) go.pb((a[i].S + 100));
double res = 0;
for(auto x : go)
if(check(x - 1e-9)) res = max(res,x);
cout << fixed << setprecision(4) << res/2;
} | #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
char c=getchar();bool f=0;x=0;
while(!isdigit(c)) f|=c=='-',c=getchar();
while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
read(x);read(a...);
}
template<class t> inline void write(t x){
if(x<0) putchar('-'),write(-x);
else{if(x>9) write(x/10);putchar('0'+x%10);}
}
const int N=1e5+5;
int n,m,tp[N],a[N],b[N];
long long ans;
void GG(){
write(-1);
exit(0);
}
signed main(){
read(n,m);
for(int i=1;i<=n;i++) read(tp[i]),a[i]=tp[i]-tp[i-1]-1;a[n+1]=m-tp[n];
for(int i=1;i<=n;i++) read(tp[i]),b[i]=tp[i]-tp[i-1]-1;b[n+1]=m-tp[n];n++;
for(int i=1,j=1;i<=n;i++) if(b[i]){
while(!a[j]) j++;
int cur=0,l=j;
while(j<=n&&cur<b[i]) cur+=a[j++];
if(cur>b[i]) GG();
ans+=max(i-l,0)+max(j-1-i,0);
}
write(ans);
} |
#include "bits/stdc++.h"
using namespace std;
int main() {
int N;
cin >> N;
string S, T;
cin >> S >> T;
vector<int>s;
for (int i = 0; i < N; ++i) {
if ('1' == S[i]) {
s.push_back(i);
}
}
vector<int>t;
int tcount = 0;
for (int i = 0; i < N; ++i) {
if ('1' == T[i]) {
t.push_back(i);
}
}
if (t.size() % 2 != s.size() % 2) {
cout << -1 << endl;
return 0;
}
if (s.size() < t.size()) {
cout << -1 << endl;
return 0;
}
vector<int>newt;
int j = 0;
for (int i = 0; i < s.size(); ++i) {
if (j >= t.size()) {
newt.push_back(s[i]);
newt.push_back(s[i]);
++i;
continue;
}
if (s[i] < t[j]) {
newt.push_back(s[i]);
newt.push_back(s[i]);
++i;
}
else {
newt.push_back(t[j]);
j++;
}
}
if (j != t.size()) {
cout << -1 << endl;
return 0;
}
long long sumS = 0;
for (int i = 0;i<s.size();++i) {
sumS += s[i];
//cout << s[i];
}
//cout << endl;
long long sumT = 0;
for (int i = 0; i <newt.size(); ++i) {
sumT += newt[i];
//cout << newt[i];
}
//cout << endl;
cout << sumS - sumT << endl;
return 0;
} | #include<bits/stdc++.h>
typedef long long LL;
typedef double dl;
#define opt operator
#define pb push_back
const LL maxn=1e6+9,mod=998244353,inf=0x3f3f3f3f;
LL Read(){
LL x(0),f(1); char c=getchar();
while(c<'0' || c>'9'){
if(c=='-') f=-1; c=getchar();
}
while(c>='0' && c<='9'){
x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
}return x*f;
}
void Chkmin(LL &x,LL y){
if(y<x) x=y;
}
void Chkmax(LL &x,LL y){
if(y>x) x=y;
}
LL add(LL x,LL y){
return x+=y,x>=mod?x-mod:x;
}
LL dec(LL x,LL y){
return x-=y,x<0?x+mod:x;
}
LL mul(LL x,LL y){
return 1ll*x*y%mod;
}
LL Pow(LL base,LL b){
LL ret(1); while(b){
if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1;
}return ret;
}
LL n,tot1,tot2;
LL a[maxn],b[maxn];
char s[maxn],t[maxn];
int main(){
n=Read();
scanf(" %s",s+1); scanf(" %s",t+1);
for(LL i=1;i<=n;++i) if(s[i]=='1') a[++tot1]=i;
for(LL i=1;i<=n;++i) if(t[i]=='1') b[++tot2]=i;
if(tot1<tot2){
puts("-1");
return 0;
}
LL flag(1);
LL j(1);
LL ans(0);
for(LL i=1;i<=tot2;++i){
if(j>tot1){
flag=0; break;
}
if(a[j]==b[i]){
++j;
continue;
}
if(a[j]<b[i]){
if(j==tot1){
flag=0; break;
}
ans+=(a[j+1]-a[j]);
j+=2; --i;
continue;
}
if(a[j]>b[i]){
ans+=(a[j]-b[i]); ++j;
}
}
if(!flag){
puts("-1"); return 0;
}
if(j>tot1){
printf("%lld\n",ans); return 0;
}
if((tot1-j+1)&1){
puts("-1"); return 0;
}
for(LL i=j;i<=tot1;i+=2){
ans+=(a[i+1]-a[i]);
}
printf("%lld\n",ans);
return 0;
} |
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define max(p, q) ((p) > (q) ? (p) : (q))
#define min(p, q) ((p) < (q) ? (p) : (q))
#define mod
using ll = long long;
using P = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T> >;
const ll INF = 1e18 + 1;
int main()
{
string s;
cin >> s;
int ans = 0;
rep(i, 0, 10000)
{
string t = to_string(i);
while (t.size() < 4)
t.insert(t.begin(), '0');
V<bool> used(10, false);
bool j = true;
rep(k, 0, 4)
{
if (s[t[k] - '0'] == 'x')
{
j = false;
break;
}
used[t[k] - '0'] = true;
}
rep(k, 0, 10) if (s[k] == 'o') if (!used[k]) j = false;
if (j)
ans++;
}
cout << ans << endl;
return 0;
}
| #include <stack>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <unordered_map>
/*#define cin(a) scanf("%d",&a)
#define llcin(a) scanf("%lld",&a)
#define fcin(a) scanf("%lf",&a)
#define cout(a) printf("%d",a)
#define cout_n(a) printf("%d\n",a)
#define cout_d(a) printf("%d ",a)
#define f2cout(a) printf("%.2f",a)
#define f2cout_n(a) printf("%.2f\n",a)
#define f2cout_d(a) printf("%.2f ",a)
#define llcout(a) printf("%lld",a)
#define llcout_n(a) printf("%lld\n",a)
#define llcout_d(a) printf("%lld ",a)*/
using namespace std;
typedef long long ll;
ll cnt;
int n;
string s[100];
int main()
{
scanf("%d", &n);
getchar();
for (int i = 1; i <= n; i++)
cin >> s[i];
ll dpTrue[100], dpFalse[100];
memset(dpTrue, 0, sizeof(dpTrue));
memset(dpFalse, 0, sizeof(dpFalse));
dpTrue[0] = dpFalse[0] = 1;
for (int i = 1; i <= n;i++)
{
if(s[i]=="AND")
dpTrue[i] = dpTrue[i - 1], dpFalse[i] = dpFalse[i - 1] * 2 + dpTrue[i - 1];
else
dpTrue[i] = dpTrue[i - 1] * 2 + dpFalse[i - 1], dpFalse[i] = dpFalse[i - 1];
}
cout << dpTrue[n];
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define f first
#define s second
void find(int N,vector<int>& a)
{
int n=(N<<1);
vector<bool> vis(n,1);
vector<pi> val(n);
for(int i=0;i<n;i++)
val[i]=make_pair(a[i],i);
sort(val.begin(),val.end());
for(int i=0;i<N;i++)
vis[val[i].s]=0;
int cur=0;
string res="";
bool f=0;
for(int i=0;i<n;i++)
{
if(cur==0 or vis[i]==f)
{
res.push_back('(');
f=vis[i];
++cur;
}
else
{
res.push_back(')');
--cur;
}
}
cout<<res;
}
int32_t main()
{
int n;
cin>>n;
vector<int> a(2*n);
for(int i=0;i<2*n;i++)
cin>>a[i];
find(n,a);
return 0;
}
| #include<set>
#include<queue>
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXN 10005
#define ENDL putchar('\n')
#define LL long long
#define DB double
#define lowbit(x) ((-x) & (x))
LL read() {
LL f = 1,x = 0;char s = getchar();
while(s < '0' || s > '9') {if(s=='-')f = -f;s = getchar();}
while(s >= '0' && s <= '9') {x=x*10+(s-'0');s = getchar();}
return f * x;
}
int n,m,i,j,s,o,k;
int b[MAXN];
int main() {
n = read();
int ct = 0;
for(int i = 1;i <= 10000;i ++) {
if(i != 6 && i != 10 && i != 15) {
int w = 0;
if(i % 2 == 0) w ++;
if(i % 3 == 0) w ++;
if(i % 5 == 0) w ++;
if(w > 1) b[++ ct] = i;
}
}
for(int i = 1;i <= n-3;i ++) {
printf("%d ",b[i]);
}
printf("6 10 15\n");
return 0;
} |
// Problem:
// E - Magical Ornament
//
//
// Contest: AtCoder - AtCoder Beginner Contest 190
// URL: https://atcoder.jp/contests/abc190/tasks/abc190_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,x,n) for(int i = x;i <= n;++i)
const int N = 1e5+7,M = 2 * N,CK = 20,INF = 0x3f3f3f3f;
int dist[CK][N],c[CK];
int edge[M],succ[M],ver[N],idx;
int f[1 << 17][CK];
void add(int u,int v)
{
edge[idx] = v;
succ[idx] = ver[u];
ver[u] = idx++;
}
void bfs(int f)
{
memset(dist[f],0x3f,sizeof dist[f]);
queue<int> q;q.push(c[f]);dist[f][c[f]] = 0;
while(!q.empty())
{
int u = q.front();q.pop();
for(int i = ver[u];~i;i = succ[i])
{
int v = edge[i];
if(dist[f][v] > dist[f][u] + 1)
{
dist[f][v] = dist[f][u] + 1;
q.push(v);
}
}
}
}
int main()
{
memset(ver,-1,sizeof ver);
int n,m;scanf("%d%d",&n,&m);
forn(i,1,m)
{
int u,v;scanf("%d%d",&u,&v);
--u;--v;
add(u,v),add(v,u);
}
int k;scanf("%d",&k);
forn(i,0,k - 1) scanf("%d",&c[i]),--c[i];
forn(i,0,k - 1) bfs(i);
memset(f,0x3f,sizeof f);
forn(i,0,k - 1) f[1 << i][i] = 1;
forn(S,1,(1 << k) - 1)
{
forn(j,0,k - 1) forn(i,0,k - 1)
{
if(f[S][j] == INF) continue;
if(!(S >> j & 1) || dist[j][c[i]] == INF || (S >> i & 1)) continue;
f[S | (1 << i)][i] = min(f[S | (1 << i)][i],f[S][j] + dist[j][c[i]]);
}
}
int res = INF;
forn(i,0,k - 1) res = min(res,f[(1 << k) - 1][i]);
printf("%d",res == INF ? -1 : res);
return 0;
} | #include <cstdio>
#include <cctype>
#include <cstring>
#define rr register
using namespace std;
const int N=100011;
struct node{int y,next;}e[N<<1];
int as[N],q[N],a[18],et=1,head,ans,tail,k,dis[18][N],n,m,dp[N<<1][18],two[18];
inline signed iut(){
rr int ans=0; rr char c=getchar();
while (!isdigit(c)) c=getchar();
while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
return ans;
}
inline void add(int x,int y){
e[++et]=(node){y,as[x]},as[x]=et;
e[++et]=(node){x,as[y]},as[y]=et;
}
inline signed min(int a,int b){return a<b?a:b;}
inline void bfs(int z,int st){
q[head=tail=1]=st,dis[z][st]=1;
while (head<=tail){
rr int x=q[head++];
for (rr int i=as[x];i;i=e[i].next)
if (!dis[z][e[i].y]){
dis[z][e[i].y]=dis[z][x]+1;
q[++tail]=e[i].y;
}
}
}
signed main(){
n=iut(); m=iut();
for (rr int i=1;i<=m;++i) add(iut(),iut());
k=iut(),memset(dp,42,sizeof(dp)),two[0]=1,ans=dp[0][0];
for (rr int i=0;i<k;++i) bfs(i,a[i]=iut());
for (rr int i=1;i<=k;++i) two[i]=two[i-1]<<1;
for (rr int i=0;i<k;++i) dp[two[i]][i]=0;
for (rr int i=3;i<two[k];++i){
for (rr int j0=0;j0<k;++j0)
for (rr int j1=0;j1<k;++j1)
if (j0!=j1&&(i&(two[j0]|two[j1]))&&dis[j0][a[j1]])
dp[i][j0]=min(dp[i][j0],dp[i^two[j0]][j1]+dis[j0][a[j1]]-2);
}
for (rr int i=0;i<k;++i) ans=min(ans,dp[two[k]-1][i]);
if (ans==dp[0][0]) return !printf("-1");
return !printf("%d",ans+k);
} |
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, s, n) for (ll i = s; i < (n); i++)
int main(){
ll k; cin >> k;
string s, t;
cin >> s >> t;
vector<ll> card(10, k);
rep(i, 4){
ll x = s[i]-'0';
ll y = t[i]-'0';
card[x]--;
card[y]--;
}
ll all = k * 9 - 8;
ll all2 = all * (all-1);
ll sum = 0;
rep2(i, 1, 10){
if (card[i] == 0) continue;
rep2(k, 1, 10){
if (card[k] == 0) continue;
vector<ll> tvec(10, 0), avec(10, 0);
rep(j, 4){
ll x = s[j]-'0';
ll y = t[j]-'0';
tvec[x]++;
avec[y]++;
}
tvec[i]++;
avec[k]++;
ll tp = 0;
ll ap = 0;
rep2(j, 1, 10){
tp += j * pow(10, tvec[j]);
ap += j * pow(10, avec[j]);
}
if (tp > ap){
if(i==k) sum += card[i] * (card[k]-1);
else sum += card[i] * card[k];
}
}
}
long double ans = (long double)sum / all2;
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const ll mod = 1e9+7;
int sum(int a, int b){return (a+b) % mod;}
int sub(int a, int b){return (a + mod - b) % mod;}
int mul(int a, int b){return (1ll * a * b) % mod;}
int power(int a,int b){
int res = 1;
while(b){
if(b&1)res = mul(res,a);
b >>= 1;
a = mul(a,a);
}
return res;
}
ll get(string str,char c){
map<int,int> cnt;
for(auto &x : str)cnt[x]++;
cnt[c]++;
ll res = 0;
for(char act = '1'; act <= '9'; act++){
ll tmp = act-'0';
res += tmp*pow(10,cnt[act]);
}
return res;
}
int K;
ld asd(char c1,char c2,map<char,int> cnt){
if(c1 != c2){
ld tmp1 = ld(K-cnt[c1])/(9*K-8);
ld tmp2 = ld(K-cnt[c2])/(9*K-8-1);
return tmp1*tmp2;
}
ld tmp1 = ld(K-cnt[c1])/(9*K-8);
ld tmp2 = ld(K-cnt[c2]-1)/(9*K-8-1);
return tmp1*tmp2;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> K;
string s1,s2; cin >> s1 >> s2;
map<char,int> cnt;
for(auto &x : s1)cnt[x]++;
for(auto &x : s2)cnt[x]++;
ld res = 0;
for(char a = '1'; a <= '9'; a++){
for(char b = '1'; b <= '9'; b++){
cnt[a]++;
cnt[b]++;
if(cnt[a] <= K && cnt[b] <= K){
ll r1 = get(s1,a);
ll r2 = get(s2,b);
cnt[a]--;
cnt[b]--;
if(r1 > r2){
res += asd(a,b,cnt);
//cout << a << ' ' << b << '\n';
//debug(asd(a,b,cnt));
}
}else{
cnt[a]--;
cnt[b]--;
}
}
}
//debug(num,den);
//ld res = num/den;
cout << fixed << setprecision(15) << res << '\n';
return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/
|
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
T f=0,x=0;char c=getchar();
while(!isdigit(c)) f=c=='-',c=getchar();
while(isdigit(c)) x=x*10+c-48,c=getchar();
return f?-x:x;
}
#define int long long
namespace run{
const int MAX=1LL<<62;
int X,Y,ans,num[109+9];
int main(){
X=read<int>(),Y=read<int>(),ans=max(X,Y);
for(int i=0;i<=64;i++){
int tmp=X,peg=1;
for(int j=0;j<i;j++){
tmp<<=1;
if(tmp>MAX){peg=0;break;}
}
if(!peg) break;
int del=abs(Y-tmp);
for(int j=0;j<64;j++) num[j]=(del>>j&1);
int g=i;
for(int j=0;j<i;j++)
if(num[j]==1){
int k=j;
while(k+1<i && num[k+1]) k++;
g++;
if(j^k){
if(k+1<i) num[k+1]=1;
else g++;
}
j=k;
}
g+=(del>>i),ans=min(ans,g);
}
cout<<ans<<endl;
return 0;
}
}
#undef int
int main(){
#ifdef my
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
return run::main();
} | #include "bits/stdc++.h"
using namespace std;
#define int long long
int x, y;
map<int, int> dp;
int recurse(int n) {
if (n <= x) {
return abs(x - n);
}
if (n % 2 == 0) {
if (dp[n / 2] == 0)
dp[n] = recurse(n / 2) + 1;
else
dp[n] = dp[n / 2] + 1;
dp[n] = min(dp[n], abs(x - n));
return dp[n];
}
else {
if (dp[n + 1] == 0)
dp[n] = recurse(n + 1) + 1;
else
dp[n] = dp[n + 1] + 1;
if (dp[n - 1] == 0)
dp[n] = min(dp[n], recurse(n - 1) + 1);
else
dp[n] = min(dp[n], dp[n - 1] + 1);
dp[n] = min(dp[n], abs(x - n));
return dp[n];
}
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> x >> y;
cout << recurse(y) << "\n";
/*for (auto i : dp) {
cout << i.first << " " << i.second << "\n";
}*/
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define N 5114514
#define all(x) (x).begin(), (x).end()
const ll mod = 1000000007;
// const ll mod = 998244353;
const ll inf = 1000000000000000000;
void solve() {
ll n;
string s;
cin >> n >> s;
vector<ll> a(n + 1);
ll k = inf;
for (int i = 0; i <= n; i++) {
cin >> a[i];
if (i) k = min(k, abs(a[i] - a[i - 1]));
}
cout << k << endl;
for (int i = 0; i < k; i++) {
for (int j = 0; j <= n; j++) {
cout << (a[j] + i) / k << ' ';
}
cout << endl;
}
}
int main() {
solve();
return 0;
} | #include <bits/stdc++.h>
//#include <atcoder/all>
#pragma GCC target("arch=skylake-avx512")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif
// index が条件を満たすかどうか
bool isOK(const vector<ll> &a, std::string S, ll index) {
ll n = a[0] / index;
ll m = a[0] % index;
FOR(i, 1, a.size()) {
ll x = a[i] / index;
ll y = a[i] % index;
if (S[i - 1] == '<') {
if (n >= x) {
return false;
}
if (n + 1 == x && m > y) {
return false;
}
} else {
if (n <= x) {
return false;
}
if (n == x + 1 && m < y) {
return false;
}
}
swap(n, x);
swap(m, y);
}
return true;
}
// 汎用的な二分探索のテンプレ
ll binary_search(const vector<ll> &a, std::string S) {
ll ng = 100000; //「index = 0」が条件を満たすこともあるので、初期値は -1
ll ok = 1; // 「index = a.size()-1」
// が条件を満たさないこともあるので、初期値は a.size()
/* ok と ng のどちらが大きいかわからないことを考慮 */
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (isOK(a, S, mid)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
void solve(long long N, std::string S, std::vector<long long> A) {
ll k = binary_search(A, S);
cout << k << endl;
vector<vector<ll>> v(N + 1);
REP(i, N + 1) {
ll n = A[i] / k;
ll m = A[i] % k;
REP(j, m) {
v[i].push_back(n + 1);
}
REP(j, k - m) {
v[i].push_back(n);
}
}
REP(j, k) {
REP(i, N + 1) {
cout << v[i][j] << " ";
}
cout << endl;
}
}
int main() {
long long N;
scanf("%lld", &N);
std::string S;
std::cin >> S;
std::vector<long long> A(N - 0 + 1);
for (int i = 0; i < N - 0 + 1; i++) {
scanf("%lld", &A[i]);
}
solve(N, S, std::move(A));
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define md 1000000007
using namespace std;
int main(){
ll n,i,j,a[201],dp[201][201],flg,rm,id[2]={-1,-1},bigval=md,k,num;
vector<ll> v[2];
bigval-=7;
bigval*=400;
cin>>n;
memset(dp,0,sizeof(dp));
for(i=0;i<n;i++)
cin>>a[i];
dp[a[0]%200][0]=1;
for(i=1;i<n;i++){
for(j=0;j<200;j++)
dp[j][i]=dp[j][i-1];
dp[a[i]%200][i]++;
for(j=0;j<200;j++)
if(dp[j][i-1]) dp[(j+a[i])%200][i]++;
}
flg=0;
for(i=0;i<200;i++)
if(dp[i][n-1]>1) {flg=1; break;}
if(flg==0) cout<<"No";
else {
rm = i;num=0;
cout<<"Yes\n";
for(i=n-1;i>0;i--){
if(dp[rm][i]>dp[rm][i-1]) id[num++]=i;
if(num==2) break;
}
if(id[1]==-1) id[1]=0;
for(i=0;i<2;i++){
num=rm;
for(j=id[i];j>-1;){
num = (num - a[j]+bigval)%200;
v[i].push_back(j);
if(num==0) break;
for(k=j-1;k>0;k--)
if(dp[num][k]>dp[num][k-1]) break;
j=k;
}
}
for(i=0;i<2;i++){
cout<<v[i].size()<<" ";
sort(v[i].begin(),v[i].end());
for(j=0;j<v[i].size();j++)
cout<<v[i][j]+1<<" ";
cout<<endl;
}
}
return 0;} | #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
int mod = 1000000007;
bool issame(int x, int y){
if(x > y) swap(x, y);
bool ret = true;
while(x){
if((x&1)^(y&1)) ret = false;
x >>= 1, y >>= 1;
}
return ret;
}
int main(void){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N; cin >> N;
vector<ll> A(N); rep(i, N) {cin >> A[i]; A[i] %= 200;}
if(N >= 20){
int states = (1 << 10);
vector<int> resB(states), resC(states);
rep(i, states){
int val = i;
ll acc = 0;
rep(j, 10){
if(val&1) (acc += A[j]) %= 200;
val >>= 1;
}
resB[i] = acc;
}
rep(i, states){
int val = i;
ll acc = 0;
rep(j, 10){
if(val&1) (acc += A[j+10]) %= 200;
val >>= 1;
}
resC[i] = acc;
}
rep(i, states){
rep(j, states){
if(i == 0 || j == 0) continue;
if(resB[i] == resC[j]){
cout << "Yes" << endl;
int valB = i, valC = j;
cout << __builtin_popcount(valB) << " ";
rep(k, 10){
if(valB&1) cout << k+1 << " ";
valB >>= 1;
}
cout << endl;
cout << __builtin_popcount(valC) << " ";
rep(k, 10){
if(valC&1) cout << k+11 << " ";
valC >>= 1;
}
cout << endl;
return 0;
}
}
}
}
else{
int states = (1 << N);
vector<int> res(states);
rep(i, states){
int val = i;
int acc = 0;
rep(j, N){
if(val&1) (acc += A[j]) %= 200;
val >>= 1;
}
res[i] = acc;
}
rep(i, states){
rep(j, states){
if(!issame(i, j) && res[i] == res[j]){
cout << "Yes" << endl;
int valB = i, valC = j;
cout << __builtin_popcount(valB) << " ";
rep(k, 10){
if(valB&1) cout << k+1 << " ";
valB >>= 1;
}
cout << endl;
cout << __builtin_popcount(valC) << " ";
rep(k, 10){
if(valC&1) cout << k+1 << " ";
valC >>= 1;
}
cout << endl;
return 0;
}
}
}
cout << "No" << endl;
}
return 0;
} |
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0)
const double EPS = 1e-10;
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
int main(){
int T; cin >> T;
while(T--) {
string s; cin >> s;
int n = s.size();
string t = "atcoder";
if(s > t){
cout << 0 << endl;
continue;
}
bool ok = false;
rep(i,n) {
if(s[i] != 'a') ok = true;
}
if(!ok){
cout << -1 << endl;
continue;
}
int ans = INF;
repr(i,1,n){
if(s[i] > 't') {
ans = min(ans,i-1);
}
else if(s[i] != 'a') {
ans = min(ans,i);
}
}
cout << ans << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000007
#define pii pair<ll, ll>
#define prdb(pranay) cout << fixed << setprecision(10) << pranay;
#define speed1 ios_base ::sync_with_stdio(false);
#define speed2 cin.tie(NULL);
#define speed3 cout.tie(NULL);
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
speed1;
speed2;
speed3;
ll t = 1;
// cin >> t;
while (t--)
{
ll n;
cin >> n;
vector<ll> v(n);
ll i, j;
ll gcd;
for (i = 0; i < n; i++)
cin >> v[i];
sort(v.begin(), v.end(), greater<ll>());
gcd = v.back();
for (i = 0; i < n - 1; i++)
gcd = __gcd(gcd, v[i]);
cout << gcd;
}
} |
#include <bits/stdc++.h>
/* #include <atcoder/all> */
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
using namespace std;
/* using namespace atcoder; */
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
vector<int> x(n), y(n);
rep(i, n) {
cin >> x.at(i);
cin >> y.at(i);
}
int res = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
double tmp = (double) (y.at(j) - y.at(i)) / (x.at(j) - x.at(i));
if (tmp >= -1.0 && tmp <= 1.0) {
res++;
}
}
}
cout << res << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define n_l '\n'
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define forn(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef double db;
typedef vector<vi> vvi;
const ll mod=1000000007;
const ll N=200005; //check this
int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powb(ll a,ll b) {ll res=1;a ; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
bool cmp(pair<ll,ll> a, pair<ll,ll> b){
return (a.fi)*2 + a.se > (b.fi)*2 + b.se;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;
// cin>>t;
while(t--){
int n;cin >> n;
vector<pii> a(n);
int ans = 0;
for(int i = 0;i < n; i++){
cin >> a[i].fi >> a[i].se;
for(int j = 0;j < i; j++){
if(abs(a[i].fi-a[j].fi) >= abs(a[i].se - a[j].se) )
ans++;
}
}
cout << ans;
}
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; i++) cin >> s.at(i);
vector<vector<ll>> dp(n + 1, vector<ll>(2)); // T, F
dp[0][0] = dp[0][1] = 1;
for (int i = 0; i < n; i++) {
if (s[i] == "AND") {
dp[i + 1][0] += dp[i][0];
dp[i + 1][1] += dp[i][0] + dp[i][1] * 2;
}
else {
dp[i + 1][0] += dp[i][0] * 2 + dp[i][1];
dp[i + 1][1] += dp[i][1];
}
}
cout << dp[n][0] << '\n';
} | #include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define forn(i,x1,n) for(int i=x1; i<n; i++)
#define forit(it, m) for(decltype(m)::iterator it = m.begin(); it!=m.end(); ++it)
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x1) __builtin_popcountll(x1)
#define zrobits(x1) __builtin_ctzll(x1)
#define mod 1000000007
// #define mod 998244353
#define inf 1e18
#define ps(x1,y) fixed<<setprecision(y)<<x1
#define mk(arr,n,type) type *arr=new type[n];
#define w(x1) int x1; cin>>x1; while(x1--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void zeus()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
zeus();
int n, q; cin >> n >> q;
int a[n + 1];
forn(i, 0, n) {
cin >> a[i];
}
a[n] = 0;
sort(a, a + n + 1);
int diff[n];
forn(i, 0, n) {
diff[i] = a[i + 1] - a[i] - 1;
}
int prefixsum[n + 1];
prefixsum[0] = 0;
forn(i, 0, n) {
prefixsum[i + 1] = prefixsum[i] + diff[i];
}
forn(i, 0, q) {
int k; cin >> k;
auto ind = lower_bound(prefixsum, prefixsum + n + 1, k) - prefixsum;
cout << a[ind - 1] + k - prefixsum[ind - 1] << endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
void solve()
{
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
int it = *min_element(a.begin(), a.end());
unordered_map<int, int> mp;
auto add = [&](int x, int val) {
if (x >= it)
return;
if (!mp.count(x))
mp[x] = val;
else
{
mp[x] = __gcd(val, mp[x]);
}
};
for (int t : a)
{
for (int j = 1; j * j <= t; j++)
if (t % j == 0)
{
add(j,t);
add(t / j,t);
}
}
int ans = 1;
for (auto [i, j] : mp)
if (i == j)
ans++;
cout << ans << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
while (T--)
{
solve();
}
} | #include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
long long gcd(long long a, long long b) {
if (b == 0) return a;
else return gcd(b, a%b);
}
long long lcm(long long x, long long y) {
return x * y / gcd(x, y);
}
map<long long, long long>mp;
//約数列挙
void calc(long long N) {
for (long long i = 1; i <= sqrt(N); i++) {
if (0 == N % i) {
mp[i] = gcd(mp[i], N);
if (N != i * i) {
mp[N / i] = gcd(mp[N / i], N);
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<long long>A(N);
rep(i, N) {
cin >> A[i];
}
long long minA = 1e18;
rep(i, N) {
minA = min(minA, A[i]);
}
rep(i, N) {
calc(A[i]);
}
int ans = 0;
for (auto p : mp) {
if ((p.first <= minA) && (p.first == p.second)) {
ans++;
}
}
cout << ans << endl;
return 0;
} |
#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
#define MOD 998244353
int W[100],fact[1000];
int dp[2][10001][101];
int main() {
int i;
int N;
scanf("%d",&N);
for (i = 0; i < N; i++) scanf("%d",&W[i]);
int j,k;
int sum = 0;
dp[1][0][0] = 1;
fact[0] = 1;
for (i = 1; i < 1000; i++) fact[i] = ((LLI) i*fact[i-1]) % MOD;
for (i = 0; i < N; i++) {
int p = i & 1;
sum += W[i];
for (j = 0; j <= sum; j++) {
for (k = 0; k <= i+1; k++) {
dp[p][j][k] = dp[!p][j][k];
if ((j-W[i] >= 0) && (k > 0)) {
dp[p][j][k] += dp[!p][j-W[i]][k-1];
if (dp[p][j][k] >= MOD) dp[p][j][k] -= MOD;
}
}
}
}
LLI ans = 0;
if (!(sum & 1)) {
i = sum/2;
for (j = 0; j <= N; j++) {
ans += (((LLI) dp[(N-1) & 1][i][j]*fact[j]) % MOD)*fact[N-j];
ans %= MOD;
}
}
cout << ans << endl;
return 0;
}
| #pragma GCC optimize("O3")
// #include <atcoder/all>
// using namespace atcoder;
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;
using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }
template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
while(*sdbg!=',')cerr<<*sdbg++;
cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}
template<class T> ostream &operator<<(ostream& os, vector<T> V) {
os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
return os << "(" << P.st << "," << P.nd << ")";
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif
// using mint = modint998244353;
// ostream& operator<<(ostream& out, mint m){
// out << m.val();
// return out;
// }
const int P = 998244353;
void add(int &a,int b){
a += b;
if(a >= P)
a -= P;
}
void sub(int &a,int b){
a -= b;
if(a < 0)
a += P;
}
int mul(int a,int b){
return a * b % P;
}
int n;
int res = 0;
vector<vector<int>> dp;
vector<int> t;
void add(int x){
int pom = t[x];
int a = SZ(dp);
int b = SZ(dp[0]);
vector<vector<int>> dp2(a + 1,vector<int>(b + pom));
R(i,a)R(j,b){
add(dp2[i + 1][j + pom], mul(dp[i][j], i + 1));
if(j <= pom){
add(dp2[a - i][pom - j], mul(dp[i][j], a - i));
}else{
add(dp2[i][j - pom], mul(dp[i][j], a - i));
}
}
// debug(dp,pom,dp2);
swap(dp,dp2);
}
void licz(int po,int ko){
if(po + 1 == ko){
debug(po,dp);
R(i,SZ(dp)){
R(j,min(SZ(dp[0]), t[po])){
sub(res, dp[i][j]);
}
}
debug(po,t[po],res);
return;
}
int m = (po + ko) / 2;
auto pam = dp;
for(int i = po; i < m; i++)add(i);
licz(m,ko);
swap(dp,pam);
for(int i = m; i < ko; i++)add(i);
licz(po,m);
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(11);
cerr << fixed << setprecision(6);
cin >> n;
t.resize(n);
res = 1;
R(i,n){
cin >> t[i];
res = mul(res, i + 1);
}
debug(res);
dp.resize(1,vector<int>(1,1));
licz(0,n);
cout << res << "\n";
}
|
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
ll power(ll a, ll b)
{
ll ans = 1;
if(b==0) return ans;
while(b>0)
{
if(b%2==0)
{
a = (a*a)%mod;
b/=2;
}
else
{
ans = (ans * a)%mod;
b-=1;
}
}
return ans;
}
int main()
{
int n;
cin>>n;
char aa, ab, ba, bb;
cin>>aa>>ab>>ba>>bb;
if(n<=3) cout<<1;
else if((bb=='B' && ab=='B')|| (aa == 'A' && ab =='A')) cout<<1;
else if((ab=='B' && ba=='B') || (ab=='A' && ba=='A'))
{
int a[1001];
a[2] = 1;
a[3] = 1;
for(int i = 4; i<1001; i++) a[i] = (a[i-1] + a[i-2])%mod;
cout<<a[n];
}
else
{
cout<<power(2, n-3);
}
} | #include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
using ll = long long;
ll MOD = 1e9+7;
ll g(ll x){
int ret = 1;
for(int i = 0;i<x;i++){
(ret*=2)%=MOD;
}
return ret;
}
ll f(ll x){
ll ret;
ll ret_1 = 1;
ll ret_2 = 1;
for(int i = 0;i<x-1;i++){
(ret = ret_1 + ret_2)%=MOD;
ret_2 = ret_1;
ret_1 = ret;
}
return ret;
}
int main()
{
int n;cin >> n;
char c[4];
for(int i = 0;i<4;i++)cin >> c[i];
if(n<4){
cout<<1<<endl;
return 0;
}
ll ans;
if( c[0]=='A'&&c[1]=='A') ans=1;
else if( c[1]=='B'&& c[3]=='B')ans=1;
else if( c[1]=='B'&&c[2]=='A'&&c[3]=='A')ans = g(n-3);
else if(c[0]=='B'&&c[1]=='A'&&c[2]=='B') ans = g(n-3);
else if( c[1]=='B'&&c[2]=='B'&&c[3]=='A')ans = f(n-2);
else if(c[0]=='B'&&c[1]=='A'&&c[2]=='A') ans = f(n-2);
cout<<ans<<endl;
}
|
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORX(i, a, b, x) for (ll i = (a); i <= (b); i+=x)
#define debug(x) cout <<" || "<< #x << " is= " << x <<endl; //use for debug
#define read(a) ll a; cin >> a;
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define pr pair<long double,long double>
#define vpll vector<pair<ll,ll>>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend() //reverse of above;
#define sz(container) int((container).size())
#define cut(x) {cout<<x<<"\n"; continue;}
#define setprec(x) cout << fixed << showpoint << setprecision(15)<<x<<"\n";
#define time cout << clock() / double(CLOCKS_PER_SEC) << endl;
#define endl '\n';
#define mod 1000000007
#define mod1 998244353
#define pi 3.141592653589793238
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
//*s.find_by_order() ->returns an iterator to the k-th largest element (counting from zero);
//s.order_of_key() ->number of elements strictly smaller then our item;
//st.rbegin()->second; last element in set
//st.erase(prev(st.end())); delete last element in set;
//sort(a+1,a+n+1,[](ll x,ll y){return abs(x)>abs(y);});
//sort(v.begin(), v.end(), greater<int>()); -> not sure work for first also if second are equal;
//q=lower_bound(all(v[a[i]]),i)-v[a[i]].begin()+1;
// s.substr(start_ind,length);
// vpll shift={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}} ->shift operator;
//bool comp(pr a,pr b){return a.second<b.second;} // use for differentiate order of comparision;
// cntbit(x) __builtin_popcount(x); -> no. of bits in given no.;
//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
const ll MAXN=2e7+5;
const ll inf=1e18+5;
int main()
{
fast_io;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
//“Don’t wish it were easier. Wish you were better.” – Jim Rohn;
ll n; cin>>n;
long double a[10];
FOR(i,1,4) cin>>a[i-1];
long double h,k,x,y,radius;
h=(a[0]+a[2])/2.0;
k=(a[1]+a[3])/2.0;
// shift p0 wrt h,k ant. clkwise;
long double theta=2*pi/(n*1.0);
//debug(theta);
a[0]-=h,a[1]-=k;
x=a[0]*cos(theta)-a[1]*sin(theta);
y=a[0]*sin(theta)+a[1]*cos(theta);
x+=h,y+=k;
setprec(x); setprec(y);
} | #include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef pair<int, int> PII;
const int N = 4e5 + 10;
PII a[N];
int b[N];
int stk[N], top;
int main(){
int n; scanf("%d", &n);
for(int i = 1; i <= 2 * n; i ++){
scanf("%d", &a[i].first);
a[i].second = i;
}
sort(a + 1, a + 1 + 2 * n);
for(int i = 1; i <= n; i ++)
b[a[i].second] = 1;
for(int i = 1; i <= 2 * n; i ++)
if(!top){
printf("(");
stk[++ top] = i;
}
else{
if(b[i] == b[stk[top]]){
printf("(");
stk[++ top] = i;
}
else{
printf(")");
top --;
}
}
return 0;
} |
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const long double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
vi x(n),y(n);
rep(i,n)cin>>x[i]>>y[i];
int m;
cin>>m;
vvi dp;
// left, up, right, down
dp.pb({0,0,2,1});
rep(i,m){
int q;
cin>>q;
vi t=dp.back();
if(q==1){
(t[2]+=1)%=4;
(t[3]+=1)%=4;
int nx=t[1],ny=-t[0];
t[0]=nx;
t[1]=ny;
}else if(q==2){
(t[2]+=3)%=4;
(t[3]+=3)%=4;
int nx=-t[1],ny=t[0];
t[0]=nx;
t[1]=ny;
}else if(q==3){
int a;cin>>a;
if(t[2]==0||t[2]==2){
(t[2]+=2)%=4;
t[0]=2*a-t[0];
}else{
(t[3]+=2)%=4;
t[0]=2*a-t[0];
}
}else{
int a;cin>>a;
if(t[2]==1||t[2]==3){
(t[2]+=2)%=4;
t[1]=2*a-t[1];
}else{
(t[3]+=2)%=4;
t[1]=2*a-t[1];
}
}
dp.pb(t);
}
int q;
cin>>q;
while(q--){
int a,b;
cin>>a>>b;b--;
if(dp[a][2]==0||dp[a][2]==2)
cout<<dp[a][0]+dx[dp[a][2]]*x[b]<<" "<<dp[a][1]+dy[dp[a][3]]*y[b]<<endl;
else
cout<<dp[a][0]+dx[dp[a][3]]*y[b]<<" "<<dp[a][1]+dy[dp[a][2]]*x[b]<<endl;
// cout<<dp[a][1]+dx[dp[a][3]]*y[b]<<" "<<dp[a][0]+dy[dp[a][2]]*x[b]<<endl;
}
}
| #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
// #define TEST_CASES
// #define ONLINE_JUDGE
#define test \
long long t; \
cin >> t; \
while (t--)
#ifndef ONLINE_JUDGE
#define reach(x) cout << "\n\t\t" << x << "\n\n";
#define deb(x) cout << #x << " " << x << '\n';
#define deb2(x, y) cout << #x << " --> " << x << " || " << #y << " --> " << y << '\n';
#define deb4(a, b, c, d) cout << #a << " = " << a << ", " << #b << " = " << b << ", " << #c << " = " << c << ", " << #d << " = " << d << '\n';
#else
#define reach(x) //
#define deb(x) //cout << #x << " " << x << '\n';
#define deb2(x, y) //cout << #x << " --> " << x << " || " << #y << " --> " << y <<'\n';
#define deb4(a, b, c, d) // cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<", "<<#c<<" = "<<c<<", "<<#d<<" = "<<d<<'\n';
#endif
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; i < n; i++)
#define boost() \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0); \
cout << fixed << setprecision(11);
#define MEM(a, val) memset(a, val, sizeof(a));
#define inputarr(a, n) \
for (int i = 0; i < n; ++i) \
cin >> a[i]
const long long INF = LONG_LONG_MAX, MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
using namespace std;
void solve()
{
ll n, i, j;
cin >> n;
vector<ll> r, g, b;
//logic start
char ch;
ll a;
fo(i, 2 * n)
{
cin >> a >> ch;
if (ch == 'R')
r.push_back(a);
else if (ch == 'G')
g.push_back(a);
else
b.push_back(a);
}
ll gs = g.size();
ll rs = r.size();
ll bs = b.size();
if (rs % 2 == 0 && gs % 2 == 0 && bs % 2 == 0)
{
cout << 0LL;
return;
}
if (rs % 2 == 0)
{
swap(r, g);
}
else if (bs % 2 == 0)
swap(b, g);
rs = r.size();
bs = b.size();
sort(b.begin(), b.end());
sort(r.begin(), r.end());
// sort(b.begin(), b.end());
ll ri = 0, bi = 0;
ll ans = abs(r[0] - b[0]);
for (ri = 0; ri < rs; ++ri)
{
ll ele = lower_bound(b.begin(), b.end(), r[ri]) - b.begin();
// deb(ele);
if (ele != bs)
ans = min(ans, abs(r[ri] - b[ele]));
if (ele != 0)
ans = min(ans, abs(r[ri] - b[ele - 1]));
}
if (g.size())
{
ll res1 = abs(g[0] - r[0]), res2 = abs(g[0] - b[0]);
for (ll x : g)
{
ll ele = lower_bound(b.begin(), b.end(), x) - b.begin();
// deb(ele);
if (ele != bs)
res2 = min(res2, abs(x - b[ele]));
if (ele != 0)
res2 = min(res2, abs(x - b[ele - 1]));
ele = lower_bound(r.begin(), r.end(), x) - r.begin();
// deb(ele);
if (ele != rs)
res1 = min(res1, abs(x - r[ele]));
if (ele != 0)
res1 = min(res1, abs(x - r[ele - 1]));
}
ans = min(ans, res1 + res2);
}
cout << ans;
}
signed main()
{
#ifdef ONLINE_JUDGE
boost()
#endif
#ifdef TEST_CASES
test
#endif
{
#ifdef TEST_CASES
// reach("--------------------------------------------");
#endif
solve();
#ifdef TEST_CASES
cout << '\n';
// reach("--------------------------------------------");
#endif
}
return 0;
}
|
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
ll read(){
char C=getchar();
ll N=0 , F=1;
while(('0' > C || C > '9') && (C != '-')) C=getchar();
if(C == '-') F=-1 , C=getchar();
while('0' <= C && C <= '9') N=(N << 1)+(N << 3)+(C - 48) , C=getchar();
return F*N;
}
ll n,p;
ll power(ll a,ll b){
ll ans = 1;
while(b){
if(b & 1)ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
int main(){
n = read();
p = read();
p -= 1;
std::cout<<(p * power(p - 1,n - 1)) % mod<<std::endl;
}
| #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
#define pb push_back
#define T ll testx; cin>>testx; while(testx--)
#define print(name) for(auto t:name){cout<<t<<" ";}cout<<endl;
#define printii(name) for(auto t:name){cout<<t.first<<" "<<t.second<<endl;}
#define mod 1000000007
#define modx 998244353
#define inf 2000000000000000000
#define mem(name,val) memset(name,val,sizeof(name))
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define endl "\n"
#define popcount(x) __builtin_popcountll(x)
#define precise cout<<fixed<<setprecision(15)
const long double pi = acos(-1);
ll gcd(ll a,ll b){if(b==0){return a;}return gcd(b,a%b);}
ll modexp(ll x,ll n)
{
if(n==0)
{return 1;}
else if(n%2 == 0)
{return modexp((x*x)%mod,n/2);}
else
{return (x*modexp((x*x)%mod,(n-1)/2))%mod;}
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n,p;cin>>n>>p;
ll res=modexp(p-2,n-1);
res*=(p-1);
res%=mod;
cout<<res<<endl;
} |
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll=long long;
using ld=long double;
using pll=pair<ll, ll>;
//using mint = modint1000000007;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo 2e18
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
//priority_queue<ll, vector<ll>, greater<ll>> Q;
/*
bが入ったら、aの、それ未満を上書き。 それ以上は関係ない
aが入ったら、bの未満を上書き
BIT2つかな
*/
// BIT,index = 1 ~ (0を投げるととまる)
// https://atcoder.jp/contests/abc174/submissions/21572028
//indexにする・・・?ちょうたいへん
#define M 200010
ll dat1[M], dat2[M], dat3[M], dat4[M]; //34=累積いれとく?
void add(ll i, ll x, ll id){
if (id==1)
for(; i<M; i += i&-i) dat1[i] += x;
if (id==2)
for(; i<M; i += i&-i) dat2[i] += x;
if (id==3)
for(; i<M; i += i&-i) dat3[i] += x;
if (id==4)
for(; i<M; i += i&-i) dat4[i] += x;
}
ll sum(ll i, ll id){
ll res = 0;
if (id==1)
for(; i>0; i -= i&-i) res += dat1[i];
if (id==2)
for(; i>0; i -= i&-i) res += dat2[i];
if (id==3)
for(; i>0; i -= i&-i) res += dat3[i];
if (id==4)
for(; i>0; i -= i&-i) res += dat4[i];
return res;
}
ll rangesum(ll L, ll R, ll id){
return sum(R, id) - sum(L-1, id);
}
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(10);
ll n, m, q;
cin >> n >> m >> q;
ll used[3][200010]; //t, x
rep(i, 3) rep(j, 200010) used[i][j]=1;
ll ans = n*m;
add(1, n, 1); //1->0
add(1, m, 2);
add(1, n, 3); //1->0
add(1, m, 4);
//34が累積和
ll T[200010];
ll X[200010];
ll Y[200010];
map<ll, ll> mp1; // val->id
map<ll, ll> mp2; // id->val
set<ll> se;
se.insert(1);
rep(i, q){
cin >> T[i] >> X[i] >> Y[i];
Y[i]++;
se.insert(Y[i]);
}
ll cnt = 1;
for(auto v: se){
mp1[v] = cnt++;
}
cnt=1;
for(auto v: se){
mp2[cnt++]=v;
}
rep(i, q){
ll t=T[i];
ll x=X[i];
ll y=Y[i];
ll z=used[t][x]; //val
//まず除く
ll zz=mp1[z];//id
ans -= z*sum(zz, t^3); // もとあった値をなかったことに
ans += sum(zz, (t^3)+2); // なかった場合の復元
add(zz, -1, t);
add(zz, -z, t+2);//累積
used[t][x]=y;
ll yy=mp1[y]; //id
ans -= sum(yy, (t^3)+2);
ans += y*sum(yy, (t^3));
add(yy, 1, t);
add(yy, y, t+2);
cout << ans -n*m<< endl;
}
} | #include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
ll N,M,Q;
map<ll,ll>mp;
map<ll,ll>mp1;
P dat[2][800005];
ll n;
void init(ll n_){
n=1;
while(n<=n_)n*=2;
for(ll i=0;i<2*n-1;i++){
dat[0][i]=P(0,0);
dat[1][i]=P(0,0);
}
}
void update(ll j,ll k,ll a){
ll m=mp1.at(k); k+=n-1;
dat[j][k].first+=a;dat[j][k].second+=a*m;
while(0<k){
k=(k-1)/2;
dat[j][k].first=(dat[j][2*k+1].first+dat[j][2*k+2].first);
dat[j][k].second=(dat[j][2*k+1].second+dat[j][2*k+2].second);
}
}
P query(ll j,ll a,ll b,ll k,ll l,ll r){
if(a<=l&&r<=b)return dat[j][k];
else if(b<=l||r<=a)return P(0,0);
else{
P val=query(j,a,b,2*k+1,l,(l+r)/2);
P var=query(j,a,b,2*k+2,(l+r)/2,r);
P p(val.first+var.first,val.second+var.second);
return p;
}
}
int main(){
cin>>N>>M>>Q;
set<ll>S;S.insert(0);
vector<ll>T(Q);vector<ll>X(Q);vector<ll>Y(Q);
for(ll q=0;q<Q;q++){
cin>>T[q];cin>>X[q];X[q]--;cin>>Y[q];S.insert(Y[q]);
}ll I=0;
for(auto x:S){mp[x]=I;I++;}
for(auto p:mp){mp1[p.second]=p.first;}vector<ll>A(N);vector<ll>B(M);ll ans=0;
init(I);update(0,0,N);update(1,0,M);
for(ll q=0;q<Q;q++){
if(T[q]==1){
ans-=query(1,0,mp.at(A[X[q]])+1,0,0,n).first*A[X[q]];
if(A[X[q]]<Y[q]){
ans-=query(1,mp.at(A[X[q]])+1,mp.at(Y[q])+1,0,0,n).second;
}else if(Y[q]<A[X[q]]){
ans+=query(1,mp.at(Y[q])+1,mp.at(A[X[q]])+1,0,0,n).second;
}else{}
ans+=query(1,0,mp.at(Y[q])+1,0,0,n).first*Y[q];update(0,mp.at(A[X[q]]),-1);
update(0,mp.at(Y[q]),1);A[X[q]]=Y[q];
}else{
ans-=query(0,0,mp.at(B[X[q]])+1,0,0,n).first*B[X[q]];
if(B[X[q]]<Y[q]){
ans-=query(0,mp.at(B[X[q]])+1,mp.at(Y[q])+1,0,0,n).second;
}else if(Y[q]<B[X[q]]){
ans+=query(0,mp.at(Y[q])+1,mp.at(B[X[q]])+1,0,0,n).second;
}else{}
ans+=query(0,0,mp.at(Y[q])+1,0,0,n).first*Y[q];update(1,mp.at(B[X[q]]),-1);
update(1,mp.at(Y[q]),1);B[X[q]]=Y[q];
}cout<<ans<<endl;
}
return 0;
} |
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff first
#define ss second
#define int long long
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define mod 998244353
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define vpii vector<pair<int,int> >
#define all(x) x.begin(),x.end()
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y) for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz(x) (int)x.size()
#define db(x) cout<<x<<"\n";
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//insert,find_by_order,order_of_key,lower_bound,upper_bound;
#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define deb(...)
#endif
//////////////////////////////code//////////////////////////////
const int N = 200;
void solve()
{
int ans = 1;
int a , b;
cin >> a >> b;
for(int i = 1; i <= b ; i++)
{
int val1 = (a+i-1)/i;
int val2 = val1 + 1;
// deb(i,val1,val2);
if(i*val1 >= a && i*val2 <= b)
{
ans = max(ans,i);
}
}
db(ans)
}
int32_t main()
{
LETS_GET_SCHWIFTY;
#ifndef ONLINE_JUDGE
freopen("INP.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int t = 1;
//cin >> t;
while (t--)
solve();
}
// check out for following mistakes-
// if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only
// is using prime sieve make sure it fits
// when using factorial template or combinatorics make sure that you edit fillfac fun values and array values
| #include<bits/stdc++.h>
using namespace std;
#define DONTSYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) //dont use stdio with iostream functions //input and output are out of order now!
#define TEST unsigned long long T; cin>>T; while(T--) //loop over each testcase
#define endl "\n"
#define fori(a,start,end) for(int a=start;a<end;a++)
#define forll(a,start,end) for(long long a=start;a<end;a++)
#define forull(a,start,end) for(unsigned long long a=start;a<end;a++)
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
const double PI = acos(-1);
void solve(){
/* code */
int a,b; cin>>a>>b;
int res=1;
fori(gd,2,b+1){
if(b/gd*gd-gd>=a) res=gd;
}
cout<<res<<endl;
}
int main()
{
DONTSYNC;
// TEST
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define ll long long
const int MAX_N = 2e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
void solve()
{
int v, t, s, d;
cin >> v >> t >> s >> d;
if (d >= v * t && d <= v * s)cout << "No" << endl;
else cout << "Yes" << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input1.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
#endif
int t = 1;
//cin >> t;
while (t--)
solve();
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
ll r,x,y;
cin >> r >> x >> y;
ll ans = 1;
if(r*r == x*x+y*y) {
cout << 1 << endl;
return 0;
}
if(r*r > x*x+y*y) {
cout << 2 << endl;
return 0;
}
while((ans*r*ans*r) < x*x+y*y){ ans++;}
cout << ans << endl;
}
|
#include<bits/stdc++.h>
#define ll long long
#define mll map<ll,ll>
#define u_mll unordered_map<ll,ll>
#define pll pair<ll,ll>
#define sll set<ll>
#define msll multiset<ll>
#define usll unordered_set<ll>
#define vll vector<ll>
#define vv vector
#define pqll priority_queue<ll, vll, greater<ll> ()>
#define pql priority_queue<ll>
#define MAX 19999999
#define ff first
#define ss second
#define pb push_back
#define srt(s) sort(s.begin(), s.end())
#define srtr(rs) sort(s.rbegin(), s.rend())
#define f(i,a,n) for(ll i = a; i < n; i++)
#define f1(i,a,n) for(ll i = a; i <= n; i++)
#define fr(i,a,n) for(ll i = n; i > a; i--)
#define abc int main
#define close_kor_taratari return 0
#define endl "\n"
#define testcase ll t; cin>>t; while(t--)
using namespace std;
bool isprime(ll n) {
if(n < 2) return false;
for(ll i = 2; i * i <= n; i++) {
if(n % i == 0)
{
return false;
}
}
return true;
}
bool perfect_sqr(ll n) {
ll a = sqrt(n);
return (a * a == n);
}
bool isfibo(ll n) {
return perfect_sqr(5*n*n + 4) or perfect_sqr(5*n*n - 4);
}
bool Max(ll a, ll b) {
return a > b;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll m, h;
cin>>m>>h;
if(h % m == 0) {
cout<<"Yes";
}
else {
cout<<"No";
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())
#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))
#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed
bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }
vector<ll> calc_all_sums(vector<ll> &v) {
vector<ll> retv;
int N = v.size();
for (ull bits = 0; bits < (1ULL << N); bits++) {
ll sum = 0;
for (size_t i = 0; i < N; i++) {
if ((bits & (1ULL << i)) != 0) {
sum += v[i];
}
}
retv.push_back(sum);
}
sort(ALL(retv));
retv.erase(unique(ALL(retv)), retv.end());
return retv;
}
ll solve(int N, ll T, vector<ll> &A) {
int mid_N = N / 2;
vector<ll> left_A{A.begin(), A.begin() + mid_N};
vector<ll> right_A{A.begin() + mid_N, A.end()};
vector<ll> left_sums = calc_all_sums(left_A);
vector<ll> right_sums = calc_all_sums(right_A);
ll retv = 0;
for (auto &&l_sum : left_sums) {
ll max_r_sum = T - l_sum;
auto r_upper_itr = upper_bound(ALL(right_sums), max_r_sum);
ll r_sum = (r_upper_itr != right_sums.begin() ? *(r_upper_itr - 1) : 0);
ll sum = l_sum + r_sum;
sum = (sum <= T ? sum : 0);
retv = max(retv, sum);
}
return retv;
}
int main() {
// get values from input
cin.tie(0);
ios::sync_with_stdio(false);
int N;
ll T;
cin >> N >> T;
vector<ll> A(N, 0);
for (size_t i = 0; i < N; i++) {
cin >> A[i];
}
// main procedure
ll ans = solve(N, T, A);
// output
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define MOD1 998244353
#define ceil(x, y) ((x)%(y))==0? ((x)/(y)) : ((x)/(y)+1)
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long */
void __print(int 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 dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("in9.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int T=1;
// cin >> T;
FOR1(tt, T){
// cout << "Case #" << tt << ": ";
int x; cin >> x;
cout << 100 - x % 100;
cout << '\n';
}
return 0;
} | #include<cstdio>
using namespace std;
int main(){
int n,a,sum=0;
scanf("%d",&n);
while(n--){
scanf("%d",&a);
a>10 ? sum+=a-10:0;
}
printf("%d\n",sum);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\n"
#define all(v) v.begin(), v.end()
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
// cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long int i;
typedef long long int lli;
typedef pair<lli, lli> pll;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli t;
cin >> t;
vector<lli> v;
for1(i, 0, t)
{
lli a;
cin >> a;
v.pb(a);
}
long double a2 = 0;
lli a3 = 0, a1 = 0;
for1(i, 0, t)
{
a1 += abs(v[i]);
if (abs(v[i]) > a3)
{
a3 = abs(v[i]);
}
a2 += (long double)(v[i] * v[i]);
}
long double a4 = sqrtl(a2);
cout << a1 << endl;
cout << fixed << setprecision(15) << a4 << endl;
cout << a3 << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main() {
int N; cin >> N;
vector<long long> A(N);
for(auto &e : A) cin >> e;
long long m = 0;
for(auto &e : A) m += abs(e);
cout << m << '\n';
double y = 0;
for(auto &e : A) y += double(e) * e;
y = sqrt(y);
printf("%.15lf\n", y);
long long c = 0;
for(auto &e : A) c = max(c, abs(e));
cout << c << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef long double ld;
typedef pair<int,int> pii;
#define x first
#define y second
int ppow(int x,int y,int mod)
{
int res=1;
while(y)
{
if(y&1)
res=res*x%mod;
y>>=1;
x=x*x%mod;
}
return res;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
cout<<ppow(10,n,m*m)/m;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)
ll modpow(ll a, ll n, ll m)
{
ll ret = 1;
while (n > 0)
{
if (n % 2 == 1) ret = ret * a % m;
a = a * a % m;
n /= 2;
}
return ret;
}
int main()
{
ll N, M;
cin >> N >> M;
ll X = modpow(10, N, M * M);
ll Y = modpow(10, N, M);
cout << mod(X - Y, M * M) / M << endl;
} |
#pragma region shig_templates
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pairI2;
typedef pair<LL, LL> pairLL2;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
#define shig_for(i, a, b) for(int i = (a); i < (b); ++i)
#define shig_rep(i, n) shig_for(i, 0, n)
#define shig_forB(bit,a,b) for(int bit = (a); bit < (1<<(b)); ++bit)
#define shig_repB(bit,n) shig_forB(bit,0,n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define tmp int temp = 0
#define str string s
template<class T> void COUT(T&& t){ cout << t << endl; }
template<class T,class... Ts>
void COUT(T&& t,Ts&&... ts){ cout << t << " "; COUT(ts...); }
void CIN() {}
template<class T,class... Ts> void CIN(T&& t,Ts&&... ts){ cin >> t; CIN(ts...); }
#pragma endregion
int main(){
LL N;
CIN(N);
vector<VLL> C(N, VLL(N, 0));
shig_rep(i, N){
shig_rep(j, N){
CIN(C[i][j]);
}
}
vector<VLL> check(N, VLL(N, 0));
shig_rep(i, N){
shig_rep(j, N){
if(j == 0)continue;
check[i][j] = C[i][j-1] - C[i][j];
}
}
shig_rep(i, N){
if(i == 0)continue;
shig_rep(j, N){
if(check[i][j] != check[i-1][j]){
COUT("No");
return 0;
}
}
}
LL mum = numeric_limits<int>::max();
int itr = -1;
shig_rep(i, N){
if(C[i][0] < mum){
mum = min(mum, C[i][0]);
itr = i;
}
}
COUT("Yes");
shig_rep(i, N){
cout << (C[i][0] - mum) << " ";
}
cout << endl;
shig_rep(j, N){
cout << C[itr][j] << " ";
}
cout << endl;
//COUT(N);
//for(string& s : S) cin >> s;
//cout << fixed << setprecision(10) << ans << endl;
return 0;
} | #include<bits/stdc++.h>
#define ll long long
using namespace std;
template <typename T, typename TT>
void print(T c, TT a,int n){
vector<int> r;
for(int i=0;i<n;i++)
r.push_back(a[i][0] - c[0]);
int mi = *min_element(r.begin(), r.end());
if(mi<0){
for(auto &x:r) x+=abs(mi);
for(auto &x:c) x-=abs(mi);
}
cout<<"Yes\n";
for(auto x:r) cout<<x<<" ";
cout<<"\n";
for(auto x:c) cout<<x<<" ";
cout<<"\n";
}
void solve(){
int n;cin>>n;
vector<vector<int>>a(n, vector<int>(n));
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
for(int i=0;i<n;i++){
vector<int> c = a[i];
int fail = 0;
for(int j=0;j<n && !fail;j++){
if(j==i) continue;
vector<int>temp(n);
for(int k=0;k<n;k++){
temp[k] = a[j][k] - c[k];
}
sort(temp.begin(), temp.end());
if(temp[0] != temp.back()){
fail = 1;
break;
}
}
if(!fail){
print(c, a, n);
return;
}
}
cout<<"No\n";
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
solve();
return 0;
}
|
/*
/^--^\
\____/
/ \ _____ _ __ __ ____ _ ____ ____ _____
| || ()_)| |\ \/ /| ===|| |__ / (__` / () \|_ _|
\__ __/ |_| |_|/_/\_\|____||____|\____)/__/\__\ |_|
|^|^\ \^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
| | |\ \| | | | | | | | | | | | | | | | | | | | | | | | |
#####/ /#################################################
| | |\/ | | | | | | | | | | | | | | | | | | | | | | | | |
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|*/
//#pragma GCC optimize("O4,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#define int ll //__int128
#define double long double
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fors(i,a,b,s) for(int i=a;i<=b;i+=s)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define L(id) (id*2+1)
#define R(id) (id*2+2)
#define LO(x) (x&(-x))
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair
#define MOD (int)(1000000007)
#define INF (int)(1e12)
#define EPS (1e-7)
#ifdef NYAOWO
#define debug(...) do{\
cerr << __LINE__ <<\
" : ("#__VA_ARGS__ << ") = ";\
_OUT(__VA_ARGS__);\
cerr << flush;\
}while(0)
template<typename T> void _OUT(T x) { cerr << x << "\n"; }
template<typename T,typename...I>
void _OUT(T x,I ...tail) { cerr << x << ", "; _OUT(tail...); }
inline void USACO(const string &s) { cerr<<"USACO: "<<s<<"\n"; }
#else
#define debug(...)
inline void USACO(const string &s){
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
#endif
inline void NYA(){ ios::sync_with_stdio(false); cin.tie(0); }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
inline int gcd(int a,int b) { return __gcd(a,b); }
inline int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p,const int &mod){
int ans=1;
while(p){
if(p&1) ans=ans*b%mod;
p/=2; b=b*b%mod;
}
return ans;
}
int fpow(int b,int p) { return fpow(b,p,MOD); }
template<typename T> inline void chmin(T &_a,const T &_b) { if(_b<_a) _a=_b; }
template<typename T> inline void chmax(T &_a,const T &_b) { if(_b>_a) _a=_b; }
int dis[1010][1010];
vector<int> adj[1010][26];
int32_t main(){
NYA();
//nachoneko so cute >/////<
int n,m; cin>>n>>m;
memset(dis,-1,sizeof(dis));
priority_queue<pair<int,pii>,vector<pair<int,pii>>,greater<pair<int,pii>>> pq;
//pair( dist , pair( s,t ) ) where s<=t
For(i,1,n) pq.emplace(0,mkp(i,i));
while(m--){
int a,b; cin>>a>>b;
char ch; cin>>ch;
adj[a][ch-'a'].eb(b);
adj[b][ch-'a'].eb(a);
if(a>b) swap(a,b);
pq.emplace(1,mkp(a,b));
}
while(!pq.empty()){
int d=pq.top().F;
int s=pq.top().S.F;
int t=pq.top().S.S;
pq.pop();
if(dis[s][t]!=-1) continue;
dis[s][t]=d;
For(ch,0,25){
for(auto &a:adj[s][ch]) for(auto &b:adj[t][ch]){
int x=min(a,b),y=max(a,b);
if(dis[x][y]==-1) pq.emplace(d+2,mkp(x,y));
}
}
}
cout<<dis[1][n]<<"\n";
return 0;
} | #pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
typedef pair<int,pii> P;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
VII dist(1001,vector<ll>(1001,INF));
vector<vector<pii>> adj(1001);
int main()
{
int n,m;
cin>>n>>m;
for(int i=0;i<m;i++){
int u,v;
char c;
cin>>u>>v>>c;
c-='a';
adj[v].pb({u,c});
adj[u].pb({v,c});
}
queue<pii>q;
dist[1][n] = 0;
q.push({1,n});
while(!q.empty()){
pii v = q.front();
q.pop();
for(pii x:adj[v.fi]){
for(pii y:adj[v.se]){
if(x.se == y.se && dist[x.fi][y.fi] == INF){
dist[x.fi][y.fi] = dist[v.fi][v.se]+2;
q.push({x.fi,y.fi});
}
}
}
}
ll ans = INF;
for(int i=1;i<=n;i++){
ans = min(ans,dist[i][i]);
for(pii x:adj[i]){
ans = min(ans,dist[i][x.fi] + 1);
}
}
if(ans == INF)ans = -1;
cout<<ans;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define gt(a,b) get<b>(a)
#define endl '\n'
#define l_b lower_bound
#define u_b upper_bound
template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
ll INF = 2147483647000000;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
bool compare(ll u,ll v)
{
return v>u;
}
//unordered_map<long long, int, custom_hash> safe_map;
//oset<ar<int,2>>b,c; insert(),order_of_key(),find_by_order(return pointer);
ll prime[10000001];
ll freq[10000001];
ll co[10000001];
vector<ll> v[10000001];
int main()
{
fastio
ll t=1;
//cin>>t;
while(t--)
{
ll n;
cin>>n;
ll arr[n];
unordered_map<ll,vector<ll>,custom_hash> sm;
ll mn=INF;
for(int i=0; i<n; i++) cin>>arr[i],mn=min(mn,arr[i]);
set<ll> s;
for(int i=0; i<n; i++)
{
for(int j=1; j*j<=arr[i]; j++)
{
if(arr[i]%j==0)
{
if(arr[i]/j==j) sm[j].pb(arr[i]);
else sm[arr[i]/j].pb(arr[i]),sm[j].pb(arr[i]);
}
}
}
ll ans=0;
for(auto it:sm)
{
ll gc=0;
if(it.ff>=mn) continue;
for(auto itt:it.ss)
{
gc=__gcd(gc,itt);
}
if(gc==it.ff) ans++;
}
cout<<ans+1<<endl;
// for(auto it: s) cout<<it<<" ";
}
} | /*
Description
@authors Magneto
@date 2020-10-12 10:59:53
@version 1.2.3
*/
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ll long long
#define l long int
#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 endl '\n'
#define pb push_back
#define pf pop.front()
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " = " << x << endl;
#define lcm(a,b) a*b/__gcd(a,b)
using namespace std;
void solve()
{
l n;
cin>>n;
ll a[n];
for(l i=0;i<n;i++)
cin>>a[i];
ll ans= a[0];
for(l i=0;i<n;i++)
ans = __gcd(ans , a[i]);
cout<<ans<<endl;
}
int32_t main()
{
FAST
l T=1;
//cin>>T;
while(T--)
{
solve();
}
}
|
#include <iostream>
#include <vector>
#include <limits>
#include <cstring>
#include <time.h>
#include <math.h>
#include <algorithm>
#include <random>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <chrono>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii > vii;
typedef vector<vector<ll> > vvi;
typedef vector<vvi > vvvi;
typedef vector<vector<pair<ll, ll> > > vvii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,s,e) for(ll i=(s);i<(e);++i)
#define repr(i,s,e) for(ll i=(e);i>(s);--i)
#define io do { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } while (0)
#define endl '\n'
#define newl cout << '\n';
#define fill0(a) memset(a, 0, sizeof(a))
#define fill1(a) memset(a, -1, sizeof(a))
#define all(v) v.begin(), v.end()
#define bg begin()
#define ed end()
#define tr(it, v) for (auto it = v.bg; it != v.ed; it++)
#define prv(v) tr(it, v) { cout << *it << endl; }
#define prm(m) tr(it, m) { cout << it->first << " -> " << it->second << endl; }
#define scan(a, n) rep(i,0,n) cin >> a[i];
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define sumv(v) *accumulate(all(v), 0)
#define ub(a, x) upper_bound(all(a), x)
#define lb(a, x) lower_bound(all(a), x)
ll min3(ll a, ll b, ll c) { return min(a, min(b, c)); }
ll max3(ll a, ll b, ll c) { return max(a, max(b, c)); }
ll mid3(ll a, ll b, ll c) { return a + b + c - min3(a, b, c) - max3(a, b, c); }
ll ceil1(ll x, ll y) { if(x % y) return (x + y) / y; else return x / y; }
const ll MOD = 1e9+7;
const ll INF = 1e18;
const ll TE3 = 1005;
const ll TE5 = 200005;
const string YN[2] = {"NO", "YES"};
using namespace std;
ll n, m;
ll v[TE5];
ll vis[TE5];
ll ma[TE5];
vi a[TE5];
ll ans = -INF;
ll dfs(ll x,ll p) {
if(p!=INF) {
ans = max(ans, v[x] - p);
}
if(vis[x]) {
ans = max(ans, ma[x] - p);
return ma[x];
}
vis[x] = 1;
ll op = p;
p = min(p, v[x]);
ll ret = v[x];
for (ll ne : a[x])
{
ret=max(ret,dfs(ne, p));
}
if(op!=INF) {
ans = max(ans, ma[x] - op);
}
return ma[x]=ret;
}
int main()
{
io;
cin >> n >> m;
fill1(ma);
rep(i, 0, n)
{
cin >> v[i];
}
rep(i,0,m) {
ll x, y;
cin >> x >> y;
--x;
--y;
a[x].pb(y);
}
rep(i,0,n) {
if(!vis[i]) {
dfs(i, INF);
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
vector<vector<int>> edge;
vector<int> v;
vector<int> d;
int dfs(ll now, ll pre, ll target) {
int res = 0;
int ma = -1, mi = 1000000;
int dma = -1, dmi = 1000000;
int cnt = 0;
for (int nxt : edge[now]) {
if (nxt == pre) continue;
cnt++;
res += dfs(nxt, now, target);
mi = min(mi, v[nxt]);
ma = max(ma, v[nxt]);
dmi = min(dmi, d[nxt]);
dma = max(dma, d[nxt]);
}
d[now] = dmi+1;
bool put = false;
if (cnt == 0) {
return 0;
}else if (cnt == 1) {
if (mi >= 2*target) {
v[now] = 0;
put = true;
}else {
v[now] = mi+1;
}
}else {
if (ma+dmi+2 <= 2*target+1) {
v[now] = mi+1;
}else if (ma+1 >= 2*target+1){
v[now] = 0;
put = true;
}else {
v[now] = ma+1;
}
}
if (now == 0 && !put) {
if (v[now] > target) put = true;
}
if (put) {
res++;
d[now] = 0;
}
return res;
}
int main() {
int N, K;
cin >> N >> K;
edge.resize(N);
v.resize(N);
d.resize(N);
for (int i = 0; i < N-1; i++) {
int u, v;
cin >> u >> v;
u--;v--;
edge[u].push_back(v);
edge[v].push_back(u);
}
ll l = 0, r = N;
while (r-l > 1) {
ll c = (l+r)/2;
fill(v.begin(), v.end(), c+1);
fill(d.begin(), d.end(), N*10);
ll need = dfs(0, -1, c);
//cout << need << endl;
if (need <= K) r = c;
else l = c;
}
cout << r << endl;
return 0;
} |
#include <iostream>
using namespace std;
string a;
bool Pal(int i , int j)
{
while(i < j)
{
if(a[i] != a[j])
return false;
i++;
j--;
}
return true;
}
int main()
{
cin >> a;
int i , j;
i = 0;
while(a[i] == '0'&& i < a.size())
i++;
j = a.size() - 1;
while(a[j] == '0' && j >= 0)
--j;
if(Pal(i , j))
cout << "Yes\n";
else cout << "No\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()
typedef long long ll;
#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)
#define fi first
#define se second
void yes(){
cout << "Yes\n";
exit(0);
}
void no(){
cout << "No\n";
exit(0);
}
bool isp(string s){
fr(i,sz(s)/2) if(s[i]!=s[sz(s)-1-i]) return 0;
return 1;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
ll n; cin >> n;
if(n==0) yes();
string s = to_string(n);
while(s.back()=='0') s.pop_back();
//prin(s);
if(isp(s)) yes();
no();
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N;
int64_t count=0;
cin>>N;
vector<int>data(200);
for(int i=0;i<N;i++){
int64_t a,z;
cin>>a;
z=a%200;
data.at(z)++;
}
for(int i=0;i<200;i++){
int64_t b,c;
b=data.at(i);
c=(b*(b-1))/2;
count+=c;
}
cout<<count;
} | #include "bits/stdc++.h"
#pragma region header
using i32 = int;
using i64 = long long int;
using u32 = unsigned int;
using u64 = unsigned long long int;
using isize = ptrdiff_t;
using usize = size_t;
inline u64 popcount(const u64 v) {
#ifdef _MSC_VER
return u64(__popcnt64(v));
#else
return u64(__builtin_popcount(v));
#endif
}
class range {
struct range_iterator {
usize itr;
constexpr range_iterator(const usize pos) noexcept : itr(pos) {}
constexpr void operator++() noexcept { ++itr; }
constexpr bool operator!=(const range_iterator& other) const noexcept {
return itr != other.itr;
}
constexpr usize operator*() const noexcept { return itr; }
};
const range_iterator first, last;
public:
constexpr range(const usize first_, const usize last_) noexcept
: first(first_), last(last_) {}
constexpr range_iterator begin() const noexcept { return first; }
constexpr range_iterator end() const noexcept { return last; }
};
template <class F>
class rec_lambda {
F f;
public:
constexpr rec_lambda(F&& f_) : f(std::forward<F>(f_)) {}
template <class... Args>
constexpr auto operator()(Args&&... args) const {
return f(*this, std::forward<Args>(args)...);
}
};
namespace cs_helper {
void zip_sort_renumber([[maybe_unused]] std::vector<usize>& order) {}
template <class T, class... Args>
void zip_sort_renumber(std::vector<usize>& order, std::vector<T>& head,
Args&&... args) {
usize n = order.size();
assert(n == head.size());
std::vector<T> sorted_head(n);
for (usize i = 0; i < n; ++i) sorted_head[i] = head[order[i]];
head = std::move(sorted_head);
zip_sort_renumber(order, args...);
}
} // namespace cs_helper
template <class T, class... Args>
std::vector<usize> zip_sort(std::vector<T>& head, Args&&... args) {
usize n = head.size();
std::vector<std::pair<T, usize>> tmp(n);
for (usize i = 0; i < n; ++i) tmp[i] = std::make_pair(head[i], i);
std::sort(tmp.begin(), tmp.end());
std::vector<usize> order(n);
for (usize i = 0; i < n; ++i) order[i] = tmp[i].second;
cs_helper::zip_sort_renumber(order, head, args...);
return order;
}
#pragma endregion
void main_() {
int N;
std::cin >> N;
std::array<u64, 200> cnt;
for (auto& el : cnt) el = 0;
for (usize i : range(0, N)) {
usize A;
std::cin >> A;
--A;
++cnt[A % 200];
}
u64 ans = 0;
for (usize i : range(0, 200)) ans += cnt[i] * (cnt[i] - 1) / 2;
std::cout << ans << '\n';
/* ----- ----- 08.05.2021 ----- ----- */
}
int main() { main_(); } |
/*ver 6*/
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
#include <tuple>
#include <map>
#include <list>
#include <set>
using namespace std;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using pll = pair<ll,ll>;
using mll = map<ll,ll>;
#define EACH(x,v) for(auto& x : v)
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define REFOR(i,a,b) for(ll i=(ll)b-1;i>=(ll)a;i--)
#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define REREP(i,n) for(ll i=(ll)n-1;i>=0;i--)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
const ll INF = 1LL << 60;
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<=b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){}
template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
template <typename T> void in1(T &s) {REP(i,s.size()){in(s[i]);}}
template <typename T> void in2(T &s,T &t) {REP(i,s.size()){in(s[i],t[i]);}}
template <typename T> void in3(T &s,T &t,T &u) {REP(i,s.size()){in(s[i],t[i],u[i]);}}
template <typename T> void in4(T &s,T &t,T &u,T &v) {REP(i,s.size()){in(s[i],t[i],u[i],v[i]);}}
template <typename T> void in5(T &s,T &t,T &u,T &v,T &w) {REP(i,s.size()){in(s[i],t[i],u[i],v[i],w[i]);}}
void out(){cout << endl;}
template <typename T,class... U> void out(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; out(u...);}
void die(){cout << endl;exit(0);}
template <typename T,class... U> void die(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; die(u...);}
template <typename T> void outv(T s) {REP(i,s.size()){if(i!=0)cout<<" ";cout<<s[i];}cout<<endl;}
template <typename T> void out1(T s) {REP(i,s.size()){out(s[i]);}}
template <typename T> void out2(T s,T t) {REP(i,s.size()){out(s[i],t[i]);}}
template <typename T> void out3(T s,T t,T u) {REP(i,s.size()){out(s[i],t[i],u[i]);}}
template <typename T> void out4(T s,T t,T u,T v) {REP(i,s.size()){out(s[i],t[i],u[i],v[i]);}}
template <typename T> void out5(T s,T t,T u,T v,T w) {REP(i,s.size()){out(s[i],t[i],u[i],v[i],w[i]);}}
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
template <typename T> T allSum(vector<T> a){T ans=T();EACH(it,a)ans+=it;return ans;}
ll ceilDiv(ll a,ll b) {return (a+b-1)/b;}
ld dist(pair<ld,ld> a, pair<ld,ld> b){return sqrt(abs(a.fi-b.fi)*abs(a.fi-b.fi)+abs(a.se-b.se)*abs(a.se-b.se));} // 2点間の距離
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
#define YES(n) ((n) ? "YES" : "NO" )
#define Yes(n) ((n) ? "Yes" : "No" )
#define yes(n) ((n) ? "yes" : "no" )
int main(){
init();
inl(a,b);
out((a+b)/2,(a-b)/2);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
/*
Fix k.
For this k, we will:
Compute the maximum possible sum of k items that is equal to X modulo k.
We will do this by using a DP approach. We go through the items one by one and decide IN ORDER whether we use them.
Our DP state is (# items used, current sum % k, items gone through) -> value.
For each k, we have 10^6 DP states.
The processing for each state is constant time.
So we have at most 10^8 "things" to do.
*/
void maxeq(long long& a, long long b){
a = max(a, b);
}
long long DP[102][101][101];
int main(){
long long n, x;
cin>>n>>x;
vector<long long> A(n);
for (int i = 0; i < n; i++) cin>>A[i];
long long ans = 2e18;
// (# items used, current sum % k, items gone through) -> value.
for (int k = 1; k <= n; k++){
//long long DP[k+1][k][n+1];
for (int a = 0; a <= k+1; a++){
for (int b = 0; b < k; b++){
for (int c = 0; c <= n; c++){
DP[a][b][c] = LLONG_MIN / 3;
}
}
}
DP[0][0][0] = 0;
for (int c = 0; c < n; c++){ // we decide whether to take item c
for (int a = 0; a < k+1; a++){
for (int b = 0; b < k; b++){
// take
maxeq(DP[a + 1][(b + A[c]) % k][c + 1], DP[a][b][c] + A[c]);
// don't take
maxeq(DP[a][b][c + 1], DP[a][b][c]);
}
}
}
if (DP[k][x % k][n] > 0) ans = min(ans, (x - DP[k][x % k][n]) / k);
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
#include <algorithm>
#include <unordered_set>
using namespace std;
int main(){
long long int l,C;
cin >> l;
C = 1;
for(int j=1; j<12; j++){
C = C*(l-j)/j;
}
cout << C << endl;
return 0;
}
| #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
void solve(){
}
int main()
{
fast_cin();
int l;
cin>>l;
ll ans=1;
for(int i=1; i<=11; i++) {
ans*=l-i;
ans/=i;
}
cout<<ans<<endl;
} |
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(c%2==0){
a=abs(a);
b=abs(b);
}
if(a<b) printf("<\n");
else if(a>b) printf(">\n");
else printf("=\n");
return 0;
} | #include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
cout << 21 - a - b - c << endl;
return 0;
} |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
inline int read()
{
int a=0,f=1;
char ch=getchar();
for(;!isdigit(ch);ch=getchar())
if(ch=='-')f=-1;
for(;isdigit(ch);ch=getchar())
a=(a<<3)+(a<<1)+ch-'0';
return a*f;
}
void write(int x)
{
if(x<0)x=-x,putchar('-');
if(x>9)write(x/10);
putchar((x%10)^48);
}
inline void writen(int x)
{write(x);puts("");}
const int MOD=1e9+7;
const int N=1e6+5;
const int INF=0x3f3f3f3f;
const double PI=acos(-1);
signed main()
{
int a,b,c;
cin>>a>>b>>c;
cout<<21-a-b-c<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, c, n) for (ll i = c; i < (n); ++i)
//以下debug用
#define d(x) cout << #x << "; " << x << endl;
#define p(x) cout << x << endl;
#define f(x) for (long unsigned int i = 0; i < x.size(); i++) cout << #x << "[" << i << "]; " << x[i] << endl;
bool ok = false;
vector<int> datas;
const int inf = 1001001001;
const ll INF = 1LL << 60; //無限大
int ans=0,num=0,counter=0;
string s;
int main(){
int a,b,c;
cin >> a >> b >> c;
ans = 7*3 - (a+b+c);
p(ans)
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<n;i++)
int n,m;
vector<int> G[20];
vector<bool> used(20,false);
vector<int> col(20,-1);
vector<int> vs;
void dfs(int v)
{
if(used[v])return;
used[v]=true;
vs.push_back(v);
for(int u:G[v])dfs(u);
}
ll now;
void dfs2(int i)
{
if(i == (int)vs.size()){
now++;
return;
}
rep(c,3){
col[vs[i]]=c;
bool ok = true;
for(int u:G[vs[i]]){
if(col[u]==c)ok = false;
}
if(!ok)continue;
dfs2(i+1);
}
col[vs[i]]=-1;
}
int main()
{
cin >> n >> m;
rep(i,m){
int a,b;
cin >> a >> b;
a--;b--;
G[a].push_back(b);
G[b].push_back(a);
}
ll ans = 1;
col = vector<int>(n,-1);
rep(i,n){
if(used[i])continue;
ans*=3;
vs = vector<int>();
dfs(i);
//col = vector<int>(20,-1);
col[vs[0]]=0;
now = 0;
dfs2(1);
ans*=now;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 2e1 + 5;
int fa[MAXN];
int find(int x) {
return fa[x] == x ? x : fa[x] = find(fa[x]);
}
void merge(int x, int y) {
fa[find(y)] = find(x);
}
vector<int> vec;
int res, col[MAXN];
int n, m, g[MAXN][MAXN];
void dfs(int k) {
if (k == vec.size()) {
++res;
return ;
}
for (int i = 1; i <= 3; ++i) {
int u = vec[k];
col[u] = i;
auto check = [](int x) -> bool {
for (int i = 1; i <= n; ++i)
if (g[x][i] && col[i] == col[x])
return false;
return true;
};
if (check(vec[k])) dfs(k + 1);
col[u] = 0;
}
}
bool vis[MAXN];
signed main(int argc, char *argv[]) {
//ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
for (int i = 0; i < MAXN; ++i) fa[i] = i;
cin >> n >> m;
while (m--) {
int u, v;
cin >> u >> v;
merge(u, v);
g[u][v] = g[v][u] = 1;
}
int ans = 1;
for (int i = 1; i <= n; ++i) {
if (vis[i]) continue;
vec.clear(), res= 0;
for (int j = 1; j <= n; ++j)
if (find(j) == i) vec.push_back(j), vis[j] = true;;
dfs(0);
ans *= res;
}
cout << ans << '\n';
system("pause");
return 0;
} |
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 100005
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0' || ch>'9'){if(ch=='-') f=-1;ch=getchar();}
while(ch>='0' && ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*f;
}
int n,a[N];
inline double js(double p)
{
double sum=0;
for(int i=1;i<=n;i++)
if(a[i]<=int(2.0*p)) sum+=p;
else sum+=double(a[i])-p;
return sum;
}
int main()
{
n=read();
for(int i=1;i<=n;i++) a[i]=read();
sort(a+1,a+n+1);
int l=1,r=n,lm,rm;
while(l+1<r)
{
lm=(l+r)>>1;rm=(lm+r)>>1;
// printf("%d %d %d %d\n",l,lm,rm,r);
if(js(double(a[lm])/2.0)>js(double(a[rm])/2.0)) l=lm;
else r=rm;
}
double ans=double(a[r])/2.0,P=0;
for(int i=1;i<=n;i++)
if(a[i]<=int(2.0*ans)) P+=ans;
else P+=double(a[i])-ans;
printf("%.6lf\n",P/double(n));
return 0;
} | #include <stdio.h>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <iostream>
#include <map>
#define go(i, l, r) for(int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define god(i, r, l) for(int i = (r), i##end = (int)(l); i >= i##end; --i)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug_in freopen("in.txt","r",stdin)
#define debug_out freopen("out.txt","w",stdout);
#define pb push_back
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
const ll maxn = 2e3+10;
const ll maxM = 1e6+10;
const ll inf_int = 1e8;
const ll inf_ll = 1e17;
template<class T>void read(T &x){
T s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
x = s*w;
}
template<class H, class... T> void read(H& h, T&... t) {
read(h);
read(t...);
}
void pt(){ cout<<'\n';}
template<class H, class ... T> void pt(H h,T... t){ cout<<" "<<h; pt(t...);}
//--------------------------------------------
int a,b,c;
double dp[105][105][105];
double dfs(int a,int b,int c){
if(a>=100 || b >= 100 || c >= 100) return 0;
if(dp[a][b][c] >= -0.5) return dp[a][b][c];
double ans = 0;
ans += (double)a/(a+b+c) * dfs(a+1,b,c);
ans += (double)b/(a+b+c) * dfs(a,b+1,c);
ans += (double)c/(a+b+c) * dfs(a,b,c+1);
return dp[a][b][c] = ans + 1;
}
int main() {
// debug_in;
// debug_out;
read(a,b,c);
go(i,0,101) go(j,0,101) go(k,0,101) dp[i][j][k] = -1;
double ans = dfs(a,b,c);
printf("%.8f\n",ans);
return 0;
} |
#include <cstdio>
#define ll long long
#define mem(x, a) memset(x, a, sizeof x)
#define mpy(x, y) memcpy(x, y, sizeof y)
#define fo(x, a, b) for (int x = (a); x <= (b); x++)
#define fd(x, a, b) for (int x = (a); x >= (b); x--)
#define go(x) for (int p = tail[x], v; p; p = e[p].fr)
using namespace std;
ll n, m;
int main()
{
scanf("%lld%lld", &n, &m);
for (ll i = 1; i * i <= m; i++)
if (m % i == 0) {
ll j = m / i;
if (i + j == n)
return 0 & printf("Yes\n");
}
printf("No\n");
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ff first
#define ss second
#define pb push_back
#define print(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
std::random_device dev;
std::mt19937 rng(dev());
std::uniform_int_distribution<std::mt19937::result_type> dist(1,10000000); // distribution in range [1, 6]
const double PI = 3.141592653589793238;
int bexp(int a, int b, int mod)
{
int res = 1;
while (b)
{
if (b & 1) res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
const int N = 100010;
const int mod = 1e9 + 7;
struct comp {
bool operator() (const pair<int, int> a, const pair<int, int> b) const
{
return a.ss > b.ss;
}
};
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(10);
int tt = 1;
// cin >> tt;
while (tt--) {
int s, p;
cin >> s >> p;
int f = 0;
for (int i = 1; i <= 1e6; ++i) {
if (i * (s - i) == p) {
f = 1;
}
}
if (f) cout << "Yes\n";
else cout << "No\n";
}
return 0;
} |
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(array) array.begin(), array.end()
#define print(x) cout << x << endl;
#define pb push_back
using namespace std;
typedef long long ll;
typedef string str;
ll INF = 10e9;
//Aのiからj番目まで表示
int print_array(vector<int> A,int i,int j){
FOR(k,i,j){
cout << A[k] << " ";
}
print(A[j]);
return 0;
}
int main()
{
int N;
cin >> N;
vector<int> A(N);
REP(i,N){
ll a;
cin >> a;
A[i] = a % 200;
}
str ans = "No";
if (N>=8){
N = 8;
vector<vector<int>> B(pow(2, N) - 1, vector<int>(0));
for (int bit = 1; bit < (1 << N); ++bit)
{
vector<int> c;
int sum = 0;
for (int i = 0; i < N; ++i)
{
if (bit & (1 << i))
{
c.pb(i + 1);
sum += A[i];
}
}
B[bit - 1].pb(sum % 200);
FOR(i, 0, c.size())
{
B[bit - 1].pb(c[i]);
}
}
sort(ALL(B));
FOR(i, 1, B.size())
{
if (B[i][0] == B[i - 1][0])
{
ans = "Yes";
print(ans);
//x
cout << B[i].size() - 1 << " ";
print_array(B[i], 1, B[i].size() - 1);
//y
cout << B[i - 1].size() - 1 << " ";
print_array(B[i - 1], 1, B[i - 1].size() - 1);
break;
}
}
}
else { // N<8のときbit全探索
vector<vector<int>> B(pow(2,N)-1, vector<int>(0));
for (int bit = 1; bit < (1 << N); ++bit)
{
vector<int> c;
int sum = 0;
for (int i = 0; i < N; ++i)
{
if (bit & (1 << i)){
c.pb(i+1);
sum += A[i];
}
}
B[bit-1].pb(sum%200);
FOR(i,0,c.size()){
B[bit - 1].pb(c[i]);
}
}
sort(ALL(B));
FOR(i,1,B.size()){
if (B[i][0]==B[i-1][0]){
ans = "Yes";
print(ans);
//x
cout << B[i].size() - 1 << " ";
print_array(B[i], 1, B[i].size() - 1);
//y
cout << B[i-1].size() - 1 << " ";
print_array(B[i-1], 1, B[i-1].size() - 1);
break;
}
}
if (ans == "No"){
print(ans);
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int a[200001], visited[200001] = {0};
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
int cnt = 0, ans = 0;
for (int i = 1; i <= n; ++i)
if (!visited[i]) {
++cnt;
visited[i] = cnt;
for (int j = a[i]; ; j = a[j])
if (visited[j]) {
if (visited[j] == cnt) ++ans;
break;
} else visited[j] = cnt;
}
cnt = 1;
while (ans--) cnt = cnt * 2 % mod;
cnt = (cnt + mod - 1) % mod;
cout << cnt;
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define R(i,b,a) for(int i=(int)(b);i>=(int)(a);i--)
#define endl "\n"
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pii pair<int,int>
#define pb push_back
#define all(v) v.begin(),v.end()
#define I first
#define S second
int dp[13][202];
int32_t main(){
ios;
int L;
cin>>L;
dp[0][0]=1;
F(i,1,12){
F(j,0,L){
F(l,1,L-11)
if(j>=l) dp[i][j]+=dp[i-1][j-l];
}
}
cout<<dp[12][L]<<endl;
}
| //#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <cstdlib> // srand,rand
#include <random>
#include <functional>
#include <list>
#include <stack>
using namespace std;
#define ll long long
#define ll128 long long
#define lp(i,n) for(ll i=0;i<n;i++)
#define modd 1000000007
#define mod2 998244353
const double EPS = 1e-20;
const double PI = acos(-1);
#define INF 8223372036854775807ll
#define ALL(a) (a).begin(),(a).end()
typedef pair<long long, long long> pl;
typedef pair<double, double> pd;
typedef pair<ll, string> pls;
typedef string::const_iterator State;
class ParseError {};
vector<ll> qv[200001];
ll N;
ll P[200001];
ll Q;
ll U[200001];
ll D[200001];
ll ans[200001];
ll count_d[200001];
vector<ll> child[200001];
void Search(ll node, ll cd[200001], ll depth) {
lp(i, qv[node].size()) {
ll qnum = qv[node][i];
ans[qnum] -= cd[D[qnum]];
}
cd[depth]++;
lp(i, child[node].size()) {
Search(child[node][i], cd, depth + 1);
}
lp(i, qv[node].size()) {
ll qnum = qv[node][i];
ans[qnum] += cd[D[qnum]];
}
}
int main() {
cin >> N;
for (ll i = 2; i <= N; i++) {
cin >> P[i];
child[P[i]].push_back(i);
}
cin >> Q;
lp(i, Q)cin >> U[i] >> D[i];
lp(i, Q) {
qv[U[i]].push_back(i);
}
Search(1, count_d, 0);
lp(i, Q) {
cout << ans[i] << endl;
}
//cout << fixed << setprecision(12) << bb << endl;
return 0;
} |
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int h,w,sum=0,mx=998244353;
cin>>h>>w;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
int in;
cin>>in;
sum+=in;
mx=min(mx,in);
}
}
cout<<sum-mx*h*w<<endl;
} | /* Author: $%U%$
* Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/
#include <bits/stdc++.h>
using namespace std;
#define fore(i, a, b) for (int i = a, to = b; i < to; i++)
#define foref(i, a, b) for (int i = b - 1, to = a; i >= to; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
typedef pair<int, int> Pair;
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
int n, m;
cin >> n >> m;
map<int, int> cnt;
int cur = 0;
fore(i, 0, n) fore(j, 0, m) {
int num;
cin >> num;
cnt[num]++;
cur += num;
}
auto it = cnt.begin();
cout << cur - n * m * (*it).first << '\n';
return 0;
} |
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,ans;
char a[105][105];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)cin>>a[i][j];
for(int i=1;i<=n;i++)
for(int j=2;j<=m;j++)if(a[i][j]=='.'&&a[i][j-1]=='.')ans++;
for(int j=1;j<=m;j++)
for(int i=2;i<=n;i++)if(a[i][j]=='.'&&a[i-1][j]=='.')ans++;
printf("%d",ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#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 long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;
//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
ll res = 1;
while (n) {
if (n & 1)res = res * a%m;
a = a * a%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, int n) {
if (n == 0)return modint(1);
modint res = (a*a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
//逆元(Eucledean algorithm)
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)); }
const int max_n = 1 << 18;
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];
}
using mP = pair<modint, modint>;
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
void solve() {
int h, w; cin >> h >> w;
vector<string> s(h);
rep(i, h) cin >> s[i];
int res = 0;
rep(i, h){
rep(j, w){
if(s[i][j] != '.') continue;
if(j != w-1)if(s[i][j+1] == '.') res++;
if(i != h-1)if(s[i+1][j] == '.') res++;
}
}
cout << res << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
//cout << fixed << setprecision(10);
//init_f();
//init();
//int t; cin >> t; rep(i, t)solve();
solve();
// stop
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
using ll = long long;
int main(void){
string X;
cin >> X;
if (X == "0") {
cout << 0 << endl;
return 0;
}
string ans;
for (auto x : X) {
if (x != '.') {
ans += x;
} else {
break;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ordered_set tree<int, null_type, less<int >,rb_tree_tag, tree_order_statistics_node_update>
using namespace __gnu_pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vii vector<int>
#define pii pair<ll,ll>
#define vll vector<ll>
#define clr(v, d) memset(v,d,sizeof(v))
using namespace std;
const int N = 2e6 + 500, mod = 1e9 + 7;
int a[N];
vector<int> dx[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin>>n;
ld ans=0;
for (int i = 1; i <n ; ++i) {
ans+=(ld)n/i;
}
cout<<fixed<<setprecision(6)<<ans<<"\n";
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);
const long double EPS=1e-10;
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 };
int main(){//cout<<fixed<<setprecision(20);
ll n;
cin>>n;
ll ans=INF;
ll t=1;
rep(b,0,70){
if(t>n)break;
ll a,c;
a=n/t;
c=n%t;
chmin(ans,a+b+c);
t*=2;
}
cout<<ans<<endl;
} | #include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <vector>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
int x; \
cin >> x; \
while (x--)
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; i < n; i++)
#define sr(i, n) for (i = 0; i < n.length(); i++)
// template<typename... T>
// void read(T&... args) {
// ((cin >> args), ...);
// }
// // template<typename... T>
// // void write(T&&... args) { //rvalue reference is new to C++
// // ((cout << args << " "), ...);
// // }
void rank0001()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// #ifndef ONLINE_JUDGE
// //freopen("input.txt", "r", stdin);
// //freopen("output.txt", "w", stdout);
// #endif
}
int main()
{
rank0001();
ll n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < s.length(); i++)
{
if (i + 2 != s.length())
{
if (s[i] == 'f' && s[i + 1] == 'o' && s[i + 2] == 'x')
{
s.erase(i, 3);
if (i == 0 || i == 1 || i == 2)
i = -1;
else
i -= 3;
}
}
//cout << s.length();
}
cout << s.length() << endl;
} |
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define DBG(a) cout<< "line "<<__LINE__ <<" : "<< #a <<" --> "<<(a)<<endl
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int mod = 998244353;
long double pi = acosl(-1);
const ll infl = 1e17+100;
const int inf = 1e9+100;
const int nmax = 1e6+5;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n;
cin>>n;
string s;
cin>>s;
vector<int>a(n+1);
for(int &x : a) cin>>x;
int kom = inf;
for(int i=0; i<n; i++){
kom = min(kom, abs(a[i]-a[i+1]));
}
vector< vector<int> >ans(kom, vector<int>(n+1) );
for(int i=0; i<=n; i++){
int z = a[i]/kom;
int extra = a[i]%kom;
for(int j=0; j<kom; j++){
ans[j][i] = z;
if(j<extra) ans[j][i]++;
}
}
cout<<kom<<"\n";
for(auto z : ans){
for(auto x : z){
cout<<x<<" ";
}
cout<<"\n";
}
}
/*
*/
| #include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
const int N = 810, inf = 1e9;
int n, m;
int a[N][N];
int s[N][N];
int vis;
bool check(int x){
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j ++)
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + (a[i][j] > x);
int res = inf;
for(int i = m; i <= n; i ++)
for(int j = m; j <= n; j ++)
res = min(res, s[i][j] - s[i - m][j] - s[i][j - m] + s[i - m][j - m]);
return res <= m * m - vis;
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j ++)
scanf("%d", &a[i][j]);
vis = m * m / 2;
if(m & 1) vis ++;
int l = 0, r = 1e9;
while(l < r){
int mid = l + r >> 1;
if(check(mid)) r = mid;
else l = mid + 1;
}
printf("%d\n", r);
return 0;
} |
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define all(v) v.begin(),v.end()
#define sortall(v) sort(all(v))
#define deb(x) cout<<#x<<" = "<<x<<'\n'
#define deb2(x, y) cout<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<'\n';
#define si(x) scanf("%d", &x)
#define sii(x,y) scanf("%d%d", &x, &y)
#define sll(x) scanf("%lld", &x)
#define ss(s) scanf("%s",&s)
#define sc(c) scanf("%c", &c)
#define pi(x) printf("%d\n", x)
#define ps(s) printf("%s\n",s)
#define pfll(x) printf("%lld\n", x)
#define pb(x) push_back(x)
#define HI cout<<"Hi\n"
#define mp(x, y) make_pair(x, y)
#define mt(x, y, z) make_tuple(x, y, z)
#define F first
#define S second
#define PI 3.1415926535897932384626
#define fr(i, n) for(auto i=0; i<n; ++i)
#define frn(i, ini, fin) for(int i=ini; i<=fin; ++i)
// ========= typedef ========== //
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> t3;
typedef std::vector<t3> vt3;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::vector<pii> vpii;
typedef std::vector<pll> vpll;
typedef unordered_map<int, int> umii;
typedef unordered_map<char, int> umci;
typedef unordered_set<int> usi;
//===========mod and data structs=============== //
//100 400
//40 500
const int mod = 1e9 + 7;
// const int N = 2*1e5+5, M = 1e6;
const ll X = 1e6;
bool primes[X+1];
unordered_map<int, int> index_energy;
int grid[105][105];
const int INF = 1e9;
int n,k;
//============================//
ll arr[10];
// ============functions =========//
int mpow(int base, int exp);
void mmul(int &num , int num2);
void printVec(vi v);
void SieveOfEratosthenes(ll n);
std::vector<int> arr8;
ll poww(int base, int exp);
// ================================= //
void solve(){
cin>>n;
vi a(n), b(n);
fr(i, n){
cin>>a[i];
}
fr(i, n){
cin>>b[i];
}
int ans = 0;
fr(i, n){
ans+=a[i]*b[i];
}
if(ans)cout<<"No\n";
else cout<<"Yes\n";
}
int main()
{
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
t=1;
while(t--) solve();
}
int mpow(int base, int exp) {
base %= mod;
int result = 1;
while (exp > 0) {
if (exp & 1) result = ((ll)result * base) % mod;
base = ((ll)base * base) % mod;
exp >>= 1;
}
return result;
}
void mmul(int &num , int num2){
num = ((num%mod)*(num2%mod))%mod;
}
void SieveOfEratosthenes(ll n){
memset(primes, true, sizeof(primes));
primes[0]=primes[1]=false;
for(ll i=2; i*i<=n; ++i){
if(primes[i]){
for(ll j=i*i; j<=n; j+=i){
primes[j]=false;
}
}
}
}
ll poww(int base, int exp) {
ll result = 1;
while (exp > 0) {
if (exp & 1) result = (result * base) ;
base = (base * base);
exp >>= 1;
}
return result;
}
// void printVec(std::vector<string> v){
// fr(i,v.size()){
// cout<<v[i]<<" ";
// }
// cout<<endl;
// } | //デバッグ用オプション:-fsanitize=undefined,address
//コンパイラ最適化
#pragma GCC optimize("Ofast")
//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//マクロ
//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=a;i>=ll(b);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
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
/*
ビット全探索
for(int bit=0;bit<(1<<n);bit++){
for(int i=0;i<n;i++){
if(bit & (1<<i)){
}
}
*/
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
signed main(){
//小数の桁数の出力指定
//cout<<fixed<<setprecision(10);
//入力の高速化用のコード
//ios::sync_with_stdio(false);
//cin.tie(nullptr);
char a,b,c;
cin>>a>>b>>c;
if(a==b&&b==c)cout<<"Won"<<endl;
else cout<<"Lost"<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vl = vector<long>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvll = vector<vll>;
using vs = vector<string>;
using pii = pair<int, int>;
#define pb push_back
#define mp make_pair
#define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) reps(i, 1, n + 1)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define rrepd(i,n) for(ll i=n;i>=1;i--)
#define debug(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << "\033[m" <<endl;
#define kd(x) cerr << "\033[33m" << #x << ": " << x << ", \033[m";
#define kdl(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << ", \033[m";
#define kde(x) cerr << "\033[33m" << #x << ": " << x << ", \033[m" << endl;
inline int in_int() {int x; cin >> x; return x;}
inline ll in_ll() {ll x; cin >> x; return x;}
inline string in_str() {string x; cin >> x; return x;}
template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;}
template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;}
ll dfs(int i, int *v, const int n, int a, int w)
{
//kd(i); kde(a);
if (a == 0) return 1;
if (i+1 == n) return 0;
if (v[i] == 1) return dfs(i+1, v, n, a, w);
int *u = new int[n];
rep(j,n) u[j] = v[j];
ll ret = 0;
// try 1
u[i] = 1;
if (i+1 < n && (i+1) % w && u[i+1] != 1) {
u[i+1] = 1;
ret += dfs(i+1, u, n, a-1, w);
u[i+1] = 0;
}
if (i+w < n && u[i+w] != 1) {
u[i+w] = 1;
ret += dfs(i+1, u, n, a-1, w);
u[i+w] = 0;
}
// try 0
u[i] = 0;
ret += dfs(i+1, u, n, a, w);
delete [] u;
return ret;
}
int main()
{
int h = in_int();
int w = in_int();
int a = in_int();
int b = in_int();
int *v = new int[h*w];
rep(j,h*w) v[j] = 0;
cout << dfs(0, v, h*w, a, w);
return 0;
}
| #include <iostream>
#include <algorithm>
#include <list>
#include <string>
int h, w;
int f (int a, int b, std::list<int> r) {
int s = 0;
if (a == 0 || r.empty()) {
s = 1;
} else {
int m = r.front();
r.pop_front();
if (b > 0) {
s += f(a, b-1, r);
}
if ((m+1) % w != 0 && m+1 == r.front()) {
r.pop_front();
s += f(a-1, b, r);
r.push_front(m+1);
}
auto i = r.begin();
while(i != r.end() && *i < m+w) i++;
if (*i == m+w) {
auto next = std::next(i);
r.erase(i);
s += f(a-1, b, r);
r.insert(next, m+w);
}
}
return s;
}
int main() {
int a, b;
std::cin >> h >> w >> a >> b;
std::list<int> r;
for(int i = 0 ; i < h*w; i++) r.push_back(i);
int s = f(a, b, r);
std::cout << s << std::endl;
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
long long a[n];
long long mx = 0;
long long sum = 0;
long long mospos = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i) a[i] += a[i - 1];
mospos = max(a[i], mospos);
mx = max(sum + mospos, mx);
sum += a[i];
}
cout << mx << endl;
}
| /*
ID: Λινδα
LANG: C++
TASK: abc196c
*/
#include <stdio.h>
long long ppct(long long x)
{
long long i=0,s=1;
do
{
x=x/10;
i++;
}
while(x!=0);
while(i--)
{
s=s*10;
}
return s;
}
int read(){char c=getchar();int t=0,f=1;while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}while(c>='0'&&c<='9'){t=(t<<1)+(t<<3)+(c^48);c=getchar();}return t*f;}
void write(int x){char ch[50];int l=0;if(x<0){putchar('-');x=-x;}do{ch[l++]=x%10+'0';x=x/10;}while(x);while(l){putchar(ch[--l]);}}
int main()
{
// freopen("main.in","r",stdin);
// freopen("main.out","w",stdout);
// freopen("main.err","w",stderr);
long long i=1,n,s=0;
scanf("%lld",&n);
while(i*ppct(i)+i<=n)
{
// printf("%lld ",i*ppct(i)+i);
s++;
i++;
}
printf("%lld\n",s);
// fclose(stdin);
// fclose(stdout);
// fclose(stderr);
return 0;
} |
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const int N = 2e5 + 5;
const ll inf = 1e18;
const ll mod = 998244353;
ll n, k, a[100][100], s, visr[100], visc[100], fact[100];
vector<ll> r[100], c[100];
bool check_col(int x, int y){
for (int i = 1; i <= n; i++)
if (a[i][x] + a[i][y] > k)
return 0;
return 1;
}
bool check_row(int x, int y){
for (int i = 1; i <= n; i++)
if (a[x][i] + a[y][i] > k)
return 0;
return 1;
}
void dfsc(int u){
s++;
visc[u] = 1;
for (auto p: c[u])
if(!visc[p])
dfsc(p);
}
void dfsr(int u){
s++;
visr[u] = 1;
for (auto p: r[u])
if(!visr[p])
dfsr(p);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
fact[0] = 1;
for (ll i = 1; i<= n; i++)
fact[i] = fact[i - 1] * i % mod;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
cin >> a[i][j];
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (check_col(i, j))
{
c[i].push_back(j);
c[j].push_back(i);
}
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (check_row(i, j))
{
r[i].push_back(j);
r[j].push_back(i);
}
ll ans = 1;
for (int i = 1; i <= n; i++)
if (!visc[i]){
s = 0;
dfsc(i);
ans = ans * fact[s] % mod;
}
for (int i = 1; i <= n; i++)
if (!visr[i]){
s = 0;
dfsr(i);
ans = ans * fact[s] % mod;
}
cout << ans;
}
| /*
* @author : ashnove
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define F first
#define S second
#define endl "\n"
#define nl cout<<endl;
#define pb push_back
#define f(i,a,b) for(ll i=a;i<b;i++)
#define Knucklehead ios_base::sync_with_stdio(false);cin.tie(NULL);
//#define mod 100000007
#define mat vector<vector<ll>>
mat cn(ll n, ll m){return vector< vector<ll> >(n, vector<ll>(m));}
bool compare(char &s1,char &s2){return s1 > s2;}
bool sortmahstyle(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
if(a.first < b.first )
return true;
if( a.first==b.first && a.S != b.second )
return true;
return false;
}
//me
ll const mod = 998244353;
ll const inf = 1e18;
ll const maxn = 1e3+1;
ll f[maxn];
void fact(){
f[0]=1;
for(ll i = 1; i< maxn; i++)
f[i] = (f[i-1]*i)%mod;
}
ll par_row[maxn], par_col[maxn];
ll Rank1[maxn], Rank2[maxn];
ll find1(ll x){
if( par_row[x] < 0)
return x;
return par_row[x] = find1(par_row[x]);
}
ll find2(ll x){
if( par_col[x] < 0)
return x;
return par_col[x] = find2(par_col[x]);
}
void merge1(ll a, ll b){
a = find1(a), b = find1(b);
if(a==b)return;
if(Rank1[a] > Rank1[b]){
par_row[b]= a;
Rank1[a]+=Rank1[b];
}
else{
par_row[a]=b;
Rank1[b]+=Rank1[a];
}
}
void merge2(ll a, ll b){
a = find2(a), b = find2(b);
if(a==b)return;
if(Rank2[a] > Rank2[b]){
par_col[b]=a;
Rank2[a]+=Rank2[b];
}
else{
par_col[a]=b;
Rank2[b]+=Rank2[a];
}
//par_col[b]=a;
}
void solve()
{
fact();
ll n, K; cin >> n >> K ;
fill(par_row, par_row+n, -1);
fill(par_col, par_col+n, -1);
fill(Rank2, Rank2+n, 1);
fill(Rank1, Rank1+n, 1);
ll a[n][n];
f(i,0,n) f(j,0,n) cin >> a[i][j];
f(i,0,n){
f(j,i+1,n){
bool ok = 1;
f(k,0,n){
if( a[j][k]+a[i][k]> K )
ok = 0;
}
if(ok){
merge1(i,j);
}
}
}
f(i,0,n){
f(j,i+1,n){
bool ok = 1;
f(k,0,n){
if( a[k][i]+a[k][j]> K )
ok = 0;
}
if(ok){
merge2(i,j);
}
}
}
ll ans= 1;
f(i,0,n){
if(par_row[i]<0)
ans = (ans*f[abs(Rank1[i])])%mod;
}
f(i,0,n){
if(par_col[i]<0)
ans = (ans*f[abs(Rank2[i])])%mod;
}
cout << ans << endl;
}
int main() {
Knucklehead
//*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
/**/
ll t;
/**/t=1;
/*/cin>>t;/**/
f(testcases,0,t){
//cout << "Case #" <<testcases+1<<": ";
solve();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < int(NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()
#define cMOD 1000000007ULL
#define cINF ((1ll<<62)-1)
#define cINFINT ((1<<30)-1)
template <typename T>
void chmin(T& a, T b){ if(a > b) a = b; }
template <typename T>
void chmax(T& a, T b){ if(a < b) a = b; }
ll ss(ll i, ll n)
{
if(i < n) return 0;
else if(n <= i && i < 2*n) return i - (n-1);
else if(2*n <= i && i < 3*n) return 3*n-1-i;
else return 0;
}
int main()
{
cin.tie( 0 ); ios::sync_with_stdio( false );
// ----------------------------------------------------------------
ll n,k;
cin >> n>>k;
ll s = 0;
bool ok = false;
REP(i,3*n-2)
{
s += ss(i+n, n);
s -= ss(i, n);
if(k > s)
{
k -= s;
continue;
}
else
{
REP(j, n)
{
ll s2 = ss(i+n-j, n);
if(k > s2)
{
k -= s2;
continue;
}
else
{
ll a = j;
ll c = min(i-a, n-1)-(k-1);
ll b = i - a - c;
cout << a+1 << " " << b+1 << " " << c+1 << endl;
ok = true;
break;
}
}
}
if(ok) break;
}
// ----------------------------------------------------------------
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
struct dsu {
public:
dsu() : _n(0) {}
dsu(int n) : _n(n), parent_or_size(n, -1) {}
int merge(int a, int b) {
assert(0 <= a && a < _n);
assert(0 <= b && b < _n);
int x = leader(a), y = leader(b);
if (x == y) return x;
if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
parent_or_size[x] += parent_or_size[y];
parent_or_size[y] = x;
return x;
}
bool same(int a, int b) {
assert(0 <= a && a < _n);
assert(0 <= b && b < _n);
return leader(a) == leader(b);
}
int leader(int a) {
assert(0 <= a && a < _n);
if (parent_or_size[a] < 0) return a;
return parent_or_size[a] = leader(parent_or_size[a]);
}
int size(int a) {
assert(0 <= a && a < _n);
return -parent_or_size[leader(a)];
}
std::vector<std::vector<int>> groups() {
std::vector<int> leader_buf(_n), group_size(_n);
for (int i = 0; i < _n; i++) {
leader_buf[i] = leader(i);
group_size[leader_buf[i]]++;
}
std::vector<std::vector<int>> result(_n);
for (int i = 0; i < _n; i++) {
result[i].reserve(group_size[i]);
}
for (int i = 0; i < _n; i++) {
result[leader_buf[i]].push_back(i);
}
result.erase(
std::remove_if(result.begin(), result.end(),
[&](const std::vector<int>& v) { return v.empty(); }),
result.end());
return result;
}
private:
int _n;
// root node: -1 * component size
// otherwise: parent
std::vector<int> parent_or_size;
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int h,w;cin >> h >> w;
vector<string> s(h);
dsu uf(h+w);
uf.merge(0,h);
uf.merge(h-1,h+w-1);
uf.merge(h,h+w-1);
REP(i,h){
cin >> s[i];
REP(j,w){
if(s[i][j]=='#') uf.merge(i,j+h);
}
}
map<int,int> mh,mw;
REP(i,h) mh[uf.leader(i)]++;
REP(i,w) mw[uf.leader(i+h)]++;
cout << min(mh.size(),mw.size())-1 << endl;
} |
//ABHISHEK AGRAWAL,BIT mesra//
//Author: Abhishekagrawal
//Date: 09/05/2021
//Time: 18:34:50
#include<bits/stdc++.h>
using namespace std;
#define booga cout << "booga" << endl
#define int long long int
#define pb push_back
#define f first
#define s second
#define mod (ll)1000000007
#define pi (double)acos(-1.0)
#define what_is(x) cerr << #x << " is " << x << endl;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define safai(...) Clearing_out(__VA_ARGS__)
void Clearing_out() { return; }
template <typename Head, typename... Tail>
void Clearing_out(Head &H, Tail & ... T) {
H.clear();
Clearing_out(T...);
}
const int N=200040;int a[N],b[N],c[N],ans,sum;
int n;
void testcase(){
int k;
cin>>k>>n;
bool vis[100000];
memset(vis,true,sizeof(vis));
for(int i=1;i<=1000;i++){
int cur=(100+k)*i;
cur/=100;
vis[cur]=false;
}
int x=1,cc=1;
vector<int>v;
for(int i=1;i<=1000;i++){
if(vis[i]) v.push_back(i-(100+k-1)/k*(cc++));
}
int n1=(n-1)/k;
int cu;
if(n1==0) cu=0;
else cu=(v[k-1]+1)*n1;
n1=n%k;
n1--;
if(n1==-1) n1=k-1;
cu+=v[n1];
cout<<((100+k-1)/k)*n+cu;
return;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
/*Today's thought: Push yourself,because no one else is going to do it for you.*/
int test=1;
// cin>>test;
while(test--){
testcase();
}
cerr << "Time : " << 1000 *((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
return 0;
}
| #include<bits/stdc++.h>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
using namespace std;
typedef long long ll;
char s[2003][2003];
ll mod=1e9+7;
ll ma[2003][2003]={0};
ll maxx[2003][2003]={0};
ll may[2003][2003]={0};
ll mas[2003][2003]={0};
ll h,w;
int main(void)
{
scanf("%lld%lld",&h,&w);
for(ll i=1;i<=h;i++)
{
scanf("%s",s[i]+1);
}
for(ll i=1;i<=h;i++)
{
for(ll j=1;j<=w;j++)
{
if(i==1&&j==1){ma[i][j]=maxx[i][j]=may[i][j]=mas[i][j]=1;continue;}
if(s[i][j]=='#') ma[i][j]=maxx[i][j]=may[i][j]=mas[i][j]=0;
else
{
ma[i][j]=maxx[i-1][j]+may[i][j-1]+mas[i-1][j-1];
maxx[i][j]=ma[i][j]+maxx[i-1][j];
may[i][j]=ma[i][j]+may[i][j-1];
mas[i][j]=ma[i][j]+mas[i-1][j-1];
ma[i][j]%=mod;
maxx[i][j]%=mod;
may[i][j]%=mod;
mas[i][j]%=mod;
}
}
}
printf("%lld\n",ma[h][w]);
} |
#include <bits/stdc++.h>
using namespace std;
struct Fast {
Fast() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
} fast;
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
long long modpow(long long m, long long n, long long modvalue) {
if (n == 0) return 1;
if (n % 2 == 0) {
long long t = modpow(m, n / 2, modvalue);
return t * t % modvalue;
} else {
return modpow(m, n - 1, modvalue) * m % modvalue;
}
}
long long moddiv(long long a, long long b, ll modvalue) { return (a * modpow(b, mod - 2, modvalue)) % modvalue; }
const ll INF = 1LL << 60;
string change_binary(long long a) {
string ret;
for (int i = 31; i >= 0; i--) {
ret += (a >> i & 1) + '0';
}
return ret;
}
ll nCkmod(ll n, ll k, ll modvalue) {
ll numera = 1;
for (int i = n; i > n - k; i--) {
numera *= i;
numera %= modvalue;
}
ll denomi = 1;
REP(i, k) {
denomi *= (i + 1);
denomi %= modvalue;
}
return moddiv(numera, denomi, modvalue);
}
map<ll, ll> cnt;
void primeFactors(long long n) {
while (n % 2 == 0) {
cnt[2]++;
n = n / 2;
}
for (int i = 3; i <= sqrt(n); i = i + 2) {
while (n % i == 0) {
cnt[i]++;
n = n / i;
}
}
if (n > 2) {
cnt[n]++;
}
}
vector<ll> dijkstra(vector<vector<P>> graph, ll s) {
vector<ll> ans(graph.size(), -1);
priority_queue<P, vector<P>, greater<P>> pq;
pq.push({0, s});
while (pq.size() > 0) {
ll cur1 = 0;
ll cur2 = 0;
if (ans[pq.top().second] != -1) {
pq.pop();
} else {
cur1 = pq.top().first;
cur2 = pq.top().second;
pq.pop();
ans[cur2] = cur1;
for (ll i = 0; i < graph[cur2].size(); i++) {
pq.push({cur1 + graph[cur2][i].first, graph[cur2][i].second});
}
}
}
return ans;
}
ll gcd(ll a, ll b) {
if (a % b == 0) {
return b;
} else {
return gcd(b, a % b);
}
}
struct UnionFind {
vector<int> parent, size;
UnionFind(int n) {
parent.resize(n, -1);
size.resize(n, 1);
}
void unite(int x, int y) {
if (same(x, y)) {
return;
}
x = root(x);
y = root(y);
if (size[x] <= size[y]) {
swap(x, y);
}
parent[y] = x;
size[x] += size[y];
}
bool same(int x, int y) { return (root(x) == root(y)); }
int root(int x) {
while (parent[x] != -1) {
x = parent[x];
}
return x;
}
int getsize(int x) { return size[root(x)]; }
};
int main() {
ll n, w;
cin >> n >> w;
vector<ll> s(n);
vector<ll> t(n);
vector<ll> p(n);
REP(i, n) {
cin >> s[i];
cin >> t[i];
cin >> p[i];
}
ll wpm = 0;
vector<ll> a(300000);
rep(i, 0, n) {
a[s[i]] += p[i];
a[t[i]] -= p[i];
}
ll maxwpm = 0;
REP(i, 300000) {
wpm += a[i];
maxwpm = max(wpm, maxwpm);
}
if (w >= maxwpm) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | // Problem: F - +1-1x2
// Contest: AtCoder - AtCoder Beginner Contest 188
// URL: https://atcoder.jp/contests/abc188/tasks/abc188_f
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<ll> VL;
typedef vector<vector<ll>> VLL;
constexpr int mod = 1e9 + 7;
constexpr ll KINF = 0x3f3f3f3f;
constexpr double eps = 1e-7;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
ll x, y;
cin >> x >> y;
unordered_map<ll, ll> memo;
function<ll(ll)> dfs = [&](ll u){
if(memo[u]) return memo[u];
if(u <= x) return memo[u] = x - u;
ll ans = u - x;
if(u % 2 == 0) ans = min(ans, dfs(u / 2) + 1);
else ans = min({dfs((u - 1) / 2) + 2, dfs((u + 1) / 2) + 2, ans});
return memo[u] = ans;
};
cout << dfs(y) << endl;
return 0;
}
|
//ABHISHEK AGRAWAL,BIT mesra//
//Newbie......You have to be odd to be no. ONE :)//
//Author: Abhishekagrawal
//Date: 15/03/2021
//Time: 04:36:03
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fl float
#define vll vector<ll>
#define pii pair<int,int>
#define vpll vector<pair<ll,ll>>
#define pb push_back
#define f first
#define s second
#define mll map<ll,ll>
#define mp make_pair
#define sp(n) fixed<<setprecision(n)
#define mod (ll)1000000007
#define sortv(v) sort(v.begin(),v.end())
#define INF (ll)(1e15)
#define loop(i,n) for(int i=0;i<n;i++)
#define loop1(i,n) for(int i=1;i<=n;i++)
#define rloop(n,i) for(int i=n-1;i>=0;i--)
#define sorta(a) sort(a,a+n,greater<ll>())
#define countone(n) __builtin_popcount(n)
#define numoftrailzero(n) __builtin_ctz(n)
#define maxpowoftwo(n) __builtin_clz(n)
#define leastindexwithone(n) __builtin_ffs(n)
#define what_is(x) cerr << #x << " is " << x << endl;
#define pfv(v) cout<<v.size()<<"\n";loop(i,v.size()) cout<<v[i]<<" ";cout<<"\n";
#define pv(v) loop(i,v.size()) cout<<v[i]<<" ";
#define all(v) v.begin(),v.end()
#define mset(dp,val) memset(dp,val,sizeof(dp))
ll test,n;ll sum,ans;
void the_happiest_place_on_earth()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#ifdef ENABLE_FILE_IO
freopen("out.txt", "r", stdin);
freopen("out1.txt", "w", stdout);
#endif
}
// bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b){
// if(a.s+2*a.f==b.s+2*b.f) return a.f>b.f;
// return (a.s+2*a.f>b.s+2*b.f);
// }
const int N=200040;ll a[N],b[N],c[N],par[N],Size[N],present[N],color[N];
ll sieve_spf[1000110];
ll n1=1000000;
void Sieve_spf(){
loop(i,n1) sieve_spf[i]=i;
sieve_spf[0]=-1;
sieve_spf[1]=1;
for(int i=2;i<n1;i+=2) sieve_spf[i]=2;
for(ll i=3;i<n1;i+=2){
if(sieve_spf[i]==i){
for(ll j=(i*i);j<n1;j+=i){
if(sieve_spf[j]==j) sieve_spf[j]=i;
}
}
}
}
vll v;
void dfs(int i, ll j){
if(i==15){
for(int k=0; k<n; ++k)
if(__gcd(a[k],j)<2) return;
ans=min(ans,j); return;
}
dfs(i+1,j);
dfs(i+1,j*v[i]);
}
void testcase(){
cin>>n;
loop(i,n) cin>>a[i];
ans=LLONG_MAX;
dfs(0,1);
cout<<ans<<"\n";
return;
}
int main(){
the_happiest_place_on_earth();
// Today's thought: Push yourself,because no one else is going to do it for you.
// Things are not always #000000 and #FFFFFF
// g++ -o a BB.cpp -DENABLE_FILE_IO;./a
// g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o a file_name.cpp;./a
test=1;int t=0;
Sieve_spf();
loop1(i,50){
if(sieve_spf[i]==i&&i!=1) v.pb(i);
}
// cin>>test;
while(test--){
//cout<<"Case #"<<++t<<": ";
testcase();
}
cerr << "Time : " << 1000 *((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/ | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
// avoid unordered_map and unordered_set!!!
#include <vector>
#include <utility>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using i32 = int32_t;
using pi64 = pair<i64, i64>;
#define vec vector
#define let const
#define DRi64(x) i64 x; cin >> x;
#define DRS(x) string x; cin >> x;
#define DRVi64(v, n) vec<i64> v(n); { for (i64 i = 0; i < n; ++i) { cin >> v[i]; }}
#define DRpi64(x) pi64 x; cin >> x.first >> x.second;
#ifdef DEBUG
#define P(x) cerr << x << "\n"
#else
#define P(x)
#endif
constexpr i64 MAXN = 3*100*1000LL+5LL;
constexpr i64 MOD = 1000000007LL;
constexpr i64 INF64 = MOD * MOD;
bool
dfs(const i64 u, const i64 p, vec<i64>& colour, const i64 mask, const vec<vec<i64>>& adj)
{
bool ok = true;
for (let i64 nbr : adj[u])
{
if (nbr == p)
{
continue;
}
if (mask & (1LL<<nbr))
{
continue;
}
if (colour[nbr] < 0)
{
colour[nbr] = !colour[u];
ok &= dfs(nbr, u, colour, mask, adj);
}
if (colour[nbr] == colour[u])
{
return false;
}
}
return ok;
}
int
main()
{
ios_base::sync_with_stdio(false);
// fast io: see 1423K
cin.tie(nullptr);
cout.tie(nullptr);
DRi64(N); DRi64(M);
vec<vec<i64>> adj(N);
for (i64 i = 0; i < M; ++i)
{
DRi64(A); DRi64(B);
A--, B--;
adj[A].push_back(B);
adj[B].push_back(A);
}
i64 ways = 0;
for (i64 mask = 0; mask < (1LL << N); ++mask)
{
bool bad = false;
for (i64 b = 0; !bad && b < N; ++b)
{
if ((1LL<<b) & mask)
{
for (let i64 nbr : adj[b])
{
bad |= (mask & (1LL<<nbr));
}
}
}
if (bad)
{
continue;
}
P(bitset<4>(mask));
i64 subways = 1;
// how many ways to colour the uncoloured vertices?
vec<i64> colour(N, -1);
for (i64 b = 0; b < N; ++b)
{
if ((1LL<<b) & mask)
{
continue;
}
if (colour[b] >= 0)
{
continue;
}
colour[b] = 0;
let bool subproblem = dfs(b, -1, colour, mask, adj);
bad |= subproblem == 0;
// indepent subproblems -- different components
subways *= 2;
}
ways += !bad * subways;
}
cout << ways << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#define endl '\n'
#define modulo 1000000007
#define int long long
#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
#define EPS 0.000000001
using namespace std;
int power(int x,int y,int m)
{
int temp;
if(y == 0)
return 1;
temp = (power(x, y/2,m))%m;
if (y%2 == 0)
return ((temp%m)*temp);
else
return ((x*temp%m)*temp%m)%m;
}
int inv(int x)
{
return (power(x,modulo-2,modulo))%modulo;
}
int pos[1501][1501],arr[500001],arr2[500001];
void DFS(int X,int Y,int DIR){
if(X>1500||Y>1500||X<0||Y<0)
return;
if((pos[X][Y]==1)||pos[X][Y]==2)
return;
if(pos[X][Y]==DIR)
return;
pos[X][Y]=DIR;
if(DIR==3)
DFS(X+1,Y,3);
else if(DIR==4)
DFS(X-1,Y,4);
else if(DIR==5)
DFS(X,Y+1,5);
else
DFS(X,Y-1,6);
}
int32_t main()
{
//freopen("output.txt","w",stdout);
//freopen("colors.in","r",stdin);
cin.tie(0),iostream::sync_with_stdio(0);
int x,y,n,m,X,Y;
cin>>x>>y>>n>>m;
for(int i=0;i<n;i++){
cin>>X>>Y;
X--,Y--;
pos[X][Y]=1;
arr[i]=X,arr2[i]=Y;
}
for(int i=0;i<m;i++){
cin>>X>>Y;
X--,Y--;
pos[X][Y]=2;
}
for(int i=0;i<n;i++){
DFS(arr[i]+1,arr2[i],3),DFS(arr[i]-1,arr2[i],4),DFS(arr[i],arr2[i]+1,5),DFS(arr[i],arr2[i]-1,6);
}
int counter=0;
for(int i=0;i<x;i++){
for(int l=0;l<y;l++)
counter+=((pos[i][l]>=3)?1:0);
}
cout<<counter+n;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 N = 1000, G = 30;
struct Node {
//0:up 1:right 2:down 3:left
double cost[4] = {4500, 4500, 4500, 4500};
};
i64 dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
Node node[G][G];
int main() {
for (i64 turn = 1; turn <= N; turn++) {
i64 s[2], t[2];
cin >> s[0] >> s[1] >> t[0] >> t[1];
vector<vector<i64>> cost(G, vector<i64>(G, 1e9));
vector<vector<pair<i64, i64>>> bef(G, vector<pair<i64, i64>>(G, {-1, -1}));
cost[s[0]][s[1]] = 0;
priority_queue<tuple<i64, i64, i64>, vector<tuple<i64, i64, i64>>, greater<tuple<i64, i64, i64>>> que;
que.push({0, s[0], s[1]});
while (que.size()) {
auto[c, x, y] = que.top();
que.pop();
if (cost[x][y] < c) {
continue;
}
for (i64 i = 0; i < 4; i++) {
i64 ddx = x + dx[i], ddy = y + dy[i];
if (ddx < 0 || G <= ddx || ddy < 0 || G <= ddy) {
continue;
}
i64 randCost = node[x][y].cost[i] * pow(((double) turn / N), 2);
if (cost[x][y] + randCost < cost[ddx][ddy]) {
cost[ddx][ddy] = cost[x][y] + randCost;
bef[ddx][ddy] = {x, y};
que.push({cost[ddx][ddy], ddx, ddy});
}
}
}
string ans;
int nowX = t[0], nowY = t[1];
while (nowX != s[0] || nowY != s[1]) {
if (nowX - 1 == bef[nowX][nowY].first) {
ans += "D";
nowX--;
} else if (nowX + 1 == bef[nowX][nowY].first) {
ans += "U";
nowX++;
} else if (nowY - 1 == bef[nowX][nowY].second) {
ans += "R";
nowY--;
} else if (nowY + 1 == bef[nowX][nowY].second) {
ans += "L";
nowY++;
}
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
double length;
cin >> length;
length /= ans.size();
for (char i:ans) {
if (i == 'D') {
node[nowX][nowY].cost[3] += length;
node[nowX][nowY].cost[3] /= 2;
nowX++;
node[nowX][nowY].cost[1] += length;
node[nowX][nowY].cost[1] /= 2;
} else if (i == 'U') {
node[nowX][nowY].cost[1] += length;
node[nowX][nowY].cost[1] /= 2;
nowX--;
node[nowX][nowY].cost[3] += length;
node[nowX][nowY].cost[3] /= 2;
} else if (i == 'R') {
node[nowX][nowY].cost[0] += length;
node[nowX][nowY].cost[0] /= 2;
nowY++;
node[nowX][nowY].cost[2] += length;
node[nowX][nowY].cost[2] /= 2;
} else if (i == 'L') {
node[nowX][nowY].cost[2] += length;
node[nowX][nowY].cost[2] /= 2;
nowY--;
node[nowX][nowY].cost[0] += length;
node[nowX][nowY].cost[0] /= 2;
}
}
}
return 0;
}
|
#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
int P[200001];
int A[100000];
int find(int A) {
if (P[A] < 0) return A;
return P[A] = find(P[A]);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
rep(i, 200001) P[i] = -1;
int N;
cin >> N;
rep(i, N >> 1) cin >> A[i];
int gomi;
if (N & 1) cin >> gomi;
int kotae = 0;
for (int i = (N >> 1) - 1; i >= 0; i--) {
int a = find(A[i]);
int b;
cin >> b;
b = find(b);
if (a == b) continue;
if (P[a] > P[b]) swap(a, b);
P[a] += P[b];
P[b] = a;
kotae++;
}
co(kotae);
Would you please return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define inf 0x3f3f3f3f
#define PI 3.1415926
typedef long long ll;
const int maxn=25;
int n;
void solve()
{
cin>>n;
int x0,x1,y0,y1;
cin>>x0>>y0>>x1>>y1;
x1-=x0,y1-=y0;
double ang=(n-2)*PI/n/2;
double d=sqrt(1.0*x1*x1+1.0*y1*y1);
double d1=d*cos(ang);
double x=x1/d,y=y1/d;
double u=x0+d1*(x*cos(ang)+y*sin(ang)),v=y0+d1*(y*cos(ang)-x*sin(ang));
printf("%.10lf %.10lf\n",u,v);
}
int main()
{
solve();
return 0;
} |