code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
#include<bits/stdc++.h>
#define qc ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rt return
#define fi first
#define se second
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
typedef long long ll;
using namespace std;
ll dig(ll n)
{
ll ans=0;
while(n>0){
n/=10;ans++;
}rt ans;
}
ll ten(ll n)
{
ll ans=1;
while(n--){
ans*=10;
}
rt ans;
}
int main(){
qc
ll n;cin>>n;
ll d=dig(n);
if(d==1)cout<<0;
else if(d%2==1){
d/=2;
for(ll i=0;i<d;i++){
cout<<9;
}
}
else{
ll a=n/ten(d/2);
n%=ten(d/2);
if(a>n)cout<<a-1;
else cout<<a;
}
rt 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll n;
cin >> n;
ll limit = (log10(n)+1)/2;
ll ans = n/pow(10,limit);
//cout << ans << " " << limit <<" " << endl;
ll temp = ans;
while(temp*pow(10,limit)+temp>n){
temp--;
ans--;
limit = log10(temp)+1;
}
cout << ans << endl;
return 0;
} |
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)
using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int a, b, x, y;
cin >> a >> b >> x >> y;
int res = 0;
int u = 2 * x < y ? 2 * x : y;
if (a > b) {
res += u * (a - b - 1) + x;
} else {
res += u * (b - a) + x;
}
cout << res << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr first
#define sc second
#define pb push_back
int a, b, x, y, ans;
int main(){
cin>>a>>b>>x>>y;
if(a < b){
ans = min((b-a)*y,(b-a)*2*x) + x;
}
else if(a > b){
ans = min((a-b-1)*y,(a-b-1)*2*x) + x;
}
else{
ans = x;
}
cout<<ans<<endl;
return 0;
}
|
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,a) for(ll i=ll(a-1);i>=0;--i)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
for (auto i = first;i != last;i++){
cin >> (*i);
}
}
template<class itr> void array_output(itr start,itr goal){
string ans = "",k = " ";
for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
if (!ans.empty()) ans.pop_back();
PRINT(ans);
}
ll gcd(ll a, ll b) {
return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll MOD3 = 1e6;
const ll EPS = 1e-10;
int sgn(const double a){
return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<int,int> pi;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
typedef complex<double> Point;
const ll MAX = 200005;
constexpr ll nx[4] = {-1,0,1,0};
constexpr ll ny[4] = {0,1,0,-1};
class BIT{
private:
vector<ll> bit;
ll size;
public:
BIT(ll n){
bit.resize(n+1);
size = n;
}
ll sum(ll i){
ll res = 0;
while(i > 0){
res += bit[i];
i -= i&-i;
}
return res;
}
void add(ll i,ll x){
while(i <= size){
bit[i] += x;
i += i&-i;
}
}
};
int main(){
ll h,w,m;
cin >> h >> w >> m;
vector<vector<ll>> x(h);
vector<ll> y(w,h);
ll ox = h,oy = w;
rep(i,m){
ll s,t;
cin >> s >> t;
s--,t--;
x[s].push_back(t);
chmin(y[t],s);
if (s == 0) chmin(oy,t);
if (t == 0) chmin(ox,s);
}
rep(i,h){
x[i].push_back(w);
SORT(x[i]);
}
ll ans = 0;
BIT a(w+1);
rep(i,ox){
if (i == 0){
rep(j,x[i][0]+1,w+1){
a.add(j,1);
}
}
else{
for (ll ind:x[i]){
if (a.sum(ind+1)-a.sum(ind) == 0){
a.add(ind+1,1);
}
}
}
ans += x[i][0]-(x[i][0]-a.sum(x[i][0]));
//PRINT(x[i][0] << " " << a.sum(x[i][0]));
}
rep(i,oy){
ans += y[i];
}
PRINT(ans);
}
| #include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)
using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m;
cin >> n >> m;
vector<vector<ll>> G(n);
rep(i, m) {
int a, b;
cin >> a >> b;
a--, b--;
G[a].pb(b);
G[b].pb(a);
}
int k;
cin >> k;
vector<ll> c(k);
set<int> p;
rep(i, k) {
cin >> c[i];
c[i]--;
p.insert(c[i]);
}
vector<vector<ll>> dist(k, vector<ll>(k));
queue<ll> q;
rep(i, k) {
q.push(c[i]);
vector<ll> tmp_dist(n, INF);
tmp_dist[c[i]] = 0;
while (!q.empty()) {
ll crr = q.front();
q.pop();
for (auto next : G[crr]) {
if (tmp_dist[crr] + 1 < tmp_dist[next]) {
tmp_dist[next] = tmp_dist[crr] + 1;
q.push(next);
}
}
}
rep(j, k) dist[i][j] = tmp_dist[c[j]];
}
// bitdp
ll max_s = 1 << k;
vector<vector<ll>> dp(max_s, vector<ll>(k, INF));
rep(i, k) dp[1 << i][i] = 1;
reps(bit, max_s, 1) {
rep(i, k) {
if ((bit >> i) & 1) {
ll target_bit = 1 << i;
ll bit2 = bit ^ target_bit;
rep(j, k) {
if ((bit2 >> j) & 1) { dp[bit][i] = min(dp[bit][i], dp[bit2][j] + dist[i][j]); }
}
}
}
}
ll res = INF;
for (ll val : dp[max_s - 1]) res = min(res, val);
if (res == INF) res = -1;
cout << res << endl;
return 0;
} |
// #include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
// using namespace atcoder;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;
const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;
int main(){
int N, K;
cin >> N >> K;
ll ans = 0;
for (int x = 2; x <= 2*N; ++x) {
int y = x - K;
if (y < 2 || 2*N < y) continue;
ans += (ll)(x-1 - max(0, (x-N-1) * 2)) * (y-1 - max(0, (y-N-1) * 2));
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#pragma optimize("-O3")
#define int long long int
#define f first
#define s second
#define pb push_back
#define endl '\n'
const int MOD=998244353;
int n, m;
int po[5005][5005];
main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
int tot=n;
for(int i=0; i<5005; i++){
po[i][0]=1;
}
po[0][0]=1;
for(int i=1; i<5005; i++){
for(int j=1; j<5005; j++){
po[i][j]=(i*po[i][j-1])%MOD;
}
}
for(int i=0; i<n; i++){
tot=(tot*m)%MOD;
}
for(int i=0; i<=n-2; i++){
int val=n-i-1;
for(int j=1; j<=m; j++){
int val=((((n-i-1)*po[m-j][i])%MOD)*po[m][n-i-2])%MOD;
tot=(tot-val+MOD)%MOD;
}
}
cout<<tot;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ll = long long;
using vl = vector<long long>;
using vi = vector<int>;
int main(){
string s; cin >> s;
string tmp1="",tmp2;
int c = s.size();
bool flag = false;
for(int ix=0;ix<c;ix++){
if(s.at(c-ix-1) != '0' || flag == true){
tmp1 = s.at(c-ix-1) + tmp1;
flag = true;
}
}
//cout << tmp1 << endl;
tmp2 = tmp1;
reverse(tmp2.begin(),tmp2.end());
if(tmp1 == tmp2){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll gcd(ll a, ll b){return b? gcd(b, a % b): a;}
ll quickpow(ll a, ll b){ll res = 1; while(b){if (b & 1) res = res * a; a = a * a; b >>= 1;} return res;}
// head
string s;
int main(void){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> s;
for (auto it: s) {
if (it == '.') break;
cout << it;
}
cout << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
char s,t;
cin>>s>>t;
if(s=='Y')cout<<char(toupper(t))<<endl;
else cout<<t<<endl;
return 0;
} | #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#include<atcoder/all>
#include<iostream>
#include<cstdint>
#include<cstddef>
using namespace std;
//using namespace atcoder;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
char a;
char b;
cin >> a >> b;
if(a == 'Y'){
if(b == 'a')cout << 'A' << endl;
else if(b == 'b')cout << 'B' << endl;
else cout << 'C' << endl;
}else{
cout << b << endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr long long mod = 1000000007;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<string> v(n);
rep(i, n) cin >> v[i];
string ss = "atcoder";
rep(i, n) {
if (ss >= v[i]) {
bool b = true;
int ind = 0;
rep(j, v[i].size()) {
if (v[i][j] != 'a') {
if (v[i][j] > 't') {
ind = j - 1;
} else {
ind = j;
}
b = false;
break;
}
}
if (b) {
cout << -1 << endl;
} else {
cout << ind << endl;
}
} else {
cout << 0 << endl;
}
}
} | #include <bits/stdc++.h>
using namespace std;
// overflow prob
#define int long long
#define p_queue priority_queue
#define all(n) n.begin(),n.end()
#define gcd(x,y) __gcd(x,y)
#define findString(s,x) s.find(x)!=string::npos
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define rall(n) n.rbegin(),n.rend()
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);cout << fixed << setprecision(10);
#define next cout<<"\n"
template<typename T> void debug(vector<T> &array, bool IsSorted) {
if (IsSorted) sort(all(array));
for (int i = 0 ; i < array.size() ; i++) {
cout << array[i] << " ";
}
next;
}
template<typename T> T max(T &a, T &b) {
return a > b ? a : b;
}
template<typename T> T min(T &a, T &b) {
return a > b ? b : a;
}
template<typename T> T maxthree(T &a, T &b, T &c) {
return max(a, max(b, c));
}
template<typename T> T minThree(T &a, T &b, T &c) {
return min(a, min(b, c));
}
const double pi = 3.141592653589793238; const int INF = 1e9; const int32_t M = 1e9 + 7; const int32_t MM = 998244353;
const int N = 1e5 + 5; const int32_t maxn = N;
void solve();
signed main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
FAST_IO
int T = 1;
// cin >> T;
while (T--) solve();
}
//.........................................................MainCode..............................................................................
// solving for base
void solve() {
string x;
cin >> x;
int m;
cin >> m;
if (x.size() == 1) {
cout << (x[0] - '0' <= m ? '1' : '0');
return;
}
int d = 0;
for (int i = 0 ; i < x.size(); i++) {
d = max(d, (int)x[i] - '0');
}
// max element
int ng = 2e18;
int ok = d;
while (ng - ok > 1) {
int mid = ok + (ng - ok) / 2;
int res = 0;
bool jdg = true;
for (int i = 0 ; i < x.size() ; i++) {
if (res >= 2e18 / mid) {
ng = mid;
jdg = false;
break;
}
res *= mid;
res += (x[i] - '0');
}
if (jdg) {
if (res > m) ng = mid;
else ok = mid;
}
}
cout << ok - d << endl;
} |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll N,M,X,Y; cin >> N >> M;
vector<pair<ll,ll>> P;
set<ll> A,B,S; S.insert(N);
for (int i =0; i<M; i++) { cin >> X >> Y; P.push_back({X,Y});}
sort(P.begin(),P.end());
ll tmp = 0,cnt;
while (tmp < M) {
A.clear(); B.clear();
cnt = tmp;
while (cnt < M) {
if (P[cnt].first == P[tmp].first) cnt++;
else break; }
for (int i =tmp; i<cnt; i++) {
ll tmpY = P[i].second;
if (S.find(tmpY)==S.end()) {
if (S.find(tmpY-1)!=S.end() || S.find(tmpY+1)!=S.end()) A.insert(tmpY);
} else {
if (S.find(tmpY-1)==S.end() && S.find(tmpY+1)==S.end()) B.insert(tmpY);
}
}
for (auto x: A) S.insert(x);
for (auto x: B) S.erase(x);
tmp = cnt;
}
cout << S.size() << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define vec vector<int>
#define vecp vector<pair<int,int>>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fr first
#define sc second
#define fr1(i,a,b) for(int i=a;i<b;i++)
#define fr2(i,a,b) for(int i=a;i>=b;i--)
#define fr3(i,a,b) for(int i=a;i<=b;i++)
#define umap unordered_map<int,int,custom_hash>
#define omap map<int,int>
#define uset unordered_set<int,custom_hash>
#define oset set<int>
#define pr pair<int,int>
#define mod 1000000007
#define mp make_pair
#define all(v) v.begin(),v.end()
#define ppb pop_back
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);
}
};
void solve()
{
int n,m,q;
cin>>n>>m>>q;
vecp v(n);
fr1(i,0,n)cin>>v[i].sc>>v[i].fr;
sort(all(v),greater<pair<int,int>>());
vec box(m);
fr1(i,0,m)cin>>box[i];
fr1(i,0,q)
{
int l,r;
cin>>l>>r;
vec cap;
fr1(i,0,m)
{
if(i>=l-1&&i<=r-1)continue;
cap.pb(box[i]);
}
ll ans=0;
vector<bool> var(cap.size(),true);
fr1(i,0,n)
{
int val=INT_MAX,index1=-1,index2=-1;
for(int j=0;j<cap.size();j++)
{
if(var[j]&&cap[j]>=v[i].sc&&cap[j]-v[i].sc<val)
{
val=cap[j]-v[i].sc;
index1=j;
index2=v[i].fr;
}
}
if(index1>=0)
{
var[index1]=false;
ans+=index2;
}
}
cout<<ans<<"\n";
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
//cin>>t;
fr3(i,1,t){
//cout<<"Case: "<<t<<;
solve();
}
return 0;
} |
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
void solve_WA() {
int N;
cin >> N;
vector<int> A(N + 1);
//vector<int> ac(N + 1, 0);
map<int, int>ac;
/*
1 5 3 2 5 2 3 1の場合はOK ※連結成分が1のみ
1 5 3 2 5 4 6 1の場合はNG ※連結成分が2以上
*/
for (size_t i = 1; i < N+1; i++)
{
cin >> A[i];
}
int l, r;
int m = N / 2;
for ( l = 1,r=N; l <= m; l++, r--)
{
if (A[l] != A[r]) {
ac[A[l]]++;
ac[A[r]]++;
}
}
//vector<P> co;
int ans = 0;
if (N == 1 || ac.size() == 0) {
ans = 0;
}
else {
ans = ac.size() - 1;
}
cout << ans << endl;
//return 0;
}
template <typename T>
struct UnionFind {
vector<T> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(T N) : par(N) { //最初は全てが根であるとして初期化
for (T i = 0; i < N; i++) par[i] = i;
}
int root(T x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(T x, T y) { // xとyの木を併合
T rx = root(x); //xの根をrx
T ry = root(y); //yの根をry
if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
}
bool same(T x, T y) { // 2つのデータx, yが属する木が同じならtrueを返す
T rx = root(x);
T ry = root(y);
return rx == ry;
}
vector<vector<T>> linked_group() {
vector<vector<T>> group(par.size());
for (T i = 0; i < par.size(); i++)
{
T r = root(par[i]);
group[r].emplace_back(i);
}
return group;
}
};
void solve() {
int N;
cin >> N;
vector<int> A(N + 1);
map<int, int>ac;
for (size_t i = 1; i < N + 1; i++)
{
cin >> A[i];
}
int l, r;
int m = N / 2;
UnionFind<int> uf(2*1e5+1);
for (l = 1, r = N; l <= m; l++, r--)
{
if (A[l] != A[r]) {
uf.unite(A[l], A[r]);
}
}
vector<vector<int>> lg = uf.linked_group();
int ans = 0;
for (auto g : lg) {
if (1 < g.size()) {
ans += g.size() - 1;
}
}
cout << ans << endl;
}
int main()
{
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define reps(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define pr(a) cout << a
#define prl(a) cout << (a) << endl
#define prld(a) cout << setprecision(15)<< (a) << endl
#define allrange(a) a.begin(),a.end()
struct GrowedUnionFind {
std::unordered_map<int,int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
std::unordered_set<int> keys;
int ccnum; //連結成分の個数
GrowedUnionFind():par(),keys(){ ccnum =0;}
void insert(int x)
{
if(!find(x)){
keys.insert(x);
par[x]=x;
ccnum++;
}
}
bool find(int x) //元が入っているか探す。平均o(1)
{
return keys.count(x)==1;
}
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); //xの根をrx
int ry = root(y); //yの根をry
if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
ccnum--;
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
int main(){
std::cin.tie(0); // cinとcoutの同期を解除
std::ios::sync_with_stdio(false);
//1変数入力
int N;
cin >> N;
bool flg=false;
int ans;
vector<int> A(N/2);
vector<int> B(N/2);
int j = N%2;//パリティ
rep(i,N){
if(i<N/2)
cin >> A[i];
else if(i>=N/2+j)
cin >> B[i-N/2-j];
else if(j==1 && i == N/2) cin >> ans; //捨て
}
ans=0;
reverse(allrange(A));
int n = N/2;
GrowedUnionFind V;
rep(i,n){
if(A[i] != B[i])
{ V.insert(A[i]);V.insert(B[i]);V.unite(A[i],B[i]);}
}
//次数1の頂点はつぶせる
//triangleが多くつぶせるといい
//写像で頂点をつぶす射影写像の合成回数の問題
//射影写像自体は可換なので, 実は順番はあまり関係ない
//非連結成分はくっつける必要はない.
//連結成分同士を1点に潰せればいい.
// 頂点数-連結成分の個数
ans = V.keys.size()-V.ccnum;
flg = true;
if(flg) prl(ans);
else prl(-1);
}
|
/** This won't be the end of me */
#include <iostream>
#include <algorithm>
#define endl '\n'
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mt make_tuple
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int mx, k, m, n;
int a[100], b[100], c[16], d[16], dish[101];
void loop()
{
int cnt = 0;
for(size_t i = 0; i < m; ++i)
{
if(dish[a[i]] && dish[b[i]])
++cnt;
}
mx = max(mx, cnt);
// cout << "max == " << mx << endl;
}
void check(int row, bool val)
{
val == true ? ++dish[d[row]] : ++dish[c[row]];
// cout << "incremented " << (val == true? d[row] : c[row]) << endl;
if(row == k-1) // base case
loop();
if(row+1 < k)
{
check(row+1, false);
check(row+1, true);
}
val == true ? --dish[d[row]] : --dish[c[row]];
// cout << "decremented " << (val == true? d[row] : c[row]) << endl;
}
void solve()
{
int i, j, l;
cin >> n >> m;
for(i = 0; i < m; ++i)
cin >> a[i] >> b[i];
cin >> k;
for(i = 0; i < k; ++i)
cin >> c[i] >> d[i];
check(0, false); // activate c[row]
check(0, true); // activate d[row]
cout << mx;
}
int main()
{
FAST
// int t; cin >> t; while(t--){
solve();
// }
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define Please return
#define AC 0
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
signed main(){
//cout << fixed << setprecision(10);
int n,m; cin >> n >> m;
vi a(m),b(m);
rep(i,0,m)cin >> a[i] >> b[i];
int k; cin >> k;
vi c(k),d(k);
rep(i,0,k){
cin >> c[i] >> d[i];
}
int ans = 0;
rep(i,0,(1<<k)){
int tmp = 0;
vi v(n);
rep(j,0,k){
if(i>>j&1){
v[d[j]-1] = 1;
}
else{
v[c[j]-1] = 1;
}
}
rep(i,0,m){
tmp += (v[a[i]-1]&&v[b[i]-1]);
}
chmax(ans,tmp);
}
cout << ans << endl;
Please AC;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
int main() {
int n;
cin >> n;
cout << n - 1;
} | #include<iostream>
#include<bits/stdc++.h>
#define forf(i,start,n,increment) for(int i = start;i<n;i+=increment)
#define all(i) i.begin(),i.end()
#define traverse(container,it) for(typeof(container.begin()) it = container.begin();it != container.end();it++)
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
if(n%2 == 0)
cout<<(n/2-1)*2+1;
else
cout<<(n/2)*2;
return 0;
} |
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
#define MOD 1000000007
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
#define MAX 1000000000000
int main(void) {
char s,t; cin >> s>>t;
if (s == 'Y') {
cout << char(t -32) << endl;
}
else {
cout << t << endl;
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pob pop_back
#define eb emplace_back
#define ins insert
#define mp make_pair
#define ff first
#define ss second
#define pf push_front
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define sz(a) (ll)a.size()
#define dec(x) fixed<<setprecision(x)
#define lcm(a,b) (a*b/__gcd(a,b))
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>,greater<ll> > pqmn;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vector<ll> > vvll;
typedef vector<string> vs;
typedef set<ll> sll;
typedef set<pll> spll;
typedef map<ll,ll> mll;
const ll inf=LLONG_MAX;
const ll mod=1e9+7;
const ld pi=acos(-1);
const ll N=100001;
void solution()
{
ll x,y;
cin >> x>> y;
if(x == y) {
cout << x;
}
else {
cout << 3 - (x + y);
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t;
t=1;
//cin>>t;
for(ll i = 1; i <= t ; i++) {
// cout << "Case #" << i <<": ";
solution();
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
long long ans = N * (N + 1) * K * 100 + K * (K + 1) * N;
ans /= 2;
cout << ans << endl;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,k;cin >> n >> k;
int ans=0;
FOR(i,1,n+1) FOR(j,1,k+1){
ans+=100*i+j;
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define RSort(a) sort(a.rbegin(), a.rend())
#define Output(a) cout << a << endl
typedef long long int ll;
typedef vector<int> vi;
typedef vector<long long> vll;
const int INF = 1<<30;
const ll MOD = 1000000007;
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; }
/* 二次元配列
vector<vector<Type>> vv(n, vector<Type>(m, d));
vector<vector<ll>> vv(n, vector<ll>(m, d));
*/
struct UnionFind {
vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
for(int i = 0; i < N; i++) par[i] = i;
}
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); //xの根をrx
int ry = root(y); //yの根をry
if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
int main(){
ll n, q; cin >> n >> q;
UnionFind tree(n);
vector<unordered_map<ll, ll>> cn(n);
int c;
rep(i, n){
cin >> c;
c--;
cn[i][c] = 1;
}
rep(i, q){
ll a, x, y;
cin >> a >> x >> y;
x -= 1;
y -= 1;
if(a == 1){
ll root_x = tree.root(x);
ll root_y = tree.root(y);
if(!tree.same(root_x, root_y)){
// マージテク (要素の大きさが小さい方を移動させることで計算量を少なくする。)
if(cn[tree.root(y)].size() < cn[tree.root(x)].size()) swap(root_x, root_y);
tree.unite(root_x, root_y); // yが根になる
for(auto [key, value] : cn[root_x]){
cn[tree.root(y)][key] += value;
}
}
}else{ // a == 2
Output(cn[tree.root(x)][y]);
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
const int mod = 1e9+7, N = 2e5+5;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val);}
int n, m, k;
struct dsu{
vector<int> p, rnk;
dsu(int n){
p.assign(n, 0);
rnk.assign(n,0);
for(int i=0;i<n;i++)p[i]=i;
}
int par(int u){
if(p[u]==u)return u;
else return p[u] = par(p[u]);
}
int merge(int u, int v){
u = par(u);
v = par(v);
if(rnk[u] > rnk[v]){
p[v] = u;
rnk[u]++;
return u;
}else {
p[u] = v;
rnk[v]++;
return v;
}
}
};
int a[N];
map<int, int> t[N];
void solve(int test_case){
int i, j, q;
cin >> n >> q;
for(i=0;i<n;i++){
cin >> a[i];
a[i]--;
t[i][a[i]]=1;
}
dsu d(n);
while(q--){
int typ, x, y;
cin >> typ >> x >> y;
x--,y--;
if(typ == 1){
x = d.par(x), y = d.par(y);
if(x == y)continue;
int u = d.merge(x, y);
if(u != x)swap(x, y);
for(auto [f, s] : t[y])t[u][f] += s;
}else {
cout << t[d.par(x)][y] << '\n';
}
}
}
signed main(){
FASTIO;
#define MULTITEST 0
#if MULTITEST
int ___T;
cin >> ___T;
for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
solve(T_CASE);
#else
solve(1);
#endif
return 0;
}
|
#include <bits/stdc++.h>
#define lowbit(x) ((x)&(-x))
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int N=160;
const int mod=1000000007;
int a,b;
int main() {
cin>>a>>b;
int ans=1;
for(int i=b;i>=1;i--) {
int r=b/i;
int l=(a+i-1)/i;
// cout<<i<<" "<<l<<" "<<r<<endl;
if(r-l+1>=2) {
ans=i;
break;
}
}
cout<<ans<<endl;
return 0;
}
| #include<stdlib.h>
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
#include <stack>
#include<stdlib.h>
#include<stdio.h>
#include <sstream>
#include <inttypes.h>
#include<climits>
//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef unsigned long long int llt;
const int M = 1e6;
ll min(int x , int y){
return ( x<y ? x:y);
}
int max(int x , int y){
return ( x<y ? y:x);
}
int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
// Function to return LCM of two numbers
ll lcm(ll a, ll b)
{
return (a / gcd(a, b)) * b;
}
int findMaxGCD(int arr[], int n)
{
// Calculating MAX in array
int high = 0;
for (int i = 0; i < n; i++)
high = max(high, arr[i]);
// Maintaining count array
int count[high + 1];
for(int i=0;i<=high;i++){
count[i]=0;
}
for (int i = 0; i < n; i++)
count[arr[i]]++;
// Variable to store the
// multiples of a number
int counter = 0;
// Iterating from MAX to 1
// GCD is always between
// MAX and 1. The first
// GCD found will be the
// highest as we are
// decrementing the potential
// GCD
for (int i = high; i >= 1; i--)
{
int j = i;
counter = 0;
// Iterating from current
// potential GCD
// till it is less than
// MAX
while (j <= high)
{
// A multiple found
if(count[j] >=2)
return j;
else if (count[j] == 1)
counter++;
// Incrementing potential
// GCD by itself
// To check i, 2i, 3i....
j += i;
// 2 multiples found,
// max GCD found
if (counter == 2)
return i;
}
}
}
void solve(){
int a,b;
cin>>a>>b;
/* int mx=1;
for(int i=b;i>a;i--){
int y =i;
for(int j = y-1;j>=a;j--){
mx = max(mx , gcd(y,j));
}
}
cout<<mx<<endl;
return;*/
int arr[b-a+1];
for(int i=0;i<(b-a+1);i++){
arr[i] = a+i;
}
cout<<findMaxGCD(arr , (b-a+1));
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define F first
#define S second
#define INF 1e18
#define N 1000005
using namespace std;
ll h, w, a, b;
ll go(vector<vector<ll>> &v, ll i, ll j, ll a, ll b)
{
if (a < 0 || b < 0)return 0;
if (j == w)
{
j = 0, ++i;
}
if (i == h)
{
return 1;
}
if (v[i][j] == 1)
{
return go(v, i, j + 1, a, b);
}
ll ans = 0;
if (j + 1 < w && a > 0 && v[i][j] == 0 && v[i][j + 1] == 0)
{
v[i][j] = v[i][j + 1] = 1;
ans += go(v, i, j + 1, a - 1, b);
v[i][j] = v[i][j + 1] = 0;
}
if (i + 1 < h && a > 0 && v[i][j] == 0 && v[i + 1][j] == 0)
{
v[i][j] = v[i + 1][j] = 1;
ans += go(v, i, j + 1, a - 1, b);
v[i][j] = v[i + 1][j] = 0;
}
if (b > 0)
{
v[i][j] = 1;
ans += go(v, i, j + 1, a, b - 1);
v[i][j] = 0;
}
return ans;
}
void solve()
{
cin >> h >> w;
cin >> a >> b;
vector<vector<ll>> v = vector<vector<ll>>(h, vector<ll>(w, 0));
cout << go(v, 0, 0, a, b) << endl;
}
int32_t main()
{
IOS
ll T = 1;
// cin >> T;
for (ll i = 1; i <= T; ++i)
{
// cout<<"Case #"<<i<<": ";
solve();
}
return 0;
} | #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;
const vec<vec<pi64>> kPieces{
vec<pi64>
{pi64{0, 0},},
{pi64{0, 0},{0, 1},},
{pi64{0, 0},{1, 0},},
};
i64
dfs(const i64 r, const i64 c, vec<vec<bool>>& G, const i64 R, const i64 C, const i64 A, const i64 B)
{
let auto& INR = [R, C](const i64 u, const i64 v)
{
return 0 <= u && u < R && 0 <= v && v < C;
};
let auto& LIN = [C](const i64 u, const i64 v)
{
return u * C + v;
};
let auto& LIN_INV = [C](const i64 x)
{
return make_pair(x / C, x % C);
};
let auto& FIT = [&](const vec<pi64>& piece)
{
for (let auto [dr, dc] : piece)
{
if (!INR(r + dr, c + dc))
{
return false;
}
if (G[r + dr][c + dc])
{
return false;
}
}
return true;
};
if (LIN(r, c) > LIN(R - 1, C - 1))
{
assert(A == 0);
assert(B == 0);
return 1;
}
P("r: " << r << " c: " << c);
let pi64 nxt(LIN_INV(LIN(r, c) + 1));
if (G[r][c])
{
return dfs(nxt.first, nxt.second, G, R, C, A, B);
}
i64 acc = 0;
for (i64 pi = 0; pi < kPieces.size(); ++pi)
{
let auto& piece = kPieces[pi];
if (!FIT(piece))
{
continue;
}
if (pi == 0 && B == 0)
{
continue;
}
if (pi > 0 && A == 0)
{
continue;
}
for (let auto [dr, dc] : piece)
{
G[r + dr][c + dc] = true;
}
acc += dfs(nxt.first, nxt.second, G, R, C, A - (pi > 0), B - (pi == 0));
for (let auto [dr, dc] : piece)
{
G[r + dr][c + dc] = false;
}
}
return acc;
}
int
main()
{
ios_base::sync_with_stdio(false);
// fast io: see 1423K
cin.tie(nullptr);
cout.tie(nullptr);
DRi64(R); DRi64(C); DRi64(A); DRi64(B);
vec<vec<bool>> G(R, vec<bool>(C, false));
cout << dfs(0, 0, G, R, C, A, B) << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::vector<std::vector<int64_t> > Graph;
#define in1(n) int64_t n;cin >> n;
#define in2(n, m) int64_t n, m;cin >> n >> m;
#define in3(n, m, k) int64_t n, m, k;cin >> n >> m >> k;
#define in4(a, b, c, d) int64_t a, b, c, d;cin >> a >> b >> c >> d;
#define rep(i, n) for (int64_t i = 0; i < n; ++i)
#define rep2(i, n) for (int64_t i = 1; i <= n; ++i)
#define repb(i, l, n) for (int64_t i = l; i < n; ++i)
#define repb2(i, l, n) for (int64_t i = l; i <= n; ++i)
#define repc(i, l, n, d) for (int64_t i = l; i < n; i+=d)
#define repc2(i, l, n, d) for (int64_t i = l; i <= n; i+=d)
#define rep_(i, r) for (int64_t i = r-1; i >= 0; --i)
#define rep_2(i, r) for (int64_t i = r; i > 0; --i)
#define rep_b(i, r, l) for (int64_t i = r; i >= l; --i)
#define rep_b2(i, r, l) for (int64_t i = r; i > l; --i)
#define rep_c(i, r, l, d) for (int64_t i = r; i >= l; i-=d)
#define rep_c2(i, r, l, d) for (int64_t i = r; i > l; i-=d)
#define repf(i, l, c, d) for (int64_t i = l; c; i+=d)
#define repi(a, b) for (auto&(a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))
#define Sort_pair(x, p) sort(ALL(x), (p))
#define mp(a, b) make_pair((a), (b))
#define Push_back(a, b) push_back( mp( (a), (b) ) )
#define ctoi(c) ((c)-'0')
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename V,typename T> bool find_num(V v, T num) { if ( find(ALL(v), num) == v.end() ) { return false; } return true; }
const int inf = 0x3fffffff;
const int64_t INF = 0x3fffffffffffffff;
const int64_t MOD = 1e9+7;
/*
int main() {
in1(n);
std::vector<int64_t> a(n);
int64_t sum = 0, num;
rep(i, a.size()) {
cin >> a[i];
if ( i == 0 ) {
num = a[i];
} else {
chmax(num, a[i]);
}
sum += a[i];
std::vector<int64_t> v = a;
int64_t ans = sum, num2 = num;
rep(j, i+1) {
v[j] += num2;
ans += num2;
chmax(num2, v[j]);
}
cout << ans << endl;
}
return 0;
}
*/
int main() {
in1(n);
std::vector<int64_t> a(n);
rep(i, a.size()) {
cin >> a[i];
}
int64_t num = 0, sum = 0, sum2 = 0;
rep(i, n) {
chmax(num, a[i]);
sum += a[i];
sum2 += sum;
cout << num*(i+1)+sum2 << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
#define all(v) (v).begin(),(v).end()
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
ll res=1;
a=a%MOD;
while(b>0){
if(b&1){res=(res*a)%MOD;b--;}
a=(a*a)%MOD;
b>>=1;
}
return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n)
{
memset(prime, true, sizeof(prime));
prime[0]=prime[1]=0;
for (int p=2; p*p<=n; p++)
{
if (prime[p] == true)
{
for (int i=p*p; i<=n; i += p)
prime[i] = false;
}
}
for(int p=2;p<1000001;p++)
if(prime[p])
primes.pb(p);
}
ll fact[100010];
ll finv[100010];
void factorial(int n){
fact[0]=1;
finv[0]=1;
for(int i=1;i<=n;i++)
fact[i]=fact[i-1]*i,fact[i]%=MOD,finv[i]=fermat_inv(fact[i]);
}
ll ncr(ll n,ll r)
{
if(n<r)
return 0;
else{
ll x=finv[r]*finv[n-r]%MOD;
return fact[n]*x%MOD;
}
}
double dp[101][101][101];
double solve(double a,double b,double c){
//cout<<a<<' '<<b<<' '<<c<<'\n';
if(dp[(int)a][(int)b][(int)c]!=-1)
return dp[(int)a][(int)b][(int)c];
if(a==100||b==100||c==100)
return 0;
return dp[(int)a][(int)b][(int)c]=a/(a+b+c)*(solve(a+1,b,c)+1)+b/(a+b+c)*(solve(a,b+1,c)+1)+c/(a+b+c)*(solve(a,b,c+1)+1);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int te=1;
//cin>>te;
//SieveOfEratosthenes(1000000);
//factorial(100005);
while(te--){
double a,b,c;
cin>>a>>b>>c;
for(int i=0;i<=100;i++)
for(int j=0;j<=100;j++)
for(int k=0;k<=100;k++)
dp[i][j][k]=-1;
cout<<setprecision(15)<<solve(a,b,c);
}
} |
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define rep(i, n) for(int i = 0; i < n; i++)
const int mod = (int)1e9 + 7;
int power(int x, int n, int m){
x %= m ;
int ans = 1 ;
while(n > 0){
if( n & 1 ) ( ans *= x ) %= m ;
( x = x * x ) %= m ;
n >>= 1 ;
}
return ans ;
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n; cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
sort(a.begin(), a.end());
int res = a[0] + 1;
for(int i = 1; i < n; i++){
res = (res * (a[i] - a[i - 1] + 1)) % mod;
}
cout << res << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;
void Main() {
ll n;
R n;
vector<ll> a(n+1,0);
rep(i,n) R a[i];
sort(all(a));
a.erase(unique(all(a)),a.end());
ll ans=1;
rrep(i,a.size()-1) {
ans*=a[i+1]-a[i]+1;
ans%=MAX;
}
pr(ans);
}
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
|
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << a*d - b*c<< endl;
} | #include <bits/stdc++.h>
#define PI acos(-1)
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define pb push_back
#define eb emplace_back
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define bump cout<<"bleh\n"
#define all(v) (v).begin(),(v).end()
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define file freopen("input.txt", "r", stdin)
#define reset(x,n) memset(x,n,sizeof(x))
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
*/
/*
find_by_order(k): It returns to an iterator to the kth element (counting from zero)
order_of_key(k) : It returns to the number of items that are strictly smaller than our item k
*/
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const int nmax=1e5+10;
const int eps=1e-8;
const ll infll=1e18+10;
const int len = 3e5+10;
int tree[4*len];
int ara[len];
void build(int node, int start, int endd)
{
if(start==endd)
{
tree[node]=ara[start];
}else
{
int mid=(start+endd)/2;
build(2*node,start,mid);
build(2*node+1,mid+1,endd);
tree[node]=tree[2*node]^tree[2*node+1];
}
}
void update(int node, int start, int endd, int idx, int val)
{
if(start==endd)
{
ara[idx]=val;
tree[node]=val;
}else
{
int mid=(start+endd)/2;
if(idx>=start and idx<=mid)
update(2*node,start,mid,idx,val);
else
update(2*node+1,mid+1,endd,idx,val);
tree[node]=tree[2*node]^tree[2*node+1];
}
}
int query(int node,int start,int endd, int l, int r)
{
if(start>=l and endd<=r)
return tree[node];
if(start>r or endd<l)
return 0 ;
int mid=(start+endd)/2;
int p1=query(2*node,start,mid,l,r);
int p2=query(2*node+1,mid+1,endd,l,r);
int ans=p1^p2;
return ans;
}
inline void solve()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
int x = (a*d) - (b*c);
cout<<x<<"\n";
}
/*
-> sometimes thinking in reverse makes it easier!
-> check for overflow! pay attention to constraints!
-> maybe write a bruteforce locally for clues!
*/
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fastio;
//int t;
//cin>>t;
//while(t--){
solve();
//}
return 0;
}
/*
*/
|
#include <iostream>
using namespace std;
int main()
{
int n, x,input;
cin >> n >> x;
for (int i = 0; i < n; i++)
{
cin >> input;
if (input != x)
{
cout << input<<endl;
}
}
}
|
#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(7)<<(x)
#define all(v) (v).begin(), (v).end()
using namespace std;
#define loop(i,a,b) for (int i=a; i<b; ++i)
using ll = long long;
const int mod = 998244353;
typedef pair<int , int> pairs;
typedef complex<ll> G;
const int N = 1e3 + 5;
int power(int a,int b){
if(!b)
return 1;
int c=power(a,b/2);
c=(1LL*c*c)%mod;
if(b%2)
c=(1LL*c*a)%mod;
return c;
}
void done() {
}
/*string solve_palindrome(const string& s)
{
string a = s;
reverse(a.begin(), a.end());
//a = s + "#" + a;
int c = 0;
for (int i = 1; i < (int)a.size(); i++)
{
while (c != 0 && a[c] != a[i])
c = pref[c - 1];
if (a[c] == a[i])
c++;
pref[i] = c;
}
return s.substr(0, c);
}
*/
/*3
3 7 7 9 11
4 6 6 7*/
void solve()
{
int n, m;
cin >> n >> m;
int c[n][m];
for(int i = 0;i < n;++i) {
for(int j = 0;j < m;++j) {
cin >> c[i][j];
}
}
}
int n, m, q;
string s, t;
int cc[N];
int pref[N];
bool check(int l, int r) {
for (int i = l, j = 1; i <= r; i++, j++) {
if (s[i] != t[j]) {
return false;
}
}
return true;
}
void another() {
char a, b;
cin >> a >> b;
if(a == 'Y')b = toupper(b);
cout << b << '\n';
}
void test_case() {
int t;
cin >> t;
while(t--)another();
}
int main() {
ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
another();
}
|
#include<bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << (x) << "\n"
using namespace std;
int si, sj, t[60][60], p[60][60], M;
bool b1[50 * 51];
int score(string s) {
int xs = si, ys = sj, r = p[xs][ys];
for (char c : s) {
if (c == 'U')xs--;
if (c == 'D')xs++;
if (c == 'L')ys--;
if (c == 'R')ys++;
r += p[xs][ys];
}
return r;
}
int main() {
srand((unsigned)time(NULL));
cin >> si >> sj; si++; sj++; b1[2525] = 1;
for0(i, 52)for0(j, 52) {
if (i * j == 0 || i == 51 || j == 51)t[i][j] = 2525;
else { cin >> t[i][j]; M = max(M, t[i][j]); }
}
for1(i, 50)for1(j, 50)cin >> p[i][j];
string s1 = ""; int v1 = score(s1), ti = clock();
while(clock() - ti <= 1800000) {
string sp = "";
int xi = si, yi = sj;
while (1) {
b1[t[xi][yi]] = 1;
int tm = b1[t[xi - 1][yi]] + b1[t[xi + 1][yi]] + b1[t[xi][yi - 1]] + b1[t[xi][yi + 1]];
if (tm == 4)break;
int ri = rand() % (4 - tm);
if (b1[t[xi - 1][yi]] == 0) { if (ri == 0) { sp += 'U'; xi--; } ri--; }
if (b1[t[xi + 1][yi]] == 0) { if (ri == 0) { sp += 'D'; xi++; } ri--; }
if (b1[t[xi][yi - 1]] == 0) { if (ri == 0) { sp += 'L'; yi--; } ri--; }
if (b1[t[xi][yi + 1]] == 0) { if (ri == 0) { sp += 'R'; yi++; } ri--; }
}
int vi = score(sp);
if (vi > v1) {
s1 = sp; v1 = vi;
}
for0(i, M)b1[i] = 0;
}
puts(s1);
} | #include <vector>
#include <stdio.h>
#include <algorithm>
int n, fa[100005], head[100005], cnt, dp[100005], size[100005];
struct edge { int to, nxt; } g[100005];
inline void add_edge(int f, int t) {
g[++cnt].to = t;
g[cnt].nxt = head[f];
head[f] = cnt;
}
void dfs(int u) {
dp[u] = 1; size[u] = 1;
std::vector<int> vs;
int side = 1, sum = 0;
for (int i = head[u]; i; i = g[i].nxt) {
dfs(g[i].to);
size[u] += size[g[i].to];
if (size[g[i].to] & 1) vs.push_back(dp[g[i].to]);
else if (dp[g[i].to] >= 0) sum += dp[g[i].to];
else dp[u] += dp[g[i].to];
}
std::sort(vs.begin(), vs.end());
for (int val : vs) {
dp[u] += side * val;
side = -side;
}
dp[u] += side * sum;
}
int main() {
scanf("%d", &n);
for (int i = 2; i <= n; ++i) scanf("%d", fa + i), add_edge(fa[i], i);
dfs(1);
printf("%d\n", (n + dp[1]) >> 1);
return 0;
} |
/** author: samari06, created: 09.03.2021 21:49:15 **/
#include <bits/stdc++.h>
#define REP(i, N) for(int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
typedef vector<int> V;
typedef vector<ll> Vll;
int t[55][55], p[55][55], sx, sy;
int cscr = 0, bstscr = 0;
string dist = "RLDU";
class Timer {
private:
clock_t time_start; // 計測開始時間
public:
Timer() { restart(); }
void restart() {
time_start = clock();
}
clock_t elaps() { // 計測開始時間からの秒数を返す
clock_t time_end = clock();
return (time_end - time_start);
}
};
// 疑似乱数列生成 (https://ja.wikipedia.org/wiki/Xorshift)
uint32_t xor32(void) {
static uint32_t y = 2463534242;
y ^= (y << 13); y ^= (y >> 17); y ^= (y << 5);
return y;
}
// 0以上1未満の小数をとる乱数
double rand01() {
return (xor32()+0.5)*(1.0/UINT_MAX);
}
int score(string &s){
int ch[2500] = {0};
int scr = p[sx][sy];
int px = sx, py = sy;
ch[t[sx][sy]] = 1;
REP(i,s.size()){
if(s[i] == 'R'){
py++;
if(py >= 50) return 0;
if(ch[t[px][py]]) return 0;
}else if(s[i] == 'L'){
py--;
if(py < 0) return 0;
if(ch[t[px][py]]) return 0;
}else if(s[i] == 'D'){
px++;
if(px >= 50) return 0;
if(ch[t[px][py]]) return 0;
}else if(s[i] == 'U'){
px--;
if(px < 0) return 0;
if(ch[t[px][py]]) return 0;
}
ch[t[px][py]] = 1;
scr += p[px][py];
}
return scr;
}
string solve(){
string ans;
Timer tmr;
const double TL = 1.9;
double time = 0.0;
// 初期解の生成
while(time < TL){
time = (double)tmr.elaps() / CLOCKS_PER_SEC;
string tans;
tans += dist[xor32()%4];
if(score(tans) != 0){
ans = tans;
break;
}
}
while(time < TL){
time = (double)tmr.elaps() / CLOCKS_PER_SEC;
int id = xor32()%ans.size();
string tans = ans;
int tscr = bstscr;
id = (int)tans.size()-1;
if(id+1 == tans.size()){
tans += dist[xor32()%4];
if(score(tans) == 0) continue;
}else{
}
ans = tans;
}
return ans;
}
int main(){
// 入力
scanf("%d%d", &sx, &sy);
REP(j,50) REP(i,50) scanf("%d", &t[j][i]);
REP(j,50) REP(i,50) scanf("%d", &p[j][i]);
// 求解
string sol = solve();
// 出力
cout << sol << "\n";
// score
//printf("score: %d\n",score(sol));
return 0;
} | #include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <climits>
#include <cassert>
#include <fstream>
#define rep(i, n) for(int i = 0; i < n; i++)
#define per(i, n) for(int i = n - 1; i >= 0; i--)
using ll = long long;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define mod 1000000007
using namespace std;
template<class T, class U>
T &chmax(T &a, const U &b){ if(a < b) a = b; return a; }
template<class T, class U>
T &chmin(T &a, const U &b){ if(a > b) a = b; return a; }
#define y first
#define x second
constexpr bool istest = false;
constexpr int n = 50;
ifstream file;
ofstream out;
void input_setup(){
if(istest){
cout << "write the in file number\n";
string s;
cin >> s;
file.open("C:/Users/souta/downloads/ahc/tools/in/" + s + ".txt");
if(file.fail()){
cout << "the file was not found\n";
return;
}
cin.rdbuf(file.rdbuf());
}
}
//答えるときのやつ
string ans = "";
void output(){
if(istest){
out.open("C:/users/souta/downloads/ahc/tools/out.txt");
if(out.fail()){
cout << "the file was not found\n";
return;
}
cout.rdbuf(out.rdbuf());
}
cout << ans << "\n";
}
pii st_pos;
vvi tiles(n, vi(n)), point(n, vi(n));
void inputs(){
//start position
cin >> st_pos.y >> st_pos.x;
//tiles
rep(i, n) rep(j, n) cin >> tiles[i][j];
//points
rep(i, n) rep(j, n) cin >> point[i][j];
}
//過去に同じ番号のタイルを通ったことがあるのかを確認する
bool checkVisited(const int &Y, const int &X, const vector<pii> &logs){
int col = tiles[Y][X];
for(auto a : logs){
if(col == tiles[a.y][a.x]) return true;
}
return false;
}
//とりあえずBFSで探索してみる
int dy[] = {-1,1,0,0};
int dx[] = {0,0,-1,1};
char dir[] = {'U', 'D', 'L', 'R'};
void bfs(){
priority_queue<pair<pii, int>> que;
vvi checked(n, vi(n, -1));
checked[st_pos.y][st_pos.x] = point[st_pos.y][st_pos.x];
vector<vector<vector<pii>>> logs(n, vector<vector<pii>>(n));
logs[st_pos.y][st_pos.x].push_back(make_pair(st_pos.y, st_pos.x));
pii bestpos = st_pos;
int mx = point[st_pos.y][st_pos.x];
rep(loop, 10){
vector<pii> temp = logs[bestpos.y][bestpos.x];
logs = vector<vector<vector<pii>>>(n, vector<vector<pii>>(n));
checked = vvi(n, vi(n, -1));
logs[bestpos.y][bestpos.x] = temp;
checked[bestpos.y][bestpos.x] = mx;
que.push(make_pair(bestpos, mx));
while(!que.empty()){
pii pos; int score;
tie(pos, score) = que.top();
que.pop();
if(checked[pos.y][pos.x] > score) continue;
rep(i, 4){
int Y = pos.y + dy[i];
int X = pos.x + dx[i];
if(Y >= n || X >= n || Y < 0 || X < 0) continue;
if(checkVisited(Y, X, logs[pos.y][pos.x])) continue;
int v = score + point[Y][X];
if(checked[Y][X] == -1 || checked[Y][X] < v){
que.push(make_pair(make_pair(Y, X), v));
checked[Y][X] = v;
logs[Y][X] = logs[pos.y][pos.x];
logs[Y][X].push_back(make_pair(Y, X));
}
}
}
mx = 0;
bestpos = st_pos;
rep(i, n) rep(j, n){
if(mx < checked[i][j]){
bestpos = make_pair(i, j);
mx = checked[i][j];
}
}
}
vector<pii> track = logs[bestpos.y][bestpos.x];
pii last = st_pos;
for(auto a : track){
rep(i, 4){
if(last.y + dy[i] == a.y && last.x + dx[i] == a.x){
ans += dir[i];
break;
}
}
last = a;
}
}
int main(){
input_setup();
inputs();
bfs();
output();
} |
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << '(' << p.first << ',' << p.second << ')';
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << '{';
for(int i = 0; i < (int)v.size(); i++) {
if(i) { os << ','; }
os << v[i];
}
os << '}';
return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
cerr << " " << x;
debugg(args...);
}
#define debug(...) \
cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 4020000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
if(a>b){
a = b; return true;
}
else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
if(a<b){
a = b; return true;
}
else return false;
}
template<typename T> inline void print(T &a){
int sz = a.size();
for(auto itr = a.begin(); itr != a.end(); itr++){
cout << *itr;
sz--;
if(sz) cout << " ";
}
cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;
int main(){
string s; cin >> s;
int ans = 0;
string t = "ZONe";
rep(i,9){
if(s.substr(i,4) == t) ans++;
}
cout << ans << endl;
} | #include <iostream>
#include <string>
using namespace std;
int main(){
string s; cin >> s;
int count = 0;
for(int i = 0; i+3 < s.size(); ++i){
if(s[i] == 'Z' && s[i+1] == 'O' && s[i+2] == 'N' && s[i+3] == 'e'){
count++;
}
}
cout << count << endl;
}
|
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
ll qp(ll a, ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a, ll b, ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a, int b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
int main(){
int A, B;
cin >> A >> B;
vector<int> EA(A,0), EB(B,0);
rep(i,min(A,B)) {
EA[i] = EB[i] = i+1;
}
if(A > B) {
int idx = 0;
rep(i,A-B) {
EA[B+i] = EA[B+i-1]+1;
rep(j,EA[B+i]) {
++EB[(B-1-(idx++))%B];
idx %= B;
}
}
} else if(A < B) {
int idx = 0;
rep(i,B-A) {
EB[A+i] = EB[A+i-1]+1;
rep(j,EB[A+i]) {
++EA[(A-1-(idx++))%A];
idx %= A;
}
}
}
rep(i,A+B) {
cout << (i < A ? EA[i] : -EB[i-A]) << (i == A+B-1 ? "\n" : " ");
}
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
#include <cstdio> // popen, pclose, fgets
#include <cstdlib>
using namespace std;
#define rep0(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using ll = long long; //long longをllだけにした
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll =vector<vvll>;
const double PI=3.14159265358979323846;
//小数点以下を指定したい時 →→→→ cout << fixed << setprecision();
//int→string string str = to_string(num);
//string→int int num = atoi(numStr.c_str());
int main() {
int a,b;cin>>a>>b;
int ans=0;
if(a+b>=15 && b>=8){
ans=1;
}
else if(a+b>=10&&b>=3){
ans=2;
}
else if(a+b>=3){
ans=3;
}
else{
ans=4;
}
cout<<ans<<endl;
} |
#include<iostream>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int get(int a,int b)
{
if(b<0) return 0;
return 1LL*(b-a+1)*(a+b)/2%mod;
}
int main()
{
int t;scanf("%d",&t);
while(t--){
ll n,a,b;cin>>n>>a>>b;
if(a>b)swap(a,b);
ll ans=2LL*((n-a+1)*(n-b+1)%mod*get(1,n-a-b+1)%mod)%mod;
//cout<<ans<<" ";
ll temp=0,t1=0;
// for(int i=1;i<=n-a+1;i++){
// ll t2=t1;
// for(int j=max(1LL,i-b+1);j<=min(n-b+1,i+a-1);j++)
// t1++;
// cout<<t1-t2<<endl;
// }
temp=(temp+get(a,min(b,n-a-b+2)+a-1))%mod;
//cout<<temp<<" ";
if(b+1<=n-a-b+2)
temp=(temp+(a+b-1)*(n-a-b-b+2)%mod)%mod;
//cout<<temp<<" ";
if(b>=n-a-b+3)
temp=(temp+(n-b+1)*(2*b+a-n-2)%mod)%mod;
//cout<<temp<<" ";
temp=(temp+get(a,n-max(b+1,n-a-b+3)+1)%mod)%mod;
//cout<<temp<<" "<<t1<<" ";
temp=2LL*temp*get(1,n-a-b+1)%mod;
ans=(ans+temp+mod)%mod;
cout<<ans<<endl;
}
} | //#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
if (ci - owa > 0) {
memcpy(cn, owa, CL);
ci -= CM;
fread(cn + CL, 1, CM, stdin);
}
ll tmp = *(ll*)ci;
if ((tmp & ma0) ^ ma0) {
int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
tmp = tmp << dig & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += (72 - dig >> 3);
}
else {
tmp = tmp & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += 8;
if ((ct = *ci++) >= '0') {
tmp = tmp * 10 + ct - '0';
if (*ci++ == '0') {
tmp = tmp * 10;
ci++;
}
}
}
return tmp;
}
const int MAX = 100000;
class shuturyoku_unko {
public:
char C[MAX * 5];
constexpr shuturyoku_unko() : C() {
rep(i, MAX) {
int X = i;
rep(j, 5) {
C[i * 5 + 4 - j] = '0' + X % 10;
X /= 10;
}
}
}
};
constexpr shuturyoku_unko f;
const int dm = 1 << 17;
char dn[dm], * di = dn, * owad = dn + dm - 20;
void putint(ll A) {
if (owad < di) {
fwrite(dn, 1, di - dn, stdout);
di = dn;
}
int dig = 1;
if (A >= 100000) {
if (A >= 1000000000) dig = 5;
else if (A >= 100000000) dig = 4;
else if (A >= 10000000) dig = 3;
else if (A >= 1000000) dig = 2;
memcpy(di + dig, f.C + A % 100000 * 5, 5);
A /= 100000;
memcpy(di, f.C + A * 5 + 5 - dig, dig);
di += 5 + dig;
}
else {
if (A >= 10000) dig = 5;
else if (A >= 1000) dig = 4;
else if (A >= 100) dig = 3;
else if (A >= 10) dig = 2;
memcpy(di, f.C + A * 5 + 5 - dig, dig);
di += dig;
}
*di++ = '\n';
}
const int mod = 1e9 + 7;
int main() {
//cin.tie(0);
//ios::sync_with_stdio(false);
int T = getint();
rep(t, T) {
ll N = getint(), A = getint(), B = getint();
ll a = min(A, N - B + 1);
ll b = min(A + B - 1, N - B + 1);
ll are = (a + b) * (b - a + 1) + b * (N - A + 1 - (b - a + 1) * 2);
ll atti = (N - A + 1) * (N - B + 1);
ll kotae = (atti + are) % mod * ((atti - are) % mod) % mod;
putint(kotae);
}
fwrite(dn, 1, di - dn, stdout);
Would you please return 0;
} |
#include<bits/stdc++.h>
#define lli long long int
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
lli n,x,i;
cin>>n>>x;
string s;
cin>>s;
for(i=0;i<s.size();i++)
{
if(s[i]=='x' && x>0)
x=x-1;
if(s[i]=='o')
x=x+1;
}
cout<<x<<"\n";
} | #include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
void chmax(LL&l,LL r){ if(l<r) l=r; }
int N;
LL X;
LL A[100];
LL dp[101][100];
void solvedp(int K){
rep(n,K+1) rep(k,K) dp[n][k]=-1000000000000;
dp[0][0]=0;
rep(i,N){
int dk=A[i]%K;
for(int n=K-1; n>=0; n--) rep(k,K){
int to_k=k+dk; if(to_k>=K) to_k-=K;
chmax(dp[n+1][to_k],dp[n][k]+A[i]);
}
}
}
int main(){
cin>>N>>X;
rep(i,N) cin>>A[i];
LL ans=X;
for(int K=1; K<=N; K++){
solvedp(K);
if(dp[K][X%K]<0) continue;
ans=min(ans,(X-dp[K][X%K])/K);
}
cout<<ans<<endl;
return 0;
} |
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}
struct Edge{
int to;
ll T;
ll K;
Edge(){}
Edge(int to,ll T,ll K):to(to),T(T),K(K){}
};
const ll INF=1e18;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N,M,X,Y;
cin>>N>>M>>X>>Y;
X--;Y--;
vector<vector<Edge>> g(N);
rep(i,M){
int a,b,t,k;
cin>>a>>b>>t>>k;
a--;b--;
g[a].push_back(Edge{b,t,k});
g[b].push_back(Edge{a,t,k});
}
vector<ll> dist(N,INF);
dist[X]=0;
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> PQ;
PQ.push(mkp(0,X));
while(!PQ.empty()){
auto f=PQ.top();
PQ.pop();
int now=f.second;
ll cost=f.first;
if(dist[now]<cost) continue;
for(auto &e:g[now]){
ll neco=cost+(e.K-cost%e.K)%e.K+e.T;
if(dist[e.to]>neco){
dist[e.to]=neco;
PQ.push(mkp(neco,e.to));
}
}
}
if(dist[Y]==INF) cout<<-1<<endl;
else cout<<dist[Y]<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int a, b, c, d;
int main(){
cin>>a>>b>>c>>d;
//max x-y
cout<<max(a,b) - min(c,d)<<"\n";
} |
#include <bits/stdc++.h>
//#include "atcoder/all"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
//using namespace atcoder;
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> P;
constexpr ll inf=1ll<<61;
constexpr ll mod=998244353;
int a[1050000];
int n=1;
int calc(int A,int B,int k,int l,int r){
if(r<=A||B<=l)return 0;
if(A<=l&&r<=B)return a[k];
int vl=calc(A,B,k*2+1,l,(l+r)/2),vr=calc(A,B,k*2+2,(l+r)/2,r);
return vl^vr;
}
int get(int l,int r){
return calc(l,r,0,0,n);
}
int main(){
int N,q;cin>>N>>q;
while(n<N)n*=2;
rep(i,N)cin>>a[n-1+i];
for(int i=n-2;i>=0;i--)a[i]=a[2*i+1]^a[2*i+2];
rep(i,q){
int t;cin>>t;
int x,y;cin>>x>>y;
x--;
if(t==1){
x+=n-1;
a[x]^=y;
while(x){
x=(x-1)/2;
a[x]=a[x*2+1]^a[x*2+2];
}
}
else{
cout<<get(x,y)<<endl;
}
}
} | //Code by Mukul Totla
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
void sublime(){
#ifndef ONLINE_JUDGE
freopen ("input.txt", "r", stdin);
freopen ("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
}
int main()
{
sublime();
ll n,i,j;
ll q;
cin>>n>>q;
ll arr[n];
for(i=0; i<n; i++)
cin>>arr[i];
ll rootn=sqrt(n);
vector<ll>v;
ll val=0;
ll cnt=0;
for(i=0; i<n; i++)
{
val^=arr[i];
cnt++;
if(cnt==rootn)
{
cnt=0;
v.push_back(val);
val=0;
}
}
if(cnt!=0)
v.push_back(val);
while(q--)
{
ll t,x,y;
cin>>t>>x>>y;
x--,y--;
if(t==1)
{
y++;
ll block=x/rootn;
v[block]^=y;
arr[x]^=y;
}
else
{
ll b1=x/rootn, b2=y/rootn;
ll ans=0;
if((b2-b1)>2)
{
for(i=b1+1; i<=b2-1; i++)
ans^=v[i];
// cout<<ans<<endl;
for(i=x; i<(b1+1)*rootn; i++)
ans^=arr[i];
for(i=b2*rootn; i<=y; i++)
ans^=arr[i];
cout<<ans<<endl;
}
else
{
for(i=x; i<=y; i++)
ans^=arr[i];
cout<<ans<<endl;
}
}
}
return 0;
} |
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 998244353
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)
#define hmap gp_hash_table<ll, ll>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
ll powa(ll a, ll b, ll c)
{
a%=c;
if(a<0)
a+=c;
ll res = 1;
while(b>0)
{
if(b&1)
res*=a, res%=c;
a*=a, a%=c;
b>>=1;
}
return res;
}
int main()
{
FAST/**/
ll n,m;
cin>>n>>m;
string arr[n];
rep(n)
cin>>arr[i];
map<ll,map<char,ll>> ma;
rep(n)
repi(j,m)
ma[i+j][arr[i][j]]++;
ll ans = 1;
autoit(ma,it)
{
map<char,ll> &m = it->ss;
ll cr = m['R'];
ll cb = m['B'];
ll un = m['.'];
//cout<<"on "<<it->ff<<" "<<cr<<" "<<cb<<" "<<un<<'\n';
if(cr>0 && cb>0)
{
cout<<0<<"\n";
return 0;
}
if(cr == 0 && cb == 0)
{
//cout<<"at "<<it->ff<<"\n";
ans *= 2;
ans%=mod;
continue;
}
}
cout<<ans<<"\n";
return 0;
}
| #include <bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n,m;
char a[510][510];
int cntr,cntb;
signed main(){
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>(a[i]+1);
for(int i=1;i<=m;i++){
bool flgr=0,flgb=0;
for(int x=1,y=i;x<=n&&y>=1;x++,y--){
if(a[x][y]=='R')flgr=1;
if(a[x][y]=='B')flgb=1;
}
if(flgr==1&&flgb==1)return puts("0"),0;
if(flgr==1)cntr++;
if(flgb==1)cntb++;
}
for(int i=2;i<=n;i++){
bool flgr=0,flgb=0;
for(int x=i,y=m;x<=n&&y>=1;x++,y--){
if(a[x][y]=='R')flgr=1;
if(a[x][y]=='B')flgb=1;
}
if(flgr==1&&flgb==1)return puts("0"),0;
if(flgr==1)cntr++;
if(flgb==1)cntb++;
}
int t=n+m-1LL-cntr-cntb;
// cout<<t<<endl;
int ans=1LL;
for(int i=1;i<=t;i++)ans=ans*2LL%998244353LL;
cout<<ans<<endl;
return 0;
}
/*
rrb
rbr
brr
r.r
.br
...
#####
#####
#####
*/
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
using C = complex<double>;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a.at(i);
vector<ll> b(410);
rep(i, n) b.at(a.at(i) + 200)++;
ll ans = 0;
for (ll i = 1; i < b.size(); i++) {
for (ll j=0;j<i;j++){
ans += b.at(i) * b.at(j) * (i - j) * (i - j);
}
}
cout << ans << endl;
} | #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
ll r = 0, s = 0;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
s += a;
r += a * a;
}
r *= n;
r -= s * s;
cout << r << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pl = pair<ll, ll>;
using Vs = vector<string>;
const ll mod = 1000000007;
const ll inf = 1000000000000;//10の12乗
int main() {
ll n,w;
cin >> n >> w;
Vl v(200010);
rep(i,n){
ll x,y,z;
cin >> x >> y >> z;
v[x]+=z;v[y]-=z;
}
bool b=1;
rep(i,200005){
v[i+1]+=v[i];
if(v[i+1]>w||v[i]>w)b=0;
//if(i<=100)cout << v[i+1] << endl;
}
if(b) cout << "Yes" << endl;
else cout << "No" << endl;
}
|
//================code===================//
//#define TLE
#ifdef TLE
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <ctime>
#define ci(t) cin>>t
#define co(t) cout<<t
#define LL long long
#define ld long double
#define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i)
#define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i)
#define setp pair<pair<int,int>,int>
#define setl pair<LL,LL>
#define micro 0.000001
using namespace std;
LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; }
LL lcm(LL a, LL b) { return (a * b) / gcd(a, b); }
#ifdef OHSOLUTION
#define ce(t) cerr<<t
#define AT cerr << "\n=================ANS=================\n"
#define AE cerr << "\n=====================================\n"
#else
#define AT
#define AE
#define ce(t)
#define __popcnt __builtin_popcountll
#endif
pair <int, int> vu[9] = { {0,1},{1,0},{0,-1} ,{-1,0},{0,0},{1,0}, {-1,1} , {1,-1},{-1,-1} }; //RDLU EWSN
template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; }
template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; }
struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl a, setl b) { return a.second < b.second; } };
struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl a, setl b) { return a.second > b.second; } };
const int max_v = 5e2 + 7;
const int INF = 1e9 + 7;
const LL LNF = (LL)5e18 + 7ll;
const LL mod = 1e9 + 7;
int arr[max_v][max_v];
int col[max_v];
int ans[max_v];
int main()
{
#ifdef OHSOLUTION
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n; ci(n);
fa(i, 0, n) fa(j, 0, n)ci(arr[i][j]);
fa(j, 0, n)
{
col[j] = arr[0][j];
fa(i, 1, n) ckmin(col[j], arr[i][j]);
}
int row = arr[0][0];
fa(i, 0, n) ckmin(row, arr[0][i]);
bool ck = true;
fa(i, 0, n)
{
if (col[i] >= arr[0][i] - row) col[i] = arr[0][i] - row;
else ck = false;
}
ans[0] = row;
fa(i, 1, n)
{
int row = arr[i][0];
fa(j, 1, n) ckmin(row, arr[i][j]);
ans[i] = row;
fa(j, 0, n)
{
if (col[j] != arr[i][j] - row) ck = false;
}
}
if (ck)
{
co("Yes\n");
fa(i, 0, n) co(ans[i] << " ");
co("\n");
fa(i, 0, n) co(col[i] << " ");
}
else co("No\n");
return 0;
} |
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int n, m, adj[20];
int dp[262144];
void solve(int, int, int, int);
int get(int x) {
if (!x) return 0;
if (dp[x] != 2e9) return dp[x];
solve(0, x, 0, x);
return dp[x];
}
void solve(int p, int r, int s, int d) {
if (!r && !s) {
dp[d] = min(dp[d], 1 + get(d & ~p));
return;
}
for (int i = n - 1; i >= 0; i--) if (r & 1 << i) {
solve(p | 1 << i, r & adj[i], s & adj[i], d);
r &= ~(1 << i);
s |= 1 << i;
}
}
int main() {
scanf("%d%d", &n, &m);
fill(dp, dp + 262144, 2e9);
while (m--) {
int a, b;
scanf("%d%d", &a, &b);
a--, b--;
adj[a] |= 1 << b;
adj[b] |= 1 << a;
}
solve(0, (1 << n) - 1, 0, (1 << n) - 1);
printf("%d", dp[(1 << n) - 1]);
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using vi = vector<int>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr long long INF = 1e9+10;
constexpr long long LINF = 1e18+10;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }
struct edge{
int from;
int to;
int c;
};
int main(){
int n, m; cin >> n >> m;
vector<vector<edge>> G(n+10);
rep(i, m){
int u, v, c; cin >> u >> v >> c;
edge e1{u,v,c};
edge e2{v,u,c};
G[u].push_back(e1);
G[v].push_back(e2);
}
//始点=頂点0としてBFS
vector<int> ans(n+10, INF);//頂点に振る番号
queue<pii> que; //頂点番号,ラベル
que.push({1, INF});//-1
while(!que.empty()){
auto p = que.front(); que.pop();
int v = p.first, c = p.second; //一致なら正、不一致なら負
//cout << "v:" << v << " c:" << c << ln;
if(ans[v]!=INF)continue;
if(c==INF)ans[v] = 1;
else{
if(c>0){
ans[v] = (c == 1 ? 2 : 1);
}else{
c = -c;
ans[v] = c;
}
}
for(auto e: G[v]){
if(ans[e.to]!=INF)continue;
int nc = e.c;
if(ans[v]!=nc) nc = -e.c;
que.push({e.to, nc});
}
}
for(int i=1; i<=n; i++){
cout << ans[i] << ln;
}
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>
#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;
// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << '\n'; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin, n;
auto a = make_v(2, n / 2, 0LL);
auto b = make_v(2, n / 2, 0LL);
ll score = 0;
REP(i, 0, n) {
cin, a[i % 2][i / 2];
}
REP(i, 0, n) {
cin, b[i % 2][i / 2];
score += b[i % 2][i / 2];
}
auto idx = make_v(2, n / 2, 0);
REP(t, 0, 2) {
iota(idx[t].begin(), idx[t].end(), 0);
sort(idx[t].begin(), idx[t].end(), [&](int i, int j) {
return a[t][i] - b[t][i] > a[t][j] - b[t][j];
});
}
ll ans = score;
REP(i, 0, n / 2 + 1) {
dump(ans, score);
chmax(ans, score);
if (i < n / 2) {
REP(t, 0, 2) {
score -= b[t][idx[t][i]];
score += a[t][idx[t][i]];
}
}
}
print(ans);
return 0;
}
| #include <stdio.h>
#include <bits/stdc++.h>
int main()
{
int i, N, A[2][100001];
scanf("%d", &N);
for (i = 1; i <= N; i++) scanf("%d", &(A[0][i]));
for (i = 1; i <= N; i++) scanf("%d", &(A[1][i]));
int j, k, l, r;
const long long inf = -(1LL << 60);
long long dp[2][100001];
for (i = 0; i <= N; i++) {
dp[0][i] = inf;
dp[1][i] = inf;
}
dp[0][1] = A[0][1];
dp[1][1] = A[1][1];
for (i = 2; i <= N; i++) {
if (i % 2 == 0) {
dp[0][0] = dp[0][1] + A[0][i];
if (dp[0][0] < dp[1][1] + A[1][i]) dp[0][0] = dp[1][1] + A[1][i];
} else dp[1][0] = dp[0][0];
k = (i < N - i)? i: N - i;
l = i % 2;
r = 1 - i % 2;
for (j = 2 - l; j <= k; j += 2) {
dp[0][j] = dp[0][j-1] + A[r][i];
if (dp[0][j] < dp[0][j+1] + A[l][i]) dp[0][j] = dp[0][j+1] + A[l][i];
dp[1][j] = dp[1][j-1] + A[l][i];
if (dp[1][j] < dp[1][j+1] + A[r][i]) dp[1][j] = dp[1][j+1] + A[r][i];
}
}
printf("%lld\n", dp[0][0]);
fflush(stdout);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}
int main2() {
ll S = nextLong();
ll P = nextLong();
for (ll a = 1; a * a <= P; a++) {
if (P % a == 0) {
ll b = P / a;
if (a + b == S) {
return 1;
}
}
}
return 0;
}
int main() {
bool ans = main2();
cout << (ans ? "Yes":"No") << endl;
return 0;
} | #include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
int a,b;
cin >> a >> b;
int c;
c=a+b;
if(15<=c){
if(8<=b){
cout << "1" << endl;
}
else if(3<=b){
cout << "2" << endl;
}
else{
cout << "3" << endl;
}
}
else if(10<=c){
if(3<=b){
cout << "2" << endl;
}
else{
cout << "3" << endl;
}
}
else if(3<=c){
cout << "3" << endl;
}
else{
cout << "4" << endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 3e5;
ll n, a[MAXN];
ll solve() {
sort(a, a+n);
vector<ll> grps;
ll last = 0, ans = 0;
for (int i = 0; i < n; ++i) {
if (a[i] != a[last]) {
grps.push_back(i-last);
last = i;
}
}
grps.push_back(n-last);
ll tot = accumulate(grps.begin(), grps.end(), 0LL);
for (ll i: grps) {
ans += i * (tot-i);
tot -= i;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> n;
for (int i = 0; i < n; ++i)
cin >> a[i];
cout << solve() << '\n';
return 0;
} | #include<bits/stdc++.h>
#define ll long long int
#define rep(i,a,b) for (int i = a; i <b; i++)
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{ll n;cin>>n;ll a[n],b[n];
ll sum=0,i;
for(ll i=0;i<n;i++)
{
cin>>a[i];
}
for( i=0;i<n;i++)
{
cin>>b[i];
}
for(i=0;i<n;i++)
{
sum+=a[i]*b[i];
}
cout<<((sum==0)?"Yes":"No");
}
|
#include<map>
#include<ctime>
#include<cstdio>
#include<cctype>
#define ll long long
using namespace std;
ll read() {
char c;
ll x=0,f=1;
while(!isdigit(c=getchar()))
f-=2*(c=='-');
while (isdigit(c)){
x=x*10+(c-48)*f;
c=getchar();
}
return x;
}
ll x,y;
map<ll,ll>f;
ll min(ll x,ll y){
return x<y?x:y;
}
ll dp(ll y){
if(f.count(y))
return f[y];
if(y<=x)
return f[y]=x-y;
ll res=y-x;
if(y&1){
res=min(res,dp(y>>1)+2);
res=min(res,dp((y+1)>>1)+2);
}
else
res=min(res,dp(y>>1)+1);
return f[y]=res;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("F.in","r",stdin);
freopen("F.out","w",stdout);
#endif
clock_t t1=clock();
//--------
x=read();
y=read();
dp(y);
printf("%lld",f[y]);
//--------
clock_t t2=clock();
fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC);
return 0;
} | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef vector<vector<bool> > vvb;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rrep(i, n) for (int i = 1; i <= int(n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = int(n)-1; i >= 0; --i)
#define MES(a) MES2 a
#define MES2(a0,a1,a2,a3,a4,x,...) x
#define mes_1(x1) cout<<x1<<endl
#define mes_2(x1,x2) cout<<x1<<" "<<x2<<endl
#define mes_3(x1,x2,x3) cout<<x1<<" "<<x2<<" "<<x3<<endl
#define mes_4(x1,x2,x3,x4) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<endl
#define mes_5(x1,x2,x3,x4,x5) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<" "<<x5<<endl
#define mes(...) CHOOSE((__VA_ARGS__,mes_5,mes_4,mes_3,mes_2,mes_1,~))(__VA_ARGS__)
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#define ynmes(a) (a) ? mes("Yes") : mes("No")
#define YNmes(a) (a) ? mes("YES") : mes("NO")
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
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; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
ll modpow(ll x, ll y) {
if(y == 1) {
return x;
}
ll ans;
if(y % 2 == 1) {
ll r = modpow(x,(y-1)/2);
ans = r * r % MOD;
ans = ans * x % MOD;
}
else {
ll r = modpow(x,y/2);
ans = r * r % MOD;
}
return ans;
}
ll modncr(ll N, ll K) {
ll res = 1;
ll p=1;
for (ll n = 0; n < K; ++n) {
res = (res*(N - n))%MOD;
p = (p*(n + 1))%MOD;
}
return (res*modpow(p,MOD-2))%MOD;
}
ll x, y;
map <ll, ll> memo;
ll rec(ll y) {
if (y == 1) return abs(x-y);
if (memo.find(y) != memo.end()) return memo[y];
if (y%2 == 0) {
memo[y] = min(rec(y/2)+1, abs(y-x));
} else {
memo[y] = min({rec(y+1)+1, rec(y-1)+1, abs(y-x)});
}
return memo[y];
}
signed main() {
ll y;
cin >> x >> y;
mes(rec(y));
}
|
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <set>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
const ll INF = 1LL << 60;
const double pi = acos(-1);
ll mod = 1000000007;
struct Edge {
int to;
long long w;
Edge(int to, long long w) : to(to), w(w) {}
};
struct dsu {
vector<int> d;
dsu(int n = 0): d(n,-1) {}
int findRoot(int x) {
if(d[x] < 0) return x;
return d[x] = findRoot(d[x]);
}
bool unite(int x,int y) {
x = findRoot(x); y = findRoot(y);
if(x == y) return false;
if(d[x] > d[y]) swap(x,y);
d[x] += d[y];
d[y] = x;
return true;
}
bool same(int x,int y) { return findRoot(x) == findRoot(y);}
int size(int x) {return -d[findRoot(x)];}
};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
return modpow(a, mod - 2, mod);
}
template <typename T>
T my_lower_bound(vector<T> a, T lb, T ub, T k) {
while(ub - lb > 1) {
T mid = (lb + ub) / 2;
if(a[mid] >= k) {
ub = mid;
}else{
lb = mid;
}
}
return ub;
}
set<int> group;
vector<vector<int>> g;
vector<int> c, ans;
vector<bool> ch;
void dfs(int i) {
for(auto t : g[i]) {
if(ch[t]) continue;
auto x = group.find(c[t]);
if(x == group.end()) {
group.insert(c[t]);
ans.push_back(t);
ch[t] = true;
dfs(t);
group.erase(c[t]);
ch[t] = false;
}else{
ch[t] = true;
dfs(t);
ch[t] = false;
}
}
}
int main() {
int n; cin >> n;
c.resize(n + 1);
ch.resize(n + 1, false);
rep1(i,n) cin >> c[i];
g.assign(n + 1, vector<int>());
rep1(i,n - 1) {
int a, b; cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
group.insert(c[1]);
ans.push_back(1);
ch[1] = true;
dfs(1);
sort(ans.begin(),ans.end());
for(auto t : ans) {
cout << t << endl;
}
return 0;
} |
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
vector<int> good;
map<int,vector<int>> adj;
map<int,int> color;
map<int,int> mark;
void dfs(int node,vector<bool> &visited){
visited[node]=1;
if(mark.count(color[node])==0){
mark[color[node]]=1;
}else mark[color[node]]++;
for(int i:adj[node]){
if(!visited[i]){
dfs(i,visited);
}
}
if(mark[color[node]]==1){
good.push_back(node);
}
mark[color[node]]--;
}
int main(){
int vertex;
cin>>vertex;
int x,y;
for(int i=0;i<vertex;i++){
cin>>x;
color[i+1]=x;
}
for(int i=0;i<vertex-1;i++){
cin>>x>>y;
adj[x].push_back(y);
adj[y].push_back(x);
}
vector<bool> visited(vertex+1);
dfs(1,visited);
sort(good.begin(),good.end());
for(int i:good){
cout<<i<<"\n";
}
return 0;
} |
#include<bits/stdc++.h>
#define ll __int128
using namespace std;
const int N = 55;
int n;
int primes[N] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}, book[N];
ll ans = 1e30;
ll gcd(ll a, ll b){ return b ? gcd(b, a % b) : a;}
void print(__int128 x) {
if(!x)
{
puts("0");
return ;
}
string ret="";
while(x)
{
ret+=x%10+'0';
x/=10;
}
reverse(ret.begin(),ret.end());
cout<<ret<<endl;
}
bool check(ll x){
for(int i = 1; i <= n; ++ i)
if(gcd(x, book[i]) == 1) return false;
return true;
}
int main(){
cin >> n;
for(int i = 1; i <= n; ++ i) cin >> book[i];
for(int i = 1; i < (1 << 15); ++ i){
ll tmp = 1;
for(int j = 0; j < 15; ++ j){
if((i >> j) & 1) tmp *= primes[j];
}
//printf("ans = %d\n", ans);
if(check(tmp)){
ans = min(ans, tmp);
}
}
print(ans);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
string S;
char mem[1000020];
const int base = 500010;
signed main()
{
cin >> S;
// int l = base, r = base + 1;
// bool flip = false;
// for(auto e : S)
// {
// if(e == 'R')flip = !flip;
// else
// {
// if(flip)mem[l--] = e;
// else mem[r++] = e;
// }
// }
// string s;
// if(flip)for(int i = r - 1; i > l; i--)s.push_back(mem[i]);
// else for(int i = l + 1; i < r; i++)s.push_back(mem[i]);
// cout << s << endl;
deque<char> s;
bool flip = false;
for(auto e : S)
{
if(e == 'R')flip = !flip;
else
{
if(flip)s.push_front(e);
else s.push_back(e);
}
}
if(flip)reverse(s.begin(), s.end());
string ans;
for(int i = 0; i < s.size(); i++)
{
if(ans.size() == 0 || ans.back() != s[i])ans.push_back(s[i]);
else ans.pop_back();
}
cout << ans << endl;
return 0;
} |
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#define int long long
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define a first
#define b second
#define fi first
#define sc second
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
#define si(x) int(x.size())
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}
template<class t> using vc=vector<t>;
template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
return os<<"{"<<p.fi<<","<<p.sc<<"}";
}
template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
os<<"{";
for(auto e:v)os<<e<<",";
return os<<"}";
}
template<class T>
void g(T &a){
cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 998244353;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
void add(T&a,T b){
a+=b;
if(a >= mod) a-=mod;
}
ll modpow(ll x,ll n){
ll res=1;
while(n>0){
if(n&1) res=res*x%mod;
x=x*x%mod;
n>>=1;
}
return res;
}
int par[2205],ran[2205];
void init(){ for(int i=0;i<2205;i++) par[i] = i; }
int find(int x){ if(x == par[x]) return x; else return par[x] = find(par[x]); }
void unite(int x,int y){
x = find(x); y = find(y); if(x==y) return;
if(ran[x] < ran[y]) par[x] = y;
else{
par[y] = x;
if(ran[x] == ran[y]) ran[x]++;
}
}
bool same(int x,int y){ return find(x)==find(y); }
int n, m;
string str[1005];
void solve(){
init();
cin >> n >> m;
rep(i, n) cin >> str[i];
unite(0, n); unite(0, n+m-1);
unite(n-1, n); unite(n-1, n+m-1);
rep(i, n){
rep(j, m){
if(str[i][j] == '#'){
unite(i, j + n);
}
}
}
set<int>x, y;
rep(i, n) x.insert(find(i));
rep(i, m) y.insert(find(n + i));
cout << min(si(x), si(y)) - 1 << endl;
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(20);
int t; t = 1; //cin >> t;
while(t--) solve();
}
| #include <stdio.h>
#include <set>
#define MN 1000
int h,w,fa[MN*2+5];
char s[MN+5][MN+5];
int r(int x){
return x;
}
int c(int x){
return x+h;
}
int gf(int u){
return fa[u]==u?u:fa[u]=gf(fa[u]);
}
void unite(int u,int v){
u = gf(u);
v = gf(v);
if(u==v) return;
fa[v] = u;
}
int main(){
scanf("%d%d",&h,&w);
for(int i=1;i<=h+w;i++)
fa[i] = i;
for(int i=1;i<=h;i++)
scanf("%s",&s[i][1]);
unite(r(1),r(h));
unite(c(1),c(w));
unite(r(1),c(1));
for(int i=1;i<=h;i++)
for(int j=1;j<=w;j++)
if(s[i][j]=='#')
unite(r(i),c(j));
int ans = 0x3fffffff;
{
std::set<int> s;
for(int i=1;i<=h;i++)
s.insert(gf(r(i)));
ans = std::min(ans,(int)s.size()-1);
}
{
std::set<int> s;
for(int i=1;i<=w;i++)
s.insert(gf(c(i)));
ans = std::min(ans,(int)s.size()-1);
}
printf("%d\n",ans);
} |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}
int main()
{
double sx,sy,gx,gy;
cin >> sx >> sy >> gx >> gy;
double ans = (sy*gx + sx*gy)/(sy+gy);
cout << fixed << setprecision(10);
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
int main()
{
long long a,b,n,m,x1,x2,x3,x4,k,k1;
cin>>n>>m>>a>>b;
x1=n-a;
x2=n-b;
x3=m-a;
x4=m-b;
k=max(x1,x2);
k1=max(x3,x4);
cout<<max(k,k1)<<endl;
}
|
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 2000;
vector<vector<int>>G;
bool temp[MAX_N];
void dfs(int v) {
if (temp[v])return;
temp[v] = true;
for (auto vv : G[v])dfs(vv);
}
int main() {
int N, M;
cin >> N >> M;
G.resize(N);
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
G[a - 1].push_back(b - 1);
}
int ans = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++)temp[j] = false;
dfs(i);
for (int j = 0; j < N; j++)if (temp[j])ans++;
}
cout << ans;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5;
int mod=1e9+7;
int gcd(int x,int y)
{
if(y==0)
{
return x;
}
return gcd(y,x%y);
}
int power(int a,int n)
{
int res=1;
while(n)
{
if(n%2)
{
res=(res*a)%mod;
}
n=n/2;
a=(a*a)%mod;
}
return res;
}
vector<vector<int>> adj;
vector<bool> vis;
void dfs(int v)
{
vis[v]=true;
int i,n=adj[v].size();
for(i=0;i<n;i++)
{
if(!vis[adj[v][i]])
{
dfs(adj[v][i]);
}
}
}
void solve()
{
int i,n,m,x,y,cnt=0;
cin>>n>>m;
adj.resize(n+1);
for(i=0;i<m;i++)
{
cin>>x>>y;
adj[x].push_back(y);
}
for(i=1;i<=n;i++)
{
vis.assign(n,false);
dfs(i);
for(int j=1;j<=n;j++)
{
cnt=cnt+vis[j];
}
}
cout<<cnt<<"\n";
}
int32_t main()
{
int t=1;
while(t--)
{
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
vector<int64_t> data(N);
for(int i=0; i<N; i++){
cin >> data.at(i);
}
unordered_map<int64_t, int64_t> freq_altsum;
freq_altsum[0]++;
int64_t altsum= 0;
for(int i=0; i<N; i++){
altsum= (i%2==0) ? data.at(i)+ altsum
: -data.at(i)+ altsum;
freq_altsum[altsum]++;
}
// for(const auto& [val,freq]:freq_altsum){
// cout << val <<": "<< freq << endl;
// }
int64_t ans= 0;
for(const auto& [val,freq]:freq_altsum){
ans+= freq* (freq- 1)/ 2;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#define fs first
#define sc second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define MP make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef FlameDragon
freopen("in.txt", "r", stdin);
#endif
int n;
cin >> n;
vector<int> a(n + n);
vector<pair<int, int>> b(n + n);
for (int i = 0; i < n + n; i++) {
cin >> a[i];
b[i] = {a[i], i};
}
vector<int> c(n + n);
sort(all(b));
for (int i = 0; i < n; i++) {
c[b[i].second] = true;
}
string ans(n + n, '(');
vector<pair<int, char>> st;
for (int i = 0; i < n + n; i++) {
if (!sz(st)) {
st.push_back({c[i], '('});
} else if (st.back().first == c[i]) {
ans[i] = st.back().second;
st.push_back(st.back());
} else {
ans[i] = st.back().second ^ '(' ^ ')';
st.pop_back();
}
}
cout << ans << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i64 i=0; i<n; i++)
#define all(v) v.begin(),v.end()
#define pp pair<int,int>
using Graph=vector<vector<int>>;
using i64=int64_t;
int main() {
int n,m;cin>>n>>m;
rep(i,m) {
string s;
cin>>s;
}
rep(i,20) {
rep(j,20) {
cout << "H";
}
cout << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define rep(i,n) for(ll i=0; i<(n);++i)
#define pb push_back
template<typename T> int max_index(vector<T>& v){auto mi = max_element(v.begin(), v.end()); return distance(v.begin(), mi);}
template<typename T> ll max_value(vector<T>& v){auto mi = max_element(v.begin(),v.end()); return (*mi);}
int main()
{
int n;
cin >> n;
vector<ll> a(n);
vector<ll> b(n);
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++) cin >> b[i];
ll ans = 0;
ll amax = 0;
for(int i = 0; i < n; i++){
amax = max(amax, a[i]);
if(ans < amax*b[i])
ans = amax*b[i];
cout << ans << endl;
}
return 0;
} |
#include <algorithm>
#include <iostream>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cmath>
#include <climits>
#include <queue>
#include <bitset>
using namespace std;
typedef vector<vector<long> > dim2veclo;
typedef vector<vector<int> > dim2vecin;
typedef vector<int> vecin;
typedef vector<long> veclo;
vecin takahashi = vecin(10, 0);
vecin aoki = vecin(10, 0);
vector<double> maisuu;
long tensuuT = 0, tensuuA = 0;
int main() {
cout << fixed << setprecision(15);
int k;
double kakuritu = 0;
cin >> k;
string s, t;
cin >> s >> t;
maisuu = vector<double>(10, k);
for (int i = 0; i < 4; i++) {
int ss = s[i] - '0';
int tt = t[i] - '0';
takahashi[ss]++;
aoki[tt]++;
maisuu[ss]--;
maisuu[tt]--;
}
for (int i = 1; i <= 9; i++) {
tensuuT += (i * pow(10, takahashi[i]));
tensuuA += (i * pow(10, aoki[i]));
}
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
if (i == j) {
if (maisuu[i] <= 1) continue;
}
else {
if (maisuu[i] == 0) continue;
if (maisuu[j] == 0) continue;
}
long T = tensuuT + i * 9 * pow(10, takahashi[i]);
long A = tensuuA + j * 9 * pow(10, aoki[j]);
if (T > A) {
double bunbo = 9 * k - 8;
double bunsi1 = maisuu[i];
double bunsi2;
if (i == j) bunsi2 = maisuu[i] - 1;
else bunsi2 = maisuu[j];
kakuritu += (bunsi1 / bunbo) * (bunsi2 / (bunbo - 1));
}
}
}
cout << kakuritu;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vtll = vector<tll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); }
void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); }
template<typename T,typename U>
ostream& operator<<(ostream& os, const pair<T,U>& p) {
cerr << ' ' << p.x << ',' << p.y; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
for(auto x: v) os << ' ' << x; return os; }
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
for(auto x: v) os << ' ' << x; return os; }
template<typename T,typename U>
ostream& operator<<(ostream& os, const map<T,U>& v) {
for(auto x: v) os << ' ' << x; return os; }
struct d_ {
template<typename T> d_& operator,(const T& x) {
cerr << ' ' << x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define deb(X ...) dbg(#X, "=", X);
#define EPS (1e-10)
#define INF (1LL<<61)
#define YES(x) cout << (x ? "YES" : "NO") << endl;
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
ll score(map<ll,ll> m) {
ll ret = 0;
for(auto i: m) ret += i.x*pow(10,i.y);
return ret;
}
int main(void) {
ios_base::sync_with_stdio(false);
ll k; string s,t; cin >> k >> s >> t;
vll v(10,k); v[0]=0;
map<ll,ll> A,B; FOR(i,1,10) { A[i]=0; B[i]=0; }
F(4) { v[s[i]-'0']--; A[s[i]-'0']++; }
F(4) { v[t[i]-'0']--; B[t[i]-'0']++; }
ll cnt = 0; FOR(i,1,10) cnt+=v[i];
double ret = 0;
FOR(a,1,10) FOR(b,1,10) {
v[a]--; v[b]--;
bool nok = v[a]<0 || v[b]<0;
v[a]++; v[b]++;
if(!nok) {
A[a]++; B[b]++;
if(score(A) > score(B)) {
// dbg(v[a],v[b],cnt);
double cur = double(v[a])/(cnt) * (v[b]-(a==b))/(cnt-1);
ret+=cur;
// dbg(a,b,cur, score(A), score(B));
}
A[a]--; B[b]--;
}
}
cout << fixed << setprecision(8) << ret << endl;
return 0;
}
|
//***JAI SHREE KRISHNA***
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define inf 1e18
#define MAX INT_MAX
#define MIN INT_MIN
#define F first
#define S second
#define pbmax priority_queue<int>//max heap
#define pbmin priority_queue<int, vector<int>, greater<int>>//min heap priority_queue
#define lpi(i,a,b) for(int i=0;i<n;i++)
#define lpd(i,a,b) for(int i=a;i>=b;i--)
const double pi = 3.14159265359;
const int mod = 1e9 + 7;
void task()
{
int a, b, c, d;
cin >> a >> b >> c >> d;
int ans = -1;
int blue = a;
int red = 0;
for (int i = 1; i <= 1e5; i++)
{
blue += b;
red += c;
if (blue <= (red )*d)
{
ans = i;
break;
}
}
cout << ans;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int test_cases = 1;
//cin >> test_cases;
while (test_cases--)
{
task();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
//#include<atcoder/all>
//using namespace atcoder;
using ll = long long;
#define INF32 2147483647
const long long INF = 1LL << 60;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;} return 0;}
template<class T> bool chmin(T &a,const T &b){if(b<a){a=b;return 1;} return 0;}
int main(){
int A,B,C,D;
cin >> A >> B >> C >> D;
double CD_B = C * D - B;
double ans = 0;
if(CD_B <= 0 ){
cout << -1 << endl;
}else{
ans = A / CD_B;
cout << ceil(ans) << endl;
}
return 0;
} |
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stdio.h>
#include<deque>
#include<map>
#include<queue>
#include<cmath>
#include<set>
typedef long long ll;
#define debug(x) cout << #x << '=' << x << endl;
#define debug_arr(a, n) for(ll i = 0; i < n; i++){cout << a[i] << ' ';} cout << endl;
#define inf 100000000000
#define loop(i,n) for(ll i = 0; i < n; i++)
#define graph vector<vector<ll>>
#define P pair<ll,ll>
using namespace std;
int main(){
ll n;
cin >> n;
vector<P> jobs(n);
loop(i,n){
cin >> jobs[i].first >> jobs[i].second;
}
ll ans = inf;
loop(i,n){
loop(j,n){
if(i == j) ans = min(jobs[i].first + jobs[j].second, ans);
else ans = min(max(jobs[i].first, jobs[j].second), ans);
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
using ll = long long;
const int N(1e5 + 10);
int n, tr[200];
std::vector<ll> a[3];
#define Odd(x) ((x) & 1)
ll Dis(int x, int y)
{
std::set<ll> S; ll ans = 1e18;
for (auto i : a[y]) S.insert(i);
for (auto i : a[x])
{
auto it = S.lower_bound(i);
if (it != S.end()) ans = std::min(ans, *it - i);
if (it != S.begin()) ans = std::min(ans, i - *std::prev(it));
}
return ans;
}
int main()
{
#ifndef ONLINE_JUDGE
file(cpp);
#endif
tr['R'] = 0, tr['G'] = 1, tr['B'] = 2;
std::ios::sync_with_stdio(false), std::cin.tie(nullptr), std::cin >> n;
for (int i = 1; i <= (n << 1); i++)
{ ll x; char c; std::cin >> x >> c; a[tr[c]].push_back(x); }
if (!(Odd(a[0].size()) || Odd(a[1].size()) || Odd(a[2].size()))) return puts("0"), 0;
if (!Odd(a[0].size())) std::swap(a[0], a[2]);
if (!Odd(a[1].size())) std::swap(a[1], a[2]);
printf("%lld\n", std::min(Dis(0, 2) + Dis(1, 2), Dis(0, 1)));
return 0;
}
|
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a;i<b;i++)
long long dp[105][600006],t;
main(){int n,k,M,b;std::cin>>n>>k>>M;dp[0][0]=1,b=n*(n+1)/2*k;fo(i,1,n+1)fo(s,0,b+1)
dp[i][s]=(dp[i-1][s]+(s<i?0:dp[i][s-i])+M-(s<i*(k+1)?0:dp[i-1][s-i*(k+1)]))%M;
fo(i,1,n+1){t=0;fo(s,0,b+1)t=(t+dp[i-1][s]*dp[n-i][s])%M;
std::cout<<(t*(k+1)+M-1)%M<<'\n';}}
| #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define re return
#define all(a) a.begin(),a.end()
#define int long long
#define Type int
#define rept(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) rept(i,0,a)
using namespace std;
void fail(string s){ cout<<s;exit(0); }
void fail(int s){ cout<<s;exit(0); }
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
void init(){
}
void run(){
int a,b,c;
cin>>a>>b>>c;
int d=b*b+c*c;
if (d<a*a)
fail(2);
rep(ans,1000000000000000){
int t=(ans*a)*(ans*a);
if (t>=d){
fail(ans);
}
}
}
signed main()
{
init();
int tc=1;
// cin>>tc;
while (tc--){
run();
}
re 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
float A,B;
cin >> A >> B;
float V;
V = (A - B) / A * 100;
cout << V << endl;
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
// clang-format off
#define PI 3.14159265358979323846264338327950L
#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 prep_ios(do_flush) if(!do_flush){ ios::sync_with_stdio(false);cin.tie(nullptr);constexpr char endl='\n'; } cout<<fixed<<setprecision(20)
#define put(expr) cout<<expr<<'\n'
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "[ "; for (auto v: vec) os << v << " "; os << "]"; return os; }template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "< "; for (auto v: vec) os << v << " "; os << ">"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{ "; for (auto v: vec) os << v << " "; os << "}"; return os; }template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{ "; for (auto v: vec) os << v << " "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{ "; for (auto v: mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{ "; for (auto v: mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
typedef int8_t i8; typedef int16_t i16; typedef int32_t i32; typedef int64_t i64; typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; typedef float f32; typedef double f64; typedef long double f80;
typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef map<int, int> mii;
typedef __int128_t i128; i128 parse(string &s) { i128 ret = 0; for (int i = 0; i < s.length(); i++) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret; } istream &operator>>(istream &is, i128 &v) { string s; is >> s; v = parse(s); return is; } ostream &operator<<(ostream &os, const i128 &v) { if (v == 0) return (os << "0"); i128 num = v; if (v < 0) { os << '-'; num = -num; } string s; for (; num > 0; num /= 10) s.push_back('0' + (char)(num % 10)); reverse(s.begin(), s.end()); return (os << s); }
template <typename T> bool chmax(T &now, const T &cand) { if (now < cand) { now = cand; return true; } return false; } template <typename T> bool chmin(T &now, const T &cand) { if (now > cand) { now = cand; return true; } return false; }
template <typename T> T gcd(const T &a, const T &b) { if (a % b == 0) return b; return gcd(b, a % b); } template <typename T> T lcm(const T &a, const T &b) { return a * b / gcd(a, b); }
template <typename T> T nCr(const T &n, T k) { if (k > n) return 0; if (k * 2 > n) k = n - k; if (k == 0) return 1; int result = n; for (int i = 2; i <= k; ++i) { result *= (n - i + 1); result /= i; } return result; }
const int INF = 1<<30; /* INF > 10^9 */ const i64 INFLL = 1LL<<60; /* INFLL > 10^18 */ const string YES = "Yes", NO = "No";
// clang-format on?
int main() {
prep_ios(true);
f64 A,B;
cin >> A>>B;
put(100.0-(B/A)*100.0);
}
|
#include<bits/stdc++.h>
using namespace std ;
# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) (v).begin() , (v).end() , comp
# define ll long long
# define ld long double
# define line cout << "\n" ;
# define fast ios_base :: sync_with_stdio ( false ) ; cin.tie ( 0 ) ;
# define pii pair < int , int >
# define pll pair < ll , ll >
# define F first
# define S second
const int mod = 1e9 + 7 ;
const int dx[] = { -1 , 0 , 1 , 0 , -1 , -1 , 1 , 1 } ;
const int dy[] = { 0 , 1 , 0 , -1 , -1 , 1 , -1 , 1 } ;
void solve ( int test_case )
{
int a , b , c , d ;
cin >> a >> b >> c >> d ;
int ans = b - c ;
cout << ans ; line ;
}
int main()
{
int t = 1 ;
// cin >> t ;
for ( int i = 1 ; i <= t ; i ++ )
{
solve ( i ) ;
}
return 0 ;
}
| #define _DEBUG
#include "bits/stdc++.h"
//#include <atcoder/all>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,a5,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug_6(x1,x2,x3,x4,x5,x6) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<", "#x6<<": "<<x6<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_6,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define prind(argument) cout<<std::fixed<<setprecision(13)<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define puba(a) emplace_back(a)
#define pubamp(a,b) emplace_back(mp(a,b))
typedef long long ll;
typedef long double ld;
using namespace std;
//using namespace atcoder;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
int a,b,c,d;
scan(a>>b>>c>>d);
prin(b-c);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define repp(i, n, m) for (int i = m; i < int(n); ++i)
//alias g++='g++ -I/mnt/c/Users/Owner/Desktop/ac-library'
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PI = pair<pair<int, int>, int>;
using PL = pair<long long, long long>;
using PLL = pair<pair<long long, long long>, long long>;
using Pxy = pair<long double, long double>;
const int INF = 1001001007;
const int modd = 1000000007;
const long long modl = 1000000007LL;
const long long mod = 998244353LL;
const ll inf = 2e18;
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
void yn(bool t) {
if (t)
yes();
else
no();
}
void Yes() { cout << "YES" << endl; }
void No() { cout << "NO" << endl; }
void YN(bool t) {
if (t)
Yes();
else
No();
}
vector<int> dx = { 0, 1, 0, -1 };
vector<int> dy = { 1, 0, -1, 0 };
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string alp = "abcdefghijklmnopqrstuvwxyz";
int main() {
string S;
cin >> S;
deque<char> T;
bool flag = false;
for (char s : S) {
if (s == 'R') {
flag = flag ? false : true;
} else {
if (flag) T.push_front(s);
else T.push_back(s);
}
}
if (flag == true) reverse(T.begin(), T.end());
string U;
rep(i,T.size()){
if(U.size() && T[i]==U.back()){
U.pop_back();
}
else U.push_back(T[i]);
}
cout << U << endl;
} | #pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize ("trapv")
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define mkp make_pair
#define pb push_back
#define pf push_front
#define inf 1000000000
#define maxn 300005
#define mod 100000000
#define mod1 1000000009
using namespace std;
void solve(){
ll n;
cin>>n;
ll ans_=LONG_LONG_MAX;
for(int i=0;i<60;++i){
ll t=(1LL<<i);
ll c=n%t;
ll a=(n/t);
ans_=min(ans_,a+c+i);
}
cout<<ans_<<'\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
// int t;
// cin>>t;
// while(t--)
solve();
return 0;
}
|
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
typedef long long ll;
const int N = 100000000;
using namespace std;
//100000000
int main(){
int n;
cin >> n;
vector<long long> a(n);
rep(i,n)cin >> a[i];
sort(a.begin(), a.end(), greater<long long>());
// rep(i,n){
// cout << a[i] << " ";
// }
// cout << endl;
vector<long long> sum(n);
rep(i,n){
sum[i] = a[i];
}
rep(i,n){
if(i == 0)continue;
sum[i] += sum[i - 1];
}
rep(i, n){
// cout << sum[i] << " ";
}
// cout << endl;
long long ans = 0;
for(int i = 0;i < n - 1;i++){
ans += a[i] * (n - i - 1) - (sum[n - 1] - sum[i]);
// cout << ans << endl;
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef vector <int> vi;
typedef pair< int ,int > pii;
#define endl "\n"
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
ll n;cin>>n;
vector<int>aa(31,0);
aa[2]=aa[3]=aa[5]=aa[7]=aa[11]=aa[13]=aa[17]=aa[19]=aa[23]=aa[29]=1;
ll v=1;
if(n==30)n=29;
for(ll i=n;i>=2;i--){
if(v%i!=0)v*=i;
}
// map<int,ll>dp;
// dp.clear();
// for(ll i=0;i<31;i++){
// if(aa[i]==0)continue;
// else{
// for(int j=1;j<=n;j++){
// ll u = j;
// ll k = 0;
// if(u%i==0){
// k++;
// u/=i;
// }
// dp[i]=max(dp[i],k);
// }
// }
// }
// for(ll i=0;i<31;i++){
// if(aa[i]){
// ll ff=1;
// for(int j=1;j<=dp[i];j++){
// ff*=i;
// }
// // cout<<ff<<" ";
// v*=ff;
// }
// }
cout<<(v+1)<<"\n";
// for(int i=2;i<=n;i++){
// cout<<(v+1)%i<<" ";
// }
// cout<<"\n";
return 0;
} |
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
//#define int long long
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PI = pair<pair<int,int>,int>;
using PL = pair<long long, long long>;
using PLL = pair<pair<long long, long long>, long long>;
using Pxy = pair<long double, long double>;
using Tiib = tuple<int, int, bool>;
using vvl = vector<vector<ll>>;
const int INF = 1001001007;
const int modd = 1000000007;
const long long modl = 1000000007LL;
const long long mod = 998244353LL;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
rep(i,ar.size()-1) cout << ar[i] << " ";
cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
rep(i,ar.size()){
rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
cout << ar[i][ar[0].size()-1] << endl;
}
}
template <typename S>
bool range(S a, S b, S x){
return (a <= x && x < b);
}
void yes(){
cout << "Yes" << endl;
}
void no (){
cout << "No" << endl;
}
ll cel (ll a, ll b){
if (a % b == 0) return a / b;
else return a / b + 1;
}
ll gcds(ll a, ll b){
ll c = a % b;
while (c != 0){
a = b;
b = c;
c = a % b;
}
return b;
}
char rps(char a, char b){
if (a == b) return a;
if (a == 'P'){
if (b == 'R') return a;
else return b;
}
if (a == 'R'){
if (b == 'P') return b;
else return a;
}
if (a == 'S'){
if (b == 'P') return a;
else return b;
}
}
int main(){
int n, k; cin >> n >> k;
string s; cin >> s;
s += s;
rep(i,k){
string t = "";
rep(j,s.size() / 2){
t += rps(s[2*j],s[2*j+1]);
}
t += t;
s = t;
}
cout << s[0] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)
/****************************** CODE IS HERE ***********************************/
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n, m; cin >> n >> m;
vector <int> A(n), B(m);
for (int &i: A) cin >> i;
for (int &i: B) cin >> i;
vector <vector<int>> dp(n+1, vector<int>(m+1, -1));
function<int(int, int)> go = [&](int i, int j) {
if (i == n and j == m) return 0;
if (i < n and j == m) return (n - i);
if (i == n and j < m) return (m - j);
int &res = dp[i][j];
if (res != -1) return res;
int ans = 1e9;
if (A[i] == B[j]) ans = go(i+1, j+1);
else ans = 1 + go(i+1, j+1);
ans = min({ans, 1 + go(i+1, j), 1 + go(i, j+1)});
return res = ans;
};
cout << go(0, 0);
return 0;
}
/*
f(i, j) => min {
if (A[i] == B[j]) f(i+1, j+1),
1 + f(i+1, j),
1 + f(i, j+1),
1 + f(i+1, j+1)
}
base cases:
if (i == n and j == m) return 0;
if (i < n and j == m) return (n-i);
if (i == n and j < m) return (m - j);
*/
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
namespace IO {
const int MAXIOSIZE = 1 << 24 | 1;
unsigned char buf[MAXIOSIZE], *p1, *p2;
#define gc (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 24, stdin), p1 == p2) ? EOF : *p1++)
template <typename T> void read(T& x) {
x = 0; char ch = gc; bool flg = false;
for (; ch < '0' || '9' < ch; ch = gc) if (ch == '-') flg |= true;
for (; '0' <= ch && ch <= '9'; ch = gc) x = x * 10 + ch - '0';
flg ? x = -x : 0;
}
template <typename T> void out(const T& x) { if (x > 9) out(x / 10); putchar(x % 10 + '0'); }
template <typename T> inline void write(const T& x, const char& ed = ' ') { if (x < 0) putchar('-'), out(-x); else out(x); putchar(ed); }
}
typedef long long ll;
const int MAXN = 2e5 + 10;
const int MAXLOG = 18 + 10;
int n, q;
vector<int> E[MAXN];
pair<int, int> Edge[MAXN];
int dfsclock, dtp[MAXN];
struct Vertex { int dfn, dep, sz, fa[MAXLOG]; ll val; } vtx[MAXN];
void dfs(int u) {
dtp[ vtx[u].dfn = ++dfsclock ] = u, vtx[u].sz = 1;
rep(i, 1, 18) vtx[u].fa[i] = vtx[vtx[u].fa[i - 1]].fa[i - 1];
vtx[u].dep = vtx[vtx[u].fa[0]].dep + 1;
for (int v : E[u]) {
if (v == vtx[u].fa[0]) continue;
vtx[v].fa[0] = u;
dfs(v); vtx[u].sz += vtx[v].sz;
}
}
bool anc_son(int u, int v) { return vtx[u].dfn <= vtx[v].dfn && vtx[v].dfn <= vtx[u].dfn + vtx[u].sz - 1; }
int get_vertex(int u, int v) { // get the closest vertex from u to v
int r = u;
per(bit, 18, 0) if (vtx[vtx[r].fa[bit]].dep >= vtx[v].dep + 1) r = vtx[r].fa[bit];
return r;
}
inline void work(int u, int v, int x) { // reachable for u, withou reaching v
if (anc_son(u, v) || anc_son(v, u)) {
if (vtx[u].dep < vtx[v].dep) return vtx[1].val += x, vtx[v].val -= x, void();
u = get_vertex(u, v); vtx[u].val += x;
return ;
}
vtx[1].val += x, vtx[v].val -= x;
}
ll ans[MAXN];
void calc_ans(int u) {
vtx[u].val += vtx[vtx[u].fa[0]].val;
ans[u] = vtx[u].val;
for (int v : E[u]) if (v != vtx[u].fa[0]) calc_ans(v);
}
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif
IO::read(n);
rep(i, 1, n - 1) {
int u, v; IO::read(u), IO::read(v);
Edge[i] = make_pair(u, v);
E[u].push_back(v), E[v].push_back(u);
}
IO::read(q);
dfs(1);
rep(i, 1, q) {
int t, e, x, u, v;
IO::read(t), IO::read(e), IO::read(x);
u = Edge[e].first, v = Edge[e].second;
if (t == 2) swap(u, v);
work(u, v, x);
}
calc_ans(1);
rep(i, 1, n) IO::write(ans[i], '\n');
return 0;
}
| #include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>
using namespace std;
#define int long long
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, C;
cin >> n >> C;
map<int, vector<int>> op;
map<int, vector<int>> cl;
vector<int> ip;
for (int i = 0; i < n; i++) {
int a, b, c;
cin >> a >> b >> c;
op[a].push_back(c);
cl[b].push_back(c);
ip.push_back(a);
ip.push_back(b);
}
sort(ip.begin(), ip.end());
ip.resize(unique(ip.begin(), ip.end()) - ip.begin());
int cur = 0;
int prev = -1;
int ans = 0;
for (auto x : ip) {
ans += (x - prev - 1) * min(C, cur);
for (auto t : op[x]) cur += t;
ans += min(C, cur);
for (auto t : cl[x]) cur -= t;
prev = x;
}
cout << ans << '\n';
}
|
#include<bits/stdc++.h>
using namespace std;
#define dvg(x) cout<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#define endl "\n"
#define rep(i, st, n) for(int i = st; i <= n; i += 1)
#define ll long long
#define l64 int64_t
#define ld long double
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll,ll>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pb(x) push_back(x)
#define pp() pop_back()
#define in(x) insert(x)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<Pll>
#define vvi vector<vi>
#define pn(n) cout<<n<<"\n";
#define pn2(x,y) cout<<x<<" "<<y<<"\n";
#define pr(ar) {for (auto i : ar) cout<<i<<" "; cout<<"\n";}
#define get(x) cin>>x;
#define get2(x, y) cin>>x>>y;
#define cn(v) for(auto &i : v) cin>>i;
#define sq(a) (a*a)
#define mem(x, y) memset(x, y, sizeof(x))
int dx[] {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
int const N = 1e5 + 10;
void solve()
{
double n; cin>>n;
double ans = 0;
for(int i = 1; i < n; i++) ans += 1.000/i;
ans *= n;
setprecision(12);
cout<<fixed<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T = 1;
//
while(T--)
{
solve();
}
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){
int n;
cin >> n;
double ans = 0;
for(int e=1;e<n;e++) ans += (double)n/(double)e;
printf("%.9lf",ans);
}
int main(void){
/*
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
*/
int tc = 1;
/*
cin >> tc;
*/
for(int test_number=1;test_number<=tc;test_number++){
solve(test_number);
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
// using mint = long double;
// using mint = modint998244353;
// using mint = modint1000000007;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;
typedef pair<ll, vector<ll>> Pd;
const ll INF = 1e18;
const ll fact_table = 320000;
priority_queue<ll> pql;
priority_queue<P> pqp;
// big priority queue
priority_queue<ll, vector<ll>, greater<ll>> pqls;
priority_queue<P, vector<P>, greater<P>> pqps;
// small priority queue
// top pop
ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
//↓,→,↑,←
#define p(x) cout << x << "\n";
#define el cout << endl;
#define pe(x) cout << x << " ";
#define ps(x) cout << fixed << setprecision(25) << x << endl;
#define pu(x) cout << (x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = a; i <= (b); i++)
#define rep3(i, a, b) for (ll i = a; i >= (b); i--)
#define all(c) begin(c), end(c)
#define sorti(v) sort(all(v))
#define sortd(v) \
sort(all(v)); \
reverse(all(v));
#define SUM(v) accumulate(all(v), 0LL)
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
// vec v(n) -> 長さnのベクトルを宣言
// mat dp(h, vec(w)) -> h * w の行列を宣言
// const ll mod = 1000000007ll;
const ll mod = 998244353ll;
ll mypow(ll a, ll b, ll m = mod) {
ll x = 1;
while (b) {
while (!(b & 1)) {
(a *= a) %= m;
b >>= 1;
}
(x *= a) %= m;
b--;
}
return x;
}
vec rv(ll read) {
vec res(read);
for (int i = 0; i < read; i++) {
cin >> res[i];
}
return res;
}
/*
ll fact[fact_table + 5], rfact[fact_table + 5];
void c3_init() {
fact[0] = rfact[0] = 1;
for (ll i = 1; i <= fact_table; i++) {
fact[i] = (fact[i - 1] * i) % mod;
}
rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
for (ll i = fact_table; i >= 1; i--) {
rfact[i - 1] = rfact[i] * i;
rfact[i - 1] %= mod;
}
return;
}
ll c3(ll n, ll r) {
return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;
}
*/
bool icpc = false;
bool multicase = false;
map<ll, ll> mp;
bool solve() {
ll n;
cin >> n;
ll sum = 0;
ll ans = 0;
mp[0]++;
rep(i, n) {
ll value;
cin >> value;
if (i % 2 == 0) value *= -1;
sum += value;
mp[sum]++;
}
for (auto [num, cnt] : mp) {
ans += cnt * (cnt - 1) / 2;
}
p(ans);
return true;
}
/*
*/
int main() {
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
if (icpc) {
while (solve())
;
return 0;
}
ll q, testcase = 1;
if (multicase) {
cin >> q;
} else {
q = 1;
}
while (q--) {
// cout << "Case #" << testcase << ": ";
solve();
testcase++;
}
// solve();
return 0;
} | #include <iostream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pb push_back
#define fo(i, a, b) for (int i = a; i < b; i++)
#define sqr(x) ((ll)(x) * (x))
#define p(a) cout << a << "\n"
#define fast_io \
ios::sync_with_stdio(0); \
cin.tie(0);
inline string IntToString(ll a)
{
char x[100];
sprintf(x, "%lld", a);
string s = x;
return s;
}
void PrintArr(ll Arr[], ll N)
{
cout << "Printing: \n";
fo(j, 0, N)
{
cout << Arr[j] << " ";
}
printf("\n");
}
inline ll StringToInt(string a)
{
char x[100];
ll res;
strcpy(x, a.c_str());
sscanf(x, "%lld", &res);
return res;
}
bool prime(ll no)
{
if (no < 3)
return false;
int factor = 0;
for (int i = 2; i * i <= no; i++)
{
if (no % i == 0)
{
return false;
}
}
return true;
}
long long lcm(ll a, ll b)
{
return (a * b) / (__gcd(a, b));
}
/*...........................DSU.................................*/
void unin(int u,int v,int parent[])
{
parent[u]+=parent[v];
parent[v]=u;
}
int find(int n,int parent[])
{
if(parent[n]<0)
return n;
return parent[n]=find(parent[n],parent);
}
/*.................................................................code starts here.........................................................*/
void testCase()
{
ll l,r; cin>>l>>r;
ll avail=r-l;
ll ans=0;
if(l==r && l!=0)
{
cout<<"0\n";
}
else if(l==r && l==0)
{
cout<<"1\n";
}
else if(2*l>r)
cout<<"0\n";
else{
avail-=l; avail+=1;
if(avail>0)
ans=(avail*(avail+1))/2;
else if(avail==0)
ans=1;
cout<<ans<<endl;
}
}
int main()
{
fast_io int t;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin>>t;
while (t--)
{
testCase();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n; cin >> n;
vector<int> A(n), B(n), C(n);
rep(i, n) cin >> A[i];
rep(i, n) cin >> B[i];
rep(i, n) cin >> C[i];
vector<int> D(n);
rep(i, n) D[i] = B[C[i]-1];
map<int, int> cntA, cntD;
rep(i, n) {
cntA[A[i]]++;
cntD[D[i]]++;
}
ll ans = 0;
for(auto [a, c]: cntA) {
ans += 1LL * c * cntD[a];
}
cout << ans << endk;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'
constexpr int INF = (sizeof(int) == 4 ? 1e9 : 2e18) + 1e5;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;
// #define MULTIPLE_TEST_CASES
void solve(const int test) {
int n;
cin >> n;
int k;
cin >> k;
while (k--) {
if (n % 200 == 0) {
n /= 200;
} else {
n *= 1000;
n += 200;
}
}
cout << n << endl;
}
signed main() {
// const string FILE_NAME = "";
// freopen((FILE_NAME + string(".in")).c_str(), "r", stdin);
// freopen((FILE_NAME + string(".out")).c_str(), "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int t = 1;
#ifdef MULTIPLE_TEST_CASES
cin >> t;
#endif
for (int i = 1; i <= t; ++i)
solve(i);
}
|
#include <bits/stdc++.h>
int main(){
int a, b, c, d;
std::cin >>a >> b >> c >> d;
std::cout << (a*d - b*c) << std::endl;
} | #include <math.h>
#include <stdio.h>
#include <time.h>
#include <algorithm>
#include <complex>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
#define cYes cout << "Yes" << endl
#define cNo cout << "No" << endl
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define rRep(i, a, b) for (ll i = a; i >= b; i--)
#define crep(i) for (char i = 'a'; i <= 'z'; ++i)
#define psortsecond(A, N) \
sort(A, A + N, \
[](const pii& a, const pii& b) { return a.second < b.second; });
#define ALL(x) (x).begin(), (x).end()
#define debug(v) \
cout << #v << ":"; \
for (auto x : v) { \
cout << x << ' '; \
} \
cout << endl;
#define endl '\n'
int ctoi(const char c) {
if ('0' <= c && c <= '9') return (c - '0');
return -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); }
constexpr ll MOD = 1000000007;
constexpr ll INF = 1000000011;
constexpr ll MOD2 = 998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS = 10e-8;
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
for (auto&& x : v) is >> x;
return is;
}
template <typename T, typename U>
istream& operator>>(istream& is, pair<T, U>& p) {
is >> p.first;
is >> p.second;
return is;
}
template <typename T, typename U>
ostream& operator>>(ostream& os, const pair<T, U>& p) {
os << p.first << ' ' << p.second;
return os;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
for (auto i = begin(v); i != end(v); ++i) {
if (i != begin(v)) os << ' ';
os << *i;
}
return os;
}
// modint
template <std::uint_fast64_t Modulus>
class modint {
using u64 = std::uint_fast64_t;
public:
u64 a;
constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
constexpr u64& value() noexcept { return a; }
constexpr const u64& value() const noexcept { return a; }
constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint& operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
constexpr modint& operator-=(const modint rhs) noexcept {
if (a < rhs.a) {
a += Modulus;
}
a -= rhs.a;
return *this;
}
constexpr modint& operator*=(const modint rhs) noexcept {
a = a * rhs.a % Modulus;
return *this;
}
constexpr modint& operator/=(modint rhs) noexcept {
u64 exp = Modulus - 2;
while (exp) {
if (exp % 2) {
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
};
int main() {
string S;
ll A, B, C, D, E, F, G, H, L, M, N, P, Q, R, T, U, X, Y, Z;
cin >> A >> B >> C >> D;
cout << A * D - B * C << endl;
}
|
//
// Created by whq on 2021/2/21.
//
#include <bits/stdc++.h>
#define uset unordered_set
#define umap unordered_map
#define debug cout<<"ok"<<endl
#define ll long long
#define ii pair<ll, ll>
#define fi first
#define se second
#define vi vector<int>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vvl vector<vector<ll>>
#define vl vector<ll>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define For(i, n) for (int i = 0; i < n; i++)
#define forn(i, a, b) for(int i=a;i<=b;i++)
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end()
#define lowbit(x) x&(-x)
using namespace std;
class A {
public:
void solve() {
ll k;
cin >> k;
ll res = 0;
for (ll i = 1; i * i * i <= k; i++) res++;
for (ll i = 1; i * (i + 1) <= k; i++) {
for (ll j = i + 1; j * i <= k; j++) {
if (i * i * j <= k) res += 3;
if (i * j * j <= k) res += 3;
}
}
for (ll i = 1; i * (i + 1) <= k; i++) {
for (ll j = i + 1; j * i <= k; j++) {
for (ll l = j + 1; l * j * i <= k; l++) res += 6;
}
}
cout << res << endl;
}
};
class B {
public:
ll base;
ll fpow(ll a, ll k) {
if (k == 0) return 1;
ll temp = fpow(a, k / 2) % base;
temp = (temp * temp) % base;
if ((k % 2) == 1) return ((temp % base) * (a % base)) % base;
else return temp;
}
ll superPow(ll a, ll b) {
if(b==0) return 1ll;
ll p1=fpow(a,b%10);
ll p2=fpow(superPow(a,b/10),10);
return (p1)*(p2)%base;
}
void solve() {
ll a, b, c;
cin >> a >> b >> c;
set<int> one = {0, 1, 5, 6};
ll cur = a % 10;
map<int, map<int, int> > two;
two[4][1] = 4;
two[4][0] = 6;
two[9][1] = 9;
two[9][0] = 1;
if (one.count(cur)) {
cout << cur << endl;
return;
}
if (cur == 4 || cur == 9) {
cout << two[cur][b % 2] << endl;
return;
}
base = 4;
map<int, map<int, int>> f;
f[2][1] = 2;
f[2][2] = 4;
f[2][3] = 8;
f[2][0] = 6;
f[3][1] = 3;
f[3][2] = 9;
f[3][3] = 7;
f[3][0] = 1;
f[7][1] = 7;
f[7][2] = 9;
f[7][3] = 3;
f[7][0] = 1;
f[8][1] = 8;
f[8][2] = 4;
f[8][3] = 2;
f[8][0] = 6;
ll left=superPow(b,c)%base;
cout<<f[cur][left]<<endl;
}
};
class C{
public:
void solve(){
string s;
cin>>s;
vi cnt(26,0);
ll n=s.size();
ll res=0;
for(int i=n-1;i>=0;i--){
cnt[s[i]-'a']++;
if(i+1<n&&s[i]==s[i+1]){
res+=n-i-cnt[s[i]-'a'];
for(int j=0;j<26;j++){
if(j==s[i]-'a') continue;
cnt[s[i]-'a']+=cnt[j];
cnt[j]=0;
}
}
}
cout<<res<<endl;
}
};
class D{
public:
ll base=998244353;
ll binpow(ll a, ll b) {
ll res = 1;
while (b > 0) {
if (b & 1) res = res * a%base;
a = a * a%base;
b >>= 1;
}
return res;
}
void solve(){
ll n,m,k;
cin>>n>>m>>k;
ll res=0;
if(n==1||m==1){
cout<<binpow(k,n*m)<<endl;
return;
}
for(ll i=1;i<=k;i++) {
ll tot=(binpow(i,n)-binpow(i-1,n))%mod;
res=(res+tot*(binpow(k-i+1,m))%base)%base;
}
if(res<0) res+=base;
cout<<res%base<<endl;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
D ans;
ans.solve();
return 0;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, j, n) for (ll i = j; i < (n); ++i)
#define rrep(i, j, n) for (ll i = (n)-1; j <= i; --i)
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& a) {
for (size_t i = 0; i < a.size(); ++i) os << (i > 0 ? " " : "") << a[i];
return os << '\n';
}
[[maybe_unused]] constexpr ll MOD = 998244353;
[[maybe_unused]] constexpr int INF = 0x3f3f3f3f;
[[maybe_unused]] constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;
ll mpow(ll x, ll e) {
ll res = 1;
while (e > 0) {
if (e & 1) res = res * x % MOD;
x = x * x % MOD;
e >>= 1;
}
return res;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
ll n, m, k;
cin >> n >> m >> k;
if (n == 1 || m == 1) {
if (n == 1 && m == 1) {
cout << k;
return 0;
}
if (n == 1) {
ll ans = 0;
rep(i, 1, k + 1) {
// 行の最小値がi
// 少なくとも人つ
ans += (MOD + (mpow(k - (i - 1), m) - mpow(k - i, m)) % MOD) % MOD;
ans %= MOD;
}
cout << ans;
return 0;
}
if (m == 1) {
ll ans = 0;
rep(i, 1, k + 1) {
ans += (MOD + (mpow(i, n) - mpow(i - 1, n)) % MOD) % MOD;
ans %= MOD;
}
cout << ans;
return 0;
}
}
// aのみの問題を考える。 ➡ 各行は独立なので、普通にk^n
// マスの埋め方は
// a[i]==xの時、i行目にはx未満の値が現れない ∧ xが少なくとも一回現れる。
// k^nで決めた後、aのmax以上の値は、任意のbで取れる。
// aのmaxがxとなる組み合わせ * (x ~ k)^m
ll ans = 0;
rep(x, 1, k + 1) {
ll tmp = (MOD + (mpow(x, n) - mpow(x - 1, n)) % MOD) % MOD;
ans += tmp * mpow(k - x + 1, m) % MOD;
ans %= MOD;
}
cout << ans;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long int ll;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for(auto it = d.b;it != d.e;++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll s, p;cin >> s >> p;
bool ans = false;
for(ll i = 1;i * i <= p;i++){
if(p % i == 0){
ll fst = i;
ll snd = p / i;
if(fst + snd == s)ans = true;
}
}
if(ans)cout << "Yes";
else cout << "No";
cout << endl;
}
| #define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
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; }
template<class T> inline T int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
#include <bits/stdc++.h>
using namespace std;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
// sort(ALL(v), [](auto const& lhs, auto const& rhs) { return lhs > rhs; /* 左の方が大きい...というイメージ。*/ });
// --------------------------------------------------------------------------------------------- //
static const int MAX = 100001;
static const ll MOD = 1000000007;
ll dividedNum(ll n){
ll ret = 0;
ll lim = sqrt(n)+1;
for(ll i=1; i<lim; i++){
if(n%i==0){
ret++;
if(i != n / i && lim <= n/i){
ret++;
}
}
}
ll res = ret / 2 * 2;
res += ret % 2;
return res;
}
ll dp[MAX];
ll N, K;
ll dividedNum2(ll n){
if(n == 2) return 1;
ll ret = 0;
ll ng_num = max(0LL, n - N - 1LL);
ll tmp = (n-1)/2 - ng_num;
ret += tmp * 2;
ret = max(0LL, ret);
if(n % 2 == 0 && n / 2 <= N){
ret++;
}
return max(0LL, ret);
}
int main(int argc, const char * argv[]) {
std::cout << std::fixed << std::setprecision(15);
cin >> N >> K;
if(K < 0) K *= -1;
memset(dp, 0, sizeof(dp));
// 足したら2 * Nになるやつを求める
ll ans = 0;
// A決定
for(int i=2; i<=2 * N; i++){
// Kから,B決定
ll A = i;
ll B = A - K;
if(!(2 <= B && B <= 2 * N)){
continue;
}
// cout << A << " " << B << endl;
// A, Bの作り方の個数を調べる
ll a_num = dividedNum2(A);
ll b_num = dividedNum2(B);
// cout << a_num << " " << b_num << endl;
// それの掛け算をansにプラス
ans += a_num * b_num;
}
cout << ans << endl;
return 0;
}
|
#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#pragma region macros
using str=string;
using ll=long long;
using vl=vector<ll>;
using vc=vector<char>;
using pl=pair<ll,ll>;
using ml=map<ll,ll>;
using sl=set<ll>;
template<class T> using V=vector<T>;
template<class T,class U> using P=pair<T,U>;
#define FOR(n) for(ll i=0;i<n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,n) for(ll i=1;i<n;i++)
#define REP(i,m,n) for(ll i=m;i<n;i++)
#define drep(i,n) for(ll i=n-1;i>=0;i--)
#define fore(n) for(auto&& i:n)
#define fors(n) for(auto&&[i,j]:n)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sor(v) sort(all(v))
#define rsor(v) sort(rall(v))
#define rev(v) reverse(all(v))
#define low(v,x) lower_bound(all(v),x)-v.begin()
#define up(v,x) upper_bound(all(v),x)-v.begin()
#define acc(v) accumulate(all(v),0LL)
#define ef(x) emplace_front(x)
#define eb(x) emplace_back(x)
#define pf() pop_front()
#define pb() pop_back()
#define mp(a,b) make_pair(a,b)
#define ceil(a,b) (a+b-1)/b
#define bit(n) (1LL<<n)
#define fi first
#define se second
#define fr front()
#define ba back()
#define be begin()
#define en end()
#define br break
#define cn continue
#define wh while
#define el else if
#define re return
const ll inf=1LL<<60;
const ll mod=1000000007;
const ll MOD=998244353;
const double pi=3.1415926535;
const double eps=1e-10;
const ll dx[4]={1,0,-1,0};
const ll dy[4]={0,1,0,-1};
void input(){}
void inputs(){}
void output(){}
template<class T,class...U> void input(T& x,U&...y){cin>>x;input(y...);}
template<class...T> void in(T&...x){input(x...);}
template<class T> void inputs(const ll t,T& x){cin>>x[t];}
template<class T,class...U> void inputs(const ll t,T& x,U&...y){cin>>x[t];inputs(t,y...);}
template<class T,class...U> void inputs(T& x,U&...y){rep(t,size(x))inputs(t,x,y...);}
template<class...T> void ins(T&...x){inputs(x...);}
template<class T,class...U> void output(T x,U...y){cout<<x<<"\n";output(y...);}
template<class...T> void out(T...x){output(x...);}
template<class...T> void fin(T...x){out(x...);exit(0);}
template<class T> istream&operator>>(istream& i,V<T>& v){for(T& x:v)i>>x;re i;}
template<class T,class U> istream&operator>>(istream& i,P<T,U>& p){re i>>p.fi>>p.se;}
template<class T> ostream&operator<<(ostream& o,V<T>& v){for(T& x:v)o<<x<<" ";re o;}
template<class T,class U> ostream&operator<<(ostream& o,P<T,U>& p){re o<<p.fi<<" "<<p.se;}
void yn(bool b){fin((b?"Yes":"No"));}
void YN(bool b){fin((b?"YES":"NO"));}
void pos(bool b){fin((b?"POSSIBLE":"IMPOSSIBLE"));}
template<class T,class U> void chmax(T& a,U b){if(a<b)a=b;}
template<class T,class U> void chmin(T& a,U b){if(a>b)a=b;}
template<class T,class U> auto max(T a,U b){re a>b?a:b;}
template<class T,class U> auto min(T a,U b){re a<b?a:b;}
ll qp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r*=x;x*=x;n>>=1;}re r;}
ll mdp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r=r*x%mod;x=x*x%mod;n>>=1;}re r;}
ll MDp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r=r*x%MOD;x=x*x%MOD;n>>=1;}re r;}
struct UnionFind{
vl par,sz;
UnionFind(ll n):par(n),sz(n,1){rep(i,n) par[i]=i;}
ll rot(ll x){
if(par[x]==x) re x;
re par[x]=rot(par[x]);
}
void uni(ll x,ll y){
x=rot(x),y=rot(y);
if(x==y) re;
if(sz[x]<sz[y]) swap(x,y);
sz[x]+=sz[y];
par[y]=x;
}
bool eql(ll x,ll y){re rot(x)==rot(y);}
ll siz(ll x){re sz[rot(x)];}
};
struct IOSetup{
IOSetup(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout<<fixed<<setprecision(10);
}
}iosetup;
#pragma endregion
signed main(){
ll x,y; in(x,y);
if(x==y) out(x);
else{
if(x==1){
if(y==0) out(2);
else out(0);
}
if(x==2){
if(y==0) out(1);
else out(0);
}
if(x==0){
if(y==1) out(2);
else out(1);
}
}
} | #include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
char ch,fu=0;
for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
if(ch=='-') fu=1, ch=getchar();
for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
if(fu) v=-v;
}
const int MO=998244353;
LL a[500010],b[500010],ans;
int n,m,k;
LL pw(LL x,LL y){
LL t=1;
for (;y;y>>=1){
if (y&1) t=t*x%MO;
x=x*x%MO;
}
return t;
}
int main(){
cin>>n>>m>>k;
if (n==1 || m==1){
ans=pw(k,n*m);
ans=(ans%MO+MO)%MO;
cout<<ans<<endl;
return 0;
}
FOR(i,1,k) a[i]=(pw(i,n)-pw(i-1,n))%MO;
FOR(i,1,k) b[i]=(pw(k-i+1,m)-pw(k-i,m))%MO;
FORD(i,k,1) (b[i]+=b[i+1])%=MO;
FOR(i,1,k) (ans+=a[i]*b[i])%=MO;
ans=(ans%MO+MO)%MO;
cout<<ans<<endl;
return 0;
} |
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a) (a).begin(),(a).end()
#define ALLR(a) (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
template<typename T>void rearrange(vector<ll>&ord, vector<T>&v){
auto tmp = v;
for(int i=0;i<tmp.size();i++)v[i] = tmp[ord[i]];
}
template<typename Head, typename... Tail>void rearrange(vector<ll>&ord,Head&& head, Tail&&... tail){
rearrange(ord, head);
rearrange(ord, tail...);
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
ll res=0,buf=0;
bool judge = true;
ll n;cin>>n;
string s,t;cin>>s>>t;
vector<ll>l,r;
rep(i,0,n)if(s[i]=='1')l.PB(i);
rep(i,0,n)if(t[i]=='1')r.PB(i);
ll idx=0;
rep(i,0,l.size()){
if(idx==r.size()||l[i]<r[idx]){
if(i+2>l.size()){
judge=false;
break;
}
res+=l[i+1]-l[i];
i++;
}
else{
res+=l[i]-r[idx];
idx++;
}
//cout<<i spa res<<endl;
}
if(idx!=r.size())judge=false;
ans(judge,res,-1);
return 0;
} | #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<climits>
#include<utility>
#include<vector>
#include<queue>
#define int long long
using namespace std;
const int MaxN = 500005;
int n, ans;
char s[MaxN], t[MaxN];
queue<int> pos;
inline int Read(){
int num = 0, op = 1;
char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') op = -1;
ch = getchar();
}
while(isdigit(ch)){
num = num * 10 + ch - '0';
ch = getchar();
}
return num * op;
}
signed main(){
n = Read();
scanf("%s%s", s+1, t+1);
for(int i=1; i<=n; i++)
if(s[i] == '1') pos.push(i);
for(int i=1; i<=n; i++){
if(s[i] == t[i]){
if(s[i] == '1') pos.pop();
continue;
}
else if(s[i] == '1' && t[i] == '0'){
if(pos.empty()){
printf("-1");
return 0;
}
int p1 = pos.front();
pos.pop();
if(pos.empty()){
printf("-1");
return 0;
}
int p2 = pos.front();
pos.pop();
ans += (p2 - p1);
s[p1] = s[p2] = '0';
}
else if(s[i] == '0' && t[i] == '1'){
if(pos.empty()){
printf("-1");
return 0;
}
int p = pos.front();
pos.pop();
ans += (p - i);
s[p] = '0', s[i] = '1';
}
}
printf("%lld", ans);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}
#define MAX_N 200005
class UnionFind
{
public:
int par[MAX_N];
int depth[MAX_N];
int nGroup[MAX_N];
UnionFind(int n) {
init(n);
}
void init(int n) {
for(int i=0; i<n; i++) {
par[i] = i;
depth[i] = 0;
nGroup[i] = 1;
}
}
int root(int x) {
if(par[x] == x) {
return x;
} else {
return par[x] = root(par[x]);
}
}
bool same(int x, int y) {
return root(x) == root(y);
}
void unite(int x, int y) {
x = root(x);
y = root(y);
if(x == y) return;
if(depth[x] < depth[y]) {
par[x] = y;
nGroup[y] += nGroup[x];
nGroup[x] = 0;
} else {
par[y] = x;
nGroup[x] += nGroup[y];
nGroup[y] = 0;
if(depth[x] == depth[y])
depth[x]++;
}
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n; cin >> n;
vector<ll> A(n); rep(i, n) cin >> A[i];
UnionFind uf(200001);
rep(i, n) {
uf.unite(A[i], A[n-1-i]);
}
ll ans = 0;
rep(i, 200001) {
if(uf.root(i) == i) {
ans += uf.nGroup[i]-1;
}
}
cout << ans << endk;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
const int N=110000;
int n,L,a[N],b[N],c[N],d[N];
long long ans;
int main() {
cin>>n>>L;
for(int i=1;i<=n;++i) cin>>a[i], c[i]=a[i]-a[i-1]-1; c[n+1]=L-a[n];
for(int i=1;i<=n;++i) cin>>b[i], d[i]=b[i]-b[i-1]-1; d[n+1]=L-b[n];
for(int i=1,j=1;i<=n+1;++i) if(d[i]) {
int sum=0,las=j;
while(c[las] == 0) ++las;
j=las;
while(sum<d[i]) sum += c[j], ++j;
if(sum != d[i]) puts("-1"), exit(0);
ans += max(i-las,0)+max(j-i-1,0);
}
cout<<ans;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*............................................................................*/
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
/* find_by_order(x) give iterator of the index x
order_by_key(x) give the position where x will be placed*/
#define int long long
#define lop(i,a,b,c) for (int i=a;i<b;i+=c)
#define rlop(i,a,b,c) for (int i=a-1;i>=b;i-=c)
#define prii pair <int,int>
#define PB push_back
#define S second
#define F first
#define B begin()
#define E end()
#define count_1(x) __builtin_popcount(x)
/*......................................................................*/
void solve(){
int t,n;cin>>t>>n;
int lw=1;int hg=1e15;int md;int ans;
while (lw<=hg){
md=(lw+hg)/2;
int z=(md*t)/100;
if (z<n){
ans=md;lw=md+1;
}
else hg=md-1;
}ans+=n;cout<<ans<<"\n"; return ;
if (n%t==0){
int a=n/t;a--;
int b=100+t;b=b*a;
cout<<b+t*ans<<"\n";return ;
}
int a=n/t;
int b=100+t;b=b*a;
cout<<b+(n%t)*ans<<"\n";return ;
}
int32_t main(){
int t;t=1;
//cin>>t;
while (t--){
solve();
}
return 0;
} | #include<cstdio>
long long a,b;
int main(){
scanf("%lld%lld",&a,&b);
printf("%lld %lld\n",(a+b)/2,(a-b)/2);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N;
cin >> N;
int d = to_string(N).length();
int M = 1;
for (int i = 0; i < d/2; i++) {
M *= 10;
}
if (d%2 == 0) {
if (N/M <= N%M) cout << N/M << endl;
else cout << N/M - 1 << endl;
}
else {
cout << M - 1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 1e6 + 5;
int main() {
ios::sync_with_stdio(false); cin.tie(0);
ll n;
cin >> n;
auto get_num = [] (string s) -> ll {
ll res = 0;
for(char &c : s) {
res *= 10;
res += (c - '0');
}
return res;
};
int ans = 0;
for(int i = 1; i < maxN; i++) {
string s = to_string(i);
s += s;
if(get_num(s) > n) continue;
++ans;
}
cout << ans;
} |
#include <bits/stdc++.h>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << endl
#define dump_4(x1, x2, x3, x4) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl
#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(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};
const ll LINF = 2e18;
const int INF = 1e9;
// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind {
vector<int> d;
UnionFind(int n = 0) : d(n, -1) {}
int find(int x) {
if (d[x] < 0) return x;
return d[x] = find(d[x]);
}
bool unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return false;
if (d[x] > d[y]) swap(x, y);
d[x] += d[y];
d[y] = x;
return true;
}
bool same(int x, int y) { return find(x) == find(y); }
int size(int x) { return -d[find(x)]; }
};
using pll = pair<ll, ll>;
using Edge = pair<double, pll>;
void solve(ll N, std::vector<ll> X, std::vector<ll> Y) {
auto dist = [&](ll i, ll j) -> double {
return sqrt(pow(X.at(i) - X.at(j), 2) + pow(Y.at(i) - Y.at(j), 2));
};
vector<Edge> edges;
ll s = N, t = N + 1;
rep(i, N) {
edges.push_back(Edge(100.0 - Y.at(i), {s, i}));
edges.push_back(Edge(Y.at(i) + 100.0, {t, i}));
FOR(j, i + 1, N) { edges.push_back(Edge(dist(i, j), {i, j})); }
}
sort(all(edges));
UnionFind uf(N + 2);
double r = 0.0;
for (auto &[d, p] : edges) {
uf.unite(p.first, p.second);
if (uf.same(s, t)) {
r = d / 2.0;
break;
}
}
cout << r << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
ll N;
scanf("%lld", &N);
std::vector<ll> x(N);
std::vector<ll> y(N);
for (int i = 0; i < N; i++) {
scanf("%lld", &x[i]);
scanf("%lld", &y[i]);
}
solve(N, std::move(x), std::move(y));
return 0;
}
| #include <iostream>
#include <cstdlib>
#include <bitset>
#include <map>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>
using namespace std;
#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecdouble vector<double>
#define vecchar vector<char>
#define vecstr vector<string>
#define vec2str vector<vector<string>>
#define vecbool vector<bool>
#define vec2bool vector<vector<bool>>
#define pairll pair<ll,ll>
#define vecpairll vector<pair<long long,long long>>
#define vec2pairll vector<vector<pair<long long,long long>>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)
#define INF 1000000000000
#define Pi 3.1415926535897932384626
ll gcd(ll a, ll b)
{
if (min(a, b) == 0)
return max(a, b);
return gcd(min(a, b), max(a, b) % min(a, b));
}
ll lcm(ll a, ll b)
{
ll buf = gcd(a, b);
return abs(a*b) / buf;
}
int main() {
ll n, m, ans = 0;
string s = "No";
bool flag = false;
cin >> n;
vecll a(n), b(n);
forll(i, 0, n)
cin >> a[i];
forll(i, 0, n)
cin >> b[i];
forll(i, 0, n)
{
ans += a[i] * b[i];
}
if (ans == 0)
s = "Yes";
cout << s;
} |
#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 main(void) {
int t;
cin >> t;
rep(loop, t) {
int n;
cin >> n;
string s1, s2, s3;
cin >> s1 >> s2 >> s3;
cout << string(n, '1') + string(n, '0') + "1" << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
// シグマの式変形
// ソートすることで絶対値を外せる
int main() {
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
sort(a.begin(), a.end());
vector<ll> s(n + 1, 0);
rep(i, n) s[i + 1] = s[i] + a[i];
ll ans = 0;
rep(i, n) ans += a[i] * i - s[i];
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << (n-1) << endl;
} | #include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
const int MOD = 1000000007;
void solve(){
int n;
cin>>n;
int ans = n/100;
if(n%100 != 0){
ans++;
}
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt","r", stdin);
freopen("output.txt","w", stdout);
#endif
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
|
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <stdio.h>
constexpr int HeighestDim = 505000;
int n, m, k;
long long int res[101];
int dim_a = 0, dim_b = 0;
int A[HeighestDim + 1], B[HeighestDim];
void mult_a(int v){
for(int i = dim_a, j = i - v; j >= 0; --i, --j){ A[i] -= A[j]; if(A[i] < 0) A[i] += m; }
}
void div_a(int v){
for(int i = v, j = 0; i <= dim_a; ++i, ++j){
A[i] += A[j]; if(A[i] >= m) A[i] -= m;
}
}
void mult_b(int v){
dim_b += v;
for(int i = dim_b, j = i - v; j >= 0; --i, --j){
B[i] -= B[j]; if(B[i] < 0) B[i] += m;
}
}
void div_b(int v){
for(int i = v, j = 0; i <= dim_b; ++i, ++j){
B[i] += B[j]; if(B[i] >= m) B[i] -= m;
}
}
int len = 0;
char Buffer[20];
char Output[1500];
int main(void){
A[0] = 1; B[0] = 1;
scanf("%d%d%d", &n, &k, &m);
if(n == 1){ printf("%d\n", k); return 0; }
else if(n == 2){ printf("%d\n%d\n", k, k); return 0; }
else if(n == 3){
printf("%d\n%d\n%d\n", k, k * static_cast<long long int>(k + 2) % m, k);
return 0;
}
res[1] = k; res[n] = k; ++k;
const int hd = (n >> 1) + (n & 1);
const int nmt = n - 2;
{
int i, j;
for(i = 1, j = k; i <= hd; ++i, j += k){ dim_a += j; mult_a(j); div_a(i); }
for(; i <= nmt; ++i, j += k){ mult_a(j); div_a(i); }
mult_b(k); div_b(1);
}
for(int i = 2, j = n - 1, I = 2 * k, J = k * (n - 2); ; I += k, J -= k){
long long int res_v = 0;
for(int d = 0; d <= dim_b; ++d) res_v += static_cast<long long int>(A[d]) * B[d] % m;
if(res_v) res_v = (k * res_v - 1) % m; else res_v = m - 1;
res[i] = res_v; res[j--] = res_v;
if(i + 1 > j) break;
mult_a(j); div_a(J);
mult_b(I); div_b(i++);
}
for(int i = 1; i <= n; ++i){
if(res[i]){
int l = 0;
do { Buffer[l++] = res[i] % 10; res[i] /= 10; } while(res[i]);
while(l--) Output[len++] = Buffer[l] ^ '0';
}
else Output[len++] = '0';
Output[len++] = '\n';
}
fwrite(Output, 1, len, stdout);
return 0;
} | #include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>
using namespace std;
int main(int argc, char** argv) {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(12);
int N, K, M;
cin >> N >> K >> M;
int MX = N * (N + 1) / 2 * K;
vector<vector<long long>> dp(N + 1, vector<long long>(MX + 1, 0));
dp[0][0] = 1;
vector<long long> cnts(N + 1, 0);
for (int i = 1; i <= N; ++i) {
fill(cnts.begin(), cnts.end(), 0);
for (int j = 0; j <= MX; ++j) {
int x = j % i;
(cnts[x] += dp[i - 1][j]) %= M;
if (j - (K + 1) * i >= 0) {
(cnts[x] += M - dp[i - 1][j - (K + 1) * i]) %= M;
}
dp[i][j] = cnts[x];
}
}
for (int i = 1; i <= N; ++i) {
long long res = 0;
for (int j = 0; j <= MX; ++j) {
(res += dp[i - 1][j] * dp[N - i][j]) %= M;
}
(res *= K + 1) %= M;
(res += M - 1) %= M;
cout << res << '\n';
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
long long s3 = 3, s5 = 5;
for (int i = 1; s3 < 1e18; ++i) {
s5 = 5;
for (int j = 1; s5 < 1e18; ++j) {
if (s3 + s5 == n) {
cout << i << " " << j << '\n';
return 0;
}
s5 *= 5;
}
s3 *= 3;
}
cout << -1 << "\n";
}
| // Author: Vinay Khilwani
// Language: C++
// @vok8: Codeforces, AtCoder, LeetCode, HackerEarth, TopCoder, Google, FB, CSES, Spoj, GitHub
// @vok_8: CodeChef, GFG
// @vok8_khilwani: HackerRank
// Never Stop Trying.
// Trying to be Better than Myself.
// while(true)
// {
// if(AC)
// {
// break;
// }
// else if(Contest Over)
// {
// Try.
// Check out Editorial.
// Understand.
// Find out your Mistake.
// Learn the topic (if new).
// Solve Problems on that topic (if new).
// Upsolve that problem.
// break;
// }
// else
// {
// Try.
// Use Pen-Paper.
// Find errors, edge cases, etc.
// continue;
// }
// }
// Optimizations
// #pragma GCC optimize("O2")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("avx2")
// #pragma GCC optimize("Os")
// Libraries
#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;
// Debugging
#define dbg(a) cerr<<a<<"\n";
#define debug_a(a) for(auto x:a) {cerr<<x<<" ";} cerr<<"\n";
#define debug_b(a) for(auto x:a) {cerr<<"["<<x.first<<", "<<x.second<<"]"<<"\n";} cerr<<"\n";
#define debug_c(a) for(auto x:a) {debug_a(x)} cerr<<"\n";
#define debug_d(a) for(auto x:a) {debug_b(x)} cerr<<"\n";
#define debug_e(a) cerr<<"["<<a.first<<", "<<a.second<<"]"<<"\n";
// Defines
#define fast ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL);
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define fr(i,a,n,b) for(int i=a; i<n; i+=b)
#define rfr(i,a,n,b) for(int i=a; i>=n; i-=b)
#define IN cin>>
#define OUT cout<<
#define nl "\n"
#define sz(a) int(a.size())
#define all(a) (a).begin(),(a).end()
#define each(a,b) for(auto &a:b)
#define pb push_back
#define set_bits(a) __builtin_popcountll(a)
#define ar array
#define write(a) for(auto x:a) {OUT x<<" ";} OUT endl;
#define read(a) for(auto &x:a) {IN x;}
// #define oset tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
using ll=long long int;
using ld=long double;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vi=vector<int>;
const ll mod=(ll)(1e9)+7LL;
const ll M=998244353LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ld pi=acos(-1);
// General Functions
ll gcd(ll a, ll b)
{
return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo) //Fast Power
{
ll ans=1LL;
while(power>0LL)
{
if(power%2LL==1LL)
{
ans=(ans*B)%modulo;
}
B=(B*B)%modulo;
power/=2LL;
}
return ans;
}
bool isPrime(ll n)
{
if(n<=1LL)
{
return false;
}
if(n<=3LL)
{
return true;
}
if(n%2==0LL || n%3==0LL)
{
return false;
}
for(ll i=5LL; (i*i)<=n; i+=6LL)
{
if(n%i==0LL || n%(i+2LL)==0LL)
{
return false;
}
}
return true;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll get_rand(ll l, ll r)
{
uniform_int_distribution<ll> uid(l,r);
return uid(rng);
}
void vok()
{
fast
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
freopen("error.txt","w",stderr);
#endif
}
// Global Variables
const int mxN=int(1e5)+100;
// Solver Function(s)
void solve()
{
string s;
IN s;
OUT s[1]<<s[2]<<s[0]<<nl;
}
// Main Function
int main()
{
vok();
int t=1;
// IN t;
while(t--)
{
solve();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
signed main(){
int A, B, C;
scanf("%d%d%d", &A, &B, &C);
if(A * A + B * B < C * C){
printf("Yes\n");
}
else{
printf("No\n");
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;
// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false)
template<typename T, typename... Ts> void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
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<typename T, typename... Ts> void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; }
template<typename... Ts> void input(Ts&... ts) { (cin >> ... >> ts); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int a, b, c;
input(a, b, c);
print(a * a + b * b < c * c ? "Yes" : "No");
return 0;
}
|
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
int a[22];
int st[22];
int orr[22];
int xorr;
int cnt;
int temp;
long long min;
int aa = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++){
scanf("%d", &a[i]);
}
for (int i = 0; i < (1 << (n-1)); i++){
cnt = 0;
for (int j = 0; j < (n-1); j++){
if (i >> j & 1){
st[j] = 1;
cnt++;
} else{
st[j] = 0;
}
}
for (int j = 0; j < n; j++){
orr[j] = 0;
}
temp = 0;
aa = 1;
for (int j = 0; j < n; j++){
if (aa != 1){
orr[temp] = a[j] | orr[temp];
} else{
orr[temp] = a[j];
aa = 0;
}
if (st[j] == 1) {
temp++;
aa = 1;
}
}
xorr = orr[0];
for (int j = 1; j <= cnt; j++){
xorr = xorr ^ orr[j];
}
if (i == 0){
min = xorr;
} else{
if (min > xorr) {
min = xorr;
}
}
}
printf("%lld", min);
} | /**
* author: Takeda Takumi
* created: 30.03.2021 16:14:34
**/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for (int i = s; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, 0, n) cin >> a[i];
int ans = 1<<30;
rep(s, 0, 1<<(n-1))
{
int now = 0;
int o = 0;
rep(i,0,n)
{
o |= a[i];
if(s>>i&1){
now ^= o;
o = 0;
}
}
now ^= o;
ans = min(ans, now);
}
cout << ans << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
typedef unsigned long long ull;
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define f(i,a,b) for(ll i=a;i<=b;i++)
// #define testcases ll t;cin>>t;while(t--)
#define dec(x) greater<x>()
/*** Define fues ***/
#define mx 200005
#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-7
#define size1 100005
const char nl = '\n';
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mem(name, fue) memset(name, fue, sizeof(name))
/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;
/*** Sorts ***/
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
inline bool cmp(pll a, pll b) { if (a.ff == b.ff)return a.ss < b.ss; return a.ff > b.ff; }
#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'
#define case cout << "Case " << t++ << ": "
/*** Functions
ll BigMod(ll base, ll pow, ll modfue){ if (pow == 0) return 1; ll ans = BigMod(base, pow / 2, modfue);ll total = ((ans % modfue) * (ans % modfue)) % modfue; if(pow % 2 == 0) return total; else{ return (total * (base % modfue) ) % modfue; } }
ll InverseMod(ll base, ll pow) { if(pow == 0) return 1; ll ans = InverseMod(base, pow / 2); ans = (ans * ans) % mod; if(pow & 1){ return (ans * base) % mod; } else{ return ans; } }
bool checkprime(ll num) { if(num < 2) return false; for(ll i = 2; i * i <= num; i++){ if(num % i == 0) return false; } return true; }
ll EularPHI(ll num) { double ans = num; for(ll i = 2; i * i <= num; i++){ if(num % i == 0){ while (num % i == 0) { num /= i; } ans *= (1.0 - (1.0 / (double)i)); } } if(num > 1) ans *= (1.0 - (1.0 / (double)num)); return (ll)ans; }
ll sumofdigit(ll n){ll sum=0;while(n){sum=sum+n%10;n=n/10;}return sum;}
ll countDigit(ll n) { if (n == 0) return 0; return 1 + countDigit(n / 10); }
ll countDigit(ll n) { return floor(log10(n) + 1); } //only positive
***/
template <class T> inline T gcd(T a, T b) {if (b == 0)return a; return gcd(b, a % b);}
template <class T> inline T lcm(T a, T b) {return a * b / gcd<T>(a, b);}
template <class T> inline T power(T b, T p) {ll ans = 1; while (p--) ans *= b; return ans;}
void solve()
{
string s;
cin>>s;
string find="ZONe";
ll n=s.size();
if(n<4)
{
cout<<0;
return;
}
ll c=0;
loop(i,0,n-3)
{
string r=s.substr(i,4);
// cout<<i<<" "<<r<<nl;
if(r==find)c++;
}
cout<<c;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll t=1;
// cin>>t;
while(t--)
{
solve();
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int count=0;
for(int i=0;i<9;i++){
if(s.at(i)=='Z'){
if(s.at(i+1)=='O'){
if(s.at(i+2)=='N'){
if(s.at(i+3)=='e'){
count++;
}
}
}
}
}
cout << count << endl;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
mt19937 rand_mt;
const int XYMAX = 10000;
class xyr{
public:
int x;
int y;
int r;
int index;
int a;
int b;
int c;
int d;
void print(){
cout << a << " "
<< b << " "
<< c << " "
<< d << endl;
}
void read(){
cin >> x >> y >> r;
}
void initialize(){
a = x;
b = y;
c = x+1;
d = y+1;
}
bool overlap(xyr& other){
if(a < other.c && c > other.a && d > other.b && b < other.d) return true;
return false;
}
bool isValid(){
if(a < 0 || a >= c) return false;
if(b < 0 || b >= d) return false;
if(c < a || c >= XYMAX) return false;
if(d < b || d >= XYMAX) return false;
return true;
}
void update_1();
void update_2();
};
void xyr::update_1(){
auto i_change = rand_mt() % 4;
if (i_change == 0){ a--;}
else if(i_change == 1){ b--;}
else if(i_change == 2){ c++;}
else if(i_change == 3){ d++;}
}
void xyr::update_2(){
auto i_change = rand_mt() % 4;
if (i_change == 0){ a = rand_mt() % a;}
else if(i_change == 1){ b = rand_mt() % b;}
else if(i_change == 2){ c = rand_mt() % c;}
else if(i_change == 3){ d = rand_mt() % d;}
}
int main()
{
// Input
int n;
cin >> n;
vector<xyr> XYR(n);
for(int i=0; i<n; i++){
XYR[i].read();
XYR[i].index = i;
XYR[i].initialize();
}
// sort(XYR.begin(), XYR.end(), [](xyr& a, xyr& b){return a.r < b.r;});
for(int i_try=0; i_try<100000; i_try++){
auto& p = XYR[i_try%n];
auto prev = p;
p.update_1();
bool isValid = p.isValid();
for(int j=0; j<n && isValid; j++){
if(p.index == XYR[j].index) continue;
if(p.overlap(XYR[j])) isValid = false;
}
if(!isValid) p = prev;
}
// Output
if (1){
sort(XYR.begin(), XYR.end(), [](xyr& a, xyr& b){return a.index < b.index;});
for(int i=0;i<n;i++){
XYR[i].print();
}
}
return 0;
}
| #include<bits/stdc++.h>
#define w(x) int x; cin>>x; for(int tc=1;tc<=x;tc++)
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pb push_back
#define pqg priority_queue<int>
#define pqs priority_queue<int,vector<int>,greater<int>>
#define mpii map<int,int>
#define endl "\n"
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define mod 1000000007
#define inp(x) cin>>x;
using namespace std;
void solve(int tc) {
int a, b, c;
cin >> a >> b >> c;
int ans;
if (c == 0) {
if (a > b) {
ans = 1;
} else
ans = 0;
} else {
if (b > a) {
ans = 0;
} else {
ans = 1;
}
}
if (ans == 1) {
cout << "Takahashi" << endl;
} else {
cout << "Aoki" << endl;
}
}
int32_t main() {
FIO
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
// w(x){
solve(1);
// }
return 0;
} |
#include<iostream>
#include<vector>
using i64 = int64_t;
template<i64 MOD>
struct modint{
i64 val;
modint():val(0){}
modint(i64 v):val(v<0?(-v)%MOD:v%MOD){}
operator i64(){return val;}
modint &operator += (modint other){this->val+=other.val;if(this->val>=MOD)this->val-=MOD;return *this;}
modint &operator -= (modint other){this->val-=other.val;if(this->val<0)this->val+=MOD;return *this;}
modint &operator *= (modint other){this->val*=other.val;if(this->val>=MOD)this->val%=MOD;return *this;}
modint &operator /= (modint other){this->val*=other.inverse();if(this->val>=MOD)this->val%=MOD;return *this;}
modint operator + (modint other)const{return modint(val)+=other;}
modint operator - (modint other)const{return modint(val)-=other;}
modint operator * (modint other)const{return modint(val)*=other;}
modint operator / (modint other)const{return modint(val)/=other;}
template<class T>modint operator + (T other)const{return modint(val)+=(modint)other;}
template<class T>modint operator - (T other)const{return modint(val)-=(modint)other;}
template<class T>modint operator * (T other)const{return modint(val)*=(modint)other;}
template<class T>modint operator / (T other)const{return modint(val)/=(modint)other;}
template<class T>
modint mpow(T _n)const{i64 n = _n;modint res(1),base(val);while(n){if(n&1)res*=base;base *= base;n >>= 1;}return res;}
template<class T,class U>
static modint mpow(T t,U u){return modint(t).mpow(u);}
modint inverse()const{return mpow(val,MOD-2);}
friend std::ostream &operator << (std::ostream& os,modint mo){return os<<mo.val;}
friend std::istream &operator >> (std::istream& is,modint& mo){return is>>mo.val;}
};
constexpr int MOD = 998244353;
using mint = modint<MOD>;
mint operator""_m(unsigned long long x){return (mint)x;}
#define rep(i,n) for(int i=0;i<(int)n;++i)
signed main(){
int n,k;
std::cin>>n>>k;
std::vector<mint> a(n);
for(auto& ai:a)std::cin>>ai;
std::vector<mint> fac(k+1),inv(k+1),finv(k+1);
fac[1]=inv[1]=finv[0]=finv[1]=1;
for(int i=2;i<=k;++i){
fac[i]=fac[i-1]*i;
inv[i]=MOD-inv[MOD%i]*(MOD/i);
finv[i]=finv[i-1]*inv[i];
}
std::vector<mint> ushi(k+1);
rep(j,k+1)rep(i,n)ushi[j]+=(a[i]*2_m).mpow(j);
std::vector<mint> tapu(k+1);
rep(j,k+1)rep(i,n)tapu[j]+=a[i].mpow(j)*finv[j];
auto solve = [&](i64 x){
mint ans = 0;
for(int k=0;k<=x;++k){
ans += tapu[k]*tapu[x-k];
}
ans *= fac[x];
ans -= ushi[x];
ans /= 2;
return ans;
};
for(int x=1;x<=k;++x)
std::cout<<solve(x)<<'\n';
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5+8, inf = 1e18+9, mod = 998244353;
int n, k, a[maxn], sa[312][maxn], sb[312][maxn], C[312][312];
void solve() {
int i, j, ans = 0, inv2 = (mod - mod / 2);
cin >> n >> k;
for (i = 1; i <= 300; i++) C[i][i] = C[i][0] = 1;
for (i = 2; i <= 300; i++) for (j = 1; j < i; j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
for (i = 1; i <= n; i++) cin >> a[i], sa[0][i] = 1, sb[0][i] = 1;
for (i = 1; i <= k; i++) for (j = 1; j <= n; j++) sa[i][j] = (sa[i - 1][j] * a[j]) % mod, sb[i][j] = (sb[i - 1][j] * 2 * a[j]) % mod;
for (i = 0; i <= k; i++) for (j = n - 1; j >= 1; j--) sa[i][j] = (sa[i][j] + sa[i][j + 1]) % mod, sb[i][j] = (sb[i][j] + sb[i][j + 1]) % mod;
for (int kk = 1; kk <= k; kk++) {
for (ans = i = 0; i <= kk; i++) ans = (ans + (((C[kk][i] * sa[i][1]) % mod) * sa[kk - i][1]) % mod) % mod;
cout << (inv2 * (mod + ans - sb[kk][1])) % mod << endl;
}
}
signed main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); //cout << fixed << setprecision(15);
int t = 1; //cin >> t;
while (t--) solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n;
cin>>n;
int l,r,ans=0;
while(n--){
cin>>l>>r;
ans+=(l+r)*(r-l+1)/2;
}
cout<<ans;
return 0;
} | #include<bits/stdc++.h>
#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++)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
void solve(){
/* code */
double sx,sy,gx,gy; cin>>sx>>sy>>gx>>gy;
cout<<fixed<<setprecision(9)<< sx+sy*(gx-sx)/(gy+sy);
}
int main()
{
DONTSYNC;
// TEST{
solve();
// }
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
//freopen("1.in","r",stdin);
//ios::sync_with_stdio(false);
char X[66];
ll M;
scanf("%s",X);cin>>M;
int n=strlen(X);
int max=0;
for(int i=0;i<n;i++){
if(X[i]-'0'>max)max=X[i]-'0';
}
ll count=0;
// for(int base=max+1;;base++){
// //cout<<base<<endl;
// ll res=0;
// int flag=0;
// for(int i=0;i<n;i++){
// res=res*base+X[i]-'0';
// if(res>M){break;flag=1;}
// }
// //cout<<res<<endl;
// if(flag==0){
// if(res<=M)count++;else break;
// }else break;
// }
if(n==1) {
ll base=max+1;
__int128 res=0;
int flag=0;
for(int i=0;i<1;i++){
res=res*base+X[i]-'0';
if(res>M){flag=1;break;}
}
//cout<<res<<endl;
if(flag==0){
if(res<=M)count++;else {cout<<0;return 0;}
}else {cout<<0;return 0;}
cout<<1;
}
else
{ll base=max+1;
__int128 res=0;
int flag=0;
for(int i=0;i<n;i++){
res=res*base+X[i]-'0';
if(res>M){flag=1;break;}
}
//cout<<res<<endl;
if(flag==0){
if(res<=M)count++;else {cout<<0;return 0;}
}else {cout<<0;return 0;}
ll l=max,r=M+1;
while(l<=r){
ll mid=l+r>>1;
ll base=mid;
__int128 res=0;
int flag=0;
for(int i=0;i<n;i++){
res=res*base+X[i]-'0';
if(res>M){flag=1;break;}
}
//cout<<res<<endl;
if(flag==0){
if(res<=M)l=mid+1;else {r=mid-1;}
}else {r=mid-1;}
}
count+=(r-max-1);
cout<<count;}
}
| //{{{
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VLL = vector<LL>;
using vi = vector<int>;
using pii = pair<int, int>;
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#ifdef LOCAL
#include "prettyprint.hpp"
// clang-format off
void _print() { cerr << "]\033[0m\n"; }
template <typename T> void __print(T x) { cerr << x; }
template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#define debug(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m["; _print(x)
#define debug_arr(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m" << (x) << "\033[0m\n"
#else
#define debug(x...)
#define debug_arr(x...)
#endif
// clang-format on
//}}}
string x;
LL m;
bool check(LL base)
{
__int128 b = base;
__int128 v = 1;
__int128 res = 0;
__int128 mm = __int128(m);
int n = sz(x);
for (int i = 0; i < n; i++)
{
__int128 dig = x[i] - '0';
if (v > m) return false;
res += dig * v;
v *= b;
}
return res <= mm;
}
int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
// freopen("out", "w", stdout);
#endif
while (cin >> x >> m)
{
int mx = -1;
reverse(all(x));
for (auto ch : x)
{
int d = ch - '0';
mx = max(mx, d);
}
if (check(mx + 1) == false)
{
cout << 0 << endl;
continue;
}
LL lo = mx + 1, hi = 3e18 + 100;
while (lo + 1 < hi)
{
LL mid = lo + (hi - lo) / 2;
bool ok = check(mid);
if (ok) lo = mid;
else
hi = mid;
}
debug(lo, hi);
if (lo >= 2e18)
{
cout << 1 << endl;
}
else
{
cout << lo - (mx + 1) + 1 << endl;
}
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
const int N = 1e5 + 5;
#define int long long int
int32_t main() {
IOS ;
// int t ; cin >> t ; while(t--) {}
int n ; cin >> n ; char c ;
int dp[4][n+1] ;
for(int i=0; i<4; i++) dp[i][0] = 0 ;
for(int i=1; i<=n; i++) {
cin >> c ;
dp[0][i] = dp[0][i-1] ;
dp[1][i] = dp[1][i-1] ;
dp[2][i] = dp[2][i-1] ;
dp[3][i] = dp[3][i-1] ;
if(c == 'A') dp[0][i]++ ;
else if(c == 'T') dp[1][i]++ ;
else if(c == 'C') dp[2][i]++ ;
else dp[3][i]++ ;
}
int cnt = 0 ;
for(int i=2; i<=n; i++) {
for(int j=1; j<i; j++) {
int x = dp[0][i] - dp[0][j-1] ;
int y = dp[1][i] - dp[1][j-1] ;
int z = dp[2][i] - dp[2][j-1] ;
int w = dp[3][i] - dp[3][j-1] ;
if(x == y and z == w) cnt++ ;
}
}
cout << cnt ;
return 0 ;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll> pql;
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef map<ll, ll> ml;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {return (a % b + b) % b;}
ll quo(ll a, ll b) {return (a - mod(a, b)) / b;}
template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;}
template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 2e5;
const ld eps = 1e-9;
const char newl = '\n';
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
string ans;
cin >> n;
vl a(2*n);
rep(i, 2*n) cin >> a[i];
vpl vec(2*n);
rep(i, 2*n) vec[i] = pl(a[i], i);
sort(all(vec));
vb plus(2*n, 1);
rep(i, n) plus[vec[i].second] = 0;
ll cnt = 0;
rep(i, 2*n) {
if(plus[i]) {
if(cnt >= 0) ans += '(';
else ans += ')';
cnt++;
}else {
if(cnt <= 0) ans += '(';
else ans += ')';
cnt--;
}
}
cout << ans << newl;
return 0;
} |
#include <bits/stdc++.h>
#include <climits>
#include <math.h>
#include <iomanip>
#include <algorithm>
#include <map>
#define rep(i,s,n) for (ll i = s; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
int main() {
int a,b,c;
cin>>a>>b>>c;
if(a==b){
if(c==0){
cout<<"Aoki"<<endl;
}else{
cout<<"Takahashi"<<endl;
}
}else if(a>b){
cout<<"Takahashi"<<endl;
}else{
cout<<"Aoki"<<endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
int a,b,c;
cin >> a >> b >> c;
int d = min(a,b);
a -= d;
b -= d;
if(c==0){
if(a-1<0) cout << "Aoki" << endl;
else cout << "Takahashi" << endl;
}
if(c==1){
if(b-1<0) cout << "Takahashi" << endl;
else cout << "Aoki" << endl;
}
} |
#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
int dx[4] = {0,1,0,-1};
int dy[4] = {-1,0,1,0};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int H, W, N, M;
cin >> H >> W >> N >> M;
vector<vector<bool>> fi(H, vector<bool>(W, true));
queue<tuple<int, int, int>> q;
vector<int> A(N), B(N);
vector<int> C(M), D(M);
rep(i,N){
cin >> A[i] >> B[i];
--A[i], --B[i];
}
rep(i,M){
cin >> C[i] >> D[i];
--C[i], --D[i];
fi[C[i]][D[i]] = false;
}
std::chrono::system_clock::time_point chrono_start =std::chrono::system_clock::now();
vector<vector<vector<bool>>> used(4, vector<vector<bool>>(H, vector<bool>(W)));
rep(i,N){
used[0][A[i]][B[i]] = true;
used[1][A[i]][B[i]] = true;
used[2][A[i]][B[i]] = true;
used[3][A[i]][B[i]] = true;
rep(d,4){
int nh = A[i] + dx[d], nw = B[i] + dy[d];
if(nh < 0 or nh >= H or nw < 0 or nw >= W or !fi[nh][nw]) continue;
q.emplace(d, nh, nw);
}
}
int cnt = 0;
while(!q.empty()){
cnt++;
auto [dir, h, w] = q.front(); q.pop();
if(used[dir][h][w]) continue;
used[dir][h][w] = true;
int nh = h + dx[dir], nw = w + dy[dir];
if(nh < 0 or nh >= H or nw < 0 or nw >= W or !fi[nh][nw]) continue;
if(used[dir][nh][nw]) continue;
q.emplace(dir, nh, nw);
}
int ans = 0;
rep(i,H) rep(j,W){
bool ok = false;
rep(k,4) if(used[k][i][j]) ok = true;
if(ok) ans++;
}
cout << ans << endl;
auto chrono_end = std::chrono::system_clock::now();
cerr << fixed << setprecision(5);
cerr << std::chrono::duration_cast<std::chrono::milliseconds>(chrono_end - chrono_start).count() << " ms" << endl;
return 0;
}
| #include <bits/stdc++.h>
#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair
using namespace std;
void setIO(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
}
const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;
const ll _INF = 1e18;
const int N = 1507;
int a[N][N];
bool vld[N][N];
int main(){
setIO();
int h, w, n, m;
cin >> h >> w >> n >> m;
for (int i = 0; i < n; i++){
int r, c;
cin >> r >> c;
a[r][c] = 1;
}
for (int i = 0; i < m; i++){
int r, c;
cin >> r >> c;
a[r][c] = -1;
}
// right
for (int i = 1; i <= h; i++){
bool ok = 0;
for (int j = 1; j <= w; j++){
if (a[i][j] == 1) ok = 1;
else if (a[i][j] == -1) ok = 0;
vld[i][j] |= ok;
}
}
// left
for (int i = 1; i <= h; i++){
bool ok = 0;
for (int j = w; j >= 1; j--){
if (a[i][j] == 1) ok = 1;
else if (a[i][j] == -1) ok = 0;
vld[i][j] |= ok;
}
}
// down
for (int i = 1; i <= w; i++){
bool ok = 0;
for (int j = 1; j <= h; j++){
if (a[j][i] == 1) ok = 1;
else if (a[j][i] == -1) ok = 0;
vld[j][i] |= ok;
}
}
// up
for (int i = 1; i <= w; i++){
bool ok = 0;
for (int j = h; j >= 1; j--){
if (a[j][i] == 1) ok = 1;
else if (a[j][i] == -1) ok = 0;
vld[j][i] |= ok;
}
}
int ans = 0;
for (int i = 1; i <= h; i++){
for (int j = 1; j <= w; j++){
if (vld[i][j]) ans++;
}
}
cout << ans << endl;
}
|
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define mem0(x) memset(x, 0, sizeof (x))
#define mem1(x) memset(x, -1, sizeof (x))
typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<vii> vvii;
typedef vector <ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int T=1, n;
while (T--){
cin >> n;
ll ans = 0;
vll acum(n,0);
vi mxpos(n,0);
ll mx = -1e18;
ll pos = -1;
for (int i = 0; i < n; ++i) {
int aux; cin >> aux;
acum[i] = aux;
if (i) acum[i] += acum[i-1];
if (acum[i] > mx){
pos = i;
mx = acum[i];
}
mxpos[i] = pos;
}
ll curr = 0;
for (int i = 0; i < n; ++i) {
ans = max(ans, curr + acum[mxpos[i]]);
curr += acum[i];
}
cout << ans << "\n";
}
} | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
int main() {
lint N;
cin >> N;
vector<lint> A(N);
for(auto& elem : A) cin >> elem;
P ans = {0,0};
for(lint i=2; i<=1000; i++) {
lint counter = 0;
for(auto a : A) {
counter += (a%i == 0);
}
ans = max(ans, P(counter, i));
}
cout << ans.second << endl;
} |
#include <array>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <functional>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;
using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vpii = vector<pii>; using vpll = vector<pll>;
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (const auto &x : v) os << x << " "; return os; }
void solve() {
int n;
cin >> n;
vector<ll> a(n), b(n), x(n);
ll suma = 0;
for (int i=0; i<n; i++) {
cin >> a[i] >> b[i];
suma += a[i];
x[i] = 2*a[i] + b[i];
}
sort(x.rbegin(), x.rend());
ll score = -suma;
int i = 0;
while (score <= 0) {
score += x[i];
i++;
}
cout << i << endl;
}
int main() {
solve();
return 0;
}
| //clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
using namespace std;
#define Fio \
ios_base::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(nullptr)
#define f(i, n) for (long long int i = 0; i < n; i++)
#define ll long long int
#define fo(i, a, b) for (long long int i = a; i <= b; i++)
#define w(t) \
int t; \
cin >> t; \
while (t--)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vl vector<long long int>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long int>>
#define mii map<int, int>
#define umii unordered_map<int, int>
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define newl cout<<"\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll inf = 1e9 + 7;
const ll mod = 1e9 + 7;
#define MAX 100005
ll mini(ll a,ll b){
if(a>=b)return b;
return a;
}
ll maxi(ll a,ll b){
if(a>=b)return a;
return b;
}
bool cmp(pair<ll,ll> a,pair<ll,ll>b){
return a.fi>b.fi;
}
int main(){
Fio;
ll n;
cin>>n;
vector<ll>A;
ll ao = 0,taka = 0;
fo(i,1,n){
ll x,y;
cin>>x>>y;
A.pb(2*x+y);
ao+=x;
}
sort(A.rbegin(),A.rend());
ll ans = 0;
fo(i,0,n-1){
taka += A[i];
ans++;
if(taka>ao)break;
}
cout<<ans;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<vector<int>> psl(N, vector<int>(2));
vector<vector<int>> psr(N, vector<int>(2));
for (int i = 0; i < N; ++i) {
cin >> psr[i][0] >> psl[i][0];
psr[i][1] = i;
psl[i][1] = i;
// cout << ps[i][0];
// cout << ps[i][1];
// cout << endl;
}
sort(psl.begin(), psl.end(),
[](const vector<int> &alpha, const vector<int> &beta) {
return alpha[0] < beta[0];
});
sort(psr.begin(), psr.end(),
[](const vector<int> &alpha, const vector<int> &beta) {
return alpha[0] < beta[0];
});
if (psr[0][1] == psl[0][1]) {
if ((psr[0][0] + psl[0][0]) <= min(psr[1][0], psl[1][0])) {
cout << psr[0][0] + psl[0][0] << endl;
} else {
cout << min(max(psr[0][0],psl[1][0]), max(psr[1][0], psl[0][0])) << endl;
}
} else {
cout << max(psr[0][0], psl[0][0]) << endl;
}
}
| #include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
#define all(v) v.begin(), v.end()
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, b) for (ll i = a; i < b; ++i)
#define rep_down(i, a, b) for (ll i = a; i > b; --i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
#define vvvvll vector<vector<vector<vector<ll>>>>
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define vvvvdo vector<vector<vector<vector<double>>>>
#define vvvdo vector<vector<vector<double>>>
#define vvdo vector<vector<double>>
#define vdo vector<double>
#define maze(S, H, W) vector<vector<char>> S(H, vector<char>(W))
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>
constexpr ll INF = (1ll << 60);
// constexpr ll mod = 998244353;
// constexpr ll mod = 67280421310721;
// constexpr ll mod = 1e18+3;
ll mod = 1000000007;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T>
void pt(T val) {
cout << val << "\n";
}
template <typename T>
void pt_vll(vector<T> &v) {
ll vs = v.size();
rep(i, vs) {
cout << v[i];
if (i == vs - 1)
cout << "\n";
else
cout << " ";
}
}
template <typename T>
void pt_vvll(vector<vector<T>> &v) {
ll vs = v.size();
rep(i, vs) pt_vll(v[i]);
}
template <typename X, typename Y>
void pt_pair(pair<X, Y> val) {
cout << val.fi << " " << val.se << "\n";
}
template <typename X, typename Y>
void pt_vpair(vector<pair<X, Y>> &v) {
rep(i, v.size()) pt_pair(v[i]);
}
ll gcd(ll a, ll b) {
if (a % b == 0) return b;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
ll modpow(ll x, ll n) {
ll ret = 1;
if (x < 0) return 0ll;
while (n > 0) {
if (n & 1) ret = ret * x % mod;
x = x * x % mod;
n >>= 1;
}
return ret;
}
ll minv(ll a, ll m) { return modpow(a, m - 2); }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N;
cin >> N;
vll A(N), B(N);
rep(i, N) cin >> A[i] >> B[i];
ll ans = INF;
rep(i, N) { rep(j, N) if (i != j) chmin(ans, max(A[i], B[j])); }
rep(i, N) chmin(ans, A[i] + B[i]);
pt(ans);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(40)
const ll MOD = 1000000007;
const ll INF = (ll) 4e18;
long long extGCD(long long a, long long b, long long &x, long long &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
long long d = extGCD(b, a % b, y, x);
y -= a / b * x;
return d;
}
long long gcd(long long a, long long b) {
if (a < b)
swap(a, b);
long long c = a % b;
if (c == 0)
return b;
return gcd(b, c);
}
//! 方程式 ax = b (mod m) の解xを返す。
//! 見つからなかった場合 -1
long long mod_solver(long long a, long long b, long long m) {
if (a < 0) {
a = (m - (abs(a) % m)) % m;
}
if (b < 0) {
b = (m - (abs(b) % m)) % m;
}
a %= m;
b %= m;
if (b == 0)
return 0;
if (a == 0)
return -1;
long long g0 = gcd(m, gcd(a, b));
a /= g0;
b /= g0;
m /= g0;
long long x, y;
long long g1 = extGCD(a, m, x, y);
if (g1 != 1) {
return -1;
}
if (x < 0)
x += m;
return (x * b) % m;
}
ll solve() {
ll X, Y, P, Q;
cin >> X >> Y >> P >> Q;
ll ret = INF;
for (ll x = -Q + 1; x < Y; ++x) {
// 電車から見た相対位置がxとなるような最小値
//! 2*(X+Y)*t +X +x == P (mod P+Q)
ll t = mod_solver(2LL * (X + Y), P - X - x, P + Q);
if (t < 0)
continue;
ll ans = 2LL * (X + Y) * t + X;
if (x >= 0) {
ans += x;
}
ret = std::min(ret, ans);
}
if (ret == INF)
ret = -1;
return ret;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll Q;
cin >> Q;
REP(_, Q) {
ll ans = solve();
if (ans < 0) {
cout << "infinity" << endl;
}
else {
cout << ans << endl;
}
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int const p=1e9+7;
int f[1005][2][2],g[1005][2][2],h[1005][2][2];
int main()
{
int n;
char aa,ab,ba,bb;
cin>>n>>aa>>ab>>ba>>bb;
f[2][0][0]=f[2][0][1]=f[2][1][0]=f[2][1][1]=1;
g[2][0][0]=g[2][0][1]=g[2][1][0]=g[2][1][1]=1;
h[2][0][0]=h[2][0][1]=h[2][1][0]=h[2][1][1]=1;
int t0=aa-'A',t1=ab-'A',t2=ba-'A',t3=bb-'A';
for(int i=3;i<=n;i++)
{
for(int j=2;j<i;j++)
{
if(t0)f[i][0][0]=(f[i][0][0]+1ll*g[j][0][t0]*f[i-j+1][t0][0])%p;
else f[i][0][0]=(f[i][0][0]+1ll*h[j][0][t0]*f[i-j+1][t0][0])%p;
if(t1)f[i][0][1]=(f[i][0][1]+1ll*f[j][0][t1]*g[i-j+1][t1][1])%p;
else f[i][0][1]=(f[i][0][1]+1ll*h[j][0][t1]*f[i-j+1][t1][1])%p;
if(t2)f[i][1][0]=(f[i][1][0]+1ll*g[j][1][t2]*f[i-j+1][t2][0])%p;
else f[i][1][0]=(f[i][1][0]+1ll*h[j][1][t2]*f[i-j+1][t2][0])%p;
if(t3)f[i][1][1]=(f[i][1][1]+1ll*g[j][1][t3]*f[i-j+1][t3][1])%p;
else f[i][1][1]=(f[i][1][1]+1ll*h[j][1][t3]*f[i-j+1][t3][1])%p;
if(!t0)g[i][0][0]|=(g[j][0][0]&g[i-j+1][0][0]);
if(!t1)g[i][0][1]|=(g[j][0][0]&g[i-j+1][0][1]);
if(!t2)g[i][1][0]|=(g[j][1][0]&g[i-j+1][0][0]);
if(!t3)g[i][1][1]|=(g[j][1][0]&g[i-j+1][0][1]);
if(t0)h[i][0][0]|=(h[j][0][1]&h[i-j+1][1][0]);
if(t1)h[i][0][1]|=(h[j][0][1]&h[i-j+1][1][1]);
if(t2)h[i][1][0]|=(h[j][1][1]&h[i-j+1][1][0]);
if(t3)h[i][1][1]|=(h[j][1][1]&h[i-j+1][1][1]);
}
}
cout<<f[n][0][1];
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
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)
int main()
{
ll N;
cin >> N;
vector<ll> A(N), B(N);
for (ll i = 0; i < N; i++)
{
cin >> A.at(i);
}
reverse(A.begin(), A.end());
for (ll i = 0; i < N; i++)
{
cin >> B.at(i);
}
priority_queue<ll, vector<ll>, greater<ll>> pque;
ll AokiSum = 0;
for (ll i = 0; i < N; i++)
{
pque.push(A.at(i));
pque.push(B.at(i));
AokiSum += pque.top();
pque.pop();
}
ll S = accumulate(A.begin(), A.end(), 0LL) + accumulate(B.begin(), B.end(), 0LL);
ll ans = S - AokiSum;
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using pll = pair<ll, ll>;
using vll = vector<ll>;
#define endl "\n"
#define space " "
#define TLE_na_ho ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MAX_SIZE 1024
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define repe(i,a,n) for(ll i=a;i<=n;i++)
#define repr(i,a,n) for(ll i=a;i>=n;i--)
#define ain(arr,n) for(ll i1=0;i1<n;i1++ ) cin>>arr[i1]
#define aout(arr,n) for(ll i1=0;i1<n;i1++ ) cout<<arr[i1]<<space
ll testcases;
int main()
{
TLE_na_ho;
//READ THE QUESTION PROPERLY!!
testcases = 1;
//cin>>testcases;
while(testcases--)
{
ll n;
cin >> n;
ll a[n];
ll md = 0, cd = 0;
double ed = 0;
f(n)
{
cin >> a[i];
md += abs(a[i]);
cd = max(cd, abs(a[i]));
ed += a[i] * a[i];
}
cout << fixed << setprecision(9) << md << endl << sqrt(ed) << endl << cd << endl;
}
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
char ch[3];
for(ll i=0;i<3;i++) cin>>ch[i];
char c = ch[0];
if(ch[1]==c && ch[2]==c) cout<<"Won\n";
else cout<<"Lost\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
if(s[0]==s[1]&&s[1]==s[2])
cout<<"Won";
else
cout<<"Lost";
} |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 41;
typedef long long LL;
LL a[1 << (MAX_N / 2)], b[1 << (MAX_N / 2)];
LL item[MAX_N];
int generate_item(LL* s, int beg, int end) {
int len = 1 << (end - beg);
for (int i = 0; i < len; i++) {
for (int j = beg; j < end; j++)
s[i] += (1 << (j - beg)) & i ? item[j] : 0;
}
sort(s, s + len);
return len;
}
LL GCD(LL x, LL y) {
return y == 0 ? x : GCD(y, x % y);
}
LL LCM(LL x, LL y) {
return x * y / GCD(x, y);
}
const int MAX_CHAR_NUM = 4 * 1e5 + 10;
char tmp[MAX_CHAR_NUM];
char get_char(LL p) {
return p % 3 == 2 ? '0' : '1';
}
vector<int> getNext(const string& s) {
vector<int> ret(s.length(), 0);
if (ret.empty()) return ret;
for (size_t k1(1), kt(0); k1 < ret.size(); ++k1) {
while (kt && s[kt] != s[k1]) kt = ret[kt - 1];
if (s[kt] == s[k1]) ++kt;
ret[k1] = kt;
}
return ret;
}
vector<int> kmp(const string& s1, const string& s2) {
vector<int> ret;
int sl1(s1.length()), sl2(s2.length());
if (!(sl1 && sl2)) return ret;
vector<int> nv2(getNext(s2));
for (int k1(0), k2(0); k1 < sl1;) {
if (s1[k1] == s2[k2]) ++k1, ++k2;
else if (k2) k2 = nv2[k2 - 1];
else ++k1;
if (k2 == sl2) ret.push_back(k1 - k2), k2 = nv2[k2 - 1];
}
return ret;
}
int match_num(const string& s, const string& t) {
return kmp(s, t).size();
}
LL get_result(LL l, LL r, const string& t) {
int len = t.length();
if (r - l <= len) {
string s(1, get_char(l));
return match_num(s, t);
}
LL m = (l + r) / 2;
LL left_result = get_result(l, m, t);
LL right_result = get_result(m, r, t);
LL mid_result = 0;
int left_idx = max(l, m - len);
int right_idx = min(r, m + len);
// if (right_idx - left_idx >= len) {
// for (int i = left_idx; i < right_idx; i++)
// tmp[i - left_idx] = get_char(i);
//
// tmp[right_idx - left_idx] = 0;
//
// string mid_string(tmp);
//
// mid_result = match_num(mid_string, t);
// }
// return mid_result;
return left_result + right_result + mid_result;
}
int main() {
LL SRC = 10000000000L;
int N, p;
string T;
cin >> N >> T;
if (N == 1) {
cout << ((T[0] == '1') + 1) * SRC << endl;
return 0;
}
tmp[N] = 0;
for (p = 0; p < 3; p++) {
for (int i = 0; i < N; i++) tmp[i] = get_char(p + i);
string S(tmp);
if (S == T) break;
}
if (p == 3) puts("0");
else {
cout << SRC - (p + N - 1) / 3 << endl;
}
return 0;
}
| #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan0
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N, M;
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N >> M;
map<int, vector<int>> pawns;
rep(i, 0, M) {
int X, Y; cin >> X >> Y;
pawns[X].push_back(Y);
}
set<int> ans;
ans.insert(N);
fore(p, pawns) {
set<int> ng;
set<int> ok;
fore(y, p.second) {
if (ans.count(y - 1)) ok.insert(y);
else if (ans.count(y + 1)) ok.insert(y);
else ng.insert(y);
}
fore(i, ng) ans.erase(i);
fore(i, ok) ans.insert(i);
}
cout << ans.size() << endl;
}
|
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include<atcoder/all>
using namespace atcoder;
#endif
typedef long long ll;
typedef long double ld;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define all(x) x.begin(),x.end()
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
template<class... T>void input(T&... a){(cin >> ... >> a);};
#define INT(...) int __VA_ARGS__; input(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define STRING(...) string __VA_ARGS__; input(__VA_ARGS__)
void print(){cout << '\n';}
template<class T, class... Ts>void print(const T& a, const Ts&... b){cout << a; (cout << ... << (cout << ' ', b)); cout << '\n';}
template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> ostream& operator << (ostream& os, set<T>& set_var) {os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {os << *itr;++itr;if(itr != set_var.end()) os << ", ";itr--;}os << "}";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {os << "{";for(auto itr = map_var.begin(); itr != map_var.end(); itr++) {os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--;}os << "}";return os;}
#ifdef __LOCAL
void debug_out(){ cerr << endl;}
template < class Head, class... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...);}
#define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
template<class T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
#define pb push_back
#define eb emplace_back
#define elif else if
#define mp make_pair
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template<typename T> T gcd(T x, T y){if(x%y == 0)return y;return gcd(y, x%y);}
template<typename T> T gcd(vector<T> a){T res = a[0];for(auto &x: a)res = gcd(res, x);return res;}
template <typename T>T mypow(T x, ll n){T ret = 1;while(n > 0){if(n & 1)(ret *= x);(x *= x);n >>= 1;}return ret;}
#define endl '\n'
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
void solve(){
INT(a,b,c);
print(max({a+b,a+c,b+c}));
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << setprecision(20);
int codeforces = 1;
//cin >> codeforces;
while(codeforces--){
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int A,B,C;cin>>A>>B>>C;
int a=A+B;
int b=B+C;
int c=A+C;
if(A==B==C){
cout<<A+B;
}else{
int z=max(max(a,b),c);
cout<<z;
}
} |
#include <cstdio>
int N;
const int MAXN=2e5+7;
char buf[MAXN];
char pattern[MAXN];
using ll = long long int;
ll setu=1e10;
int main(){
scanf("%d\n",&N);
scanf("%s",buf);
if (N==1&&buf[0]=='1') {
puts("20000000000");
return 0;
}
else if (N==1&&buf[0]=='0'){
puts("10000000000");
return 0;
}
for(int i=0;i<N+6;i++){
if (i%3==0) pattern[i]='1';
else if (i%3==1) pattern[i]='1';
else pattern[i]='0';
}
int offset=0;
while(offset<3){
bool match=true;
for(int i=0;i<N;i++)
if (pattern[i+offset]!=buf[i]) {
match=false;
break;
}
if (match) break;
end: offset++;
}
out:
if (offset==3){
puts("0");
return 0;
}
ll len=(N+offset+2)/3;
ll ans=(setu-len)+1;
printf("%lld\n",ans);
return 0;
} | #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 ff first
#define ss second
#define int long long int
#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_popcountint(x)
#define zrobits(x) __builtin_ctzint(x)
#define mod 1000000007
#define INF 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) int x; cin>>x; while(x--)
#define LCM(a,b) ((a*b)/__gcd(a,b))
#define PI 2*acos(0.0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// If want to add duplicate values replace int with pair below
// and give the second pair value always unique in order to add duplicates in set.
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// W,N,E,S
int dx[] = { -1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
void c_p_c()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
// seive prime
void seive_prime(int N)
{
vector<bool>prime(N + 1, true);
vector<int>prime_no;
prime[0] = false;
prime[1] = false;
for (int i = 4; i <= N; i += 2)
{
prime[i] = false;
}
for (int i = 3; i * i <= N; i += 2)
{
if (prime[i])
{
int m = i * i;
while (m <= N)
{
prime[m] = false;
m += i;
}
}
}
int i = 0;
for (auto v : prime)
{
if (v)
prime_no.push_back(i);
i++;
}
// return prime_no;
}
// Primality Test
bool isPrime(int n)
{
if (n == 2)
return true;
for (int i = 2; i * i <= n; i++)
{
if (n % i == 0)
return false;
}
return true;
}
// Modular Exponentiation
int modularExpo(int a, int b, int modVal)
{
int res = 1;
while (b > 0)
{
if (b & 1)
{
res = (res * a) % modVal;
}
b = b >> 1;
a = (a * a) % modVal;
}
return (res % modVal);
}
// Euler Totient function
void find_phi(vector<int>&phi)
{
for (int i = 1; i < phi.size(); i++)
phi[i] = i;
for (int i = 2; i < phi.size(); i++)
{
if (phi[i] == i)
{
for (int j = i; j < phi.size(); j += i)
{
phi[j] = phi[j] - (phi[j] / i);
}
}
}
// for(int i=3; i<phi.size(); i++)
// {
// phi[i]+=phi[i-1];
// }
}
int32_t main()
{
c_p_c();
// int case_no = 1;
// w(t)
// {
// }
int n;
cin >> n;
int cnt[n + 1] = {0};
for (int i = 0; i < n; i++)
{
int a;
cin >> a;
cnt[a] += 1;
}
int flag = 1;
for (int i = 1; i <= n; i++)
{
if (cnt[i] > 1)
{
flag = 0;
break;
}
}
if (flag)
cout << "Yes";
else
cout << "No";
#ifndef ONLINE_JUDGE
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
#endif
return 0;
} |
// chrono::system_clock::now().time_since_epoch().count()
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define debug(x) cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MAXN = (int)1e6 + 5;
ll dp[MAXN];
int L, R;
ll ans;
void solve() {
cin >> L >> R;
for (int g = R; g >= 1; g--) {
int cnt = 0;
for (int i = g; i <= R; i += g) {
if (i >= L) {
cnt++;
}
dp[g] -= dp[i];
}
dp[g] += cnt * 1ll * cnt;
if (g > 1) {
ans += dp[g];
}
}
for (int a = L; a <= R; a++) {
for (int b = a; b <= R; b += a) {
if (a == 1 || b == 1) {
continue;
}
if (a == b) {
--ans;
}
else {
ans -= 2;
}
}
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
for (int i = 1; i <= tt; ++i) {
solve();
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
int l,r;
cin>>l>>r;
vector<ll> po(r+1,0);
ll ans=0;
for(int g=r;g>=2;g--){
po[g]=r/g-(l-1)/g;
po[g]*=po[g];
for(int g2=2*g;g2<=r;g2+=g){
po[g]-=po[g2];
}
ans+=po[g];
if(g>=l)ans-=r/g*2-1;
}
cout<<ans<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
namespace Sakurajima_Mai{
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(int i=a,bbb=b;i<=bbb;++i)//attention reg int or reg ll ?
#define repd(i,a,b) for(int i=a,bbb=b;i>=bbb;--i)
#define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define ce(i,r) i==r?'\n':' '
#define pb push_back
#define all(x) x.begin(),x.end()
#define gmn(a,b) a=min(a,b)
#define gmx(a,b) a=max(a,b)
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const int infi=1e9;//infi较大,注意涉及inf相加时爆int
const ll infl=4e18;
inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; }
inline ll pos_mod(ll a,ll b){ return (a%b+b)%b; }
//std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0));
}
using namespace Sakurajima_Mai;
namespace Fast_Read{
inline int qi(){
int f=0,fu=1; char c=getchar();
while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
return f*fu;
}
inline ll ql(){
ll f=0;int fu=1; char c=getchar();
while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
return f*fu;
}
inline db qd(){
char c=getchar();int flag=1;double ans=0;
while((!(c>='0'&&c<='9'))&&c!='-') c=getchar();
if(c=='-') flag=-1,c=getchar();
while(c>='0'&&c<='9') ans=ans*10+(c^48),c=getchar();
if(c=='.'){c=getchar();for(int Bit=10;c>='0'&&c<='9';Bit=(Bit<<3)+(Bit<<1)) ans+=(double)(c^48)*1.0/Bit,c=getchar();}
return ans*flag;
}
}
namespace Read{
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define rai(x,a,b) repi(i,a,b) x[i]=qi()
#define ral(x,a,b) repi(i,a,b) x[i]=ql()
}
namespace Out{
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define ps(x) printf("%s",x)
#define pc(x) printf("%c",x)
#define pe() puts("")
}
namespace DeBug{
#define MARK false
#define DB if(MARK)
#define pr(x) cout<<#x<<": "<<x<<endl
#define pra(x,a,b) cout<<#x<<": "<<endl; \
repi(i,a,b) cout<<x[i]<<" "; \
puts("");
#define FR(a) freopen(a,"r",stdin)
#define FO(a) freopen(a,"w",stdout)
}
using namespace Fast_Read;
using namespace Read;
using namespace Out;
using namespace DeBug;
const int MAX_N=2e5+5;
int n;
vector<int>ball[MAX_N];
int main()
{
n=qi();
repi(i,1,n){
int x=qi(),c=qi();
ball[c].pb(x);
}
ll resl=0,posl=0,resr=0,posr=0;
repi(i,1,n)if(ball[i].size()){
sort(all(ball[i]));
ll pl=ball[i][0],pr=*ball[i].rbegin();
ll nowl=min(abs(posl-pr)+pr-pl+resl,abs(posr-pr)+pr-pl+resr);
ll nowr=min(abs(posl-pl)+pr-pl+resl,abs(posr-pl)+pr-pl+resr);
resl=nowl,resr=nowr;
posl=pl,posr=pr;
}
pl(min(resl+abs(posl),resr+abs(posr))),pe();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,x,y;
cin>>a>>b>>x>>y;
int y_=min(2*x,y);
int kyori_=abs(2*b+1-2*a);
cout<<kyori_/2*y_+x<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i)
#define DOR(i,s,t) for(int i=(s),_t=(t); i>=_t; --i)
#define EOR(i,x) for(int i=Head[x]; ~i; i=Nxt[i])
typedef long double db;
typedef long long ll;
namespace Eddd {
inline char sc() {
return getchar();
static const int LEN=100000;
static char Buf[LEN],*OP=Buf,*ED=Buf;
if(OP==ED) ED=(OP=Buf)+fread(Buf,1,LEN,stdin);
return *OP++;
}
template<class T> void rd(T &x) {
static int c,f;x=f=0;
while(c=sc(),c<48) if(c=='-') f=1;
do x=(x<<3)+(x<<1)+(c^48);
while(c=sc(),c>47);if(f) x=-x;
}
template<class T> void pt(T x) {
if(x<0) putchar('-'),x=-x;
else if(!x) putchar('0');
static int Stk[30],tp=0;
for(; x; x/=10) Stk[tp++]=x%10;
while(tp) putchar(Stk[--tp]^48);
}
template<class T> void ptk(const T &x) {
pt(x);putchar(' ');
}
template<class T> void ptn(const T &x) {
pt(x);putchar('\n');
}
template<class T> bool chkmi(T &x,const T &y) {
return x>y?x=y,true:false;
}
template<class T> bool chkmx(T &x,const T &y) {
return x<y?x=y,true:false;
}
}
using namespace Eddd;
int main() {
int a,b;
rd(a);rd(b);
ptn(a*2+100-b);
return 0;
} | #include <bits/stdc++.h>
#define yy cout<<"YES"<<endl;
#define nn cout<<"NO"<<endl;
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i)
#define rep(i, a, n) for (int i = a; i < n; i++)
#define mod 1000000007
#define cl cout <<endl
#define fi first
#define se second
#define int long long
#define w(x) int x; cin>>x; while(x--)
#define endl ("\n")
#define f(i, a, n) for(int i=a; i<n; i++)
#define pb push_back
#define mi(a,b,c) min(a,min(b,c))
#define cc(r) cout<<r<<" "
#define ce(r) cout<<r<<endl
#define cn continue
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sz(a) int((a).size())
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(6);
cout << fixed;
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin );
// freopen("output.txt" , "w" , stdout) ;
// #endif
int t =1 ;
//cin >> t ;
while (t--)
{
double a , b ;
cin >> a >> b ;
cout << a*b/100<< endl ;
}
return 0;
} |
#include <bits/stdc++.h>
#define f(i,j,k) for(long long i=j;i<k;i++)
#define f2(i,j,k) for(long long i=j;i>=k;i--)
#define ll long long
using namespace std;
const long long mod=1e9+7;
void chmin(int& a, int b){ if(a > b) a = b; }
void chmax(int& a, int b){ if(a < b) a = b; }
int main(){
ll n;
cin>>n;
ll x,c;
map<ll, vector<ll>> num;
f(i,0,n){
cin>>x>>c;
num[c].push_back(x);
}
vector<pair<ll,ll>> pairs;
pairs.emplace_back(0,0);
for(auto &[k, v]:num){
sort(v.begin(),v.end());
pairs.emplace_back(v[0],v.back());
}
pairs.emplace_back(0,0);
ll dp_size=pairs.size();
vector<vector<ll>> dp(dp_size,vector<ll>(2));
dp[0][0]=0,dp[0][1]=0;
f(i,1,dp_size){
ll distance=pairs[i].second-pairs[i].first;
ll now_left=pairs[i].first,now_right=pairs[i].second;
ll pre_left=pairs[i-1].first,pre_right=pairs[i-1].second;
ll left_sum=dp[i-1][0],right_sum=dp[i-1][1];
dp[i][0]=min(left_sum+abs(now_right-pre_left),right_sum+abs(now_right-pre_right))+distance;
dp[i][1]=min(left_sum+abs(now_left-pre_left),right_sum+abs(now_left-pre_right))+distance;
}
cout<<min(dp[dp_size-1][0],dp[dp_size-1][1])<<endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,ans=0;
set<pair<ll,ll>> e,o;
pair<ll,ll> w,x,y,z;
int main(){
cin>>n;
ll a[n],b[n];
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)cin>>b[i];
for(int i=0;i<n;i++){
if(i%2==0)e.insert({a[i]-b[i],i});
else o.insert({a[i]-b[i],i});
}
for(int i=0;i<n/2;i++){
w=*begin(e),x=*begin(o),y=*rbegin(e),z=*rbegin(o);
if(-w.first-x.first>=y.first+z.first){ans+=b[w.second]+b[x.second];e.erase(w);o.erase(x);}
else{ans+=a[y.second]+a[z.second];e.erase(y);o.erase(z);}
}
cout<<ans<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;
void Main() {
ll a,b;
cin >> a >> b;
REP(x,-333,333) {
REP(y,-333,333) {
if(x+y==a&&x-y==b) {
pr(x,y);
return;
}
}
}
}
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
| #include <bits/stdc++.h>
using namespace std;
int main(){
int a, b;
cin >> a >> b;
auto x = (a + b) / 2;
auto y = a - x;
cout << x << " " << y << endl;
} |
//abc192 a
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main() {
int X;
cin >> X;
for(int i=1 ; i<=100 ; i++){
int current_coin = X + i;
if(current_coin % 100 == 0){
cout << i << endl;
}
}
}
| #include <iostream>
#include <vector>
using namespace std;
int main()
{
int n;
cin>>n;
if(n==1 )
{
cout<<0;
return 0;
}
if(n==2)
{
cout<<1;
return 0;
}
int l=1;
int r=n-1;
int count=0;
while(l+r==n && r>0 && l>0)
{
l++;
r--;
count++;
}
cout<<count;
} |
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#include <iostream>
#include <cassert>
template<long long mod>
class modint{
private:
using T = long long;
T a;
public:
constexpr modint(const long long x = 0) noexcept : a((x%mod+mod)%mod) {}
constexpr T& value() noexcept { return a; }
constexpr const T& value() const noexcept { return a; }
constexpr modint operator-() const noexcept {
return modint(0) -= *this;
}
constexpr modint operator+(const modint& rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint& rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint& rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint& rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint& operator+=(const modint& rhs) noexcept {
a += rhs.a;
if(a >= mod) a -= mod;
return *this;
}
constexpr modint &operator-=(const modint& rhs) noexcept {
if(a < rhs.a) a += mod;
a -= rhs.a;
return *this;
}
constexpr modint& operator*=(const modint& rhs) noexcept {
a = a*rhs.a%mod;
return *this;
}
constexpr modint& operator/=(const modint& rhs) noexcept {
return *this *= rhs.inv();
}
constexpr bool operator==(const modint& rhs) const noexcept {
return a == rhs.a;
}
constexpr bool operator!=(const modint& rhs) const noexcept {
return not (*this == rhs);
}
constexpr modint pow(long long k) const noexcept {
modint ret(1);
modint x = k > 0 ? *this : this->inv();
k = abs(k);
while(k > 0){
if(k&1) ret *= x;
x *= x;
k >>= 1;
}
return ret;
}
constexpr modint inv() const noexcept {
return pow(mod-2);
}
friend std::ostream& operator<<(std::ostream &os, const modint &X) noexcept {
return os << X.a;
}
friend std::istream& operator>>(std::istream &is, modint &X) noexcept {
is >> X.a;
X.a %= mod;
if(X.a < 0) X.a += mod;
return is;
}
};
int main(){
using mint = modint<998244353>;
int n;
cin >> n;
vector<long long> A(n);
for(int i = 0; i < n; ++i)
cin >> A[i];
sort(A.begin(),A.end());
mint t = 0;
for(int i = n-1; i >= 0; --i){
t *= 2;
t += A[i];
}
mint ans = 0;
for(auto a : A){
t -= a;
t /= 2;
ans += t*a + a*a;
}
cout << ans << endl;
}
| #define IOS ios::sync_with_stdio(false);
#define rep(i, a, n) for(ll i=a;i<=n;i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define put(x) cout<< x << "\n"
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
ll n, m, t, k, l, r, ans, cnt, sum, flag;
double arr[N];
int main() {
IOS;
cin >> n;
arr[n] = 0;
for (int i = n - 1; i >= 0; i--) {
arr[i] = arr[i + 1] + (1.0 * n / (n - i));
}
printf("%.6f\n", arr[0]-1);
return 0;
} |
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define pb push_back
#define fe first
#define lb lower_bound
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi map<int,int>
#define mii map<pi,int>
#define vi vector<int>
#define vvi vector<vi>
#define bs binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define all(c) (c).begin(),(c).end()
#define sz(x) (int)x.size()
#define PI 3.14159265358979323846
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set;
const int N=3e5+10;
const int INF=1e18;
int mod= 1e9+7;
int dx[4]={0,0,+1,-1};
int dy[4]={+1,-1,0,0};
int po(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1)
res = (res%mod * a%mod) % mod;
a =(a%mod*a%mod) % mod;
b >>= 1;
}
return res;
}
int n;
void solve() {
cin>>n;
vi a(n,0);
rep(i,0,n) cin>>a[i];
sort(all(a));
int sum=0;
for(int i=n-1;i>=0;i--) {
sum+=(i*a[i]-(n-i-1)*a[i]);
}
cout<<sum<<endl;
}
int32_t main() {
cool;
int t=1;
//~ freopen("input.txt","r",stdin);
//~ freopen("output.txt","w",stdout);
//cin>>t;
while(t--)
solve();
return 0;
}
| //Water Heater
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define rrep(i,x,y) for(ll i=x-1;i>=y;i--)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18
signed main (){
int n,w;cin>>n>>w;
vector<int>s(n),t(n),p(n);
rep(i,0,n)cin>>s[i]>>t[i]>>p[i];
vector<int>c(200001,0);
rep(i,0,n){
c[s[i]]+=p[i];
c[t[i]]-=p[i];
}
int sum=0;
rep(i,0,200001){
sum+=c[i];
if(sum>w){
cout<<"No"<<nnn;
return 0;
}
}
cout<<"Yes"<<nnn;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(pow(2, n));
for (int i = 0; i < pow(2, n); i++) {
cin >> a.at(i);
}
vector<int> b;
b = a;
vector<int> copy;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < a.size() / 2; j++) {
if (a.at(j * 2) > a.at(j * 2 + 1)) {
copy.push_back(a.at(j * 2));
}
if (a.at(j * 2) < a.at(j * 2 + 1)) {
copy.push_back(a.at(j * 2 + 1));
}
}
a = copy;
copy = {};
}
int ans = min(a.at(0), a.at(1));
for (int i = 0; i < pow(2, n); i++) {
if (ans == b.at(i)) {
cout << i + 1 << endl;
break;
}
}
return 0;
}
| #include<bits/stdc++.h>
#define rep(i,n) for ( int i=0; i< (n); ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
int winner(int i0, int k, int n, vector<int> &a){
if(k==0) return i0;
int w1 = winner(i0, k-1, n, a);
int w2 = winner(i0+pow(2,k-1), k-1, n, a);
//int w = a[w1]>a[w2]? w1 : w2;
//cout << a[w1] << " " << a[w2] << " " << w << endl;
if(k==n) return a[w1]>a[w2]? w2 : w1;
return a[w1]>a[w2]? w1 : w2;
}
int main(){
int n;
cin >> n;
int size = pow(2,n);
vector<int> a(size);
rep(i,size) cin >> a[i];
cout << winner( 0, n, n, a)+1 << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
// clang-format off
using ll = int64_t;
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
for (auto& a : v) cin >> a;
return is;
}
template <class T>
istream& operator>>(istream& is, vector<pair<T, T>>& v) {
for (auto& a : v) cin >> a.first >> a.second;
return is;
}
template <class T>
istream& operator>>(istream& is, vector<tuple<T, T, T>>& v) {
for (auto& a : v) {
T a1, a2, a3;
cin >> a1 >> a2 >> a3;
a = {a1, a2, a3};
}
return is;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
for (auto& a : v) os << a << " ";
os << endl;
return os;
}
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) { a = b; return true; }
return false;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) { a = b; return true; }
return false;
}
#define all(v) begin(v), end(v)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using veci = vector<int>;
using vecll = vector<ll>;
using Pi = pair<int, int>;
using Pll = pair<ll, ll>;
using Ti = tuple<int, int, int>;
// clang-format on
// cout << std::fixed << std::setprecision(15);
bool isd7(int d) {
while (d > 0) {
if (d % 10 == 7) return false;
d /= 10;
}
return true;
}
int isd8(int d) {
while (d > 0) {
if (d % 8 == 7) return false;
d /= 8;
}
return true;
}
int main() {
int N;
cin >> N;
int ans = 0;
for (int i = 1; i <= N; i++) {
if (isd7(i) && isd8(i)) ans++;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;
bool f(int n){
string s = to_string(n);
for(auto c : s){
if(c == '7') return false;
}
while(n != 0){
int now = n % 8;
if(now == 7) return false;
n /= 8;
}
return true;
}
int main(){
int n;
cin >> n;
n++;
int ans = 0;
rep2(i, 1, n){
if(f(i) == true) ans++;
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())
#define INT(...) int __VA_ARGS__; IN(__VA_ARGS__);
#define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__);
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__);
#define CHR(...) char __VA_ARGS__; IN(__VA_ARGS__);
#define LD(...) ld __VA_ARGS__; IN(__VA_ARGS__);
/* const ll mod = 1e9 + 7; */
const ll mod = 998244353;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
void IN() {}
template <class Head, class... Tail>
void IN(Head &head, Tail &... tail) {
cin >> head;
IN(tail...);
}
class mint {
private:
ll x;
public:
constexpr mint(const ll x = 0) noexcept : x((x % mod + mod) % mod) {}
constexpr ll value() noexcept { return x; }
constexpr mint operator += (const mint right) noexcept {
if ((x += right.x) >= mod) x -= mod;
return *this;
}
constexpr mint operator -= (const mint right) noexcept {
if ((x += mod - right.x) >= mod) x -= mod;
return *this;
}
constexpr mint operator *= (const mint right) noexcept {
x = x * right.x % mod;
return *this;
}
constexpr mint operator /= (const mint right) noexcept {
return *this *= right.inv();
}
constexpr mint operator + (const mint right) const noexcept {
return mint(*this) += right;
}
constexpr mint operator - (const mint right) const noexcept {
return mint(*this) -= right;
}
constexpr mint operator / (const mint right) const noexcept {
return mint(*this) /= right;
}
constexpr mint operator * (const mint right) const noexcept {
return mint(*this) *= right;
}
constexpr mint inv() const {
return pow(mod-2);
}
constexpr mint pow(ll n) const {
if (n == 0) return 1;
mint a = pow(n>>1);
a *= a;
if (n & 1) a *= *this;
return a;
}
};
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
LL(a, b, c);
mint aa = (a * (a + 1)) / 2;
mint bb = (b * (b + 1)) / 2;
mint cc = (c * (c + 1)) / 2;
cout << (aa * bb * cc).value() << endl;
}
| #include <iostream>
#include <cstdio>
#include <cctype>
using namespace std;
template <typename T>
inline T read() {
T x = 0, f = 1; char c = getchar();
while (!isdigit(c)) { if (c == '-') f = - f; c = getchar(); }
while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
return x * f;
}
#define lint long long int
#define ulint unsigned lint
#define readint read <int> ()
#define readlint read <lint> ()
const int inf = 1e9 + 1e7, Mod = 998244353, Inv = 499122177;
const lint INF = 1e18 + 1e9;
lint Ans = 1ll;
lint Solve(lint x) { return (x + 1ll) * x % Mod * Inv % Mod; }
int main(void) {
for (int i = 1; i <= 3; i ++) (Ans *= Solve(readlint)) %= Mod;
printf("%lld\n", Ans);
return 0;
} |
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define f(i,n) for(int i=0;i<n;i++)
#define fs(i,s,n) for(int i=s;i<n;i++)
#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(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define MOD 998244353;
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) int x; cin>>x; while(x--)
#define PI 3.1415926535897932384626
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;
int inv(int a) {
int r = 1, t = a, k = MOD - 2;
while (k) {
if (k & 1) r = (long long) r * t % MOD;
t = (long long) t * t % MOD;
k >>= 1;
}
return r;
}
int mpow(int base, int exp) {
base %= mod;
int result = 1;
while (exp > 0) {
if (exp & 1) result = (result * base) % mod;
base = (base * base) % mod;
exp >>= 1;
}
return result;
}
void sm25official()
{
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(){
sm25official();
string s;
cin>>s;
if(s[0]==s[1] && s[1]==s[2]) cout<<"Won"<<endl;
else cout<<"Lost"<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const ll INFL = (1ll << 60);
//cout << setprecision(20) <<
int main() {
ll n; cin >> n;
ll pn = pow(2, n);
vector<P> a(pn);
for (int i = 0; i < pn; i++) {
ll _a; cin >> _a;
a[i] = P(i + 1, _a);
}
vector<P> next;
vector<P> prev = a;
while (prev.size() != 2) {
for (int i = 0; i < prev.size(); i+=2) {
P target = prev[i];
if (prev[i].second < prev[i + 1].second) target = prev[i + 1];
next.push_back(target);
getchar();
}
prev = next;
next = vector<P>();
}
if (prev[0].second < prev[1].second) {
cout << prev[0].first << endl;
}
else {
cout << prev[1].first << endl;
}
} |
Subsets and Splits