code_file1
stringlengths 87
4k
| code_file2
stringlengths 85
4k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*
*/
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
ll X, Y;
cin >> X >> Y;
for(ll i = -100; i <= 100; i++){
for(ll j = -100; j <= 100; j++){
if (i + j == X && i - j == Y){
cout << i << " " << j << endl;
return 0;
}
}
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << (a + b) / 2 << " " << (a - b) / 2 << endl;
} |
#include <bits/stdc++.h>
#define ll long long
//#include "crocodile.h"
#define pb push_back
#define task "asd"
#define pll pair<ll, ll>
#define pii pair<pll, ll>
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7;
const ll N = 2e5+5;
const int base = 313;
ll n, k, m, tong, ans, t, a[N], b[N];
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n & 1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
void sol()
{
cin >> n >> k;
cout << (k - 1) * pw(k-2, n-1) % mod;
}
int main()
{
if(fopen(task".INP", "r"))
{
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
/*
4
2 5
10 10
2 5
3 3
4 5
5 2 4 9
1
8 8
5 3 1 6 10 100 9 15
https://codeforces.com/contest/791/problem/E
*/
| #include <bits/stdc++.h>
#include <numeric>
using namespace std;
// using mint = long double;
// using mint = modint998244353;
// using mint = modint1000000007;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<ll, vector<ll>> Pd;
const ll INF = 4e18;
const ll fact_table = 3200008;
priority_queue<ll> pql;
priority_queue<P> pqp;
// big priority queue
priority_queue<ll, vector<ll>, greater<ll>> pqls;
priority_queue<P, vector<P>, greater<P>> pqps;
// small priority queue
// top pop
ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
//↓,→,↑,←
/*
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
*/
#define p(x) cout << x << endl;
#define el cout << endl;
#define pe(x) cout << x << " ";
#define ps(x) cout << fixed << setprecision(25) << x << endl;
#define pu(x) cout << (x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = a; i <= (b); i++)
#define rep3(i, a, b) for (ll i = a; i >= (b); i--)
#define all(c) begin(c), end(c)
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
// vec v(n) -> 長さnのベクトルを宣言
// mat dp(h, vec(w)) -> h * w の行列を宣言
// const ll mod = 998244353ll;
const ll mod = 1000000007ll;
ll mypow(ll a, ll b, ll m = mod) {
ll x = 1;
while (b) {
while (!(b & 1)) {
(a *= a) %= m;
b >>= 1;
}
(x *= a) %= m;
b--;
}
return x;
}
vec rv(ll read) {
vec res(read);
for (int i = 0; i < read; i++) {
cin >> res[i];
}
return res;
}
/*
ll fact[fact_table + 5], rfact[fact_table + 5];
void c3_init() {
fact[0] = rfact[0] = 1;
for (ll i = 1; i <= fact_table; i++) {
fact[i] = (fact[i - 1] * i) % mod;
}
rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
for (ll i = fact_table; i >= 1; i--) {
rfact[i - 1] = rfact[i] * i;
rfact[i - 1] %= mod;
}
return;
}
ll c3(ll n, ll r) {
return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;
}
*/
bool icpc = false;
bool multicase = false;
// 配列の長さ、取り間違えてない?
ll m_size = 2;
vec matmul(vec &dp, mat &mt) {
vec ret(m_size, 0ll);
for (ll i = 0; i < m_size; i++) {
for (ll j = 0; j < m_size; j++) {
ret[i] += mt[i][j] * dp[j];
ret[i] %= mod;
}
}
return ret;
}
mat update(mat &mt) {
mat ret(m_size, vec(m_size, 0ll));
for (ll i = 0; i < m_size; i++) {
for (ll j = 0; j < m_size; j++) {
for (ll k = 0; k < m_size; k++) {
ret[i][j] += (mt[i][k] * mt[k][j]) % mod;
ret[i][j] %= mod;
}
}
}
return ret;
}
void matpow(vec &dp, mat &mt, ll k) {
ll m = dp.size();
while (k) {
if (k & 1) dp = matmul(dp, mt);
mt = update(mt);
k /= 2;
}
return;
}
bool solve() {
ll n, p;
cin >> n >> p;
ll ans = mypow(p - 2, n - 1) * (p - 1);
ans %= mod;
p(ans);
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
if (icpc) {
while (solve())
;
return 0;
}
ll q, testcase = 1;
if (multicase) {
cin >> q;
} else {
q = 1;
}
while (q--) {
// cout << "Case #" << testcase << ": ";
solve();
testcase++;
}
// solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<char> a(12);
for ( int k = 0; k < 12; k++){
cin >> a.at(k);
}
int p = 0;
for ( int i = 0; i < 9; i++){
if (a.at(i) == 'Z' && a.at(i + 1) == 'O'){
if (a.at(i + 2) == 'N' && a.at(i + 3) == 'e'){
p++;
}
}
}
cout << p << endl;
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#define is_in(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (int)(x).size()
#define rng(a) a.begin(),a.end()
#define rngr(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#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 ALLR(c) (c).rbegin(), (c).rend()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値;
const int inf = 1<<30;
const double pi = acos(-1);
using ll = long long;
using P = pair<int, int>;
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vs vector<string>
#define vp vector<P>
#define vvp vector<vp>
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
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 n = 0;//"Yes";"No"
string s;
cin >> s;
rep(i, sz(s))if(i+4 <= sz(s)){
string t = s.substr(i, 4);
if(t == "ZONe") ++n;
}
cout << n << endl;
return 0;
} |
#include <cstdio>
#include <cctype>
#define int long long
#define FOR(i,j,k) for(int i=j; i<=k; ++i)
inline long long read (void) {
long long x = 0; int f = 1, ch = getchar();
while(!isdigit(ch)) { if(ch == '-') f = -f; ch = getchar(); }
while(isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); }
return x * f;
}
const int maxn = 200005;
int tot_edge, head[maxn], to[maxn<<1], link[maxn<<1];
long long weight[maxn<<1], a[maxn], ans;
int b[65];
inline void add_edge (int x, int y, long long w) {
to[++tot_edge] = y;
link[tot_edge] = head[x];
weight[tot_edge] = w;
head[x] = tot_edge;
}
void dfs (int x, int f = 0) {
for(int now = head[x]; now; now = link[now]) {
if(to[now] == f) continue;
a[to[now]] = a[x] ^ weight[now];
dfs (to[now], x);
}
}
signed main (void) {
int n = read();
FOR(i,2,n) {
int x = read(), y = read(); long long w = read();
add_edge (x, y, w);
add_edge (y, x, w);
}
dfs (1);
for(int i=n; i>=1; --i)
for(int j=0; j<60; ++j)
if((1ll<<j) & a[i]) ++ b[j];
for(int i=1; i<=n; ++i)
for(int j=0; j<60; ++j)
if((1ll<<j) & a[i]) ans = (ans + (1ll<<j) % 1000000007 * (n-i- --b[j])) % 1000000007;
else ans = (ans + (1ll<<j) % 1000000007 * b[j]) % 1000000007;
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
//indexed set is using "int" here--------- use ll ...
// typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long int ll;
typedef long double ld;
#define FAST \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
while (y > 0)
{
if (y & 1)
res = (res * x) % p;
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
ll modInverse(ll n, ll p)
{
return power(n, p - 2, p);
}
ve <ll> exor,parent;
map <pair<ll,ll>,ll> wt;
void dfs(ll node, ve<pair <ll,ll>> adj[], ve<bool> &visited)
{
visited[node] = true;
// do stuff
exor[node]=exor[parent[node]]^wt[{parent[node],node}];
for (int i = 0; i < (int)adj[node].size(); i += 1)
{
if (!visited[adj[node][i].first])
{
parent[adj[node][i].first]=node;
dfs(adj[node][i].first, adj, visited);
}
}
}
long long int sumXOR(ve <ll> arr, ll n)
{
ll sum = 0;
ll one =1;
for (int i = 0; i < 61; i++)
{
// Count of zeros and ones
ll zc = 0, oc = 0;
// Individual sum at each bit position
long long int idsum = 0;
for (int j = 0; j < n; j++)
{
if (arr[j] % 2 == 0)
zc++;
else
oc++;
arr[j] /= 2;
}
// calculating individual bit sum
idsum = (((oc%rem) * (zc%rem))%rem * ((one << i)%rem))%rem;
// final sum
sum += idsum;
sum%=rem;
}
return sum;
}
int main()
{
FAST;
// freopen("input1.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
/*ll tests;
cin>>tests;
rep (gg,0,tests)
{}*/
ll n;
cin >> n;
exor.assign(n+1,0);
parent.assign(n+1,0);
ve<pair<ll, ll>> adj[n + 1];
rep(i, 0, n - 1)
{
ll u, v, w;
cin >> u >> v >> w;
wt[{u,v}]=w;
wt[{v,u}]=w;
adj[u].pb({v, w});
adj[v].pb({u, w});
}
ve <bool> visit(n+1,false);
dfs(1,adj,visit);
ll sum=0;
rep (i,1,n+1)
{
sum+=exor[i];
}
ve <ll> v1(n);
rep (i,1,n+1)
{
v1[i-1]=exor[i];
}
ll ans=sumXOR(v1,n);
cout<<ans<<"\n";
}
|
#include <bits/stdc++.h>
#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; }
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 A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
void dbg_out() { cerr << " end.\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
const int N = 3e5+5;
const int mod = 1e9+7;
/**
Read problem statement carefully
**/
LL BT[N];
int arr[N];
int n;
void add(int x){
for(; x <= n; x += x&-x)
BT[x]++;
}
int query(int x){
int res = 0;
for(; x > 0; x -= x&-x)
res += BT[x];
return res;
}
void solve(){
cin >> n;
LL inv = 0;
for(int i = 0; i < n; ++i){
cin >> arr[i]; arr[i]++;
inv += i - query(arr[i]);
add(arr[i]);
}
int small, big;
for(int i = 0; i < n; ++i){
cout << inv << "\n";
small = arr[i]-1;
big = n - arr[i];
inv += big - small;
}
}
int main()
{
Fast;
//louisfghbvc
solve();
return 0;
}
/**
enjoy the problem.
**/
| #include<bits/stdc++.h>
using namespace std;
//Ҫ��longlong��Ҫ��longlong��Ҫ��longlong��
//���鿪�������鿪�������鿪����
char s[200005];
int main() {
int t, n;
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
scanf("%s", s);
scanf("%s", s);
scanf("%s", s);
for(int i = 1; i <= n; ++i)
putchar('0');
for(int i = 1; i <= n; ++i)
putchar('1');
putchar('0');
puts("");
/*if(s[0] == s[n - 1] && s[0] == '0') {
}*/
}
getchar();
getchar();
return 0;
}
|
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define FOR(i,a,b,c) for(int i=a;i<b;i+=c)
#define REV(i,a,b,c) for(int i=a;i>=b;i-=c)
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
typedef tree
<int,null_type,less <int>,rb_tree_tag,tree_order_statistics_node_update>
indexed_set;
typedef tree
<int,null_type,less_equal <int>,rb_tree_tag,tree_order_statistics_node_update>
indexed_multiset;
template <typename T>
istream & operator>>(istream &is, vector<T> &v) {
for(auto &data:v){
is>>data;
}
return is;
}
template <typename T>
ostream & operator<<(ostream &os,const vector<T> &v) {
for(auto &data:v){
os<<data<< " ";
}
return os;
}
class BUNrEaDaBlESTrInG {
public:
void solve(std::istream& in, std::ostream& out) {
int T=1;
while(T--){
string s;
in>>s;
int n=s.size();
string ans="Yes";
FOR(i,0,n,1){
if(i%2==0){
if(s[i]>=97 and s[i]<=122){
}
else{
ans="No";
}
}
else{
if(s[i]>=65 and s[i]<=90){
}
else{
ans="No";
}
}
}
out<<ans<< "\n";
}
}
};
int32_t main() {
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
BUNrEaDaBlESTrInG solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define inf 1001000009
#define infmx 1e18ll
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define all(x) x.begin(),x.end()
///debug
#define wh(x) cerr<<#x<<" is "<<x<<endl;
#define error(args...){string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it,args);}
void err(istream_iterator<string>it){cout<<endl;}
template<class H,class... T>void err(istream_iterator<string>it,H a,T... t){cerr<<*it<<" = "<<a<<" | ";err(++it,t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class T>auto&operator<<(ostream& os,vector<T>_v){bool a=1;for(auto x:_v){os<<(a?"":" ")<<x;a=0;}return os;}
///
typedef pair<int,int>pi;
typedef pair<long long,long long>pll;
typedef pair<pi,int>ppi;
typedef pair<int,pi>pip;
typedef vector<int>vi;
typedef vector<pi>vpi;
const int mod=1e9+7;
ll power(ll a,ll p){ll r=1,y=a;while(p){if(p&1)r=(1LL*r*y)%mod;p>>=1;y=(1LL*y*y)%mod;}return r;}
const int N=2100000;
int ara[N];
int main()
{
IOS;
ll n;cin>>n;
ll l=0,r=2000000000;
while(l<=r){
ll mid=(l+r)>>1;
if(mid*(mid+1)/2>(n+1))r=mid-1;
else l=mid+1;
}
// cout<<r<<endl;
cout<<n-r+1<<endl;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define PI = 3.14159265359
#define INF 100100100
#define mod 10000007
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
int main(){
int n;
cin >> n;
vector<int> a(n);
rep(i,n) cin >> a[i];
int ans = 0;
rep(l,n){
int x = INF;
for(int r = l; r < n; ++r){
x = min(x, a[r]);
ans = max(ans, (r-l+1)*x);
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,N) for(int i=0; i<(N); i++)
using namespace std;
int main() {
int N;
cin >> N;
vector<int64_t> a(N);
rep(i,N) cin >> a.at(i);
int64_t ans=0;
rep(i,N){
if(i != 0){
if(a.at(i) == a.at(i-1)) continue;
}
int64_t now=0;
for(int j=i-1; 0<=j; j--){
if(a.at(i) <= a.at(j)) now += a.at(i);
else break;
}
for(int j=i+1; j<N; j++){
if(a.at(i) <= a.at(j)) now += a.at(i);
else break;
}
now += a.at(i);
ans = max(ans,now);
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define mod 1000000007
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int t;cin >> t;
while(t--){
ll l,r,count;
cin >> l >> r;
if(r/2<l)count =0;
else count = r-l-l+1;
cout << count*(count+1)/2 << '\n';
}
}
| #include "bits/stdc++.h"
using namespace std;
using LLI = long long;
#define INF 999999999
#define MOD 1000000007
#define FOR(i, s, e) for(LLI i = s, i##_lim = (e); i < i##_lim; i++)
#define FORR(i, s, e) for(LLI i = s-1, i##_lim = (e); i##_lim<=i; i--)
#define REP(i, n) FOR(i,0,n)
#define REPR(i, n) FORR(i,n,0)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define Mat2(type,name,h,w,def) vector<vector<type>> name(h,vector<type>(w, def))
#define Mat3(type,name,h,w,d,def) vector<vector<vector<type>>> name(h,vector<vector<type>>(w, vector<int>(d,def)))
// int 2.14E±9 LLIi 9.2E±18 double 1.7E±380
int main()
{
cout << fixed << setprecision(10);
int t;
cin >> t;
REP(i, t)
{
LLI l, r;
cin >> l >> r;
if (r < l * 2)
{
cout << 0 << endl;
}
else
{
cout << (r - l * 2 + 1) * (r - l * 2 + 2) / 2 << endl;
}
}
return 0;
} |
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;
/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
if (b == 0) return a;
else return GCD(b, a % b);
}
int main()
{
int H, W;
cin >> H >> W;
vector<vector<int>> A(H, vector<int>(W, 0));
int ans = 0;
int min_val = 101;
rep(i, H) {
rep(j, W) {
cin >> A[i][j];
min_val = min(min_val, A[i][j]);
}
}
rep(i, H) {
rep(j, W) {
ans += A[i][j] - min_val;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int H, W;
cin >> H >> W;
vector<int> A(H*W);
for(int i = 0;i < H*W;i++){
cin >> A.at(i);
}
int m = 100;
for(int i = 0;i < H*W;i++){
m = min(m, A.at(i));
}
int ans = 0;
for(int i = 0;i < H*W;i++){
ans += A.at(i) - m;
}
cout << ans << endl;
} |
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define rep2(i,n,i2,n2) for (ll i = 0; i < (n) ; i++) for (ll i2 = 0; i2 < (n2) ; i2++)
#define incRepFT(i,s,n) for (ll i = (s); i <= (n) ; i++)
#define decRepFT(i,s,n) for (ll i = (s); i >= (n) ; i--)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000 //1e4
#define base10_5 100000 //1e5
#define base10_6 1000000 //1e6
#define base10_7 10000000 //1e7
#define base10_8 100000000 //1e8
#define base10_9 1000000000 //1e9
#define MOD 998244353
#define pb push_back
#define ll long long
#define ld long double
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vstr vector<string>
#define vvstr vector<vector<string>>
typedef pair<ll,ll> P;
// #include <iomanip>
// cout << fixed << setprecision(15) << y << endl;
// for(char c : S)
//min({a1, a2, ..., an})
//max({a1, a2, ..., an})
//swap(a, b)
//S.substr(si)
// sort <--> reverse
//count(v.begin(), v.end(), x)
// char t - 'a'
// char t - '0'
//xを2進数にした時の1の数
//__builtin_popcount(x)
//__builtin_popcountll(x)
ll A;
ll B;
ll C;
ll D;
ll N;
ll M;
ll K;
ll T;
ll H;
ll W;
ll X;
ll Y;
ll Z;
string S;
vstr Ss;
ll ltmp;
string stmp;
double dtmp;
ll llmin(ll a,ll b){
if(a>=b) return b;
return a;
}
ll llmax(ll a,ll b){
if(a<=b) return b;
return a;
}
P d_move[4] = {
P(0 , 1),P(0 , -1),P(1 , 0),P(-1 , 0)//,P(1 , 1),P(1 , -1),P(-1 , 1),P(-1 , -1)
};
//for(P drc : d_move)
double double_hosei = 1000000; //求められる精度分補正をかけておく
map<char,ll> mapcnt[1010];
ll getPower(ll value,ll shisu,ll mod){
ll ans = 1;
ll cnt = shisu;
while(cnt>0){
if(cnt%2==1){
ans = ans * value % mod;
}
value = value * value % mod;
cnt = cnt/2;
}
return ans;
}
ll getans(){
ll sentaku = 0;
ll maxsum = (H-1) + (W-1);
//cout << "start" << endl;
for( ll si = 0 ; si <=maxsum ; si++ ){
map<char,ll> mapcnt;
ll hi_start = llmax(0,si-(W-1));
for( ll hi = 0 ; hi <H ; hi++ ){
ll wi = si - hi;
if(wi < 0 ) break;
if(wi > W-1) continue;
//cout << si << " " << hi << " " << wi << endl;
mapcnt[ Ss[hi][wi] ]++;
}
if(mapcnt['R']>0 && mapcnt['B']>0) return 0;
else{
if(mapcnt['R']==0 && mapcnt['B']==0) sentaku++;
}
}
ll ans = getPower(2,sentaku,MOD);
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> H;
cin >> W;
Ss.resize(H);
rep(hi,H) cin >> Ss[hi];
cout << getans() << endl;
} | #include <iostream>
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
string p[520];
signed main(){
int mx = 0;
int h,w;
cin >> h >> w;
int ans = 1;
for(int i = 0;i < h;i++){
cin >> p[i];
}
bool able = true;
for(int i = 0;i < w;i++){
int sti = i;
int stj = 0;
bool c = true;
int cnt = 0;
map<char,int> mp;
while(sti >= 0 && stj < h){
if(p[stj][sti] != '.'){
if(mp[p[stj][sti]] == 0){
cnt += 1;
mp[p[stj][sti]] = 1;
if(cnt == 2)able = false;
}
c = false;
}
sti--;
stj++;
}
if(c) ans = (ans * 2ll)% 998244353;
}
for(int i = 1;i < h;i++){
int sti = w - 1;
int stj = i;
bool c = true;
int cnt = 0;
map<char,int> mp;
while(sti >= 0 && stj < h){
if(p[stj][sti] != '.'){
if(mp[p[stj][sti]] == 0){
cnt += 1;
mp[p[stj][sti]] = 1;
if(cnt == 2)able = false;
}
c = false;
}
sti--;
stj++;
}
if(c) ans = (ans * 2ll)% 998244353;
}
if(able == true)cout << ans << endl;
else cout << 0 << endl;
} |
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long int;
using pii = pair<ll, ll>;
#define LOCAL
#ifdef LOCAL
#define trace(...) _f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 0
#endif
template <typename T> void _f(const char* name, T&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename T, typename... Args>
void _f(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
_f(comma + 1, args...);
}
void solve() {
ll m, h; cin >> m >> h;
cout << (h % m == 0? "Yes" : "No") << endl;
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);
int t=1;;while(t--)solve();return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); ++i)
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#define DEBUG(x) cerr << '(' << __LINE__ << ") " << #x << ": " << x << endl;
#else
#define DEBUG(x)
#endif
int main() {
vector<int> a(3);
rep(i,3) cin >> a[i];
sort(a.begin(),a.end());
if (a[2]-a[1]==a[1]-a[0]) cout << "Yes" << endl;
else cout << "No" << endl;
}
// end
|
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
#define MOD 1000000007
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int a, b, c, d;
int main(){
cin >> a >> b;
cin >> c >> d;
cout << a*d - b*c << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vi2 vector<vector<int>>
#define vl vector<long long>
#define vl2 vector<vector<long long>>
template <class T> T maxAny(T a, T b){
if(a > b) return a;
else return b;
}
template <class T> T minAny(T a, T b){
if(a > b) return b;
else return a;
}
int main(){
int n, k, m, sum=0;
cin >> n >> k >> m;
vi a(n-1);
rep(i, n-1){
cin >> a[i];
sum += a[i];
}
sum = m*n-sum;
if(sum>k) cout << -1 << endl;
else cout << max(0,sum) << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define print(a) \
for (auto x : a) \
cout << x << " "; \
cout << endl
#define print_upto(a, n) \
for (ll i = 1; i <= n; i++) \
cout << a[i] << " "; \
cout << endl
#define take(a, n) \
for (ll i = 1; i <= n; i++) \
cin >> a[i];
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x, y) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << "\n"
#define watch3(x, y, z) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << " and " << (#z) << " is " << (z) << "\n"
void my_debugger(string s, int LINE_NUM)
{
cerr << endl;
}
template <typename start, typename... end>
void my_debugger(string s, int LINE_NUM, start x, end... y)
{
if (s.back() != ',')
{
s += ',';
cerr << "LINE(" << LINE_NUM << "): ";
}
int i = s.find(',');
cerr << s.substr(0, i) << " = " << x;
s = s.substr(i + 1);
if (!s.empty())
cerr << ", ";
my_debugger(s, LINE_NUM, y...);
}
#define debug(...) my_debugger(#__VA_ARGS__, __LINE__, __VA_ARGS__);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(), (c).end()
#define allr(c) (c).rbegin(), (c).rend()
#define nl "\n"
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define MOD 1000000007
#define inf 1e17
// cout << fixed << setprecision(15) << ans << nl;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> ppll;
const ll N = 200009;
void solve()
{
ll m, h;
cin >> m >> h;
if (h % m == 0)
{
cout << "Yes" << nl;
}
else
{
cout << "No" << nl;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll T = 1;
// cin >> T;
while (T--)
{
solve();
}
return 0;
}
| #include<bits/stdc++.h>
#define int long long
#define ld long double
#define fi first
#define se second
#define vll vector<int>
#define pii pair<int,int>
#define pb push_back
#define sz(v) (int)(v).size()
#define inf (int)(1e18)
#define md (int)(1e9+7)
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=a;i<b;++i)
using namespace std;
const int M = 2e5 + 10;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int B,C;
cin>>B>>C;
if(C==1) {
cout<<(B?2:1);
return 0;
}
// C=2k+1 -> -B-k -B+k 2k+1
// C=2k -> B-k, B+k-1 2k
int k=C/2;
if(C&1) {
int L=max(B-k,-B-k),R=min(B+k-1,-B+k);
cout<<(4*k+1-max(0ll,R-L+1));
return 0;
}
int L=max(B-k,-B-k+1),R=min(B+k-1,-B+k-1);
cout<<(4*k-1-max(0ll,R-L+1));
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
float a=0,b=0;
cin >> a >> b;
float ans=0.0;
if(b!=0)
{
ans=(a*b)/100;
cout << ans << "\n";
}
else
{
cout << "0" << "\n";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i=0;i<n;i++)
#define INF 1000000001
#define lINF 1000000000000001
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvll = vector<vll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vs = vector<string>;
using vc = vector<char>;
using P = pair<ll, ll>;
using si = stack<int>;
using ss = stack<string>;
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;}
//1e9<int型の最大値<1e10
//1e18<long型の最大値<1e19
//配列直入れ↓
//g++ -std=c++17 -Wshadow -Wall -D_GLIBCXX_DEBUG -o a b.cpp && ./a
//bit全探索
//2のk乗は"1<<k"で書ける
int main(){
float a,b;
cin>>a>>b;
cout<<a/100*b<<endl;
} |
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define reps(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define prl(a) cout << (a) << endl
#define allrange(a) a.begin(),a.end()
bool solve_translated(vector<pair<int,int>> &S,vector<pair<int,int>> &T){
int N = S.size();
int dx = S[0].first-T[0].first;
int dy = S[0].second-T[0].second;
bool flg = true;
reps(i,1,N){
if(!((S[i].first==T[i].first+dx) && (S[i].second==T[i].second+dy))){flg = false; break;}
}
return flg;
}
vector<pair<int,int>> Pitagora_rot(vector<pair<int,int>> &S,int a, int b , int c){
int N = S.size();
vector<pair<int,int>> PS(N);
auto pt0 = S[0];
PS[0] = pt0;
bool flg = true;
int dx,dy,x,y;
reps(i,1,N){
dx = S[i].first - pt0.first;
dy = S[i].second - pt0.second;
x=dx*a-dy*b;
y=dx*b+dy*a;
if(((x%c)!=0) || ((y%c)!=0)) {flg = false; break;}
PS[i] = make_pair(x/c+pt0.first, y/c+pt0.second);
}
if(flg) return PS;
else return vector<pair<int,int>>();
}
int main(){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
int N;cin >> N;
vector<pair<int,int>> S(N),T(N);
rep(i,N)
{
int x,y;
cin >> x >> y;
S[i].first = x;S[i].second = y;
}
rep(i,N)
{
int x,y;
cin >> x >> y;
T[i].first = x;
T[i].second = y;
}
sort(allrange(T));
/*ピタゴラ三角形
5 12 13
8 15 17
3 4 5
*/
constexpr int tri[12][3] ={
{3,4,5},
{4,3,5},
{-3,4,5},
{-4,3,5},
{0,1,1},
{1,0,1},
{-1,0,1},
{0,-1,1},
{-3,-4,5},
{-4,-3,5},
{3,-4,5},
{4,-3,5}
};
/*
vector<vector<int>> tri(0);
tri.push_back(vector<int>({3,4,5}));
tri.push_back(vector<int>({4,3,5}));
tri.push_back(vector<int>({-3,4,5}));
tri.push_back(vector<int>({-4,3,5}));
tri.push_back(vector<int>({0,1,1}));
tri.push_back(vector<int>({1,0,1}));
tri.push_back(vector<int>({-1,0,1}));
tri.push_back(vector<int>({0,-1,1}));
tri.push_back(vector<int>({-3,-4,5}));
tri.push_back(vector<int>({-4,-3,5}));
tri.push_back(vector<int>({3,-4,5}));
tri.push_back(vector<int>({4,-3,5}));
// tri.push_back(vector<int>({-5, -12, 13}));
// tri.push_back(vector<int>({-12, -5, 13}));
// tri.push_back(vector<int>({-8,-15,17}));
// tri.push_back(vector<int>({-15,-8,17}));
// tri.push_back(vector<int>({5, 12, 13}));
// tri.push_back(vector<int>({12, 5, 13}));
// tri.push_back(vector<int>({8,15,17}));
// tri.push_back(vector<int>({15,8,17}));
// tri.push_back(vector<int>({-5, 12, 13}));
// tri.push_back(vector<int>({-12, 5, 13}));
// tri.push_back(vector<int>({-8,15,17}));
// tri.push_back(vector<int>({-15,8,17}));
// tri.push_back(vector<int>({5, -12, 13}));
// tri.push_back(vector<int>({12, -5, 13}));
// tri.push_back(vector<int>({8,-15,17}));
// tri.push_back(vector<int>({15,-8,17}));
*/
bool flg;
if(N==2){
auto sx = S[0].first-S[1].first;
auto sy = S[0].second-S[1].second;
auto tx = T[0].first-T[1].first;
auto ty = T[0].second-T[1].second;
flg= (sx*sx+sy*sy==tx*tx+ty*ty);
} else {
rep(j,12){
auto S2 = Pitagora_rot(S,tri[j][0],tri[j][1],tri[j][2]);
if(S2.empty()) continue;
sort(allrange(S2));
flg = solve_translated(S2,T);
if(flg) break;
}
}
if(flg) prl("Yes"); else prl("No");
}
| //Never stop trying
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
#define int ll
typedef string str;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up
template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
ll random(ll a, ll b){
return a + rng() % (b - a + 1);
}
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl;
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;
void IO() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
/////////////////////////ONLY CLEAN CODES ALLOWED/////////////////////////
const int C=1e15;
bool reasonable(int x){
return x>=-C && x<=C;
}
int32_t main() {
boost; IO();
int N; cin>>N;
vi X(N),Y(N);
FOR(i,0,N) cin>>X[i]>>Y[i];
int M; cin>>M;
vpi vec;
FOR(i,0,M){
int t,p=-1; cin>>t;
if(t>=3) cin>>p;
vec.eb(t,p);
}
int a[M],b[M],v[M],v2[M],c[M],d[M];
int cur_a=1,cur_b=1,cur_v=0,cur_v2=1,cur_c=0,cur_d=0;
FOR(i,0,M){
int t=vec[i].fi,p=vec[i].se;
if(t==2){
swap(cur_a,cur_b);
swap(cur_v,cur_v2);
swap(cur_c,cur_d);
cur_a*=-1;
cur_c*=-1;
}
else if(t==1){
swap(cur_a,cur_b);
swap(cur_v,cur_v2);
swap(cur_c,cur_d);
cur_b*=-1;
cur_d*=-1;
}
else if(t==3){
cur_a*=-1;
cur_c*=-1;
cur_c+=2*p;
}
else if(t==4){
cur_b*=-1;
cur_d*=-1;
cur_d+=2*p;
}
a[i]=cur_a; b[i]=cur_b;
v[i]=cur_v; v2[i]=cur_v2;
c[i]=cur_c; d[i]=cur_d;
/*dbg(cur_a)
dbg(cur_v)
dbg(cur_c)*/
}
int Q; cin>>Q;
while(Q--){
int op,i; cin>>op>>i;
op--; i--;
if(op<0){
cout << X[i] << ' ' << Y[i] << endl;
continue;
}
int x=X[i],y=Y[i];
cur_a=a[op];
cur_b=b[op];
cur_c=c[op];
cur_d=d[op];
dbgs(cur_a,cur_b)
if(v[op]==0){
cout << cur_a*x+cur_c << ' ' << cur_b*y+cur_d << endl;
}
else{
cout << y*cur_a+cur_c << ' ' << cur_b*x+cur_d << endl;
}
}
return 0;
}
//Change your approach |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
class UnionFind {
private:
vector<int> ps;
public:
UnionFind(int n){
ps.resize(n);
for(int i = 0; i < n; i++){
ps[i] = i;
}
}
int find_set(int i){
return ps[i] == i ? i : ps[i] = find_set(ps[i]);
}
void unite_sets(int i, int j){
ps[find_set(i)] = find_set(j);
}
};
const int MAXN = 60;
long long fat[MAXN * MAXN];
int main(){
fat[0] = 1;
for(int i = 1; i < MAXN*MAXN; i++){
fat[i] = (i * fat[i-1])%MOD;
}
int N, K;
while(scanf("%d%d", &N, &K) > 0){
int a[N][N];
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
scanf("%d", &a[i][j]);
}
}
UnionFind uf(N);
for(int x = 0; x < N; x++){
for(int y = x+1; y < N; y++){
bool test = true;
for(int i = 0; i < N and test; i++){
test = a[x][i] + a[y][i] <= K;
}
if(test) uf.unite_sets(x, y);
}
}
map<int,int> set_size;
for(int i = 0; i < N; i++){
set_size[uf.find_set(i)]++;
}
long long num_matrices = 1;
for(auto s : set_size){
num_matrices = (num_matrices * fat[s.second]) % MOD;
}
uf = UnionFind(N);
for(int x = 0; x < N; x++){
for(int y = x+1; y < N; y++){
bool test = true;
for(int i = 0; i < N and test; i++){
test = a[i][x] + a[i][y] <= K;
}
if(test) uf.unite_sets(x, y);
}
}
set_size.clear();
for(int i = 0; i < N; i++){
set_size[uf.find_set(i)]++;
}
for(auto s : set_size){
num_matrices = (num_matrices * fat[s.second]) % MOD;
}
printf("%lld\n", num_matrices);
}
}
| #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#define all(x) x.begin(), x.end()
#ifdef _DEBUG
#define disp(x) cout << #x << " : " << x << endl
#else
#define disp(x)
#endif
using namespace std;
using ll = int64_t;
const ll mod = 998244353;
struct mint {
ll x;
mint(ll x=0) : x((x%mod+mod)%mod){}
mint operator-() const {return mint(-x);}
mint& operator+=(const mint a){
if((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a){
if((x += mod - a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a){
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if(!t) return 1;
mint a = pow(t>>1);
a *= a;
if(t&1) a *= *this;
return a;
}
ll val(){ return x; }
// for prime mod
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
friend istream& operator>>(istream& is, mint& a) { return is >> a.x;}
friend ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
};
struct UnionFind {
ll n;
vector<ll> siz, parent;
map<ll,vector<ll>> group;
UnionFind(ll n_) : n(n_), parent(n_), siz(n_, 1) {
for(ll i = 0; i < n; i++) parent[i] = i;
}
ll root(ll x){
if(parent[x] == x) return x;
return parent[x] = root(parent[x]);
}
void unite(ll x,ll y){
ll rx = root(x);
ll ry = root(y);
if(rx == ry) return;
if(siz[rx] < siz[ry]) swap(rx, ry);
siz[rx] += siz[ry];
parent[ry] = rx;
}
bool same(ll x,ll y){
ll rx = root(x);
ll ry = root(y);
return rx == ry;
}
void grouping(){
for(ll i = 0; i < n; i++) root(i);
for(ll i = 0; i < n; i++) group[parent[i]].push_back(i);
}
void clear(){
for(ll i = 0; i < n; i++) { parent[i] = i; }
siz = vector<ll>(n, 1);
group.clear();
}
ll size(ll x){ return siz[root(x)]; }
};
mint fac(ll x) {
mint res = 1;
for(ll i = x; i > 1; i--) {
res *= i;
}
return res;
}
int main(){
int n, k; cin >> n >> k;
int a[n][n]; rep(i, n)rep(j, n) cin >> a[i][j];
UnionFind cntr(n), cntc(n);
rep(i, n)loop(j, i+1, n){
bool flag = true;
rep(l, n) {
if(a[i][l] + a[j][l] > k) flag = false;
}
if(flag) cntr.unite(i, j);
}
rep(i, n)loop(j, i+1, n) {
bool flag = true;
rep(l, n) {
if(a[l][i] + a[l][j] > k) flag = false;
}
if(flag) cntc.unite(i, j);
}
cntr.grouping();
cntc.grouping();
mint ansr = 1, ansc = 1, ans = 1;
for(auto p : cntr.group) {
ansr *= fac(p.second.size());
}
for(auto p : cntc.group) {
ansc *= fac(p.second.size());;
}
ans *= ansr;
ans *= ansc;
cout << ans << endl;
return 0;
}
|
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#include<functional>
#include<iomanip>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)
#define fps(n) fixed << setprecision(n)
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define eldn endl
#define elnd endl
#define icn cin
#define cotu cout
#define Endl endl
#define EE endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b){if(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
int main(){
cin.tie(0);ios::sync_with_stdio(false);
int n; cin >> n;
double ans = 0.0;
reps(i,1,n-1){
ans += (double)n * (1 / (double)i);
}
cout << fps(20) << ans << EE;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
int N;cin>>N;
string S[N];
rep(i,N)cin>>S[i];
vector<vector<int>> D(N,vector<int>(N,1e5));
rep(i,N){
rep(j,N){
if(i==j)D[i][j]=0;
if(S[i][j]=='1')D[j][i]=1;
}
}
rep(k,N){
rep(i,N){
rep(j,N){
D[i][j]=min(D[i][j],D[i][k]+D[k][j]);
}
}
}
double ans=0,t;
rep(i,N){
t=0;
rep(j,N)if(D[i][j]!=1e5)t++;
ans+=1/t;
}
cout<<fixed<<setprecision(9)<<ans;
}
|
#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const int mod=998244353;
const int mex=55;
#define ll long long
#define test int t;cin>>t;while(t--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int>
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++)
#define int long long
int power(int a,int b)
{
int ans=1,f=a;
while(b)
{
if(b&1ll) ans=ans*f%mod;
f=f*f%mod;
b=b>>1ll;
}
return ans%mod;
}
veci v1[mex];
int vis[mex];
int cp;
void dfs(int n)
{
//cout<<n<<endl;
vis[n]=1;
cp++;
fo(i,0,sz(v1[n]))
if(vis[v1[n][i]]==0)dfs(v1[n][i]);
}
signed main()
{
int fact[55];
fact[0]=1;
fo(i,1,mex)fact[i]=fact[i-1]*i%mod;
int n,k;
cin>>n>>k;
int a[n][n];
fo(i,0,n)
fo(j,0,n)
{
cin>>a[i][j];
}
int c[n]={0},r[n]={0};
fo(j,0,n)
{
int cnt=0;
fo(k1,0,j)
{
int fg=0;
fo(i,0,n)
{
if((a[i][j]+a[i][k1])<=k) fg++;
}
if(fg==n)
{
v1[j].pb(k1);
v1[k1].pb(j);
}
}
//c[j]=cnt;
}
int ans=1;
fo(i,0,n)
if(vis[i]==0)
{ dfs(i);
ans=ans*fact[cp]%mod;
cp=0;
}
fo(i,0,n+1)
{
vis[i]=0;
v1[i].clear();
}
fo(j,0,n)
{
int cnt=0;
fo(k1,0,j)
{
int fg=0;
fo(i,0,n)
{
if((a[j][i]+a[k1][i])<=k) fg++;
}
if(fg==n)
{v1[j].pb(k1);
v1[k1].pb(j);
}
}
//r[j]=cnt;
}
fo(i,0,n)
if(vis[i]==0)
{ dfs(i);
ans=ans*fact[cp]%mod;
cp=0;
}
cout<<ans<<endl;
} | #include<ctime>
#include<cstdio>
#include<cctype>
#define ll long long
using namespace std;
const ll N=55;
const ll HgS=998244353;
ll read() {
char c;
ll x=0,f=1;
while(!isdigit(c=getchar()))
f-=2*(c=='-');
while (isdigit(c)){
x=x*10+(c-48)*f;
c=getchar();
}
return x;
}
ll f[N],sz[N],vis[N];
ll n,k,x,jc[N],a[N][N];
void start(){
for(ll i=1;i<=n;++i){
f[i]=i;
sz[i]=1;
vis[i]=0;
}
}
ll get(ll x){
if(x==f[x])
return x;
f[x]=get(f[x]);
return f[x];
}
void merge(ll x,ll y){
x=get(x);
y=get(y);
if(x==y)
return;
f[y]=x;
sz[x]+=sz[y];
}
int main() {
#ifndef ONLINE_JUDGE
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
#endif
clock_t t1=clock();
//--------
x=1;
jc[0]=1;
n=read();
k=read();
for(ll i=1;i<=n;++i)
jc[i]=jc[i-1]*i%HgS;
for(ll i=1;i<=n;++i)
for(ll j=1;j<=n;++j)
a[i][j]=read();
start();
for(ll i=1;i<=n;++i)
for(ll j=1;j<=n;++j){
ll flg=1;
for(ll l=1;l<=n;++l){
if(a[i][l]+a[j][l]>k){
flg=0;
break;
}
}
if(flg)
merge(i,j);
}
for(ll i=1;i<=n;++i){
get(i);
if(vis[f[i]])
continue;
vis[f[i]]=1;
x*=jc[sz[f[i]]];
x%=HgS;
}
start();
for(ll i=1;i<=n;++i)
for(ll j=1;j<=n;++j){
ll flg=1;
for(ll l=1;l<=n;++l){
if(a[l][i]+a[l][j]>k){
flg=0;
break;
}
}
if(flg)
merge(i,j);
}
for(ll i=1;i<=n;++i){
get(i);
if(vis[f[i]])
continue;
vis[f[i]]=1;
x*=jc[sz[f[i]]];
x%=HgS;
}
printf("%lld",x);
//--------
clock_t t2=clock();
fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int n,a[100010];
inline int read()
{
int x=0,w=0;char ch=0;
while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
return w?-x:x;
}
int gcd(int N,int M)
{while(N^=M^=N^=M%=N);return M;}
int main()
{
n=read();
for(int i=1;i<=n;i++){
a[i]=read();
a[1]=gcd(a[1],a[i]);
}
cout<<a[1]<<'\n';
} | #include <iostream>
using namespace std;
const int kMaxN = 21;
int l[kMaxN][kMaxN], a[kMaxN], b[kMaxN];
int n, m, x, y, t, c;
long long ans = 1;
void S(int x) {
if (b[x]) {
return;
}
a[++t] = x;
b[x] = 1;
for (int i = 1; i <= n; i++) {
if (l[x][i]) {
S(i);
}
}
}
void P(int x) {
if (x > t) {
c++;
return;
}
int v[4] = {0};
for (int i = 1; i < x; i++) {
if (l[a[i]][a[x]]) {
v[b[a[i]]] = 1;
}
}
for (int i = 1; i <= 3; i++) {
if (!v[i]) {
b[a[x]] = i;
P(x + 1);
}
}
}
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> x >> y;
l[x][y] = l[y][x] = 1;
}
for (int i = 1; i <= n; i++) {
if (!b[i]) {
t = c = 0;
S(i);
P(1);
ans *= c;
}
}
cout << ans;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXS = 5e4 + 7;
#define FASTIO {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define f(i,n) for(int i = 1 ; i <= N ; i ++)
#define f0(i,n) for(int i = 0 ; i < N ; i ++)
int main(){
FASTIO
int T;
T = 1;
//cin >> T;
while(T --){
int A , B;
cin >> A >> B;
int temp = min(A , B) + 3;
if(temp > max(A,B))
cout << "Yes" << "\n";
else
cout << "No" << "\n";
}
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF (int)1e9
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
//
#define FOR(i, a, b, in) for (int i=a ; i<(b) ; i+=in)
#define RFOR(i, a, b, in) for (int i=a-1 ; i>=(b) ; i-=in)
#define REP(i, a, b) FOR(i, a, b, 1)
#define RREP(i, a, b) RFOR(i, a, b, 1)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define all(cont) cont.begin(), cont.end()
void solve () {
int ans = 0;
int n;
cin >> n;
int a = 1e5 + 1;
int b = 1e5 + 1;
int bb = b;
int p = 0;
int pb = 0;
REP (i, 0, n) {
int tmp, bbb;
cin >> tmp >> bbb;
if (tmp < a) {
a = tmp;
p = i;
} else if (tmp == a) p = -1;
if (bbb <= b) {
bb = b;
b = bbb;
pb = i;
}
}
if (p == pb) {
ans = min(a + b, max(a, bb));
} else {
ans = max(a, b);
}
cout << ans << "\n";
}
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
//$ sudo g++ -o name name.cpp
//$ ./name
|
#include "bits/stdc++.h"
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
long long a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, m =0, n = 0, p = 0, q = 0, mod=998244353;
string s;
char moji;
cin >> a;
n=0;
for(int i=1;n<a;i*=2)
{
m++;
for(int j=0;j<i&&n+j<a;j++)
{
cout << m << ' ';
}
n+=i;
}
return 0;
} | #include<iostream>
#include<vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> A(N,1);
int i,j;
for(i=1;i<N;i++) {
for(j=1;j*j<=i+1;j++) {
if((i+1)%j == 0) {
A[i] = max(A[i],max(A[j-1],A[(i+1)/j-1]));
}
}
A[i]++;
}
for(i=0;i<N;i++)cout << A[i] << " ";
cout << endl;
} |
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;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; }
const long long INF = 1LL <<60;
const long long MOD = 1000000007;
typedef long long ll;
using namespace std;
ll gcd(ll m,ll n){
if(n==0) return m;
return gcd(n,m%n);
}
int main(){
int x, y;
cin >> x >> y;
if(x == 0 && y == 0) cout << 0 << endl;
if(x == 1 && y == 1) cout << 1 << endl;
if(x == 2 && y == 2) cout << 2 << endl;
if(x == 0 && y == 1) cout << 2 << endl;
if(x == 1 && y == 0) cout << 2 << endl;
if(x == 1 && y == 2) cout << 0 << endl;
if(x == 2 && y == 1) cout << 0 << endl;
if(x == 0 && y == 2) cout << 1 << endl;
if(x == 2 && y == 0) cout << 1 << endl;
return 0;
} | /*
GNU G++ compiler
Author-Ajay Raj Singh
while(alive)
{
eat();
sleep();
code();
}
*/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
//#include<boost/multiprecision/cpp.hpp>
//#include<boots/algorithms/string.hpp>
#define ll long long int
#define pii pair<ll,ll>
#define vi vector<ll>
#define vii vector<pii>
#define vs vector<string>
#define vvi vector<vector<ll>>
#define pb push_back
#define flush fflush(stdout)
#define freq(x,val) count(x.begin(),x.end(),val)
#define permute(v) next_permutation(v.begin(),v.end())
#define all(x) x.begin(),x.end()
#define add(v) accumulate(v.begin(),v.end(),0)
#define mci map<char,ll>
#define mii map<ll,ll>
#define endl "\n"
#define db long double
const ll mod=1e9+7;
using namespace __gnu_pbds;
using namespace std;
ll pow(ll x,ll y)
{
ll res=1;
x=x%mod;
while(y>0)
{
if(y&1)
res=(res*x)%mod;
y=y>>1;
x=(x*x)%mod;
}
return res;
}
ll modinv(ll a)
{
return pow(a,mod-2);
}
void printval(ll x,ll y)
{
cout<<"Case #"<<x<<": "<<y<<endl;
return;
}
void solution()
{
ll x,y;
cin>>x>>y;
if(x==y)
cout<<x<<endl;
else
cout<<(3-(x+y))<<endl;
}
int main()
{
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t=1;
//cin>>t;
while(t--)
{
solution();
}
return 0;
} |
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define f(x, m) for(auto x : m)
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int ,int>>
#define vll vector<pair<ll ,ll>>
#define all(v) v.begin(),v.end()
#define sor(a) sort( a.begin(), a.end() )
#define ros(a) sort( a.rbegin(), a.rend())
#define prec(n) fixed << setprecision(n)
#define ff first
#define ss second
#define print(x) for(auto it : x) cout << it << " ";
#define debug(x) cerr << #x << " is " << x << endl;
#define rq(x, y) range_query(1, 0, n, x, y)
#define ru(x, y, val) range_update(1, 0, n, x, y, val)
typedef long long ll;
using namespace std;
// using namespace __gnu_pbds;
#define dbg(args...){ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << "NEXT\n"; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << ", ";
err(++it, args...);
}
template<typename... T>
void rd(T& ... args){
((cin >> args), ...);
}
template<typename... T>
void ps(T ... args){
((cout << args << ' '), ...);
cout << '\n';
}
// using ordered_set = tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7, MOD1 = 998244353LL, MAX = 1e5 + 5;
const char nl = '\n';
const ll INF = 2e18 + 5;
int n;
ll x;
int res(int y, int re){
if(y < 0){
y += re;
}
assert(y >= 0);
return y;
}
void solve(){
cin >> n >> x;
vi a(n);
for(int& it : a){
cin >> it;
}
ll ans = INF;
for(int i = 1; i <= n; i++){
vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(i, vector<ll>(i + 1, -INF)));
// dp[i][j][k] elemento i, con j de modulo con k elementos
for(int j = 0; j < i; j++)
dp[0][j][0] = 0;
for(int l = 1; l <= i; l++){
for(int j = l; j <= n; j++){
for(int k = 0; k < i; k++){
// if(j < l) continue;
dp[j][k][l] = dp[j - 1][k][l];
if((dp[j - 1][res(k - (a[j - 1] % i), i)][l - 1]) % i == res(k - (a[j - 1] % i), i))
dp[j][k][l] = max(dp[j - 1][res(k - (a[j - 1] % i), i)][l - 1] + a[j - 1], dp[j][k][l]);
// dbg(j, k, l, dp[j][k][l]);
}
}
}
if(dp[n][x % i][i] > 0){
// dbg(i, x%i, dp[n][x%i][i]);
ans = min(ans, (x - dp[n][x % i][i]) / i);
}
}
cout << ans << '\n';
}
int main(){
cpu();
int __ = 1;
// cin >> __;
while(__--){
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv){vprint(v)};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20);
ll N;
cin >> N;
vll X(N), Y(N);
rep(i, N) cin >> X[i] >> Y[i];
ll M;
cin >> M;
vvll op(M, vll(2, 0));
rep(i, M){
cin >> op[i][0];
if(op[i][0]>=3) cin >> op[i][1];
}
ll Q;
cin >> Q;
vll A(Q), B(Q);
rep(i, Q) cin >> A[i] >> B[i];
ll a = 1, b = 0, c = 0;
ll d = 0, e = 1, f = 0;
vll as = {a}, bs = {b}, cs = {c}, ds = {d}, es = {e}, fs = {f};
rep(m, M){
switch(op[m][0]){
case 1:{
ll u = a, v = b, w = c;
a = d;
b = e;
c = f;
d = -u;
e = -v;
f = -w;
break;
}
case 2:{
ll u = a, v = b, w = c;
a = -d;
b = -e;
c = -f;
d = u;
e = v;
f = w;
break;
}
case 3:{
a = -a;
b = -b;
c = -c + 2*op[m][1];
break;
}
case 4:{
d = -d;
e = -e;
f = -f + 2*op[m][1];
break;
}
}
as.push_back(a);
bs.push_back(b);
cs.push_back(c);
ds.push_back(d);
es.push_back(e);
fs.push_back(f);
}
rep(q, Q){
ll x = as[A[q]]*X[B[q]-1] + bs[A[q]]*Y[B[q]-1] + cs[A[q]];
ll y = ds[A[q]]*X[B[q]-1] + es[A[q]]*Y[B[q]-1] + fs[A[q]];
cout << x << " " << y << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF 1e9+7
#define rep(i,n) for(ll i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
const int maxn = 200000;
ll mod = INF;
int main(){
string s;
int n,x;
cin >> n>>x;
rep(i,n){
char c;
cin >> c;
if(c=='o'){
x++;
}else{
x=max(0,x-1);
}
}
cout << x<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
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; }
ll a, b, k;
int main() {
cin >> a >> b >> k;
ll sum = a+b;
ll now = 0;
ll acnt = 0;
ll bcnt = 0;
string ans;
for(ll i = 0; i < sum; ++i) {
// cout << "now " << now << endl;
if(a-acnt == 0) {
ans.push_back('b');
bcnt++;
continue;
}
if(b-bcnt == 0) {
ans.push_back('a');
acnt++;
continue;
}
ll ca = a-acnt-1LL;
ll cb = b-bcnt;
ll ue = 1LL;
map<ll, ll> uecnt;
if(ca >= cb) {
for(ll j = 0; j < cb; ++j) {
ll tar = sum-(i+1)-j;
ll tt = tar;
for(ll k = 2; k*k <= tt; ++k) {
if(tar%k == 0) {
while(tar%k == 0) {
tar /= k;
uecnt[k]++;
}
}
}
uecnt[tar]++;
ll tar2 = cb-j;
ll tt2 = tar2;
for(ll k = 2; k*k <= tt2; ++k) {
if(tar2%k == 0) {
while(tar2%k == 0) {
tar2 /= k;
uecnt[k]--;
}
}
}
uecnt[tar2]--;
}
}else {
for(ll j = 0; j < cb; ++j) {
ll tar = sum-(i+1)-j;
ll tt = tar;
for(ll k = 2; k*k <= tt; ++k) {
if(tar%k == 0) {
while(tar%k == 0) {
tar /= k;
uecnt[k]++;
}
}
}
uecnt[tar]++;
ll tar2 = cb-j;
ll tt2 = tar2;
for(ll k = 2; k*k <= tt2; ++k) {
if(tar2%k == 0) {
while(tar2%k == 0) {
tar2 /= k;
uecnt[k]--;
}
}
}
uecnt[tar2]--;
}
}
ll kasan = 1LL;
for(auto x : uecnt) {
for(int l = 0; l < x.second; ++l) {
kasan *= x.first;
}
}
// cout << "now " << kasan << endl;
ll check = now+kasan;
if(check >= k) {
// ここはaを使う
ans.push_back('a');
acnt++;
}else {
now += kasan;
ans.push_back('b');
bcnt++;
}
}
cout << ans << endl;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';
#define all(x) (x).begin(),(x).end()
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
int n;
cin>>n;
string s,t;
cin>>s>>t;
ll r = 0;
ll ans = 0;
for(int i=0;i<n;i++){
chmax(r,i+1);
if(s[i] != t[i]){
while(r<n && s[r] == '0')r++;
if(r == n){
cout << -1 << endl;
return 0;
}
ans += r - i;
s[r] = '0';
s[i] = t[i];
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = i + 1;
}
sort(begin(a), end(a));
string ans = "Yes";
for (int i = 0; i < n; i++) {
if (a[i] != b[i]) {
ans = "No";
break;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a) ;i<(b) ;i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0 ;i<(n) ;i++)
#define RREP(i,n) for (int i=(n)-1;i>=0 ;i--)
#define EACH(i,a,b) for (int i=(a) ;i<=(b);i++)
#define REACH(i,a,b) for (int i=(b) ;i>=(a);i--)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(a,x,b) ((a) <= (x) && (x) < (b))
#define PB push_back
const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;
using ll = long long;
using V = vector<int>;
template<typename T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T = int> T inline input() { T x; cin >> x; return (x); }
template<typename T> void inline print(T& x) { cout << x << '\n'; }
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(16);
int N,M;
cin >> N >> M;
V A(N);
REP(i,N) cin >> A[i];
map<int,int> cnt;
set<int> s;
EACH(i,0,N) {
s.insert(i);
}
int ans = INF;
REP(i,M) {
int a = A[i];
cnt[a]++;
s.erase(a);
}
chmin(ans, *s.begin());
REP(i,N-M) {
int aleft = A[i];
int aright = A[i+M];
cnt[aleft]--;
if (cnt[aleft] == 0) s.insert(aleft);
cnt[aright]++;
s.erase(aright);
chmin(ans, *s.begin());
}
print(ans);
} | #include <cstdio>
const int maxn = 1.5e6+5;
inline int min(int a,int b){return a<b?a:b;}
int n,m,a[maxn],cnt[maxn],mex[maxn<<2],ans=1919810;
void build(int k,int l,int r){
if(l == r)return mex[k]=l,void();
int mid = l+r>>1;
build(k<<1,l,mid),build(k<<1|1,mid+1,r),mex[k] = min(mex[k<<1],mex[k<<1|1]);
}
void insert(int k,int l,int r,int p,int v){
if(l == r){
if(v)++cnt[l],(cnt[l]==1?mex[k]=1919810:0);
else --cnt[l],(cnt[l]==0?mex[k]=l:0);
return ;
}
int mid = l+r>>1;
p<=mid?insert(k<<1,l,mid,p,v):insert(k<<1|1,mid+1,r,p,v);
mex[k] = min(mex[k<<1],mex[k<<1|1]);
}
int main(){
scanf("%d %d",&n,&m),build(1,1,n+1);
for(int i=1;i<=n;++i)scanf("%d",&a[i]),++a[i];
for(int i=1;i<=m;++i)insert(1,1,n+1,a[i],1);
ans=min(ans,mex[1]);
for(int i=m+1;i<=n;++i)insert(1,1,n+1,a[i-m],0),insert(1,1,n+1,a[i],1),ans=min(ans,mex[1]);
printf("%d\n",ans-1);
return 0;
} |
#include <bits/stdc++.h>
#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(n) begin(n),end(n)
using namespace std;
using P = pair<int, int>;
using ll = long long;
int h, w;
bool used[16][16];
ll dfs(int i, int j, int a, int b){
if(j>=w) j=0, i++;
if(i==h) return 1;
if(a<0 || b<0) return 0;
if(used[i][j]) return dfs(i,j+1, a, b);
ll res = 0;
used[i][j] = true;
// 次に置く
res += dfs(i, j+1, a, b-1);
// 横に置く
if(j+1<w && !used[i][j+1]){
used[i][j+1] = true;
res += dfs(i, j+1, a-1, b);
used[i][j+1] = false;
}
// 縦に置く
if(i+1<h && !used[i+1][j]){
used[i+1][j] = true;
res += dfs(i, j+1, a-1, b);
used[i+1][j] = false;
}
used[i][j] = false;
return res;
}
int main()
{
int a, b;
cin >> h >> w >> a >> b;
ll ans = dfs(0, 0, a, b);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef vector<bool> VB;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) LL((a).size())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define ROF(i,a,b) for(LL i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const LL LARGE_INT = 1e9+100;
const LL INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const LL MOD = 1e9+7;
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
LL modpow(LL a, LL n) {
LL res = 1;
while (n > 0) {
if (n & 1) res = res * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return res;
}
void Main()
{
LL k;cin>>k;
LL result = 0;
FOR(i,1,k+1){
LL now = k/i;
for(LL j=1;j*j<=now;j++){
LL sum = 0;
if(now==1){
result++;
}
else{
sum = 1;
sum += (now/j-j) * 2;
result += sum;
}
}
}
cout<<result<<endl;
return;
}
int main()
{
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
} |
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-10;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
if(a>b){
a = b; return true;
}
else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
if(a<b){
a = b; return true;
}
else return false;
}
template<typename T> inline void print(T &a){
for(auto itr = a.begin(); itr != a.end(); itr++){
cout << *itr << " ";
}
cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
cout << "debug: " << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
cout << "debug: " << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;
ll dp[2][50001][3];
int main(){
int n; cin >> n;
vl a(n), b(n);
rep(i,n) cin >> a[i];
rep(i,n) cin >> b[i];
priority_queue<ll> pq0, pq1;
ll ans = 0;
rep(i,n){
if(i & 1) pq1.push(a[i] - b[i]);
else pq0.push(a[i] - b[i]);
ans += b[i];
}
rep(i,n/2){
ll s = pq1.top(); pq1.pop();
ll t = pq0.top(); pq0.pop();
if(s+t < 0) break;
ans += s+t;
}
cout << ans << "\n";
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <iomanip>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define reverseall(x) reverse(all(x))
#define to_upper(x) transform(x.begin(), x.end(), x.begin(), ::toupper)
#define to_lower(x) transform(x.begin(), x.end(), x.begin(), ::tolower)
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORS(i,s,n) for(int i=s;i<n;i++)
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL); cout.tie(NULL);}
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "= " << x << ", " << #y << "= " << y << endl
#define clr(x) memset(x, 0, sizeof(x))
#define gcd __gcd
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef priority_queue<int, vi, greater<int>> minpq;
typedef priority_queue<ll, vi, greater<ll>> minpql;
const int mod = 1000000007;
const double eps = 1e-14;
void YES(bool t = 1) { const string YESNO[2] = {"NO", "YES"};cout << YESNO[t] << endl; }
void Yes(bool t = 1) { const string YesNo[2] = {"No", "Yes"};cout << YesNo[t] << endl; }
void yes(bool t = 1) { const string yesno[2] = {"no", "yes"};cout << yesno[t] << endl; }
inline bool isPowerOfTwo(ll x) { return x && (!(x&(x-1))); }
ll mpow(int b, int e, int modu=0) {
ll result = 1,base = b, exp = e;
if(modu) base %= mod;
while (exp > 0) {
if (exp & 1){
result = ((ll)result * base) ;
if(modu) result %= mod;
}
base = ((ll)base * base);
if(modu) base %= mod;
exp >>= 1;
}
return result;
}
// int64_t bpow(int b, int e){
// int64_t result = 1,base = b, exp = e;
// while (exp > 0) {
// if (exp & 1){
// result = ((int64_t)result * base) ;
// }
// base = ((int64_t)base * base);
// exp >>= 1;
// }
// return result;
// }
// bool isPerfectSquare(long double x){long double sr = sqrt(x); return ((sr - floor(sr)) == 0);}
// bool isIn(string &s2, string &s1){if (s1.find(s2) != string::npos) return true;return false;}
// bool isSorted(vi &arr){for(int i=0;i<(int)arr.size()-1;i++) if(arr[i] > arr[i+1]) return false;return true;}
void print_v(vi &arr){for(auto x: arr) cout << x <<',';cout << "\n";}
int TEST_CASES = 0;
void submain(){
long double x,y,r;
cin >> x >> y >> r;
ll ans = 0;
r += eps;
for(int i=floor(x-r);i<=ceil(x+r);i++){
// deb(i);
long double val = r*r-(i-x)*(i-x);
if(val >= 0){
val = sqrt(val);
long double vala = floor((long double)val+y);
long double valb = ceil((long double)y-val);
// deb2(vala, valb);
ans += (vala-valb+1);
}
}
cout << ans << '\n';
}
int main()
{
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
send help
if(TEST_CASES){
int t;
cin >> t;
while(t--){
submain();
}
}else{
submain();
}
return 0;
} |
// #pragma GCC optimize(3,"Ofast","inline")
// #pragma GCC optimize(2)
// #pragma GCC optimize("-Ofast","-funroll-all-loops")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <string>
#include <iostream>
#include <list>
#include <cstdlib>
#include <bitset>
#include <assert.h>
#include <time.h>
#include <iomanip>
#include <functional>
#include <unordered_map>
#include <unordered_set>
// #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
// char buf[(1 << 21) + 1], * p1 = buf, * p2 = buf;
// #define int long long
#define lowbit(x) (x & (-x))
#define lson root << 1, l, mid
#define rson root << 1 | 1, mid + 1, r
typedef unsigned long long ull;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> VI;
#define rg register
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define SZ(x) ((int)((x).size()))
#define bug puts("BUG")
#define ALL(x) x.begin(),x.end()
const long long INF = 2e18; //0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-10;
void err(){puts("");}
template<typename T,typename... Args>void err(const T& arg,const Args&... args){
std::cout << arg << ' ';
err(args...);
}
template<typename T> void read(T &x){
x = 0;char ch = getchar();ll f = 1;
while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {
read(first);
read(args...);
}
template<typename T>void chmax(T& a,T b){
if (b > a)
a = b;
}
template<typename T>void chmin(T& a,T b){
if (b < a)
a = b;
}
#ifdef LOCAL
#define dbg(x...) do{std::cout<<#x<<" -> ";err(x);}while(0)
FILE *_INPUT = freopen("input.txt", "r", stdin);
// FILE *_OUTPUT = freopen("output.txt", "w", stdout);
#else
#define dbg(x...) ;
#endif
using namespace std;
const int maxn = 2e5 + 10;
const int DEG = 20;
int fa[maxn][20];
int deep[maxn], son[maxn], len[maxn];
vector<int> G[maxn];
int lca(int u,int v)
{
if (deep[u] < deep[v])
swap(u, v);
int x = deep[u] - deep[v];
for (int i = 0; i < DEG && x; ++i)
{
if (x & 1)
u = fa[u][i];
x >>= 1;
}
if (u == v)
return u;
for (int i = 0; i < DEG; ++i)
{
if (fa[u][i] == fa[v][i])
continue;
u = fa[u][i];
v = fa[v][i];
}
return fa[u][0];
}
void dfs(int u, int pre)
{
son[u] = 0;
len[u] = 0;
deep[u] = deep[pre] + 1;
fa[u][0] = pre;
for (int i = 1; i < DEG; ++i)
{
fa[u][i] = fa[fa[u][i - 1]][i - 1];
}
for (int v : G[u])
{
if (v == pre)
continue;
dfs(v, u);
len[u] = max(len[u], len[v] + 1);
if (len[v] > len[son[u]])
son[u] = v;
}
}
ll ans[maxn];
int las = 0;
void dfs2(int u, int pre)
{
ans[u] = ans[las] + deep[u] + deep[las] - 2 * deep[lca(u, las)];
las = u;
for (int v : G[u])
{
if (v == pre || v == son[u])
continue;
dfs2(v, u);
}
if(son[u])
dfs2(son[u], u);
}
int main()
{
int n;
int u, v;
read(n);
for (int i = 1; i < n; ++i)
{
read(u, v);
G[u].emplace_back(v);
G[v].emplace_back(u);
}
dfs(1, 0);
int R = 0;
for (int i = 1; i <= n; ++i)
{
if (deep[i] > deep[R])
R = i;
}
dfs(R, 0);
dfs2(R, 0);
for (int i = 1; i <= n; ++i)
printf("%lld%c", ans[i], " \n"[i == n]);
} | #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <deque>
using namespace std;
using ll = long long;
void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }
#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)
// constexpr int MOD = 1e9+7;
int n;
vc<vc<int>> e;
pair<int, int> farthest(int i, int par = -1){
pair<int, int> ret {0, i};
for(const int &j : e[i]){
if(j == par) continue;
auto next = farthest(j, i);
next.first ++;
Maxi(ret, next);
}
return ret;
}
vc<int> longest(int s, int t, int par = -1){
if(s == t) return {s};
for(const int &i : e[s]){
if(i == par) continue;
auto p = longest(i, t, s);
if(!p.empty()){
p.push_back(s);
return p;
}
}
return {};
}
vc<int> ans;
vc<int> path;
int v = 1;
void assign(int i, int depth = 0, int par = -1){
ans[i] = v;
for(const int &j : e[i]){
if(j == par || (depth != -1 && j == path[depth+1])) continue;
v ++;
assign(j, -1, i);
v ++;
}
if(depth != -1 && depth < path.size()-1){
v ++;
assign(path[depth+1], depth+1, i);
// v ++;
}
}
int main(){
cin >> n;
e = vc<vc<int>>(n);
ans = vc<int>(n);
Rep(n-1){
Cin(int, a, b); a--, b--;
e[a].push_back(b);
e[b].push_back(a);
}
int s = farthest(0).second;
int t = farthest(s).second;
path = longest(t, s);
assign(s);
Couts(ans);
}
|
//* Jai shree Ram
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lld long double
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define vll vector<ll>
#define all(a) (a).begin(),(a).end()
#define sz(a) (int)a.size()
#define pb push_back
#define ppb pop_back
#define pf push_front
#define fr first
#define sc second
#define uniq(v) (v).erase(unique(all(v)),(v).end())
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
void __print(int x) {cerr << x;}void __print(long x) {cerr << x;}void __print(long long x) {cerr << x;}void __print(unsigned x) {cerr << x;}void __print(unsigned long x) {cerr << x;}void __print(unsigned long long x) {cerr << x;}void __print(float x) {cerr << x;}void __print(double x) {cerr << x;}void __print(long double x) {cerr << x;}void __print(char x) {cerr << '\'' << x << '\'';}void __print(const char *x) {cerr << '\"' << x << '\"';}void __print(const string &x) {cerr << '\"' << x << '\"';}void __print(bool x) {cerr << (x ? "true" : "false");}template<typename T, typename V>void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}void _print() {cerr << "]\n";}template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
// __builtin_popcountll(x);
// __builtin_clz(x) // Count Leading zeros
// __builtin_ctz(x) // Trailing zeros
const int MM = 998244353;
const int mod = 1e9 + 7;
const int INF = 1e9 + 5;
const int N = 1e5 + 5;
/* Common Mistakes By Me
* make sure to read the bottom part of question
* special cases (n=1?)
* In Game Theory Check your solution and consider all the solutions
* Always initialise value to the declare array in local scope
* don't use debugs in interactive problems
*/
void solve()
{
lld a,b;
cin >> a >> b;
cout << a*b/100 << "\n";
}
signed main()
{
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int t;
t=1;
// cin>>t;
while(t--)
{
solve();
}
} | #include<bits/stdc++.h>
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
return x*f;
}
long double a,b;
int main()
{
cin>>a>>b;
cout<<a*b*0.01;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
template <int mod> struct ModInt {
int x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if((x += p.x) >= mod) x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if((x += mod - p.x) >= mod) x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int) (1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while(b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
friend ostream &operator<<(ostream &os, const ModInt &p) {
return os << p.x;
}
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt<mod>(t);
return (is);
}
static int get_mod() { return mod; }
};
template <typename T> T power(T a, long long n) {
T r = 1;
while(n > 0){
if(n & 1) r *= a;
a *= a;
n >>= 1;
}
return r;
}
const int mod = int(1e9) + 7;
using mint = ModInt<mod>;
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int N, P; cin >> N >> P;
mint ans = P - 1;
ans *= power(mint(P-2), N-1);
cout << ans << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using LL = long long;
using pii = pair<int, int>;
int main() {
cin.tie(0); ios::sync_with_stdio(0);
LL n, p; cin >> n >> p;
if (p == 2) {
cout << (n==1 ? 1 : 0) << endl;
return 0;
}
LL res = 1, top = n-1, base = p-2, mod = 1e9+7;
while (top) {
if (top & 1) res = res*base%mod;
base = base*base%mod;
top >>= 1;
}
res = res*(--p)%mod;
cout << res << endl;
} |
#include<iostream>
#include<cstdio>
#include<cstring>
typedef long long ll;
typedef unsigned un;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
ll read()
{
ll f=1,x=0;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
return f*x;
}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
bool umin(int& a,int t){if(t<a)return a=t,1;return 0;}
bool umin(ll& a,ll t){if(t<a)return a=t,1;return 0;}
bool umax(int& a,int t){if(t>a)return a=t,1;return 0;}
bool umax(ll& a,ll t){if(t>a)return a=t,1;return 0;}
#define MAXN 511
bool a[MAXN][MAXN];
char s[MAXN];
int main()
{
int n=read();
for(int i=1;i<=n;++i)
{
scanf("%s",s+1);
for(int j=1;j<=n;++j)a[i][j]=(s[j]=='1');
a[i][i]=1;
}
for(int k=1;k<=n;++k)
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j)a[i][j]|=(a[i][k]&a[k][j]);
double ans=0;
for(int u=1;u<=n;++u)
{
int c=0;
for(int s=1;s<=n;++s)c+=a[s][u];
ans+=1.00/c;
}
printf("%.11lf\n",ans);
return 0;
}
| // Coder: @SumitRaut
#include <bits/stdc++.h>
#define speedup ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr),cout.precision(16)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;
#define sbc __builtin_popcount
#define pb push_back
#define em emplace
#define emb emplace_back
#define ff first
#define ss second
#define ll long long
const ll mod = 1e9+7;
template<typename T> void smax(T& a, T b) { if(a<b) a=b; }
template<typename T> void smin(T& a, T b) { if(a>b) a=b; }
template<typename T> T pw(T a,T b) { T p=1,one=1; while(b) { if(b&one) p=p*a; a=a*a; b >>=1; } return p; }
template<typename T> T pwm(T a,T b,T md=mod) { T p=1,one=1; while(b) { if(b&one) p=p*a%md; a=a*a%md; b >>=1; } return p; }
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
for(auto& it:v)
is>>it;
return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
for (auto &it : v)
os << it << ' ';
return os;
}
#ifndef ONLINE_JUDGE
class Timer { chrono::high_resolution_clock::time_point start_t, end_t; public: Timer() { start_t=chrono::high_resolution_clock::now(); } ~Timer() { end_t = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>(end_t-start_t); cerr<<"\nRunTime: "<<duration.count()<<"ms"<<'\n'; } };
void debug() { cerr << '\n'; }
template <typename T, typename... Args>
void debug(T print, Args... args) { cerr << ' ' << print; debug(args...); }
#define deb(...) cerr << "[" << #__VA_ARGS__ << "]" << " --> ", debug(__VA_ARGS__)
#else
#define deb(...) void(0)
#endif
const int inf=1e8;
vector<int> cnt;
void bfs(int v, vector <int> &d, vector<vector<int>>& g) {
queue<int> Qu;
Qu.push(v);
d[v] = 0;
while (!Qu.empty()) {
auto tmp = Qu.front();
Qu.pop();
++cnt[tmp];
for (auto &it:g[tmp]) {
if (d[it] == inf) {
d[it] = d[tmp] + 1;
Qu.push(it);
}
}
}
}
void solve() {
int n;
cin>>n;
vector<vector<int>> g(n);
cnt.assign(n,0);
for(int i=0;i<n;++i) {
string s;
cin>>s;
for(int j=0;j<n;++j)
if(s[j]=='1')
g[i].pb(j);
}
for(int i=0;i<n;++i) {
vector<int> d(n,inf);
bfs(i,d,g);
}
double ans=0.0;
for(auto& it:cnt)
ans+=1.0/it;
cout<<ans<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
Timer timer;
#endif
speedup;
//int t; cin>>t; while(t--)
solve();
}
|
/*---------------------------------------
BISMILLAHIR RAHMANIR RAHIM
AUTHOR : Md. Sajjat Hossen
TIME : 20-March,2021 10:10:41 PM
----------------------------------------*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds_multiset;
inline int Int() { int x; scanf("%d", &x); return x; }
inline ll Long() { ll x; scanf("%lld", &x); return x; }
int dx[8] = { 0, -1, 0, 1, -1, -1, 1, 1 };
int dy[8] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int N = (int) 2e5 + 5;
const int mxN = (int) 1e6 + 6;
const ll MOD = (ll) 1e9 + 7;
#define debug(x) cerr << #x << " = " << x << '\n';
#define all(x) x.begin(), x.end()
#define szof(x) (int) x.size()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI acos(-1.0)
#define TN typename
#define nl '\n'
#define Fast_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
template <TN T> T gcd(T a, T b) { return !b ? a : gcd(b, a % b); }
template <TN T> T lcm(T a, T b) { return a * (b / gcd(a, b)); }
int checkdigit(ll n) {
int res = 0;
while (n) {
res++;
n /= 10;
}
return res;
}
bool checkEqual(ll n, int t) {
//debug("yes")
string s1 = "", s2 = "";
int i = 1;
while (n) {
if (i <= t) s1 += ((n % 10) + '0');
else s2 += ((n % 10) + '0');
n /= 10;
i++;
}
return (s1 == s2) ? 1 : 0;
}
int main() {
//Fast_IO
//clock_t tStart = clock();
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int test = 1, tc = 0;
while (test--) {
ll n = Long();
int k = checkdigit(n);
int i = 1, ans = 0;
while (1) {
int digit = checkdigit(i);
ll x = i * pow(10, digit) + i;
//debug(x)
if (x > n) break;
if (checkEqual(x, digit)) {
//debug(x);
ans++;
}
++i;
}
printf("%d\n", ans);
}
//fprintf(stderr, "\nRuntime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
return 0;
} | //#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <bitset>
#include <complex>
#include <limits>
#include <random>
#include<fstream>
#include<array>
#include<assert.h>
using namespace std;
#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 +7;
const double EPS = 1e-9;
signed main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
string S;
cin >> S;
map<char, int> cmap;
cmap['R'] = 0;
cmap['S'] = 1;
cmap['P'] = 2;
char jan[3][3]=
{
{'R','R','P'},
{'R','S','S'},
{'P','S','P'}
};
rep(i, 0, K)
{
string T;
if (SZ(S) % 2 == 1)
{
S += S;
}
rep(i, 0, SZ(S))
{
if (i % 2 == 1)continue;
T += jan[cmap[S[i]]][cmap[S[i + 1]]];
}
S = T;
}
cout << S[0] << endl;
return 0;
}
|
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define u64 uint64_t
#define ll long long
#define endl "\n"
#define PI acos(-1)
#define fi first
#define si second
#define mkp make_pair
#define pb push_back
#define set0(arr) memset(arr, 0, sizeof(arr))
#define setinf(arr) memset(arr, 126, sizeof(arr))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define all(x) (x).begin(),(x).end()
#define sz(v) ((ll)(v).size())
#define mem(a,b) memset(a, b, sizeof(a))
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define mchk(mask,pos) (mask & (1<<pos))
#define mset(mask,pos) (mask bitor (1<<pos))
#define munset(mask,pos) (mask ^ (1<<pos))
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using pll = pair<ll, ll> ;
using vl = vector<ll> ;
using vpll = vector<pll> ;
using mll = map<ll, ll> ;
using mcl = map<char, ll> ;
using msl = map<string,ll> ;
using sl = set<ll> ;
using sc = set<char> ;
using dl = deque<ll> ;
const int N = 1e6+5 ;
const int mod = (int) 1e9 + 7;
vl adj[N] ;
vpll adjc[N] ; // Only for this N can't be greater than 1e6+5;segmentation fault;
ll vis[N] ;
ll arr[N] ;
ll sumd(ll a,ll b){return (((a%mod)+(b%mod))%mod);}
ll muld(ll a,ll b){return (((a%mod)*(b%mod))%mod);}
ll subd(ll a,ll b){return (((a%mod)-(b%mod)+mod)%mod);}
bool chk(ll ii,ll jj,ll nn,ll mm){if((0<=ii&&ii<nn)&&(0<=jj&&jj<mm)) return true;else return false;}
int main()
{
IOS;
ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi, ma, cs;
string str ;
char ch ;
double db ;
ll l, r ;
//code
cin>>tc;
for(cs=1;cs<=tc;cs++)
{
cin>>n;
string str1,str2,str3;
cin>>str1>>str2>>str3;
for(i=0;i<n;i++)
{
cout<<1;
}
for(i=0;i<n;i++)
{
cout<<0;
}
cout<<1;
cout<<endl;
}
//code
return 0;
}
| #define TO_BE_SUBMITTED
#include <bits/stdc++.h>
// #include <atcoder/fenwicktree>
// #include <atcoder/segtree>
// #include <atcoder/lazysegtree>
// #include <atcoder/string>
// #include <atcoder/math>
// #include <atcoder/convolution>
// #include <atcoder/modint>
// #include <atcoder/dsu>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
// #include <atcoder/scc>
// #include <atcoder/twosat>
namespace atcoder{};
using namespace atcoder;
using namespace std;
#define fr first
#define sc second
#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 srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vlp = vector<LP>;
inline int getInt()
{
int x;
scanf("%d", &x);
return x;
}
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 (a > b)
{
a = b;
return true;
}
return false;
}
ll a, b, c, d;
bool ok(ll x){
return a + b * x <= d * c * x;
}
void solve()
{
cin >> a >> b >> c >> d;
if(c * d <= b){
cout << -1 << "\n";
return;
}
ll l = -1LL;
ll r = 1e8;
while(r - l > 1LL){
ll mid = (r + l) / 2LL;
if(ok(mid)){
r = mid;
} else {
l = mid;
}
}
cout << r << "\n";
}
int main()
{
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
long const mod = 1e9+7;
int main(){
long n,m;
cin >> n >> m;
vector<long>h(n);
vector<long>w(m);
for(int i=0;i<n;i++)cin >> h[i];
for(int i=0;i<m;i++)cin >> w[i];
sort(h.begin(),h.end());
sort(w.begin(),w.end());
vector<long>guki(n);
guki[0] = -h[0];
int a = -1;
for(int i=1;i<n;i++){
a *= -1;
guki[i] = guki[i-1] + a*h[i];
}
long ans = 1LL << 60;
for(int i=0;i<m;i++){
long tmp = 0;
int cnt = upper_bound(h.begin(),h.end(), w[i]) - h.begin();
if(cnt % 2 == 0){
if(cnt != 0)tmp += guki[cnt-1];
tmp -= w[i];
}else{
tmp += guki[cnt - 1];
tmp += w[i];
}
if(cnt == 0){
tmp -= guki[n-1];
}else{
tmp -= (guki[n-1] - guki[cnt-1]);
}
ans = min(ans, tmp);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 10;
long long n, m, Num, a[maxn], b[maxn], cnt[maxn * 2], lstt[maxn * 2], ans = 1e18;
struct My {
long long val, pos, kkk;
inline My() {}
inline My(long long val, long long pos, long long kkk) : val(val), pos(pos), kkk(kkk) {}
} q[maxn * 2];
inline bool comp(const My &x, const My &y) {
return x.val < y.val;
}
int main() {
scanf("%lld%lld", &n, &m);
for (long long i = 1; i <= n; ++i) {
scanf("%lld", &a[i]);
q[i] = My(a[i], i, 1);
}
for (long long i = 1; i <= m; ++i) {
scanf("%lld", &b[i]);
q[i + n] = My(b[i], i, 2);
}
sort(q + 1, q + n + m + 1, comp);
for (long long i = 1, lnk = -1; i <= n + m; ++i) {
if (q[i].kkk == 1) {
if (lnk != -1) {
cnt[i] = cnt[i - 1] + abs(q[i].val - lnk);
lnk = -1;
}
else {
lnk = q[i].val; cnt[i] = cnt[i - 1];
}
} else cnt[i] = cnt[i - 1];
}
for (long long i = n + m, lnk = -1; i; --i) {
if (q[i].kkk == 1) {
if (lnk != -1) {
lstt[i] = lstt[i + 1] + abs(q[i].val - lnk);
lnk = -1;
}
else lnk = q[i].val, lstt[i] = lstt[i + 1];
} else lstt[i] = lstt[i + 1];
}
for (long long i = 1, lnk = -1; i <= n + m; ++i) {
if (q[i].kkk == 2) {
if (lnk != -1) {
ans = min(cnt[i] + lstt[i] + abs(q[i].val - lnk), ans);
++Num;
}
} else {
if (lnk != -1) lnk = -1;
else lnk = q[i].val;
}
}
for (long long i = n + m, lnk = -1; i; --i) {
if (q[i].kkk == 2) {
if (lnk != -1) {
ans = min(cnt[i] + lstt[i] + abs(q[i].val - lnk), ans);
++Num;
}
} else {
if (lnk != -1) lnk = -1; else lnk = q[i].val;
}
}
printf("%lld\n", ans);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
LL n;
LL F[91];
vector<int> seq;
vector<int> ans;
int main()
{
cin>>n;
F[1]=F[2]=1;
for(int i=3;i<=90;i++)
F[i]=F[i-1]+F[i-2];
for(int i=90;i>=1;i--)
if(n>=F[i]) n-=F[i],seq.pb(1);
else if(seq.size()) seq.pb(0);
reverse(seq.begin(),seq.end());
seq.pop_back();
reverse(seq.begin(),seq.end());
int P=seq.size()&1;
ans.pb(1+P);
for(int i=0;i<seq.size();i++)
{
P=1-P;
ans.pb(3+P);
if(seq[i]) ans.pb(1+P);
}
cout<<ans.size()<<'\n';
for(int i=0;i<ans.size();i++)
cout<<ans[i]<<'\n';
return 0;
} | //GIVE ME AC!!!!!!!!!!!!!!!!!
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define ll int
#define ld long double
#define floatset() fixed<<setprecision(15)
#define all(n) n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
#define rep(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define pb push_back
#define eb emplace_back
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
using namespace std;
using vl=vector<ll>;
using vi=vector<int>;
using vs=vector<string>;
using vc=vector<char>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using vvc=vector<vc>;
using vd=vector<double>;
using vp=vector<P>;
using vb=vector<bool>;
using P=pair<ll,ll>;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const ll MOD=1000000007;
const ll mod=998244353;
const double pi=acos(-1);
template<typename T1,typename T2 >
ostream &operator<<(ostream&os,const pair<T1,T2>&p) {
os<<p.first<<" "<<p.second;
return os;
}
template<typename T1,typename T2>
istream &operator>>(istream&is,pair<T1,T2>&p) {
is>>p.first>>p.second;
return is;
}
template<typename T>
ostream &operator<<(ostream&os,const vector<T>&v) {
for(int i=0;i<(int)v.size();i++) {
os<<v[i]<<(i+1!=v.size()?" ":"");
}
return os;
}
template<typename T>
istream &operator>>(istream&is,vector<T>&v) {
for(T &in:v)is>>in;
return is;
}
void scan(){}
template<class Head,class... Tail>
void scan(Head&head,Tail&... tail) {
cin>>head;
scan(tail...);
}
template<class T>
void print(const T &t) { cout << t << '\n'; }
template<class Head, class... Tail>
void print(const Head &head, const Tail &... tail) {
cout << head << ' ';
print(tail...);
}
template<class... T>
void fin(const T &... a) {
print(a...);
exit(0);
}
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);}
vector<ll>prime_factorize(ll N) {
vector<ll>res;
for (ll a = 2; a * a <= N; ++a) {
if (N % a != 0) continue;
while (N % a == 0) {
N /= a;
}
res.push_back(a);
if(N==1)break;
}
if (N != 1) res.push_back(N);
return res;
}
int main(){
LL(l,r);
long long ans=0;
rep(i,max(2,l),r+1){
vl p=prime_factorize(i);
ll cnt=0;
ll s=p.size();
rep(bit,1,(1<<s)){
ll now=1;
rep(j,0,p.size()){
if((bit>>j)&1){
now*=p[j];
}
}
ll res=(r/now)-((i-1)/now);
if(__builtin_popcount(bit)%2==1){
cnt+=res;
}
else{
cnt-=res;
}
}
ans+=cnt;
}
rep(i,max(2,l),r+1){
ans-=r/i;
}
fin(ans*2);
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
long long N;
cin >> N;
vector<long long> A(N),B(N);
for(int i=0;i<N;i++) cin >> A[i];
for(int i=0;i<N;i++) cin >> B[i];
long long Amax=0;
priority_queue<long long> Q;
for(int i=0;i<N;i++){
Amax = max(Amax,A[i]);
Q.push(Amax * B[i]);
cout << Q.top() << endl;
}
return 0;
}
| //#pragma GCC optimize("Ofast")
//#pragma GCC optimize("O2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
////
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>
#include <utility>
#define all(x) (x).begin(), (x).end()
#define allp(x) (x)->begin(), (x)->end()
#define pb push_back
using namespace std;
void dout() { cerr << endl; }
//typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
cerr << H << ' ';
dout(T...);
}
using ll = long long;
//#ifdef __int128
//using hll = __int128;
//#endif
using pii = pair<ll, ll>;
using ld = long double;
template <typename T>
void do_uniq(vector<T> &vec){
sort(all(vec));
vec.resize(unique(all(vec)) - vec.begin());
}
#ifndef ONLINE_JUDGE
clock_t timestamp_start = clock();
void time_calc()
{
cerr << (ld)(clock() - timestamp_start) / CLOCKS_PER_SEC << "\n";
}
#endif
#ifdef _getchar_nolock
#else
# define _getchar_nolock getchar_unlocked
#endif
#define integer int
integer mod = 1e9 + 7;
integer ml(integer a, integer b) {
return (a * 1ll * b) % mod;
}
integer add(integer a, integer b) {
integer rt = a + b;
if (rt < mod) return rt;
return rt - mod;
}
integer sub(integer a, integer b) {
return add(a, mod - b);
}
integer sq(integer a) {
return ml(a, a);
}
integer b_p(integer b, ll p) {
if (p == 0) return 1;
if (p & 1) return ml(b, b_p(b, p - 1));
return sq(b_p(b, p >> 1));
}
const ll inf = 1e18 + 231;
#define solvsh
//#define multi
#ifdef solvsh
void precalc() {}
const int INF = 2e9;
vector<int> divs[200];
const int MAXN = 52;
ld C[MAXN][MAXN];
void solve() {
int n;
cin >> n;
vector<ll> ai;
vector<ll> bi;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
ai.push_back(a);
}
for (int i = 0; i < n; ++i) {
int b;
cin >> b;
bi.push_back(b);
}
ll a_mx = ai[0];
ll c_mx = bi[0] * ai[0];
for (int i = 0; i < n; ++i) {
a_mx = max(a_mx, ai[i]);
c_mx = max(c_mx, bi[i] * a_mx);
cout << c_mx<< "\n";
}
}
#else
void precalc() {}
void solve() {}
#endif
void multisolve() {
precalc();
int t;
cin >> t;
int i = 1;
while (t--) {
solve();
i++;
}
}
void singlesolve (){
precalc();
solve();
}
#ifndef ONLINE_JUDGE
void gen() {
}
#endif
#define int int
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cout << fixed << setprecision(20);
#ifdef multi
// gen();
multisolve();
#else
singlesolve();
// gen();
#endif
// time_calc();
} |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr LL mod = 998244353;
constexpr int maxn = 200000 + 1;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, K;
cin >> N >> K;
vector<vector<int>> G(N + 1);
for(int i = 1, u, v; i < N; i += 1){
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
vector<int> size(N + 1), cut(N + 1), msize(N + 1);
int center = 0;
function<void(int, int, int)> fc = [&](int u, int par, int tot){
size[u] = 1;
msize[u] = 0;
for(int v : G[u]) if(v != par and not cut[v]){
fc(v, u, tot);
size[u] += size[v];
msize[u] = max(msize[u], size[v]);
}
msize[u] = max(msize[u], tot - size[u]);
if(msize[u] < msize[center]) center = u;
};
msize[center] = INT_MAX;
fc(1, 0, N);
vector<vector<pair<int, int>>> vvn(N + 1);
function<void(int, int, int, int)> DFS = [&](int u, int par, int dep, int root){
vvn[u].push_back({root, dep});
for(int v : G[u]) if(v != par and not cut[v]) DFS(v, u, dep + 1, root);
};
function <void(int, int)> solve = [&](int u, int tot){
vvn[u].push_back({u, 0});
for(int v : G[u]) if(not cut[v])
DFS(v, u, 1, u);
cut[u] = 1;
for(int v : G[u]) if(not cut[v]){
center = 0;
if(size[v] > size[u]) size[v] = tot - size[u];
fc(v, 0, size[v]);
solve(center, size[v]);
}
};
solve(center, N);
vector<vector<int>> par(N + 1, vector<int>(19));
vector<int> dep(N + 1), p(N + 1);
function<void(int)> dfs = [&](int u){
for(int i = 1; i < 20; i += 1)
par[u][i] = par[par[u][i - 1]][i - 1];
for(int v : G[u]) if(par[u][0] != v){
par[v][0] = u;
dep[v] = dep[u] + 1;
dfs(v);
}
};
auto ga = [&](int u, int k){
for(int i = 19; i >= 0; i -= 1)
if(k >= (1 << i)){
k -= 1 << i;
u = par[u][i];
}
return u;
};
dfs(1);
for(int i = 1; i <= N; i += 1) p[i] = i;
sort(p.begin() + 1, p.end(), [&](const int& x, const int& y){
return dep[x] > dep[y];
});
int L = 1, R = N - 1;
while(L < R){
int M = (L + R) >> 1, k = 0;
//cout << L << " " << R << " " << M << endl;
vector<int> d(N + 1, -1E9);
for(int i = 1; i <= N; i += 1){
int u = p[i], vis = 0;
for(auto [v, dr] : vvn[u])
if(d[v] >= dr) vis = 1;
if(vis) continue;
k += 1;
int x = ga(u, M);
if(x == 0) break;
for(auto [v, dr] : vvn[x]) if(M >= dr)
d[v] = max(d[v], M - dr);
}
//cout << k << endl;
if(k > K) L = M + 1;
else R = M;
}
cout << L << "\n";
return 0;
} | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define forn(a, e) for (i64 a = 0; a < (i64)(e); a++)
#define forr(a, s, e) for (i64 a = s; a < (i64)(e); a++)
#define fore(e, a) for (auto& e : a)
#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logvff(a, f1, f2) {cerr << #a".{"#f1 << ", "#f2 << "} = \n"; fore(e, a) { cerr << "(" << e.f1 <<", " << e.f2 << ") ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logvff(a, f1, f2)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif
using iip = pair<int, int>;
using llp = pair<i64, i64>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;
template<typename T> using vec = vector<T>;
template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }
template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }
template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }
template<typename T, size_t N>
istream& operator>>(istream& is, array<T, N>& c) { for (auto& e : c) is >> e; return is; }
template<typename ...T>
istream& read(T&... args) { return (cin >> ... >> args); }
static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }
// const i64 INF = 2e18;
const int INF = 2e9;
const __int128_t M = 1000000;
const int MXB = 20;
using bin = bitset<MXB + 1>;
const double EPS = 1e-8;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
rande.seed(chrono::steady_clock::now().time_since_epoch().count());
string s;
while (read(s)) {
int n = s.size();
auto cc = make_vec(0, n + 1, 26);
for (int i = n - 1; i >= 0; i--) {
for (int j = 0; j < 26; j++) {
cc[i][j] = cc[i + 1][j];
}
cc[i][s[i] - 'a']++;
}
i64 ans = 0;
int lp = n;
char lc = 0;
for (int i = n - 3; i >= 0; i--) {
if (s[i] == s[i + 1] && s[i + 1] != s[i + 2]) {
int cl = cc[i + 2][s[i] - 'a'] - cc[lp][s[i] - 'a'];
ans += max(0, lp - (i + 2) - cl);
if (s[i] != lc) {
ans += n - lp;
}
lp = i;
lc = s[i];
}
}
cout << ans << endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef std::vector<bool> vb;
typedef std::vector<std::vector<bool>> vvb;
typedef std::vector<string> vstr;
typedef std::pair<long long, long long> pll;
#define INF 1999999999
#define INFLL std::numeric_limits<long long>::max()
#define MODA 1000000007
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define rep1(i,n) for (long long i = 1; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define errv1(x) cerr << #x <<" "<< x << endl;
#define errv2(x, y) cerr << #x <<" "<< x <<" "<< #y <<" "<< y << endl;
#define errv3(x, y, z) cerr << #x <<":"<< x <<" "<< #y <<":"<< y <<" "<< #z <<":"<< z << endl;
#define errv4(x, y, z, a) cerr << #x <<":"<< x <<" "<< #y <<":"<< y <<" "<< #z <<":"<< z <<" "<< #a <<":"<< a << endl;
int main() {
ll H, W;
cin >> H >> W;
vvll A(H, vll(W));
rep(i,H){
rep(j,W){
cin >> A[i][j];
}
}
ll mini = INFLL;
rep(i,H){
rep(j,W){
mini = min(mini, A[i][j]);
}
}
ll ans =0;
rep(i,H){
rep(j,W){
ans += A[i][j] - mini;
}
}
cout << ans << endl;
return 0;
}
| #include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <list>
#include <cassert>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define ll long long
#define repi(i,a,b) for(ll i=a;i<b;++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
using vvv = vector<vector<vector<ll>>>;
using vv = vector<vector<ll>>;
using vec = vector<ll>;
using P = pair<ll, ll>;
int main(void) {
ll n; cin >> n;
ll ans = INF;
rep(i, n) {
ll a, p, x; cin >> a >> p >> x;
if (x - a > 0) ans = min(ans, p);
}
if (ans == INF) ans = -1;
cout << ans << endl;
system("pause");
} |
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main ()
{
string s[3];
int per[10];
set<char> sc;
rep(i,3){
cin>>s[i];
rep(j,s[i].length()){
sc.insert(s[i][j]);
}
}
if (sc.size()>10) {
cout<< "UNSOLVABLE";
return 0;
}
iota (per,per+10,0);
map<char,int> ci;
int il =0;
do{
long num[3]={0};
bool check = true;
int ii =0;
for ( auto it = sc.begin(); it != sc.end();it++ ){
ci[*it] = per[ii];
ii++;
}
rep(i,3){
rep(j,s[i].length()) {
int temp = ci[s[i][j]];
num[i]*=10; num[i]+=temp;
if (j==0 && temp ==0) check =false;
}
}
if (check== true){
if (num[0]+num[1]==num[2]){
cout<<num[0]<<endl<<num[1]<<endl<<num[2];
return 0;
}
}
}while (next_permutation(per,per+10));
cout<< "UNSOLVABLE";
return 0;
}
| #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// using cint = cpp_int;
#define fastio \
std::cin.tie(nullptr); \
std::ios::sync_with_stdio(false);
using ll = long long;
using ld = long double;
#define For(i, m, n) for(int i = (m); (i) < (n); ++(i))
#define Rep(i, n) For(i, 0, n)
#define Each(e, con) for(auto e: con)
#define rEach(e, con) for(auto &e: con)
#define crEach(e, con) for(const auto &e: con)
#define All(con) (con).begin(), (con).end()
#define Unique(con) std::sort(All(con)); (con).erase(std::unique(All(con)), (con).end())
#define Reverse(con) std::reverse(All(con))
#define Middle(con) (con).begin() + ((con).end() - (con).begin()) / 2
template <class Ty1, class Ty2>
std::istream &operator>>(std::istream &is, std::pair<Ty1, Ty2> &arg)
{ is >> arg.first >> arg.second; return is; }
template <class Ty>
std::istream &operator>>(std::istream &is, std::vector<Ty> &arg)
{ rEach(e, arg) is >> e; return is; }
template <class Ty>
std::istream &operator>>(std::istream &is, std::vector<std::vector<Ty>> &arg)
{ rEach(sub, arg) { rEach(e, sub) { is >> e; }} return is; }
template <class Ty1, class Ty2>
std::istream &vecinput(std::vector<Ty1> &arg1, std::vector<Ty2> &arg2)
{ assert(arg1.size() == arg2.size());
auto sz = arg1.size(); Rep(i, (int)sz) std::cin >> arg1[i] >> arg2[i]; return std::cin; }
template <class Ty1, class Ty2, class Ty3>
std::istream &vecinput(std::vector<Ty1> &arg1, std::vector<Ty2> &arg2, std::vector<Ty3> &arg3)
{ assert(arg1.size() == arg2.size()); assert(arg2.size() == arg3.size());
auto sz = arg1.size(); Rep(i, (int)sz) std::cin >> arg1[i] >> arg2[i] >> arg3[i]; return std::cin; }
template <class Ty1, class Ty2, class Ty3, class Ty4>
std::istream &vecinput(std::vector<Ty1> &arg1, std::vector<Ty2> &arg2, std::vector<Ty3> &arg3, std::vector<Ty4> &arg4)
{ assert(arg1.size() == arg2.size()); assert(arg2.size() == arg3.size()); assert(arg3.size() == arg4.size());
auto sz = arg1.size(); Rep(i, (int)sz) std::cin >> arg1[i] >> arg2[i] >> arg3[i] >> arg4[i]; return std::cin; }
int main() {
fastio
string a, b, c;
cin >> a >> b >> c;
vector<char> alpha;
crEach(e, a) alpha.push_back(e);
crEach(e, b) alpha.push_back(e);
crEach(e, c) alpha.push_back(e);
Unique(alpha);
if(alpha.size() > 10) {
puts("UNSOLVABLE");
return 0;
}
vector<int> digit{0,1,2,3,4,5,6,7,8,9};
map<char, int> mp;
do {
Rep(i, (int)alpha.size()) {
mp[alpha[i]] = digit[i];
}
ll x = 0, y = 0, z = 0;
if(mp[a[0]] == 0) continue;
if(mp[b[0]] == 0) continue;
if(mp[c[0]] == 0) continue;
Rep(i, (int)a.size()) x = x * 10 + mp[a[i]];
Rep(i, (int)b.size()) y = y * 10 + mp[b[i]];
Rep(i, (int)c.size()) z = z * 10 + mp[c[i]];
if(x + y == z) {
cout << x << endl;
cout << y << endl;
cout << z << endl;
return 0;
}
} while(next_permutation(All(digit)));
puts("UNSOLVABLE");
return 0;
} |
// main.cpp
// ABC182F
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
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 argc, const char * argv[]) {
int n;
cin>>n; // コインの種類数、コインが1円だけの時、払い方は1通り
if(n==1){
cout<<1<<endl;
return 0;
}
ll x;
cin>>x; // 代金
vector<ll>a(n); // コイン
rep(i,n) cin>>a[i];
if(x%a[n-1]==0){
cout<<1<<endl;
return 0;
}
vector<ll>r(n); // 使える枚数
rep(i,n-1) r[i]=a[i+1]/a[i]-1;
r[n-1]=x/a[n-1];
vector<ll> d(2); // 代金との差額
d[0]=a[n-1]*r[n-1]-x;
d[1]=a[n-1]*(r[n-1]+1)-x;
ll e=0;
// i番目までで、代金との差d=map->firstになる個数
// 代金との差はたかだか2種類、数値が大きいのでmapで管理する
vector<vector<int>>dp(n,vector<int>(2));
dp[n-1][0]=1;
dp[n-1][1]=1;
map<ll,ll>mp0,mp1;
int i=n-2;
while(d[0]!=0){
mp0.clear();
if(abs(d[0])<a[i]) mp0[d[0]]++;
ll lmt0=d[0]/a[i]; // 調査する範囲を絞る TLE解消
for(ll j=lmt0-1;j<=lmt0+1;j++){
if(j==0)continue;
if(abs(j)>r[i])continue;
e=d[0]+a[i]*j;
if(abs(e)<a[i]){
mp0[e]++;
if(mp0.size()==2) break;
}
e=d[0]-a[i]*j;
if(abs(e)<a[i]){
mp0[e]++;
if(mp0.size()==2) break;
}
}
map<ll,int>nd;// 次のdの候補
for(auto es=mp0.begin();es!=mp0.end();es++){
nd[es->first]++;
if(mp0.begin()->first==es->first){
dp[i][0]+=es->second*dp[i+1][0];
}else{
dp[i][1]+=es->second*dp[i+1][0];
}
}
mp1.clear();
if(abs(d[1])<a[i]) mp1[d[1]]++;
ll lmt1=d[1]/a[i]; // 調査する範囲を絞る TLE解消
for(ll j=lmt1-1;j<=lmt1+1;j++){
if(j==0) continue;
if(abs(j)>r[i])continue;
e=d[1]+a[i]*j;
if(abs(e)<a[i]){
mp1[e]++;
if(mp1.size()==2) break;
}
e=d[1]-a[i]*j;
if(abs(e)<a[i]){
mp1[e]++;
if(mp1.size()==2) break;
}
}
for(auto es=mp1.begin();es!=mp1.end();es++){
nd[es->first]++;
if(mp0.begin()->first==es->first){
dp[i][0]+=es->second*dp[i+1][1];
}else{
dp[i][1]+=es->second*dp[i+1][1];
}
}
int d_cnt=0;
for(auto cs=nd.begin();cs!=nd.end();cs++){
d[d_cnt]=cs->first;
d_cnt++;
}
i--;
if(i<0) i=0;
}
ll ans=dp[i+1][0]+dp[i+1][1];
cout<<ans<<endl;
return 0;
}
/*
2 300
1 100
*/
| #include<bits/stdc++.h>
using namespace std;
#define eps 1e-10
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<r;i++)
#define rrep(i,r,l) for(int i=r-1;i>=l;i--)
typedef long long ll;
int n;
ll x,a[55],b[55];
map<ll,int> v;
int main()
{
scanf("%d%lld",&n,&x);
rep(i,0,n) scanf("%lld",&a[i]);
rep(i,0,n-1) b[i]=a[i+1]/a[i];
v[x%a[n-1]]=1;
if(x%a[n-1]!=0) v[x%a[n-1]-a[n-1]]=1;
rrep(i,n-1,0){
map<ll,int> u;
for(auto x:v){
ll c=(x.first+a[i+1])%a[i];
ll d=(x.first-c)/a[i];
if(abs(d)<b[i]) u[c]+=x.second;
if(c&&abs(d+1)<b[i]) u[c-a[i]]+=x.second;
}
v.clear(),v=u;
}
printf("%lld\n",v[0]);
return 0;
} |
#include <iostream>
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define max_value 0x3f3f3f
#define all(v) v.begin(),v.end()
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
using namespace std;
typedef pair<ll,ll> pii;
const int inf=1e9+7;
const int mod=998244353;
const int maxn=2e3+1;
ll sqr(ll x){
return x*x;
}
/*ll invfac(ll a,ll b){
return (f[a]*modexpo((f[b]*f[a-b])%inf,inf-2))%inf;
}*/
ll modexpo(ll a,ll b){
a%=inf;
ll res=1;
while(b>0){
if(b&1)
res=res*a%inf;
a=a*a%inf;
b>>=1;
}
return res;
}
void solve(){
ll sum=0;
ll n,k;
cin>>n>>k;
ll z=100;
for(int j=1;j<=n;j++){
for(ll i=1;i<=k;i++){
sum+=z+i;
}
z+=100;}
cout<<sum;
}
int main(){
/*file;*/
int t;
t=1;
while(t--){
solve();
}
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,x,n) for(int i=x;i<=n;i++)
#define all(v) v.begin(),v.end()
#define foreach(c,itr) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)
#define p_b push_back
#define pii pair<int,int>
#define fr first
#define sc second
#define m_p make_pair
#define zero(a) memset(a,0,sizeof(a))
#define setp setprecision
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f;
const ll mod=1000000007;
const ld eps=1e-14;
int i,j;
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n,k;
cin>>n>>k;
int ans=n*(n+1)/2*100*k+k*(k+1)/2*n;
cout<<ans<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#pragma optimize("-O3")
#define int long long int
#define f first
#define s second
#define pb push_back
#define endl '\n'
const int N=3e5+5;
int cnt[N];
main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k;
cin>>n>>k;
for(int i=0; i<n; i++){
int x;
cin>>x;
cnt[x]++;
cnt[x]=min(cnt[x], k);
}
int ans=0;
int rem=k;
for(int i=0; i<N; i++){
int cn=min(cnt[i], rem);
if(cn==rem){
continue;
}
else{
ans+=i*(rem-cn);
rem=cn;
}
}
cout<<ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
constexpr int DEBUG = 0;
constexpr int64 P = 1000000007;
struct FiniteField {
private:
int64 x;
public:
FiniteField(int64 raw_x) : x(raw_x) {
if (x >= P || x < 0) {
x %= P;
if (x < 0) x += P;
}
}
FiniteField() : x(0) {}
int64 Value() const { return x; }
inline FiniteField operator+(FiniteField o) const {
FiniteField r(*this); r += o; return r;
}
inline FiniteField operator-(FiniteField o) const {
FiniteField r(*this); r -= o; return r;
}
inline FiniteField operator* (FiniteField o) const {
FiniteField r(*this); r *= o; return r;
}
inline FiniteField operator/ (FiniteField o) const {
FiniteField r(*this); r /= o; return r;
}
inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
void operator/=(FiniteField o) {
int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
}
};
ostream& operator<<(ostream& s, const FiniteField& x) { s << x.Value(); return s; }
FiniteField Solve() {
int n;
cin >> n;
int64 m;
cin >> m;
int64 s = 0;
vector<int64> xs(n);
for (int i = 0; i < n; i++) {
cin >> xs[i];
s += xs[i];
}
if (m < s) {
return 0;
}
int64 r = m - s;
int64 g = s + n - 1;
int64 a = r + g + 1;
int64 b = g + 1;
FiniteField x = 1;
for (int64 i = 1; i <= b; i++) {
x *= (a - i + 1);
x /= i;
}
return x;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << Solve() << endl;
} |
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <list>
#include <cassert>
#include <climits>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;
#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define FORSZ(i,a,v) FOR(i,a,SZ(v))
#define REPSZ(i,v) REP(i,SZ(v))
std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 200000;
int n, m;
int s[MAXN], t[MAXN];
vector<int> adj[MAXN];
bool done[MAXN];
int q[MAXN], qhead, qtail;
bool solve() {
REP(i, n) done[i] = false;
REP(i, n) if (!done[i]) {
qhead = qtail = 0; q[qhead++] = i, done[i] = true; ll ssum = 0, tsum = 0;
while (qtail < qhead) {
int at = q[qtail++];
ssum += s[at], tsum += t[at];
REPSZ(j, adj[at]) {
int to = adj[at][j];
if (!done[to]) done[to] = true, q[qhead++] = to;
}
}
if (ssum != tsum) return false;
}
return true;
}
void run() {
scanf("%d%d", &n, &m);
REP(i, n) scanf("%d", &s[i]);
REP(i, n) scanf("%d", &t[i]);
REP(i, m) { int a, b; scanf("%d%d", &a, &b); --a, --b; adj[a].PB(b); adj[b].PB(a); }
printf("%s\n", solve() ? "Yes" : "No");
}
int main() {
run();
return 0;
}
| //Author: master19
#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 ll long long int
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
#define mod 1000000007LL // fixed...
#define modd 1000000007LL // Can be changed for global use
#define all(arr) arr.begin(),arr.end()
#define x(arr) arr.begin(),arr.end()
#define ulli unsigned long long int
#define assign(x,val) memset(x,val,sizeof(x))
#define prec(val, dig) fixed << setprecision(dig) << val
#define Sort(arr) sort(arr.begin(), arr.end())
#define time() std::chrono::high_resolution_clock::now();
#define lower(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define upper(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
#define crap ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define get(arr, num) vector < ll > arr(num); for(int i=0; i<num; i++)cin >> arr[i];
#define get_set(arr, num, st, type) set < type > st; for(int i=0; i<num; i++) st.insert(arr[i]);
#define put(arr, num) for(int i=0; i<num; i++)cout << arr[i] << " "; cout << endl;
#define Time(start, finish) std::chrono::duration<double> elapsed = finish - start; cout << elapsed.count() << endl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > new_ds;
void debug_out() { cerr << endl; }
template <typename HeadStart, typename... TailEnd>
void debug_out(HeadStart H, TailEnd... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
ll lets_do_it();
ll dx[] = {-1, 1, 0, 0};
ll dy[] = {0, 0, -1, 1};
pair < ll, ll > dig[] = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}};
bool isValid(ll x, ll y, ll row, ll col){
return ((x>=0) && (y >=0) && (x < row) && (y < col));
}
int main(int argc, const char** argv) {
crap;
ll test = 1;
// cin >> test;
auto start = std::chrono::high_resolution_clock::now();
for(int loop=0; loop<test; loop++){
// cout << "Case #" << (loop+1) << ": ";
lets_do_it();
}
auto finish = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = finish - start;
cerr << "Game is on :-> " << elapsed.count() << "s"<< endl;
return 0;
}
ll dfs(vector < vector < ll > > & graph, vector < ll > & init, vector < ll >& final, vector < bool > & visit, ll start, ll *left, ll *right){
*left += init[start-1];
*right += final[start-1];
visit[start] = true;
for(int i=0; i<graph[start].size(); i++){
if(!visit[graph[start][i]]){
dfs(graph, init, final, visit, graph[start][i], left, right);
}
}
return 0;
}
bool dfsHelper(vector < vector < ll > > &graph, vector < ll >&init, vector < ll >&final){
vector < bool > visit(graph.size(), false);
ll left = 0, right = 0;
bool res = true;
for(int i=1; i<graph.size(); i++){
if(!visit[i]){
left = 0, right = 0;
dfs(graph, init, final, visit, i, &left, &right);
if(left == right)
res = res & true;
else
res = res & false;
// debug(res, i, left, right);
}
}
return res;
}
ll lets_do_it(){
// Your code goes by here !!
ll num, val;
cin >> num >> val;
get(init, num);
get(final, num);
vector < vector < ll > > graph(num+1);
ll u, v;
for(int i=0; i<val; i++){
cin >> u >> v;
graph[u].pb(v);
graph[v].pb(u);
}
if(dfsHelper(graph, init, final))
cout << "Yes\n";
else
cout << "No\n";
return 0;
}
|
#include <bits/stdc++.h>
#include<iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
int64_t N, a, b;
vector<int64_t> square_number;
cin >> N;
for(a = 2; N >= pow(a, 2); a++){
for(b = 2; N >= pow(a, b); b++){
square_number.push_back(pow(a, b));
}
}
sort(square_number.begin(), square_number.end());
square_number.erase(unique(square_number.begin(), square_number.end()), square_number.end());
int size = square_number.size();
cout << N - size << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i =0;i<(int)(n);i++)
#define endl '\n'
typedef pair<int,int> P;
typedef long long ll;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
set<string> s1;
set<string> s2;
int n;
cin >> n;
string ans = "satisfiable";
rep(i,n){
string s;
cin >> s;
if(s[0]=='!'){
string t = s.substr(1,s.size()-1);
if(s2.find(t)!=s2.end()){
ans = t;
}
s1.insert(s);
}
else{
string t = "!"+s;
if (s1.find(t) != s1.end())
{
ans = s;
}
s2.insert(s);
}
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N=200005;
#define M 1000000007
#define double long double
#define BINF 100000000000000
#define init(arr,val) memset(arr,val,sizeof(arr))
#define MAXN 17500001
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;
int n, k;
int a[N], power[105];
string s;
int dp[101][101][101];
int get(int x, int y){
if(x == y) return x;
int s = x + y;
if(s == 1) return 1;
if(s == 2) return 0;
return 2;
}
int get(int l, int r, int lvl){
// cout << l << ' ' << r << ' ' << lvl << endl;
if(lvl == 1){
return get(a[l], a[r]);
}
if(dp[l][r][lvl] != -1) return dp[l][r][lvl];
int g = power[lvl - 1];
int x = get(l, (l + g - 1 + n) % n, lvl - 1);
int y = get((l + g) % n , r, lvl - 1);
return dp[l][r][lvl] = get(x, y);
}
#undef int
int main() {
#define int long long int
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("optput.txt", "w", stdout);
#endif
cin >> n >> k;
cin >> s;
for(int i = 0; i < n; i++){
if(s[i] == 'R') a[i] = 0;
else if(s[i] == 'P') a[i] = 1;
else a[i] = 2;
}
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++){
for(int l = 0; l <= k; l++){
dp[i][j][l] = -1;
}
}
}
power[0] = 1;
for(int i = 1; i < 105; i++){
power[i] = (2 * power[i - 1]) % n;
}
int ans = get(0, (power[k] - 1 + n) % n, k);
if(ans == 0) cout << "R\n";
else if(ans == 1) cout << "P\n";
else cout << "S\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
long long n,m,k;
cin>>n>>m>>k;
vector<long long> data(2000010,0),datac(2000010,0);
if(n>m+k){
cout<<0<<endl;
return 0;
}
set<ll> sosuu;
for(ll i=2;i<2000010;i++){
sosuu.insert(i);
}
for(ll i=2;i<1500;i++){
if(!sosuu.count(i)){
continue;
}
for(ll j=2;j*i<2000010;j++){
if(sosuu.count(i*j)){
sosuu.erase(i*j);
}
}
}
for(ll x:sosuu){
ll y=x;
while(y<=n+m){
data.at(x)+=(n+m)/y;
data.at(x)-=n/y;
data.at(x)-=m/y;
y*=x;
}
}
for(ll x:sosuu){
ll y=x;
while(y<=n+m){
datac.at(x)+=(n+m)/y;
datac.at(x)-=(n-k-1)/y;
datac.at(x)-=(m+k+1)/y;
y*=x;
}
}
long long count=1,ccon=1;
for(ll i=2;i<=n+m;i++){
for(ll j=0;j<data.at(i);j++){
count*=i;
count%=1000000007;
}
//cout<<data.at(i)<<endl;
}
//cout<<endl;
for(ll i=2;i<=n+m;i++){
for(ll j=0;j<datac.at(i);j++){
ccon*=i;
ccon%=1000000007;
//cout<<i<<endl;
}
}
if(k==n){
ccon=0;
}
//cout<<count<<" "<<ccon<<endl;
cout<<(count-ccon+1000000007)%1000000007<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;
int main(){
int n;
cin >> n;
string s;
cin >> s;
vector<int> sumA(n+1,0);
vector<int> sumG(n+1,0);
vector<int> sumC(n+1,0);
vector<int> sumT(n+1,0);
rep1(i,n){
sumA[i] = sumA[i-1] + (s[i-1] == 'A');
sumG[i] = sumG[i-1] + (s[i-1] == 'G');
sumC[i] = sumC[i-1] + (s[i-1] == 'C');
sumT[i] = sumT[i-1] + (s[i-1] == 'T');
}
int ans = 0;
rep(i,n){
for(int j=i+1;j<n+1;j++){
int nowA = sumA[j]-sumA[i];
int nowG = sumG[j]-sumG[i];
int nowC = sumC[j]-sumC[i];
int nowT = sumT[j]-sumT[i];
if(nowA == nowT && nowC == nowG) ans ++;
}
}
cout << ans << endl;
}
| #include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <tuple>
#include <utility>
#include <unordered_set>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define reps(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
const int MOD = 1000000007;
int main(){
ll n;
cin>>n;
ll m;
cin>>m;
vector<string> s(n);
for (ll i = 0; i < n; i++) {
cin >> s[i];
}
vector<ll> cnt(n,0);
rep(i,n){
rep(j,m){
if(s[i][j]=='1'){
cnt[i]++;
}
}
}
ll odd=0,even=0;
for( auto x : cnt){
if(x%2==0){
even++;
}else{
odd++;
}
}
cout<<odd*even<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x,y,res;
map<ll,ll>mp; //将a变成b需要的步数
ll dfs(ll k){
if(k<=x) return x-k; //-1 使x变小
if(mp[k]) return mp[k];
ll cnt=k-x; //k>x
if(!(k&1)) cnt=min(cnt,dfs(k/2)+1); //1步 *2的操作
else cnt=min(cnt,min(dfs(k+1),dfs(k-1))+1); //奇数则+1或-1
mp[k]=cnt; //记忆化搜索
return mp[k];
}
int main(void){
while(cin>>x>>y){
mp.clear();
res=dfs(y);
cout<<res<<endl;
}
return 0;
} | #include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <functional>
#include <utility>
#include <tuple>
#include <numeric>
#include <queue>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <regex>
#include <stack>
#include <limits>
#include <climits>
using namespace std;
map<long long, long long> f;
long long calc(long long y, long long x) {
if (f.count(y) > 0) return f[y];
if (y <= x) return x - y;
long long res = y - x;
if (y % 2 == 1) {
res = min(res, 2+calc((y + 1) / 2, x));
res = min(res, 2 + calc((y - 1) / 2, x));
} else {
res = min(res, 1 + calc(y / 2, x));
}
return f[y] = res;
}
int main() {
ios_base::sync_with_stdio(false);
long long x, y;
cin >> x >> y;
if (x >= y) {
cout << x - y;
} else {
cout << calc(y, x);
}
cout << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long a,i=0,j=0;
double b,s=0,y=100;
cin>>a>>b;
int c[a],d[a];
for(i=0;i<a;i++){
cin>>c[i];
cin>>d[i];
}
for(i=0;i<a;i++)
{
s+=c[i]*d[i];
if(s>b*y){
j=1;
cout<<i+1<<endl;
break;
}
}
if(j==0){
cout<<-1<<endl;
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=(a),(i##i)=(b);i<=(i##i);++i)
#define Rep(i,n) for(int i=0,(i##i)=(n);i<(i##i);++i)
#define Fodn(i,a,b) for(int i=(a),(i##i)=(b);i>=(i##i);--i)
#define pln puts("")
#define il inline
#define ff first
#define ss second
using LL=long long;using u32=unsigned int;using u64=unsigned LL;using LD=long double;
template<typename T>using pii=pair<T,T>;
template<typename T>il bool read(T&x){
x=0;char c=getchar();int f=1;while(!isdigit(c)&&(c!='-')&&(c!=EOF))c=getchar();
if(c==EOF)return 0;if(c=='-')f=-1,c=getchar();
while(isdigit(c)){x=(x<<1)+(x<<3)+(c&15);c=getchar();}x*=f;return 1;}
template<typename T,typename...Args>
il bool read(T&x,Args&...args){bool res=1;res&=read(x);res&=read(args...);return res;}
const int M=1000000007,INF=0x3f3f3f3f;const LL INFLL=0x3f3f3f3f3f3f3f3fLL;
const int N=1000010;const double EPS=1e-6;
int n,x;
bool f=0;
LL now;
inline void init(){
read(n,x);x*=100;
For(i,1,n){
LL u,v;read(u,v);now+=u*v;
if(now>x){
f=1;printf("%d\n",i);break;
}
}
}
inline void solve(){
if(!f)puts("-1");
}
signed main(){
init();solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
long long int t,n,i,x,mx,mn,f,j,s,r,y;
cin>>n;
vector<long long int>v(402);
for(i=0;i<n;i++)
{
cin>>x;
v[x+200]++;
}
s=0;
for(i=0;i<400;i++)
{
for(j=i;j<=400;j++)
{
if(i!=j&&v[i]>=0&&v[j]>=0)
{
r=(i-200)-(j-200);
s+=(v[i]*v[j]*r*r);
}
}
}
cout<<s<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> II;
const int MAXN = 500 + 10;
int n, c[MAXN][MAXN];
int a[MAXN];
int b[MAXN];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
scanf("%d", &c[i][j]);
}
}
a[1] = *min_element(c[1] + 1, c[1] + 1 + n);
for (int j = 1; j <= n; ++j) {
b[j] = c[1][j] - a[1];
}
for (int i = 2; i <= n; ++i) {
a[i] = c[i][1] - b[1];
}
try {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
if (c[i][j] != (LL)a[i] + b[j]) {
throw false;
}
}
}
} catch (bool check) {
puts("No");
return 0;
}
puts("Yes");
for (int i = 1; i <= n; ++i) {
printf("%d ", a[i]);
}
puts("");
for (int i = 1; i <= n; ++i) {
printf("%d ", b[i]);
}
puts("");
return 0;
} |
#include <bits/stdc++.h> //yaad rkhne layak baatein
#include <bits/stdc++.h> // bool found = false use it to find some number after the given number with some cond.
// while (!found)
#include <iostream> // freq.table-> int freq[26] = {0}; for (ll i = 0; i < s1.length(); i++) freq[s1[i] - 'A']++;
#define ll long long //[s[i] - 'a'] ->this convers char to corr.int eg. 'c' to 3.
// if(a<=min1){
// min2 = min1;
// index2 = index1;
// min1 = a;
// index1 = i; to find index of 2nd smallest element
// }
// else if(a<=min2){
// min2 = a;
// index2 = i;
// }
#define INF 2000000000
#define pb push_back
using namespace std;
//cout<<fixed<<setprecision(12)<<ans<<endl;
const int M = 1e9 + 7;
#define loop0(i, n) for (ll i = 0; i < n; i++) // str.insert(0, 5, '1'); => it will insert 1 five times in start of str.
#define loop00(i, n) for (ll i = 0; i <= n; i++)
#define loop1(i, n) for (ll i = 1; i < n; i++)
#define loop11(i, n) for (ll i = 1; i <= n; i++)
#define loopab(i, a, b) for (ll i = a; i <= b; i++)
void flashSpeed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
long long mod(long long x)
{
return ((x % M + M) % M);
}
long long add(long long a, long long b)
{
return mod(mod(a) + mod(b));
}
long long mul(long long a, long long b)
{
return mod(mod(a) * mod(b));
}
ll modPow(ll a, ll b)
{
if (b == 0)
return 1LL;
if (b == 1)
return a % M;
ll res = 1;
while (b)
{
if (b % 2 == 1)
res = mul(res, a);
a = mul(a, a);
b = b / 2;
}
return res;
}
const int N = 2e5 + 2;
int fact[N];
void precalc()
{
fact[0] = 1;
for (int i = 1; i < N; i++)
{
fact[i] = mul(fact[i - 1], i);
}
}
ll inv(ll x)
{
return modPow(x, M - 2);
}
ll divide(ll a, ll b)
{
return mul(a, inv(b));
}
ll nCr(ll n, ll r)
{
return divide(fact[n], mul(fact[r], fact[n - r]));
}
double Round(double var)
{
float value = (int)(var * 100 + .5);
return (float)value / 100;
}
ll ceils(ll x, ll y) {
return x / y + ((x % y) != 0);
}
ll Gcd(ll a, ll b)
{
if (b > a)
{
return Gcd(b, a);
}
if (b == 0)
return a;
else
return Gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return a / Gcd(a, b) * b;
}
bool isPal(string s)
{
for (int i = 0; i < (int)s.size() / 2; i++)
{
if (s[i] != s[(int)s.size() - 1 - i])
return false;
}
return true;
}
ll Sumdigits(ll a)
{
ll total = 0;
while (a)
{
total += a % 10;
a /= 10;
}
return total;
}
bool isPerfectSquare(int n)
{
for (int i = 1; i * i <= n; i++) {
if ((n % i == 0) && (n / i == i)) {
return true;
}
}
return false;
}
bool isPowerOfTwo(int n){
return (ceil(log2(n)) == floor(log2(n)));
}
void lexosmallest(string s,string c){
string t1 = s;
sort(t1.begin(), t1.end());
int index = -1;
for (int i = 0; i < s.length(); i++) {
if (s[i] != t1[i]) {
index = i;
break;
}
}
int j;
for (int i = 0; i < s.length(); i++) { //khela yha pe hua hai..loop poora chala hai
if (s[i] == t1[index])
j = i;
}
swap(s[index], s[j]);
}
void solution(){
string s;
string ans;
cin>>s;
for(auto c:s){
if(c=='6'){
ans.push_back('9');
}else if(c=='9'){
ans.push_back('6');
}else{
ans.push_back(c);
}
}
reverse(ans.begin(),ans.end());
cout<<ans<<endl;
}
int main()
{
flashSpeed();
int t=1;
// cin>>t;
while(t--)
{
solution();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPE(i,l,n) for(ll i=l;i<=ll(n);i++)
#define FORA(i,I) for(const auto& i:I)
#define ALL(v) v.begin(),v.end()
#define UQ(v) v.erase(unique(ALL(v)), v.end())
#define ACM(v) accumulate(ALL(v), 0)
#define P(str) cout << str << endl
#define VLL vector<ll>
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
constexpr int64_t INF = 1e18;
ll my_pow(ll x, ll n) {
if (n == 0) return 1;
if (n % 2 == 0) return my_pow(x * x, n / 2);
return x * my_pow(x, n - 1);
}
int main(){
ll n;
cin >> n;
REPE(i, 1, INF){
ll ttmp = n - my_pow(3, i);
if(ttmp < 0) break;
REPE(j, 1, INF){
ll tmp = ttmp - my_pow(5, j);
if(tmp < 0) break;
else if(tmp == 0){
cout << i << " " << j << endl;
return 0;
}
}
}
P(-1);
} |
#include<bits/stdc++.h>
#define ri register int
#define ll long long
using namespace std;
inline int rd(){
int res = 0,f = 0;
char ch = getchar();
for(;!isdigit(ch);ch = getchar()) if(ch == '-') f = 1;
for(;isdigit(ch);ch = getchar()) res = (res<<3) + (res<<1) + ch - 48;
return f ? -res : res;
}
int main(){
int n = rd(),k = rd();
ll ans = 0;
for(ri i = 1;i <= n;++i)
for(ri j = 1;j <= k;++j) ans += i*100 + j;
printf("%lld\n",ans);
return 0;
}
| #include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
int main() {
int n; cin >> n;
vector<ll> a(n), s(n+1, 0);
set<ll> st;
rep(i, n) {
cin >> a[i];
s[i+1] = a[i] + s[i];
}
ll ans = -1e18, tmp = 0;
st.insert(s[0]);
rep(i, n) {
st.insert(s[i+1]);
ans = max(tmp + *st.rbegin(), ans);
tmp += s[i+1];
}
cout << ans << endl;
return 0;
}
//小数点精度
//cout << fixed << std::setprecision(15) << y << endl; |
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>
#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif
#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/
constexpr lnt MOD = 998244353;
struct mint
{
lnt v;
mint():v(0){}
mint(lnt v):v((v+MOD)%MOD){}
mint operator-()const{ return mint(0) - *this; }
mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
mint& operator/=(const mint& a){ (*this) *= a.inv(); 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 operator/(const mint& a)const{ return mint(*this) /= a; }
bool operator<(const mint& a)const{ return v < a.v; }
bool operator==(const mint& a)const{ return v == a.v; }
mint pow(lnt k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
mint inv()const{ return pow(MOD-2); }
static mint comb(lnt n, lnt k) { if(n-k<k) k=n-k; mint num(1), dom(1); for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; } return num/dom; }
static std::vector<mint> construct_comb(int n) {
std::vector<mint> c(n+1); mint a = 1; c[0] = a; for(int i=1;i<=n;i++) { a = a*mint(n+1-i)/i; c[i] = a; } return c;
}
static std::vector<mint> construct_fact(int n) { std::vector<mint> f(n+1,1); for(int i=2;i<=n;i++) f[i]=f[i-1]*i; return f; }
};
std::istream& operator>>(std::istream&i,mint&a){ lnt t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }
int main() {
int n,m;
std::cin >> n >> m;
mint ans=mint(n)*mint(m).pow(n);
for(int x=2;x<=n;x++) {
mint o=0;
for(int y=1;y<=m;y++) {
o+=mint(m-y).pow(x-2)*mint(m).pow(n-x);
}
ans-=o*mint(n-x+1);
}
print(ans);
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
ll n,m,ans,pw[5005][5005];
int main()
{
cin>>n>>m;
pw[0][0]=1;
for(int i=1;i<=m;i++)
{
pw[i][0]=1;
for(int j=1;j<=n;j++)
pw[i][j]=(pw[i][j-1]*i)%mod;
}
ans=n;
for(int i=1;i<=n;i++)
ans=(ans*m)%mod;
for(ll lg=2;lg<=n;lg++)
for(ll x=1;x<=m;x++)
{
ll val=(pw[m-x][lg-2]*pw[m][n-lg])%mod;
val=(val*(n-lg+1))%mod;
ans-=val;
if(ans<0)
ans+=mod;
}
cout<<ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()
typedef long long ll;
#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)
#define fi first
#define se second
const int N = 2e5+10;
ll a[N], b[N], p[N];
ll dono[N];
void no(){
cout << -1 << "\n";
exit(0);
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
ll n; cin >> n;
fr(i,n) cin >> a[i];
fr(i,n) cin >> b[i];
fr(i,n) cin >> p[i], p[i]--;
fr(i,n) dono[p[i]] = i;
fr(i,n) if(p[i]!=i and b[p[i]]>=a[i]) no();
vector<pair<ll,ll>> vp;
fr(i,n) vp.emplace_back(a[i],i);
sort(all(vp));
vector<pair<ll,ll>> ans;
for(auto &[peso,ia] : vp){
if(p[ia]==ia) continue;
ll iq = dono[ia];
ans.emplace_back(ia,iq);
swap(p[ia],p[iq]);
dono[p[ia]] = ia;
dono[p[iq]] = iq;
}
cout << sz(ans) << "\n";
for(auto &[i,j] : ans){
cout << i+1 << " " << j+1 << "\n";
}
} | /*
"An anomaly, I'm Muhammad Ali
Cause I know one day I'm gonna be the"
- Greatest, Eminem
*/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size()) cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" "; cout<<endl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;
int main(){
Shazam;
int n; cin >> n;
vector<pair<int,int>> a(n), b(n);
for(int i = 0; i < n; i++){
cin >> a[i].ff >> b[i].ff;
a[i].ss = b[i].ss = i;
}
sort(all(a));
sort(all(b));
if(a.front().ss != b.front().ss){
cout << max(a[0].ff , b[0].ff) << endl;
}
else{
cout << min({a[0].ff + b[0].ff, max(a[1].ff ,b[0].ff), max(a[0].ff , b[1].ff)}) << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef pair<int,lld> pil;
typedef pair<lld,int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
if(0<=y&&y<n&&0<=x&&x<m) return true;
return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
const int MAX = 1000100;
struct SCC_cl{
// 1 based SCC
int V, E, cnt, dfsn[MAX], SN, sn[MAX],tsat[MAX];
vector<int> adj[MAX];
bool finished[MAX];
stack<int> S;
vector<vector<int> > SCC;
SCC_cl(){
memset(dfsn,0,sizeof(dfsn));
memset(sn,0,sizeof(sn));
memset(finished,false,sizeof(finished));
cnt = 0;
SN = 0;
}
void init(int V){
this->V = V;
}
int DFS(int curr){
dfsn[curr] = ++cnt;
S.push(curr);
int result = dfsn[curr];
for(int next: adj[curr]){
if(dfsn[next] == 0) result = min(result, DFS(next));
else if(!finished[next]) result = min(result, dfsn[next]);
}
if(result == dfsn[curr]){
vector<int> currSCC;
while(1){
int t = S.top();
S.pop();
currSCC.push_back(t);
finished[t] = true;
sn[t] = SN;
if(t == curr) break;
}
sort(currSCC.begin(), currSCC.end());
SCC.push_back(currSCC);
SN++;
}
return result;
}
void goSCC(){
for(int i=1; i<=V; i++)
if(dfsn[i] == 0) DFS(i);
}
void add_edge(int a,int b){
adj[a].push_back(b);
}
int get_ans(int n,int m){
set<int> s1,s2;
for(int e=1;e<=n;e++){
s1.insert(sn[e]);
}
for(int e=n+1;e<=n+m;e++){
s2.insert(sn[e]);
}
return min(sz(s1)-1,sz(s2)-1);
}
// two sat
// A v B -> A^c -> B , B^c -> A
// 1 based SCC -> i : 2*i - 1 , 2*i
void getTwoSat(){
memset(tsat,-1,sizeof(tsat));
pi p[MAX];
for(int i=1;i<=V;i++)
p[i] = mk(sn[i], i);
sort(p+1, p+1+V);
for(int i=V; i>=1; i--){
int var = p[i].second;
if(tsat[(var+1)/2] == -1) tsat[(var+1)/2] = !(var%2);
}
}
bool isTwoSat(){
for(int e=1;e<=V;e+=2){
if(sn[e]==sn[e+1]) return false;
}
return true;
}
};
SCC_cl gh;
string a[1010];
void solve(int tc){
int n,m;
scanf("%d%d",&n,&m);
gh.init(n+m);
gh.add_edge(1,n+m);
gh.add_edge(1,n+1);
gh.add_edge(n,n+1);
gh.add_edge(n,n+m);
gh.add_edge(n+1,1);
gh.add_edge(n+1,n);
gh.add_edge(n+m,1);
gh.add_edge(n+m,n);
for(int e=1;e<=n;e++) cin >> a[e];
for(int p=1;p<=m;p++){
vector<int> v;
for(int e=1;e<=n;e++){
if(a[e][p-1]=='#') v.push_back(e);
}
if(sz(v)){
for(int q=0;q<sz(v);q++){
gh.add_edge(v[q],p+n);
}
}
}
for(int e=1;e<=n;e++){
vector<int> v;
for(int p=1;p<=m;p++){
if(a[e][p-1]=='#') v.push_back(p);
}
if(sz(v)){
for(int q=0;q<sz(v);q++){
gh.add_edge(v[q]+n,e);
}
}
}
gh.goSCC();
printf("%d\n",gh.get_ans(n,m));
}
int main(void){
/*
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
*/
int tc = 1;
/*
scanf("%d",&tc);
*/
for(int test_number=1;test_number<=tc;test_number++){
solve(test_number);
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
const int maxn=2020;
int n,m;
int fa[maxn];
int fnd(int x)
{
if(fa[x]==x)
{
return x;
}
return fa[x]=fnd(fa[x]);
}
void merge(int x,int y)
{
fa[fnd(x)]=fnd(y);
}
set<int> s1,s2;
int main()
{
cin>>n>>m;
for(int i=1;i<=n+m;i++)
{
fa[i]=i;
}
merge(1,n);
merge(1,n+1);
merge(1,n+m);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
char c;
cin>>c;
if(c=='#')
{
merge(i,j+n);
}
}
}
for(int i=1;i<=n;i++)
{
s1.insert(fnd(i));
}
for(int i=n+1;i<=n+m;i++)
{
s2.insert(fnd(i));
}
cout<<min((int)s1.size(),(int)s2.size())-1<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,char>> adj[1000];
bool vis[1000][1000];
int best[1000][1000];
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
best[i][j] = 1e9;
}
}
while (m--) {
int u, v;
char c;
cin >> u >> v >> c, --u, --v;
adj[u].emplace_back(v, c);
adj[v].emplace_back(u, c);
}
best[0][n-1] = 0;
queue<pair<int,int>> q;
q.push({0, n-1});
int ans = INT_MAX;
while (!q.empty()) {
int u, v;
tie(u, v) = q.front();
q.pop();
if (vis[u][v]) continue;
if (u == v) ans = min(ans, best[u][v]);
vis[u][v] = true;
for (auto [x1, c1] : adj[u]) {
if (x1 == v) {
ans = min(ans, best[u][v] + 1);
continue;
}
for (auto [x2, c2] : adj[v]) {
if (c1 == c2) {
if (best[x1][x2] > best[u][v] + 2) {
best[x1][x2] = best[u][v] + 2;
q.push({x1, x2});
}
}
}
}
}
if (ans == INT_MAX) cout << "-1";
else cout << ans;
return 0;
}
| #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pre(i,a,b) for(int i=a;i>=b;i--)
#define N 1005
using namespace std;
int n,m,v[N][N],vis[N][N],ans=0x7fffffff;
vector<int>c[N][26];
struct node{
int x,y,val;
node(int X=0,int Y=0,int V=0){x=X;y=Y;val=V;}
bool operator<(const node o)const{return val>o.val;}
};
priority_queue<node>q;
int main(){
scanf("%d%d",&n,&m);
rep(i,1,n)v[i][i]=1;
rep(i,1,m){
int x,y;char op[2];
scanf("%d%d%s",&x,&y,op);
v[x][y]=v[y][x]=1;
c[x][(*op)-'a'].push_back(y);
c[y][(*op)-'a'].push_back(x);
}
q.push(node(1,n,0));
while(!q.empty()){
node now=q.top();q.pop();
vis[now.x][now.y]=1;
if(now.x==now.y){printf("%d\n",min(ans,now.val*2));return 0;}
if(v[now.x][now.y]){ans=min(ans,now.val*2+(now.x!=now.y));continue;}
rep(col,0,25){
for(int i=0;i<(int)c[now.x][col].size();i++)
for(int j=0;j<(int)c[now.y][col].size();j++){
int x=c[now.x][col][i],y=c[now.y][col][j];
if(!vis[x][y])vis[x][y]=1,q.push(node(x,y,now.val+1));
}
}
}
if(ans==0x7fffffff)puts("-1");else printf("%d\n",ans);
return 0;
}
|
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map> //http://vivi.dyndns.org/tech/cpp/map.html
#include <set> //http://vivi.dyndns.org/tech/cpp/set.html
#include <vector>
#include <deque>
#include <queue>
#include <numeric> //gcd,lcm c++17
#include <tuple>
#include <iomanip> //setprecision
#include <unordered_map>
#include <chrono>
//#define _GLIBCXX_DEBUG
using namespace std;
template <typename T>
using vc = vector<T>;
template <typename T>
using vv = vc<vc<T>>;
template <typename T>
using PQ = priority_queue<T, vc<T>, greater<T>>;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
//typedef __uint128_t Int;
using vi = vc<int>;
using vl = vc<ll>;
using vd = vc<double>;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define ALL(a) (a).begin(), (a).end()
#define sz(x) (int)(x).size()
template <class T1, class T2, class Pred = std::less<T2>>
struct sort_pair_second
{
//sort_pair_second<ll,ll,greater<ll>>()
bool operator()(const std::pair<T1, T2> &left, const std::pair<T1, T2> &right)
{
Pred p;
return p(left.second, right.second);
}
};
template <class T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
if (a > b)
{
a = b;
return 1;
}
return 0;
}
int MOD = 1e9 + 7;
double EPS = 1e-9;
int INF = 2000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
int rdx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int rdy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int N;
string S;
int f(int n)
{
if (n == 0)
return 0;
if (n == 1)
return 1;
return n + f(n - 1);
}
int main()
{
cin >> N >> S;
int left = 0, right = 0;
int n = N - N % 2;
int nextright = n;
int nextleft = 0;
int a = 0, g = 0, c = 0, t = 0;
ll ans = 0;
while (nextright > 0)
{
while (right < nextright)
{
if (S[right] == 'A')
a++;
else if (S[right] == 'G')
g++;
else if (S[right] == 'C')
c++;
else if (S[right] == 'T')
t++;
right++;
}
while (left < nextleft)
{
if (S[left] == 'A')
a--;
else if (S[left] == 'G')
g--;
else if (S[left] == 'C')
c--;
else if (S[left] == 'T')
t--;
left++;
}
if (a == t && g == c)
ans++;
nextright = right + 1;
nextleft = left + 1;
if (right == N)
{
n -= 2;
right = 0;
left = 0;
nextright = n;
nextleft = 0;
a = 0, g = 0, c = 0, t = 0;
continue;
}
}
cout << ans << endl;
/*
vi a, g;
int acnt = 0, gcnt = 0;
int ans = 0;
FOR(i, 0, N - 1)
{
if ((S[i] == 'A' && S[i + 1] == 'T') || (S[i] == 'T' && S[i + 1] == 'A'))
{
acnt++;
ans++;
}
else if (acnt)
{
acnt--;
a.push_back(acnt / 2);
acnt = 0;
}
if ((S[i] == 'G' && S[i + 1] == 'C') || (S[i] == 'C' && S[i + 1] == 'G'))
{
ans++;
gcnt++;
}
else if (gcnt)
{
gcnt--;
g.push_back(gcnt / 2);
gcnt = 0;
}
}
if (acnt)
{
acnt--;
a.push_back(acnt / 2);
}
if (gcnt)
{
gcnt--;
g.push_back(gcnt / 2);
gcnt = 0;
}
for (auto x : a)
ans += f(x);
for (auto x : g)
ans += f(x);*/
} | //Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(a,b) __gcd(a,b)
#define endl '\n'
const int N=3e5+10;
const int inf=1e9;
const int mod=1e9+7;
int main(int argc, char const *argv[])
{
/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif*/
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
int n, k;
cin >> n >> k;
int a[n];
int cnt[N]={0};
for(int i=0; i<n; i++)
{
cin >> a[i];
cnt[a[i]]++;
}
int ans=0;
for(int i=0; i<N; i++)
{
if(cnt[i]<k)
{
int tmp=k-cnt[i];
if(tmp>k)
tmp=k;
ans+=tmp*i;
k-=tmp;
}
if(k==0)
break;
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = double;
const int mxn = 1e3+10;
const int mod = 998244353;
int pa[2*mxn], sz[2*mxn], h ,w;
string mt[mxn];
int find(int v) {
if(v==pa[v]) return v;
return pa[v] = find(pa[v]);
}
void unite(int a, int b) {
a = find(a); b = find(b);
if(a!=b) pa[b] = a, sz[a]+=sz[b];
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>h>>w;
for(int i=0; i<h; i++) cin>>mt[i];
for(int i=0; i<h+w; i++) pa[i] = i, sz[i] = 1;
unite(0, 0+h); unite(0, w-1+h); unite(h-1, 0+h); unite(h-1, w-1+h);
for(int i=0; i<h; i++) for(int j=0;j<w; j++) if(mt[i][j]=='#') unite(i, j+h);
set<pair<int, int> > s; for(int i=0;i<w+h; i++) s.insert(make_pair(find(i), sz[find(i)]));
int row = 0, col = 0;
for(auto x:s) {
if(x.second>=2) row++, col++;
else if(x.first<h) row++;
else col++;
}
int ans = min(row, col)-1;
cout << ans << '\n';
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
template<typename T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } else return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else return false; }
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll inf = 1'000'000'000'000'000'001;
ll base_n(string x, ll n) {
ll ret = 0;
for (char c : x) {
if (ret > inf / n) return -1;
ret *= n;
ret += (ll)c - '0';
}
return ret;
}
int main() {
string x;
ll m;
cin >> x >> m;
ll d = 0;
for (char c : x) chmax(d, (ll)c - '0');
if (x.size() == 1) {
if (d <= m) cout << 1 << endl;
else cout << 0 << endl;
return 0;
}
ll ng = inf;
ll ok = d;
while (abs(ok - ng) > 1) {
ll c = ok + (ng - ok) / 2;
ll y = base_n(x, c);
if (y < 0) {
ng = c;
continue;
}
if (y <= m) ok = c;
else ng = c;
}
ll ans = ok - d;
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
void dfs(int node, int f, auto& g, auto& seen, auto& sol, auto& edges) {
seen[node] = 1;
int n = g.size();
for (int v = 0; v < n; v += 1) {
if (g[node][v] == 0)
continue;
if (v == f)
continue;
int ind = g[node][v] - 1;
if (seen[v]) {
if (v == edges[ind].first)
sol[ind] = 0;
else
sol[ind] = 1;
continue;
}
if (v == edges[ind].first)
sol[ind] = 1;
else
sol[ind] = 0;
dfs (v, node, g, seen, sol, edges);
}
}
int main() {
int n, m; cin >> n >> m;
vector<vector<int>> g(n, vector<int> (n, 0));
vector<pair<int, int>> edges;
for (int i = 0; i < m; i += 1) {
int a, b; cin >> a >> b;
a -= 1, b -= 1;
edges.push_back(make_pair(a, b));
}
vector<int> c(n, 0);
for (int i = 0; i < n; i += 1) {
cin >> c[i];
}
vector<int> sol(m, -1);
for (int i = 0; i < m; i += 1) {
auto e = edges[i];
if (c[e.first] < c[e.second]) {
sol[i] = 1;
} else if (c[e.first] > c[e.second]) {
sol[i] = 0;
} else {
g[e.first][e.second] = i + 1;
g[e.second][e.first] = i + 1;
}
}
vector<int> seen(n, 0);
for (int i = 0; i < n; i += 1)
if (not seen[i]) {
dfs(i, -1, g, seen, sol, edges);
}
for (int i = 0; i < m; i += 1) {
if (sol[i])
cout << "<-\n";
else
cout << "->\n";
}
} | #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define pb push_back
#define em emplace_back
#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define vd vector<double>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define fast \
cin.tie(0); \
ios::sync_with_stdio(false);
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
struct RMQ {
int n; // 葉の数
vector<int> dat; // 完全二分木の配列
RMQ(int n_) : n(), dat(n_ * 4, 0) { // 葉の数は 2^x の形
int x = 1;
while (n_ > x) {
x *= 2;
}
n = x;
}
void update(int i, int x) {
i += n - 1;
dat[i] = x;
while (i > 0) {
i = (i - 1) / 2; // parent
dat[i] = dat[i * 2 + 1] ^ dat[i * 2 + 2];
}
}
// the minimum element of [a,b)
int query(int a, int b) { return query_sub(a, b, 0, 0, n); }
int query_sub(int a, int b, int k, int l, int r) {
if (r <= a || b <= l) {
return 0;
} else if (a <= l && r <= b) {
return dat[k];
} else {
int vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
return (vl ^ vr);
}
}
};
int main() {
fast;
int n, q;
cin >> n >> q;
vi a(n);
rep(i, 0, n) cin >> a[i];
RMQ seg(n);
rep(i, 0, n) seg.update(i, a[i]);
rep(i, 0, q) {
int t, x, y;
cin >> t >> x >> y;
if (t == 1) {
seg.update(x - 1, seg.dat[x + seg.n - 2] ^ y);
} else {
cout << seg.query(x - 1, y) << endl;
}
}
return 0;
} |
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define ff first
#define ss second
#define ii pair<int,int>
#define vii vector<ii>
#define INF 1000000000
#define mod 1000000007
#define endl "\n"
#define ll long long
#define int ll
#define ull unsigned long long
#define ld long double
const double PI = (2.0 * acos(0.0));
#define cz(x) 63 - __builtin_clzll(x)
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void INPUT()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
map<int, int> cnt;
int X, Y;
int solve(int now)
{
if (now <= X)
return X - now;
if (cnt.count(now))
return cnt[now];
int res = now - X;
if (now % 2 == 0)
res = min(res, solve(now / 2) + 1);
else
res = min(res, 1 + min(solve(now - 1), solve(now + 1)));
return cnt[now] = res;
}
void Tmain()
{
cin >> X >> Y;
cout << solve(Y);
}
signed main()
{
FIO
INPUT();
int T = clock();
int t = 1;
for (int tc = 1; tc <= t; tc++)
{
Tmain();
}
cerr << "\n\nTIME: " << (double)(clock() - T) / CLOCKS_PER_SEC << " sec\n";
T = clock();
return 0;
} | #include <bits/stdc++.h>
#define endl "\n"
#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 e_b emplace_back
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ipair;
typedef pair<ll, ll> lpair;
template <class T> ostream &operator << (ostream &o, const vector<T> &v) //vectorの中身を見る
{o << "{"; for(int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", ":"") << v[i]; o << "}"; return o;}
void map_p(map<int, int> &d){cout << "map: "; for(auto a : d){cout << "{" << a.first << ":" << a.second << "}, ";} cout << endl;} //mapの中身を見る
void set_p(set<int> &d){cout << "set: "; for(int a : d){cout << a << ", ";} cout << endl;} //setの中身を見る
template <typename T>
bool chmax(T &a, const T& b) {
if (a < b) {
a = b; // aをbで更新
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
if (a > b) {
a = b; // aをbで更新
return true;
}
return false;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
char s, t;
cin >> s >> t;
if(s == 'Y'){
if('a' <= t and t <= 'z') t -= 'a' - 'A';
else if('A' <= t and t <= 'Z') t += 'a' - 'A';
}
cout << t << endl;
return 0;
} |
/*
@uthor: Amit Kumar
user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define int long long
#define double long double
#define uint unsigned long long
#define all(vec) vec.begin(),vec.end()
#define endl "\n"
int google_itr = 1;
#define google(x) cout<<"Case #"<<x<<": "
#define pi 3.14159265358979323846264338327950L
const int mod = 1e9+7;
const int inf = 1e18;
void virus(){
int len;
cin >> len;
string seq;
cin >> seq;
int ans = 0;
for(auto i=0; i<len; i++){
int a = 0, b = 0;
for(auto j=i; j<len; j++){
if(seq[j] == 'A') a++;
if(seq[j] == 'T') a--;
if(seq[j] == 'C') b++;
if(seq[j] == 'G') b--;
if(!a and !b) ans++;
}
}
cout << ans << endl;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif*/
int t = 1;
//cin >> t;
while(t--){
auto start = high_resolution_clock::now();
virus();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<seconds>(stop - start);
//cerr << "\n Time: "<<duration.count()<<endl;
//your code goes here
}
return 0;
} | //------------ヘッダーインクルード------------
#include <stdio.h>
#include <cmath>
#include <stdarg.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
//#include <pair>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
//------------型マクロ定義------------
typedef long l;
typedef long long ll;
#define INIF 1e9;
#define MOD 1000000007;
#define ALL(v) (v).begin(), (v).end()
//------------vectorマクロ定義------------
#define v(Type) vector<Type>
#define vv(Type) vector<vector<Type>>
#define vvv(Type) vector<vector<vector<Type>>>
#define vini(n, m) ((n), (m))
//------------forマクロ定義------------
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define rep2(i, m, n) for(int i = (m); (i) < (n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define fe(i, STL) for(auto i: (STL))
//------------ioマクロ定義------------
#define co cout<<
#define en <<endl
#define br co "" en
#define pr(value) ","<<#value<<": "<<value
#define sn(value) #value,value
template<class Type>
void print_value(string name, Type value){co name << ":" << value;}
#define pri(value) print_value(sn(value))
template<class Type>
void print_value2(string name, Type value){
int num = 0;
fe(i, value)co name << "[" << num++ << "]:" << i << ", ";
}
#define pri2(Type, value) print_value2<Type>(sn(value))
//------------main------------
int main(){
int N;
cin >> N;
long long int che = 0, man = 0, input;
long double eu = 0.0;
rep(i, N){
cin >> input;
man += abs(input);
eu += (input * input);
if(che < abs(input))che = abs(input);
}
eu = sqrt(eu);
co man en;
co fixed << setprecision(15) << eu en;
co che en;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) int(x.size())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
const ll INF = 1e18;
const int MOD = 1e9+7;
const int MX = 2e5+7;
const double PI = 3.1415926535897932384626;
ll bpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1)
res *= a;
a *= a;
b >>= 1;
}
return res;
}
void solve() {
ll N; cin >> N;
ll ans = LLONG_MAX;
ll calc = 0, a = 0, c = 0;
for (ll b = 0; b <= 60; b++) {
calc = 1LL << b;
a = N/calc;
c = N-(a*calc);
ans = min(ans, a+b+c);
}
cout << ans;
}
void fastIO(string name = "") {
cin.tie(0)->sync_with_stdio(0);
if (sz(name)) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
int main() {
fastIO("");
int tc = 1; //cin >> tc;
while (tc--) solve();
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
long long modPow(long long x, long long a) {
if (a == 1) return x;
if (a % 2) return (x * modPow(x, a - 1)) % MOD;
long long t = modPow(x, a / 2);
return (t * t) % MOD;
}
long long modInv(long long x) {
return modPow(x, MOD - 2);
}
void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
if (rest == 0) {
f(indexes);
} else {
if (s < 0) return;
recursive_comb(indexes, s - 1, rest, f);
indexes[rest - 1] = s;
recursive_comb(indexes, s - 1, rest - 1, f);
}
}
// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
int indexes[k];
recursive_comb(indexes, n - 1, k, f);
}
// nPnの順列に対して処理を実行する
void foreach_permutation(int n, std::function<void(int *)> f) {
int indexes[n];
for (int i = 0; i < n; i++) indexes[i] = i;
do {
f(indexes);
} while (std::next_permutation(indexes, indexes + n));
}
// nPkの順列に対して処理を実行する
void foreach_permutation(int n, int k, std::function<void(int *)> f) {
foreach_comb(n, k, [&](int *c_indexes) {
foreach_permutation(k, [&](int *p_indexes) {
int indexes[k];
for (int i = 0; i < k; i++) {
indexes[i] = c_indexes[p_indexes[i]];
}
f(indexes);
});
});
}
int main() {
ll n,q,a,b,c,ans;
q = 1;
b = 0;
cin >> n;
ans = n;
while (n >q)
{
a = n/q;
c = n%q;
if(a+b+c < ans ){
ans = a+b+c;
}
q *= 2;
b++;
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
#define per(i,n) for(ll (i)=(n)-1;(i)>=0;--(i))
#ifdef LOCAL
#define debug(x) cerr<<__LINE__<<": "<<#x<<"="<<x<<endl;
#define debugALL(x) cerr<<__LINE__<<": "<<#x<<"=";for(auto i=(x).begin();i!=--(x).end();i++)cerr<<*i<<" ";cerr<<*--(x).end()<<endl;
#else
#define debug(x) true
#define debugALL(x) true
#endif
using namespace std;
int main(){
ll n;
cin>>n;
vector<pair<ll,string>> a;
rep(i,n){
string s;
ll t;
cin>>s>>t;
a.emplace_back(t,s);
}
sort(a.rbegin(),a.rend());
cout<<a[1].second<<endl;
}
| #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#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;
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; }
template<class T> inline int sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
// 任意MODが使えるModint
// 型宣言の前にmodint::set_mod(MOD) をしてね
struct modint{
long long x;
modint() : x(0) {}
modint(long long x):x(x%mod()){}
static int &mod() {
static int mod = 0;
return mod;
}
static void set_mod(int md) {
mod() = md;
}
modint& operator+=(const modint a){
if((x+=a.x)>=mod()) x-=mod();
return *this;
}
modint& operator-=(const modint a){
if((x += mod()-a.x)>=mod()) x-=mod();
return *this;
}
modint& operator*=(const modint a){
(x*=a.x)%=mod();
return *this;
}
modint operator+(const modint a) const{
modint res(*this);
return res+=a;
}
modint operator-(const modint a) const{
modint res(*this);
return res-=a;
}
modint operator*(const modint a) const{
modint res(*this);
return res*=a;
}
modint pow(long long t) const{
if(!t) return 1;
modint a = pow(t>>1);
a*=a;
if(t&1) a*=*this;
return a;
}
//for prime mod
modint inv() const{
return pow(mod()-2);
}
modint& operator/=(const modint a){
return (*this) *= a.inv();
}
modint operator/(const modint a) const{
modint res(*this);
return res/=a;
}
};
int main()
{
ll a,b,c; cin >> a >> b >> c;
a %= 10;
ll st = a;
vl vec(1, a);
while(1) {
a *= st;
a %= 10;
if(a == st) break;
vec.push_back(a);
}
// for(auto tmp: vec) cout << tmp << "\n";
ll n = sz(vec);
ll mod=n;
modint::set_mod(mod);
modint x(b);
modint y = x.pow(c);
// cout << y.x << "\n";
ll id = y.x;
if(id == 0) id = n;
cout << vec[id-1] << "\n";
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define swap(a,b) (a^=b^=a^=b)
#define ll long long int
#define ull unsigned long long int
#define uint unsigned int
#define format(a) memset(a,0,sizeof(a))
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define dec(x,y,z) for(int x=y;x>=z;x--)
#define mst(x) memset(x,0,sizeof(x))
const int maxn=2e6+220;
inline int read()
{
int ans=0;
char last=' ',ch=getchar();
while(ch<'0'|ch>'9')last=ch,ch=getchar();
while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
if(last=='-')ans=-ans;
return ans;
}
string s;
int dir=0;
char a[maxn];
int l=1e6+21,r=1e6+20;
int nxt(int pos)
{
if(dir)return pos+1;
else return pos-1;
}
int pre(int pos)
{
if(!dir)return pos+1;
else return pos-1;
}
int main()
{
cin>>s;
rep(i,0,s.size()-1)
{
if(s[i]=='R')
{
dir^=1;
}
else
{
if(dir==0)
{
a[++r]=s[i];
if(a[r]==a[r-1]&&l!=r)r-=2;
}
else
{
a[--l]=s[i];
if(a[l]==a[l+1]&&l!=r)l+=2;
}
}
}
if(!dir)rep(i,l,r)cout<<a[i];
else dec(i,r,l)cout<<a[i];
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
int main(){
string s;
cin >> s;
string t;
string ans;
bool h = false;
rep(i, s.size()){
if (s[i] == 'R') h = !h;
else{
if (!h) t.push_back(s[i]);
else t.insert(t.begin(), s[i]);
}
}
if (h){
reverse(t.begin(), t.end());
}
for (char c : t){
if (ans.size() && ans.back() == c) ans.pop_back();
else ans.push_back(c);
}
cout << ans << endl;
} |
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin() , (x).end()
void dbg(){
cerr << endl;
}
template<typename Head , typename... Tail>
void dbg(Head h , Tail... t){
cerr << h << " ";
dbg(t...);
}
#ifdef EMBI_DEBUG
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", dbg(__VA_ARGS__)
#else
#define debug(...)
#endif
const int max_n = 1e5 + 9;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
ll prod = 1;
while(b)
{
if(b&1)
prod = (prod*a)%mod;
a = (a*a)%mod;
b >>= 1;
}
return prod;
}
void solve(){
int n;
cin >> n;
vll a(n);
for(int i = 0 ; i < n ; i++) {
cin >> a[i];
}
ll sum = 1;
ll dp[n][n+1];
memset(dp , 0 , sizeof(dp));
for(int i = 0 ; i < n ; i++) {
dp[i][1] = 1;
}
for(int j = 2 ; j <= n ; j++) {
int b[n] , dp1[n];
memset(dp1, 0 , sizeof(dp1));
for(int i = 0 ; i < n ; i++) {
b[i] = a[i] % j;
}
int curr_rem = 0;
for(int i = 0 ; i < n ; i++) {
curr_rem += b[i];
curr_rem %= j;
dp[i][j] = dp1[curr_rem];
dp1[curr_rem] += dp[i][j-1];
dp1[curr_rem] %= mod;
}
sum += dp[n-1][j];
sum %= mod;
}
cout << sum << "\n";
}
signed main(){
int t = 1;
// cin >> t;
for(int i = 1 ; i <= t ; i++){
solve();
}
} | // Never gonna give you up
// Never gonna let you down
// Never gonna run around and desert you
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
#define fi first
#define se second
#define pf push_front
#define pb push_back
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void solve(){
int n; cin >>n;
int a[n],sum=0; for(auto &i:a) cin >>i;
for(int i=0; i<n; i++){
int b; cin >>b;
sum+=a[i]*b;
}
cout <<(!sum?"Yes":"No");
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// int T; cin >>T; while(T--)
solve(); return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int main() {
ll N, W;
cin >> N >> W;
vector<ll> imos(2 * 1e5 + 1000);
REP(i, N) {
int s, t, p;
cin >> s >> t >> p;
imos[s] += p, imos[t] -= p;
}
REP(i, 2 * 1e5 + 100) { imos[i + 1] += imos[i]; }
REP(i, 2 * 1e5 + 100) {
if (imos[i] > W) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int N, W;
cin >> N >> W;
vector<int> S(N), T(N);
vector<ll> P(N);
vector<ll> voldif(200001);
for (int i = 0; i < N; i++) {
int s, t, p;
cin >> s >> t >> p;
voldif[s] += p;
voldif[t] -= p;
}
string ans = "Yes";
ll vol = 0;
for (auto &x : voldif) {
vol += x;
if (vol > W) ans = "No";
}
cout << ans << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int n;
int a[maxn];
int t;
void solve() {
cin>>n;
for(int i=1 ; i<=n ; i++) cin>>a[i];
bool bruh=false;
if(n%2==1) cout<<"Second\n";
else {
sort(a+1,a+1+n);
int cnt=0;
for(int i=2 ; i<=n ; i+=2) {
if(a[i]!=a[i-1]) bruh=true;
}
if(!bruh) cout<<"Second\n";
else cout<<"First\n";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>t;
while(t--) {
solve();
}
}
| #include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+1000;
int n,q,c[maxn],fa[maxn];
map<int,int> a[maxn];
void read(int &x)
{
char ch;bool ok;
for(ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') ok=1;
for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
int getfa(int x)
{
if(fa[x]==x) return x;
else return fa[x]=getfa(fa[x]);
}
void join(int x,int y)
{
if(getfa(x)==getfa(y)) return;
if(a[getfa(x)].size()<a[getfa(y)].size()) swap(x,y);
for(pair<int,int>lll:a[getfa(y)]) a[getfa(x)][lll.first]+=lll.second;
fa[getfa(y)]=getfa(x);
}
int main()
{
read(n),read(q);
for(int i=1;i<=n;i++) read(c[i]);
for(int i=1;i<=n;i++) fa[i]=i;
for(int i=1;i<=n;i++) a[i][c[i]]++;
while(q--)
{
int x,y,z;
read(x),read(y),read(z);
if(x==1) join(y,z);
else printf("%d\n",a[getfa(y)][z]);
}
return 0;
}
|
#include<bits/stdc++.h>
#define lint long long int
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define arep(i,a,n) for(int i=a;i<n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define fill(a,x) fill(a.begin(),a.end(),x)
#define eb(data) emplace_back(data)
#define pb(data) emplace_back(data)
#define mp make_pair
#define ALNUM 26
#define vint vector<int>
#define vlint vector<lint>
#define F first
#define S second
#define ALL(data) data.begin(),data.end()
#define GEts(s) getline(cin,s);
#define UNIQUE(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
using namespace std;
template<typename Rast>inline void out(Rast rast){cout<<rast<<"\n";return;}
template<typename Rast>inline void in(Rast& rast){cin>>rast;return;}
template<typename T>istream& operator >> (istream& is, vector<T>& vec){for(T& x: vec) is >> x;return is;}
template<typename First, typename... Rest>void in(First& first, Rest&... rest){cin >> first;in(rest...);return;}
template<typename First, typename... Rest>void out(First first, Rest... rest){cout << first<<" ";out(rest...);return;}
template<typename T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a * b / gcd(a, b);}
template<typename T1,typename T2>bool chmax(T1& a,T2 b){if(a<b){a=b;return true;}else{return false;}}
template<typename T1,typename T2>bool chmin(T1& a,T2 b){if(a>b){a=b;return true;}else{return false;}}
static const double pi = 3.141592653589793;
int modpow(int a,int n,int p){if (n==0)return 1%p; if(n==1)return a%p;if(n%2==1)return (a*modpow(a,n-1,p))%p;lint t=modpow(a,n/2,p);return (t*t)%p;}//a^n%p
lint MOD=pow(10,9)+7;
//lint MOD=998244353;
lint inf=pow(2,50);
int intinf=pow(2,30);
/**int dirx[]={1,0};int diry[]={0,1};//*///右、下
/**int dirx[]={0,1,0,-1};int diry[]={-1,0,1,0};//*///四方位
/**int dirx[]={-1,0,1,1,1,0,-1,-1};int diry[]={-1,-1,-1,0,1,1,1,0};//*///八方位
class unionfind{
public:
vector<int> table;
void init(int size){
table.resize(size);
rep(i,size)table[i]=i;
};
int root(int index){
if(table[index]==index)return index;
else{
int hoge=root(table[index]);
table[index]=hoge;
return hoge;
}
};
bool same(int x,int y){
return(root(x)==root(y));
};
int marge(int x,int y){
int yroot=root(y);
int xroot=root(x);
if(xroot==yroot)return 0;
table[yroot]=xroot;
return 0;
}
int getsize(){
set<int> ma;
rep(i,table.size())ma.insert(root(i));
int re=ma.size();
return re;
}
};
string s;
int n;
int ans=intinf;//めちゃくちゃでかい値
int dfs(string bit){
//再帰関数
if(bit.size()==n){
//サイズがNのビット列が生成されている
//各bitにあった処理をするよ
//22454367
//00010001
//57
//6663277
//6+6+6+3+2+7+7=37
int val=0;//各桁の総和
int count=0;
for(int i=0;i<n;i++){
if(bit[i]=='0'){
//消してないから足している
val+=(s[i]-'0');
}else{
//消してるから数える
count++;
}
}
if(val%3==0&&val!=0){
//いくつかの桁を消したら割り切れた数になってるな
//ここで答えを更新すれば良い
ans=min(ans,count);
}
}
else{
dfs(bit+'0');
dfs(bit+'1');
}
return 0;
}
int main(){
cin.tie(0);ios::sync_with_stdio(false);cout<<std::fixed<<std::setprecision(16);
cin>>s;
n=s.size();
dfs("");
if(ans==intinf){
//めちゃくちゃでかい値だったら初期値のままだから更新されてないため
cout<<-1<<endl;
}else{
cout<<ans<<endl;
}
return 0;
}
| #include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 105;
int k,ans;
char ch[MAXN];
inline int dfs(int sum,int x,int cnt)
{
if(sum % 3 == 0 && sum > 0)
return cnt;
if(x > k)
return 0x3f3f3f3f;
return min(dfs(sum - ch[x] + '0',x+1,cnt+1),dfs(sum,x+1,cnt));
}
int main()
{
scanf("%s",ch+1);
k = strlen(ch+1);
for(int i = 1;i <= k;i++)
ans += ch[i] - '0';
int x = dfs(ans,1,0);
if(x == 0x3f3f3f3f)
printf("-1\n");
else
printf("%d\n",x);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t; using Vll =vector<ll>; using VVll =vector<vector<ll>>;
template <class T> using Vec = vector<T>; template <class T> using VVec = vector<vector<T>>;
#define INF 9223372036854775807LL/2
void Z(ll i=-1){ if(i==-1)cout<<"Test"<<endl; else cout<<"Test"<<i<<endl; }
template <class T> void VVcout(VVec<T> A){ for(auto Vi:A) { for(auto i:Vi)cout<<i<<' '; cout<<endl;}}
template <class T> void Vcout(Vec<T> A){ for(auto i:A) cout<<i<<' '; cout<<endl;}
template <class T> void chmax(T &x,T y){if(x<y) x=y;} template <class T> void chmin(T &x,T y){if(x==-1 || x>y) x=y;}
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(si, i,n) for(ll i=si;i<n;i++)
int main(){
string s;
ll n;
cin>>n>>s;
if(n==1){
cout<<-1<<endl;
return 0;
}
if(s.at(0)!=s.at(n-1)){
cout<<1<<endl;
return 0;
}
char sc=s.at(0);
bool allsame=true;
rep(i,n) if(sc!=s.at(i)) allsame=false;
if(allsame){
cout<<-1<<endl;
return 0;
}
bool sucdif=false;
reps(1,i,n) if(sc!=s.at(i) && sc!=s.at(i-1))sucdif=true;
if(sucdif){
cout<<2<<endl;
return 0;
}
cout<<-1<<endl;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#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); }
int ceilInt(int a, int b) {
if(!b) return 0;
if(a%b) return a/b + 1;
return a/b;
}
int INF = 1e18;
int MOD = 998244353;
void solve()
{
int n; cin>>n;
vi arr(n);
rep(i, 0, n) cin>>arr[i];
vi pre = arr;
rep(i, 1, n) pre[i] += pre[i-1];
int till = 0, mx = -1;
rep(i, 0, n) {
amax(mx, arr[i]);
till += pre[i];
cout<<till+mx*(i+1)<<endl;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
rep(i, 0, t)
{
// cout<<"Case #"<<i+1<<": ";
solve();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
o<<"{";
for(const T& v:vc) o<<v<<",";
o<<"}";
return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }
#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
os<<t<<" ~ ";
dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {"; \
for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif
struct Cow{
using D = int;
const D inf = 1e9;
struct Edge{
int to;
D cost;
Edge(int to,D cost):to(to),cost(cost){}
};
int N,M;
vector<vector<Edge>> G;
vector<D> d;
Cow(int N):N(N){
G.assign(N,vector<Edge>());
d.assign(N,inf);
}
void add_edge(int t,int s,D c){ // correspond to t-s <= c
// printf("%d->%d :%d\n",t,s,c);
G[s].pb(Edge(t,c));
}
void add_edge(int t,int s,D clow,D chigh){ // clow <= t-s <= chigh
add_edge(t,s,chigh);
add_edge(s,t,-clow);
}
/*
return the inequalities have a valid assignment
if satisfiable, minimize d[T]-d[S]
negative cycle <=> unsatisfiable
d[T] - d[S] = inf <=> feasible unboundedly
d[S]=0
Tによらなくない?(気づき)
*/
bool IsValidAssign(int S = 0){
vector<int> prev(N);
d[S] = 0;
rep(ph,N){
bool update = 0;
int v = -1;
rep(s,N) for(auto e:G[s]){
int t = e.to;
D cost = e.cost;
if(d[s]+cost < d[t]){
update=1;
v = t;
d[t] = d[s]+cost;
prev[t] = s;
}
}
if(ph == N-1 && update){
// vector<int> path;
// path.pb(v);
// int u = v;
// do{
// show(u);
// u = prev[u];
// path.pb(u);
// }while(u!=v);
// reverse(all(path));
// show(path);
return 0;
}
if(!update) break;
}
return 1;
}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false); //DON'T USE scanf/printf/puts !!
cout << fixed << setprecision(20);
int N,M; cin >> N >> M;
const int inf = 1e9;
int ans = inf;
V<int> w(N); rep(i,N) cin >> w[i];
int mxw = *max_element(all(w));
V<int> lim(1<<N,0);
rep(i,M){
int l,v; cin >> l >> v;
if(v < mxw){
cout << -1 << endl;
return 0;
}
rep(s,1<<N){
int sum=0;
rep(j,N) if(s&1<<j) sum += w[j];
if(sum > v) chmax(lim[s],l);
}
}
show(lim);
V<int> o(N); iota(all(o),0);
do{
Cow cow(N);
rep(l,N) for(int r=l+1;r<N;r++){
int s=0;
for(int i=l;i<=r;i++) s|=1<<o[i];
cow.add_edge(l,r,-lim[s]);
}
rep(i,N-1){
cow.add_edge(i,i+1,0);
}
if(cow.IsValidAssign(N-1)){
show(cow.d);
chmin(ans,cow.d[N-1]-cow.d[0]);
}
}while(next_permutation(all(o)));
if(ans == inf) cout << -1 << endl;
else cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
#define endl '\n'
#define lowbit(x) (x & -x)
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define ck(x) (x >= mod ? x - mod : x)
#define inf 0x3f3f3f3f
#define eps 1e-6
#define maxn 1500010
#define maxm 1010
#define G 3
#define invG 332748118
const int mod = 998244353;
const double PI = 4 * atan2(1.0, 1.0);
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash {
int operator()(int x) const { return x ^ RANDOM; }
int operator()(pair<int, int> x) const { return x.first ^ x.second ^ RANDOM; }
};
int n, m, a[maxn], cnt[maxn], p, ans = inf;
set<int> s;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
s.insert(0);
for (int i = 1; i < m; i++) {
cnt[a[i]]++;
if (s.count(a[i]))s.erase(a[i]);
if (cnt[a[i] + 1] == 0)s.insert(a[i] + 1);
}
for (int i = m; i <= n; i++) {
cnt[a[i]]++;
if (s.count(a[i]))s.erase(a[i]);
if (cnt[a[i] + 1] == 0)s.insert(a[i] + 1);
// cout << i << ":";
// for (auto &u:s)cout << u << ' ';
// cout << endl;
ans = min(ans, *s.begin());
cnt[a[i - m + 1]]--;
if (cnt[a[i - m + 1]] == 0 && s.count(a[i - m + 1] + 1))s.erase(a[i - m + 1] + 1);
if (a[i - m + 1] > 0 && cnt[a[i - m + 1] - 1] != 0)s.insert(a[i - m + 1]);
if (cnt[0] == 0)s.insert(0);
}
cout << ans << endl;
return 0;
} |
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
long long gcd(long long x,long long y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x/gcd(x,y)*y;}
int main()
{
int n;
long long temp=0,ans=1;
cin>>n;
for(int i=2;i<=n;i++)
{
temp=gcd(ans,i);
ans=ans/temp*i;
//cout<<ans<<endl;
}
ans++;
printf("%lld",ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//const ll INF = numeric_limits<ll>::max() / 4;
//const int INF = numeric_limits<int>::max() / 4;
int main() {
// ll N;
string S;
cin >> S;
bool f = true;
string s = "ZONe";
int c = 0;
while(f){
int p = S.find(s);
if(p < S.size()){
c++;
S[p] = '.';
}else{
f = false;
}
}
cout << c << endl;
return(0);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, x, ans;
while (cin >> n) {
ans = 0;
while (n--) {
cin >> x;
ans += x > 10 ? x - 10 : 0;
}
cout << ans << '\n';
}
return 0;
} | #include <iostream>
using namespace std;
int main(){
int followerNum;
int followNum;
cin >> followerNum >> followNum;
int followMax = 2*followerNum + 100;
int availableFollow = followMax - followNum;
cout << availableFollow << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];
ll lcm(ll a, ll b) {
return a*b/__gcd(a,b);
}
ll power(ll a, ll n, ll mod) {
ll res = 1;
while(n > 0) {
if(n&1) {
res = (res*a)%mod;
}
a = (a*a)%mod;
n = n/2;
}
return res;
}
ll sum(int arr[], int n) {
ll res = 0;
f(i,n) {
res += arr[i];
}
return res;
}
void seive() {
prime[1] = 0;
for(int i=2; i<=100000; i++) {
prime[i] = 1;
}
for(ll i=2; i<=100000; i++) {
if(prime[i]) {
for(ll j=i*i; j<=100000; j+=i) {
prime[j] = 0;
}
}
}
}
ll cal(ll arr[], ll n, vector<ll> v) {
if(n == 0) {
ll ans = 0;
for(auto it : v ) {
ans = ans ^ it;
}
return ans;
}
else {
if(v.size() == 0) {
v.pb(arr[n-1]);
return cal(arr,n-1,v);
}
else {
vector<ll> temp = v;
temp.pb(arr[n-1]);
v.back() = v.back() | arr[n-1];
return min(cal(arr,n-1,v), cal(arr,n-1,temp));
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
// cin>>t;
while(t--){
ll n;
cin>>n;
ll arr[n];
f(i,n) cin>>arr[i];
vector<ll> v;
cout<<cal(arr,n,v);
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n;
cin >> n;
vector < int > a((int)(1 << n) + 1), last, win;
for (int i = 1; i <= (1 << n); i++) {
cin >> a[i];
last.push_back(i);
}
while(last.size() > 2) {
for (int i = 0; i < (int)last.size(); i += 2) {
if (a[last[i]] > a[last[i + 1]]) {
win.push_back(last[i]);
} else {
win.push_back(last[i + 1]);
}
}
last = win;
win.clear();
}
if (a[last[0]] > a[last[1]]) {
cout << last[1] << '\n';
} else {
cout << last[0] << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> Pair;
typedef tuple<int,int,int> tpl;
#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)
#define en "\n"
constexpr double EPS = 1e-9;
constexpr double PI = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
void Main(){
int K; cin >> K;
string S,T; cin >> S >> T;
VI num(10,K), na(10,0), nb(10,0);
REP(i,4){
int x = S[i]-'0';
num[x]--; na[x]++;
x = T[i]-'0';
num[x]--; nb[x]++;
}
double ans = 0;
FOR(i,1,10)FOR(j,1,10){
na[i]++; nb[j]++;
bool flag = false;
FOR(k,1,10){
if(na[k]+nb[k]>K){
flag = true;
break;
}
}
if(flag){
na[i]--; nb[j]--;
continue;
}
int sa = 0, sb = 0;
FOR(k,1,10){
int t = 1;
REP(_,na[k]) t *= 10;
sa += k*t;
t = 1;
REP(_,nb[k]) t *= 10;
sb += k*t;
}
na[i]--; nb[j]--;
if(sa<=sb) continue;
if(i==j){
ans += 1.0 * num[i] / (9*K-8) / (9*K-9) * (num[i]-1);
}
else{
ans += 1.0 * num[i] / (9*K-8) / (9*K-9) * num[j];
}
}
cout << ans << en;
return;
}
int main(void){
cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
int t=1; //cin>>t;
REP(_,t) Main();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using Int = long long;
const char newl = '\n';
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
vector<T> ts(n);
for(size_t i=0;i<n;i++) cin>>ts[i];
return ts;
}
struct Precision{
Precision(){
cout<<fixed<<setprecision(12);
}
}precision_beet;
// [0, n]
template<typename T>
vector<T> powers(Int n,T x){
vector<T> po(n+1,T(1));
for(Int i=0;i<n;i++) po[i+1]=po[i]*x;
return po;
}
//INSERT ABOVE HERE
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
Int k;
cin>>k;
auto way=[&](string s,string t)->Int{
string a=s+t;
for(char c='1';c<='9';c++){
Int cnt=count(a.begin(),a.end(),c);
if(cnt>k) return 0;
}
Int x=k-count(a.begin(),a.end(),s.back())+1;
Int y=k-count(a.begin(),a.end(),t.back())+1;
if(s.back()==t.back()) return x*(x+1);
return x*y;
};
auto po=powers(10,10LL);
auto score=[&](string s){
Int res=0;
for(char c='1';c<='9';c++){
Int cnt=count(s.begin(),s.end(),c);
res+=(c-'0')*po[cnt];
}
return res;
};
string s,t;
cin>>s>>t;
Int num=0,den=0;
for(char x='1';x<='9';x++){
for(char y='1';y<='9';y++){
s.back()=x;
t.back()=y;
// if(x=='2' and y=='1') cout<<score(s)<<' '<<score(t)<<':'<<way(s,t)<<endl;
if(score(s)>score(t)) num+=way(s,t);
den+=way(s,t);
}
}
// cout<<num<<' '<<den<<endl;
using D = double;
cout<<D(num)/D(den)<<endl;
return 0;
}
|
#include <cstdio>
#include <iostream>
#include <algorithm>
long long B = 10;
using namespace std;
long long exponent(long long r, long long base) {
long long sum = 1;
for (int i = 1; i <= r; i++) {
sum *= base;
}
return sum;
}
int main() {
long long N;
scanf("%lld", &N);
int digits = 0;
long long temp_N = N;
while (temp_N) {
temp_N /= B;
digits++;
}
if ((digits & 1) == 1){
int half = (digits - 1) / 2;
long long sum = 0;
long long base = 1;
for(int i = 0;i <= half - 1;i++){
sum += base * 9;
base *= 10;
}
printf("%lld", sum);
}
else{
long long base = exponent(digits / 2, 10);
long long high = N / base;
long long sum = high;
if (high * base + high > N) sum -= 1;
printf("%lld", sum);
}
}
| #include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <iterator>
#include <stack>
#include <queue>
#include <functional>
#include <map>
using namespace std;
#define ll long long
#define double long double
#define vi vector<int>
#define vvi vector<vi>
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
int main()
{
string N;
cin >> N;
string front, back;
int half_size = N.size() / 2;
if (half_size == 0)
{
cout << "0" << endl;
return 0;
}
if (N.size() % 2 == 0)
{
for (size_t i = 0; i < half_size; i++)
{
front += N[i];
back += N[half_size + i];
}
}
else
{
for (size_t i = 0; i < half_size; i++)
{
front += "9";
back += "9";
}
}
int front_int, back_int;
front_int = stoi(front);
back_int = stoi(back);
int ans = 0;
if (front_int <= back_int)
{
ans++;
}
front_int--;
ans += front_int;
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define TC 0
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
template <typename T>
vector<T> readArr(int n) {
vector <T> v(n);
for (auto &it : v)
cin >> it;
return v;
}
void init() {
;
}
void solve() {
int k; cin >> k;
string s, t; cin >> s >> t;
vector <ll> cards(10, k);
for (char ch: s)
if (ch != '#')
cards[ch-'0']--;
for (char ch: t)
if (ch != '#')
cards[ch-'0']--;
ll scoreA = 0, scoreB = 0;
vector <int> s1(10), s2(10);
for (int i=0; i<4; i++) {
s1[s[i]-'0']++;
s2[t[i]-'0']++;
}
// string test = "11222
for (int i=1; i<=9; i++) {
// cout << deb(i) deb(s1[i]) deb(s2[i]) << "\n";
scoreA += (i * pow(10, s1[i]));
scoreB += (i * pow(10, s2[i]));
}
//cout << scoreA <<" " << scoreB << "\n";
ll num = 0;
ll d = 0;
for (int i=1; i<=9; i++) {
for (int j=1; j<=9; j++) {
if (i == j) {
if (cards[i] < 2)
continue;
} else if (cards[i] == 0 || cards[j] == 0) {
continue;
}
ll ct = cards[i] * cards[j];
if (i == j)
ct = (cards[i]*(cards[i]-1));
d += ct;
ll ns1 = scoreA;
ns1 -= (i*pow(10, s1[i]));
ns1 += (i*pow(10, s1[i]+1));
ll ns2 = scoreB;
ns2 -= (j*pow(10, s2[j]));
ns2 += (j*pow(10, s2[j]+1));
//cout << deb(i) deb(j) deb(ns1) deb(ns2) << "\n";
if (ns1 > ns2) {
num += ct;
}
}
}
//cout << num << " " << " " << d << "\n";
double res = (double)num / (double)d;
printf("%.14f\n", res);
}
int main() {
IOS
init();
int t = 1;
if (TC)
cin >> t;
while (t--) {
solve();
}
}
| #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
lint K;
string S, T;
cin >> K >> S >> T;
vector<lint> cnt(10, K);
vector<lint> ta(10);
vector<lint> ao(10);
REP(i, 4) {
ta[S[i] - '0']++;
cnt[S[i] - '0']--;
ao[T[i] - '0']++;
cnt[T[i] - '0']--;
}
lint bunsi = 0;
lint bunbo = 0;
FOR(i, 1, 10) FOR(j, 1, 10) {
lint tascore = 0;
lint aoscore = 0;
FOR(k, 1, 10) {
lint tmp = k;
REP(j, ta[k]) tmp *= 10;
if(k == i) tmp *= 10;
tascore += tmp;
}
FOR(k, 1, 10) {
lint tmp = k;
REP(j, ao[k]) tmp *= 10;
if(k == j) tmp *= 10;
aoscore += tmp;
}
lint pattern = cnt[i] * cnt[j];
if(i == j) pattern = cnt[i] * (cnt[j] - 1);
if(tascore > aoscore) bunsi += pattern;
bunbo += pattern;
}
cout << fixed << setprecision(10) << (double)bunsi / (double)bunbo << "\n";
} |
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define RREP(i, n) for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll INFL = 1e18;
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(a > b) { a = b; return true; } return false; }
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
int N, S, D; cin >> N >> S >> D;
int X[N], Y[N]; REP(i, N) cin >> X[i] >> Y[i];
REP(i, N)
{
if(X[i] < S && Y[i] > D)
{
Yes;
return 0;
}
}
No;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vll = vector<long long>; using vs = vector<string>;
using vvi = vector<vector<int>>; using vvll = vector<vector<long long>>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
void solve1(){
int n;
cin >> n;
vector<pll> at(n);
for(auto& [a,t]: at) cin >> a >> t;
int q;
cin >> q;
vector<ll> x(q);
for(auto& y: x) cin >> y;
auto f = [](const ll x, const ll a, const ll t)->ll{
if(t==1){
return x+a;
}else if(t==2){
return max(x,a);
}else{
return min(x,a);
}
};
for(int i = 0; i < q; ++i){
ll var = x[i];
for(int j = 0; j < n; ++j){
const auto [a,t] = at[j];
var = f(var, a, t);
}
cout << var << endl;
}
}
void solve2(){
constexpr ll ll_max = (1LL<<62)+((1LL<<62)-1LL);
constexpr ll ll_min = -(1LL<<62)-(1LL<<62);
auto conv = [&](const ll a__, const ll t__)->tuple<ll,ll,ll>{
ll add, floor__, ceil__;
if(t__ == 1){
floor__ = ll_min;
ceil__ = ll_max;
add = a__;
}else if(t__ == 2){
floor__ = a__;
ceil__ = ll_max;
add = 0;
}else{
floor__ = ll_min;
ceil__ = a__;
add = 0;
}
return {add, floor__, ceil__};
};
int n;
cin >> n;
vector<tuple<ll,ll,ll>> v(n);
for(int i = 0; i < n; ++i){
ll a, t;
cin >> a >> t;
v[i] = conv(a,t);
}
auto [add, floor__, ceil__] = v[0];
for(int i = 1; i < n; ++i){
auto [a2, b2, c2] = v[i];
if(ceil__ != ll_max){
ceil__ += a2;
}
if(floor__ != ll_min){
floor__ += a2;
}
tie(add, floor__, ceil__) = make_tuple(add+a2, max(b2, floor__), min(c2, max(b2, ceil__)));
}
int q;
cin >> q;
vector<ll> x(q);
for(auto& y: x) cin >> y;
auto f = [](const ll x, const ll add, const ll floor__, const ll ceil__)->ll{
return min(ceil__, max(floor__, x+add));
};
for(int i = 0; i < q; ++i){
cout << f(x[i], add, floor__, ceil__) << endl;
}
}
tuple<int,int,int> test(){
return {1,3,4};
}
void solve3(){
constexpr ll ll_max = ((1LL<<62)+((1LL<<62)-1LL))/4LL;
constexpr ll ll_min = (-(1LL<<62)-(1LL<<62))/4LL;
int n;
cin >> n;
ll add = 0, floor__ = ll_min, ceil__ = ll_max;
for(int i = 0; i < n; ++i){
ll a, t;
cin >> a >> t;
if(t == 1){
floor__ += a;
ceil__ += a;
add += a;
}else if(t == 2){
floor__ = max(floor__, a);
//ceil__ = max(ceil__, a);
}else{
ceil__ = min(ceil__, a);
//floor__ = min(floor__, a);
}
}
int q;
cin >> q;
vector<ll> x(q);
for(auto& y: x) cin >> y;
auto f = [](const ll x, const ll add, const ll floor__, const ll ceil__)->ll{
return min(ceil__, max(floor__, x+add));
};
for(int i = 0; i < q; ++i){
cout << f(x[i], add, floor__, ceil__) << endl;
}
}
int main(){
//solve1();
solve2();
//solve3();
}
|
#include<bits/stdc++.h>
#define N 200005
#define Mod 998244353
#define MOD(x) (x>=Mod)&&(x-=Mod)
#define Ms(a,b) memset(a,b,sizeof a)
#define db(x) cerr<<#x<<"="<<x<<endl;
#define db2(x,y) cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
using namespace std;
int rd(){
int res=0,c,f=0;
while(!isdigit(c=getchar()))f=c=='-';
do res=(res<<1)+(res<<3)+(c^48);
while(isdigit(c=getchar()));
return f?-res:res;
}
int dp[N][18];
int n,m;
int main(){
n=rd(),m=rd(),dp[0][0]=1;
for(int i=1;i<=n;i++)
for(int j=0;j<=17;j++)
for(int k=0;k<=j;k++)
dp[i][j]+=dp[i-1][j-k],MOD(dp[i][j]);
int res=0;
for(int i=1;i<=m;i++){
int now=1,x=i;
for(int j=2;1ll*j*j<=x;j++){
int t=0;
while(x%j==0)x/=j,++t;
now=1ll*now*dp[n][t]%Mod;
}
if(x!=1)now=1ll*now*n%Mod;
res+=now,MOD(res);
}
printf("%d\n",res);
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 998244353
#define infi 1010000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}
class Combination {
vl fac,finv,inv;
public:
Combination(ll n) {
n++;
fac.resize(n);finv.resize(n);inv.resize(n);
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
reps(i,2,n){
fac[i] = fac[i-1]*(ll)i%mod;
inv[i] = (ll)mod - inv[mod%i]*(ll)(mod/i)%mod;
finv[i] = finv[i-1]*inv[i]%mod;
}
}
ll com(ll n, ll m){
if(n < m) return 0;
if(n < 0 || m < 0) return 0;
return fac[n]*(finv[m]*finv[n-m]%mod)%mod;
}
};
class Prime {
int N;
public:
vi prime_list, f;
Prime(int n){
N = n;
f.resize(N+1);
for (ll i = 2; i <= N; i++) {
if(f[i]) continue;
f[i] = i;
prime_list.pb(i);
for (ll j = i*i; j <= N; j += i) {
if(!f[j]) f[j] = i;
}
}
}
bool is_prime(int n){return f[n] == n;}
vi prime_factorize(int n){
vi res;
while (n > 1) {
res.pb(f[n]);
n /= f[n];
}
return res;
}
ve<pii> prime_factorize_pii(int n){
vi p_list = prime_factorize(n);
if(p_list.size() == 0) return {};
ve<pii> res(1,{p_list[0],0});
for (int p : p_list) {
if(res.back().fi == p) res.back().se++;
else res.pb(make_pair(p,1));
}
return res;
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M;
cin >> N >> M;
if(N == 1){
cout << M << endl;
return 0;
}
Prime P(400010);
ll ans = 0;
Combination C(400010);
rep(i,M){
ve<pii> a = P.prime_factorize_pii(i+1);
ll aa = 1LL;
for (pii p : a) {
aa *= C.com((ll)(N-1LL+(ll)p.se),(ll)(N-1LL));
aa %= mod;
}
//cout << i+1 csp aa << endl;
ans += aa;
ans %= mod;
}
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define INF LONG_MAX/3
//#define DIV 1000000007
//#define DIV 998244353
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
ll N;
cin >> N;
vector<string> ans;
ans.push_back("AB");
rep(i, N-1) {
vector<string> n_ans;
for(string s: ans) {
n_ans.push_back(s + s);
}
for(string s: ans) {
string rev = "";
for(char ch: s) {
if(ch == 'A') {
rev += "B";
} else {
rev += "A";
}
}
n_ans.push_back(s + rev);
}
string s = "";
rep(i, n_ans[0].size()/2) s += "A";
rep(i, n_ans[0].size()/2) s += "B";
n_ans.push_back(s);
swap(ans, n_ans);
}
cout << ans.size() << endl;
for(auto s: ans) cout << s << endl;
}
| #include<cstdio>
#include<vector>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
namespace Elaina{
// #define NDEBUG
#include<cassert>
#define rep(i, l, r) for(int i=(l), i##_end_=(r); i<=i##_end_; ++i)
#define drep(i, l, r) for(int i=(l), i##_end_=(r); i>=i##_end_; --i)
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define Endl putchar('\n')
#define mmset(a, b) memset(a, b, sizeof a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T>inline T fab(T x){ return x<0? -x: x; }
template<class T>inline void getmin(T& x, const T rhs){ x=min(x, rhs); }
template<class T>inline void getmax(T& x, const T rhs){ x=max(x, rhs); }
template<class T>inline T readin(T x){
x=0; int f=0; char c;
while((c=getchar())<'0' || '9'<c) if(c=='-') f=1;
for(x=(c^48); '0'<=(c=getchar()) && c<='9'; x=(x<<1)+(x<<3)+(c^48));
return f? -x: x;
}
template<class T>inline void writc(T x, char s='\n'){
static int fwri_sta[1005], fwri_ed=0;
if(x<0) putchar('-'), x=-x;
do fwri_sta[++fwri_ed]=x%10, x/=10; while(x);
while(putchar(fwri_sta[fwri_ed--]^48), fwri_ed);
putchar(s);
}
}
using namespace Elaina;
int a[5];
signed main(){
rep(i, 1, 3) a[i]=readin(1);
sort(a+1, a+4);
if(a[1]==a[2]) writc(a[3]);
else if(a[2]==a[3]) writc(a[1]);
else writc(0);
return 0;
} |
#include<bits/stdc++.h>
#define print(x) cout << (#x) << ": " << (x) << endl
#define p1d(x) cout << (#x) << ": ["; for(auto& zz: x) cout << zz << " "; cout << "]\n"
#define p2d(x) cout << (#x) << ": \n["; for(auto& vec: x) {for(auto& v: vec) cout << v << " "; cout << ",\n";}
#define p2s(x) cout << (#x) << ": ["; for(auto& vec: x) {cout << vec << ",\n";}
#define pb push_back
#define endl "\n"
// __builtin_popcount
typedef long long ll;
using namespace std;
int static fast = [](){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);
ll partition(int& need, int fac, int exclude, int thres) {
int cnt = 2;
ll tmp = 0, init = need;
//print(fac);
while(need > 0) {
tmp = fac * cnt;
if (tmp >= thres) {
//cout << "consume " << (init - need) << endl;
// cout << "need = " << cpy << ", last = " << tmp << endl;
return init-need;
}
if ((tmp % exclude) != 0) {
cout << tmp << " ";
need -= 1;
}
cnt += 1;
}
// cout << "need = " << cpy << ", last = " << tmp << endl;
//cout << "consume " << (init - need) << endl;
return need;
}
int main() {
int n, n2;
cin >> n;
n2 = n;
cout << (2*3) << " " << (3*5) << " " << (2*5) << " ";
n -= 3;
partition(n, 2*3, 5, 10000);
partition(n, 2*5, 3, 10000);
partition(n, 3*5, 2, 10000);
partition(n, 2*3*5, 99999, 10000);
// assert(acc == n2);
// if (n < 1000) {
// int div3 = n / 3;
// partition(div3, 3*5, 2);
// partition(div3, 2*5, 3);
// partition(n-div3*2, 2*3, 5);
// } else {
// int X = 100;
// int divX = n / X;
// // print(divX); // trail and run
// partition(divX*13, 3*5, 2);
// partition(divX*25, 2*5, 3);
// partition(n-divX*62, 2*3, 5);
// }
return 0;
}
| #include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> plli;
typedef vector< vi > vvi ;
typedef vector< vlli > vvlli ;
#define fi(i,a,b) for(int i=a;i<=b;i++)
#define flli(i,a,b) for(long long int i=a;i<=b;i++)
#define bi(i,a,b) for(int i=a;i>=b;i--)
#define blli(i,a,b) for(long long int i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pi 2*acos(0.0)
#define pb push_back
#define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
#define present(v,num) (v.find(num)!=v.end())
#define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
#define pq priority_queue
#define mp make_pair
const int inf=INT_MAX;
const lli INF =LLONG_MAX;
const lli mod = 1e9+7;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast;
lli n;cin>>n;
vlli a;
lli idx=1;
set<lli> vals;
flli(i,1,n-2)
{
lli val=6*idx;
if(val<=10000)
{
vals.insert(val);
idx++;
}
}
idx=1;
flli(i,1,n-2)
{
lli val=10*idx;
lli szvals=sz(vals);
if(val==110 || val==165)idx++;
if(val<=10000 && szvals<n-2 && val!=110 && val!=165)
{
vals.insert(val);
idx++;
}
}
idx=1;
flli(i,1,n-2)
{
lli val=15*idx;
lli szvals=sz(vals);
if(val==110 || val==165)idx++;
if(val<=10000 && szvals<n-2 && val!=110 && val!=165)
{
vals.insert(val);
idx++;
}
}
a.pb(2*5*11);
a.pb(3*5*11);
tr(vals,it)a.pb(*it);
lli sza=sz(a);
assert(sza==n);
flli(i,0,n-1)cout<<a[i]<<" ";
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
return 0;
} |
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;i++)
#define fore(i,l,r) for(int i=int(l);i<=int(r);i++)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);
#define uid(a,b) uniform_int_distribution<int>(a,b)(rng)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 505;
int n, k;
void burn() {
cin >> n >> k;
while (k--) {
if (n % 200 == 0) {
n /= 200;
} else {
n = n * 1000 + 200;
}
// cout << n << " ";
}
cout << n << endl;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fastio;
int t = 1;
// cin >> t;
while (t--) {
burn();
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main() {
int k;
long n;
cin >> n >> k;
for (int i = 0; i < k; i++) {
if (n % 200 == 0)n /= 200;
else n = n * 1000 + 200;
}
cout << n << endl;
return 0;
} |
#ifdef _LOCAL
#define _GLIBCXX_DEBUG
#endif
#ifdef _DEBUG
#define bug(x) cout<<'['<<#x<<'='<<x<<']'<<"\n";
#else
#define bug(x)
#endif
#include <bits/stdc++.h>
using namespace std;
#pragma region macros
using str=string;
using ll=long long;
using ld=long double;
using vl=vector<ll>;
using vc=vector<char>;
using vb=vector<bool>;
using pl=pair<ll,ll>;
using ml=map<ll,ll>;
using sl=set<ll>;
template<class T> using V=vector<T>;
template<class T,class U> using P=pair<T,U>;
#define FOR(n) for(ll i=0;i<n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,n) for(ll i=1;i<n;i++)
#define REP(i,m,n) for(ll i=m;i<n;i++)
#define drep(i,n) for(ll i=n-1;i>=0;i--)
#define fore(n) for(auto&& e1:n)
#define fors(n) for(auto&&[e1,e2]:n)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sor(v) sort(all(v))
#define rsor(v) sort(rall(v))
#define rev(v) reverse(all(v))
#define low(v,x) lower_bound(all(v),x)-v.begin()
#define up(v,x) upper_bound(all(v),x)-v.begin()
#define acc(v) accumulate(all(v),0LL)
#define ef(x) emplace_front(x)
#define eb(x) emplace_back(x)
#define pf() pop_front()
#define pb() pop_back()
#define mp(a,b) make_pair(a,b)
#define ceil(a,b) (a+b-1)/b
#define bit(n) (1LL<<n)
#define fi first
#define se second
#define fr front()
#define ba back()
#define be begin()
#define en end()
#define br break
#define cn continue
#define wh while
#define el else if
#define re return
const ll inf=1LL<<60;
const ll mod=1000000007;
const ll MOD=998244353;
const ld pi=3.1415926535;
const ld eps=1e-10;
const ll dx[4]={1,0,-1,0};
const ll dy[4]={0,1,0,-1};
const ll DX[8]={1,1,0,-1,-1,-1,0,1};
const ll DY[8]={0,1,1,1,0,-1,-1,-1};
void input(){}
void inputs(){}
void output(){}
template<class T,class...U> void input(T& x,U&...y){cin>>x;input(y...);}
template<class...T> void in(T&...x){input(x...);}
template<class T> void inputs(const ll t,T& x){cin>>x[t];}
template<class T,class...U> void inputs(const ll t,T& x,U&...y){cin>>x[t];inputs(t,y...);}
template<class T,class...U> void inputs(T& x,U&...y){rep(t,size(x))inputs(t,x,y...);}
template<class...T> void ins(T&...x){inputs(x...);}
template<class T,class...U> void output(T x,U...y){cout<<x<<"\n";output(y...);}
template<class...T> void out(T...x){output(x...);}
template<class...T> void fin(T...x){out(x...);exit(0);}
template<class T> istream&operator>>(istream& i,V<T>& v){for(T& x:v)i>>x;re i;}
template<class T,class U> istream&operator>>(istream& i,P<T,U>& p){re i>>p.fi>>p.se;}
template<class T> ostream&operator<<(ostream& o,V<T>& v){for(T& x:v)o<<x<<" ";re o;}
template<class T,class U> ostream&operator<<(ostream& o,P<T,U>& p){re o<<p.fi<<" "<<p.se;}
void yn(bool b){fin((b?"Yes":"No"));}
void YN(bool b){fin((b?"YES":"NO"));}
void pos(bool b){fin((b?"POSSIBLE":"IMPOSSIBLE"));}
template<class T,class U> void chmax(T& a,U b){if(a<b)a=b;}
template<class T,class U> void chmin(T& a,U b){if(a>b)a=b;}
template<class T,class U> auto max(T a,U b){re a>b?a:b;}
template<class T,class U> auto min(T a,U b){re a<b?a:b;}
ll qp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r*=x;x*=x;n>>=1;}re r;}
ll mdp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r=r*x%mod;x=x*x%mod;n>>=1;}re r;}
ll MDp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r=r*x%MOD;x=x*x%MOD;n>>=1;}re r;}
struct UnionFind{
vl par,sz;
UnionFind(ll n):par(n),sz(n,1){rep(i,n) par[i]=i;}
ll rot(ll x){
if(par[x]==x) re x;
re par[x]=rot(par[x]);
}
void uni(ll x,ll y){
x=rot(x),y=rot(y);
if(x==y) re;
if(sz[x]<sz[y]) swap(x,y);
sz[x]+=sz[y];
par[y]=x;
}
bool eql(ll x,ll y){re rot(x)==rot(y);}
ll siz(ll x){re sz[rot(x)];}
};
struct IOSetup{
IOSetup(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout<<fixed<<setprecision(10);
}
}iosetup;
#pragma endregion
signed main(){
ll n; in(n);
ll ans=0;
FOR(200000){
ans=(i+1)*(i+2)/2;
if(n<=ans) fin(i+1);
}
} | #include <iostream>
#include <stdio.h>
#include <vector>
#include <climits>
#include <algorithm>
#include <queue>
#include <functional>
#include <random>
using namespace std;
typedef long long ll;
typedef vector<int> vec_i;
typedef vector<vector<int>> vv_i;
typedef vector<pair<int, int>> vec_P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPT(i, j, n) for (int i = (int)(j)+1; i < (int)(n); i++)
const int INF = INT_MAX;
struct edge { ll to, cost; };
typedef pair<ll, ll> P;
bool cross(double l1, double r1, double l2, double r2) {
return (l2 <= r1 && l1 <= r2);
}
int main(void) {
int N;
cin >> N;
double T, L, R;
vector<double> Left(N);
vector<double> Right(N);
REP(i, N) {
cin >> T >> L >> R;
if (T == 2) {
R-=0.1;
}
else if (T == 3) {
L+=0.1;
}
else if (T == 4) {
L+=0.1;
R-=0.1;
}
Left.at(i) = L;
Right.at(i) = R;
}
int count = 0;
REP(i, N) {
REPT(j, i, N) {
if (cross(Left.at(i), Right.at(i), Left.at(j), Right.at(j))) {
//cout << i << " " << j << endl;
//cout <<Left.at(i) << " " << Right.at(i) << " " << Left.at(j) << " " << Right.at(j) << endl;
count++;
}
}
}
cout << count << endl;
}
|
/*Bismillahir Rahmanir Rahim*/
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define ff first
#define ss second
#define ll long long int
#define dd double
#define pb push_back
#define mp make_pair
#define pr pair<ll,ll>
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vector<ll>,greater<ll>>
#define mod 1000000007
#define pd(x,y) fixed<<setprecision(y)<<x
#define w(x) ll x; cin>>x; while(x--)
#define loop(i,x,n) for(ll i=x;i<n;i++)
#define rloop(x,n) for(ll i=n-1;i>=x;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
//Apna Time Aayega :)
using namespace std;
signed main()
{
ll n,ans=1;
cin>>n;
(n%2==0) ? (cout<<"White"<<endl) : (cout<<"Black"<<endl) ;
}
| #include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
//const bool debug = false;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
bool a[200];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long n, t;
cin >> t >> n;
n--;
rep(i, 100) {
int num = (100 + t)*i / 100;
a[num] = true;
}
vector<int>list;
rep(i, 100 + t) {
if (!a[i]) list.push_back(i);
}
/*rep(i, list.size()) {
cout << list[i] << endl;
}*/
long long ans = (n / list.size())*(100 + t) + list[n%list.size()];
cout << ans << endl;
return 0;
} |
//************ || MD. SAJID ALAM CHOWDHURY || *************//
//**************** || 22-May-2021(Sat) || *****************//
//******************** || 18:40:18 || *********************//
#include<bits/stdc++.h>
using namespace std;
//********************* || DEFINES || *********************//
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ff first
#define ss second
#define IN insert
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define PP prev_permutation
#define all(v) v.begin(),v.end()
#define Fo(i,a,b) for(i=a;i<=b;i++)
#define Fb(i,b,a) for(i=b;i>=a;i--)
//******************** || TYPEDEFS || *********************//
typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//******************** || CONSTANTS || ********************//
const ll MAX=2e5+5;
const ll MOD=1e9+7;
const ll INF=1e18+5;
const ld PI=acos(-1);
//******************** || FUNCTIONS || ********************//
ll gcd(ll m,ll n)
{
while(n!=0)
{
m%=n;
swap(m,n);
}
return m;
}
ll lcm(ll m,ll n)
{
return ((m*n)/gcd(m,n));
}
ll perm(ll m,ll n)
{
ll s=1,p=1;
for(ll i=m+1;i<=(m+n);i++)
{
s*=i;
s/=p;
p++;
}
return s;
}
int main()
{
#ifndef ONLINE_JUDGE
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
#endif
/***********************/ BOOST /***********************/
//***************** || READY TO GO || *****************//
ll a,b,k,i,q,r,p,cnt=0,f;
cin>>a>>b>>k;
string str,ans;
for(i=1;i<=a;i++)
{
str.PB('a');
}
for(i=1;i<=b;i++)
{
str.PB('b');
}
f=a+b;
while(cnt!=f)
{
p=perm(a-1,b);
if(k<=p)
{
ans.PB('a');
a--;
}
else
{
ans.PB('b');
k-=p;
b--;
}
cnt++;
}
cout<<ans<<endl;
return 0;
//*************** || DONE AND DUSTED || ***************//
} | # include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
char s[5000];
scanf("%d %s", &n, s);
vector<int> a(n+1,0), t(n+1,0), c(n+1,0), g(n+1,0);
for(int i=1;i<=n;i++) {
a[i] = a[i-1];
t[i] = t[i-1];
c[i] = c[i-1];
g[i] = g[i-1];
if(s[i-1] == 'A') { a[i]++; }
else if(s[i-1] == 'T') { t[i]++; }
else if(s[i-1] == 'C') { c[i]++; }
else if(s[i-1] == 'G') { g[i]++; }
}
long long int ans=0;
for(int i=0;i<=n;i++) {
for(int j=i-2;j>=0;j-=2) {
if(a[i]-a[j] == t[i]-t[j] && c[i]-c[j] == g[i]-g[j]) { ans++; }
/*
if(a[i]>0 && t[i]>0 && a[i]-a[j] == t[i]-t[j]) { ans++; printf("%d %d\n", i, j); }
else if(c[i]>0 && g[i]>0 && c[i]-c[j]>0 && c[i]-c[j] == g[i]-g[j]) { ans++; printf("%d %d\n", i, j); }
else if(a[i]>0 && t[i]>0 && c[i]>0 && g[i]>0 && a[i]-a[j] == t[i]-t[j] && c[i]-c[j] == g[i]-g[j]) { ans++; printf("%d %d\n", i, j); }
*/
}
}
cout << ans << endl;
return 0;
}
|
#include<iostream>
#include<cmath>
#include<vector>
#include<bitset>
#include<bitset>
#include<string>
#include<utility>
#include<queue>
#include <iomanip>
#include <limits>
#include<tuple>
#include<algorithm>
#include<set>
using namespace std;
typedef long long int ll;
// ll
int main(){
int n,k;
cin >> n >> k;
vector<vector<ll>> a(n+1,vector<ll>(n+1));
ll ok=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin >> a.at(i+1).at(j+1);
ok=max(a.at(i+1).at(j+1),ok);
}
}
ll ng=(-1);
ll mid;
// cout << ok << endl;
bool ind=false;
while(ok>ng+1){
mid=(ok+ng)/2;
// cout << ng <<"," << ok << "," << mid << endl;
vector<vector<ll>> s(n+1,vector<ll>(n+1,0));
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
s.at(i).at(j)=s.at(i-1).at(j)+s.at(i).at(j-1)-s.at(i-1).at(j-1);
if(mid<a.at(i).at(j))s.at(i).at(j)++;
}
}
ind=false;
for(int i=k;i<=n;i++){
for(int j=k;j<=n;j++){
if(s.at(i).at(j)-s.at(i-k).at(j)-s.at(i).at(j-k)+s.at(i-k).at(j-k)<k*k/2+1){
ind=true;
break;
}
}
if(ind)break;
}
if(ind){
ok=mid;
}else{
ng=mid;
}
}
cout << ok << endl;
return 0;
} | #define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
int dp[1001][1001];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
int a[1000], b[1000];
cin >> n >> m;
rep(i, n)cin >> a[i];
rep(i, m)cin >> b[i];
rep(i, n + 1)rep(j, m + 1)dp[i][j] = INF;
dp[0][0] = 0;
rep(i, n + 1)rep(j, m + 1) {
int d = dp[i][j];
if (i < n)dp[i + 1][j] = min(dp[i + 1][j], d + 1);
if (j < m)dp[i][j + 1] = min(dp[i][j + 1], d + 1);
if (i < n && j < m) {
dp[i + 1][j + 1] = min(dp[i + 1][j + 1], d + (a[i] != b[j]));
}
}
cout << dp[n][m] << endl;
return 0;
}
|
#include <bits/stdc++.h>
// 1. dp
typedef long double ld;
#define int long long
#define gcd __gcd
#define endl "\n"
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define mod2 998244353
#define maxe *max_element
#define mine *min_element
#define inf 1e18
#define pb push_back
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define sz(x) (int)(x).size()
#define mk make_pair
#define deci(x, y) fixed<<setprecision(y)<<x
#define w(t) int t; cin>>t; while(t--)
#define nitin ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define PI 3.141592653589793238
using namespace std;
void solve() {
int n;
cin>>n;
if(n%2==0){
cout<<"White";
}
else{
cout<<"Black";
}
}
int32_t main() {
nitin;
solve();
}
| #include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
string ans = (n % 2 == 0) ? "White" : "Black";
cout << ans;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
for (int i = 0; i < m; ++i) cin >> a[i];
sort(a.begin(), a.end());
a.insert(a.begin(), 0);
a.push_back(n + 1);
vector<int> v;
int mn = n;
for (int i = 0; i + 1 < (int)a.size(); ++i) {
int len = a[i + 1] - a[i] - 1;
if (len > 0) {
v.push_back(len);
mn = min(mn, len);
}
}
int ans = 0;
for (auto len : v) ans += (len + mn - 1) / mn;
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (ll 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 mp make_pair
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL)
const int mod = 1e9 + 7, mxn = 1e5 + 1;
int solve(){
int n, m;
cin>> n>> m;
if(m == 0){
return cout<< 1<< "\n", 0;
}
int a[m];
rep(i, 0, m){
cin>> a[i];
}
sort(a, a + m);
int mn = a[0] - 1;
if(mn == 0){
mn = INT_MAX;
}
for(int i = 1; i < m; i++){
if(a[i] != a[i - 1] + 1){
mn = min(mn, a[i] - a[i - 1] - 1);
}
}
if(mn == INT_MAX){
return cout<< 0<< "\n", 0;
}
ll ans = 0;
ans = (a[0] - 1 + mn - 1) / mn;
for(int i = 1; i < m; i++){
ans += (a[i] - a[i - 1] - 1 + mn - 1) / mn;
}
ans += (n - a[m - 1] + mn - 1) / mn;
cout<< ans<< "\n";
return 0;
}
//Counting problems: Sometimes easier to find complement of the answer
int main()
{
fast;
int t = 1;
// cin>> t;
while(t--){
solve();
}
return 0;
}
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);
/* inv[1] = 1; // inv is ll
for(int i=2; i<=mxn; ++i)
inv[i]=mod-mod/i*inv[mod%i]%mod;*/
// lower bound >=
// upper bound >
// vector<int>().swap(vec); //free memory from vec
|
#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
// #define mp make_pair
#define pii pair<int,int>
// #define mod 998244353
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,a,n) for(int i=a;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
vector<string> split(const string& s, char c) {
vector<string> v; stringstream ss(s); string x;
while (getline(ss, x, c)) v.push_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
stringstream s; s << "[";
for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
s << arr[n - 1] << "]";
return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
__evars_out_var(a);
cerr << "; ";
__evars(++it, args...);
}
template<typename T_vector>
void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) {
if (start < 0) start = 0;
if (end < 0) end = int(v.size());
for (int i = start; i < end; i++)
cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
template<typename T> istream& operator >>(istream &in,vector<T> &v){
for(auto &x:v) in>>x; return in;
}
template<typename T> ostream& operator <<(ostream &out,vector<T> &v){
for(auto &x:v) out<<x<<' '; return out;
}
template<typename T1,typename T2> istream& operator >>(istream &in,pair<T1,T2> &p){
in>>p.first>>p.second; return in;
}
template<typename T1,typename T2> ostream& operator <<(ostream &out,pair<T1,T2> &p){
out<<p.first<<' '<<p.second; return out;
}
template<class T, class H>using umap=unordered_map<T,H,custom_hash>;
template<class T>using uset=unordered_set<T,custom_hash>;
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fio;
clock_t clk = clock();
int t = 1;
// cin >> t;
rep(tc, t)
{
// cout << "Case #" << tc + 1 << ": ";
vll a(3);
cin >> a;
sort(all(a));
if(a[1] - a[0] == a[2] - a[1])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
}
| #include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int main()
{
int64_t n, q;
cin >> n >> q;
vector<int64_t> a(n);
vector<int64_t> dsum(n);
for (int i = 0; i < n; i++)
{
cin >> a[i];
if (i > 0)
{
dsum[i] = dsum[i - 1] + a[i] - a[i - 1] - 1;
}
else
{
dsum[i] = a[i] - 1;
}
}
for (int i = 0; i < q; i++)
{
int64_t k;
cin >> k;
int l = 0;
int r = n - 1;
int c = (l + r) / 2;
int64_t ans = 0;
if (k <= dsum[l])
{
ans = k;
}
else if (dsum[r] < k)
{
ans = a[r] + k - dsum[r];
}
else
{
// 二分探索
while (c != r && c != l)
{
if (dsum[c] < k)
{
l = c;
c = (l + r) / 2.0;
}
else
{
r = c;
c = floor((l + r) / 2.0);
}
}
ans = a[c] + k - dsum[c];
}
cout << ans << endl;
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define sz(x) (int)((x).size())
#define fi first
#define sc second
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define fl fflush(stdout)
//#define mod 1000000007
#define mod2 998244353
#define pi 3.14159265358979323846
//bool comp(const pair<int,double> &a,const pair<int,double> &b){ return (a.second > b.second); }
/*
bool prime[111111];
bool isPrime(int n)
{
for(int i=2;i*i<=n;++i)
{
if(n%i==0)
return false;
}
return true;
}
bool prime[100005];
void sieve(int n)
{
memset(prime,true,sizeof(prime));
prime[1]=false;
for (int p=2;p*p<=n;p++)
{
if (prime[p]==true)
{
for (int i=p*p;i<=n;i+=p)prime[i]=false;
}
}
}
void dfs(int p){
used[p]=true;
rep(i,n){
if(used[i]==true) continue;
if(X[i]==X[p] || Y[i]==Y[p])dfs(i);
}
}
void bfs(int s) {
d = vector<int>(n, INF); d[s] = 0;
queue<int> q;
q.push(s);
while (!q.empty()) {
int v = q.front();
q.pop();
for (auto to : g[v]) { if (d[to] == INF) { d[to] = d[v] + 1; q.push(to); } }
}
}
void update(int x, ll val){while(x <= n)tree[x] += val,x += (x & -x);}
ll read(int x){ ll sum=0; while (x>0)sum+=tree[x],x -= (x & -x); return sum;}
void update(int l, int r, int nod, int lvl)
{
if(l==r)tree[nod] = x;
else
{
int mid = (l+r)/2; //left tree
if(i <= mid) update(l,mid,nod*2,lvl-1);//right tree
else update(mid+1,r,nod*2+1,lvl-1);
if(lvl%2 == 0) tree[nod] = (tree[2*nod]^tree[nod*2 + 1]);
else tree[nod] = (tree[2*nod]|tree[nod*2 + 1]);
}
}
bool sortbysec(const pair<int,int> &a , const pair<int,int> &b) {
if(a.first==b.first) {return(a.second < b.second);}
else return a.first<b.first;
}
while(n>0)
{
if(n&1)ans=(ans*x)%mo;
n/=2;
x =(x*x)%mo;
}
bool sortbysec(const pair<int,int> &a , const pair<int,int> &b) {
return a.second<b.second;//
}
#define max 60
ll dp[25][25];
ll nCr(ll n, ll r)
{
if(n==r) return dp[n][r] = 1;
if(r==0) return dp[n][r] = 1;
if(r==1) return dp[n][r] = n;
if(dp[n][r]) return dp[n][r];
return dp[n][r] = (nCr(n-1,r) + nCr(n-1,r-1));
}
*/
void solve(){
//points to remember:
//1.overflow 2.max/min values 3.array bound 4.special case(n==1) 5.infinite loop
int n; cin>>n;
vector<int> v(n);
rep(i,0,n)cin>>v[i];
int mex=0;
set<int> s,p;
rep(i,0,200001)p.insert(i);
rep(i,0,n){
p.erase(v[i]);
if(v[i]==mex)mex=*p.begin();
cout<<mex<<"\n";
}
}
int main(){
//ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
//sieve(100000);
//int t; cin>>t; while(t--)
solve();
} | #include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
ll f(ll x){
return (x+1)*x/2;
}
int main(){
ll l=1,r=100000;
ll n;
cin >> n;
while(l<r){
ll mid=(l+r)/2;
if(f(mid)<n)
l=mid+1;
else
r=mid;
}
cout << l << endl;
return 0;
} |
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <stdio.h>
#include <unistd.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define itrep(itr, base) for (auto itr = base.begin(); itr != base.end(); itr++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl
#define PI 3.14159265359
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main() {
string a, b;
cin >> a >> b;
int ans = 0;
rep (i, a.size()) {
ans += a[i] - '0';
}
int tmp = 0;
rep (i, b.size()) {
tmp += b[i] - '0';
}
if (ans > tmp) P(ans);
else P(tmp);
return 0;
}
| #include <iostream>
using namespace std;
int main() {
int a,b;
cin>>a>>b;
int m,sum=0,n,summ=0;
while(a!=0)
{
m=a%10;
sum=sum+m;
a=a/10;
}
while(b!=0)
{
n=b%10;
summ=summ+n;
b=b/10;
}
if(sum>summ)
cout<<sum;
else
cout<<summ;
return 0;
}
|
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n , k;
cin>>n>>k;
ll a[n];
map<ll , ll> mp;
for(int i = 0; i < n; i++){
cin>>a[i];
mp[a[i]]++;
}
ll ans = 0 , cur = 0;
for(ll i = 0; i <= n; i++){
ans += ((k - min(k , mp[i]))*i);
k -= (k - min(k , mp[i]));
}
for(ll i = 0; i <= n; i++){
if(mp[i] == 0){
cur = i;
break;
}
}
ans += (k * (cur));
cout<<ans;
return 0;
} | #define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define puba(a) emplace_back((a))
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
template<typename TypeInt>
std::string Itoa(const TypeInt v, int base)
{
static const char table[] = "0123456789";
string ret;
static numeric_limits<TypeInt> t;
TypeInt n = v;
if (t.is_signed) {
if (v < 0) n *= -1;
}
while (n >= base) {
ret += table[n%base];
n /= base;
}
ret += table[n];
if (t.is_signed) {
if (v < 0 && base == 10) ret += '-';
}
// 文字列の順番を逆にする
std::reverse(ret.begin(), ret.end());
return ret;
}
int main(){
int N;
scan(N);
int ans=0;
rep1(i,N){
string s1=Itoa(i,10);
string s2=Itoa(i,8);
bool is=true;
for(const auto& c:s1){
if(c=='7'){
is=false;
break;
}
}
for(const auto& c:s2){
if(c=='7'){
is=false;
break;
}
}
if(is) ans++;
}
prin(ans);
return 0;
}
|
// A - kcal
#include<bits/stdc++.h>
#define repi(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define rep(i, n) repi(i, 0, n)
#define rrepi(i, n, s) for(int i=n-1; i>=s; --i)
using namespace std;
using ll = long long;
int main(){
int a, b;
cin >> a >> b;
double v = (double)b/100;
double ans = v*a;
printf("%.15f\n", ans);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
int ar[n][m];
int min=1000;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>ar[i][j];
if(ar[i][j]<min)
min=ar[i][j];
}
}
int ctr=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(ar[i][j]>min){
ctr=ctr+(ar[i][j]-min);
}
}
}
cout<<ctr<<endl;
return 0;
} |
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
static int IN(void)
{
int x=0,f=1,c;while(c=getchar(),c<48||c>57){if(c==45)f=-f;}
while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f*x;
}
static void OUT(long x){if(x<0){putchar('-'),x=-x;}if(x>=10){OUT(x/10);}putchar(x-x/10*10+48);}
typedef struct List{int adj,v,c,d;}edge;
int hsz=0;long minHeap[200001][2],output[2];
static void PUSH(int id,long key)
{
int i=++hsz,j=i>>1;long sw[2];
minHeap[i][0]=id,minHeap[i][1]=key;
while(j)
{
if(minHeap[i][1]<minHeap[j][1])
{
sw[0]=minHeap[j][0],sw[1]=minHeap[j][1];
minHeap[j][0]=minHeap[i][0],minHeap[j][1]=minHeap[i][1];
minHeap[i][0]=sw[0],minHeap[i][1]=sw[1];
i=j;j>>=1;
}else break;
}
}
static void POP(void)
{
int i=1,j=i+1;long sw[2];
output[0]=minHeap[i][0],output[1]=minHeap[i][1];
minHeap[i][0]=minHeap[hsz][0],minHeap[i][1]=minHeap[hsz--][1];
while(j<=hsz)
{
if(j<hsz&&minHeap[j^1][1]<minHeap[j][1]){j^=1;}
if(minHeap[j][1]<minHeap[i][1])
{
sw[0]=minHeap[j][0],sw[1]=minHeap[j][1];
minHeap[j][0]=minHeap[i][0],minHeap[j][1]=minHeap[i][1];
minHeap[i][0]=sw[0],minHeap[i][1]=sw[1];
i=j;j=i<<1;
}else break;
}
return;
}
int main(void)
{
int N=IN(),M=IN(),vis[100000],esz=0,head[100000];
long dist[100000];edge e[200001];
rep(i,N){dist[i]=9e18;}
while(M--)
{
int A=IN(),B=IN(),C=IN(),D=IN();
e[++esz].adj=head[A-1];
head[A-1]=esz;
e[esz].v=B;
e[esz].c=C;
e[esz].d=D;
e[++esz].adj=head[B-1];
head[B-1]=esz;
e[esz].v=A;
e[esz].c=C;
e[esz].d=D;
}
dist[0]=0l;
PUSH(1,0l);
while(hsz)
{
POP();
long v=output[1];
if(vis[output[0]-1]){continue;}
for(int i=head[output[0]-1];i;i=e[i].adj)
{
int to=e[i].v;long len=0l;
if(e[i].d)
{
int x=sqrt(e[i].d)-1;
if(e[i].d/(x+1)>1+e[i].d/(x+2)){x++;}
if(e[i].d/(x+1)>1+e[i].d/(x+2)){x++;}
if(v>1l*x){len=1l*e[i].c+1l*e[i].d/(v+1l);}
else{len=1l*e[i].c+1l*x-v+1l*e[i].d/(1l*x+1l);}
}else{len=1l*e[i].c;}
if(dist[to-1]>v+len)
{
dist[to-1]=v+len;
PUSH(to,v+len);
}
}
vis[output[0]-1]=1;
}
if(dist[N-1]==9e18){puts("-1");}else OUT(dist[N-1]);
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(ar) ar.begin(),ar.end()
#define endl '\n'
void swap(string &y,string &z,int a,int b) {
char k;
k=y[a];
y[a]=z[b];
z[b]=k;
}
void swapin(string &y,int a,int b) {
char k;
k=y[a];
y[a]=y[b];
y[b]=k;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
string s;
cin>>s;
string y=s.substr(0,n);
string z=s.substr(n,n);
int q;
cin>>q;
int kk=0;
while(q--) {
int t,a,b;
cin>>t>>a>>b;
a--;
b--;
if(t==1) {
if(kk%2) {
if(a<n) {
if(b>=n) {
b=b-n;
swap(z,y,a,b);
}
else {
swapin(z,a,b);
}
}
else {
a=a-n;
b=b-n;
swapin(y,a,b);
}
}
else {
if(a<n) {
if(b>=n) {
b=b-n;
swap(y,z,a,b);
}
else {
swapin(y,a,b);
}
}
else {
a=a-n;
b=b-n;
swapin(z,a,b);
}
}
}
else{
kk++;
}
}
if(kk%2) {
cout<<z<<y<<endl;
}
else{
cout<<y<<z<<endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
#define nline "\n"
#define ff first
#define ss second
#define ll long long
#define pb push_back
void solve() {
int n;
cin >> n;
int sum = 0;
for (int i = 1; i <= n; ++i) {
sum += i;
if (sum >= n) {
cout << i;
break;
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// int t;
// cin >> t;
// while (t--)
solve();
}
| #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <cstdint>
#include <vector>
using namespace std;
int main(){
long long n;
cin>>n;
long long ans=0.5*(-1+sqrt(1+8*n));
if(ans*(ans+1)<2*n){
ans+=1;
}
cout<<ans;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 10e16;
int main() {
int H, W;
cin >> H >> W;
vector<string> s(H);
rep(i, H) cin >> s[i];
vector<vector<P>> G(26);
vector<bool> reached(26, false);
rep(i, H) rep(j, W) {
if (s[i][j] >= 'a' && s[i][j] <= 'z') {
G[s[i][j] - 'a'].push_back({i, j});
}
}
rep(i, H) rep(j, W) {
if (s[i][j] != 'S') continue;
vector<vector<ll>> dist(H, vector<ll>(W, INF));
queue<P> que;
que.push({i, j});
dist[i][j] = 0;
while (!que.empty()) {
int h = que.front().first;
int w = que.front().second;
que.pop();
if (s[h][w] >= 'a' && s[h][w] <= 'z' &&
reached[s[h][w] - 'a'] == false) {
for (auto p : G[s[h][w] - 'a']) {
if (p.first == h && p.second == w) continue;
if (dist[p.first][p.second] < INF) continue;
dist[p.first][p.second] = dist[h][w] + 1;
que.push({p.first, p.second});
reached[s[h][w] - 'a'] = true;
}
}
for (int direction = 0; direction < 4; direction++) {
int nh = h + dx[direction];
int nw = w + dy[direction];
if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
if (dist[nh][nw] < INF) continue;
if (s[nh][nw] == '#') continue;
dist[nh][nw] = dist[h][w] + 1;
que.push({nh, nw});
if (s[nh][nw] == 'G') {
cout << dist[h][w] + 1 << endl;
return 0;
}
}
}
cout << -1 << endl;
}
} | #include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef pair<string,int> psi;
typedef pair<int,string> pis;
typedef array<int,2> aii;
typedef array<int,3> aiii;
typedef array<int,4> aiiii;
typedef unsigned long long ull;
typedef long long int ll;
typedef array<ll,2> all;
typedef array<ll,3> alll;
typedef array<ll,4> allll;
#define pb push_back
#define ff first
#define ss second
#define MAX 300005
#define MOD 1000000007
#define INF 1e9+100
vector<int>adj[MAX];
int xMove[] = { 0,1,0,-1,1,1,-1,-1, 2, 2, -2, -2, 1, 1, -1, -1 };
int yMove[] = { 1,0,-1,0,1,-1,1,-1, 1, -1, 1, -1, 2, -2, 2, -2 };
string s[2000];
int dist[2000][2000],h,w;
vector<aii> vec[26];
int bfs(int x, int y, int dx, int dy)
{
queue<aii> q;
q.push({x,y});
memset(dist,-1,sizeof dist);
dist[x][y]=0;
int already_pushed[26]= {};
while(!q.empty())
{
auto [cx,cy]=q.front();
q.pop();
for(int i=0; i<4; i++)
{
int nx=cx+xMove[i],ny=cy+yMove[i];
if(nx>=0 and nx<h and ny>=0 and ny<w and s[nx][ny]!='#' and dist[nx][ny]==-1)
{
dist[nx][ny]=dist[cx][cy]+1;
q.push({nx,ny});
}
}
if(s[cx][cy]>=97 and s[cx][cy]<=122 and !already_pushed[s[cx][cy]-97])
{
already_pushed[s[cx][cy]-97]=1;
for(auto [nx,ny]: vec[s[cx][cy]-97])
{
if(dist[nx][ny]==-1)
{
dist[nx][ny]=dist[cx][cy]+1;
q.push({nx,ny});
}
}
}
}
return dist[dx][dy];
}
int main()
{
//freopen("input.in","r",stdin);
//freopen("output.txt","w",stdout);
cin.tie(0),cout.tie(0);
ios_base::sync_with_stdio(0);
cout.setf(ios::fixed);
cout.precision(10);
int TC=1;
int n,m,q,k;
//cin>>TC;
for(int t1=1; t1<=TC; t1++)
{
cin>>h>>w;
for(int i=0; i<h; i++)
cin>>s[i];
int sx,sy,dx,dy;
for(int i=0; i<h; i++)
{
for(int j=0; j<w; j++)
{
if(s[i][j]=='S')
sx=i,sy=j;
else if(s[i][j]=='G')
dx=i,dy=j;
else if(s[i][j]!='#' and s[i][j]!='.')
vec[s[i][j]-97].pb({i,j});
}
}
cout<<bfs(sx,sy,dx,dy)<<endl;
}
return 0;
}
|
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3fll
typedef unsigned long long ull;
typedef long long ll;
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define nep(i,r,l) for(int i=r;i>=l;i--)
void sc(int &x){scanf("%d",&x);}
void sc(int &x,int &y){scanf("%d%d",&x,&y);}
void sc(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void sc(ll &x){scanf("%lld",&x);}
void sc(ll &x,ll &y){scanf("%lld%lld",&x,&y);}
void sc(ll &x,ll &y,ll &z){scanf("%lld%lld%lld",&x,&y,&z);}
void sc(char *x){scanf("%s",x);}
void sc(char *x,char *y){scanf("%s%s",x,y);}
void sc(char *x,char *y,char *z){scanf("%s%s%s",x,y,z);}
void out(int x){printf("%d\n",x);}
void out(ll x){printf("%lld\n",x);}
void out(int x,int y){printf("%d %d\n",x,y);}
void out(ll x,ll y){printf("%lld %lld\n",x,y);}
void out(int x,int y,int z){printf("%d %d %d\n",x,y,z);}
void out(ll x,ll y,ll z){printf("%lld %lld %lld\n",x,y,z);}
using namespace std;
const int N=5e5+5,mod=3;
int n,rt,dep[N],son[N];
vector<int>e[N];
void dfs(int u,int p)
{
dep[u]=dep[p]+1;
if(dep[u]>dep[rt]) rt=u;
for(int v:e[u])
if(v!=p)
dfs(v,u);
}
void dfs2(int u,int p)
{
dep[u]=1;
for(int v:e[u])
if(v!=p)
{
dfs2(v,u);
if(dep[v]+1>dep[u])
dep[u]=dep[v]+1,son[u]=v;
}
}
int id,ans[N];
void dfs3(int u,int p)
{
ans[u]=++id;
for(int v:e[u])
if(v!=son[u]&&v!=p)
dfs3(v,u);
if(son[u]) dfs3(son[u],u);
++id;
}
int main()
{
//freopen("1.in","r",stdin);freopen("1.out","w",stdout);
sc(n);
rep(i,1,n-1)
{
int u,v;sc(u,v);
e[u].push_back(v);
e[v].push_back(u);
}
dfs(1,0);
dfs2(rt,0);
dfs3(rt,0);
rep(i,1,n)
printf(i==n?"%d\n":"%d ",ans[i]);
}
| #include<bits/stdc++.h>
// #pragma optimize("-O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,avx,mmx,tune=native")
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1e9
//#define BIG_INF 1e18
#define vi vector<ll>
#define sz(a) ll((a).size())
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1)
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// typedef tree<
// ll,
// null_type,
// less<ll>,
// rb_tree_tag,
// tree_order_statistics_node_update>
// ordered_set;
typedef long long ll;
const ll BIG_INF = 4e18;
const ll mod = 1e9 + 7;
ll fast_exp(ll a, ll b)
{
if(b <= 0)
return 1;
else
{
ll res = 1;
res = fast_exp(a,b/2);
res = (res*res)%mod;
if(b%2 == 1)
res = (res*a)%mod;
return res;
}
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long true_rand(long long n) {
// Returns a random number between 0 and n - 1 inclusive using mt19937.
uniform_int_distribution<long long> uid(0, n - 1);
return uid(rng);
}
typedef double ld;
const long long N = 2e5+1000;
const long double pi = acos(-1.0);
using cd = complex<double>;
const double PI = acos(-1);
ld eps = 1e-12;
int vis[N] = {};
vector <int> edge[N];
int farthest = 1, dist = 0;
int dia_2;
void dfs(int v, int cur_dist)
{
vis[v] = 1;
if(cur_dist > dist)
{
farthest = v;
dist = cur_dist;
}
for(auto e: edge[v])
{
if(vis[e] == 0)
{
dfs(e,cur_dist+1);
}
}
}
int col[N] = {};
void color(int v)
{
vis[v] = 1;
if(v == dia_2)
col[v] =1;
for(auto e: edge[v])
{
if(vis[e] == 0)
{
color(e);
col[v] = max(col[v],col[e]);
}
}
}
int global_num = 1;
int final_num[N] = {};
void final_dfs(int v)
{
vis[v] = 1;
final_num[v] = global_num;
for(auto e: edge[v])
{
if(vis[e] == 0 && col[e] == 0)
{
global_num++;
final_dfs(e);
global_num++;
}
}
for(auto e: edge[v])
{
if(vis[e] == 0 && col[e] == 1)
{
global_num++;
final_dfs(e);
global_num++;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
//freopen("c.txt","r",stdin);
// freopen("input.txt", "w", stdout);
int n;
cin >> n;
int u, v;
for(int i = 0; i < n-1; i++)
{
cin >> u >> v;
edge[u].pb(v);
edge[v].pb(u);
}
dfs(1,0);
int dia_1 = farthest;
int dia_1_dist = dist;
farthest = dia_1;
dist = 0;
for(int i = 1; i<=n; i++)
vis[i] = 0;
dfs(dia_1,0);
dia_2 = farthest;
for(int i = 1; i<=n; i++)
vis[i] = 0;
color(dia_1);
for(int i = 1; i<=n; i++)
vis[i] = 0;
final_dfs(dia_1);
for(int i = 1; i <= n; i++)
cout << final_num[i] << " ";
cout << '\n';
// cout << "Case #" << cs++ << ": " << ans << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
double X,Y,Z,A,G;
cin >> X >> Y >> Z;
G=Y/X;
double i=0;
while(i/Z<G){
A=i;
i++;
}
cout << A <<endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define BIG 2000005
ll M = 998244353;
int main() {
ll A, B, C;
cin >> A >> B >> C;
ll ans = A * (A+1) / 2 % M;
ans = (ans * (B * (B+1) / 2 % M)) % M;
ans = (ans * (C * (C+1) / 2 % M)) % M;
cout << ans << endl;
return 0;
} |
//#define _GLIBCXX_DEBUG
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, 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 1; } return 0; }
const int INF = 1000000000;
//参照: http://satanic0258.hatenablog.com/entry/2016/04/29/004730
ll Pow(ll N, ll P){
ll re = 1;
for(ll i=0; i<P; ++i){
re *= N;
}
return re;
}
int ans = INF;
void dfs(vector<int>& A, vector<ll> digits){
int ret =0;
if (A.size() == digits.size()){
for (int i=0; i<digits.size(); i++){
if (A[i] == 1){
digits[i] = 0;
ret++;
}
}
int digsum =0;
for (int i=0; i<digits.size(); i++){
digsum += digits[i];
digsum %= 3;
}
if (digsum%3 == 0 and A != vector<int>(digits.size(),1))chmin(ans,ret);
return;
}
for (int v=0; v<2; v++){
A.push_back(v);
dfs(A, digits);
A.pop_back();
}
}
int main() {
IOS;
ll N;
cin >> N;
ll digit_len = 1;
ll nd = N;
while (nd > 10){
nd /= 10;
digit_len++;
}
vector<ll>digits(digit_len);
for (int i=0; i<digit_len; i++){
if (i==0)digits[i] = (N % Pow(10,i+1));
else digits[i] = ((N % Pow(10,i+1)) - digits[i-1]) / Pow(10,i);
}
ll digit_sum = 0;
for (int i=0; i<digit_len; i++){
digits[i] %= 3;
digit_sum += digits[i];
digit_sum %= 3;
}
if (digit_sum == 0){
cout << 0 << endl;
return 0;
}
vector<int>Hoge;
dfs(Hoge, digits);
if (ans != INF) cout << ans << endl;
else cout << -1 << endl;
} | #include <bits/stdc++.h>
#define fi first
#define se second
#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)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
// Unionfind
struct uf{
vi d;
uf() {};
uf(int mx) : d(mx,-1) {};
int root(int x){
if(d[x]<0) return x;
return d[x] = root(d[x]);
}
bool unite(int x, int y){
x = root(x); y = root(y);
if(x == y) return false;
if(d[x] > d[y]) swap(x,y);
d[x] += d[y]; d[y] = x;
return true;
}
bool same(int x, int y) { return root(x) == root(y);}
int size(int x){ return -d[root(x)];}
int operator[] (int x) {return root(x);}
int operator() (int x) {return size(x);}
};
int main() {
int n, q; cin >> n >> q;
vi c(n);
rep(i,n) cin >> c[i], --c[i];
vector<set<int> > s(n); // 1次元目が根の2次元目にその根がどのような種類のクラスを保持しているか
vector<map<int,int> > m(n); // 1次元目が根の2次元目で各クラスに何人いるかを保持
rep(i,n){
s[i].insert(c[i]);
m[i][c[i]] = 1;
}
uf dis(n);
vi ans;
rep(_,q){
int qi; cin >> qi;
if(qi == 1){
int a,b; cin >> a >> b; --a,--b;
if(dis.same(a,b)) continue;
if(dis.size(a) < dis.size(b)) swap(a,b);
int ra = dis.root(a), rb = dis.root(b);
for(int clsb : s[rb]){
if(s[ra].count(clsb)) m[ra][clsb] += m[rb][clsb];
else s[ra].insert(clsb), m[ra][clsb] = m[rb][clsb];
}
// printf("ra: %d m[ra][1]: %d\n", ra, m[ra][1]);
dis.unite(a,b);
}else{
int x,y; cin >> x >> y; --x,--y;
ans.push_back(m[dis.root(x)][y]);
}
}
for(int res: ans) cout << res << endl;
return 0;
}
|
/*
Author : MatsuTaku
Date : 01/30/21
*/
#include <bits/stdc++.h>
using namespace std;
#include <x86intrin.h>
#ifndef ONLINE_JUDGE
#define Assert(cond) assert(cond)
#else
#define Assert(cond)
#endif
#define rep(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; i++)
using lint = long long int;
template<typename T>
using vvec = vector<vector<T>>;
template<typename T>
vvec<T> make_vvec(int n, int m, T v) { return vvec<T>(n, vector<T>(m, v)); }
template<typename T>
void chmax(T& dst, T x) { dst = max(dst, x); }
template<typename T>
void chmin(T& dst, T x) { dst = min(dst, x); }
class Solver {
public:
Solver();
void solve();
};
Solver::Solver() {}
void Solver::solve() {
int n,m; cin>>n>>m;
vector<pair<int,int>> AB(m);
rep(i, m) {
int a,b; cin>>a>>b; a--; b--;
AB[i] = {a,b};
}
int k; cin>>k;
vector<pair<int,int>> CD(k);
rep(i, k) {
int c,d; cin>>c>>d; c--; d--;
CD[i] = {c,d};
}
int ans = 0;
rep(mask, 1<<k) {
vector<int> C(n);
rep(i, k) {
if (mask&(1<<i)) {
C[CD[i].first]++;
} else {
C[CD[i].second]++;
}
}
int sat = 0;
for (auto [a,b] : AB) {
if (C[a] > 0 and C[b] > 0)
sat++;
}
chmax(ans, sat);
}
cout << ans << endl;
}
int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
cout<<fixed<<setprecision(10);
Solver solver;
int t = 1;
// cin>>t;
while (t--) {
solver.solve();
}
return 0;
}
| #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back
#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
//const int mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
VL dx={1,0,-1,0};
VL dy={0,1,0,-1};
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
vector<VL> adj;
VL visit2,lefti,righti;
int comp;
ll a,b;
void dfs(int v)
{
a+=lefti[v];
b+=righti[v];
visit2[v]=1;
for(auto to:adj[v])
{
if(visit2[to]==0)
{
dfs(to);
}
}
return;
}
void solve()
{
ll n,m;
cin>>n>>m;
lefti.assign(n,0);
righti.assign(n,0);
fr(i,0,n)
{
cin>>lefti[i];
}
fr(j,0,n)
{
cin>>righti[j];
}
comp=0;
bool ans=true;
adj.assign(n,VL());
visit2.assign(n,0);
fr(i,0,m)
{
ll x,y;
cin>>x>>y;
x--,y--;
adj[x].pb(y);
adj[y].pb(x);
}
fr(i,0,n)
{
if(visit2[i]==0)
{
a=0;b=0;
dfs(i);
if(a!=b)
{
ans=false;
}
}
}
// ll ans=true;
if(a!=b)
{
ans=false;
}
fr(i,0,n)
{
if(visit2[i]==0)
{
ans=false;
}
}
if(ans)
cout<<"Yes\n";
else
cout<<"No\n";
return;
}
int main()
{
IOS;
ll t=1,pp;
//cin>>t;
pp=t;
while(t--)
{
//cout<<"Case #"<<pp-t<<": ";
solve();
}
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
* BE CAREFUL REGARDING THE DEFAULT VALUES IN segement trees etc
* BE very careful in int vs long long vs unsigned long long
*/
/*
recursion - matrix exponential
*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithmQ |
#include <bits/stdc++.h>
#define nmax 100010
#define fi first
#define se second
#define ll long long
#define mp make_pair
const int oo=1e9+7;
using namespace std;
int n,a[nmax];
pair<ll,ll> f[nmax][3][2];
pair<ll,ll> operator +=(pair<ll,ll> &x,pair<ll,ll> y)
{
x.fi+=y.fi; x.se+=y.se;
x.fi%=oo; x.se%=oo;
if (x.fi<0) x.fi+=oo;
if (x.se<0) x.se+=oo;
return x;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n;
for (int i=1;i<=n;++i) cin>>a[i];
f[1][0][0]={a[1],1};
for (int i=1;i<=n;++i)
{
ll x,y;
x=f[i][0][0].fi; y=f[i][0][0].se;
f[i+1][0][0]+={x+y*a[i+1],y};
f[i+1][1][0]+={x-y*a[i+1],y};
x=f[i][0][1].fi; y=f[i][0][1].se;
f[i+1][0][1]+={x+y*a[i+1],y};
f[i+1][1][1]+={x-y*a[i+1],y};
x=f[i][1][0].fi; y=f[i][1][0].se;
f[i+1][0][0]+={x+y*a[i+1],y};
f[i+1][2][1]+={x-y*a[i+1],y};
x=f[i][1][1].fi; y=f[i][1][1].se;
f[i+1][0][1]+={x+y*a[i+1],y};
f[i+1][2][1]+={x-y*a[i+1],y};
x=f[i][2][1].fi; y=f[i][2][1].se;
f[i+1][0][1]+={x+y*a[i+1],y};
f[i+1][2][1]+={x-y*a[i+1],y};
}
cout<<(f[n][0][0].fi+f[n][1][0].fi)%oo;
return 0;
}
| /**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀
**/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define ld double
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define F(i,a,b) for(i=a;i<b;i++)
//#include <ext/pb_ds/assoc_container.hpp> // policy based data structure header files
//#include <ext/pb_ds/tree_policy.hpp> // policy based data structure header files
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
//using namespace __gnu_pbds; // for pbds
//#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> // have functions like order_of_key, find_by_order
const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781641;
const ll M=1e9+7;
const ll MAXN=100200;
ll i,j,mask;
ll mod(ll x)
{
return (x+M)%M;
}
ll add(ll a,ll b)
{
return mod(mod(a)+mod(b));
}
ll mul(ll a,ll b)
{
return mod(mod(a)*mod(b));
}
ll power(ll p,ll x)
{
ll res=1;
while(x>0) {
if(x%2==1) {
res=mul(res,p);
}
x/=2;
p=mul(p,p);
}
return res;
}
void solve()
{
ll n;
cin>>n;
ll sumMinus=0, sumPlus=0;
vector<ll> v(n);
F(i,0,n) {
cin>>v[i];
}
if(n==1) {
cout<<v[0];
} else {
sumMinus=add(v[0], -v[1]);
sumPlus=add(v[0], v[1]);
ll cntPlus=1;
ll cntMinus=1;
F(i,2,n) {
ll mn=add(sumPlus, mul(-1,mul(v[i], cntPlus)) );
ll mx=add(sumPlus, mul(cntPlus, v[i]) );
mx=add(mx, add(sumMinus, mul(cntMinus, v[i]) ));
sumMinus=mn;
sumPlus=mx;
ll tmp=cntPlus;
cntPlus=add(cntPlus, cntMinus);
cntMinus=tmp;
//cout<<sumMinus<<" "<<sumPlus;nl
}
// nl
// cout<<sumMinus<<" "<<sumPlus;nl
ll ans=add(sumMinus, sumPlus);
cout<<ans;
}
}
int main()
{
IOS
/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE*/
ll t,test=1;
//cin>>test;
F(t,1,test+1) {
//cout<<"Case #"<<t<<": ";
solve();
nl
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.