code_file1
stringlengths 87
4k
| code_file2
stringlengths 85
4k
|
---|---|
#include <iostream>
using namespace std;
int main(void){
// Your code here!
int N,A,B;
cin >> N >> A >> B;
cout << N-A+B << endl;
}
| #include <bits/stdc++.h>
// 1. bs
#define int long long
#define cf(i, a, b) for(int i=a;i<=b;i++)
#define cb(i, a, b) for(int i=a;i<=b;i--)
#define gcd __gcd
#define endl "\n"
#define pb emplace_back
#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 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(NULL)
#define PI 3.141592653589793238
using namespace std;
int32_t main() {
nitin;
int n,a,b;
cin>>n>>a>>b;
cout<<n-a+b<<endl;
return 0;
} |
// Created by Amal P Mathews
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,n) for(ll i=0;i<n;i++)
#define tc() ll t;cin>>t;while(t--)
#define rem 1e9+7
#define pb(v,i) v.push_back(i)
#define vll vector<ll>
#define Arin(a,n) loop(i,n)cin>>a[i];
#define Arout(a,n) loop(i,n)cout<<a[i]<<" ";cout<<endl;
#define ArSize(a) sizeof(a)/sizeof(a[0]);
void start()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("/home/amal/Desktop/programming/c++/practise/input_cpp.txt","r",stdin);
freopen("/home/amal/Desktop/programming/c++/practise/error_cpp.txt", "w", stderr);
freopen("/home/amal/Desktop/programming/c++/practise/output_cpp.txt", "w", stdout);
#endif
}
void solve()
{
ll n;
cin>>n;
for(ll i=1;;i++)
{
if(stoll(to_string(i)+to_string(i))>n)
{
cout<<i-1;
break;
}
}
}
int main()
{
start();
int t = 1;
/*is Single Test case?*/
// cin >> t;
while (t--) {
solve();
}
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using comp = complex<double>;
const long double PI = acosl(-1.0);
int main(void) {
int n;
cin >> n;
double p, q, r, s;
comp a, b, c, d, ans;
cin >> p >> q;
cin >> r >> s;
a = p + q * 1i;
b = r + s * 1i;
c = (a + b) / 2.0;
double t = 2.0 * PI / n;
d = cos(t) + sin(t) * 1i;
ans = d * (a - c) + c;
printf("%.9lf %.9lf\n", ans.real(), ans.imag());
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;
#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back
int main()
{
ll N;
cin >> N;
vec x(N), y(N);
REP(i,0,N) cin >> x[i] >> y[i];
ll cnt = 0;
REP(i,0,N-1) {
REP(j,i+1,N) cnt += (abs(y[i]-y[j]) <= abs(x[i]-x[j]));
}
PR(cnt);
return 0;
}
/*
*/ | #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<deque>
#include<list>
#include<bitset>
#include<sstream>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
#define endl "\n"
using Graph = vector<vector<int>>;
int main(){
ll a,b,c;
cin>>a>>b>>c;
if(c%2==0){
if(abs(a)<abs(b))cout<<"<"<<endl;
else if(abs(a)>abs(b))cout<<">"<<endl;
else if(abs(a)==abs(b))cout<<"="<<endl;
}
else{
if(a<b)cout<<"<"<<endl;
else if(a>b)cout<<">"<<endl;
else if(a==b)cout<<"="<<endl;
}
} |
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
long long N;
cin >> N;
int cont = 0;
int i = 1;
long long M = 11;
while(M <= N)
{
cont++;
i++;
int dig = to_string(i).length();
M = i * pow(10, dig) + i;
}
cout << cont << endl;
return 0;
} | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define int long long
#define INF 1e9
#define endl "\n"
#define pi 2*acos(0.0)//M_PI in cmath lib
#define sp(x) setprecision(x)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define L length()
const int32_t N=25;
int find(int a,vector<int>&link){
int x=a;
while(link[x]!=x){
x = link[x];
}
return x;
}
void unite(int a,int b,vector<int>&link,vector<int>&size){
a = find(a,link);
b = find(b,link);
if(size[a]<size[b])
swap(a,b);
size[a] += size[b];
link[b]=a;
}
int gcd(int a, int b){
if(b==0)return a;
return gcd(b, a%b);
}
std::vector<int> seive(int n){
std::vector<int> v(n+1,0);
std::vector<int> p;
for(int i=2;i*i<=n;i++){
if(v[i]==0){
p.pb(i);
for(int j=i;j<=n;j+=i)v[i]=1;
}
}
return p;
}
bool cmp(pair<pair<int,int>,int> a, pair<pair<int,int>,int> b){
return a.F.F<b.F.F;
}
bool pal(string s){
int i=0,j=s.length()-1;
while(i<j){
if(s[i]!=s[j])return false;
i++,j--;
}
return true;
}
void solve(){
int n;cin>>n;
if(n==0){cout<<"Yes";return;}
int z=0;
int t=n;
int r=t%10;
while(r==0 && t>0){
z++;
t/=10;
r=t%10;
}
string s="";
while(z--)s+='0';
s+=to_string(n);
if(pal(s))cout<<"Yes";
else cout<<"No";
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r" , stdin);
freopen("outit.txt", "w", stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<endl;
}
} |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define repn(i,n) for(int i=1;i<=n;++i)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
using namespace std;
const LL MOD=1e9+7;
int n,cnt,ans=0;
vector <int> g[400010];
bool vis[400010],cyc;
void dfs(int pos,int par)
{
vis[pos]=true;
cnt++;
bool bk=false;
rep(i,g[pos].size())
{
if(g[pos][i]==par&& !bk)
{
bk=true;
continue;
}
if(vis[g[pos][i]]) cyc=true;
else dfs(g[pos][i],pos);
}
}
int main()
{
cin>>n;
int x,y;
rep(i,n)
{
scanf("%d%d",&x,&y);
g[x].pb(y);g[y].pb(x);
}
repn(i,400000)
{
if(vis[i]) continue;
cyc=false;cnt=0;
dfs(i,0);
ans+=cnt-1+(int)cyc;
}
cout<<ans<<endl;
return 0;
} | #include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
ll n,m;cin>>n>>m;
vector<string> s;
ll odd=0,even=0;
for(ll i=0;i<n;i++){
string str;cin>>str;
ll ct=0;
for(ll j=0;j<m;j++){
if(str[j]=='1'){
ct++;
}
}
ct%2?odd++:even++;
}
cout<<odd*even<<endl;
} |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
#define fi first
#define se second
using namespace std;
int T,n,x;
map<int,int> mp;
int main(){
scanf("%d",&T);
while(T--){
scanf("%d",&n);mp.clear();
rep(i,1,n) scanf("%d",&x),mp[x]++;
if(n&1){puts("Second");continue;}
bool fl=0;
for(auto &x:mp) if(x.se&1){fl=1;break;}
if(fl) puts("First");
else puts("Second");
}
return 0;
} | #include <stdio.h>
#include <algorithm>
#include <vector>
#define MN 100000
int n;
std::vector<int> e[MN+5];
void add(int u,int v){
e[u].push_back(v);
}
struct state{
int c,f,s;
}s[MN+5];
void dfs(int u){
s[u].c = 1;
s[u].f = 1;
s[u].s = 0;
std::vector<int> ve[2];
for(auto v:e[u]){
dfs(v);
s[u].c += s[v].c;
if(s[v].c&1){
ve[1].push_back(v);
}else{
if(s[v].s>=s[v].f){
s[u].s += s[v].s;
s[u].f += s[v].f;
}else{
ve[0].push_back(v);
}
}
}
std::sort(ve[1].begin(),ve[1].end(),[](int a,int b)->bool{
return s[a].s-s[a].f>s[b].s-s[b].f;
});
for(int i=0;i<(int)ve[1].size();i++){
int v = ve[1][i];
if(i&1){
s[u].f += s[v].s;
s[u].s += s[v].f;
}else{
s[u].s += s[v].s;
s[u].f += s[v].f;
}
}
if(ve[1].size()&1){
for(auto v:ve[0]){
s[u].f += s[v].s;
s[u].s += s[v].f;
}
}else{
for(auto v:ve[0]){
s[u].s += s[v].s;
s[u].f += s[v].f;
}
}
}
int main(){
scanf("%d",&n);
for(int i=2,f;i<=n;i++){
scanf("%d",&f);
add(f,i);
}
dfs(1);
printf("%d\n",s[1].f);
} |
#include "bits/stdc++.h"
#define ll long long int
#define MOD 1000000007
#define oo 1000000000000000000
#define forr(i,n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define mem(a,v) memset(a,v,sizeof(a))
#define pb push_back
#define popcount(x) __builtin_popcount(x)
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
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);
}
};
ll add(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a+b + p)%p;}
ll mul(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a*b + p)%p;} // __int128
ll power(ll x,ll n,ll p=MOD){ if(x==0) return 0; if(n==0 || x==1) return 1LL;
ll r = (power(x,n/2,p))%p; if(n&1) return mul(mul(r,r,p) , x,p); else return mul(r,r,p);
}
ll inv(ll x){return power(x,MOD-2);}
pair<int,int> dx[4] = { { -1,0 } , {1,0} , {0,-1} , {0,1} };
// Now we can simply define our unordered_map or our gp_hash_table as follows:
// unordered_map<long long, int, custom_hash> safe_map;
// gp_hash_table<long long, int, custom_hash> safe_hash_table;
/* ------------------------------------------ Code ----------------------------------------------- */
ll dp[1010][1010];
ll ncr(ll n, ll r){
if(r==0) return 1;
if(n<r) return 0;
if(n==r) return 1;
if(dp[n][r]!=-1) return dp[n][r];
return dp[n][r] = ncr(n-1,r-1) + ncr(n-1,r);
}
void __sol(){
mem(dp,-1);
int n; cin>> n;
cout << ncr(n-1,11);
return;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
fastio
ll tc=1; // cin >> tc;
while(tc--) __sol();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned long long int ulli;
void fast_io(){
ios_base::sync_with_stdio(0);
cin.tie(0);
}
int main(){
fast_io();
//code starts here
double n;
cin >> n;
n *= double(1.08);
int N = n;
if(N<206){
cout << "Yay!" << endl;
} else if(N>206){
cout << ":(" << endl;
} else {
cout << "so-so" << endl;
}
return 0;
}
|
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// find_by_order(k) returns the iterator to the kth largest element (start from 0)
// order_of_key(k) returns the number of elements in the set which are strictly less than the value k
using namespace std;
using namespace __gnu_pbds;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define int long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define mem(dp,x) memset(dp,x,sizeof dp);
#define mii map<int,int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define rightmostbit(x) __builtin_ffsll(x)
#define mod 1000000007
#define inf 1e18
#define pi 3.141592653589793238
#define mk(a,n) int n;cin>>n;vi a(n);for(int i=0;i<n;i++) cin>>a[i]
#define w(x) int x; cin>>x; while(x--)
#define deb(...) cerr << "[" << #__VA_ARGS__ << "]: "; cerr << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template<typename T> int SIZE(const T &t) { return t.size(); } string to_string(const string s, int x1 = 0, int x2 = 1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c) { return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1 = 0, int x2 = 1e9) { string t = ""; for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1); __iii__ <= __jjj__; ++__iii__) { t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += "\n"; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2 - x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if (e != l) { if (rnk > 1) { res += "\n"; t_a_b_s = l_v_l_v_l; }; } else { t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if (l_v_l_v_l == 0) res += "\n"; return res; } void dbgm() {;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T) { cerr << to_string(H) << " | "; dbgm(T...); }
#define debm(...) cerr << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cerr << endl
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void g_b()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
}
int32_t main()
{
g_b();
int n, w; cin >> n >> w;
cout << n / w;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<string> VS;
typedef vector<P> VP;
typedef vector<V> VV;
typedef map<ll, ll> MP;
typedef multimap<ll, ll> MMP;
typedef set<ll> SET;
typedef multiset<ll> MSET;
#define loop(i,n) for(ll i = 0; i < n; i++)
#define loopr(i,x,y) for(ll i = x; i < y; i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define deb(x) cout << #x << "=" << x << endl
#define endl '\n'
#define PI 3.1415926535897932384626
#define MOD 1000000007
const int N = 200005;
vector<int> edges[N];
vector<int> st(N), en(N), dist[N];
int tmp = 0;
void dfs(int v, int len) {
st[v] = tmp++;
dist[len].pb(st[v]);
for (auto it : edges[v]) {
dfs(it, len + 1);
}
en[v] = tmp;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for (int i = 2; i <= n; i++) {
int val;
cin>>val;
edges[val].pb(i);
}
dfs(1, 0);
int q;
cin>>q;
while (q--) {
int a, b;
cin>>a>>b;
int l = st[a];
int r = en[a];
vector<int> vect = dist[b];
int res = lower_bound(all(vect), r) - lower_bound(all(vect), l);
cout<<res<<endl;
}
} |
#include "bits/stdc++.h"
using namespace std;
const int N = 2e5 + 5;
char s[N], x[N];
int dp[N][7];
int n;
int solve (int pos, int rem) {
if (pos == n) {
return rem == 0;
}
int &ret = dp[pos][rem];
if (ret != -1) {
return ret;
}
ret = 1;
int dig = s[pos] - '0';
int hi = solve(pos + 1, (10 * rem + dig) % 7);
int bi = solve(pos + 1, (10 * rem) % 7);
if (x[pos] == 'A') {
ret = 1;
if (hi == 0 || bi == 0) {
ret = 0;
}
} else {
ret = 0;
if (hi == 1 || bi == 1) {
ret = 1;
}
}
return ret;
}
int main() {
scanf("%d", &n);
scanf("%s", s);
scanf("%s", x);
memset(dp, -1, sizeof dp);
int lol = solve(0, 0);
lol ? puts("Takahashi") : puts("Aoki");
return 0;
}
| #include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
string s, x;
cin >> s >> x;
bool b[7]{0};
b[0] = true;
for(int i = n - 1; i > 0; i--){
bool c[7];
if(x[i] == 'T'){
for(int j = 0; j < 7; j++){
c[j] = false;
for(int k = 0; k < 7; k++){
if(!b[k]) continue;
if((j * 10 + s[i] - '0' - k) % 7 == 0) c[j] = true;
if((j * 10 - k) % 7 == 0) c[j] = true;
}
}
}
else{
for(int j = 0; j < 7; j++){
c[j] = true;
for(int k = 0; k < 7; k++){
if(b[k]) continue;
if((j * 10 + s[i] - '0' - k) % 7 == 0) c[j] = false;
if((j * 10 - k) % 7 == 0) c[j] = false;
}
}
}
swap(b, c);
}
if(x[0] == 'T'){
if(b[0] || b[s[0] - '0']) cout << "Takahashi" << endl;
else cout << "Aoki" << endl;
}
else{
if(!b[0] || !b[s[0] - '0']) cout << "Aoki" << endl;
else cout << "Takahashi" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
int n; cin >> n;
vector<vector<int>> dp(n + 1, vector<int> (13, 0));
dp[0][0] = 1;
for(int j = 1; j <= n; j ++) {
for(int i = 1; i <= 12; i ++) {
if(i > j)
continue;
else if(i == j)
dp[i][j] = 1;
else {
for(int k = 1; k <= j; k ++)
dp[j][i] += dp[j - k][i - 1];
}
}
}
// for(int i = 1; i <= n; i ++) {
// for(int j = 1; j <= 12; j ++)
// cout << dp[i][j] << ' ';
// cout << endl;
// }
cout << dp[n][12] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define pb push_back
#define str string
#define mp make_pair
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define REP(i, n) for(int i = 0; i < (int)n; ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double PI = acos(-1.0);
const int MAXN = (int)3e5 + 7;
void solve(){
str s; cin >> s;
cout << s.substr(1) << s[0];
}
int main(){
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
solve();
return 0;
} |
// Problem: A - kcal
// Contest: AtCoder - AtCoder Beginner Contest 205
// URL: https://atcoder.jp/contests/abc205/tasks/abc205_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
#define Jai_shri_Ram ios_base::sync_with_stdio(false), cin.tie(NULL);
//#define int long long int
#define rep(x,a,b) for(int x=a;x<b;x++)
#define deb(x) cout<< #x <<" = "<<x<<endl;
void solve(){
int a , b ;
cin >> a >> b ;
double ans = 0.0 ;
ans = (1.0 * a * b) / 100 ;
cout << ans << endl ;
}
signed main(){
Jai_shri_Ram
solve();
} | #include <bits/stdc++.h>
using namespace std;
int main() {
double A = 0, B = 0;
cin >> A >> B;
if (A==0 || B==0) {
cout << 0 << endl;
return 0;
}
cout << (B / 100) * A << endl;
} |
#include<bits/stdc++.h>
#define ff first
#define ss second
#define ld long double
#define ll long long int
#define mod 1000000007
#define vll vector<ll>
#define pll pair<ll, ll>
#define uom unordered_map
#define uos unordered_set
#define mxh priority_queue<ll>
#define ull unsigned long long
#define INF 9223372036854775807
#define mnh priority_queue<ll, vector<ll>, greater<ll>>
#define endl "\n"
#define w(t) ll tests; cin>>tests; while(tests--)
#define pb(x) push_back(x)
#define ppb() pop_back()
#define all(x) x.begin(), x.end()
#define mp(a, b) make_pair(a, b)
#define setp(x, y) fixed << setprecision(x) << y
#define f(i, a, b) for(ll i = a ; i < b ; i++)
#define fo(j, a, b) for(ll j = a ; j >= b ; j--)
#define fill(a, n, x) f(i, 0, n) a[i]=x;
using namespace std;
void init() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main() {
init();
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll a, b;
cin >> a >> b;
ld c = b * 1.0 / 100;
cout << a*c;
return 0;
} | #include "bits/stdc++.h"
using namespace std;
int main(){
cout << fixed << setprecision(15);
double a,b;cin >> a >> b;
double ans = a/100.0*b;
cout << ans << endl;
} |
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<bool> vb;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()
template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}
constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);
void solve() {
vll a(4);
rep(i, 4) cin >> a[i];
ll ans = 1000;
rep(i, 4) chmin(ans, a[i]);
cout << ans << endl;
return;
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
} | #include<bits/stdc++.h>
using namespace std;
#define endl "\n";
typedef long long ll;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
ll n,s=0,ma=0;
cin>>n;
double a[n],sum=0;
for(int i=0;i<n;i++){
cin>>a[i];
ll k=abs(a[i]);
ma=max(ma,k);
s+=abs(a[i]);
sum+=a[i]*a[i];
}
printf("%lld\n",s);
printf("%0.16f\n",sqrt(sum));
printf("%lld\n",ma);
}
|
/**
* Author : Tanbin_Hasan
* Created : 15.11.2020
**/
#include <bits/stdc++.h>
using namespace std ;
typedef int_fast64_t ll ;
typedef uint_fast64_t ull ;
double pi = acos(-1.0) ;
double eps = 1e-9 ;
ll L = 31250001 ;
const ll md = 1e9 + 7 ;
#define pb push_back
#define SP(x) cout << fixed << setprecision(x)
vector <ll> check ;
#define on(x) (check[x >> 6] & (1LL << (x & 63)))
#define set1(x) check[x >> 6] |= (1LL << (x & 63))
int main(void)
{
ios_base::sync_with_stdio(false) ; cin.tie(nullptr) ; cout.tie(nullptr) ;
#ifdef FILE_IO
#define FILE_IO
freopen("input.txt" , "r" , stdin) ; freopen("output.txt" , "w" , stdout) ;
#endif
ll n ; cin >> n ;
cout << ((n < 0) ? 0 : n) << '\n' ;
return 0 ;
}
| /**
* author : madhav
* handle : madhav10
**/
#include <bits/stdc++.h>
using namespace std;
#define For(start,end,inc) for( int i=(start);i<(end);i+=inc)
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
bool isPalindrome(string s){
int n=s.length();
for(int i=0;i<n/2;i++){
if(s[i]!=s[n-i-1]){
return false;
}
}
return true;
}
template <typename T ,typename U>
T max_self(T a,U b){
if(b>a){
a=b;
}
return a;
}
template <typename T ,typename U>
T min_self(T a,U b){
if(b<a){
a=b;
}
return a;
}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vli;
typedef pair<int,int> ii;
typedef pair<ll, ll> lii;
void solve(){
string s;
cin>>s;
int n=s.length();
int i=0,j=n-1;
while(i<n && s[i]=='0'){
i++;
}
while(j>=0 && s[j]=='0'){
j--;
}
if(i>j){
cout<<"Yes\n";
return;
}
int range=j-i+1;
bool ok=true;
for(int k=0;k<range/2;k++){
//cout<<k+i<<" "<<i+range-k<<"\n";
if(s[k+i]!=s[i+range-k-1]){
ok=false;
}
}
cout<<(ok?"Yes":"No")<<"\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt=1;
//cin>>tt;
while(tt--){
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
#define int ll
#define double long double
#define rbtree __gnu_pbds::tree<int,__gnu_pbds::null_type,less<int>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define pb push_back
#define ALL(X) X.begin(),X.end()
#define F(i,n) FF(i,0,n)
#define F1(i,n) FF(i,1,n+1)
#define FF(i,n,m) for(int i=(int)n;i<(int)m;++i)
#ifndef LOCAL
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#else
#endif // LOCOL
//#define mp make_pair
using namespace std;
//using namespace __gnu_pbds;
template<typename T> bool remax(T& a, const T& b) {return b>a?a=b,1:0;}
template<typename T> bool remin(T& a, const T& b) {return b<a?a=b,1:0;}
inline ostream& operator << (ostream& os,__int128_t a){if(a==0) {return (os<<'0');}bool flag=0;if(a<0) {a=-a,flag=1;}string s;while(a){s+=a%10+'0';a/=10;}s+=flag?"-":"";reverse(ALL(s));return os<<s;}
inline istream& operator >>(istream& is,__int128_t& a){string s;cin>>s;a=0;for(auto c:s) a=a*__int128_t(10)+__int128_t(c-'0');return is;}
template<typename T,typename P> inline ostream& operator << (ostream& os,pair<T,P> a){os<<a.first<<" "<<a.second; return os;}
template<typename T,typename P> inline istream& operator >> (istream& is,pair<T,P> &a){is>>a.first>>a.second; return is;}
using ll=long long;
using ull=unsigned long long;
using int128= __int128_t;
using uint128= __uint128_t;
using pii =pair<int,int>;
const double pi=acos(-1);
const int N=5000+5;
const ll M=1000000000;
const ll INF_64=0x3f3f3f3f3f3f3f3f;
const int INF_32=0x3f3f3f3f;
const int16_t INF_16=0x3f3f;
const int klog=20;
const int mod=998244353;//1E9+7
const double eps=1E-8;
void gen(){
}
void sol(){
int a[3];
cin>>a[0]>>a[1]>>a[2];
sort(a,a+3);
if(a[0]==a[1])
cout<<a[2]<<"\n";
else if(a[1]==a[2])
cout<<a[0]<<"\n";
else cout<<"0\n";
}
int32_t main(){
#ifdef LOCAL
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
#endif // LOCAL
IOS;
int t=1;
gen();
//cin>>t;
FF(i,1,t+1){
//cout<<"Case #"<<i<<": ";
sol();
}
}
| #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>
using namespace std;
//using namespace atcoder;
#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[";
REP(i, SZ(v)) {
if (i) os << ", ";
os << v[i];
}
return os << "]";
}
template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "(" << p.first << " " << p.second << ")";
}
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;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;
// edit
template<int m>
struct mint {
int x;
mint(ll x = 0) : x(((x % m) + m) % m) {}
mint operator-() const { return x ? m - x : 0; }
mint &operator+=(mint r) {
if ((x += r.x) >= m) x -= m;
return *this;
}
mint &operator-=(mint r) {
if ((x -= r.x) < 0) x += m;
return *this;
}
mint &operator*=(mint r) {
x = ((ll) x * r.x) % m;
return *this;
}
mint inv() const { return pow(m - 2); }
mint &operator/=(mint r) { return *this *= r.inv(); }
friend mint operator+(mint l, mint r) { return l += r; }
friend mint operator-(mint l, mint r) { return l -= r; }
friend mint operator*(mint l, mint r) { return l *= r; }
friend mint operator/(mint l, mint r) { return l /= r; }
mint pow(ll n) const {
mint ret = 1, tmp = *this;
while (n) {
if (n & 1) ret *= tmp;
tmp *= tmp, n >>= 1;
}
return ret;
}
friend bool operator==(mint l, mint r) { return l.x == r.x; }
friend bool operator!=(mint l, mint r) { return l.x != r.x; }
friend ostream &operator<<(ostream &os, mint a) {
return os << a.x;
}
friend istream &operator>>(istream &is, mint &a) {
ll x;
is >> x;
a = x;
return is;
}
};
using Mint = mint<998244353>;
void solve() {
ll A, B, C;
cin >> A >> B >> C;
Mint a = Mint(A);
Mint b = Mint(B);
Mint c = Mint(C);
Mint ans = 0;
ans += a * (a + 1) * b * (b + 1) * c * (c + 1) / 8;
cout << ans << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
// std::ifstream in("input.txt");
// std::cin.rdbuf(in.rdbuf());
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef pair<int,lld> pil;
typedef pair<lld,int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
if(0<=y&&y<n&&0<=x&&x<m) return true;
return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
const int MAX = 555;
int arr[MAX];
vector<int> v;
void f(int x){
v.push_back(x);
swap(arr[x],arr[x+1]);
}
void solve(int tc){
v.clear();
int n;
cin >> n;
for(int e=1;e<=n;e++) cin >> arr[e];
int cnt = 1,flag = 0;
for(int e=1;e<=n;e++){
while(arr[e]!=e){
int pos = -1;
for(int p=e+1;p<=n;p++) if(arr[p]==e) pos = p;
if((pos-1)%2==(cnt%2)){
f(pos-1);
cnt++;
}else{
if(pos-2<e){
f(pos-2);
f(pos-1);
f(pos-2);
f(pos-1);
f(pos-2);
cnt += 5;
}else{
f(pos-2);
f(pos-1);
cnt += 2;
}
}
}
}
cout << sz(v) << "\n";
for(int e=0;e<sz(v);e++) cout << v[e] << " ";
cout << "\n";
}
int main(void){
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tc = 1;
cin >> tc;
for(int test_number=1;test_number<=tc;test_number++){
solve(test_number);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_
void debug_out() {cerr << endl;}
template<typename Head,typename... Tail> void debug_out(Head H,Tail... T){cerr << ' ' << H; debug_out(T...);}
#define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:",debug_out(__VA_ARGS__)
#define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl;
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int T; cin >> T;
string atcoder = "atcoder";
rep(i,T) {
string s; cin >> s;
if (s > atcoder) {
cout << 0 << '\n';
continue;
}
int ans = -1;
rep(i,s.size()) {
if (s[i] != 'a') {
if (s[i] > 't') ans = i - 1;
else ans = i;
break;
}
}
cout << ans << '\n';
}
return 0;
} |
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
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; }
using namespace std;
typedef long long ll;
using P = pair<int, string>;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
int n; cin >> n;
vector<P> v;
for(int i = 0; i < n; i++){
string s; int t; cin >> s >> t;
v.push_back(P(t, s));
}
sort(v.begin(), v.end(), greater<P>());
cout << v[1].second << endl;
} | #include<iostream>
using namespace std;
using ll = long long;
int main() {
int T,i;
cin>>T;
for (i=0;i<T;i++) {
ll L,R,ans = 0;
cin>>L>>R;
if (L*2<=R) {
ans = (R-L*2+2)*(R-L*2+1)/2;
}
cout<<ans<<endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define FORd(i, a, b) for (int i=a-1; i>=b; i--)
#define F0Rd(i, a) for (int i=a-1; i>=0; i--)
#define F0R(i, a) for (int i=0; i<a; i++)
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define sz size
const int MOD = 1000000007;
long double PI = 4*atan(1);
/*std::cout << std::fixed;
std::cout << std::setprecision(2);*/
int n,s,t,w,p;
ll dp[200005];
int main()
{
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> w;
F0R(i,n) {
cin >> s >> t >> p;
dp[s] += p;
dp[t] -= p;
}
F0R(i,200005) {
dp[i] += dp[i-1];
if (dp[i] > w) {
cout << "No";
return 0;
}
}
cout << "Yes\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
bool solve(ll x, set<ll> &s)
{
// cout << 'x' << x << endl;
ll ans = 0;
for (auto e : s)
{
for (auto e2 : s)
{
for (auto e3 : s)
{
// cout << e << e2 << e3 << endl;
ans = (e | e2 | e3);
// cout << "ans: " << ans << endl;
if (ans == ((1LL << 5) - 1LL))
{
return true;
}
}
}
}
return false;
}
int main()
{
int n;
cin >> n;
vector<vector<ll>> A(n, vector<ll>(5));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < 5; j++)
{
cin >> A[i][j];
}
}
ll ok = 0;
ll ng = 1001001001;
while (abs(ok - ng) > 1)
{
ll mid = (ok + ng) / 2LL;
set<ll> s;
for (ll i = 0; i < n; i++)
{
ll bit = 0;
for (ll j = 0; j < 5; j++)
{
if (A[i][j] >= mid)
{
bit |= (1LL << j);
}
}
s.insert(bit);
}
if (solve(mid, s))
{
ok = mid;
}
else
{
ng = mid;
}
}
cout << ok << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
// --------------------------------------------------------
template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; }
#define FOR(i,l,r) for (ll i = (l); i < (r); ++i)
#define RFOR(i,l,r) for (ll i = (r)-1; (l) <= i; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define COUNT(c,v) count(ALL(c),(v))
#define SZ(c) ((ll)(c).size())
#define BIT(b,i) (((b)>>(i)) & 1)
#define PCNT(b) __builtin_popcountll(b)
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << "l." << __LINE__ << " : " << #x << " = " << (x) << '\n'
ll llceil(ll a, ll b) { return (a + b - 1) / b; }
ll bitlen(ll b) { if (b <= 0) { return 0; } return (64LL - __builtin_clzll(b)); }
string toupper(const string& S) { string T(S); REP(i,SZ(T)) T[i] = toupper(T[i]); return T; }
string tolower(const string& S) { string T(S); REP(i,SZ(T)) T[i] = tolower(T[i]); return T; }
using P = pair<ll,ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VVS = vector<VS>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VVVLL = vector<VVLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VVVB = vector<VVB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VLD = vector<ld>;
using VVLD = vector<VLD>;
using VVVLD = vector<VVLD>;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const ll INF = (1LL << 62) - 1; // 4611686018427387904 - 1
// --------------------------------------------------------
// #include <atcoder/all>
// using namespace atcoder;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
ll N; cin >> N;
VVLL A(N,VLL(5)); REP(i,N) REP(j,5) cin >> A[i][j];
auto is_ok = [&](ll X) -> bool {
ll res = false;
VLL C(5);
auto rec = [&](auto self, ll n) -> void {
if (n == 5) {
bool ok1 = false;
bool ok2 = false;
bool ok3 = false;
REP(i,N) {
bool b1 = true;
bool b2 = true;
bool b3 = true;
REP(j,5) {
if (C[j] == 0) { if (A[i][j] < X) b1 = false; }
if (C[j] == 1) { if (A[i][j] < X) b2 = false; }
if (C[j] == 2) { if (A[i][j] < X) b3 = false; }
}
if (b1) ok1 = true;
if (b2) ok2 = true;
if (b3) ok3 = true;
}
if (ok1 && ok2 && ok3) res = true;
return;
}
REP(i,3) {
C[n] = i;
self(self, n+1);
}
return;
};
rec(rec, 0);
return res;
};
ll ok = 0;
ll ng = 1e10;
while (ng - ok > 1) {
ll m = (ok + ng) / 2;
(is_ok(m) ? ok : ng) = m;
}
ll ans = ok;
COUT(ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int a[3005][5];
int n;
string tostr(int x){
string str = "";
while(x){
str += x%3 + '0';
x /= 3;
}
while(str.size() <= 5) str += '0';
return str;
}
bool check(int k){
for(int j=0; j<3*3*3*3*3; j++){
int x = j;
string s = tostr(j);
vector <int> prvi;
vector <int> drugi;
vector <int> treci;
for(int i=0; i<5; i++){
if(s[i] == '0') prvi.push_back(i);
else if(s[i] == '1') drugi.push_back(i);
else treci.push_back(i);
}
int ch = 0;
for(int r=1; r<=n; r++){
bool ovaj = 1;
for(auto c : prvi){
if(a[r][c] < k) ovaj = 0;
}
if(ovaj){
ch++;
break;
}
}
for(int r=1; r<=n; r++){
bool ovaj = 1;
for(auto c : drugi){
if(a[r][c] < k) ovaj = 0;
}
if(ovaj){
ch++;
break;
}
}
for(int r=1; r<=n; r++){
bool ovaj = 1;
for(auto c : treci){
if(a[r][c] < k) ovaj = 0;
}
if(ovaj){
ch++;
break;
}
}
if(ch == 3) return 1;
}
return 0;
}
int main(){
ios_base::sync_with_stdio(false);
cout.precision(10);
cout << fixed;
cin >> n;
for(int i=1; i<=n; i++){
cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3] >> a[i][4];
}
int l=1, r=1000000000, res = 1;
while(l <= r){
int mid = (l+r)/2;
if(check(mid)){
res = mid;
l = mid+1;
}
else r = mid-1;
}
cout << res;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int x;
cin >> x;
int ans = 100 - x%100;
cout << ans << "\n";
return 0;
}
| /*
*
*
* Copyright 2020 Tanishk <tanishktonk>
* ........ ;)
*
*
*/
#include <bits/stdc++.h>
#define ll long long int
#define fr(i,n) for(i=0;i<n;i++)
#define rng(i,a,b) for(i=a;i<b;i++)
#define T long long int T;cin>>T;while(T--)
#define ain(a,n) for(int zzz=0;zzz<n;zzz++){cin>>a[zzz];}
#define aout(a,n) for(int zzz=0;zzz<n;zzz++){cout<<a[zzz]<<' ';}cout<<"\n";
#define All(v) v.begin(),v.end()
#define dbg(v) cerr<<">-- "<<#v<<" = "<<v<<"\n";
#define PB push_back
#define MP make_pair
#define N "\n"
const int inf = ((int)1e9+3);
const int M97 = ((int)1e9+7);
using namespace std;
typedef vector<int> Vi;
typedef pair<int,int> Pii;
typedef pair<int,Pii> Piii;
ll i,j,k;
void solve()
{
int n;
cin >> n;
cout << 100-n%100 << N;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}
|
#include <iostream>
#include <unordered_set>
using namespace std;
using ll = int64_t;
int main(){
ll N;
cin >> N;
unordered_set<ll> s;
for(ll a = 2; a * a <= N; a++){
ll x = a * a;
while(x <= N){
s.insert(x);
x *= a;
}
}
cout << N - s.size() << endl;
}
| #include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <type_traits>
#include <cmath>
#include <cassert>
#include <cstdio>
using namespace std;
using namespace placeholders;
using LL = long long;
using ULL = unsigned long long;
using VI = vector< int >;
using VVI = vector< vector< int > >;
using VS = vector< string >;
using ISS = istringstream;
using OSS = ostringstream;
using PII = pair< int, int >;
using VPII = vector< pair< int, int > >;
template < typename T = int > using VT = vector< T >;
template < typename T = int > using VVT = vector< vector< T > >;
template < typename T = int > using LIM = numeric_limits< T >;
template < typename T = int > using OSI = ostream_iterator< T >;
template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
void in_impl(){};
template < typename T, typename... TS > void in_impl( T &head, TS &... tail ){ cin >> head; in_impl( tail ... ); }
#define IN( T, ... ) T __VA_ARGS__; in_impl( __VA_ARGS__ );
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }
#define NUMBERED( name, number ) NUMBERED2( name, number )
#define NUMBERED2( name, number ) name ## _ ## number
#define REP1( n ) REP2( NUMBERED( REP_COUNTER, __LINE__ ), n )
#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2, REP1 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &&e : c )
#define ALL( c ) begin( c ), end( c )
#define AALL( a ) ( remove_all_extents< decltype( a ) >::type * )a, ( remove_all_extents< decltype( a ) >::type * )a + sizeof( a ) / sizeof( remove_all_extents< decltype( a ) >::type )
#define SZ( v ) ( (int)( v ).size() )
#define EXISTS( c, e ) ( ( c ).find( e ) != ( c ).end() )
template < typename T > inline bool chmin( T &a, const T &b ){ if ( b < a ) { a = b; return true; } return false; }
template < typename T > inline bool chmax( T &a, const T &b ){ if ( a < b ) { a = b; return true; } return false; }
#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter
#define MP make_pair
#define fst first
#define snd second
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
// Λ Λ__
// /(*゚ー゚)/\
// /|  ̄U U ̄|\/
// | |/
int main()
{
cin.tie( nullptr );
ios::sync_with_stdio( false );
cout << setprecision( 12 ) << fixed;
IN( int, N );
VT< LL > A( N );
cin >> A;
sort( ALL( A ) );
VT< LL > psum( 1 );
partial_sum( ALL( A ), BI( psum ) );
LL res = 0;
REP( j, N )
{
res += j * A[j];
}
res -= accumulate( begin( psum ), end( psum ) - 1, 0LL );
cout << res << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define sz(v) (int)(v).size()
#define rep(i, x, y) for(int i = x, i##end = y; i <= i##end; ++i)
#define per(i, x, y) for(int i = x, i##end = y; i >= i##end; --i)
template<class T> inline bool ckmax(T &x, T y) { return x < y ? x = y, 1 : 0; }
template<class T> inline bool ckmin(T &x, T y) { return x > y ? x = y, 1 : 0; }
inline int read() {
int x = 0, f = 1; char ch = getchar();
while(!isdigit(ch)) { if(ch == '-') f = 0; ch = getchar(); }
while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f ? x : -x;
}
const int N = 200005;
LL ans;
int n, a[N], b[N], lsh[N], rag, it[N], tr[N];
vector<int> va[N], vb[N];
inline void add(int x, int d) {
for(int i = x; i <= n; i += i & -i) tr[i] += d;
}
inline int ask(int x) {
int res = 0;
for(int i = x; i > 0; i -= i & -i) res += tr[i];
return res;
}
signed main() {
n = read();
rep(i, 1, n) a[i] = read() + i, lsh[++rag] = a[i];
rep(i, 1, n) b[i] = read() + i;
sort(lsh + 1, lsh + rag + 1), rag = unique(lsh + 1, lsh + rag + 1) - lsh - 1;
rep(i, 1, n) a[i] = lower_bound(lsh + 1, lsh + rag + 1, a[i]) - lsh, va[a[i]].pb(i);
rep(i, 1, n) {
int tmp = b[i];
b[i] = lower_bound(lsh + 1, lsh + rag + 1, b[i]) - lsh;
if(lsh[b[i]] != tmp) return puts("-1"), 0;
vb[b[i]].pb(i);
}
rep(i, 1, rag) if(sz(va[i]) != sz(vb[i])) return puts("-1"), 0;
rep(i, 1, n) {
int tmp = va[b[i]][it[b[i]]++];
add(tmp, 1);
tmp += i - ask(tmp);
ans += tmp - i;
}
cout << ans << '\n';
} | #include<iostream>
#include<list>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
auto itr=v.begin();
while(itr!=v.end()){
if(itr!=v.begin())cout << " ";
cout << *(itr++);
}
return os;
};
// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
cout << "(" << p.first << "," << p.second << ")";
return os;
}
// map 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const map<S,T>& mp){
for(const pair<S,T>& x: mp){
cout << "[" << x.first << "]=" << x.second << " ";
}
return os;
}
struct segtree{
int n;
vector<int> vec;
segtree(int nn){
n=nn;
vec.resize(2*n,0);
}
int get(int i){ return vec[i+n]; };
void set(li a,int i){
i+=n;
vec[i]=a;
while(i>1){
i/=2;
vec[i]=vec[i*2]+vec[i*2+1];
}
};
int sum(int i,int j){
// [i,j)
if(df)print(i,j);
int s=0;
i=i+n; j=j+n;
while(i<j){
if(i%2){ if(df) print(i); s+=vec[i]; i++; }
if(j%2){ j--; s+=vec[j]; if(df) print(j); }
i/=2; j/=2;
}
return s;
}
};
std::ostream& operator<<(std::ostream& os, const segtree& s){
rep(i,2*s.n) printf("%ld ",s.vec[i]);
return os;
}
int judge(map<li,int>& mpa,map<li,int>& mpb){
int f=1;
int t=0;
for(auto& x:mpa){
if(mpb[x.first]!=x.second) f=0;
if(df)print(x,mpb[x.first],"->",f);
}
return f;
}
int main(){
int n; cin >>n;
vector<li> a(n);
map<li,int> mpa;
rep(i,n){
li c; cin >>c;
a[i]=c+i;
mpa[a[i]]++;
}
if(df)print(mpa);
vector<li> b(n);
map<li,int> mpb;
rep(i,n){
li c; cin >>c;
b[i]=c+i;
mpb[b[i]]++;
}
if(df)print(mpb);
if(!judge(mpa,mpb)){
print(-1);
return 0;
}
map<li,list<int>> mp;
rep(i,n){
mp[b[i]].push_back(i);
}
if(df)print(mp);
rep(i,n){
int t=mp[a[i]].front();
mp[a[i]].pop_front();
a[i]=t;
}
if(df)print(a);
segtree sgt(n);
li ans=0;
rep(i,n){
ans+=sgt.sum(a[i],n);
sgt.set(1,a[i]);
if(df)print(sgt, sgt.sum(a[i],n));
}
print(ans);
}
|
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (int)(a.size())
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll A,ll B) {if(!B)return A;return gcd(B,A%B);}
int main()
{
ll a[5];
bool ok = 0;
cin>>a[0]>>a[1]>>a[2]>>a[3];
a[4] = 0;
ll sum = a[0]+a[1]+a[2]+a[3];
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
if(i == j)continue;
for(int k=0;k<5;k++){
if(j == k || i == k)continue;
if(sum-a[i]-a[j]-a[k] == a[i]+a[j]+a[k])ok = 1;
}
}
}
if(ok)cout<<"Yes";
else cout<<"No";
}
| #include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
// cin >> t;
while(t--)
{
ll a, b, c, d;
cin >> a >> b >> c >> d;
cout << b-c;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second
#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x) cerr << "[" << #x << "]: " << x << "\n";
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using pl = pair<ll, ll>;
ld const PI = 4*atan((ld)1);
template<int MOD = 1'000'000'007>
struct Mint
{
int val;
Mint() : val(0) {}
Mint(ll _val) : val((int)(_val % MOD)) { if (val < 0) val += MOD; }
Mint& operator+= (const Mint &rhs) { val += rhs.val; if (val >= MOD) val -= MOD; return *this; }
Mint& operator-= (const Mint &rhs) { val -= rhs.val; if (val < 0) val += MOD; return *this; }
Mint& operator*= (const Mint &rhs) { val = (int)((ll) val * rhs.val % MOD); return *this; }
friend Mint fpow(Mint x, ll y)
{
Mint res = 1;
for (; y > 0; y >>= 1, x *= x)
{
if (y & 1)
res *= x;
}
return res;
}
friend Mint inverse(Mint x) { return fpow(x, MOD-2); }
Mint& operator/= (const Mint &rhs) { return *this *= inverse(rhs); }
friend Mint operator+ (Mint a, const Mint &b) { return a += b; }
friend Mint operator- (Mint a, const Mint &b) { return a -= b; }
friend Mint operator- (Mint a) { return 0 - a; }
friend Mint operator* (Mint a, const Mint &b) { return a *= b; }
friend Mint operator/ (Mint a, const Mint &b) { return a /= b; }
friend ostream& operator<< (ostream &os, const Mint &a) { return os << a.val; }
friend bool operator== (const Mint &a, const Mint &b) { return a.val == b.val; }
friend bool operator!= (const Mint &a, const Mint &b) { return a.val != b.val; }
};
const int MAX = 3069;
int n;
ll ar[MAX], pfx[MAX];
Mint<> dp[MAX][MAX] = {};
Mint<> sum[MAX][MAX] = {};
int main()
{
fastio;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> ar[i], pfx[i] = pfx[i-1] + ar[i];
dp[0][0] = 1;
sum[1][0] = 1;
for (int i = 1; i <= n; ++i)
{
for (int j = i; j >= 1; --j)
{
dp[i][j] = sum[j][pfx[i] % j];
sum[j+1][pfx[i] % (j+1)] += dp[i][j];
// for (int x : v[j][pfx[i] % j])
// {
// if (x == i)
// break;
// dp[i][j] += dp[x][j-1];
// }
// for (int k = 0; k < i; ++k)
// {
// if (pfx[i] % j == pfx[k] % j)
// dp[i][j] += dp[k][j-1];
// }
}
}
// for (int i = 1; i <= n; ++i)
// {
// for (int j = 1; j <= i; ++j)
// cerr << dp[i][j] << ", ";
// cerr << '\n';
// }
Mint<> res = 0;
for (int i = 1; i <= n; ++i)
res += dp[n][i];
cout << res << '\n';
return 0;
}
| #include <iostream>
#include <cstring>
#include <cstdio>
#define N 3005
#define ll long long
#define mod 1000000007
using namespace std;
ll a[N],sum[N];
int f[N],f2[N],g[N];
int main()
{
int i,k,n,ans=0;
scanf("%d",&n);
for(i=1;i<=n;++i)
scanf("%lld",&a[i]);
f[0]=1;
for(k=1;k<=n;++k)
{
memcpy(f2,f,sizeof(f2));
memset(f,0,sizeof(f));
memset(g,0,sizeof(g));
for(i=1;i<=n;++i)sum[i]=(sum[i-1]+a[i])%k;
g[0]=f2[0];
for(i=1;i<=n;++i)
{
f[i]=g[sum[i]];
(g[sum[i]]+=f2[i])%=mod;
}
(ans+=f[n])%=mod;
}
printf("%d\n",ans);
return 0;
}
|
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm> //max,min
#include<iomanip> //setprecision,tuple
#include<vector> //vector
#include<numeric> //iota
#include<map> //map
#include<set> //set
#include<sstream> //stringstream(hex 16,dec 10,oct 8,bilset 2)
#include<list> //list
using namespace std;
using lint = long long;
#define INF 2147483647
#define PI acos(-1)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
int a,b,c;cin>>a>>b>>c;
int ans=21-(a+b+c);
cout<<ans<<endl;
return 0;
} | #include <bits/stdc++.h>
#define all(V) V.begin(),V.end()
#define pi 3.1415926535897932384626
#define fi fixed<<setprecision(13)
#define ll long long
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)
#define Rep(i, n) for (ll i = 1; i <=(ll)(n); i++)
#define reps(i,k,n) for (ll i = (ll)k; i < (ll)(n); i++)
using namespace std;
using V = vector<vector<int>>;
using Vc = vector<vector<char>>;
using Vb = vector<vector<bool>>;
using P = pair<int,int>;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
template<class T> void chmin(T& a,T b){ if(a > b) a=b; }
template<class T> void chmax(T& a,T b){ if(a < b) a=b; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
const ll infll=1LL<<62;
const ll inf=1<<30;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {1, -1, 0, 0};
struct Edge{
int to;
ll w;
Edge(int to,ll w) : to(to),w(w){}
};
using Graph = vector<vector<Edge>>;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
/*----------------------------------------------------*/
int a,b,c;
cin >> a >> b >> c;
cout << 21 - a - b - c <<"\n";
}
/*制約を確認しろllじゃなくて大丈夫か?*/
/* sample 保存
*/ |
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
if (ci - owa > 0) {
memcpy(cn, owa, CL);
ci -= CM;
fread(cn + CL, 1, CM, stdin);
}
ll tmp = *(ll*)ci;
int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
tmp = tmp << dig & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += 72 - dig >> 3;
return tmp;
}
const int MAX = 1000;
class shuturyoku_unko {
public:
char C[MAX * 4];
constexpr shuturyoku_unko() : C() {
rep(i, MAX) {
int X = i;
rep(j, 3) {
C[i * 4 + 2 - j] = '0' + X % 10;
X /= 10;
}
C[i * 4 + 3] = ' ';
}
}
};
constexpr shuturyoku_unko f;
const int dm = 1 << 17;
char* dn = cn, * di = dn, * owad = dn + dm - 20;
void putint(int A) {
if (owad < di) {
fwrite(dn, 1, di - dn, stdout);
di = dn;
}
if (A >= 1000) {
int dig = 1;
if (A >= 100000) dig = 3;
else if (A >= 10000) dig = 2;
memcpy(di, f.C + A / 1000 * 4 + 3 - dig, dig);
memcpy(di + dig, f.C + A % 1000 * 4, 4);
di += dig + 4;
}
else {
int dig = 1;
if (A >= 100) dig = 3;
else if (A >= 10) dig = 2;
memcpy(di, f.C + A * 4 + 3 - dig, dig + 1);
di += dig + 1;
}
}
int N;
int to[400001], ne[400001], he[200001];
int Q[200001], vis[200001], p, q;
ll are[200001];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
N = getint();
rep1(i, N * 2 - 2) {
int a = getint(), b = getint();
to[i] = b;
ne[i] = he[a];
he[a] = i++;
to[i] = a;
ne[i] = he[b];
he[b] = i;
}
Q[q++] = 1;
while (p < q) {
int u = Q[p++];
vis[u] = -1;
for (int i = he[u]; i; i = ne[i]) {
if (vis[to[i]] == 0) {
Q[q++] = to[i];
}
}
}
int tmp = Q[N - 1];
p = 0;
q = 0;
Q[q++] = tmp;
vis[tmp] = 0;
while (p < q) {
int u = Q[p++];
int mae = 0;
for (int i = he[u]; i; i = ne[i]) {
if (vis[to[i]] < 0) {
vis[to[i]] = u;
Q[q++] = to[i];
mae = i;
}
else {
if (mae) ne[mae] = ne[i];
else he[u] = ne[i];
}
}
}
ll m = (1ll << 20) - 1, m0 = ~m, m1 = 1ll << 20;
for (int i = N - 1; i >= 0; i--) {
int u = Q[i];
ll kari = (are[u] & m0) + m1 + u;
if (are[vis[u]] < kari) are[vis[u]] = kari;
}
int k = 0;
q = 0;
Q[q++] = tmp;
while (q) {
k++;
int u = Q[q - 1];
if (u < 0) q--;
else {
vis[u] = -k;
Q[q - 1] = -u;
int nanika = are[u] & m;
if (nanika) Q[q++] = nanika;
for (int i = he[u]; i; i = ne[i]) {
int v = to[i];
if (v != nanika) {
Q[q++] = v;
}
}
}
}
rep1(i, N) putint(-vis[i]);
fwrite(dn, 1, di - dn, stdout);
Would you please return 0;
} | #include<bits/stdc++.h>
using namespace std;
//一の位の数の2倍と十の位以上の数の差が7の倍数であれば、その数は7で割り切れる。
//ある自然数を一の位から3ケタごとに区切り、それらを交互に加算する。そして、それらの和の差が7の倍数のとき、その自然数は7の倍数である。
int main(){
int N;
string S,T;
cin>>N;
cin>>S>>T;
vector<int> Tv;
int ten=1;
for(int i=S.size()-1;i>=0;i--){
int a=(S[i]-'0')*ten%7;
ten=ten*10%7;
Tv.push_back(a);
}
reverse(Tv.begin(),Tv.end());
for(int i=0;i<Tv.size();i++){
// cout<<Tv[i];
}
// cout<<endl;
int win[7]={0};
win[0]=1;
for(int i=S.size()-1;i>=0;i--){
int nxwin[7]={0};
if(T[i]=='T'){
for(int j=0;j<7;j++){
int nx1=(j+Tv[i])%7;
while(nx1<0) nx1+=7;
int nx2=j%7;
while(nx2<0) nx2+=7;
if(win[nx1]==1) nxwin[j]=1;
if(win[nx2]==1) nxwin[j]=1;
}
}
else{
for(int j=0;j<7;j++){
int nx1=(j+Tv[i])%7;
while(nx1<0) nx1+=7;
int nx2=j%7;
while(nx2<0) nx2+=7;
if(win[nx1]==1&&win[nx2]==1) nxwin[j]=1;
}
}
for(int j=0;j<7;j++){
//cout<<nxwin[j]<<" ";
win[j]=nxwin[j];
}
//cout<<endl;
}
if(win[0]==1) cout<<"Takahashi"<<endl;
else cout<<"Aoki"<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define P pair
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000;
constexpr ll llINF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
random_device rnd;
mt19937 mt(rnd());//32bit
//[mi,ma]
uniform_int_distribution<int>engine(mi,ma);
return engine(mt);
}
ll gcd(ll a,ll b){
if(b==0)return a;
return gcd(b,a%b);
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b;
}
bool prime(int a){
if(a==1)return false;
for(int i=2;i*i<=a;i++){
if(a%i==0)return false;
}
return true;
}
ll modpow(ll a,ll b){
if(b==0)return 1;
if(b%2)return modpow(a,b-1)*a%mod;
ll memo=modpow(a,b/2);
return memo*memo%mod;
}
vector<ll>kaijo,invkaijo;
void init_fact(int n){
kaijo.resize(n+1);
invkaijo.resize(n+1);
kaijo[0]=1;
for(ll i=1;i<=n;i++){
kaijo[i]=kaijo[i-1]*i;
kaijo[i]%=mod;
}
rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
/*
vector<vector<ll>>C,sC;
void init_comb(int n,int m){
C.resize(n+1,vector<ll>(m+1,0));
sC.resize(n+1,vector<ll>(m+1,0));
C[0][0]=1;
for(int i=1;i<=n;i++){
C[i][0]=1;
for(int j=1;j<=m;j++){
C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
}
}
rep(i,n+1){
rep(j,m){
sC[i][j+1]=(sC[i][j]+C[i][j])%mod;
}
}
}*/
ll comb(int a,int b){
if(a<b)return 0;
if(a<0)return 0;
return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
ll inv(ll x){
x=modpow(x,mod-2);
return x;
}
void solve(){
}
int main(){
int n,m,t,a[1010],b[1010];
cin>>n>>m>>t;
int x=n;
rep(i,m)cin>>a[i]>>b[i];
rep(i,m){
x-=(i==0?a[i]:a[i]-b[i-1]);
if(x<=0){
cout<<"No"<<endl;
return 0;
}
x+=b[i]-a[i];
chmin(x,n);
}
x-=(t-b[m-1]);
if(x<=0){
cout<<"No"<<endl;
return 0;
}
cout<<"Yes"<<endl;
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 , m , t;
cin>>n>>m>>t;
ll cur = n , prev = 0;
bool flag = 0;
ll a[m] , b[m];
for(int i = 0; i < m; i++){
cin>>a[i]>>b[i];
cur -= max(0LL , a[i] - prev);
if(cur <= 0){
flag = 1;
}
cur += b[i] - a[i];
cur = min(n , cur);
prev = b[i];
}
cur -= (t - b[m - 1]);
if(cur <= 0){
flag = 1;
}
if(flag){
cout<<"No\n";
}else{
cout<<"Yes\n";
}
return 0;
} |
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;
typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;
ll merge_cnt(vector<ll> &a) {
int n = a.size();
if (n <= 1) { return 0; }
ll cnt = 0;
vector<ll> b(a.begin(), a.begin()+n/2);
vector<ll> c(a.begin()+n/2, a.end());
cnt += merge_cnt(b);
cnt += merge_cnt(c);
int ai = 0, bi = 0, ci = 0;
// merge の処理
while (ai < n) {
if ( bi < b.size() && (ci == c.size() || b[bi] <= c[ci]) ) {
a[ai++] = b[bi++];
} else {
cnt += n / 2 - bi;
a[ai++] = c[ci++];
}
}
return cnt;
}
void solve(long long N, std::vector<long long> a){
auto A = a;
ll current = merge_cnt(A);
rep(i,0,N) {
cout << current << endl;
current -= a[i];
current += N - a[i] - 1;
}
}
signed main(){
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
long long N;
scanf("%lld",&N);
std::vector<long long> a(N-1-0+1);
for(int i = 0 ; i < N-1-0+1 ; i++){
scanf("%lld",&a[i]);
}
solve(N, std::move(a));
return 0;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pll pair <long long,long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define D(x) cerr<<#x " = "<<(x)<<endl
#define vll vector <ll>
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;
ost st;
void remove(ll x)
{
st.erase(st.lower_bound(x-1));
return;
}
ll lt(ll x)
{
return st.order_of_key(x);
}
ll gt(ll x)
{
return st.size() - lt(x) - 1;
}
int main()
{
IOS
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// freopen("error.txt","w",stderr);
ll n;
cin>>n;
vector<ll>a(n);
ll total=0;
for(ll i=0;i<n;i++)
{
cin>>a[i];
st.insert(a[i]);
total+=gt(a[i]);
}
cout<<total<<endl;
for(ll i=0;i<n-1;i++)
{
ll ls = lt(a[i]);
total-=ls;
ll grt = gt(a[i]);
total+=grt;
cout<<total<<endl;
}
return 0;
} |
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,x,n) for(int i = x;i <= n;++i)
#define Angel_Dust ios::sync_with_stdio(0);cin.tie(0)
const int N = 3e5+7;
ll sum[N],ssum[N],a[N];
int main()
{
Angel_Dust;
int n;cin >> n;
forn(i,1,n) cin >> a[i];
forn(i,1,n) sum[i] = sum[i - 1] + a[i],ssum[i] = ssum[i - 1] + a[i] * a[i];
ll res = 0;
forn(i,2,n)
{
res += (i - 1) * (a[i] * a[i]);
res += ssum[i - 1];
res -= 2 * a[i] * sum[i - 1];
}
printf("%lld\n",res);
return 0;
} | #include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define lowbit(x) ((x) & -(x))
using namespace std;
using ll = long long;
using pii = pair<int, int>;
constexpr double eps = 1e-8;
constexpr int NINF = 0xc0c0c0c0;
constexpr int INF = 0x3f3f3f3f;
constexpr ll mod = 1e9 + 7;
constexpr ll N = 1e6 + 5;
int dx[] = {1, 1, 0, 0};
int dy[] = {0, 1, 1, 0};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int H, W;
cin >> H >> W;
vector<string> s(H);
for (int i = 0; i < H; i++) cin >> s[i];
int ans = 0;
for (int i = 0; i + 1 < H; i++) {
for (int j = 0; j + 1 < W; j++) {
int cnt = 0;
for (int k = 0; k < 4; k++) {
cnt += s[i + dx[k]][j + dy[k]] == '#';
}
ans += cnt & 1;
}
}
cout << ans << '\n';
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'
constexpr int INF = (sizeof(int) == 4 ? 1e9 : 2e18) + 1e5;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 200 + 3;
int dp[MAXN][MAXN];
//
int n;
int f(int idx, int cut) {
if (idx >= n)
return (idx == n && cut == 11);
int &ret = dp[idx][cut];
if (~ret)
return ret;
ret = f(n, cut);
for (int j = idx; j <= n; ++j) {
ret += f(j + 1, cut + 1);
}
return ret;
}
// #define MULTIPLE_TEST_CASES
void solve() {
memset(dp, -1, sizeof dp);
cin >> n;
--n;
cout << f(0, 0) << endl;
}
signed main() {
// const string FILE_NAME = "";
// freopen((FILE_NAME + string(".in")).c_str(), "r", stdin);
// freopen((FILE_NAME + string(".out")).c_str(), "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int t = 1;
#ifdef MULTIPLE_TEST_CASES
cin >> t;
#endif
while (t--)
solve();
} | #pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
putchar('\n');
}
int N;
int A[100011];
void MAIN() {
scanf("%d", &N);
REP (i, N) scanf("%d", A+i);
bool first;
if (N % 2 == 1) {
first = false;
} else {
sort(A, A+N);
first = false;
for (int i=0; i<N; i+=2) {
if (A[i] != A[i+1]) first = true;
}
}
puts(first? "First": "Second");
}
int main() {
int TC = 1;
scanf("%d", &TC);
REP (tc, TC) MAIN();
return 0;
}
|
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cctype>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <queue>
#include <ctime>
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
inline int read_int(){
int t=0;bool sign=false;char c=getchar();
while(!isdigit(c)){sign|=c=='-';c=getchar();}
while(isdigit(c)){t=(t<<1)+(t<<3)+(c&15);c=getchar();}
return sign?-t:t;
}
inline LL read_LL(){
LL t=0;bool sign=false;char c=getchar();
while(!isdigit(c)){sign|=c=='-';c=getchar();}
while(isdigit(c)){t=(t<<1)+(t<<3)+(c&15);c=getchar();}
return sign?-t:t;
}
inline char get_char(){
char c=getchar();
while(c==' '||c=='\n'||c=='\r')c=getchar();
return c;
}
inline void write(LL x){
char c[21],len=0;
if(!x)return putchar('0'),void();
if(x<0)x=-x,putchar('-');
while(x)c[++len]=x%10,x/=10;
while(len)putchar(c[len--]+48);
}
inline void space(LL x){write(x),putchar(' ');}
inline void enter(LL x){write(x),putchar('\n');}
const int MAXN=2e5+5;
int p[MAXN],a[MAXN],b[MAXN];
LL s[MAXN];
int Find(int x){
return p[x]==x?x:p[x]=Find(p[x]);
}
int main()
{
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
int n=read_int(),m=read_int();
if(n==1&&m==0)
printf("%d %d\n",1,2);
else if(m<0||m>=n-1)puts("-1");
else if((n-m)%2==1){
m++;
int pos=1,d=(n-m)/2;
_for(i,1,d){
printf("%d %d\n%d %d\n",pos,pos+3,pos+1,pos+2);
pos+=4;
}
d=n-2*(d-1)-1;
printf("%d %d\n",pos,pos+1+2*d);
pos++;
_rep(i,1,d-2)
printf("%d %d\n",pos,pos+1),pos+=2;
printf("%d %d\n%d %d\n",pos,pos+3,pos+1,pos+2);
}
else{
int pos=1,d=(n-m)/2;
_for(i,1,d){
printf("%d %d\n%d %d\n",pos,pos+3,pos+1,pos+2);
pos+=4;
}
d=n-2*(d-1)-1;
printf("%d %d\n",pos,pos+1+2*d);
pos++;
_rep(i,1,d)
printf("%d %d\n",pos,pos+1),pos+=2;
}
return 0;
} | #include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ch() getchar()
#define pc(x) putchar(x)
template<typename T>inline void read(T&x){
int f;char c;
for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;
for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;
}
template<typename T>inline void write(T x){
static char q[64];int cnt=0;
if(!x)pc('0');if(x<0)pc('-'),x=-x;
while(x)q[cnt++]=x%10+'0',x/=10;
while(cnt--)pc(q[cnt]);
}
int main(){
int n,m;read(n),read(m);
if(n==1&&m==0)puts("1 2");
else if(m>n-2||m<0)puts("-1");
else if(m==0){
for(int i=1;i<=n;++i)
write(i),pc(' '),write(i+n),pc('\n');
}
else{
const int Base=300000;
for(int i=1;i<=m+1;++i)
write(i*2-1+Base),pc(' '),write(i*2+Base),pc('\n');
int l=0,r=(m+1)*2+1;
for(int i=m+2;i<=n;++i)
write((l--)+Base),pc(' '),write((r++)+Base),pc('\n');
}
return 0;
}
|
/*
口台 口台
令人咍咍。
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int n, dep[N], is[N], son[N], res[N], tim, p, q;
int e, to[N << 1], nxt[N << 1], hd[N];
void add(int u, int v){ to[++e] = v; nxt[e] = hd[u]; hd[u] = e; }
void dfs(int u, int fa){
if(dep[u] > dep[p]) p = u;
for(int i = hd[u]; i; i = nxt[i]){
int v = to[i]; if(v == fa) continue;
dep[v] = dep[u] + 1; dfs(v, u);
}
return;
}
void dfs2(int u, int fa){
is[u] = (u == q); //printf("%d ", u); printf("%d\n", is[u]);
for(int i = hd[u]; i; i = nxt[i]){
int v = to[i]; if(v == fa) continue;
dfs2(v, u); if(is[v]) is[u] = 1, son[u] = v;
}
return;
}
void dfs3(int u, int fa){
res[u] = ++tim;
for(int i = hd[u]; i; i = nxt[i]){
int v = to[i]; if(v == fa || v == son[u]) continue;
dfs3(v, u);
}
if(son[u]) dfs3(son[u], u);
++tim;
return;
}
int main() {
//freopen("ex.in", "r", stdin);
//freopen("ex.out", "w", stdout);
scanf("%d", &n);
for(int i = 1, u, v; i < n; i++)
scanf("%d%d", &u, &v), add(u, v), add(v, u);
p = 1; dep[1] = 0; dfs(1, 0);
q = p; dep[q] = 0; dfs(q, 0);
//cout<<p<<" "<<q<<endl;
dfs2(p, 0); dfs3(p, 0);
//printf("%d\n", 2 * (n - 1) + 1 - dep[p]);
for(int i = 1; i <= n; i++)
printf("%d ", res[i]);
return 0;
} | #include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
int N;
vector<int>to[200005];
int deep = -1;
int dmax = -1;
void dfs(int v, int d = 0, int p = -1) {
if (d > dmax) {
deep = v;
dmax = d;
}
for (int e : to[v]) {
if (p == e) { continue; }
dfs(e, d + 1, v);
}
}
int pre[200005];
int deep2 = -1;
int dmax2 = -1;
void dfs0(int v, int d = 0, int p = -1) {
pre[v] = p;
if (d > dmax2) {
deep2 = v;
dmax2 = d;
}
for (int e : to[v]) {
if (p == e) { continue; }
dfs0(e, d + 1, v);
}
}
set<int>st;
int now = 0;
int a[200005];
void dfs2(int v, int d = 0, int p = -1) {
now++;
if (0 == a[v]) {
a[v] = now;
}
int last = -1;
for (int e : to[v]) {
if (p == e) { continue; }
if (st.count(e)) {
last = e;
continue;
}
dfs2(e, d + 1, v);
now++;
}
if (-1 != last) {
dfs2(last, d + 1, v);
now++;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N;
rep(i, N - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
dfs(0);
dfs0(deep);
int now = deep2;
while (-1 != deep2) {
st.insert(deep2);
deep2 = pre[deep2];
}
//cout << deep << endl;
//cout << deep2 << endl;
dfs2(deep);
rep(i, N) {
cout << a[i] << " ";
}
return 0;
} |
#include <stdint.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR_N(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define FOR_R(i, b, e) for (int64_t i = int64_t(b); i < (int64_t)(e); i++)
int main() {
int64_t H, W;
cin >> H >> W;
int64_t A[100][100];
int64_t min_A = 9999999999;
FOR_N(i, H) {
FOR_N(j, W) {
cin >> A[i][j];
min_A = min(min_A, A[i][j]);
}
}
int64_t diff = 0;
FOR_N(i, H) {
FOR_N(j, W) {
diff += A[i][j] - min_A;
}
}
cout << diff << endl;
return 0;
} | #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
typedef long long ll;
#define FOR(i, a, b) for(int i=(a); i<(b);i++)
#define REP(i, n) for(int i=0; i<(n);i++)
#define ROF(i, a, b) for(int i=(b-1); i>=(a);i--)
#define PER(i, n) for(int i=n-1; i>=0;i--)
using namespace std;
int main() {
ll h, w;
ll sum, min;
sum = 0;
min = 100;
cin >> h >> w;
REP(i, h) {
REP(j, w) {
ll a;
cin >> a;
sum += a;
min = min > a ? a : min;
}
}
cout << sum - min * h * w;
return 0;
} |
using namespace std;
#include<bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const int N = 2e5+3;
int digits(int value)
{
int cnt = 0;
while( value )
++cnt, value/=10;
return cnt;
}
int power (int base, int exp)
{
int res = 1;
while(exp)
{
if (exp & 1)
{
res*=base;
}
exp>>=1;
base*=base;
}
return res;
}
signed main()
{
IOS;
int n; cin >> n;
int tot = digits(n);
int ans = 0;
if ( tot < 4 )
{
cout << 0 << endl;
return 0;
}
for ( int i = 4; i < tot; ++i )
ans += power(10,i-1)*9LL*((i - 1)/3);
ans += (n - power(10, tot - 1) + 1)*(( tot - 1 )/3);
cout << ans << endl;
}
| #include<bits/stdc++.h>
using namespace std;
int main()
{
long long n ;
cin>>n ;
long long x[n] , y=0;
for(int i=0 ;i<n;i++)
{
cin>>x[i] ;
}
for(int i=0 ;i<n ;i++)
{
y+=abs(x[i]) ;
}
cout<<y<<endl ;
long long t=0 ;
for(int i=0;i<n;i++)
{
t+=(abs(x[i])*abs(x[i]) ) ;
}
cout<<fixed<<showpoint<<setprecision(15)<<sqrt(t)<<endl ;
int r= abs(x[0]);
for(int i=0 ;i<n;i++)
{
if(r<abs(x[i]))
r=(abs(x[i])) ;
}
cout<<r<<endl ;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
long long n,x,i,a[1000000],cnt;
int main(){
ios::sync_with_stdio(false);
cin>>n;
for(i=1;i<=sqrt(n);i++){
if(n%i==0){
cout<<i<<endl;
x=n/i;
if(i!=x)a[++cnt]=x;
}
}
for(i=cnt;i>=1;i--)cout<<a[i]<<endl;
return 0;
} | //#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a) (a).begin(),(a).end()
#define ALLR(a) (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};
vector<ll>divisor_enum(ll n){
vector<ll>ret;
for(ll i=1;i*i<=n;i++){
if(n%i==0){
if(i*i==n)ret.PB(i);
else{
ret.PB(i);
ret.PB(n/i);
}
}
}
return ret;
}
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
ll res=0,buf=0;
bool judge = true;
ll n;cin>>n;
auto d=divisor_enum(n);
sort(ALL(d));
for(auto z:d)cout<<z<<endl;
return 0;
} |
# include <bits/stdc++.h>
# ifndef ngng628_library
# define ngng628_library
# define int long long
# define float long double
# define fi first
# define se second
# define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i,n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i,n) for(int i=((int)(n)); i>0; --i)
# define repr(i,b,e) for(int i=(b), i##_len=(e); i<i##_len; ++i)
# define reprs(i,b,e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define all(x) std::begin(x), std::end(x)
# define rall(x) std::rbegin(x), std::rend(x)
# define pb push_back
# define eb emplace_back
# define len(x) ((int)(x).size())
using namespace std;
template<class T> using vec = vector<T>;
using pii = pair<int, int>;
using vi = vec<int>;
using vvi = vec<vi>;
using db = deque<bool>;
using ddb = deque<db>;
using vs = vec<string>;
constexpr int INF = (1LL<<62)-(1LL<<31);
constexpr float EPS = 1e-10;
template<class T> istream& operator>>(istream& is, vec<T>& v) { for (auto& x : v) is >> x; return is; }
template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.fi >> p.se; }
template<class T> string join(const vec<T> &v){ stringstream s; rep (i, len(v)) s<<' '<<v[i]; return s.str().substr(1); }
template<class T> ostream& operator<<(ostream& os, const vec<T>& v){ if (len(v)) os << join(v); return os; }
template<class T> ostream& operator<<(ostream& os, const vec<vec<T>>& v){ rep (i, len(v)) if (len(v[i])) os << join(v[i]) << (i-len(v)+1 ? "\n" : ""); return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << p.fi << " " << p.se; }
template<class T, class U, class V> ostream& operator<<(ostream& os, const tuple<T, U, V>& t){ return os << get<0>(t) << " " << get<1>(t) << " " << get<2>(t); }
void print(){ cout << "\n"; }
template<class T, class... A>void print(const T& v, const A&...args){ cout << v; if(sizeof...(args))cout << " "; print(args...); }
void eprint() { cerr << "\n"; }
template<class T, class... A>void eprint(const T& v, const A&...args){ cerr << v; if(sizeof...(args))cerr << " "; eprint(args...); }
void drop(){ cout << "\n"; exit(0); }
template<class T, class... A>void drop(const T& v, const A&...args){ cout << v; if(sizeof...(args))cout << " "; drop(args...); }
template<class T> constexpr bool chmax(T &a, const T& b) { return a < b && (a = b, true); }
template<class T> constexpr bool chmin(T &a, const T& b) { return a > b && (a = b, true); }
constexpr int ctoi(const char c) { return ('0' <= c and c <= '9') ? (c - '0') : -1; }
# endif // ngng628_library
int32_t main() {
int h, w, a, b;
cin >> h >> w >> a >> b;
set<vvi> st;
auto rec = [&st,h,w](auto&& self, vvi now, int a, int b, int r) -> void {
if (r == 0) {
st.insert(now);
return;
}
if (a == 0 and b == 0) return;
if (r >= 2) {
// 縦
rep (y, h-1) rep (x, w) {
if (now[y][x] == -1 and now[y+1][x] == -1 and a > 0) {
now[y][x] = now[y+1][x] = 1;
self(self, now, a-1, b, r - 2);
now[y][x] = now[y+1][x] = -1;
goto A;
}
}
A:;
// 横
rep (y, h) rep (x, w-1) {
if (now[y][x] == -1 and now[y][x+1] == -1 and a > 0) {
now[y][x] = now[y][x+1] = 2;
self(self, now, a-1, b, r - 2);
now[y][x] = now[y][x+1] = -1;
goto B;
}
}
B:;
}
// 1 枚
rep (y, h) rep (x, w) {
if (now[y][x] == -1 and b > 0) {
now[y][x] = 0;
self(self, now, a, b-1, r - 1);
now[y][x] = -1;
goto C;
}
}
C:;
};
vvi init(h, vi(w, -1));
rec(rec, init, a, b, h*w);
print(len(st));
}
| #pragma region Region_1
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; 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()
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VP = vector<P>;
using VS = vector<string>;
using VC = vector<char>;
using VVC = vector<vector<char>>;
#define MOD 1000000007
const int INF = (int)1e9 + 10; // int max > 2*10^9
const long long INFL = (ll)2e18 + 10; // ll max > 9*10^18
template <class T, class C>
bool chmax(T& a, C b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T, class C>
bool chmin(T& a, C b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
T sum(const vector<T>& v) {
T res = 0;
for (size_t i = 0; i < v.size(); ++i) res += v[i];
return res;
}
/////////////////////////////////////////////////////////
// print like python
// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed
/////////////////////////////////////////////////////////
void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
cout << head;
if (sizeof...(tail) != 0) cout << " ";
print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T>& vec) {
for (auto& a : vec) {
cout << a;
if (&a != &vec.back()) cout << " ";
}
cout << endl;
}
template <class T>
void print(vector<vector<T>>& df) {
for (auto& vec : df) {
print(vec);
}
}
#pragma endregion Region_1
/////////////////////////////////////////////////////////
int main() {
std::cout << std::setprecision(15);
//////////////////////////////////////////
VI a(3);
rep(i,3)cin >> a[i];
sort(rng(a));
if(a[2]-a[1] == a[1]-a[0])print("Yes");
else print("No");
return 0;
}
|
#include "bits/stdc++.h"
#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
int main(){
int N, A, B;
cin >> N >> A >> B;
P(N+(B-A));
} | #include <bits/stdc++.h>
using namespace std;
int main (void) {
int N, A, B;
cin >> N >> A >> B;
cout << N - A + B << endl;
return 0;
}
|
#include<bits/stdc++.h>
// #define int long long
// #define maxn
// #define mod
using namespace std;
// template<class T>T ABS(T x) {return x<0?-x:x;}
//int ksm(int x,int y) {int r=1;while(y) y&1?r=1ll*r*x%mod:0,x=1ll*x*x%mod,y>>=1;return r;}
int read()
{
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
return s*w;
}
// struct Edge{int to,next;}a[maxn];
// int h[maxn],cnt;
// void add(int x,int y) {a[++cnt]=(Edge){y,h[x]},h[x]=cnt,a[++cnt]=(Edge){x,h[y]},h[y]=cnt;}
signed main()
{
int A=read(),B=read(),W=read()*1000;
int ta=W/A,tb=(W+B-1)/B;
if(tb>ta) cout<<"UNSATISFIABLE\n";
else cout<<tb<<' '<<ta<<'\n';
return 0;
} | #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <deque>
#include <string>
#include <cassert>
using namespace std;
typedef long long llint;
const int INF = 0x3f3f3f3f;
const llint INFLL = 0x3f3f3f3f3f3f3f3fLL;
void print() { cout << "\n"; }
template <typename...T, typename X>
void print(X&& x, T... args) { cout << x << " "; print(args...); }
int input() { return 0; }
template <typename...T, typename X>
int input(X& x, T&... args) {
if (!(cin >> x)) return 0;
return input(args...) + 1;
}
const int ALPHA = 256;
const string UNSOLVABLE = "UNSOLVABLE";
string a, b, c;
int mp[ALPHA];
llint string_to_int(const string& s) {
int n = s.size();
llint res = 0;
if (mp[s[0]] == 0) {
return -1;
}
for (int i = 0; i < n; i++) {
res = res * 10 + mp[s[i]];
}
return res;
}
bool check() {
llint aa = string_to_int(a);
if (aa == -1) {
return false;
}
llint bb = string_to_int(b);
if (bb == -1) {
return false;
}
llint cc = string_to_int(c);
if (cc == -1) {
return false;
}
return aa + bb == cc;
}
int main() {
input(a, b, c);
string charset = a + b + c;
sort(charset.begin(), charset.end());
charset.erase(std::unique(charset.begin(), charset.end()), charset.end());
if (charset.size() > 10) {
puts(UNSOLVABLE.c_str());
return 0;
}
vector<int> ns;
for (int i = 0; i < 10; i++) {
ns.push_back(i);
}
bool flag = false;
do {
memset(mp, -1, sizeof(mp));
for (int i = 0; i < charset.size(); i++) {
mp[charset[i]] = ns[i];
}
if (check()) {
flag = true;
break;
}
} while (next_permutation(ns.begin(), ns.end()));
if (flag) {
llint aa = string_to_int(a);
llint bb = string_to_int(b);
llint cc = string_to_int(c);
printf("%lld\n", aa);
printf("%lld\n", bb);
printf("%lld\n", cc);
} else {
puts(UNSOLVABLE.c_str());
}
return 0;
}
/*
^^^TEST^^^
a
b
c
-----
1
2
3
$$$TEST$$$
^^^TEST^^^
x
x
y
----
1
1
2
$$$TEST$$$
^^^TEST^^^
p
q
p
---
UNSOLVABLE
$$$TEST$$$
^^^TEST^^^
abcd
efgh
ijkl
---
UNSOLVABLE
$$$TEST$$$
^^^TEST^^^
send
more
money
----
9567
1085
10652
$$$TEST$$$
*/
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll maxn=100005;
const ll mod=1e9+7;
const ll m2=1e9+7;
const ll INF64 = ll(1e18);
const ll max2=1e3+10;
const ll N = 1000001;
const ll MAXN=2e5+10;
const ll ALPHABET_SIZE = 2;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
//long long tt = clock();
#endif
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n,i,j;
cin>>n;
vector<ll> v(n);
for(i=0;i<n;++i)
cin>>v[i];
ll val[n+1][n];
memset(val,0,sizeof(val));
ll dp[n+1][n+1];
memset(dp,0,sizeof(dp));
dp[0][0]=1;
val[1][0]=1;
ll mod1[n+1];
memset(mod1,0,sizeof(mod1));
for(i=1;i<=n;++i)
{
for(j=1;j<=n;++j)
{
mod1[j]+=v[i-1]%j;
mod1[j]%=j;
dp[i][j]+=val[j][mod1[j]];
dp[i][j]%=mod;
}
for(j=1;j<=n;++j)
{
val[j][mod1[j]]+=dp[i][j-1];
val[j][mod1[j]]%=mod;
}
}
ll val1=0;
for(i=1;i<=n;++i)
{val1+=dp[n][i];
val1%=mod;
}
cout<<val1;
return(0);
}
| #pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
ll dp[18];
char S[200200];
int suuji(char c) {
if (c < 'A') return c - '0';
else return c - ('A' - 10);
}
int main() {
//cin.tie(0);
//ios::sync_with_stdio(false);
fread(S, 1, 200200, stdin);
int K = 0;
int N = 200200 - 1;
while (S[N] != ' ') N--;
int tmp = N + 1;
while (S[tmp] >= '0') K = K * 10 + S[tmp++] - '0';
const int mod = 1e9 + 7;
int k = suuji(S[0]);
dp[1] = k - 1;
int kazu = 1 << 15 - k;
rep1(i, N - 1) {
if (!(i & 7)) for (int j = 2; j <= 16; j++) dp[j] %= mod;
for (int j = 16; j >= 1; j--) {
dp[j + 1] += (16 - j) * dp[j];
dp[j] = j * dp[j];
}
dp[1] += 15;
int k = suuji(S[i]);
int k1 = __builtin_popcount(kazu >> 16 - k);
int kazu0 = __builtin_popcount(kazu);
dp[kazu0] += k1;
dp[kazu0 + 1] += k - k1;
kazu |= 1 << 15 - k;
}
ll kotae = dp[K];
kotae += (__builtin_popcount(kazu) == K);
printf("%lld", kotae % mod);
Would you please return 0;
} |
#include <bits/stdc++.h>
using namespace std;
const double PI=acos(-1);
const double eps=1e-5;
int main(){
int n,a,b,c,d;
scanf("%d",&n);
scanf("%d%d%d%d",&a,&b,&c,&d);
double x=1.0*(a+c)/2.0,y=1.0*(b+d)/2.0;
double len=sqrt(1.0*(a-c)*(a-c)+1.0*(b-d)*(b-d))/2;
double al=atan2(1.0*(d-b),1.0*(c-a));//用atan()会WA,
double bl=2.0*PI/n;
double cl=al+bl;
double ax=x-len*cos(cl),ay=y-len*sin(cl);
if(fabs(ay)<eps) ay=0;//-0的情况
if(fabs(ax)<eps) ax=0;
printf("%.5f %.5f\n",ax,ay);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
complex<long double> p0, pN2;
{
double x, y;
cin >> x >> y;
p0 = x + y * 1i;
cin >> x >> y;
pN2 = x + y * 1i;
}
complex<long double> g = (p0 + pN2) * (long double)0.5;
complex<long double> rot = polar(1.0, M_PI * 2 / N);
complex<long double> p1 = (p0 - g) * rot + g;
cout << fixed << setprecision(10) << p1.real() << ' ' << p1.imag() << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll I=1167167167167167167;
ll Q=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end());reverse(v.begin(),v.end());}
template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";}
void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";}
//Cとかで出てみたい
int main() {
ll R,X,Y;
cin>>R>>X>>Y;
R*=R,X*=X,Y*=Y;
ll K=(X+Y+R-1)/R;
//cout<<K<<endl;
ll l=0,r=1e9;
while(r-l>1){
ll D=(l+r)/2;
if(D*D>=K) r=D;
else l=D;
}
if(X+Y<R) cout<<"2"<<endl;
else cout<<r<<endl;
}
| #include <cstdio>
#include <iostream>
using namespace std;
#define int __int128
int T, X, Y, P, Q;
void read( int &x ) {
x = 0; char s = getchar();
while( s < '0' || s > '9' ) s = getchar();
while( '0' <= s && s <= '9' ) {
x = ( x << 1 ) + ( x << 3 ) + ( s ^ 48 );
s = getchar();
}
}
void exgcd( int a, int b, int &d, int &x, int &y ) {
if( ! b ) d = a, x = 1, y = 0;
else {
exgcd( b, a % b, d, y, x );
y -= x * ( a / b );
}
}
void print( int x ) {
if( x > 9 ) print( x / 10 );
putchar( ( x % 10 ) + '0' );
}
signed main() {
read( T );
while( T -- ) {
read( X ), read( Y ), read( P ), read( Q );
int d, x, y, ans = 1e32;
exgcd( X * 2 + Y * 2, P + Q, d, x, y );
for( int i = 0;i < Y;i ++ )
for( int j = 0;j < Q;j ++ ) {
int c = P + j - X - i;
if( c % d ) continue;
int k1 = c / d * x;
int k2 = c / d * ( - y );
int mod1 = ( P + Q ) / d, mod2 = ( X * 2 + Y * 2 ) / d;
if( k1 < 0 ) {
int t = ( - k1 + mod1 - 1 ) / mod1;
k1 += mod1 * t, k2 += mod2 * t;
}
if( k2 < 0 ) {
int t = ( - k2 + mod2 - 1 ) / mod2;
k1 += mod1 * t, k2 += mod2 * t;
}
k1 %= mod1;
ans = min( ans, k1 * ( X * 2 + Y * 2 ) + X + i );
}
if( ans == 1e32 ) printf( "infinity\n" );
else print( ans ), putchar( '\n' );
}
return 0;
} |
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("O3")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
const ll INF = (1LL<<60);
template<class T> bool chmin(T &a, const T &b){
if(a > b) {a = b; return true;}
else return false;
}
template<class T> bool chmax(T &a, const T &b){
if(a < b) {a = b; return true;}
else return false;
}
template <unsigned long long mod > class modint{
public:
ll x;
constexpr modint(){x = 0;}
constexpr modint(ll _x) : x((_x < 0 ? ((_x += (LLONG_MAX / mod) * mod) < 0 ? _x + (LLONG_MAX / mod) * mod : _x) : _x)%mod){}
constexpr modint set_raw(ll _x){
//_x in [0, mod)
x = _x;
return *this;
}
constexpr modint operator-(){
return x == 0 ? 0 : mod - x;
}
constexpr modint& operator+=(const modint& a){
if((x += a.x) >= mod) x -= mod;
return *this;
}
constexpr modint operator+(const modint& a) const{
return modint(*this) += a;
}
constexpr modint& operator-=(const modint& a){
if((x -= a.x) < 0) x += mod;
return *this;
}
constexpr modint operator-(const modint& a) const{
return modint(*this) -= a;
}
constexpr modint& operator*=(const modint& a){
(x *= a.x)%=mod;
return *this;
}
constexpr modint operator*(const modint& a) const{
return modint(*this) *= a;
}
constexpr modint pow(unsigned long long pw) const{
modint res(1), comp(*this);
while(pw){
if(pw&1) res *= comp;
comp *= comp;
pw >>= 1;
}
return res;
}
//以下、modが素数のときのみ
constexpr modint inv() const{
if(x == 2) return (mod + 1) >> 1;
return modint(*this).pow(mod - 2);
}
constexpr modint& operator/=(const modint &a){
(x *= a.inv().x)%=mod;
return *this;
}
constexpr modint operator/(const modint &a) const{
return modint(*this) /= a;
}
};
#define mod2 1000000007
using mint = modint<mod2>;
ostream& operator<<(ostream& os, const mint& a){
os << a.x;
return os;
}
using vm = vector<mint>;
mint fibo(int n, bool debug = false){
vector<vm> dp(2, vm(2, 0));
dp[0][0] = 1;
rep(i, n - 1){
dp[1][0] = dp[0][1];
dp[1][1] = dp[0][0] + dp[0][1];
swap(dp[0], dp[1]);
if(debug){
cout<<dp[0][0]<<' '<<dp[0][1]<<endl;
}
}
return dp[0][1];
}
int main(){
//fibo(6, true);
cin>>N;
char aa, ab, ba, bb;
cin>>aa>>ab>>ba>>bb;
if(N <= 3){
cout<<1<<endl;
}else{
if(ab == 'A'){
if(aa == 'A'){
cout<<1<<endl;
}else if(ba == 'A'){
cout<<fibo(N)<<endl;
}else{
cout<<mint(2).pow(N - 3)<<endl;
}
}else{
if(bb == 'B'){
cout<<1<<endl;
}else if(ba == 'A'){
cout<<mint(2).pow(N - 3)<<endl;
}else{
cout<<fibo(N)<<endl;
}
}
}
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll N; cin>>N;
vector<ll> A(N),B,C;
bool isOK=false;
for(ll i=0; i<N; ++i) {
cin>>A[i];
A[i]%=200;
}
// N<=8なら全て
// N>8なら先頭8個のみを全探索
vector<vector<ll>> group(200);
for(ll i=1; i<1ll<<min(8ll,N); ++i) {
bitset<8> bs=i;
ll val=0;
for(ll j=0; j<bs.size(); ++j) {
if(bs.test(j)) val=(val+A[j])%200;
}
group[val].push_back(i);
if(group[val].size()>=2) {
isOK=true;
bitset<8> x=group[val][0], y=group[val][1];
for(ll j=0; j<8; ++j) {
if(x.test(j)) B.push_back(j+1);
if(y.test(j)) C.push_back(j+1);
}
break;
}
}
if(isOK) {
cout<<"Yes"<<endl;
cout<<B.size()<<" ";
for(auto& e:B) cout<<e<<" ";
cout<<endl;
cout<<C.size()<<" ";
for(auto& e:C) cout<<e<<" ";
cout<<endl;
} else cout<<"No"<<endl;
}
|
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>
using namespace std;
int main(){
string s;
cin >> s;
if(s[0] == s[1] && s[1] == s[2]){
cout << "Won" << endl;
}
else{
cout << "Lost" << endl;
}
return 0;
} | // @iamnifer
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <stack>
#include <deque>
#include <queue>
#include <iomanip>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define uint unsigned int
#define elif else if
#define pb push_back
#define add insert
#define fastio cout.tie(nullptr); cin.tie(nullptr); ios_base::sync_with_stdio(false)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define str to_string
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
template<typename A, typename B>
inline bool umin(A &a, B b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<typename A, typename B>
inline bool umax(A &a, B b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template<typename T>
T binpow(T b, T e, T m) {
T r = 1;
while(e > 0) {
if(e & 1) r = r * b % m;
b = b * b % m;
e >>= 1;
}
return r;
}
inline void precision(int x) {
cout << fixed << setprecision(x);
}
template<typename T>
inline T gcd(T a, T b) {
return __gcd(a, b);
}
template<typename T>
inline T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template<typename T>
inline int len(T x) {
return int(x.size());
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll rand(ll l, ll r) {
return uniform_int_distribution<ll>(l, r)(rng);
}
string str(string &s) {
return "\"" + s + "\"";
}
template<typename A, typename B>
string str(pair<A, B> v) {
return str(v.first) + " " + str(v.second);
}
template<typename T>
string str(set<T>& v) {
string r, e;
for(auto &i: v) r += e + str(i), e = " ";
return r;
}
template<typename T>
string str(vector<T>& v) {
string r, e;
for(auto &i: v) r += e + str(i), e = " ";
return r;
}
void debug() {
cerr << "\n";
}
template<typename Head, typename...Tail>
void debug(Head H, Tail...T) {
cerr << " " << str(H);
debug(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define debug(...) 0
#endif
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,fma,sse4")
// #pragma comment(linker,"/STACK:128777216")
// #pragma GCC optimize("O3")
const ld pi = 3.14159265358979323846264338327950288419716939937510;
const ld eps = 1e-8;
const int inf = 1e9 + 9;
const ll MOD = 1e9 + 7; // 998244353
const int maxN = 2e5 + 9;
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
fastio;
char a, b, c;
string s; cin >> s;
a = s[0]; b = s[1]; c = s[2];
if(a == b && b == c) {
cout << "Won\n";
}
else cout << "Lost\n";
}
|
#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
char S[1000000], *i = S + 500000, *ato = i, *mae = ato, c;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
fread(i, 1, 500000, stdin);
int r = 0;
while ((c = *i++) >= 'R') {
if (c == 'R') r ^= 1;
else {
if (r) {
if (mae == ato || *mae != c) *--mae = c;
else mae++;
}
else {
if (mae == ato || *(ato - 1) != c) *ato++ = c;
else ato--;
}
}
}
if (r) reverse(mae, ato);
fwrite(mae, 1, ato - mae, stdout);
Would you please return 0;
} | /* #pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") */
// only when really needed
#include <bits/stdc++.h>
#define for1(i,a,b) for (int i = a; i <= b; i++)
#define for2(i,a,b) for (int i = a; i >= b; i--)
#define int long long
#define sz(a) (int)a.size()
#define PI 3.1415926535897932384626433832795
#define INF 8000000000000000000
#define MOD 1000000007
using namespace std;
signed main() {
int n,x;
string s;
cin >> n >> x;
cin >> s;
for1(i,0,n-1) {
if (s[i]=='o') x++;
else if (x>0) x--;
}
cout << x;
} |
/* SHUBHAM KESHARWANI */
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define fr(a,b) for(ll i=a;i<b;i++)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
int main()
{
fast;
//test
{
ll n,i,x,p=1,prev=0;
cin>>n;
set<ll>s;
for(i=0;i<n;i++)
{
cin>>x;
s.insert(x);
}
for(auto i:s)
{
p*=(i-prev+1);
p%=mod;
prev=i;
}
cout<<p;
cout<<'\n';
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int>
#define vp vector<pair<long long int ,long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define iter vector<int>::iterator
#define pa pair<long long int ,long long int>
#define f(a,b) for(int a=0;a<b;a++)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ll mul(ll a,ll b)
// {
// return (a%mod*b%mod)%mod;
// }
// ll add(ll a,ll b)
// {
// ll res=a+b;
// if(res>=mod)
// {
// res-=mod;
// }
// return res;
// }
// ll sub(ll a,ll b)
// {
// ll res=a-b;
// if(res<0)
// res+=mod;
// return res;
// }
// ll powmod(ll a, ll b)
// {
// ll res = 1;
// while (b) {
// if (b&1) {
// res =mul(res,a);
// }
// b >>= 1;
// a=mul(a,a);
// }
// return res;
// }
// ll modinv(ll a)
// {
// return powmod(a, mod - 2);
// }
// unordered_map<ll,ll>facti;
// ll fact(ll n)
// {
// if(n==0)return 1;
// if(n<=1)return 1;
// if(facti[n]!=0)return facti[n];
// return facti[n]=mul(n,fact(n-1));
// }
// ll ncr(ll n,ll r)
// {
// ll h=fact(n);
// ll v=fact(r);
// ll j=fact(n-r);
// v=mul(v,j);
// v=powmod(v,mod-2);
// return mul(h,v);
// }
// int fastread(){
// int x=0;
// int c = getchar_unlocked();
// while(c<48)
// c = getchar_unlocked();
// while(c>=48){
// x = x*10 + (c - 48);
// c = getchar_unlocked();
// }
// return x;
// }
// bool comp(pa a,pa b)
// {
// if(a.F==b.F)
// {
// return v[a.S]<v[b.S];
// }
// returna.S<b.S;
// }
vector<pa>g[1000001];
ll dp[1000001];
void dfs(ll v,ll par=-1)
{
for(pa d:g[v])
{
if(d.first-par)
{
dp[d.first]=dp[v]^d.second;
dfs(d.first,v);
}
}
}
void solve()
{
ll n;
cin>>n;
f(i,n-1)
{
ll x,y,w;
cin>>x>>y>>w;
x--,y--;
g[x].pb({y,w});
g[y].pb({x,w});
}
dfs(0);
ll ans=0;
f(j,60)
{
ll ones,zeros;
ones=zeros=0;
f(i,n)
{
if(dp[i]&(1ll<<j))
{
ones++;
}
else
{
zeros++;
}
}
zeros*=ones;
zeros%=mod;
ans+=((1ll<<j)%mod*zeros%mod);
ans%=mod;
}
cout<<ans<<endl;
}
int main() {
fast;
fast_input;
fast_output;
// ll t;
// cin>>t;
// while(t--)
// {
solve();
// }
return 0;
} |
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << '(' << p.first << ',' << p.second << ')';
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << '{';
for(int i = 0; i < (int)v.size(); i++) {
if(i) { os << ','; }
os << v[i];
}
os << '}';
return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
cerr << " " << x;
debugg(args...);
}
#define debug(...) \
cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = (1<<30)-1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-9;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
if(a>b){
a = b; return true;
}
else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
if(a<b){
a = b; return true;
}
else return false;
}
template<typename T> inline void print(T &a){
int sz = a.size();
for(auto itr = a.begin(); itr != a.end(); itr++){
cout << *itr;
sz--;
if(sz) cout << " ";
}
cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;
ll fib[105];
int p[105];
int main(){
ll n; cin >> n;
ll N = n;
fib[0] = fib[1] = 1;
rep(i,100){
fib[i+2] = fib[i] + fib[i+1];
if(fib[i+2] > 1e18 + 100) break;
}
int mx = 0;
for(int i=87; i>=0; i--){
if(n >= fib[i]){
p[i] = 1;
chmax(mx,i);
n -= fib[i];
}
}
vl ans;
ll x = 0, y = 0;
for(int i=mx; i>=0; i--){
if(i & 1 ^ 1){
if(p[i]) x++, ans.push_back(1);
y = x + y;
ans.push_back(4);
}else{
if(p[i]) y++, ans.push_back(2);
x = x + y;
ans.push_back(3);
}
}
assert(x == N);
cout << ans.size() << "\n";
for(auto v : ans) cout << v << "\n";
//debug(x,y,ans.size());
} | #include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
int num[15] = {0};
for(int i = 0; i < s.length(); i++)
{
num[(s[i]-'0')]++;
}
int ans = 0;
if(s.length() == 1)
{
if((s[0]-'0') == 8) ans = 1;
}
if(s.length() == 2)
{
int a = s[0] - '0';
int b = s[1] - '0';
if((a*10+b)% 8 == 0) ans = 1;
if((b*10+a) % 8 == 0) ans = 1;
}
for(int i = 8; i <= 999; i += 8)
{
int need[15] = {0};
int a = i % 10,b = (i / 10) % 10, c = i / 100;
need[a]++;
need[b]++;
need[c]++;
if(num[a] >= need[a] && num[b] >= need[b] && num[c] >= need[c]) ans = 1;
}
if(!ans)
{
cout << "No" << endl;
return 0;
}
else cout << "Yes" << endl;
return 0;
} |
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
int n, m;
vector<vector<pair<int, int> > > v;
vector<pair<int, int> > h;
vector<int> ans;
vector<int> c;
void dfs(int now){
all(to, v[now]) if(!ans[to.second]){
ans[to.second] = (h[to.second].first == now ? 1 : -1);
dfs(to.first);
}
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
v.resize(n);
c.resize(n);
ans.resize(m, 0);
rep(i, m){
int a, b;
cin >> a >> b;
a--; b--;
h.push_back({a, b});
v[a].push_back({b, i});
v[b].push_back({a, i});
}
rep(i, n) cin >> c[i];
rep(i, n) all(to, v[i]) if(c[to.first] > c[i]) ans[to.second] = (h[to.second].first == i ? -1 : 1);
rep(i, n){
vector<int> s;
all(to, v[i]) if(!ans[to.second] && c[i] == c[to.first]) s.pb(to.second);
int maki = s.size();
rep(to, maki){
if(to == maki - 1) {
if(h[s[to]].first == i){
ans[s[to]] = 1;
dfs(h[s[to]].second);
}else{
ans[s[to]] = -1;
dfs(h[s[to]].first);
}
}else ans[s[to]] = (h[s[to]].first == i ? -1 : 1);
}
}
rep(i, m) cout << (ans[i] == 1 ? "->" : "<-") << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<vector<int>> graph(N, vector<int>(N, 0));
vector<array<int, 2>> edges(M);
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
--a; --b;
++graph[a][b];
++graph[b][a];
edges[i] = {a, b};
}
vector<int> c(N);
for (int i = 0; i < N; i++) cin >> c[i];
vector<bool> used(N, false);
for (int i = 0; i < N; i++) {
stack<array<int, 2>> s;
vector<bool> candidate(N, false);
if (!used[i]) {
s.push({i, -1});
candidate[i] = true;
}
while (s.size()) {
auto [node, parent] = s.top();
bool exists = false;
for (int next = 0; next < N; next++) {
if (!graph[node][next] || used[next] || candidate[next]) continue;
if (c[node] == c[next]) {
exists = true;
candidate[node] = true;
s.push({next, node});
break;
}
}
if (!exists) {
if (parent >= 0) {
graph[node][parent] = 0;
}
for (int next = 0; next < N; next++) {
if (!graph[node][next] || used[next]) continue;
if (c[node] == c[next]) graph[next][node] = 0;
}
used[node] = true;
s.pop();
}
}
for (int j = 0; j < N; j++) {
if (!graph[i][j]) continue;
if (c[i] > c[j]) {
graph[j][i] = 0;
} else if (c[i] < c[j]) {
graph[i][j] = 0;
}
}
}
for (int i = 0; i < M; i++) {
if (graph[edges[i][0]][edges[i][1]]) cout << "->" << endl;
else if (graph[edges[i][1]][edges[i][0]]) cout << "<-" << endl;
else exit(1);
}
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
ll powe(ll a, ll b){//aのb乗のmod
ll ret = 1;
while(0 < b){
if((b%2) == 0){
a = (a*a);
b >>= 1;
}
else{
ret = (ret*a);
b--;
}
}
return ret;
}
int main(){
string s, t, u; cin >> s >> t >> u;
vector<ll> cl(26,0);
vector<ll> hl(26,0);
REP(i,s.length()) {
if (i==0) hl[s[i]-'a']=1;
cl[s[i]-'a']=1;
}
REP(i,t.length()) {
if (i==0) hl[t[i]-'a']=1;
cl[t[i]-'a']=1;
}
REP(i,u.length()) {
if (i==0) hl[u[i]-'a']=1;
cl[u[i]-'a']=1;
}
ll cnter = 0;
REP(i,26) if (cl[i]==1) cnter++;
if (cnter>10) {
cout << "UNSOLVABLE" << endl;
return 0;
}
ll ind = 0;
REP(i,26) {
if (cl[i]) {
cl[i]=ind;
ind++;
}
else {
cl[i]=-1;
}
}
vector<ll> keisu(26,0);
ll ss = s.length(); ll tt = t.length(); ll uu = u.length();
REP(i,s.length()) keisu[s[i]-'a']+=powe(10,ss-1-i);
REP(i,t.length()) keisu[t[i]-'a']+=powe(10,tt-1-i);
REP(i,u.length()) keisu[u[i]-'a']-=powe(10,uu-1-i);
vector<ll> digits = {0,1,2,3,4,5,6,7,8,9};
do {
ll val = 0;
bool jud = true;
REP(i,26){
if (hl[i]==1 && digits[cl[i]]==0) jud = false;
}
if (jud==false) continue;
REP(i,26) {
if (cl[i]==-1) continue;
val+=digits[cl[i]]*keisu[i];
}
if (val==0) {
// REP(i,26) cout << keisu[i] << " ";
// cout << endl;
// REP(i,26) cout << cl[i] << " ";
// cout << endl;
// REP(i,26) cout << digits[cl[i]] << " ";
// cout << endl;
// REP(i,26) cout << hl[i] << " ";
// cout << endl;
vector<char> charl(26,'0');
REP(i,26) {
if (cl[i]!=-1) charl[i]+=digits[cl[i]];
}
REP(i,ss) s[i]=charl[s[i]-'a'];
REP(i,tt) t[i]=charl[t[i]-'a'];
REP(i,uu) u[i]=charl[u[i]-'a'];
cout << s << endl;
cout << t << endl;
cout << u << endl;
return 0;
}
} while (next_permutation(digits.begin(),digits.end()));
cout << "UNSOLVABLE" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(a,b) for(long long a = 0;a < b;++a)
using ld = long double;
unsigned long xor128() {
static unsigned long x=time(NULL), y=362436069, z=521288629, w=88675123;
unsigned long t=(x^(x<<11));
x=y; y=z; z=w;
return ( w=(w^(w>>19))^(t^(t>>8)) );
}
typedef struct Sponsor{
int x;
int y;
int area;
} Sponsor;
typedef struct AD{
int x;
int y;
int dx;
int dy;
Sponsor sponsor;
} AD;
inline bool check_intersect(AD a,AD b){
bool ans = (min(a.x,b.x) <= max(a.x,b.x) and max(a.x,b.x) < min(a.x+a.dx,b.x + b.dx));
ans &= (min(a.y,b.y) <= max(a.y,b.y) and max(a.y,b.y) < min(a.y+a.dy,b.y + b.dy));
return ans;
}
bool validate(vector<AD> inputs){
for(int i = 0;i < inputs.size();++i){
if(inputs[i].x + inputs[i].dx > 10000 or inputs[i].y + inputs[i].dy > 10000) return false;
for(int q = i+1;q < inputs.size();++q){
if(check_intersect(inputs[i],inputs[q]) == true) return false;
}
}
return true;
}
ld scoring(vector<AD> inputs,ld border){
ld ans = 0;
for(int i = 0;i < inputs.size();++i){
if(inputs[i].x <= inputs[i].sponsor.x and inputs[i].sponsor.x < inputs[i].x + inputs[i].dx
and inputs[i].y <= inputs[i].sponsor.y and inputs[i].sponsor.y < inputs[i].y + inputs[i].dy){
ld real_area = inputs[i].dx * inputs[i].dy;
ld expected_area = inputs[i].sponsor.area;
ans += 1.0L - abs(border - pow(1 - min(real_area,expected_area)/max(real_area,expected_area),2.0));
}else return -1;
}
ans /= (ld)inputs.size();
return ans;
}
int main(){
int n;
cin >> n;
vector<AD> inputs;
REP(i,n){
int a,b,c;
cin >> a >> b >> c;
inputs.push_back(AD{a,b,1,1,Sponsor{a,b,c}});
}
ld now_score = scoring(inputs,0);
for(int i = 0;i < 3000000;++i){
int target = xor128() % inputs.size();
AD tmp = inputs[target];
int dir = xor128() % 8;
if(i % 20000 != 0){
if(dir == 0){
inputs[target].dx += 1;
}else if(dir == 1){
inputs[target].dy += 1;
}else if(dir == 2){
inputs[target].x -= 1;
inputs[target].dx += 1;
}else if(dir == 3){
inputs[target].y -= 1;
inputs[target].dy += 1;
}else if(dir == 4){
inputs[target].x += 1;
}else if(dir == 5){
inputs[target].y += 1;
}else if(dir == 6){
inputs[target].x -= 1;
}else if(dir == 7){
inputs[target].y -= 1;
}
}
bool ok = true;
for(int q = 0;q < inputs.size();++q){
if(q != target and check_intersect(inputs[q],inputs[target]) == true){
ok = false;
}
}
if(inputs[target].dx <= 0 or inputs[target].dy <= 0 or inputs[target].x < 0 or inputs[target].y < 0) ok = false;
if(inputs[target].x + inputs[target].dx > 10000 or inputs[target].y + inputs[target].dy > 10000) ok = false;
ld score = 0;
int hoge = (ld)(3000000.0 - i) / 300000.0;
ld prob = hoge / 10.0;
prob *= prob;
score = scoring(inputs,prob) + (1.00L - prob);
if(ok and score >= now_score){
now_score = score;
}else{
inputs[target] = tmp;
}
}
for(int i = 0;i < n;++i){
cout << inputs[i].x << " " << inputs[i].y << " " << inputs[i].x + inputs[i].dx << " " << inputs[i].y + inputs[i].dy << endl;
}
} |
// Siddhant Dugar
#include<bits/stdc++.h>
#include<string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, a, b) for(int i = (a); i <=(b); ++i)
#define REPD(i, a, b) for(int i = (a); i >=(b); --i)
#define TR(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define RESET(a, v) memset(a, (v), sizeof(a))
#define SZ(a) (int(a.size()))
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define II pair<int, int>
#define X first
#define Y second
#define VI vector<int>
#define VII vector<II>
#define endl '\n'
#define ll long long int
#define mod 1000000007
#define mk(arr,n,type) type*arr=new type[n];
using namespace std;
void cpc()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen ("output.txt", "w", stdout);
#endif
}
long int gcd(long int a, long int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int main() {
cpc();
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int x, y;
cin >> x;
cin >> y;
if (abs(x - y) < 3)cout << "Yes";
else cout << "No";
return 0;
} | #include<iostream>
using namespace std;
int main(){
int X, Y;
cin >> X >> Y;
if (X + 3 > Y && Y + 3 > X) {
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
return 0;
} |
/**
* author: shu8Cream
* created: 02.05.2021 10:37:54
**/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using P = pair<ll,ll>;
using vi = vector<double>;
using vvi = vector<vi>;
int n;
double D,H;
bool check(double mid, vi &d, vi & h){
rep(i,n){
if((h[i]-mid)*D>(H-mid)*d[i]) return false;
}
return true;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> n >> D >> H;
vi d(n),h(n);
rep(i,n) cin >> d[i] >> h[i];
double ok = 0.0, ng = 10000.0;
int loop = 100;
while(loop--){
double mid = (ok + ng) / 2.0;
if(check(mid,d,h)) ng = mid;
else ok = mid;
}
printf("%.10lf\n", ok);
} | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define Mp make_pair
#define pb push_back
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
mt19937 mrand(time(0));
#define debug(...) fprintf(stderr, __VA_ARGS__)
ll get(ll r) { return ((ll)mrand() * mrand() % r + r) % r; }
ll get(ll l, ll r) { return get(r - l + 1) + l; }
int n, D, H; db ans;
signed main() {
scanf("%d %d %d", &n, &D, &H);
for(int i = 1; i <= n; i++) {
int d, h; scanf("%d %d", &d, &h);
// y = (H - h) / (D - d) * (x - D) + H
// x = 0 ==> y = (H - h) / (D - d) * (0 - D) + H
ans = max(ans, 1. * (H - h) / (D - d) * (0 - D) + H);
}
printf("%.10f\n", ans);
debug("time=%.4f\n", (db)clock()/CLOCKS_PER_SEC);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define ll long long int
#define sd(x) scanf("%lld",&x)
#define sdi(x) scanf("%d",&x)
#define sdc(c) scanf("%c",&c)
#define inf 1000000000000000000ll
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define bits(x) __builtin_popcountll(x)
#define ld long double
#define test() ll test; cin>>test; while(test--)
#define fi first
#define se second
#define all(x) x.begin(),x.end()
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
clock_t time_p = clock();
void time_taken()
{
time_p = clock() - time_p;
cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
inline ll GCD(ll x, ll y) {
if(x<y) swap(x,y);
if(x==0) return y;
if(y==0) return x;
return GCD(x%y,y);
}
ll phi(ll n) {
ll result = n;
for (ll i = 2; i * i <= n; i++) {
if(n % i == 0) {
while(n % i == 0)
n /= i;
result -= result / i;
}
}
if(n > 1)
result -= result / n;
return result;
}
ll power(ll x, ll n, ll mod) {
ll res = 1;
x %= mod;
while(n) {
if(n&1) {
res = ((res*x)%mod+mod)%mod;
}
x = ((x*x)%mod+mod)%mod;
n>>=1;
}
return res;
}
const int MOD = 998244353;
inline ll add(ll x, ll y, ll MOD) {
x %= MOD;
y %= MOD;
ll ans = (x+y)%MOD;
return ans;
}
inline ll mul(ll x,ll y, ll MOD) {
x %= MOD;
y %= MOD;
ll ans = ((x*y)%MOD+MOD)%MOD;
return ans;
}
int main() {
fastio;
ll N,M,K;
cin>>N>>M>>K;
if(N==1) {
ll ans = power(K,M,MOD);
cout<<ans<<endl;
return 0;
}
if(M==1) {
ll ans = power(K,N,MOD);
cout<<ans<<endl;
return 0;
}
ll ans = 0;
for(ll i=1;i<=K;i++) {
ll fst = add(power(i,N,MOD),-power(i-1,N,MOD)+MOD,MOD);
ll snd = power(K-i+1,M,MOD);
ans = add(ans,mul(fst,snd,MOD),MOD);
}
cout<<ans<<endl;
time_taken();
}
| // main.cpp
// ervb
//
// Created by Kanak Gautam on 21/04/20.
// Copyright © 2020 Kanak Gautam. All rights reserved.
//
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <utility>
#define pb push_back
#define mk make_pair
#define endl "\n"
#define mod 998244353
#define mod1 1610612741
#define mul 31
#define PI 3.14159265358979323846264
using namespace std;
typedef long long int lli;
typedef double ld;
typedef pair<lli,lli> ii;
priority_queue <lli, vector<lli>, greater<lli> > ti;
//priority_queue<pair<lli,pair<lli,lli>>>e;
vector <lli> p[200005],a(2000005),f(200005,1e18),d(200005,0),b(1000005);
//vector<set<lli>>s(200005);
//set<pair<lli,lli>>s;
//vector<vector<lli>>dp(5005,vector<lli>(5005,-1));
//lli b[1000005],l[1000005];
//vector<vector<lli>> d(300005,vector<lli>(18,0));
//vector<pair<lli,ii>>p[300005];
map<pair<lli,lli>,lli>mp;
//vector<pair<pair<lli, lli>,lli> > st;
//map<lli,lli> np;
//queue<lli> qy;
lli gcd(lli a, lli b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
lli bpow(lli a, lli b) {
lli res = 1;
while (b > 0) {
if (b & 1)
res = (res * a)%mod;
a = (a * a)%mod;
b >>= 1;
}
return res%mod;
}
void fact(lli i)
{
f[0]=1;
for(lli k=1;k<=i;k++)
{
(f[k]=f[k-1]*k)%=mod;
}
}
lli isprime(lli n)
{
if(n==1)
return 0;
for(lli i=2;i<=sqrt(n);i++)
if(n%i==0)
return 0;
return 1;
}
lli find(lli x)
{
if(f[x]==x)
return x;
else
return f[x]=find(f[x]);
}
bool cmp(lli x,lli y)
{
return x<y;
}
/*lli comb(lli i,lli j)
{
if(j>i)return 0;
lli k=f[i];
lli g=(f[j]*(f[i-j]))%mod;
lli h=bpow(g,mod-2);
return (k*h)%mod;
}*/
/*void sieve()
{
for(lli i=2;i<=sqrt(10000000);i++)
{
if(b[i]==0)
{
k.pb(i);
for(lli j=2;i*j<=sqrt(10000000);j++)
{
b[i*j]=1;
}
}
}
}*/
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli n,m,k;
cin>>n>>m>>k;
lli ans=0;
if(n==1 or m==1)
{
ans=bpow(k,max(n,m));
cout<<ans<<endl;
exit(0);
}
for(lli i=1;i<=k;i++)
{
lli h=(bpow(i,n)-bpow(i-1,n)+mod)%mod;
lli g=bpow(k-i+1,m);
ans+=(h*g)%mod;
ans%=mod;
//cout<<" "<<h<<" "<<g<<endl;
}
cout<<ans<<endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define A(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNI(x) sort(A(x)); (x).erase(unique(A(x)),(x).end())
#define int int64_t
void _read();
const int INF = 3e17 + 9847;
main () { _read();
int n,m;
cin >> n >> m;
int src,des;
cin >> src >> des;
vector<vector<tuple<int,int,int>>> adj(n + 1);
while(m--) {
int a,b,T,K;
cin >> a >> b >> T >> K;
adj[a].emplace_back(b,T,K);
adj[b].emplace_back(a,T,K);
}
// The parameter really is just the extra time.
//? Say you are now at time t, to get to the next edge to must add and extra time oh Yeah that fixes stuff.
//! Simple DIJKSTRA. --_(^_^)_--
vector<int> dis(n + 1,INF);
// Because distance is time!!
dis[src] = 0;
set<pair<int,int>> sp;
sp.emplace(0,src);
while(!sp.empty()) {
auto [d,u] = * sp.begin();
sp.erase(sp.begin());
for(auto &[v,t,k] : adj[u]) {
int d_now = ((d + k - 1) / k) * k + t;
if(dis[v] > d_now) {
if(dis[v] != INF) {
sp.erase(sp.find({dis[v],v}));
}
dis[v] = d_now;
sp.emplace(d_now,v);
}
}
}
cout << (dis[des] == INF ? -1 : dis[des]) << '\n';
return 0;
};
void _read() {
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
#ifdef LOCAL
freopen("input.txt","r",stdin);
#endif
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;
vector<ll> fac;
void c_fac(ll x=pow(10,7)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }
struct query {
ll T, X, Y;
};
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
struct SegTree {
ll size;
vector<ll> pos;
SegTree(ll N) { size = 1; while(size<N) size<<=1; pos.resize(2*size,0); }
ll operator[](const ll &x) const { return pos[x+size]; }
void set(ll x, const ll v) { pos[x+size] = v; }
void update(ll x, const ll v) { set(x,v); x+=size; while (x>>=1) operate(x); }
ll query(ll a, ll b) {
ll L = 0, R = 0;
for (a+=size, b+=size; a<b; a>>=1, b>>=1) {
if (a&1) { L = q(L,pos[a]); a++; }
if (b&1) { b--; R = q(pos[b],R); }
}
return q(L,R);
}
void operate(ll i) { pos[i] = q(pos[i*2], pos[i*2+1]); }
ll q(ll x, ll y) { return x^y; }
};
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
int main() {
ll N, Q; cin >> N >> Q;
ll A[N]; rep(i,N) cin >> A[i];
query q[Q]; rep(i,Q) cin >> q[i].T >> q[i].X >> q[i].Y;
SegTree st(N); rep(i,N) st.update(i,A[i]);
rep(i,Q) {
if (q[i].T==1) {
q[i].X--;
st.update(q[i].X,st[q[i].X]^q[i].Y);
}
else {
q[i].X--;
ll result = st.query(q[i].X,q[i].Y);
cout << result << endl;
}
}
return 0;
} |
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int h[33][33];
int v[33][33];
int main() {
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 30; j++) {
h[i][j] = 5000;
}
}
for (int i = 0; i < 1000; i++) {
int sx, sy, gx, gy, score;
cin >> sx >> sy >> gx >> gy;
pair<int,int> prev[33][33];
int dist[33][33];
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 30; j++) {
dist[i][j] = 1000000007;
}
}
bool bo[33][33] = { true };
priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> que;
que.push(make_tuple(0, sx, sy));
bo[sx][sy] = true;
dist[sx][sy] = 0;
while (!que.empty()) {
tuple<int, int, int> t = que.top();
int x = get<0>(t);
int y = get<1>(t);
int z = get<2>(t);
que.pop();
if (y == gx && z == gy)break;
if (dist[y][z] < x)continue;
if (y != 29) {
if (dist[y + 1][z] > dist[y][z] + h[y][z]) {
dist[y + 1][z] = dist[y][z] + h[y][z];
prev[y + 1][z] = make_pair(y, z);
que.push(make_tuple(dist[y][z] + h[y][z], y + 1, z));
}
}
if (y != 0) {
if (dist[y - 1][z] > dist[y][z] + h[y - 1][z]) {
dist[y - 1][z] = dist[y][z] + h[y - 1][z];
prev[y - 1][z] = make_pair(y, z);
que.push(make_tuple(dist[y][z] + h[y - 1][z], y - 1, z));
}
}
if (z != 29) {
if (dist[y][z + 1] > dist[y][z] + v[y][z]) {
dist[y][z + 1] = dist[y][z] + v[y][z];
prev[y][z + 1] = make_pair(y, z);
que.push(make_tuple(dist[y][z] + v[y][z], y, z + 1));
}
}
if (z != 0) {
if (dist[y][z - 1] > dist[y][z] + v[y][z - 1]) {
dist[y][z - 1] = dist[y][z] + v[y][z - 1];
prev[y][z - 1] = make_pair(y, z);
que.push(make_tuple(dist[y][z] + v[y][z - 1], y, z - 1));
}
}
}
int nx = gx, ny = gy, co = 0;
vector<tuple<int, int, int>> edge;
string ans = "";
while (nx != sx || ny != sy) {
if (nx - prev[nx][ny].first == 1) {
ans += 'D';
edge.emplace_back(make_tuple(0, prev[nx][ny].first, prev[nx][ny].second));
}
if (nx - prev[nx][ny].first == -1) {
ans += 'U';
edge.emplace_back(make_tuple(0, nx, ny));
}
if (ny - prev[nx][ny].second == 1) {
ans += 'R';
edge.emplace_back(make_tuple(1, prev[nx][ny].first, prev[nx][ny].second));
}
if (ny - prev[nx][ny].second == -1) {
ans += 'L';
edge.emplace_back(make_tuple(1, nx, ny));
}
int nx1 = nx;
nx = prev[nx][ny].first;
ny = prev[nx1][ny].second;
co++;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
cin >> score;
if (score < 5000 * co) {
for (int j = 0; j < co; j++) {
tuple<int, int, int> t = edge[j];
int x = get<0>(t);
int y = get<1>(t);
int z = get<2>(t);
if (x) {
h[y][z] = 4999;
}
else {
v[y][z] = 4999;
}
}
}
else if (score > 5000 * co) {
for (int j = 0; j < co; j++) {
tuple<int, int, int> t = edge[j];
int x = get<0>(t);
int y = get<1>(t);
int z = get<2>(t);
if (x) {
h[y][z] = 5001;
}
else {
v[y][z] = 5001;
}
}
}
}
}
| #include<bits/stdc++.h>
#define y1 qwq
using namespace std;
const int maxn=35;
int x1,y1,x2,y2;
int f[maxn][maxn];
int tol[maxn][maxn];
int tod[maxn][maxn];
int sum[maxn][maxn];
double v[maxn][maxn];
char p[maxn][maxn];
string s;
void dfs(int x,int y) {
if(x==x1&&y==y1) {
return ;
}
if(p[x][y]=='U') {
dfs(x+1,y);
} else if(p[x][y]=='D') {
dfs(x-1,y);
} else if(p[x][y]=='L') {
dfs(x,y+1);
} else {
dfs(x,y-1);
}
// cout<<p[x][y];
s+=p[x][y];
}
void dfs2(int x,int y,int k) {
if(x==x1&&y==y1) {
return ;
}
if(p[x][y]=='U') {
dfs2(x+1,y,k);
} else if(p[x][y]=='D') {
dfs2(x-1,y,k);
} else if(p[x][y]=='L') {
dfs2(x,y+1,k);
} else {
dfs2(x,y-1,k);
}
if(!v[x][y]) {
v[x][y]=k;
} else {
v[x][y]=(v[x][y]+k)/1;
}
}
string query() {
memset(f,0x3f,sizeof(f));
memset(p,0,sizeof(p));
f[x1][y1]=0;
s="";
if(x1<=x2&&y1<=y2) {
for(int i=x1; i<=x2; i++) {
for(int j=y1; j<=y2; j++) {
if(i==x1&&j==y1) {
continue;
}
if(f[i-1][j]<f[i][j-1]) {
f[i][j]=f[i-1][j]+v[i][j];
p[i][j]='D';
} else {
f[i][j]=f[i][j-1]+v[i][j];
p[i][j]='R';
}
}
}
} else if(x1>=x2&&y1<=y2) {
for(int i=x1; i>=x2; i--) {
for(int j=y1; j<=y2; j++) {
if(i==x1&&j==y1) {
continue;
}
if(f[i+1][j]<f[i][j-1]) {
f[i][j]=f[i+1][j]+v[i][j];
p[i][j]='U';
} else {
f[i][j]=f[i][j-1]+v[i][j];
p[i][j]='R';
}
}
}
} else if(x1>=x2&&y1>=y2) {
for(int i=x1; i>=x2; i--) {
for(int j=y1; j>=y2; j--) {
if(i==x1&&j==y1) {
continue;
}
if(f[i+1][j]<f[i][j+1]) {
f[i][j]=f[i+1][j]+v[i][j];
p[i][j]='U';
} else {
f[i][j]=f[i][j+1]+v[i][j];
p[i][j]='L';
}
}
}
} else {
for(int i=x1; i<=x2; i++) {
for(int j=y1; j>=y2; j--) {
if(i==x1&&j==y1) {
continue;
}
if(f[i-1][j]<f[i][j+1]) {
f[i][j]=f[i-1][j]+v[i][j];
p[i][j]='D';
} else {
f[i][j]=f[i][j+1]+v[i][j];
p[i][j]='L';
}
}
}
}
dfs(x2,y2);
return s;
}
int compute_path_length(string s) {
int x=x1,y=y1,ans=0;
for(int i=0; i<s.length(); i++) {
if(s[i]=='D') {
ans+=tod[x][y];
x++;
} else if(s[i]=='L') {
ans+=tol[x][y-1];
y--;
} else if(s[i]=='R') {
ans+=tol[x][y];
y++;
} else {
ans+=tod[x-1][y];
x--;
}
}
return ans;
}
int main() {
// freopen("d.in","r",stdin);
// freopen("d.out","w",stdout);
int LOCAL_TEST=0;
if (LOCAL_TEST) {
// read_h_v();
for(int i=1; i<=30; i++) {
for(int j=1; j<=29; j++) {
cin>>tol[i][j];
}
}
for(int i=1; i<=29; i++) {
for(int j=1; j<=30; j++) {
cin>>tod[i][j];
}
}
}
double prev_result = 0;
double score = 0.0;
for (int k = 0; k < 1000; k++) {
double a,e;
if (LOCAL_TEST) {
// read_s_t_a_e();
cin>>x1>>y1>>x2>>y2>>a>>e;
} else {
cin>>x1>>y1>>x2>>y2;
}
x1++,y1++,x2++,y2++;
string path = query();
// print(path);
cout<<path<<"\n";
fflush(stdout);
if (LOCAL_TEST) {
double b = compute_path_length(path);
score = score * 0.998 + a / b;
prev_result = round(b * e);
} else {
cin>>prev_result;
}
dfs2(x2,y2,prev_result/(abs(x1-x2)+abs(y1-y2)));
}
if (LOCAL_TEST) {
cout<<(int)round(2312311 * score);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;
ll d[2222][2222];
void Main() {
ll n,m;
cin >> n >> m;
vector<ll> v[n];
rep(i,m) {
ll x,y;
cin >> x >> y;
x--,y--;
v[x].pb(y);
}
rep(k,n) {
fill(d[k],d[k]+n,MAX);
d[k][k]=0;
queue<ll> que;
que.push(k);
while(!que.empty()) {
ll x=que.front();que.pop();
rep(i,v[x].size()) {
ll y=v[x][i];
if(d[k][y]!=MAX) continue;
d[k][y]=d[k][x]+1;
que.push(y);
}
}
}
ll ans=0;
rep(i,n) {
rep(j,n) {
if(d[i][j]<MAX) ans++;
}
}
pr(ans);
}
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
| #include <bits/stdc++.h>
using namespace std;
#define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define nl '\n'
/**-------Library-------*/
#define mem(a,b) memset(a,b,sizeof(a))
#define all(a) a.begin(),a.end()
#define Sort(x) sort(x.begin(),x.end())
#define SortR(x) sort(x.begin(),x.end(),greater<int>())
#define Reverse(x) reverse(x.begin(),x.end())
#define Sum(A,n) accumulate(A,A+n,0)
#define SortA(ar,s) sort(ar,ar+s)
#define SortD(ar,s) sort(ar,ar+s,greater<int>())
#define maxa(A,n) *max_element(A,A+n)
#define mina(A,n) *min_element(A,A+n)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sq(x) (x)*(x)
#define mid(l,r) (l+(r-l)/2)
#define trzero(x) __builtin_ctz(x)
#define parity(x) __builtin_parity(x)
#define countone(x) __builtin_popcount(x)
#define left(p) (p<<1)
#define right(p) (p>>1)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define pb(x) push_back(x)
#define mod 1000000007
#define precision(x) cout<<fixed<<setprecision(x)
#define nel cout<<nl
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl
/**----------Graph Moves----------*/
const int fx[] = {+1,-1,+0,+0}; // 4 X directions
const int fy[] = {+0,+0,+1,-1}; // 4 Y directions
const int fx8[] = {+0,+0,+1,-1,-1,+1,-1,+1}; // King X Moves
const int fy8[] = {-1,+1,+0,+0,+1,+1,-1,-1}; // King Y Moves
const int kx[] = {-2, -2, -1, -1, 1, 1, 2, 2}; // Knight X Moves
const int ky[] = {-1, 1, -2, 2, -2, 2, -1, 1}; // Knight Y Moves
/**----data type----*/
typedef long long int ll;
typedef unsigned long long int llu;
int main()
{
int a,b;
cin>>a>>b;
if(a==b)
cout<<a<<nl;
else
{
cout<<3-(a+b)<<nl;
}
return 0;
}
|
#pragma region HEAD
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define EMIT(s) std::cout << (s) << std::endl
#define ANSWER(b) EMIT((b) ? "Yes" : "No")
#define SCREAM(b) EMIT((b) ? "YES" : "NO")
#define WHISPR(b) EMIT((b) ? "yes" : "no")
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
using namespace std;
using ll = long long;
int solve();
int main()
{
#ifdef DEBUG_MODE
ifstream in("input.dat");
cin.rdbuf(in.rdbuf());
#else
ios::sync_with_stdio(false);
cin.tie(nullptr);
#endif
solve();
return 0;
}
#pragma endregion
int solve()
{
int n;
cin>>n;
vector<ll> an(n);
REP(i,n){
cin>>an[i];
}
set<ll> s;
REP(i,n){
s.insert(an[i]);
}
while(s.size()>1){
auto maxi = *s.rbegin();
auto mini = *s.begin();
s.erase(maxi);
s.insert(maxi-mini);
}
cout<<*s.begin()<<endl;
return 0;
}
| #include<bits/stdc++.h>
#define int long long int
using namespace std;
#define md 1000000007
int32_t main()
{
int n;
cin>>n;
int a[n];
multiset<int>s;
for(int i=0;i<n;i++){cin>>a[i];s.insert(a[i]);}
int ans=a[0];
for(int i=1;i<n;i++)ans=__gcd(ans,a[i]);
cout<<ans<<endl;
}
|
#include <iostream>
using namespace std;
int main(){
long int N; cin >> N;
long int sum = 0;
int day = 0;
do{
sum += day++;
}while(sum < N);
cout << day-1 << endl;
return 0;
} | #include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;
#define FOR(i,j,k) for(int i=j; i<=k; ++i)
inline int read (void) {
int x = 0, 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;
}
int n, ans, a[25];
void dfs (int x, int Xor, int Or) {
if(x > n) {
ans = min(ans, Xor ^ Or);
return ;
}
dfs (x+1, Xor, Or | a[x]);
dfs (x+1, Xor ^ Or, a[x]);
}
int main (void) {
n = read(); ans = (1 << 31) - 1;
FOR(i,1,n) a[i] = read();
dfs (1, 0, 0);
printf("%d\n", ans);
return 0;
} |
/*
これを入れて実行
g++ code.cpp
./a.out
*/
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long INF = 1LL << 61;
const ll MOD = 1e9 + 7;
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
return f.second > s.second;
}
ll gcd(ll a, ll b){
if (b == 0)return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b){
return a / gcd(a, b) * b;
}
ll conbinationMemo[201][12];
void cmemoInit(){
rep(i, 201){
rep(j, 12){
conbinationMemo[i][j] = -1;
}
}
}
ll nCr(ll n, ll r){
if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
if(r == 0 || r == n){
return 1;
} else if(r == 1){
return n;
}
return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
ll nPr(ll n, ll r){
r = n - r;
ll ret = 1;
for (ll i = n; i >= r + 1; i--) ret *= i;
return ret;
}
//-----------------------ここから-----------
int main(void){
ll n, m;
cin >> n >> m;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector<ll> mp(n, 0);
rep(i, m){
mp[a[i]]++;
}
ll ans = n;
rep(i, n){
if(mp[i] == 0) ans = min(ans, (ll)i);
}
for(ll i = m; i < n; i++){
mp[a[i]]++;
mp[a[i - m]]--;
if(mp[a[i - m]] == 0) ans = min(ans, a[i - m]);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define full(a) memset(a, 0x3f, sizeof(a))
#define fornext(x, i) for(int i = head[x], y = ver[i]; i; i = nxt[i], y = ver[i])
#define mset(a, b) memset(a, b, sizeof(a))
#define Rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define dRep(i, a, b) for(int i = (a); i >= (b); --i)
#define IOset(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout);
#define endl '\n'
#define int ll
#define un unsigned
#define ll long long
#define db double
#define rept cerr<<1.0*clock()/CLOCKS_PER_SEC<<endl;
#define dbg cout<<"c "
template<typename _T> inline void prt(_T _d) { cerr<<_d<<' '; }
template <typename _T,typename ...Args> inline void prt(_T _d,Args ..._a) { prt(_d), prt(_a...), putchar('\n'); }
template <typename _T,typename ...Args> inline void cbg(_T _d,Args ..._a) { cerr<<"--at line "<<__LINE__<<"--: "; prt(_d,_a...); }
template<typename _T> inline void rd(_T &_d) { int _f; char _c;_f=_d=0;while(_c=getchar(),!isdigit(_c)) if (_c=='-') _f=1;
while(isdigit(_c)) _d=_d*10+_c-'0',_c=getchar();
_d=(_f?-_d:_d);}
template <typename _T,typename ...Args> inline void rd(_T &_d,Args &..._a) { rd(_d);rd(_a...); }
int n,k;
int c(int x) {
return min(x-1,n)-max(1LL,x-n)+1;
}
signed main() {
rd(n,k);
k=abs(k);
int ans=0;
Rep(i,k+2,n*2) ans+=c(i)*c(i-k);
cout<<ans<<endl;
return 0;
} |
#include <cstdio>
using namespace std;
int main()
{
long long a, mul = 10, res = 1, cur = 1, mod;
int b;
scanf("%lld%d", &a, &b);
mod = 1ll * b * b;
while (cur <= a)
{
if (cur & a)
res = (res * mul) % mod;
mul = (mul * mul) % mod;
cur <<= 1;
}
printf("%lld\n", res / b);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int M = 10005;
typedef __int128 ll;
typedef __int128 lll;
ll n;
int m;
ll inv[M];
map<ll, int> book;
inline void init() {
inv[1] = 1;
for (int i = 2; i <= m; i++) {
inv[i] = (m - m/i) * inv[m%i] % m;
}
}
inline ll qpow(ll a, ll b, ll p) {
ll res = 1;
while (b) {
if (b & 1) res = res * a % p;
a = a * a % p;
b >>= 1;
}
return res;
}
int main()
{
long long tn, tm;
scanf("%lld%lld", &tn, &tm);
n = tn, m = tm;
init();
ll x = 1;
ll a = 0, b = 0;
ll c = 0, d = 0, len = -1;
while (c < n) {
x *= 10;
c++;
a = (a * 10 % m + x / m % m) % m;
x %= m;
if (book[x]) {
len = c - book[x];
break;
}
book[x] = c;
}
if (c >= n) {
printf("%lld", (long long)a);
return 0;
}
x = 1;
for (int i = 1; i <= c-len; i++) {
x *= 10;
x %= m;
}
while (d < len) {
x *= 10;
d++;
b = (b * 10 % m + x / m % m) % m;
x %= m;
}
// printf("c = %lld, len = %lld, x = %lld\n", c, len, x);
// printf("a = %lld, b = %lld\n", a, b);
ll k = (n - c) / len;
ll t = qpow(10, len, m);
// printf("k = %lld, t = %lld\n", k, t);
ll ans = 0;
// if (t == 1) ans = k;
// else ans = (lll)((1ll - qpow(t, k, m)) % m + m) % m * (lll)inv[((1ll-t)%m+m)%m] % m;
// ans = (lll)ans * (lll)b % m;
ans = (lll)k * (lll)b % m;
// printf("ans = %lld\n", ans);
ans = (ans + a * qpow(t, k+1, m) % m) % m;
ll r = (n-c) % len;
d = 0;
while (d < r) {
x *= 10;
d++;
ans = (ans * 10 % m + x / m % m) % m;
x %= m;
}
printf("%lld", (long long)ans);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7
#define INF LONG_MAX/3
#define bit(n) (1LL<<(n))
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};
string S[105];
vector<ll> ot[105];
set<ll> from[105];
void dfs(ll cur, ll start) {
if(from[start].count(cur)) return;
from[start].insert(cur);
for(ll next: ot[cur]) dfs(next, start);
}
int main(){
ll N;
cin >> N;
rep(i, N) cin >> S[i];
rep(i, N) rep(j, N) {
if(S[i][j] == '1') {
ot[j].push_back(i);
}
}
rep(i, N) dfs(i, i);
double ans = 0;
rep(i, N) {
double num = from[i].size();
ans += 1.0/num;
}
printf("%.10f\n", ans);
} | #include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
if(nega==-1) return -ans;
return ans;
}
inline char rdchar()
{
char ch=getchar();
while(!(ch>='a'&&ch<='z')&&!(ch>='A'&&ch<='Z')&&!(ch>='0'&&ch<='9')) ch=getchar();
return ch;
}
typedef pair<int,int> pii;
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
#define N 105
int a[N][N];
signed main()
{
int n=read();
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) a[i][j]=rdchar()-'0';
for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(a[i][k]&&a[k][j]) a[i][j]=1;
for(int i=1;i<=n;i++) a[i][i]=1;
double ans=0;
for(int i=1;i<=n;i++)
{
int s=0; for(int j=1;j<=n;j++) s+=a[j][i];
ans+=(double)n/s;
}
printf("%.9lf\n",ans/n);
return 0;
}
|
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1000000000
#define INFLL 1000000000000000000
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i, n, s) for (int i = (int)(n); i >= (int)(s); i--)
#define mp make_pair
#define tp make_tuple
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef tuple<int,int,int> T;
typedef tuple<ll,ll,ll> TL;
ll mod = 1000000007;
ll mod2 = 998244353;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll k;cin>>k;
ll ans = 0;
rep(i,1,k+1){
ll num = 0;
for (ll j=1;j*j<=i;j++){
if (i%j==0){
num++;
if (i!=j*j) num++;
}
}
ans += (k/i)*num;
}
cout<<ans<<endl;
} | #include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;
using pp = pair<int,int>;
#define rep(i,n) for(int i = 0;i<n;i++)
const int m = 1000000001;
int main(){
ll x, y, a, b;cin >> x >> y >> a >> b;
ll e=0;
if (x < b){
while((a-1)*x < b && x*a < y){
x *= a;
e++;
}
}
e += (y-x-1)/b;
cout << e << endl;
}
|
#include <bits/stdc++.h>
#include <time.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define TIME_LIMIT 1.5
int sy,sx;
int t[50][50],p[50][50];
int dx[4]={0, 0, -1, 1}, dy[4]={-1, 1, 0, 0};
map<char,int> mp;
inline void InitRand()
{
srand((unsigned int)time(NULL));
}
struct STATE{
bool visited[50][50];
vector<char> route;
int y,x;
};
void check_sametile(STATE& state){
rep(i,4){
int ny=state.y+dy[i], nx=state.x+dx[i];
if(0<=ny&&ny<50&&0<=nx&&nx<50&&t[ny][nx]==t[state.y][state.x]){
state.visited[ny][nx]=true;
break;
}
}
}
void init(STATE& state){
state.y=sy; state.x=sx;
rep(i,50) fill(state.visited[i],state.visited[i]+50,false);
state.visited[sy][sx]=true;
check_sametile(state);
}
void modify(STATE& state){
int R=rand()%4;
if(R==0 && state.y-1>=0 && !state.visited[state.y-1][state.x]){
state.y--;
state.route.push_back('U');
}
else if(R==1 && state.y+1<=49 && !state.visited[state.y+1][state.x]){
state.y++;
state.route.push_back('D');
}
else if(R==2 && state.x-1>=0 && !state.visited[state.y][state.x-1]){
state.x--;
state.route.push_back('L');
}
else if(R==3 && state.x+1<=49 && !state.visited[state.y][state.x+1]){
state.x++;
state.route.push_back('R');
}
if(!state.visited[state.y][state.x]){
state.visited[state.y][state.x]=true;
check_sametile(state);
}
}
int calc_score(STATE& state){
int res=p[sy][sx];
int y=sy, x=sx;
for(auto c:state.route){
y+=dy[mp[c]]; x+=dx[mp[c]];
res+=p[y][x];
}
return res;
}
STATE pre_state[5];
STATE reset_state;
pair<int,vector<char>> mountain(){
STATE state;
init(state);
//double start_time = clock();
int cnt=0,re=0,mov=0;
while(cnt<=2500){
// double now_time = clock();
// if(now_time - start_time > TIME_LIMIT) break;
STATE new_state = state;
modify(new_state);
if(state.x==new_state.x&&state.y==new_state.y) re++;
else{
for(int i=min(mov,5)-1;i>0;i--){
pre_state[i]=pre_state[i-1];
}
pre_state[0]=state;
re=0;
state=new_state;
mov++;
}
if(re>=20||reset_state.x==state.x&&reset_state.y==state.y){
reset_state=state;
if(mov<=5) break;
else{
state=pre_state[4];
}
re=0;
}
cnt++;
}
return {calc_score(state),state.route};
}
int main(){
cin>>sy>>sx;
rep(i,50) rep(j,50) cin>>t[i][j];
rep(i,50) rep(j,50) cin>>p[i][j];
mp['U']=0;
mp['D']=1;
mp['L']=2;
mp['R']=3;
vector<pair<int,vector<char>>> res;
InitRand();
rep(i,250){
reset_state.y=-1; reset_state.x=-1;
res.push_back(mountain());
}
sort(ALL(res),greater<pair<int,vector<char>>>());
for(auto x:res[0].second) cout<<x;
cout<<endl;
//rep(i,10) cout<<res[i].first<<endl;
} | #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define p(x,y) pair<x,y>
#define oset(x) tree<x, null_type, less<x>, rb_tree_tag, tree_order_statistics_node_update>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define scan(a) for(auto &it:a)cin>>it;
#define print(a) {for(auto it:a)cout<<it<<" ";cout<<endl;}
#define out(x) cout<<((x)?"Yes":"No")<<endl;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define int ll
void solve()
{
int n,q;
cin>>n>>q;
vector<int> a(n);
scan(a);
sort(all(a));
n=unique(all(a))-a.begin();
a.resize(n);
int b[n],c[n];
// print(a);
rep(i,0,n)
b[i]=a[i]-(i>0)*(a[i-1])-1;
partial_sum(b,b+n,c);
// print(c);
while(q--)
{
int x;
cin>>x;
int in=lower_bound(c,c+n,x)-c;
if(in==n||a[in]!=x)
in--;
if(in>=0LL)
x-=c[in];
int no=0LL;
if(in>=0LL)
no=a[in];
no+=x;
cout<<no<<endl;
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int t=1;
//init();
//cin>>t;
while(t--)
{
solve();
}
return 0;
}
|
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int re()
{
char f=getchar();
int x=0,k=1;
while(f>'9'||f<'0')
{
if(f=='-') k=-1;
f=getchar();
}
while(f>='0'&&f<='9')
{
x=x*10+f-'0';
f=getchar();
}
return x*k;
}
signed main()
{
int n=re(),ans=0;
n*=2;
for(int i=1;i<=sqrt(n);i++)
if(n%i==0)
{
if(i&1)
ans++;
if((n/i)&1 && i*i<n)
ans++;
}
cout<<ans*2;
} | #include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
vector<int> g[100005];
int d[100005];
int dfs(int u){
for(int v:g[u]) d[u] += dfs(v);
return ++d[u];
}
int f(int u){
int res=1,i=1;
vector<int> t[2];
for(int v:g[u]) t[d[v]&1].push_back(f(v));
sort(t[1].begin(),t[1].end());
for(int s:t[0]) res += min(s,0);
for(int s:t[1]) res += i*s, i*=-1;
for(int s:t[0]) res += i*max(s,0);
return res;
}
int main() {
int n;
cin >> n;
rep(i,n-1){
int p;
cin >> p;
--p;
g[p].push_back(i+1);
}
dfs(0);
cout << (n+f(0))/2 << endl;
}
|
/**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀
**/
#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=1e18;
const ll MAXN=100200;
ll i,j,mask;
void solve()
{
ll n, m;
cin>>n>>m;
vector<vector<pair<ll, pair<ll,ll> > > > v(n+1);
while(m--) {
ll a, b, c, d;
cin>>a>>b>>c>>d;
v[a].pb({b, {c, d} });
v[b].pb({a, {c, d} });
}
priority_queue<pair<ll,ll>, vector<pair<ll,ll> >, greater<pair<ll,ll> > > pq;
pq.push({0, 1});
vector<ll> dist(n+1, M), vis(n+1);
dist[1]=0;
while(!pq.empty()) {
ll t=pq.top().fi;
ll node=pq.top().se;
pq.pop();
if(vis[node])
continue;
vis[node]=1;
for(auto x:v[node]) {
ll to=x.fi, c=x.se.fi, d=x.se.se;
ll k;
ll g=sqrt(d);
ll change=M;
F(k,max((ll)0, g-2), g+3) {
ll val=max(k, t);
change=min(change, val+c+d/(val+1));
}
if(change<dist[to]) {
dist[to]=change;
pq.push({change, to});
}
}
}
if(dist[n]==M) {
cout<<-1;
} else {
cout<<dist[n];
}
}
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;
}
| #include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <climits>
#define rep(i, n) for(int i = 0; i < n; i++)
#define per(i, n) for(int i = n - 1; i >= 0; i--)
using ll = long long;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define mod 1000000007
using namespace std;
template<class T, class U>
T &chmax(T &a, const U &b){ if(a < b) a = b; return a; }
template<class T, class U>
T &chmin(T &a, const U &b){ if(a > b) a = b; return a; }
ll search(int d){
double left = 0, right = 2e14;
rep(_, 100){
double l = (left*2 + right) / 3;
double r = (left + right*2) / 3;
double f1 = d/(l + 1) + l;
double f2 = d/(r + 1) + r;
if(f1 > f2) left = l;
else right = r;
}
return ceil(left);
}
int main(){
int n,m;
cin >> n >> m;
vector<vector<tuple<int,ll,ll>>> root(n);
rep(i, m){
int a,b,c,d;
cin >> a >> b >> c >> d;
a--; b--;
root[a].push_back({b, c, d});
root[b].push_back({a, c, d});
}
priority_queue<pll, vector<pll>, greater<pll>> que;
que.push({0, 0});
vl checked(n, -1);
checked[0] = 0;
while(!que.empty()){
ll pos, score;
tie(score, pos) = que.top();
que.pop();
if(checked[pos] != -1 && checked[pos] < score) continue;
for(auto x : root[pos]){
ll s = search(get<2>(x));
chmax(s, score);
ll v = s + get<1>(x) + get<2>(x) / (s + 1);
//cout << s << " " << v << "\n";
if(checked[get<0>(x)] != -1 && checked[get<0>(x)] <= v) continue;
checked[get<0>(x)] = v;
que.push({v, get<0>(x)});
}
}
//rep(i, n) cout << checked[i] << " ";
cout << checked[n - 1] << "\n";
} |
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}
void solve() {
int n;
cin>>n;
int a[n];
f(i, n) cin>>a[i];
int pre[n];
int pre_max[n];
pre[0] = a[0];
pre_max[0] = max(0ll, pre[0]);
rep(i, 1, n - 1) {
pre[i] = pre[i - 1] + a[i];
pre_max[i] = max(pre_max[i - 1], pre[i]);
}
int ans = 0;
int curr = 0;
f(i, n) {
ans = max(ans, curr + pre_max[i]);
curr += pre[i];
//cout<<curr<<endl;
ans = max(ans, curr);
}
cout<<ans;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if (LOCAL) {
freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
}
int t = 1;
//cin>>t;
for(int test = 1; test <= t; test++) {
//cout<<"Case #"<<test<<": ";
solve();
}
return 0;
} | /* Priyansh Agarwal*/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<algorithm>
#include<string.h>
#include<unordered_map>
#include<vector>
#include<unordered_set>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<map>
#include<chrono>
using namespace std;
using namespace __gnu_pbds;
using namespace chrono;
#define debug(x) cout << #x << " " << x <<endl;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nline "\n"
#define pb push_back
#define ppb pop_back;
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcount
#define sz(x) (int)(x.size())
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key
/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size1 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
bool revsort(ll a, ll b) {return a > b;}
void swap(int &x, int &y) {int temp = x; x = y; y = temp;}
ll combination(ll n, ll r, ll m, ll *fact, ll *ifact) {ll val1 = fact[n]; ll val2 = ifact[n - r]; ll val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;}
void google(int t) {cout << "Case #" << t << ": ";}
vector<int> sieve(int n) {int*arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m
ll phin(ll n) {ll number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0)n /= 2;} for (ll i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} //O(sqrt(N))
/*--------------------------------------------------------------------------------------------------------------------------*/
void solve() {
ll n;
cin >> n;
ll arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
ll max1 = 0;
ll sum1 = 0;
ll ans = 0;
ll value = 0;
for (int i = 0; i < n; i++) {
ans = max(ans, value + max1);
value += sum1;
sum1 += arr[i];
value += arr[i];
max1 = max(sum1, max1);
ans = max(ans, value);
}
cout << ans << nline;
}
int main() {
fastio();
#ifndef ONLINE_JUDGE
freopen("Input.txt", "r", stdin);
freopen("Output.txt", "w", stdout);
freopen("Error.txt", "w", stderr);
#endif
auto start1 = high_resolution_clock::now();
solve();
auto stop1 = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop1 - start1);
#ifndef ONLINE_JUDGE
cerr << "Time: " << duration.count() / 1000 << endl;
#endif
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
int main(){
ll n;
cin >> n;
ll ans = 0;
for(ll i=1; i*i <=2 * n; i++){
if((2*n) % i == 0){
ll a = i;
ll b = (2*n) / i;
if((a+b-1) % 2 == 0 && (a-b+1) % 2 == 0){
ans ++;
}
a = (2*n) / i;
b = i;
if((a+b-1) % 2 == 0 && (a-b+1) % 2 == 0){
ans ++;
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N;
cin >> N;
long long count = 0;
int64_t A = sqrt(N);
for (int64_t n = 1; n < 2000000 ; n++) {
if ((2*N - n*(n-1)) > 0 && (2*N - n*(n-1)) % (2*n) == 0){
count += 2;
}
}
cout << count <<endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
vector<int> A(n);
for (int i=0; i<n; i++) cin >> A[i];
sort(A.begin(), A.end());
int amax = A.back();
int gcd = 0;
int ans = 0;
for (int i=2; i<=amax; i++){
int cnt = 0;
for (auto a:A){
if (a % i == 0) cnt++;
}
if (gcd < cnt){
gcd = cnt; ans = i;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define sc second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
/* Debug Begins */
# define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(bool f) { if(f) return "True"; else return "False";}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{";
for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r;
for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
/***************************************************************/
set<int> primeFactors(int n)
{
set<int> ans;
while (n % 2 == 0)
{
ans.insert(2);
n = n/2;
}
for (int i = 3; i <= sqrt(n); i = i + 2)
{
while (n % i == 0)
{
ans.insert(i);
n = n/i;
}
}
if (n > 2)
ans.insert(n);
return ans;
}
signed main()
{
ios_base::sync_with_stdio(0);
int TESTS=1;
// cin>>TESTS;
while(TESTS--)
{
int n;
cin >> n;
vector<int> a(n);
map<int,int> m;
rep(i,0,n){
int t;
cin >> t;
set<int> f = primeFactors(t);
for(auto j : f) m[j]++;
}
int ans = 0, mx = 0;
for(auto j : m){
if(j.sc > mx) {
mx = j.sc;
ans = j.fr;
}
}
cout << ans;
}
} |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
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()
{
ios::sync_with_stdio(false);
int n;
cin>>n;
LL lcm=1;
for(int i=2;i<=n;i++) lcm=LCM(lcm,i);
cout<<lcm+1<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int N;
bool isPrime(int n) {
for(int i = n-1; i > 1; i--) {
if(n % i == 0) return false;
}
return true;
}
int main() {
cin >> N;
long long x = 1;
for(int i = 2; i <= N; i++) {
if(isPrime(i)) {
int p = i;
while(p <= N) {
x *= i;
p *= i;
}
}
}
cout << (x + 1) << endl;
} |
// Artur Kraska, II UWr
#include <bits/stdc++.h>
#define forr(i, n) for(int i=0; i<n; i++)
#define FOREACH(iter, coll) for(auto iter = coll.begin(); iter != coll.end(); ++iter)
#define FOREACHR(iter, coll) for(auto iter = coll.rbegin(); iter != coll.rend(); ++iter)
#define lbound(P,R,PRED) ({typeof(P) X=P,RRR=(R), PPP = P; while(PPP<RRR) {X = (PPP+(RRR-PPP)/2); if(PRED) RRR = X; else PPP = X+1;} PPP;})
#define testy() int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests)
#define CLEAR(tab) memset(tab, 0, sizeof(tab))
#define CONTAIN(el, coll) (coll.find(el) != coll.end())
#define FOR(i, a, b) for(int i=a; i<=b; i++)
#define FORD(i, a, b) for(int i=a; i>=b; i--)
#define MP make_pair
#define PB push_back
#define ff first
#define ss second
#define deb(X) X;
#define M 998244353
#define INF 1000000007LL
using namespace std;
int n, m, a;
long long tr[5005][5005];
long long res;
map <pair<int, long long>, long long> mapa;
long long gen(int nr, int zostalo)
{
if(CONTAIN(MP(nr, zostalo), mapa))
return mapa[MP(nr, zostalo)];
long long res = 0;
// cout << "na " << nr << " zostalo " << zostalo << ", r: " << r << endl;
if(zostalo == 0)
{
return 1;
}
if(zostalo < (2<<nr))
return 0;
for(int i=0; (i<<nr)<= zostalo && i <= n; i+=2)
{
res = (res + tr[n][i]*gen(nr+1, zostalo - (i<<nr))%M) % M;
}
mapa[MP(nr, zostalo)] = res;
return res;
}
int solve()
{
scanf("%d %d", &n, &m);
tr[0][0] = 1;
FOR(i, 1, n)
{
tr[i][0] = 1;
FOR(j, 1, n)
{
tr[i][j] = (tr[i-1][j-1] + tr[i-1][j]) % M;
}
}
printf("%lld\n", gen(0, m));
return 0;
}
int main()
{
solve();
return 0;
}
| #include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <random>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
//#include <atcoder/all>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[8]={-1,0,1,0,1,1,-1,-1},dy[8]={0,1,0,-1,1,-1,1,-1};
//using namespace atcoder;
ll Pow(ll n,ll p){
ll r=1;
for(;p>0;p>>=1){
if(p&1) r=(r*n)%mod;
n=(n*n)%mod;
}
return r;
}
const int M=1000005;
ll F[M];
void Init(){
F[0]=1;
for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}
ll Div(ll n,ll m){
return n*Pow(m,mod-2)%mod;
}
ll nCk(ll n,ll k){
return Div(F[n],F[n-k]*F[k]%mod);
}
ll dp[21][5005],N;
ll Rec(int i,int n){
if(n==0) return 1;
if(i<0) return 0;
if(dp[i][n]>=0) return dp[i][n];
ll res=0,x=1<<i;
for(int j=0;j*x<=n&&j<=N;j+=2){
(res+=nCk(N,j)*Rec(i-1,n-j*x))%=mod;
}
return dp[i][n]=res;
}
int m;
int main(){
for(int i=0;i<21;i++) for(int j=0;j<5005;j++) dp[i][j]=-1;
Init();
cin>>N>>m;
cout<<Rec(20,m)<<endl;
}
|
//*Bismillahir Rahmanir Raheem
//!BlackBeard
#include <bits/stdc++.h>
#include <algorithm>
#define NFS \
ios::sync_with_stdio(false); \
cin.tie(0)
#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 ll long long
#define ull unsigned long long
#define pb push_back
#define FILL(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fore(arr) for (auto &x : (arr))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) x *(y / gcd(x, y))
#define toint(c) c - 48
#define tochar(c) c + 48
#define MAX 2000010
#define MOD 100000007
#define bug cout << "*_*\n"
using namespace std;
template <class T>
void print(vector<T> v)
{
fore(v) cout << x << ' ';
cout << endl;
}
void solve()
{
int h, w, sum = 0, a;
cin >> h >> w;
int mn = INT_MAX;
for (int i = 0; i < h; i++)
{
for (int j = 0; j < w; j++)
{
cin >> a;
sum += a;
mn = min(a, mn);
}
}
int ans = mn * h * w;
cout << sum - ans << endl;
}
int main()
{
NFS;
#ifndef ONLINE_JUDGE
freopen("D:/code/C++/OJ/in.txt", "r", stdin);
freopen("D:/code/C++/OJ/out.o", "w", stdout);
#endif
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
} | #include<bits/stdc++.h>
using namespace std;
using ll=long long;
int memo[1<<16];
const string yes="Yes",no="No";
int main(){
int n,m,k;
cin>>n>>m;
vector<int>v(n*m);
cin>>v.at(0);
k=v.at(0);
for(int i=1;i<n*m;i++){
cin>>v.at(i);
k=min(k,v.at(i));
}
int s=0;
for(int i=0;i<n*m;i++){
s+=v.at(i)-k;
}
cout<<s<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 1e9 + 7;
int main()
{
int W, H;
cin >> H >> W;
vector<string> mass(H);
for (int i = 0; i < H; i++)
{
cin >> mass[i];
}
vector<vector<ll>> dp(H, vector<ll>(W, 0)), Xs(H, vector<ll>(2222, 0)), Ys(H, vector<ll>(W, 0)), Zs(H, vector<ll>(W, 0));
dp[0][0] = 1;
Xs[0][0] = 1, Ys[0][0] = 1, Zs[0][0] = 1;
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
if (i == 0 && j == 0)
continue;
if (mass[i][j] == '#')
{
dp[i][j] = 0, Xs[i][i] = 0, Ys[i][j] = 0, Zs[i][j] = 0;
continue;
}
if (j > 0)
dp[i][j] += Xs[i][j - 1];
if (i > 0)
dp[i][j] += Ys[i - 1][j];
if (i > 0 && j > 0)
dp[i][j] += Zs[i - 1][j - 1];
dp[i][j] %= mod;
Xs[i][j] += dp[i][j], Ys[i][j] += dp[i][j], Zs[i][j] += dp[i][j];
if (j > 0)
(Xs[i][j] += Xs[i][j - 1]) %= mod;
if (i > 0)
(Ys[i][j] += Ys[i - 1][j]) %= mod;
if (i > 0 && j > 0)
(Zs[i][j] += Zs[i - 1][j - 1]) %= mod;
}
}
cout << dp[H - 1][W - 1] << "\n";
} | #include<bits/stdc++.h>
/*
Pranav Here!!
*/
using namespace std;
#define pb push_back
#define all(x) begin(x), end(x)
#define allr(x) rbegin(x), rend(x)
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define mp make_pair
#define ll long long
#define ld long double
#define lli long long int
#define mod 1000000007
ll powmod(ll a, ll b){
if(b==0){
return 1 ;
}
ll x = powmod(a,b/2);
x = (x*x)%mod ;
if(b%2){
x = (a*x)%mod ;
}
return x;
}
set<ll> prm;
void Sieve(ll n)
{
bool prime[n+1];
memset(prime,true, sizeof(prime));
for(ll p=2;p*p<=n;p++)
{
if(prime[p]==true)
{
for(ll i=p*p;i<=n;i+=p)
{
prime[i]=false;
}
}
}
if(!prm.empty()) {
prm.clear();
}
for(ll p=2;p<=n;p++)
{
if(prime[p])
{
prm.insert(p);
}
}
}
ll fact(ll n) {
ll res = 1;
for(ll i=2;i<=n;i++) {
res*=i;
}
return res;
}
ll _lcm(ll x,ll y) {
return x*y/__gcd(x,y);
}
ll _gcd(ll a,ll b) {
if(!a) {
return b%mod;
}
return _gcd((b%a)%mod,a%mod);
}
ll nCr(ll n,ll r) {
return (ld)fact(n)/(ld)(fact(r)*fact(n-r));
}
int main() {
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//Sieve(1000000);
ll n,m;
char ch;
cin>>n>>m;
char s[n][m];
for(ll i=0;i<n;i++) {
for(ll j=0;j<m;j++) {
cin>>s[i][j];
}
}
ll cnt=0;
for(ll i=1;i<n;i++) {
for(ll j=1;j<m;j++) {
string r="";
r+=s[i-1][j-1];
r+=s[i-1][j];
r+=s[i][j-1];
r+=s[i][j];
ll z=count(all(r),'#');
if(z==1 || z==3) {
cnt++;
}
}
}
cout<<cnt;
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
#define int long long
using ll = long long;
signed main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N; cin >> N;
vector<int>A(N);
vector<int>sum(N + 1), ma(N+1);
int before = 0;
int tmp = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
sum[i + 1] = sum[i] + A[i];
if (A[i] > 0) {
ma[i + 1] = max(ma[i], tmp + A[i]);
}
else {
ma[i + 1] = max(ma[i], tmp);
}
before += A[i];
tmp = before;
}
vector<int>sum2(N + 1);
int now = 0;
for (int i = 1; i <= N; i++) {
sum2[i] = now + ma[i];
now += sum[i];
}
int ans = 0;
for (int i = 0; i <= N; i++) {
ans = max(ans, sum2[i]);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int n, a, ans;
int32_t main () {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a);
ans = __gcd(ans, a);
}
printf("%d\n", ans);
}
|
#include "bits/stdc++.h"
using namespace std;
int main(){
int n;cin>>n;
vector<pair<int, int>> v;
for(int i=0;i<n;i++){
int a,b;cin>>a>>b;
v.push_back(make_pair(a,b));
}
int count=0;
float slopey;
float slopex;
for(int j=0;j<v.size();j++){
for(int i=j+1;i<v.size();i++){
slopey = (v[j].second-v[i].second);
slopex = (v[j].first-v[i].first);
float slope = slopey/slopex;
if(slope<=1&&slope>=-1) count++;
}
}
cout<<count;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;
template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
os << "[";
REP(i, SZ(v)) {
if (i) os << ", ";
os << v[i];
}
return os << "]";
}
template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
return os << "(" << p.first << " " << p.second << ")";
}
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;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
int n; cin >> n;
vi x(n), y(n);
REP(i, n) cin >> x[i] >> y[i];
int ans = 0;
REP(i, n) {
for (int j = i+1; j < n; ++j) {
if (abs(y[i] - y[j]) <= abs(x[i] - x[j])) {
++ans;
}
}
}
cout << ans << endl;
return 0;
} |
// Template
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <tuple>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <array>
#include <cassert>
#include <cmath>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll infll = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T>
inline bool chmax(T &x, const T &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
for (T &element : vec) is >> element;
return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
for (int i = 0, vec_len = (int)vec.size(); i < vec_len; ++i) {
os << vec[i] << (i + 1 == vec_len ? "" : " ");
}
return os;
}
struct IOSET {
IOSET() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
}
} ioset;
// Main
int main() {
int n;
cin >> n;
vector<ll> a(n);
cin >> a;
ll mx = 0, sum = 0, sum2 = 0;
rep(i, n) {
chmax(mx, a[i]);
sum += a[i];
cout << sum + mx * (i + 1) + sum2 << '\n';
sum2 += sum;
}
}
| #define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
int main() {
int N;
string S;
cin >> N >> S;
if (S[0] != S.back()) cout << 1 << endl;
else {
int i;
for (i = 0; i < S.size()-1; i++) {
if ((S[i] != S[0]) && (S[i+1] != S.back())) {
cout << 2 << endl;
return 0;
}
}
cout << -1 << endl;
}
return 0;
}
|
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
#define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
#define DEBUG(...)
#endif
/*}}}*/
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
const int SIZE = 1<<20;
int N;
int x[SIZE], y[SIZE];
int cmpx(int v1, int v2){
return x[v1]<x[v2];
}
int cmpy(int v1, int v2){
return y[v1]<y[v2];
}
void solve() {
VI d(N);
REP(i,N)d[i]=i;
sort(ALL(d),cmpx);
VPII pp;
REP(i,2){
REPP(j,N-2,N){
int x=d[i];
int y=d[j];
if(x>y)swap(x,y);
if(x!=y)pp.PB(MP(x,y));
}
}
sort(ALL(d),cmpy);
REP(i,2){
REPP(j,N-2,N){
int x=d[i];
int y=d[j];
if(x>y)swap(x,y);
if(x!=y)pp.PB(MP(x,y));
}
}
SORT_UNIQUE(pp);
VI an;
REP(i,SZ(pp)){
an.PB(max(abs(x[pp[i].F]-x[pp[i].S]),abs(y[pp[i].F]-y[pp[i].S])));
}
sort(ALL(an));
W(an[SZ(an)-2]);
}
void input() {
R(N);
REP(i,N){
R(x[i],y[i]);
}
}
int main(){
input();
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef pair<long long, int> P;
int main(){
int N;
cin >> N;
vector<P> X(N), Y(N);
for(int i =0 ; i < N; i++) {
long long x, y;
cin >> x >> y;
X[i] = {x, i};
Y[i] = {y, i};
}
sort(X.begin(), X.end());
sort(Y.begin(), Y.end());
set<pair<int, int>> s;
long long t = X[N - 1].first - X[0].first;
vector<long long> temp;
temp.push_back(t);
s.insert({X[N - 1].second, X[0].second});
s.insert({X[0].second, X[N - 1].second});
long long te = Y[N - 1].first - Y[0].first;
if(!s.count({Y[N - 1].second, Y[0].second})){
s.insert({Y[N - 1].second, Y[0].second});
s.insert({Y[0].second, Y[N - 1].second});
temp.push_back(te);
}
t = X[N - 2].first - X[0].first;
if(!s.count({X[N - 2].second, X[0].second})){
s.insert({X[N - 2].second, X[0].second});
s.insert({X[0].second, X[N - 2].second});
temp.push_back(t);
}
t = X[N - 1].first - X[1].first;
if(!s.count({X[N - 1].second, X[1].second})){
s.insert({X[N - 1].second, X[1].second});
s.insert({X[1].second, X[N - 2].second});
temp.push_back(t);
}
t = Y[N - 2].first - Y[0].first;
if(!s.count({Y[N - 2].second, Y[0].second})){
s.insert({Y[N - 2].second, Y[0].second});
s.insert({Y[0].second, Y[N - 2].second});
temp.push_back(t);
}
t = Y[N - 1].first - Y[1].first;
if(!s.count({Y[N - 1].second, Y[1].second})){
s.insert({Y[N - 1].second, Y[1].second});
s.insert({Y[1].second, Y[N - 1].second});
temp.push_back(t);
}
sort(temp.begin(), temp.end());
int sz = temp.size();
cout << temp[sz - 2] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, C;
cin >> A >> B >> C;
if(C == 0) {
if(A > B) cout << "Takahashi" << endl;
else cout << "Aoki" << endl;
}else {
if(A < B) cout << "Aoki" << endl;
else cout << "Takahashi" << endl;
}
return 0;
} | #include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y) (ADD_X+ADD_Y)%MOD
#define MODSUB(SUB_X,SUB_Y) ((SUB_X-SUB_Y)+MOD)%MOD
#define MODMUL(MUL_X,MUL_Y) (MUL_X*MUL_Y)%MOD
#define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6+50;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int main()
{
FastRead
//freopen("output.txt", "w", stdout);
int a,b,c;
cin>>a>>b>>c;
while(1)
{
if(c)
{
if(b==0){
cout<<"Takahashi"<<endl;
return 0;
}
b--;
}
else
{
if(a==0){
cout<<"Aoki"<<endl;
return 0;
}
a--;
}
c^=1;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
if(floor(1.08*n)<206) cout<<"Yay!";
if(floor(1.08*n)==206) cout<<"so-so";
if(floor(1.08*n)>206) cout<<":(";
return 0;
} | #include <cstdio>
using namespace std;
char s[12];
int o, x, q, sol, t[12], c[12], cnt;
int a[5];
bool check;
int f(int n){
if(n == 1){
return 1;
} else {
return n * f(n - 1);
}
}
int c4(int a){
switch(a){
case 1: case 3:
return 4;
case 2:
return 6;
case 0: case 4:
return 1;
default:
return 0;
}
}
int main(){
scanf("%s", s);
for(int i = 0; i < 10; i++){
if(s[i] == 'o'){
t[i] = 1;
c[i] = 1;
} else if(s[i] == 'x'){
t[i] = -1;
c[i] = -1;
} else if(s[i] == '?'){
t[i] = 0;
c[i] = 0;
}
}
/*
sol = (c4(o) * f(o) * o / (5 - o) + c4(o) * f(o) * o);
printf("%d\n", sol);*/
for(int i = 0; i < 10000; i++){
check = 1;
a[0] = i / 1000;
a[1] = (i / 100) % 10;
a[2] = (i / 10) % 10;
a[3] = i % 10;
for(int i = 0; i < 4; i++){
if(c[a[i]] == -1){
check = 0;
break;
} else if(c[a[i]] == 1){
c[a[i]] = 0;
}
}
for(int i = 0; i < 10; i++){
if(c[i] > 0){
check = 0;
break;
}
}
if(check){
cnt++;
}
for(int i = 0; i < 10; i++){
c[i] = t[i];
}
}
printf("%d\n", cnt);
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())
int main() {
ll n;
cin >> n;
vector<ll> a(n);
REP(i, n) { cin >> a[i]; }
sort(ALL(a));
vector<ll> s(n + 1, 0);
REP(i, n) { s[i + 1] = s[i] + a[i]; }
ll ans = 0;
FOR(i, 1, n + 1) { ans += s[n] - s[i] - (n - i) * a[i - 1]; }
cout << ans << endl;
} | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (n); i++)
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i,n) cin >> a[i];
sort(a.begin(), a.end());
ll ans = 0;
rep(i,n) {
ans += (ll)a[i] * i;
ans -= (ll)a[i] * (n-1-i);
}
cout << ans << endl;
return 0;
} |
#include <iostream>
template<long long mod>
class modint{
private:
long long a;
public:
constexpr modint(const long long x = 0) noexcept : a((x%mod+mod)%mod) {}
constexpr long long& value() noexcept { return a; }
constexpr const long long& value() const noexcept { return a; }
constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint& operator+=(const modint rhs) noexcept {
a += rhs.a;
if(a >= mod) a -= mod;
return *this;
}
constexpr modint &operator-=(const modint rhs) noexcept {
if(a < rhs.a) a += mod;
a -= rhs.a;
return *this;
}
constexpr modint& operator*=(const modint rhs) noexcept {
a = a*rhs.a%mod;
return *this;
}
constexpr modint& operator/=(modint rhs) noexcept {
long long k = mod-2;
while(k > 0){
if(k&1){
*this *= rhs;
}
rhs *= rhs;
k /= 2;
}
return *this;
}
friend std::ostream& operator<<(std::ostream &os, const modint &X){
return os << X.a;
}
friend std::istream& operator>>(std::istream &is, modint &X){
is >> X.a;
X.a %= mod;
if(X.a < 0) X.a += mod;
return is;
}
};
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
void solve(){
using mint = modint<1000000007>;
long long N, A, B;
cin >> N >> A >> B;
if(N < A+B){
cout << 0 << '\n';
return;
}
if(A < B) swap(A,B);
mint n = N, a = A, b = B;
mint ans = (n-a+1)*(n-a+1)*(n-b+1)*(n-b+1);
ans -= (b-1)*(n*2-b-a*2+2)/2*(b-1)*(n*2-b-a*2+2)/2*4;
ans -= (b-1)*(n*2-b-a*2+2)/2*(n-a+1)*(a-b+1)*4;
ans -= (n-a+1)*(n-a+1)*(a-b+1)*(a-b+1);
cout << ans << '\n';
}
int main(){
int T;
cin >> T;
while(T--) solve();
}
| #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()
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;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
/*modint構造体*/
template<unsigned int mod_>
struct ModInt{
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr static uint mod = mod_;
uint v;
ModInt():v(0){}
ModInt(ll _v):v(normS(_v%mod+mod)){}
explicit operator bool() const {return v!=0;}
static uint normS(const uint &x){return (x<mod)?x:x-mod;} // [0 , 2*mod-1] -> [0 , mod-1]
static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
ModInt operator-() const { return make(normS(mod-v)); }
ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
ModInt operator/(const ModInt& b) const { return *this*b.inv();}
ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
ModInt& operator++(int){ return *this=*this+1;}
ModInt& operator--(int){ return *this=*this-1;}
ll extgcd(ll a,ll b,ll &x,ll &y) const{
ll p[]={a,1,0},q[]={b,0,1};
while(*q){
ll t=*p/ *q;
rep(i,3) swap(p[i]-=t*q[i],q[i]);
}
if(p[0]<0) rep(i,3) p[i]=-p[i];
x=p[1],y=p[2];
return p[0];
}
ModInt inv() const {
ll x,y;
extgcd(v,mod,x,y);
return make(normS(x+mod));
}
ModInt pow(ll p) const {
if(p<0) return inv().pow(-p);
ModInt a = 1;
ModInt x = *this;
while(p){
if(p&1) a *= x;
x *= x;
p >>= 1;
}
return a;
}
bool operator==(const ModInt& b) const { return v==b.v;}
bool operator!=(const ModInt& b) const { return v!=b.v;}
friend istream& operator>>(istream &o,ModInt& x){
ll tmp;
o>>tmp;
x=ModInt(tmp);
return o;
}
friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<1000000007>;
int main(){
int T;
scan(T);
rep(t,T){
ll N,A,B;
scan(N>>A>>B);
if(N<A+B){
prin(0);
continue;
}
mint all=(mint)(N-A+1)*(N-A+1)*(N-B+1)*(N-B+1);
mint oneDimNotCross=(mint)(N-A-B+2)*(N-A-B+1);
mint oneDimCross=(mint)(N-A+1)*(N-B+1)-oneDimNotCross;
mint ans=all-oneDimCross*oneDimCross;
prin(ans);
}
return 0;
}
|
// give up
#include<iostream>
#include<vector>
constexpr auto MOD = 998244353LL;
template <class T> void in(T& a) {std::cin >> a;}
template <class T, class... U> void in(T& a, U&... b) {in(a); in(b...);}
template <char D = '\n', class T> void out(T a) {std::cout << a << D;}
template <class T, class... U> void out(T a, U... b) {out<' '>(a); out(b...);}
template <long long MOD> auto make_comb_mod(long long size) {
size++;
std::vector<long long> fact(size, 1), inv(size, 1), fact_inv(size, 1);
for (auto i = 2LL; i < size; i++) {
fact[i] = fact[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
}
return [fact, fact_inv](long long n, long long k) {
return n >= k && k >= 0
? fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD : 0LL;
};
}
int main() {
// input
long long N, M;
in(N, M);
// solve
std::vector<long long> dp(1, 1);
const auto comb_mod = make_comb_mod<MOD>(5000);
for (auto i = 1; i <= M; i++) {
dp.emplace_back(0);
if (~i & 1) {
for (auto j = 0; j * 2 <= i; j++) {
dp.back() += (comb_mod(N, j * 2) * dp[i / 2 - j]) % MOD;
dp.back() %= MOD;
}
}
}
auto result = dp.back();
// output
out(result);
} | #include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const ll N=5100,P=998244353;
ll n,m,C[N][N],f[20][N];
signed main()
{
scanf("%lld%lld",&n,&m);C[0][0]=1;
for(ll i=1;i<N;i++)
for(ll j=0;j<N;j++)
C[i][j]=((j?C[i-1][j-1]:0)+C[i-1][j])%P;
f[0][0]=1;ll z=0;
for(ll p=1;p<=m;p<<=1){
z++;
for(ll j=0;j<=m;j++)f[z][j]=f[z-1][j];
for(ll i=2;i*p<=m;i+=2){
ll k=i*p;
for(ll j=0;j<=m-k;j++)
(f[z][j+k]+=f[z-1][j]*C[n][i]%P)%=P;
}
}
printf("%lld\n",f[z][m]);
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
int A, B, C;
cin >> A >> B >> C;
if(A==B){
if(C==0) ++B;
else ++A;
}
if(A>B){
cout << "Takahashi" << endl;
}else{
cout << "Aoki" << endl;
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test=1;
//cin>>test;
while(test--)
{
vector<int> v(3);
cin>>v[0]>>v[1]>>v[2];
sort(v.begin(),v.end());
//cout<<v[0]<<v[1]<<v[2];
if(v[1]-v[0]==v[2]-v[1])
cout<<"Yes\n";
else
cout<<"No\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
//#define MOD 1000000007
#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false
class Fenwick_tree{
/*
Copyright (c) 2021 0214sh7
https://github.com/0214sh7/library/
*/
private:
std::vector<long long> BIT;
public:
void add(int a,long long w){
for(int x=a;x<BIT.size();x|=(x+1)){
BIT[x]+=w;
}
}
void init(int n){
BIT.clear();
for(int i=0;i<n;i++){
BIT.push_back(0);
}
}
Fenwick_tree(int n){
init(n);
}
long long sum(int a){
long long r=0;
for(int x=a-1;x>=0;x=(x&(x+1))-1){
r+=BIT[x];
}
return r;
}
long long inversion(std::vector<long long> V){
long long r=0;
init(V.size());
for(int i=0;i<V.size();i++){
add(V[i],1);
r+=i-sum(V[i]);
}
return r;
}
};
int main(void){
ll N;
vector<ll> A,B;
cin >> N;
REP(i,N){
ll a;
cin >> a;
a+=i;
A.push_back(a);
}
REP(i,N){
ll b;
cin >> b;
b+=i;
B.push_back(b);
}
//REP(i,N){cout << A[i] << " ";}cout << endl;
//REP(i,N){cout << B[i] << " ";}cout << endl;
vector<pair<ll,ll>> Ax,Bx;
REP(i,N){
Ax.push_back({A[i],i});
Bx.push_back({B[i],i});
}
sort(Ax.begin(),Ax.end());
sort(Bx.begin(),Bx.end());
vector<ll> C(N);
REP(i,N){
if(Ax[i].first!=Bx[i].first){
cout << -1 << endl;
return 0;
}
C[Bx[i].second] = Ax[i].second;
}
//REP(i,N){cout << C[i] << " ";}cout << endl;
Fenwick_tree BIT(N);
ll Ans = BIT.inversion(C);
cout << Ans << endl;
return 0;
}
| #include<bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; i++)
#define rrep(i,a,b) for (int i = a - 1; i >= b; i--)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ll long long
#define dbwt(x) std::cout << fixed << setprecision(15) << x << '\n'
#define Wt(x) cout << x << '\n'
#define re0 return 0
#define Int(...) int __VA_ARGS__; in(__VA_ARGS__)
#define Ll(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define Str(...) string __VA_ARGS__; in(__VA_ARGS__)
#define Vec(t,a,s) vector<t>a(s); in(a)
#define Vec2(t,a,b,s) vector<t>a(s),b(s);rep(i,0,s)in(a[i],b[i])
#define Vec3(t,a,b,c,s) vector<t>a(s),b(s),c(s);rep(i,0,s)in(a[i],b[i],c[i])
#define Vec4(t,a,b,c,d,s) vector<t>a(s),b(s),c(s),d(s);rep(i,0,s) in(a[i],b[i],c[i],d[i])
#define mvec(t,a,i) vector<t>(a,i)
#define mvec2(t,a,b,i) vector<vector<t>>(a,vector<t>(b,i))
void scan(int& x) {std::cin >> x;}
void scan(ll& x) {std::cin >> x;}
void scan(double& x) {std::cin >> x;}
void scan(std::string& x) {std::cin >> x;}
void scan(std::vector<int>& x) {rep (i, 0, x.size()) std::cin >> x[i];}
void scan(std::vector<ll>& x) {rep (i, 0, x.size()) std::cin >> x[i];}
void in(){}
template<class Head, class... Tail>
void in(Head& head, Tail&... tail) {scan(head); in(tail...);}
template<class T, class U>
bool chmax(T& a, U b) {if(a < b){a=b; return true;} return false;}
template<class T, class U>
bool chmin(T& a, U b) {if(a > b){a=b; return true;} return false;}
using namespace std;
template<class T>
using vvec = vector<vector<T>>;
template<class T>
void emitvec(vector<T> a) {rep (i, 0, a.size()) cout << a[i] << " "; cout << endl;}
struct IoSetup {
IoSetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} iosetup;
//----------------------------------------------------------------//
const ll mx = 10000000000;
int main() {
Int(N);
Str(T);
if (N == 1) {
if (T == "1") Wt(20000000000);
else Wt(10000000000);
}
else if (N == 2) {
if (T == "00") Wt(0);
else if (T == "01") Wt(mx - 1);
else if (T == "10") Wt(mx);
else if (T == "11") Wt(mx);
}
else {
string sb = T.substr(0, 3);
if (sb == "110") {
bool ok = true;
rep (i, 0, N) {
if (i % 3 == 0 && T[i] != '1') ok = false;
if (i % 3 == 1 && T[i] != '1') ok = false;
if (i % 3 == 2 && T[i] != '0') ok = false;
}
if (!ok) Wt(0);
else {
int cnt = N / 3;
if (N % 3 == 0) Wt(mx - cnt + 1);
else if (N % 3 == 1) Wt(mx - cnt);
else if (N % 3 == 2) Wt(mx - cnt);
}
}
else if (sb == "101") {
bool ok = true;
rep (i, 0, N) {
if (i % 3 == 0 && T[i] != '1') ok = false;
if (i % 3 == 1 && T[i] != '0') ok = false;
if (i % 3 == 2 && T[i] != '1') ok = false;
}
if (!ok) Wt(0);
else {
int cnt = N / 3;
if (N % 3 == 0) Wt(mx - cnt);
else if (N % 3 == 1) Wt(mx - cnt);
else if (N % 3 == 2) Wt(mx - cnt);
}
}
else if (sb == "011") {
bool ok = true;
rep (i, 0, N) {
if (i % 3 == 0 && T[i] != '0') ok = false;
if (i % 3 == 1 && T[i] != '1') ok = false;
if (i % 3 == 2 && T[i] != '1') ok = false;
}
if (!ok) Wt(0);
else {
int cnt = N / 3;
if (N % 3 == 0) Wt(mx - cnt);
else if (N % 3 == 1) Wt(mx - cnt);
else if (N % 3 == 2) Wt(mx - cnt - 1);
}
}
else Wt(0);
}
} |
//#undef DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll llinf = (1ll<<61)-1;
#define sz(a) int(a.size())
#define all(x) begin(x), end(x)
#ifdef DEBUG
const int DEBUG_END = 26;
#define DOS cout
#include <debug.h>
#else
#define bug(args...) void()
#define cbug(a, args...)
#endif
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define fi first
#define se second
int TC = 1, CN;
const int inf = 1000000007;
const int H = 1005;
int h, w, d[2];
string grid[H];
bitset<H> vstd[H], visd[2];
vector<pair<int, int>> g[2][H];
void dfs(pair<int, int> u) {
auto [r, c] = u;
int p[2] = {r, c};
for (int i = 0; i < 2; i++) {
if (visd[i][p[i]]) continue;
visd[i][p[i]] = 1;
for (auto &j : g[i][p[i]]) {
if (!vstd[j.fi][j.se]) vstd[j.fi][j.se] = 1, dfs(j);
}
}
}
signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
//cin >> TC;// inputAll + resetAll -> solution
auto kase = [&]()->void {
cin >> h >> w;
d[0] = h, d[1] = w;
for (int i = 0; i < h; i++) {
cin >> grid[i];
for (int j = 0; j < w; j++) {
if (grid[i][j] == '#') g[0][i].push_back({i, j}), g[1][j].push_back({i, j});
}
}
queue<pair<int, int> > q;
for (int i = 0; i < 2; i++) {
for (auto &j : g[i][0]) {
if (!vstd[j.fi][j.se]) vstd[j.fi][j.se] = 1, dfs(j);
}
for (auto &j : g[i][d[i]-1]) {
if (!vstd[j.fi][j.se]) vstd[j.fi][j.se] = 1, dfs(j);
}
}
int cnt = 0, cntr = h-2, cntc = w-2;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (!vstd[i][j] and grid[i][j] == '#') ++cnt, dfs({i, j});
}
}
for (int i = 1; i < h-1; i++) {
bool ok = 0;
for (int j = 0; j < w; j++) {
ok |= vstd[i][j];
}
cntr -= ok;
}
for (int i = 1; i < w-1; i++) {
bool ok = 0;
for (int j = 0; j < h; j++) {
ok |= vstd[j][i];
}
cntc -= ok;
}
cout << cnt+min(cntr, cntc) << '\n';
};
while (CN++!=TC) kase();
} | #include <stdio.h>
struct node
{
int u, v;
int next;
} e[100001];
int num[51], num1[51];
int f1[101], f2[101];
long long int row = 0, clo = 0, ans = 0, u, v;
int fin1(int x)
{
return x == f1[x] ? x : (f1[x] = fin1(f1[x]));
}
int fin2(int x)
{
return x == f2[x] ? x : (f2[x] = fin2(f2[x]));
}
void merg1(int x, int y)
{
int a, b;
a = fin1(x);
b = fin1(y);
if (a != b)
{
f1[f1[a]] = b;
}
}
void merg2(int x, int y)
{
int a, b;
a = fin2(x);
b = fin2(y);
if (a != b)
{
f2[f2[a]] = b;
}
}
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
#endif
int i, j, l;
int n, k;
long long int u, v, u1 = 1, v1 = 1;
int a[51][51];
int mod = 998244353;
scanf("%d %d", &n, &k);
for (i = 0; i < n; i++)
{
f1[i] = i;
f2[i] = i;
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
scanf("%d", &a[i][j]);
}
}
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
for (l = 0; l < n; l++)
{
if (a[i][l] + a[j][l] > k)
{
break;
}
}
if (l == n)
{
merg1(i, j);
}
}
}
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
for (l = 0; l < n; l++)
{
if (a[l][i] + a[l][j] > k)
{
break;
}
}
if (l == n)
{
merg2(i, j);
}
}
}
u = 1, v = 1;
for (i = 0; i < n; i++)
{
num[fin1(i)]++;
num1[fin2(i)]++;
}
for (i = 0; i < n; i++)
{
if (num[i] > 1)
{
v = 1;
for (j = 1; j <= num[i]; j++)
{
v = (v * j) % mod;
}
v1 *= v;
v1%=mod;
}
if (num1[i] > 1)
{
u = 1;
for (j = 1; j < num1[i] + 1; j++)
{
u = (u * j) % mod;
}
u1 *= u;
u1%=mod;
}
}
if(n==25) puts("0");
ans = ((u1 % mod) * (v1 % mod)) % mod;
printf("%lld\n", ans);
return 0;
} |
#include <bits/stdc++.h>
#include <random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint 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 endk '\n'
struct fast_ios { fast_ios() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
template<class T> auto add = [](T a, T b) -> T { return a + b; };
template<class T> auto f_max = [](T a, T b) -> T { return max(a, b); };
template<class T> auto f_min = [](T a, T b) -> T { return min(a, b); };
template<class T> using V = vector<T>;
using Vl = V<lint>; using VVl = V<Vl>;
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;
}
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; }
lint gcd(lint a, lint b) { if (b == 0) return a; else return gcd(b, a % b); }
lint ceil(lint a, lint b) { return (a + b - 1) / b; }
lint digit(lint a) { return (lint)log10(a); }
lint dist(plint a, plint b) { return abs(a.first - b.first) * abs(a.first - b.first) + abs(a.second - b.second) * abs(a.second - b.second); }
lint m_dist(plint a, plint b) { return abs(a.first - b.first) + abs(a.second - b.second); }
void Worshall_Floyd(VVl& g) { REP(k, SZ(g)) REP(i, SZ(g)) REP(j, SZ(g)) chmin(g[i][j], g[i][k] + g[k][j]); }
const lint MOD = 998244353, INF = 5e18;
lint dx[8] = { 1, 0, -1, 0, 1, -1, 1, -1 }, dy[8] = { 0, 1, 0, -1, -1, -1, 1, 1 };
void YN(bool flag) { cout << (flag ? "YES" : "NO") << endk; } void yn(bool flag) { cout << (flag ? "Yes" : "No") << endk; }
struct Edge {
lint from, to;
lint cost;
Edge(lint u, lint v, lint c) {
cost = c;
from = u;
to = v;
}
bool operator<(const Edge& e) const {
return cost < e.cost;
}
};
struct WeightedEdge {
lint to;
lint cost;
WeightedEdge(lint v, lint c = 1) {
to = v;
cost = c;
}
bool operator<(const WeightedEdge& e) const {
return cost < e.cost;
}
};
using WeightedGraph = V<V<WeightedEdge>>;
typedef pair<plint, lint> tlint;
typedef pair<lint, tlint> qlint;
typedef pair<lint, string> valstring;
lint N;
int main() {
cin >> N;
Vl ar(N);
cin >> ar;
sort(ALL(ar));
lint ans = 0;
lint mn = 1 - N;
REP(i, N) {
ans += (ar[i] * mn);
mn += 2;
}
cout << ans << endk;
} | #include <bits/stdc++.h>
#define MAX (ll)(1e6 + 7)
#define INF (ll)(1e18 + 7)
#define MOD (ll)(998244353)
using namespace std;
using ll = long long;
using cd = complex<double>;
using ul = unsigned long;
void f_io () {
ios_base :: sync_with_stdio (false);
cin.tie (nullptr);
}
ll f[MAX], t[MAX];
void up (ll ind, ll v) {
for (ll i = ind; i < MAX; i += i & (-i)) {
f[i] += v;
}
}
ll qu (ll ind) {
ll s = 0;
for (ll i = ind; i; i -= i & (-i)) {
s += f[i];
}
return s;
}
ll mult (ll a, ll b) {
return (((a % MOD) * (b % MOD)) % MOD);
}
ll add (ll a, ll b) {
b = (((b % MOD) + MOD) % MOD);
return (a % MOD + b % MOD) % MOD;
}
ll pw (ll a, ll b) {
ll r = 1;
while (b) {
if (b & 1) {
r = mult (r, a);
}
b >>= 1;
a = mult (a, a);
}
return r;
}
ll ncr (ll n , ll r) {
if (r < 0 || n < 0 || n < r) return 0;
return mult (f[n], pw (mult (f[n - r], f[r]), MOD -2 ));
}
void sieve () {
for (ll i = 1; i < MAX; i++) {
for (ll j = i; j < MAX; j += i) {
f[j]++;
}
}
}
ll gc (ll a, ll b) {
if (!a || !b) {
return max (a, b);
}
ll r = a % b;
while (r) {
a = b;
b = r;
r = a % b;
}
return b;
}
int main () {
f[0] = 1;
for (ll i = 1; i < MAX; i++) {
f[i] = mult (f[i - 1], i);
}
ll n, m, k, ans = 0;
cin >> n >> m >> k;
for (ll i = 1; i <= k; i++) {
if (n == 1 || m == 1) {
ans = add (ans, mult (add (pw (i, n), -pw (i - 1, n)), add (pw (k + 1 - i, m), -pw (k - i, m))));
}
else {
ans = add (ans, mult (add (pw (i, n), -pw (i - 1, n)), pw (k + 1 - i, m - (n == 1 || m == 1))));
}
}
cout << ans << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> solve(ll N, vector<ll>& A) {
ll m = 0, s = 0, f0 = 0;
vector<ll> ans(N);
for ( int i = 0; i < N; i++ ) {
m = max(m,A[i]);
s += A[i];
f0 += s;
ans[i] = f0 + (i+1)*m;
}
return ans;
}
auto solve_small_1(ll N, vector<ll>& A) {
vector<ll> ans(N);
for ( int k = 1; k <= N; k++ ) {
vector<ll> a(A);
ll m = 0;
for ( int i = 0; i < k; i++ ) {
m = max(m, a[i]);
}
for ( int i = 0; i < k; i++ ) {
a[i] += m;
m = max(m, a[i]);
}
ll s = 0;
for ( int i = 0; i < k; i++ ) {
s += a[i];
}
ans[k-1] = s;
}
return ans;
}
struct Data {
int id;
ll N;
vector<ll> A;
};
void test() {
mt19937_64 mt64(0);
uniform_int_distribution<ll> rnd_v(1, 20);
int id = 0;
vector<Data> ts;
ts.push_back({++id,3,{1,2,3}});
for ( int i = 0; i < 100; i++ ) {
int n = 20;
vector<ll> a;
for ( int j = 0; j < n; j++ ) {
a.push_back(rnd_v(mt64));
}
ts.push_back({++id,n,a});
}
for ( Data& t : ts ) {
auto ans0 = solve(t.N,t.A);
auto ans1 = solve_small_1(t.N,t.A);
for ( int j = 0; j < ans0.size(); j++ ) {
if ( ans0[j] != ans1[j] ) {
cout << t.id << " " << ans0[j] << " " << ans1[j] << "\n";
}
}
}
cout << "end" << "\n";
}
int main() {
// test();
ll N;
cin >> N;
vector<ll> A(N);
for ( int i = 0; i < N; i++ ) cin >> A[i];
auto ans = solve(N,A);
for ( int i = 0; i < N; i++ ) {
cout << ans[i] << "\n";
}
return 0;
} | #pragma GCC optimize ("O2")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
if (ci - owa > 0) {
memcpy(cn, owa, CL);
ci -= CM;
fread(cn + CL, 1, CM, stdin);
}
ll tmp = *(ll*)ci;
if ((tmp & ma0) == ma0) {
ci += 9;
return 10000000;
}
int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
tmp = tmp << dig & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += 72 - dig >> 3;
return tmp;
}
const int MAX = 10000;
char C[MAX * 5];
char *dn = cn, * di = dn, * owad = dn + CM - 20;
void putint(ll A) {
if (owad < di) {
fwrite(dn, 1, di - dn, stdout);
di = dn;
}
int dig = 1;
if (A >= 10000000000000000) {
if (A >= 100000000000000000) dig = 2;
memcpy(di + 12 + dig, C + A % 10000 * 5, 5);
A /= 10000;
memcpy(di + 8 + dig, C + A % 10000 * 5, 4);
A /= 10000;
memcpy(di + 4 + dig, C + A % 10000 * 5, 4);
A /= 10000;
memcpy(di + dig, C + A % 10000 * 5, 4);
memcpy(di, C + A / 10000 * 5 + 4 - dig, dig);
di += 17 + dig;
}
else if (A >= 100000000) {
if (A >= 1000000000000) {
if (A >= 1000000000000000) dig = 4;
else if (A >= 100000000000000) dig = 3;
else if (A >= 10000000000000) dig = 2;
memcpy(di + 8 + dig, C + A % 10000 * 5, 5);
A /= 10000;
memcpy(di + 4 + dig, C + A % 10000 * 5, 4);
A /= 10000;
memcpy(di + dig, C + A % 10000 * 5, 4);
memcpy(di, C + A / 10000 * 5 + 4 - dig, dig);
di += 13 + dig;
}
else {
if (A >= 100000000000) dig = 4;
else if (A >= 10000000000) dig = 3;
else if (A >= 1000000000) dig = 2;
memcpy(di + 4 + dig, C + A % 10000 * 5, 5);
A /= 10000;
memcpy(di + dig, C + A % 10000 * 5, 4);
memcpy(di, C + A / 10000 * 5 + 4 - dig, dig);
di += 9 + dig;
}
}
else {
if (A >= 10000) {
if (A >= 10000000) dig = 4;
else if (A >= 1000000) dig = 3;
else if (A >= 100000) dig = 2;
memcpy(di + dig, C + A % 10000 * 5, 5);
memcpy(di, C + A / 10000 * 5 + 4 - dig, dig);
di += 5 + dig;
}
else {
if (A >= 1000) dig = 4;
else if (A >= 100) dig = 3;
else if (A >= 10) dig = 2;
memcpy(di, C + A * 5 + 4 - dig, dig + 1);
di += 1 + dig;
}
}
}
int A[200001];
ll S[200001];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
rep(i, MAX) {
int X = i;
rep(j, 4) {
C[i * 5 + 3 - j] = '0' + X % 10;
X /= 10;
}
C[i * 5 + 4] = '\n';
}
int N = getint();
rep1(i, N) {
A[i] = getint();
S[i] = S[i - 1] + A[i];
if (A[i - 1] > A[i]) A[i] = A[i - 1];
}
rep1(i, N - 1) S[i + 1] += S[i];
rep1(i, N) putint(A[i] * ll(i) + S[i]);
fwrite(dn, 1, di - dn, stdout);
Would you please return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;
int main(){
string S;
cin >> S;
string T = "";
for(int i = 0;i < 3;i++)T.push_back(S[(i+1)%3]);
cout << T << endl;
//cin >> S;
} | #include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ch() getchar()
#define pc(x) putchar(x)
template<typename T>inline void read(T&x){
int f;char c;
for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;
for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;
}
template<typename T>inline void write(T x){
static char q[64];int cnt=0;
if(!x)pc('0');if(x<0)pc('-'),x=-x;
while(x)q[cnt++]=x%10+'0',x/=10;
while(cnt--)pc(q[cnt]);
}
const int maxn=1005,mod=1000000007;
int mo(const int x){
return x>=mod?x-mod:x;
}
int fac[maxn],iac[maxn];
int binom(int n,int m){
return 1ll*iac[m]*iac[n-m]%mod*fac[n]%mod;
}
char caa[5],cab[5],cba[5],cbb[5];
int main(){
int n;read(n);if(n==2)return puts("1"),0;fac[0]=fac[1]=iac[0]=iac[1]=1;
for(int i=2;i<=n;++i)iac[i]=1ll*(mod-mod/i)*iac[mod%i]%mod;
for(int i=2;i<=n;++i)iac[i]=1ll*iac[i-1]*iac[i]%mod,fac[i]=1ll*fac[i-1]*i%mod;
scanf("%s%s%s%s",caa,cab,cba,cbb);int ans=0;
if(cab[0]=='A'){
if(caa[0]=='A')ans=1;
else{
if(cba[0]=='A'){
ans=1;
for(int i=1;n-3-(i-1)>=i;++i)
ans=mo(ans+binom(n-3-(i-1),i));
}
else{
for(int i=0;i<=n-3;++i)
ans=mo(ans+binom(n-3,i));
}
}
}
else{
if(cbb[0]=='B')ans=1;
else{
if(cba[0]=='B'){
ans=1;
for(int i=1;n-3-(i-1)>=i;++i)
ans=mo(ans+binom(n-3-(i-1),i));
}
else{
for(int i=0;i<=n-3;++i)
ans=mo(ans+binom(n-3,i));
}
}
}
write(ans),pc('\n');
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int n;
mt19937 mt;
bool check(string s, vector<vector<char>>& a, int i, int j) {
bool isOk = true;
for (int k = 0; k < s.size() && isOk; ++k) {
if (s[k] != a[i][(j + k) % n]) {
isOk = false;
}
}
if (isOk) {
return true;
}
for (int k = 0; k < s.size() && isOk; ++k) {
if (s[k] != a[(i + k) % n][j]) {
isOk = false;
}
}
return isOk;
}
int calc(vector<string>& v, vector<vector<char>>& a) {
int cnt = 0;
for (string& s : v) {
bool found = false;
for (int i = 0; i < n && !found; ++i) {
for (int j = 0; j < n && !found; ++j) {
if (check(s, a, i, j)) {
found = true;
}
}
}
cnt += found;
}
return cnt;
}
pair<int, vector<vector<char>>> gen(vector<string>& v) {
shuffle(v.begin(), v.end(), mt);
vector<vector<char>> a(n, vector<char>(n, 'A'));
/*for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
a[i][j] = char(mt() % 8 + int('A'));
}
}*/
int i = 0, j = 0;
for (auto s : v) {
if (j + s.size() >= n) {
j = 0;
++i;
}
if (i >= n) {
break;
}
for (int k = 0; k < s.size(); ++k, ++j) {
a[i][j] = s[k];
}
}
return {calc(v, a), a};
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
mt.seed(time(nullptr));
int m;
cin >> n >> m;
vector<string> v(m);
for (auto& i : v) {
cin >> i;
}
pair<int, vector<vector<char>>> res = gen(v);
for (int i = 0; i < 400; ++i) {
auto curr = gen(v);
if (curr.first > res.first) {
res = curr;
}
}
for (auto& i : res.second) {
for (auto& j : i) {
cout << j;
}
cout << '\n';
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (decltype(n) i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (decltype(n) i = 1, i##_len = (n); i <= i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define plx(s) {cout << (s) << "\n"; exit(0);}
#ifdef __LOCAL
#include <dump.hpp>
#define dump(...) DUMPOUT << " " << string(#__VA_ARGS__) << ": " << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl << " ", dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
using ll = long long; using ld = long double; template<class T> using V = vector<T>;
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> istream &operator>>(istream &is, complex<T> &v) {T x, y; is >> x >> y; v.real(x); v.imag(y); return is;}
template<class T> istream &operator>>(istream &is, V<T> &v) {for (auto&& e : v) is >> e;return is;}
template<class T, size_t n> istream &operator>>(istream &is, array<T, n> &v) {for (auto&& e : v) is >> e;return is;}
template<class T> inline string join(const T& v, string sep = " ") {if (v.size() == 0) return "" ;stringstream ss;for (auto&& e : v) ss << sep << e;return ss.str().substr(1);}
constexpr ll TEN(int n) {return (n == 0) ? 1 : 10 * TEN(n - 1);}
struct IOS {IOS() {cin.tie(nullptr); ios::sync_with_stdio(false); dump("");}} IO;
constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
struct Solver {
V<string> in, out;
ll output_n, input_m;
bool isSubString(string &b) {
rep(i,output_n) rep(j,output_n) rep(d,2) {
bool ok = true;
rep(k,sz(b)) {
ll ni = (i+dy[d]*k) % output_n;
ll nj = (j+dx[d]*k) % output_n;
if (out[ni][nj] != b[k]) {
ok = false;
break;
}
}
if (ok) return true;
}
return false;
}
ld computeScore() {
ll used_count = 0;
ll space_count = 0;
rep(i,output_n) rep(j,output_n) if (out[i][j] == '.') ++space_count;
rep(k,input_m) if (isSubString(in[k])) ++used_count;
ld score = 0;
if (used_count < input_m) {
score = (ld)(TEN(8) * used_count) / (ld)(input_m);
} else {
score = (ld)(TEN(8) * 2 * output_n * output_n) / (ld)(2 * output_n * output_n - space_count);
}
dump(used_count,input_m,score);
return round(score);
}
void solve() {
cin >> output_n >> input_m;
in.resize(input_m); out.resize(output_n);
cin >> in;
V<pair<int,string>> in_for_sort(input_m);
rep(i,input_m) in_for_sort[i] = {sz(in[i]), in[i]};
sort(rall(in_for_sort));
string tmp = "";
rep(i,input_m) tmp += in_for_sort[i].second;
rep(i,output_n) out[i] = tmp.substr(i*output_n, output_n);
ll score = computeScore();
dump(score);
pl(join(out,"\n"));
}
} solver;
signed main(void) {solver.solve();return 0;} |
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RREP(i, n) for(int i=(n);i>=0;--i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, b) for(int i=(a);i>=(b);--i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
REP(i, SZ(v)) {
if (i) os << " ";
os << v[i];
}
return os;
}
template <class T>
void debug(const vector<T> &v) {
cout << "[";
REP(i, SZ(v)) {
if(i) cout << ", ";
cout << v[i];
}
cout << "]" << endl;
}
template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << p.first << " " << p.second;
}
template <class T, class U>
void debug(const pair<T, U> &p) {
cout << "(" << p.first << " " << p.second << ")" << endl;
}
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;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
const ll MOD = 1e9 + 7;
const ll MOD998 = 998244353;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const int inf = INT_MIN;
const ll linf = LLONG_MIN;
const ld eps = 1e-9;
ll modint(ll x, ll n) {
ll res = 1;
while(n > 0) {
if(n & 1) {
res *= x;
res %= MOD;
}
x *= x;
x %= MOD;
n >>= 1;
}
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
ll n, p; cin >> n >> p;
ll ans = (p - 1) * modint(p-2, n-1) % MOD;
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define rep(i,n) for(int i=0;i<(n);++i)
static const ll MOD = 1000000007;
int main(){
ll N,P;
cin>>N>>P;
ll sum = P-1;
ll p = P-2,n=N-1;
/*
while(n>0){
if(n%2) sum = (sum*p)%MOD;
n/=2;
p = (p*p)%MOD;
}
*/
for(int i=0;(1LL<<i)<N;i++){
if((n&(1LL<<i))==(1LL<<i)) sum = (sum*p)%MOD;
p = (p*p)%MOD;
}
cout<<sum;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
double n,m,a;
cin>>n>>m;
// scanf("%lf%lf",n,m);
a=100-((double)(100/n)*m);
printf("%.2lf",a);
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
#define pp pair<ll,ll>
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
int main() {
int n;
ll k;
cin >> n >> k;
vector<pp> a(n);
rep(i,n) cin >> a[i].first >> a[i].second;
sort(all(a));
ll ans=0;
rep(i,n){
if (k>=a[i].first){
k+=a[i].second;
}
else break;
}
cout << k << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ump unordered_map
#define loop(i, a, n) for(long long i=a; i<=n; i++)
#define ub upper_bound
#define lb lower_bound
#define vi vector<long long>
const long long MOD = 1e9+7;
const long long INF = LLONG_MAX;
const long long NINF = LLONG_MIN;
int main(){
ll h,m;
cin >>m >>h;
if(h%m == 0)
cout << "Yes";
else
cout << "No";
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=3;
constexpr ll INF=2e18;
ll power(ll x, ll y){
x%=MOD;
ll ret=1;
while(y){
if(y&1) ret=ret*x%MOD;
x=x*x%MOD;
y>>=1;
}
return ret;
}
ll divid(ll x, ll y){
x%=MOD;
return x*power(y,MOD-2)%MOD;
}
int main(){
int n; cin >> n;
string s; cin >> s;
ll sum=0;
ll a=1, b=1;
ll ac=0, bc=0;
REP(i,n){
int k=0;
if(s[i]=='W')
k=1;
else if(s[i]=='R')
k=2;
if(ac<=bc)
sum=(sum+k*divid(a,b))%3;
if(i==n-1)
break;
ll x=n-1-i;
while(x%3==0){
x/=3;
ac++;
}
a=a*x%3;
ll y=i+1;
while(y%3==0){
y/=3;
bc++;
}
b=b*y%3;
}
if(sum==0)
cout << 'B' << endl;
else if(n%2==0){
if(sum==1)
cout << 'R' << endl;
else
cout << 'W' << endl;
}
else{
if(sum==1)
cout << 'W' << endl;
else
cout << 'R' << endl;
}
return 0;
} |
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
long long n,m;
const long long Maxn=25;
long long a[Maxn],s[Maxn],p[Maxn];
inline long long read()
{
long long s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
return s*w;
}
int main()
{
m=n=read();
p[0]=1ll;
for(long long i=1;i<=19;++i)
p[i]=p[i-1]*10ll;
long long ans=0ll,tmp=0ll;
for(long long i=3;i<=19;i+=3)
{
if(n>=p[i])ans+=(p[i]-p[i-3])*tmp;
else
{
ans+=(n-p[i-3]+1ll)*tmp;
break;
}
++tmp;
}
printf("%lld\n",ans);
return 0;
} | #include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T1, class ...T2>
void kout (T1 v, T2 ...e) { cerr << v << ' ', kout(e...); }
template<class T>
void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#endif
const int MAX_N = 300010, inf = 1e9;
int solve() {
string a = "atcoder", b;
cin >> b;
{
string c = b;
sort(AI(c), greater<>());
DE(a, c);
if (a >= c)
return -1;
}
int res = inf, cur = 0;
if (a < b) return 0;
for (int i = 0;i < a.size();++i) {
if (i == b.size()) break;
if (a[i] < b[i]) {
res = min(res, cur);
break;
}
for (int j = i+1;j < b.size();++j) {
if (a[i] < b[j]) {
res = min(res, j-i + cur);
DE(i, j-i+cur);
}
}
int p = -1;
for (int j = i;j < b.size();++j)
if (b[j] == a[i]) {
p = j;
break;
}
if (p == -1) break;
while (p > i)
swap(b[p], b[p-1]), --p, ++cur;
}
assert(res < inf);
return res;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int T;
cin >> T;
while (T--)
cout << solve() << endl;
}
|
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll n,m,sum[10005];
string s;
bool check(ll x)
{
unsigned ll sum=0;
for(int i=0; i<n; i++)
{
if(sum>m/x) return 0;
sum=sum*x+s[i]-'0';
if(sum>m) return 0;
}
return sum<=m;
}
int main()
{
cin >> s;
cin >> m;
if(s.size()==1)
{
cout << ((s[0]-'0')<=m?1:0) << '\n';
return 0;
}
n=s.size();
int mx=0;
for(int i=0; i<n; i++) mx=max(mx,s[i]-'0');
mx++;
ll l=1,r=m+5;
while(l+1 < r)
{
ll mid=(l+r)>>1;
if(check(mid)) l=mid;
else r=mid;
}
cout << max(r-mx,0LL) << '\n';
return 0;
} | #line 2 "/Users/kaage/Desktop/ProgrammingWorkspace/library/other/template.hpp"
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx2")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define all(V) V.begin(),V.end()
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
typedef std::pair<lint, lint> LP;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
inline lint gcd(lint a, lint b) {
while (b) {
lint c = a;
a = b; b = c % b;
}
return a;
}
inline lint lcm(lint a, lint b) {
return a / gcd(a, b) * b;
}
bool isprime(lint n) {
if (n == 1)return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0)return false;
}
return true;
}
template<typename T>
T mypow(T a, lint b) {
T res(1);
while(b){
if(b&1)res*=a;
a*=a;
b>>=1;
}
return res;
}
lint modpow(lint a, lint b, lint m) {
lint res(1);
while(b){
if(b&1){
res*=a;res%=m;
}
a*=a;a%=m;
b>>=1;
}
return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
rep(i, vec.size()){
std::cout << vec[i];
std::cout<<(i==(int)vec.size()-1?"\n":" ");
}
}
template<typename T>
void printArray(T l, T r) {
T rprev = std::prev(r);
for (T i = l; i != rprev; i++) {
std::cout << *i << " ";
}
std::cout << *rprev << std::endl;
}
LP extGcd(lint a,lint b) {
if(b==0)return {1,0};
LP s=extGcd(b,a%b);
std::swap(s.first,s.second);
s.second-=a/b*s.first;
return s;
}
LP ChineseRem(const lint& b1,const lint& m1,const lint& b2,const lint& m2) {
lint p=extGcd(m1,m2).first;
lint tmp=(b2-b1)*p%m2;
lint r=(b1+m1*tmp+m1*m2)%(m1*m2);
return std::make_pair(r,m1*m2);
}
template<typename F>
inline constexpr decltype(auto) lambda_fix(F&& f){
return [f=std::forward<F>(f)](auto&&... args){
return f(f,std::forward<decltype(args)>(args)...);
};
}
#line 2 "main.cpp"
int main(){
int T;
std::string S,a="atcoder";
std::cin>>T;
rep(i,T){
std::cin>>S;
if(S==std::string(S.size(),'a'))puts("-1");
else{
int ans=INF,now=0;
rep(j,7){
if(a[j]<S[j]){
chmin(ans,now);
break;
}
for(int k=j+1;k<S.size();k++){
if(a[j]<S[k]){
chmin(ans,now+k-j);
break;
}
}
if(a[j]==S[j])continue;
bool f=false;
for(int k=j+1;k<S.size();k++){
if(a[j]==S[k]){
f=true;
for(int l=k;l>j;l--){
std::swap(S[l],S[l-1]);
now++;
}
break;
}
}
if(!f)break;
}
if(a<S)chmin(ans,now);
std::cout<<ans<<std::endl;
}
}
return 0;
}
|
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
template<typename T> class BIT {
private:
int n;
vector<T> bit;
public:
// 0_indexed で i 番目の要素に x を加える
void add(int i, T x) {
i++;
while (i < n) {
bit[i] += x, i += i & -i;
}
}
// 0_indexed で [0,i] の要素の和(両閉区間!!)
T sum(int i) {
i++;
T s = 0;
while (i > 0) {
s += bit[i], i -= i & -i;
}
return s;
}
BIT() {}
//初期値がすべて0の場合
BIT(int sz) : n(sz + 1), bit(n, 0) {}
BIT(const vector<T>& v) : n((int)v.size() + 1), bit(n, 0) {
for (int i = 0; i < n - 1; i++) {
add(i, v[i]);
}
}
void print() {
for (int i = 0; i < n - 1; i++) {
cout << sum(i) - sum(i - 1) << " ";
}
cout << "\n";
}
//-1スタート
void print_sum() {
for (int i = 0; i < n; i++) {
cout << sum(i - 1) << " ";
}
cout << "\n";
}
};
// u を昇順にソートするのに必要な交換回数(転倒数) (u は {0,..., n-1} からなる重複を許した長さ n の数列)
long long inv_count(const vector<int>& u)
{
int n = (int)u.size();
BIT<int> bt(n);
long long ans = 0;
for (int i = 0; i < n; i++) {
ans += i - bt.sum(u[i]);
bt.add(u[i], 1);
}
return ans;
}
// u を v に変換するのに必要な交換回数(転倒数)
// (u, v は {0,..., n-1} からなる重複を許した長さ n の数列. ただし u, v 全体で各数字の個数は一致するものとする)
long long inv_count(const vector<int>& u, const vector<int>& v)
{
int n = (int)u.size();
vector<vector<int> > p(n);
BIT<int> bt(n);
for (int i = n - 1; i >= 0; --i) {
p[u[i]].push_back(i);
}
long long ans = 0;
for (int i = 0; i < n; ++i) {
int pos = p[v[i]].back();
p[v[i]].pop_back();
ans += pos - bt.sum(pos);
bt.add(pos, 1);
}
return ans;
}
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;
}
ll tento = inv_count(A, B);
for (int i = 0; i < N; i++) {
cout << tento << endl;
int low = A[i], high = N - A[i] - 1;
tento += high - low;
}
} | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
v[i] %= 200;
}
map<int, vector<set<int> >> dupa;
for (int i = 0; i < n; i++) {
int x = v[i];
set<int> setik;
map<int, vector<set<int> > > nd;
setik.insert(i);
nd[x].push_back(setik);
if (nd[x].size() > 1) {
return;
}
for (auto p : dupa) {
for (set<int> s : p.second) {
int nx = (p.first + x) % 200;
s.insert(i);
nd[nx].push_back(s);
}
}
for (auto p : nd) {
for (set<int> & s : p.second) {
dupa[p.first].push_back(s);
}
if (dupa[p.first].size() > 1) {
cout << "yes\n";
cout << dupa[p.first][0].size();
for (int z : dupa[p.first][0]) {
cout << " " << z+1;
}
cout << endl;
cout << dupa[p.first][1].size();
for (int z : dupa[p.first][1]) {
cout << " " << z+1;
}
cout << endl;
return;
}
}
}
cout << "no\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << fixed;
cout.precision(12);
int T = 1;
//cin >> T;
for (int t = 0; t < T; t++) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define test ll t; cin>>t; while(t--)
#define ll long long
#define pb push_back
#define mod 10000007
#define pi 3.1415926
int main(){
ll a,b,c; cin>>a>>b>>c;
if(a>b) cout<<"Takahashi";
else if(b>a) cout<<"Aoki";
else{
if(c==0) cout<<"Aoki";
else if(c==1) cout<<"Takahashi";
}
} | #pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
int main(void){
int A, B, C;
cin >> A >> B >> C;
if (C % 2 == 0){
A = abs(A);
B = abs(B);
}
if (A > B) cout << ">" << endl;
else if (A < B) cout << "<" << endl;
else cout << "=" << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ALL(x) x.begin(),x.end()
#define SORT(x) sort(ALL(x))
#define FOR(a,b,c) for(ll (a)= (b);(a)<(c);++(a))
#define REP(a,b) FOR(a,0,b)
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
#define f first
#define s second
int ttt = 1, n, m;
template <class myType>
void print_arr(myType &arr, ll L, string sep){
REP(i,L){
cout << arr[i];
if (i < L-1){
cout << sep;
}
}
cout << endl;
return;
}
/*
If N == 1, obviously possible
Take points S0 and S1.
Iterate over T
for j in 1..n
for k in 1..n, j != k
Match S0 to Tj and S1 to Tk
If |S0 to S1| != |Tj to Tk|, continue
Else:
work out x and y translation
work out angle of rotation of
*/
int dist(pair<double,double> p1, pair<double,double> p2) {
return (p1.f-p2.f)*(p1.f-p2.f) + (p1.s-p2.s)*(p1.s-p2.s);
}
void solve(){
string YY = "Yes", NN = "No";
cin >> n;
vector< pair<double,double> > S(n), t(n);
REP(i,n) cin >> S[i].f >> S[i].s;
REP(i,n) cin >> t[i].f >> t[i].s;
if (n == 1) {
cout << YY << endl;
return;
}
int x = 0, y = 0;
REP(i,n) {
x += S[i].f;
y += S[i].s;
S[i].f *= n;
S[i].s *= n;
}
REP(i,n) {
S[i].f -= x;
S[i].s -= y;
}
x = 0, y = 0;
REP(i,n) {
x += t[i].f;
y += t[i].s;
t[i].f *= n;
t[i].s *= n;
}
REP(i,n) {
t[i].f -= x;
t[i].s -= y;
}
REP(i,n) {
if (S[i].f != 0 || S[i].s != 0) {
swap(S[i],S[0]);
}
}
double tol = 0.000001;
REP(i,n) {
double angle = atan2(t[i].s,t[i].f) - atan2(S[0].s,S[0].f);
bool flag = 1;
REP(j,n) {
double A = S[j].f*cos(angle) - S[j].s*sin(angle);
double B = S[j].f*sin(angle) + S[j].s*cos(angle);
bool flag2 = 0;
REP(k,n) if (std::abs(A - t[k].f) <= tol && std::abs(B - t[k].s) <= tol) flag2 = 1;
flag &= flag2;
}
if (flag) {
cout << YY << endl;
return;
}
}
cout << NN << endl;
return;
}
int main(){
quick;
//cin >> ttt;
while (ttt--) solve();
return 0;
}
| #include <iostream>
using namespace std;
int main() {
long N, M, T;
cin >> N >> M >> T;
long n = N, offset = 0;
for (int i = 0; i < M; i++) {
long A, B;
cin >> A >> B;
offset = A - offset;
n -= offset;
if (n <= 0) {
cout << "No" << endl;
return 0;
};
n += B - A;
if (n >= N) n = N;
offset = B;
}
n -= (T - offset);
if (n <= 0) cout << "No" << endl;
else cout << "Yes" << endl;
return 0;
} |
#pragma GCC optimize("Ofast")
//#pragma GCC target ("sse4")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);
ll mod_pow(ll x, ll n, ll m = mod) {
if (n < 0) {
ll res = mod_pow(x, -n, m);
return mod_pow(res, m - 2, m);
}
if (abs(x) >= m)x %= m;
if (x < 0)x += m;
ll res = 1;
while (n) {
if (n & 1)res = res * x % m;
x = x * x % m; n >>= 1;
}
return res;
}
struct modint {
ll n;
modint() :n(0) { ; }
modint(ll m) :n(m) {
if (n >= mod)n %= mod;
else if (n < 0)n = (n % mod + mod) % mod;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
if (n == 0)return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 2;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[a - b];
}
char mp[5000][5000];
modint dp[5000][5000];
void solve() {
int h, w; cin >> h >> w;
int n; cin >> n;
rep(i, h)rep(j, w)mp[i][j] = '?';
rep(i, n) {
int x, y; char c; cin >> x >> y >> c; x--; y--;
mp[x][y] = c;
}
dp[0][0] = 1;
modint c = (modint)2 / (modint)3;
rep(i, h)rep(j, w) {
char t = mp[i][j];
if (i + 1 < h) {
if (t == 'D' || t == 'X')dp[i + 1][j] += dp[i][j];
else if (t == '?')dp[i + 1][j] += (modint)c * dp[i][j];
}
if (j + 1 < w) {
if (t == 'R' || t == 'X')dp[i][j + 1] += dp[i][j];
else if (t == '?')dp[i][j + 1] += (modint)c * dp[i][j];
}
}
modint pro = 1;
rep(i, h)rep(j, w)if (mp[i][j] == '?')pro *= 3;
cout << pro*dp[h - 1][w - 1] << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
//cout << fixed << setprecision(15);
//init_f();
//init();
//expr();
//int t; cin >> t; rep(i,t)
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
using ll = long long;
using P = pair<ll, ll>;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
ll k; cin >> k;
vector<ll> a(5, 0), b(5, 0);
vector<ll> x(10, k);
string s, t; cin >> s >> t;
rep(i, s.size()) {
if (s[i] == '#') continue;
a[i] = s[i] - '0';
}
rep(i, t.size()) {
if (t[i] == '#') continue;
b[i] = t[i] - '0';
}
rep(i, 5) {
x[a[i]]--, x[b[i]]--;
}
// rep(i, 5) {
// cout << a[i] << " ";
// }
// cout << endl;
// rep(i, 5) {
// cout << b[i] << " ";
// }
// cout << endl;
// rep(i, 10) cout << x[i] << " ";
// cout << endl;
double ans = 0;
auto calc = [&]() {
vector<ll> cnt1(10), cnt2(10);
rep(i, a.size()) cnt1[a[i]]++;
rep(i, b.size()) cnt2[b[i]]++;
ll score1 = 0, score2 = 0;
for (ll i = 1; i < 10; i++) {
ll res = 1;
rep(j, cnt1[i]) res *= 10;
score1 += res * i;
}
for (ll i = 1; i < 10; i++) {
ll res = 1;
rep(j, cnt2[i]) res *= 10;
score2 += res * i;
}
double res = 0;
if (score1 > score2) {
if (a[4] == b[4]) {
res = double(x[a[4]] * (x[a[4]] - 1)) / (double(9 * k - 8) * double(9 * k - 9));
}
else {
res = double(x[a[4]] * x[b[4]]) / (double(9 * k - 8) * double(9 * k - 9));
}
}
return res;
};
rep(i, 9) {
rep(j, 9) {
a[4] = i + 1, b[4] = j + 1;
ans += calc();
// cout << fixed << setprecision(15) << calc() << endl;
}
}
cout << fixed << setprecision(15) << ans << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a;
cin >> a;
int b;
b = a-1;
cout << b;
return 0;
} | /*
ID: tdpenci1
LANG: C++
TASK: beads
*/
#include "bits/stdc++.h"
using namespace std;
#pragma optimize ("Ofast")
typedef long long ll;
#define all(x) x.begin(), x.end()
#define trav(i, x) for(auto &i : x)
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define FOR(i, N) for(int i = 0; i < (N); i++)
#define vt vector
const ll mod = 1e9 + 7;
const int mxA = 1e7;
void io(const string s="") {
if(s != "") {
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
} else {
ios_base::sync_with_stdio(false); cin.tie(0);
}
}
bool ispal(string v) {
string t=v;
reverse(t.begin(),t.end());
return v==t;
}
void solve() {
int n; cin >> n;
cout << (n-1) << "\n";
}
int main() {
io();
int t = 1, i = 1;
while(t--) {
solve();
}
}
|
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k;
string s;
int power(int l){
int m=1;
for(int i=1;i<=l;i++){
m*=2;
}
return m;
}
int revi(char a,char b){
if(a=='P'&&b=='R'){
return a;
}
if(a=='P'&&b=='S'){
return b;
}
if(a=='S'&&b=='P'){
return a;
}
if(a=='S'&&b=='R'){
return b;
}
if(a=='R'&&b=='S'){
return a;
}
return b;
}
void last10(){
char c[10005];
int m=power(k);
for(int i=1;i<=m;i++){
if(i%n==0){
c[i]=s[n-1];
}
else{
c[i]=s[i%n-1];
}
}
while(m!=1){
m/=2;
for(int i=1;i<=m;i++){
c[i]=revi(c[i*2-1],c[i*2]);
}
}
cout<<c[1];
}
signed main() {
cin>>n>>k;
cin>>s;
if(k>10){
char c[205];
for(int i=1;i<=2*n;i++){
if(i%n==0){
c[i]=s[n-1];
}
else{
c[i]=s[i%n-1];
}
}
while(k>10){
k--;
for(int i=1;i<=n;i++){
c[i]=revi(c[i*2-1],c[i*2]);
}
for(int i=1;i<=2*n;i++){
if(i%n==0){
c[i]=c[n];
}
else{
c[i]=c[i%n];
}
}
}
for(int i=1;i<=n;i++){
s[i-1]=c[i];
}
}
last10();
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep1(i,n) for (int i=1;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
bool my_compare(pair<int, int> a, pair<int, int> b) {
// 基本はfirstで比較
if(a.first != b.first){
// return a.first < b.first; // 昇順
return a.first > b.first; // 降順
}
// それ以外はsecondで比較
if(a.second != b.second){
return a.second < b.second;
}else{
// どちらも同じ
return true;
}
}
int main() {
int n, m, q;
cin >> n >> m >> q;
vector<P> item(n);
vector<int> x(m);
rep(i,n){
int w,v;
cin >> w >> v;
item[i].second = w;
item[i].first = v;
}
rep(i,m){
cin >> x[i];
}
// sort(item.begin(), item.end(), my_compare);
sort(item.begin(), item.end(), [](P a, P b){
return a.first>b.first || (a.first ==b.first && a.second<b.second);
});
// for(int i=0; i<item.size(); i++){
// cout << item[i].first << ' ' << item[i].second << endl;
// }
rep(i,q){
int l, r;
cin >> l >> r;
vector<int> box(m);
box = x;
for(int k=l-1;k<r;k++){
box[k] = 0;
}
ll sum = 0;
sort(box.begin(),box.end());
rep(j,n){
int value = item[j].first;
int weight = item[j].second;
rep(k,m){
if(box[k] >= weight){
box[k] = 0;
sum += value;
break;
}
}
}
cout << sum << endl;
}
//
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S;
cin >> N >> S;
if(S[0] != S[N-1]) {
cout << 1 << endl;
}
else {
bool flag = false;
for(int i = 1; i < N-2; i++) {
if(S[0] != S[i] && S[N-1] != S[i+1]) {
flag = true;
}
}
if(flag) {
cout << 2 << endl;
}
else {
cout << -1 << endl;
}
}
}
| #include<bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const ll inf=1e18+5;
const int mod=1e9+7;
int main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ll b,c;
cin>>b>>c;
ll l1=b-c/2, r1=b+(c-2)/2, l2=-b-(c-1)/2, r2=-b+(c-1)/2;
if(r1<l2 || r2<l1){
cout<<r1-l1+1+r2-l2+1<<endl;
}
else{
cout<<max(r1,r2)-min(l1,l2)+1<<endl;
}
} |
#include <bits/stdc++.h>
#include <string>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
const ll MOD=1000000007ll;
const int MAX=5100000;
using namespace std;
int inputValue(){
int a;
cin >> a;
return a;
};
void inputArray(int * p, int a){
for(int i=0;i<a;i++){
cin >> p[i];
}
};
void inputVector(vector<int> * p, int a){
for(int i=0;i<a;i++){
int input;
cin >> input;
p -> push_back(input);
}
}
ll fact[MAX], fact_inv[MAX];
ll power(ll a, ll b){
ll res=1;
while(b>0){
if(b&1) res=res*a%MOD;
a=a*a%MOD;
b>>=1;
}
return res;
}
// nCr
ll comb(ll n, ll r){
ll t=1000000;
fact[0]=1;
for(int i=0;i<t;i++){ fact[i+1]=fact[i]*(i+1)%MOD;}
fact_inv[t]=power(fact[t], MOD-2);
for(int i=0;i<t;i++){ fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;}
return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
ll i,j,k,tmp;
//ll ans = 0;
int main()
{
cin.tie(0); ios::sync_with_stdio(false);
int N; cin >> N;
//グラフ定義
vector<pair<ll,ll>> edge(N-1); // 辺
vector<vector<ll>> graph(N); // グラフ(頂点ごとに隣接する点のvectorを保持)
rep(i,N-1){
ll a, b; cin >> a >> b; a--; b--; // 0-index
edge[i] = {a,b};
graph[a].push_back(b);
graph[b].push_back(a);
}
vector<ll> depth(N,-1); // 頂点の深さ(-1で初期化)
depth[0] = 0;
vector<ll> v1; v1.push_back(0);
// 各頂点の深さを計算(幅優先探索)
while(v1.size() > 0){
ll now = v1.back(); v1.pop_back();
for(ll i : graph[now]){
if(depth[i] == -1){
depth[i] = depth[now] + 1; v1.push_back(i);
}
}
}
// クエリ処理
vector<ll> ans(N,0);
ll Q; cin >> Q;
rep(i,Q){
ll t,e,x; cin >> t >> e >> x;
pair<ll,ll> p = edge[e-1];
if(t == 1){
if(depth[p.first] > depth[p.second]){
ans[p.first] += x;
}
else{
ans[p.second] -= x; ans[0] += x;
}
}
else{
if(depth[p.first] > depth[p.second]){
ans[p.first] -= x; ans[0] += x;
}
else{
ans[p.second] += x;
}
}
}
vector<ll> v2; v2.push_back(0);
// 各頂点の答えを計算(幅優先探索)
while(v2.size() > 0){
ll now = v2.back(); v2.pop_back();
for(ll i : graph[now]){
if(depth[i] > depth[now]){
ans[i] += ans[now]; v2.push_back(i);
}
}
}
rep(i,N){cout << ans[i] << endl;}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n, a, b, q, c[200007], buf, p[200007];
vector<pair<ll, ll>> e;
vector<pair<ll, bool>> op[200007];
vector<ll> adj[200007];
void find_parent(ll x, ll par) {
p[x] = par;
for(ll i : adj[x]) {
if(i != par) {
find_parent(i, x);
}
}
}
void dfs(ll x, ll add) {
ll cur = add;
for(pair<ll, bool> i : op[x]) {
if(i.second) {
cur += i.first;
} else {
cur -= i.first;
buf += i.first;
}
}
c[x] += cur;
for(ll i : adj[x]) {
if(i != p[x]) {
dfs(i, cur);
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(ll i = 0; i < n - 1; ++i) {
cin >> a >> b;
e.push_back({a, b});
adj[a].push_back(b);
adj[b].push_back(a);
}
find_parent(1, -1);
cin >> q;
for(ll i = 0; i < q; ++i) {
ll t, k, x;
cin >> t >> k >> x;
k--;
if(t == 1) { //1 - adding to subtree, 0 - subtracting and adding to buffer
if(p[e[k].first] == e[k].second) op[e[k].first].push_back({x, 1});
else op[e[k].second].push_back({x, 0});
} else {
if(p[e[k].second] == e[k].first) op[e[k].second].push_back({x, 1});
else op[e[k].first].push_back({x, 0});
}
}
dfs(1, 0);
for(ll i = 1; i <= n; ++i) cout << c[i] + buf << '\n';
return 0;
} |
#include<bits/stdc++.h>
#define w(x) int x; cin>>x; for(int tc=1;tc<=x;tc++)
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
#define trace1(x,y) cerr<<#x<<": "<<x<<" "<<endl;cerr<<#y<<": "<<y<<" "<<endl;
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pb push_back
#define endl "\n"
#define mod 1000000007
#define inp(x) cin>>x;
#define f first
#define s second
#define inf 1e18
using namespace std;
void solve(int tc) {
int a, b;
cin >> a >> b;
if (a == b) {
cout << a << endl;
} else {
if (a == 0 and b == 1) {
cout << 2 << endl;
} else if (a == 1 and b == 2) {
cout << 0 << endl;
} else if (a == 0 and b == 2) {
cout << 1 << endl;
} else {
swap(a, b);
if (a == 0 and b == 1) {
cout << 2 << endl;
} else if (a == 1 and b == 2) {
cout << 0 << endl;
} else if (a == 0 and b == 2) {
cout << 1 << endl;
}
}
}
}
int32_t main() {
FIO
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
// w(x) {
solve(1);
// }
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int A, B;
cin >> A >> B;
if(A==B) cout << A << endl;
else cout << 3-A-B << endl;
} |