code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
int main()
{
// input
long long t, N;
cin >> t >> N;
// for (int i = 1; i <= 100; i++)
// {
// cout << i << " " << (100 + t) / 100.0 * i << endl;
// }
cout << (long long)(100.0 / t * N + 0.99) + N - 1 << endl;
} | #include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(n) for(int i=0;i<n;i++)
#define rep(i,j,n) for(int i=j;i<n;i++)
#define pb push_back
#define ppb pop_back()
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define every(a,n) a,a+n
#define mp make_pair
#define F first
#define S second
#define max(a, b) (a < b ? b : a)
#define min(a, b) ((a > b) ? b : a)
#define tez ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all_st for(auto it=st.begin();it!=st.end();it++)
#define mp_x unordered_map<int,int>x
#define endl "\n"
#define sz(x) (int)x.size()
void solve()
{
double a,b;
cin>>a>>b;
if(a==0){
cout<<0;
return;
}
else{
cout<<(double)(a/100)*(double)b;
}
}
signed main()
{
tez
int test_case=1;
//cin>>test_case;
for(int i=1;i<=test_case;i++)
{
solve();
}
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5e5 + 5;
int main() {
ios :: sync_with_stdio(0), cin.tie(0);
ll s, p;
cin >> s >> p;
for (ll i = 2; i * i <= p; ++i) {
if (p % i == 0) {
if (i + (p / i) == s) {
cout << "Yes";
return 0;
}
}
}
if (p + 1 == s) {
cout << "Yes";
}
else {
cout << "No";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int n,w;
cin>>n>>w;
cout<<n/w;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,x;
cin >> n>> x;
vector<char>s(n);
for(int i=0;i<n;i++){
cin >> s.at(i);
}
for(int i=0;i<n;i++){
if(s.at(i)=='o'){
x++;
}
else{
if(x>0)
x--;
}
}
cout<<x;
}
| #include <bits/stdc++.h>
using namespace std;
// input
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__); // __VA_ARGS__可変引数マクロ
template<typename T> void MACRO_VAR_Scan(T& t) { std::cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest& ...rest) { std::cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define MAT(type, c, m, n) std::vector<std::vector<type>> c(m, std::vector<type>(n));for(auto& R:c)for(auto& w:R)std::cin>>w;
// output
template<typename T>void MACRO_OUT(const T t) { std::cout << t; }
template<typename First, typename...Rest>void MACRO_OUT(const First first, const Rest...rest) { std::cout << first << " "; MACRO_OUT(rest...); }
#define OUT(...) MACRO_OUT(__VA_ARGS__);
#define FOUT(n, dist) std::cout<<std::fixed<<std::setprecision(n)<<(dist); // std::fixed 浮動小数点の書式 / setprecision 浮動小数点数を出力する精度を設定する。
#define SP std::cout<<" ";
#define TAB std::cout<<"\t";
#define BR std::cout<<"\n";
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define ENDL std::cout<<std::endl;
#define FLUSH std::cout<<std::flush;
// utility
#define ALL(a) (a).begin(),(a).end()
#define REP(w, n) for(int w=0;w<int(n);++w)
#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T& a, const T b) { return a = (a > b) ? b : a; }
template<class T> using V = std::vector<T>;
template<class T> using VV = V<V<T>>;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = std::pair<int, int>;
using PAIRLL = std::pair<ll, ll>;
constexpr int INFINT = (1 << 30) - 1; // 1.07x10^ 9
constexpr int INFINT_LIM = (1LL << 31) - 1; // 2.15x10^ 9
constexpr ll INFLL = 1LL << 60; // 1.15x10^18
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62); // 9.22x10^18
constexpr double eps = 1e-7;
constexpr int MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
template<class T, size_t N> void FILL(T(&a)[N], const T & val) { for (auto& x : a) x = val; } // int a[5] = {1,2,3,4,5}; FILL(a,10);
template<class ARY, size_t N, size_t M, class T> void FILL(ARY(&a)[N][M], const T & val) { for (auto& b : a) FILL(b, val); } // 2次元配列でもそのまま使える
template<class T> void FILL(std::vector<T> & a, const T & val) { for (auto& x : a) x = val; } // 使い方 vector<int> a(3); FILL(a,10);
template<class ARY, class T> void FILL(std::vector<std::vector<ARY>> & a, const T & val) { for (auto& b : a) FILL(b, val); } // 2次元配列でもそのまま使える
// ------------>8------------------------------------->8------------
int main() {
INIT;
VAR(int,n,x)
VAR(string,s)
REP(i,n){
if (s[i] == 'x')
{
x -= 1;
if (x<0)
{
x = 0;
}
}
else
{
x += 1;
}
}
OUT(x)
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>; // <value, weight>
int main() {
bool box_state[50];
int n, m, q;
cin >> n >> m >> q;
vector<pii> ni;
vector<pii> ni_copy;
for (int i = 0; i < n; i++) {
int w, v;
cin >> w >> v;
ni.push_back(make_pair(v, w));
ni_copy.push_back(make_pair(v, w));
}
sort(ni.begin(), ni.end()); // 後ろ(大きいほう)から出していく
sort(ni_copy.begin(), ni_copy.end());
vector<int> box_size_tmp(m), box_size;
for (int& e : box_size_tmp) cin >> e;
for (int k = 0; k < q; k++) {
int from, to;
cin >> from >> to;
// 初期化部分
for (int j = 0; j < 50; j++) box_state[j] = true;
for (int j = from - 1; j < to; j++) {
box_state[j] = false;
}
box_size.clear();
ni.resize(ni_copy.size());
for (int j = 0; j < (int)ni_copy.size(); j++) ni[j] = ni_copy[j];
for (int j = 0; j < m; j++) {
if (box_state[j]) box_size.push_back(box_size_tmp[j]);
}
sort(box_size.begin(), box_size.end());
int sum_value = 0;
while (!ni.empty() && !box_size.empty()) {
pii tmp = ni[(int)ni.size() - 1];
int value = tmp.first, weight = tmp.second;
if (weight <= box_size[(int)box_size.size() - 1]) {
for (int i = 0; i < (int)box_size.size(); i++) {
if (box_size[i] >= weight) {
sum_value += value;
// cout << "a" << box_size.size() << "b" << endl;
box_size.erase(box_size.begin() + i);
break;
}
}
}
ni.pop_back();
}
cout << sum_value << endl;
}
} | #include <bits/stdc++.h>
#include <string>
#define MAX 100007
#define scn1(a) scanf("%d", &a);
#define scn2(a, b) scanf("%d %d", &a, &b);
#define scn3(a, b, c) scanf("%d %d %d", &a, &b, &c);
#define lscn1(a) scanf("%lli", &a);
#define lscn2(a, b) scanf("%lli %lli", &a, &b);
#define lscn3(a, b, c) scanf("%lli %lli %lli", &a, &b, &c);
#define prnt(a) printf("%d\n", a);
#define forr(i, a, n) for(int i=a;i<n;i++)
#define nl puts("");
#define PB push_back
#define enl cout << "\n";
#define CHK(a) cout << (#a) << " = " << (a) << endl;
typedef long long int ll;
using namespace std;
void arraychk(int a[],int n) {for(int i=0;i<n;i++)cout<<a[i]<<" ";enl;}
#define LOOPCHK(a, n) arraychk(a, n);
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll tt=1;
// cin >> tt;
for(int cse=1; cse<=tt; cse++)
{
int n=0, x=0, y=0, ans=0, sum=0;
cin >> n;
double a[n], b[n];
forr(i, 0, n)
cin >> a[i] >> b[i];
forr(i, 0, n)
{
forr(j, i+1, n)
{
if( ((b[j]-b[i])/(a[j]-a[i]))<=1 && ((b[j]-b[i])/(a[j]-a[i]))>=-1 )
{
ans++;
}
}
}
// cout << "Case " << cse << ":";
cout << ans << endl;
}
return 0;
}
|
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
using namespace std;
const int mx=1e6+5;
inline int read() {
int x=0,f=1; char c=getchar();
while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
return x*f;
}
int L,R,res;
int prime[mx],phi[mx],c[mx],num,cnt,tot;
void write(int x) {
if(x<10) {
putchar(x+'0');
return;
}
write(x/10);
putchar(x%10+'0');
}
void dfs(int x,int mul,int f,int m) {
if(mul>m) return;
if(x>num) {
tot+=(m/mul)*f;
return;
}
dfs(x+1,mul,f,m);
dfs(x+1,mul*c[x],(f==1)?-1:1,m);
}
int solve(int n,int m) {
if(n>m) swap(n,m);
int sum=0;
for(int i=2;i<=n;i++) {
num=0; int tmp=i;
for(int j=1;j<=cnt&&prime[j]<=sqrt(tmp);j++) {
if(tmp%prime[j]==0) {
c[++num]=prime[j];
while(tmp%prime[j]==0) tmp/=prime[j];
}
}
if(tmp>1) c[++num]=tmp;
tot=0;
for(int j=1;j<=num;j++) dfs(j+1,c[j],1,m);
sum+=tot;
}
for(int i=2;i<=n;i++) {
sum-=m/i;
}
for(int i=2;i<=m;i++) {
sum-=n/i;
}
// printf("%lld %lld %lld\n",n,m,sum+n);
return sum+(n-1);
}
signed main() {
L=read(),R=read();
for(int i=2;i<=R;i++) {
if(!phi[i]) prime[++cnt]=i,phi[i]=i-1;
for(int j=1;j<=cnt&&i*prime[j]<=R;j++) {
if(i%prime[j]==0) {
phi[i*prime[j]]=phi[i]*prime[j];
}
else {
phi[i*prime[j]]=phi[i]*(prime[j]-1);
}
}
}
if(L==1) {
res=solve(R,R);
}
else {
res=solve(R,R)-2*solve(L-1,R)+solve(L-1,L-1);
}
write(res);
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「sからnまで」の降順の繰り返し
typedef long long ll;
const int inf = 1e9+7;
const int mod = 1e9+7;
int main() {
int h,w;
cin>>h>>w;
vector<string>s(h);
rep(i,h)cin>>s[i];
int cnt=0;
rep(i,h){
rep2(j,0,w-2){
if(s[i][j]=='.'&&s[i][j+1]=='.'){
cnt++;
}
}
}
rep(i,w){
rep2(j,0,h-2){
if(s[j][i]=='.'&&s[j+1][i]=='.'){
cnt++;
}
}
}
cout<<cnt<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define ll long long
#define int ll
#define mod 1000000007
#define DEBUG cout<<"Hello1\n";
#define all(v) (v).begin(),(v).end()
#define deb(...) debug(#__VA_ARGS__, __VA_ARGS__);
const int N = 1e6 + 5;
const ll inf = 1e18 + 5;
typedef pair<int, int> pii;
void fileIO();
template<class T> void print_container(T &container);
template<class T> void print_pair_container(T &container);
template<class T> void printArr(T &a, int n);
template<typename T> void debug(string s, T x);
template<typename T, typename... Args>
void debug(string s, T x, Args... args);
int n, m;
void solve(int tc = 0) {
cin >> n;
if (n % 2) {
cout << "Odd\n";
} else {
if ((n / 2) % 2 == 0) {
cout << "Even\n";
} else {
cout << "Same\n";
}
}
}
int32_t main()
{
fileIO();
int t = 1; cin >> t; for (int i = 1; i <= t; i++)
solve();
return 0;
}
void fileIO() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
}
template<typename T> void debug(string s, T x)
{
cout << s << " = " << x << "\n";
}
template<typename T, typename... Args> void debug(string s, T x, Args... args)
{
cout << s.substr(0, s.find(',')) << " = " << x << " | ";
debug(s.substr(s.find(',') + 2), args...);
}
template<class T> void print_container(T &container)
{
for (auto &t : container)
{
cout << t << " ";
}
cout << endl;
}
template<class T> void print_pair_container(T &container)
{
for (auto &t : container)
{
cout << t.first << " " << t.second << endl;
}
cout << endl;
}
template<class T> void printArr(T &a, int n)
{
for (int i = 0; i < n; i++)
{
cout << a[i] << " ";
}
cout << endl;
}
| #define _CRT_SECURE_NO_WARNINGS
#define fast ios::sync_with_stdio(false); cin.tie(0)
#define foru(i, k, n) for (ll i = k; i < n; i++)
#define ford(i, k, n) for (ll i = k; i >= n; i--)
#define pb push_back
#define ff first
#define ss second
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <queue>
#include <bitset>
#include <map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<ll, ll> pll;
int main() {
fast;
int t;
cin >> t;
while (t--) {
ll n;
cin >> n;
int cnt = 0;
while (n % 2 == 0) {
n /= 2;
cnt++;
}
if (cnt == 0)cout << "Odd\n";
else if (cnt == 1)cout << "Same\n";
else cout << "Even\n";
}
return 0;
} |
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define rf(i, a, b) for (ll i = a; i >= b; i--)
typedef std::vector<long long> vi;
#define F first
#define S second
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mod 1000000007
#define PB push_back
#define MP make_pair
#define PI 3.14159265358979323846
#define all(a) a.begin(), a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
const ll INF = LLONG_MAX / 2;
const ll N = 2e5 + 1;
using namespace std;
ll n, maxid = 0, m;
ll pow1(ll n, ll p)
{
if (p == 0)
return 1;
ll x = pow1(n, p / 2);
if (x > m || x >= 1000000001)
return INF;
x = (x * x);
if (x > m)
return INF;
if (p % 2 == 0)
return x;
else
{
if (x * n > m)
return INF;
return (x * n);
}
}
string x;
bool check(ll k)
{
ll j = 0, ans = 0;
rf(i, n - 1, 0)
{
if (pow1(k, j) == INF)
return false;
if (pow1(k, j) + ans > m || ans > m)
return false;
ans += (pow1(k, j) * ((ll)(x[i] - '0')));
j++;
}
if (ans > m)
return false;
return true;
}
int main()
{
fast;
ll t = 1;
// std::cin >> t;
while (t--)
{
cin >> x;
n = x.length();
cin >> m;
if (x.length() == 1)
{
ll c = x[0] - '0';
if (m < c)
cout << 0 << "\n";
else
cout << 1 << "\n";
continue;
}
fr(i, 0, n)
maxid = max(maxid, (ll)(x[i] - '0'));
ll l = maxid + 1, r = m + 1;
// cout << l << "\n";
// cout << maxid << "\n";
while (l <= r)
{
ll mid = (l + r) / 2;
if (check(mid))
{
l = mid + 1;
}
else
{
r = mid - 1;
}
}
cout << l - 1 - maxid << "\n";
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef __int128 ll;
string x;
ull m;
bool check(ull mid)
{
ll ans=0;
int flag=1;
for(int i=0;i<x.size();i++)
{
ans=ans*mid+ll(x[i]-'0');
if(ans>m)
{
flag=0;
break;
}
}
return flag;
}
int main()
{
char c='0';
cin>>x>>m;
for(int i=0;i<x.size();i++)
{
c=max(c,x[i]);
}
ull t=c-'0';
if(x.size()==1)
{
if(t<=m) cout<<1<<endl;
else cout<<0<<endl;
}
else
{
ull l=0,r=1e18;
while(l<r)
{
ull mid=(l+r+1)>>1;
if(check(mid)) l=mid;
else r=mid-1;
}
if(l<t) cout<<0<<endl;
else cout<<l-t<<endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<long,long>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define Mi map<int,int>
#define mii map<pii,int>
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define ff first
#define ss second
#define sz(x) (int)x.size()
//#define endl '\n'
#define mod 1000000007
//#define mod 998244353
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rem(i,a,b) for(int i=a;i>b;i--)
#define mp(a,b) make_pair(a,b)
#define INF numeric_limits<ll>::max();
#define NINF numeric_limits<ll>::min();
#define vvi(a,b,name) vector<vector<int>> name(a,vector<int>(b,-1))
const long double pi=3.14159265359;
inline ll add(ll a, ll b, ll m)
{
if ((a + b) >= m)
return (a + b) % m;
return a + b;
}
inline ll mul(ll a, ll b, ll m)
{
if ((a * b) < m)
return a * b;
return (a * b) % m;
}
ll power(ll x, ll y, ll m)
{
ll res = 1;
x = x % m;
if (x == 0)
return 0;
while (y > 0)
{
if (y & 1)
res = (res * x) % m;
y = y >> 1;
x = (x * x) % m;
}
return res;
}
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
int main()
{fast;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
int t=1,n;
//cin>>t;
while(t--)
{cin>>n;
string a,b;
cin>>a>>b;
queue<int> q1,q2;
rep(i,0,n){
if(a[i]=='0'){
q1.push(i);
}
else{
q2.push(i);
}
}
int zero=0,one=0;
rep(i,0,n){
if(b[i]=='0') zero++;
else one++;
}
if(zero!=q1.size()||one!=q2.size()){
cout<<-1<<endl;
continue;
}
int ans=0;
int i=n-1;
while(i>=0){
if(a[i]==b[i]){
i--;
continue;
}
if(a[i]=='1'){
int j=i;
while(a[j]!='0'){
j--;
}
swap(a[i],a[j]);
i--;
}
else{
int k=i;
while(b[k]!='0'){
k--;
}
swap(b[i],b[k]);
i--;
}
//cout<<i<<" "<<a<<" "<<b<<endl;
ans++;
}
cout<<ans<<endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define int long long
using namespace std;
#ifdef LOCAL
#include "/media/brayand/BrayanD/debugger.h"
#else
#define db(...) false
#define dbl(...) false
#define dbg(...) false
#define dbm(...) false
#define dbs(...) false
#define dbas(...) false
#endif
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
string A, B;
cin >> A >> B;
vector<int> v1, v2;
for(int i = 0 ; i < N ; i++)
{
if(A[i] == '1')
{
v1.push_back(i);
}
if(B[i] == '1')
{
v2.push_back(i);
}
}
if(v1.size() != v2.size())
{
cout << -1 << '\n';
return 0;
}
int tam = v1.size();
int res = 0;
for(int i = 0 ; i < tam ; i++)
{
if(v1[i] == v2[i])continue;
if(v1[i] < v2[i])
{
if(i != tam-1)
{
if(v1[i+1] <= v2[i])
{
// db(1);
res += v1[i+1]-v1[i]-1;
}
else
{
res += v2[i]-v1[i];
}
}
else
{
res += v2[i]-v1[i];
}
}
if(v1[i] > v2[i])
{
if(i != 0)
{
if(v1[i-1] >= v2[i])
{
res += v1[i]-v1[i-1]-1;
}
else
{
res += v1[i]-v2[i];
}
}
else
{
res += v1[i]-v2[i];
}
}
}
cout << res << '\n';
return 0;
} |
#include<bits/stdc++.h> // 54 71 "Baklol, Take it easy"
using namespace std;
using ll = long long int;
using ld = long double;
#define rep(x, k, n) for(int x = (k); x <= (n); ++x)
#define rept(x, k, n) for(int x = (k); x < (n); ++x)
#define repr(x, k, n) for(int x = (k); x >= (n); --x)
#define pb push_back
#define siz(x) ((int)(x).size())
#define o2(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define clr(x, k) memset(x, k, sizeof(x)) // 0, -1
#define printv(v, k, n) rep(i, k, n) cout << v[i] << " \n"[i==n];
#define print2dv(V,k,n,m) rep(j, k, n) printv(V[j], k, m);
#define out(x) cout << ((x) ? "Yes" : "No") << '\n'
#define setbits(x) __builtin_popcountll(x)
#define inf INT_MAX
#define ninf INT_MIN
#define int long long // "be carefull"
typedef vector<int> vi;
typedef pair<int, int> pii;
template <typename Arg1>
void debug_out(const char* name, Arg1&& arg1){
cerr << name << " = " << arg1 << " ]" << "\n";
}
template <typename Arg1, typename... Args>
void debug_out(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " = " << arg1 << ",";
debug_out(comma+1, args...);
}
#ifndef ONLINE_JUDGE
#define deb(...) cerr << "[ ", debug_out(#__VA_ARGS__, __VA_ARGS__)
#define debv(v, k, n) rep(i, k, n) cerr << v[i] << " \n"[i==n];
#define deb2dv(V, k, n, m) rep(j, k, n) debv(V[j], k, m);
#define line rep(i, 0, 50){ cerr << '-'; } cerr << '\n'
#else
#define deb(...)
#define debv(v, k, n)
#define deb2dv(V, k, n, m)
#define line
#endif
const int mod = 1e9 + 7; // 998244353;
const int N = 2e5 + 5, M = 2e5 + 5;
/*/------------------------------ CODE BEGINS ------------------------------/*/
int k;
void Solve_main() {
cin >> k;
int res = 0;
rep(a, 1, N){
if(a > k) break;
rep(b, 1, N){
if((a * b) > k) break;
rep(c, 1, N){
if((a * b * c) > k) break;
res++;
}
}
}
cout << res << '\n';
}
/*/------------------------------- CODE ENDS -------------------------------/*/
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
srand(chrono::high_resolution_clock::now().time_since_epoch().count());
// cout << setprecision(12) << fixed;
int tc = 1;
// cin >> tc;
for(int i = 1; i <= tc; i++) {
Solve_main();
// BRUTE_FORCE();
}
cerr << "[time:" << 1.0*clock()/CLOCKS_PER_SEC << "s] ";
return 0;
}
/*
-> edge cases, n = 1 ?
-> Submit - right file.
-> Move on - if completely_stuck > 30 minute.
-> entire input - multiple testcases.
-> time complexity - 1 sec : 4e8 will work but risky.
-> space complexity - 256 mb : 6e7(int), 3e7(ll), 2e8(bool, char), will work.
-> mod : sort ?, mint, remove #define int.
-> builtin fuction - add ll.
-> Iterative > Recursive.
-> clear - global variables.
*/ | #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;
int n;
int a[200000];
signed main() {
int i;
cin >> n;
rep(i, n) cin >> a[i];
int asum = 0, amax = 0;
int res1 = 0;
rep(i, n) {
asum += a[i];
amax = max(amax, a[i]);
res1 += asum;
int ans = res1 + (i + 1) * amax;
cout << ans << endl;
}
return 0;
} |
const bool isDebugMode = true;
int testcase = 1;
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const int SHOWSIZE = 1 << 5;
const long long MOD = 1000000007; //998244353;
const long long dy[] = {-1, 0, 0, 1};
const long long dx[] = {0, -1, 1, 0};
const string abc = "abcdefghijklmnopqrstuvwxyz";
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for (const auto &e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
long long power(long long a, long long n){long long res = 1; while(n > 0){if(n & 1)res = res * a; a = a * a; n >>= 1;} return res;}
void pt(){cout << endl; return;}
template<class Head> void pt(Head&& head){cout << head; pt(); return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
void dpt(){if(!isDebugMode) return; cout << endl; return;}
template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;}
template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void enu(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void enu2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T> void debug(T v){if(!isDebugMode) return; rep(i, min(v.size(), SHOWSIZE)) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, min(v.size(), SHOWSIZE)){rep(j, min(v[i].size(), SHOWSIZE)) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> long long recgcd(T1 a, T2 b){return a % b ? recgcd(b, a % b) : b;}
template<typename T> vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value != 0>::type fill_v(U &u, const V... v) { u = U(v...); }
template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value == 0>::type fill_v(U &u, const V... v){for (auto &e : u) fill_v<T>(e, v...);}
bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; }
void solve();
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
cin >> testcase;
while(testcase--) solve();
return 0;
}
void solve(){
ll L, R; cin >> L >> R;
if(R < 2 * L) pt(0);
else pt((R - 2 * L + 1) * (R - 2 * L + 2) / 2);
} |
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
using namespace std;
vector<ll> solve(ll t, vector<ll> l, vector<ll> r) {
vector<ll> res(t);
for(ll i = 0ll; i < t; i++) {
ll count = max(r[i] - 2ll * l[i] + 1ll, 0ll);
res[i] = count * (count + 1ll) / 2ll;
}
return res;
}
int main()
{
std::ios::sync_with_stdio(false);
ll t;
cin >> t;
vector<ll> l(t), r(t);
for(int i = 0; i < t; i++) {
cin >> l[i] >> r[i];
}
vector<ll> res = solve(t, l, r);
for(ll i=0ll;i<t; i++) {
cout << res[i] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N,M;
int x,y;
string A[800];
int score[800]={0};
char dna[20][20];
cin >> N >> M;
for(int i=0; i<M; i++) {
string a;
cin >> a;
bool iscontain=false;
int conv=0;
int convj=0;
for( int j=0; j<i; j++)
if(A[j].find(a)!=string::npos) {
iscontain=true;
if(score[j]>conv) {
conv=score[j];
convj=j;
}
break;
}
if(iscontain!=true) {
A[i]=a;
score[i]++;
} else {
score[convj]++;
A[i]="";
}
}
bool convine=true;
while(convine) {
convine=false;
for(int i=0; i<M; i++) {
if(A[i].size()>2){
string b=A[i].substr(A[i].size()-2);
for(int j=0; j<M; j++) {
if( i==j ) continue;
if( A[j][0]==b[0] && A[j][1]==b[1] ){
if( A[i].size()+A[j].size()-2 <= N) {
A[i] = A[i] + A[j].substr(2);
A[j] ="";
score[i]+=score[j];
score[j]=0;
convine=true;
break;
}
}
}
}
}
}
convine=true;
while(convine) {
convine=false;
for(int i=0; i<M; i++) {
if(A[i].size()>2 && A[i].size()<N){
for(int j=0; j<M; j++) {
if( i==j ) continue;
if( (A[j].size() > 2) && ((A[i].size()+A[j].size()) <= N) ){
A[i] = A[i] + A[j];
A[j] ="";
score[i]+=score[j];
score[j]=0;
convine=true;
break;
}
}
}
}
}
for(int i=0; i<M; i++){
int max=score[i];
int maxj=i;
for(int j=i; j<M; j++){
if(score[j]>max) {
max=score[j];
maxj=j;
}
}
if( i!=maxj){
string tmp;
tmp=A[maxj];
A[maxj]=A[i];
A[i]=tmp;
int ti=score[maxj];
score[maxj]=score[i];
score[i]=ti;
}
}
for(int i=0; i<N; i++) {
if(A[i].size() < 20) A[i]+="....................";
}
for(int i=0; i<N; i++) {
cout << A[i].substr(0,20) << endl;
}
};
| #include <iostream>
#include <cmath>
#include <vector>
int main(void)
{
size_t N, M;
std::cin >> N >> M;
std::vector<int> A(M);
std::vector<int> B(M);
for (size_t i = 0; i < M; i++) {
std::cin >> A[i] >> B[i];
}
size_t K;
std::cin >> K;
std::vector<int> C(K);
std::vector<int> D(K);
for (size_t i = 0; i < K; i++) {
std::cin >> C[i] >> D[i];
}
int count = 0;
size_t KK = (size_t)std::pow(2, K);
for (size_t j = 0; j < KK; ++j) {
bool n[N+1] = {};
for (size_t i = 0; i < K; i++) {
n[j&(1<<i) ? C[i] : D[i]] = true;
}
int c = 0;
for (size_t i = 0; i < M; i++) {
if (n[A[i]] && n[B[i]]) {
c++;
}
}
count = std::max(count, c);
}
std::cout << count;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
#define lin(x) ll x; cin>>x;
#define stin(x) string x; cin>>x;
#define yn(x) if(x) { cout<<"Yes"<<endl; } else { cout<<"No"<<endl; }
#define YN(x) if(x) { cout<<"YES"<<endl; } else { cout<<"NO"<<endl; }
#define co(x) cout<<x<<endl;
using ll=long long;
using ld=long double;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll mod=998244353;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
return ((a > b) ? (a = b, true) : (false));
}
ll powmod(ll n, ll k, ll m) {
ll r=1;
for(; k>0; k >>=1) {
if(k&1) r=(r*n)%m;
n=(n*n)%m;
}
return r;
}
ll fact(ll n) {
ll a=1;
rep(i,n) {
a=a*(n-i);
}
return a;
}
ll pow(ll a, ll b) {
ll x=1;
rep(i,b) {
x=x*a;
}
return x;
}
struct mint {
ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main() {
mint A;
cin>>A;
mint B;
cin>>B;
mint C;
cin>>C;
mint x=1;
x=A*(A+1)*B*(B+1)*C*(C+1);
x=x/8;
co(x);
} | #include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <fstream>
using namespace std;
#define LL long long
LL a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, n = 0, m = 0, x = 0, y = 0;
string s;
vector<LL> v;
array<array<bool, 100005>, 105> dp;
struct Data
{
};
LL all = 0;
int main(void)
{
cin >> n;
v.resize(n);
for (auto& i : v) {
cin >> i;
all += i;
}
dp[0][0] = true;
dp[0][v[0]] = true;
for (int i = 1; i < n; i++) {
for (int j = 0; j < all; j++) {
if (dp[i - 1][j]) {
dp[i][j] = true;
dp[i][j + v[i]] = true;
}
}
}
int ans = all;
for (int i = (all + 1) / 2; i <= all; i++) {
if (dp[n - 1][i]) {
cout << i;
return 0;
}
}
return 0;
} |
#include"iostream"
#include"cstdio"
#include"cmath"
#include"cstring"
#include"algorithm"
#include"stack"
#include"queue"
using namespace std;
#define read(x) scanf("%d",&x)
#define readl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define MOD 998244353
#define MAXN 15
int n;
ll k;
ll e[MAXN][MAXN];
int f[MAXN];
int ans=0;
int main()
{
read(n),readl(k);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++) readl(e[i][j]);
f[i]=i;
}
do
{
int lst=1;
ll now=0;
for(int i=2;i<=n;i++)
{
now+=e[lst][f[i]];
lst=f[i];
}
now+=e[lst][1];
if(now==k) ans++;
}while(next_permutation(f+2,f+n+1));
printf("%d\n",ans);
return 0;
}
| #include <iostream>
#include <algorithm>
#include <string>
#include <complex>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()
#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; }
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; }
typedef long long ll;
template<class T> using vvec = vector<vector<T>>;
template<class T> using vvvec = vector<vvec<T>>;
constexpr ll INF = 1e14; //32 ~2*10^10 //64 ~9*10^19
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-6;
struct Edge {
Edge(int _s, int _t, ll f, ll _cost = 1) : from(_s), to(_t), cost(_cost), fee(f) {};
int from, to;
ll cost;
ll fee;
};
typedef vector<vector<Edge>> Graph;
void add_edge(Graph& g, int from, int to, ll fee, ll cost = 1) {
g[from].push_back(Edge(from, to, fee, cost));
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } else return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }
//int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll h,w; cin >> h >> w;
vector<string> s(h);
rep(i,h) cin >> s[i];
ll ans = 0;
rep(i, h) rep(j, w) {
if (s[i][j] == '.') {
if (i+1 < h && s[i+1][j] == '.') ++ans;
if (j + 1 < w && s[i][j+1] == '.') ++ans;
}
}
cout << ans << endl;
} |
#include<bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long n , a [200005] , num , did [200005] , f = 1;
set < pair < int , int > > s;
vector < int > v;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin >> n;
for ( int i = 1 ; i <= n ; i ++ )
{
cin >> a [i];
s . insert ( { a [i] , i } );
}
while ( s . size () )
{
pair < int , int > p = * -- s . end ();
s . erase ( -- s . end () );
int x = p . first , y = p . second;
if ( x == y ) continue;
num ++;
if ( x > y )
{
if ( did [y] )
{
f = 0;
break;
}
did [y] = 1;
s . erase ( s . lower_bound ( { a [ y + 1 ] , y + 1 } ) );
swap ( a [y] , a [ y + 1 ] );
s . insert ( { a [y] , y } );
s . insert ( { a [ y + 1 ] , y + 1 } );
v . push_back ( y );
}
else
{
if ( did [ y - 1 ] )
{
f = 0;
break;
}
did [ y - 1 ] = 1;
s . erase ( s . lower_bound ( { a [ y - 1 ] , y - 1 } ) );
swap ( a [y] , a [ y - 1 ] );
s . insert ( { a [y] , y } );
s . insert ( { a [ y - 1 ] , y - 1 } );
v . push_back ( y - 1 );
}
}
if ( f == 0 )
{
cout << -1;
return 0;
}
if ( v . size () == n - 1 ) for ( int i = 0 ; i < v . size () ; i ++ ) cout << v [i] << endl;
else cout << -1;
}
| #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;
class BIT{
public:
ll n,bit[555555];
BIT(){fill(bit,bit+555555,0);}
void add(ll i,ll x){
while(i<=n){
bit[i]+=x;
i+=i&-i;
}
}
ll sum(ll i){
ll s=0;
while(i>0){
s+=bit[i];
i-=i&-i;
}
return s;
}
};
BIT b=BIT();
void Main() {
ll n;
R n;
vector<ll> a(n);
rep(i,n) R a[i];
{
b.n=n+1;
ll ans=0;
rep(i,n) {
b.add(a[i],1);
ans+=b.sum(n+1)-b.sum(a[i]);
}
if(ans!=n-1) {
pr(-1);
return;
}
}
rep(i,n) a[i]--;
ll c[n];
rep(i,n) c[a[i]]=i;
vector<ll> v;
rep(i,n) {
while(c[i]!=i) {
v.pb(c[i]);
ll x=a[c[i]],y=a[c[i]-1];
swap(a[c[i]],a[c[i]-1]);
c[x]--;
c[y]++;
}
}
rep(i,v.size()) pr(v[i]);
}
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
|
#include<bits/stdc++.h>
using namespace std;
void solve(long long*arr1 , long long*arr2 , long long n)
{
long long sum = 0;
for(int i = 0 ; i < n ; i++)
{
sum+=(arr1[i]*arr2[i]);
}
if(sum==0)
{cout << "Yes" << endl;}
else
{
cout << "No" << endl;
}
return;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long*arr = new long long[n];
long long*arrw = new long long[n];
for(int i = 0 ; i < n; i++)
{
cin >> arr[i];
}
for(int i = 0 ; i < n; i++)
{
cin >> arrw[i];
}
solve(arr,arrw ,n);
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <deque>
#include <bitset>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define PLL pair<ll,ll>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dec(i,a,b) for(int i=a;i>=b;i--)
#define forn(i, n) for(int i = 0; i < int(n); i++)
using namespace std;
int dir[4][2] = { { 1,0 },{ 0,1 } ,{ 0,-1 },{ -1,0 } };
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-6;
inline ll read()
{
ll x = 0; bool f = true; char c = getchar();
while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return f ? x : -x;
}
ll gcd(ll m, ll n)
{
return n == 0 ? m : gcd(n, m % n);
}
ll qpow(ll m, ll k, ll mod)
{
ll res = 1, t = m;
while (k)
{
if (k & 1)
res = res * t % mod;
t = t * t % mod;
k >>= 1;
}
return res;
}
/**********************************************************/
const ll mod = 998244353;
const int N = 1e5 + 5;
ll a[N], b[N];
int main()
{
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
rep(i, 1, n)
cin >> a[i];
rep(i, 1, n)
cin >> b[i];
ll ans = 0;
rep(i, 1, n)
ans += a[i] * b[i];
if (ans)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
|
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int MOD=1000000007;
long long int fie[28][3][200007]={{{0}}};
int giri[19]={0};
int hen(char a){
if(a<='9')return a-'0';
else return a-'A'+10;
}
int main(){
string N;
cin>>N;
int K;
cin>>K;
int s=hen(N[0]);
fie[1][1][0]=1;
fie[1][0][0]=s-1;
fie[0][0][0]=1;
giri[s]=1;
/*
for(int k=0;k<7;k++){
for(int i=0;i<17;i++){
for(int j=0;j<2;j++){
printf("[%d]",fie[i][j][k]);
}
puts("");
}
puts("==============");
}
*/
for(int k=0;k<N.size()-1;k++){
int flg=1;
//for(int l=0;l<=k;l++){
//if(N[l]==N[k+1])flg=0;
if(giri[hen(N[k+1])]==1)flg=0;
//}
if(k!=N.size()-1){
giri[hen(N[k+1])]=1;
}
int girisyu=0;
for(int i=0;i<16;i++){
if(giri[i]==1)girisyu++;
}
int giriikasyu=0;
for(int l=hen(N[k+1])-1;0<=l;l--){
if(giri[l]==1)giriikasyu++;
}
for(int i=0;i<=16;i++){
for(int j=0;j<2;j++){
if(i!=0){
if(j==0){
fie[i][j][k+1]+=fie[i][j][k]*i;
fie[i][j][k+1]%=MOD;
fie[i+1][j][k+1]+=fie[i][j][k]*(16-i);
fie[i+1][j][k+1]%=MOD;
}
else if(j==1){
fie[i][0][k+1]+=fie[i][j][k]*giriikasyu;
fie[i][0][k+1]%=MOD;
fie[i+1][0][k+1]+=fie[i][j][k]*((hen(N[k+1]))-giriikasyu);
fie[i+1][0][k+1]%=MOD;
if(flg==1){
fie[i+1][j][k+1]+=fie[i][j][k];
fie[i+1][j][k+1]%=MOD;
}
else{
fie[i][j][k+1]+=fie[i][j][k];
fie[i][j][k+1]%=MOD;
}
}
}
else if(i==0&&j==0){
fie[i][j][k+1]=1;
fie[i][j][k+1]%=MOD;
fie[i+1][j][k+1]+=fie[i][j][k]*15;
fie[i+1][j][k+1]%=MOD;
}
}
}
}
long long int ans=0;
int pa=N.size()-1;
for(int i=K;i<=K;i++){
for(int j=0;j<2;j++){
ans+=fie[i][j][pa];
ans%=MOD;
}
}
cout<<ans<<endl;
/*
for(int k=0;k<7;k++){
for(int i=0;i<17;i++){
for(int j=0;j<2;j++){
printf("[%d]",fie[i][j][k]);
}
puts("");
}
puts("==============");
}
*/
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
typedef long long ll;
string num;
int rn[200005];
int k;
int n;
int dp[200005][20];
ll dfs(int x,ll now,bool zero,bool flag)
{
int cnt=0;
for(int i=0;i<16;i++)
{
if(now&(1<<i))cnt++;
}
if(x>=n)return cnt==k;
if(cnt>k)return 0;
if(!flag&&zero&&dp[x][cnt]!=-1)return dp[x][cnt];
ll ans=0;
int lim=flag?rn[x]:15;
for(int i=0;i<=lim;i++)
{
int tmp;
if(!zero&&i==0)tmp=now;
else tmp=now|(1<<i);
ans+=dfs(x+1,tmp,zero||(i!=0),flag&&(i==lim));
ans%=mod;
}
if(!flag&&zero)dp[x][cnt]=ans;
return ans;
}
int main()
{
cin>>num>>k;
n=num.size();
memset(dp,-1,sizeof dp);
for(int i=0;i<n;i++)
{
if(num[i]>='0'&&num[i]<='9')rn[i]=num[i]-'0';
else rn[i]=num[i]-'A'+10;
}
printf("%lld\n",dfs(0,0,0,1));
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int dist[1005][1005];
int A[1005],B[1005];
char C[1005];
vector<pair<int,int> > G[1005];
main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N,M;
cin>>N>>M;
for(int i=0;i<M;i++){
cin>>A[i]>>B[i]>>C[i];
G[A[i]].push_back(make_pair(B[i],C[i]));
G[B[i]].push_back(make_pair(A[i],C[i]));
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) dist[i][j] = (1 << 29);
}
queue<pair<int,int > > Q;
dist[1][N]=0;
Q.emplace(1,N);
while(Q.size()){
auto [pos1,pos2]=Q.front();
Q.pop();
for(pair<int,int> e1:G[pos1]){
for(pair<int,int> e2:G[pos2]){
if(e1.second!=e2.second)continue;
if(dist[e1.first][e2.first]==(1<<29)){
dist[e1.first][e2.first]=dist[pos1][pos2]+1;
Q.emplace(e1.first,e2.first);
}
}
}
}
int ans=(1<<29);
for(int i=1;i<=N;i++){
ans=min(ans,2*dist[i][i]);
}
for(int i=0;i<M;i++){
ans=min(ans,2*dist[A[i]][B[i]]+1);
ans=min(ans,2*dist[B[i]][A[i]]+1);
}
if(ans!=(1<<29))cout<<ans<<endl;
else cout<<-1<<endl;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll rd() {
ll x=0,f=1;
char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c))x=x*10+c-'0',c=getchar();
return x*f;
}
#define d rd()
ll a,b,k,aa,bb;
ll yh[65][65];
ll now,ans;
int main(){
a=aa=d,b=bb=d,k=d;
yh[0][0]=1,yh[1][0]=yh[1][1]=1;
f(i,2,61){
yh[i][0]=yh[i][i]=1;
f(j,1,i-1)yh[i][j]=yh[i-1][j]+yh[i-1][j-1];
}
f(i,1,a+b){
if(!aa)bb--,cout<<"b";
else if(!bb)cout<<"a",aa--;
else if(now+yh[aa+bb-1][aa-1]<k)now+=yh[aa+bb-1][aa-1],bb--,cout<<"b";
else cout<<"a",aa--;
}
return 0;
}
|
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i] << " "
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF = (1LL<<60)-1;
const int maxN = 1000001;
int countFreq(string &pat, string &txt)
{
int M = len(pat);
int N = len(txt);
int res = 0;
for (int i = 0; i <= N - M; i++){
int j;
for (j = 0; j < M; j++)
if (txt[i+j] != pat[j])
break;
if (j == M)
{
res++;
j = 0;
}
}
return res;
}
int32_t main(){
SPEED;
int a, b;
cin >> a >> b;
cout << (a + b)/2 << " " << a - (a + b)/2 ;
} | #include <bits/stdc++.h>
#include <math.h>
using namespace std;
template<typename T>
long long modpow(const T n,const T p,const T mod);
template<typename T>
long long modinv(const T n,const T mod);
template<typename T>
bool chmax(T &a,const T &b);
template<typename T>
bool chmin(T &a,const T &b);
long long inf=1000000007;
int main(){
int a,b;
cin>>a>>b;
for(int i=-1000;i<=1000;i++){
for(int j=-1000;j<=1000;j++){
if(i+j==a && i-j==b){
cout<<i<<" "<<j<<endl;
return 0;
}
}
}
return 0;
}
template<typename T>
long long modpow(const T n,const T p,const T mod){
if(p==0) return 1;
if(p%2==0){
long long a=modpow(n,p/2,mod);
return a*a%mod;
}
if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
cerr<<"ERROR"<<endl;
return 1;
}
template<typename T>
long long modinv(const T n,const T mod){
return modpow(n,mod-2,mod);
}
template<typename T>
bool chmax(T &a,const T &b){
if(a<b){
a=b;
return 1;
}
return 0;
}
template<typename T>
bool chmin(T &a,const T &b){
if(a>b){
a=b;
return 1;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
//# define M_PI 3.14159265358979323846
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, x0, y0, xn, yn;
cin >> n >> x0 >> y0 >> xn >> yn;
pair<double, double> c = {((double)(x0+xn)) /2., ((double)(y0+yn)) /2.};
pair<double, double> v = {x0 - c.first, y0 - c.second};
double r = sqrt(v.first * v.first + v.second * v.second);
double alpha;
if (x0 != xn) {
alpha = atan(v.second/v.first);
if (v.first < 0) {
alpha += M_PI;
}
} else {
alpha = M_PI/2.;
if (v.second < 0) {
alpha += M_PI;
}
}
pair<double, double> v1 = {r * cos(alpha + 2.*M_PI/n), r * sin(alpha + 2.*M_PI/n)};
cout << c.first + v1.first << " " << c.second + v1.second << endl;
return 0;
}
// go through problem examples
// for A, B: local structure, brute force
// unit test problem mechanics
// sums, multiplication -> long long
// lcm, gcd -> prime factorization -> first figure for one factor
// expectation, count -> sumation order
// max -> greedy, binsearch, dp
// bit operations -> figure of single bits
| #include<stdio.h>
#include<math.h>
static inline int IN(void)
{
int x=0,f=1,c=getchar();while(c<48||c>57){if(c==45){f=-f;}c=getchar();}
while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f*x;
}
int main(void)
{
int N=IN(),p[2][2];p[0][0]=IN(),p[0][1]=IN(),p[1][0]=IN(),p[1][1]=IN();
return !printf("%f %f\n",
(p[0][0]-(p[1][0]+p[0][0])/2.0)*cos(2*M_PI/(double)N)-(p[0][1]-(p[1][1]+p[0][1])/2.0)*sin(2*M_PI/(double)N)+(p[1][0]+p[0][0])/2.0,
(p[0][0]-(p[1][0]+p[0][0])/2.0)*sin(2*M_PI/(double)N)+(p[0][1]-(p[1][1]+p[0][1])/2.0)*cos(2*M_PI/(double)N)+(p[1][1]+p[0][1])/2.0
);
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n); for(auto& a : v) init(a, x, m...); }
int main(int argc, char** argv) {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(15);
if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
int n, t;
cin >> n >> t;
vector<vector<int>> T;
init(T, 0, n, n);
FOR(i, n) FOR(j, n) cin >> T[i][j];
int cnt = 0;
vector<int> v(n);
iota(v.begin(), v.end(), 0);
do{
if (v[0] != 0) break;
ll time = 0;
FOR(i, n-1)
time += T[v[i]][v[i+1]];
time += T[v[n-1]][0];
cnt += time == t;
}while(next_permutation(v.begin(), v.end()));
cout << cnt << endl;
if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll N,K;
cin >> N >> K;
vector<vector<int>> T(N,vector<int>(N));
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
cin >> T.at(i).at(j);
}
}
vector<int> perm(N - 1);
ll count = 0;
ll time;
for(int i = 0; i < N - 1; i++){
perm.at(i) = i + 1;
}
do{
time = T.at(0).at(perm.at(0));
for(int i = 0; i < N - 2; i++){
time += T.at(perm.at(i)).at(perm.at(i + 1));
}
time += T.at(perm.at(N - 2)).at(0);
if(time == K) count++;
}while(next_permutation(perm.begin(),perm.end()));
cout << count << endl;
}
|
// Username: WillTheBill
// Time of creation: 2020-11-22 13:51
// Original filename: m.cp.cpp
#include<bits/stdc++.h>
using namespace std;
// shortcuts
#define pb push_back
#define fi first
#define se second
#define all(_v) _v.begin(),_v.end()
#define ll long long
// IO
#define multitest signed __T; cin >> __T; while(__T--)
template<typename T>
void _read(T& t);
template<typename T>
void _read(vector<T>&v);
template<typename T1, typename T2>
void _read(pair<T1,T2>&p);
template<typename T>
void _read(T& t){cin >> t;}
template<typename T>
void _read(vector<T>&v){for(unsigned _i=0;_i<v.size();_i++)_read(v[_i]);}
template<typename T1, typename T2>
void _read(pair<T1,T2>&p){_read(p.first);_read(p.second);}
void _masterread(){}
template<typename T,typename... V>
void _masterread(T& t, V&... v){_read(t);_masterread(v...);}
#define re(...)_masterread(__VA_ARGS__)
template<typename T>
void _print(T t);
template<typename T>
void _print(vector<T>&v);
template<typename T1, typename T2>
void _print(pair<T1,T2>&p);
template<typename T>
void _print(T t){cout<<t;}
template<typename T>
void _print(vector<T>&v){for(unsigned _i=0;_i<v.size();_i++)_print(v[_i]),cout<<(_i==v.size()-1?"":" ");}
template<typename T1, typename T2>
void _print(pair<T1,T2>&p){_print(p.first);cout<<" ";_print(p.second);}
void _masterprint(){cout<<endl;}
template<typename T,typename... V>
void _masterprint(T t, V... v){_print(t);if(sizeof...(v))cout<<" ";_masterprint(v...);}
#define pr(...)_masterprint(__VA_ARGS__)
// DEBUG
// colored output???
template <typename T> // start forward declaration
void _debug(T t);
template<typename T1,typename T2>
void _debug(pair<T1,T2> p);
template<typename T>
void _debug(vector<T>v);
template <typename T> // end forward declaration
void _debug(T t){cerr<<t;}
template<typename T1,typename T2>
void _debug(pair<T1,T2> p){cerr<<"{";_debug(p.first);cerr<<", ";_debug(p.second);cerr<<"}";}
template<typename T>
void _debug(vector<T>v){cerr<<"(";for(unsigned _i=0;_i<v.size();_i++)_debug(v[_i]),cerr<<(_i==v.size()-1?"":", ");cerr << ")";}
void _masterdebug(){cerr<<"]\n";}
template<typename T,typename... V>
void _masterdebug(T t,V... v){_debug(t);if(sizeof...(v))cerr<<", ";_masterdebug(v...);}
#ifdef __local__
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"] = [";_masterdebug(__VA_ARGS__)
#else
#define debug(...)
#endif
// TYPES
// #define int long long
signed main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
vector<vector<vector<double>>> dp (101, vector<vector<double>> (101, vector<double> (101, 0.0)));
int A,B,C; re(A,B,C);
dp[A][B][C] = 1.0;
double sum = 0;
double propsum = 0;
for(int i = 0; i <= 100; i++){
for(int j = 0; j <= 100; j++){
for(int k = 0; k <= 100; k++){
if(i == A && j == B && k == C) continue;
int s = i + j + k;
if(s <= 1) continue;
if((i == 100 && j == 100) || (i == 100 && k == 100) || (j == 100 && k == 100)) continue;
if(i > 0 && j != 100 && k != 100) dp[i][j][k] += dp[i-1][j][k] * (i-1) / ((double)(s-1));
if(j > 0 && i != 100 && k != 100) dp[i][j][k] += dp[i][j-1][k] * (j-1) / ((double)(s-1));
if(k > 0 && i != 100 && j != 100) dp[i][j][k] += dp[i][j][k-1] * (k-1) / ((double)(s-1));
if(dp[i][j][k] < 0){
debug(i,j,k);
}
if(i == 100 || j == 100 || k == 100){
int amount = i - A + j - B + k - C;
if(amount < 0) continue;
debug(dp[i][j][k], i, j, k, amount);
sum += amount * dp[i][j][k];
propsum += dp[i][j][k];
}
}
}
}
debug(dp[99][99][99]);
debug(sum, propsum);
cout << setprecision(10) << fixed;
pr(sum / propsum);
}
| #include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
using P = pair<int,int>;
const char EOLN = '\n';
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define int long long
// DP
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
// 定数
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007 //問題による
const double pi = 3.14159265359;
// メモ
// vector二次元配列
// vector<vector<ll>> cnt(h,vector<ll> (w));
// bit演算
// for (int bit = 0; bit < (1<<k); ++bit)
// bit & (1 << i)
// 複数変数をいっきに代入
// tie(a,b,c) = make_tuple(10, 7.7, "hello");
//大きい配列はglobalで宣言しておいた方が良い
//3次元はvectorだと面倒だから配列で。
const int x=100;
double dp[x+1][x+1][x+1];
signed main()
{
int a,b,c;
cin >> a >> b >> c;
for(int i=x-1; i>=0; --i){
for(int j=x-1; j>=0; --j){
for(int k=x-1; k>=0; --k){
if(i+j+k == 0) continue;
double now = 0;
now += dp[i+1][j][k]*i;
now += dp[i][j+1][k]*j;
now += dp[i][j][k+1]*k;
dp[i][j][k] = now/(i+k+j) + 1;
}
}
}
double ans = dp[a][b][c];
//少数の出力はprintfで指定するのが良い
printf("%.10f\n",ans);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int64_t MOD = 1000000007;
double PI = 3.141592653589793;
int main()
{
int A, B, X, Y;
cin >> A >> B >> X >> Y;
int N = 200;
vector<vector<pair<int, int>>> list(N);
for (int i = 0; i < 100; i++)
{
list[i].push_back({i + 100, X}), list[i + 100].push_back({i, X});
if (i != 99)
{
list[i + 1].push_back({i + 100, X}), list[i + 100].push_back({i + 1, X});
list[i].push_back({i + 1, Y}), list[i + 1].push_back({i, Y});
list[i + 100].push_back({i + 101, Y}), list[i + 101].push_back({i + 100, Y});
}
}
vector<int> length(N, MOD); //始点からの距離
queue<int> que; //訪問予定
int search, now;
que.push(A - 1);
length[A - 1] = 0;
while (!que.empty())
{
int now = que.front();
que.pop();
for (int i = 0; i < list[now].size(); i++)
{
auto search = list[now][i];
int to = search.first; //目的地
int Length = search.second; //距離
if (length[to] > length[now] + Length)
{
length[to] = length[now] + Length;
que.push(to);
}
}
}
cout << length[B + 99];
} | /*
Three things which are very important --
Violence - Speed - Momentum
*/
#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 oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define setbits(x) __builtin_popcountll(x)
#define leadzero(x) __builtin_clz(x)
#define trailzero(x) __builtin_ctz(x)
#define bitsparity(x) __builtin_parity(x)
#define mod 1000000007
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define pre(y,x) fixed<<setprecision(y)<<x
#define dbg1(x) cerr << "|" << #x << ": " << (x) << "|\n";
#define dbg2(x,y) cerr << "|" << #x << ": " << (x) << "|" << #y << ": " << (y) << "|\n";
#define dbg3(x,y,z) cerr << "|" << #x << ": " << (x) << "|" << #y << ": " << (y) << "|" << #z << ": " << (z) << "|\n";
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define popb pop_back
#define endl '\n'
#define all(v) v.begin(), v.end()
#define sz(x) ((int)((x).size()))
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
ll power(ll a, ll b) {
if(b<0) return 1;
ll res=1;
while(b) {
if(b&1)
res = (res*a);//%mod;
a = (a*a);//%mod;
b >>= 1;
}
return res;
}
bool ispoweroftwo(ll x){ return (x&&!(x&(x-1)));}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
const int inf = 1e9;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
char MV[] = {'U', 'R', 'D', 'L'};
//integer to char always remember (char+'0')
const double pi = acos(-1);
const ll INF = 1e18;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
FIO;
int a, b, x, y;
cin >> a >> b >> x >> y;
int diff = abs(a-b);
if(diff == 0) {
cout << x;
}
else if(diff == 1) {
if(a > b) {
cout << x;
} else {
cout << min(diff*3*x-(diff-1)*x, x + diff*y);
}
} else {
if(a > b) {
cout << min(2*diff*x-x, x + (diff-1)*y);
} else {
cout << min(diff*3*x-(diff-1)*x, x + diff*y);
}
}
}
/*
*/
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pii pair<int,int>
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%lld",&t)
#define p(t) printf("%lld\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi 3.1415926358
#define bits(x) __builtin_popcountll(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<pii,vector<pii>,greater<pii> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define spitr set<pii>:: iterator
#define mitr map<int,int>:: iterator
#define E 0.0000001
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
tree_order_statistics_node_update>
new_data_set;
#define trace1(x) cerr<<#x<<": "<<x<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int32_t main()
{
fast;
string s;cin>>s;
int ans=0;
for(int i=0;i<=9999;i++)
{
string cur=tostring(i);
reverse(all(cur));
while(cur.size()<4)
cur+='0';
reverse(all(cur));
mii exist;
for(int j=0;j<4;j++)
exist[cur[j]]++;
bool flag=true;
for(int j=0;j<10;j++)
{
if(s[j]=='o' and !exist.count((j+'0')))
flag=false;
if(s[j]=='x' and exist.count((j+'0')))
flag=false;
}
ans+=(flag);
}
cout<<ans;
} | #include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int count = 0;
bool flag;
for (int i = 0; i < 10000; i++) {
flag = true;
vector<int> m(10);
int x = i;
for (int j = 0; j < 4; j++) {
m[x%10] = 1;
x /= 10;
}
for (int k = 0; k < 10; k++) {
if (s[k] == 'o' && m[k] != 1) flag = false;
if (s[k] == 'x' && m[k] != 0) flag = false;
}
if (flag) count++;
}
cout << count << endl;
} |
/* by Hyperhydrochloric Acid */
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define loop(i, n) for(int i = 0; i < (n); ++i)
#define cont(i, n) for(int i = 1; i <= (n); ++i)
#define circ(i, a, b) for(int i = (a); i <= (b); ++i)
#define range(i, a, b, c) for(int i = (a); ((c) > 0 ? i <= (b) : i >= (b)); i += (c))
#define foreach(it, v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define y0 y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1 y1II11II11III11I1III11II111IIII1II1I1
#define pub push_back
#define pob pop_back
#define mak make_pair
typedef long long ll;
typedef long double lf;
const int Inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */
const int jt = 1000000007;
int n;
char aa, ab, ba, bb;
int fib[1005];
int main() {
scanf("%d", &n);
scanf(" %c %c %c %c", &aa, &ab, &ba, &bb);
aa -= 'A'; ab -= 'A'; ba -= 'A'; bb -= 'A';
if((!ab && !aa) || (ab && bb)) {
// 固定
puts("1");
} else if((!ab && aa && ba) || (ab && !ba && !bb)) {
// 打印机
int cnt = 1;
cont(i, n - 3) (cnt *= 2) %= jt;
printf("%d\n", cnt);
} else {
// 漏墨打印机
fib[1] = 0; fib[2] = 1;
circ(i, 3, n) fib[i] = (fib[i - 1] + fib[i - 2]) % jt;
printf("%d\n", fib[n]);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main () {
int N;
cin >> N;
ll m = 1e9 + 7;
char a, b, c, d;
cin >> a >> b >> c >> d;
if (b == 'A') {
if (a == 'A') {
cout << 1 << endl;
return 0;
}
if (c == 'B') {
ll ret = 1;
for (int i = 0; i < N - 3; i ++) {
ret *= 2;
ret %= m;
}
cout << ret << endl;
return 0;
}
ll ans[1010];
ans[2] = ans[3] = 1;
for (int i = 4; i <= N; i ++) {
ans[i] = ans[i - 1] + ans[i - 2];
ans[i] %= m;
}
cout << ans[N] << endl;
} else {
if (d == 'B') {
cout << 1 << endl;
return 0;
}
if (c == 'A') {
ll ret = 1;
for (int i = 0; i < N - 3; i ++) {
ret *= 2;
ret %= m;
}
cout << ret << endl;
return 0;
}
ll ans[1010];
ans[2] = ans[3] = 1;
for (int i = 4; i <= N; i ++) {
ans[i] = ans[i - 1] + ans[i - 2];
ans[i] %= m;
}
cout << ans[N] << endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using LD = long double;
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }
void Main(){
const ll INF = 1e18;
ll n; cin >> n;
vll pow3(40, 3), pow5(30, 5);
rep(i, 40) {
if(pow3[i] > INF/3) break;
pow3[i+1] = 3 * pow3[i];
}
rep(i, 30) {
if(pow5[i] > INF/5) break;
pow5[i+1] = 5 * pow5[i];
}
rep(i, 40) rep(j, 30){
if(n == pow3[i] + pow5[j]){
cout << i+1 << " " << j+1 << endl;
return;
}
}
cout << -1 << endl;
return;
}
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
for (in_vec_cout res : vec) {cout << res << " ";}
cout << endl;
}
const ll inf = 1e18;
const ll mod = 1e9 + 7;
int main() {
ll N; cin >> N;
vector<ll> cnt(200);
rep(i,N) {
ll a; cin >> a;
cnt[a%200]++;
}
ll ans = 0;
for (ll v : cnt) {
ans += v*(v-1)/2;
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MOD 1000000007
#define MAX 100010
#define aout(a) REP(i,sizeof(a)) cout << a[i] << " "; cout << endl;
#define vout(v) REP(i,v,size()) cout << v[i] << " "; cout << endl;
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
int main(){
long double X,Y,A,B; cin>>X>>Y>>A>>B;
ll count = 0;
long double col;
while(X < Y){
if( (X*A < X+B) && (X*A < Y) ){
X *= A;
count++;
}
else if(X+B < Y){
col = (Y-X) / B;
count += ceil(col)-1;
break;
}
else break;
}
cout<<count;
}
| #include<bits/stdc++.h>
using namespace std;
#define GODSPEED ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define f first
#define s second
#define newl cout<<"\n";
#define pb push_back
#define mset(a,x) memset(a,x,sizeof(a))
#define debv(a) for(auto it: a)cout<<it<<" ";newl;
#define deb1(a) cout<<a<<"\n";
#define deb2(a,b) cout<<a<<" "<<b<<"\n";
#define deb3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define deb4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define uniq(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll N = 2e6+5;
const ll mod = 998244353;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll LEVEL = log2(N)+1;
ll n, m;
ll fastmod(ll x, ll y, ll m){
ll res = 1;
while(y){
if(y&1) res = res * x % m;
x = x * x % m;
y /= 2;
}
return res;
}
void solve(){
cin >> n >> m;
deb1(fastmod(10, n, m * m) / m)
}
int main(){
GODSPEED;
int test = 1;
//cin >> test;
for(int i = 1; i <= test; i++){
solve();
}
#ifndef ONLINE_JUDGE
cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#endif
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[10][10],num[10];
int main()
{
ll n,k,res=0;
cin>>n>>k;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>a[i][j];
for(int i=1;i<=n;i++)
num[i]=i;
do
{
ll last,now,sum=0;
for(int i=1;i<n;i++)
{
last=num[i];
now=num[i+1];
sum=sum+a[last][now];
}
sum=sum+a[1][num[n]];
if(sum==k)
res++;
}while(next_permutation(num+2,num+1+n));
cout<<res;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define length size()
#define int long long
#define ll long long
#include <cstdint>
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;
}
const int MOD = 1000000007;
const int mod = 1000000007;
const int MAX = 510000;
const double inf = 900719925474099;
template<typename T> string join(vector<T> &vec ,const string &sp){
int si = vec.length;
if(si==0){
return "";
}else{
stringstream ss;
rep(i,si-1){
ss << vec[i] << sp;
}
ss << vec[si - 1];
return ss.str();
}
}
vector<vector<int>> ruiseki2d(vector<vector<int>> vec){
rep(i,vec.size()-1){
rep(j,vec[0].size()-1){
vec[i+1][j+1] = vec[i][j+1]+vec[i+1][j]-vec[i][j]+vec[i+1][j+1];
}
}
return vec;
}
vector<int> ruiseki(vector<int> vec){
rep(i,vec.size()-1){
vec[i+1] += vec[i];
}
return vec;
}
int t,s;
int solve(int a){
return (a<0)?a*s:a*t;
}
signed main(void){
int n,k;
cin >> n >> k;
vector<int> vec(n-1);
vector<vector<int>> town(n,vector<int>(n));
rep(i,n-1){
vec[i] = i+1;
}
rep(i,n){
rep(j,n){
cin >> town[i][j];
}
}
int ans = 0;
do {
//cout << join(vec," ") <<endl;
int sum = 0;
int now = 0;
for(int i=0;i<n-1;i++){
int next = vec[i];
sum += town[now][next];
now = next;
}
sum += town[now][0];
if(sum == k) ans++;
}while (std::next_permutation(vec.begin(),vec.end()));
cout << ans << endl;
}
|
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define fi first
#define se second
#define vll vector<int>
#define pii pair<int,int>
#define pb push_back
#define sz(v) (int)(v).size()
#define inf (int)(1e18)
#define md (int)(1e9+7)
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=a;i<b;++i)
using namespace std;
const int M = 2e5 + 10;
#define K 101
int ex(int a,int b=md-2){
int ans=1;
while(b) {
if(b&1) ans=(ans*a)%md;
a=(a*a)%md,b/=2;
}
return ans;
}
inline int add(int a,int b){
a+=b;
if(a>=md) a-=md;
return a;
}
inline int sub(int a,int b){
a-=b;
if(a<0) a+=md;
return a;
}
inline int mul(int a,int b){
return (a*b)%md;
}
int f[M],iv[M];
int C(int n,int r){
if(n<r) return 0;
return mul(f[n],mul(iv[r],iv[n-r]));
}
void init(){
f[0]=1;
for(int i=1;i<M;++i) {
f[i]=mul(i,f[i-1]);
}
iv[M-1]=ex(f[M-1]);
for(int i=M-2;i>=0;--i) {
iv[i]=mul(i+1,iv[i+1]);
}
}
struct mat{
int data[K][K]={0};
};
mat operator*(mat &a, mat &b){
mat c;
for(int i=0;i<K;++i)for(int j=0;j<K;++j){
c.data[i][j]=0;
for(int k=0;k<K;++k) {
c.data[i][j]+=(a.data[i][k]*1ll*b.data[k][j])%md;
if(c.data[i][j]>=md) c.data[i][j]-=md;
}
}
return c;
}
mat operator^(mat &a,int b){
mat c;
for(int i=0;i<K;++i)for(int j=0;j<K;++j) c.data[i][j]=(i==j);
while(b){if(b&1)c=c*a;a=a*a;b/=2;}
return c;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,m,k;
cin>>n>>m>>k;
mat A;
int a[n];
rep(i,0,n) cin>>a[i];
int p=ex(mul(m,2));
rep(i,0,n)rep(j,0,n) {
A.data[i][j]=i==j;
}
rep(i,0,m) {
int u,v;
cin>>u>>v;
u--,v--;
A.data[u][v]=add(A.data[u][v],p);
A.data[v][u]=add(A.data[v][u],p);
A.data[u][u]=sub(A.data[u][u],p);
A.data[v][v]=sub(A.data[v][v],p);
}
A=A^k;
mat B;
rep(i,0,n) {
rep(j,0,n) B.data[i][j]=a[j];
}
A=B*A;
rep(i,0,n) cout<<A.data[i][i]<<"\n";
return 0;
} | #include<bits/stdc++.h>
using namespace std;
const int N=5005,mod=998244353;
int n,m,ans,f[N][2],g[N][2];
inline int add(int a,int b){
a+=b;
return a<mod?a:a-mod;
}
inline int dec(int a,int b){
a-=b;
return a<0?a+mod:a;
}
inline int mul(int a,int b){
return 1LL*a*b%mod;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
memset(f,0,sizeof(f));
memset(g,0,sizeof(f));
f[0][0]=1;
g[0][0]=0;
for(int j=1;j<=n;j++){
f[j][0]=add(mul(f[j-1][0],m-1),mul(f[j-1][1],i-1));
g[j][0]=add(mul(g[j-1][0],m-1),mul(g[j-1][1],i-1));
f[j][1]=add(f[j-1][0],mul(f[j-1][1],m-i+1));
if(j==n){
j++;
j--;
}
g[j][1]=add(g[j-1][0],f[j-1][0]);
g[j][1]=add(g[j][1],mul(g[j-1][1],m-i+1));
}
ans=add(ans,add(g[n][0],g[n][1]));
}
printf("%d\n",ans);
return 0;
} |
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned ll
#define uint unsigned int
#define db double
#define pint pair<int,int>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define Rep(x,y,z) for(int x=(y);x<=(z);x++)
#define Red(x,y,z) for(int x=(y);x>=(z);x--)
using namespace std;
const int MAXN=100005;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int n,m,a[MAXN],b[MAXN],c[MAXN],vis[MAXN],ans[MAXN];
vector<int>G[MAXN];
void dfs(int x){
vis[x]=1;
for(auto o:G[x]){
int y=a[o]+b[o]-x;
if(~ans[o])continue;
ans[o]=(y==a[o]);
if(vis[y])continue;
dfs(y);
}
}
int main(){
// freopen("std.in","r",stdin);
// freopen("std.out","w",stdout);
n=read(),m=read(),memset(ans,-1,sizeof(ans));
Rep(i,1,m)a[i]=read(),b[i]=read();
Rep(i,1,n)c[i]=read();
Rep(i,1,m)if(c[a[i]]==c[b[i]])
G[a[i]].pb(i),G[b[i]].pb(i);
Rep(i,1,n)if(!vis[i])dfs(i);
Rep(i,1,m){
if(c[a[i]]==c[b[i]])puts(ans[i]?"<-":"->");
else puts(c[a[i]]<c[b[i]]?"<-":"->");
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(type, val, n) for(type val = 0; val < n; ++val)
#define repi(type, val, init, end) for(type val = init; val < end; ++val)
using Int = long long;
using uInt = unsigned long long;
int main() {
uInt n, ans[100005] = { 0 };
cin >> n;
rep (int, i, n + 1) ans[i] = 1;
repi(int, i, 2, n + 1) {
if (ans[i] == 1) {
for (uInt check_pow = i; check_pow < n + 1; check_pow *= i)
for (uInt add_i = check_pow << (check_pow == i ? 1 : 0); add_i < n + 1; add_i += check_pow) {
ans[add_i]++;
}
ans[i]++;
}
else {}
}
repi (int, i, 1, n)
cout << ans[i] << " ";
cout << ans[n] << endl;
return 0;
} |
//Codeforcesで128bit整数を使いたいとき
//→__int128_tを使う&GNU C++17 (64)で提出する
//インクルードなど
#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;
typedef long long ll;
//イテレーション
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//x:コンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007 //問題による
//略記
#define F first
#define S second
//出力(空白区切りで昇順に)
#define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl;
#define coutall(x) {for(int i=0;i<sizeof(x)/sizeof(x[0]);i++){cout<<x[i]<<"|";};};cout<<endl;
//aをbで割る時の繰上げ,繰り下げ
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}
ll f(ll x){
if(x<1000){return 0;};
return 1+f(x/1000);
}
signed main(){
ll n;cin>>n;
ll a[n],b[n],c=INF32;
REP(i,n){
cin>>a[i]>>b[i];
c=min(c,a[i]+b[i]);
};
REP(i,n){REP(j,n){
if(i==j){continue;};
c=min(c,max(a[i],b[j]));
};};
cout<<c;
} | //fake_name
#include<bits/stdc++.h>
using namespace std ;
#define int long long int
#define F first
#define S second
int MOD = 998244353 ;
int mod = 1e9 + 7 ;
int inf = 1e18 ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
signed main()
{
ios_base::sync_with_stdio(false) ;
cin.tie(0) ; cout.tie(0) ;
int n ;
cin >> n ;
int a[n] , b[n] ;
for( int i = 0 ; i < n ; i++ )
cin >> a[i] >> b[i] ;
int ans = inf ;
for( int i = 0 ; i < n ; i++ ){
for( int j = 0 ; j < n ; j++ )
if( i == j )
ans = min( ans , a[i]+b[j] ) ;
else
ans = min( ans , max( a[i] , b[j] ) ) ;
}
cout << ans ;
cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
} |
#include <iostream>
using namespace std;
int main() {
int x,y;
cin >> x >> y;
if(x==y) {
cout << x << endl;
return 0;
}
else{
cout << 3-x-y << endl;
return 0;
}
} | #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
typedef long long int ll;
typedef long double ld;
#define MOD 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define endl '\n'
#define pb push_back
#define conts continue
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(), a.rend()
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
#define ff first
#define ss second
#define ceil2(x,y) (x+y-1) / y
#ifndef ONLINE_JUDGE
#define debug(x) cout << #x <<" = "; print(x); cout << endl;
#else
#define debug(x)
#endif
bool iseven(ll n) {if ((n & 1) == 0) return true; return false;}
void print(ll t) {cout << t;}
void print(int t) {cout << t;}
void print(string t) {cout << t;}
void print(char t) {cout << t;}
void print(double t) {cout << t;}
void print(ld t) {cout << t;}
template <class T, class V> void print(pair <T, V> p);
template <class T> void print(vector <T> v);
template <class T> void print(set <T> v);
template <class T, class V> void print(map <T, V> v);
template <class T> void print(multiset <T> v);
template <class T, class V> void print(pair <T, V> p) {cout << "{"; print(p.ff); cout << ","; print(p.ss); cout << "}";}
template <class T> void print(vector <T> v) {cout << "[ "; for (T i : v) {print(i); cout << " ";} cout << "]";}
template <class T> void print(set <T> v) {cout << "[ "; for (T i : v) {print(i); cout << " ";} cout << "]";}
template <class T> void print(multiset <T> v) {cout << "[ "; for (T i : v) {print(i); cout << " ";} cout << "]";}
template <class T, class V> void print(map <T, V> v) {cout << "[ "; for (auto i : v) {print(i); cout << " ";} cout << "]";}
void solve()
{
ll a,b; cin >> a >> b;
if(a == b){
cout << a << endl;
}
else{
if(a > b){
swap(a,b);
}
if(a == 0 && b == 1){
cout << 2 << endl;
}
else if(a == 0 && b == 2){
cout << 1 << endl;
}
else if(a == 1 && b == 2){
cout << 0 << endl;
}
}
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("D:/Competitive Programming/input.txt", "r", stdin);
freopen("D:/Competitive Programming/output.txt", "w", stdout);
#endif
fastio;
solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define ll long long
const int MAX_N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
void solve() {
int n, m; cin >> n >> m;
int f[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
char c; cin >> c;
f[i][j] = (c == '+' ? 1 : -1);
}
}
int dp[n][m]; // (Takahashi - Aoki)
for (int i = n - 1; i >= 0; i--) {
for (int j = m - 1; j >= 0; j--) {
if (i == n - 1 && j == m - 1) { // base case
dp[i][j] = 0;
} else if ((i + j) % 2) {
dp[i][j] = INF;
if (i + 1 < n) dp[i][j] = min(dp[i][j], dp[i + 1][j] - f[i + 1][j]);
if (j + 1 < m) dp[i][j] = min(dp[i][j], dp[i][j + 1] - f[i][j + 1]);
} else {
dp[i][j] = -INF;
if (i + 1 < n) dp[i][j] = max(dp[i][j], dp[i + 1][j] + f[i + 1][j]);
if (j + 1 < m) dp[i][j] = max(dp[i][j], dp[i][j + 1] + f[i][j + 1]);
}
}
}
if (dp[0][0] == 0) {
cout << "Draw\n";
} else {
cout << (dp[0][0] > 0 ? "Takahashi" : "Aoki") << "\n";
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int tc = 1;
// cin >> tc;
for (int t = 1; t <= tc; t++) {
// cout << "Case #" << t << ": ";
solve();
}
} | #include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
/*-------------------------------------------*/
int h, w;
char a[2009][2009];
int dp[2009][2009];
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> h >> w;
rep(i, h) cin >> a[i];
FORR(i, h) FORR(j, w) {
if(i + 1 < h || j + 1 < w) dp[i][j] = -1e9;
if(i + 1 < h)
chmax(dp[i][j], -dp[i + 1][j] + (a[i + 1][j] == '+' ? 1 : -1));
if(j + 1 < w)
chmax(dp[i][j], -dp[i][j + 1] + (a[i][j + 1] == '+' ? 1 : -1));
}
if(dp[0][0] < 0) cout << "Aoki\n";
if(dp[0][0] == 0) cout << "Draw\n";
if(dp[0][0] > 0) cout << "Takahashi\n";
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert
#define nl "\n"
const ll MOD = 998244353;
ll add(ll x, ll y) {
x += y;
if (x >= MOD) return x - MOD;
return x;
}
ll sub(ll x, ll y) {
x -= y;
if (x < 0) return x + MOD;
return x;
}
ll mult(ll x, ll y) {
return (x * y) % MOD;
}
template<typename T> T signum(T a) {
return (a > 0) - (a < 0);
}
template<typename T> T cmp(T a, T b) {
return signum(a-b);
}
template<typename T> bool mins(T& lhs , T& rhs) {
if (rhs < lhs) {
lhs = rhs;
return true;
}
return false;
}
template<typename T> bool maxs(T& lhs , T& rhs) {
if (rhs > lhs) {
lhs = rhs;
return true;
}
return false;
}
const int MAX = INT_MAX;
void gks(int tc) {
printf("Case #%d: ", tc);
};
int main() {
string s1, s2, s3;
cin>>s1;
cin>>s2;
cin>>s3;
string p = "0123456789";
set<char> a;
for (auto x : s1) a.insert(x);
for (auto x : s2) a.insert(x);
for (auto x : s3) a.insert(x);
if (a.size() >= 11) {
cout<<"UNSOLVABLE";
return 0;
}
bool f = false;
do {
map<char, int> my_map;
//if (p[0] == '0') continue;
int i = 0;
for (auto x : a) {
my_map[x] = p[i++];
}
string i1;
for (auto x : s1) {
i1.append(1, my_map[x]);
}
if (i1 == "0") continue;
string i2;
for (auto x : s2) {
i2.append(1, my_map[x]);
}
if (i2 == "0") continue;
string i3;
for (auto x : s3) {
i3.append(1, my_map[x]);
}
if (i3 == "0") continue;
ll j1 = stoll(i1);
ll j2 = stoll(i2);
ll j3 = stoll(i3);
/*
if (p == "0267495183") {
cout<<j1<<nl<<j2<<nl<<j3<<nl;
}
*/
if (j1 + j2 == j3 && i1[0] != '0' && i2[0] != '0' && i3[0] != '0') {
f = true;
cout<<j1<<nl<<j2<<nl<<j3<<nl;
break;
}
}while (next_permutation(p.begin(), p.end()));
if (!f) {
cout<<"UNSOLVABLE"<<nl;
}
return 0;
}
| // doot diddly donger cuckerino Hahahahahah
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vi = vector<int>;
#define all(x) (x).begin(), (x).end()
const ld PI = acos(-1);
template <typename T> inline T mini(T& x, T y) { return x = min(x, y); }
template <typename T> inline T maxi(T& x, T y) { return x = max(x, y); }
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T, typename U>
std::ostream& operator<<(std::ostream& stream, const pair<T, U>& p) {
return stream << p.first << " " << p.second;
}
template <typename T>
std::ostream& operator<<(std::ostream& out, const vector<T>& vec) {
for (const T& x: vec) out << x << ' ';
return out;
}
template <typename T>
std::istream& operator>>(std::istream& in, vector<T>& vec) {
for (auto& x: vec) in >> x;
return in;
}
class MEX {
struct MEXNode {
MEXNode *children[2];
bool is_full = false;
int cnt = 0;
public:
MEXNode() {
children[0] = nullptr;
children[1] = nullptr;
}
};
private:
inline MEXNode *nonnull(MEXNode *& n) {
if (!n) n = new MEXNode();
return n;
}
void insert(int val, int level, MEXNode *n) {
if (level == -1) {
n->cnt++;
n->is_full = true;
return;
}
int cur_bit = (val & (1 << level)) >> level;
insert(val, level - 1, nonnull(n->children[cur_bit]));
n->is_full = nonnull(n->children[0])->is_full && nonnull(n->children[1])->is_full;
n->cnt = nonnull(n->children[0])->cnt + nonnull(n->children[1])->cnt;
}
// Remove an integer from the set
void remove(int val, int level, MEXNode *n) {
if (level == -1) {
n->cnt--;
n->is_full = n->cnt > 0;
return;
}
int cur_bit = (val & (1 << level)) >> level;
remove(val, level - 1, nonnull(n->children[cur_bit]));
n->is_full = nonnull(n->children[0])->is_full && nonnull(n->children[1])->is_full;
n->cnt = nonnull(n->children[0])->cnt + nonnull(n->children[1])->cnt;
}
// Find the minimum element >=x that isn't present in the set
int get(int val, int level, MEXNode *n) {
if (n->is_full) {
return -1;
} else if (n->cnt == 0) {
return val;
}
int cur_bit = (val & (1 << level)) >> level;
int ans = get(val, level - 1, nonnull(n->children[cur_bit]));
if (cur_bit == 0 && ans == -1) {
ans = get((val >> level << level) | (1 << level), level - 1, nonnull(n->children[1]));
}
return ans;
}
MEXNode root_node;
public:
void insert(int x) {
insert(x, 31, &root_node);
}
void remove(int x) {
remove(x, 31, &root_node);
}
int get(int x) {
return get(x, 31, &root_node);
}
};
class CNeqMin {
public:
void solve(std::istream& cin, std::ostream& cout) {
int n;
cin >> n;
MEX mex;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
mex.insert(x);
cout << mex.get(0) << '\n';
}
}
};
int32_t main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
CNeqMin solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=1e5+5;
ll f[maxn][2],g[maxn];
int main()
{
ll ans=0,x;
int n;
scanf("%d",&n);
ll tot=2*n-3+(n-3)*(n-4)/2;
tot%=mod;
// 0 - 1 +
f[0][1]=1; g[0]=1;
for(int i=1;i<=n;i++)
{
f[i][0]=f[i-1][1];
f[i][1]=(f[i-1][0]+f[i-1][1])%mod;
g[i]=(f[i][0]+f[i][1])%mod;
}
for(int i=1;i<=n;i++)
{
scanf("%lld",&x);
x%=mod;
ll plus=0,multi=0;
plus=g[n-i];
if(i>=2) plus=g[i-2]*plus%mod;
if(i!=1) multi=1;
if(i>=3) multi=g[i-3];
if(i!=n) multi=g[n-i-1]*multi%mod;
ans=(ans+1LL*x*(plus-multi+mod)%mod)%mod;
}
printf("%lld",(ans+mod)%mod);
return 0;
} | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ll long long int
#define umap unordered_map
#define mod 1000000007ll
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MN(a,b,c) min(a,min(b,c))
#define MX(a,b,c) max(a,max(b,c))
#define pr1 pair<ll,ll>
#define F first
#define S second
#define mP make_pair
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,x,y) for(ll i=x;i<=y;i++)
#define f2(i,x,y) for(ll i=x;i>=y;i--)
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define modsum(a,b) ((a%mod)+(b%mod))%mod
#define modpro(a,b) ((a%mod)*(b%mod))%mod
#define moddif(a,b) ((a%mod)-(b%mod)+mod)%mod
#define modsumt(a,b,c) modsum(a,modsum(b,c))
//__builtin_popcount(x)
//__builtin_parity(x) =(number of set bits)%2
//__builtin_clz(x) to count the number of leading zeroes
//__builtin_ctz(x) to count the number of trailing zeroes
//__gcd(a,b)
// Binary Search
// TO AVOID GETTING INFINITE LOOP
// mid = (l+r)/2 l=mid+1 r=mid
// mid = (l+r+1)/2 l=mid r=mid-1
using namespace std;
ll fac[200005];
/*void calc_pow2()
{
pow2[0]=1;
for(ll i=1;i<63;i++) pow2[i]=2*pow2[i-1];
}*/
ll modularExponentiation(ll x,ll n,ll M)
{
ll result=1;
while(n>0)
{
if(n % 2 ==1)
result=modpro(result,x);
x=modpro(x,x);
n=n/2;
}
return result;
}
ll binaryExponentiation(ll x,ll n)
{
ll result=1;
while(n>0)
{
if(n % 2 ==1)
result=result * x;
x=x*x;
n=n/2;
}
return result;
}
ll pow1(ll x,ll y)
{
ll z=1;
while(y--){z=z*x;}
return z;
}
/*bool isprime(ll n)
{
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
// This is checked so that we can skip
// middle five numbers in below loop
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}*/
// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
return modularExponentiation(n, p - 2, p);
}
// Returns nCr % p using Fermat's little
// theorem.
unsigned long long nCrModPFermat(unsigned long long n,
ll r, ll p)
{
// Base case
if (r == 0)
return 1;
// Fill factorial array so that we
// can find all factorial of r, n
// and n-r
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}
ll check(ll x,ll y)
{
ll z=1;
ll ans=0;
while(z<x){ans++;z*=y;}
return ans;
}
ll countbits(ll n)
{
ll x=0;
while(n>0)
{
x++;
n=(n&(n-1));
}
return x;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;cin>>n;
vector <ll> a(n);
f(i,n) cin>>a[i];
if(n==1) cout<<a[0];
else
{
ll dp[n][2];
ll countp[n];
ll countn[n];
countp[1]=countn[1]=1;
dp[1][0]=a[1];
dp[1][1]=-1*a[1];
ll sum=0;
for(ll i=2;i<n;i++)
{
countp[i]=modsum(countp[i-1],countn[i-1]);
countn[i]=countp[i-1];
dp[i][0]=modsum(sum,modpro(countp[i],a[i]));
dp[i][1]=moddif(dp[i-1][0],modpro(countn[i],a[i]));
sum=modsum(dp[i][0],dp[i][1]);
//cout<<dp[i][0]<<' '<<dp[i][1]<<' '<<sum<<"\n";
}
ll num=modsum(countp[n-1],countn[n-1]);
num=modpro(num,a[0]);
sum=modsum(sum,num);
cout<<sum;
}
} |
// Problem : D - Let's Play Nim
// Contest : AtCoder - AtCoder Regular Contest 105
// URL : https://atcoder.jp/contests/arc105/tasks/arc105_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
int T;
int N;
int arr[100005];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> T;
while(T--){
cin >> N;
for(int i = 1; i<=N; i++){
cin >> arr[i];
}
sort(arr+1, arr+1+N);
if(N%2 == 1){
cout << "Second\n";
}
else{
bool secondwin = 1;
for(int i = 2; i<=N; i+=2){
if(arr[i] != arr[i-1]){
secondwin = 0;
}
}
if(secondwin){
cout << "Second\n";
}
else{
cout << "First\n";
}
}
}
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n; cin >> n;
map<int, int> mp;
vector<int> v(1 << n, 0);
for (int i = 0; i < 1 << n; i ++ )
{
int x; scanf("%d", &x);
v.push_back(x);
mp[x] = i;
}
for (int i = 0; i < n - 1; i ++ )
{
vector<int> a;
for (int j = 0; j < v.size(); j += 2)
a.push_back(max(v[j], v[j + 1]));
v = a;
}
cout << mp[min(v[v.size() - 2], v[v.size() - 1])] + 1 << endl;
return 0;
}
|
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#define Rint register int
#define INF 0x3f3f3f3f
using namespace std;
typedef long long lxl;
const int maxn=1e5+5;
template <typename T>
inline void read(T &x)
{
x=0;T f=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
x*=f;
}
int n,k;
lxl ans;
int main()
{
#ifndef ONLINE_JUDGE
freopen("B.in","r",stdin);
freopen("B.out","w",stdout);
#endif
read(n),read(k);
for(int i=2;i<=(n<<1);++i)
{
int j=i-k;
if((j<2)||(j>(n<<1))) continue;
ans+=1ll*(2*min(n,i-1)-i+1)*(2*min(n,j-1)-j+1);
}
printf("%lld\n",ans);
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;
int64_t solve(int64_t X) {
// TODO: edit here
return 100-X%100;
}
// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
constexpr char endl = '\n';
int64_t X;
cin >> X;
auto ans = solve(X);
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 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
class ops
{
public:
ll cx, cy, sx, sy;
bool sw;
ops()
{
cx = 0, cy = 0, sx = 1, sy = 1;
sw = 0;
}
void t1()
{
swap(cx,cy);
swap(sx,sy);
sy = -sy;
sw^=1;
cy = -cy;
}
void t2()
{
swap(cx,cy);
swap(sx,sy);
sx = -sx;
sw^=1;
cx = -cx;
}
void t3(ll p)
{
sx = -sx;
cx = -cx + 2*p;
}
void t4(ll p)
{
sy = -sy;
cy = -cy + 2*p;
}
pii get(pii pt)
{
if(sw)
swap(pt.ff, pt.ss);
pt.ff = pt.ff*sx + cx;
pt.ss = pt.ss*sy + cy;
return pt;
}
void conv(ll ty, ll p = -1)
{
if(ty == 1)
t1();
else if(ty == 2)
t2();
else if(ty == 3)
t3(p);
else t4(p);
}
};
int main()
{
FAST/**/
ll n;
cin>>n;
pii arr[n];
rep(n)
cin>>arr[i].ff>>arr[i].ss;
ll m;
cin>>m;
pii op[m];
rep(m)
{
cin>>op[i].ff;
if(op[i].ff>2)
cin>>op[i].ss;
}
ll q;
cin>>q;
pair<pii,ll> quer[q];
rep(q)
cin>>quer[i].ff.ff>>quer[i].ff.ss, quer[i].ss = i;
ops ds;
sort(quer,quer+q);
ll ptr = 0;
pii ans[q];
rep(q)
{
while(ptr<m && quer[i].ff.ff-1>=ptr){
//cout<<"applying "<<ptr+1<<' '<<op[ptr].ff<<'\n';
ds.conv(op[ptr].ff, op[ptr].ss), ptr++;
//cout<<ds.cx<<" "<<ds.cy<<" "<<ds.sx<<" "<<ds.sy<<'\n';
}
pii pt = ds.get(arr[quer[i].ff.ss-1]);
ans[quer[i].ss] = pt;
}
rep(q)
cout<<ans[i].ff<<" "<<ans[i].ss<<'\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007
#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()
using ll = long long;
template<class T> bool chmax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b){ if (a > b) { a = b; return true; } return false; }
int dp[1 << 17][17];
int main() {
int n;
int x[17], y[17], z[17], d[17][17];
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> x[i] >> y[i] >> z[i];
}
fill(d[0], d[n], INF);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
d[i][j] = abs(x[i] - x[j]) + abs(y[i] - y[j]) + max(0, z[j] - z[i]);
}
}
for (int k = 0; k < n; ++k) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
chmin(d[i][j], d[i][k] + d[k][j]);
}
}
}
fill(dp[0], dp[1 << n], INF);
dp[0][0] = 0;
for (int i = 0; i < (1 << n); ++i) {
for (int u = 0; u < n; ++u) {
for (int v = 0; v < n; ++v) {
if (!(i >> v & 1)) {
chmin(dp[i | (1 << v)][v], dp[i][u] + d[u][v]);
}
}
}
}
cout << dp[(1 << n) - 1][0] << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define read() freopen("in.txt","r",stdin)
#define write() freopen("out.txt","w",stdout)
typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef float flt;
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
#define pie acos(-1)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define MAX 300005
#define MOD 1000000007
#define INF 1000000100
#define for0(i, n) for(ll i=0; i<n; i++)
#define for1(i, n) for(ll i=1; i<=n; i++)
#define forab(i, a, b) for(ll i=a; i<=b; i++)
#define forabx(i, a, b, x) for(ll i=a; i<=b; i+=x)
#define forinv(i, a, b) for(ll i=a; i>=b; i--)
#define clr0(a) memset(a, 0, sizeof(a))
#define ceil(x, y) (x+y-1) / (y)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / __gcd(a, b))
#define sort1(a, x, y) sort(a+x, a+y+1)
#define debug(x) cout << "DEBUG " << x << endl;
#define Y() cout << "YES" << endl;
#define N() cout << "NO" << endl;
#define inArr(a, x, y) forab(i, x, y) { cin >> a[i]; }
#define outArr(a, x, y) forab(i, x, y) { cout << a[i] << " "; } cout << endl;
void solve() {
ll n;
cin >> n;
ll t[n+10], l[n+10], r[n+10];
for1(i, n) {
cin >> t[i] >> l[i] >> r[i];
}
ll ans = 0;
for1(i, n-1) {
forab(j, i+1, n) {
ll l1, r1, l2, r2;
if (t[i]==1) {
l1 = l[i]*10;
r1 = r[i]*10;
}
else if (t[i]==2) {
l1 = l[i]*10;
r1 = r[i]*10 - 1;
}
else if (t[i]==3) {
l1 = l[i]*10 + 1;
r1 = r[i]*10;
}
else if (t[i]==4) {
l1 = l[i]*10 + 1;
r1 = r[i]*10 - 1;
}
if (t[j]==1) {
l2 = l[j]*10;
r2 = r[j]*10;
}
else if (t[j]==2) {
l2 = l[j]*10;
r2 = r[j]*10 - 1;
}
else if (t[j]==3) {
l2 = l[j]*10 + 1;
r2 = r[j]*10;
}
else if (t[j]==4) {
l2 = l[j]*10 + 1;
r2 = r[j]*10 - 1;
}
if ( (l1>=l2 && l1<=r2) || (l2>=l1 && l2<=r1) || (r1>=l2 && r1<=r2) || (r2>=l1 && r2<=r1) ) {
ans ++;
//cout << "ANSWER ++ FOR " << i << " " << j << endl;
}
}
}
cout << ans << endl;
}
void testcase() {
ll t;
cin >> t;
while (t--) {
solve();
}
}
int main () {
FastIO()
//testcase();
solve();
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
/* // Ordered Set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define os_find(k) find_by_order(k)
#define os_order(k) order_of_key(k)
*/
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector<int> vi;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define mod 998244353//1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define make_graph(k) int x,y; f0(i,0,k){cin>>x>>y; adj[x].pb(y); adj[y].pb(x);}
#define test int t;cin>>t;while(t--)
int fact[300000];
int binExp(int x,int n)
{
int res=1;
while(n)
{
if(n&1) res=(res*x)%mod;
x=(x*x)%mod;
n>>=1;
}
return res;
}
int modInv(int i) {return binExp(i,mod-2);}
int ncr(int n,int r) {return (n>=r?(fact[n]*modInv(fact[r]))%mod*modInv(fact[n-r])%mod:0);}
signed main()
{
fast
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<a*d-b*c;
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define MOD 1000000007
#define INF LLONG_MAX
#define MINF LLONG_MIN
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
int pow(int x, int y, int mod) {
int temp;
if (y == 0)
return 1;
temp = (pow(x, y / 2, mod)) % mod;
if (y % 2 == 0)
return (temp * temp) % mod;
else
return (((x * temp) % mod) * temp) % mod;
}
int score(vector<int> &v) {
int ans = 0;
for(int i = 1; i <= 9; i ++) {
ans += i * pow(10, v[i]);
}
return ans;
}
void solve(int tno) {
int k; cin >> k;
vector<int> cards(10, k);
string S, T;
cin >> S >> T;
vector<int> t(10, 0), a(10, 0);
for(char ch : S) {
if(ch == '#')
continue;
t[ch - '0'] ++;
cards[ch - '0'] --;
}
for(char ch : T) {
if(ch == '#')
continue;
a[ch - '0'] ++;
cards[ch - '0'] --;
}
int taka = 0, aoki = 0;
for(int i = 1; i <= 9; i ++) {
for(int j = 1; j <= 9; j ++) {
if(i == j || cards[i] == 0 || cards[j] == 0)
continue;
t[i] ++;
a[j] ++;
if(score(t) > score(a))
taka += cards[i] * cards[j];
else
aoki += cards[i] * cards[j];
t[i] --;
a[j] --;
}
}
for(int i = 1; i <= 9; i ++) {
if(cards[i] < 2)
continue;
t[i] ++;
a[i] ++;
if(score(t) > score(a)) {
taka += cards[i] * (cards[i] - 1);
}
else {
aoki += cards[i] * (cards[i] - 1);
}
t[i] --;
a[i] --;
}
// cout << taka << ' ' << (taka + aoki) << endl;
printf("%.15lf\n", (taka * 1.0) / (taka + aoki));
}
int32_t main() {
FASTIO
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
// cin >> t;
t = 1;
for (int i = 1; i <= t; i ++)
solve(i);
} | //#pragma GCC optimize ("Ofast")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(),_obj.end()
#define F first
#define S second
#define INF 1e18
#define pll pair<ll, ll>
#define vll vector<ll>
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=1e5+11,mod=1e9+7;
ll max(ll a,ll b) {return ((a>b)?a:b);}
ll min(ll a,ll b) {return ((a>b)?b:a);}
vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
void sol(void)
{
cin>>n>>m;
string s[n];
vector<int> r[n];
vector<int> c[m];
int rp[n]={0};
int colp[m]={0};
int cnt=0;
for(int i=0;i<n;i++)
{
cin>>s[i];
for(int j=0;j<m;j++)
{
if(s[i][j]=='#')
r[i].pb(j),c[j].pb(i);
else
cnt++;
}
}
ll ans=0;
ll cc;
temp=power(2,cnt);
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(s[i][j]=='#')
continue;
while(rp[i]<r[i].size() && r[i][rp[i]]<j)
rp[i]++;
int right=((rp[i]<r[i].size())?r[i][rp[i]]:m);
int left=-1;
if(rp[i]>0)
left=r[i][rp[i]-1];
ll calc=temp+mod;
cc=right-left-1;
int up=-1;
int down=n;
while(colp[j]<c[j].size() && c[j][colp[j]]<i)
colp[j]++;
if(colp[j]<c[j].size())
down=c[j][colp[j]];
if(colp[j]>0)
up=c[j][colp[j]-1];
cc+=down-up-1;
cc--;
ll calc2=(power(2,cnt-cc));
calc-=calc2;
calc%=mod;
ans+=calc;
ans%=mod;
}
}
cout<<ans;
return ;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int test=1;
//cin>>test;
for(int i=1;i<=test;i++)
sol();
}
|
/*
author : aryan57
created : 29-May-2021 18:09:38 IST
*/
#include <bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
#define int long long
#define X first
#define Y second
#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define F(i, a, b) for (int i = a; i <= b; i++)
#define RF(i, a, b) for (int i = a; i >= b; i--)
const int mxn = 1e5;
const long long INF = 2e18;
const int32_t M = 1000000007;
// const int32_t M = 998244353;
const long double pie = acos(-1);
void solve_LOG()
{
int n;
cin>>n;
vector <int> v[3];
F(i,0,2*n-1)
{
int a;
cin>>a;
char x;
cin>>x;
if(x=='R')v[0].push_back(a);
if(x=='G')v[1].push_back(a);
if(x=='B')v[2].push_back(a);
}
if(sz(v[0])%2==0 && sz(v[1])%2==0 && sz(v[2])%2==0)
{
cout<<0;
cout<<"\n";
return;
}
int x=-1;
F(i,0,2)
{
if(sz(v[i])%2==0)
{
x=i;
break;
}
}
assert(x!=-1);
if(x==1)
{
swap(v[1],v[2]);
}
if(x==0)
{
swap(v[0],v[2]);
}
sort(all(v[0]));
sort(all(v[1]));
int ans=INF;
for(int x : v[0])
{
int pos=lower_bound(all(v[1]),x)-v[1].begin();
F(i,pos-3,pos+3)
{
if(i<0 || i>=sz(v[1]))continue;
ans=min(abs(x-v[1][i]),ans);
}
}
assert(ans!=INF);
vector<pair<int,int> > vec(sz(v[2]));
int mnx=INF;
int mnx_pos=-1;
int mny=INF;
int mny_pos=-1;
F(j,0,sz(v[2])-1)
{
int pos=lower_bound(all(v[0]),v[2][j])-v[0].begin();
int mn=INF;
F(i,pos-3,pos+3)
{
if(i<0 || i>=sz(v[0]))continue;
mn=min(abs(v[2][j]-v[0][i]),mn);
}
// assert(mn!=INF);
vec[j].X=mn;
if(mnx>mn)
{
mnx=mn;
mnx_pos=j;
}
pos=lower_bound(all(v[1]),v[2][j])-v[1].begin();
mn=INF;
F(i,pos-3,pos+3)
{
if(i<0 || i>=sz(v[1]))continue;
mn=min(abs(v[2][j]-v[1][i]),mn);
}
// assert(mn!=INF);
vec[j].Y=mn;
if(mny>mn)
{
mny=mn;
mny_pos=j;
}
}
if(mnx_pos!=mny_pos)
{
ans=min(ans,mnx+mny);
}else
{
F(i,0,sz(vec)-1)
{
if(i!=mnx_pos)ans=min(ans,mnx+vec[i].Y);
if(i!=mny_pos)ans=min(ans,mny+vec[i].X);
}
}
cout<<ans;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
#ifdef ARYAN_SIEVE
sieve();
#endif
#ifdef ARYAN_SEG_SIEVE
segmented_sieve();
#endif
#ifdef ARYAN_FACT
fact_init();
#endif
// cout<<fixed<<setprecision(10);
int _t=1;
// cin>>_t;
for (int i=1;i<=_t;i++)
{
// cout<<"Case #"<<i<<": ";
solve_LOG();
}
return 0;
}
// parsed : 29-May-2021 18:09:30 IST | //#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define uni(x) sort(all(x)),x.resize(unique(all(x))-x.begin());
#define GETPOS(c,x) (lower_bound(all(c),x)-c.begin())
#define lown1(x,val) low(in(x),val)-x
#define lowm1(x,val) low(im(x),val)-x
#define low1(x,nums,val) low(x+1,x+nums+1,val)-x
#define mst(x,val) memset((x),val,sizeof((x)))
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define far(i,V) for(auto &i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lcm(a,b) ((a)*(b))/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) ((x)&(-x))
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (((x)<0)?(x)%mo_num+mo_num:(x)%mo_num)
#define vc vector
#define vct vector<int>
#define SET set<int>
#define dq deque<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define Umap unordered_map<int,int>
#define P pair<int,int>
#define mk make_tuple
#define eps 1e-6
//Remember cancel"#define endl '\n'" in interactive questions or use "<<flush"
#define endl '\n'
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
//#define yn(key) out(key?"Yes":"No")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
#define ik(i,k) i+1,i+1+k
#define bffs(i) __builtin_ffs(i)
#define bcount(i) __builtin_popcount(i)
#define bone(i) ((1<<i)-1)
#define db double
#define ll long long
#define got(container,num) get<num-1>(container)
#define int long long
#define print(a,n) fun(i)cout<<a[i]<<(i!=n?' ':endl);
#define outcase(x) cout<<"Case #"<<(++case_of_T)<<": "<<(x)<<endl;
#define ptcase(x) printf("Case #%d: %d\n",++case_of_T,x);
#define plcase(x) printf("Case #%lld: %lld\n",++case_of_T,x);
using namespace std;
//Remember to cancel the line below and declare INT=INT_MAX/2; when you want to change long to int
const int INF=LLONG_MAX/4,SINF=0x3f3f3f3f,Lim=1<<20,MINF=LLONG_MAX;
//const int INF=INT_MAX/4,SINF=0x3f;
// use C:printf("%.16f", x); -> printf("%.10f", x); can accelerate the program
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};//down up left right
const int maxn=1e6+1e5;
int mo_num=1e9+7;
//const int mo_num=998244353;
int n,m,t,a[maxn],b[maxn],ans,case_of_T;
void solve()
{
cin>>n;
fun(i)cin>>a[i];
int now=0;
fu(i,2,1000)
{
int num=0;
fun(j)num+=a[j]%i==0;
if(num>now)
{
now=num;ans=i;
}
}
out(ans)
return ;
}
main()
{
IOS
int T=1;
//cin>>T;
while(T--)solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define read read1<ll>()
# define Type template<typename T>
Type T read1(){
T t=0;
char k;
bool vis=0;
do (k=getchar())=='-'&&(vis=1);while('0'>k||k>'9');
while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar();
return vis?-t:t;
}
# define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout)
const int N=90;
ll fib[135],s;
vector<pair<int,int> >ans;
int main(){s=read;
fib[1]=fib[0]=1;
for(int i=2;i<=N;++i)fib[i]=fib[i-1]+fib[i-2];
if(s==1)return printf("1\n1"),0;
vector<int>ve;
for(int i=N;i&&s;--i)
if(fib[i]<=s){
ve.push_back(i);
s-=fib[i];
}
for(int i=1;i<ve.size();++i)
if(ve[0]-ve[i]&1)
ans.push_back(make_pair(ve[0]-ve[i],1));
else ans.push_back(make_pair(ve[0]-ve[i],2));
for(int i=1;i<ve[0];++i)
ans.push_back(make_pair(i,i&1?4:3));
ans.push_back(make_pair(-1,1));
ans.push_back(make_pair(-1,2));
sort(ans.begin(),ans.end());
if(~ve[0]&1)
for(int i=0;i<ans.size();++i)
if(ans[i].second<=2)ans[i].second=3-ans[i].second;
else ans[i].second=7-ans[i].second;
cout<<ans.size()<<endl;ll l=0,r=0;
for(int i=0;i<ans.size();++i)printf("%d\n",ans[i].second)/*,ans[i].second==1?++l:ans[i].second==2?++r:ans[i].second==3?l+=r:r+=l*/;
// cout<<l<<' '<<r<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 101;
int dp[N][N * N * N], cnt[N];
int n, k, mod;
void upd(int & var, int val) {
var += val;
if (var >= mod)
var -= mod;
}
int main() {
scanf("%d %d %d", &n, &k, &mod);
dp[0][0] = 1;
int sum = 0;
for (int x = 1; x <= n; ++x) {
memset(cnt, 0, sizeof cnt);
sum += k * x;
int full = k * x;
for (int j = 0, z = 0; j <= sum; ++j) {
int now = dp[x-1][j];
upd(cnt[z], now);
dp[x][j] = cnt[z];
if (j >= full) {
upd(cnt[z], mod - dp[x-1][j-full]);
}
++z;
if (z >= x)
z -= x;
}
}
for (int i = 1; i <= n; ++i) {
int lef = i - 1, rig = n - i;
long long ans = 0;
for (int j = 0; j <= sum; ++j) {
ans = (ans + 1LL * dp[lef][j] * dp[rig][j]) % mod;
}
ans = (ans * (k+1) - 1) % mod;
if (ans < 0)
ans += mod;
printf("%lld\n", ans);
}
return 0;
}
|
#include <cstdio>
const int maxn=100+10;
struct E{
int to;
int next;
}ed[maxn*maxn*2];
int head[maxn];
int tot;
void J(int a,int b){
ed[++tot].to=b;
ed[tot].next=head[a];
head[a]=tot;
}
int en;
int vis[maxn];
int ans;
void Dfs(int x){
if(x==en+1){
ans++;
return;
}
if(!head[x]){
Dfs(x+1);
return;
}
for(int i=head[x];i;i=ed[i].next){
if(vis[ed[i].to]){
Dfs(x+1);
return;
}
}
Dfs(x+1);
vis[x]=1;
Dfs(x+1);
vis[x]=0;
}
long long gcd(long long a,long long b){
return b?gcd(b,a%b):a;
}
int main(){
long long a,b;
scanf("%lld%lld",&a,&b);
en=b-a+1;
for(int i=1;i<=b-a+1;i++)
for(int j=1;j<=b-a+1;j++){
if(i==j)
continue;
if(gcd(a+i-1,a+j-1)!=1){
J(i,j);
J(j,i);
}
}
Dfs(1);
int ha=0;
for(int i=1;i<=b-a+1;i++)
if(!head[i])
ha++;
printf("%lld",1ll*ans*(1ll<<ha));
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
int const MAXN = 1 << 21;
int n, m, T;
int p[30], cnt;
int dp[MAXN];
void init() {
for (int i = 2; i < 72; i++) {
int f = 1;
for (int j = 2; j * j <= i; j++) {
if (i % j == 0) {
f = 0;
break;
}
}
if (f) p[cnt++] = i;
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int A, B;
cin >> A >> B;
init();
dp[0] = 1;
for (int x = A; x <= B; x++) {
int bit = 0;
for (int i = 0; i < cnt; i++)
if (x % p[i] == 0) bit |= (1 << i);
for (int i = 0; i < (1 << cnt); i++)
if (!(bit & i)) {
dp[bit | i] += dp[i];
}
}
int ans = 0;
for (int i = 0; i < (1 << cnt); i++) ans += dp[i];
cout << ans;
return 0;
} |
# include <bits/stdc++.h>
# ifndef ngng628_library
# define ngng628_library
# define int long long
# define float long double
# define fi first
# define se second
# define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i,n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i,n) for(int i=((int)(n)); i>0; --i)
# define repr(i,b,e) for(int i=(b), i##_len=(e); i<i##_len; ++i)
# define reprs(i,b,e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define all(x) std::begin(x), std::end(x)
# define rall(x) std::rbegin(x), std::rend(x)
# define pb push_back
# define eb emplace_back
# define len(x) ((int)(x).size())
using namespace std;
template<class T> using vec = vector<T>;
using pii = pair<int, int>;
using vi = vec<int>;
using vvi = vec<vi>;
using db = deque<bool>;
using ddb = deque<db>;
using vs = vec<string>;
constexpr int INF = (1LL<<62)-(1LL<<31);
constexpr float EPS = 1e-10;
template<class T> istream& operator>>(istream& is, vec<T>& v) { for (auto& x : v) is >> x; return is; }
template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.fi >> p.se; }
template<class T> string join(const vec<T> &v){ stringstream s; rep (i, len(v)) s<<' '<<v[i]; return s.str().substr(1); }
template<class T> ostream& operator<<(ostream& os, const vec<T>& v){ if (len(v)) os << join(v); return os; }
template<class T> ostream& operator<<(ostream& os, const vec<vec<T>>& v){ rep (i, len(v)) if (len(v[i])) os << join(v[i]) << (i-len(v)+1 ? "\n" : ""); return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << p.fi << " " << p.se; }
template<class T, class U, class V> ostream& operator<<(ostream& os, const tuple<T, U, V>& t){ return os << get<0>(t) << " " << get<1>(t) << " " << get<2>(t); }
void print(){ cout << "\n"; }
template<class T, class... A>void print(const T& v, const A&...args){ cout << v; if(sizeof...(args))cout << " "; print(args...); }
void eprint() { cerr << "\n"; }
template<class T, class... A>void eprint(const T& v, const A&...args){ cerr << v; if(sizeof...(args))cerr << " "; eprint(args...); }
void drop(){ cout << "\n"; exit(0); }
template<class T, class... A>void drop(const T& v, const A&...args){ cout << v; if(sizeof...(args))cout << " "; drop(args...); }
template<class T> constexpr bool chmax(T &a, const T& b) { return a < b && (a = b, true); }
template<class T> constexpr bool chmin(T &a, const T& b) { return a > b && (a = b, true); }
constexpr int ctoi(const char c) { return ('0' <= c and c <= '9') ? (c - '0') : -1; }
struct Setup_io { Setup_io() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cerr.tie(0); cout << fixed << setprecision(15); } } setup_io;
# endif // ngng628_library
vi divisor(int n) {
vi v;
for (int i = 1; i*i <= n; i++) {
if (n % i == 0) {
v.pb(i);
if (i*i != n) v.pb(n / i);
}
}
sort(all(v));
return v;
}
struct Solver {
void solve() {
int n;
cin >> n;
if (n % 2 == 0 and (n / 2) & 1) {
print("Same");
}
else if (n % 2 == 0) {
print("Even");
}
else {
print("Odd");
}
}
};
int32_t main() {
int t;
cin >> t;
while (t--) {
Solver solver;
solver.solve();
}
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 1000000000000
typedef long long ll;
int main()
{
int n, cnt = 0;
cin >> n;
string t;
cin >> t;
if (n == 1)
{
if (t == "0")
{
cout << 10000000000 << endl;
}
else
{
cout << 2 * 10000000000 << endl;
}
}
else if (n == 2)
{
if ((t == "11") || (t == "10"))
{
cout << 10000000000 << endl;
}
else if (t == "01")
{
cout << 10000000000 - 1 << endl;
}
else
{
cout << 0 << endl;
}
}
else
{
REP(i, t.length() - 2)
{
if ((t[i] == '0' && t[i + 1] == '1' && t[i + 2] == '0') || (t[i] == '1' && t[i + 1] == '1' && t[i + 2] == '1') || (t[i] == '0' && t[i + 1] == '0' && t[i + 2] == '1') || (t[i] == '1' && t[i + 1] == '0' && t[i + 2] == '0') || (t[i] == '0' && t[i + 1] == '0' && t[i + 2] == '0'))
{
cout << 0 << endl;
return 0;
}
}
REP(i, t.length())
{
if (t[i] == '0')
{
cnt++;
}
}
if (t[t.length() - 1] == '0')
{
cout << 10000000000 - cnt + 1 << endl;
}
else
{
cout << 10000000000 - cnt << endl;
}
}
} |
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
typedef long long ll;
using namespace std;
ll n;
void solve()
{
cin >> n;
int cnt = 0;
while(n%2==0)
{
n/=2;
cnt++;
}
if(cnt==1) cout << "Same" << endl;
else if(cnt==0) cout << "Odd" << endl;
else cout << "Even" << endl;
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int tc=1;
cin>>tc;
for(int i=1;i<=tc;i++)
{
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long n, t;
int main()
{
ios_base::sync_with_stdio(false);
cin>>t;
while (t--)
{
cin>>n;
if (n%2==1) cout<<"Odd"<<"\n";
else if ((n/2)%2==1) cout<<"Same"<<"\n";
else cout<<"Even"<<"\n";
}
} |
#include<iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <cstring>
#include <cassert>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
//#define L_JUDGE
#ifdef L_JUDGE
#pragma warning(disable:4996)
#endif
using namespace std;
inline int read() {
int x = 0, f = 1; char ch = getchar();
while(ch > '9' || ch < '0') { if(ch == '-') f = -1; ch = getchar(); }
do x = x * 10 + ch - 48, ch = getchar(); while(ch >= '0' && ch <= '9');
return x * f;
}
LL bin(LL x, LL n, LL MOD) {
LL ret = MOD != 1;
for (x %= MOD; n; n >>= 1, x = x * x % MOD)
if (n & 1) ret = ret * x % MOD;
return ret;
}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
const int MOD=1e9+7;
const int MAXN=2010;
char G[MAXN][MAXN];
LL H, W;
LL d[MAXN][MAXN];
void Solve(){
cin>>H>>W;
int cnt=0;
for(int i=0;i<H;i++){
cin>>G[i];
for(int j=0;j<W;j++){
if(G[i][j]=='.')cnt++;
}
}
memset(d, 0, sizeof(d));
for(int ri=0;ri<H;ri++){
int l[MAXN], r[MAXN];
int a=-1, b=W;
for(int ci=0;ci<W;ci++){
if(G[ri][ci]=='#'){
a=ci;
}
l[ci]=a;
}
for(int ci=W-1;ci>=0;ci--){
if(G[ri][ci]=='#'){
b=ci;
}
r[ci]=b;
}
for(int ci=0;ci<W;ci++){
if(r[ci]-1>=l[ci]+1)
d[ri][ci]+=(r[ci]-1-l[ci]-1);
}
}
for(int ci=0;ci<W;ci++){
int l[MAXN], r[MAXN];
int a=-1,b=H;
for(int ri=0;ri<H;ri++){
if(G[ri][ci]=='#'){
a=ri;
}
l[ri]=a;
}
for(int ri=H-1;ri>=0;ri--){
if(G[ri][ci]=='#'){
b=ri;
}
r[ri]=b;
}
for(int ri=0;ri<H;ri++){
if(r[ri]-1>=l[ri]+1)
d[ri][ci]+=(r[ri]-1-l[ri]);
}
}
LL ans=0;
for(int ri=0;ri<H;ri++){
for(int ci=0;ci<W;ci++){
if(G[ri][ci]=='#')continue;
ans = ans+bin(2, cnt-d[ri][ci], MOD)*(bin(2, d[ri][ci], MOD)-1)%MOD;
ans %= MOD;
}
}
cout<<ans<<endl;
}
int main(){
#ifdef L_JUDGE
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
Solve();
return 0;
#ifdef L_JUDGE
fclose(stdin);
fclose(stdout);
// system("out.txt");
#endif
return 0;
}
| #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<vector>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#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>;
using i64 = int_fast64_t;
constexpr i64 MAX = 10000000;
constexpr i64 MOD = 1000000007;
i64 fac[MAX], finv[MAX], inv[MAX];
template <i64 modulus>
class modcal
{
public:
i64 a;
constexpr modcal(const i64 x = 0) noexcept : a(x % modulus) {}
constexpr i64 &value() noexcept { return a; }
constexpr const i64 &value() const noexcept { return a; }
constexpr modcal operator+(const modcal rhs) const noexcept
{
return modcal(*this) += rhs;
}
constexpr modcal operator-(const modcal rhs) const noexcept
{
return modcal(*this) -= rhs;
}
constexpr modcal operator*(const modcal rhs) const noexcept
{
return modcal(*this) *= rhs;
}
constexpr modcal operator/(const modcal rhs) noexcept
{
return modcal(*this) /= rhs;
}
constexpr modcal &operator+=(const modcal rhs) noexcept
{
a += rhs.a;
if (a >= modulus)
{
a -= modulus;
}
return *this;
}
constexpr modcal &operator-=(const modcal rhs) noexcept
{
if (a < rhs.a)
{
a += modulus;
}
a -= rhs.a;
return *this;
}
constexpr modcal &operator*=(const modcal rhs) noexcept
{
a = a * rhs.a % modulus;
return *this;
}
constexpr modcal &operator/=(modcal rhs) noexcept
{
i64 exp = modulus - 2;
while (exp)
{
if (exp % 2)
{
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
void COMninit()
{
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++)
{
fac[i] = fac[i - 1] * i % modulus;
inv[i] = MOD - inv[modulus % i] * (modulus / i) % modulus;
finv[i] = finv[i - 1] * inv[i] % modulus;
}
}
i64 COMn(i64 n, i64 k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % modulus) % modulus;
}
constexpr modcal<1000000007> modpow(const modcal<1000000007> &a, i64 n)
{
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
using modc = modcal<1000000007>;
i64 Left[2100][2100],Right[2100][2100],Up[2100][2100],Down[2100][2100];
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 h,w;
cin >> h >> w;
vector<string> a(h);
i64 k = 0;
rep(i,h){
cin >> a[i];
rep(j,w){
if(a[i][j] == '.')k++;
}
}
rep(i,h){
i64 cur = 0;
rep(j,w){
if(a[i][j] == '#')cur = 0;
else cur++;
Left[i][j] = cur;
}
}
rep(i,h){
i64 cur = 0;
for(i32 j = w - 1; 0 <= j; j--){
if(a[i][j] == '#')cur = 0;
else cur++;
Right[i][j] = cur;
}
}
rep(j,w){
i64 cur = 0;
rep(i,h){
if(a[i][j] == '#')cur = 0;
else cur++;
Up[i][j] = cur;
}
}
rep(j,w) {
i64 cur = 0;
for (i32 i = h - 1; i >= 0; i--) {
if (a[i][j] == '#')cur = 0;
else cur++;
Down[i][j] = cur;
}
}
modc ans = 0;
rep(i,h){
rep(j,w){
if(a[i][j] == '#')continue;
i64 num = Left[i][j] + Right[i][j] + Up[i][j] + Down[i][j] - 3;
modc base = 2;
ans += ans.modpow(base,k).a;
ans -= ans.modpow(base,(k - num)).a;
}
}
cout << ans.a << endl;
} |
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
}
} iosetup;
template <typename Abelian>
struct BIT {
BIT(int n, const Abelian ID = 0) : n(n), ID(ID), dat(n, ID) {}
void add(int idx, Abelian val) {
while (idx < n) {
dat[idx] += val;
idx |= idx + 1;
}
}
Abelian sum(int idx) const {
Abelian res = ID;
--idx;
while (idx >= 0) {
res += dat[idx];
idx = (idx & (idx + 1)) - 1;
}
return res;
}
Abelian sum(int left, int right) const {
return left < right ? sum(right) - sum(left) : ID;
}
Abelian operator[](const int idx) const { return sum(idx, idx + 1); }
int lower_bound(Abelian val) const {
if (val <= ID) return 0;
int res = 0, exponent = 1;
while (exponent <= n) exponent <<= 1;
for (int mask = exponent >> 1; mask > 0; mask >>= 1) {
if (res + mask - 1 < n && dat[res + mask - 1] < val) {
val -= dat[res + mask - 1];
res += mask;
}
}
return res;
}
private:
int n;
const Abelian ID;
std::vector<Abelian> dat;
};
int main() {
int n, m, q; cin >> n >> m >> q;
vector<int> t(q), x(q), y(q); REP(i, q) cin >> t[i] >> x[i] >> y[i], --t[i], --x[i];
vector<int> z = y;
z.emplace_back(0);
sort(ALL(z));
z.erase(unique(ALL(z)), z.end());
int l = z.size();
vector<int> a[2]{vector<int>(n, 0), vector<int>(m, 0)};
BIT<int> num[2]{BIT<int>(l), BIT<int>(l)};
num[0].add(0, n);
num[1].add(0, m);
BIT<ll> sum[2]{BIT<ll>(l), BIT<ll>(l)};
ll ans = 0;
REP(i, q) {
int c = t[i], d = t[i] ^ 1, idx = lower_bound(ALL(z), a[c][x[i]]) - z.begin();
ans -= 1LL * num[d].sum(0, idx) * a[c][x[i]];
ans -= sum[d].sum(idx, l);
num[c].add(idx, -1);
sum[c].add(idx, -a[c][x[i]]);
idx = lower_bound(ALL(z), y[i]) - z.begin();
ans += 1LL * num[d].sum(0, idx) * y[i];
ans += sum[d].sum(idx, l);
num[c].add(idx, 1);
sum[c].add(idx, y[i]);
a[c][x[i]] = y[i];
cout << ans << '\n';
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef unsigned long long ull;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define ep emplace_back
#define EL printf("\n")
#define sz(A) (int) A.size()
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define FOD(i,r,l) for (int i=r;i>=l;i--)
#define fillchar(a,x) memset(a, x, sizeof (a))
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL);
double MIN = 0;
int main()
{
faster;
int n;
double D, H;
cin >> n >> D >> H;
FOR(i,1,n) {
int d, h;
cin >> d >> h;
double d1 = D - d, h1 = H - h;
double l = (h1 / d1) * D;
MIN = max(MIN, H - l);
}
cout << MIN;
return 0;
}
|
#include <algorithm>
#include <array>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <optional>
#include <queue>
#include <set>
#include <string>
#include <string_view>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
int64_t read_int() {
int64_t ret = 0, sgn = 1;
int ch = getchar_unlocked();
while (isspace(ch)) { ch = getchar_unlocked(); }
if (ch == '-') { sgn = -1; ch = getchar_unlocked(); }
for (; isdigit(ch); ch = getchar_unlocked())
ret = (ret * 10) + (ch - '0');
ungetc(ch, stdin);
return sgn * ret;
}
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
template <typename T> inline void assign_min(T& x, const T& value) noexcept { x = min(x, value); }
template <typename T> inline void assign_max(T& x, const T& value) noexcept { x = max(x, value); }
constexpr char LF = '\n';
//-------------------------------------------------------------------------------------------------
int main() {
vector<int64_t> A(4);
REP(i, 4) { A[i] = read_int(); }
int all_sum = A[0]+A[1]+A[2]+A[3];
bool ok = false;
REP(a, 2) REP(b, 2) REP(c, 2) REP(d, 2) {
if (a+b+c+d > 0) {
int64_t sum = 0;
if(a > 0) sum += A[0];
if(b > 0) sum += A[1];
if(c > 0) sum += A[2];
if(d > 0) sum += A[3];
if(sum == all_sum-sum) {
ok = true;
}
}
}
if (ok) cout << "Yes\n";
else cout << "No\n";
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 25;
int G[MAXN][MAXN];
int n, m;
int dp[(1 << 18) + 10];
int solve(int x) {
if (dp[x]) return dp[x];
bool flag = 1;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (((x >> i) & 1) && ((x >> j) & 1)) {
if (!G[i + 1][j + 1]) {
flag = 0;
break;
}
}
}
}
if (flag) {
return dp[x] = 1;
}
int res = MAXN;
for (int s = x; s > 0; s = (s - 1) & x) {
if (s == 0) break;
if (s == x) continue;
res = min(res, solve(s) + solve(x ^ s));
}
return dp[x] = res;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int u, v;
scanf("%d%d", &u, &v);
G[u][v] = G[v][u] = 1;
}
// if (m == 0) {
// printf("%d\n", n);
// return 0;
// }
int ans = solve((1 << n) - 1);
printf("%d\n", ans);
return 0;
} |
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i,s,n) for(int i = s; i < (int)(n); i++)
#define Rep(i,s,n) for(int i = n; i >= (int)(s); i--)
int main() {
int n;
double d, h;
cin >> n >> d >> h;
double mk = h / d;
rep(i, 0, n) {
double a, b;
cin >> a >> b;
mk = min(mk, (h-b)/(d-a));
}
cout << fixed << setprecision(6) << h-mk*d << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=150;
int n,D,H,x[N],y[N];
bool ok(double mid){
double slop=(double)(H-mid)/(double)(D-0);
for(int i=0;i<n;i++){
double val=slop*x[i]+mid;
if(val<y[i])return false;
}
return true;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>D>>H;
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
double l=0,r=H,ans;
for(int rep=0;rep<100;rep++){
double mid=(l+r)/2;
//cout<<mid<<endl;
if(ok(mid)){
ans=mid;
r=mid;
}
else {
l=mid;
}
}
cout<<fixed<<setprecision(17)<<ans<<'\n';
} |
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef unsigned long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define vint vector<int>
#define pb push_back
#define pf push_front
#define ppb pop_back
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define pic pair<int,char>
#define fr first
#define sc second
#define mp make_pair
#define inarr(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define showarr(a,x,y) for(ll i=x;i<y;i++)cout<<a[i]<<" ";
#define PI 3.1415926535897
#define time_passed 1.0 * clock() / CLOCKS_PER_SEC
using namespace std;
double power(double a,int b) {if(b==0){return 1;}else if(b%2==0){return power(a*a,b/2);}else if(b%2==1){return a*power(a*a,(b-1)/2);}}
bool cmp(pair<int,int>a,pair<int ,int> b){return a.second>b.second;}
template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.x>>a.y;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.x<<" "<<a.y;return out;}
template<typename T,typename T1>T maxs(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T mins(T &a,T1 b){if(b<a)a=b;return a;}
/*double f(double x,double Nu,double k){return power(x,k)-Nu;}
double fd(double x,double Nu,double k){return k*pow(x,k-1);}
double root(int Nu,int k){double ans=9;for(int i=1;i<20;i++){ans=ans-f(ans,Nu,k)/fd(ans,Nu,k);cout<<ans<<" ";}return ans;}
*/
const ll mod=1e9+7;
//const int inf=3e5+5;
//const ll inf=1e9+7;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
//vector <int >adj[0];
bool isprime(int n)
{
if(n==1)return false;
if(n==2) return true;
for(int i=2;i*i<=n;i++)
{
if(n%i==0)return false;
}
return true;
}
void love_for_infinity()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<min(min(a,b),min(c,d));
}
int main()
{ IOS
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#ifdef SIEVE
sieve();
#endif
#ifdef NCR
init();
#endif
ll t;t=1;//cin>>t;
while(t--){love_for_infinity();cout<<endl;}
return 0;
}
|
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ub upper_bound
#define lb lower_bound
#define isrt insert
#define clr clear
#define rsz resize
#define ff first
#define ss second
#define lli long long int
#define pb push_back
#define pf push_front
#define mkp make_pair
#define pii pair<lli,lli>
#define vi vector<int>
#define mii map<lli,lli>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define INF 1e9
#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 all(v) v.begin(),v.end()
#define endl "\n"
const double PI = acos(-1);
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
lli maxm(lli a, lli b)
{
return (a >= b ? a : b);
}
lli minm(lli a, lli b)
{
return (a <= b ? a : b);
}
lli power(lli x, lli y, lli p)
{
lli res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0)
{
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
#define FMAX 1000010
vector<lli> fact(FMAX, 1);
vector<lli> fact_inv(FMAX, 1);
lli nCrmodp(lli n, lli r, lli p)
{
if (r > n)
return 0;
lli pro = (fact[n] * fact_inv[r]) % p;
pro = (pro * fact_inv[n - r]) % mod;
return pro;
}
void precompute()
{
lli x = 1;
for (lli i = 1; i < FMAX; ++i)
{
x *= i;
x %= mod;
fact[i] = x;
fact_inv[i] = power(x, mod - 2, mod);
}
}
void c_p_c()
{
precompute();
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main()
{
c_p_c();
vector<int>v(4);
int ans= 1e9;
for (int i = 0; i < 4; ++i)
{
cin >> v[i];
ans = min(ans, v[i]);
}
cout << ans << endl;
return 0;
} |
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<stack>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> L_L;
const ll INF=2e18;
const ll MOD=1e9+7;
const double EPS=1e-9;
ll M,H;
int main(){
cin>>M>>H;
if(H%M==0){
cout<<"Yes";
}else{
cout<<"No";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;
const double eps = 1e-10;
template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
for(auto &e:u) fill_v<T>(e,v...);
}
template <typename F>
class
#if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
[[nodiscard]]
#endif // defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
FixPoint final : private F
{
public:
template <typename G>
explicit constexpr FixPoint(G&& g) noexcept
: F{std::forward<G>(g)}
{}
template <typename... Args>
constexpr decltype(auto)
operator()(Args&&... args) const
#if !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9
noexcept(noexcept(F::operator()(std::declval<FixPoint>(), std::declval<Args>()...)))
#endif // !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9
{
return F::operator()(*this, std::forward<Args>(args)...);
}
}; // class FixPoint
#if defined(__cpp_deduction_guides)
template <typename F>
FixPoint(F&&)
-> FixPoint<std::decay_t<F>>;
#endif // defined(__cpp_deduction_guides)
namespace
{
template <typename F>
#if !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard)
# if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
__attribute__((warn_unused_result))
# elif defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_Check_return_)
_Check_return_
# endif // defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
#endif // !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard)
inline constexpr decltype(auto)
makeFixPoint(F&& f) noexcept
{
return FixPoint<std::decay_t<F>>{std::forward<std::decay_t<F>>(f)};
}
} // namespace
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
int64 M, H;
cin >> M >> H;
if ( H % M == 0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()
typedef long long ll;
#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)
#define fi first
#define se second
const int N = 510;
ll dist[2][N][N];
int vis[2][N][N];
int n, m;
ll math[N][N], matv[N][N];
template <class T>
using pqt = priority_queue<T,vector<T>,greater<T>>;
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
fr(i,n) fr(j,m-1) cin >> math[i][j];
fr(i,n-1) fr(j,m) cin >> matv[i][j];
pqt<tuple<ll,bool,int,int>> pq;
fr(cor,2) fr(i,n) fr(j,m) dist[cor][i][j] = LLONG_MAX;
pq.emplace(0,0,0,0);
dist[0][0][0] = 0;
while(!pq.empty()){
ll dac; bool cor; int i, j; tie(dac,cor,i,j) = pq.top(); pq.pop();
if(vis[cor][i][j]) continue;
vis[cor][i][j] = 1;
dist[cor][i][j] = dac;
if(j+1<m){
pq.emplace(dac+math[i][j],0,i,j+1);
}
if(j-1>=0){
pq.emplace(dac+math[i][j-1],0,i,j-1);
}
if(i+1<n){
pq.emplace(dac+matv[i][j],0,i+1,j);
}
if(i-1>=0){
if(cor==0){
pq.emplace(dac+2,1,i-1,j);
} else{
pq.emplace(dac+1,1,i-1,j);
}
}
}
cout << dist[0][n-1][m-1] << "\n";
} | #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n, t;
cin >> n >> t;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector<ll> pre, post;
rep(i, n){
if(i < (n+1)/2) pre.push_back(a[i]);
else post.push_back(a[i]);
}
// for(auto e: pre) cout << e << " ";
// cout << endl;
// for(auto e: post) cout << e << " ";
// cout << endl;
unordered_set<ll> sm1;
vector<ll> sm2;
int n1 = pre.size();
int n2 = post.size();
rep(i, 1<<n1){
vector<int> use(n1, 0);
rep(j, n1){
if(i & (1<<j)){
use[j] = 1;
}
}
ll sm = 0;
rep(j, n1){
if(use[j]) sm += pre[j];
}
sm1.insert(sm);
}
rep(i, 1<<n2){
vector<int> use(n2, 0);
rep(j, n2){
if(i & (1<<j)){
use[j] = 1;
}
}
ll sm = 0;
rep(j, n2){
if(use[j]) sm += post[j];
}
sm2.push_back(sm);
}
// for(auto e: sm1) cout << e << " ";
// cout << endl;
// for(auto e: sm2) cout << e << " ";
// cout << endl;
sort(sm2.begin(), sm2.end());
ll res = 0;
for(auto e: sm1){
if(e > t) continue;
int idx = lower_bound(sm2.begin(), sm2.end(), t-e) - sm2.begin();
ll val = sm2[idx]+e;
if(idx == 0) val = e;
if(idx == (int)sm2.size()) val = sm2.back()+e;
if(val > t){
if(idx == 0) val = 0;
else val = sm2[idx-1] + e;
}
res = max(res, val);
// cout << e << " " << idx << " " << val << " " << res << endl;
}
cout << res << endl;
return 0;
} |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cstdlib>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define PI 3.1415926535897932
#define INF 1e18
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repe(i, j, n) for (ll i = j; i < n; i++)
#define repi(i, n) for (ll i = 0; i <= n; i++)
#define repie(i, j, n) for (ll i = j; i <= n; i++)
#define all(x) x.begin(), x.end()
#define println() cout << endl
#define P pair<ll, ll>
#define fi first
#define se second
using Graph = vector<vector<ll>>;
long long modinv(long long a, long long m)
{
long long b = m, u = 1, v = 0;
while (b)
{
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
ll dp[2000][2000];
ll nCr(ll n, ll r)
{
if(n==r) return dp[n][r] = 1;
if(r==0) return dp[n][r] = 1;
if(r==1) return dp[n][r] = n%MOD;
if(dp[n][r]) return dp[n][r]%MOD;
return dp[n][r] = nCr(n-1,r)%MOD + nCr(n-1,r-1)%MOD;
}
ll H(ll n, ll r) {
return nCr(n+r-1, r)%MOD;
}
int prime[10000000];
bool is_prime[100000000 + 1];
int sieve(int n) {
int pcnt = 0;
for(int i = 0; i <= n; i++) {
is_prime[i] = true;
}
is_prime[0] = is_prime[1] = false;
for(int i = 2; i <= n; i++) {
if(is_prime[i]) {
prime[pcnt++] = i;
for(int j = 2*i; j <= n; j += i) {
is_prime[j] = false;
}
}
}
return pcnt;
}
struct UnionFind {
//自身が親であれば、その集合に属する頂点数に-1を掛けたもの
//そうでなければ親のid
vector<ll> r;
UnionFind(ll N) {
r = vector<ll>(N, -1);
}
ll root(ll x) {
if (r[x] < 0) return x;
return r[x] = root(r[x]);
}
bool unite(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y) return false;
if (r[x] > r[y]) swap(x, y);
r[x] += r[y];
r[y] = x;
return true;
}
ll size(ll x) {
return -r[root(x)];
}
bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
ll rx = root(x);
ll ry = root(y);
return rx == ry;
}
};
void solve1() {
ll n, q; string s; cin >> n >> s >> q;
string pre, post;
pre = s.substr(0, n);
post = s.substr(n, n);
bool f = true;
//cout << pre << " " << post << endl;
rep(i, q) {
int t, a, b; cin >> t >> a >> b;
if(t == 1) {
if(a <= n && b <= n) {
swap(pre[a-1], pre[b-1]);
} else if(a <= n && b > n) {
swap(pre[a-1], post[b-1-n]);
} else {
swap(post[a-1-n], post[b-1-n]);
}
} else {
swap(post, pre);
}
}
cout << pre + post << endl;
}
int main()
{
solve1();
}
| #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;
//Arr.find_by_order(k-1):kth smallest
//Arr.order_of_key(X):no. of elements less than x
#define int long long
#define ld long double
#define dob double
#define pb push_back
#define tle ios_base::sync_with_stdio(false);cin.tie(NULL);
const int hell=1e9+7;
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int>>
int inf=1e18;
const int N=1e5+9;
//getline(cin,st); To Take Entire Sentence In Input;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
bool prime(int n)
{
for( int i=2;i*i<=n;i++)
{
if(n%i==0)
return false;
}
return true;
}
int power(int a,int b,int m)
{
int ans=1;
while(b)
{
if(b&1)
ans=(ans*a)%m;
b/=2;
a=(a*a)%m;
}
return ans;
}
int32_t main()
{
tle
int t=1;
// cin>>t;
//precompute();
while(t--)
{
int n;
cin>>n;
string s;
cin>>s;
int q;
cin>>q;
int ct=0;
for(int i=0;i<q;i++)
{
int typ,l,r;
cin>>typ>>l>>r;
if(typ==1)
{
if(ct%2==0)
swap(s[l-1],s[r-1]);
else
{
if(l<=n)
l=l+n;
else
l=l-n;
if(r<=n)
r=r+n;
else
r=r-n;
swap(s[l-1],s[r-1]);
}
}
else
ct++;
}
// reverse(s.begin(),s.end());
if(ct%2==1)
s=s.substr(n)+s.substr(0,n);
cout<<s;
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
const ll siz = 3e5 + 7;
ll t[4 * siz];
int n, q;
void built(int a[], int tl , int tr, int v) {
if (tl == tr) {
t[v] = a[tl];
}
else
{
int tm = (tl + tr) / 2;
built(a, tl, tm, 2 * v);
built(a, tm + 1, tr, 2 * v + 1);
t[v] = (t[2 * v] ^ t[2 * v + 1]);
}
}
void update(int v, int tl, int tr, int pos, int val) {
if (tl == tr) {
t[v] = val;
}
else
{
int tm = (tl + tr) / 2;
if (pos <= tm)
update(2 * v, tl, tm, pos, val);
else
update(2 * v + 1, tm + 1, tr, pos, val);
t[v] = (t[2 * v] ^ t[2 * v + 1]);
}
}
ll query(int v, int tl, int tr , int l , int r) {
if (l > r)return 0;
if (l == tl && r == tr) {
return t[v];
}
int tm = (tr + tl) / 2;
return (query(2 * v, tl, tm, l, min(r, tm)) ^query(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> q;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
built(a, 0, n - 1, 1);
while (q--) {
int t;
cin >> t;
if (t == 2) {
int u, v;
cin >> u >> v;
--u;
--v;
cout << query(1, 0, n - 1, u, v) << endl;
}
else
{
int u, v;
cin >> u >> v;
--u;
int by = v ^ a[u];
update(1, 0, n - 1, u, by);
a[u] = by;
}
}
} | #include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
template< typename T >
struct BinaryIndexedTree {
vector< T > data;
BinaryIndexedTree(int sz) {
data.assign(++sz, 0);
}
T sum(int k) {
T ret = 0;
for(++k; k > 0; k -= k & -k) ret += data[k];
return (ret);
}
void add(int k, T x) {
for(++k; k < data.size(); k += k & -k) data[k] += x;
}
};
int main() {
#ifdef DEBUG
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
#endif
ll N, Q;
cin >> N >> Q;
static ll A[300300];
static ll T[300300];
static ll X[300300];
static ll Y[300300];
BinaryIndexedTree<ll>* Count[31];
for(int i = 0; i < N; i++){
cin >> A[i];
}
for(int i = 0; i < Q; i++){
cin >> T[i] >> X[i] >> Y[i];
}
for(int j = 0; j < 31; j++){
Count[j] = new BinaryIndexedTree<ll>(N*2);
}
for(int i = 0; i < N; i++){
for(int j = 0; j < 31; j++){
if( (A[i] >> j) & 1){
Count[j]->add(i, 1);
}
}
}
for(int i = 0; i < Q; i++){
if(T[i] == 1){
ll newA = A[X[i]] ^ Y[i];
for(int j = 0; j < 31; j++){
if( (A[X[i]] >> j) & 1){
Count[j]->add(X[i]-1, 1);
}
if( (newA >> j) & 1){
Count[j]->add(X[i]-1, 1);
}
}
A[X[i]] = newA;
}else{
ll output = 0;
ll two = 1;
for(int j = 0; j < 31; j++){
if(X[i] > 1){
if( (Count[j]->sum(Y[i]-1) - Count[j]->sum(X[i]-2)) % 2 == 1){
output += two;
}
}else{
if( (Count[j]->sum(Y[i]-1)) % 2 == 1){
output += two;
}
}
two *= 2;
}
cout << output << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
#define gc() getchar()
using namespace std;
typedef long long ll;
template <typename T> void rd(T &x){
ll f=1;x=0;char c=gc();
for(;!isdigit(c);c=gc())if(c=='-')f=-1;
for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
x*=f;
}
ll n,q,h[100010],ans;
inline void bsh(ll k){
ll l=0,r=h[n]+k+1,mid,f;
while(l+1<r){
mid=l+r>>1;
f=lower_bound(h+1,h+n+1,mid)-h-1;
//printf("%lld %lld %lld %lld\n",l,r,mid,f);
if(mid-f>k)r=mid;
else l=mid;
}
printf("%lld\n",l);
}
int main(){
rd(n),rd(q);
for(ll i=1;i<=n;i++)rd(h[i]);
for(ll i=1,t;i<=q;i++){
rd(t);
bsh(t);
}
return 0;
}
| #include "bits/stdc++.h"
typedef long long int ll;
using namespace std;
int64_t n, q;
void solve() {
cin >> n >> q;
vector<int64_t> a;
for(int i=0;i<n;++i) {
int64_t t; cin >> t;
a.push_back(t);
}
sort(a.begin(), a.end());
for(int i=0;i<q;++i) {
int64_t k; cin >> k;
int64_t pre = 0;
while(1) {
int64_t cnt = upper_bound(a.begin(), a.end(), k) - upper_bound(a.begin(), a.end(), pre);
if(cnt == 0)
break;
pre = k;
k += cnt;
}
cout << k << "\n";
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int T = 1;
while(T--) solve();
return 0;
}
|
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
const int inf = 1e18;
const int max_n = 3010;
const int Mod = 998244353;
int n,k;
int dp[max_n][max_n];
int f(int n,int k){
if(n>k) return 0;
if(k==0){
if(n==0) return 1;
else return 0;
}
if(n==0){
return 0;
}
if(dp[n][k]!=-1) return dp[n][k];
int t1 = f(n-1,k-1);
int t2 = f(2*n,k);
int ans = (t1+t2)%Mod;
dp[n][k]=ans;
return ans;
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
memset(dp,-1,sizeof(dp));
cin>>n>>k;
swap(n,k);
cout<<f(n,k)<<endl;
} | #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 main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll a,b;
cin >> a >> b;
cout << (a+b)/2 << " " << (a-b)/2 << endl;
return 0;
}
|
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int N, M, Q;
long long int X[200005], Y[200005];
int op[200005],A[200005], B[200005];
long long int p[200005];
vector<int> V[200005];
map<pair<int, int>, int> MAP;
long long int a[4], b[4];
long long int tmp[4];
void QUERY(int k, int p_val) {
if (k == 1) {
for (int i = 1; i <= 3; i++) { tmp[i] = a[i]; }
for (int i = 1; i <= 3; i++) { a[i] = b[i]; b[i] = -tmp[i]; }
}
else if (k == 2) {
for (int i = 1; i <= 3; i++) { tmp[i] = a[i]; }
for (int i = 1; i <= 3; i++) { a[i] = -b[i]; b[i] = tmp[i]; }
}
else if (k == 3) {
//for (int i = 1; i <= 3; i++) { tmp[i] = a[i]; }
a[3] = 2 * p_val - a[3]; a[1] = -a[1]; a[2] = -a[2];
}
else if (k == 4) {
b[3] = 2 * p_val - b[3]; b[1] = -b[1]; b[2] = -b[2];
}
}
long long int ans_x[200005], ans_y[200005];
int main(void) {
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> X[i] >> Y[i];
}
cin >> M;
for (int i = 1; i <= M; i++) {
cin >> op[i];
if (op[i] >= 3) { cin >> p[i]; }
}
cin >> Q;
for (int i = 1; i <= Q; i++) {
cin >> A[i] >> B[i];
V[A[i]].push_back(B[i]);
MAP[make_pair(A[i], B[i])] = i;
}
a[1] = 1;
b[2] = 1;
for (int i = 0; i <= M; i++) {
// cout << "op= " << op[i] << endl;
QUERY(op[i], p[i]);
//cout << "a : " << a[1] << " " << a[2] << " " << a[3] << endl;
//cout << "b : " << b[1] << " " << b[2] << " " << b[3] << endl;
for (auto y : V[i]) {
int I = MAP[make_pair(i, y)];
ans_x[I] = a[1] * X[y] + a[2] * Y[y] + a[3];
ans_y[I] = b[1] * X[y] + b[2] * Y[y] + b[3];
}
}
for (int i = 1; i <= Q; i++) {
int I = MAP[make_pair(A[i], B[i])];
cout << ans_x[I] << " " << ans_y[I] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using matrix = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
void Cout(ll x) {cout << x << endl; exit(0);}
const ll inf = 1e18;
const ll mod = 1e9 + 7;
matrix E = {{1,0,0},{0,1,0},{0,0,1}};
matrix op1 = {{0,1,0},{-1,0,0},{0,0,1}};
matrix op2 = {{0,-1,0},{1,0,0},{0,0,1}};
matrix op3 = {{-1,0,0},{0,1,0},{0,0,1}};
matrix op4 = {{1,0,0},{0,-1,0},{0,0,1}};
matrix pre3(ll p) {
matrix res = op3;
res[0][2] = 2*p;
return res;
}
matrix pre4(ll p) {
matrix res = op4;
res[1][2] = 2*p;
return res;
}
matrix times(matrix X, matrix Y) {
ll H = X.size(), W = Y[0].size(), K = Y.size();
matrix res(H,vector<ll>(W));
rep(i,H) rep(j,W) {
rep(k,K) res[i][j] += X[i][k]*Y[k][j];
}
return res;
}
int main() {
ll N; cin >> N;
vector<matrix> vec(N);
rep(i,N) {
ll x, y; cin >> x >> y;
vec[i] = {{x},{y},{1}};
}
ll M; cin >> M;
vector<matrix> op(M+1,E);
repp(i,1,M+1) {
ll com; cin >> com;
if (com==1) op[i] = times(op1,op[i-1]);
else if (com==2) op[i] = times(op2,op[i-1]);
else {
ll p; cin >> p;
matrix opt;
if (com==3) opt = pre3(p);
else opt = pre4(p);
op[i] = times(opt,op[i-1]);
}
}
ll Q; cin >> Q;
vector<ll> X(Q), Y(Q);
rep(i,Q) {
ll a, b; cin >> a >> b;
b--;
matrix tmp = times(op[a],vec[b]);
X[i] = tmp[0][0];
Y[i] = tmp[1][0];
}
rep(i,Q) cout << X[i] << " " << Y[i] << endl;
} |
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 1600008
#define mod 998244353
#define f first
#define s second
ll arr[sz+10],brr[sz+10];
ll num=1;
char c[sz];
std::vector<ll> v[34];
long long binpow(long long a, long long b,long long mod1) {
a %= mod1;
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a % mod1;
a = a * a % mod1;
b >>= 1;
}
return res;
}
int main()
{
int t=1;
//scanf("%d",&t);
for(int cs=1;cs<=t;cs++)
{
ll a,b,c;
scanf("%lld %lld %lld",&a,&b,&c);
a%=10;
ll n=a;
arr[n]++;
ll val=0;
for(int i=2;;i++)
{
n=(n*a)%10;
if(arr[n])
{
val=i-1;
break;
}
}
ll a1=binpow(b,c,val);
if(a1==0)
a1=val;
n=a;
for(int i=2;i<=a1;i++)
n=(n*a)%10;
a=n;
printf("%lld\n",a);
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
typedef long long ll;
const double pi = acos(-1.0);
#define debug puts("*****************")
#define memset(a,b) memset(a,b,sizeof(a))
const int mod = (1 ? 1000000007 : 998244353);
const int inf = (1 ? 0x3f3f3f3f : 0x7fffffff);
const int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
const ll INF = (1 ? 0x3f3f3f3f3f3f3f3f : 0x7fffffffffffffff);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll poww(ll a, ll b,ll mod) { ll s = 1; while (b) { if (b & 1)s = (s * a) % mod; a = (a * a) % mod; b >>= 1; }return s % mod; }
/*----------------------------------------------------------------------------------------------------------------------*/
const int N = 1e5 + 11;
ll n,m;
void solve()
{
ll a,b,c;
cin>>a>>b>>c;
b=poww(b,c,4);
a%=10;
if(a==1||a==5||a==6||a==0)
{
cout<<a<<endl;
return;
}
if(a==4&&b%2==1)cout<<4<<endl;
else if(a==4&&b%2==0)cout<<6<<endl;
else if(a==9&&b%2==1)cout<<9<<endl;
else if(a==9&&b%2==0)cout<<1<<endl;
else
{
int z[4];
if(a==2){z[0]=6;z[1]=2;z[2]=4;z[3]=8;}
if(a==3){z[0]=1;z[1]=3;z[2]=9;z[3]=7;}
if(a==7){z[0]=1;z[1]=7;z[2]=9;z[3]=3;}
if(a==8){z[0]=6;z[1]=8;z[2]=4;z[3]=2;}
cout<<z[b]<<endl;
}
}
/*----------------------------------------------------------------------------------------------------------------------*/
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
ll T = 1;
//cin >> T;
while (T--)solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
// template {{{
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1)
#define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1)
#define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl
constexpr i32 inf = 1001001001;
constexpr i64 infll = 1001001001001001001ll;
constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1};
constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;
template <typename T = i64> T input() { T x; cin >> x; return x; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}
pair<int, int> diam_dfs(int v, int p, int dep, const vector<vector<int>> &G, vector<pair<int, int>> &ds) {
pair<int, int> res(dep, v);
for (auto &u : G[v]) {
if (u == p) continue;
chmax(res, diam_dfs(u, v, dep + 1, G, ds));
}
ds[v] = res;
return res;
}
void dfs(int v, int p, int &e, const vector<vector<int>> &G, const vector<pair<int, int>> &ds, vector< int > &ans) {
ans[v] = e;
vector< pair<int, int> > us;
for (auto &u : G[v]) {
if (u == p) continue;
us.emplace_back(ds[u].first, u);
}
whole(sort, us);
for (auto &[d, u] : us) {
e++;
dfs(u, v, e, G, ds, ans);
e++;
}
}
void solve() {
int n = input();
vector< vector< int > > G(n);
range(i, 1, n) {
int a = input() - 1, b = input() - 1;
G[a].emplace_back(b);
G[b].emplace_back(a);
}
vector< pair<int, int> > ds(n);
auto [d0, v0] = diam_dfs(0, -1, 0, G, ds);
diam_dfs(v0, -1, 0, G, ds);
int e = 1;
vector< int > ans(n);
dfs(v0, -1, e, G, ds, ans);
cout << ans << endl;
}
signed main() {
solve();
}
| #include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define endl "\n"
using namespace std;
const int max_n = 2e5+100;
const int off_set = 1e5+5;
const int max_A = 55;
const int Mod = 1e9+7;
const int inf = 2e18;
int n;
vector<int> adj[max_n];
int depth[max_n],dp[max_n];
void dfs(int v,int p,int d){
depth[v]=d;
dp[v]=d;
for(int x:adj[v]) if(x!=p){
dfs(x,v,d+1);
dp[v]=max(dp[v],dp[x]+1);
}
return;
}
int ans[max_n];
int counter;
void solve(int v,int p){
ans[v]=counter;
for(int x:adj[v]) if(x!=p){
counter++;
solve(x,v);
counter++;
}
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin>>n;
for(int i=0;i<n-1;i++){
int x,y;cin>>x>>y;x--;y--;
adj[x].pb(y);
adj[y].pb(x);
}
dfs(0,-1,0);
int farthest=0;
for(int i=0;i<n;i++) if(depth[i]>depth[farthest]){
farthest=i;
}
dfs(farthest,-1,0);
for(int i=0;i<n;i++){
sort(adj[i].begin(),adj[i].end(),[](const int& a,const int& b)->bool{
return dp[a]<dp[b];
});
}
solve(farthest,-1);
for(int i=0;i<n;i++){
cout<<ans[i]+1<<" ";
}
cout<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define ld long double
#define rep(i,n) for (ll i = 0;i<(n);++i)
#define all(v) v.begin(),v.end()
template <typename T>bool chmax(T &a, const T& b) {if (a < b) {a = b;return true;}return false;}
template <typename T>bool chmin(T &a, const T& b) {if (a > b) {a = b;return true;}return false;}
vector<long long> divisor(long long n){vector<long long> res;long long i = 1;while (i*i<=n){if(n%i==0){res.push_back(i);}i++;}if(res.size()==0)return res;for(long long i = res.size()-1-(res.back()*res.back()==n);i>=0;--i){res.push_back(n/res[i]);}return res;}
long long safe_mod(long long x,long long m){x%=m;if(x<0){x+=m;}return x;}
long long modpow(long long x,long long n,long long mod){long long ans=1;while(n>0){if(n&1){ans*=x;ans%=mod;}n>>=1;x*=x;x%=mod;}return ans;}
long long intpow(long long x,long long n){long long ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;}
//template<typename T>T intpow(T x,T n){T ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;}
vector<pair<long long,long long>> factor_lst(long long n){vector<pair<long long,long long>> factor_lst;long long d=2;while(d*d<=n){if(n%d==0){long long num=0;while(n%d==0){num+=1;n/=d;}factor_lst.push_back({d,num});}d+=1;}if(n!=1){factor_lst.push_back({n,1});}return factor_lst;}
#define Uniq(a) sort(all(a));a.erase(unique(all(a)),end(a))
int msb(int x){return x==0 ? -1:32-__builtin_clz(x);}//1-indexed
int lsb(int x){return x==0 ? 32:__builtin_ctz(x)+1;}//1-indexed
int popcnt(int x){return __builtin_popcount(x);}
int popcnt(long long x){return __builtin_popcount(x);}
bool ingrid(int i,int j,int H,int W){
return 0<=i&&i<H&&0<=j&&j<W;
}
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
template<typename T> void print(vector<T> &v){for(int i=0;i<v.size();++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;}
template<typename T> void print(T* v,int size){for(int i=0;i<size;++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;}
template<typename T,typename S>void print(pair<T,S>&p){cout<<p.first<<" "<<p.second<<endl;}
const ll LINF=4*1e18;
const ll MINF=5*1e15;
const int INF=1e9+5;
const ld PI=acosl(-1);
const ld DINF=INF;
void Main();
int main(){cout<<fixed<<setprecision(15);Main();}
void Main(){
int N,M;cin>>N>>M;
vector<pair<int,int>> P(M);
vector<int> lstx,lsty;
lstx.push_back(0);
lsty.push_back(N);
lsty.push_back(N+1);
rep(i,M){
cin>>P[i].first>>P[i].second;
lstx.push_back(P[i].first);
lsty.push_back(P[i].second);
lsty.push_back(P[i].second+1);
}
Uniq(lstx);Uniq(lsty);
map<int,int> mx,my;
rep(i,lstx.size())mx[lstx[i]]=i;
rep(i,lsty.size())my[lsty[i]]=i;
vector<vector<int>> query(lstx.size());
rep(i,M)query[mx[P[i].first]].push_back(my[P[i].second]);
vector<bool> dp(lsty.size(),false);
dp[my[N]]=true;
rep(i,lstx.size()){
vector<bool> lst(query[i].size());
rep(j,query[i].size()){
lst[j]=(query[i][j]>0&&dp[query[i][j]-1])||((query[i][j]<lsty.size()-1)&&dp[query[i][j]+1]);
}
rep(j,query[i].size()){
dp[query[i][j]]=lst[j];
}
}
int ans=0;
rep(i,lsty.size()-1)if(dp[i])ans+=lsty[i+1]-lsty[i];
cout<<ans<<endl;
}
| /*
AtCoder Regular Contest 111 - A - Simple Math 2
https://atcoder.jp/contests/arc111/tasks/arc111_a
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
ll MOD = 1000000007;
// ll sum() { return 0; }
// template<typename T, typename... Args>
// T sum(T a, Args... args) { return a + sum(args...); }
#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl
void solve() {
// [10 ^ N / M] % M
// = [10 ^ N - k * M ^ 2] % M
// = [10 ^ N / M] % M
ll n, m;
cin >> n >> m;
ll sq = m * m, ans = 1, pow = 10;
while (n > 0) {
if (n & 1) ans = (ans * pow) % sq;
pow = (pow * pow) % sq;
n >>= 1;
}
OUT((ans / m) % m);
}
int main()
{
FAST_INP;
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r", stdin);
// freopen("output.txt","w", stdout);
// #endif
// int tc; cin >> tc;
// TC(tc) solve();
solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
/*
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
*/
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}
ll mod_pow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
const int mod = 1e9 + 7;
int conv(string &S, string &T) {
int ret = 0;
int N = S.size();
priority_queue<int, vector<int>, greater<int>> Q;
for (int i = 0; i < N; i++) {
if (T[i] == '0') {
Q.push(i);
}
}
for (int i = 0; i < N; i++) {
if (T[i] == '1' && S[i] == '0') {
while(!Q.empty()) {
int x = Q.top(); Q.pop();
if (x <= i) continue;
swap(T[i], T[x]);
ret++;
break;
}
}
}
return ret;
}
int f(string &S, string &T) {
string S_ = T, T_ = S;
int r1 = conv(S, T);
reverse(all(S));
reverse(all(T));
int r2 = conv(S, T);
int r3 = conv(S_, T_);
reverse(all(S_));
reverse(all(T_));
int r4 = conv(S_, T_);
return min(r1 + r2, r3 + r4);
}
void solve() {
int N;
cin >> N;
string S, T;
cin >> S >> T;
int s1 = 0, t1 = 0;
for (int i = 0; i < N; i++) {
if (S[i] == '1') s1++;
}
for (int i = 0; i < N; i++) {
if (T[i] == '1') t1++;
}
if (s1 != t1) {
cout << "-1" << endl;
return;
}
int prev = 0;
s1 = 0, t1 = 0;
int ans = 0;
for (int i = 0; i < N; i++) {
if (S[i] == '1') s1++;
if (T[i] == '1') t1++;
if (s1 == t1) {
string s = S.substr(prev, i + 1 - prev);
string t = T.substr(prev, i + 1 - prev);
ans += f(s, t);
prev = i + 1;
}
}
cout << ans << endl;
}
int main() {
#ifdef LOCAL_ENV
cin.exceptions(ios::failbit);
#endif
cin.tie(0);
ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
} | #include <bits/stdc++.h>
using namespace std ;
int N, ans=0;
string S, T;
vector<int> a, b;
int main(){
cin >> N >> S >> T;
bool f=true;
int x=-1;
for(int i=0;i<N;i++){
if(S[i]=='0')a.push_back(i);
if(T[i]=='0')b.push_back(i);
}
if(a.size()!=b.size())puts("-1");
else{
for(int i=0;i<a.size();i++){
if(a[i]!=b[i])ans++;
}
cout << ans << endl;
}
return 0;
}
|
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#define Q 400005
using namespace std;
#define gc() getchar()
inline bool ig(char c){return c>='0'&&c<='9';}
inline void read(int &oi){char c;int f=1,rs=0;while(c=gc(),(!ig(c))&&c!='-');c^'-'?rs=(c^48):f=-1;while(c=gc(),ig(c))rs=rs*10+(c^48);oi=rs*f;}
inline void print(int oi){if(oi<0)putchar('-'),oi=~oi+1;if(oi>9)print(oi/10);putchar(oi%10+48);}
int n,q;char c[Q];bool flag;
int main(){
read(n);scanf("%s",c);read(q);
for(int i=1;i<=q;++i){
int opt,x,y;read(opt);read(x);read(y);
if(opt==2)flag^=1;
else{
if(flag){
if(x>n)x-=n;else x+=n;
if(y>n)y-=n;else y+=n;
}
char ch=c[x-1];
c[x-1]=c[y-1];c[y-1]=ch;
}
}
if(flag){
for(int i=n;i<=2*n-1;++i)putchar(c[i]);
for(int i=0;i<=n-1;++i)putchar(c[i]);putchar('\n');
}
else printf("%s\n",c);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> Pair;
typedef tuple<int,int,int> tpl;
#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)
#define en "\n"
constexpr double EPS = 1e-9;
constexpr double PI = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
void Main(){
int N,M; cin >> N >> M;
VI A(N); REP(i,N) cin >> A[i];
VI B(M); REP(i,M) cin >> B[i];
ll dp[N+1][M+1]; REP(i,N+1)REP(j,M+1) dp[i][j] = LINF;
dp[0][0] = 0;
REP(i,N) dp[i+1][0] = i+1;
REP(i,M) dp[0][i+1] = i+1;
ll cummin[N+1][M+1]; REP(i,N+1)REP(j,M+1) cummin[i][j] = LINF;
cummin[0][0] = 0;
REP(i,N) cummin[i+1][0] = i+1;
REP(i,M) cummin[0][i+1] = i+1;
REP(i,N)REP(j,M){
// 取り除く場合
chmin(dp[i+1][j+1], dp[i][j]+2);
chmin(dp[i+1][j+1], dp[i][j+1]+1);
chmin(dp[i+1][j+1], dp[i+1][j]+1);
// 残す場合
if(A[i]==B[j]) chmin(dp[i+1][j+1], dp[i][j]);
else chmin(dp[i+1][j+1], dp[i][j]+1);
}
ll ans = dp[N][M];
cout << ans << en;
return;
}
int main(void){
cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
int t=1; //cin>>t;
REP(_,t) Main();
return 0;
} |
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll N = 1e6 + 5;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;cin>>n;
ll ans=0,mx=0,s=0,k=0;
for(int i=1;i<=n;i++){
ll x;cin>>x;
s+=x;
k=max(k,s);
ans+=k;
mx=max(ans,mx);
ans+=s-k;
// cout<<ans<<" "<<s<<'\n';
}
cout<<mx<<'\n';
return 0;
} | #include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long INF=1e18;
long long mod=1e9+7;
//status unsolved
int main(){
long long n;
cin>>n;
long long a[n];
rep(i,n){
cin>>a[i];
}
long long s[n+1];
s[0]=0;
long long M[n+1];//M[i]:=i番目までの累積和の最大
M[0]=0;
rep(i,n){
s[i+1]=s[i]+a[i];
if(s[i+1]>M[i]){
M[i+1]=s[i+1];
}
else{
M[i+1]=M[i];
}
}
long long ans=0;
long long now=0;
rep2(i,n){
ans=max(now+M[i],ans);
now+=s[i];
//ans=max(now,ans);
//cout<<ans<<endl;
}
cout<<ans<<endl;
}
/*
*/
|
//help others........
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define pb push_back
#define F first
#define S second
#define pii pair<long long,int>
#define all(a) a.begin(),a.end()
#define read(n,a) for(int i = 0;i<n;i++){cin>>a[i];}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll mod = 1e9+7;
ll fct[1009];
int N = 509;
void fact() {
fct[0] = 1;
fct[1] = 1;
for (ll i = 2; i <= 1000; i++)
fct[i] = (i * fct[i-1])%mod;
}
bool find(int s,vector<int>a){
for(int i = 0;i<(int)a.size();i++)
{
if(a[i] == s)
return true;
}
return false;
}
void getans()
{
int a,b;
cin>>a>>b;
int c = a+b;
if(c>=15 && b >=8)
cout<<1<<endl;
else if(c>=10&& b>=3)
cout<<2<<endl;
else if(c>=3)
cout<<3<<endl;
else
cout<<4<<endl;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int t = 1;
//cin>>t;
while(t--)
getans();
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(a+b>=15&&b>=8){
cout<<"1\n";
}else if(a+b>=10&&b>=3){
cout<<"2\n";
}else if(a+b>=3){
cout<<"3\n";
}else{
cout<<"4\n";
}
} |
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;
//マクロ
//forループ
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF 1000000007
#define MAXR 100000 //10^5:配列の最大のrange
//最大化問題最小化問題
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
signed main(){
//入力の高速化用のコード
ios::sync_with_stdio(false);
cin.tie(nullptr);
//入力
ll N;
cin >> N;
FOR(i,1,log(N)){
FOR(j,1,log(N)){
if(N==powl(5,i)+powl(3,j)){cout << j << " " << i << endl;
return 0;
}
}
}
//出力
cout << -1 << endl;
//cout << fixed << setprecision(10) << ans << endl;
return 0;
} | #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<climits>
#include<complex>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define int long long
template<typename T>
void dbg_a(T *a,int l,int r){cout<<" {";for(int i = l;i<r;i++) cout<<a[i]<<", ";cout<<a[r]<<"}"<<endl;}
typedef long long ll;
template<typename T = int>
inline T read(){
T f = 1,r = 0;
char c = getchar();
while(c<'0'||c>'9'){if(c == '-') f = -1; c = getchar();}
while(c>='0'&&c<='9'){ r = (r<<1) + (r<<3) + c - '0';c = getchar();}
return f*r;
}
typedef pair<int,int> PII;
#define fi first
#define se second
#define mst(a,b) memset(a,b,sizeof(a))
#define For(i,a,b) for(int i = a;i<=b;i++)
#define For_(i,a,b) for(int i = a;i>=b;i--)
#define _for(i,a) for(int i = 0;i<a;i++)
#define All(x) x.begin(),x.end()
// For(i,1,n) For(j,1,m) printf("f[%lld][%lld] = %lld\n",a,b,c);
const int N = 8 + 2,M = N*2 + 10,INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n,k;
void solve(){
n = read();
int a = read(),b = read();
int d = n - b - a;
if(d < 0){
cout<<0<<"\n";
return ;
}
int ans1 = (d + 1) % mod * (d + 2) % mod * (n - a + 1) % mod * (n - b + 1) % mod;
int ans2 = (d + 1) * (d + 1) % mod * (d + 2) %mod * (d + 2) % mod;
cout<<(ans1 * 2 - ans2 + mod)%mod<<"\n";
}
signed main(){
int T = 1;
T = read();
while(T--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vt vector
#define all(x) x.begin(), x.end()
#define trav(i, x) for(auto &i : x)
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define top front
void solve() {
int n, m; scanf("%d%d", &n, &m);
vector<vector<char>> G(n, vector<char> (m));
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
cin >> G[i][j];
}
}
int row_count = 0;
for(int i = 0; i < n - 1; i++) {
for(int j = 0; j < m - 1; j++) {
int c=0;
c += G[i][j]=='#';
c += G[i+1][j]=='#';
c += G[i][j+1]=='#';
c += G[i+1][j+1]=='#';
if(c==1||c==3) row_count++;
}
}
printf("%d", row_count);
}
int main() {
int t = 1, i = 1;
while(t--) {
// printf("Case #%d: ", i)
solve();
i++;
}
}
| #include <bits/stdc++.h>
using namespace std;
template <class A, class B> bool cmin(A& a, B b) { return a > b && (a = b, true); }
template <class A, class B> bool cmax(A& a, B b) { return a < b && (a = b, true); }
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, X;
cin >> N >> X;
vector<int> A(N);
for (int i = 0; i < N; i++) cin >> A.at(i);
for (const auto& a : A) {
if (a == X) continue;
cout << a << '\n';
}
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) begin(v), end(v)
#define sz(v) v.size()
#define INF 1e18+9
#define EPSILON 1e-14
template <typename T>
bool chmax(T &a, const T& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll si, sj;
vector<vector<ll>> p(50, vector<ll>(50));
vector<bool> vst(2500, false);
vector<vector<ll>> t(50, vector<ll>(50));
ll scoring(string S){
ll score = 0;
score += p.at(si).at(sj);
vst.at(t.at(si).at(sj)) = true;
ll px = si;
ll py = sj;
rep(i, sz(S)){
if(S.at(i) == 'U'){
px--;
}
else if(S.at(i) == 'D'){
px++;
}
else if(S.at(i) == 'L'){
py--;
}
else if(S.at(i) == 'R'){
py++;
}
if(vst.at(t.at(px).at(py))){
cerr << t.at(px).at(py) << ": twice visited" << endl;
return -1;
}
else{
vst.at(t.at(px).at(py)) = true;
score += p.at(px).at(py);
}
}
return score;
}
string solve(){
string ans = "";
vector<ll> dx = {-1, 1, 0, 0};
vector<ll> dy = {0, 0, -1, 1};
string dir = "UDLR";
ll px = si;
ll py = sj;
vst.at(t.at(si).at(sj)) = true;
while(true){
bool move = false;
rep(i, 4){
if(0 <= px+dx.at(i) && px+dx.at(i) <= 49 && 0 <= py+dy.at(i) && py+dy.at(i) <= 49 && !vst.at(t.at(px+dx.at(i)).at(py+dy.at(i)))){
px += dx.at(i);
py += dy.at(i);
vst.at(t.at(px).at(py)) = true;
ans += dir.at(i);
move = true;
break;
}
}
if(!move){
break;
}
}
return ans;
}
string greed(){
string ans = "";
vector<ll> dx = {-1, 1, 0, 0};
vector<ll> dy = {0, 0, -1, 1};
string dir = "UDLR";
ll px = si;
ll py = sj;
vst.at(t.at(si).at(sj)) = true;
while(true){
ll add = 0;
ll d = -1;
rep(i, 4){
if(0 <= px+dx.at(i) && px+dx.at(i) <= 49 && 0 <= py+dy.at(i) && py+dy.at(i) <= 49 && !vst.at(t.at(px+dx.at(i)).at(py+dy.at(i)))){
if(chmax(add, p.at(px+dx.at(i)).at(py+dy.at(i)))){
d = i;
}
}
}
if(d == -1){
break;
}
px += dx.at(d);
py += dy.at(d);
vst.at(t.at(px).at(py)) = true;
ans += dir.at(d);
}
return ans;
}
int main()
{
cin >> si >> sj;
rep(i, 50){
rep(j, 50){
cin >> t.at(i).at(j);
}
}
rep(i, 50){
rep(j, 50){
cin >> p.at(i).at(j);
}
}
cout << greed() << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int si, sj;
vector<vector<int>> t(50, vector<int>(50,0));
vector<vector<int>> p(50, vector<int>(50,0));
vector<vector<bool>> used(50, vector<bool>(50, false));
string ans_s;
int score() {
int ans = 0;
return ans;
}
void solve() {
queue<P> q;
q.push(make_pair(si, sj));
used.at(si).at(sj) = true;
for (int i = 0; i < 4; i++) {
int xd = si + dx[i];
int yd = sj + dy[i];
if (xd >= 0 && xd < 50 && yd >= 0 && yd < 50 && t.at(si).at(sj) == t.at(xd).at(yd)) used.at(xd).at(yd) = true;
}
ll s = 0;
mt19937 mt(1234);
uniform_int_distribution<> rand4(0, 3);
int cnt = 0, false_cnt = 0;
while(!q.empty() && false_cnt < 10 && cnt < 100000000) {
P tmp = q.front();
int i = rand4(mt);
int x = tmp.first + dx[i];
int y = tmp.second + dy[i];
if (x >= 0 && x < 50 && y >= 0 && y < 50 && !used.at(x).at(y)) {
false_cnt = 0;
s += p.at(x).at(y);
used.at(x).at(y) = true;
q.pop();
q.push(make_pair(x, y));
for (int j = 0; j < 4; j++) {
int xd = x + dx[j];
int yd = y + dy[j];
if (xd >= 0 && xd < 50 && yd >= 0 && yd < 50 && t.at(x).at(y) == t.at(xd).at(yd)) used.at(xd).at(yd) = true;
}
if (i == 0) ans_s += 'U';
else if (i == 1) ans_s += 'L';
else if (i == 2) ans_s += 'D';
else ans_s += 'R';
} else false_cnt++;
cnt++;
}
}
int main(){
cin >> si >> sj;
for (int i = 0; i < 50; i++) {
for (int j = 0; j < 50; j++) {
cin >> t.at(i).at(j);
}
}
for (int i = 0; i < 50; i++) {
for (int j = 0; j < 50; j++) {
cin >> p.at(i).at(j);
}
}
solve();
//ans_s.erase(ans_s.size()-1);
cout << ans_s << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _for(i,a,b) for(int i = (a); i < (b); i++)
#define _rep(i,a,b) for(int i = (a); i <= (b); i++)
#define all(v) (v).begin(), (v).end()
int ans1 = 0;
int A, B, H, W;
int vis[20][20];
void dfs1(int x, int y, int a1, int b1) {
if(a1 < 0 or b1 < 0) return;
if(y == W) x++, y = 0;
if(x == H) return (void) ans1++;
if(vis[x][y]) return dfs1(x, y+1, a1, b1);
vis[x][y] = 1; dfs1(x, y+1, a1, b1-1);
if(!vis[x+1][y]) vis[x+1][y] = 1, dfs1(x, y+1, a1-1, b1), vis[x+1][y] = 0;
if(!vis[x][y+1]) vis[x][y+1] = 1, dfs1(x, y+1, a1-1, b1), vis[x][y+1] = 0;
vis[x][y] = 0;
return;
}
void taskD() {
cin >> H >> W >> A >> B;//BF
ans1 = 0;
//dfs(0, 0, A, B);
dfs1(0, 0, A, B);
cout << ans1;
return;
}
int main() {
//ios_base::sync_with_stdio(false), cin.tie(nullptr);
//taskPe26();
taskD();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return 1;
}
return 0;
}
#define 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
struct Setup {
Setup() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} __Setup;
using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define FOR(i, a, b) for(int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//-------------------------------------
int N;
ll X;
ll a[101];
ll dp[101][101][101];
int main() {
cin >> N >> X;
REP(i, N) cin >> a[i];
ll ans = LLINF;
FOR(k, 1, N+1) {
REP(i,N+1)REP(j,k+1)REP(l,k) dp[i][j][l] = -LLINF;
dp[0][0][0] = 0;
REP(i, N) {
REP(cnt, k + 1) {
REP(r, k) {
if(dp[i][cnt][r] == -LLINF) continue;
// えらぶ
if(cnt < k) {
ll cost = 0;
if(a[i] + r >= k) {
cost++;
ll remain = a[i] - (k - r);
cost += remain / k;
}
int nxt_r = (a[i] + r) % k;
if((dp[i][cnt][r] + cost) * k + nxt_r <= X) {
chmax(dp[i+1][cnt+1][nxt_r], dp[i][cnt][r] + cost);
}
}
// えらばない
chmax(dp[i+1][cnt][r], dp[i][cnt][r]);
}
}
}
if(dp[N][k][X%k] == -LLINF) continue;
chmin(ans, (X - X % k - dp[N][k][X%k] * k) / k);
}
assert(ans != LLINF);
cout << ans << endl;
} |
#include <iostream>
namespace wxy{
void main(){
int a,b,x,y;
std::cin >> a >> b;
x = (a + b) / 2;
y = a - x;
std::cout << x << " " << y;
}
}signed main(){wxy::main();return 0;} | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>b)return 0; a=b; return 1;}
#define bitUP(x,a) ((x>>a)&1)
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double EPS = 1e-6;
long double PI = acos(-1);
const ll INF=(1LL<<62);
const int MAX=(1<<30);
constexpr ll MOD=1000000000+7;
inline void bin101(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
}
using pii=pair<int,int>;
using pil=pair<int,ll>;
using pli=pair<ll,int>;
using pll=pair<ll,ll>;
using psi=pair<string,int>;
using pis=pair<int,string>;
using psl=pair<string,ll>;
using pls=pair<ll,string>;
using pss=pair<string,string>;
using Graph=vector<vector<int>>;
template<typename T >
struct edge {
int to;
T cost;
edge()=default;
edge(int to, T cost) : to(to), cost(cost) {}
};
template<typename T>
using WeightGraph=vector<vector<edge<T>>>;
//1-indexed vector cin
template<typename T>
inline void vin1(vector<T> &v){
for(size_t i=1;i<v.size();i++) cin>>v[i];
}
//0-indexed vector cin
template<typename T>
inline void vin0(vector<T> &v){
for(size_t i=0;i<v.size();i++) cin>>v[i];
}
//1-indexed vector<vector> cin
template<typename T>
inline void vin1(vector<vector<T>> &v){
for(size_t i=1;i<v.size();i++){
for(size_t j=1;j<v[i].size();j++) cin>>v[i][j];
}
}
//0-indexed vector<vector> cin
template<typename T>
inline void vin0(vector<vector<T>> &v){
for(size_t i=0;i<v.size();i++){
for(size_t j=0;j<v[i].size();j++) cin>>v[i][j];
}
}
//要素数n 初期値x
template<typename T>
inline vector<T> vmake(size_t n,T x){
return vector<T>(n,x);
}
//a,b,c,x data[a][b][c] 初期値x
template<typename... Args>
auto vmake(size_t n,Args... args){
auto v=vmake(args...);
return vector<decltype(v)>(n,move(v));
}
//pair cout
template<typename T, typename U>
inline ostream &operator<<(ostream &os,const pair<T,U> &p) {
os<<p.first<<" "<<p.second;
return os;
}
//pair cin
template<typename T, typename U>
inline istream &operator>>(istream &is,pair<T,U> &p) {
is>>p.first>>p.second;
return is;
}
//ソート
template<typename T>
inline void vsort(vector<T> &v){
sort(v.begin(),v.end());
}
//逆順ソート
template<typename T>
inline void rvsort(vector<T> &v){
sort(v.rbegin(),v.rend());
}
//1ビットの数を返す
inline int popcount(int x){
return __builtin_popcount(x);
}
//1ビットの数を返す
inline int popcount(ll x){
return __builtin_popcountll(x);
}
void solve(){
int N,X;
cin>>N>>X;
vector<int> A(N);
vin0(A);
vector<int> ans;
for(auto a:A){
if(a!=X) ans.push_back(a);
}
for(int i=0;i<ans.size();i++){
cout<<(i==0?"":" ")<<ans[i];
}
cout<<endl;
}
int main(){
bin101();
int T=1;
//cin>>T;
while(T--) solve();
}
|
#include <bits/stdc++.h>
#define INF 1e9
#define LINF (1LL << 63 - 1)
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define ALL(a) (a).begin(),(a).end()
// #define chmax(a, b) a = max(a, b)
// #define chmin(a, b) a = min(a, b)
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int)x.size())
using namespace std;
//using namespace atcoder;
using ld = long double;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> bool chmin(T& a, const T& b) { if(a > b){ a = b; return 1;} return 0; }
template<typename T> bool chmax(T& a, const T& b) { if(a < b){ a = b; return 1;} return 0; }
const ll ZER = 0;
const ll MOD = 1e9 + 7;
ll dp[2020][2020];
int main(){
// std::cin.tie(0);
// std::ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<ll> a(n), b(m);
rep(i, n)cin >> a[i];
rep(i, m)cin >> b[i];
rep(i, n)dp[i + 1][0] = i + 1;
rep(j, m)dp[0][j + 1] = j + 1;
rep(i, n){
rep(j, m){
if(a[i] == b[j]){
dp[i + 1][j + 1] = dp[i][j];
}
else {
dp[i + 1][j + 1] = min({dp[i][j], dp[i + 1][j], dp[i][j + 1]}) + 1;
}
}
}
cout << dp[n][m] << endl;
} | #include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <list>
#include <unordered_set>
#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
void ex_gcd(ll a,ll b, ll& d,ll& x,ll& y){
if(!b) {d=a;x=1;y=0;}
else { ex_gcd(b,a%b,d,y,x); y-=a/b*x;}
}
ll inv(ll a,ll n) {
ll d,x,y; ex_gcd(a,n,d,x,y);
return d==1?(x%n+n)%(n/d):-1;
}
const int maxn = 1005;
const int mod = 1000000007;
int a[maxn], b[maxn];
int f[maxn][maxn];
int main() {
#ifdef suiyuan2009
freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
//freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=m;i++)cin>>b[i];
int ret = 0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
f[i][j] = max(f[i-1][j],f[i][j-1]);
f[i][j] = max(f[i][j],f[i-1][j-1]+2-(a[i]!=b[j]));
ret = max(ret, f[i][j]);
}
cout<<n+m-ret<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int, int>
const int maxN = 1e6 + 10;
int n;
int a[maxN];
int main()
{
long long v, t, s, d;
cin>>v>>t>>s>>d;
long long l = v*t;
long long r = v*s;
if (d>r || d<l) printf("Yes\n"); else printf("No\n");
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b;
cin >> c >> d;
cout << a * d - b * c;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
#define DEBUG_ON
int main(){
ll n;
cin>>n;
vector <ll> a(n);
ll sum=0;
ll ind=0;
ll yoko=0;
ll ind_y=999;
ll yokom=0;
ll MAX;
ll robo=0;
ll hasi=0;
vector <ll> ma(n);
rep(i,n){
cin>>a.at(i);
sum+=a.at(i);
if(i>=1){
if(sum>ma.at(i-1)){
ma.at(i)=sum;
}
else{
ma.at(i)=ma.at(i-1);
}
}
else{
if(sum>=0){
ma.at(i)=sum;
}
else{
ma.at(i)=0;
}
}
robo = max(robo, hasi + ma.at(i));
hasi += sum;
}
cout<<robo;
return 0;
} | //Code by @Luckyniu (<Luogu uid>=142548)
#include<bits/stdc++.h>
#define int long long
#define in long double
#define inf 0x3f3f3f3f3f3f
#define ie inline
#define rg register
#define debug fprintf(stderr,"passed [%s] in line %d\n",__FUNCTION__,__LINE__);
using namespace std;
ie int power(int b, int k){
if(k==1) return b;
if(k&1){
return power(power(b,k>>1),2);
}
return power(power(b,(k-1)>>1),2)*b;
}
ie void read(int& tp){
tp=0;
int pt=1;
char cha=getchar();
while(cha<'0'||cha>'9'){
if(cha=='-') pt=-1;
cha=getchar();
}
while(cha>='0'&&cha<='9'){
tp=tp*10+cha-'0';
cha=getchar();
}
tp*=pt;
}
ie void write(int x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
int t;
int n;
signed main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
read(t);
while(t--){
read(n);
if(n&1) puts("Odd");
else if((n/2)&1) puts("Same");
else puts("Even");
}
return 0;
} |
// Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 105
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
#define what_is(x) cerr << #x << " is " << x << endl;
#define pii pair <ll, ll>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll INF = 1e13;
ll N, X, a[MAX], ans, rnd, M;
ll vis[MAX][MAX][MAX];
ll memo[MAX][MAX][MAX];
ll dp(ll i, ll k, ll md) {
if(i > N) {
if(md or k)
return -INF;
return 0;
}
if(vis[i][k][md] == rnd)
return memo[i][k][md];
// NOPE
ll ans = dp(i + 1, k, md);
// YEP
if(k > 0)
ans = max(ans, dp(i + 1, k - 1, (md + a[i]) % M) + a[i]);
vis[i][k][md] = rnd;
return memo[i][k][md] = ans;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin) ;
freopen("output.txt", "w", stdout) ;
#endif
optimiza_io
cin >> N >> X;
for(ll i = 1; i <= N; i ++)
cin >> a[i];
sort(a + 1, a + N + 1);
ans = X - a[N];
for(ll i = 2; i <= N; i ++) {
rnd++;
M = i;
ll st = (i - (X % i)) % i;
ll can = dp(1, i, st);
if(can > 0)
ans = min(ans, (X - can) / i);
}
cout << ans << "\n";
return 0;
}
// CHECAR LIMITES | #include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
vector<string> vec_splitter(string s) {
s += ',';
vector<string> res;
while(!s.empty()) {
res.push_back(s.substr(0, s.find(',')));
s = s.substr(s.find(',') + 1);
}
return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
stringstream ss; ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
double get_time() {
return 1.0 * clock() / CLOCKS_PER_SEC;
}
int main() {
int n, k;
cin >> n >> k;
vector<vector<int>> a(n, vector<int>(n));
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++)
cin >> a[i][j];
}
int w = (k*k + 1) / 2;
auto can = [&] (int x) {
auto b = a;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(b[i][j] <= x)
b[i][j] = 1;
else
b[i][j] = 0;
}
}
// is there a k x k submatrix of b with sum >= w?
vector<vector<int>> pref(n + 1, vector<int>(n + 1));
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
pref[i + 1][j] = pref[i][j] + b[i][j];
}
}
for(int i = 0; i < n + 1 - k; i++) {
int sum = 0;
for(int a = 0; a < k; a++) {
sum += pref[i + k][a] - pref[i][a];
}
debug(i + 1, x, sum);
for(int j = 0; j < n + 1 - k; j++) {
debug(x, i + 1, j + 1, sum);
if(sum >= w) {
debug(x, i + 1, j + 1, sum);
return true;
}
if(j + k < n) {
sum -= pref[i + k][j] - pref[i][j];
sum += pref[i + k][j + k] - pref[i][j + k];
}
}
}
return false;
};
debug(can(4));
int lo = 0, hi = 1E9 + 5;
while(lo < hi) {
int mid = (lo + hi) / 2;
if(can(mid))
hi = mid;
else
lo = mid + 1;
}
assert(can(lo));
cout << lo << '\n';
} |
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<tuple>
#include<cstring>
#include<bitset>
#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define pb push_back
#define eb emplace_back
#define INF 1000000000
#define INFLL 1000000000000000000LL
using namespace std;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
using ll = long long;
using PP = pair<ll, ll>;
#define MAX_N 200000
ll N;
PP x[MAX_N], y[MAX_N];
vector<ll> ans;
map<PP, ll> mp;
int main() {
cin >> N;
REP(i, N) {
cin >> x[i].first >> y[i].first;
x[i].second = i;
y[i].second = i;
}
sort(x, x + N);
sort(y, y + N);
REP(i, 10)REP(j, 10) {
if (i < N && 0 <= N - j && N - j < N && i != N - j) {
ll f =max(x[i].second, x[N - j].second);
ll s = min(x[i].second, x[N - j].second);
chmax(mp[{f, s}], abs(x[i].first - x[N - j].first));
f = max(y[i].second, y[N - j].second);
s = min(y[i].second, y[N - j].second);
chmax(mp[{f, s}], abs(y[i].first - y[N - j].first));
}
}
for (auto&& m : mp) {
ans.push_back(m.second);
}
sort(ALL(ans));
cout << ans[SZ(ans) - 2] << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 998244353
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
ll binpow(ll x,ll y)/* (x^y)%p in O(log y) */{ll res=1;while (y > 0){if(y&1)res=(res*x);y = y>>1;x=(x*x);}return res;}
ll binpowmod(ll x,ll y,ll p)/* (x^y)%p in O(log y) */{ll res=1;x=x%p;while (y > 0){if(y&1)res=(res*x)%p;y = y>>1;x=(x*x)%p;}return res;}
ll mod_inverse(ll n,ll p)/* Returns n^(-1) mod p */{return binpowmod(n,p-2,p);}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
return gcd(y,x%y);
}
bool isPowerOfTwo (ll x)
{
/* First x in the below expression is for the case when x is 0 */
return x && (!(x&(x-1)));
}
void swap(int &x,int &y){
int temp = x;
x = y;
y = temp;
}
unsigned int onesComplement(unsigned int n)
{
// Find number of bits in the given integer
int number_of_bits = floor(log2(n))+1;
// XOR the given integer with poe(2,
// number_of_bits-1 and print the result
return ((1 << number_of_bits) - 1) ^ n;
}
bool comp1(pair<int,int> x, pair<int,int> y)
{
return x.second < y.second;
}
// class cmp //comrootator for priority_queue
// { //declaration: priority_queue<int,vector<int>,cmp>
// public:
// bool operator()(E& A,E& B)
// {
// // if(A.first == B.first)
// // return A.second < B.second;
// return A.wt > B.wt;
// }
// };
void solve(){
int n;
cin >> n;
vector<pair<ll,ll>> xy;
for(int i = 0; i < n; ++i) {
ll x, y; cin >> x >> y;
xy.push_back({x, y});
}
sort(xy.begin(), xy.end());
vector<ll> ans;
for(int i = 1; i < n; ++i) {
ll dist = max(abs(xy[i].first - xy[0].first), abs(xy[i].second - xy[0].second));
ans.push_back(dist);
}
for(int i = n - 2; i >= 1; --i) {
ll dist = max(abs(xy[i].first - xy[n - 1].first), abs(xy[i].second - xy[n - 1].second));
ans.push_back(dist);
}
xy.pop_back();
reverse(xy.begin(), xy.end());
xy.pop_back();
sort(xy.begin(), xy.end(),[](pair<ll,ll>& p, pair<ll,ll>& q){
return p.second < q.second;
});
if(xy.size() >= 2) {
n = xy.size();
for(int i = 1; i < n; ++i) {
ll dist = max(abs(xy[i].first - xy[0].first), abs(xy[i].second - xy[0].second));
ans.push_back(dist);
}
for(int i = n - 2; i >= 1; --i) {
ll dist = max(abs(xy[i].first - xy[n - 1].first), abs(xy[i].second - xy[n - 1].second));
ans.push_back(dist);
}
}
sort(ans.begin(), ans.end(), greater<ll>());
cout << ans[1];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(15);
// int t;
// cin >> t;
// while(t--){
// solve();
// }
solve();
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
int main()
{
int n;
cin >> n;
vector<long long> ref(200, 0);
vector<int> arr(n);
rep(i, n) {
cin >> arr[i];
ref[arr[i] % 200]++;
}
long long ans = 0;
rep(i, 200) ans += ref[i]*(ref[i]-1) / 2;
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,ans;
int main(){
cin>>n;
for(ll i=1;i*i<=n+n;i++){
ll S=n+n-i*(i-1);
if(S%(i+i)!=0)continue;
ll l=S/(i+i);
if(l<=0)continue;
ans++;
}
ans<<=1;
cout<<ans<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<long long> Vll;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
struct UnionFind{
vector<int> par; // par[自分]=親
UnionFind(ll N) :par(N){
rep(i,N) par[i]=i;
}
int root(int 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);
int ry=root(y);
if(rx==ry)return;
par[rx]=ry;
}
bool same(int x,int y){ //x,yの木の根が同じならtrueを返す
int rx=root(x);
int ry=root(y);
return rx==ry;
}
};
int main(){
ll n,m;
cin >> n >> m;
Vll a(n),b(n);
rep(i,n)cin >>a[i];
rep(i,n)cin >> b[i];
UnionFind tree(n);
rep(i,m){
ll c,d;
cin >> c>> d;
tree.unite(c-1,d-1);
}
map<ll,ll > aa,bb;
rep(i,n){
if(aa.count(tree.root(i))){
aa[tree.root(i)]+=a[i];
bb[tree.root(i)]+=b[i];
}
else{
aa[tree.root(i)]=a[i];
bb[tree.root(i)]=b[i];
}
}
bool ans=true;
for(auto p: aa){
ll x=p.first;
if(aa[x]==bb[x])continue;
else {
ans=false;
break;
}
}
if(ans)cout << "Yes" << endl;
else cout << "No" << endl;
}
| #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>
using namespace std;
typedef long long ll;
int N, M;
vector<ll> A;
vector<ll> B;
vector<int> edge[200010];
bool arrived[200010];
pair<ll, ll> dfs(int cur)
{
pair<ll, ll> ret = {A[cur], B[cur]};
arrived[cur] = true;
for (int i = 0; i < (int)edge[cur].size(); i++)
{
int nxt = edge[cur][i];
if (arrived[nxt] == false)
{
pair<ll, ll> p = dfs(nxt);
ret.first += p.first;
ret.second += p.second;
}
}
//cout << cur << " " << ret.first << " " << ret.second << endl;
return ret;
}
int main()
{
cin >> N >> M;
for (int i = 0; i < N; i++)
{
int a;
cin >> a;
A.emplace_back(a);
}
for (int i = 0; i < N; i++)
{
int b;
cin >> b;
B.emplace_back(b);
}
for (int i = 0; i < M; i++)
{
int c, d;
cin >> c >> d;
c--;
d--;
edge[c].emplace_back(d);
edge[d].emplace_back(c);
}
memset(arrived, false, sizeof(arrived));
for (int i = 0; i < N; i++)
{
if (arrived[i] == false)
{
pair<ll, ll> p = dfs(i);
if (p.first != p.second)
{
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){
int n;
cin >> n;
vector<int> a(n),b(n),c(n),d(n),e(n);
rep(i,n) cin >> a[i] >> b[i] >> c[i] >> d[i] >> e[i];
vector<int> ftest(n,0),ff(n,0);
rep(i,n){
for(int j=i+1; j<n; j++){
if(a[i]>=a[j] && b[i]>=b[j] && c[i]>=c[j] && d[i]>=d[j] && e[i]>=e[j]) ftest[j]--;
if(a[i]<=a[j] && b[i]<=b[j] && c[i]<=c[j] && d[i]<=d[j] && e[i]<=e[j]) ftest[i]--;
if(a[i]==a[j] && b[i]==b[j] && c[i]==c[j] && d[i]==d[j] && e[i]==e[j]){
ff[i]++;ftest[j]=-3; ff[j]=-10000;
}
}
}
vector<int> fc;
rep(i,n) {
if(ftest[i]>=-2) fc.push_back(i);
if(ff[i]==1){
rep(i,2) fc.push_back(i);
}
if(ff[i]>=2){
rep(i,3) fc.push_back(i);
}
}
int m=fc.size();
// cout << m << endl;
int ans=1;
rep(i,m){
for(int j=i+1; j<m; j++){
for(int k=j+1; k<m; k++){
int pp=max(a[fc[i]],max(a[fc[j]],a[fc[k]]));
int ss=max(b[fc[i]],max(b[fc[j]],b[fc[k]]));
int tt=max(c[fc[i]],max(c[fc[j]],c[fc[k]]));
int cc=max(d[fc[i]],max(d[fc[j]],d[fc[k]]));
int hh=max(e[fc[i]],max(e[fc[j]],e[fc[k]]));
int allp=min(pp,min(ss,min(tt,min(cc,hh))));
ans=max(ans,allp);
}
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
template <long long mod>
struct modular {
long long value;
modular(long long x = 0LL) {
value = x % mod;
if (value < 0LL) value += mod;
}
modular& operator+=(modular other) {
if ((value += other.value) >= mod) value -= mod;
return *this;
}
modular& operator-=(modular other) {
if ((value -= other.value) < 0LL) value += mod;
return *this;
}
modular& operator*=(modular other) {
value = value * other.value % mod;
return *this;
}
modular& operator/=(modular other) {
long long a = 0LL, b = 1LL, c = other.value, m = mod;
while (c != 0LL) {
long long t = m / c;
m -= t * c;
swap(c, m);
a -= t * b;
swap(a, b);
}
a %= mod;
if (a < 0LL) a += mod;
value = value * a % mod;
return *this;
}
modular operator-() { return modular(-value); }
modular operator+(modular rhs) { return modular(*this) += rhs; }
modular operator-(modular rhs) { return modular(*this) -= rhs; }
modular operator*(modular rhs) { return modular(*this) *= rhs; }
modular operator/(modular rhs) { return modular(*this) /= rhs; }
bool operator==(modular rhs) { return value == rhs.value; }
bool operator!=(modular rhs) { return value != rhs.value; }
bool operator<(modular rhs) { return value < rhs.value; }
};
template <long long mod>
string to_string(modular<mod> x) {
return to_string(x.value);
}
template <long long mod>
ostream& operator<<(ostream& stream, modular<mod> x) {
x.value %= mod;
if (x.value < 0LL) x.value += mod;
return stream << x.value;
}
template <long long mod>
istream& operator>>(istream& stream, modular<mod>& x) {
stream >> x.value;
x.value %= mod;
if (x.value < 0LL) x.value += mod;
return stream;
}
const long long mod = (long long)1e9 + 7;
using mint = modular<mod>;
inline mint pw(mint a, long long n) {
mint res = 1;
while (n > 0LL) {
if (n & 1LL) {
res *= a;
}
a *= a;
n >>= 1;
}
return res;
}
vector<mint> fact, finv;
inline void cinit(int n) {
fact.resize(n, mint(1LL));
finv.resize(n, mint(1LL));
for (int i = 2; i < n; i++) {
fact[i] = fact[i - 1] * i;
}
finv[n - 1] /= fact[n - 1];
for (int i = n - 2; i >= 2; i--) {
finv[i] = finv[i + 1] * (i + 1);
}
}
inline mint C(int n, int k) {
if (n < k || k < 0 || n < 0) {
return mint(0LL);
}
return fact[n] * finv[k] * finv[n - k];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<vector<int>> c(2, vector<int>(2));
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
char x;
cin >> x;
c[i][j] = x - 'A';
}
}
if (n <= 3) {
cout << 1 << '\n';
return 0;
}
if (c[0][1] == 1) {
swap(c[0][0], c[1][1]);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
c[i][j] ^= 1;
}
}
}
if (c[0][0] == 0) {
cout << 1 << '\n';
} else if (c[1][0] == 0) {
vector<vector<mint>> dp(2, vector<mint>(n));
dp[0][0] = 1;
for (int i = 1; i < n; i++) {
dp[0][i] = dp[0][i - 1] + dp[1][i - 1];
dp[1][i] = dp[0][i - 1];
}
cout << dp[1][n - 1] << '\n';
} else {
cout << pw(2, n - 3) << '\n';
}
return 0;
} |
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
ll mymin(ll x,ll y) {return x<y?x:y;}
int main()
{
ll n;scanf("%lld",&n);
ll Ans=n;
for(int i=0;i<=62;i++){
ll t=(1ll<<i);
Ans=mymin(Ans,n/t+n%t+i);
}
printf("%lld\n",Ans);
return 0;
} | #ifndef AUTO_UTIL_HEADER_HPP
#define AUTO_UTIL_HEADER_HPP
#include <bits/stdc++.h>
#include <cassert>
using std::cin, std::cout, std::bitset, std::complex;
using std::vector, std::array, std::string, std::pair, std::list, std::queue, std::deque;
using std::priority_queue, std::set, std::map, std::unordered_map;
using std::greater;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ull = unsigned long long int;
using ll = long long int;
using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using cdouble = complex<double>;
const double eps = 1e-7;
#define Loop(i, n) for(int i = 0; i < int(n); i++)
#define Loopll(i, n) for(ll i = 0; i < ll(n); i++)
#define Loop1(i, n) for(int i = 1; i <= int(n); i++)
#define Loopll1(i, n) for(ll i = 1; i <= ll(n); i++)
#define Loopr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = ll(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = int(n); i >= 1; i--)
#define Looprll1(i, n) for(ll i = ll(n); i >= 1; i--)
#define Foreach(buf, container) for(const auto &buf : container)
#define Foreachr(buf, container) for(const auto &buf : reversed(container))
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define quickio() std::ios::sync_with_stdio(false); std::cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
#define Comp(type_t) bool operator<(const type_t &another) const
#define fst first
#define snd second
bool feq(double x, double y) { return abs(x - y) <= eps; }
bool inrange(ll x, ll t) { return x >= 0 && x < t; }
bool inrange(vll xs, ll t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; }
int ceillog2(ll x) { int m = int(log2(x)); return m + ((1LL << m) < x ? 1 : 0); }
int floorlog2(ll x) { int m = int(log2(x)); return m - ((1LL << m) > x ? 1 : 0); }
const string endl = "\n";
template<class T> T reversed(T container) { reverse(container.begin(), container.end()); return container; }
template<class T> void printv(const vector<T> &v) { for (const T &x : v) cout << x << " "; cout << endl; }
template<class T> void printmx(const vector<vector<T>> &mx) { for (const vector<T> &v : mx) printv(v); }
template<class T> void chmin(T &x, const T &y) { x = std::min(x, y); }
template<class T> void chmax(T &x, const T &y) { x = std::max(x, y); }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m* m <= x ? 0 : -1); }
ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return ll(m) * ll(n) / gcd(m, n); }
#endif // AUTO_UTIL_HEADER_HPP
//========================================================================//
int main() {
ll n; cin >> n;
ll ans = LLONG_MAX;
Loopll(b, 62) {
ll a = n >> b;
ll c = n % (1LL << b);
chmin(ans, a + b + c);
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T>
void view_1d(vector<T> V, string sep) {
for (ll i=0; i<V.size(); i++) {
cout << V[i];
if (i == V.size() - 1) {
cout << endl;
} else {
cout << sep;
}
}
}
template<typename T>
void view_2d(vector<vector<T>> V, string sep) {
for (ll i=0; i<V.size(); i++) {
for (ll j=0; j<V[i].size(); j++) {
cout << V[i][j];
if (j == V[i].size() - 1) {
cout << endl;
} else {
cout << sep;
}
}
}
}
//==============================//
int main() {
ll N, P;
cin >> N >> P;
ll BASE = 1000000007;
ll n = N - 1;
ll x = P - 2;
ll ans = P - 1;
while (n > 0) {
if (n & 1) ans = ans * x % BASE;
x = x * x % BASE;
n >>= 1;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int A;
int B;
cin >> A >> B;
A >= 0;
B <= 2 * A + 100;
B <= 1000;
cout << 2 * A + 100 - B << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif
template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}
const int MAX = 4e5 + 5;
int vis[MAX];
vector<pair<int, int>> adj[MAX];
bool dfs(int u, int p) {
bool ret = true;
vis[u] = true;
for (auto [v, i] : adj[u]) {
if (!vis[v])
ret &= dfs(v, i);
else if (i != p)
ret = false;
}
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i=0; i<n; i++) {
int a, b;
cin >> a >> b;
adj[a].emplace_back(b, i);
adj[b].emplace_back(a, i);
}
int ret = MAX - 1;
for (int i=1; i<MAX; i++)
if (!vis[i] && dfs(i, -1))
ret--;
cout << ret << "\n";
return 0;
}
| #include<bits/stdc++.h>
#define rep(i, n) for (int i = 0, length = n; i < length; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long>
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define ci4(w, x, y, z) cin >> w >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << " " << y << endl
#define co3(x, y, z) cout << x << " " << y << " " << z << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
typedef priority_queue<P> PQP;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;
const int MAX_N = 1e3, MOD = 1e9 + 7, INF = 1e9;
int n, m;
bool used[MAX_N * MAX_N];
map<char, vector<int>> to[MAX_N];
int main() {
ci2(n, m);
rep(i, m) {
int a, b;
char c;
ci3(a, b, c);
to[a - 1][c].epb(b - 1);
to[b - 1][c].epb(a - 1);
}
queue<P> q;
q.ep(0, n - 1);
used[n - 1] = true;
int ans = INF, dist = 0;
while (!q.empty()) {
P p = q.front(); q.pop();
if (p.fi > dist && ans < INF) {
co(ans);
return 0;
}
dist = p.fi;
int l = p.se / n, r = p.se % n;
for (auto &i: to[l]) {
if (to[r].find(i.fi) == to[r].end()) continue;
for (auto &j: to[l][i.fi]) {
for (auto &k: to[r][i.fi]) {
if (j == r && k == l) ans = min(ans, 2 * p.fi + 1);
if (j == k) ans = min(ans, 2 * p.fi + 2);
int tmp = j * n + k;
if (!used[tmp]) {
q.ep(p.fi + 1, tmp);
used[tmp] = true;
}
}
}
}
}
co(-1);
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1010000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}
char ff(char s, char t){
if(s == t) return t;
if(s != 'R' && t != 'R') return 'R';
else if(s != 'B' && t != 'B') return 'B';
else return 'W';
}
string g(string s){
//cout << 1 csp si(s) csp s << endl;
if(si(s) == 1) return s;
int a = 1;
int aa = a;
while (a <= si(s)) {
if((si(s)-1) % a == 0) chmax(aa,a);
a *= 3;
}
string t = "";
int b = 0;
while (b+aa < si(s)) {
t += ff(s[b],s[b+aa]);
//cout << s[b] csp b csp s[b+aa] csp b+aa << " ";
b += aa;
}
//cout << endl;
if(si(t) == 1) return t;
else return g(t);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
string s;
cin >> s;
cout << g(s) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
class Mint {
private:
int val;
public:
Mint () {val = 0;}
Mint(int _val) : val(_val) {}
Mint& operator += (const Mint &o) {val = (val + o.val < mod ? val + o.val : val + o.val - mod); return *this;}
template <typename T> Mint& operator += (const T &o) {return *this += Mint(o);}
Mint& operator -= (const Mint &o) {val = (val < o.val ? val - o.val + mod : val - o.val); return *this;}
template <typename T> Mint& operator -= (const T &o) {return *this -= Mint(o);}
Mint& operator *= (const Mint &o) {return *this = (1LL * val * o.val >= mod ? (1LL * val * o.val) % mod : val * o.val);}
template <typename T> Mint& operator *= (const T &o) {return *this *= Mint(o);}
friend bool operator == (const Mint &o1, const Mint &o2) {return (o1.val == o2.val);}
template <typename T> friend bool operator == (const Mint &o1, const T &o2) {return (o1 == Mint(o2));}
template <typename T> friend bool operator == (const T &o1, const Mint &o2) {return (Mint(o1) == o2);}
friend bool operator != (const Mint &o1, const Mint &o2) {return (o1.val != o2.val);}
template <typename T> friend bool operator != (const Mint &o1, const T &o2) {return (o1 != Mint(o2));}
template <typename T> friend bool operator != (const T &o1, const Mint &o2) {return (Mint(o1) != o2);}
friend Mint operator + (const Mint &o1, const Mint &o2) {return Mint(o1) += o2;}
template <typename T> friend Mint operator + (const Mint &o1, const T &o2) {return Mint(o1) += o2;}
template <typename T> friend Mint operator + (const T &o1, const Mint &o2) {return Mint(o1) += o2;}
friend Mint operator - (const Mint &o1, const Mint &o2) {return Mint(o1) -= o2;}
template <typename T> friend Mint operator - (const Mint &o1, const T &o2) {return Mint(o1) -= o2;}
template <typename T> friend Mint operator - (const T &o1, const Mint &o2) {return Mint(o1) -= o2;}
friend Mint operator * (const Mint &o1, const Mint &o2) {return Mint(o1) *= o2;}
template <typename T> friend Mint operator * (const Mint &o1, const T &o2) {return Mint(o1) *= o2;}
template <typename T> friend Mint operator * (const T &o1, const Mint &o2) {return Mint(o1) *= o2;}
Mint power(long long y) {
Mint ans = 1;
Mint x = *this;
while(y > 0) {
if(y & 1) ans *= x;
y >>= 1;
x *= x;
}
return ans;
}
Mint inverse () {return power(mod - 2);}
Mint& operator /= (const Mint &o) {return *this *= Mint(o).inverse();}
template <typename T> Mint& operator /= (const T &o) {return *this *= Mint(o).inverse();}
friend Mint operator / (const Mint &o1, const Mint &o2) {return Mint(o1) /= o2;}
template <typename T> friend Mint operator / (const Mint &o1, const T &o2) {return Mint(o1) /= o2;}
template <typename T> friend Mint operator / (const T &o1, const Mint &o2) {return Mint(o1) /= o2;}
bool operator ~ () const {return ~(this -> val);}
bool operator ! () const {return (this -> val == 0);}
void operator ++ () {*this += 1;}
void operator -- () {*this -= 1;}
void operator ++ (int) {*this += 1;}
void operator -- (int) {*this -= 1;}
friend ostream &operator << (ostream &os, const Mint &o) {os << o.val; return os;}
};
const int maxN = 3005;
Mint dp[maxN][maxN], mp[maxN][maxN];
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int n;
cin >> n;
ll a[n];
for(int i = 0; i < n; i++) {
cin >> a[i];
}
mp[0][0] = 1;
ll sum = 0;
for(int i = 1; i <= n; i++) {
sum += a[i - 1];
for(int j = i; j > 0; j--) {
dp[i][j] = mp[j - 1][sum % j];
mp[j][sum % (j + 1)] += dp[i][j];
}
}
Mint ans = 0;
for(int i = 1; i <= n; i++) {
ans += dp[n][i];
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
vector<pair<int,int>> x;
vector<pair<int,int>> y;
for(int i = 0; i < n; i++){
int xi, yi;
cin >> xi >> yi;
x.push_back(make_pair(xi,i));
y.push_back(make_pair(yi,i));
}
sort(x.begin(),x.end());
sort(y.begin(),y.end());
vector<tuple<int,int,int>> l;
l.push_back(make_tuple(x[n-1].first-x[0].first,x[0].second,x[n-1].second));
l.push_back(make_tuple(x[n-1].first-x[1].first,x[1].second,x[n-1].second));
l.push_back(make_tuple(x[n-2].first-x[0].first,x[0].second,x[n-2].second));
l.push_back(make_tuple(y[n-1].first-y[0].first,y[0].second,y[n-1].second));
l.push_back(make_tuple(y[n-1].first-y[1].first,y[1].second,y[n-1].second));
l.push_back(make_tuple(y[n-2].first-y[0].first,y[0].second,y[n-2].second));
sort(l.begin(),l.end());
reverse(l.begin(),l.end());
int lmax_a, lmax_b;
tie(ignore,lmax_a,lmax_b) = l[0];
int ans;
for(auto li : l){
int il, ia, ib;
tie(il,ia,ib) = li;
if(!((lmax_a == ia && lmax_b == ib)||(lmax_a == ib && lmax_b == ia))){
ans = il;
break;
}
}
cout << ans << endl;
} | #include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<string.h>
#include<math.h>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define F first
#define S second
#define MAX 500005
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define AC ios::sync_with_stdio(0);cin.tie(0);
using namespace std;
signed main(){
AC;
int n;
cin>>n;
vector<pair<ll,int> > x;
vector<pair<ll,int> > y;
FOR(i,0,n){
ll a,b;
cin>>a>>b;
x.pb({a,i});
y.pb({b,i});
}
sort(x.begin(),x.end());
sort(y.begin(),y.end());
vector<pair<ll,pair<int,int> > > aa;
aa.clear();
map<pair<int,int> ,bool> used;
aa.pb({abs(x[0].F-x[n-1].F),{x[n-1].S,x[0].S}});
aa.pb({abs(x[0].F-x[n-2].F),{x[n-2].S,x[0].S}});
aa.pb({abs(x[1].F-x[n-1].F),{x[n-1].S,x[1].S}});
aa.pb({abs(y[0].F-y[n-1].F),{y[n-1].S,y[0].S}});
aa.pb({abs(y[0].F-y[n-2].F),{y[n-2].S,y[0].S}});
aa.pb({abs(y[1].F-y[n-1].F),{y[n-1].S,y[1].S}});
sort(aa.begin(),aa.end());
if(aa[5].S.F==aa[4].S.F&&aa[5].S.S==aa[4].S.S){
cout<<aa[3].F<<endl;
}
else if(aa[5].S.F==aa[4].S.S&&aa[5].S.S==aa[4].S.F){
cout<<aa[3].F<<endl;
}
else{
cout<<aa[4].F<<endl;
}
}
|
#include<bits/stdc++.h>
#define int long long
using namespace std;
int get() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)) { if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); }
return x * f;
}
const int N = 2e5 + 5;
int n, m, q, a[N], b[N], ans, len, bin[N], tot;
struct Ask {
int T, x, y;
} s[N];
struct BIT {
int sum[N], sum0;
int lowbit(int x) { return x & (-x); }
void add(int x, int v) { while(x <= tot) sum[x] += v, x += lowbit(x); }
int ask(int x) { int r(0); while(x) r += sum[x], x -= lowbit(x); return r + sum0; }
int ask(int l, int r) { if(l > r) return 0; return ask(r) - ask(l - 1); }
} A1, B1, AS, BS;
void add1(int x) {
ans += BS.ask(a[x] + 1, tot) + bin[a[x]] * B1.ask(1, a[x]);
A1.add(a[x], 1), AS.add(a[x], bin[a[x]]);
}
void del1(int x) {
ans -= BS.ask(a[x] + 1, tot) + bin[a[x]] * B1.ask(1, a[x]);
A1.add(a[x], -1), AS.add(a[x], -bin[a[x]]);
}
void add2(int x) {
ans += AS.ask(b[x], tot) + bin[b[x]] * A1.ask(1, b[x] - 1);
B1.add(b[x], 1), BS.add(b[x], bin[b[x]]);
}
void del2(int x) {
ans -= AS.ask(b[x], tot) + bin[b[x]] * A1.ask(1, b[x] - 1);
B1.add(b[x], -1), BS.add(b[x], -bin[b[x]]);
}
signed main() {
n = get(), m = get(), q = get();
for(int i = 1; i <= q; i++) s[i].T = get(), s[i].x = get(), s[i].y = get(), bin[i] = s[i].y;
bin[q + 1] = 0;
sort(bin + 1, bin + 1 + q + 1), tot = unique(bin + 1, bin + 1 + q + 1) - bin - 1;
for(int i = 1; i <= q; i++) s[i].y = lower_bound(bin + 1, bin + 1 + tot, s[i].y) - bin;
for(int i = 1; i <= n; i++) a[i] = 1;
for(int i = 1; i <= m; i++) b[i] = 1;
A1.add(1, n), B1.add(1, m);
for(int i = 1; i <= q; i++) {
int T = s[i].T, x = s[i].x, y = s[i].y;
if(T == 1) del1(x), a[x] = y, add1(x);
else del2(x), b[x] = y, add2(x);
printf("%lld\n", ans);
}
return 0;
}
| #include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
//using lll=boost::multiprecision::cpp_int;
template <class T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
template <typename T>
T mypow(T x, T n, const T &p = -1)
{ //x^nをmodで割った余り
T ret = 1;
while (n > 0)
{
if (n & 1)
{
if (p != -1)
ret = (ret * x) % p;
else
ret *= x;
}
if (p != -1)
x = (x * x) % p;
else
x *= x;
n >>= 1;
}
return ret;
}
using namespace std;
// using namespace atcoder;
template<int mod>
struct Modint{
int x;
Modint():x(0){}
Modint(int64_t y):x((y%mod+mod)%mod){}
Modint &operator+=(const Modint &p){
if((x+=p.x)>=mod)
x -= mod;
return *this;
}
Modint &operator-=(const Modint &p){
if((x+=mod-p.x)>=mod)
x -= mod;
return *this;
}
Modint &operator*=(const Modint &p){
x = (1LL * x * p.x) % mod;
return *this;
}
Modint &operator/=(const Modint &p){
*this *= p.inverse();
return *this;
}
Modint operator-() const { return Modint(-x); }
Modint operator+(const Modint &p) const{
return Modint(*this) += p;
}
Modint operator-(const Modint &p) const{
return Modint(*this) -= p;
}
Modint operator*(const Modint &p) const{
return Modint(*this) *= p;
}
Modint operator/(const Modint &p) const{
return Modint(*this) /= p;
}
bool operator==(const Modint &p) const { return x == p.x; }
bool operator!=(const Modint &p) const{return x != p.x;}
Modint inverse() const{//非再帰拡張ユークリッド
int a = x, b = mod, u = 1, v = 0;
while(b>0){
int t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return Modint(u);
}
Modint pow(int64_t n) const{//繰り返し二乗法
Modint ret(1), mul(x);
while(n>0){
if(n&1)
ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os,const Modint &p){
return os << p.x;
}
};
using modint = Modint<mod>;
void solve()
{
double a,b;
cin>>a>>b;
double x=a-b;
double ans=x/a*100;
cout<<ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
solve();
return 0;
}
|
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <numeric>
#include <math.h>
#include <complex>
using namespace std;
#define rep(i, n) for (long long int i = 0; i < (long long int)(n); i++)
#define irep(i, n) for (long long int i = 1; i <= (long long int)(n); i++)
#define drep(i, n, diff) for (long long int i = 0; i < (long long int)(n); i += diff)
#define mod 1000000007
#define INF 100100100100100101
#define ld(val) printf("%s : %lld\n", #val, val);
#define sd(val) printf("%s : %s\n", #val, val);
typedef long long int ll;
typedef pair<ll, ll> P;
typedef pair<P, P> PP;
typedef tuple<ll, ll, ll> TP;
int main() {
ll n, k;
cin >> n >> k;
rep(i, k) {
if(n%200==0){
n/=200;
}else{
n*=1000;
n+=200;
}
}
cout << n << endl;
return 0;
}
| #include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
using namespace std;
pair<int,int> fun(int a, int b){
return {min(a,b),max(a,b)};
}
bool comp(pair<pair<ll,ll> ,int > a ,pair<pair<ll,ll> ,int > b ){
return a.F.F<b.F.F;
}
bool comp2(pair<pair<ll,ll> ,int > a ,pair<pair<ll,ll> ,int > b ){
return a.F.S<b.F.S;
}
void test(){
ll n;
cin>>n;
ll x[n],y[n];
f(i,n)cin>>x[i]>>y[i];
vector<pair<pair<ll,ll>,int> > v;
f(i,n)v.pb({{x[i],y[i]},i});
sort(v.begin(),v.end(),comp);
set<pair<int,int> > st;
st.insert(fun(v[0].S,v[n-1].S));
st.insert(fun(v[0].S,v[n-2].S));
st.insert(fun(v[1].S,v[n-1].S));
sort(v.begin(),v.end(),comp2);
st.insert(fun(v[0].S,v[n-1].S));
st.insert(fun(v[0].S,v[n-2].S));
st.insert(fun(v[1].S,v[n-1].S));
vector<ll> dis;
for(auto z : st){
dis.pb(max(abs(x[z.F]-x[z.S]), abs(y[z.F]-y[z.S])));
}
sort(dis.rbegin(),dis.rend());
cout<<dis[1]<<"\n";
}
int main(){
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tests=1;
// cin>>tests;
while(tests--){
test();
}
}
|
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60) //1LL<<63でオーバーフロー
#define inf (1<<29) //1<<29でオーバーフロー
int main(int argc,char* argv[]){
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
int a,b;
cin >> a >> b;
cout << 2*a+100-b << endl;
return 0;
}
| #include <iostream>
#include <cmath>
#include <utility>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
#define mp make_pair
#define x first
#define y second
int main () {
int a,b;
cin>>a>>b;
cout<<(a+b)/2<<" ";
cout<<(a-b)/2;
return 0;
} |
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
using ll = long long;
int h, w, n, m, vis[1510][1510];
struct pos{
int x, y;
};
pos p[500005];
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
void dfs(int x, int y, int k) {
if (x < 0 || y < 0 || x >= h || y >= w) return;
if (vis[x][y] == 1 || vis[x][y] == -1) return;
if (vis[x][y] == 0) vis[x][y] = 2;
dfs(x + dx[k], y + dy[k], k);
}
int main() {
scanf("%d %d %d %d\n", &h, &w, &n, &m);
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d %d", &x, &y);
p[i].x = x - 1, p[i].y = y - 1;
vis[x - 1][y - 1] = 1;
}
for (int i = 0; i < m; i++) {
int x, y;
scanf("%d %d", &x, &y);
vis[x - 1][y - 1] = -1;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 4; j++)
dfs(p[i].x + dx[j], p[i].y + dy[j], j);
}
int ans = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (vis[i][j] > 0) ans++;
}
}
printf("%d", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef pair<int, int> ii;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define each(x, s) for(auto& x : s)
#define loop(x) for(int i = 0;i < x;i++)
#define vloop(v, x) for(int v = 0;v < x;v++)
#define avg(l, r) l + (r - l) / 2
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define endl "\n"
const ll mod = 1000000007;
int main() {
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int h, w, n, m;
cin >> h >> w >> n >> m;
vector<vb> grid(h, vb(w, true));
int ans = h * w, x, y;
vector<vi> lvs(w, vi(1, -2)), bvs(w, vi(1, -1)), lhs(h, vi(1, -2)), bhs(h, vi(1, -1));
loop(n) {
cin >> x >> y;
x--, y--;
grid[x][y] = false;
lhs[x].push_back(y);
lvs[y].push_back(x);
}
loop(m) {
cin >> x >> y;
x--, y--;
grid[x][y] = false;
bhs[x].push_back(y);
bvs[y].push_back(x);
ans--;
}
loop(h) {
lhs[i].push_back(INF + 1);
bhs[i].push_back(INF);
sort(iter(lhs[i]));
sort(iter(bhs[i]));
}
loop(w) {
lvs[i].push_back(INF + 1);
bvs[i].push_back(INF);
sort(iter(lvs[i]));
sort(iter(bvs[i]));
}
vi vls(w, 0), vbs(w, 0);
loop(h) {
int hl = 0, hb = 0;
vloop(j, w) {
if (lhs[i][hl + 1] == j) {
hl++;
vls[j]++;
}
else if (bhs[i][hb + 1] == j) {
hb++;
vbs[j]++;
}
if (!grid[i][j]) continue;
if (lhs[i][hl] < bhs[i][hb] and lhs[i][hl + 1] > bhs[i][hb + 1] and lvs[j][vls[j]] < bvs[j][vbs[j]] and lvs[j][vls[j] + 1] > bvs[j][vbs[j] + 1]) {
ans -= grid[i][j];
grid[i][j] = false;
}
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
// #define LOCAL // 提出時はコメントアウト
#define DEBUG_
typedef long long ll;
const double EPS = 1e-9;
const ll INF = ((1LL<<62)-(1LL<<31));
typedef vector<ll> vecl;
typedef pair<ll, ll> pairl;
template<typename T> using uset = unordered_set<T>;
template<typename T, typename U> using mapv = map<T,vector<U>>;
template<typename T, typename U> using umap = unordered_map<T,U>;
#define ALL(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define sz(x) (ll)x.size()
ll llceil(ll a,ll b) { return (a+b-1)/b; }
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; }
template<class T> vector<vector<T>> genarr(ll n, ll m, T init) { return vector<vector<T>>(n,vector<T>(m,init)); }
///// DEBUG
#define DUMPOUT cerr
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
template<typename T>istream&operator>>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<typename T,typename U>ostream&operator<<(ostream&os,pair<T,U>&pair_var){os<<"("<<pair_var.first<<", "<<pair_var.second<<")";return os;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&vec){os<<"{";for(int i=0;i<vec.size();i++){os<<vec[i]<<(i+1==vec.size()?"":", ");}
os<<"}";return os;}
template<typename T,typename U>ostream&operator<<(ostream&os,map<T,U>&map_var){os<<"{";repi(itr,map_var){os<<*itr;itr++;if(itr!=map_var.end())os<<", ";itr--;}
os<<"}";return os;}
template<typename T>ostream&operator<<(ostream&os,set<T>&set_var){os<<"{";repi(itr,set_var){os<<*itr;itr++;if(itr!=set_var.end())os<<", ";itr--;}
os<<"}";return os;}
void dump_func(){DUMPOUT<<endl;}
template<class Head,class...Tail>void dump_func(Head&&head,Tail&&...tail){DUMPOUT<<head;if(sizeof...(Tail)>0){DUMPOUT<<", ";}
dump_func(std::move(tail)...);}
#ifndef LOCAL
#undef DEBUG_
#endif
#ifdef DEBUG_
#define DEB
#define dump(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \
<< endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
//////////
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
int solve(ostringstream &cout) {
#ifdef LOCAL
ifstream in("../../Atcoder/input.txt");
cin.rdbuf(in.rdbuf());
#endif
ll N;
cin>>N;
vecl A(N),B(N);
rep(i,N) {
cin>>A[i]>>B[i];
}
rep(i,N) {
REP(j,i+1,N) {
REP(k,j+1,N) {
ll x = A[j] - A[i], y = B[j] - B[i];
ll X = A[k] - A[i], Y = B[k] - B[i];
if (x * Y == y * X) {
cout << "Yes" << endl;
return 0;
}
}
}
}
cout << "No" << endl;
return 0;
}
int main() {
ostringstream oss;
int res = solve(oss);
cout << oss.str();
return res;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
ll arr[n][3];
for(int i=0;i<n;i++){
cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
}
ll ans=INT_MAX;
for(int i=0;i<n;i++){
ll dif=arr[i][2]-arr[i][0];
if(dif>0){
ans=min(ans,arr[i][1]);
}
}
if(ans==INT_MAX){
cout<<-1;
}
else{
cout<<ans;
}
return 0;
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long int;
void solve() {
}
int main() {
// input
int N;
cin >> N;
vector<int> A(N, 0);
rep(i, N) cin >> A[i];
sort(A.begin(), A.end());
int k = 0;
int ans = 0;
for (int i = 2; i <= A[N - 1]; i++)
{
int gcd = 0;
for (int a : A)
{
if (a % i == 0) {
gcd++;
}
}
if (k <= gcd) {
k = gcd;
ans = i;
}
}
cout << ans << endl;
} | #include<iostream>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod(ll a);
int main(){
int n;
cin >> n;
vector<int> p(n);
vector<int> a(200000,0);
for(int i=0;i<n;++i) cin >> p[i];
int min=0;
for(int i=0;i<n;++i){
a[p[i]]++;
//cout<<"input "<<p[i]<<" "<<min<<endl;
if(min==p[i]){
int k=p[i];
while(a[k]!=0) k++;
min = k;
}
cout<<min<<endl;
}
}
ll mod(ll a){
int b=1000000007;
while(a<0) a+=b;
return a%b;
} |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const ll mod = 1e9+7;
ll mul(ll a,ll b){return ((a%mod)*(b%mod))%mod;}
ll sum(ll a,ll b){return ((a%mod)+(b%mod))%mod;}
ll sub(ll a,ll b){return ((a%mod)-(b%mod))%mod;}
ll power(ll a,ll b){
ll res = 1;
while(b){
if(b&1)res = mul(res,a);
b >>= 1;
a = mul(a,a);
}
return res;
}
ll gcdE(ll a,ll b,ll *x, ll *y){
if(a == 0){
*x = 0, *y = 1;
return b;
}
ll x1,y1;
ll gcd = gcdE(b%a,a,&x1,&y1);
*x = y1-(b/a)*x1;
*y = x1;
return gcd;
}
ll modInverse(ll b,ll m){
ll x,y;
ll g = gcdE(b,m,&x,&y);
if(g != 1) return -1;
return (x%mod+mod)%mod;
}
ll modDivide(ll a,ll b){
a = a%mod;
ll inv = modInverse(b,mod);
if(inv == -1) return -1;
return (inv*a)%mod;
}
ll binomialCoeff(int n,int k){
ll res = 1;
if(k > n-k) k = n-k;
for(int i = 0; i < k; i++){
res = mul(res,n-i);
res = modDivide(res,i+1);
}
return res;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int N,M; cin >> N >> M;
vi A(N);
int sum = 0;
forn(i,0,N){
cin >> A[i];
sum += A[i];
}
if(sum > M){
cout << 0 << '\n';
return 0;
}
ll res = binomialCoeff(M+N,sum+N);
if(res < 0)res += mod;
cout << res << '\n';
return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/
| #include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
// using mint2 = modint998244353;
typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
const double EPS = 1e-10;
const Int INF = 5e18;
const int inf = 1e9;
const Int mod = 1e9+7;
//const Int mod = 998244353;
typedef struct {
int64_t to, weight;
} edge;
Int dx[] = {0, 1, 0, -1, -1, 1, -1, 1};
Int dy[] = {1, 0, -1, 0, -1, -1, 1, 1};
template<class T>
istream &operator>>(istream &is, vector<T> &v) {
for (auto &e : v) {
is >> e;
}
return is;
}
bool print_space_enable = false;
void print() {
std::cout << '\n';
print_space_enable = false;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
if (print_space_enable) std::cout << " ";
std::cout << fixed << setprecision(15) << head;
print_space_enable = true;
print(std::forward<Tail>(tail)...);
}
template<typename T>
void print(vector<T> v) {
for (size_t i = 0; i < v.size(); i++) {
if (i > 0) std::cout << " ";
std::cout << v[i];
}
std::cout << '\n';
}
template<class T>
vector<T> make_vec(size_t n, T val) {
return vector<T>(n, val);
}
template<class... Ts>
auto make_vec(size_t n, Ts... ts) {
return vector<decltype(make_vec(ts...))>(n, make_vec(ts...));
}
bool is_overflow(Int a, Int b) {
return a > INF / b;
}
void solve() {
Int n, q;
cin >> n >> q;
vector<Int> a(n);
cin >> a;
vector<Int> k(q);
cin >> k;
a.push_back(INF);
sort(all(a));
for (Int i = 0; i < q; i++) {
Int ok = 3e18;
Int ng = -1;
while (abs(ok - ng) > 1) {
Int mid = (ok + ng) / 2;
Int num = upper_bound(all(a), mid) - a.begin();
if (mid - num >= k[i]) {
ok = mid;
} else {
ng = mid;
}
}
print(ok);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
//Int _t; cin >> _t; while (_t--) solve();
return 0;
}
|
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define ll long long
#define ld long double
#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 pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define SUM(v) accumulate(all(v), 0LL)
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
const string YESNO[2] = {"NO", "YES"};
const string YesNo[2] = {"No", "Yes"};
const string yesno[2] = {"no", "yes"};
void YES(bool t = 1) { cout << YESNO[t] << endl; }
void Yes(bool t = 1) { cout << YesNo[t] << endl; }
void yes(bool t = 1) { cout << yesno[t] << endl; }
int main() {
int A, B; cin >> A >> B;
int ans = 1;
for (int i = 1; i < 200500; i++) {
int r = 0;
if (A % i != 0) r = i - A % i;
if (B - A >= i + r) ans = i;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int charToInt(char c){
char zero_num = '0';
return (int)c - (int)zero_num;
}
signed main(){
int N; cin>>N;
int M; cin>>M;
vec_int a(M);
vec_int b(M);
rep(i,M)cin>>a.at(i)>>b.at(i);
vec_int c(N); rep(i,N)cin>>c.at(i);
vector<vec_int> G(N+1);
rep(i,M){
G.at(a.at(i)).push_back(b.at(i));
G.at(b.at(i)).push_back(a.at(i));
}
map<P, int> path_map;
rep(i, M){
path_map[make_pair(a.at(i), b.at(i))] = i;
path_map[make_pair(b.at(i), a.at(i))] = i;
}
vector<string> ans(M,"");
rep(i,M){
if(c.at(a.at(i)-1)>c.at(b.at(i)-1)){
ans.at(i) = "->";
}else if(c.at(a.at(i)-1)<c.at(b.at(i)-1)){
ans.at(i) = "<-";
}
}
rep(i,M){
if(ans.at(i)==""){
vec_int visited(N+1, 0);
visited.at(a.at(i)) =1;
stack<P> st;
st.push(make_pair(b.at(i), a.at(i))); // node, parent
int node_val = c.at(a.at(i)-1);
while(!st.empty()){
int node = st.top().first;
int parent = st.top().second;
st.pop();
int ind = path_map[make_pair(parent, node)];
if(ans.at(ind)!="")continue;
if(a.at(ind)==parent && b.at(ind)==node){
ans.at(ind) = "->";
}else{
ans.at(ind) = "<-";
}
for(auto next_node: G.at(node)){
if(next_node==parent)continue;
if(c.at(next_node-1)!=node_val)continue;
st.push(make_pair(next_node, node));
}
}
}
}
rep(i,M){
cout<<ans.at(i)<<endl;
}
return 0;
} |
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int ll;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}
int main(){
int x[4];
int lowest = 101;
for (int i = 0; i < 4; i++) {
cin >> x[i];
if ((int) x[i] < lowest) {
lowest = (int) x[i];
}
}
cout << lowest;
} | #include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <climits>
#include <iomanip>
#define endl "\n"
#define debug(x) cout << #x << " : " << x << endl;
#define debug2(x, y) cout << #x << " : " << x << ", " << #y << " : " << y << endl;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0);
typedef long long ll;
using namespace std;
int main()
{
FASTIO
int a, b, c, d;
cin >> a >> b >> c >> d;
int ans = min({a, b, c, d});
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
typedef pair<pi,ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
int H,W,grid[501][501];
int main(){
fast;
cin >> H >> W;
int mn = 1e9, ans = 0;
FOR(i,1,H) FOR(j,1,W){
cin >> grid[i][j]; mn = min(mn, grid[i][j]);
ans += grid[i][j];
}
cout << ans - mn * H * W;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < b; i++)
int H, W;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> H >> W;
vector<vector<ll>> a(H, vector<ll>(W));
ll mmin = 101;
for(int i = 0; i < H; i++) {
for(int j = 0; j < W; j++) {
{
cin >> a[i][j];
mmin = min(mmin, a[i][j]);
}
}
};
ll s = 0;
for(int i = 0; i < H; i++) {
for(int j = 0; j < W; j++) {
s += abs(a[i][j] - mmin);
}
}
cout << s << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int INF=1<<29;
int h,w;
vector<string> B;
bool vis[2000][2000][2];
int memo[2000][2000][2];
int dfs(int i,int j,int turn){
if(i==h-1 && j==w-1) return 0;
int& res=memo[i][j][turn];
if(vis[i][j][turn]) return res;
vis[i][j][turn]=true;
if(turn==0){
res=-INF;
if(i<h-1) res=max(res,dfs(i+1,j,1-turn)+(B[i+1][j]=='+'?1:-1));
if(j<w-1) res=max(res,dfs(i,j+1,1-turn)+(B[i][j+1]=='+'?1:-1));
}
else{
res=INF;
if(i<h-1) res=min(res,dfs(i+1,j,1-turn)-(B[i+1][j]=='+'?1:-1));
if(j<w-1) res=min(res,dfs(i,j+1,1-turn)-(B[i][j+1]=='+'?1:-1));
}
return res;
}
int main(){
cin>>h>>w;
B.resize(h);
rep(i,h) cin>>B[i];
int res=dfs(0,0,0);
puts(res>0?"Takahashi":res==0?"Draw":"Aoki");
return 0;
}
| #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;
int main(void){
int h, w, i, j;
string buff;
vector<vector<int> > field, score;
cin >> h >> w;
field.resize(h,vector<int>(w));
score.resize(h,vector<int>(w));
for(i=0;i<h;i++){
cin >> buff;
for(j=0;j<w;j++){
if(buff[j]=='+') field[i][j] = 1;
else field[i][j] = -1;
}
}
if((h+w)%2==0){
score[h-1][w-1] = field[h-1][w-1];
}
else{
score[h-1][w-1] = field[h-1][w-1] * -1;
}
j = w-1;
for(i=h-2;i>=0;i--){
if((i+j)%2==0){
score[i][j] = score[i+1][j] + field[i][j];
}
else{
score[i][j] = score[i+1][j] - field[i][j];
}
}
i = h-1;
for(j=w-2;j>=0;j--){
if((i+j)%2==0){
score[i][j] = score[i][j+1] + field[i][j];
}
else{
score[i][j] = score[i][j+1] - field[i][j];
}
}
for(i=h-2;i>=0;i--){
for(j=w-2;j>=0;j--){
if((i+j)%2==0){
score[i][j] = min(score[i+1][j],score[i][j+1]) + field[i][j];
}
else{
score[i][j] = max(score[i+1][j],score[i][j+1]) - field[i][j];
}
}
}
if(h==1){
if(w==1){
cout << "Draw" << endl;
return 0;
}
score[0][0] = score[0][1];
}
else if(w==1){
score[0][0] = score[1][0];
}
else{
score[0][0] = min(score[1][0],score[0][1]);
}
if(score[0][0]>0){
cout << "Aoki" << endl;
}
else if(score[0][0]<0){
cout << "Takahashi" << endl;
}
else{
cout << "Draw" << endl;
}
return 0;
}
|
// Create your own template by modifying this file!
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cassert>
#include <deque>
#include <stack>
#include <functional>
#include <bitset>
#include <numeric>
#define int LL
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef DEBUG
#define debug(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
#define debug(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
template<class T> void MIN(T& a, const T& b) { a = min(a, b); }
template<class T> void MAX(T& a, const T& b) { a = max(a, b); }
#define MULTITEST 0
void solve() {
int N, M;
R(N, M);
VPII e(M);
REP(i, M) {
R(e[i].F, e[i].S);
e[i].F--;
e[i].S--;
}
VI c(N);
REP(i, N) {
R(c[i]);
}
VI ans(M, -1);
vector<VI> adj(N);
REP(i, M) {
if (c[e[i].F] == c[e[i].S]) {
adj[e[i].F].PB(i);
adj[e[i].S].PB(i);
} else {
ans[i] = (c[e[i].F] < c[e[i].S]);
}
}
vector<bool> used(N);
function<void(int)> dfs;
dfs = [&](int v) {
if (used[v]) {
return;
}
used[v] = true;
for (int i : adj[v]) {
if (ans[i] < 0) {
ans[i] = (e[i].S == v);
dfs(v ^ e[i].F ^ e[i].S);
}
}
};
REP(v, N) {
if (!used[v] && adj[v].size()) {
int i = adj[v].front();
ans[i] = (e[i].S == v);
dfs(v ^ e[i].F ^ e[i].S);
}
}
for (int b : ans) {
assert(b >= 0);
W(b ? "<-" : "->");
}
}
#undef int
int main() {
#if MULTITEST
CASET{
solve();
}
#else
solve();
#endif
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> s(N);
for (int i = 0; i < N; i++) {
cin >> s[i];
}
vector<long long> dp(N + 1, 1);
for (int i = 1; i <= N; i++) {
if (s[i - 1] == "AND") {
dp[i] = dp[i - 1];
}
else {
dp[i] = dp[i - 1] + (1LL << i);
}
}
cout << dp[N] << endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
string S;
bool flag = true;
cin >> S;
for(int i = 1; i <= S.length(); i++) {
if(i % 2 == 1) {
if('A' <= S[i - 1] && S[i - 1] <= 'Z') {
cout << "No" << endl;
flag = false;
break;
}
}
else {
if('a' <= S[i - 1] && S[i - 1] <= 'z') {
cout << "No" << endl;
flag = false;
break;
}
}
}
if(flag == true) {
cout << "Yes" << endl;
}
}
| #include <iostream>
int main()
{
int N;
std::cin >> N;
int r = N%100;
if (r) std::cout << N/100 + 1 << std::endl;
else std::cout << N/100 << std::endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define mod 998244353
#define MOD 1000000007
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
// aのn乗を求める(modp)
int modPow(ll a, ll n, ll p) {
if (n == 0) return 1; // 0乗にも対応する場合
if (n == 1) return a % p;
if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
ll t = modPow(a, n / 2, p);
return (t * t) % p;
}
int main(){
ll n, m;
cin >> n >> m;
string s;
ll odd = 0, even = 0;
rep(i, n){
cin >> s;
ll count = 0, len = s.size();
rep(i, len){
if(s[i] == '1') count++;
}
if(count%2 == 0) even++;
else odd++;
}
cout << odd*even << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define deb(k) cerr << #k << ": " << k << "\n";
#define size(a) (int)a.size()
#define fastcin cin.tie(0)->sync_with_stdio(0);
#define st first
#define nd second
#define pb push_back
#define mk make_pair
#define int long long
typedef long double ldbl;
typedef double dbl;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef vector<int> vint;
#define MAXN 300100
#define MAXLG 20
const int inf = 0x3f3f3f3f;
const ll mod = 1000000007;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const int N = 300100;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
int n, m;
cin>>n>>m;
string s[n];
map<int, int>f;
vint a(n);
for(int i=0;i<n;i++){
cin>>s[i];
for(int j=0;j<m;j++){
a[i] *= 2;
a[i] += (s[i][j] - '0');
}
f[a[i]]++;
}
queue<pii>q;
q.push({0, 0});
int x = 0, y = 0;
bitset<(1<<20)> vis;
vis[0] = 1;
while(!q.empty()){
pii a = q.front();
q.pop();
if(a.nd == 0) x += f[a.st];
else y += f[a.st];
for(int i=0;i<m;i++){
int aux = a.st ^ (1<<i);
if(vis[aux]) continue;
vis[aux] = 1;
q.push({aux, a.nd^1});
}
}
cout<<x*y<<"\n";
// Have you read the problem again?
// Maybe you understood the wrong problem
}
int32_t main(){
fastcin;
int t_ = 1;
//cin>>t_;
while(t_--)
solve();
return 0;
}
|
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define repk(i,a,n) for(int i=a;i<=(n);i++)
#define pb push_back
#define ppb pop_back
#define all(k) k.begin(),k.end()
#define eb emplace_back
#define mp make_pair
#define ll long long
#define pl pair<ll,ll>
#define vc vector<char>
#define vl vector<ll>
#define vvl vector<vl>
#define vi vector<int>
#define vvi vector<vi>
#define vc vector<char>
#define vpi vector<pi>
#define vpl vector<pl>
#define vvc vector<vc>
#define mi map<int,int>
#define ml map<ll,ll>
template<typename T, typename U> inline bool mn(T& m, U x) { if (m > x) { m = x; return true; } return false; }
#define umap unordered_map<int,int>
using namespace std;
void sol() {
int n; cin >> n;
vl ar(n);
rep(i, 0, n)cin >> ar[i];
ll cnt = -1, res = *min_element(all(ar));
while (cnt != res) {
cnt = res;
rep(i, 0, n) {
if (!(ar[i] % res))mn(res, res);
else
mn(res, ar[i] % res);
}
}
cout << res;
}
int main() {
int t = 1; //cin >> t;
while (t--)sol();
return 0;
} | #include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
#define x first
#define y second
typedef pair<int, int> PII;
const int N = 70010;
int n;
PII a[N];
int main()
{
cin >> n;
n = pow(2, n);
for(int i = 1; i <= n; i ++ )
{
cin >> a[i].x;
a[i].y = i;
}
while(n > 2)
{
for(int i = 1; i <= n; i += 2 )
{
if(a[i].x > a[i + 1].x)
{
a[i/2 + 1].x = a[i].x;
a[i/2 + 1].y = a[i].y;
}
else
{
a[i/2 + 1].x = a[i + 1].x;
a[i/2 + 1].y = a[i + 1].y;
}
}
n /= 2;
}
if(a[1].x > a[2].x) cout << a[2].y << endl;
else cout << a[1].y << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n;
cin >> n;
long long sum = 0;
long long cnt = 0;
long long i = 0;
while (sum <= n + 1)
{
i++;
sum += i;
cnt++;
}
cnt--;
cout << n - cnt + 1 << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll b,c;
ll cnt(ll a){
if(c<a) return 0;
else return (c-a)/2+1;
}
int main(){
cin>>b>>c;
ll ans=0;
if(b==0){
ans=cnt(0)+cnt(3);
}else if(b>0){
ans=cnt(1)+cnt(4);
if(c>=2*b) ans+=2*b;
else ans+=cnt(0)+cnt(3);;
}else{
b*=-1;
ans=cnt(0)+cnt(3);
if(c>=2*b+1) ans+=2*b;
else ans+=cnt(1)+cnt(4);
}
cout<<ans<<endl;
}
|
#include <bits/stdc++.h>
#define int long long int
using namespace std;
signed main(){
ios::sync_with_stdio(0);
cin.tie(NULL); cout.tie(NULL);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
map<int , int> mp;
bool ae = true;
for(int i = 1;i<= n;i++){
int z;
cin>>z;
mp[z]++;
}
map<int , int>:: iterator it;
for(it = mp.begin() ; it!= mp.end();it++){
if((it->second)%2==0 ){
;
}
else{
ae = false;
}
}
if(n%2==0){
if(ae){
cout<<"Second\n";
}
else{
cout<<"First\n";
}
}
else{
cout<<"Second\n";
}
}
}
| #include <bits/stdc++.h>
#define vi vector<int>
#define tests int t; cin>>t; while(t--)
#define ll long long
#define vll vector<long long>
#define srt(v) sort(v.begin(), v.end())
#define srtg(v) sort(v.begin(), v.end(), greater<int> ())
#define FOR(k, n) for(int k=0; k<n; k++)
#define pb push_back
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using namespace std;
char nums[10] = { '0','1','2','3','4','5','6','7','8','9' };
char alphsl[26] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
const int MOD = 1000000007;
char alphs[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
void solve() {
vi v(4);
cin>>v[0]>>v[1]>>v[2]>>v[3];
int sum=v[0]+v[1]+v[2]+v[3];
if(sum%2==1) {
cout<<"No"<<endl;
return;
}
if(v[0]==sum/2||v[1]==sum/2||v[2]==sum/2||v[3]==sum/2||v[0]+v[1]==sum/2||v[0]+v[2]==sum/2||v[0]+v[3]==sum/2||v[1]+v[2]==sum/2||v[1]+v[3]==sum/2||v[2]+v[3]==sum/2){
cout<<"Yes"<<endl;
}
else cout<<"No"<<endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
} |
/*
problem :
algorithm :
created : Programmer_juruo
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define N 2000005
#define M 2005
#define lowbit(x) x & (-x)
#define F1(i, n) for(int i = 1; i <= n; i++)
#define F(i, a, n) for(int i = a; i <= n; i++)
#define F0(i, n) for(int i = 0; i < n; i++)
#define dbg(x) cout << #x << ":" << x << endl;
#define se second
#define fi first
#define y1 juruo
#define mp make_pair
#define pb push_back
#define arr vector<int>
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
typedef pair <int, int> pii;
typedef priority_queue <int> pq;
typedef long long ll;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int p = 107;
const int P = 100007;
const int Mod = 1e9+7;
int n, m;
int t[N], l[N], r[N];
vector <pair<int, pair<int, int> > > v;
void work() {
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> t[i] >> l[i] >> r[i];
}
int ans = 0;
for(int i = 1; i <= n; i++) {
for(int j = i+1; j <= n; j++) {
v.clear();
v.pb(mp(l[i], pii(r[i], t[i])));
v.pb(mp(l[j], pii(r[j], t[j])));
sort(v.begin(), v.end());
if(v[0].se.fi > v[1].fi) {
++ans;
} else if(v[0].se.fi == v[1].fi) {
if(v[0].se.se == 1 || v[0].se.se == 3) {
if(v[1].se.se == 1 || v[1].se.se == 2) {
++ans;
}
}
}
}
}
cout << ans << endl;
}
signed main() {
//freopen("1.in", "r", stdin);
//freopen("1.out", "w", stdout);
int T = 1;
//cin >> T;
while(T--) {
work();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define fo(a,b,c) for(int a=b;a<c;a++)
#define int long long int
#define ff first
#define ss second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;
const int cmod = 998244353;
const int N = 3e5 + 5;
const int inf = 1e18 + 2;
int power(int a,int b)
{
if(b==0)
return 1;
else if(b%2==0)
{
int c=power(a,b/2);
return (c*c)%mod;
}
else
return ((a%mod)*(power(a,b-1)%mod))%mod;
}
void solve(int Case)
{
int n,s=0;
cin>>n;
int a[n][3];
fo(i,0,n)
{
fo(j,0,3)
{
cin>>a[i][j];
}
}
fo(i,0,n)
{
fo(j,i+1,n)
{
if(a[i][2]>a[j][2])
{
if(a[i][1]<a[j][2])
s++;
else if(a[i][1]==a[j][2])
{
if((a[i][0]==1||a[i][0]==2)&&(a[j][0]==3||a[j][0]==1))
s++;
}
}
else if(a[i][2]<a[j][2])
{
swap(i,j);
if(a[i][1]<a[j][2])
s++;
else if(a[i][1]==a[j][2])
{
if((a[i][0]==1||a[i][0]==2)&&(a[j][0]==3||a[j][0]==1))
s++;
}
swap(i,j);
}
else
s++;
}
}
cout<<s;
}
int32_t main()
{
fastio
int testcase = 1;
//cin >> testcase;
int Case = 1;
while(testcase --)
{
solve(Case);
}
return 0;
} |
#include <iostream>
using namespace std;
int main() {
char a, b, c;
cin>>a>>b>>c;
if (a == b && b==c){
cout<<"Won";
}
else{
cout<<"Lost";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
string S;
cin >> S;
int ans = 0;
for (int i = 0; i < S.size(); i++){
if (S.substr(i, 4) == "ZONe")
ans++;
}
cout << ans << endl;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.