code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
int n,m,a[200050],dp[200050],ans=-2e9;
vector<int> e[200050];
bool vis[200050];
void dfs(int x) {
if (vis[x]) return;
vis[x]=1;
for (int i:e[x]) {
dfs(i); dp[x]=max(dp[x],dp[i]);
}
ans=max(ans,dp[x]-a[x]);
dp[x]=max(dp[x],a[x]);
}
int main() {
cin>>n>>m;
for (int i=1; i<=n; ++i)
scanf("%d",a+i),dp[i]=-1e9;
while (m--) {
int x,y; scanf("%d%d",&x,&y);
e[x].push_back(y);
}
for (int i=1; i<=n; ++i)
if (!vis[i]) dfs(i);
cout<<ans;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
map<int, int> rev;
const int N = 102;
const int M = 102102;
vi vis(N), ans(M), ok(M);
vii ed(M);
void dfs(vector<vii> &gr, int u, int p) {
vis[u] = 1;
for (auto [v, e]: gr[u]) if (p != v) {
if (vis[v]) {
ok[rev[e]] = 1;
ans[rev[e]] = ed[rev[e]].fst == v;
}
else {
ans[rev[e]] = ed[rev[e]].snd == v;
ok[rev[e]] = 1;
dfs(gr, v, u);
}
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n, m;
cin >> n >> m;
vi c(n+1), done(m), vis(n+1);
vector<vii> g(n+1);
rep(i,0,m) {
cin >> ed[i].first >> ed[i].second;
g[ed[i].fst].eb(ed[i].snd, i);
g[ed[i].snd].eb(ed[i].fst, i);
}
rep(i,1,n+1) cin >> c[i];
rep(i,1,n+1) {
if (vis[i]) continue;
queue<int> q;
q.push(i);
vis[i] = 1;
vi comp;
while (!q.empty()) {
int u = q.front(); q.pop();
comp.pb(u);
for (auto [v, j]: g[u]) if (!vis[v] && c[v] == c[u]) {
vis[v] = 1;
q.push(v);
}
}
vector<vii> gr(n+1);
int nedges = 0;
for (auto u: comp) {
for (auto [v, j]: g[u]) {
if (c[u] == c[v] && !done[j]) {
rev[nedges] = j;
gr[u].eb(v, nedges);
gr[v].eb(u, nedges);
++nedges;
done[j] = 1;
}
}
}
dfs(gr, i, i);
}
rep(i,0,m) {
if (!ok[i]) {
assert(c[ed[i].fst] != c[ed[i].snd]);
ans[i] = c[ed[i].fst] > c[ed[i].snd];
}
if (ans[i]) cout << "->";
else cout << "<-";
cout << '\n';
}
} |
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>
ostream &operator<<(ostream &os, const vector<T> &x){
os << "{";
for(size_t i = 0; i < x.size(); i++){
if(i < x.size()-1) os << x[i] << ", ";
else os << x[i];
}
os << "}";
return os;
}
int main(void){
int b;
rep(k, 1000){
int sx, sy, tx, ty;
cin >> sx >> sy >> tx >> ty;
int dx = tx-sx;
int dy = ty-sy;
char u, v;
u = 'D', v = 'R';
if(dx < 0) u = 'U', dx = -dx;
if(dy < 0) v = 'L', dy = -dy;
rep(i, dx) cout << u;
rep(i, dy) cout << v;
cout << endl;
cout << flush;
cin >> b;
}
return 0;
}
| #include <algorithm>
#include <chrono>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
//------------------------------------------------------------------------------
class Timer {
public:
explicit Timer()
: mStart(chrono::system_clock::now())
{}
void start() { mStart = chrono::system_clock::now(); }
double msec() const {
auto t = chrono::system_clock::now();
return 1e-3 * chrono::duration_cast<std::chrono::microseconds>(t - mStart).count();
}
private:
chrono::system_clock::time_point mStart;
};
//------------------------------------------------------------------------------
class XorShift {
public:
using result_type = uint32_t;
explicit XorShift(result_type seed){ init(seed); }
void init(result_type s){
x = 1812433253U * (s ^ (s >> 30));
y = 1812433253U * (x ^ (x >> 30)) + 1;
z = 1812433253U * (y ^ (y >> 30)) + 2;
w = 1812433253U * (z ^ (z >> 30)) + 3;
}
static constexpr result_type min() { return numeric_limits<result_type>::min(); }
static constexpr result_type max() { return numeric_limits<result_type>::max(); }
result_type operator() () {
result_type t = x ^ (x << 11);
x = y; y = z; z = w;
return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}
private:
result_type x;
result_type y;
result_type z;
result_type w;
};
void randomPlay(){
for(int _=0;_<1000;_++){
int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
string s;
if(x1 < x2) s.append(string(x2-x1, 'D'));
if(x1 > x2) s.append(string(x1-x2, 'U'));
if(y1 < y2) s.append(string(y2-y1, 'R'));
if(y1 > y2) s.append(string(y1-y2, 'L'));
cout << s << endl;
int score; cin >> score;
}
}
int main(){
randomPlay();
} |
#include <iostream>
using namespace std;
int main() {
int x;
cin >> x;
cout << (100 - (x%100)) << "\n";
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, revnum, t, pali;
cin >> N;
revnum = 0;
if (N == 0) {
cout << "Yes" << endl;
return 0;
}
while (N % 10 == 0) {
N = N / 10;
}
pali = N;
while (N != 0) {
t = N % 10;
revnum = revnum * 10 + t;
N = N / 10;
}
if (pali == revnum) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
}
|
#include<bits/stdc++.h>
using namespace std;
#define debug printf("%d %s\n",__LINE__,__FUNCTION__)
using ll=long long;using ld=double;using pii=pair<int,int>;using vi=vector<int>;
using qi=queue<int>;using pqi=priority_queue<int>;using si=set<int>;
#define pb push_back
#define mk make_pair
#define ins insert
#define era erase
#define fi first
#define se second
#define lowbit(x) x&-x
const int INF=0x3f3f3f3f;
const ll INFLL=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
int _w,_t;FILE* _f;
const int N=3e5+5;
int n,q,a[N],sum[N];
void add(int u,int d){
while(u<=n){
sum[u]^=d;
u+=lowbit(u);
}
}
int qsum(int u){
int tmp=0;
while(u>0){
tmp^=sum[u];
u-=lowbit(u);
}
return tmp;
}
void solve(){
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
add(i,a[i]);
}
int t,x,y;
while(q--){
scanf("%d%d%d",&t,&x,&y);
if(t^2){
add(x,y);
}
else{
printf("%d\n",qsum(y)^qsum(x-1));
}
}
}
int main(){
#ifdef MULTI_CASES
_w=scanf("%d",&_t);while(_t--)
#endif
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
//#pragma target("sse,sse2,sse3,ssse3,sse,popcnt,abm,mmx,avx,avx2,fma,tune=native")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
template <typename T>
istream& operator >> (istream& in, vector<T>& a) {
for (auto& i : a)
in >> i;
return in;
}
template <typename T>
ostream& operator << (ostream& out, const vector<T>& a) {
for (auto& i : a) {
out << i << " ";
}
return out;
}
template <typename T, typename D>
istream& operator >> (istream& in, pair<T, D>& a) {
in >> a.first >> a.second;
return in;
}
template <typename T, typename D>
ostream& operator << (ostream& out, const pair<T, D>& a) {
out << a.first << " " << a.second;
return out;
}
struct LogOutput{
template<typename T>
LogOutput& operator<<(T x) {
#ifdef DIVAN
cout << x;
#endif
return *this;
}
};
LogOutput fout;
typedef long long ll;
typedef unsigned long long ull;
typedef double dl;
#define nl '\n'
#define elif else if
#define all(_v) _v.begin(), _v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define sqr(_v) ((_v) * (_v))
#define vpi vector<pair<int, int>>
#define eb emplace_back
#define pb push_back
#define mod(x, m) ((x) >= 0 ? ((x) % m) : (((x) % m) + m))
#define vi vector<int>
#define pi pair<int, int>
#define ti tuple<int, int, int>
#define minq(x, y) x = min((x), (y))
#define maxq(x, y) x = max((x), (y))
#define forn(i, n) for (int i = 0; i < (n); ++i)
const ll INFL = 9187201950435737471;
const ll nINFL = -9187201950435737472;
const int INF = 2139062143;
const int nINF = -2139062144;
const ull ULINF = numeric_limits<ull>::max();
const long double Pi = acos(-1);
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rnd(seed);
inline void IO() {
#ifdef DIVAN
freopen("../input.txt", "r", stdin);
freopen("../output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
}
const int MAXN = 1e5 + 15;
vpi adj[MAXN];
int col[MAXN];
bool used[MAXN];
void DFS(int v) {
used[v] = 1;
for (auto [to, c] : adj[v]) {
if (used[to]) {continue;}
if (col[v] == c) {
if (c == 1) {
col[to] = 2;
} else {
col[to] = 1;
}
} else {
col[to] = c;
}
DFS(to);
}
}
void Solve() {
int n, m;
cin >> n >> m;
while (m--) {
int a, b, c;
cin >> a >> b >> c;
adj[a].eb(b, c);
adj[b].eb(a, c);
}
col[1] = 1;
DFS(1);
for (int i = 1; i <= n; ++i) {
cout << col[i] << '\n';
}
}
signed main() {
IO();
int t = 1;
// cin >> t;
int startTime = clock();
while (t--) {
Solve();
}
int endTime = clock();
#ifdef DIVAN
cout << '\n' << "Time: " << (endTime - startTime + 999) / 1000;
#endif
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N, count = 0;
char a = '!';
cin >> N;
vector<string> s(N);
set<string> z;
for (int i = 0; i < N; i++)
{
cin >> s.at(i);
z.insert(s.at(i));
}
for (auto value : z)
{
if (z.count(value) && z.count(a+value))
{
cout << value << endl;
return 0;
}
}
cout << "satisfiable" << endl;
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;
using P = pair<int,int>;
int main(){
string S;
cin >> S;
int s_siz = S.size();
vector<int> num(10);
rep(i,s_siz){
int n = S[i] - '0';
num[n]++;
}
for(int i=8; i<1000; i+=8){
string t = to_string(i);
int t_siz = t.size();
rep(j,min(s_siz,3)-t_siz) t = '0' + t;
map<char,int> mp;
rep(j,t_siz) mp[t[j]]++;
bool flag = true;
for(auto itr : mp){
int n = itr.first - '0';
if(itr.second > num[n]){
flag = false;
break;
}
}
if(flag){
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
} |
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<ll ,ll>
#define INT_MAX 2147483647
#define MOD 1000000007
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
int main() {
int n, k; cin >> n >> k;
int nsum = 100 * n * (n + 1) / 2;
int ksum = k * (k + 1) / 2;
cout << nsum * k + ksum * n<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pob pop_back
#define S second
#define F first
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vll vector<long long int>
#define pll pair<long long int,long long int>
#define mod 1000000007
#define mod2 998244353
#define ll long long int
#define ld long double
#define pi 3.141592653589793238
#define Endl endl
#define endl "\n"
const int N = 2e5 + 15;
const ll inf = 1e18;
void solve()
{
ll a , b;
cin >> a >> b;
ll ans = 0;
for(ll i=1;i<=a;i++)
{
for(ll j=1;j<=b;j++)
ans += (i*100 + j);
}
cout << ans;
}
void debug(ll tt) {}
signed main()
{
FAST;
int t = 1;
// cin >> t;
while(t--)
{
solve();
}
} |
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pll pair<ll,ll>
#define ppl pair<pll,ll>
#define plp pair<ll,pll>
#define pi 3.14159265358979323846264338327950
const ll MOD=1e9 + 7;
const ll N=4e5 + 7;
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// use rng for random number generation
ll POWER(ll base,ll expo)
{
ll ret=1;
while(expo)
{
if(expo&1)ret=ret*base%MOD;
expo>>=1;
base=base*base%MOD;
}
return ret%MOD;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll tt = 1; //cin>>tt;
while(tt--)
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ll n; cin>>n;
ll ans = n*(n - 1)/2;
map<ll,ll> mp;
for(ll i=0;i<n;i++){
ll x; cin>>x;
mp[x]++;
}
for(auto i : mp){
ll x = i.se;
ll rem = x*(x - 1)/2;
ans -= rem;
}
cout<<ans;
}
return 0;
}
| /*** In the name of Allah(swt), the most gracious, most merciful.***/
/*** Alhamdulillah for Everything ***/
#include<bits/stdc++.h>
using namespace std;
typedef bool boo;
typedef int li;
typedef long il;
typedef unsigned long ul;
typedef long long int ll;
typedef unsigned long long ull;
typedef double dd;
typedef string str;
#define vli vector < li >
#define vll vector < ll >
#define sli set < li >
#define sll set < ll >
#define pli pair < li , li >
#define pll pair < ll , ll >
#define vpi vector < pair < li , li > >
#define vpl vector < pair < ll , ll > >
#define mpl map < ll , ll >
#define Test ll t; std :: cin >> t; while(t--)
#define input(a , n) for( int i = 0 ; i < n ; i++ ) std :: cin >> a[i];
#define lp(a , i , b) for( ll i = a ; i < b ; i++ )
#define rlp(a , i , b) for( ll i = a; i >= b ; i-- )
#define sz(x) x.size()
#define len(z) z.begin() , z.end()
#define ci(x) std :: cin >> x;
#define co(x) std :: cout << x nl;
#define fix(x) fixed << setprecision(x)
#define mem(z , l) memset( z , l , sizeof(z) )
#define MP make_pair
#define pb push_back
#define F first
#define S second
#define nl << endl;
#define nll std :: cout << endl;
#define cy std :: cout << "YES" << endl;
#define cn std :: cout << "NO" << endl;
#define rn return;
#define Good_Bye return 0;
#define gcd(a , b) __gcd( a , b )
#define lcm(a , b) ( a * ( b / gcd( a , b ) ) )
#define Faster ios_base :: sync_with_stdio( 0 ); cin.tie( 0 ); cout.tie( 0 );
int dx[] = { -1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
int dx1[] = { -1, -1, -1, 0, 0, 0, 1, 1, 1};
int dy1[] = { -1, 0, 1, -1, 0, 1, -1, 0, 1};
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
const ll MOD = 1e+7;
const double PI = 3.141592653589793238462643383279;
///_____________________________________________ L E T ' S B E G I N ____________________________________________________________
int main()
{
Faster
ll x, n, sum(0);
cin >> n;
int ar[n + 2]; //,br[n+2];
map<ll, ll>mp;
lp(0, i, n)
{
cin >> ar[i];
++mp[ar[i]];
}
lp(0, i, n)
{
--mp[ar[i]];
sum += n - i - 1 - mp[ar[i]];
}
cout << sum nl
Good_Bye
}
// author : Md. Nahid Chowdhury(IIUC_CSE48th Batch)
///||||||||||||||||||||||||||||||||||||||||||||||| E N D |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define M 1000000000
#define MAX 20000000000
#define set_zero(a) memset(a,0,sizeof(a))
#define N 100005
using namespace std;
void solve(ll tc){
string s; cin>>s;
ll n = s.length();
bool ok = false;
ll j = -1;
for(ll i = 0;i<n;i++){
if(s[i] == '.'){
ok = true;
j = i;
break;
}
}
if(ok){
for(ll i = 0;i<j;i++) cout<<s[i];
cout<<endl;
}
else cout<<s<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
ll t = 1 ;// cin>>t;
ll tc = 0;
while(t--){
tc++;
solve(tc);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define COUT(x) cout << (x) << endl
#define PB push_back
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define MOD 1000000007
const vector<int> DX = {1, -1, 0, 0};
const vector<int> DY = {0, 0, 1, -1};
template<typename T>
void pv(const vector<T> &vec) {
for (auto x : vec) {
cout << x << ' ';
}
cout << '\n';
}
/*
--------------------------------------------------------
*/
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
if (n % 2) {
cout << "Black" << endl;
} else {
cout << "White" << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------
void solve() {
int i,j,k,l,r,x,y; string s;
FOR(y,20) {
FOR(x,20) cout<<(char)('A'+rand()%8);
cout<<endl;
}
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
| //wtrl,everybody hangbeat me
#include<bits/stdc++.h>
/*#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>*/
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<ll,ll> pll;
/*=====================================================================*/
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define sz(a) (int)(a.size())
#define all(s) (s).begin(),(s).end()
#define m_p make_pair
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<=n;i++)
#define ford(i,p,n) for(int i=n;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define INF 1e9
#define PI acos(-1)
/*=====================================================================*/
string int_to_string(ll n)
{
string s="";
while(n)
{
ll now=n%10;
s+=now+'0';
n/=10;
}
reverse(s.begin(),s.end());
return s;
}
ll string_to_int(string s)
{
ll n=0;
rep(i,s.size())
{
n*=10;
n+=s[i]-'0';
}
return n;
}
/*======================================================================*/
ll lcm(int a,int b)
{
return a/__gcd(a,b)*b;
}
bool prime(int n)
{
if(n==0||n==1)
return false;
for(int i=2;i*i<=n;i++)
if(n%i==0)
return false;
return true;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
vi v[100010];
pii dfs(int now)
{
int ok=1,pos=0,neg=0;
vi to;
rep(i,v[now].size())
{
pii nxt=dfs(v[now][i]);
if(nxt.second)
{
ok=1-ok;
to.pb(nxt.first);
}
else
{
if(nxt.first>0)
{
pos+=nxt.first;
}
else
{
neg+=nxt.first;
}
}
}
sort(all(to));
int ans=1;
ans+=neg;
rep(i,to.size())
{
if(i%2)
{
ans-=to[i];
}
else
{
ans+=to[i];
}
}
if(to.size()%2)
{
ans-=pos;
}
else
{
ans+=pos;
}
return pii(ans,ok);
}
/*======================================================================*/
int main()
{
std::ios::sync_with_stdio(false);
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/
/*====================================================================*/
int n;
cin>>n;
rep(i,n-1)
{
int p;
cin>>p;
p--;
v[p].pb(i+1);
}
cout<<(dfs(0).first+n)/2<<endl;
return 0;
}
|
#include<bits/stdc++.h>
using ll = int_fast64_t;
#define REP(i,b,e) for(ll i=b; i<e; i++)
int main(){
ll n, k;
scanf("%ld %ld", &n, &k);
ll ans = 0;
REP(ab, 2, 3*n){
ll cd = ab-k;
if(cd<2) continue;
ll l1 = std::max(0l, ab-n), r1 = std::min(ab, 0+n);
ll l2 = std::max(0l, cd-n), r2 = std::min(cd, 0+n);
ans += std::max(0l, std::min(ab-1, r1-l1+1)) * std::max(0l, std::min(cd-1, r2-l2+1));
}
printf("%ld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fi(i,n) for(int i=0;i<n;i++)
#define f(i, a, b) for(int i=a;i<b;i++)
#define vi vector<int>
#define pb push_back
#define MOD 998244353
#define pii pair<int, int>
#define ff first
#define ss second
#define setzero(a) memset(a,0,sizeof(a))
ll digits(ll n)
{
return floor(log10(double(n))) + 1;
}
void faster()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
ll modularExponentiation(ll x,ll n,ll M)
{
ll result = 1;
while(n>0)
{
if(n % 2 ==1)
{
result = ((result%M)*(x%M))%M;
}
x = ((x%M)*(x%M))%M;
n = n/2;
}
return result%M;
}
ll d, x, y;
void extendedEuclid(ll A, ll B)
{
if(B == 0)
{
d = A;
x = 1;
y = 0;
}
else
{
extendedEuclid(B, A%B);
int temp = x;
x = y;
y = temp - (A/B)*y;
}
}
// DP solution for nCr
ll nCrModp(ll n, ll r)
{
if (r > n - r)
r = n - r;
ll C[r + 1];
memset(C, 0, sizeof(C));
C[0] = 1;
for (ll i = 1; i <= n; i++)
{
for (ll j = min(i,r); j > 0; j--)
{
C[j] = (C[j] + C[j - 1]);
}
}
return C[r];
}
ll modInverse(ll A, ll M)
{
extendedEuclid(A,M);
return (x%M+M)%M; //x may be negative
}
// primefactors[a] = primefactors[a/primedivisor[a]] + 1
ll sumdigits(ll n)
{
ll ans = 0;
while(n>0)
{
ans += n%10;
n = n/10;
}
return ans;
}
ll less_power2(ll n)
{
ll i = 1;
while(i*2<=n)
{
i = i*2;
}
return i;
}
bool isPrime(int n)
{
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
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;
}
int main()
{
ll n,k;
cin>>n>>k;
ll arr[2*n + 1];
arr[0] = 0;
arr[1] = 0;
ll i = 1;
for(ll j = 2;j<(2 + n);j++)
{
arr[j] = i;
i++;
}
i = n - 1;
for(ll j = n + 2;j<=2*n;j++)
{
arr[j] = i;
i--;
}
ll ans = 0;
for(ll i = 2;i<=2*n;i++)
{
ll sol1 = k + i;
ll freq1 = arr[i];
if(sol1<= 2*n && sol1>=2)
{
ll freq2 = arr[sol1];
ans += freq1*freq2;
}
}
cout<<ans;
}
|
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 100 + 5;
int mod, k, dp[N][N], a[N];
string s;
int add(int a, int b){
return (a + b) % mod;
}
int mul(int a, int b){
return 1ll * a * b % mod;
}
int fp(int b, int p){
if(p == 0) return 1;
int ret = fp(b, p >> 1);
ret = mul(ret, ret);
if(p & 1) ret = mul(ret, b);
return ret;
}
int beats(int a, int b){
if(a == b) return a;
if((a + 1) % 3 == b) return b;
return a;
}
int solve(int idx, int k){
if(k == 0) return a[idx];
if(dp[idx][k] != -1) return dp[idx][k];
int l = solve(idx, k - 1);
int r = solve(add(idx, fp(2, k - 1)), k - 1);
return dp[idx][k] = beats(l, r);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> mod >> k >> s;
for(int i = 0; i < mod; i++){
if(s[i] == 'P') a[i] = 1;
else if(s[i] == 'S') a[i] = 2;
}
memset(dp, -1, sizeof dp);
int ans = solve(0, k);
if(ans == 0) cout << 'R';
else if(ans == 1) cout << 'P';
else cout << 'S';
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007ll
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
using namespace std;
#define pi (long double)3.14159265358979323846
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
struct sch{
ll s,e,t;
};
bool sortinrev(const struct sch &a, const struct sch &b)
{
return (a.s < b.s);
}
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a,ll b)
{
return a*b/gcd(a,b);
}
ll power(ll x, ll y, ll p)
{
ll res = 1;
x = x % p;
while (y > 0)
{
if (y & 1)
res = (res*x) % p;
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
int main()
{
ll n,k;
cin>>n>>k;
string s;
cin>>s;
while(k--)
{
s = s+s;
string tmp = "";
for(int i=0;i<s.size();i+=2)
{
if((s[i]=='R' && s[i+1]=='P') || (s[i]=='P' && s[i+1]=='R'))
{
tmp += 'P';
}
else if((s[i]=='R' && s[i+1]=='S') || (s[i]=='S' && s[i+1]=='R'))
{
tmp += 'R';
}
else if((s[i]=='S' && s[i+1]=='P') || (s[i]=='P' && s[i+1]=='S'))
{
tmp += 'S';
}
else
{
tmp += s[i];
}
}
s = tmp;
}
cout<<s[0]<<endl;
} |
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <chrono>
#include <random>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
// typedef pair<int,int> P;
// typedef pair<int,P> IP;
// typedef pair<P,P> PP;
double const PI=3.141592653589793;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;
int I[]={1,0,-1,0};
int J[]={0,1,0,-1};
int N=50;
int si, sj;
int t[50][50];
int p[50][50];
int main(){
cin>>si>>sj;
rep(i,N) rep(j,N) cin>>t[i][j];
rep(i,N) rep(j,N) cin>>p[i][j];
string ans;
vector<int> chk(N*N,1);
int x=si, y=sj;
while(true){
chk[t[x][y]]=0;
int maxi=-1;
int id=-1;
rep(k,4){
int i=x+I[k];
int j=y+J[k];
if(0<=i && i<N && 0<=j && j<N && chk[t[i][j]] && maxi<p[i][j]){
// cout<<p[i][j]<<endl;
maxi=p[i][j];
id=k;
}
}
if(id==-1) break;
// cout<<id<<endl;
x+=I[id];
y+=J[id];
if(id==0) ans+='D';
else if(id==1) ans+='R';
else if(id==2) ans+='U';
else if(id==3) ans+='L';
}
cout<<ans<<endl;
return 0;
} | // ____ ____
// /@@@@\ |@@@@| ____
// /@@@@@@\ |@@@@| |@@@@|
// /@@@@@@@@\ |@@@@| __|@@@@|___ ____ ____ ___ _________ ____ ____ ____________ ___ _________ ____ ____
// /@@@@/\@@@@\ |@@@@| @@@@@@@@@@@ |@@@@| |@@@@| |@@@\/@@@@@@@@@\ (@@@@\ /@@@@) /@@@@@@@@@@@@| |@@@\/@@@@@@@@@\ (@@@@\ /@@@@)
// /@@@@/ \@@@@\ |@@@@| |@@@@| |@@@@| |@@@@| |@@@@| \@@@@@| \@@@@\ /@@@@/ |@@/ |@@@@| |@@@@| \@@@@@| \@@@@\ /@@@@/
// /@@@@(____)@@@@\ |@@@@| |@@@@| |@@@@| |@@@@| |@@@@| |@@@@| \@@@@\ /@@@@/ |@@@@| |@@@@| |@@@@| \@@@@\ /@@@@/
// /@@@@@@@@@@@@@@@@\ |@@@@| |@@@@| |@@@@| |@@@@| |@@@@| |@@@@| \@@@@\/@@@@/ /@@@@@@@@@@@@@| |@@@@| |@@@@| \@@@@\ /@@@@/
// /@@@@@@@@@@@@@@@@@@\ |@@@@| |@@@@|___ |@@@@|____/@@@@@| |@@@@| |@@@@| \@@@@@@@@/ (@@@@( )@@@@@| |@@@@| |@@@@| \@@@@|@@@@/
// /@@@@/ \@@@@\ |@@@@| |@@@@@@@@ \@@@@@@@@@@@@@@| |@@@@| |@@@@| \@@@@@@/ \@@@@\_/@@@@@@| |@@@@| |@@@@| \@@@@@@@/
// /@@@@/ \@@@@\ |@@@@| \@@@@@@/ \@@@@@/ \@@@| |@@@@| |@@@@| )@@@@/ \@@@@@@@/\@@@| |@@@@| |@@@@| \@@@@@/
// (@@@@/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
//-----------------------------------------------
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define sq(x) (x) * (x)
#define fr first
#define sc second
//-----------------------------------------------
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pli = pair<ll, int>;
const int N = 1000 * 1000 + 5;
const ll mod = 1000000007;
const ll mod3 = 998244353;
const ll INFL = 1000000000 * 1ll * 1000000000 + 500000;
const ll INF = 1000000000;
const ld pi = acosl(-1.0);
vector<int> a, b;
set<int> sa, sb, overall;
int n, m;
void input() {
cin >> n >> m;
a.resize(n);
b.resize(m);
for (int i = 0; i < n; i++) {
cin >> a[i];
overall.insert(a[i]);
}
for (int i = 0; i < m; i++) {
cin >> b[i];
overall.insert(b[i]);
}
sa = set<int>(a.begin(), a.end());
sb = set<int>(b.begin(), b.end());
}
void solve(int testId) {
for (int element : overall) {
if ((sa.find(element) == sa.end()) ^ (sb.find(element) == sb.end())) {
cout << element << " ";
}
}
cout << endl;
}
int main() {
// freopen("test", "r", stdin);
int testcases = 1;
// scanf("%d", &testcases);
for(int testId = 1; testId <= testcases; testId++) {
input();
solve(testId);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<pair<int, string> > t(n);
for (int i = 0; i < n; i++)
{
cin >> t.at(i).second >> t.at(i).first;
}
sort(t.begin(), t.end());
cout << t.at(n - 2).second << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
using ll=long long;
using P=pair<int, int>;
int main(){
int n;
cin>>n;
vector<P> pv(n);
vector<string> sv(n);
rep(i, n){
pv[i].second=i;
cin>>sv[i]>>pv[i].first;
}
//cout<<pv[1].second<<endl;
sort(pv.begin(), pv.end());
cout<<sv[pv[n-2].second]<<endl;
return 0;
} |
#include <bits/stdc++.h>
#include <algorithm>
#include <unordered_map>
#define ull unsigned long long
#define int long long
#define ll long long
#define fr(i, n) for (int i = 0; i < n; i++)
#define frf(i, j, n) for (int i = j; i <= n; i++)
#define frd(i, n) for (int i = n; i >= 0; i--)
#define mp(i, j) make_pair(i, j)
#define pb(x) push_back(x)
#define INF 1e18
#define int64_t 64
using namespace std;
typedef pair<int, int> pi;
const int MAX = 1e6 + 1;
// typedef vector<vector<ll>> matrix;
const ll PRIME = 1e9 + 7;
// typedef pair<int, pair<int, int>> ppi;
// const ll MAX = 1e6 + 1;
int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
const int mod = 998244353;
int mul (int a,int b)
{
return ( ((a%mod) * (b%mod )) % mod);
}
int add(int a,int b)
{
return ((a % mod ) + (b % mod) % mod) ;
}
void solve()
{
int n;
cin>>n;
int a,b;
int sum=0;
fr(i,n)
{
cin>>a>>b;
a--;
int temp1= (b*(b+1))/2;
int temp2= (a*(a+1))/2;
sum+=(temp1-temp2);
}
cout<<sum;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
t = 1;
// cin >> t;
// int k=1;
while (t--)
{
// cout << "Case " << k++ << ":\n";
solve();
}
} | #include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
ll t, n;
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> t >> n;
ll x = (n * 100) / t;
if ((n * 100) % t) ++x;
cout << x + n - 1;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a,b;
cin>>a>>b;
for(int x=-100;x<=100;x++){
for(int y=-100;y<=100;y++){
if(x+y==a and x-y==b){
cout<<x<<" "<<y<<endl;
break;
}
}
}
} | #include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<(a+b)/2<<" "<<(a-b)/2<<"\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<P,int>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = 998244353;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-9;
vector<vector<int> > g;
void chmin(int &a, int b){
a = min(a,b);
}
ll N, K;
ll dp[3005][3005]; // i:unit, j:cnt, k:2^k
ll rec(ll i, ll j){
if(i==0 && j==0) return 1;
if(i==0 || j==0) return 0;
if(dp[i][j] != -1) return dp[i][j];
ll res = 0;
if(i>=1 && j>=1) res += rec(i-1,j-1);
if(i*2 <= j) res += rec(i*2, j);
res %= MOD;
return dp[i][j] = res;
}
int main(){
for(int i=0;i<=3000;i++){
for(int j=0;j<=3000;j++){
dp[i][j] = -1;
}
}
cin >> N >> K;
cout << rec(K, N) << endl;
return 0;
} | //_base::sync_with_stdio(false);
// cin.tie(nullptr);
// cout.tie(nullptr);
#include <valarray>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#include <stdio.h>
#include <string.h>
#include <unordered_set>
#include <random>
#include <unordered_map>
#define mxN 1000000007
#define mat vector<vector<int>>
#define ll long long
#define pb push_back
#define all(a) a.begin(), a.end()
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int h, w, mod = 998244353;
cin >> h >> w;
vector<string> v;
for (int i = 0; i < h; ++i) {
string s;
cin >> s;
v.pb(s);
}
ll ans = 1;
for (int i = 0; i < w; ++i) {
bool ald = true;
int y = 0, x = i;
set <int> s;
while (x > -1 && y < h) {
if (v[y][x] != '.') {
ald = false;
s.insert(v[y][x]);
}
--x;
++y;
}
if (s.size() > 1) {
cout << 0 << endl;
return 0;
}
if (ald) {
ans *= 2;
}
ans %= mod;
}
for (int i = 1; i < h; ++i) {
bool ald = true;
int y = i, x = w - 1;
set <int> s;
while (x > -1 && y < h) {
if (v[y][x] != '.') {
ald = false;
s.insert(v[y][x]);
}
--x;
++y;
}
if (s.size() > 1) {
cout << 0 << endl;
return 0;
}
if (ald) {
ans *= 2;
}
ans %= mod;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
int i;
bool flag=false;
string s;
cin >> s;
for(i=0;i<s.length();i++)
{
if (i%2==0 && !(s[i]>='a' && s[i]<='z'))
{
flag=true;
break;
}
if (i%2!=0 && !(s[i]>='A' && s[i]<='Z'))
{
flag=true;
break;
}
}
if(flag) cout << "No" << endl;
else cout << "Yes" << endl;
return 0;
} | //ABHISHEK AGRAWAL,BIT mesra//
//Newbie......You have to be odd to be no. ONE :)//
//Authhor: Abhishekagrawal
//Date: 20/02/2021
//Time: 17:30:13
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fl float
#define vll vector<ll>
#define pii pair<int,int>
#define vpll vector<pair<ll,ll>>
#define pb push_back
#define f first
#define s second
#define mll map<ll,ll>
#define mp make_pair
#define sp(n) fixed<<setprecision(n)
#define mod (ll)1000000007
#define sortv(v) sort(v.begin(),v.end())
#define INF (ll)(1e15)
#define loop(i,n) for(int i=0;i<n;i++)
#define loop1(i,n) for(int i=1;i<=n;i++)
#define rloop(n,i) for(int i=n-1;i>=0;i--)
#define sorta(a) sort(a,a+n,greater<ll>())
#define countone(n) __builtin_popcount(n)
#define numoftrailzero(n) __builtin_ctz(n)
#define maxpowoftwo(n) __builtin_clz(n)
#define leastindexwithone(n) __builtin_ffs(n)
#define what_is(x) cerr << #x << " is " << x << endl;
#define pfv(v) cout<<v.size()<<"\n";loop(i,v.size()) cout<<v[i]<<" ";cout<<"\n";
#define pv(v) loop(i,v.size()) cout<<v[i]<<" ";
#define all(v) v.begin(),v.end()
#define mset(dp,val) memset(dp,val,sizeof(dp))
ll test,n;ll sum,ans;
// #ifdef TESTING
// #define DEBUG fprintf(stderr, "====TESTING====\n")
// #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
// #define debug(...) fprintf(stderr, __VA_ARGS__)
// #else
// #define DEBUG
// #define VALUE(x)
// #define debug(...)
// #endif
void the_happiest_place_on_earth()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#ifdef ENABLE_FILE_IO
freopen("out.txt", "r", stdin);
freopen("out1.txt", "w", stdout);
#endif
}
// bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b){
// if(a.s+2*a.f==b.s+2*b.f) return a.f>b.f;
// return (a.s+2*a.f>b.s+2*b.f);
// }
const int N=200040;ll a[N],b[N],c[N],par[N],Size[N],present[N],color[N];
void testcase(){
string s;
cin>>s;
n=s.length();
loop(i,n){
if(i&1){
if(s[i]>='a'){cout<<"No";return;}
}
else{
if(s[i]<='Z'){cout<<"No";return;}
}
}
cout<<"Yes";
return;
}
int main(){
the_happiest_place_on_earth();
// Today's thought: Push yourself,because no one else is going to do it for you.
// Things are not always #000000 and #FFFFFF
// START OF PROGRAM LOGIC
// g++ -o a BB.cpp -DENABLE_FILE_IO;./a
// g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o a file_name.cpp;./a
test=1;int t=0;
// cin>>test;
while(test--){
//cout<<"Case #"<<++t<<": ";
testcase();
}
cerr << "Time : " << 1000 *((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
// //END OF PROGRAM LOGIC
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/ |
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define pi 3.141592653589793
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define sz size()
#define cu cout<<
#define en endl
#define sp " "
#include<cstdio>
#include<cstring>
typedef unsigned long long UL;
template<typename T>inline T S(T a)
{
return a*a;
}
template<class T>inline string tostring(T a)
{
ostringstream os("");
os << a;
return os.str();
}
template<typename T>inline ll tolong(T a)
{
ll res;
istringstream os(a);
os>>res;
return res;
}
template<typename T>inline T gcd(T a, T b)
{
if (b == 0)return a;
else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
if (b == 0)return 1;
else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll modd = (ll)1e9 + 7;
const int mod = 10000007;
/*#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{
memset(prime, true, sizeof(prime));
for( ll i=2; i*i<=N; i++)
{
if (prime[i] == true)
{
prm.pb(i);
for (ll j=i*i; j<=N; j += i)
pe[j] = false;
}
}
}*/
void pr (int f)
{
if(f==1)cout<<"YES\n";
else cout<<"NO\n";
}
bool isprime(ll n)
{
if(n<2) return 0;
if(n==2) return 1;
else
{
for(int i=2; i*i<=n; i++)
if(n%i==0) return 0;
}
return 1;
}
ll countSum(ll x)
{
ll res = 0;
while (x != 0)
{
res += (x % 10);
x /= 10;
}
return res;
}
const int NN = 1e6+5;
int main()
{
fast ;
int n;
cin >> n;
string s[n];
map<string , int>mp;
for(int i=0;i<n;i++)
{
cin >> s[i];
mp[s[i]]++;
}
for (int i=0;i<n;i++)
{
string k ="!";
string x = k+s[i];
if(mp[x])
{
cout << s[i]<<endl;
return 0;
}
}
cout <<"satisfiable\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);
int n;
cin >> n;
unordered_set<string> st;
rep(i, n){
string s;
cin >> s;
st.insert(s);
}
for(auto e: st){
string other = '!' + e;
if(st.count(other)){
cout << e << endl;
return 0;
}
}
cout << "satisfiable" << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define endl '\n'
#define pb push_back
#define sz(c) (ll)c.size()
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define F first
#define S second
#define M 1000000007
#define PI 3.1415926535897932384
#define pii pair<ll,ll>
const ll INF=2e18;
const ll N=1e5;
ll mod=998244353;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vp;
typedef vector<vector<ll>> vvi;
//bool isPrime(ll n){
// if(n<=1)
// return false;
// if(n<=3)
// return true;
// if(n%2==0 || n%3==0)
// return false;
// for(ll i=5;i*i<=n;i=i+6)
// {
// if(n%i==0 || n%(i+2)==0)
// return false;
// }
// return true;
//}
//ll fact(ll n)
//{
// ll ans=1;
// for(ll i=1;i<=n;i++)
// ans=(ans*i)%M ;
// return ans;
//}
//
//
//
//
ll exp(ll x,ll n){
ll res=1;
while(n>0){
if(n%2==1)
res=(res*x)%M;
x=(x*x)%M;
n=n/2;
}
return res;
}
//
//
//ll nCr(ll n, ll k)
//{
// ll res = 1;
//
// // Since C(n, k) = C(n, n-k)
// if(k>n-k){
// k=n-k;
// }
//
// // Calculate value of
// // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
// for (ll i=0;i<k;i++) {
// res *= (n - i);
// res /= (i + 1);
// }
//
// return res;
//}
//vector<ll> fact(1005,0);
//void fac(){
// fact[0]=1;
// fact[1]=1;
// for(int i=2;i<1005;i++){
// fact[i] = (fact[i-1]*i)%M;
// }
//}
//ll ncr(ll n,ll r){
// ll num= fact[n];
// ll den= (fact[n-r]*fact[r])%M;
// den = exp(den,M-2);
// return (num*den)%M;
//
//}
//vector<vector<ll>> dp(1001,vector<ll>(503,1));
//void pre(){
// for(int i=0;i<=1000;i++){
// for(int j=0;j<=min(i,502);j++){
// if(j==0 or i==j){
// dp[i][j]=1;
// continue;
// }
// dp[i][j]= (dp[i-1][j]+ dp[i-1][j-1])%M;
// }
// }
//}
//string db(ll n)
//{
// // array to store binary number
// ll binaryNum[32];
//
// // counter for binary array
// ll i = 0;
// while (n > 0) {
//
// // storing remainder in binary array
// binaryNum[i] = n % 2;
// n = n / 2;
// i++;
// }
// string s="";
// // printing binary array in reverse order
// for (int j = i - 1; j >= 0; j--) {
// s+= (binaryNum[j]+'0');
// }
// return s;
//// cout << binaryNum[j];
//
//}
void null(){
ll n,s,d;
cin>>n>>s>>d;
bool res=false;
for(int i=0;i<n;i++){
ll x,y;
cin>>x>>y;
if(x<s and y>d){
res=true;
}
}
if(res)
cout<<"Yes";
else
cout<<"No";
cout<<endl;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
cout<<setprecision(9);
cout<<fixed;
ll t = 1;
clock_t start, end;
start = clock();
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// freopen("error.txt", "w", stderr);
// #endif
// cin>>t;
// compute();
while(t--){
null();
}
end = clock();
double time_taken = double(end - start) / double(CLOCKS_PER_SEC);
//cerr<<time_taken;
} | #include <iostream>
using namespace std;
int main(){
int T;
cin>>T;
while (T--){
int n;
cin>>n;
string s1;
string s2;
string s3;
cin>>s1>>s2>>s3;
string res;
for (int i=0;i<n;i++){
res+='1';
}
for (int i=0;i<n;i++){
res+='0';
}
res+='1';
cout << res<<'\n';
}
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n,ans=LONG_LONG_MAX;
cin>>n;
for(int b=0;(1LL<<b)<=n;b++)
ans=min(ans,b+(n>>b)+(n&((1LL<<b)-1)));
cout<<ans<<endl;
} | /* HAVE PATIENCE YOU CAN SOLVE EVERY QUESTION
JUST THINK*/
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
//#include <unordered_set>
//#include <unordered_map>
using namespace std;
int mod = 1000000007;
const double pi = 3.141592653689793238460;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 5;
const int pr = 31;
#define ll long long
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define MEM(x) memset(x,inf,sizeof(x))
#define fi first
#define se second
#define forn(i, n) for (int i = 0; i< n; i++)
#define forl(i,l,u) for(int i=(int)l;i<=(int)u;++i)
#define all(v) (v).begin(), (v).end()
#define sum(a) ( accumulate ((a).begin(), (a).end(), 0ll))
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
int f(int x, int y, string a[]) {
int l;
if (a[x][y] == '+')l = 1;
else l = -1;
return l;
}
int n;
long long dp[501][501];
vector<int > one(n);
vector<int> zero(n);
int main()
{
//#define int ll
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
ll n;
cin >> n;
ll ans = 1e18;
forl(i, 0, 61) {
ll b = (ll)pow(2, (ll)i);
ll c = n % b;
ll a = n / b;
ans = min(ans, (a + (ll)i + c));
}
cout << ans << endl;
}
|
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl "\n"
#define debug(arr) for(int x : arr) cout << x << " "; cout << endl;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int32_t main() {
fast;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int x, y;
cin >> x >> y;
if(x == y) {
cout << x << endl;
}else {
cout << 3 - (x + y) << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main()
{
int x,y, rock=0, scissors=1, paper=2;
cin>>x>>y;
if(x==y) cout<<x;
else{
if(x==rock&&y==scissors || x==scissors&&y==rock) cout<<paper;
else if(x==paper&&y==rock || x==rock&&y==paper) cout<<scissors;
else cout<<rock;
}
return 0;
} |
#include <set>
#include <map>
#include <stdio.h>
#include <stdlib.h>
#include <queue>
#include <string>
#include <vector>
#include <cmath>
#include <cstdio>
#include <utility>
#include <iostream>
#include <iterator>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int x; cin >> x;
x = x % 100;
cout << 100 - x << 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++)
#define LOCAL 1;
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif
template<typename T>
ostream& operator<< (ostream& out, const vector<T>& v) {
out << "[";
size_t last = v.size() - 1;
for (size_t i = 0; i < v.size(); ++i) {
out << v[i];
if (i != last)
out << ", ";
}
out << "]";
return out;
}
template<typename F, typename S>
ostream& operator<< (ostream& out, const pair<F,S>& p) {
out << "[" << p.first << ", " << p.second << "]";
return out;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll x; cin >> x;
cout << (100 - x%100) << endl;
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
void Main() {
int N, K;
cin >> N >> K;
map<int, int> m;
for (int i = 0; i < N; ++i) {
int a;
cin >> a;
m[a] += 1;
}
vector<int> numOfA;
for (int i = 0; i < N; ++i) {
if (m.count(i) == 0) {
break;
}
numOfA.push_back(m[i]);
}
for (int i = 1; i < numOfA.size(); ++i) {
numOfA[i] = min(numOfA[i - 1], numOfA[i]);
}
if (numOfA.size() == 0) {
cout << 0 << endl;
return;
}
vector<int> combination;
for (int i = 0; i < numOfA.back(); ++i) {
combination.push_back(numOfA.size());
}
for (int i = numOfA.size() - 2; i >= 0; --i) {
int n = numOfA[i] - numOfA[i + 1];
for (int j = 0; j < n; ++j) {
combination.push_back(i + 1);
}
}
int ans = 0;
for (int i = 0; i < K; ++i) {
if (i == combination.size()) {
break;
}
ans += combination[i];
}
cout << ans << endl;
}
int main() {
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
| // #include <atcoder/all>
#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 n;
ll a[200009], b[200009];
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> n;
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
ll sum = 0;
rep(i, n) sum += a[i];
vector<int> odd, even;
rep(i, n)(i & 1 ? odd : even).push_back(b[i] - a[i]);
sort(ALL(odd), greater<int>());
sort(ALL(even), greater<int>());
ll ans = sum;
rep(i, n / 2) chmax(ans, sum += odd[i] + even[i]);
cout << ans << endl;
return 0;
} |
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
#define int long long
#define mod 1000000007
int ans = 0;
vector<int>graph[200001];
vector<int>visited(200001, -1);
void dfs(vector<int>graph[], int start, vector<int>&visited)
{
visited[start] = 1;
for (auto i : graph[start])
{
if (visited[i] == -1)
{ ans++;
dfs(graph, i, visited);
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
vector<int>arr(n);
for (int i = 0; i < n; i++)
cin >> arr[i];
int i = 0;
int j = n - 1;
while (i < j)
{
graph[arr[i]].push_back(arr[j]);
graph[arr[j]].push_back(arr[i]);
i++;
j--;
}
for (int i = 0; i < arr.size(); i++)
{
if (visited[arr[i]] == -1)
{
dfs(graph, arr[i], visited);
}
}
cout << ans << endl;
} | #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define endl "\n"
#define deb(x) cout<<#x<<" "<<x<<endl;
#define sc(ar,n) for(int pen=0;pen<n;pen++){ cin>>ar[pen];}
#define pr(ar,n) for(int pen=0;pen<n;pen++){ cout<<ar[pen]<<" ";} cout<<endl;
#define fr(i,x,n) for(int i=x;i<n;i++)
#define frt(it,vb) for(auto it=vb.begin();it!=vb.end();it++)
#define mem(ar,x) memset(ar,x,sizeof(ar));
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define rt return 0;
#define ct continue;
#define MAX 1000000000000000000
#define MAX1 1000000000
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
inline int solve()
{
int n;
cin>>n;
int ar[n];
sc(ar,n);
vector <int> vt[200010];
fr(i,0,n/2){
if(ar[i] != ar[n-i-1]){
vt[ar[i]].push_back(ar[n-i-1]);
vt[ar[n-i-1]].push_back(ar[i]);
}
}
int vis[200010];
mem(vis,0);
int ans = 0;
fr(i,1,200010){
if(vis[i] == 0){
queue <int> q;
q.push(i);
vis[i] = 1;
int c = 0;
while(!q.empty()){
int x = q.front();
q.pop();
c++;
frt(it,vt[x]){
if(vis[*it] == 0){
q.push(*it);
vis[*it] = 1;
}
}
}
ans += c-1;
}
}
cout << ans << endl;
rt;
}
signed main()
{
// fastio;
int t;
int test_cases=1;
if(test_cases==0)
cin>>t;
else
t=1;
while(t--){
solve();
}
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MIN = -1e18;
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int n;
ll m, ans = 1e18;
cin >> n >> m;
vector<ll> a(n);
for (ll& x : a) cin >> x;
for (int k = 1; k <= n; ++k) {
vector<vector<ll>> dp(k, vector<ll>(k+1, MIN));
dp[0][0] = 0;
for (ll x : a) {
for (int c = k; c >= 1; --c) {
for (int r = 0; r < k; ++r) {
if (dp[(r-x%k+k)%k][c-1] >= 0) {
dp[r][c] = max(dp[r][c], dp[(r-x%k+k)%k][c-1] + x);
}
}
}
}
if (dp[m%k][k] < 0) continue;
ans = min(ans, (m - dp[m%k][k])/k);
}
cout << ans;
return 0;
}
| #include <iostream>
#include <vector>
#include <limits>
#include <cstring>
#include <time.h>
#include <math.h>
#include <algorithm>
#include <random>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <chrono>
#include <sstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii > vii;
typedef vector<vector<ll> > vvi;
typedef vector<vvi > vvvi;
typedef vector<vector<pair<ll, ll> > > vvii;
typedef ll func_ii_i(ll, ll);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,s,e) for(ll i=(s);i<(e);++i)
#define repr(i,s,e) for(ll i=(e);i>(s);--i)
#define io do { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(10); } while (0)
#define endl '\n'
#define newl cout << '\n';
#define fill0(a) memset(a, 0, sizeof(a))
#define fill1(a) memset(a, -1, sizeof(a))
#define all(v) v.begin(), v.end()
#define bg begin()
#define ed end()
#define tr(it, v) for (auto it = v.bg; it != v.ed; it++)
#define prv(v) do { tr(it, v) { cout << *it << " "; }; cout << endl; } while (0)
#define prm(m) tr(it, m) { cout << it->first << " -> " << it->second << endl; }
#define scan(a, n) rep(_idx,0,n) cin >> a[_idx];
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define sumv(v) accumulate(all(v), 0ll)
#define ub(a, x) upper_bound(all(a), x)
#define lb(a, x) lower_bound(all(a), x)
#define tcT template<class T
ll min3(ll a, ll b, ll c) { return min(a, min(b, c)); }
ll max3(ll a, ll b, ll c) { return max(a, max(b, c)); }
ll mid3(ll a, ll b, ll c) { return a + b + c - min3(a, b, c) - max3(a, b, c); }
ll ceil1(ll x, ll y) { if(x % y) return (x + y) / y; else return x / y; }
tcT> void rmdup(vector<T> &v) { sort(all(v)); v.erase(unique(all(v)), v.ed); }
tcT> ll fst1(ll l, ll h, T f) {
++h; // f is increasing
while(l<h) {
ll mi = l + ((h - l) >> 1);
f(mi) ? h = mi : l = mi + 1;
}
return l;
}
tcT> ll lst1(ll l, ll h, T f) {
--l; // f is decreasing
while(l<h) {
ll mi = l + ((h - l + 1) >> 1);
f(mi) ? l = mi : h = mi - 1;
}
return l;
}
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll TE3 = 1005;
const ll TE5 = 300005;
const ll dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
const string YN[2] = {"NO", "YES"};
using namespace std;
ll dp[105][105][105];
ll g(vi &v,ll n,ll k,ll x,ll rem,ll t) {
if(rem==0 && t==0) {
return 0;
}
if(rem<=0) {
return -INF;
}
if(x<0) {
return -INF;
}
if(dp[x][rem][t]!=-1) {
return dp[x][rem][t];
}
ll e=v[x];
ll em=e%k;
ll nm=(t-em+k)%k;
ll ans=g(v,n,k,x-1,rem,t);
ans=max(ans,e+g(v,n,k,x-1,rem-1,nm));
return dp[x][rem][t]=ans;
}
int main()
{
io;
ll n,x;
cin>>n>>x;
vi v(n);
scan(v,n);
ll ans=-1;
rep(k,1,n+1) {
ll t=x%k;
fill1(dp);
ll su=g(v,n,k,n-1,k,t);
if(su<0) {
continue;
}
ll local=(x-su)/k;
if(ans==-1) {
ans=local;
} else {
ans=min(ans,local);
}
}
cout<<ans<<endl;
return 0;
}
|
#include <iostream>
#include <bits/stdc++.h>
#include <map>
using namespace std;
int main() {
int H, W;
cin >> H >> W;
char a[H][W];
int dist[H][W];
map<char, vector<pair<int, int>>> mp;
for(int i=0; i<H; i++) {
for(int j=0; j<W; j++) {
char c;
cin >> c;
a[i][j] = c;
if(c != '#' && c != '.') mp[c].emplace_back(i, j);
dist[i][j] = -1;
}
}
dist[mp['S'][0].first][mp['S'][0].second] = 0;
queue<pair<int, int>> q;
q.emplace(mp['S'][0].first, mp['S'][0].second);
// cout << list_d[0].size() << endl;
vector<int> dx{-1, 0, 1, 0};
vector<int> dy{0, 1, 0, -1};
while(q.size()) {
// cout << "t:" << t << ' ' << e[0] << ' ' << e[1] << endl;
auto [x, y] = q.front();
q.pop();
for(int d=0; d<4; d++) {
// cout << i << ' ' << j << endl;
int x2 = x + dx[d];
int y2 = y + dy[d];
if(dist[x2][y2] == -1 && x2 >= 0 && x2 < H && y2 >= 0 && y2 < W && a[x2][y2] != '#') {
// cout << x << ' ' << y << ' ' << endl;
if(a[x2][y2] == 'G') {
cout << dist[x][y]+1 << endl;
return 0;
}
dist[x2][y2] = dist[x][y] + 1;
q.emplace(x2, y2);
}
}
for(const auto& c : mp[a[x][y]]) {
if(dist[c.first][c.second] >= 0) continue;
dist[c.first][c.second] = dist[x][y] + 1;
q.emplace(c.first, c.second);
// cout << c[0] << ' ' << c[1] << endl;
}
}
cout << -1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr char newl = '\n';
ll dp[100][200000 + 10];
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, K;
ll m;
cin >> n >> K >> m;
int lim_sum = (n - 1) / 2;
lim_sum = lim_sum * (lim_sum + 1) / 2 * K;
dp[0][0] = 1;
for (int i = 1; i < n; i++) {
int max_sum = min((i - 1) * i / 2 * K, lim_sum);
for (int j = 0; j <= max_sum; j++) {
if (dp[i - 1][j] == 0) continue;
for (int k = 0; k <= K; k++) {
if (j + k * i > lim_sum) break;
dp[i][j + k * i] += dp[i - 1][j];
if (dp[i][j + k * i] >= m) dp[i][j + k * i] -= m;
}
}
}
for (int i = 1; i <= n; i++) {
int li = i - 1;
int ri = n - i;
int mini = min(li, ri);
int max_sum = mini * (mini + 1) / 2 * K;
ll ans = 0;
for (int j = 0; j <= max_sum; j++) {
(ans += dp[li][j] * dp[ri][j] % m);
if (ans >= m) ans -= m;
}
ans = (ans * (K + 1) + m - 1) % m;
cout << ans << newl;
}
return 0;
}
|
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
#define all(v) v.begin(), v.end()
using in = long long;
#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 Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
const in MOD = 1000000007;
const in INF=(in)1e18+7;
const int inf=max(int(1e18)+7,int(1e9)+7);
using P=pair<int,int>;
using T=tuple<int,int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};
template <typename Typ>
bool chmin(Typ &a, const Typ& b) {if (a > b) {a = b; return true;} return false;}
template <typename Typ>
bool chmax(Typ &a, const Typ& b) {if (a < b) {a = b; return true;} return false;}
template <typename Typ>
Typ ceil(Typ x, Typ y){return (x+y-1)/y;}
#ifdef _DEBUG
#define debug(x) cout<<"debug:"<<x<<endl
#define vdebug(x) cout<<"debug:";\
for(auto asdf:x) cout<<asdf<<" ";\
cout<<endl
#else
#define debug(x)
#define vdebug(x)
#endif
int main(){
ios::sync_with_stdio(false);cin.tie(nullptr);
//cout << fixed << setprecision(12);
int n,m; cin>>n>>m;
vector<int> a(m),b(m);
rep(i,m) cin>>a[i]>>b[i];
int k; cin>>k;
vector<int> c(k),d(k);
rep(i,k) cin>>c[i]>>d[i];
int ans=0;
for(int tmp = 0;tmp< (1<<k); tmp++){
bitset<16> bt(tmp);
vector<bool> num(n,false);
rep(i,k){
if(bt.test(i)) num[d[i]-1]=true;
else num[c[i]-1]=true;
}
int cnt=0;
rep(i,m){
if(num[a[i]-1] and num[b[i]-1]) cnt ++;
}
chmax(ans,cnt);
}
cout<<ans<<"\n";
}/*
./problem.exe
*/ | #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;
using ll = long long;
using ld = long double;
using ordered_set = tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
void fastio() {
cin.tie(nullptr);
cin.sync_with_stdio(false);
}
const ll MOD = 1e9+7;
const ll INF = 1e18;
const ll N = 2e5+5;
#define S second
#define F first
#define vt vector
#define rep(i, st, en) for(ll i = (st); i < (en); ++i)
#define repr(i, en, st) for(ll i = (en); i >= (st); --i)
int main() {
fastio();
ll r, x, y;
cin >> r >> x >> y;
ll d2 = x*x + y*y;
ll r2 = r*r;
ll n = sqrtl(d2/r2);
while (r2*n*n < d2) {
n++;
}
if (r2 > d2) {
n = 2;
}
cout << n << "\n";
} |
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<map>
#include<stack>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<cstdlib>
#include<utility>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
long long n;
scanf("%lld",&n);
if (n%2==1)
{
printf("Odd\n");
continue;
}
n/=2;
if (n%2==1)
{
printf("Same\n");
continue;
}
printf("Even\n");
}
}
| #include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <math.h>
#include <random>
#include <chrono>
#include <assert.h>
using namespace std ;
using ll = long long ;
using ld = long double ;
template<class T> using V = vector<T> ;
template<class T> using VV = V<V<T>> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
long double pie = acos(-1) ;
ll INF = 1e18 ;
void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
ll extGCD(ll a,ll b,ll &x,ll &y){
if(b==0){
x = 1 ;
y = 0 ;
return a ;
}
ll d = extGCD(b,a%b,y,x) ;
y -= a/b*x ;
return d ;
}
void fix_cout(){cout << fixed << setprecision(20) ;}
template<class T> void chmax(T &a,T b){if(a<b) a = b ;}
template<class T> void chmin(T &a,T b){if(a>b) a = b ;}
int main(){
int n ; cin >> n ;
V<ll> a(n) ;
for(auto &i:a) cin >> i ;
sort(all(a)) ; reverse(all(a)) ;
ld ans = 1e15 ;
ll sum = 0 ;
for(int i=0;i<n;i++){
ld sub = 0 ;
ld x = a[i]/2.0 ;
sub += sum-a[i]*i;
sub /= n ;
sub += x ;
sum += a[i] ;
chmin(ans,sub) ;
}
fix_cout() ;
cout << ans << endl ;
} |
#include <bits/stdc++.h>
using namespace std;
#define llong long long
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )
#ifdef testing/*{{{*/
mt19937 rng(177013);
#else
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
#endif
#define rand() (int)(rng() >> 1)
#define CONCAT_(x, y) x##y
#define CONCAT(x, y) CONCAT_(x, y)
#define SPEC(name) CONCAT(name, __LINE__)
#ifdef LOCAL_DEBUG
int __db_level = 0;
#define clog cerr << string(__db_level * 2, ' ')
struct debug_block {
string msg;
debug_block(const string& s): msg(s) { clog << "{ " << msg << endl; ++__db_level; }
~debug_block() { --__db_level; clog << "} " << msg << endl; }
};
#define DB(args...) stringstream SPEC(ss); SPEC(ss)<< args; debug_block SPEC(dbbl)(SPEC(ss).str())
#else
#define clog if (0) cerr
#define DB(...)
#endif
#define db(val) "[" #val " = " << val << "]; "
template<class U, class V> ostream& operator<<(ostream& out, const pair<U, V>& p) {
return out << "(" << p.first << ", " << p.second << ")";
}
template<size_t i, class T> ostream& print_tuple_utils(ostream& out, const T& tup) {
if constexpr(i == tuple_size<T>::value) return out << ")";
else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup);
}
template<class ...U>
ostream& operator<<(ostream& out, const tuple<U...>& tup) { return print_tuple_utils<0, tuple<U...>>(out, tup); }
template<class, typename = void> struct has_const_iterator : false_type {};
template<class T> struct has_const_iterator<T, void_t<typename T::const_iterator>> : true_type {};
template<class T>
typename enable_if<has_const_iterator<T>::value && !is_same<T, string>::value, ostream&>::type
operator<<(ostream& out, const T& container) {
auto beg = container.begin(), end = container.end();
out << "(" << container.size() << ") {";
if (beg != end) out << *(beg++);
while (beg != end) out << ", " << *(beg++);
return out << "}";
}
#define ptrtype(x) typename iterator_traits<x>::value_type
template<class u> vector<ptrtype(u)> $v(u a, u b) { return vector<ptrtype(u)>(a, b); }/*}}}*/
// ACTUAL SOLUTION START HERE ////////////////////////////////////////////////////////////////
const int max_col = 400000 + 10;
int n;
int dsu[max_col];
bool has_cycle[max_col];
int find_set(int u) {
return dsu[u] < 0 ? u : dsu[u] = find_set(dsu[u]);
}
bool join(int u, int v) {
u = find_set(u);
v = find_set(v);
if (u == v) return false;
if (-dsu[u] < -dsu[v]) swap(u, v);
dsu[u] += dsu[v];
if (has_cycle[v]) has_cycle[u] = true;
dsu[v] = u;
return true;
}
int main(void) {
#ifdef LOCAL
freopen("main.inp", "r", stdin);
freopen("main.out", "w", stdout);
freopen(".log", "w", stderr);
#endif
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
memset(dsu, -1, sizeof(dsu));
memset(has_cycle, 0, sizeof(has_cycle));
rep(i, n) {
int u, v; cin >> u >> v;
if (!join(u, v)) {
has_cycle[find_set(u)] = true;
}
}
int ans = 0;
rep(i, max_col) {
if (dsu[i] >= 0) continue;
if (has_cycle[i]) ans += -dsu[i];
else ans += -dsu[i] - 1;
}
cout << ans;
return 0;
}
// vim: foldmethod=marker
| #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cstdio>
#include <cstring>
#define min(a, b) ((a) < (b) ? (a) : (b))
static constexpr int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
if (ci - cn == cm) {
fread(cn, 1, cm, stdin);
ci = cn;
}
return *ci++;
}
inline int getint() {
int A = 0;
while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
return A;
}
static constexpr int mx = 400000;
int p[mx], cnt[mx], siz[mx];
inline int get(int x) { return p[x] == -1 ? x : p[x] = get(p[x]); }
int main() {
int n = getint();
memset(p, -1, sizeof(p));
while (n--) {
int a = get(getint() - 1), b = get(getint() - 1);
if (a != b) {
p[b] = a;
cnt[a] += cnt[b];
}
cnt[a]++;
}
for (int i = 0; i < mx; i++) {
siz[get(i)]++;
}
int ans = 0;
for (int i = 0; i < mx; i++) {
if (get(i) == i) {
ans += min(cnt[i], siz[i]);
}
}
printf("%d", ans);
}
|
/* >>>>>Shwetal<<<<< */
#include <bits/stdc++.h>
#define int long long
#define f(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define inputArray(arr) f(i, 0, arr.size()) cin >> arr[i]
#define printArray(arr) f(i, 0, arr.size()) cout << arr[i] << ' '; cout << endl
#define endl '\n'
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
bool solve() {
string s;
cin >> s;
int n = s.size();
// bool flag = true;
f(i, 0, n){
if(i % 2 == 1 && islower(s[i])){
return false;
}
if(i % 2 == 0 && isupper(s[i])){
return false;
}
}
return true;
}
int32_t main(){
// freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
// cin >> T;
while(T--){
// solve();
if(solve())
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
for (int i = 0; i < (int)S.size(); i++) {
if ((i % 2 == 0) && (S.at(i) < 'a' || S.at(i) > 'z')) {
cout << "No" << endl;
return 0;
}
else if ((i % 2 == 1) && (S.at(i) < 'A' || S.at(i) > 'Z')) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
} |
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/priority_queue.hpp>
//#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef gp_hash_table<int, int> hashmap;
//typedef tree<pii, null_type, std::less<pii>, splay_tree_tag, tree_order_statistics_node_update> splaytree;
//typedef tree<pii, null_type, std::less<pii>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
//typedef __gnu_pbds::priority_queue<int, std::greater<int>, __gnu_pbds::binary_heap_tag> binheap;
//typedef __gnu_pbds::priority_queue<int, std::greater<int>, __gnu_pbds::pairing_heap_tag> pairingheap;
template <typename T>
inline void read(T &x)
{
T data = 0, f = 1;
char ch = getchar();
while (!isdigit(ch))
{
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch))
{
data = (data << 3) + (data << 1) + ch - '0';
ch = getchar();
}
x = f * data;
}
template <typename T, typename... Args>
inline void read(T &t, Args &...args)
{
read(t);
read(args...);
}
#define int ll
//mt19937 rnd(time(0));
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int maxn = 6e5 + 9;
const ll mod = 998244353;
int n, n2;
ll BIT[maxn], a[maxn], ans[maxn];
inline int lowbit(int x)
{
return x & -x;
}
void add(int k, int x)
{
for (; k <= n; k += lowbit(k))
BIT[k] += x;
}
ll ask(int k)
{
ll ret = 0;
for (; k; k -= lowbit(k))
ret += BIT[k];
return ret;
}
signed main()
{
//freopen("in.txt","r",stdin);
//freopen("data.txt","w",stdout);
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
//std::cout.tie(0);
read(n);
for (int i = 1; i <= n; ++i)
{
read(a[i]);
a[i]++;
a[i + n] = a[i];
}
n2 = n * 2;
int cnt = 0;
for (int i = 1, l = 1, r = 0; i <= n; ++i)
{
int ql = i, qr = i + n - 1;
ans[i] = ans[i - 1];
while (l < ql)
{
ans[i] -= ask(a[l] - 1);
add(a[l], -1);
l++;
cnt--;
}
while (r < qr)
{
r++;
add(a[r], 1);
cnt++;
//cout << r << ' ' << cnt << ' ' << ask(a[r]) << '\n';
ans[i] += (cnt - ask(a[r]));
}
cout << ans[i] << '\n';
}
// for (int i = 1; i <= n; ++i)
// {
// cout << ans[i] - ans[i + n] << '\n';
// }
//fclose(stdin);
//fclose(stdout);
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=1000000007;
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;
}
template <class T>
class SegTree {
int n;// 葉の数
vector<T> data;// データを格納するvector
T def; // 初期値かつ単位元
function<T(T, T)> operation; // 区間クエリで使う処理
function<T(T, T)> update;// 点更新で使う処理
T find(int a, int b) {
T val_left = def, val_right = def;
for (a += (n - 1), b += (n - 1); a < b; a >>= 1, b >>= 1)
{
if ((a & 1) == 0){
val_left = operation(val_left, data[a]);
}
if ((b & 1) == 0){
val_right = operation(data[--b],val_right);
}
}
return operation(val_left, val_right);
}
public:
// _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数,
// _update:更新関数
SegTree(size_t _n, T _def, function<T(T, T)> _operation=[](T a, T b){return a+b;},
function<T(T, T)> _update=[](T a,T b){return b;})
: def(_def), operation(_operation), update(_update) {
n = 1;
while (n < _n) {
n *= 2;
}
data = vector<T>(2 * n - 1, def);
}
void set(int i, T x) { data[i + n - 1] = x; }
void build() {
for (int k=n-2;k>=0;k--) data[k] = operation(data[2*k+1],data[2*k+2]);
}
// 場所i(0-indexed)の値をxで更新
void change(int i, T x) {
i += n - 1;
data[i] = update(data[i], x);
while (i > 0) {
i = (i - 1) / 2;
data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
}
}
// [a, b)の区間クエリを実行
T query(int a, int b) {
//return _query(a, b, 0, 0, n);
return find(a,b);
}
// 添字でアクセス
T operator[](int i) {
return data[i + n - 1];
}
};
int main() {
lin(N);
vl A(N);
rep(i,N) {
cin>>A.at(i);
}
SegTree <ll>st(N,0);
ll count=0;
rep(i,N) {
count+=st.query(A.at(i),N);
st.change(A.at(i),1);
}
rep(i,N) {
co(count);
count+=N-1-2*A.at(i);
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define var auto
template<typename T, T MOD = 1000000007>
struct Mint{
static constexpr T mod = MOD;
T v;
Mint():v(0){}
Mint(signed v):v(v){}
Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}
Mint pow(long long k){
Mint res(1),tmp(v);
while(k){
if(k&1) res*=tmp;
tmp*=tmp;
k>>=1;
}
return res;
}
static Mint add_identity(){return Mint(0);}
static Mint mul_identity(){return Mint(1);}
Mint inv(){return pow(MOD-2);}
Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
Mint& operator/=(Mint a){return (*this)*=a.inv();}
Mint operator+(Mint a) const{return Mint(v)+=a;}
Mint operator-(Mint a) const{return Mint(v)-=a;}
Mint operator*(Mint a) const{return Mint(v)*=a;}
Mint operator/(Mint a) const{return Mint(v)/=a;}
Mint operator-() const{return v?Mint(MOD-v):Mint(v);}
bool operator==(const Mint a)const{return v==a.v;}
bool operator!=(const Mint a)const{return v!=a.v;}
bool operator <(const Mint a)const{return v <a.v;}
static Mint comb(long long n,int k){
Mint num(1),dom(1);
for(int i=0;i<k;i++){
num*=Mint(n-i);
dom*=Mint(i+1);
}
return num/dom;
}
};
template<typename T, T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T, T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}
const ll MOD = (int)(1e9 + 7);
constexpr ll factorial(int n){
ll res = 1;
for (int i = 1; i <= n; i++){
res *= i;
res %= MOD;
}
return res;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> a(n);
int sum = 0;
for (int i = 0; i < n; i++){
cin >> a[i];
sum += a[i];
}
using M = Mint<int>;
M res = 1;
for (int i = 1, j = n + m; i <= sum + n; i++, j--){
res *= j;
res /= i;
}
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)
template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;
#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif
const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll modpow(ll a, ll n, ll mod_) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod_;
a = a * a % mod_;
n >>= 1;
}
return res;
}
const ll MAX_SIZE = 4005005;
array<ll, MAX_SIZE> fac, inv, finv;
struct finit{
finit(){
// combination init
fac[0] = 1;
for (ll i = 1; i < MAX_SIZE; i++) fac[i] = fac[i - 1] * i % MOD;
finv[MAX_SIZE - 1] = modpow(fac[MAX_SIZE - 1], MOD - 2, MOD);
for(ll i = MAX_SIZE - 1; i > 0; i--) finv[i - 1] = finv[i] * i % MOD;
//inv init
repe(i, 1, MAX_SIZE) inv[i] = modpow(i, MOD - 2, MOD);
}
} finit_;
ll perm(ll a, ll b) { return fac[a] * finv[a - b] % MOD; }
ll comb(ll a, ll b) { return fac[a] * finv[b] % MOD * finv[a - b] % MOD; }
int main() {
ll N, M;
cin >> N >> M;
vl A(N);
rep(i, N) cin >> A[i];
ll sum = accumulate(all(A), 0ll);
if(sum > M){
cout << 0 << endl;
return 0;
}
ll ans = finv[sum + N];
rep(i, sum + N)(ans *= (M + N - i)) %= MOD;
cout << ans << endl;
} |
///////////////////////////////
////ACくれなきゃ悪戯しちゃうぞ!////
///////////////////////////////
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
#include <map>
#include <utility>
#include <set>
#include <deque>
//using
using namespace std;
using vi = vector <int>;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
using vvc = vector<vector<char> >;
using vd = vector <double>;
using vpl = vector <pair<ll,ll> >;
//define
#define rep(i,r) for(ll i=0;i<(r);i++)
#define Rep(i,l,r) for(ll i=(l);i<(r);i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
#define all(n) n.begin(),n.end()
//素数判定 O(√A)
bool is_prime(ll x){
if(x<=1) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
//各位の和
int wa(ll x)
{
ll sum = 0;
while(x!=0){
sum += x% 10;
x /= 10;
}
return sum;
}
/*順列生成
do {
// 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/
//最大公約数 ユークリッドの互除法
ll gcd(ll a, ll b) {
if (b==0) return a;
else return gcd(b, a%b);
}
//最小公倍数 a*b/gcd
ll lcm(ll a, ll b) {
return a/gcd(a, b)*b;
}
//10進→2進
ll binary(ll bina){
ll ans = 0;
for (ll i = 0; bina>0 ; i++)
{
ans = ans+(bina%2)*pow(10,i);
bina = bina/2;
}
return ans;
}
//'A'65,'a'97
//reverse 回文
/*for(const auto& [x,y]:m) mapの範囲for
{
q+=y*(y-1)/2;
}*/
/*小数点精度指定
cout<<fixed<<setprecision(9)<<;
*/
//文字列の削除 erase(n)
//グローバル変数宣言等
ll p=0,q=0,r=0;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
#define inf 1000000000000 //10^12:∞
#define mod 1000000007 //10^9+7:合同式の法
int main()
{
unsigned long long n;cin>>n;
if(n==1||n==2||n==3)
{
print(n/3+1)return 0;
}
for (unsigned long long i = 0; i < n; i++)
{
if(i%2==0)
{
p=i/2*(i+1);
}else
p=(i+1)/2*(i);
if(1+n<p)
{
print(n-i+2);return 0;
}
}
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int64_t n;
cin>>n;
int64_t cnt=0,sum=0;
while(cnt+sum<=n)sum+=++cnt;
cout<<n-cnt+1<<'\n';
} |
/**
* @author: adityasonani
* */
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#define ll long long
#define ld long double
#define ln "\n"
#define fastio ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define MOD (int) 1000000007
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << x << endl;
#define debugV(x) cerr << #x << " = ["; for(auto i: x){ cerr << i << ", ";} cerr << "]" << endl;
#define precise(x) cout << fixed << setprecision(x)
#define MAX (int) 100007 // 10^5
std::vector<int> gv(int n){std::vector<int> v(n);for(auto &x: v){std::cin>>x;}return v;}
using namespace std;
/*
*/
void solve()
{
int n, d, h;
cin>>n>>d>>h;
int mxH = INT_MIN, mxD = 1;
double ans = 0.0;
while(n--){
int da, ha;
cin>>da>>ha;
double x = ((double)(da*h)-(d*ha))/(double)(da-d);
ans = max(ans, x);
}
precise(10);
cout << ans;
}
signed main()
{
fastio;
auto start = std::chrono::high_resolution_clock::now();
int t=1;
// cin>>t;
while(t--)
solve();
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);
// cerr << "\nTime taken : " << ((long double)duration.count())/((long double) 1e9) <<" s "<< endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using Int = long long;
int main(){
Int n,s,d; cin>>n>>s>>d;
vector<Int> x(n);
vector<Int> y(n);
rep(i,n) cin>>x[i]>>y[i];
rep(i,n){
if(x[i]<s && y[i]>d){
cout<<"Yes"<<endl;
return 0;
}
}
cout<<"No"<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T; cin >> T;
string ss = "atcoder";
while (T--) {
string s = ss;
string t; cin >> t;
string tt = t;
sort(tt.rbegin(), tt.rend());
if (t > s) {
cout << 0 << '\n';
}
else if (tt <= s) {
cout << -1 << '\n';
}
else {
int ans = INT_MAX;
for (int i = 0; i < (int)t.size(); i++) {
if (t[i] > 't') {
ans = i - 1;
break;
}
}
for (int i = 0; i < (int)t.size(); i++) {
if (t[i] > 'a') {
ans = min(ans, i);
break;
}
}
cout << ans << '\n';
}
}
return 0;
} | #include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
int Solve(string & s) {
if (s == string(s.size(), 'a'))
return -1;
if ("atcoder" < s)
return 0;
int i;
rep(i, s.size()) {
if (s[i] != 'a')
break;
}
if (s[i] > 't')
return i - 1;
return i;
}
int main(void) {
int num, i;
string s;
cin >> num;
rep(i, num) {
cin >> s;
cout << Solve(s) << "\n";
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
cin>>x;
if(x>=0) cout<<x;
else if(x<0) cout<<0;
} | #include<bits/stdc++.h>
#define ll long long int
#define nl '\n'
#define pi acos(-1)
#define GCD(a, b) __gcd(a, b)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inout freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
using namespace std;
int main(void){
//boost;
ll t,k,n,m,mi=0,mx=0,ans=0,po=0,ne=0,cnt=0,sum=0;
cin>>t;
//vector<ll>a(t);
ll ar[1001];
map<char,int>mp;
vector<string>str(105);
bitset<6>set_t;
read:
if(t>=0) cout<<t;
else cout<<0;
}
|
//Code by Ritik Agarwal
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x).size()
#define int long long int
#define loop(i,a,b) for(int i=a;i<b;i++)
#define scan(arr,n) for (int i = 0; i < n; ++i) cin >> arr[i]
#define vi vector<int>
#define si set<int>
#define pii pair <int, int>
#define sii set<pii>
#define vii vector<pii>
#define mii map <int, int>
#define pb push_back
#define ff first
#define ss second
#define all(aa) aa.begin(), aa.end()
#define rall(a) a.rbegin() , a.rend()
#define read(a,b) int a,b; cin>>a>>b
#define readt(a,b,c) int a,b,c; cin>>a>>b>>c
#define readf(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d;
#define print(v) for(auto x:v) cout<<x<<" ";cout<<endl
#define printPair(res) for(pair<int,int>& p:res) cout<<p.first<<" "<<p.second<<endl;
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
//***** Constants *****
const int mod = 1000000007; /* 1e9 + 7*/
const int MAXN = 1500005; /*1e6 +5 */
const int mod1= 998244353;
const int NAX=2E5+5;
int vis[MAXN]={0};
int fac[300001];
void fact(int m){fac[0]=1;for(int i=1;i<=300000;i++) fac[i]=(fac[i-1]%m * i%m)%m;}
/* Iterative Function to calculate (x^y)%p in O(log y)*/
long long power( long long x, int y, int p){ long long res = 1;
x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p;} return res;}
// Returns n^(-1) mod p
long long modInverse( long long n, int p) { return power(n, p - 2, p); }
long long nCr( long long n,int r, int p) { if (r == 0) return 1; if(n<r) return 0;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; }
int binarySearch(vi arr, int l, int r, int x) {
if (r >= l) { int mid = l + (r - l) / 2; if (arr[mid] == x) return mid;
if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);
return binarySearch(arr, mid + 1, r, x); } return -1; }
bool sortGrt(const pair<int,int> &a,
const pair<int,int> &b)
{
return (a.second > b.second);
}
void solve(int test)
{
string s;cin>>s;
if(s[0]==s[1] && s[1]==s[2])
cout<<"Won\n";
else
cout<<"Lost\n";
}
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
faster;
fact(mod);
int t=1;
//cin>>t;
for(int test=1;test<=t;test++)
{
solve(test);
}
} | #include<iostream>
using namespace std;
int main()
{
char a[3];
for (int i = 0; i < 3; i++)
{
cin >> a[i];
}
if ((a[0] == a[1]) && (a[1] == a[2]))
{
cout << "Won" << endl;
}
else
{
cout << "Lost" << endl;
}
} |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fore(b,c) for(int val0=b;val0<c;val0++)
#define forr(k,c,s) for(int k=c;k<s;k++)
#define pb push_back
#define mmp make_pair
using namespace __gnu_pbds;
using namespace std;
template<typename T>
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long double ld;
typedef vector<vii> al;
typedef vector<ll> vl;
const int INF = 1e9;
const ll INFL = 1LL<<61;
const ll MN = 3030;
const ll LG = 13;
const ll M = 998244353;
ll dp[MN][MN];
ll ds(ll n, ll k) {
if(k > n) {return 0;}
if(k == n) {return 1;}
if(n == 0 || k == 0) {return 0;}
if(dp[n][k] != -1) {return dp[n][k];
}
//cout << "roop " << n << " " << k << '\n';
ll res = ds(n-1,k-1) + ds(n,2*k);
res %= M;
return dp[n][k] = res;
}
int main() {
//ios::sync_with_stdio(0);cout.precision(20);cout.tie(0);cin.tie(0);
memset(dp,-1,sizeof(dp));
ll n,k;
cin >> n >> k;
cout << ds(n,k) << '\n';
}
| //#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;
//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;
int n;
LL f[110][2];
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
scanf("%d",&n);
f[0][1]=f[0][0]=1;
for(int i=1;i<=n;i++)
{
char s[20]; scanf("%s",s+1);
if(s[1]=='A')
{
f[i][0]=2*f[i-1][0]+f[i-1][1];
f[i][1]=f[i-1][1];
}
else
{
f[i][0]=f[i-1][0];
f[i][1]=2*f[i-1][1]+f[i-1][0];
}
}
printf("%lld\n",f[n][1]);
return 0;
}
/*
*/
|
#include <bits/stdc++.h>
#define lowbit(x) ((x) & (-x))
using namespace std;
typedef long long LL;
const int N = 200005;
int n, e;
int a[N], b[N], c[N], d[N * 4];
LL m, f[N * 4];
void init() {
memset(f, 0, sizeof(f));
}
void add(int p, int val) {
for (; p < e; p += lowbit(p)) f[p] += val;
}
LL cal(int p) {
LL ans = 0;
for (; p > 0; p -= lowbit(p)) ans += f[p];
return ans;
}
void gao() {
e = 0;
d[e++] = 0;
for (int i = 0; i < n; i++) {
d[e++] = a[i], d[e++] = a[i] + 1;
d[e++] = b[i], d[e++] = b[i] + 1;
}
sort(d, d + e);
e = unique(d, d + e) - d;
for (int i = 0; i < n; i++) {
a[i] = lower_bound(d, d + e, a[i]) - d;
b[i] = lower_bound(d, d + e, b[i]) - d;
// printf("l= %d, r= %d, c= %d\n", a[i], b[i], c[i]);
}
init();
for (int i = 0; i < n; i++) {
add(a[i], c[i]);
add(b[i] + 1, -c[i]);
}
LL ans = 0;
for (int i = 1; i < e - 1; i++) {
LL tmp = cal(i);
// printf("i= %d %d %lld %lld\n", i, d[i], tmp, tmp * (d[i + 1] - d[i]));
ans += min(m, tmp) * (d[i + 1] - d[i]);
}
cout << ans << '\n';
}
inline bool scan_d(int &num)
{
char in;bool IsN=false;
in=getchar();
if(in==EOF) return false;
while(in!='-'&&(in<'0'||in>'9')) in=getchar();
if(in=='-'){ IsN=true;num=0;}
else num=in-'0';
while(in=getchar(),in>='0'&&in<='9'){
num*=10,num+=in-'0';
}
if(IsN) num=-num;
return true;
}
int main() {
scan_d(n);
scanf("%lld", &m);
for (int i = 0; i < n; i++) scan_d(a[i]), scan_d(b[i]), scan_d(c[i]);
gao();
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl '\n'
#define int long long int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define revrep(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
ostream &operator<<( ostream &output, const pii &p ) { output << p.first << " " << p.second;return output; }
istream &operator>>( istream &input, pii &p ) { input >> p.first >> p.second;return input; }
template<typename T>
void inline println(vector<T> args){ for(T i: args)cout<<i<<" ";cout<<endl; }
void amax(int& a, int b) { a = max(a, b); }
void amin(int& a, int b) { a = min(a, b); }
const string YES = "Yes";
const string NO = "No";
int INF = 1e18;
int MOD = 998244353;
void solve()
{
int a, b, x, y; cin>>a>>b>>x>>y;
int dp[2][101];
rep(i, 0, 2) rep(j, 0, 101) dp[i][j] = INF;
set<pair<int, pii>> q;
dp[0][a] = 0;
q.insert({0, {0, a}});
while(q.size()) {
auto front = *q.begin();
auto cor = front.second;
q.erase(q.begin());
vii nxt;
int other = 1-cor.first;
nxt.pb({cor.first, cor.second+1});
nxt.pb({cor.first, cor.second-1});
nxt.pb({other, cor.second});
if(other == 0) nxt.pb({other, cor.second+1});
else nxt.pb({other, cor.second-1});
for(auto pr: nxt) {
if(pr.second > 100) continue;
if(pr.second < 0) continue;
int dd = (pr.first == cor.first ? y:x);
int dist = dd+dp[cor.first][cor.second];
if(dp[pr.first][pr.second] > dist) {
auto key = q.find({dp[pr.first][pr.second], pr});
if(key != q.end()) q.erase(key);
q.insert({dist, pr});
dp[pr.first][pr.second] = dist;
}
}
}
cout<<dp[1][b]<<endl;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
rep(i, 0, t)
{
solve();
}
return 0;
} |
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
string n;
int k;
string res;
//-----------
bool cmp(char a, char b)
{
return a>b;
}
//-----------
string inttostring(long long n)
{
stringstream stream;
stream<<n;
string st=stream.str();
return st;
}
//--------------------------------
long long stringtoint(string m)
{
long long k=atoll(m.c_str());
return k;
}
//------------------------------
int main()
{
cin>>n>>k;
res=n;
while (k--)
{
string a=res,b=res;
int x,y,z;
sort(a.begin(),a.end());
sort(b.begin(),b.end(),cmp);
x=stringtoint(a);
y=stringtoint(b);
z=y-x;
res=inttostring(z);
}
cout<<res;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define asort(a,n) sort(a,a+n)
#define vsort(v) sort(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define mod 1000000007
#define endl "\n"
#define LL_MAX LLONG_MAX
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
//********************************* mekch ************************************//
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
ll binExp(ll x,ll n)
{
ll res=1;
while(n)
{
if(n&1) res=(res*x)%mod;
x=(x*x)%mod;
n>>=1;
}
return res;
}
bool isPerfectSquare(long double x)
{
long double sr = sqrt(x);
return ((sr - floor(sr)) == 0);
}
int main()
{
run;
ll t;
// ALWAYS UES LL_MAX
long double n,i,x,y,ok=0,sum=0,ans=0,res;
ll res1,res2,res3,res4;
cin>>x>>y;
res=x*x-4*y;
if (isPerfectSquare(res))
{
res1=sqrt(res);
res2=x+res1;
res3=x-res1;
// cout<<"jdc";
if(res2%2==0)
res2=res2/2;
else
res2=-1;
if(res3%2==0)
res3=res3/2;
else
res3=-1;
if(res2>0||res3>0)
{
if(res2>0)
res4=x-res2;
else
res4=x-res3;
if(res4>0)
yes;
else
no;
}
else
no;
}
else
no;
} |
/*
Author: Arnab Sinha
███████╗██╗ ██╗███████╗██████╗ ██╗ ██████╗ ██████╗██╗ ██╗███████╗██████╗ █████╗ █████╗
██╔════╝██║ ██║██╔════╝██╔══██╗ ██║ ██╔═══██╗██╔════╝██║ ██╔╝██╔════╝██╔══██╗██╔══██╗██╔══██╗
███████╗███████║█████╗ ██████╔╝ ██║ ██║ ██║██║ █████╔╝ █████╗ ██║ ██║╚██████║╚██████║
╚════ █║██╔══██║██╔══╝ ██╔══██╗ ██║ ██║ ██║██║ ██╔═██╗ ██╔══╝ ██║ ██║ ╚═══██║ ╚═══██║
███████║██║ ██║███████╗██║ ██║███████╗███████╗╚██████╔╝╚██████╗██║ ██╗███████╗██████╔╝ █████╔╝ █████╔╝
╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝╚══════╝╚═════╝ ╚════╝ ╚════╝
*/
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define li long long int
#define ld long double
#define all(v) v.begin(),v.end()
#define rev(a) reverse(all(a))
#define sort(a) sort(all(a))
#define pb push_back
#define INF 1e18+10
#define MINF -1e18-10
#define rep(i,a,b) for(li i=a;i<b;i++)
#define vli vector<li>
#define MAXN 1e5+10
const li mod = 1e9+7;
using namespace std;
li power(li a, li b) { a%=mod; li ret = 1; while(b){ if(b&1) ret*=a; a*=a;; if(ret>=mod) ret%=mod; if(a>=mod) a%=mod; b>>=1; } return ret; }
template <class T> void read(T& x){
cin>>x;
}
template <class T, class... U> void read(T& x, U&... u){
read(x);
read(u...);
}
template <class A> void read(vector<A>& v){
for(auto &it:v)
read(it);
}
template <class A> void print(A x){
cout<<x;
}
template <class A> void printl(A x){
cout<<x<<endl;
}
template <class A> void print(vector<A>& v)
{
for(auto &it:v){
print(it);
cout<<' ';
}
cout<<endl;
}
vector<li> v[200005];
bool visited[200005];
long int a[200005],b[200005];
li n,m;
li sum1=0, sum2=0;
void dfs(li num) {
// component_nodes.pb(num);
sum1+=a[num-1];
sum2+=b[num-1];
visited[num] = true;
for(auto it:v[num]) {
if(visited[it]==true)
continue;
dfs(it);
}
return;
}
void solve()
{
cin>>n>>m;
rep(i,0,200005){
visited[i] = false;
}
rep(i,0,n)cin>>a[i];
rep(i,0,n)cin>>b[i];
rep(i,0,m){
li c,d;
cin>>c>>d;
v[c].pb(d);
v[d].pb(c);
}
rep(i,1,n+1){
if(visited[i]==false){
// cout<<"Yes\n";
sum1=sum2=0;
dfs(i);
}
if(sum1!=sum2){
cout<<"No\n";
return;
}
}
cout<<"Yes\n";
// dfs(1,0);
}
int main()
{
IOS;
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
solve();
return 0;
} | #include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <tuple>
#include <numeric>
using namespace std;
int main(int argc, char* argv[]){
int N,M;
cin >> N >> M;
vector<long long> A(N);
vector<long long> B(N);
vector <pair<int,int>> P(M);
long long sum_a = 0;
long long sum_b = 0;
for(int i=0;i<N;i++){
cin >> A[i];
sum_a += A[i];
}
for(int i=0;i<N;i++){
cin >> B[i];
sum_b += B[i];
}
vector<int> num(N,0);
for(int i=0;i<M;i++){
int c,d, tmp;
cin >> c >> d;
if(c>d){
tmp = c;
c = d;
d = tmp;
}
num[c-1]++;
num[d-1]++;
P[i] = make_pair(c, d);
}
bool flag = true;
for(int i=0; i<N; i++){
if(num[i]==0 && A[i]!=B[i]){
flag = false;
}
}
if(sum_a != sum_b || flag==false){
cout << "No" << endl;
}else{
cout << "Yes" << endl;
}
return 0;
}
|
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#include <string> // ヘッダファイルインクルード
#include <typeinfo>
using namespace std; // 名前空間指定
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
template <class T>
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; // check the limits, dummy
const ll infl = 1LL << 60;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T>
void print(const vector<T> v) {
cout << "[ ";
F0R(i, v.size()) { cout << v[i] << ' '; }
cout << "]" << '\n';
}
int mod(int i, int j) {
return (i % j) < 0 ? (i % j) + 0 + (j < 0 ? -j : j) : (i % j + 0);
}
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
/* lcm (a, b) : 2整数版
入力:整数 a, b
出力:aとbの最小公倍数
*/
long long lcm(long long a, long long b) {
long long d = gcd(a, b);
return a / d * b;
}
// --------------------------------------------------------
// This is tool
// --------------------------------------------------------
void Main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
// pは与えられる配列
vector<int> p(n);
FOR(i, 0, n) cin >> p[i];
vector<int> ans(n + 1000);
vi done_swap(n - 1, 0);
int count = 0;
bool done_sort = true;
int number = 1;
int get_key = 0;
FOR(i, 0, n) {
if (p[i] == number) {
for (int j = i - 1; j >= get_key; j--) {
swap(p[j], p[j + 1]);
ans[count] = j + 1;
count++;
done_swap[j]++;
if (done_swap[j] != 1) {
cout << -1 << endl;
return;
}
}
number = i + 1;
get_key = i;
}
}
FOR(i, 0, n - 1) {
if (p[i] > p[i + 1]) {
done_sort = false;
break;
}
}
if (done_sort and count == n - 1) {
FOR(i, 0, n - 1) { cout << ans[i] << endl; }
} else {
cout << -1 << endl;
}
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
Main();
} | #include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define vec vector
using namespace std;
const int MOD = 3;
const int INV[3] = {0, 1, 2};
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef LOCAL
// freopen("in1.txt", "r", stdin);
// freopen("in1.txt", "w", stdout);
#endif
int n;
cin >> n;
string c;
cin >> c;
vec<int> a(n), b(n);
for (int i=0, p=1, q=0, x; i<(n+1)/2; i++) {
a[i] = a[n-i-1] = (q==0 ? p : 0);
x = n-i-1;
while (x%MOD==0) {
q++;
x /= MOD;
}
p = (p * x) % MOD;
x = i+1;
while (x%MOD==0) {
q--;
x /= MOD;
}
p = (p * INV[x%MOD]) % MOD;
}
// cout << "a "; for (int x : a) cout << x << ' '; cout << '\n';
int sum = 0;
for (int i=0; i<n; i++) {
if (c[i] == 'W') sum = (sum + a[i]*1) % MOD;
if (c[i] == 'R') sum = (sum + a[i]*2) % MOD;
}
if (n%2 == 0) sum = -sum;
sum = (sum%MOD + MOD) % MOD;
if (sum == 0) cout << 'B';
if (sum == 1) cout << 'W';
if (sum == 2) cout << 'R';
cout << '\n';
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
ll gcd(ll a, ll b) {
if (a < b) {
a ^= b;
b ^= a;
a ^= b;
}
return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll f(ll h) {
if (h == 1) {
return 1;
} else {
return 2 * f(h / 2) + 1;
}
}
ll mod = 1000000007;
ll powmod(ll a, ll b) {
ll ret = 1;
for (int i = 0; i < b; i++) {
ret = (ret * a) % mod;
}
return ret;
}
ll comb(ll n, ll k) {
map<string, ll> memo;
if (n == k || k == 0) {
return 1;
} else {
string key = to_string(n) + to_string(k);
if (memo.count(key) != 0) {
return memo[key];
} else {
ll v = comb(n - 1, k - 1) + comb(n - 1, k);
memo[key] = v;
return v;
}
}
}
int f(int n, int k) {
int ret = 0;
while (n < k) {
n *= 2;
ret++;
}
return ret;
}
int main() {
int N, K;
cin >> N >> K;
vector<int> v(N), box(K, -1);
for (int i = 0; i < N; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
int i = 0;
int prev = -1;
for (auto a : v) {
if (prev != a) {
i = 0;
}
if (box[i] + 1 == a) {
box[i] = a;
i++;
}
prev = a;
}
ll ans = 0;
for (auto a : box) {
if (a != -1) {
ans += (a + 1);
}
}
cout << ans << endl;
}
| #include<bits/stdc++.h>
using namespace std;
long long in(){
long long x;
cin>>x;
return x;
}
int main(){
long long x=in(),y=in(),a=in(),b=in(),ans=0;
while(x<b/(a-1) && x<y/a)x*=a,ans++;
ans+=(y-1-x)/b;
cout<<ans<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
// --------------------------------------------------------
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; }
#define FOR(i,l,r) for (ll i = (l); i < (r); ++i)
#define RFOR(i,l,r) for (ll i = (r)-1; (l) <= i; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define COUNT(c,v) count(ALL(c),(v))
#define SZ(c) ((ll)(c).size())
#define BIT(b,i) (((b)>>(i)) & 1)
#define PCNT(b) __builtin_popcountll(b)
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << "l." << __LINE__ << " : " << #x << " = " << (x) << '\n'
ll llceil(ll a, ll b) { return (a + b - 1) / b; }
ll bitlen(ll b) { if (b <= 0) { return 0; } return (64LL - __builtin_clzll(b)); }
string toupper(const string& S) { string T(S); REP(i,SZ(T)) T[i] = toupper(T[i]); return T; }
string tolower(const string& S) { string T(S); REP(i,SZ(T)) T[i] = tolower(T[i]); return T; }
using P = pair<ll,ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VVS = vector<VS>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VVVLL = vector<VVLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VVVB = vector<VVB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VLD = vector<ld>;
using VVLD = vector<VLD>;
using VVVLD = vector<VVLD>;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const ll INF = (1LL << 62) - 1; // 4611686018427387904 - 1
// --------------------------------------------------------
// #include <atcoder/all>
// using namespace atcoder;
// Editorial AC
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
ll N; cin >> N;
VLL V(2*N); REP(i,2*N) cin >> V[i];
priority_queue<ll,VLL,greater<ll>> pq;
ll ans = SUMLL(V);
REP(i,N) {
pq.push(V[N-1-i]);
pq.push(V[N+i]);
ans -= pq.top(); pq.pop();
}
COUT(ans);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
int main(){
cin>>n>>m;
if(m==0){
for(int i=1;i<=n;i++)printf("%d %d\n",i*2-1,i*2);
return 0;
}
if(abs(m)>n-2||m<0)return puts("-1"),0;
if(m>0){
int now=2*m+4;
printf("%d %d\n",1,2*m+3);
printf("%d %d\n",2*m+2,2*m+4);
for(int i=1;i<=m;i++)printf("%d %d\n",2*i,2*i+1);
while(now<2*n)printf("%d %d\n",now+1,now+2),now+=2;
}
else {
m=-m;
int now=2*m+4;
printf("%d %d\n",2,2*m+4);
printf("%d %d\n",1,3);
for(int i=1;i<=m;i++)printf("%d %d\n",2*i+2,2*i+3);
while(now<2*n)printf("%d %d\n",now+1,now+2),now+=2;
}
return 0;
} |
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define endl "\n"
#define rep(X,Y) for(X=0;X<Y;X++)
#define rep1(X,Y) for(X=1;X<=Y;X++)
#define rrep(X,Y) for(X=Y-1;X>=0;X--)
#define rrep1(X,Y) for(X=Y;X>=1;X--)
#define ml ll T,g; cin>>T; for(g=0;g<T;g++)
#define case "Case "<<g+1<<": "
#define sf(T) scanf("%lld",&T)
#define pf(T) printf("%lld\n",T)
#define FastRead \
ios_base::sync_with_stdio(false); \
cin.tie(0);
#define pi acos(-1)
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
int main()
{
FastRead
char a,b,c;
cin>>a>>b>>c;
cout<<b<<c<<a;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("O3")
#pragma GCC target ("avx,avx2,fma")
#ifdef LOCAL
#define D(a) cerr << #a << " = " << a << endl
#else
#define D(a) 8
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define all(a) (a).begin(),(a).end()
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<long long,long long>;
using vi = vector<int>;
using ll = long long;
pii puntos[200000];
struct momento {
ll a,b,dx,dy;
bool haySwap;
};
momento resultados[200000+1];
int main() {
fastio;
resultados[0].a = 1;
resultados[0].b = 1;
resultados[0].dx = 0;
resultados[0].dy = 0;
resultados[0].haySwap = false;
ll n,m,q;
cin >> n;
forn(i,n) {
cin >> puntos[i].fst;
cin >> puntos[i].snd;
}
cin >> m;
ll numop,p;
forn(i,m) {
cin >> numop;
resultados[i+1] = resultados[i];
switch(numop){
case 1:
swap(resultados[i+1].a,resultados[i+1].b);
swap(resultados[i+1].dx,resultados[i+1].dy);
resultados[i+1].b *= -1;
resultados[i+1].dy *= -1;
resultados[i+1].haySwap = !resultados[i+1].haySwap;
break;
case 2:
swap(resultados[i+1].a,resultados[i+1].b);
swap(resultados[i+1].dx,resultados[i+1].dy);
resultados[i+1].a *= -1;
resultados[i+1].dx *= -1;
resultados[i+1].haySwap = !resultados[i+1].haySwap;
break;
case 3:
cin >> p;
resultados[i+1].dx *= -1;
resultados[i+1].a *= -1;
resultados[i+1].dx += 2*p;
break;
case 4:
cin >> p;
resultados[i+1].dy *= -1;
resultados[i+1].b *= -1;
resultados[i+1].dy += 2*p;
break;
}
}
cin >> q;
ll A,B;
forn(i,q){
cin >> A >> B;
B--;
if(!resultados[A].haySwap)
cout << puntos[B].fst * resultados[A].a + resultados[A].dx << " " << puntos[B].snd * resultados[A].b + resultados[A].dy << endl;
else
cout << puntos[B].snd * resultados[A].a + resultados[A].dx << " " << puntos[B].fst * resultados[A].b + resultados[A].dy << endl;
}
return 0;
}
|
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<double, double> pd;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef map<int, int> mapi;
typedef map<ll, ll> mapl;
double eps = 1e-12;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = a; i > b; i--)
#define repl(i, a, b) for (ll i = a; i < b; i++)
#define perl(i, a, b) for (ll i = a; i > b; i--)
#define maploop(p, i) for (auto i = p.begin(); i != p.end(); i++)
#define Ceil(a, b) (((a % b) == 0) ? (a / b) : ((a / b) + 1))
#define stable [](const auto &a, const auto &b) { return a.fi < b.fi; }
#define ln cout << endl;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define FASTIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define tsolve(t) \
ll t; \
cin >> t; \
while (t--) \
{ \
solve(); \
}
// ==================== Solve =====================
void solve()
{
string s;
cin >> s;
int n = sz(s);
int idx = -1;
rep(i, 0, n)
{
if (s[i] == '.')
{
idx = i;
break;
}
}
if (idx == -1)
{
cout << s << endl;
return;
}
rep(i, 0, idx) cout << s[i];
cout << endl;
}
// ================================================
signed main()
{
FASTIO
//tsolve(t)
solve();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e3+9;
const int MAX=1e2+9;
const double ep=1e-10;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double inf=1e20;
const double pi=acos(-1);
#define debug1 puts("?");
#define debug(x) cout<<"##"<<(x)<<endl;
#define mk make_pair
#define PII pair<int,int>
#define PDI pair<double,int>
#define PIII pair<int,PII >
#define PIII1 pair<PII,int>
#define PIIII pair<PII,PII >
#define PIL pair<int,ll>
#define PLI pair<ll,int>
#define PLIII pair<PLI,PII >
#define PLL pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define dep(i,a,b) for(int i=(a);i>=(b);--i)
#define sd(x) scanf("%d",&(x))
#define slld(x) scanf("%lld",&(x))
#define sdd(x,y) scanf("%d%d",&(x),&(y))
#define sc(s) scanf("%s",(s))
#define pd(x) printf("%d\n",(x))
#define plld(x) printf("%lld\n",(x))
#define pdk(x) printf("%d ",(x))
#define plldk(x) printf("%lld ",(x))
#define pdd(x,y) printf("%d %d\n",(x),(y))
#define PR(x) printf("Case %d: ",(x))
/*
*/
int h,w,n,m;
int a[maxn][maxn],res;
bool vis[maxn][maxn];
void solve()
{
sdd(h,w);
sdd(n,m);
rep(i,1,n)
{
int x,y;
sdd(x,y);
a[x][y]=1;
}
rep(i,1,m)
{
int x,y;
sdd(x,y);
a[x][y]=-1;
}
rep(i,1,h)rep(j,1,w)
{
if(a[i][j]==1)
{
if(!vis[i][j])res++;
vis[i][j]=1;
rep(ii,i+1,h)
{
if(a[ii][j])break;
if(!vis[ii][j])res++;
vis[ii][j]=1;
}
dep(ii,i-1,1)
{
if(a[ii][j])break;
if(!vis[ii][j])res++;
vis[ii][j]=1;
}
rep(jj,j+1,w)
{
if(a[i][jj])break;
if(!vis[i][jj])res++;
vis[i][jj]=1;
}
dep(jj,j-1,1)
{
if(a[i][jj])break;
if(!vis[i][jj])res++;
vis[i][jj]=1;
}
}
}
pd(res);
}
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
int T=1;
// sd(T);
while(T--)solve();
} |
#include<bits/stdc++.h>
#include<bits/extc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
#ifndef DEBUG
#define cerr while(false) cerr
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define priority_queue std::priority_queue
#define F first
#define S second
ll a[50];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, t;
cin>>n>>t;
int k=n/2;
vector<int> v1, v2;
set<ll> sum1, sum2;
for(int i=0;i<n;i++){
cin>>a[i];
if(i<k) v1.push_back(a[i]);
else v2.push_back(a[i]);
}
int sz1=v1.size(), sz2=v2.size();
for(int i=0;i<(1<<sz1);i++){
ll sum=0;
for(int j=0;j<sz1;j++){
if(i&(1<<j)){
sum+=v1[j];
}
}
sum1.insert(sum);
}
for(int i=0;i<(1<<sz2);i++){
ll sum=0;
for(int j=0;j<sz2;j++){
if(i&(1<<j)){
sum+=v2[j];
}
}
sum2.insert(sum);
}
ll ans=0;
for(ll i:sum1){
if(i>t) continue;
auto it=sum2.upper_bound(t-i);
it--;
ans=max(ans, i+(*it));
}
cout<<ans<<endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
int main(){
ll n, t, a; cin >> n >> t;
vector<ll> fa;
vector<ll> la;
REP(i,n) {
cin >> a;
if (i<20) fa.pb(a);
else la.pb(a);
}
sort(fa.rbegin(), fa.rend());
sort(la.rbegin(), la.rend());
ll fsize = fa.size();
ll lsize = la.size();
vector<ll> fcan;
vector<ll> lcan;
REP(i,(1ll<<fsize)) {
ll val = 0;
REP(j,fsize){
if ((i>>j)%2) val += fa[j];
}
fcan.pb(val);
}
REP(i,(1ll<<lsize)) {
ll val = 0;
REP(j,lsize){
if ((i>>j)%2) val += la[j];
}
lcan.pb(val);
}
sort(fcan.rbegin(), fcan.rend());
sort(lcan.begin(), lcan.end());
ll ans = 0;
if (lsize==0) {
sort(fcan.begin(), fcan.end());
auto ind = upper_bound(fcan.begin(), fcan.end(), t);
if (ind==fcan.begin()){
cout << 0 << endl;
}
else {
ind--;
cout << *ind << endl;
}
return 0;
}
REP(i,fcan.size()){
ll nval = fcan[i];
auto ind = upper_bound(lcan.begin(), lcan.end(), t-nval);
if (ind!=lcan.begin()) {
ind--;
ll maxval = *ind;
// cout << nval << " " << maxval << endl;
ans = max(nval+maxval, ans);
}
}
cout << ans << endl;
return 0;
} |
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
// typedef vector<pair<int,int>> vpii;
// typedef vector<vector<int>> vvi;
// typedef vector<vector<char>> vvc;
// typedef vector<vector<string>> vvs;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repll(i, n) for (long long int i = 0; i < n; i++)
#define fin(ans) cout << (ans) << endl
#define P 1000000007
#define STI(s) atoi(s.c_str()) // string to int
#define mp(p, q) make_pair(p, q)
#define Sort(a) sort(a.begin(), a.end())
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int INF = INT_MAX;
const long long LLINF = 1LL << 60;
template <typename T_char>
char ToUpper(char cX) {
return toupper(cX);
}
// g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a) {
ll count = 0;
for (ll i = 0; i < a; i++) {
if (a == 0) {
break;
} else {
a = a / 10;
count++;
}
}
return count;
}
uintmax_t comb(unsigned int n, unsigned int r) {
if (r * 2 > n) r = n - r;
uintmax_t dividend = 1;
uintmax_t divisor = 1;
for (unsigned int i = 1; i <= r; ++i) {
dividend *= (n - i + 1);
divisor *= i;
}
return dividend / divisor;
}
//桁数のカウント
// pow(x,n) == x^n
// sum = accumulate(v.begin(),v.end(),0);
// using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int digsum(int n) {
int res = 0;
while (n > 0) {
res += n % 10;
n /= 10;
}
return res;
}
#include <iomanip>
// vector vの中のn以下の数で最大のものを返す
int bs(vector<ll>& v, vector<ll>& fb, ll k) {
int ok = 0; //これがx以下
int ng = 100000000; // x以上
// 問題によってokとngを入れ替える
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (mid <= k)
ok = mid;
else
ng = mid;
}
return ok;
}
//約数全列挙
vector<long long> divisor_efficiency(long long n) {
vector<long long> ret;
for (long long i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i != 1 && i * i != n) ret.push_back(n / i);
}
}
sort(ret.begin(), ret.end()); // 昇順に並べる
return ret;
}
//素数判定(効率前処理なし)
bool is_prime_efficiency(long long n) { // is n prime or not
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
vector<pair<long long, long long> > prime_factor(long long n) {
vector<pair<long long, long long> > ret;
for (long long i = 2; i * i <= n; i++) {
if (n % i != 0) continue;
long long tmp = 0;
while (n % i == 0) {
tmp++;
n /= i;
}
ret.push_back(make_pair(i, tmp));
}
if (n != 1) ret.push_back(make_pair(n, 1));
return ret;
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
/////////////////////////////////////////////////////
string s;
cin >> s;
int count = 0;
rep(i,9){
if(s.substr(i,4) == "ZONe") count++;
}
cout << count << endl;
//////////////////////////////////////////////////////
return 0;
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define F(i,n) for (int i = 0; i < n; ++i)
#define F1(i,n) for (int i = 1; i <= n; ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define dbgg(x) cerr << #x << " = " << x << ' '
#define T(x) x[pool]
#define mineq(x,y) { if ((x) > (y)) (x) = (y); }
#define maxeq(x,y) { if ((x) < (y)) (x) = (y); }
#define MEOW cout << "meowwwww" << '\n'; system("pause");
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c)
{
s << "[ "; for (auto it : c) s << it << " "; s << "\b]\n";
return s;
}
template<typename T>
ostream& operator <<(ostream &s, const pair<int, T> &c)
{
s << "[ "; cout << c.fi << " , " << c.se << " ] ";
return s;
}
const int maxn = 345678;
int n;
int a[maxn], pre[maxn];
map<int, int> cnt;
void input()
{
ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
F1 (i, n) cin >> a[i];
}
void solve()
{
F1 (i, n) if (i & 1) pre[i] = pre[i - 1] + a[i];
else pre[i] = pre[i - 1] - a[i];
F (i, n + 1) ++cnt[pre[i]];
int ans = 0;
for (auto x : cnt) ans += x.se * (x.se - 1) / 2;
//F (i, n + 1) dbgg(pre[i]);
cout << ans << '\n';
}
main()
{
input();
solve();
}
|
#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include<bits/stdc++.h>
#define Rushia_mywife ios::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define FL cout.flush()
#define all(x) (x).begin(),(x).end()
#define mem(x,i) memset((x),(i),sizeof((x)))
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<long long,long long>;
using ld = long double;
mt19937 mtrd(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1000000007;
const int mod2 = 998244353;
const ld PI = acos(-1);
#define Bint __int128
#define int long long
int qpow(int x,int powcnt,int tomod){
int res = 1;
for(;powcnt;powcnt>>=1,x=(x*x)%tomod)
if(1&powcnt)res = (res*x)%tomod;
return (res%tomod);
}
int inv(int x){ return qpow(x,mod-2,mod); }
// --------------------------------------**
const int N = 2e5+10;
string s;
int sum[26];
void solve(){
cin >> s;
int n = s.size(),ans = 0;
sum[s[n-1]-'a']++;
for(int i=n-2;i>=0;i--){
if(s[i]==s[i+1]){
ans += n-i-1-sum[s[i]-'a'];
mem(sum,0);
sum[s[i]-'a'] = n-i;
}
else
sum[s[i]-'a']++;
}
cout << ans << '\n';
}
signed main(){
Rushia_mywife
int t = 1;
//cin >> t;
while(t--)
solve();
}
| #include<bits//stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <= n; i++)
#define rrep(i,n) for(ll i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
ll mod = 998244353;
int main(){
ll n;cin >>n;
ll ok = 0,ng = 2e9+7;
if(n==1) {
cout << 1 << endl;
return 0;
}
while(ng -ok >1){
ll mid = (ng+ok)/2;
ll sum = mid*(mid+1)/2;
if(sum <= n+1) ok = mid;
else ng = mid;
}cout << n+1-ok << endl;
} |
// In the name of god
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define Sort(x) sort(all(x))
#define debug(x) cerr << #x << " : " << x << "\n"
#define use_file freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef string str;
const ll maxn = 3e5 + 5, mod = 1e9 + 7, inf = 1e18 + 7;
ll n, dp[maxn];
vector <ll> adj[maxn];
bool bl[maxn];
void dfs(ll u){
dp[u] ++;
bl[u] = 1;
vector <ll> v0, v1;
for(ll v : adj[u]){
dfs(v);
if(bl[v])bl[u] = 1 - bl[u];
if(bl[v])v1.pb(dp[v]);
else v0.pb(dp[v]);
}
if(adj[u].size() == 0){
bl[u] = 1;
dp[u] = 1;
return;
}
if(v0.size())Sort(v0);
if(v1.size())Sort(v1);
if(v0.size())reverse(all(v0));
if(v1.size())reverse(all(v1));
while(v0.size()){
if(v0.back() > 0)break;
dp[u] += v0.back();
v0.pop_back();
}
bool b = 1;
while(v1.size()){
if(b)dp[u] += v1.back();
else dp[u] -= v1.back();
v1.pop_back();
b = 1 - b;
}
while(v0.size()){
if(b)dp[u] += v0.back();
else dp[u] -= v0.back();
v0.pop_back();
}
}
int main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
for(ll i = 2; i <= n; i ++){
ll p;
cin >> p;
adj[p].pb(i);
}
dfs(1);
for(ll i = 0; i <= n; i ++){
if(i - (n - i) == dp[1])return cout << i << endl, 0;
}
}
| #include<bits/stdc++.h>
#define LL long long
#define SZ(x) (int)x.size()-1
#define F(i,a,b) for (int i=a;i<=b;++i)
#define DF(i,a,b) for (int i=a;i>=b;--i)
#define pb push_back
#define ms(a,b) memset(a,b,sizeof a)
using namespace std;
int read(){
char ch=getchar(); int w=1,c=0;
for (;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
for (;isdigit(ch);ch=getchar()) c=(c<<3)+(c<<1)+(ch^48);
return w*c;
}
const int M=2e5+10;
int n,dp[M],sz[M];
vector<int> v[M];
bool cmp(int x,int y){
return 2*dp[x]-sz[x]<2*dp[y]-sz[y];
}
void dfs(int x){
sz[x]=dp[x]=1;
vector<int> t;
int tmp=1,t0=0,t1=0;
F(i,0,SZ(v[x])){
int y=v[x][i];
dfs(y);
if (sz[y]&1){
t.pb(y);
}
else{
if (2*dp[y]-sz[y]<0){
tmp+=dp[y];
}
else{
t0+=dp[y];
t1+=sz[y]-dp[y];
}
}
sz[x]+=sz[y];
}
sort(t.begin(),t.end(),cmp);
F(i,0,SZ(t)){
int y=t[i];
if (i&1) tmp+=sz[y]-dp[y];
else tmp+=dp[y];
}
if ((SZ(t)+1)&1) tmp+=t1;
else tmp+=t0;
dp[x]=tmp;
// cout<<x<<" "<<dp[x]<<" "<<sz[x]<<"\n";
}
int main(){
n=read();
F(i,2,n){
int x=read();
v[x].pb(i);
}
dfs(1);
cout<<dp[1]<<"\n";
return 0;
}
|
#include <stdio.h>
inline int read() {
int b = getchar(), c = 0;
int m = b == 45;
if (m) b = getchar();
while (b > 47) {
c = c * 10 + b - 48;
b = getchar();
}
return m ? - c : c;
}
int p[200001];
int main() {
int a[400002];
int n = read(), m = read();
long s = 0;
for (int i = 1; i <= n + n; i++) a[i] = read();
for (int i = 0; i < m + m; i++) p[read()] = 1;
p[1] = 1;
for (int i = 1; i < 200001; i++) {
if (p[i]) s += a[i] - a[i + n];
}
puts(s ? "No" : "Yes");
} | #include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
vector<long long int> diff;
vector<bool> seen;
long long int sum;
void dfs(const Graph &G,int v){
sum += diff[v];
seen[v] = true;
for(auto next_v:G[v]){
if(seen[next_v]) continue;
else dfs(G,next_v);
}
}
int main(){
int N,M;
cin >> N >> M;
vector<long long int> A(N);
for(int i=0;i<N;i++) cin >> A[i];
vector<long long int> B(N);
for(int i=0;i<N;i++) cin >> B[i];
diff.assign(N,0);
for(int i=0;i<N;i++) diff[i] = A[i]-B[i];
Graph G(N,vector<int>(0));
seen.assign(N,false);
for(int i=0;i<M;i++){
int c,d;
cin >> c >> d;
c--;
d--;
G[c].push_back(d);
G[d].push_back(c);
}
bool flag = true;
for(int i=0;i<N;i++){
if(seen[i]) continue;
else{
sum=0;
dfs(G,i);
if(sum != 0){
flag = false;
break;
}
}
}
if(flag) cout << "Yes" << endl;
else cout << "No" << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
int main() {
ll x, y, a, b;
cin >> x >> y >> a >> b;
ll ans = 0;
while (1) {
if (y / a <= x) break;
if (a * x >= y) break;
if (a * x > x + b) break;
x *= a;
++ans;
}
ans += (y - 1 - x) / b;
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define endl '\n'
#define rep(i,a,b) for(i=a;i<b;i++)
#define mod 1000000007
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
const int N = 2e6 + 5;
void solve()
{
ll n, i, aoki = 0, taki = 0, ans = 0;
cin >> n;
ll a[n], b[n];
vector<pair<ll,int>> v(n);
rep(i, 0, n)
{
cin >> a[i] >> b[i];
v[i].F = 2*a[i] + b[i];
v[i].S = i;
aoki += a[i];
}
sort(all(v));
reverse(all(v));
for(i = 0 ; taki <= aoki && i < n; i++)
{
int idx = v[i].S;
taki += a[idx] + b[idx];
aoki -= a[idx];
ans++;
}
cout << ans;
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int t = 1;
//cin >> t;
while(t--)
{
solve();
}
return 0;
} |
#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define pdd pair<double,double>
#define pii pair<int,int>
#define pll pair<LL,LL>
#define mp make_pair
#define LL long long
#define ULL unsigned long long
#define sqr(x) ((x)*(x))
#define pi acos(-1)
using namespace std;
#define MXN 200005
void solve(){
int n;
scanf("%d",&n);
int a[200005],b[200005],p[200005];
for(int i = 0;i<n;i++)scanf("%d",&a[i]);
for(int i = 0;i<n;i++)scanf("%d",&b[i]);
for(int i = 0;i<n;i++)scanf("%d",&p[i]),p[i]--;
for(int i = 0;i<n;i++){
if(a[i]<=b[p[i]]&&p[i]!=i){
printf("-1\n");
return ;
}
}
priority_queue<pii> pq;
for(int i = 0;i<n;i++){
pq.push(mp(a[i],i));
}
vector<pii> ans;
while(!pq.empty()){
pii pp=pq.top();
pq.pop();
while(p[pp.y]!=pp.y){
ans.pb(mp(p[pp.y],pp.y));
swap(p[pp.y],p[p[pp.y]]);
}
}
printf("%d\n",ans.size());
for(auto it:ans){
printf("%d %d\n",it.x+1,it.y+1);
}
}
//a*10 b*10/m
//b*10%m
int main(){
int t=1;
//scanf("%d",&t);
//int n;
while(t--){
solve();
}
}
/*
the first two line contains string "x" followed by two space followed by number one followed by two space followed by string "y".
*/ | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
vector<int> b(n);
for (int i=0;i<n;i++) cin >> a[i];
b = a;
sort(b.begin(),b.end());
reverse(b.begin(),b.end());
int ans = 0;
for (int i=0;i<n;i++) {
int len = 0;
for (int j=0;j<n;j++) {
if (a[j] >= b[i]) {
len++;
}
else {
ans = max(ans,b[i]*len);
len = 0;
}
}
ans = max(ans,b[i]*len);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int decimaltoOctal(int deciNum)
{
int octalNum = 0, countval = 1;
int dNo = deciNum;
while (deciNum != 0) {
int remainder = deciNum % 8;
octalNum += remainder * countval;
countval = countval * 10;
deciNum /= 8;
}
return octalNum;
}
int main() {
int n;
cin>>n;
set<int> s;
for(int i=1; i<=n; i++) {
string deci = to_string(i);
string oct = to_string(decimaltoOctal(i));
for(int j=0; j<deci.length(); j++) {
if(deci[j] == '7') s.insert(i);
}
for(int j=0; j<oct.length(); j++) {
if(oct[j] == '7') s.insert(i);
}
}
cout<<n-s.size()<<endl;
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define be(x) x.begin(), x.end()
using namespace std;
int main()
{
string s;
cin >> s;
for (int i = 1; i < s.size(); i++)
{
cout<<s[i];
}
cout<<s[0]<<endl;
return 0;
}
|
#include<iostream>
#include<vector>
#include<utility>
using namespace std;
int main()
{
int N, D, H;
cin >> N >> D >> H;
vector<pair<int, int>> O(N);
for (size_t i = 0; i < N; i++)
{
cin >> O.at(i).first >> O.at(i).second;
}
double ret = 0;
for (size_t i = 0; i < N; i++)
{
ret = max(ret, O.at(i).second - (H - O.at(i).second) * O.at(i).first / (double)(D - O.at(i).first));
}
cout << ret;
return 0;
} | //FIRST THINK THEN CODE.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M = 1000000007;
const ll MM = 998244353;
ll begtime = clock();
#define end_routine() cerr << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define trace(...)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
template<typename T, typename F>
void chmax( T &a, F b) {
if (b > a)a = b;
}
template<typename T, typename F>
void chmin( T &a, F b) {
if (b < a)a = b;
}
/* if you want to multiply 2 64 bit numbers mod c.
i.e a*b%c.
this function will help in preventing "overflow".
*/
ll mulmod(ll a, ll b, ll c) {
ll ans = 0;
ll y = a % c;
while (b) {
if (b & 1) {
(ans += y) %= c;
}
y = y * 2 % c;
b >>= 1;
}
return ans;
}
ll powM(ll a, ll b, ll m)
{
if (b < 0)return 0;
if (a <= 0)return 0;
a %= m;
ll ans = 1LL;
while (b)
{
if (b & 1)ans = ans * a % m;
//ans = mulmod(ans, a, m);
a = a * a % m;
//a = mulmod(a, a, m);
b >>= 1;
}
return ans;
}
ll powMbig(ll a, ll b, ll m)
{
if (a <= 0)return 0;
a %= m;
ll ans = 1LL;
while (b)
{
if (b & 1)//ans = ans * a % m;
ans = mulmod(ans, a, m);
//a = a * a % m;
a = mulmod(a, a, m);
b >>= 1;
}
return ans;
}
ll poww(ll a, ll b)
{
ll ans = 1;
while (b)
{
if (b & 1)ans = ans * a;
a = a * a;
b >>= 1;
}
return ans;
}
string tostring(ll x) {
stringstream sss;
sss << x;
string ans = sss.str();
return ans;
}
const ll N = 1e6 + 5;
ll gandu(ll c) {
return (c * (c - 1) / 2);
}
int main() {
IOS;
#ifndef ONLINE_JUDGE
freopen("input1.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
#endif
ll n, x;
cin >> n >> x;
string s; cin >> s;
FOR(i, n) {
if (s[i] == 'o')x++;
else x = max(x - 1, 0ll);
}
cout << x;
return 0;
}
|
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;
//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX_N; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(ll n, ll k) {
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// mod.m での a の逆元 a^ { -1 } を計算する
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 gcd(ll x, ll y) {
return y ? gcd(y, x % y) : x;
}
ll lcm(ll x, ll y) {
if (x == 0 || y == 0)return 0;
return (x / gcd(x, y) * y);
}
//union-find木について
ll par[101010];
ll rank2[101010];
void init(ll n) {
rep(i, n) {
par[i] = i;
rank2[i] = 0;
}
}
ll find(ll x) {
if (par[x] == x) {
return x;
}
else {
return par[x] = find(par[x]);
}
}
void unite(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y)return;
if (rank2[x] < rank2[y]) {
par[x] = y;
}
else {
par[y] = x;
if (rank2[x] == rank2[y]) {
rank2[x]++;
}
}
}
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll move[201010];
//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
ll ans = INF;
rep(i, 4) {
ll a;
cin >> a;
ans = min(ans, a);
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <math.h>
using namespace std;
const int COUNT_A = 100;
int a[4];
int n = 0;
int min(int a, int b) {
if (a > b) {
return b;
}
return a;
}
int main() {
cin >> a[0] >> a[1] >> a[2] >> a[3];
n = min(a[0], min(a[1], min(a[2], a[3])));
printf("%d",n);
} |
//Author: Fuadul Hasan([email protected])
//BSMRSTU,Gopalganj
//#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <random>
#include <cassert>
#include <cstring>
#include <sstream>
#include <complex>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;
//int input........
template <typename T> inline void readline(T &n) {n = 0; int f = 1; register int ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readline(T &n, TT &m) { readline(n); readline(m); }
template <typename T, typename TT, typename TTT> inline void readline(T &n, TT &m, TTT &l) { readline(n, m); readline(l);}
// long long input........
template <typename T> inline void readlinel(T &n) {n = 0; long long f = 1; register long long ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readlinel(T &n, TT &m) { readlinel(n); readlinel(m); }
template <typename T, typename TT, typename TTT> inline void readlinel(T &n, TT &m, TTT &l) { readlinel(n, m); readlinel(l);}
//debug..........
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}
//............ignore it..................//
#define F first
#define S second
#define Pi atan(1)*4
#define mp make_pair
#define pb push_back
const int M = 1e9 + 7;
#define ll long long int
#define happy cin.tie(0);
#define point(x) setprecision(x)
void Print(int n){printf("%d ", n);}
void print(int n){printf("%d\n", n);}
#define Test printf("Case %d: ",tc++);
int length(string s){return s.size();}
void print(ll n){printf("%I64d\n", n);}
void Print(ll n){printf("%I64d ", n);}
#define coding ios::sync_with_stdio(false);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
void print(int n,int m){printf("%d ",n);printf("%d ",m);}
void print(ll n,ll m){printf("%I64d ",n);printf("%I64d ",m);}
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
int length(long long x){int l = 0;for(long long i=x;i;i/=10)l++;return l;}
int dx[8]= {1,0,-1,0,-1,-1,1,1};int dy[8]= {0,1,0,-1,-1,1,-1,1}; int tc = 1;
void print(int n,int m,int k){printf("%d ",n);printf("%d ",m);printf("%d ",k);}
void print(ll n,ll m,ll k){printf("%I64d ",n);printf("%I64d ",m);printf("%I64d ",k);}
long long pow(long long a,long long n){ll res = 1;while(n){if(n&1) res = ((res%M)*(a%M))%M;a = ((a%M)*(a%M))%M;n>>=1;}return res%M;}
template<class T> bool remin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool remax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
#define pr pair<int, int>
#define vpr vector<pr>
#define vi std::vector<int>
#define vll std::vector<ll>
#define all(n) n.begin(),n.end()
const int Inf = (int)2e9 + 5;
const ll Lnf = (ll)2e18 + 5;
const int N = 5e3 + 5;
const int NN = 1e6 + 5;
int solve()
{
//happy coding
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<min(a,min(b,min(c,d)))<<endl;
return 0;
//error();
}
int main(){
int test = 1;
//readline(test);//(void)getchar();
while (test--)solve();return 0;
} | // Username: WillTheBill
// Time of creation: 2020-11-22 12:49
// 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);
int a,b,c,d; re(a,b,c,d);
int res = 3;
if(a==c&&b==d) res = 0;
if(a + b == c + d) res = min(res, 1ll);
if(a - b == c - d) res = min(res, 1ll);
if(abs(a-c) + abs(b - d) <= 3) res = min(res, 1ll);
for(int i = a - 10; i <= a + 10; i++){
for(int j = b - 10; j <= b + 10; j++){
if(!(i + j == a + b || i - j == a - b || abs(i - a) + abs(j - b) <= 3)) continue;
if(i == c && j == d) res = min(res, 1ll);
if(i + j == c + d) res = min(res, 2ll);
if(i - j == c - d) res = min(res, 2ll);
if(abs(i - c) + abs(j - d) <= 3) res = min(res, 2ll);
}
}
if((a + b) % 2 == (c + d) % 2){
res = min(res, 2ll);
}
/*int l = -1e10, r = 1e10;
while(l <= r){
int m = (l + r) / 2;
int d1 = abs(a + m - c) + abs(b + m - d);
if(d1 == 0){
res = min(res, 1ll);
}
if(d1 <= 3){
res = min(res, 2ll);
break;
}
int d2 = abs(a + m + 1 - c) + abs(b + m + 1 - d);
if(d2 < d1){
l = m + 1;
}else{
r = m - 1;
}
}
l = -1e10, r = 1e10;
while(l <= r){
int m = (l + r) / 2;
int d1 = abs(a + m - c) + abs(b - m - d);
if(d1 == 0){
res = min(res, 1ll);
}
if(d1 <= 3){
res = min(res, 2ll);
break;
}
int d2 = abs(a + m + 1 - c) + abs(b - (m + 1) - d);
if(d2 < d1){
l = m + 1;
}else{
r = m - 1;
}
}*/
pr(res);
}
|
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <queue>
#include <numeric>
using namespace std;
using ll = long long;
#define For(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFor(i,a,b) for(ll i=(a);i>=(ll)(b);i--)
#define co(a) cout<<a<<endl
#define Sort(a) sort((a).begin(),(a).end())
#define Rev(a) reverse((a).begin(),(a).end())
#define Unique(a) (a).erase(unique((a).begin(), (a).end()),(a).end())
#define cfs(a) cout<<fixed<<setprecision(a)
ll N;
vector<bool> ans(100005);
vector<ll> check(100005);
void dfs(vector<ll> &coler,vector<vector<ll>> &ki,ll now, ll bef) {
if (0 == check[coler[now - 1]]) {
ans[now] = true;
}
check[coler[now - 1]]++;
For(i, 0, ki[now].size()) {
if (ki[now][i] != bef) {
dfs(coler, ki, ki[now][i], now);
}
}
check[coler[now - 1]]--;
}
int main() {
//ll N;
cin >> N;
vector<ll> coler(N); //colerだけ0から
For(i, 0, N) {
cin >> coler[i];
}
vector<vector<ll>> ki(N+1, vector<ll>(0));
ll A, B;
For(i, 0, N - 1) {
cin >> A >> B;
ki[A].push_back(B);
ki[B].push_back(A);
}
check[coler[0]] = 1;
ans[1] = true;
For(i, 0, ki[1].size()) {
dfs(coler, ki, ki[1][i], 1);
}
For(i, 0, N + 1) {
if (ans[i]) {
co(i);
}
}
} | #include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
//const int inf = 1e18;
//const int mod = 998244353;
const int mod = 1e9 + 7;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
const int maxn = 1e6 + 10;
const int N = 6e6 + 100;
int c[maxn];
vector<int > e[maxn];
int vis[maxn];
int g[maxn];
void dfs(int x,int fa){
if (vis[c[x]]==0) g[x]=1;
vis[c[x]]++;
for(auto v:e[x]) if (fa!=v) dfs(v,x);
vis[c[x]]--;
}
void solve() {
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>c[i];
for (int i = 0; i < n - 1; ++i) {
int u,v;
cin>>u>>v;
e[u].push_back(v);
e[v].push_back(u);
}
dfs(1,0);
for (int i = 1; i <=n; ++i)
if (g[i]) cout<<i<<"\n";
}
signed main() {
//ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();//cout<<"\n";
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define f(i,j,n) for(int i = j; i <= n; i++)
#define r(i,n,j) for(int i = n; i >= j; i--)
#define all(container) container.begin() , container.end()
#define sz(container) (int)container.size()
#define ff first
#define ss second
#define pii pair <int , int>
#define sp(x) setprecision(x)
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
#define T int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
int power(int x, int y, int p)
{
int 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;
}
int32_t main()
{
fast
ld x,y,a,b;
cin>>x>>y>>a>>b;
if(x>a) {
swap(x,a);
swap(y,b);
}
ld d=abs(x-a);
ld m= b*d;
m=m/(ld)(y+b);
cout<<fixed<<sp(10)<<a-m;
} | #include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
ll gcdmax=max(a,b);
ll gcdmin=min(a,b);
while(true){
if(gcdmax%gcdmin==0)break;
else gcdmax%=gcdmin;
swap(gcdmin,gcdmax);
}
return gcdmin;
}
ll powerup(ll N,ll P,ll M){
if(P==0)return 1;
else if(P%2==0){
ll t=powerup(N,P/2,M);
return t*t%M;
}
else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
ll k=1;
while(k*k<=N){
k++;
}
vector<ll> A(1);
rep(i,k){
if(i==1)A.at(0)=1;
else if(i>=2){
if(N%i==0)A.push_back(i);
}
}
ll t=0;
t=A.size();
rep(i,t){
if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
}
return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
rep(i,N+1){
if(i==0){
fac.push_back(1);
finv.push_back(1);
inv.push_back(1);
}
else if(i==1){
fac.push_back(1);
finv.push_back(1);
inv.push_back(1);
}
else{
fac.push_back(fac.at(i-1)*i%P);
inv.push_back(P-inv.at(P%i)*(P/i)%P);
finv.push_back(finv.at(i-1)*inv.at(i)%P);
}
}
}
ll COM(ll n,ll k,ll P){
if(n<k)return 0;
if(n<0||k<0)return 0;
return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}
struct UnionFind {
vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化
for(ll i = 0; i < N; i++) par[i] = i;
}
ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(ll x, ll y) { // xとyの木を併合
ll rx = root(x); //xの根をrx
ll ry = root(y); //yの根をry
if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
}
bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
ll rx = root(x);
ll ry = root(y);
return rx == ry;
}
};
int main(){
ld sx,sy,gx,gy;
cin>>sx>>sy>>gx>>gy;
cout<<fixed<<setprecision(7)<<sx*(gy/(sy+gy))+gx*(sy/(sy+gy))<<endl;
}
|
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
ll x=0,f=1;
char ch=getchar();
while(!isdigit(ch))f^=ch=='-',ch=getchar();
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f?x:-x;
}
#define all(x) (x).begin(),(x).end()
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
int a[100010],b[100010];
std::vector<ll>A,B;
int main(){
#ifdef LOCAL
freopen("in.in","r",stdin);
//freopen("out.out","w",stdout);
#endif
int n=gi();
ll sa=0;
for(int i=1;i<=n;++i)sa+=a[i]=gi();
for(int i=1;i<=n;++i)b[i]=gi()-a[i];
A.resize(n/2+1),B.resize(n/2+1);
for(int i=1,j=1;i<=n;i+=2,++j)A[j]=b[i],B[j]=b[i+1];
std::sort(A.begin()+1,A.end(),std::greater<ll>());
std::sort(B.begin()+1,B.end(),std::greater<ll>());
for(int i=1;i<=n/2;++i)A[i]+=A[i-1],B[i]+=B[i-1];
ll ans=0;for(int i=0;i<=n/2;++i)cxk(ans,A[i]+B[i]);
printf("%lld\n",ans+sa);
return 0;
}
| #include <bits/stdc++.h>
// ifブロックはインデントがいる
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define repp(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
#define all(v) v.begin(), v.end()
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<long long, long long>;
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using PP = pair<ll, P>;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
vector<vector<ll> > g, dist;
vector<vector<vector<ll>>> predicted_cost;
vector<vector<P>> pre;
const ll h = 30, w = 30;
void dijkstra(int sx, int sy) {
dist = vector<vector<ll> >(h, vector<ll>(w, INF));
pre = vector<vector<P> >(h, vector<P>(w, P(-1, -1)));
dist[sx][sy] = 0;
priority_queue<PP, vector<PP>, greater<PP> > pq;
pq.push(PP(0, P(sx, sy)));
while (!pq.empty()) {
PP p = pq.top();
pq.pop();
ll c = p.first;
ll vx = p.second.first, vy = p.second.second;
rep(i, 4) {
ll nx, ny;
nx = vx + dx[i], ny = vy + dy[i];
if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
if (dist[nx][ny] <= g[nx][ny] + c) continue;
dist[nx][ny] = g[nx][ny] + c;
pre[nx][ny] = P(vx, vy);
pq.push(PP(dist[nx][ny], P(nx, ny)));
}
}
}
vector<P> restore(ll tx, ll ty) {
vector<P> path;
ll x, y;
for (; tx != -1 || ty != -1; tx = pre[x][y].first, ty = pre[x][y].second) {
path.push_back(P(tx, ty));
x = tx, y = ty;
}
reverse(path.begin(), path.end());
return path;
}
char compare_pos(P s, P t) {
if (s.first < t.first)
return 'D';
if (s.first > t.first)
return 'U';
if (s.second < t.second)
return 'R';
if (s.second > t.second)
return 'L';
}
ll vector_average(vector<ll> &cost){
ll sum = accumulate(all(cost),0LL);
return sum / cost.size();
}
//ミョ(-ω- ?)
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
g.resize(30);
predicted_cost.resize(30);
rep(i, 30) {
g[i].resize(30);
predicted_cost[i].resize(30);
rep(j, 30) g[i][j] = 6000;
}
rep(q,1000){
P s,t;
cin >> s.first >> s.second >> t.first >> t.second;
dijkstra(s.first, s.second);
auto rstr = restore(t.first, t.second);
rep(i, rstr.size() - 1) { cout << compare_pos(rstr[i], rstr[i + 1]); }
cout << endl;
ll len;
cin >> len;
if(rstr.size())len /= rstr.size();
rep(i, rstr.size() - 1) {
predicted_cost[rstr[i].first][rstr[i].second].push_back(len);
if(q > 100)g[rstr[i].first][rstr[i].second] = vector_average(predicted_cost[rstr[i].first][rstr[i].second]);
}
}
return 0;
}
/*グラフ情報とは別に、パス長からの平均を順次格納していった2+1次元の配列をやりながら、その平均値を取って暫定の頂点間距離にするといい感じに収束していくのでは
-> 84163614602
パス長から乱数パラメーターのV_ip,H_ipを求められれば道のコストの尤度が大きくなって幸せになる
クエリの点数計算式 round(2312311 * \sigma_{k=1}^1000 {0.998^{1000-k} * a_k / b_k})から、序盤より後半のak / bkが重視される
序盤でより正確な道のコストを求められれば点数の改善ができる
パスに関して、M=1のときはパスの評価値に平均を使えるけど、M=2のときはyj(ramdom)によって[0,yj),[yj,2]
*/ |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll solve() {
ll A, B;
cin >> A >> B;
ll d = B-A;
ll ans = 0;
for ( ll d = B-A; d > 0; d-- ) {
if ( B/d != (A%d==0 ? A/d : (A/d+1)) ) {
return d;
}
}
return 1;
}
int main() {
auto ans = solve();
cout << ans << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<pll> vll;
typedef vector<vl> vvl;
#define fori(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define trav(x, a) for (auto &x : a)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define sz(a) (int)(a).size()
#define fi first
#define se second
clock_t time_p = clock();
void time_taken()
{
time_p = clock() - time_p;
cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
const ll mod = 1e9 + 7;
const ll INF = 1e18;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
int main()
{
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int R, C;
cin >> R >> C;
vii adj[R * C];
fori(i, R) fori(j, C - 1)
{
int from = i * C + j;
int to = i * C + (j + 1);
int w;
cin >> w;
adj[from].pb({to, w});
adj[to].pb({from, w});
}
fori(i, R - 1) fori(j, C)
{
int from = i * C + j;
int to = (i + 1) * C + j;
int w;
cin >> w;
adj[from].pb({to, w});
}
min_heap<pair<ll, int>> pq;
pq.push({0, 0});
vl d(R * C, INF);
d[0] = 0;
while (!pq.empty())
{
auto [dis, at] = pq.top();
pq.pop();
auto [r, c] = make_pair(at / C, at % C);
if (d[at] < dis)
continue;
for (auto [to, w] : adj[at])
{
if (d[to] > d[at] + w)
{
d[to] = d[at] + w;
pq.push({d[to], to});
}
}
for (int to = 0; to < r; to++)
{
int tto = to * C + c;
int cost = r - to + 1;
if (d[tto] > d[at] + cost)
{
d[tto] = d[at] + cost;
pq.push({d[tto], tto});
}
}
}
cout << d.back() << endl;
time_taken();
return 0;
} |
#include <bits/stdc++.h>
#define ll long long
#define sf scanf
#define pf printf
#define nl printf("\n")
#define pb push_back
#define TEST int Test;cin>>Test;for(int _t=1;_t<=Test;_t++)
using namespace std;
int main()
{
int a,b,c,d;
sf("%d %d %d %d",&a,&b,&c,&d);
double theta = (atan((double)(c-a)/(double)(b+d)));
double x = (b*tan(theta))+a;
pf("%lf\n",x);
return 0;
}
| #include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;
int main(){
double sx,sy,gx,gy;
cin >> sx >> sy >> gx >> gy;
gy=-gy;
double ans=sx-(sy*(gx-sx)/(gy-sy));
cout << fixed << setprecision(8) << ans << endl;
} |
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep1(i, n) for (int i = n; i >= 1; i--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define eb emplace_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
typedef long long int ll;
typedef pair<ll, ll> P;
// typedef modint1000000007 mint;
void speedUpIO() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
/*--------------------------------------------------*/
const int INF = 1e9;
const ll LINF = 2e18;
const int MAX = 100010;
void solve() {
ll k, n, m;
cin >> k >> n >> m;
V<ll> a(k);
rep(i, k) cin >> a[i];
V<ll> b(k);
rep(i, k) b[i] = a[i] * m / n;
ll d = m - accumulate(all(b), 0LL);
V<P> bp(k);
rep(i, k) bp[i] = P(m * a[i] % n, i);
sort(rall(bp));
rep(i, d) {
int j = bp[i].se;
b[j]++;
}
rep(i, k) {
cout << b[i] << " ";
}
cout << "\n";
}
int main() {
speedUpIO();
int t = 1;
// cin >> t;
while (t--) {
solve();
// cout << solve() << "\n";
// cout << (solve() ? "Yes" : "No") << "\n";
// cout << fixed << setprecision(15) << solve() << "\n";
}
return 0;
}
| //#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
if (ci - owa > 0) {
memcpy(cn, owa, CL);
ci -= CM;
fread(cn + CL, 1, CM, stdin);
}
ll tmp = *(ll*)ci;
if ((tmp & ma0) ^ ma0) {
int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
tmp = tmp << dig & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += (72 - dig >> 3);
}
else {
tmp = tmp & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += 8;
if ((ct = *ci++) >= '0') {
tmp = tmp * 10 + ct - '0';
if (*ci++ == '0') {
tmp = tmp * 10;
ci++;
}
}
}
return tmp;
}
int tmp[200001];
void pakuri_sort(int N, int A[]) {
const int b = 8;
rep(k, 4) {
int kazu[1 << b] = {}, kazu2[1 << b] = {};
rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
k++;
rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
}
}
int main() {
//cin.tie(0);
//ios::sync_with_stdio(false);
int N = getint(), M = getint();
int A[200010];
rep1(i, M) A[i] = getint();
A[0] = 0;
A[M + 1] = N + 1;
pakuri_sort(M, A + 1);
int mae = 0;
int saishou = 2e9;
int t = 0;
rep(i, M + 1) {
int kari = A[i + 1] - A[i] - 1;
if (kari) {
if (kari < saishou) saishou = kari;
tmp[t++] = kari;
}
}
if (saishou > 1.5e9) {
printf("0");
return 0;
}
ll kotae = 0;
rep(i, t) kotae += (tmp[i] + saishou - 1) / saishou;
printf("%d\n", kotae);
Would you please return 0;
} |
/*****author: maxifier******/
#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <stack>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
#include <queue>
using namespace std;
#define int long long int
#define emp emplace_back
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define lb lower_bound
#define ub upper_bound
const int inf = 1e18;
const int32_t m = 1e9 + 7;
const int32_t mm = 998244353;
void maxifier() {
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int x = b[0] - a[n - 1];
cout << ((x) >= 0 ? (x + 1) : 0);
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int tc, t = 0;
tc = 1;
//cin >> tc;
while (tc--) {
//++t;
//cout << "Case" << " " << "#" << t << ":" << " ";
maxifier();
}
return 0;
} | //Hare Krishna
//author: Dipjoy Basak
//dip_10
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define int ll
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int, int>
#define vpi vector<pair<int, int>>
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define rrep(i, r, l) for (int i = r; i >= l; i--)
#define readarray(a,n) rep(i,0,n-1)cin>>a[i];
#define all(v) v.begin(), v.end()
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x<<" "; _print(x); cerr << endl;
#else
#define debug(x);
#endif
#define INF INT_MAX
//*----------------------------------------DEBUG functions--------------------------*
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(ld t) {cerr << t;}
void _print(double t) {cerr << 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) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
//-----------------------------------------------------------------------------------------------------------------------------
const int mod=1000000007;
const int maxn=100005;
int x,y,z,n,k;
void solve()
{
string s;
cin>>s;
reverse(s.begin(),s.end());
rep(i,0,s.size()-1){
if(s[i]=='9'){
cout<<'6';
}else if(s[i]=='6'){
cout<<'9';
}else{
cout<<s[i];
}
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout << setprecision(15) << fixed;
int t;
t = 1;
// cin >> t;
while (t--)
{
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (ll i = x; i < y; i++)
#define DEC(i, x, y) for (ll i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
using namespace std;
// Some typedef's
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
ll lcm(ll a, ll b) { return (a * (b / __gcd(a, b))); }
// Some constants
const int inf = 1e9 + 7;
const double eps = 1e-6;
const double pi = 1.00 * acos(-1.00);
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(ll t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << 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) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
void solve()
{
int n;
cin>>n;
map<int,int> mp;
rep(n)
{
int x;
cin>>x;
mp[x]++;
}
for(int i=1;i<=n;i++)
{
if(mp[i]==0)
{
cout<<"No\n";
return;
}
}
cout<<"Yes\n";
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("Error.txt", "w", stderr);
freopen("Input.txt","r",stdin);
freopen("Output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(false);cin.tie(NULL);
ll t = 1;
//cin >> t;
while (t--)
{
solve();
}
return 0;
} | #include <algorithm>
#include <array>
#include <bitset>
#include <deque>
#include <forward_list>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <ostream>
#include <queue>
#include <regex>
#include <set>
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define int long long
#define si(v) size(v)
#define all(v) begin(v), end(v)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, n, m) for (int i = (n); i <= (m); ++i)
#define rep3(i, n, m) for (int i = (n); i >= (m); --i)
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define pb push_back
template <class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T,vector<T>,greater<T>>;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using pii = pair<int,int>;
using vpi = vector<pii>;
constexpr ll INF = 2000000000;
constexpr ll INFLL = 2000000000000000000;
constexpr ll MAX = 500005;
constexpr ll MOD = 1000000007;
signed main(void)
{
ios::sync_with_stdio(false);
cin.tie();
cout << fixed << setprecision(15);
int n; cin >> n;
vi a(n);
rep(i, n) cin >> a[i];
vi s(n+1, 0);
rep(i, n) s[i+1] += s[i] + a[i];
vi mx(n+1, 0);
rep(i, n) chmax(mx[i+1], max(s[i+1], mx[i]));
int now = 0, ans = 0;
rep(i, n) {
int ma = now + mx[i+1];
now += s[i+1];
chmax(ans, ma);
}
cout << ans << endl;
return (0);
}
|
#include <bits/stdc++.h>
using namespace std;
double eps = 1e-9;
double pi = acos(-1);
int fx[8] = {1, -1, 0, 0, 1, -1, -1, 1};
int fy[8] = {0, 0, 1, -1, 1, -1, 1, -1};
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define ull unsigned long long
#define en "\n"
#define ff first
#define ss second
#define sp(x) fixed << setprecision(x)
#define VECT(v) vector<int>v
#define SCAN(v) int temp; for(int i=0; i<n; i++) {cin>>temp; v.push_back(temp);}
#define PRINT(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << en;
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.begin(), v.end(), greater<int>())
#define CASEP(v) cout<<"Case "<<tc<<": "<<v<<"\n"
#define DEBUG(v) cout << v << " "; cout << en;
#define MIN(a, b) a < b ? a : b
#define MAX(a, b) a > b ? a : b
#define mem(a, b) memset(a, b, sizeof(a))
#define valid(nx, ny, row, col) nx >= 0 && nx < row && ny >= 0 && ny < col
#define pii pair <int, int>
#define inf (int)2e9
#define mod (int)1e9 + 7
int main(void)
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
fast_io
int a, b, c;
cin >> a >> b >> c;
if(a * a + b * b < c * c)
cout << "Yes\n";
else
cout << "No\n";
return 0;
} | #include <iostream>
using namespace std;
int main(){
int a,b,c; cin>>a>>b>>c;
a*=a;
b*=b;
c*=c;
if(c>a+b)cout<<"Yes";
else cout<<"No";
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
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; }
const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
int main(){
int N;
cin >> N;
vector<ll> A(N);
map<ll,ll> mp;
ll a;
ll po = 1;
ll tmp = 0;
REP(i,N){
cin >> a;
A[i] = po * a;
po *= -1;
tmp += A[i];
if(mp.count(tmp)) mp[tmp] ++;
else mp[tmp] = 1;
}
ll ans = 0;
tmp = 0;
REP(i,N-1){
if(mp.count(tmp)) ans += mp[tmp];
tmp += A[i];
mp[tmp] --;
}
cout << ans << endl;
return 0;
} | #include<iostream>
#include<cstdio>
#include<map>
#include<bitset>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<ctime>
using namespace std;
#define M 300005
#define N 1000005
#define MP make_pair
#define debug() cerr<<"Why So Serious?"<<endl
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
template<class T>void Rd(T &x){
x=0;static char c;
while(c=getchar(),c<48);
do x=(x<<1)+(x<<3)+(c^48);
while(c=getchar(),c>47);
}
int n;
int A[M];
int Sum[2][M];
map<ll,int>S;
int main(){
Rd(n);
int a=0;
ll sum0=0,sum1=0;
ll ans=0;
S[0]=1;
for(int i=1;i<=n;++i){
Rd(a);
if(i&1)sum1+=a;
else sum0+=a;
ll res=sum1-sum0;
if(S.find(res)!=S.end())ans+=S[res];
else if(S.find(res)==S.end())S[res]=0;
S[res]++;
}
printf("%lld\n",ans);
return 0;
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll LINF = 1e18;
template <class T>
void get_unique(vector<T>& x) {
x.erase(unique(x.begin(), x.end()), x.end());
}
template <class T>
bool chmax(T& a, const T& b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
for (int i = 0; i < int(v.size()); i++) {
is >> v[i];
}
return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
for (int i = 0; i < int(v.size()); i++) {
os << v[i];
if (i < sz(v) - 1) os << ' ';
}
return os;
}
int main() {
int n;
cin >> n;
vector<int> a(n), b(n), p(n), invp(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
rep(i, n) {
cin >> p[i];
p[i]--;
invp[p[i]] = i;
}
vector<pair<int, int>> ans;
vector<int> idx(n);
rep(i, n) idx[i] = i;
sort(all(idx), [&](int i, int j) { return a[i] < a[j]; });
for (int i : idx) {
if (p[i] == i) continue;
if (a[i] <= b[p[i]]) {
cout << -1 << '\n';
return 0;
}
ans.emplace_back(i, invp[i]);
swap(p[invp[i]], p[i]);
swap(invp[p[i]], invp[p[invp[i]]]);
}
cout << sz(ans) << '\n';
for (auto [i, j] : ans) {
cout << ++i << ' ' << ++j << '\n';
}
} | #include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
/* template */
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
void debug_out() { std::cout << std::endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cout << H << " ";
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
struct Edge{
int to;
ll weight;
Edge(int t, ll w) : to(t), weight(w){ }
};
struct edge{
int from;
int to;
ll weight;
edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;
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;
}
constexpr ll LNF = 1LL<<50;
constexpr int INF = 1e9+7;
const long double PI=acos(-1);
vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};
/* template */
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
vector<ll> a(4);
rep(i,0,4){
cin >> a[i];
}
sort(all(a));
if(a[3]==a[1]+a[0]+a[2] || a[3]+a[0]==a[1]+a[2] || a[3]+a[1]==a[0]+a[2] || a[3]+a[2]==a[1]+a[0]){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
return 0;
} |
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
#define int long long
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define F first
#define S second
#define SZ(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define LINE cout << "\n---------------\n";
#define endl cout << '\n';
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define debug(x) cerr << #x << " = " << x << '\n';
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
int dp[(1<<19)];
struct T
{
int X,Y,Z;
T(int _x , int _y , int _z):X(_x) , Y(_y) , Z(_z){}
T(){}
};
vector<T> limit;
signed main(){
IOS;
int n , m ;
cin >> n >> m ;
for(int i=0 ; i<m ; ++i){
int x,y,z;
cin >> x >> y >> z;
limit.push_back({x,y,z});
}
//basic
dp[0]=1;
//dp
for(int i=1 ; i<(1<<n) ; ++i){
int bits=0;
for(int j=0 ; j<n ; ++j){
bits += (i >> j & 1);
}
bool ok = 1;
for(int j=0 ; j<m ; ++j){
int x = limit[j].X , y = limit[j].Y , z = limit[j].Z;
if(bits <= x){
int cnt=0;
for(int k=0 ; k<y ; ++k) cnt += (i >> k & 1);
if(cnt > z) ok = 0;
}
}
if(ok){
for(int j=0 ; j<n ; ++j){
if(i >> j & 1){
dp[i] += dp[i ^ (1<<j)];
}
}
}
// cout << dp[i] << '\n';
}
cout << dp[(1<<n)-1] << '\n';
} | #include<iostream>
#include<vector>
using namespace std;
#define popcount __builtin_popcount
int main(){
int n,m;
cin>>n>>m;
int xyz[110][3];
for(int i=0;i<m;i++)for(int j=0;j<3;j++)cin>>xyz[i][j];
int n2=1<<n;
long long mask[110]={0};
vector<long long> dp(n2);
for(int i=0;i<n;i++)mask[i+1]=mask[i]<<1|1;
dp[0]=1;
for(int s=0;s<n2;s++){
int x=popcount(s);
for(int i=0;i<m;i++){
if(x==xyz[i][0])
if(popcount(s&mask[xyz[i][1]])>xyz[i][2])dp[s]=0;
}
for(int i=0;i<n;i++){
if(~s>>i&1){
dp[s|1<<i]+=dp[s];
}
}
}cout<<dp.back()<<endl;
return 0;
}
|
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) for(auto x:obj)cout<<x<<' ';cout<<endl;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> lp;
typedef pair<double, double> FP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;
ll x, y;
map<ll, ll> costs;
ll A,D;
ll solve(ll N){
if(N == 0)return abs(x);
if(N == x)return 0;
if(costs.count(N) != 0)return costs[N];
ll res = INF;
if(N < INF/D)res = abs(N-x)*D;
//div2
{
ll to = N/2*2;
ll tou = to + 2;
res = min(res, solve(to/2)+ A + abs(N-to)*D);
if(tou/2 < N)res = min(res, solve(tou/2) + A + abs(N-tou)*D);
}
return costs[N] = res;
}
int main(){
cin >> x >> y;
if(x >= y){
cout << x-y << endl;
return 0;
}
A = 1; D = 1;
cout << solve(y) << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ff first
#define brn "\n"
#define ss second
#define mk make_pair
#define int long long
#define pb push_back
#define pf push_front
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(x) int x; cin>>x; while(x--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define so(a,n) sort(a,a+n)
#define rso(a,n) sort(a,a+n),reverse(a,a+n)
#define all(v) (v).begin(),(v).end()
#define ps(x,y) fixed<<setprecision(y)<<x
#define sz size();
#define p_sieve 10000007
const int maxn = 1e3 + 5;
const int modulo = 1000000007;
#define mod 1000000009;
const double pi = 3.14159;
#define INF 1000001000
#define imx 9999999999999999
#define imi -9999999999999999
//check n==1 and base cases//
//********************************---------always check array boundness-----------****************
// factorial ncr
// int printNcR(int n, int r)
// {
// if (n < r)return 0;
// long long p = 1, k = 1;
// if (n - r < r)
// r = n - r;
// if (r != 0) {
// while (r) {
// p *= n;
// k *= r;
// long long m = __gcd(p, k);
// p /= m;
// k /= m;
// n--;
// r--;
// }
// }
// else p = 1;
// return p;
// }
// int power(int x, unsigned int y)
// {
// int res = 1;
// //x = x % modulo;
// if (x == 0) return 0;
// while (y > 0)
// {
// if (y & 1) res = (res * x);
// y = y >> 1;
// x = (x * x);
// }
// return res;
// }
// const int N = 1e4 + 5;
// int dp[N];
// bool prime[N];
// std::vector<int> v;
// bool prime[N];
// void precompute()
// {
// memset(prime , 1, sizeof(prime));
// prime[0] = 0;
// prime[1] = 0;
// for (int i = 2; i * i <= N; i++)
// {
// if (prime[i] == 1)
// for (int j = i * i; j <= N; j += i )prime[j] = 0;
// }
// }
// generating subsets..
// for ( int i = 0 ; i < ( 1 << m ) ; ++ i )
// {
// for ( int j = 0; j < m ; ++ j )
// {
// if ( ( i & ( 1 << j ) ) != 0)
// {
// }
// }
// }
// int msb(unsigned a) {
// return __lg(a ^ (a & (a - 1)));
// }
// int mceil(int a, int b)
// {
// if (a % b == 0)return a / b;
// else return a / b + 1;
// }
const int N = 2e5 + 5;
std::vector<int> v[N];
void solve()
{
int n; cin >> n;
int mini = 1e18;
int ok = -1;
FOR(i, 0, n)
{
int x, y, z; cin >> x >> y >> z;
z -= x;
if (z > 0)mini = min(mini, y), ok = 1;
}
if (ok == 1)cout << mini;
else cout << "-1";
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//precompute();
//w(t)
solve();
} |
#include<cstdio>
using namespace std;
int n,a,b;
int main(){
scanf("%d%d%d",&n,&a,&b);
printf("%d\n",n-a+b);
return 0;
}
| // Created by ...
#include <bits/stdc++.h>
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
using namespace std;
using ll = long long;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, a, b;
cin >> n >> a >> b;
cout << n - a + b;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7
#define INF 1000000007 //10^9+7
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
vector<pair<ll, ll> > to[1005];
ll memo[1005][1005];
int main(){
ll N, M;
cin >> N >> M;
rep(i, M) {
char ch;
ll a, b, c;
cin >> a >> b >> ch;
c = ch-'a';
a--;b--;
to[a].push_back(make_pair(b, c));
to[b].push_back(make_pair(a, c));
}
ll ret = INF;
rep(i, N) rep(j, N) memo[i][j] = -1;
//cost, s, e
priority_queue<tuple<ll, ll, ll>, vector<tuple<ll, ll, ll> >, greater<tuple<ll,ll,ll>>>Q;
Q.push({0, 0, N-1});
while(!Q.empty()) {
ll cost, s, e;
tie(cost, s, e) = Q.top();
Q.pop();
if(memo[s][e] != -1) continue;
memo[s][e] = cost;
if(s == e) {
chmin(ret, cost);
continue;
}
for(auto item0: to[s]) if(item0.first == e) {
chmin(ret, cost + 1);
continue;
}
for(auto item0: to[s]) for(auto item1: to[e]) {
if(item0.second == item1.second) {
Q.push({cost + 2, item0.first, item1.first});
}
}
}
if(ret != INF) {
cout << ret << endl;
return 0;
}
cout << -1 << endl;
}
| // atcoder/abc197/F/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/
#include <bits/stdc++.h>
#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))
using namespace std;
template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }
template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }
using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;
constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;
const int N = 1000 + 3;
vec<pair<int, char>> g[N];
int main(int argc, char *argv[])
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.setf(ios_base::fixed);
cout.precision(15);
int n, m;
while (cin >> n >> m) {
fill(g, g + N, vec<pair<int, char>>());
for (int i = 0; i < m; ++i) {
int a, b;
char c;
cin >> a >> b >> c;
--a;
--b;
g[a].push_back(make_pair(b, c));
g[b].push_back(make_pair(a, c));
}
const int inf = 1 << 29;
static int cost[N][N];
fill(&cost[0][0], &cost[N - 1][N - 1] + 1, inf);
cost[0][n - 1] = 0;
priority_queue<pair<int, pair<int, int>>> q;
q.push(make_pair(0, make_pair(0, n - 1)));
while (q.size()) {
auto p = q.top();
q.pop();
int c = abs(p.first);
int a = p.second.first;
int b = p.second.second;
map<char, vec<int>> x, y;
each (i, g[a]) x[i.second].push_back(i.first);
each (i, g[b]) y[i.second].push_back(i.first);
for (char d = 'a'; d <= 'z'; ++d) {
each (i, x[d]) {
each (j, y[d]) {
int nc = c + 2;
if (cost[i][j] > nc) {
cost[i][j] = nc;
q.push(make_pair(-nc, make_pair(i, j)));
}
}
}
}
}
int mn = inf;
for (int i = 0; i < N; ++i) {
setmin(mn, cost[i][i]);
}
for (int i = 0; i < n; ++i) {
each (e, g[i]) {
int j = e.first;
setmin(mn, cost[i][j] + 1);
}
}
cout << (mn == inf ? -1 : mn) << endl;
}
return 0;
}
|
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <type_traits>
#include <cmath>
#include <cassert>
#include <cstdio>
using namespace std;
using namespace placeholders;
using LL = long long;
using ULL = unsigned long long;
using VI = vector< int >;
using VVI = vector< vector< int > >;
using VS = vector< string >;
using ISS = istringstream;
using OSS = ostringstream;
using PII = pair< int, int >;
using VPII = vector< pair< int, int > >;
template < typename T = int > using VT = vector< T >;
template < typename T = int > using VVT = vector< vector< T > >;
template < typename T = int > using LIM = numeric_limits< T >;
template < typename T = int > using OSI = ostream_iterator< T >;
template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
void in_impl(){};
template < typename T, typename... TS > void in_impl( T &head, TS &... tail ){ cin >> head; in_impl( tail ... ); }
#define IN( T, ... ) T __VA_ARGS__; in_impl( __VA_ARGS__ );
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }
#define NUMBERED( name, number ) NUMBERED2( name, number )
#define NUMBERED2( name, number ) name ## _ ## number
#define REP1( n ) REP2( NUMBERED( REP_COUNTER, __LINE__ ), n )
#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2, REP1 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &&e : c )
#define ALL( c ) begin( c ), end( c )
#define AALL( a ) ( remove_all_extents< decltype( a ) >::type * )a, ( remove_all_extents< decltype( a ) >::type * )a + sizeof( a ) / sizeof( remove_all_extents< decltype( a ) >::type )
#define SZ( v ) ( (int)( v ).size() )
#define EXISTS( c, e ) ( ( c ).find( e ) != ( c ).end() )
template < typename T > inline bool chmin( T &a, const T &b ){ if ( b < a ) { a = b; return true; } return false; }
template < typename T > inline bool chmax( T &a, const T &b ){ if ( a < b ) { a = b; return true; } return false; }
#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter
#define MP make_pair
#define fst first
#define snd second
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
// Λ Λ__
// /(*゚ー゚)/\
// /|  ̄U U ̄|\/
// | |/
constexpr auto INF = LIM< LL >::max() / 2;
int main()
{
cin.tie( nullptr );
ios::sync_with_stdio( false );
cout << setprecision( 12 ) << fixed;
IN( int, N, T );
VI A( N );
cin >> A;
const int n = N / 2;
const int m = N - n;
VT< LL > after_half( 1, -INF );
REP( s, 1 << m )
{
LL r = 0;
REP( i, m )
{
if ( s & 1 << i )
{
r += A[ n + i ];
}
}
after_half.PB( r );
}
sort( ALL( after_half ) );
VT< LL > befor_half;
REP( s, 1 << n )
{
LL r = 0;
REP( i, n )
{
if ( s & 1 << i )
{
r += A[i];
}
}
befor_half.PB( r );
}
sort( ALL( befor_half ) );
auto pos = end( after_half ) - 1;
LL res = 0;
FOR( r, befor_half )
{
for ( ; T - r < *pos; --pos );
chmax( res, r + *pos );
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const long long MOD = 1000000007;
ll N, T, A[100];
signed main(){
cin >> N >> T;
REP(i, N) cin >> A[i];
vector<ll> v, w;
REP(i, 1 << (N / 2)){
ll t = 0;
REP(j, N / 2){
if(i & (1 << j)) t += A[j];
}
v.push_back(t);
}
REP(i, 1 << (N - (N / 2))){
ll t = 0;
REP(j, N - N / 2){
if(i & (1 << j)) t += A[j + N / 2];
}
w.push_back(t);
}
sort(ALL(w));
/*
for(auto t : v) cerr << t << " ";
cerr << endl;
for(auto t : w) cerr << t << " ";
cerr << endl;
*/
ll ans = 0;
for(auto t : v){
if(t > T) continue;
ll d = upper_bound(ALL(w), T - t) - w.begin();
if(d == 0) ans = max(ans, t);
else ans = max(ans, t + w[d - 1]);
}
PRINT(ans);
return 0;
} |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using 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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
#define n50 250000
int f(int r,int c){
return r*500+c;
}
int main(){
int R,C; cin >> R >> C;
vvi g(n50);
vvi co(n50);
rep(r,R) rep(c,C-1){
int in; cin >> in;
int ff=f(r,c);
g[ff].pb(ff+1);
g[ff+1].pb(ff);
co[ff].pb(in);
co[ff+1].pb(in);
}
rep(r,R-1) rep(c,C){
int in; cin >> in;
int ff=f(r,c);
g[ff].pb(ff+500);
co[ff].pb(in);
}
rep(c,C){
rep(r,R){
rep(s,r){
int ff=f(r,c);
g[ff].pb(f(s,c));
co[ff].pb(r-s+1);
}
}
}
vector<int> D(n50, 1e9);
vector<bool> used(n50, false);
priority_queue<pair<int,int>,
vector<pair<int,int>>,
greater<pair<int,int>>> q;
q.push({0,0});
while(!q.empty()){
int d = q.top().first; int to = q.top().second; q.pop();
if(used[to]) continue;
used[to] = true; D[to] = d;
rep(i,sz(g[to])){
int nxt=g[to][i];
int nd = D[to] + co[to][i];
if(D[nxt] <= nd) continue;
D[nxt] = nd;
q.push({nd, nxt});
}
}
int ans = D[f(R-1,C-1)];
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int r, c;
cin >> r >> c;
vector <vector<int>> a(r + 1, vector <int> (c + 1, 0));
for(int i = 1; i <= r; i++) {
for(int j = 1; j < c; j++) {
cin >> a[i][j];
}
}
vector <vector<int>> b(r + 1, vector <int> (c + 1, 0));
for(int i = 1; i < r; i++) {
for(int j = 1; j <= c; j++) {
cin >> b[i][j];
}
}
auto Dijkstra = [&] (pair <int, int> src, pair<int, int> dst) -> int {
vector <vector<int>> dist(r + 1, vector <int> (c + 1, 1e9));
using tup = tuple <int, int, int>;
priority_queue <tup, vector<tup>, greater<tup>> pq;
dist[src.first][src.second] = 0;
pq.emplace(0, src.first, src.second);
while(!pq.empty()) {
auto [cost, x, y] = pq.top();
pq.pop();
if(dist[x][y] < cost) continue;
{
int nx = x, ny = y + 1;
if(nx >= 1 && nx <= r && ny >= 1 && ny <= c && dist[nx][ny] > dist[x][y] + a[x][y]) {
dist[nx][ny] = dist[x][y] + a[x][y];
pq.emplace(dist[nx][ny], nx, ny);
}
}
{
int nx = x, ny = y - 1;
if(nx >= 1 && nx <= r && ny >= 1 && ny <= c && dist[nx][ny] > dist[x][y] + a[x][y - 1]) {
dist[nx][ny] = dist[x][y] + a[x][y - 1];
pq.emplace(dist[nx][ny], nx, ny);
}
}
{
int nx = x + 1, ny = y;
if(nx >= 1 && nx <= r && ny >= 1 && ny <= c && dist[nx][ny] > dist[x][y] + b[x][y]) {
dist[nx][ny] = dist[x][y] + b[x][y];
pq.emplace(dist[nx][ny], nx, ny);
}
}
{
for(int i = 1; i < x; i++) {
int nx = x - i, ny = y;
if(nx >= 1 && nx <= r && ny >= 1 && ny <= c && dist[nx][ny] > dist[x][y] + 1 + i) {
dist[nx][ny] = dist[x][y] + 1 + i;
pq.emplace(dist[nx][ny], nx, ny);
}
}
}
}
return dist[dst.first][dst.second];
};
pair <int, int> src = make_pair(1, 1);
pair <int, int> dst = make_pair(r, c);
cout << Dijkstra(src, dst);
} |
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
int main(){
ll n, q;
cin >> n >> q;
vector<ll> a(n);
for(ll&v:a) cin >> v;
while(q--) {
ll k;
cin >> k;
ll ok = 2e18;
ll ng = 0;
while(ok-ng > 1) {
ll m = (ok+ng)/2;
ll d = upper_bound(a.begin(), a.end(), m) - a.begin();
ll nth = m - d;
if(nth >= k) {
ok = m;
} else {
ng = m;
}
}
cout << ok << endl;
}
}
| #include<iostream>
#include<bits/stdc++.h>
#define m_p make_pair
#define fi first
#define se second
#define pb push_back
typedef long long ll;
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define crap ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;
#define INF 1000000
#define vll vector<ll>
const int M = 1e9+7;
ll fastpower(ll x,ll n,ll M)
{
if(n==0)
return 1;
else if(n%2 == 0) //n is even
return fastpower((x*x)%M,n/2,M);
else //n is odd
return (x*fastpower((x*x)%M,(n-1)/2,M))%M;
}
ll GCD(ll A, ll B) {
if(B==0)
return A;
else
return GCD(B, A % B);
}
bool vowl(char c)
{
return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';
}
ll modInverse(ll A,ll M)// when M is prime
{
return fastpower(A,M-2,M);
}
void sieve(ll N) {
bool isPrime[N+1];
for(ll i = 0; i <= N;++i) {
isPrime[i] = true;
}
isPrime[0] = false;
isPrime[1] = false;
for(ll i = 2; i * i <= N; ++i) {
if(isPrime[i] == true) { //Mark all the multiples of i as composite numbers
for(ll j = i * i; j <= N ;j += i)
isPrime[j] = false;
}
}
}
vector<ll> factorize(ll n) {
vector<ll> res;
for (ll i = 2; i * i <= n; ++i) {
while (n % i == 0) {
res.push_back(i);
n /= i;
}
}
if (n != 1) {
res.push_back(n);
}
return res;
}
int main()
{
crap;
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ll n,q;
cin>>n>>q;
ll arr[n];
f(i,n)cin>>arr[i];
map<ll,ll> mp;
ll p=1;
for(int i=0;i<n;i++)
{
mp[arr[i]]=p++;
}
while(q--)
{
ll x;
cin>>x;
ll a=1,b=1e18+1e6;
ll ans;
while(a<=b)
{
unsigned long long int mid=(b+a)/(ll)2;
auto it=mp.upper_bound(mid);
ll l;
if(it==mp.end())l=n;
else
l=it->second-1;
ll y=x+l;
if(y>mid)
{
a=mid+1;
}
else
{
if(mp.find(mid)==mp.end()&&(x+l)==mid)ans=mid;
b=mid-1;
}
}
cout<<ans<<"\n";
}
return 0;
} |
#include<iostream>
int main(){
int i,j,bit;
int n,a,b;
int num[8]={};
int can[200]={};
int count=0;
std::cin>>n;
if(n>8)n=8;
for(i=0;i<n;i++){
std::cin>>a;
num[i]=a%200;
}
for(bit=1;bit<(1<<n);++bit){
b=0;
for(i=0;i<n;i++){
if(bit&(1<<i)){
b+=num[i];
}
}
b=b%200;
if(can[b])break;
else can[b]=bit;
}
if(bit==(1<<n))std::cout<<"No"<<std::endl;
else{
std::cout<<"Yes"<<std::endl;
count=0;
for(i=0;i<n;i++){
if(bit&(1<<i))count++;
}
std::cout<<count<<" ";
for(i=0;i<n;i++){
if(bit&(1<<i))std::cout<<i+1<<" ";
}
std::cout<<std::endl;
count=0;
for(i=0;i<n;i++){
if(can[b]&(1<<i))count++;
}
std::cout<<count<<" ";
for(i=0;i<n;i++){
if(can[b]&(1<<i))std::cout<<i+1<<" ";
}
std::cout<<std::endl;
}
} | //雪花飄飄北風嘯嘯
//天地一片蒼茫
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n;
int arr[205];
bool memo[205][205];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
cin>>n;
rep(x,0,n){
cin>>arr[x];
arr[x]%=200;
}
memo[0][0]=true;
rep(x,0,n){
rep(y,0,200) if (memo[x][y]){
memo[x+1][(y+arr[x])%200]=true;
memo[x+1][y]=true;
memo[x+1][(y-arr[x]+200)%200]=true;
}
}
vector<int> add;
vector<int> minus;
int py=0;
rep(x,n,0){
if (sz(add) && memo[x][(py+arr[x])%200]){
minus.pub(x);
py=(py+arr[x])%200;
}
else if (sz(minus) && memo[x][(py-arr[x]+200)%200]){
add.pub(x);
py=(py-arr[x]+200)%200;
}
else if (memo[x][(py+arr[x])%200]){
minus.pub(x);
py=(py+arr[x])%200;
}
else if (memo[x][(py-arr[x]+200)%200]){
add.pub(x);
py=(py-arr[x]+200)%200;
}
}
if (sz(add)==0 && sz(minus)==0){
cout<<"No"<<endl;
return 0;
}
if (sz(add)==n && sz(minus)==0){
cout<<"No"<<endl;
return 0;
}
if (sz(add)==0 && sz(minus)==n){
cout<<"No"<<endl;
return 0;
}
set<int> s;
rep(x,0,n) s.insert(x);
for (auto &it:add) s.erase(it);
for (auto &it:minus) s.erase(it);
if (!s.empty()) add.pub(*s.begin()),minus.pub(*s.begin());
cout<<"Yes"<<endl;
sort(all(add));
sort(all(minus));
cout<<sz(add)<<" "; for (auto &it:add) cout<<it+1<<" "; cout<<endl;
cout<<sz(minus)<<" "; for (auto &it:minus) cout<<it+1<<" "; cout<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main () {
int n;
cin >> n;
vector<int> x(n),y(n);
for(int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
int ans = 0;
for(int i = 0; i < n; i++) {
for(int j = i+1; j < n; j++) {
double k = (double)(y[j]-y[i])/(x[j]-x[i]);
if(k>=-1&&k<=1) ans++;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
ll n;
cin >> n;
vll x(n), y(n);
REP(i, n) cin >> x[i] >> y[i];
ll res = 0;
REP(i, n) {
REP(j, n) {
if (j <= i) continue;
if (abs(x[j] - x[i]) >= abs(y[j] - y[i])) res++;
}
}
cout << res << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int main(){
int x;
scanf("%d",&x);
int now=x;
while(1){
now++;
if(now%100==0){
cout<<now-x;
return 0;
}
}
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int x;
cin>>x;
x%100==0 ? cout<<(100) : cout<<(100 - x%100);
} |
#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#define endl "\n"
#define pb push_back
#define ll long long
#define d1(x) cerr << #x << "--> " << x << endl
#define d2(x,y) cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x,y,z) cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define d4(x,y,z,w) cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z << " | "<< #w << "--> " << w <<endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
using namespace std;
ll mode = 1e9 + 7;
const ll maxn = 2*1e5 + 5;
const ll inf = 1e18;
ll __lcm(ll a, ll b){ return (a*b)/__gcd(a,b); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getRand(ll l, ll r){ uniform_int_distribution<int> uid(l, r); return uid(rng); }
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) { return out << "(" << a.F << ", " << a.S << ")"; }
template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
out << "["; for (int i=0;i<v.size();i++) { if(i) out << ", "; out << v[i]; } return out << "]"; }
void solve(){
ll n;
cin>>n;
map<int,vector<int>> b;
map<int,int> ma, mb, mc;
for (int i=1;i<=n;i++){
int x;
cin>>x;
ma[x]++;
}
for (int i=1;i<=n;i++){
ll x;
cin>>x;
b[x].pb(i);
mb[x]++;
}
for (int i=1;i<=n;i++){
ll x;
cin>>x;
mc[x]++;
}
ll ans = 0;
for (int i=1;i<=n;i++){
if (mb.count(i)==0) continue;
vector<int> bb = b[i];
for (auto j:bb){
ans = ans + ma[i]*mc[j];
}
}
cout<<ans<<endl;
}
int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
srand(time(0));
ios::sync_with_stdio(0);
cin.tie(0);
ll test_case = 1;
//cin>>test_case;
for (int i=1;i<=test_case;i++){
solve();
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main()
{
int n,x;
cin >> n;
int arr1[n+2]= {0};
memset(arr1,0,sizeof(arr1));
for(int i=1; i<=n; i++)
{
cin>>x;
arr1[x]++;
}
int arr2[n+1];
for(int j=1;j<=n; j++)
{
cin >> arr2[j];
}
unsigned long long int cnt=0;
while(n--)
{
cin >> x;
int k=arr2[x];
cnt=cnt+arr1[k];
}
cout<<cnt<<endl;
}
|
// clang-format off
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <cctype>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep2(i,s,n) for (int i=(s); i<(int)(n); ++i)
#define noflush ios::sync_with_stdio(false);cin.tie(nullptr);constexpr char endl='\n'
#define prec(i) fixed << setprecision(i)
#define put(expr) cout<<expr<<'\n'
#define putV(A) cout << '['; rep(i, A.size()) { cout << A[i]; if (i != A.size() - 1) cout << ' '; else cout << "]\n"; }
typedef int8_t i8; typedef int16_t i16; typedef int32_t i32; typedef int64_t i64; typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; typedef float f32; typedef double f64; typedef long double f80;
typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef map<int, int> mii;
typedef __int128_t i128; i128 parse(string &s) { i128 ret = 0; for (int i = 0; i < s.length(); i++) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret; } istream &operator>>(istream &is, i128 &v) { string s; is >> s; v = parse(s); return is; } ostream &operator<<(ostream &os, const i128 &v) { if (v == 0) return (os << "0"); i128 num = v; if (v < 0) { os << '-'; num = -num; } string s; for (; num > 0; num /= 10) s.push_back('0' + (char)(num % 10)); reverse(s.begin(), s.end()); return (os << s); }
template <typename T> bool chmax(T &now, const T &cand) { if (now < cand) { now = cand; return true; } return false; } template <typename T> bool chmin(T &now, const T &cand) { if (now > cand) { now = cand; return true; } return false; }
template <typename T> T gcd(const T &a, const T &b) { if (a % b == 0) return b; return gcd(b, a % b); } template <typename T> T lcm(const T &a, const T &b) { return a * b / gcd(a, b); }
template <typename T> T nCr(const T &n, T k) { if (k > n) return 0; if (k * 2 > n) k = n - k; if (k == 0) return 1; int result = n; for (int i = 2; i <= k; ++i) { result *= (n - i + 1); result /= i; } return result; }
const int INF = 1<<30; /* INF > 10^9 */ const i64 INFLL = 1LL<<60; /* INFLL > 10^18 */ const string YES = "Yes", NO = "No";
// clang-format on
int main() {
noflush;
int N;
cin >> N;
vector<bool> B(N);
rep(i, N) {
string s;
cin >> s;
if (s == "AND")
B[i] = true;
else
B[i] = false;
}
i128 ans = 1;
for (int i = B.size() - 1; i >= 0; i--) {
if (B[i]) {
// AND
ans *= 2;
--ans;
} else {
// OR
ans *= 2;
}
}
ans *= 2;
--ans;
put(ans);
}
| #include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
vector<string> s(n+1);
for(int i=1;i<=n;i++){
cin>>s[i];
}
vector<long long> t(n+1);
vector<long long> f(n+1);
if(s[1]=="AND"){
t[1]=1l;
f[1]=3l;
}
else{
t[1]=3l;
f[1]=1l;
}
for(int i=2;i<=n;i++){
if(s[i]=="AND"){
t[i]=t[i-1]*1l; //true,true
f[i]=2l*f[i-1]+t[i-1]; //(f,f),(f,t),(t,f)
}
else{
t[i]= 2l*t[i-1]+f[i-1]; //(t,t),(t,f),(f,t)
f[i] = f[i-1]*1l; //f,f
}
}
cout<<t[n]<<"\n";
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
int n;
cin >> n;
vector<string> s(n);
rep(i, 0, n) cin >> s[i];
set<string> st;
rep(i, 0, n) st.insert(s[i]);
for(string s : st){
if(s[0] != '!'){
string t = "!" + s;
decltype(st)::iterator it = st.find(t);
if(it != st.end()){
cout << s << endl;
return 0;
}
}
}
cout << "satisfiable" << endl;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e6+10;
int p[N];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int x,y;
cin >> x >> y;
int c = min(x,y);
int d = max(x,y);
if((d-c)<3)cout << "Yes";
else cout << "No";
}
|
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// ifstream cin("input.txt");
// ofstream cout("output.txt");
ll tst = 1;
while(tst--){
ull res,n,i,j,k,lim;
cin>>n;
set<ull> st;
res = n;
lim = pow(n , 0.5);
for(i =2;i<=lim;i++){
k = 2;
j= pow(i,k);
for(;j<=n;){
if(st.find(j)==st.end()){
//cout<<j<<endl;
res--;
}
st.insert(j);
k++;
j = pow(i,k);
}
}
cout<<res<<endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
unordered_set<long long> us;
long long counter = 0;
for (long long i = 2; i <= sqrt(n); i++) {
long long tmp = i * i;
while (tmp <= n) {
us.insert(tmp);
tmp *= i;
}
}
cout << n - us.size() << endl;
return 0;
}
|
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>
//#include<atcoder/dsu>
//using namespace atcoder;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;
#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)
const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 998244353;
void solve() {
int n, m;
cin >> n >> m;
if (m == 0) {
for (int i = 0; i < n; ++i) {
cout << 2 * i + 1 << " " << 2 * i + 2 << "\n";
}
return;
}
if ((m < 0) || (m >= n - 1)) {
cout << -1 << endl;
return;
}
for (int i = 0; i < m + 1; ++i) {
cout << 2 * i + 2 << " " << 2 * i + 3 << "\n";
}
cout << 1 << " " << 2 * m + 4 << "\n";
int x = 2 * m + 4;
for (int i = m + 2; i < n; ++i) {
int j = i - m - 2;
cout << x + 2 * j + 1 << " " << x + 2 * j + 2 << "\n";
}
}
//#define LOCAL
int main() {
ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
solve();
#ifdef LOCAL
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
typedef long long int ll;
using ii= pair<ll,ll>;
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define all(o) (o).begin(),(o).end()
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ld long double
#define eps 0.00000000001
#define mod 1000000007
class prioritize{
public: bool operator() (ii &p1,ii &p2){
return p1.F<p2.F;
}
};
auto start_time= high_resolution_clock::now();
void time()
{
#ifndef ONLINE_JUDGE
auto stop_time= high_resolution_clock::now();
auto duration= duration_cast<milliseconds>(stop_time-start_time);
cout<<"run time: "<<duration.count()<<" ms"<<"\n";
#endif
return;
}
void ojudge()
{
#ifndef ONLINE_JUDGE
freopen("input1.txt","r", stdin);
freopen("output1.txt","w",stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
return;
}
vector<ll> le,ri;
ll t=0;
void all_poss_subset_sum(vector<ll> & brr,vector<ll> &sum_vec)
{
ll n = brr.size();
ll no_of_subsets = (1<<n);
fr(i,0,no_of_subsets){
ll ans=0;
fr(j,0,n){
if(i & (1<<j)) ans += brr[j];
}
sum_vec.PB(ans);
}
}
void meet_in_the_middle(ll arr[],ll n)
{
vector<ll> left,right;
fr(i,0,n/2) left.PB(arr[i]);
fr(i,n/2,n) right.PB(arr[i]);
all_poss_subset_sum(left,le);
all_poss_subset_sum(right,ri);
//return ans;
}
int main()
{
ojudge();
ll n;
cin>>n>>t;
ll arr[n];
fr(i,0,n) cin>>arr[i];
meet_in_the_middle(arr,n);
sort(all(ri));
ll ans=0;
for(auto it:le)
{
if(it>t) continue;
ll tgt = t-it;
ll ind = upper_bound( ri.begin(),ri.end(),tgt)-ri.begin()-1;
ans = max(ans,it + ri[ind]);
}
cout<<ans<<"\n";
time();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using P = pair<i64, i64>;
#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()
void solve(long long L) {
vector<vector<i64>> dp(L, vector<i64>(12));
dp[0][0] = 1;
for(int i = 0; i < L; ++i) {
dp[i][0] = 1;
for(int j = 1; j < 12; ++j) {
for(int k = 0; k < i; ++k) {
dp[i][j] += dp[k][j - 1];
}
}
}
cout << dp[L - 1][11] << endl;
}
struct IoSetup {
IoSetup() {
// cin.tie(nullptr);
// ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
}
} iosetup;
int main() {
long long L;
scanf("%lld", &L);
solve(L);
return 0;
}
| /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author Kein Yukiyoshi
*/
// clang-format off
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
#define Endl endl
#define itn int
#define fi first
#define se second
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep2(i, a, b) for (int i = (int)(a), i##_len=(b); i < i##_len; i++)
#define rep3(i, a, b) for (int i = (int)(a), i##_len=(b); i >= i##_len; i--)
#define FOR(i, a) for (auto &i: a)
#define ALL(obj) begin(obj), end(obj)
#define _max(x) *max_element(ALL(x))
#define _min(x) *min_element(ALL(x))
#define _sum(x) accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(begin(A), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(begin(A), upper_bound(ALL(A), key))
const int MOD = 1000000007;
// const int MOD = 998244353;
const int INF = (int)(1e13 + 7);
const double EPS = 1e-8;
const double PI = 3.14159265358979;
template <class T> using V = vector<T>;
template <class T> using VV = vector<vector<T>>;
template <class T> using VVV = vector<vector<vector<T>>>;
template <class T, class S> using P = pair<T, S>;
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b;return true;}return false;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b;return true;}return false;}
int _ceil(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); }
int _mod(int &a) {a = a >= 0 ? a % MOD : a - (MOD * _ceil(a, MOD));return a;}
int _pow(int a, int b) {int res = 1;for (a %= MOD; b; a = a * a % MOD, b >>= 1)if (b & 1) res = res * a % MOD;return res;}
struct mint {long long x;mint(long long 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(long long t) const {if (!t) return 1;mint a = pow(t >> 1);a *= a;if (t & 1) a *= *this;return a;}mint inv() const { return pow(MOD - 2); }mint &operator/=(const mint a) { return *this *= a.inv(); }mint operator/(const mint a) const { return mint(*this) /= a; }};istream &operator>>(istream &is, mint &a) { return is >> a.x; }ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
// clang-format on
class CDuodecimFerra {
public:
static void solve(istream &cin, ostream &cout) {
cin.tie(nullptr);
cout.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
int L;
cin >> L;
int ans = 1;
V<int> temp(10);
rep(i, 10) temp[i] = i + 2;
rep2(i, L - 11, L) {
ans *= i;
FOR(j, temp) {
if (j != 1 and ans % j == 0) {
ans /= j;
j = 1;
}
}
}
cout << ans << endl;
}
};
signed main() {
CDuodecimFerra solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
template<typename T>
void maxs(T& x, T&& y) {
x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
x=std::max(x,y);
}
template<typename T>
void mins(T& x, T&& y) {
x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
x=std::min(x,y);
}
struct doublepair{
int a, b;
};
int main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ull n;
cin >> n;
std::vector<ull> three;
std::vector<ull> five;
for (ull i=3;i < n;i *=3) {
three.push_back(i);
}
for (ull i=5;i < n;i *=5) {
five.push_back(i);
}
bool is_find {false};
doublepair ans;
for (int i = 0;i < three.size();++i) {
for (int j = 0;j < five.size();++j) {
if (three[i] + five[j] > n) {
break;
} else if (three[i] + five[j] == n) {
ans.a = i+1;
ans.b = j+1;
is_find = true;
break;
}
}
if (is_find == true) break;
}
if (is_find) cout << ans.a << ' ' << ans.b << '\n';
else cout << -1 << '\n';
}
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define Swap(a, b) do { typeof(a) T = (a); a = b; b = T; } while(0)
static inline int
input() {
int x = 0, f = 0, c = getchar();
while(c < '0' || c > '9') { f ^= (c == '-'), c = getchar(); }
while(c > 47 && c < 58) { x = x * 10 + c - '0', c = getchar(); }
return f ? -x : x;
}
static inline void
Asc64(long long *a, const int sz) {
int shift = 0, elem[256];
long long x = 0, *aux = (long long*)malloc(sizeof(long long)*sz);
if(aux == nullptr) { exit(EXIT_FAILURE); }
while(shift < 64) {
int bucket[256] = {0};
for(int i = 0; i < sz; ++i) {
x = (a[i] >> shift) & 255;
++bucket[x];
aux[i] = a[i];
}
elem[0] = 0;
for(int i = 0; i < 255; ++i) {
elem[i + 1] = elem[i] + bucket[i];
}
for(int i = 0; i < sz; ++i) {
x = (aux[i] >> shift) & 255; a[elem[x]] = aux[i];
++elem[x];
}
shift += 8;
}
free(aux);
}
int main() {
int n = input();
int len = 0, sizeS = 0, sizeT = 0;
long long S[n], T[n];
char temp[11];
for(int i = 0; i < n; ++i) {
if(!scanf("%s", temp)) {
exit(EXIT_FAILURE);
}
len = (int)strlen(temp);
S[i] = T[i] = 0;
if(temp[0] == '!') {
--len;
for(int j = 0; j < len; ++j) {
T[sizeT] = T[sizeT] * 27 + (temp[j + 1] - 'a' + 1);
}
++sizeT;
}
else {
for(int j = 0; j < len; ++j) {
S[sizeS] = S[sizeS] * 27 + (temp[j] - 'a' + 1);
}
++sizeS;
}
}
Asc64(S, sizeS);
Asc64(T, sizeT);
int idxS = 0, idxT = 0;
long long check = 0;
while(idxS < sizeS && idxT < sizeT) {
check = S[idxS] - T[idxT];
if(!check) {
memset(temp, '\n', 11);
len = 0;
while(S[idxS]) {
temp[len++] = 'a' + S[idxS] % 27 - 1;
S[idxS] /= 27;
}
for(int i = 0; i < len/2; ++i) {
Swap(temp[i], temp[len - 1 - i]);
}
return !puts(temp);
}
else if(check < 0) {
++idxS;
}
else {
++idxT;
}
}
return !puts("satisfiable");
} |
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define flc(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define vec vector<lint>
#define nep(x) next_permutation(all(x))
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=3e5+5;
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;}
//vector<int> bucket[MAX_N/1000];
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
/*#include<atcoder/all>
using namespace atcoder;
typedef __int128_t llint;*/
int main(void){
int N;
cin >> N;
lint A[N];
rep(i,N) cin >> A[i];
lint sum[N+1]={};
rep(i,N) sum[i+1]=sum[i]+A[i];
int modsum[N+1][N+1]={};
rep(i,N+1) rep(j,N+1) if(j!=0) modsum[i][j]=sum[i]%j;
lint dp[N+1][N+1]={};
dp[0][0]=1;
int x[N+1][N+1]={};
for(int j=1;j<=N;j++){
int last[N+1]={};
rep(i,N+1) last[i]=-1;
for(int i=1;i<=N;i++){
x[i][j]=last[modsum[i][j]];
last[modsum[i][j]]=i-1;
}
}
for(int i=1;i<=N;i++) for(int j=1;j<=i;j++){
dp[i][j]=((dp[x[i][j]+1][j])+dp[x[i][j]+1][j-1])%MOD;
}
lint ans=0;
for(int i=1;i<=N;i++) ans=(ans+dp[N][i])%MOD;
cout << ans << endl;
} | #include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=1;i<=(n);++i)
#define rep3(i,i0,n) for(ll i=i0;i<(n);++i)
#define rrep(i,n) for(ll i=((n)-1); i>=0; --i)
#define rrep2(i,n) for(ll i=(n); i>0; --i)
#define pb push_back
#define mod 1000000007
#define fi first
#define se second
#define len(x) ((ll)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
using Pi = pair< ll, ll >;
using vl = vector<ll>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<Pi>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
const ll INF = 1LL << 60;
const ld PI = 3.1415926535897932385;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
void printb(ll N,ll d=16){
rep(i,d){
cout<<(N/(1<<(d-i-1)))%2;
}
cout<<endl;
}
void printv(vector<ll>a){
rep(i,a.size()){
if(i==a.size()-1){
cout<<a[i]<<endl;
}else{
cout<<a[i]<<" ";
}
}
}
bool In_map(ll y,ll x,ll h,ll w){
if(y<0 || x<0 || y>=h || x>=w){
return 0;
}else{
return 1;
}
}
bool compare(Pi a, Pi b) {
if(a.first != b.first){
return a.first < b.first;
}else{
return a.second < b.second;
}
}
//const vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1};
//const vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
int main() {
ll N,K;
cin>>N>>K;
vl a(N);
rep(i,N){
cin>>a[i];
}
sort(all(a));
ll ans=0;
map<ll,ll>m;
m[0]=K;
rep(i,N){
if(m[a[i]]>0){
ans++;
m[a[i]]--;
m[a[i]+1]++;
}
}
cout<<ans<<endl;
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 = 2e5, MOD = 1e9 + 7, INF = 1e9;
int n, v[2 * MAX_N];
int main() {
ci(n);
ll sum = 0, aoki = 0;
rep(i, 2 * n) {
ci(v[i]);
sum += v[i];
}
PQG q;
rep(i, n) {
q.ep(v[n - i - 1]);
q.ep(v[n + i]);
aoki += q.top(); q.pop();
}
co(sum - aoki);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Pr pair<ll,ll>
#define Tp tuple<int,int,int>
using Graph = vector<vector<int>>;
int main(){
ll N; cin >> N;
ll v[2*N]; ll sum = 0,loss = 0;
rep(i,2*N){
cin >> v[i]; sum += v[i];
}
ll k1 = N-1; ll k2 = N;
multiset<ll> mean;
rep(i,N){
mean.insert(v[k1]); mean.insert(v[k2]);
auto itr = mean.begin();
loss += *itr; mean.erase(itr);
k1--; k2++;
}
cout << sum-loss << endl;
} |
// < Rahil Malhotra / ViciousCoder >
#include "bits/stdc++.h"
using namespace std;
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double
int n,k;
int tree[2000005];
int lazy[2000005];
void propogate(int i,int l,int r)
{
tree[i]+=(r-l+1)*lazy[i];
if(l!=r)
lazy[i*2]+=lazy[i],lazy[i*2+1]+=lazy[i];
lazy[i]=0;
}
void update(int i,int l,int r,int l1,int r1,int val)
{
if(lazy[i])
propogate(i,l,r);
if(l1>r1 || l>r1 || l1>r)
return;
if(l1<=l && r<=r1)
{
tree[i]+=(r-l+1)*val;
if(l!=r)
lazy[i*2]+=val,lazy[i*2+1]+=val;
return;
}
int mid=(l+r)/2;
update(i*2,l,mid,l1,r1,val);
update(i*2+1,mid+1,r,l1,r1,val);
tree[i]=tree[i*2]+tree[i*2+1];
}
int query(int i,int l,int r,int l1,int r1)
{
if(l1>r1 || l>r1 || l1>r)
return 0;
if(lazy[i])
propogate(i,l,r);
if(l1<=l && r<=r1)
return tree[i];
int mid=(l+r)/2;
return query(i*2,l,mid,l1,r1)+query(i*2+1,mid+1,r,l1,r1);
}
int32_t main()
{
IOS;
cin>>n>>k;
int ans=0;
for(int i=1;i<=n;i++)
update(1,1,2*n+2,i+1,i+n,1);
for(int i=2;i<=2*n;i++)
{
int left=i-k;
if(left<2 || left>2*n)
continue;
// int ways=abs(left)-1;
// int ways2=abs(i)-1;
// ans+=ways*ways2;
// print(i,ways,ways2,left,ways*ways2);
ans+=query(1,1,2*n+2,i,i)*query(1,1,2*n+2,left,left);
}
cout<<ans;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,n,a) for (int i=n;i>=a;i--)
#define mst(a,i) memset(a,i,sizeof a)
#define ll long long
#define pb push_back
#define eps 1e-10
#define fi first
#define se second
#define pii pair<int,int>
#define inf 0x3f3f3f3f
const int mod = 1000000007;
const int N = 2e5+6;
ll n,k,tot;
ll g(ll e)
{
if(e>=2&&e<=n+1)return e-1;
return 2*n-e+1;
}
int main()
{
std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>k;
ll x,y;
if(k>=0)
{
x=k+2;y=2*n;
}
else
{
x=2;
y=2*n+k;
}
rep(i,x,y)
{
ll e1=i;
ll e2=i-k;
tot+=g(e1)*g(e2);
}
cout<<tot;
} |
#include<bits/stdc++.h>
using namespace std;
#define lll __int128_t
#define ll long long
#define int long long
#define FOR(i,a,b) for(ll i=a;i<(ll)b;i++)
#define FORr(i,a,b) for(ll i =a;i>=(ll)b;i--)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,n)
#define print(arr) for(auto a: arr) cout << a<< " "; cout << endl;
#define case(i) cout << "Case " << i << ": ";
#define in(a) ll a; cin >> a;
#define inp(arr,n) vector<ll>arr(n); for(auto &a: arr) cin >> a;
#define pb emplace_back
#define all(a) a.begin(), a.end()
#define mp make_pair
#define f first
#define vll vector<ll>
#define s second
ll mod = 1e9 + 7;
#define pll pair<ll, ll>
#define set_bit(x, idx) x = x|(1LL<<idx)
ll dx[8] = {0,1,0,-1,1,-1,1,-1};
ll dy[8] = {-1,0,1,0,1,1,-1,-1};
#define toggle_bit(x, idx) x = x^(1LL<<idx)
#define check_bit(x, idx) min(x&(1LL<<idx),1LL)
#define endl "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rng(x,y) uniform_int_distribution<int>(x,y)(rng)
template<typename T> ostream& operator<<(ostream &os, const multiset<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T> ostream& operator<<(ostream &os, const set<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define db long double
ll hash58 = 288230376151711717;
ll hash32 = 1610612741;
#ifdef DEBUG
#define ios
#define dbg(...) cerr << __LINE__ << " : " ;cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#define ok cerr << __LINE__ << " is done " << endl;
#else
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define dbg(...)
#define ok
#endif
string one;
ll fact[5];
ll dp[12][6][30];
ll solve(ll idx, ll cnt, ll div){
if(dp[idx][cnt][div] != -1) return dp[idx][cnt][div];
if(idx == 10 ) {
if(cnt) return 0;
ll now = fact[4]/div;
return dp[idx][cnt][div] = now;
}
ll ans = 0;
if(one[idx] == 'o'){
for(int i = 1; i <= cnt; i++){
ans += solve(idx+1, cnt-i, div*fact[i]);
}
}
else if(one[idx] == '?'){
for(int i = 0; i <= cnt; i++){
ans += solve(idx+1, cnt-i, div*fact[i]);
}
}
else{
ans = solve(idx+1, cnt, div);
}
return dp[idx][cnt][div] = ans;
}
void solvetc(ll tt){
memset(dp, -1LL, sizeof dp);
cin >> one;
fact[0] = 1;
rep1(i, 5) fact[i] = i*fact[i-1];
cout << solve(0, 4, 1) << endl;
}
int32_t main()
{
ios ;
//freopen("in", "r", stdin);
ll nn = 1;
//cin >> nn;
rep(i, nn) solvetc(i+1);
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(){
int N;
cin >> N;
long long s = 0;
vector<long long> A(N), B(N);
for(int i = 0; i < N; ++i){
cin >> A[i];
s += A[i];
}
for(int i = 0; i < N; ++i){
cin >> B[i];
}
vector<long long> O, E;
for(int i = 0; i < N; ++i){
long long d = B[i]-A[i];
if(i%2) O.emplace_back(d);
else E.emplace_back(d);
}
sort(O.rbegin(), O.rend());
sort(E.rbegin(), E.rend());
long long ans = s;
for(int i = 0; i < N/2; ++i){
s += O[i]+E[i];
ans = max(ans,s);
}
cout << ans << endl;
}
|
#include<bits/stdc++.h>
int main() {
using namespace std;
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int N; cin >> N;
// you can attain 0..L-N
int L; cin >> L; L -= N;
vector<int> A; A.reserve(N+2);
A.push_back(0);
for (int i = 0; i < N; i++) {
int a; cin >> a; a--;
A.push_back(a-i);
}
A.push_back(L);
vector<int> B; B.reserve(N+2);
B.push_back(0);
for (int i = 0; i < N; i++) {
int a; cin >> a; a--;
B.push_back(a-i);
}
B.push_back(L);
N += 2;
map<int, int> minA;
map<int, int> maxA;
map<int, int> minB;
map<int, int> maxB;
for (int i = 0; i < N; i++) {
maxA[A[i]] = i;
maxB[B[i]] = i;
}
for (int i = N-1; i >= 0; i--) {
minA[A[i]] = i;
minB[B[i]] = i;
}
int64_t ans = 0;
for (auto it : minB) {
int v = it.first;
if (minA.count(v)) {
minB[v] = min(minB[v], minA[v]);
maxB[v] = max(maxB[v], maxA[v]);
ans += (maxB[v] - minB[v]) - (maxA[v] - minA[v]);
} else {
cout << -1 << '\n';
exit(0);
}
}
cout << ans << '\n';
return 0;
}
| #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}
int n,l;
int a[100010],b[100010];
int d[100010];
map<int,bool> ext;
map<int,int> L,R;
map<int,vector<int>> V;
void solve(){
cin >> n >> l;
rep(i,n) cin >> a[i+1];
rep(i,n) cin >> b[i];
a[n+1]=l+1;
rep(i,n+2){
if(!ext[a[i]-i]){
L[a[i]-i]=i;
R[a[i]-i]=i;
}
else{
chmax(R[a[i]-i],i);
}
ext[a[i]-i]=true;
}
ll ans=0;
// for(auto p:ext){
// cout << p.first << " " << L[p.first] << " " << R[p.first] << endl;
// }
rep(i,n){
if(!ext[b[i]-i-1]){
cout << -1 << endl;
return;
}
V[b[i]-i-1].push_back(i+1);
}
for(auto p:V){
int t=p.first;
// cout << t << endl;
// for(int i:p.second) cout << i << " ";
//cout << "" << endl;
if(L[t]>p.second.back()){
ans+=L[t]-p.second[0];
}
else if(R[t]<p.second[0]){
ans+=p.second.back()-R[t];
}
else{
ans+=max(0,L[t]-p.second[0])+max(0,p.second.back()-R[t]);
}
}
cout << ans << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(50);
solve();
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
int A,B;
int X; //???????
cin >> A >> B;
X = (2 * A +100 ) - B;
cout << X << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
ll a,b;
cin>>a>>b;
vector<ll>vec(1000);
vector<ll>veco(1000);
for(ll i=0;i<a;i++){
ll c;
cin>>c;
vec.at(c-1)=1;
}
for(ll i=0;i<b;i++){
ll c;
cin>>c;
veco.at(c-1)=1;
}
for(ll i=0;i<1000;i++){
if(veco.at(i)*veco.at(i)+vec.at(i)*vec.at(i)==1){
cout<<i+1<<' ';
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forin(in ,n) for(ll i=0; i<n; i++) cin>>in[i]
#define forout(out) for(ll i=0; i<(ll)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, n) for (ll i = a; i < n; ++i)
#define rep_down(i, a, n) for (ll i = a; i >= n; --i)
#define P pair<ll, ll>
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>
constexpr ll INF = (1ll << 60);
// constexpr ll mod = 1000000007;
constexpr ll mod = 998244353;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T>
void pt(T val) {
cout << val << "\n";
}
template <typename T>
void pt_vll(vector<T> &v) {
ll vs = v.size();
rep(i, vs) {
cout << v[i];
if (i == vs - 1)
cout << "\n";
else
cout << " ";
}
}
ll mypow(ll a, ll n) {
ll ret = 1;
if(n==0) return 1;
if(a==0) return 0;
rep(i, n) {
if (ret > (ll)(1e18 + 10) / a) return -1;
ret *= a;
}
return ret;
}
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;
}
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;
}
int main() {
ll r,x,y,z,st,ed,left,right,ans=0;
double X,Y,R;
cin>>X>>Y>>R;
X*=10000.00000001;
Y*=10000.00000001;
R*=10000.00000001;
x=X;
y=Y;
r=R;
if(y+r>=0) st=(y+r)/10000;
else st=(y+r-9999)/10000;
if(y-r>=0) ed=(y-r+9999)/10000;
else ed=(y-r)/10000;
rep_up(i,ed,st+1){
ll yy=y-10000*i;
ll k=sqrt(r*r-yy*yy)+1;
while(k*k+yy*yy>r*r){
k--;
}
if(x+k>=0) right=(x+k)/10000;
else right=(x+k-9999)/10000;
if(x-k>=0) left=(x-k+9999)/10000;
else left=(x-k)/10000;
ans+=right-left+1;
}
cout<<ans<<endl;
} | #include <bits/stdc++.h>
using namespace std;
long long int MOD=1000000007;
long long power(long long a,long long b)
{
a %= MOD;
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
bool isprime(long long n)
{
if(n==1)
return false;
long long i;
for(i=2;i*i<=n;i++)
{
if(n%i==0)
return false;
}
return true;
}
/*_______________________________________________*/
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long double x,y,r,i;
long long ans=0;
cin>>x>>y>>r;
r+=1e-14;
for(i=floor(x-r);i<=ceil(x+r);i++)
{
long double temp1=(r*r)-((i-x)*(i-x));
if(temp1<0)
continue;
temp1=sqrt(temp1);
ans+=floor(temp1+y)-ceil(-temp1+y)+1;
}
cout<<ans;
} |
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define debug(x) cout << #x << ':' << x << endl;
#define rep(i,n) for(long long i = 0; i < n ; i++)
#define reps(i,n) for(long long i = 1; i <= n ; i++)
#define make_unique(v) sort(all(v));v.erase(unique(all(v)), v.end());
#define REMOVE(v,a) v.erase(remove(v.begin(),v.end(), a), v.end());
#define pb push_back
#define mp make_pair
#define endl '\n'
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<ll,ll> pll;
const ll MOD = 1e9+7;
bool cmp(int X, int Y) {return X > Y;}
ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll lcm(ll a, ll b) {return (a / gcd(a, b)) * b;}
ll modpow(ll a, ll b, ll m=MOD){a %= m; ll res = 1; while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){if(b<0){return 0;}ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
const int N = 100005;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
ll vis[N];
ll fact(ll x){
ll res = 1;
for(ll i = 1; i<=x ; i++){
res*=i;
res = (res+MOD)%MOD;
}
return res;
}
int main(){ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n,w;cin>>n>>w;
ll k = n/w;
cout<<k<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<vector<bool>> graph(N, vector<bool>(N, false));
for (int i = 0; i < M; ++i) {
int from, to;
cin >> from >> to;
--from; --to; // Convert to 0-based.
graph[from][to] = true;
graph[to][from] = true;
}
const int INFTY = N + 1;
// dpv[mask] = min number of cliques you need
// to include all of the nodes that are set in the mask
vector<int> dpv(1 << N, INFTY);
dpv[0] = 0;
// O(N ^ 2 * 2 ^ N + 3 ^ N)
for (int mask = 1; mask < (1 << N); ++mask) {
// Check whether this mask can form one clique.
bool valid = true;
// Loop over every pair of set bits.
for (int bit1 = 0; bit1 < N; ++bit1) {
if (mask & (1 << bit1)) {
for (int bit2 = bit1 + 1; bit2 < N; ++bit2) {
if (mask & (1 << bit2)) {
if (!graph[bit1][bit2]) {
valid = false;
}
}
}
}
}
if (valid) {
dpv[mask] = 1;
} else {
// Transition: consider all submasks.
for (int submask = mask; submask > 0; submask = (submask - 1) & mask) {
dpv[mask] = min(dpv[mask], dpv[submask] + dpv[mask - submask]);
}
}
}
cout << dpv.back() << endl;
} |
# include <cstdio>
# include <cctype>
template <class code>inline code read (const code &a)
{
code x=0;short w=0;char ch=0;
while (!isdigit (ch)) {w|=ch=='-';ch=getchar ();}
while (isdigit (ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getchar ();}
return w?-x:x;
}
int main ()
{
int a=read (a),b=read (b),c=read (c);
printf ("%d\n",a-b+c);
return 0;
} | #include <bits/stdc++.h>
#define fi first
#define se second
#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(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using ll = long long;
using P = pair<int, int>;
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
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; }
int main()
{
int h, w;
cin >> h >> w;
vs s(h);
rep(i, h) cin >> s[i];
int ans = 0;
rep(i, h)rep(j, w){
if(s[i][j] == '#') continue;
if(i+1 < h && s[i+1][j] == '.') ++ans;
if(j+1 < w && s[i][j+1] == '.') ++ans;
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;typedef long long ll;
void swa(int &x, int &y){int temp = x;x = y;y = temp;}
void IO() {freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);}
bool jj(int g,int h,int k){
if(g<=k&&k<=h){
return true;
}
return false;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);
int x;cin>>x;
int a[2][x];
for(int i=0;i<2;i++){
for(int j=0;j<x;j++){
int f;cin>>f;
a[i][j]=f;
}
}
int ans=0;
for(int i=1;i<=1000;i++){
bool ff=true;
for(int j=0;j<x;j++){
if(!jj(a[0][j],a[1][j],i)){
ff=false;
break;
}
}
if(ff==true){
ans++;
}
}
cout<<ans<<endl;
return 0;
}
| #pragma GCC optimize("Ofast")
#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
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h>
#include <functional>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
constexpr ll INF = 1e18;
constexpr ll LLMAX = 9223372036854775807;
constexpr int inf = 1e9;
constexpr ll mod = 1'000'000'007;
// constexpr ll mod = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define eol endl
// ---------------------------------------------------------------------------
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> A(N),B(N);
int mn = inf;
int mx = 0;
for(int i=0; i<N; i++){
cin >> A[i];
chmax(mx,A[i]);
}
for(int i=0; i<N; i++){
cin >> B[i];
chmin(mn,B[i]);
}
cout << max(0,mn-mx+1) << eol;
return 0;
} |
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int read()
{
int a = 0,x = 1;
char ch = getchar();
while(ch > '9' || ch < '0'){
if(ch == '-') x = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
a = a*10 + ch-'0';
ch = getchar();
}
return a*x;
}
char a,b;
char js(char c)
{
if(c >= 'a' && c <= 'z') return c-'a'+'A';
else return c;
}
int main()
{
scanf(" \n%c",&a);
scanf(" \n%c",&b);
if(a == 'Y') {
printf("%c",js(b));
} else printf("%c",b);
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */
const int N = 2e5 + 9; // MUDAR ISSO
signed main(){
IOS;
int n; cin >> n;
string s; cin >> s;
vector<char> r;
int cnt = 0;
for(int i = 0; i < n; i++) {
r.push_back(s[i]);
if(r.size() >= 3) {
int N = r.size() - 1;
if(r[N-2] == 'f' and r[N-1] == 'o' and r[N] == 'x') {
cnt+=3;
r.pop_back();
r.pop_back();
r.pop_back();
}
}
}
cout << n - cnt << "\n";
}
/*
Coisas pra se lembrar:
* Overflow, tamanho do N
* Casos especiais (e.g. n = 1)
* Nao ficar parado e fazer alguma coisa
* Escrever coisas no papel
* NAO FICAR TRAVADO EM UMA IDEIA
*/ |
/********include********/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
//#include <atcoder/all>
/***/
//#include <iomanip>
//#include <cmath>
#include <bits/stdc++.h>
/********define********/
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define rrep(i,x) for(long long i=x-1;i>=0;i--)
#define rrepn(i,x) for(long long i=x;i>1;i--)
#define REP(i,n,x) for(long long i=n;i<x;i++)
#define REPN(i,n,x) for(long long i=n+1;i<x;i++)
#define pr printf
#define re return
#define mod 1000000007
//#define mod 998244353
#define inf INT_MAX//19桁
#define INF 1e18+5//19桁
const double PI=3.14159265358979323846;
#define fi first
#define se second
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
typedef pair<long long, long long> P;
/********変数宣言********/
//vector<long long> g[200020];
vector<pair<long long,long long>> g[200020];
ll s[200020];
bool used[200020];
//bool dp[100005];
ll A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,Q,R,S,T,U,V,W,X,Y,Z;
double dA,dB,dC,dD,dE,dF,dG,dH,dI,dJ,dK,dL,dM,dN,dO,dP,dQ,dR,dS,dT,dU,dV,dW,dX,dY,dZ;
string sa,sb,sc,sd,se,sf,sg,sh,si,sj,sk,sl,sm,sn,so,sp,sq,sr,ss, su,sv,sw,sx,sy,sz;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cin>>N;cin>>M;
vector<string>v(M);
vector<pair<long long, string> > p(M);
//sort(p.begin(), p.end());
//sort(p.begin(), p.end(),greater<pair<long long,long long> >());
rep(j,M){
cin>>v[j];
}
rep(i,M){
p[i].fi=v[i].size();
p[i].se=v[i];
}
sort(p.begin(), p.end());
ll check;
check=0;
ll i;
i=0;
ll flg;
while(check<N*N && i<M){
if(check%N!=0){
if(p[i-1].se[p[i-1].se.size()-1]==p[i].se[0]){
rep(j,p[i].se.size()-1){
p[i].se[j]=p[i].se[j+1];
}
p[i].se.resize(p[i].se.size()-1);
}
}
if(check%N+p[i].se.size()<=N){
cout<<p[i].se;
check+=p[i].se.size();
if(check%N==0){
cout<<"\n";
}
}
else{
while(check%N!=0){
cout<<".";
check++;
}
cout<<"\n";
}
i++;
}
re 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int num[8];
int main(){
int n,m;
cin>>n>>m;
vector<string>t(m);
vector<string>s;
rep(i,m){
cin>>t[i];
}
for(int k=2;k<=12;k++){
rep(i,m){
if(t[i].length()==k){
s.push_back(t[i]);
}
}
}
int cur=0;
rep(i,20){
string temp="";
while(1){
string pretemp=temp;
temp+=s[cur];
if(temp.size()>20){
temp=pretemp;
break;
}
cur++;
}
int rest=20-temp.length();
cout<<temp;
rep(j,rest) cout<<".";
cout<<endl;
}
/*rep(i,m){
cout<<s[i]<<endl;
}*/
return 0;
}
|
#include <iostream>
using namespace std;
int main()
{
int N;
cin>>N;
int c;
if(N<=1){
c=0;
}
else {
c=N-1;
}
cout<<c;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
const auto ans = [](int p) { return p > 1? "Even": p < 1? "Odd": "Same"; };
int T; ios_base::sync_with_stdio(false), cin.tie(nullptr), cin >> T;
for (long long N; T--; cout << ans(__builtin_ctzll(N)) << '\n')
cin >> N; }
|
//winners never quit//
//never give up//
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast() ios_base::sync_with_stdio(0);cin.tie(nullptr);
const double PI = acos(-1);
#define MOD 1000000007
#define endl '\n'
const ll inf=1e9+10;
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
os << "{";
for (auto it = v.begin(); it != v.end(); ++it) {
if ( it != v.begin() ) os << ", ";
os << *it;
}
return os << "}";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if ( it != v.begin() ) os << ", ";
os << *it;
}
return os << "]";
}
template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if ( it != v.begin() ) os << ", ";
os << *it;
}
return os << "]";
}
template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if ( it != v.begin() ) os << ", ";
os << it -> first << " = " << it -> second ;
}
return os << "]";
}
#define debug(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {
cerr << endl;
}
template <typename T>
void faltu( T a[], int n ) {
for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
cerr << endl;
}
template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
cerr << arg << ' ';
faltu(rest...);
}
void solve()
{
ll m,h; cin>>m>>h;
if(h%m==0) cout<<"Yes"<<"\n";
else cout<<"No"<<"\n";
}
int main()
{
solve();
}
//Author:_mehedi_ | #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=2*1e9;
const ld PI=acosl(-1);
void Main();
int main(){cout<<fixed<<setprecision(15);Main();}
void Main(){
ll t,N;cin>>t>>N;
ll pos=100*N,ng=0;
while(pos-ng>1){
ll mid=(pos+ng)/2;
if((100+t)*mid/100-mid>=N)pos=mid;
else ng=mid;
}
cout<<(100+t)*pos/100-1<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
int cnt=0;
for(int i=0;i<n;i++)
{
if(arr[i]>10)
{
cnt+=(arr[i]-10);
}
}
cout<<cnt<<endl;
return 0;
}
| #include <bits/stdc++.h>
#define LOCAL
using namespace std;
using ll = long long;
// const int MOD = 1e9 + 7;
#define mem(a, b) memset(a, b, sizeof(a))
#define REP(i, a) for (int i = 0; i < a; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(a) a.begin(), a.end()
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
inline void quickread() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout << fixed << setprecision(10);
}
inline void print_vector(vector<int> &A){
for (auto&& x : A){
cout << x << " ";
}
cout << endl;
}
inline void print_vector(vector<ll> &A){
for (auto&& x : A){
cout << x << " ";
}
cout << endl;
}
inline void print_array(const int A[], int n) {
REP(i, n) {
if (i < n - 1) {
cout << A[i] << " ";
} else {
cout << A[i] << endl;
}
}
}
ll gcd(ll a, ll b) {
if (a < b) swap(a, b);
while (b) {
ll r = a % b; a = b; b = r;
}
return a;
}
inline void solve() {
int n;
cin >> n;
vector<int> a(n);
REP(i, n) cin >> a[i];
ll res = 0;
for (auto x : a) {
res += max(x - 10, 0);
}
cout << res << endl;
}
int main() {
quickread();
int t = 1;
// cin >> t;
for (int _ = 0; _ < t; _++) {
solve();
}
return 0;
}
|
Subsets and Splits