code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include<bits/stdc++.h> #define int long long using namespace std; inline 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*10+ch-'0',ch=getchar(); return s*w; } int a[103]; int f[103][103]; signed main() { int n=read(),x=read(); int M=0; for(int i=1; i<=n; i++) a[i]=read(),M=max(M,a[i]); int ans=x-M; for(int i=2; i<=n; i++) { //use i elements int t=x%i; //the goal memset(f,-1,sizeof(f)); f[0][0]=0; for(int j=1; j<=n; j++) { int g=a[j]%i; for(int A=j; A>=1; A--) for(int k=0; k<i; k++) if(f[A-1][k]!=-1) { f[A][(k+g)%i]=max(f[A][(k+g)%i],f[A-1][k]+a[j]); } } if(f[i][t]!=-1) ans=min(ans,(x-f[i][t])/i); } printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; // #define int long long typedef pair<int, int> pii; #define ll long long #define ar array const int mxN=1e5+1; const int mod=1e9+7; const ll INF=1e18; #define what_is(x) cerr << #x << " is " << x << endl; vector<int> adj[mxN]; ll dp[(1<<18)][18]; ll d[19][mxN]; ll c[19]; int n,m; void bfs(int cur,int src){ for(int i=0;i<=n;i++){ d[cur][i]=INF; } d[cur][src]=0; queue<int> q; q.push(src); while(!q.empty()){ int u=q.front(); q.pop(); for(int v:adj[u]){ if(d[cur][v] == INF){ d[cur][v]=d[cur][u]+1; q.push(v); } } } } void solve(){ cin>>n>>m; for(int i=0;i<m;i++){ int x,y; cin>>x>>y;--x,--y; adj[x].push_back(y); adj[y].push_back(x); } int k; cin>>k; for(int i=0;i<k;i++){ cin>>c[i]; c[i]--; bfs(i,c[i]); } for(int mask=1;mask<(1<<k);mask++){ // initialize mask if(__builtin_popcount(mask)==1){ for(int i=0;i<k;i++){ if((1<<i)&mask){ dp[mask][i]=1; }else{ dp[mask][i]=INF; } } continue; } for(int i=0;i<k;i++){ // i is my left edge which I want to add dp[mask][i]=INF; if(mask&(1<<i)){ // pick all other active bit in mask except i (mask^(1<<i)) for(int j=0;j<k;j++){ if((1<<j)&(mask^(1<<i))){ dp[mask][i]=min(dp[mask][i],dp[mask^(1<<i)][j]+d[i][c[j]]); } } } } } ll ans=INF; for(int i=0;i<k;i++){ ans=min(ans,dp[(1<<k)-1][i]); } if(ans==INF){ ans=-1; } cout<<ans<<endl; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout<<setprecision(12)<<fixed; int t=1; // cin>>t; while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using int64 = long long; constexpr int DEBUG = 0; template<typename T> vector<vector<T>> Make2DVector(int d1, int d2, T default_value) { return vector<vector<T>>(d1, vector<T>(d2, default_value)); } constexpr int MAX_V = 130000; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k, m; cin >> n >> k >> m; auto dp = Make2DVector<int>(n, MAX_V + 1, 0); dp[0][0] = 1; for (int i = 1; i < n; i++) { for (int j = 0; j <= MAX_V; j++) { if (dp[i - 1][j] == 0) continue; for (int l = 0; l <= k; l++) { if (j + i * l > MAX_V) break; dp[i][j + i * l] += dp[i - 1][j]; if (dp[i][j + i * l] >= m) { dp[i][j + i * l] -= m; } } } } for (int x = 1; x <= n; x++) { int a = n - x; int b = x - 1; int64 ans = 0; for (int v = 0; v <= MAX_V; v++) { ans += static_cast<int64>(dp[a][v]) * static_cast<int64>(dp[b][v]); ans %= m; } ans *= k + 1; // ans -= 1; ans += m - 1; ans %= m; cout << ans << endl; } }
//Relive your past life. //Face your demons. //The past is never dead,it is not even past. //The memories are not only the key to the past but...also to the future. //coded in Rusty Lake #include<cmath> #include<math.h> #include<ctype.h> #include<algorithm> #include<bitset> #include<cassert> #include<cctype> #include<cerrno> #include<cfloat> #include<ciso646> #include<climits> #include<clocale> #include<complex> #include<csetjmp> #include<csignal> #include<cstdarg> #include<cstddef> #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> #include<cwchar> #include<cwctype> #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<string.h> #include<stdlib.h> #include<stdio.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define ll long long #define pb push_back #define mp make_pair #define orz 1000000007 using namespace std; int n,k,m,ans[105],f[240005],a[105]; int main(){ srand(time(0)); scanf("%d%d%d",&n,&k,&m); for(int i=1;i*2-1<=n;++i){ memset(f,0,sizeof(f)); f[120000]=1; for(int j=1;j<=n;++j)a[j]=j-i; random_shuffle(a+1,a+n+1); for(int j=1;j<=n;++j){ int t=a[j]; if(!t) continue; if(t>0){ int T=t*k; for(int s=230000;s>230000-t;--s){ int o=0; for(int I=0;I<k;++I){ o+=f[s-I*t]; if(o>=m)o-=m; } for(int q=s;q>=10000;q-=t){ o+=f[q-T]-f[q]; if(o<0)o+=m; else if(o>=m)o-=m; f[q]+=o; if(f[q]>=m)f[q]-=m; } } } else{ t=-t; int T=t*k; for(int s=10000;s<10000+t;++s){ int o=0; for(int I=0;I<k;++I){ o+=f[s+I*t]; if(o>=m)o-=m; } for(int q=s;q<=230000;q+=t){ o+=f[q+T]-f[q]; if(o<0)o+=m; else if(o>=m)o-=m; f[q]+=o; if(f[q]>=m)f[q]-=m; } } } } ans[i]=ans[n+1-i]=(f[120000]*1ll*(k+1ll)-1ll)%m; } for(int i=1;i<=n;++i)printf("%d\n",ans[i]); return 0; }
#include <vector> #include <array> #include <stack> #include <queue> #include <list> #include <bitset> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <algorithm> #include <numeric> #include <iostream> #include <iomanip> #include <string> #include <chrono> #include <random> #include <cmath> #include <cassert> #include <climits> #include <cstring> #include <cstdlib> #include <functional> #include <sstream> using namespace std; int main(int argc, char** argv) { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(12); int n; cin >> n; vector<pair<int,int>> S(n); vector<pair<int,int>> T(n); for (int i = 0; i < n; ++i) { cin >> S[i].first >> S[i].second; } for (int i = 0; i < n; ++i) { cin >> T[i].first >> T[i].second; } auto dis2 = [&](const pair<int,int>& P) { long long x = P.first, y = P.second; return x * x + y * y; }; auto dis = [&](const pair<int,int>& A, const pair<int,int>& B) { long long x = A.first - B.first; long long y = A.second - B.second; return x * x + y * y; }; auto crossProduct = [&](pair<int,int>& A, pair<int,int>& B) { return A.first * B.second - A.second * B.first; }; auto cmp = [&](const pair<int,int>& l, const pair<int,int>& r) { auto L = atan2(l.second, l.first); auto R = atan2(r.second, r.first); if (L == R) { return dis2(l) < dis2(r); } else { return L < R; } }; auto build = [&](int s, vector<pair<int,int>>& P) { int n = P.size(); vector<pair<int,int>> res; for (int i = 0; i < n; ++i) { if (i == s) { continue; } int x = P[i].first - P[s].first; int y = P[i].second - P[s].second; res.emplace_back(x, y); } sort(res.begin(), res.end(), cmp); return res; }; auto check = [&](vector<pair<int,int>>& A, vector<pair<int,int>>& B) { int n = A.size(); if (n == 0) { return true; } for (int i = 0; i < n; ++i) { if (dis2(A[0]) != dis2(B[i])) { continue; } bool ok = true; for (int j = 1; j < n; ++j) { int k = (i + j) % n; if (dis2(A[j]) != dis2(B[k])) { ok = false; } if (dis(A[j], A[0]) != dis(B[k], B[i])) { ok = false; } if (crossProduct(A[j], A[0]) != crossProduct(B[k], B[i])) { ok = false; } if (!ok) { break; } } if (ok) { // for (auto& p : A) { // cout << p.first << ',' << p.second << endl; // } // cout << i << " " << endl; // for (auto& p : B) { // cout << p.first << "," << p.second << endl; // } // cout << "-----" <<endl; return true; } } return false; }; bool res = false; for (int i = 0; i < n; ++i) { auto A = build(i, S); for (int j = 0; j < n; ++j) { auto B = build(j, T); if (check(A, B)) { res = true; break; } } if (res) { break; } } if (res) { cout << "Yes\n"; } else { cout << "No\n"; } return 0; }
#include <bits/stdc++.h> #define lc (o<<1) #define rc ((o<<1)|1) using namespace std; #define DebugP(x) cout << "Line" << __LINE__ << " " << #x << "=" << x << endl typedef long long LL; typedef complex<double> Comp; const int maxn = 5e5 + 5; const int inf = 0x3f3f3f3f; const int modu = 1e9 + 7; template<class T> inline void read(T &x) { x=0;int f=0;char ch=getchar(); while(ch<'0'||ch>'9') {f|=(ch=='-');ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} x=f?-x:x; return; } template<class T, class ...U> void read(T &x, U& ... u) { read(x); read(u...); } struct Edge { int u, v; LL T, K; Edge(int u=0, int v=0, LL T=0, LL K=0): u(u), v(v), T(T), K(K) {} }; vector<Edge> edges; vector<int> G[maxn]; int n, m, x, y; void addEdge(int u, int v, LL T, LL K) { edges.push_back(Edge(u, v, T, K)); G[u].push_back(edges.size()-1); } LL dist[maxn]; struct Node { LL d; int id; Node(LL d=0, int id=0): d(d), id(id) {} bool operator<(const Node &op) const { return d > op.d; } }; priority_queue<Node> Q; bool vis[maxn]; int main() { // freopen("input.txt", "r", stdin); read(n, m, x, y); for (int i = 0; i < m; ++i) { int a, b, c, d; read(a, b, c, d); addEdge(a, b, c, d); addEdge(b, a, c, d); } memset(vis, 0, sizeof(vis)); memset(dist, 0x3f, sizeof(dist)); dist[x] = 0; Q.push(Node(dist[x], x)); while (!Q.empty()) { while (!Q.empty() && vis[Q.top().id]) Q.pop(); if (Q.empty()) break; int u = Q.top().id; Q.pop(); vis[u] = 1; for (int i: G[u]) { Edge &e = edges[i]; if (dist[e.v] > (dist[u]/e.K + (dist[u]%e.K > 0))*e.K + e.T) { dist[e.v] = (dist[u]/e.K + (dist[u]%e.K > 0))*e.K + e.T; Q.push(Node(dist[e.v], e.v)); } } } if (dist[0] == dist[y]) printf("-1\n"); else printf("%lld\n", dist[y]); return 0; }
/******************************************************/ /******************************************************/ /** **/ /** BISMILLAHIR RAHMANIR RAHIM **/ /** REAZ AHAMMED CHOWDHURY - reaziii **/ /** Department of Computer Science and Engineering **/ /* INSTITUTE OF SCIENCE AND TECHNOLOGY **/ /** **/ /******************************************************/ /******************************************************/ #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define pcase(x) printf("Case %d: ",x++) #define fri(f) for(int i=0;i<f;i++) #define frj(f) for(int j=0;j<f;j++) #define reset(x) memset(x,-1,sizeof(x)) #define all(x) x.begin(),x.end() #define input freopen("input.txt","r",stdin); #define output freopen("output.txt","w",stdout) #define infi INT_MAX #define linfi LLONG_MAX #define pii pair<int,int> #define pll pair<ll,ll> #define mgraph map<int,vector<int> > #define pb push_back #define clr(x) memset(x,0,sizeof(x)) #define fro(i,x,y) for(int i=x;i<y;i++) #define ech(x,a) for(auto &x : a) #define ff first #define ss second #define vi vector<int> #define vl vector<ll> #define pi acos(-1.0) using namespace std; using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<class T> void read(T& x) {cin >> x;} template<class H, class... T> void read(H& h, T&... t) {read(h); read(t...);} template<class A> void read(vector<A>& x) {for (auto &a : x) read(a);} template<class H> void print(vector<H> &x) {ech(a, x) cout << a << " "; cout << endl;} template<class P> void debug(P h) { #ifndef ONLINE_JUDGE cerr << h << " "; #endif } template<class W, class... V> void debug(W h, V... t) { #ifndef ONLINE_JUDGE debug(h); debug(t...); cerr << endl; #endif } typedef long long int ll; typedef long double ld; typedef unsigned long long int ull; bool checkbitt(ll num, int pos) {return (num >> pos) & 1;} ll setbitt(ll num, ll pos) {return (1 << pos) | num;} ll resetbitt(ll num, int pos) {if (!checkbitt(num, pos)) return num; else return (1 << pos)^num;} ll bigmod(ll a, ll b, ll mod) {if (b == 0) return 1; if (b == 1) return a; if (b & 1) {return ((a % mod) * (bigmod(a, b - 1, mod) % mod)) % mod;} ll x = bigmod(a, b / 2, mod); return (x * x) % mod;} ll geti() {ll x; read(x); return x;} const ll mod = 1e9 + 7; const ll N = 2e5 + 10; int dx[4] = { +0, +0, +1, -1}; int dy[4] = { -1, +1, +0, +0}; //................................___Start from here___...............................// //................................_____________________..............................// int solve() { int n, k; string s; read(n, k, s); fri(n) { if (s[i] == 'o') k++; else { k--; k = max(0, k); } } cout << k << endl; return 0; } int main(int argc, char* argv[]) { if (argc <= 1) { #ifndef ONLINE_JUDGE input; output; #endif #ifdef ONLINE_JUDGE ios_base::sync_with_stdio(false); cin.tie(0); #endif } int cs = 1, cn = 1; // read(cs); while (cs--) { solve(); } }
#include<bits/stdc++.h> #define ll long long using namespace std; const ll N=2e5+5,M=2e5,mod=998244353; ll n,m,mi[N],jc[N*2],s[N],ans,save[N],inv[N*2],jcinv[N*2]; ll qpow(ll n,ll k){ ll t=1; while(k){ if(k&1)t=t*n%mod; n=n*n%mod; k>>=1; } return t; } // ll C(ll n,ll m){ // return jc[n]*qpow(jc[m],mod-2)%mod*qpow(jc[n-m],mod-2)%mod; // } ll C(ll n,ll m){ return jc[n]*jcinv[m]%mod*jcinv[n-m]%mod; } ll solve(ll x){ ll t=x,sum=1; while(t!=1){ ll c=0,p=mi[t]; while(t%p==0)t/=p,c++; sum=sum*s[c]%mod; } return sum; } int main() { ll i,j,x; cin>>m>>n;m--; for(i=2;i<=M;i++){ if(mi[i])continue; for(j=i;j<=M;j+=i) if(!mi[j])mi[j]=i; } jc[0]=jc[1]=1; inv[1]=1; jcinv[1]=jcinv[0]=1; for(i=2;i<=n+m;i++)jc[i]=jc[i-1]*i%mod; for(i=2;i<=n+m;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod; for(i=2;i<=n+m;i++)jcinv[i]=jcinv[i-1]*inv[i]%mod; for(i=1;i<=n;i++)s[i]=C(i+m-1,m-1); for(i=1;i<=n;i++)save[i]=solve(i); for(i=2;i<=n;i++)save[i]+=save[i-1]; for(i=1;i<=n;i++){ x=n/i; ans=(ans+save[x])%mod; } cout<<ans; }
#include <iostream> #include <bits/stdc++.h> #define For(i,x,y) for(int i = (x); i <= (y); i ++ ) #define fori(i,x,y) for(int i = (x); i < (y); i ++ ) #define mp make_pair #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define endl '\n' #define all(x) a.begin(), a.end() #define mst(x,a) memset(x, a, sizeof x) #define debug(a) cout<< #a <<": " << a << endl using namespace std; typedef long long LL; typedef pair<int,int>pa; const int inf = 0x3f3f3f3f; const int INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9+7; const int maxn = 2e5+10; const int maxm = 1e6+10; const int N = 1e6+10; int dp[maxn][20][2][2]; int a[maxn], n, k; int dfs(int x, int sta, bool lead = true, bool limit = true){ int cnt = __builtin_popcount(sta); int& ans = dp[x][cnt][lead][limit]; if(~ans) return ans; if(cnt > k) return ans = 0; if(x==n) return cnt==k; int up = limit?a[x]:15; ans = 0; For(i,0,up){ int add = dfs(x+1, (lead&&!i) ? sta : sta|1<<i, !i&&lead, limit && i == up); ans = (LL)ans + add; if(ans >= mod) ans -= mod; } return ans; } int main() { ios::sync_with_stdio(0); #ifdef LOCAL freopen("in.txt", "r", stdin); #endif string s; cin>>s>>k; mst(dp,-1); n = sz(s); fori(i,0,n)a[i] = isdigit(s[i])?s[i]-'0':s[i]-'A'+10; printf("%d\n", dfs(0,0)); return 0; }
#include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<algorithm> #include<queue> #include<vector> #include<cstring> #include<map> #include<set> #include<cstdlib> #include<bitset> using namespace std; #define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) typedef long long ll; #define N 200005 ll p=1e9+7; ll n,m,f[N][17][17]={0},v[22]={0},sm; char a[N]; int main() { ll i,j,k,a1,a2,an=0; scanf("%s",a+1); n=strlen(a+1); for(ll i=1;i<=n;i++) if(a[i]>='0'&&a[i]<='9') a[i]-='0'; else a[i]-='A'-10; scanf("%lld",&m); for(ll i=0;i<=m;i++) f[0][i][i]=1; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) for(ll k=j;k<=m;k++) f[i][j][k]=((ll)f[i-1][j][k-1]*(17ll-k)+(ll)f[i-1][j][k]*k)%p; for(ll i=1;i<=n;i++) an=(an+15ll*f[i-1][1][m])%p; // for(ll i=1;i<=n;i++) // { // for(ll j=1;j<=m;j++) // for(ll k=j;k<=m;k++)printf("%lld\n",f[i][j][1]); // } for(ll i=1;i<=n;i++) { for(ll j=a[i]+1;j<=15;j++) an=(an-f[n-i][sm+(!v[j])][m]+p)%p; //printf("%lld\n",an); sm+=!v[a[i]]; v[a[i]]=1; } printf("%lld",an); }
/************************************************************** * Problem: * Author: Vanilla_chan * Date: **************************************************************/ #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #include<map> #include<set> #include<queue> #include<vector> #include<limits.h> #define IL inline #define re register #define LL long long #define ULL unsigned long long #ifdef TH #define debug printf("Now is %d\n",__LINE__); #else #define debug #endif #ifdef ONLINE_JUDGE char buf[1<<23],* p1=buf,* p2=buf,obuf[1<<23],* O=obuf; #define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++) #endif using namespace std; template<class T>inline void read(T& x) { char ch=getchar(); int fu; while(!isdigit(ch)&&ch!='-') ch=getchar(); if(ch=='-') fu=-1,ch=getchar(); x=ch-'0';ch=getchar(); while(isdigit(ch)) { x=x*10+ch-'0';ch=getchar(); } x*=fu; } inline int read() { int x=0,fu=1; char ch=getchar(); while(!isdigit(ch)&&ch!='-') ch=getchar(); if(ch=='-') fu=-1,ch=getchar(); x=ch-'0';ch=getchar(); while(isdigit(ch)) { x=x*10+ch-'0';ch=getchar(); } return x*fu; } int G[55]; template<class T>inline void write(T x) { int g=0; if(x<0) x=-x,putchar('-'); do { G[++g]=x%10;x/=10; } while(x); for(int i=g;i>=1;--i)putchar('0'+G[i]);putchar('\n'); } #define N 110 LL gcd(LL a,LL b) { if(b) return gcd(b,a%b); return a; } int n,x[N]; bool book[N]; int prime[N],cnt; void init() { book[1]=1; for(int i=2;i<=50;i++) { if(!book[i]) { prime[++cnt]=i; for(int j=2;i*j<=50;j++) book[i*j]=1; } } } bool y[N]; LL ans=1e18+5; LL check() { LL tmp=1; for(int i=1;i<=cnt;i++) if(y[i]) tmp*=prime[i]; for(int i=1;i<=n;i++) { if(gcd(tmp,x[i])==1) return 0; } return tmp; } void dfs(int p) { LL t; if(t=check()) { ans=min(ans,t); return; } if(p==cnt+1) return; dfs(p+1); y[p]=1; dfs(p+1); y[p]=0; } int main() { n=read(); init(); for(int i=1;i<=n;i++) x[i]=read(); dfs(1); write(ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, l, r) for (int i = l; i <= (int)(r); i++) #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define all(v) v.begin(), v.end() #define MOD (int) (1e9+7) #define INF (int) 1e9 #define LLINF (ll) 1e18 int main(){ int n; cin >> n; ll x[n]; rep(i, n) cin >> x[i]; vector<int> ps{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}; ll ans = LLINF; rep(ni, 1<<ps.size()){ vector<int> use(15); int ii = ni; rep(iii, 15){ use[iii] = ii&1; ii >>= 1; } ll tmp = 1; rep(i, 15){ if(use[i]==1) tmp *= ps[i]; } bool ok = true; rep(i, n){ if(__gcd(tmp, x[i])==1) ok = false; } if(ok) chmin(ans, tmp); } cout << ans << endl; // printf("%d\n", N); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<long long> Vll; ll mm=1000000000;ll MM=mm+7; #define rep(i, n) for(int i=0;i<n;i++) #define PI 3.141592653589793 int main(){ string s; cin >> s; ll cnto=0; ll cntx=0; ll cnt=0; rep(i,10){ if(s[i]=='o')cnto++; else if(s[i]=='x')cntx++; else cnt++; } ll ans=1; if(cnto>4 || cntx==10)ans=0; else if(cnto==4){ ans=4*3*2*1; } else if(cnto==3){ ans=36+4*3*2*1*cnt; } else if(cnto==2){ ans=14+cnt*6*4+cnt*cnt*12; } else if(cnto==1){ ans=1+cnt*4+cnt*cnt*6+cnt*cnt*cnt*4; } else{ ans=cnt*cnt*cnt*cnt; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ string s; cin >> s; ll knt = 0; for(int i = 0;i < 10;i++){ for(int j = 0;j < 10;j++){ for(int k = 0;k < 10;k++){ for(int l = 0;l < 10;l++){ string t = s; bool flag = true; if(t.at(i) == 'x') flag = false; if(t.at(j) == 'x') flag = false; if(t.at(k) == 'x') flag = false; if(t.at(l) == 'x') flag = false; t.at(i) = 'x'; t.at(j) = 'x'; t.at(k) = 'x'; t.at(l) = 'x'; rep(y,10){ if(t.at(y) == 'o') flag = false; } if(flag) knt++; } } } } cout << knt << endl; }
#include <bits/stdc++.h> using namespace std; using C = complex<double>; C unko(){ double x,y; cin>>x>>y; return C(x,y); } int main(void){ int n; cin>>n; C s=unko(); C t=unko(); C o=(s+t)/2.0; double PI=acos(-1); double rad=2*PI/n; C r(cos(rad),sin(rad)); C ans=o+r*(s-o); cout<<fixed<<setprecision(10)<<ans.real()<<" "<<ans.imag()<<endl; return 0; }
#include <bits/stdc++.h> // clang-format off using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18; void print0() {} template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);} void print() { print0("\n"); } template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);} // clang-format on int main() { ll t; cin >> t; for (ll i = 0; i < t; i++) { ll l, r; cin >> l >> r; ll mn = l + l; ll mx = r; if (mn > mx) { print(0); continue; } ll n = mx - mn + 1; print(n * (n + 1) / 2); } }
#include<bits/stdc++.h> using namespace std; struct { int x, y, z; }city[18], a, b; int drum[18][18], total_cost = INT_MAX, cities, t, cost[(1 << 18)][18]; int distance(int i, int j) { a = city[i]; b = city[j]; return abs(b.x - a.x) + abs(b.y - a.y) + max(0, b.z - a.z); } int main() { cin >> cities; for (int i = 1; i <= cities; i++) cin >> city[i].x >> city[i].y >> city[i].z; for (int i = 1; i <= cities; i++) for (int j = 1; j <= cities; j++) drum[i][j] = distance(i, j); int maxim = (1 << cities); for (int i = 1; i <= maxim; i++) for (int j = 1; j <= cities; j++) cost[i][j] = 1000000000; cost[1][1] = 0; for (int i = 1; i < maxim; i++) for (int j = 1; j < cities; j++) if (i & (1 << j)) for (int x = 1, exc = (i - (1 << j)); x <= cities; x++) cost[i][j + 1] = min(cost[i][j + 1], cost[exc][x] + drum [x][j + 1]); for (int i = 2; i <= cities; i++) total_cost = min(total_cost, cost[maxim - 1][i] + drum[i][1]); cout << total_cost; }
#include <bits/stdc++.h> #include <math.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep1(i, n) for(int i = 1; i < n+1; i++) #define all(A) A.begin(),A.end() typedef long long ll; vector<int> x,y,z; int dist(int a,int b){ return abs(x[b]-x[a])+abs(y[b]-y[a])+max(0,z[b]-z[a]); } void infout(int a){ if(a == 1e9) cout << "INF"; else cout << a; cout << ","; } void chmin(int& a, int b){ a = min(a,b); } int main(){ int n; cin >> n; x.resize(n); y.resize(n); z.resize(n); rep(i,n) cin >> x[i] >> y[i] >> z[i]; vector<vector<int>> dp(1<<n,vector<int>(n,1e9)); rep(i,n){ if(i == 0) continue; dp[1<<i][i] = dist(0,i); } rep(i,1<<n){ //from where? rep(from,n){ //to where? rep(to,n){ chmin(dp[i|1<<to][to],dp[i][from]+dist(from,to)); } } } cout << dp[(1<<n)-1][0] << endl; }
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<map> #include<stack> #include<set> #define iss ios::sync_with_stdio(false) using namespace std; typedef long long ll; using namespace std; typedef long long ll; const int maxn = 1e6 + 7; const int mod = 998244353; int head[maxn],num,fa[maxn],n,m,ans[maxn]; struct node{ int v,w,next; }e[maxn]; void add(int u,int v,int w){ e[num].next = head[u]; e[num].v = v; e[num].w = w; head[u] = num ++; } int Find(int x){ if(fa[x] != x) fa[x] = Find(fa[x]); return fa[x]; } void dfs(int u,int pre){ for(int i = head[u];i != -1;i = e[i].next){ int to = e[i].v,w = e[i].w; if(to == pre) continue; if(w == ans[u]){ if(w == n) ans[to] = 1; else ans[to] = w + 1; } else ans[to] = w; dfs(to,u); } } int main (){ scanf("%d%d",&n,&m); memset(head,-1,sizeof(head)); for(int i = 1; i <= n; i ++){ fa[i] = i; } for(int i = 1,u,v,w; i <= m; i ++){ scanf("%d%d%d",&u,&v,&w); int x = Find(u); int y = Find(v); // printf ("%d %d..\n",x,y); if(x == y) continue; fa[x] = y; // printf ("%d %d %d\n",u,v,w); add(u,v,w); add(v,u,w); } ans[1] = 1; dfs(1,-1); for(int i = 1; i <= n; i ++){ printf ("%d\n",ans[i]); } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define forin(in ,n) for(ll i=0; i<n; i++) cin>>in[i] #define forout(out) for(ll i=0; i<(ll)out.size(); i++) cout<<out[i]<<endl #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep_up(i, a, n) for (ll i = a; i < n; ++i) #define rep_down(i, a, n) for (ll i = a; i >= n; --i) #define P pair<ll, ll> #define all(v) v.begin(), v.end() #define fi first #define se second #define vvvll vector<vector<vector<ll>>> #define vvll vector<vector<ll>> #define vll vector<ll> #define pqll priority_queue<ll> #define pqllg priority_queue<ll, vector<ll>, greater<ll>> constexpr ll INF = (1ll << 60); constexpr ll mod = 1000000007; //constexpr ll mod = 998244353; constexpr double pi = 3.14159265358979323846; template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> void pt(T val) { cout << val << "\n"; } template <typename T> void pt_vll(vector<T> &v) { ll vs = v.size(); rep(i, vs) { cout << v[i]; if (i == vs - 1) cout << "\n"; else cout << " "; } } ll mypow(ll a, ll n) { ll ret = 1; if(n==0) return 1; if(a==0) return 0; rep(i, n) { if (ret > (ll)(1e18 + 10) / a) return -1; ret *= a; } return ret; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } struct Edge{ ll to; ll co; }; int main() { ll n,m,x=0,y=0,z=0,k,cnt=1,ans=0; cin>>n>>m; vector<vector<Edge>> G(n); vll color(n); rep(i,m){ cin>>x>>y>>z; x--;y--; G[x].push_back({y,z}); G[y].push_back({x,z}); } queue<ll> que; que.emplace(0ll); color[0]=1; while(!que.empty()){ ll state=que.front(); que.pop(); for(auto e:G[state]){ if(color[e.to]>0) continue; if(color[state]==e.co){ color[e.to]=(e.co)%n+1; }else{ color[e.to]=e.co; } que.emplace(e.to); } } rep(i,n){ cout<<color[i]<<endl; } }
#define LOCAL #include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2") #define IOS ios::sync_with_stdio(false);cin.tie(0) #define all(x) x.begin(), x.end() #define ff first #define ss second #define LLINF 0x3f3f3f3f3f3f3f3f #define INF 0x3f3f3f3f #define uniq(x) sort(all(x)); x.resize(unique(all(x))-x.begin()); #define sz(x) (int)x.size() #define pw(x) (1LL<<x) using pii = pair<int, int>; using ll = long long; const ll MOD = 998244353LL; const long double PI = acos(-1.0); int popcount(int x) { int cnt = 0; while(x>0) { if(x&1) cnt += 1; x/=2; } return cnt; } void solve() { int n; cin >> n; cout << (1<<n) - 1<< "\n"; int x=1<<(n-1) ; for(int i=1 ; i<=(1<<n)-1 ; i++) { string s = ""; for(int j=0 ; j<(1<<n) ; j++) { s+="A"; } for(int j=0 ; j<(1<<n) ; j++) { if(popcount(i&j)&1) s[j]='B'; } cout << s << "\n"; } } int main() { IOS; int t = 1; while(t--) solve(); }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) int main(){ int n, nn; cin >> n; nn = 1 << n; cout << nn-1 << "\n"; for(int bt=1; bt<nn; bt++){ rep(i,nn) cout << (char)(__builtin_parity(bt&i) + 'A'); cout << "\n"; } }
#include<bits/stdc++.h> #define int long long #define x first #define y second #define mp make_pair #define pb push_back #define endl "\n" using namespace std; const int max_n = 1e5+10; const int inf = 1e18; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s;cin>>s; s.pb(s[0]); for(int i=1;i<s.size();i++){ cout<<s[i]; } cout<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin>>N; cout<< (N-1) <<endl; return 0; }
#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #define rep(i,n) for(ll i=0;i<(n);++i) #define rep2(i,n) for(ll i=1;i<=(n);++i) #define rep3(i,i0,n) for(ll i=i0;i<(n);++i) #define rrep(i,n) for(ll i=((n)-1); i>=0; --i) #define rrep2(i,n) for(ll i=(n); i>0; --i) #define pb push_back #define mod 998244353 #define fi first #define se second #define len(x) ((ll)(x).size()) using namespace std; using ll = long long; using ld = long double; using Pi = pair< ll, ll >; using vl = vector<ll>; using vc = vector<char>; using vb = vector<bool>; using vs = vector<string>; using vp = vector<Pi>; using vvc = vector<vector<char>>; using vvl = vector<vector<ll>>; using vvvl = vector<vector<vector<ll>>>; const ll INF = 1LL << 60; const ld PI = 3.1415926535897932385; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) {return a/gcd(a,b)*b;} #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define mp make_pair void printb(ll N,ll d=16){ rep(i,d){ cout<<(N/(1<<(d-i-1)))%2; } cout<<endl; } void printv(vector<ll>a){ rep(i,a.size()){ if(i==a.size()-1){ cout<<a[i]<<endl; }else{ cout<<a[i]<<" "; } } } bool In_map(ll y,ll x,ll h,ll w){ if(y<0 || x<0 || y>=h || x>=w){ return 0; }else{ return 1; } } bool compare(Pi a, Pi b) { if(a.first != b.first){ return a.first < b.first; }else{ return a.second < b.second; } } //const vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1}; //const vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1}; const vector<ll> dx{1,0,-1,0}; const vector<ll> dy{0,1,0,-1}; template <std::uint_fast64_t Modulus> class modint { using u64 = std::uint_fast64_t; public: u64 a; constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } }; using mint = modint<mod>; long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { ll N; cin>>N; vl A(N); rep(i,N){ cin>>A[i]; } sort(all(A)); mint ans=0; mint now=0; ll flag=0; rep(i,N){ ans+=(now+A[i])*A[i]; now*=2; now+=A[i]; //cout<<now.a<<endl; //cout<<ans.a<<endl; } cout<<ans.a<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; // #define int long long const int mod=998244353; int pw(int a,int t=mod-2){ int x=1; while(t>0){ if(t&1)x=1ll*x*a%mod; a=1ll*a*a%mod,t>>=1; } return x; } int32_t main(){ ios::sync_with_stdio(0),cin.tie(0); int n; cin >> n; int a[n],sum=0; for(int i=0;i<n;i++){ cin >> a[i]; sum=(sum+1ll*a[i]*a[i])%mod; } sort(a,a+n); int x=0,y=0,ans=0; for(int i=0;i<n;i++){ y=(1ll*pw(pw(2,n-i))*a[i]%mod)%mod; ans=(ans+1ll*x*y%mod)%mod; x=(x+1ll*pw(pw(2,i+1))*a[i]%mod)%mod; } ans=1ll*ans*pw(2,n)%mod; ans=(ans+sum)%mod; cout << ans; }
#include <bits/stdc++.h> using namespace std; void solve () { char x,y; cin>>x; cin>>y; if(x=='Y' ) { char ans=toupper(y); cout<<ans; } else if(x=='N') { cout<<y; } } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }
#pragma region head #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; using pi = pair<int, int>; using pll = pair<ll, ll>; template <class T> using vv = vector<vector<T>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define bit(n) (1LL << (n)) template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } const int INF = 1002003004; const ll LINF = 1002003004005006007ll; struct preprocess { preprocess() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } ____; #pragma endregion head #pragma region library #pragma endregion library int main() { char s, t; cin >> s >> t; if (s == 'Y') { t -= 32; } cout << t << '\n'; }
#include <iostream> #include <algorithm> #include <iterator> #include <string> #include <vector> #include <map> #include <stack> #include <queue> #include <functional> #include <cctype> #include <climits> // INT_MAX ... #include <cstring> // using namespace std; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; int ans = 3; if (r1 == r2 && c1 == c2) { ans = 0; } else if (r1 + c1 == r2 + c2 || r1 - c1 == r2 - c2 || abs(r1 - r2) + abs(c1 - c2) <= 3) { ans = 1; } else if ((r1 + c1) % 2 == (r2 + c2) %2 || abs(r1 - r2) + abs(c1 - c2) <= 6 || abs((r1 - r2) + (c1 - c2)) <= 3 || abs((r1 - r2) - (c1 - c2)) <= 3) { ans = 2; } cout << ans << '\n'; return 0; }
//#include <atcoder/all> #include <bits/stdc++.h> using namespace std; #define rep2(x,fr,to) for(int x=(fr);x<(to);x++) #define rep(x,to) for(int x=0;x<(to);x++) #define repr(x,fr,to) for(int x=(fr);x>=(to);x--) #define all(c) c.begin(),c.end() #define sz(v) (int)v.size() typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9+7; //998244353; void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);} //using mint = modint1000000007; vector<string> ff(vector<string> iv, int c){ int h=iv.size(), w=iv[0].size(); auto rt=iv; if(c%2) rt.assign(w, string(h, ' ')); if(c==1) rep(i,h) rep(j,w) rt[j][h-1-i] = iv[i][j]; if(c==2) rep(i,h) rep(j,w) rt[h-1-i][w-1-j] = iv[i][j]; if(c==3) rep(i,h) rep(j,w) rt[w-1-j][i] = iv[i][j]; return rt; } void f3(vector<string>& iv){ int h=iv.size(), w=iv[0].size(); int lsw=0; rep(i, h){ int lsw=0; rep(j ,w){ if(iv[i][j]=='P') lsw=1; if(iv[i][j]=='B') lsw=0; if(lsw && iv[i][j]=='.') iv[i][j] ='T'; } } } int main() { cin.tie(0); ios_base::sync_with_stdio(false); int h, w, n ,m; cin >>h >>w >>n >>m; vector<string> ba(h, string(w, '.')); rep(i, n){ int a, b; cin >>a >>b; ba[a-1][b-1] ='P'; } rep(i, m){ int c, d; cin >>c >>d; ba[c-1][d-1] = 'B'; } rep(i, 4){ f3(ba); ba = ff(ba, 1); } ll ans =0; for(auto& xl: ba) for(auto x :xl) if(x=='P'||x=='T') ans++; cout << ans <<"\n"; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for(ll i = 0; i < (ll)(n); i++) #define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++) #define ALL(x) x.begin(), x.end() #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) #define SORT(x) sort(ALL(x)) #define REV(x) reverse(ALL(x)) using namespace std; using ll = long long; using vl = vector<ll>; using vvl = vector<vl>; using vf = vector<float>; using vd = vector<double>; using vs = vector<string>; using vb = vector<bool>; using sl = stack<ll>; using ql = queue<ll>; const long long INF=2305843009213693951; const long long dx[]={0,1,0,-1,1,-1,1,-1}; const long long dy[]={1,0,-1,0,1,1,-1,-1}; void Yes(bool a){cout<<(a?"Yes":"No")<<endl;} void YES(bool a){cout<<(a?"YES":"NO")<<endl;} int binary_search(ll x, vl a){ auto ite = lower_bound(ALL(a), x); if(ite != a.end() && *ite == x) { return ite - a.begin() ; } else { return -1; } } ll modpow(ll a, ll n, ll mod) { if(n == 0) return 1; if(n == 1) return a % mod; if(n % 2 == 1) return (a * modpow(a, n - 1, mod)) % mod; ll t = modpow(a, n / 2, mod); return (t * t) % mod; } int main() { ll N; cin >> N; if(N % 2 == 0) { cout << "White" << endl; } else { cout << "Black" << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int n; scanf("%d",&n); puts(n%2?"Black":"White"); }
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; #define ll long long bool cmp(int a,int b) { return a>b; } int main() { int n; scanf("%d",&n); ll a[200100]; for(int i=1;i<=n;i++) scanf("%lld",&a[i]); sort(a+1,a+n+1,cmp); ll sum[200100]; sum[1]=a[1]; for(int i=2;i<=n;i++) sum[i]=sum[i-1]+a[i]; ll ans=0; for(int i=1;i<n;i++) ans+=sum[n-i]-(sum[n]-sum[i]); printf("%lld",ans); return 0; }
#include <bits/stdc++.h> #define rep(i,cc,n) for(int i=cc;i<=n;++i) using namespace std; using ll = long long; ll Solve(int n, vector<ll> a) { sort(a.begin(), a.end()); ll sum = 0; for (ll i = n - 1; 0 <= i; --i) { sum += (i * a[i]) - (n - 1 - i) * a[i]; } return sum; } int main() { int n; cin >> n; vector<ll> a(n); rep(i,0,n-1) cin >> a[i]; cout << Solve(n, a) << endl; return 0; }
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(char &c){ int i; for(;;){ i = my_getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c = i; } inline int rd(char c[]){ int i; int sz = 0; for(;;){ i = my_getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c[sz++] = i; for(;;){ i = my_getchar_unlocked(); if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){ break; } c[sz++] = i; } c[sz]='\0'; return sz; } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } inline void wt_L(const char c[]){ int i=0; for(i=0;c[i]!='\0';i++){ my_putchar_unlocked(c[i]); } } char s[100000+10]; int n; int main(){ int i; n = rd(s); reverse(s, s+n); for(i=(0);i<(n);i++){ if(s[i] == '6'){ s[i] = '9'; } else if(s[i] == '9'){ s[i] = '6'; } } wt_L(s); wt_L('\n'); return 0; } // cLay version 20210405-1 // --- original code --- // char s[1d5+10]; // int n; // { // rd(s@n); // reverse(s, s+n); // rep(i, n) {if(s[i] == '6') {s[i] = '9';} else if(s[i] == '9') {s[i] = '6';}} // wt(s); // }
//雪花飄飄北風嘯嘯 //天地一片蒼茫 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; #define ll long long #define ii pair<ll,ll> #define iii pair<ii,ll> #define fi first #define se second #define endl '\n' #define debug(x) cout << #x << " is " << x << endl #define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--)) #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() #define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> //change less to less_equal for non distinct pbds, but erase will bug mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); int n; int arr[1005]; int brr[1005]; int apsp[1005][1005]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(ios::badbit | ios::failbit); memset(apsp,1,sizeof(apsp)); cin>>n; rep(x,0,n){ arr[x]=(2*x)%n; brr[x]=(2*x+1)%n; } rep(x,0,n) cout<<arr[x]+1<<" "<<brr[x]+1<<endl; }
#include <bits/stdc++.h> using namespace std; long long binpow(long long a, long long b, long long MOD) { long long res = 1; while (b) { if (b % 2) res = res * a % MOD; a = a * a % MOD; b /= 2; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long n, m; cin >> n >> m; cout << binpow(10, n, m * m) / m << '\n'; }
#include <bits/stdc++.h> #define FASTIO using namespace std; using ll = long long; using Vi = std::vector<int>; using Vl = std::vector<ll>; using Pii = std::pair<int, int>; using Pll = std::pair<ll, ll>; constexpr int I_INF = std::numeric_limits<int>::max(); constexpr ll L_INF = std::numeric_limits<ll>::max(); template <typename T1, typename T2> inline bool chmin(T1& a, const T2& b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> inline bool chmax(T1& a, const T2& b) { if (a < b) { a = b; return true; } return false; } template <std::ostream& os = std::cout> class Prints { private: class __Prints { public: __Prints(const char* sep, const char* term) : sep(sep), term(term) {} template <class... Args> auto operator()(const Args&... args) const -> decltype((os << ... << std::declval<Args>()), void()) { print(args...); } template <typename T> auto pvec(const T& vec, size_t sz) const -> decltype(os << std::declval<decltype(std::declval<T>()[0])>(), void()) { for (size_t i = 0; i < sz; i++) os << vec[i] << (i == sz - 1 ? term : sep); } template <typename T> auto pmat(const T& mat, size_t h, size_t w) -> decltype(os << std::declval<decltype(std::declval<T>()[0][0])>(), void()) { for (size_t i = 0; i < h; i++) for (size_t j = 0; j < w; j++) os << mat[i][j] << (j == w - 1 ? term : sep); } private: const char *sep, *term; void print() const { os << term; } void print_rest() const { os << term; } template <class T, class... Tail> void print(const T& head, const Tail&... tail) const { os << head, print_rest(tail...); } template <class T, class... Tail> void print_rest(const T& head, const Tail&... tail) const { os << sep << head, print_rest(tail...); } }; public: Prints() {} __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); } }; Prints<> prints; Prints<std::cerr> prints_err; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void solve() { ll N, M; cin >> N >> M; ll x = 1; ll c = 10; for (; N > 0; N >>= 1) { if (N & 1) x = x * c % (M * M); c = c * c % (M * M); } prints()(x / M); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% int main() { #ifdef FASTIO std::cin.tie(nullptr), std::cout.tie(nullptr); std::ios::sync_with_stdio(false); #endif #ifdef FILEINPUT std::ifstream ifs("./in_out/input.txt"); std::cin.rdbuf(ifs.rdbuf()); #endif #ifdef FILEOUTPUT std::ofstream ofs("./in_out/output.txt"); std::cout.rdbuf(ofs.rdbuf()); #endif std::cout << std::setprecision(18) << std::fixed; solve(); std::cout << std::flush; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,cc,n) for(int i=cc;i<n;++i) #define lrep(i,cc,n) for(long long i=cc;i<n;++i) #define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i) #define rrep(i,cc,n) for(int i=cc;i>=n;--i) #define pii pair<int, int> #define pll pair<long long, long long> using ll = long long; const vector<int> dx = {1, 0, -1, 0}; const vector<int> dy = {0, 1, 0, -1}; const vector<int> dx2 = {1, 1, 1, 0, 0, 0, -1, -1, -1}; const vector<int> dy2 = {1, 0, -1, 1, -1, 0, 1, 0, -1}; const double PI = 3.1415926535; const ll inf = 1001001001; const ll e9 = 1000000000; const ll mod = 1000000007; const ll mod2 = 998244353; const ll MAX = 1000000; const ll MOD = 1000000007; const ll big = (1ll<<60); const ll moda = 1000000007; const ll modb = 100000007; ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; } ll modPow(ll a, ll n, ll p) { if (n == 0) return 1; if (n == 1) return a % p; if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p; ll t = modPow(a, n / 2, p); return (t * t) % p; } ll choose(ll n, ll r, ll mod){ ll mul = 1, div = 1; for(ll i = 0; i < r; i++){ mul *= n - i; div *= i + 1; mul %= mod; div %= mod; } return mul * modPow(div, mod - 2, mod) % mod; } int main(){ int n; string s, x; cin >> n >> s >> x; vector<vector<bool>>dp(7,vector<bool>(n+1,false));//takahashi_win:true dp[0][n] = true; int digit = 1; rep(i, 0, n){ int temp = (s[n-1-i]-'0'); if(x[n-1-i]=='T'){ rep(j, 0, 7){ dp[j][n-i-1] = dp[(temp*digit+j)%7][n-i]||dp[j][n-i]; } }else{ rep(j, 0, 7){ dp[j][n-i-1] = dp[(temp*digit+j)%7][n-i]&&dp[j][n-i]; } } if(i!=n-1)(digit *= 10) %= 7; } /* if(x[0]=='T'){ if(dp[(s[0]-'0')*digit%7][0]||dp[0][0]){ cout << "Takahashi" << endl; }else{ cout << "Aoki" << endl; } }else{ if(dp[(s[0]-'0')*digit%7][0]&&dp[0][0]){ cout << "Takahashi" << endl; }else{ cout << "Aoki" << endl; } }*/ if(dp[0][0]){ cout << "Takahashi" << endl; }else{ cout << "Aoki" << endl; } 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; // template<class T> // using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update> ; // template<class key, class value, class cmp = std::less<key>> // using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>; template<class T> ostream& operator<<(ostream &os, set<T> S){os << "{ ";for(auto s:S) os<<s<<" ";return os<<"}";} template<class T> ostream& operator<<(ostream &os, unordered_set<T> S){os << "{ ";for(auto s:S) os<<s<<" ";return os<<"}";} template<class T> ostream& operator << (ostream& os, multiset<T> S){os << "{ ";for(auto s:S) os<<s<<" ";return os<<"}";} //template<class T> ostream& operator<<(ostream &os, ordered_set<T> S){os << "{ ";for(auto s:S) os<<s<<" ";return os<<"}";} template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";} template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {os << "{ ";for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") ";return os<<"}";} template<class T> ostream& operator<<(ostream &os,vector<T> V){os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";} #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__,__VA_ARGS__) template<typename Arg1> void __f(const char* name,Arg1&& arg1){ cout<<name<<" : "<<arg1<<endl; } template<typename Arg1,typename... Args> void __f(const char* names,Arg1&& arg1,Args&&... args){ const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...); } #else #define trace(...) 1 #endif //reading vectors template <class T> void RV(vector<T> &v){for(auto &c : v) cin >> c;} template <class T> void RV(vector<vector<T>> &v){for(auto &c : v) RV(c);} //defines and typedefs #define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define TC int testcase; cin >> testcase;while(testcase--) #define forn(i,n) for(int i=0;i<n;i++) #define rep(i,n) for(int i = 1;i<=n;i++) #define ALL(x) x.begin(),x.end() #define int long long int // #define LL long long int #define PB push_back #define EB emplace_back #define F first #define S second #define endl "\n" #define SZ(x) (int)x.size() typedef pair<int,int>PII; typedef vector<PII> VPII; typedef vector<int> VI; typedef vector<VI> VVI; auto clk=clock(); //constants int mod = 1e9+7; const long long inf = 1e17; const double eps = 1e-6; const int LOGN = 25; // maths stuff template <class T,class U>T pow_mod(T a,U b,int m= mod){long long res = 1;while(b){ if(b&1) res =((long long)res*a)%m; a = ((long long)a*a)%m;b >>=1;}return res;} template <typename T> T inv(T a){return pow_mod(a,mod-2,mod);} template <typename T> T gcd(T a,T b){if(b == 0) return a;return gcd(b,a%b);} template <typename T> T lcm(T a,T b){ return a*b /gcd(a,b);} template <typename T> string to_bin(T num){string binary = "";while (num){binary += (num % 2 == 1 ? "1" : "0");num >>= 1;}reverse(binary.begin(), binary.end());return binary;} //////////////////////////////////////////////////// void __Solve__(){ int n,x; cin >> n >> x; string s; cin >> s; for(char c : s){ if(c == 'o') x++; else x = max(x-1,0LL); } cout << x << endl; } signed main() { srand(chrono::high_resolution_clock::now().time_since_epoch().count()); cout<<fixed<<setprecision(2); FASTIO #ifdef LOCAL freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout); #endif int test_case = 1; //cin >> test_case; forn(i,test_case){ //cout << "Case #" << i+1<<": "; __Solve__(); } #ifdef LOCAL cerr<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<" seconds" << "\n"; #endif }
#include<bits/stdc++.h> using namespace std; typedef long long ll; template<typename T> ostream& operator<<(ostream &os, vector<T> &v){ string sep = " "; if(v.size()) os << v[0]; for(int i=1; i<v.size(); i++) os << sep << v[i]; return os; } template<typename T> istream& operator>>(istream &is, vector<T> &v){ for(int i=0; i<v.size(); i++) is >> v[i]; return is; } #ifdef DBG void debug_(){ cout << endl; } template<typename T, typename... Args> void debug_(T&& x, Args&&... xs){ cout << x << " "; debug_(forward<Args>(xs)...); } #define dbg(...) debug_(__VA_ARGS__) #else #define dbg(...) #endif int main() { ios_base::sync_with_stdio(false); cout << setprecision(20) << fixed; int n; cin >> n; vector<int> a(n); cin >> a; ll ans = 0; for(int i=0; i<n; i++){ if(a[i]>10) ans += a[i]-10; } cout << ans << endl; return 0; }
# include <ciso646> # include <cstdio> # include <algorithm> namespace Main { namespace Source { typedef signed int dint; typedef unsigned int uint; static inline const uint abs(const dint x) { return x < 0 ? -x : x; } static inline const uint max(const uint a, const uint b) { return a < b ? b : a; } } using namespace Source; enum { N = (const uint)2e5 }; struct house { dint x, y; uint id; inline const void read(const uint id) { scanf("%d%d", &x, &y), this->id = id; } friend inline const uint operator xor (const house& a, const house& b) { return max(abs(a.x - b.x), abs(a.y - b.y)); } friend inline const bool operator < (const house& a, const house& b) { return a.id < b.id; } friend inline const bool cmpx(const house& a, const house& b) { return a.x < b.x; } friend inline const bool cmpy(const house& a, const house& b) { return a.y < b.y; } }; static uint n; static house h[N + 1]; static uint mx, my, mi, mj; static uint mmx, mmy; extern inline const bool cmpx(const house& a, const house& b); extern inline const bool cmpy(const house& a, const house& b); static inline const bool eq(const uint a, const uint b, const uint c, const uint d) { return a == c && b == d or a == d && b == c; } static inline const void main() { scanf("%u", &n); for (register uint i(1); i <= n; ++i) h[i].read(i); std::sort(&h[1], &h[n] + 1, cmpx), mx = h[n].x - h[1].x; std::sort(&h[1], &h[n] + 1, cmpy), my = h[n].y - h[1].y; if (mx >= my) { std::sort(&h[1], &h[n] + 1, cmpx), mi = h[1].id, mj = h[n].id; mmx = max(h[n - 1].x - h[1].x, h[n].x - h[2].x); std::sort(&h[1], &h[n] + 1, cmpy); mmy = eq(h[1].id, h[n].id, mi, mj) ? max(h[n - 1].y - h[1].y, h[n].y - h[2].y) : my; } else { std::sort(&h[1], &h[n] + 1, cmpy), mi = h[1].id, mj = h[n].id; mmy = max(h[n - 1].y - h[1].y, h[n].y - h[2].y); std::sort(&h[1], &h[n] + 1, cmpx); mmx = eq(h[1].id, h[n].id, mi, mj) ? max(h[n - 1].x - h[1].x, h[n].x - h[2].x) : mx; } printf("%u\n", max(mmx, mmy)); } } signed int main() { Main::main(); return 0; }
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; void Main() { int n; cin >> n; vector<long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); vector<long> sa(n+1); for (int i = 0; i < n; i++) { sa[i+1] = sa[i] + a[i]; } long ans = 0; for (int i = 0; i < n; i++) { auto nm = lower_bound(a.begin(), a.end(), a[i]) - a.begin(); ans += a[i]*nm - sa[nm]; ans += (sa[n] - sa[nm]) - a[i]*(n-nm); } ans /= 2; cout << ans << endl; } int main(int argc, char **argv) { ios::sync_with_stdio(false); std::cin.tie(nullptr); Main(); return 0; }
#include <iostream> #include <iomanip> #include <assert.h> #include <vector> #include <string> #include <cstring> #include <sstream> #include <map> #include <set> #include <queue> #include <algorithm> #include <numeric> #include <cmath> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef std::pair<long long, long long> Pll; typedef std::vector<int> vi; typedef std::vector<long long> vl; typedef std::vector<std::string> vs; typedef std::vector<std::pair<long long, long long>> vpll; typedef std::vector<std::vector<ll>> vvl; template<class T> using V = std::vector<T>; template<class T> using VV = std::vector<std::vector<T>>; const long double PI = (acos(-1)); const long long MOD = 1000000007; static const int MAX_INT = std::numeric_limits<int>::max(); // 2147483647 = 2^31-1 static const ll MAX_LL = std::numeric_limits<long long>::max(); static const int INF = (1 << 29); // cf) INT_MAX = 2147483647 = 2^31-1 static const ll INFLL = (1ll << 61); // cf) LLONG_MAX = 9223372036854775807 = 2^63 - 1 #define rep(i,n) REP(i,0,n) #define REP(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i) #define rrep(i,n) RREP(i,0,n) #define RREP(i,x,n) for(ll i=(ll)(n)-1ll;i>=(ll)(x);--i) #define ALL(x) x.begin(), x.end() #define RALL(x) x.rbegin(), x.rend() #define SUM(x) accumulate(ALL(x), 0ll) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) // change min/max template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } void Main() { ll a, b, c, d; cin >> a >> b >> c >> d; ll cnt = b - c; cout << cnt << endl; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout << std::fixed << std::setprecision(15); Main(); double tmp; cin >> tmp; return 0; }
#include<iostream> using namespace std; const int N_MAX = 2505; const int LIMIT = 10001; int N; void read() { cin >> N; } void work() { int toAdd[3] = {6, 10, 15}; bool used[LIMIT] = {}; int nAns = 0; int ans[N_MAX]; for (int i = 0; i < 3; ++i) { used[toAdd[i]] = true; ans[nAns++] = toAdd[i]; } for (int loop = 0; loop < 3; ++loop) { for (int i = toAdd[loop] * 2; i < LIMIT && nAns < N; i += toAdd[loop]) { if (!used[i]) { ans[nAns++] = i; used[i] = true; } } } for (int i = 0; i < nAns; ++i) { if (i) cout << ' '; cout << ans[i]; } cout << endl; } int main() { read(); work(); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define M 1000000007 int main(){ ll n; cin>>n; int sum=0; int i=1; while(sum<n){ sum+=i; i++; } cout<<i-1<<endl; return 0; }
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define sz(a) (int)(a.size()) #define all(a) a.begin(),a.end() #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; typedef pair<int,pii> P; ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);} int main() { int n; cin>>n; vector<ll>a(n); ll ans = INF; for(int i=0;i<n;i++)cin>>a[i]; /* for(ll i=0;i<(1<<n);i++){ ll fin = 0; for(int j=0;j<n;j++){ int k = j; ll cur = a[j]; while(k+1<n){ int c = i&(1LL<<j); int b = i&(1LL<<k); if(c && !b)break; if(b && !c)break; k++; cur = cur|a[k]; } fin= cur ^ fin; j = k; } ans = min(ans,fin); }*/ vector<set<ll>>b(20); for(int i=0;i<n;i++){ ll cur = 0; for(int j=i;j>=0;j--){ cur = cur|a[j]; if(j == 0)b[i].insert(cur); else{ for(ll x:b[j-1]){ b[i].insert(cur ^ x); } } } } for(ll x:b[n-1])ans = min(ans,x); cout<<ans; }
#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=998244353, INF=(1LL<<60); #define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl; long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); ll cnt = 0; ll h, w; cin >> h >> w; vector<string> s(h); rep(i, h) cin >> s[i]; bool ng = false; for(ll k=0;k<=h+w-2;k++) { int num = 0; for(ll i=min(k, h-1);i>=max(0LL, k-(w-1));i--) { ll j = k - i; if(s[i][j] == 'R') { if(num == 0) num++; else if(num == -1) ng = true; }else if(s[i][j] == 'B') { if(num == 0) num--; else if(num == 1) ng = true; } } if(num == 0) cnt++; } if(ng) { cout << 0 << endl; return 0; } cout << modpow(2LL, cnt) << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) #define reps(i,s,n) for(int i=(s); i<(n); i++) #define all(v) v.begin(),v.end() #define outve(v) for(auto i : v) cout << i << " ";cout << endl #define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;} #define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];} #define out(n) cout << (n) << endl #define fi first #define se second #define pb push_back #define si(v) int(v.size()) #define len(v) int(v.length()) #define lob(v,n) lower_bound(all(v),n) #define lobi(v,n) lower_bound(all(v),n) - v.begin() #define upb(v,n) upper_bound(all(v),n) #define upbi(v,n) upper_bound(all(v),n) - v.begin() #define mod 1000000007 #define infi 1900000000 #define infl 1100000000000000000 #define cyes cout << "Yes" << endl #define cno cout << "No" << endl #define csp << " " << #define outset(n) cout << fixed << setprecision(n); using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vector<int>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using pii = pair<int,int>; using pll = pair<ll,ll>; template<typename T> using ve = vector<T>; template<typename T> using pq2 = priority_queue<T>; template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>; template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;} template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;} int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int x; cin >> x; cout << (x >= 0 ? x : 0) << endl; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <cstring> #include <math.h> #include <bitset> #include <queue> #include <set> #include <iomanip> #include <assert.h> #include <cstdio> // #include<bits/stdc++.h> using namespace std; typedef long long ll; constexpr long long int INFLL = 1001001001001001LL; constexpr long long int infll = 1001001001001001LL; constexpr int INF = 1000000007; constexpr int inf = 1000000007; const int mod = 1000000007; const double pi = 3.14159265358979323846264; inline bool chmin(ll &a, ll b) { if (a > b) { a = b; return true; } return false; } inline bool chmax(ll &a, ll b) { if (a < b) { a = b; return true; } return false; } template <typename T> T seinomi(T a) { if (a > 0) { return a; } else { return 0; } } //桁数取得 template <typename T> T ketasuu(T num) { return std::to_string(num).length(); } //整数乗 ll llpow(ll a, ll n) { if (n == 0) { return 1; } else { ll rep = a; for (ll i = 1; i < n; i++) { rep *= a; } return rep; } } template <class ForwardIt, class T> void iota(ForwardIt first, ForwardIt last, T value) { while (first != last) { *first++ = value; ++value; } } template <typename T> T amarinasi(T a, T b) { if (a % b == 0) { return a / b; } else if (a % b > 0) { return a / b + 1; } else { return a / b - 1; } } //小数点以下10桁テンプレート(main関数内の最初に貼付け) //std::cout << std::fixed << std::setprecision(10); //---------------------------------------------------------------- int main() { ll n; cin >> n; ll cnt = 1; vector<ll> a; map<ll, ll> rensou; for (ll i = 0; i < 28; i++) { cnt *= 5; a.push_back(cnt); rensou[cnt] = i; if (cnt * 5 >= n) { break; } } a.push_back(1000000000000000010); cnt = 1; bool judge = false; for (ll i = 0; i < 40; i++) { cnt *= 3; ll amari = n - cnt; auto itr = lower_bound(a.begin(), a.end(), amari); if (*itr == amari) { cout << i + 1 << " " << rensou[amari] + 1 << endl; judge = true; break; } if (cnt * 3 >= n) { break; } } if (!judge) { cout << -1 << endl; } }
//GIVE ME AC!!!!!!!!!!!!!!!!! #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define ll long long #define all(n) n.begin(),n.end() #define rall(n) n.rbegin(),n.rend() #define rep(i, s, n) for (ll i = s; i < (ll)(n); i++) using namespace std; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const ll inf =1e18; const ll MOD=1000000007; const ll mod=998244353; const double pi=acos(-1); using P=pair<ll,ll>; ll merge_cnt(vector<ll> &a) { ll 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); ll 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; } int main(){ int n; cin>>n; map<int,vector<int>>p; int a[n]; rep(i,0,n){ cin>>a[i]; p[a[i]+i].push_back(i); } int b; bool ok=true; vector<ll>ans(n); rep(i,0,n){ cin>>b; b+=i; if(p[b].size()==0){ ok=false; break; } else{ ans[p[b][0]]=i; p[b].erase(p[b].begin()); } } if(!ok){ cout<<-1<<endl; return 0; } cout<<merge_cnt(ans)<<endl; }
/*Lucky_Glass*/ #include <cstdio> #include <cstring> #include <algorithm> const int N = 2e5 + 10; #define con(typ) const typ & struct BITArray { int arr[N], siz; void modify(con(int) pos, con(int) key) { for (int i = pos; i <= siz; i += i & -i) arr[i] += key; } int query(con(int) pos) { int ans = 0; for (int i = pos; i; i -= i & -i) ans += arr[i]; return ans; } } bit; int n; std::pair<int, int> posa[N], posb[N]; int rec[N]; int main() { scanf("%d", &n); for (int i = 1, tmp; i <= n; ++i) { scanf("%d", &tmp); posa[i] = std::make_pair(tmp + i - 1, i); } for (int i = 1, tmp; i <= n; ++i) { scanf("%d", &tmp); posb[i] = std::make_pair(tmp + i - 1, i); } std::sort(posa + 1, posa + 1 + n); std::sort(posb + 1, posb + 1 + n); for (int i = 1; i <= n; ++i) if ( posa[i].first != posb[i].first ) { printf("-1\n"); return 0; } else { rec[posa[i].second] = posb[i].second; } bit.siz = n; long long ans = 0; for (int i = 1; i <= n; ++i) { ans += bit.query(n - rec[i] + 1); bit.modify(n - rec[i] + 1, 1); } printf("%lld\n", ans); return 0; }
#include <iostream> #include <cstdio> #include <cmath> #include <map> #define rep(i,a,b) for(int i=a;i<=b;i++) #define per(i,a,b) for(int i=a;i>=b;i--) using namespace std; const int N=1e5+5; int a[N],T,n; map<int,int>mp; void solve(){ scanf("%d",&n); rep(i,1,n) scanf("%d",a+i); rep(i,1,n) mp[a[i]]++; bool flag=1; rep(i,1,n) if(mp[a[i]]&1){ flag=0; break; } if(n%2==0) puts(flag?"Second":"First"); else puts(flag?"First":"Second"); mp.clear(); } int main(){ scanf("%d",&T); while(T--) solve(); return 0; }
//#pragma GCC optimize ("O2") //#pragma GCC target ("avx2") #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 ll num[524310]; bool kazu[524310]; const int ma = (1 << 19) - 1; int k; void add(ll n) { int n2 = (n & ma) + 1; while (num[n2]) { if (num[n2] == n + 1) { kazu[n2] = !kazu[n2]; k += (kazu[n2] * 2) - 1; return; } n2 = n2 * 2 % 524309; } num[n2] = n + 1; kazu[n2] = 1; k++; } int main() { cin.tie(0); ios::sync_with_stdio(false); int T; cin >> T; rep(t, T) { int N; cin >> N; if (N % 2) { rep(i, N) { int a; cin >> a; } co("Second"); } else { int tmp = k; rep(i, N) { int a; cin >> a; add(a + 1000000000ll * t); } if (tmp == k) co("Second"); else co("First"); } } Would you please return 0; }
#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(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() constexpr ll MOD=1000000007; constexpr ll INF=2e18; struct Ad{ll x, y, r, num;}; struct Recang{ ll x1, y1, x2, y2; ll size(){ return abs(x2-x1)*abs(y2-y1); } }; const int MAX=9999; int n; Ad ads[300]; Recang ans[300]; bool overlap(Recang a, Recang b){ return max(a.x1,b.x1)<min(a.x2,b.x2)&&max(a.y1,b.y1)<min(a.y2,b.y2); } bool check(Recang a, int k){ REP(i,n){ if(i==k) continue; if(overlap(a,ans[i])) return 1; } return 0; } void solve(){ cin >> n; int x, y, r; REP(i,n){ cin >> x >> y >> r; ads[i]=Ad{x,y,r,i}; } sort(ads,ads+n,[](const Ad& a, const Ad& b){return a.r<b.r;}); REP(i,n){ Ad ad=ads[i]; ans[ad.num]={ad.x,ad.y,ad.x+1,ad.y+1}; } REP(i,n){ Ad ad=ads[i]; Recang tmpr={ad.x,ad.y,ad.x+1,ad.y+1}; while(1){ bool ok=0; tmpr.x1--; if(tmpr.x1<0||check(tmpr,ad.num)) tmpr.x1++; else ok=1; if(tmpr.size()>ad.r) break; tmpr.y1--; if(tmpr.y1<0||check(tmpr,ad.num)) tmpr.y1++; else ok=1; if(tmpr.size()>ad.r) break; tmpr.x2++; if(tmpr.x2>MAX||check(tmpr,ad.num)) tmpr.x2--; else ok=1; if(tmpr.size()>ad.r) break; tmpr.y2++; if(tmpr.y2>MAX||check(tmpr,ad.num)) tmpr.y2--; else ok=1; if(tmpr.size()>ad.r) break; if(!ok) break; } ans[ad.num]=tmpr; } REP(i,n){ Recang tmpr=ans[i]; cout << tmpr.x1 << " "; cout << tmpr.y1 << " "; cout << tmpr.x2 << " "; cout << tmpr.y2 << endl; } } int main(){ solve(); return 0; }
/** * author: Niloy_Das * created: 2021-06-06 18:19:58 **/ #include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define firstio() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define fo(i,k,n) for ( i = k; i < n; i++) #define F first #define S second #define ll long long #define pb push_back #define mp make_pair #ifndef ONLINE_JUDGE #define debug(x) cerr << #x << " ";print(x);cerr<<endl; #else #define debug(x) #endif typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; typedef map<int, int> mii; typedef map<ll, ll> mll; void print(int x){cerr << x;} void print(ll x){cerr << x;} void print(double x){cerr << x;} void print(char x){cerr << x;} void print(string x){cerr << x;} template <class T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";} template <class T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";} template <class T,class V> void print(map <T,V> v) {cerr << endl << "[ \n"; for (auto i=v.begin();i!=v.end();i++) {print(i->F); cerr << " "; print(i->S); cerr<<endl;} cerr << "]";} int n,m; int bfs(vector<vector<int>> &graph,int source){ queue<int>q; vector<bool>visit(n+1,false); q.push(source); visit[source] = true; int sum = 0; while (!q.empty()) { int k = q.front(); q.pop(); for(auto it:graph[k]){ if(!visit[it]){ sum++; q.push(it); visit[it] = true; } } } return sum; } int main() { firstio() #ifndef ONLINE_JUDGE freopen("Error.txt","w",stderr); freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int t = 1,i; // cin >> t; while(t--){ cin >> n >> m; vector<vector<int>> graph(n+1); fo(i,0,m){ int a,b; cin >> a >> b; graph[a].push_back(b); } int sum=n; fo(i,1,n+1){ sum+=bfs(graph,i); } cout << sum << "\n"; } return 0; }
// author : lynmisakura // TIMESTAMP: 2020-10-17, 20:00:51 #include<bits/stdc++.h> #include<iomanip> using namespace std; #define REP(i,n) for(int i = 0;i < n;i++) #define RNG(i,s,n) for(int i = s;i < n;i++) #define _RNG(i,s,e) for(int i=s;i>=e;i--) #define mp make_pair #define pb push_back #define eb emplace_back #define dup(x,y) (x + y - 1) / (y) #define all(x) (x).begin(),(x).end() #define lb(x,key) lower_bound(all(x) , (key)) #define ub(x,key) upper_bound(all(x) , (key)) template<class T> bool chmax(T& a,T b){ if(a < b){ a = b; return true; }else return false; } template<class T> bool chmin(T& a,T b){ if(a > b){ a = b; return true; }else return false; } using ll = long long; using ld = long double; using vi = vector<int>; using vl = vector<ll>; using pi = pair<int,int>; using pl = pair<ll,ll>; using vpi = vector<pi>; using vpl = vector<pl>; #define debug(arr) cout << #arr << " = " << arr << '\n' #define debug2(a,b) cout<<"["<<#a<<","<<#b<<"] = "<<"["<<a<<","<<b<<"]\n" #define debug3(a,b,c) cout<<"["<<#a<<","<<#b<<","<<#c<<"] = "<<"["<<a<<","<<b<<","<<c<<"]\n" template<class T> ostream &operator << (ostream& out, const vector<T>& arr) { cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}"; return out; } template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) { cout << "{\n"; for (auto& vec : arr)cout << " " << vec << ",\n"; cout << "}"; return out; } template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){ cout << "{" << p.first << "," << p.second << "}" << '\n'; return out; } template<class T> istream &operator >> (istream& in, vector<T>& arr) { for (auto& i : arr)cin >> i; return in; } template<class S,class T> istream &operator >> (istream& in,pair<S,T>& p){ cin >> p.first >> p.second; return in; } #define F first #define S second ///////////////////////////////////////////////////////////////////////// int main(void){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int n; vector<long long> a; ld m = 0,u = 0,c = 0; cin >> n; a.resize(n); REP(i,n){ cin >> a[i]; } REP(i,n){ m += abs(a[i]); } REP(i,n){ u += a[i] * a[i]; } u = sqrt(u); c = 0.0; REP(i,n){ if(abs(a[i]) > c) c = abs(a[i]); } cout << m << '\n'; cout << u << '\n'; cout << c << '\n'; return 0; }
#include <bits/stdc++.h> #define LL long long using namespace std; int n,C; LL A,B; int main() { scanf("%d",&n); for (int i=1,x;i<=n;i++) { scanf("%d",&x); A+=abs(x); B+=(LL)x*x; C=max(C,abs(x)); } printf("%lld\n%.12f\n%d\n",A,sqrt(B),C); 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 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; } string toupper(const string& S) { string T(S); REP(i,SZ(T)) T[i] = toupper(T[i]); return T; } string tolower(const string& S) { string T(S); REP(i,SZ(T)) T[i] = tolower(T[i]); return T; } using P = pair<ll,ll>; using VP = vector<P>; using VVP = vector<VP>; using VS = vector<string>; using VVS = vector<VS>; using VLL = vector<ll>; using VVLL = vector<VLL>; using VVVLL = vector<VVLL>; using VB = vector<bool>; using VVB = vector<VB>; using VVVB = vector<VVB>; using VD = vector<double>; using VVD = vector<VD>; using VVVD = vector<VVD>; using VLD = vector<ld>; using VVLD = vector<VLD>; using VVVLD = vector<VVLD>; static const double EPS = 1e-10; static const double PI = acos(-1.0); static const ll MOD = 1000000007; // static const ll MOD = 998244353; static const ll INF = (1LL << 62) - 1; // 4611686018427387904 - 1 // -------------------------------------------------------- // #include <atcoder/all> // using namespace atcoder; // Editorial AC int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); ll N, M; cin >> N >> M; VVP G(N); REP(_,M) { ll u, v, c; cin >> u >> v >> c; u--; v--; G[u].push_back(P(v, c)); G[v].push_back(P(u, c)); } VLL C(N,-1); C[0] = 1; queue<ll> q; q.push(0); while (!q.empty()) { ll u = q.front(); q.pop(); for (auto& [v, c] : G[u]) { if (C[v] != -1) continue; if (C[u] == c) { C[v] = (c == N ? 1 : c+1); } else { C[v] = c; } q.push(v); } } REP(i,N) COUT(C[i]); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define all(v) v.begin(), v.end() void chmax(ll &x, ll y) {x = max(x,y);} void chmin(ll &x, ll y) {x = min(x,y);} void Yes() {cout << "Yes" << endl; exit(0);} void No() {cout << "No" << endl; exit(0);} template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);} const ll inf = 1e18; const ll mod = 1e9 + 7; int main() { ll N, X; cin >> N >> X; vector<ll> A(N); rep(i,N) cin >> A[i]; ll ans = inf; rep(i,N) chmin(ans,X-A[i]); for (ll k=2; k<=N; k++) { // dp[i][j][k] : A[i]まで見たときj種類使って余りがlである最大値 vector<vector<vector<ll>>> dp(N,vector<vector<ll>>(k+1,vector<ll>(k,-inf))); rep(i,N) dp[i][0][0] = 0LL; dp[0][1][A[0]%k] = A[0]; for (ll i=0; i<N-1; i++) { ll a = A[i+1]; rep(j,k+1) rep(l,k) { if (dp[i][j][l]==-inf) continue; // 使わない chmax(dp[i+1][j][l],dp[i][j][l]); if (j+1>k) continue; // 使う chmax(dp[i+1][j+1][(l+a)%k],dp[i][j][l]+a); } } ll S = dp[N-1][k][X%k]; if (S==-inf) continue; chmin(ans,(X-S)/k); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, N) for(int i = 0; i < (int)N; i++) #define CREP(i, l, r) for(int i = l; i <= r; i++) const ll LLINF = (1LL << 60); // > 10^18 ll 2*LLINF int main() { ll n; cin >> n; vector<ll> sum(5000010, 0); REP(i,5000000) sum[i+1] += sum[i]+i+1; ll res = 2; for(int k = 2; n >= sum[k]; k++){ if(n%k == sum[k-1]%k) res += 2; } cout << res; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll n; cin>>n; n*=2; int ans=0; for(ll l=1;l*l<=n;l++){ if(n%l==0){ ll t=n/l+1-l; if(t%2==0){ ans++; if(t)ans++; } } } cout<<ans; }
#pragma GCC optimize("O2") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx2") #pragma GCC optimize("Os") #include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define PI acos(-1) #define pb push_back #define ld long double #define sp fixed<<setprecision #define bp __builtin_popcountll #define all(x) x.begin(),x.end() #define pii pair<long long,long long> #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); const int M = (1e9)+7; const int N = 1e5+5; const int INF = 1e9; signed main() { FAST int tc=1; //cin>>tc; for(int ti=1;ti<=tc;ti++) { int n,m; cin>>n>>m; string s[n]; for(int i=0;i<n;i++)cin>>s[i]; int dist[n][m], vis[n][m] = {}; pii st,en; vector<pii> x[26]; int done[26] = {}; pii dir[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1} }; set<pair<int,pii>> all; for(int i=0;i<n;i++)for(int j=0;j<m;j++) { if(s[i][j] == 'S')st = {i,j}; if(s[i][j] == 'G')en = {i,j}; if(s[i][j] >= 'a' && s[i][j] <= 'z')x[s[i][j]-'a'].pb({i,j}); dist[i][j] = s[i][j] == 'S' ? 0 : INF; all.insert({dist[i][j],{i,j}}); } while(true) { auto it = all.begin(); pii now = it->ss; int d = it->ff; if(d == INF)break; all.erase(it); if(now == en)break; vis[now.ff][now.ss] = 1; for(int i=0;i<4;i++) { pii ne = {now.ff+dir[i].ff, now.ss+dir[i].ss}; if(ne.ff>=0 && ne.ss>=0 && ne.ff<n && ne.ss<m && s[ne.ff][ne.ss] != '#' && !vis[ne.ff][ne.ss] && dist[ne.ff][ne.ss] > d + 1) { //all.erase({dist[ne.ff][ne.ss], ne}); dist[ne.ff][ne.ss] = d + 1; all.insert({dist[ne.ff][ne.ss], ne}); } } if(s[now.ff][now.ss] >= 'a' && s[now.ff][now.ss] <= 'z') { int ind = s[now.ff][now.ss] - 'a'; if(done[ind])continue; for(pii ne: x[ind]) { if(!vis[ne.ff][ne.ss] && dist[ne.ff][ne.ss] > d + 1) { //all.erase({dist[ne.ff][ne.ss], ne}); dist[ne.ff][ne.ss] = d + 1; all.insert({dist[ne.ff][ne.ss], ne}); } } done[ind] = 1; } } int ans = dist[en.ff][en.ss]; if(dist[en.ff][en.ss] == INF)ans = -1; cout<<ans<<endl; } return 0; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; // edge[node_from][i] = pair(cost, node_to_i) vector<long> dijkstra(vector<vector<pair<long, int>>> &edge, int start=0) { priority_queue<pair<long, int>> q; int n_node = edge.size(); vector<long> cost(n_node, -1L); q.push(make_pair(0, start)); while (! q.empty()) { auto [now_c, now] = q.top(); q.pop(); if (cost[now] != -1) continue; cost[now] = -now_c; for (auto [next_c, next]: edge[now]) { if (cost[next] == -1) q.push(make_pair(now_c-next_c, next)); } } return cost; } void Main() { int h, w; cin >> h >> w; vector<string> grid(h); pair<int, int> start, end; vector<vector<pair<int, int>>> potal(256); vector<vector<pair<long, int>>> edge(h*w+'z'-'a'+1); for (int i = 0; i < h; i++) { cin >> grid[i]; for (int j = 0; j < w; j++) { switch (grid[i][j]) { case 'S': start = make_pair(i, j); break; case 'G': end = make_pair(i, j); break; case '.': break; case '#': break; default: potal[grid[i][j]].push_back(make_pair(i, j)); break; } } } int d[4][2] = {{-1, 0}, {+1, 0}, {0, -1}, {0, +1}}; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (grid[i][j] == '#') continue; for (int k = 0; k < 4; k++) { int dy = d[k][0]; int dx = d[k][1]; if (i+dy>=0 && i+dy<h && j+dx>=0 && j+dx<w && grid[i+dy][j+dx] != '#') { edge[i*w+j].push_back(make_pair(1, (i+dy)*w+(j+dx))); edge[(i+dy)*w+(j+dx)].push_back(make_pair(1, i*w+j)); } } } } for (int c = 'a'; c <= 'z'; c++) { for (auto [i, j]: potal[c]) { edge[i*w+j].push_back(make_pair(1, w*h+c-'a')); edge[w*h+c-'a'].push_back(make_pair(0, i*w+j)); } } auto cost = dijkstra(edge, start.first*w+start.second); cout << cost[end.first*w+end.second] << endl; } int main(int argc, char **argv) { ios::sync_with_stdio(false); std::cin.tie(nullptr); Main(); return 0; }
#include <bits/stdc++.h> #include <math.h> #define rep(i,n) for (int i = 0; i < (n) ;i++) using namespace std; using p=pair<int,int>; typedef long long ll; int main() { string a; cin >> a; int i = 0; while(a[i]!='.'&&(a[i]=='0'||a[i]=='1'||a[i]=='2'||a[i]=='3'||a[i]=='4'||a[i]=='5'||a[i]=='6'||a[i]=='7'||a[i]=='8'||a[i]=='9')){ cout << a[i]; i++; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; #define rep(i, n) for(int i = 0; i < (int)(n); i++) int main() { string x; cin >> x; for(int i; i < x.size(); i++) { char c = x[i]; if(c == '.') break; else cout << c; } cout << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; #define mod 1000000007 using ll=long long; const int INF=1000000000; const ll LINF=1001002003004005006ll; int dx[]={1,0,-1,0},dy[]={0,1,0,-1}; // ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} 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;} struct IOSetup{ IOSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(12); } } iosetup; 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==(int)v.size()?"":" "); return os; } template<typename T> istream &operator>>(istream &is,vector<T>&v){ for(T &x:v)is>>x; return is; } struct UnionFind{ private: vector<int> par,siz; public: int con; UnionFind(int n):par(n),siz(n,1),con(n){ iota(begin(par),end(par),0); } int root(int x){ return (par[x]==x?x:(par[x]=root(par[x]))); } bool sameroot(int x,int y){ return root(x)==root(y); } bool unite(int x,int y){ x=root(x);y=root(y); if(x==y) return false; if(siz[x]<siz[y])swap(x,y); siz[x]+=siz[y]; par[y]=x; con--; return true; } int size(int x){ return siz[root(x)]; } }; signed main(){ int h,w;cin>>h>>w; UnionFind uf(h+w); rep(i,h){ rep(j,w){ char c;cin>>c; if(c=='#'){ uf.unite(i,h+j); } } } uf.unite(0,h); uf.unite(0,h+w-1); uf.unite(h-1,h); uf.unite(h-1,h+w-1); int res=INF; // left { UnionFind l(h); vector<vector<int>> v(h+w); rep(i,h) v[uf.root(i)].push_back(i); rep(i,h+w){ if(v.empty()) continue; for(int j=1;j<(int)v[i].size();j++) l.unite(v[i][0],v[i][j]); } chmin(res,l.con-1); } { UnionFind r(w); vector<vector<int>> v(h+w); rep(i,w) v[uf.root(h+i)].push_back(i); rep(i,h+w){ if(v.empty()) continue; for(int j=1;j<(int)v[i].size();j++) r.unite(v[i][0],v[i][j]); } chmin(res,r.con-1); } cout<<res<<endl; return 0; } /* 4 5 ..... .###. ..... ..... */
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <iostream> #include <cassert> #include <cmath> #include <string> #include <queue> #include <set> #include <map> #include <cstdlib> using namespace std; #define mp make_pair #define pb push_back #define fi first #define se second #define li long long #define pii pair<int, int> #define vi vector<int> #define li long long #define forn(i, n) for (int i = 0; i < (int)n; i++) #define fore(i, b, e) for (int i = (int)b; i <= (int)e; i++) const int MAXN = 2005; bool visited[MAXN]; vi edges[MAXN]; int n, m; void dfs(int v) { visited[v] = true; for (int u : edges[v]) { if (!visited[u]) dfs(u); } } void add_edge(int row, int col) { edges[row].pb(col + n); edges[col + n].pb(row); } int main() { scanf("%d%d", &n, &m); forn(i, n) { string s; cin >> s; forn(j, m) { if (s[j] == '#') { add_edge(i, j); } } } /*forn(i, n) { add_edge(i, 0); add_edge(i, m - 1); } forn(j, m) { add_edge(0, j); add_edge(n - 1, j); }*/ add_edge(0, 0); add_edge(0, m); add_edge(n - 1, 0); add_edge(n - 1, m - 1); int row_comp = 0; forn(i, n) { if (!visited[i]) { ++row_comp; dfs(i); } } memset(visited, false, sizeof(visited)); int col_comp = 0; fore(i, n, n + m - 1) { if (!visited[i]) { ++col_comp; dfs(i); } } //cerr << row_comp << " " << col_comp << endl; printf("%d", min(row_comp - 1, col_comp - 1)); }
#include <bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define FOR(i, a, b) for (ll i = (a); i <= (b); i++) #define FORX(i, a, b, x) FOR (ll i = (a); i <= (b); i+=x) #define debug(x) cerr << #x << " is= " << x << endl; //use FOR debugging #define read(a) int a; cin >> a; #define FORD(i, a, b) for (ll i = (a); i >= (b); i--) #define pb(a) push_back(a) #define pf(a) push_front(a) #define mp(a,b) make_pair(a,b) #define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) #define ll long long int #define vi vector<int> #define vll vector<ll> #define vpii vector<pair<int,int>> #define vov vector<vector<int>> #define pr pair<int,int> #define vpll vector<pair<ll,ll>> #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() //reverse of above; #define sz(container) int((container).size()) #define cut(x) {cout<<x<<"\n"; return;} #define setprec(x) cout << fixed << showpoint << setprecision(15)<<x<<"\n"; #define gcd(a,b) __gcd(a,b) #define lcm(a,b) a*b/__gcd(a,b) #define time cout << clock() / double(CLOCKS_PER_SEC) << endl; #define endl "\n"; #define cntbit(x) __builtin_popcount(x); #define fi first #define se second #define mod 1000000007 #define mod1 998244353 using namespace std; using namespace __gnu_pbds; typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset; //*s.find_by_order() ->returns an iterator to the k-th largest element (counting from zero); //s.order_of_key() ->number of elements strictly smaller then our item; //st.rbegin()->second; last element in set //st.erase(prev(st.end())); delete last element in set; //sort(a+1,a+n+1,[](ll x,ll y){return abs(x)>abs(y);}); //sort(v.begin(), v.end(), greater<int>()); const int N=2e5+5; const ll inf=1e18; ll n,a[N],ma=0; set<ll>s; void solve() { FOR(i,1,n) { s.insert(a[i]); if(ma==a[i]) { while(s.find(ma)!=s.end()) ma++; } cout<<ma<<endl; } } int main() { fast_io; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin>>n; FOR(i,1,n) cin>>a[i]; solve(); }
#include<bits/stdc++.h> using namespace std; #define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long int #define endl "\n" const int maxr = 1e5 + 5; int solve(int idx, vector<bool> &vis, string &s) { if(idx == 4) { int flag = 1; for(int i = 0; i < 10; i++) { if(s[i] == 'o' && !vis[i]) flag = 0; } return flag; } int cnt = 0; for(int i = 0; i < 10; i++) { if(s[i] == 'o' || s[i] == '?') { bool temp = vis[i]; vis[i] = true; cnt += solve(idx + 1, vis, s); vis[i] = temp; } } return cnt; } int32_t main() { GO; string s; cin >> s; int cnt = 0; for(auto x: s) if(x == 'o') cnt++; if(cnt > 4) { cout << 0 << endl; return 0; } vector<bool> vis(10, 0); int ans = solve(0, vis, s); cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; #define rep(i,n) for(int i=0;i<(n);i++) #define rrep(i,n) for(int i=(n)-1;i>=0;i--) #define rep1(i,n) for(int i=1;i<=(n);i++) #define rrep1(i,n) for(int i=(n);i>0;i--) #define fore(i_in,a) for (auto& i_in: a) #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fio() cin.tie(nullptr);ios::sync_with_stdio(false); #define DEBUG_CTN(v) cerr<<#v<<":";for(auto itr=v.begin();itr!=v.end();itr++) cerr<<" "<<*itr; cerr<<endl template<class T> bool chmax(T &a, const T &b) {if (a<b) { a = b; return true; } return 0;} template<class T> bool chmin(T &a, const T &b) {if (a>b) { a = b; return true; } return 0;} template<class T> void print(const T &t) { cout << t << "\n"; } const ll INF = 1LL << 62; const int iINF = 1 << 30; #define pq(T) priority_queue<T, vector<T>, greater<T>> struct Edge {ll to; ll w; Edge(ll to, ll w) : to(to), w(w) {}}; using Graph = vector<vector<Edge>>; vl dijkstra(Graph &G, int s){ int n = G.size(); vl dist(n, INF); dist[s] = 0; using pp = pair<ll, ll>; pq(pp) que; que.push({dist[s], s}); while (!que.empty()) { ll v = que.top().second; ll d = que.top().first; que.pop(); if (d > dist[v]) continue; if(!G[v].empty()) fore(e, G[v]) { if (chmin(dist[e.to], dist[v] + e.w)) { que.push({dist[e.to], e.to}); } } } return dist; } int n; int main() { fio(); cin>>n; Graph E(n+1); rep1(i,n){ ll x = (2*i)%n+1, y=(2*i+1)%n+1; cout<<x<<" "<<y<<"\n"; E[i].emplace_back(x,1); E[i].emplace_back(y,1); } ll ans = 0; rep1(i,n) { vl dist = dijkstra(E,i); ll tmp = 0; rep1(i,n) chmax(tmp,dist[i]); chmax(ans,tmp); } }
// Created by ... #include <bits/stdc++.h> #define db1(x) cout<<#x<<"="<<x<<'\n' #define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n' #define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n' #define vll vector< ll > #define M 100000 #define MD 1000000007 #define pb push_back #define rep(i,a,b) for(ll i = a; i <= b; ++i) #define fo(i,a,b) for(int i = a; i<= b; ++i) #define pii pair<ll,ll> #define vec(a) vector<a > #define all(a) a.begin(),a.end() #define se second #define fi first #define inf 0xffffffff #define inchar getchar_unlocked #define outchar(x) putchar_unlocked(x) #define int long long #define endl '\n' #define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) using namespace std; using ll = long long; ll md=MD; ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;} ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);} ll Min(ll a,ll b){if(a<b)return a; return b;} ll Max(ll a,ll b){if(a>b)return a; return b;} bool check(int a,int b,int c,int d){ return ((abs(a-c)+abs(b-d)<=3) || (a+b==c+d) || (a-b==c-d)); } int32_t main() { IOS; vec(pii) v; rep(i,-2,2)rep(j,-2,2)v.pb({i,j}); v.pb({-3,0});v.pb({3,0});v.pb({0,-3});v.pb({0,3}); int a,b,c,d; cin>>a>>b>>c>>d; if(a==c && b==d)cout<<"0"; else if(check(a,b,c,d))cout<<"1"; else{ for(auto&p:v){ if(check(a+p.fi,b+p.se,c,d) || check(a,b,c+p.fi,d+p.se)){cout<<"2"; return 0;} } int k1=abs(a-b+c-d); if(k1%2==0){ cout<<"2"; return 0; } cout<<"3"; } cout<<'\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> point; #define x() real() #define y() imag() #define vec(a, b) ((b) - (a)) #define dot(a, b) (conj(a) * (b)).real() #define fastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) const ld eps = 1e-6; const int N = 2e5 + 7; ll values[N]; ll all = 0; vector<int> g[N]; pair<int, int> edges[N]; int parent[N]; int in[N]; void dfs(int node, ll value, int par) { values[node] += value; for (auto i : g[node]) { if (i != par) dfs(i, values[node], node); } } void dfs1(int node, int par) { parent[node] = par; for (auto i : g[node]) { if (i != par) { dfs1(i, node); } } } int main() { int n; cin >> n; for (int i = 1; i <= n-1; i++) { int a, b; cin >> a >> b; edges[i] = {a, b}; g[a].push_back(b); g[b].push_back(a); in[b]++; } int root = 1; dfs1(root, -1); int q; cin >> q; while (q--) { ll t, e, x; cin >> t >> e >> x; int a = edges[e].first, b = edges[e].second; if (t == 1) { // a, b if (parent[b] == a) { all += x; values[b] -= x; } else { values[a] += x; } } else { if (parent[a] == b) { all += x; values[a] -= x; } else { values[b] += x; } } } dfs(root, all, -1); for (int i = 1; i <= n; i++) { cout << values[i] << '\n'; } }
#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 dup(x,y) (((x)+(y)-1)/(y)) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef pair<int, int> pii; const double EPS = 1e-10; const int INF = 1e9; const ll LINF = 1e18; const int MOD = 1000000007; const double PI = acos(-1); int dx[4] = {0,1,0,-1}; int dy[4] = {1,0,-1,0}; template<typename T> bool chmax(T &a, T b) {if(a<b){a=b; return 1; } return 0; } template<typename T> bool chmin(T &a, T b) {if(a>b){a=b; return 1; } return 0; } ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) { return a/gcd(a,b)*b;} ll mpow(ll x, ll p) { if (p==0) return 1; ll res=mpow(x,p/2); res=res*res%MOD; return p%2?res*x%MOD:res; } ll lpow(ll x, ll p) { if (p==0) return 1; ll res=lpow(x,p/2); res*=res; return p%2?res*x:res; } vector<int> to[200005]; int par[200005]; int seen[200005]; ll imos[200005]; void dfs(int prev, int cur) { par[cur] = prev; seen[cur] = 1; if (prev != -1) imos[cur] += imos[prev]; for (int nx: to[cur]) { if (seen[nx]) continue; dfs(cur, nx); } } int main() { int n; cin >> n; vector<int> a(n-1), b(n-1); // 隣接リストにデータを追加 rep(i,n-1) { cin >> a[i] >> b[i]; a[i]--, b[i]--; to[a[i]].push_back(b[i]); to[b[i]].push_back(a[i]); } // 0を根として、各頂点の親を記録する dfs(-1, 0); int q; cin >> q; rep(i,q) { int t, e, x; cin >> t >> e >> x; e--; int v = a[e], u = b[e]; // tが2のときは、vとuをswapすれば操作が同じになる if (t == 2) swap(v, u); if (par[u] == v) { imos[0] += x; imos[u] -= x; } else { imos[v] += x; } } // seenの値を0にして、再度dfsを実行する rep(i,n) seen[i] = 0; dfs(-1, 0); rep(i,n) cout << imos[i] << endl; }
#include <iostream> #include <algorithm> #include <stack> #include <queue> #include <vector> #include <bitset> #include <iomanip> #include <cmath> #include <set> #include <unordered_set> #include <functional> #include <map> #include <unordered_map> #include <string> #include <tuple> #include <deque> using namespace std; using ll = long long; const int MOD=1e9+7; const int MAX=100009; ll fac[100009],finv[100009],inv[100009]; #define pi 3.14159265358979323846 #define ee 2.71828182845904523536 #define INF 1e18 ll gcd(ll x, ll y) { // 最大公約数 if (y == 0)return x; else return gcd(y, x % y); } bool prime(ll x) { //素数判定 if(x==1)return false; if (x!=2&&x % 2 == 0)return false; for (ll i = 3; i <= sqrt(x); i+=2) { if (x % i == 0)return false; } return true; } ll modinv(ll a, ll m) { //逆元 long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } ll modpow(ll a, ll n, ll mod) { //二分累乗法 ll res = 1; while (n) { if (n % 2)res = res * a % mod; a = a * a % mod; n /= 2; } return res; } void COMinit() { //二項係数計算の前処理 fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(int n, int k){ //二項係数計算 if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } struct UnionFind { // UnionFind vector<int> par; vector<int> siz; UnionFind(int N) : par(N), siz(N, 1) { for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; if (par[rx] > par[ry])swap(rx, ry); siz[rx] += siz[ry]; par[ry] = rx; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } int size(int x) { return siz[root(x)]; } }; int main() { int n; cin>>n; ll dp[100009][2]={}; dp[0][0]=1; for(int i=0;i<n-1;i++){ dp[i+1][0]+=dp[i][0]+dp[i][1]; dp[i+1][0]%=MOD; dp[i+1][1]+=dp[i][0]; dp[i+1][1]%=MOD; } ll a[100009]; for(int i=0;i<n;i++){ cin>>a[i]; } ll ans=a[0]*((dp[n-1][0]+dp[n-1][1])%MOD)%MOD; for(int i=1;i<n;i++){ ans+=a[i]*((dp[i-1][0]+dp[i-1][1])%MOD*((dp[n-i-1][0]+dp[n-i-1][1])%MOD)%MOD-dp[i-1][0]*dp[n-i-1][0]%MOD); ans%=MOD; if(ans<0)ans+=MOD; } cout<<ans<<endl; }
using namespace std; #include <bits/stdc++.h> #define N 100005 #define ll long long #define mo 1000000007 int n; ll a[N]; int main(){ ll x; scanf("%d",&n); for (int i=1;i<=n;++i) scanf("%lld",&a[i]); ll c0=1,s0=a[1],c1=0,s1=0; for (int i=2;i<=n;++i){ ll _c0=c0+c1,_s0=s0+s1+_c0*a[i]; ll _c1=c0,_s1=s0-_c1*a[i]; c0=_c0%mo,s0=_s0%mo; c1=_c1%mo,s1=_s1%mo; } ll ans=((s0+s1)%mo+mo)%mo; printf("%lld\n",ans); return 0; }
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define uni(x) x.erase(unique(rng(x)),x.end()) #define PQ(T) priority_queue<T,v(T),greater<T> > #define dup(x,y) (((x)+(y)-1)/(y)) #define v(T) vector<T> #define vv(T) v(v(T)) using ll = int64_t; using ull = uint64_t; using uint = uint32_t; using pii = pair<int,int>; using pll = pair<ll,ll>; using pil = pair<int,ll>; using pil = pair<int,ll>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; template<typename T>inline istream& operator>>(istream&i,v(T)&v) {rep(j,v.size())i>>v[j];return i;} template<typename T>string join(const v(T)&v) {stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);} template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v) {if(v.size())o<<join(v);return o;} template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v) {return i>>v.fi>>v.se;} template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v) {return o<<v.fi<<","<<v.se;} constexpr double eps = 1e-6; constexpr ll LINF = 100200300400500600ll; constexpr int INF = 2*((1<<30)-1)+1; //-------------------------------------------------------- #define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false); #define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());} #define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop) //-------------------------------------------------------------- template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;} template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;} constexpr int dx[4] = {0,1,0,-1}; constexpr int dy[4] = {-1,0,1,0}; // constexpr int mod = 1000000007; constexpr ll mod = 998244353; #define Yes(ifeq) cout<<(( ifeq )? "Yes":"No")<<endl; void Main(){ ull n_; cin>>n_; ull n=n_; // ull ans=0;g++-10 ull len=to_string(n).length(); ull num=1,ans=0; for(ull i=1;i<len;i++){ num*=10; ans+=(num-num/(ull)10)*max(((i-(ull)1)/(ull)3),(ull)0); } ans+=(n+1-num)*((len-(ull)1)/(ull)3); cout<<ans<<endl; } signed main(int argc,char** argv) {fastio; myio; myloopset Main();}
#include "bits/stdc++.h" using namespace std; #define rep(i, a, b) for(int i=a; i<=b; i++) #define trav(a, x) for(auto& a : x) #define all(x) begin(x), end(x) #define sz(x) (int) x.size() #define pb push_back #define f first #define s second #define nl "\n" typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; const int MOD = 1e9+7; template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>; // int dp[101][2]; int a, b, x, y; int main(){ ios::sync_with_stdio(false); cin.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); cin >> a >> b >> x >> y; cout << (a==b?x:min(a>b?(a-b-1)*y+x:(b-a)*y+x, (a>b? (a-b)*(2*x)-x: (2*b-2*a+1)*x))); }
#include <bits/stdc++.h> //#pragma GCC optimize("unroll-loops") //#pragma GCC optimize("-O3") //#pragma GCC optimize("Ofast") //#pragma GCC optimize("fast-math") //#pragma GCC optimize("no-stack-protector") #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define sz(x) int(x.size()) #define all(x) x.begin(),x.end() #define PB push_back #define MP make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define pil pair<int, ll> #define pli pair<ll, int> #define pdd pair<ld, ld> #define ft first #define sd second #define i2 array<int,2> #define i3 array<int,3> #define i6 array<int,6> #define i4 array<int,4> #define l2 array<ll,2> #define l3 array<ll,3> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; typedef long double ld; template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; const int N = 500100; const int M = 300100; const int BIG = int(5e8) + 10; const int oo = 2e9; const ll OO = 1e18; const int md = int(1e9) + 7; const int PW = 60; const ld E = 1e-9; const int MX = 1000100; mt19937 rnd(chrono::system_clock().now().time_since_epoch().count()); void BAD(){ cout << -1; exit(0); } int mult(int x, int y) { return (1ll * x * y) % md; } int sum(int x, int y){ x += y; if (x >= md) x -= md; return x; } ll mx = 0, SUM = 0, cur = 0, n; int main(){ #ifdef _LOCAL freopen("in.txt","r",stdin); // freopen("output.txt","w",stdout); #else // freopen("mining.in","r",stdin); freopen("mining.out","w",stdout); ios_base::sync_with_stdio(0); cin.tie(0); #endif cin >> n; for (ll i = 1; i <= n; i++){ ll x; cin >> x; SUM += x; cur += SUM; mx = max(mx, x); cout << cur + mx * i << '\n'; } return 0; }
#include <bits/stdc++.h> #include <cassert> #define rep(i, N) for (int i = 0; i < (N); ++i) #define rep2(i, a, b) for (ll i = a; i <= b; ++i) #define rep3(i, a, b) for (ll i = a; i >= b; --i) #define pb push_back #define eb emplace_back #define fi first #define se second #define nl '\n' #define endl '\n' #define all(c) begin(c), end(c) #define ok() puts(ok ? "Yes" : "No"); #define pcnt(x) __builtin_popcountll(x) #define df(x) ll x = in(); template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; using vvll = vector<vll>; using ii = pair<int, int>; using vvi = vector<vi>; using vii = vector<ii>; using vs = vector<string>; using P = pair<ll, ll>; using gt = greater<P>; template <class T> using minq = priority_queue<T, vector<T>, greater<T>>; using vP = vector<P>; inline ll in() { ll x; scanf("%lld", &x); return x; } template <class T> void takeUnique(vector<T> &v) { auto last = std::unique(v.begin(), v.end()); v.erase(last, v.end()); } template <class T> void print(const initializer_list<T> &il) { for (auto x : il) { cout << x << " "; } cout << "\n"; } inline void priv(vll a) { rep(i, (int)a.size() - 1) cout << a[i] << " "; cout << a.back() << nl; } inline void priv(vi a) { rep(i, (int)a.size() - 1) cout << a[i] << " "; cout << a.back() << nl; } const ll LINF = 8e18L + 1; const int INF = 8e9 + 1; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; int dxx[] = {0, 1, 1, 1, 0, -1, -1, -1}; int dyy[] = {1, 1, 0, -1, -1, -1, 0, 1}; // g++ -std=c++17 -stdlib=libc++ #define _GLIBCXX_DEBUG // This slows down the execution; even the time complexity, since it checks if // std funcs such as lower_bound meets prereqs int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(16); int n; cin >> n; vll a(n); rep(i, n) cin >> a[i]; ll mx = 0; ll t = 0; vll SS(n + 1); rep(i, n) SS[i + 1] += SS[i] + a[i]; rep(i, n) { chmax(mx, a[i]); ll now = (i + 1) * mx; t += SS[i + 1]; now += t; cout << now << nl; } return 0; }
#include <iostream> #include <string> #include <cstdio> #include <algorithm> #include <vector> using namespace std; int main(void) { double ans=0; double a=0,b=0; cin >> a >> b; ans=a*b/100; cout << ans << endl; return 0; }
/* For you, who has never forgotten the magic. It wants you to know it remembers you too.*/ /*J. M. D. */ #include <bits/stdc++.h> using namespace std; #define int long long #define pll pair<int,int> #define ppll pair<string,pair<string, string>> #define vvll vector<vector<int>> #define l_b lower_bound #define u_b upper_bound #define vll vector<int> #define vpll vector<pll> #define vc vector <char> #define vs vector <string> #define pb emplace_back #define p_b pop_back() #define prq priority_queue #define setbits(x) __builtin_popcountll(x) #define sps(x,y) fixed<<setprecision(y)<<x #define hell 1000000007 #define rep(i,s,n) for(int i=s;i<n;i++) #define ff first #define mem(arr,x) memset(arr,x,sizeof(arr)) #define ss second #define pi 3.14159265358979323846 #define all(v) v.begin(),v.end() #define allr(x) x.rbegin(),x.rend() #define mp make_pair #define display(x) for(auto dsp:x)cout<<dsp<<" "; cout<<"\n"; #define INF 1000000000000000000//18 void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } const int N = 5e6+100; // const int BLK= 555; //--------------------------------------------- int dr[4] = {0, 0, 1,-1}; int dc[4] = {1,-1, 0, 0}; int ddr[8]= {0, 0, 1, -1, 1, -1, 1, -1}; int ddc[8]= {1, -1, 0, 0, 1, -1, -1, 1}; int ddr1[8]= {1, 1, -1, -1, 2, 2, -2, -2}; int ddc1[8]= {2, -2, 2, -2, 1, -1, 1, -1}; //-------------------------------------------- int32_t main() { fast(); // int t,z; // cin>>t; // rep(z,1,t+1){ // cout<<"Case #"<<z<<": "; double a, b; cin>>a>>b; double ans= (a*b)/100; cout<<sps(ans, 6)<<"\n"; }
#include<bits/stdc++.h> #pragma GCC optimize("Ofast") //#pragma GCC target("avx2") #pragma GCC optimize("unroll-loops") using namespace std; //#include<boost/multiprecision/cpp_int.hpp> //#include<boost/multiprecision/cpp_dec_float.hpp> //namespace mp=boost::multiprecision; //#define mulint mp::cpp_int //#define mulfloat mp::cpp_dec_float_100 struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init; #define INF (1<<30) #define LINF (lint)(1LL<<56) #define endl "\n" #define rep(i,n) for(lint (i)=0;(i)<(n);(i)++) #define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--) #define flc(x) __builtin_popcountll(x) #define pint pair<int,int> #define pdouble pair<double,double> #define plint pair<lint,lint> #define fi first #define se second #define all(x) x.begin(),x.end() #define vec vector<lint> #define nep(x) next_permutation(all(x)) typedef long long lint; int dx[8]={1,1,0,-1,-1,-1,0,1}; int dy[8]={0,1,1,1,0,-1,-1,-1}; const int MAX_N=3e5+5; template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;} template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;} //vector<int> bucket[MAX_N/1000]; constexpr lint MOD=1000000007; //constexpr int MOD=998244353; /*#include<atcoder/all> using namespace atcoder; typedef __int128_t llint;*/ int main(void){ int N; cin >> N; lint A[N]; rep(i,N) cin >> A[i]; lint ans=0; lint plus=1,minus=0; lint fib[N+1]={}; fib[0]=1,fib[1]=1; rep(i,N-1) fib[i+2]=(fib[i+1]+fib[i])%MOD; rep(i,N){ lint mul=(plus*fib[N-i]-minus*fib[N-i-1]+MOD*MOD)%MOD; ans=(ans+mul*A[i])%MOD; lint np=(plus+minus)%MOD; lint nm=(plus)%MOD; plus=np,minus=nm; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) #define all(v) begin(v), end(v) #define sz(v) v.size() #define INF 1e17 #define EPSILON 1e-14 template <typename T> bool chmax(T &a, const T& b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T& b) { if (a > b) { a = b; return true; } return false; } bool collision_detection(ll a, ll b, ll c, ll d, ll e, ll f, ll g, ll h){ pair<long double, long double> center1 = {(a+c)/2.0, (b+d)/2.0}; pair<long double, long double> center2 = {(e+g)/2.0, (f+h)/2.0}; long double x_dist = abs(center1.first - center2.first); long double y_dist = abs(center1.second - center2.second); if(x_dist >= (c-a)/2.0 + (g-e)/2.0){ return false; } if(y_dist >= (d-b)/2.0 + (h-f)/2.0){ return false; } return true; } vector<ll> enum_div(ll n){ vector<ll> ret; for(ll i = 1 ; i*i <= n ; ++i){ if(n%i == 0){ ret.push_back(i); if(i*i != n){ ret.push_back(n/i); } } } sort(all(ret)); return ret; } int main() { random_device rd; seed_seq seed = {rd()}; mt19937 engine(seed); uniform_int_distribution<> dist(0, 9999); ll n; cin >> n; vector<ll> x(n), y(n), r(n); rep(i, n){ cin >> x.at(i) >> y.at(i) >> r.at(i); } vector<tuple<ll, ll, ll, ll>> ads(n); rep(i, n){ rep(j, r.at(i)){ ll factor = pow(2,8); vector<ll> divisors = enum_div((r.at(i)-j)/factor); bool put = false; ll cnt = 0; for(ll div : divisors){ if(cnt <= 8){ cnt++; continue; } ll a = x.at(i); ll b = y.at(i); ll c = a + div; ll d = b + ((r.at(i)-j)/factor)/div; if(c > 10000 || d > 10000){ continue; } bool hit = false; rep(k, i){ if(collision_detection(a, b, c, d, get<0>(ads.at(k)), get<1>(ads.at(k)), get<2>(ads.at(k)), get<3>(ads.at(k)))){ hit = true; break; } } if(hit){ continue; } ads.at(i) = {a, b, c, d}; put = true; break; } if(put){ break; } if(j == r.at(i)-1){ bool make = false; while(!make){ ll p = dist(engine); ll q = dist(engine); rep(k, i){ if(collision_detection(p, q, p+1, q+1, get<0>(ads.at(k)), get<1>(ads.at(k)), get<2>(ads.at(k)), get<3>(ads.at(k)))){ break; } if(k == i-1){ ads.at(i) = {p, q, p+1, q+1}; make = true; break; } } } } } //cerr << i << endl; } rep(i, n){ cout << get<0>(ads.at(i)) << " " << get<1>(ads.at(i)) << " " << get<2>(ads.at(i)) << " " << get<3>(ads.at(i)) << '\n'; } }
#include <bits/stdc++.h> using namespace std; #define f first #define s second #define pb push_back #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define db(x) cout << '>' << #x << ':' << x << endl; #define sz(x) ((int)(x).size()) #define newl cout << "\n" #define ll long long int #define vi vector<int> #define vll vector<long long> #define vvll vector<vll> #define pll pair<long long, long long> #define fast_io() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); ll tc, n, m, k; const int MAXN = 200005; vector<vector<int>> g(MAXN), gr(MAXN); vector<bool> used(MAXN); vector<int> order, component; void dfs1(int v) { used[v] = true; for (size_t i = 0; i < g[v].size(); ++i) if (!used[g[v][i]]) dfs1(g[v][i]); order.push_back(v); } void dfs2(int v) { used[v] = true; component.push_back(v); for (size_t i = 0; i < gr[v].size(); ++i) if (!used[gr[v][i]]) dfs2(gr[v][i]); } int solve() { cin >> n >> m; vll arr(n); rep(i, 0, n) cin >> arr[i]; vll final(n); rep(i, 0, n) cin >> final[i]; // m edges // graph rep(i, 0, m) { ll u, v; cin >> u >> v; u--; v--; g[u].pb(v); g[v].pb(u); gr[v].pb(u); gr[u].pb(v); } used.assign (n, false); for (int i=0; i<n; ++i) if (!used[i]) dfs1 (i); used.assign (n, false); for (int i=0; i<n; ++i) { int v = order[n-1-i]; if (!used[v]) { dfs2 (v); // logic for this component ll arrsum = 0; ll finalsum = 0; for(auto x:component) { arrsum += arr[x]; finalsum += final[x]; } if(arrsum != finalsum) { cout<<"No"; return 0; } component.clear(); } } cout << "Yes"; return 0; } int main() { fast_io(); #ifndef ONLINE_JUDGE freopen("../input.txt", "r", stdin); freopen("../output.txt", "w", stdout); #endif solve(); return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vii = vector<pii>; using vll = vector<pll>; #define fi first #define se second #define sz(c) ((int)(c).size()) #define all(c) (c).begin(), (c).end() #define forn(i, m, n) for (int i = m, nnnn = (n); i < nnnn; ++i) #define pb push_back #define mp make_pair #define NIL 0 #define INF INT_MAX #define int128 __int128_t // greatest common divisor ll gcd(ll a, ll b) { return b ? gcd (b, a % b) : a; } // lowest common multiple ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // sieve of eratosthenes with smallest prime factor vector<int> sieve; void prime_sieve(int n){ sieve.reserve(n+1); forn(i, 0, n+1) sieve[i] = i; forn(i, 2, n+1){ if (sieve[i] == i){ forn(j, 2, n/i+1){ if (sieve[i*j] == i*j) sieve[i*j] = i; } } } } // normalise input to be in range of modulo // faster than % when close to P ll norm(ll a, ll P) { while (a >= P) a -= P; while (a < 0) a += P; return a; } // multiply and modulo ll mul_mod(ll a, ll b, ll P) { return a * b % P; } // power and modulo (log n) ll pow_mod(ll a, ll b, ll P){ ll curr = a, ans = 1; while(b != 0){ if (b&1) { ans *= curr; ans%=P; } curr *= curr; curr %= P; b >>= 1; } return ans; } // calculate modulo inverse (log n) ll inv_mod(ll a, ll P) { return pow_mod(a, P - 2ll, P); } // calculate modulo inverse (log n) ll div_mod(ll a, ll b, ll P) { return a * inv_mod(b, P) % P; } // most significant bit (log n) int msb(ll a){ for(int i = 62; i >= 0; i--){ if (a & ((ll)1 << i)) return i + 1; } return 0; } // Factorial vector<ll> fact; void Fact(int n, ll P){ if (fact.size() < 1) fact.pb(1); forn(i, fact.size(), n+1) fact.pb(fact[i-1] * i % P); } void Fact(int n){ if (fact.size() < 1) fact.pb(1); forn(i, fact.size(), n+1) fact.pb(fact[i-1] * i); } vector<ll> fact_inv; void Fact_inv(int n, ll P){ if (fact_inv.size() < 1) fact_inv.pb(1); forn(i, fact_inv.size(), n+1) fact_inv.pb(fact_inv[i-1] * inv_mod(i, P) % P); } // Combinations ll nCr(int n, int r, ll P){ if (r > n) return 0; Fact(n, P); Fact_inv(n, P); return (fact[n] * fact_inv[r] % P) * fact_inv[n-r] % P; } ll nCr_inv(int n, int r, ll P){ if (r > n) return 0; Fact(n, P); Fact_inv(n, P); return (fact_inv[n] * fact[r] % P) * fact[n-r] % P; } // RNG mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // Mod const ll mod = 1000000007; void solve(){ int l, r; cin >> l >> r; vector<int> pf(r+1, 0); vector<bool> distinct(r+1, true); forn(i, 2, r+1){ if(!pf[i]){ for(int j = i, mul = 1; j <= r; j+=i, mul++) { pf[j]++; if (!(mul % i)) distinct[j] = false; } } } ll cnt= 0, cnt2=0; for(ll i = 2; i <= r; i++) if(distinct[i]) { if (pf[i]&1) cnt += (r/i - (l-1)/i) * (r/i - (l-1)/i - 1); else cnt -= (r/i - (l-1)/i) * (r/i - (l-1)/i - 1); } forn(i, max(l, 2), r+1) cnt2 += r/i-1; cout << cnt - cnt2*2; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout << setprecision(16) << fixed; solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; 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; } #define all(x) (x).begin(),(x).end() #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=998244353,MAX=200005,INF=1<<30; int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); int N,M;cin>>N>>M; vector<int> cnt(10000); for(int i=0;i<N;i++){ int a;cin>>a; cnt[a]++; } for(int i=0;i<M;i++){ int a;cin>>a; cnt[a]++; } for(int i=1;i<=1000;i++){ if(cnt[i]==1) cout<<i<<" "; } cout<<endl; }
#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";} //頑張る int main() { ll N,M; cin>>N>>M; vector<ll> p(1001); rep(i,N){ ll a; cin>>a; p[a]^=1; } rep(i,M){ ll a; cin>>a; p[a]^=1; } rep(i,1001){ if(p[i]==1) cout<<i<<" "; } cout<<endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(ll i=0;i<(ll)n;i++) #define dump(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << (x) << "\n"; #define spa << " " << #define fi first #define se second #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() using ld = long double; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; template<typename T> using V = vector<T>; template<typename T> using P = pair<T, T>; template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); } template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); } template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;} template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;} struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());} template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } void fail() { cout << -1 << '\n'; exit(0); } inline int popcount(const int x) { return __builtin_popcount(x); } inline int popcount(const ll x) { return __builtin_popcountll(x); } template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++) {cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}}; template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0]; for(ll i=1;i<n;i++)cerr spa v[i]; cerr<<"\n";}; const ll INF = (1ll<<62); // const ld EPS = 1e-10; // const ld PI = acos(-1.0); const ll mod = (int)1e9 + 7; //const ll mod = 998244353; int main(){ ll N; cin >> N; ll MA = 90; V<ll> fib(MA); fib[0] = 0; fib[1] = 1; REP(i, MA-2) fib[i+2] = fib[i+1] + fib[i]; ll x = N; V<ll> ids; REP(i, MA-1){ if(x >= fib[MA-1-i]){ ids.push_back(MA-1-i); x -= fib[MA-1-i]; } } ll sz = ids.size(); V<ll> X = ids, Y = ids; REP(i, sz) Y[i]--; V<ll> res; for(ll t=0;;t++){ REP(i, sz){ if(X[i] == 1){ X[i]--; if(t%2==0) res.push_back(1); else res.push_back(2); } } bool ok = true; REP(i, sz) if(X[i] != 0) ok = false; REP(i, sz) if(Y[i] != 0) ok = false; if(ok) break; REP(i, sz){ if(X[i] >= 2){ X[i] -= 2; } } if(t%2 == 0) res.push_back(3); else res.push_back(4); swap(X, Y); } reverse(ALL(res)); cout << res.size() << endl; for(auto x: res) cout << x << endl; return 0; }
#include <cstdio> #include <iostream> #include <cstring> #include <cstdlib> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <list> #include <climits> #include <bitset> #include <fstream> #include <algorithm> #include <functional> #include <stack> #include <string> #include <cmath> #include <numeric> #include <tuple> #include <cassert> #include <random> #include <chrono> #include <ext/rope> #include <unordered_map> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/priority_queue.hpp> #include <ext/pb_ds/assoc_container.hpp> #define rep(i,a,n) for (int i=a;i<=n;i++) #define per(i,a,n) for (int i=a;i>=n;i--) #define sz(x) (x).size() #define lbt(x) ((x)&(-x)) #define all(x) (x).begin(),(x).end() #define mem(a,b) memset(a,b,sizeof(a)) #define fun function #define fi first #define se second #define re register #define ls i << 1 #define rs i << 1 | 1 #define pb push_back #define mkp make_pair #define pii pair<int,int> #define pdi pair<double,int> #define pdd pair<double,double> #define mod 1000000007 #define int long long using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; typedef long long ll; typedef unsigned long long ull; typedef rope<char> RPstring; typedef __gnu_pbds::tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> RBtree; /*rk = t.order_of_key(v)+1, get_k = *t.find_by_order(k)*/ /*idx begin of 0*/ typedef __gnu_pbds::priority_queue<pii,greater<pii>,pairing_heap_tag> PQ_pii_s;//small typedef __gnu_pbds::priority_queue<pii,less<pii>,pairing_heap_tag> PQ_pii_b;//big // gp_hash_table<T,T> x const double eps = 1e-8; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const double pi = acos(-1.0); void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) int tt; inline int rd(){ int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } void out(int a) {if(a<0)putchar('-'),a=-a;if(a>=10)out(a/10);putchar(a%10+'0');} #define pnt(x) out(x),puts("") #define put(x) out(x), putchar(' ') #define putschar(x) putchar(x), puts("") //int t[maxn]; //void upd(int p, int x) {for(;p<=n;p+=lbt(p))t[p]+=x;} //int ask(int p) {int ret = 0;for(;p;p-=lbt(p))ret+=t[p];return ret;} int bit_cnt(int x) {int res=0;while(x)res+=x&1,x>>=1;return res;} int INT(string x, int sys) {int base=sys,res=0;for(auto i: x)res*=sys,res+=i-'0';return res;}//sys->10 string TNI(int x, int sys) {string res="";while(x)res+=x%sys+'0',x/=sys;reverse(all(res));return res;}//10->sys int gcd(int a, int b) {return b?gcd(b,a%b):a;} int lcm(int a, int b) {return a*b/gcd(a,b);} ll mul(ll a, ll b, int m) {ll ret = 0ll;while(b){if(b&1)ret+=a,ret%=m;a+=a,a%=m,b>>=1;}return ret;} ll mul(ll a, ll b) {ll ret = 0ll;while(b){if(b&1)ret+=a;a+=a,b>>=1;}return ret;} ll ksm(ll a, ll b, int m) {ll ret = 1ll;while(b){if (b&1) ret*=a,ret%=m;a*=a,a%=m,b>>=1;}return ret;} ll ksm(ll a, ll b) {ll ret = 1ll;while(b){if(b&1)ret*=a;a*=a,b>>=1;}return ret;} ll inv(ll x, int m) {return ksm(x,m-2,m);} void run() { string s; cin >> s; rotate(s.begin(), s.begin()+1, s.end()); cout << s; } signed main(){ // for (tt = rd(); tt--; ) run(); return 0; }
#include <bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(0);cin.tie(0) #define fp(i,a,b) for(int i=a ; i<b ; i++) #define fn(i,a,b) for(int i=a ; i>=b ; i--) #define fit(i,x) for(auto i=x.begin() ; i != x.end() ; i++) #define pb push_back #define ff first #define ss second #define all(x) x.begin(),x.end() typedef long long ll; typedef pair<int,int> ii; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<ll> vll; const int M=5e5+5; const int INF=1e9; const int MOD=1e9+7; ll s,p; int main(){ fastio; cin >> s >> p; bool b = false; for(ll i=1; i*i <= p; i++) if (p % i == 0) if (i + (p/i) == s) b = true; if (b) cout << "Yes\n"; else cout << "No\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll typedef pair<int,int> pi; typedef vector <ll> vi; typedef vector <pi> vpi; typedef pair<pi, pi> pipi; typedef set <ll> si; //~ typedef pair<int,pii> wtf; typedef long double ld; #define f first #define s second #define FOR(i,s,e) for(ll i=s;i<=ll(e);++i) #define DEC(i,s,e) for(ll i=s;i>=ll(e);--i) #define pb push_back #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) #define aFOR(i,x) for (auto i: x) #define mem(x,i) memset(x,i,sizeof x) #define fast ios_base::sync_with_stdio(false),cin.tie(0) #define maxn 2001 #define mp make_pair #define INF (ll)1e18 //~ #define getchar_unlocked _getchar_nolock int TC,N,a,b; int A,B,C; int ans[maxn]; void solve(){ cin >> A >> B; int co = 1; int co2 = 1; FOR(i,1,min(A,B) - 1){ ans[co] = co2; ans[co+1] = -co2; co2++; co += 2; } if (B > A){ B -= min(A,B) - 1; A = 1; int sm = 0; FOR(i,1,B){ sm += co2; ans[co] = -co2; co2++; co++; } ans[co] = sm;co++; }else{ A -= min(A,B) - 1; B = 1; int sm = 0; FOR(i,1,A){ sm += co2; ans[co] = co2; co2++; co++; } ans[co] = -sm;co++; } FOR(i,1,co-1) cout << ans[i] << ' '; } int32_t main(){ fast; //~ cin >> TC; TC = 1; while (TC--) solve(); }
#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 ///////////////////////////////////////////////////////// const double PI = M_PI; int main() { std::cout << std::setprecision(15); ////////////////////////////////////////// int n; cin >> n; double x0, y0, x2, y2; cin >> x0 >> y0 >> x2 >> y2; double xo = (x0 + x2) / 2; double yo = (y0 + y2) / 2; // print("o", xo,yo); double x02 = x0 - xo; double y02 = y0 - yo; double theta = (PI*(double)2) / (double)n; double x1 = x02 * cos(theta) - y02 * sin(theta); double y1 = x02 * sin(theta) + y02 * cos(theta); x1 += xo; y1 += yo; print(x1, y1); return 0; }
#include <bits/stdc++.h> #define SZ(x) (int)(x).size() #define ALL(x) (x).begin(),(x).end() #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second using namespace std; typedef double DB; typedef long double LD; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<PII> VPII; // head int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin>>n; vector<LL> a(n+1); LL t=0,tt=0; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=2;i<=n;i++) { t+=(a[i]-a[1])*(a[i]-a[1]); tt+=(a[i]-a[1]); } LL res=t; for(int i=3;i<=n;i++) { tt+=a[i-2]-a[i-1]; t=t-(a[i-1]-a[i-2])*(a[i-1]-a[i-2])+(a[i-2]-a[i-1])*(a[i-2]-a[i-1])*(n-i+1)+2*(a[i-2]-a[i-1])*tt; res+=t; tt+=(a[i-2]-a[i-1])*(n-i+1); } cout<<res<<'\n'; return 0; }
#include<bits/stdc++.h> using namespace std; #define Mod(x) (x>=P)&&(x-=P) #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i) #define erep(i,a) for(int i=hd[a];i;i=nxt[i]) typedef long long ll; void Max(int &x,int y){(x<y)&&(x=y);} void Min(int &x,int y){(x>y)&&(x=y);} bool vio; char IO; int rd(int res=0){ bool f=0; while(IO=getchar(),IO<48||IO>57) f=IO=='-'; do res=(res<<1)+(res<<3)+(IO^48); while(IO=getchar(),isdigit(IO)); return f?-res:res; } const int M=1e3+10; int C[M][M],A[M][M],B[M][M],n,K,S; int Sc(int i,int j){ return C[i][j]-C[i-K][j]-C[i][j-K]+C[i-K][j-K]; } bool check(int x){ rep(i,1,n)rep(j,1,n)C[i][j]=(A[i][j]<=x); rep(i,1,n)rep(j,1,n)C[i][j]+=C[i][j-1]; rep(i,1,n)rep(j,1,n)C[i][j]+=C[i-1][j]; rep(i,K,n)rep(j,K,n) if(Sc(i,j)>=S)return 1; return 0; } bool let; int main(){ cerr<<(&vio-&let)/1024.0/1024<<endl; n=rd(),K=rd(),S=K*K/2+1; S=K*K+1-S; rep(i,1,n)rep(j,1,n)A[i][j]=rd(); int L=0,R=1e9,res=0; while(L<=R){ int mid=(L+R)>>1; if(check(mid)){ res=mid,R=mid-1; }else L=mid+1; } printf("%d",res); }
#include <bits/stdc++.h> #define FIXED_FLOAT(x) std::fixed <<std::setprecision(20) << (x) #define all(v) (v).begin(), (v).end() using namespace std; #define forn(i,n) for (int i = 0; i < (n); ++i) #define rforn(i, n) for(int i = (n) - 1;i >= 0;--i) using ll = long long; int mod = (ll)1e9 + 7; #define PI acos(-1) typedef pair<int, int> pairs; const int INF = 1e9 + 1; const int N = 2e5 + 100; const double eps = 1e-7; template <class T> using V = vector<T>; // from yosupo template <class T> using VV = V<V<T>>; // from yosupo template <typename XPAX> void ckma(XPAX &x, XPAX y) { x = (x < y ? y : x); } template <typename XPAX> void ckmi(XPAX &x, XPAX y) { x = (x > y ? y : x); } 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...);} #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) void solve() { int n; cin >> n; int k; cin >> k; VV<int> c(n, V<int>(n)); struct node { int i, j, x; bool operator<(node p) { return x < p.x; }; }; V<node> val; forn(i, n) forn(j, n) { cin >> c[i][j]; node p; p.x = c[i][j]; p.i = i; p.j = j; val.push_back(p); } sort(all(val)); int G = k * k; auto issok = [&](int now) { VV<int> pref(n + 1, V<int>(n + 1)); for(auto c : val) { if(c.x <= now) { pref[c.i + 1][c.j + 1]++; } else break; } for(int i = 1;i <= n;++i) { for(int j = 1;j <= n;++j) { pref[i][j] += pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1]; } } /* for(int i = 1;i <= n;++i) { for(int j = 1; j <= n;++j) { cout << pref[i][j] << ' '; } cout << '\n'; } */ //debug(pref[n][n]); int pk = 0; for(int i = 1;i <= n;++i) { for(int j = 1;j <= n;++j) { int x = i + k - 1; int y = j + k - 1; if(x > n || y > n)continue; int sum = pref[x][y] - pref[x][j - 1] - pref[i - 1][y] + pref[i - 1][j - 1]; //debug(i, j, x, y, sum); //debug(pref[x][j - 1], pref[i][y - 1]); ckma(pk, sum); //debug(sum); } } return (pk >= (G + 1) / 2); }; int low = 0; int high = 1e9; while(low < high) { int mid = (low + high) / 2; if(issok(mid)) { high = mid; } else low = mid + 1; } cout << low << '\n'; } void test_case() { int t; cin >> t; forn(p, t) { //cout << "Case #" << p + 1 << ": "; solve(); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); solve(); }
#include<bits/stdc++.h> using namespace std; #define ll long long const int maxn = 4e5 + 5; int n; int a[maxn]; int main() { scanf("%d",&n); for(int i=1;i<=2*n;i++) scanf("%d",&a[i]); priority_queue<int> heap; ll sum = 0, aoki = 0; for(int i=1;i<=n;i++) { heap.push(-a[n-i+1]); heap.push(-a[n+i]); sum += a[n-i+1] + a[n+i]; aoki += -heap.top(); heap.pop(); } printf("%lld",sum - aoki); }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++) #define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++) #define setp(n) fixed << setprecision(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 (a>b) { a=b; return 1; } return 0; } #define ll long long #define vll vector<ll> #define vi vector<int> #define pll pair<ll,ll> #define pi pair<int,int> #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define fi first #define se second #define pb push_back #define ins insert #define debug(a) cerr<<(a)<<endl #define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl #define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;} using namespace std; template<class A, class B> ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";} template<class A, class B> istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;} /* Some Libraries */ //------------------------------------------------- int main(void) { cin.tie(0); ios::sync_with_stdio(false); int N; cin>>N; vll v1(N),v2(N); rep(i,2*N){ ll v; cin>>v; if (i<N) v1[i]=v; else v2[i-N]=v; } reverse(all(v1)); ll ans=0; multiset<ll> ms; rep(i,N){ ll mx = max(v1[i],v2[i]); ll mn = min(v1[i],v2[i]); ans+=mx; ms.ins(mx); if (!ms.empty() && *ms.begin()<mn){ auto itr = ms.begin(); ans+=mn-*itr; ms.ins(mn); ms.erase(itr); } } cout<<ans<<"\n"; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; int main() { int N, M, A, B; cin >> N >> M; vector<vector<int>> d(N, vector<int>(N, 1e9)), edge(N); rep(i, N) d[i][i] = 0; rep(i, M) { cin >> A >> B; d[A - 1][B - 1] = 1; edge[A - 1].push_back(B - 1); } int ans = 0; rep(k, N) { vector<bool> done(N, false); queue<int> q; q.push(k); done[k] = true; ans++; while (!q.empty()) { int p = q.front(); q.pop(); rep(i, edge[p].size()) { int u = edge[p][i]; if (done[u]) continue; q.push(u); done[u] = true; ans++; } } } cout << ans << endl; }
#include<iostream> #include<vector> #include<bits/stdc++.h> #define mod 1000000007 #define pi 3.14159265358979 #define PRE(x,p) cout<<setprecision(x)<<p; #define pb push_back #define mp make_pair #define f first #define s second #define endl "\n" #define high INT_MAX #define low INT_MIN #define ll long long int using namespace std; void showa(ll a[],ll n){ for(ll i=1;i<=n;i++) cout<<a[i]<<' '; cout<<endl; } void showv(vector<ll>v){ for(ll i=0;i<v.size();i++) cout<<v[i]<<' '; cout<<endl;} ll modd; ll power(ll x, ll y) { ll res = 1; x = x % modd; while (y > 0) { if (y & 1) res = (res * x) % modd; y = y >> 1; x = (x * x) % modd; } return res; } void solve() { ll n,m; cin>>n>>m; modd=m*m; cout<<(power(10,n)/m) %m; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t=1; // cin>>t; for(ll test=1;test<=t;test++) { // cout<<"CASE #"<<test<<": "; solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define PI 3.14159265359 using ll = long long; #define MAX 100000 int main(){ string s; cin >> s; int ans = 0; rep(num, 10000){ vector<int> a(10); int x = num; rep(i,4){ int d = x%10; a[d] = 1; x /= 10; } bool ok = true; rep(i,10){ if(s[i] == 'o' && a[i] != 1) ok = false; if(s[i] == 'x' && a[i] != 0) ok = false; } if(ok) ans++; } cout << ans << endl; return 0; }
#pragma GCC optimize("Ofast") // #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #define F first #define S second #define vec vector #define pb push_back #define cld complex<ld> #define pll pair<ll, ll> #define pdd pair<ld, ld> #define umap unordered_map #define uset unordered_set #define pii pair<int, int> #define pnn pair<Node*, Node*> #define all(m) m.begin(), m.end() #define uid uniform_int_distribution #define init(m, x) memset(m, x, sizeof(m)); #define pripii(p) cout << "{" << p.F << ", " << p.S << "} " #define fast cin.tie(0); cout.tie(0); cin.sync_with_stdio(0); cout.sync_with_stdio(0); using namespace std; typedef string str; typedef long long ll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int main() { fast; str t; cin >> t; int o = 0; set<int> mu, nmu; for (int q = 0; q < 10; q++) { if (t[q] == 'o') mu.insert(q); if (t[q] == 'x') nmu.insert(q); } for (int q = 0; q < 10; q++) { for (int w = 0; w < 10; w++) { for (int e = 0; e < 10; e++) { for (int r = 0; r < 10; r++) { set<int> tyt = {q, w, e, r}; int fl = 1; for (int i : mu) fl &= tyt.count(i); for (int i : nmu) fl &= !tyt.count(i); o += fl; } } } } cout << o; }
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <unordered_map> #include <queue> #include <vector> #include <algorithm> #include <cmath> using namespace std; typedef unsigned long long ull; long long MX = 1e18; int n; int a[110]; ull x; ull calc2(long long sum, int k) { sum = x - sum; if (sum % k) return MX; return sum / k; } long long f[110][110][110]; ull calc(int k) { for (int i = 0; i <= n; ++i) for (int h = 0; h <= k; ++h) for (int j = 0; j < k; ++j) f[i][h][j] = -MX; f[0][1][a[0] % k] = a[0]; for (int i = 1; i < n; ++i) { for (int h = 2; h <= i+1 && h <= k; ++h) for (int j = 0; j < k; ++j) { f[i][h][j] = max(f[i-1][h][j], f[i-1][h-1][((j-a[i])%k+k)%k] + a[i]); } f[i][1][a[i]%k] = a[i]; for (int j = 0; j < k; ++j) { f[i][1][j] = max(f[i][1][j], f[i-1][1][j]); } } ull ans = MX; for (int j = 0; j < k; ++j) { if (f[n-1][k][j] <= 0) continue; ans = min(ans, calc2(f[n-1][k][j], k)); } return ans; } int main() { cin >> n >> x; for (int i = 0; i < n; ++i) cin >> a[i]; ull ans = MX; for (int k = 1; k <= n; ++k) { ull c = calc(k); if (c < ans) ans = c; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define V vector #define debug(v) {for(auto i: v) cout << i << " "; cout << endl;} #define vcin(v) rep(i, v.size()) cin >> v[i] #define wcin(v, w) rep(i, v.size()) cin >>v[i] >>w[i] int main(){ ll n,k; cin >>n >>k; ll a,b; V<pair<ll,ll>> ab(n); rep(i,n){ cin >>a >>b; ab[i]={a,b}; } sort(all(ab)); ll kane=k,now=0; rep(i,n){ if(kane>=ab[i].first-now){ kane=kane-ab[i].first+now+ab[i].second; now=ab[i].first; } else break; } cout <<now+kane; }
#include <bits/stdc++.h> using namespace std; //@formatter:off //@formatter:on int main() { int N, K; cin >> N >> K; int64_t res = 0; for (int A = 2; A <= 2 * N; A++) { int B = A - K; if (!(2 <= B and B <= 2 * N)) continue; int64_t pa = 0, pb = 0; if (A <= N )pa += A - 1; else pa += 2 * N - A + 1; if (B <= N ) pb += B - 1; else pb += 2 * N - B + 1; res += pa * pb; } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for(ll i = (a); i < (b); ++i) #define REP(i, n) for(ll i = 0; i < (n); ++i) #define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array) template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } const int INF = 1000100100; int main() { ll A, B; cin >> A >> B; ll X, Y; X = (A + B)/2; Y = A - X; cout << X << " " << Y << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ string a, b, c; cin >> a >> b >> c; map<char, int> m; string s = a + b + c; int ss = s.size(); int kind = 0; vector<char> ch; for(int i = 0;i < ss;i++){ m[s[i]]++; if(m[s[i]] == 1){ kind++; ch.push_back(s[i]); } } if(kind > 10){ cout << "UNSOLVABLE" << endl; return 0; } vector<int> per(10); int as = a.size(); int bs = b.size(); int cs = c.size(); for(int i = 0;i < 10;i++) per[i] = i; int ap = pow(10, as - 1); int bp = pow(10, bs - 1); int cp = pow(10, cs - 1); int64_t po[10]; for(int i = 0;i < 10;i++) po[i] = pow(10, i); for(int j = 0;j < 3628800;j++){ next_permutation(per.begin(), per.end()); for(int i = 0;i < kind;i++){ m[ch[i]] = per[i]; } int64_t h = 0; int64_t l = 0; int64_t ans = 0; for(int i = 0;i < as;i++) h += (m[s[as - 1 - i]] * po[i]); for(int i = 0;i < bs;i++) l += (m[s[as + bs - 1 - i]] * po[i]); for(int i = 0;i < cs;i++) ans += (m[s[ss - i - 1]] * po[i]); if(h < ap || l < bp || ans < cp) continue; if(h + l == ans){ cout << h << endl; cout << l << endl; cout << ans << endl; return 0; } } cout << "UNSOLVABLE" << endl; }
#include <bits/stdc++.h> using namespace std; #define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define int long long #define pb push_back #define ll long long #define rep(i, n) for (ll i = 0; i < n; i++) #define rep1(i, n) for (ll i = n - 2; i >= 0; i--) #define repi(i, n) for (ll i = 1; i <= n; i++) #define repi1(i, n) for (ll i = n; i >= 1; i--) #define mem(arr, x) memset(arr, x, sizeof(arr)) #define CLOCK cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; typedef vector<ll> vi; typedef vector<char> vc; #define mp make_pair #define ss second #define mod 1000000007 const int MAX = 1000000000; const int inf = 1e18; const long double PI = 3.141592653589793238460; void solve() { int n,k; cin>>n>>k; vector<pair<int,int>>v; rep(i,n) { int p,q; cin>>p>>q; v.pb(mp(p,q)); } sort(v.begin(),v.end()); int pai=k; if(v[0].first>k) { cout<<k<<'\n'; return ; } k-=v[0].first; int res=v[0].first; if(n==1) { cout<<res+v[0].second<<'\n'; return; } //cout<<k; map<int,int>m; for(int i=1;i<n;i++) { k+=v[i-1].second; if(k<(v[i].first-v[i-1].first)) { res=v[i-1].first+k; k=0; break; } else { k-=(v[i].first-v[i-1].first); res=v[i].first; m[v[i].first]++; // k+=v[i].second; } } if(m[v[n-1].first]) k+=v[n-1].second; if(k) { res+=k; } cout<<res<<'\n'; } int32_t main() { fast_io; int T=1; //cin>>T; while(T--) { solve(); } }
#include <iostream> #include <vector> #include <algorithm> #include <cassert> #include <array> using namespace std; constexpr int MOD = 1e9+7; int modular_add(int a, int b){ assert( a >= 0 && a < MOD && b >=0 && b < MOD); int ans = a + b; if(ans >= MOD){ ans = ans % MOD; } return ans; } void solve(){ int h, w; cin >> h >> w; vector<string> grid(h); for(int i = 0 ; i < h ; i++){ cin >> grid[i]; assert(w == (int) grid[i].size()); } //dp[i][j][0] : number of way to move from (i,j) to goal with first move right //dp[i][j][1], dp[i][j][2] : same, but first move down, diagonal //dp[i][j][3] : total vector<vector<array<int,4>>> dp(h, vector<array<int,4>>(w)); for(int i = h - 1; i >= 0 ; i--){ for(int j = w - 1; j >= 0 ; j--){ //if it's a block, we cannot move if(grid[i][j] == '#') continue; //special case goal: we don't have to move in anydirection if(i == h - 1 && j == w -1){ dp[i][j] = {0, 0, 0, 1}; continue; } //try moving right if(j + 1 < w ){ //we can either move to (i, j+ 1) frist or pass through it in the right direction dp[i][j][0] = modular_add(dp[i][j+1][3], dp[i][j+1][0]); } //try moving down if( i + 1 < h){ //we can either move to (i+ 1, j) frist or pass through it in the downward direction dp[i][j][1] = modular_add(dp[i+1][j][3], dp[i+1][j][1]); } //try moving diagonal if( i + 1 < h && j + 1 < w){ //we can either move to (i+ 1, j + 1) frist or pass through it in the diagonal direction dp[i][j][2] = modular_add(dp[i+1][j+1][3], dp[i+1][j+1][2]); } //finally, we count the total way dp[i][j][3] = modular_add(dp[i][j][0], modular_add(dp[i][j][1], dp[i][j][2])); } } cout << dp[0][0][3] << endl; } int main(){ /*unsync iostream with stdio to improve I/O speed*/ std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); /************************************************/ solve(); }
#include <iostream> #include <cstring> #include <climits> #include <cstdio> #include <vector> #include <cstdlib> #include <ctime> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #include<algorithm> #define inf 0x3f3f3f3f using namespace std; typedef unsigned long long ull; typedef long long ll; typedef double dd; const int N = 1e5+5; const dd eps = 1e-8; const int mod = 1e9+7; char table[2010][2010]; ll h,w,dp[2010][2010],x[2010][2010],y[2010][2010],z[2010][2010]; int main(){ // freopen("input.txt","r",stdin); cin>>h>>w; for(int i = 1;i <= h;i++){ for(int j = 1;j <= w;j++) cin>>table[i][j]; } dp[1][1] = 1; for(int i = 1;i <= h;i++){ for(int j = 1;j <= w;j++){ if(i == 1 and j == 1) continue; if(table[i][j] == '#') continue; x[i][j] = (x[i-1][j] + dp[i-1][j])%mod; y[i][j] = (y[i][j-1] + dp[i][j-1])%mod; z[i][j] = (z[i-1][j-1] + dp[i-1][j-1])%mod; dp[i][j] = (x[i][j] + y[i][j] + z[i][j])%mod; } } cout<<dp[h][w]<<endl; return 0; }
#include <bits/stdc++.h> // 1. dp typedef long double ld; #define int long long #define gcd __gcd #define endl "\n" #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define mod2 998244353 #define maxe *max_element #define mine *min_element #define inf 1e18 #define pb push_back #define all(x) x.begin(), x.end() #define f first #define s second #define lb lower_bound #define ub upper_bound #define ins insert #define sz(x) (int)(x).size() #define mk make_pair #define deci(x, y) fixed<<setprecision(y)<<x #define w(t) int t; cin>>t; while(t--) #define nitin ios_base::sync_with_stdio(false); cin.tie(nullptr) #define PI 3.141592653589793238 using namespace std; int dp[4000][4000]; int solve(int n,int k){ if(k>n) return 0; if(n==0) return 1; if(k==0) return 0; if(dp[n][k]!=0) return dp[n][k]; return dp[n][k]=(solve(n-1,k-1)+solve(n,2*k))%mod2; } void solve() { int n,k; cin>>n>>k; cout<<solve(n,k)<<endl; } int32_t main() { nitin; solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const double pi = acos(-1); const double eps = 1e-8; const ll mod = 1e9 + 7; const ull base = 131; const ull mod1 = 1e9 + 9; const ull mod2 = 1610612741; const int maxn = 3e3 + 10; ll dp[maxn][maxn]; int n, k; const ll m = 998244353; int main() { scanf("%d%d", &n, &k); fill(dp[0], dp[0]+maxn, 1); for (int i = 1; i <= n; ++i) for (int j = i; j >= 1; --j) { dp[i][j] = dp[i - 1][j - 1] % m; if (2*j <= i) dp[i][j] = (dp[i][j] + dp[i][j*2])%m; } printf("%lld\n", dp[n][k]); return 0; }
#include <iostream> #include <sstream> #include <algorithm> #include <cmath> #include <functional> #include <vector> #include <map> #include <queue> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<int, int>; int main() { int n; cin >> n; vector<int> a(n), b(n); vector<ll> dec; ll at = 0; rep(i, n) { cin >> a[i] >> b[i]; at += a[i]; dec.push_back(2 * a[i] + b[i]); } sort(dec.rbegin(), dec.rend()); int ans = 0; while (at >= 0) { at -= dec[ans]; ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <string> using namespace std; #define ll long long #define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i)) const int N =100; bool isprime(int n) { if (n <= 1) return false; for (int i = 2; i*i<=n; i++) if (n % i == 0) return false; return true; } ll binarySearch(ll arr[], ll l, int r, ll x,ll n) { sort(arr,arr+n); if (r >= l) { ll mid = l + (r - l) / 2; if (arr[mid] == x) return mid; if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x,n); return binarySearch(arr, mid + 1, r, x,n); } return -1; } long long lcm(long long a,long long b) { long long p,r; p = a*b; r = __gcd(a, b); return p/r; } 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; } bool isPerfectSquare(long double x) { long double sr = sqrt(x); return ((sr - floor(sr)) == 0); } ll f(ll n) { return n * (n - 1) / 2; } bool powerof2(ll n) { return n!=0 && ((n&(n-1))==0); } double fact(double n) {cout<<setprecision(9); if(n==0 ||n==1) return 1; else return n*fact(n-1); } void solve() { int n; cin>>n; int a[n][2]; for(int i=0;i<n;i++) { cin>>a[i][0]>>a[i][1]; } int ans=0; for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { int p = abs(a[j][1]-a[i][1]); int q = abs(a[j][0]-a[i][0]); if(p<=q) ans++; } } cout<<ans<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; t=1; //cin>>t; while(t--) { solve(); } }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define absdiff(a,b) (a>b)?a-b:b-a #define mp make_pair #define pb push_back #define ff first #define ss second #define fast ios_base::sync_with_stdio(false);cin.tie(0); const ll MOD = 1000000007; const ll ll_MAX = 1e15; ll fast_expo(ll x,ll p){ if(p==0) return 1; else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;} ll invMod(ll num){ return fast_expo(num, MOD - 2)%MOD; } const ll N = 3e3 + 5; ll dp[N][N], pre[N], sum[N][N]; int main(){ fast #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll t_c; t_c = 1; // cin >> t_c; for(ll t_i = 0; t_i < t_c; ++t_i){ ll n; cin >> n; ll arr[n + 1]{}; for(ll i = 1; i <= n; ++i){ cin >> arr[i]; pre[i] = pre[i - 1] + arr[i]; } dp[0][0] = 1; sum[0][0] = 1; for(ll i = 1; i <= n; ++i){ for(ll j = n; j > 0; --j){ dp[i][j] = sum[j - 1][pre[i]%j]; sum[j][pre[i]%(j + 1)] = (sum[j][pre[i]%(j + 1)] + dp[i][j])%MOD; } } ll ans = 0; for(ll i = 1; i <= n; ++i){ ans = (ans + dp[n][i])%MOD; } cout << ans << endl; } return 0; }
#include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <deque> #include <complex> #include <stack> #include <queue> #include <cstdio> #include <cctype> #include <cstring> #include <ctime> #include <iterator> #include <bitset> #include <numeric> #include <list> #include <iomanip> #include <cassert> #if __cplusplus >= 201103L #include <array> #include <tuple> #include <initializer_list> #include <unordered_set> #include <unordered_map> #include <forward_list> using namespace std; #define cauto const auto& #define ALL(v) begin(v),end(v) #else #define ALL(v) (v).begin(),(v).end() #endif namespace{ typedef long long LL; typedef pair<int,int> pii; typedef pair<LL,LL> pll; typedef vector<int> vint; typedef vector<vector<int> > vvint; typedef vector<long long> vll, vLL; typedef vector<vector<long long> > vvll, vvLL; #define VV(T) vector<vector< T > > template <class T> void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){ v.assign(a, vector<T>(b, t)); } template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); } template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); } template <class F, class T> void convert(const F &f, T &t){ stringstream ss; ss << f; ss >> t; } template <class Con> string concat(const Con &c, const string &spr){ stringstream ss; typename Con::const_iterator it = c.begin(), en = c.end(); bool fst = true; for(; it != en; ++it){ if(!fst){ ss << spr; } fst = false; ss << *it; } return ss.str(); } template <class Con, class Fun> vector<typename Con::value_type> cfilter(const Con &c, Fun f) { vector<typename Con::value_type> ret; typename Con::const_iterator it = c.begin(), en = c.end(); for(; it != en; ++it){ if(f(*it)){ ret.emplace_back(*it); } } return ret; } #if __cplusplus >= 201103L template <class Con, class Fun> auto cmap(const Con &c, Fun f) -> vector<decltype(f(*c.begin()))> { vector<decltype(f(*c.begin()))> ret; ret.reserve(c.size()); for(const auto &x: c){ ret.emplace_back(f(x)); } return ret; } #endif #if __cplusplus >= 201402L #define lambda(e) ([&](const auto &_){ return (e); }) #define lambda2(e) ([&](const auto &_a, const auto &_b){ return (e); }) #endif #define REP(i,n) for(int i=0;i<int(n);++i) #define RALL(v) (v).rbegin(),(v).rend() #define tget(t,i) get<i>(t) #define MOD 1000000007LL #define EPS 1e-8 LL extgcd(LL a, LL b, LL &x, LL &y){ LL d = a; if(b){ d = extgcd(b, a % b, y, x); y -= a / b * x; } else{ x = 1; y = 0; } return d; } LL modinv(LL a, LL m = MOD){ LL x, y; extgcd(a, m, x, y); return (m + x % m) % m; } LL gcd(LL x, LL y){ while(y){ LL r = x % y; x = y; y = r; } return x; } // a * x = b (mod m) pair<LL,LL> linear_congruence( const vector<LL> &va, const vector<LL> &vb, const vector<LL> &vm ){ LL x = 0, m = 1; for(size_t i = 0; i < va.size(); ++i){ LL a = va[i] * m; LL b = vb[i] - va[i] * x; LL d = gcd(vm[i], a); if(b % d != 0){ return make_pair(0, -1); // NA } LL t = b / d * modinv(a / d, vm[i] / d) % (vm[i] / d); x = x + m * t; m *= vm[i] / d; } x = (x % m + m) % m; return make_pair(x, m); } LL solve(){ LL x, y, p, q; cin >> x >> y >> p >> q; LL ans = LLONG_MAX; vector<LL> va, vb, vm; for(LL i = 0; i < y; ++i) for(LL j = 0; j < q; ++j){ va = {1, 1}; vb = {x + i, p + j}; vm = {2 * (x + y), p + q}; auto r = linear_congruence(va, vb, vm); if(r.second != -1){ chmin(ans, r.first); } } return ans; } void mainmain(){ int t; for(cin >> t; t--; ){ LL ans = solve(); if(ans == LLONG_MAX){ cout << "infinity\n"; } else{ cout << ans << '\n'; } } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(4); mainmain(); }
#include <bits/stdc++.h> #define rep(a,n) for (ll a = 0; a < (n); ++a) using namespace std; //using namespace atcoder; using ll = long long; typedef pair<ll,ll> P; typedef pair<ll,P> PP; typedef vector<vector<int> > Graph; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; } const ll INF = 1e18; #define SZ(x) ((int)(x).size()) #define debug(v) cout<<#v<<": ",prt(v); template <typename A,typename B> inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";} template <typename A,typename B,typename C> inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";} inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';} template <typename T> inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';} template<typename T> inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } } template <typename T> inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';} template <typename A,typename B> inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';} template <typename A,typename B> inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';} template <typename T> inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';} template <typename T> inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';} /* aはsortしておく 最後に残る可能性がある整数 a1~anのうちいずれかの約数(この時点で1つ以上のaの要素の公約数になることは確定する) a1以下 上の条件を満たす整数を全列挙 kが最後に残るためにはaから取り出したいくつかの要素の最大公約数になることがあれば良い これはaの要素のうちkの倍数のものをみていき、kで割った商の集合の最大公約数が1になれば良い 計算量 約数全列挙:O(N*(maxA)^1/2) 約数の個数の最大:2e6くらい?でも直感的にはもっと少なそう<-ダメだった */ /* divisor(n) 入力:整数 n 出力:nのすべての約数 計算量:O(√n) */ set<ll>st; vector<ll>a; map<ll,ll>mp; void divisor(ll n){ vector<ll>ret; for(ll i=1;i*i<=n;i++){ if(n%i==0){ ret.push_back(i); if(i*i!=n)ret.push_back(n/i); } } for(auto x:ret){ if(x>a[0])continue; mp[x]=__gcd(mp[x],n); //st.insert(x); } return; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); ll n; cin >> n; a.resize(n); rep(i,n)cin>>a[i]; sort(a.begin(),a.end()); rep(i,n){ divisor(a[i]); //debug(mp); } ll ans = 0; /* for(auto x:st){ ll g = 0;//大丈夫かな? rep(i,n){ if(a[i]%x==0){ g = __gcd(a[i]/x,g); } } if(g==1)ans++; } */ for(auto p:mp){ if(p.second==p.first)ans++; } cout << ans << endl; return 0; }
/** ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀ ⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀ ⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀ ⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀ ⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀ ⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀ ⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀ * author: Daredevil666 * institution: IIT Patna **/ #define _USE_MATH_DEFINES #include <bits/stdc++.h> #define nl cout<<"\n"; #define ll long long int #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=1e16; const ll MAXN=100200; ll i,j,mask; void solve() { ll n; cin>>n; ll minn=M; map<ll,ll> mp; F(i,0,n) { ll x; cin>>x; minn=min(minn,x); for(j=1;j*j<=x;j++) { if(x%j==0) { mp[j]=__gcd(mp[j],x); ll k=x/j; mp[k]=__gcd(mp[k],x); } } } set<ll> st; for(auto x:mp) { if(x.second<=minn) { st.insert(x.second); } } cout<<st.size(); } int main() { IOS /*#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #*/ /*ll t,test; cin>>test; F(t,1,test+1) { //cout<<"Case #"<<t<<": "; solve(); nl }*/ solve(); return 0; }
//多分分かったけど、みんな速くない? #include <iostream> #include <string> #include <algorithm> #include <functional> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <tuple> #include <cstdio> #include <cmath> #define rep(i, n) for(i = 0; i < n; i++) #define int long long using namespace std; typedef vector<int> Array; typedef vector<Array> Mat; const int mod = 1000000007; Array mul(Mat mat, Array vec) { int n = mat.size(); int m = mat[0].size(); Array ret(m, 0); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ret[i] += mat[i][j] * vec[j]; ret[i] %= mod; } } return ret; } Mat identify(int n) { Mat mat(n, Array(n, 0)); int i; rep(i, n) mat[i][i] = 1; return mat; } Mat mul(Mat a, Mat b) { int n = a.size(); int m = b[0].size(); Mat mat(n, Array(m, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { for (int k = 0; k < a[0].size(); k++) { mat[i][j] += a[i][k] * b[k][j]; mat[i][j] %= mod; } } } return mat; } Mat powmod(Mat a, int n) { if (n == 0) return identify(a.size()); if (n % 2 == 0) return powmod(mul(a, a), n / 2); return mul(a, powmod(a, n - 1)); } int powmod(int a, int n, int mod) { if (n == 0) return 1; if (n % 2 == 0) return powmod((a * a) % mod, n / 2, mod); return a * powmod(a, n - 1, mod) % mod; } int n, m, K; int a[100]; bool exist[100][100]; signed main() { int i, j, k; cin >> n >> m >> K; rep(i, n) cin >> a[i]; rep(i, m) { int x, y; cin >> x >> y; x--; y--; exist[x][y] = exist[y][x] = true; } Mat mat(n, Array(n, 0)); vector<vector<double>> mat_debug(n, vector<double>(n, 0)); rep(i, n) { mat[i][i] = 1; mat_debug[i][i] = 1.0; } rep(i, n) { rep(j, n) { if (exist[i][j]) { mat[j][i] = (mat[j][i] + mod + powmod(2 * m, mod - 2, mod)) % mod; mat[i][i] = (mat[i][i] + mod - powmod(2 * m, mod - 2, mod)) % mod; //mat_debug[j][i] += 1.0 / (2 * m); //mat_debug[i][i] -= 1.0 / (2 * m); } } } /*cout << "mat" << endl; rep(i, n) { rep(j, n) { cout << mat_debug[i][j] << " "; } cout << endl; }*/ Array vec(n); rep(i, n) vec[i] = a[i]; //(mat ** k) * vecを求めたい Mat res = powmod(mat, K); Array ans = mul(res, vec); /*cout << "res" << endl; rep(i, n) { rep(j, n) { cout << res[i][j] << " "; } cout << endl; }*/ //cout << "ans" << endl; rep(i, ans.size()) { cout << ans[i] << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (ll i = 0; i < (ll)(n); i++) #define repr(i,a,b) for (ll i = (a); i < (ll)(b); i++) #define rng(x) (x).begin(), (x).end() #define rrng(x) (x).rbegin(), (x).rend() #define popcnt(x) __builtin_popcountll(x) #define pb push_back #define eb emplace_back #define MP make_pair #define MT make_tuple #define fr first #define sc second using namespace std; template <class T, class U> inline bool chmax(T &a, const U &b) { return (a < b ? a = b, 1 : 0); } template <class T, class U> inline bool chmin(T &a, const U &b) { return (a > b ? a = b, 1 : 0); } template <class T> using vc = vector<T>; template <class T> using vv = vc<vc<T>>; template <class T> using vvv = vc<vv<T>>; template <class T> using PQ = priority_queue<T, vc<T>, greater<T>>; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; using ti3 = tuple<int, int, int>; using tl3 = tuple<ll, ll, ll>; using vi = vc<int>; using vl = vc<ll>; using vs = vc<string>; using vpl = vc<pll>; using vpd = vc<pdd>; using vvi = vv<int>; using vvl = vv<ll>; using vvpl = vv<pll>; const ld pi = 3.141592653589793; const ll linf = 1001001001001001001LL; const int inf = 1001001001; constexpr int MOD = 1e9+7; // constexpr int MOD = 998244353; struct mint { long long x; mint(long long x = 0) noexcept : x((x%MOD + MOD) % MOD) {} // basis mint operator-() const { return mint(-x); } mint& operator+=(const mint a) noexcept { if((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint a) noexcept { if((x += MOD-a.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint a) noexcept { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const noexcept { return mint(*this) += a; } mint operator-(const mint a) const noexcept { return mint(*this) -= a; } mint operator*(const mint a) const noexcept { return mint(*this) *= a; } mint mpow(long long t) const noexcept { if(!t) return 1; mint a = mpow(t>>1); a *= a; if(t&1) a *= *this; return a; } // for prime MOD mint inv() const noexcept { return mpow(MOD-2); } mint& operator/=(const mint a) noexcept { return *this *= a.inv(); } mint operator/(const mint a) const noexcept { return mint(*this) /= a; } // comparison bool operator==(const mint &a) const noexcept { return this->x == a.x; } bool operator!=(const mint &a) const noexcept { return this->x != a.x; } // I/O stream friend istream& operator>>(istream& is, mint& a) noexcept { return is >> a.x; } friend ostream& operator<<(ostream& os, const mint& a) noexcept { return os << a.x; } }; // additional mint mpow(const long long &a, long long n) noexcept { return mint(a).mpow(n); } mint mpow(const mint &a, long long n) noexcept { return a.mpow(n); } int main() { ll h, w; cin >> h >> w; vs S(h); rep(i,h) cin >> S[i]; vvl R(h, vl(w, 0)), C(h, vl(w, 0)); rep(i,h) { ll l = 0, r = 0; while (l < w) { while (r < w && S[i][r] == '.') r++; repr(j,l,r) R[i][j] = r-l; if (l == r) r++; l = r; } } rep(i,w) { ll l = 0, r = 0; while (l < h) { while (r < h && S[r][i] == '.') r++; repr(j,l,r) C[j][i] = r-l; if (l == r) r++; l = r; } } ll K = 0; rep(i,h)rep(j,w) K += S[i][j] == '.'; vc<mint> pow2(5000); rep(i,5000) pow2[i] = mpow(2, i); mint ans = 0; rep(i,h)rep(j,w) { if (S[i][j] == '#') continue; ans += (pow2[R[i][j]+C[i][j]-1]-1)/pow2[R[i][j]+C[i][j]-1]; } ans *= mpow(2, K); cout << ans << endl; }
#include<bits/stdc++.h> #define all(x) (x).begin(),(x).end() #define ll long long #define rep(i,n) for(int i = 0; i < int(n); i++) #define vi vector<int> using namespace std; const int INF = 1001001001; const int MOD = 1e9+7; template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; } template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; } string solve(){ cin.tie(0), ios::sync_with_stdio(false); int n,s,d; cin >> n >> s >> d; vi x(n),y(n); rep(i,n) cin >> x[i] >> y[i]; rep(i,n){ if(x[i] < s && d < y[i]) return "Yes"; } return "No"; } int main(){ cout << solve() << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int n,s,d,a,b; int main() { cin>>n>>s>>d; for(int i=1;i<=n;++i) { cin>>a>>b; if(a<s&&b>d) { cout<<"Yes"; return 0; } } cout<<"No"; return 0; }
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define X first #define Y second using namespace std; typedef long long int ll; typedef vector <int> vi; typedef pair <int,int> pii; const int Size=2e6+10; const int INF=0x3f3f3f3f; inline int read() { int x=0, f=1; char ch=getchar(); while(ch<'0' || ch>'9') {if(ch=='-') f=-1; ch=getchar();} while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();} return x*f; } vi f[Size]; int main() { int n=read(),m=read(),a; for (int i=0;i<=n;++i) f[i].pb(0); for (int i=1;i<=n;++i) {a=read(); f[a].pb(i);} for (int i=0;i<=n;++i) f[i].pb(n+1); int res; for (int i=0;i<=n;++i) { int siz=f[i].size(); bool flag=false; for (int j=1;j<=siz-1;++j) if (f[i][j]-f[i][j-1]>=m+1) {flag=true; break;} if (flag) {res=i; break;} } printf("%d\n",res); return 0; }
#include<bits/stdc++.h> using namespace std; vector<vector<int>>G, dG; vector<int>in, out; int cnt = 0, depth = 0; void dfs(int n){ in[n] = cnt++; dG[depth].push_back(in[n]); for(int g : G[n]){ depth++; dfs(g); depth--; } out[n] = cnt++; } int main(){ int n; cin >> n; in = out = vector <int>(n); G = dG = vector <vector <int>>(n+1, vector <int> (0)); int p; for(int i=1; i<n; i++){ cin >> p; p--; G[p].emplace_back(i); } dfs(0); int q, u, d; cin >> q; for(int i=0; i<q; i++){ cin >> u >> d; u--; const auto& v = dG[d]; cout << lower_bound (v.cbegin(), v.cend(), out[u]) - lower_bound (v.cbegin(), v.cend(), in[u]) << endl; } return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i <= n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n) using namespace std; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<ll, ll>; using Graph = vector<vector<int>>; using Edge = pair<int, ll>; const int MAX = 100000; const ll INF = 1LL << 60; struct UnionFind { vector<int> par, siz; UnionFind(int n) : par(n, -1), siz(n, 1) {} // 連結成分サイズの配列。最初はみんな根、サイズ1。 // 木の根を求める int root(int x) { if (par[x] < 0) return x; // 根 else return root(par[x]); // 経路圧縮(O(logn)になる) } // xとyの属する集合を併合。小さい方をくっつける。 bool unite(int x, int y) { // 先に経路圧縮。根どうしを結合する。 x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); // sizの大きい方を根に par[y] = x; //yの根はxに。葉はrootの値が正になる。 siz[x] += siz[y]; return true; } //xとyが同じ集合に属するか判定 bool issame(int x, int y) { return root(x) == root(y); } //集合のサイズを返す int size(int x) { return siz[root(x)]; } }; int main() { // cin高速化 cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vll a(n), b(n); REP(i, n) cin >> a[i]; REP(i, n) cin >> b[i]; // 無向グラフを連結 UnionFind uf(n); REP(i, m) { int x, y; cin >> x >> y; --x, --y; uf.unite(x, y); } // 連結部分の総和 vll sa(n, 0), sb(n, 0); REP(v, n) { int r = uf.root(v); sa[r] += a[v], sb[r] += b[v]; } bool ans = true; // 任意の頂点について、根の総和が一致するか確認 REP(v, n) { int r = uf.root(v); if (sa[r] != sb[r]) ans = false; } if (ans) cout << "Yes" << "\n"; else cout << "No" << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define all(x) (x).begin(),(x).end() using ll = long long; using P = pair<ll, ll>; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, -1, 0, 1}; string char_to_string(char val) { return string(1, val); } int char_to_int(char val) { return val - '0'; } char inverse_char(char c) { if(isupper(c)) return tolower(c); else return toupper(c); } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } struct edge { ll to, cost; }; vector<ll> C; vector<vector<ll>> tree; vector<ll> res; // その頂点にたどり着いたか? vector<ll> ans; // 答え map<ll, ll> _tmp; void dfs(ll pnt) { res[pnt] = 1; _tmp[C[pnt]]++; if(_tmp[C[pnt]] == 1) ans.push_back(pnt); for(int i = 0; i < tree[pnt].size(); ++i) { if(res[tree[pnt][i]] == 1) continue; dfs(tree[pnt][i]); } _tmp[C[pnt]]--; } int main() { ll N; cin >> N; C.resize(N); REP(i, N) cin >> C[i]; vector<ll> A(N - 1), B(N - 1); REP(i, N - 1) { cin >> A[i] >> B[i]; --A[i]; --B[i]; } tree.resize(N); res.resize(N); REP(i, N - 1) { tree[A[i]].push_back(B[i]); tree[B[i]].push_back(A[i]); } dfs(0); sort(all(ans)); REP(i, ans.size()) cout << ans[i] + 1 << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define fr(i,n) for(int i=0;i<n;i++) #define fro(i,j,n) for(int i=j;i<n;i++) #define ifr(i,n) for(int i=n-1;i>=0;i--) int main() { int n; cin >> n; int ans[n]; fr(i,n){ ans[i]=1; } if(n>=15){ int count=1; fr(i,n*8/15){ ans[i]*=6; ans[i]*=count; count++; if(count%5==0)count++; } count=1; fro(i,n*8/15,n*4/5){ ans[i]*=10; ans[i]*=count; count++; if(count%3==0)count++; } count=1; fro(i,n*4/5,n*14/15){ ans[i]*=15; ans[i]*=count; count++; if(count%2==0)count++; } count=1; fro(i,n*14/15,n){ ans[i]*=30; ans[i]*=count; count++; } }else{ int count=1; fr(i,n/3){ ans[i]*=6; ans[i]*=count; count++; if(count%5==0)count++; } count=1; fro(i,n/3,n*2/3){ ans[i]*=10; ans[i]*=count; count++; if(count%3==0)count++; } count=1; fro(i,n*2/3,n){ ans[i]*=15; ans[i]*=count; count++; if(count%2==0)count++; } } fr(i,n){ cout << ans[i] << " "; } }
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; set<int> a; a.insert(6); a.insert(10); a.insert(15); for(int i=3;i<=1666;i++) a.insert(6*i); for(int i=2;i<=1000;i++) a.insert(10*i); for(int i=2;i<=666;i++) a.insert(15*i); vector<int> t(a.begin(),a.end()); for(int i=0;i<n;i++){ cout<<t[i]<<" "; } }
#include <bits/stdc++.h> #define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a) #define rep2(i, s, n) rep3(i, s, n, 1) #define rep(i, n) rep2(i, 0, n) using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int, int>; template <int mod = (int)(1e9 + 7)> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; const int MOD = 1e9 + 7; using mint = ModInt<MOD>; int main() { int h, w; cin >> h >> w; vector<string> s; rep(i, h){ string x; cin >> x; s.push_back(x); } vector<vector<int>> hbox(h), wbox(w); rep(i, h){ hbox[i].push_back(-1); hbox[i].push_back(w); } rep(i, w){ wbox[i].push_back(-1); wbox[i].push_back(h); } int messcnt = 0; rep(i, h){ rep(j, w){ if(s[i][j]=='#'){ messcnt++; hbox[i].push_back(j); wbox[j].push_back(i); } } } rep(i, h){ sort(hbox[i].begin(), hbox[i].end()); } rep(i, w){ sort(wbox[i].begin(), wbox[i].end()); } vector<mint> two(h*w-messcnt+1); two[0] = 1; rep2(i, 1, h*w-messcnt+1){ two[i] = two[i-1]*2; } mint res = 0; rep(i, h){ rep(j, w){ if(s[i][j]=='.'){ auto it = upper_bound(hbox[i].begin(), hbox[i].end(), j); int hnum = (*(it) - *(--it)) - 1; it = upper_bound(wbox[j].begin(), wbox[j].end(), i); int wnum = (*(it) - *(--it)) - 1; int x = hnum + wnum - 1; res += two[h*w-messcnt] - two[h*w-messcnt - x]; } } } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> iint; typedef pair<ll,ll> llll; #define ALL(x) (x).begin(),(x).end() const ll zero = 0; const ll one = 1; const ll INF = 9223372036854775807; //10^18 const int inINF = 2147483647; //10^9 const ll MOD = 1000000007; //10^9+7 const ll MOD2 = 998244353; void Yes() {printf("Yes\n");} void No() {printf("No\n");} void YES() {printf("YES\n");} void NO() {printf("NO\n");} int main(){ ll H, W; cin >> H >> W; vector<string> S(H); for (int i = 0; i < H; i++) { cin >> S[i]; } vector<vector<int>> A(H, vector<int> (W, -1)); vector<vector<int>> y(H, vector<int> (W, -1)); vector<vector<int>> t(H, vector<int> (W, -1)); for (int i = 0; i < H; i++) { if(S[i][0] == '.'){ y[i][0] = 1; } for (int j = 1; j < W; j++) { if(S[i][j-1] == '#'){ if(S[i][j] == '.'){ y[i][j] = 1; } } else{ if(S[i][j] == '.'){ y[i][j] = y[i][j-1] + 1; } } } int tmp = -1; for (int j = W-1; j >= 0; j--) { if(y[i][j] == -1){ tmp = -1; } else{ if(tmp == -1){ tmp = y[i][j]; } else{ y[i][j] = tmp; } } } } for (int i = 0; i < W; i++) { if(S[0][i] == '.'){ t[0][i] = 1; } for (int j = 1; j < H; j++) { if(S[j-1][i] == '#'){ if(S[j][i] == '.'){ t[j][i] = 1; } } else{ if(S[j][i] == '.'){ t[j][i] = t[j-1][i] + 1; } } } int tmp = -1; for (int j = H-1; j >= 0; j--) { if(t[j][i] == -1){ tmp = -1; } else{ if(tmp == -1){ tmp = t[j][i]; } else{ t[j][i] = tmp; } } } } ll cnt = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { A[i][j] = y[i][j] + t[i][j] - 1; if(S[i][j] == '.') cnt++; } } vector<ll> p(5000); p[0] = 1; vector<ll> inv(5); inv[1] = 1; for (int i = 2; i < 5; i++) { inv[i] = MOD - (MOD / i) * inv[MOD % i] % MOD; } for (int i = 1; i < 5000; i++) { p[i] = p[i-1] * inv[2] % MOD; } ll tk = 1; for (ll i = 0; i < cnt; i++) { tk = tk * 2 % MOD; } ll ans = 0; ll tmp; for (ll i = 0; i < H; i++) { for (ll j = 0; j < W; j++) { if(A[i][j] >= 1){ tmp = (1 - p[A[i][j]] + MOD) % MOD; ans = (ans + tmp) % MOD; } } } ans = ans * tk % MOD; printf("%lld\n", ans); // printf("%lld\n", tk); // printf("%d\n", A[0][0]); // printf("%d\n", A[0][1]); // printf("%d\n", A[0][2]); // printf("%d\n", y[0][0]); // printf("%d\n", y[0][1]); // printf("%d\n", y[0][2]); // printf("%d\n", t[0][0]); // printf("%d\n", t[0][1]); // printf("%d\n", t[0][2]); // printf("%d\n", t[1][0]); // printf("%d\n", t[1][1]); // printf("%d\n", t[1][2]); }
#include <bits/stdc++.h> using namespace std; // type alias typedef long long LL; typedef pair<int,int> II; typedef tuple<int,int,int> III; typedef vector<int> VI; typedef vector<string> VS; typedef unordered_map<int,int> MAPII; typedef unordered_set<int> SETI; template<class T> using VV=vector<vector<T>>; // minmax template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; } template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; } // repetition #define FORE(i,a,b) for(int i=(a);i<=(b);++i) #define REPE(i,n) for(int i=0;i<=(n);++i) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) for(int i=0;i<(n);++i) #define FORR(x,arr) for(auto& x:arr) #define SZ(a) int((a).size()) // collection #define ALL(c) (c).begin(),(c).end() // DP #define MINUS(dp) memset(dp, -1, sizeof(dp)) #define ZERO(dp) memset(dp, 0, sizeof(dp)) // stdout #define println(args...) fprintf(stdout, ##args),putchar('\n'); // debug cerr template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; } void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; } template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); } template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; } #define __KUMATRACE__ true #ifdef __KUMATRACE__ #define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); } #define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; } #define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); } #else #define dump(args...) #define dumpc(ar) #define dumpC(beg,end) #endif const long long Inf=2e18; const int MAX_V=2e5; long long D[MAX_V]; using P=pair<long long, int>; using Edge=tuple<int, long long, long long>; vector<Edge> G[MAX_V]; void dijkstra(int V, int st) { for(int i=0; i<V; ++i) D[i]=Inf; priority_queue<P,vector<P>,greater<P>> Q; Q.emplace(0,st); D[st]=0; while(Q.size()>0) { long long t; int u; tie(t,u)=Q.top(),Q.pop(); if(t!=D[u]) continue; for(auto e : G[u]) { long long c,d; int v; tie(v,c,d)=e; auto f=[&](LL t) -> LL { return t+c+d/(t+1); }; LL tmin=f(t),m=(LL)sqrt(d+0.5); FORE(d,-100,100) if(m+d>=t) { SMIN(tmin,f(m+d)); } //dump(u,v,t,tmin); if(tmin<D[v]) D[v]=tmin,Q.emplace(tmin,v); } } } // $ cp-batch RushHour2 | diff RushHour2.out - // $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address RushHour2.cpp && ./a.out /* 6/6/2021 14:48-15:48 give up https://atcoder.jp/contests/ABC204/editorial/224 https://motsu-xe.hatenablog.com/entry/2021/06/06/224341 */ int N,M; void solve() { dijkstra(N,0); LL res=D[N-1]; if(res>=Inf) res=-1; cout<<res<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout<<setprecision(12)<<fixed; cin>>N>>M; REP(i,M) { int u,v,c,d; cin>>u>>v>>c>>d; --u,--v; G[u].emplace_back(v,c,d),G[v].emplace_back(u,c,d); } solve(); return 0; }
#define _DEBUG #include "bits/stdc++.h" //#include <atcoder/all> #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,a5,x,...) x #define debug_1(x1) cout<<#x1<<": "<<x1<<endl #define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl #define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl #define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl #define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl #define debug_6(x1,x2,x3,x4,x5,x6) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<", "#x6<<": "<<x6<<endl #ifdef _DEBUG #define debug(...) CHOOSE((__VA_ARGS__,debug_6,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__) #else #define debug(...) #endif #define rep(index,num) for(int index=0;index<(int)num;index++) #define rep1(index,num) for(int index=1;index<=(int)num;index++) #define brep(index,num) for(int index=(int)num-1;index>=0;index--) #define brep1(index,num) for(int index=(int)num;index>0;index--) #define scan(argument) cin>>argument #define prin(argument) cout<<argument<<endl #define prind(argument) cout<<std::fixed<<setprecision(13)<<argument<<endl #define kaigyo cout<<endl #define eps 1e-7 #define PI acosl(-1) #define mp(a1,a2) make_pair(a1,a2) #define ALL(a) (a).begin(),(a).end() #define rALL(a) (a).rbegin(),(a).rend() #define puba emplace_back #define pubamp(a,b) emplace_back(mp(a,b)) typedef long long ll; typedef long double ld; using namespace std; //using namespace atcoder; typedef pair<ll,ll> pll; typedef pair<int,int> pint; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<pint> vpint; typedef vector<pll> vpll; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } ll INFl=(ll)1e+18+1; int INF=1e+9+1; int main(){ int N; scan(N); prin((N-1)/100+1); return 0; }
#include <bits/stdc++.h> #define INF LLONG_MAX/2 #define rep(i,n) for(int i = 0; i <(n) ; i++) using namespace std; typedef long long ll; typedef __int128_t LL; //入出力では使えないことに注意が必要. 計算過程で途中64bitを超える可能性があるときに使う typedef pair<ll,ll> pll; #define all(x) (x).begin(), (x).end() template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } vector<ll> A; // vector<vector<ll> > dp(N+1, vector<ll>(2, 0)); // vector<vector<vector<ll> > > dp(N, vector<vector<ll> >(M, vector<ll>(L, 0))); int main(){ string s; ll N; cin >> s; N = s.size(); vector<ll> idx; idx.push_back(-1); ll rnum = 0; for(ll i=0; i<N; i++){ if(s[i]=='R'){ idx.push_back(i); rnum ++; } } string T = ""; for(ll i=rnum; i>=1; i-=2){ for(int j = idx[i]-1; j > idx[i-1]; j--){ T += s[j]; if(T[T.size()-1] == T[T.size()-2]){ T = T.erase(T.size()-2); } } } // cout << T << endl; ll p = 0; if(rnum%2==1) p =1; for(ll i=p; i<rnum; i+=2){ for(int j = idx[i]+1; j < idx[i+1]; j++){ T += s[j]; if(T[T.size()-1] == T[T.size()-2]){ T = T.erase(T.size()-2); } } } // cout << T << endl; // for(int i = 1; i < idx.size(); i++){ // for(int j = idx[i]-1; j > idx[i-1]; j--){ // T += s[j]; // if(T.size()>=2){ // if(T[T.size()-1] == T[T.size()-2]){ // T = T.erase(T.size()-2); // } // }else if(T.size()==2){ // if(T[T.size()-1] == T[T.size()-2]){ // T = ""; // } // } // // cout << s[j] << endl; // } // } for(ll i=idx[idx.size()-1]+1; i<N; i++){ T += s[i]; if(T[T.size()-1] == T[T.size()-2]){ T = T.erase(T.size()-2); } // cout << T << endl; } cout << T << endl; // T = ""; // for(ll i=0; i<N; i++){ // if(s[i]=='R'){ // reverse(all(T)); // }else{ // T += s[i]; // if(T[T.size()-1] == T[T.size()-2]){ // T = T.erase(T.size()-2); // } // } // } // cout << T << endl; return 0; }
// For the purpose of C++ competitive programming only. #include "bits/stdc++.h" using namespace std; #define FOR(a, c) for (int(a) = 0; (a) < (c); (a)++) #define FORL(a, b, c) for (int(a) = (b); (a) < (c); (a)++) #define FORR(a, b, c) for (int(a) = (b); (a) > (c); (a)--) #define INF 1000000000000000003 #define MOD 1000000007 #define F first #define S second #define pb push_back #define pob pop_back #define mp make_pair #define endl '\n' typedef long long int ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; deque<char> ret; bool rev = false; for (auto &c : s) { if (c == 'R') { rev ^= 1; } else { if (!rev) { if (ret.size() && ret.back() == c) { ret.pop_back(); } else { ret.push_back(c); } } else { if (ret.size() && ret.front() == c) { ret.pop_front(); } else { ret.push_front(c); } } } } if (!rev) { for (auto it = ret.begin(); it != ret.end(); it++) { cout << *it; } } else { for (auto it = ret.rbegin(); it != ret.rend(); it++) { cout << *it; } } cout << endl; return 0; }
#include<bits/stdc++.h> #define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define test() int t; cin>>t; while(t--) #define all(v) v.begin(),v.end() #define st(v) sort(all(v)) #define stA(arr,n) sort(arr,arr+n) #define findInVec(v,key) (find(all(v),key)!=v.end()) #define findInSet(v,key) (v.find(key) != v.end()) #define findInStr(s,key) (s.find(key) != string::npos) #define findInMap(m,key) (mp.find(key) != mp.end()) #define prt(i) cout<<i<<"\n" #define fos(v) for(auto x:v) #define fo(m,n,i) for(int i=m;i<n;i++) #define Fo(m,n,i) for(int i=m;i>n;i--) #define setbit(i) __builtin_popcount(i) #define del(v,pos) v.erase(v.begin()+pos) #define cnt(v,key) (count(all(v),key)) #define cnts(s,key) (s.count(key)) #define sumArr(a,s,e,sum)(accumulate(a+s,a+e,sum)) typedef long long ll; using namespace std; ll stringToLong(string s){stringstream raaz(s);ll x = 0;raaz >> x;return x;} string longToString(ll k){stringstream ss;ss<<k;string s; ss>>s; return s;} bool isPowerOfTwo(int n){if(n==0) return false; return (ceil(log2(n)) == floor(log2(n)));} void scanArr(int *arr,int n){fo(0,n,i) cin>>arr[i];} void printArr(int *arr,int n){fo(0,n,i) cout<<arr[i]<<" ";} void scanVector(vector<ll> &v,int n){fo(0,n,i){int temp;cin>>temp;v.push_back(temp);}} void printVector(vector<ll> v){fos(v) cout<<x<<" ";} int main() { IOS int n; cin>>n; vector<int>a,b; int mn=INT_MAX,mx=INT_MAX; for(int i=0;i<n;i++) { int k; cin>>k; a.push_back(k); } for(int i=0;i<n;i++) { int k; cin>>k; b.push_back(k); } int r=b[0],l=a[0]; for (int i = 1; i < n; i++) { if (a[i] > r || b[i] < l) { cout <<"0"; return 0; } else { l = max(l, a[i]); r = min(r, b[i]); } } cout<<(r-l)+1; return 0; }
#include <bits/stdc++.h> using namespace std; #define PB push_back #define F first #define S second #define MP make_pair #define LL long long #define ULL unsigned long long #define LB lower_bound #define MOD1 1000000007 #define MOD2 1000000009 #define int LL #define pii pair<int, int> #define all(a) a.begin(), a.end() const int maxn = 1e5 + 1; void solve() { int n; cin >> n; vector<int> a(n), b(n); for(auto &i: a) cin >> i; for(auto &i: b) cin >> i; if(n == 0){ cout << 0; return; } int ll = a[0], ul = b[0]; for(int i = 1; i < n; i++){ if(a[i] > ll) ll = a[i]; if(b[i] < ul) ul = b[i]; } int zero = 0; int ans = max(zero,ul-ll+1); cout << ans; } signed main() { static const int _ = []() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); return 0; }(); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; // ---------- Debugger #define TRACE string to_string(string s) { return '"' + s + '"'; } string to_string(char c) { return '\'' + string(1, c) + '\''; } string to_string(char * s) { return to_string((string) s); } string to_string(const char * s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template < typename A > string to_string(A v); template < typename A, typename B > string to_string(pair < A, B > p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template < typename C > struct rge { C b, e; }; template < typename C > rge<C> range(C i, C j) { return rge<C>{i, j}; } template < typename C > string to_string(rge<C> v) { bool first = true; string res = "["; for(auto it = v.b; it != v.e; it++) { if (!first) { res += ", "; } first = false; res += to_string(*it); } res += "]"; return res; } template < typename A > string to_string(A v) { return to_string(range(v.begin(), v.end())); } #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template < typename Head > void __f(const string names, Head arg1) { cerr << names << " : " << to_string(arg1) << endl; } template < typename Head, typename...Tail > void __f(const string names, Head arg1, Tail...args) { int b = 0, comma = names.size(); for(int i=0;i<names.size();i++) { if(names[i] == ',' && b == 0) { comma = i; break; } if(names[i] == '(' || names[i] == '{' || names[i] == '[' || names[i] == '<') b++; else if(names[i] == ')' || names[i] == '}' || names[i] == ']' || names[i] == '>') b--; } // size_t comma = names.find(', '); cerr << names.substr(0, comma) << " : " << to_string(arg1) << " | "; __f(names.substr(comma + 1), args...); } #else #define trace(...) #endif // ---------- Debugger #define LL long long #define FI ios_base::sync_with_stdio(false); cin.tie(NULL); #define PREC cout << setprecision(10) << fixed; const int MOD = (int)1e9 + 7; const int INF = (int)1e9 + 9; const int MX = (int)1e5 + 5; int main() { int a,b; cin >> a >> b; int ms = a + b; if(ms >= 15 && b >= 8) { cout << 1; } else if(ms >= 10 && b >=3) { cout << 2; } else if(ms >= 3) { cout << 3; } else { cout << 4; } cout << endl; return 0; }
#include<iostream> #include<bits/stdc++.h> #define ll long long #define REP(s,n) for(int i=s;i<n;i++) #define IOS ios::sync_with_stdio(0);cout.tie(0);cin.tie(0); #define ee "\n" using namespace std; void slove() { ll a,b; cin>>a>>b; ll ansa = 0,ansb=0; a=a+b; if(a>=15) ansa=1; else if(a>=10 && a<15) ansa=2; else if(a>=3 && a<10) ansa=3; else ansa=4; if(b>=8) ansb=1; else if(b>=3 && b<8) ansb=2; else if(b>=0 && b<3) ansb=3; else ansb=4; cout<<max(ansa,ansb)<<"\n"; } int main() { IOS int t=1; //cin>>t;//For test case while(t--){ slove(); } return 0; }
//This Code is written by Anubhav Srivastava(anubhavsrivastavawebpage.wordpress.com) #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; //Defines #define pb push_back #define f(i,n) for(ll i=0;i<n;i++) #define fl(i,a,b) for(ll i=a;i<b;i++) #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); #define vec(x) vector<x> #define mp make_pair #define popc(x) __builtin_popcountll(x) #define iter(it, s) for(auto it = s.begin(); it != s.end(); it++) #define all(x) x.begin(), x.end() #define sortall(x) sort(all(x)) #define pair(x,y) pair<ll x,ll y> #define deb(x) cout << #x << "=" << x << "\n" #define PI 3.1415926535897932384626 const int mod = 1000000007; //Important Functions //Main Function int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n,v1,t,k,m,q; cin >> n >> k; vec(ll) v(200005,0); int flag=0; f(i,n){ cin >> t >> m >> q; v[t]+= q; v[m]-=q; } ll sum=0; f(i,n){ sum+=v[i]; if(sum>k) { cout << "No\n"; return 0; } } cout << "Yes\n"; return 0; }
#define _CRT_SECURE_NO_WARNINGS #define fast ios::sync_with_stdio(false); cin.tie(0) #define foru(i, k, n) for (ll i = k; i < n; i++) #define ford(i, k, n) for (ll i = k; i >= n; i--) #define pb push_back #define ff first #define ss second #include <iostream> #include <vector> #include <algorithm> #include <string> #include <list> #include <queue> #include <bitset> #include <map> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pii; typedef pair<ll, ll> pll; const ll mod = 998244353; void imult(ll& lhs, const ll& rhs) { lhs = ((lhs % mod) * (rhs % mod)) % mod; } void iadd(ll& lhs, const ll& rhs) { lhs = ((lhs%mod) + (rhs%mod)) % mod; } void isubt(ll& lhs, const ll& rhs) { ll ret = (lhs - rhs) % mod; lhs = ret + (ret < 0 ? mod : 0); } ll bpw(const ll& lhs, const ll& rhs) { if (rhs == 0)return 1; ll ret = bpw(lhs, rhs >> 1); imult(ret, ret); if (rhs & 1) imult(ret, lhs); return ret; } ll inv(const ll& x) { return bpw(x, mod - 2); } ll mult(const ll& lhs, const ll& rhs) { return ((lhs % mod) * (rhs % mod)) % mod; } ll add(const ll& lhs, const ll& rhs) { return ((lhs%mod) + (rhs%mod)) % mod; } ll subt(const ll& lhs, const ll& rhs) { ll ret = (lhs - rhs) % mod; return ret + (ret < 0 ? mod : 0); } ll div(const ll& lhs, const ll& rhs) { return mult(lhs, inv(rhs)); } const int sz = 5005, LOG = 13; int n, m; ll dp[LOG+1][sz]; ll chs[sz][sz]; void initchs() { foru(i, 0, sz)chs[i][0] = 1; foru(i, 1, sz) { foru(j, 0, i + 1) { if (!j)chs[i][j] = 1; else chs[i][j] = add(chs[i - 1][j], chs[i - 1][j - 1]); } } } int main() { fast; cin >> n >> m; initchs(); ford(bit, LOG - 1, 0) { ll msk = (1 << bit); foru(sum, 0, m + 1) { for (int i = 0; 2 * i <= n && sum > 2 * i * msk; i++) { iadd(dp[bit][sum], mult(dp[bit + 1][sum - 2 * i * msk], chs[n][2 * i])); } if (sum % (2 * msk) == 0) iadd(dp[bit][sum], chs[n][sum / msk]); } } cout << dp[0][m] << '\n'; return 0; }
// #pragma GCC optimize("O2") #include <bits/stdc++.h> // #include "D:/program_learning/vs_code/workplace/ACMtemplate/data_struct/UnionFindSet.hpp" using namespace std; #define mp make_pair #define phb push_back #define ppb pop_back #define eb emplace_back #define pp pop #define ph push #define ff first #define ss second #define htl(v, n) (v)+1,(v)+1+(n), greater<decltype((v)[1])>() #define lth(v, n) (v)+1,(v)+1+(n), less<decltype((v)[1])>() #define Max(a, b) (((a) > (b)) ? (a) : (b)) #define Min(a, b) (((a) < (b)) ? (a) : (b)) #define isZero(x) ((x)>0?(x):-(x)<eps) #define isEqual(x, y) (abs((x)-(y))<eps) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define iFOR(it, begin, end) for(auto it = (begin); it!=(end);it++) #define rFOR(i, a, b) for(int i = (a); i >= (b); i--) #define vFOR(it, a) for(auto it = a.begin();it != a.end();it++) #define aFOR(a, s) for(auto & (a) : (s)) #define pFOR(i, j, l, r, sit) for(int i = l,j = r; sit ;i++, j--) #define DEBUG(x) cout << #x << " = " << (x) << endl #define checktime() cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" ; system("pause") #define endl '\n' #define faster_cpp_io() std::ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0) #define setp(n) fixed << setprecision(n) #define cases(t,i) int t;cin >> t;for(int i = 1;i<=t;i++) using pll = pair<long long,long long>; using pii = pair<int,int>; using ull = unsigned long long; using ll = long long; using ld = long double; using vs = vector<string>; using vl = vector<long long>; using vvl = vector<vector<long long>>; using vi = vector<int>; using vvi = vector<vector<int>>; using mll = map<long long, long long>; using umll = unordered_map<long long, long long>; constexpr ll mod = 10007; constexpr ll inf = 0x7f7f7f7f7f7f7f7f; constexpr ld eps = 1e-9; constexpr ll cap = 1e5+5; constexpr ld pi = acos(-1); string in;ll ans; ll dic[26]; void solve(){ cin >> in; ll len = in.size(); rFOR(i, len - 1, 0){ if(i >= len - 2){ dic[in[i] - 'a'] ++; } else{ if(in[i] == in[i + 1] && in[i] != in[i + 2]){ ans += (len - i - 1 - dic[in[i] - 'a']); FOR(j, 0, 25){ if(in[i] - 'a' == j){ dic[in[i] - 'a'] = len - i; }else{ dic[j] = 0; } } } else dic[in[i] - 'a'] ++ ; } } cout << ans << endl; } int main() { faster_cpp_io(); // cases(t,i) solve(); // checktime(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) (v).begin(), (v).end() using ll = long long; constexpr int INF = 1e9; constexpr long long LINF = 1e18; constexpr long long MOD = 1e9 + 7; signed main() { string s; cin >> s; int n = s.size(); reverse(ALL(s)); ll ans = 0; ll cnt[26] = {}; char pre = '('; rep(i, n) { if (pre == s[i]) { rep(j, 26) { if (j == s[i] - 'a') continue; ans += cnt[j]; cnt[s[i] - 'a'] += cnt[j]; cnt[j] = 0; } } cnt[s[i] - 'a']++; pre = s[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;i++) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;i--) inline int read() { int x=0,f=1;char c=getchar(); while(c<48||c>57){if(c=='-')f=-1;c=getchar();} while(c>=48&&c<=57)x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } using namespace std; const int M=1e5+5; long long res[M]; int A[M],B[M],C[M],sz[M]; int main() { int n=read(); rep(i,1,n)A[i]=read(); rep(i,1,n)B[i]=read(); rep(i,1,n)C[i]=read(),sz[C[i]]++; rep(i,1,n)res[B[i]]+=sz[i]; long long ans=0; rep(i,1,n)ans+=res[A[i]]; cout<<ans; return 0; }
#include<algorithm> #include<iostream> #include<vector> using namespace std; #define For(i,l,r) for(int i=l;i<=r;i++) #define Pair pair<int,int> #define F first #define S second #define pb push_back #define abs(x) ((x)>0?(x):-(x)) #define MAXN 200001 int N;Pair x[MAXN],y[MAXN]; int main() { cin>>N;For(i,1,N)cin>>x[i].F>>y[i].F,x[i].S=y[i].S=i;sort(x+1,x+N+1);sort(y+1,y+N+1); vector<int>b;b.pb(x[N].F-x[1].F),b.pb(x[N-1].F-x[1].F),b.pb(x[N].F-x[2].F),max(y[N].S,y[1].S)!=max(x[N].S,x[1].S)||min(y[N].S,y[1].S)!=min(x[N].S,x[1].S)?b.pb(y[N].F-y[1].F),0:0,b.pb(y[N-1].F-y[1].F),b.pb(y[N].F-y[2].F); sort(b.begin(),b.end(),greater<int>());cout<<b[1]<<endl;return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, int>; int ctoi(char c) { if (c == 'R') { return 0; } else if (c == 'G') { return 1; } else{ return 2; } } int main () { int N; cin >> N; P A[200020]; int cnt[] = {0, 0, 0}; for (int i = 0; i < N * 2; i ++) { ll a; char c; cin >> a >> c; int b = ctoi(c); cnt[b] ++; A[i] = make_pair(a, b); } sort(A, A + (N * 2)); if ((cnt[0] % 2 + cnt[1] % 2 + cnt[2] % 2) == 0) { cout << 0 << endl; return 0; } int a = 0; while (cnt[a] % 2 == 0) a ++; int b = a + 1; while (cnt[b] % 2 == 0) b ++; ll inf = 1e8 + 8; inf = inf * inf; ll ans = inf; //cout << a << ' ' << b << endl; ll mim[] = {-inf, -inf, -inf}; int re = 3 - a - b; ll ans1 = inf; ll ans2 = inf; for (int i = 0; i < N * 2; i ++) { ll p; int q; tie(p, q) = A[i]; mim[q] = p; if (q == re) { ans1 = min(ans1, p - mim[a]); ans2 = min(ans2, p - mim[b]); } else if (q == a) { ans1 = min(ans1, p - mim[re]); ans = min(ans, p - mim[b]); } else { ans2 = min(ans2, p - mim[re]); ans = min(ans, p - mim[a]); } } ans = min(ans, ans1 + ans2); cout << ans << endl; }
#define _USE_MATH_DEFINES #include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<string> #include <cassert> #include <numeric> #include <unordered_map> #include <queue> #include <math.h> #include <climits> #include <set> #include <map> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; //template<class T> using pq = priority_queue<T, vector<T>, greater<T>>; #define FOR(i, a, b) for(ll i=(a); i<(b);i++) #define REP(i, n) for(ll i=0; i<(n);i++) #define ROF(i, a, b) for(ll i=(b-1); i>=(a);i--) #define PER(i, n) for(ll i=n-1; i>=0;i--) #define REPREP(i,j,a,b) for(ll i=0;i<a;i++)for(ll j=0;j<b;j++) #define VV(type) vector< vector<type> > #define VV2(type,n,m,val) vector< vector<type> > val;val.resize(n);for(ll i;i<n;i++)val[i].resize(m) #define vec(type) vector<type> #define VEC(type,n,val) vector<type> val;val.resize(n) #define VL vector<ll> #define VVL vector< vector<ll> > #define SZ size() #define all(i) begin(i),end(i) #define SORT(i) sort(all(i)) #define BITI(i) (1<<i) #define BITSET(x,i) x | (1<<i) #define BITCUT(x,i) x & ~(1<<i) #define EXISTBIT(x,i) ((x>>i) & 1 != 0) #define ALLBIT(n) (1<<n-1) class UndirectedGraph { public: struct edge { ll to,cost; }; // 行先,容量,逆容量,コスト UndirectedGraph(ll n) { edges.resize(n); } void addEdge(ll from, ll to, ll cost) { edge eF = { to,cost }; edges[from].push_back(eF); edge eT = { from,cost }; edges[to].push_back(eT); } void FindConnect(ll v, vector<bool>& out) { out.assign(edges.size(), false); vector<ll> stack; stack.push_back(v); out[v] = true; while (!stack.empty()) { v = stack.back(); stack.pop_back(); for (int i = 0; i < edges[v].size(); i++) { ll t = edges[v][i].to; if (!out[t]) { out[t] = true; stack.push_back(t); } } } } vector<vector<edge>> edges; }; int main() { ll n, m; cin >> n >> m; VL a(m), b(m), c(m); UndirectedGraph g(n); REP(i, m) { char cc; cin >> a[i] >> b[i] >> cc; a[i]--; b[i]--; c[i] = cc - 'a'; g.addEdge(a[i], b[i], c[i]); } queue<tuple<ll, ll, ll>> que; vector<vector<bool>> used(n); REP(i, n) { used[i].assign(n, false); } que.push({ 0,0,n - 1 }); used[0][n - 1] = true; used[n - 1][0] = true; ll find = -1; while (!que.empty()) { auto [dist, l, r] = que.front(); que.pop(); if (find != -1 && find < dist) { cout << find * 2 + 1; return 0; } if (l == r) { cout << dist * 2; return 0; } REP(i, g.edges[l].size()) { REP(j, g.edges[r].size()) { if (g.edges[l][i].cost == g.edges[r][j].cost) { if (g.edges[l][i].to == r && g.edges[r][j].to == l) { find = dist; continue; } if (used[g.edges[l][i].to][g.edges[r][j].to]) continue; que.push({ dist + 1,g.edges[l][i].to ,g.edges[r][j].to }); used[g.edges[l][i].to][g.edges[r][j].to] = true; used[g.edges[r][j].to][g.edges[l][i].to] = true; } } } } if (find != -1) { cout << find * 2 + 1; return 0; } cout << -1; }
#ifdef _DEBUG #include "../../../library/src/debug_template.hpp" #define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__) #else #define DMP(...) ((void)0) #endif #include <cassert> #include <cstdio> #include <cmath> #include <iostream> #include <iomanip> #include <string> #include <vector> #include <set> #include <map> #include <unordered_map> #include <queue> #include <numeric> #include <algorithm> #include <bitset> #include <variant> using namespace std; using lint = long long; constexpr int INF = 1010101010; constexpr lint LINF = 1LL << 60; struct init { init() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_; template<class T> class FenwickTree { public: explicit FenwickTree(int sz, T &&x = T{}) : n(sz), bit(n + 1) { for (int i = 0; i < n; i++) add(i, x); } void add(int k, const T &x) { for (; k < n; k |= k + 1) bit[k] += x; } void set(int k, const T &x) { add(k, x - sum(k, k + 1)); } [[nodiscard]] T sum(int k) const { T res = 0; for (k--; k >= 0; k = (k & (k + 1)) - 1) res += bit[k]; return res; } [[nodiscard]] T sum(int l, int r) const { return sum(r) - sum(l); } private: int n; vector<T> bit; }; int main() { string S; cin >> S; const int N = S.size(); vector<FenwickTree<int>> alpha(26, FenwickTree<int>(S.size())); for (int i = 0; i < N; i++) { alpha[S[i] - 'a'].add(i, 1); } lint ans = 0; char prev = '*'; // [last.index, N) = last.char pair<int, char> last = {N, '*'}; for (int i = N - 1; i >= 0; prev = S[i], i--) { if (prev == S[i]) { const auto[li, lc] = last; ans += N - (i + 2) - (lc == prev) * (N - li) - alpha[S[i] - 'a'].sum(i + 2, li); last = {i, S[i]}; } } cout << ans << '\n'; return 0; }
// Author: HarshKumar #include <bits/stdc++.h> using namespace std; #define ll int64_t const ll N = 1e6 + 6, M = 1e9 + 7; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); string s; cin >> s; ll n = s.size(), c = 0; vector<ll> f(26); for (ll i = n - 1; i; i--) { ll x = s[i] - 'a'; if (s[i] == s[i - 1]) { c += n - 1 - i - f[x]; for (ll i = 0; i < 26; i++) f[i] = 0; f[x] = n - 1 - i; } f[x]++; } cout << c; }
// Problem: B - Products of Min-Max // Contest: AtCoder - AtCoder Regular Contest 116 // URL: https://atcoder.jp/contests/arc116/tasks/arc116_b // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; #define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define mp make_pair #define pb push_back #define ff first #define ss second #define vi vector<ll> #define vll vector<ll> #define all(x) (x).begin() , (x).end() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #define rnd(x, y) uniform_ll_distribution<ll>(x, y)(rng) void dbg(){ cerr << endl; } template<typename Head , typename... Tail> void dbg(Head h , Tail... t){ cerr << h << " "; dbg(t...); } #ifdef EMBI_DEBUG #define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", dbg(__VA_ARGS__) #else #define debug(...) #endif const ll max_n = 1e5 + 9; const ll mod = 998244353; const ll inf = 1e9; typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; ll power(ll a , ll b) { ll prod = 1; while(b) { if(b&1) prod = (prod*a)%mod; a = (a*a)%mod; b >>= 1; } return prod; } void solve(){ ll n; cin >> n; vector<ll> a(n); for(ll &it : a) { cin >> it; } sort(all(a)); ll sum = 0; for(ll i = 0 ; i < n ; i++) { sum += (a[i]*a[i])%mod; sum %= mod; } // for(ll i = 0 ; i < n ; i++) { // for(ll j = i ; j >= 0 ; j--) { // sum += (a[i] * a[j] * power(2 , max(0ll , i - j - 1))) % mod; // sum %= mod; // } // } ll b[n]; for(ll i = n - 2 , j = 0 ; i >= 0 ; j++ , i--) { b[i] = (a[i]*power(2,j))%mod; } ll suff[n]; suff[n-1] = a[n-1]%mod; for(ll i = n-2 ; i >= 0 ; i--) { suff[i] = (suff[i+1] + b[i]) % mod; } for(ll i = n-1 , j = 0 ; i >= 0 ; i-- , j++) { assert(suff[0]-suff[i]+mod >= 0); assert(power(power(2,j),mod-2) < mod); assert(((suff[0]-suff[i]+mod)%mod) < mod); sum += ((a[i]%mod) * ((((suff[0]-suff[i]+mod)%mod)*power(power(2,j),mod-2))%mod))%mod; sum %= mod; } cout << sum << "\n"; } signed main(){ ll t = 1; // cin >> t; for(ll i = 1 ; i <= t ; i++){ solve(); } }
#include<cstdio> #include<algorithm> #include<cstring> #define ll long long #define fo(i,x,y) for(ll i=x;i<=y;i++) using namespace std; const ll mod=998244353; const int N=2e5+10; ll n,m,i,j,k,tot,ans,s,t,x,y,z,er; ll a[N]; ll e[N]; void read(ll &a) { a=0; char c=getchar(); while (c<'0'||c>'9') c=getchar(); while (c>='0'&&c<='9') {a=a*10-48+c; c=getchar();} return; } ll ksm(ll i,ll j) { ll re=1; while (j>0) { if (j&1) re=re*i%mod; j/=2; i=i*i%mod; } return re; } int main() { e[0]=1; fo(i,1,N-1) e[i]=e[i-1]*2%mod; read(n); fo(i,1,n) read(a[i]); sort(a+1,a+n+1); s=0; fo(i,1,n) s=(s+a[i]*e[i-1])%mod; er=ksm(2,mod-2); ans=0; fo(i,1,n) { s=(s-a[i]+mod)*er%mod; ans=(ans+a[i]*s)%mod; ans=(ans+a[i]*a[i])%mod; } printf("%lld\n",ans); }
#include <iostream> using namespace std; int main() { int a, b, a_sum = 0, b_sum = 0; cin >> a >> b; for (int i = 0; i < 3; i++){ a_sum += (a % 10); a = (a / 10); b_sum += (b % 10); b = (b / 10); } int result = a_sum > b_sum ? a_sum : b_sum; cout << result; }
#include<bits/stdc++.h> using namespace std; template<typename T>inline T read(){ T x=0,f=0;char c=getchar(); while(!isdigit(c)) f=c=='-',c=getchar(); while(isdigit(c)) x=x*10+c-48,c=getchar(); return f?-x:x; } namespace run{ const int N=4e5+9; map<char,int> mp; int C[4][4]; inline int Lucas(int n,int m){ if(n<3 && m<3) return C[n][m]; return Lucas(n/3,m/3)*Lucas(n%3,m%3)%3; } int n;char s[N]; int main(){ n=read<int>(),scanf("%s",s+1); for(int i=0;i<4;i++){ C[i][0]=1; for(int j=1;j<=i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%3; } mp['W']=0,mp['R']=1,mp['B']=2; int ans=0; for(int i=1;i<=n;i++) ans=(Lucas(n-1,i-1)*mp[s[i]]+ans)%3; // cout<<ans<<endl; if(!ans) puts("W"); else{ if(~n&1) ans^=3; if(ans==1) puts("R"); else puts("B"); } return 0; } } int main(){ #ifdef my freopen(".in","r",stdin); freopen(".out","w",stdout); #endif return run::main(); }
#include <functional> #include <tuple> #include <optional> #include <variant> #include <string> #include <string_view> #include <array> #include <vector> #include <deque> #include <set> #include <map> #include <stack> #include <queue> #include <algorithm> #include <valarray> #include <random> #include <numeric> #include <iostream> #include <cassert> #include <sstream> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template <typename K> using hset = gp_hash_table<K, null_type>; template <typename K, typename V> using hmap = gp_hash_table<K, V>; using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; template <typename T> using minq = priority_queue<T, vector<T>, greater<T>>; template <typename T> using maxq = priority_queue<T>; int main() { int n; cin >> n; string s; cin >> s; vi a(n + 1); for (int i = 0; i < n + 1; ++i) { cin >> a[i]; } int k = 100000000; for (int i = 0; i < n; ++i) { k = min(k, abs(a[i] - a[i + 1])); } vvi res(k); for (int i = 0; i < n + 1; ++i) { for (int j = 0; j < k; ++j) { res[j].push_back((a[i] + j) / k); } } cout << k << '\n'; for (int i = 0; i < k; ++i) { for (int j = 0; j < n + 1; ++j) { cout << res[i][j] << ' '; } cout << '\n'; } }
//#define NDEBUG #include <algorithm> #include <cassert> #include <cstddef> #include <cstdint> #include <iostream> #include <utility> #include <vector> namespace n91 { using i32 = std::int32_t; using i64 = std::int64_t; using u32 = std::uint32_t; using u64 = std::uint64_t; using isize = std::ptrdiff_t; using usize = std::size_t; struct rep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { ++i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr rep(const usize f, const usize l) noexcept : f(std::min(f, l)), l(l) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; struct revrep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { --i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr revrep(const usize f, const usize l) noexcept : f(l - 1), l(std::min(f, l) - 1) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; template <class T> auto md_vec(const usize n, const T& value) { return std::vector<T>(n, value); } template <class... Args> auto md_vec(const usize n, Args... args) { return std::vector<decltype(md_vec(args...))>(n, md_vec(args...)); } template <class T> constexpr T difference(const T& a, const T& b) noexcept { return a < b ? b - a : a - b; } template <class T> void chmin(T& a, const T& b) noexcept { if (b < a) a = b; } template <class T> void chmax(T& a, const T& b) noexcept { if (a < b) a = b; } template <class F> class rec_lambda { F f; public: rec_lambda(F&& f) : f(std::move(f)) {} template <class... Args> auto operator()(Args &&... args) const { return f(*this, std::forward<Args>(args)...); } }; template <class F> auto make_rec(F&& f) { return rec_lambda<F>(std::move(f)); } template <class T> T scan() { T ret; std::cin >> ret; return ret; } constexpr char eoln = '\n'; template <class T> T ceildiv(const T& l, const T& r) { return l / r + (l % r != 0 ? 1 : 0); } } // namespace n91 namespace n91 { void main_() { /* std::ios::sync_with_stdio(false); std::cin.tie(nullptr); //*/ const usize n = scan<usize>(); scan<std::string>(); std::vector<usize> a(n + 1); for (auto& e : a) { std::cin >> e; } usize k = 100000; for (const usize i : rep(0, n)) { chmin(k, difference(a[i], a[i + 1])); } std::cout << k << eoln; for (const usize j : rep(0, k)) { for (const auto& e : a) { std::cout << (e + j) / k << " "; } std::cout << eoln; } } } // namespace n91 int main() { n91::main_(); return 0; }
#include<bits/stdc++.h> #define ll long long #define f first #define s second #define pb push_back using namespace std; ll k,ra[500005],ans; int main(){ ios::sync_with_stdio(false); cin >> k; for(int i=1; i<=k; i++){ ra[i] = ra[i - 1]; for(int j=1; j*j<=i; j++){ if(i % j == 0){ if(j * j == i)ra[i]++; else ra[i] += 2; } } } for(int i=1; i<=k; i++){ ans += ra[k / i]; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define clr(a) memset(a, 0, sizeof(a)) #define full(a) memset(a, 0x3f, sizeof(a)) #define mset(a, b) memset(a, b, sizeof(a)) #define cpy(a,b) memcpy(a, b, sizeof(a)) #define fornext(x, i) for(signed i = hd[x], y = ver[i]; i; i = nxt[i], y = ver[i]) #define Rep(i, a, b) for(signed i = (signed)(a); i <= (signed)(b); ++i) #define dRep(i, a, b) for(signed i = (signed)(a); i >= (signed)(b); --i) #define IOset(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout); #define pb push_back #define It iterator #define endl '\n' #define un unsigned #define int ll #define ll long long #define db double #define rept cerr<<1.0*clock()/CLOCKS_PER_SEC<<endl; #define dbg cout<<"c " #define dbug(x) cerr << #x " = " << (x) << endl 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...); } template <typename _T, typename ...Args> inline void prt(_T _d, Args ..._a) { _prt(_d), _prt(_a...), cerr<<endl; } template <typename _T, typename ...Args> inline void prt(_T _d) { cerr << _d <<endl; } template<typename _T> inline void rd(_T &_d) { signed _f; char _c; _f = 1,_d = 0; while (_c = getchar(), !isdigit(_c)) if(_c=='-') _f=-1; while (isdigit(_c)) _d = _d * 10 + _c - '0', _c = getchar(); _d=_f*_d; } template <typename _T, typename ...Args> inline void rd(_T &_d, Args &..._a) { rd(_d); rd(_a...); } const int N=2e5+5; int f[N]; signed main() { int n,ans=0; rd(n); Rep(i,1,n) Rep(j,1,n/i) f[i*j]++; Rep(i,1,n) Rep(j,1,n/i) ans+=f[j]; cout<<ans<<endl; return 0; }
/* https://atcoder.jp/contests/abc200/tasks/abc200_e ## 題意: ## 思路: */ #include <bits/stdc++.h> using namespace std; typedef long long int ll; const int INF = 0x3fffffff; const ll LINF = 9223372036854775807; #define dump(x) cout << #x << " = " << (x) << endl #define ALL(x) begin(x),end(x) #define rep(i,s,e) for(int i=(s); i<=(e); ++i) #define repRev(i,s,e) for(int i=(s); i>=(e); --i) #define range(i,s,n) for(int i=(s), i_stop=(s)+(n); i<i_stop; ++i) #define rangeRev(i,s,n) for(int i=(s), i_stop=(s)-(n); i>i_stop; --i) template<typename T> bool chmax(T& a, const T b) {if(a<b) {a=b;return true;} return false;} template<typename T> bool chmin(T& a, const T b) {if(a>b) {a=b;return true;} return false;} void solve() { int n; cin>>n; string s,t; cin>>s>>t; vector<int> a,b; range(i,0,n) if(s[i]=='0') a.push_back(i); range(i,0,n) if(t[i]=='0') b.push_back(i); if(a.size() != b.size()) {printf("-1\n"); return;} int ans=0; range(i,0,a.size()) if(a[i]!=b[i]) ++ans; cout<<ans<<endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; }
#include <algorithm> #include <climits> // FOO_MAX, FOO_MIN #include <cmath> #include <cstdlib> // abs(int) #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <string> #include <unordered_set> #include <vector> using namespace std; #define roundup(n, d) (((n) + ((d)-1)) / (d)) #define assign_max(into, compared) (into = max((into), (compared))) #define assign_min(into, compared) (into = min((into), (compared))) #define rep(i, n) for (long long i = 0; i < (long long)n; ++i) #define v_in(v) \ for (auto&& i : v) \ cin >> i #define vv_in(vv) rep(I, (long long)vv.size()) for (auto&& J : vv[I]) cin >> J #define FAST_IO \ ios::sync_with_stdio(false); \ cin.tie(nullptr); #define fix(n) fixed << setprecision(n) #define ALL(v) v.begin(), v.end() #define printvar(x) cout << #x << ":" << x << endl #define PI 3.14159265358979323846 using ll = long long; using ull = unsigned long long; using vll = vector<long long>; using vvll = vector<vector<long long>>; int main(void) { FAST_IO ll n; cin >> n; unordered_set<string> bang; unordered_set<string> notbang; bang.reserve(n); notbang.reserve(n); rep(i, n) { string str; cin >> str; if (str[0] == '!') { string tempstr = str.substr(1); if (notbang.find(tempstr) != notbang.end()) { cout << tempstr << endl; return 0; } bang.emplace(tempstr); } else { if (bang.find(str) != bang.end()) { cout << str << endl; return 0; } notbang.emplace(str); } } cout << "satisfiable" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define LOCAL //Credit: Errichto's debug template #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " using ll = long long int; using ld = long double; using vi = vector<int>; using mii = map<int, int>; using pii = pair<int, int>; const int inf = 1e9; const int N = 100005; const ll mod = (ll) 1e9 + 7; const ll mod2 = (ll) 998244353; void test(){ int n; cin >> n; vi arr(n); for(int i = 0; i < n; i++) cin >> arr[i]; set<int> s; for(int i = 0; i <= n; i++) s.insert(i); for(int i = 0; i < n; i++){ if(s.find(arr[i]) != s.end()) s.erase(arr[i]); int ans = *s.begin(); cout << ans << '\n'; } } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int tt = 1; //cin >> tt; while(tt--){ test(); } return 0; } /* */
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; vector<long long> xs(n); for (long long &x : xs) cin >> x; long long result0 = 0; long long result1 = 0; long long result2 = 0; for (int i = 0; i < n; ++i) { result0 += abs(xs[i]); result1 += xs[i] * xs[i]; result2 = max(result2, abs(xs[i])); } double result1a = sqrt(result1); cout << setprecision(10); cout << result0 << endl << result1a << endl << result2 << endl; return 0; }
#include <bits/stdc++.h> #define endl "\n" using namespace std; typedef long long ll; typedef vector<ll> vl; typedef pair<ll, ll> PP; #define overload4(_1, _2, _3, _4, name, ...) name #define overload3(_1, _2, _3, name, ...) name #define rep1(n) for (ll i = 0; i < n; ++i) #define rep2(i, n) for (ll i = 0; i < n; ++i) #define rep3(i, a, b) for (ll i = a; i < b; ++i) #define rep4(i, a, b, c) for (ll i = a; i < b; i += c) #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define rrep1(n) for (ll i = n; i--;) #define rrep2(i, n) for (ll i = n; i--;) #define rrep3(i, a, b) for (ll i = b; i-- > (a);) #define rrep4(i, a, b, c) for (ll i = (a) + ((b) - (a)-1) / (c) * (c); i >= (a); i -= c) #define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__) #define elif else if ll beki(ll i) { return 1ll << i; } #define skip(M) \ if (M) \ continue #define all(v) v.begin(), v.end() #define allm(x, y, M) for (auto [(x), (y)] : (M)) #define alls(i, S) for (auto(&i) : (S)) #define pb push_back #define fi first #define se second #pragma warning(disable : 4312) const ll INF = (1LL << 61) - 1; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll MAX_N1 = 200010; const ll MAX_N2 = 500010; template <class X> void print(X x) { cout << x << endl; } void print(vl x) { for (ll i : x) { cout << i << " "; } cout << endl; } void print(vector<PP> x) { for (PP i : x) { cout << i.first << " " << i.second << endl; } cout << endl; } template <class X> int lbound(vector<X> &Y, X a) { return lower_bound(all(Y), a) - Y.begin(); } template <class X> int ubound(vector<X> &Y, X a) { return upper_bound(all(Y), a) - Y.begin(); } template <class X> X lbound2(vector<X> &Y, X a, int mode = 0) { int x = lbound(Y, a) - mode; if (x < 0 || x >= Y.size()) return INF; return Y[x]; } template <class X> X ubound2(vector<X> &Y, X a, int mode = 0) { int x = ubound(Y, a) - mode; if (x < 0 || x >= Y.size()) return INF; return Y[x]; } template <class... T> void zero(T &...t) { (..., (t = 0)); } template <class... T> void cl(T &...t) { (..., (t.clear())); } template <class... T> void in(T &...t) { (..., (cin >> t)); } template <class... T> void put(vl &V, int n) { ll k; rep(i, n) { cin >> k; V.pb(k); } } int max_index(vl &V) { return max_element(all(V)) - V.begin(); } int min_index(vl &V) { return min_element(all(V)) - V.begin(); } ll sum(vl &V) { return accumulate(all(V), 0ll); } void Uni(vl &V) { V.erase(unique(all(V)), V.end()); } template <class X> bool ma(X &a, X b) { if (a < b) { a = b; return true; } return false; } template <class X> bool mi(X &a, X b) { if (a > b) { a = b; return true; } return false; } void vset(vl &A, ll n, ll k) { A = vl(n, k); } void so(vl &A) { sort(all(A)); } ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, m, u, v; ll codeforces = 1; string S, T; vl A, B, C, D, ANS; vector<PP> VP, VP2; set<ll> s1, s2; void solve() { long double x1, x2, y1, y2; in(n); in(x1, y1, x2, y2); long double kk = M_PI / (n / 2); long double a1 = (x1 + x2) / 2, a2 = (y1 + y2) / 2, b1 = x1 - a1, b2 = y1 - a2; long double c1 = cos(kk) * b1 - sin(kk) * b2, c2 = sin(kk) * b1 + cos(kk) * b2; //cout << a1 << " " << a2 << endl; //cout << c1 << " " << c2 << endl; cout << a1 + c1 << " " << a2 + c2 << endl; } int main() { cout << fixed << setprecision(15); cin.tie(0); ios::sync_with_stdio(false); //cin >> codeforces; while (codeforces--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define all(x) (x).begin(),(x).end() using ll = long long; using P = pair<ll, ll>; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, -1, 0, 1}; string char_to_string(char val) { return string(1, val); } int char_to_int(char val) { return val - '0'; } char inverse_char(char c) { if(isupper(c)) return tolower(c); else return toupper(c); } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } struct edge { ll to, cost; }; #define PI 3.141592653589793 double ansx(double x1, double y1, double x2, double y2, double degree) { double rty = degree * PI / 180.0; // cout << rty << " " << sin( rty ) << endl; double atai_x = (x2 - x1) * cos( rty ) - (y2 - y1) * sin( rty ); return atai_x; } double ansy(double x1, double y1, double x2, double y2, double degree) { double rty = degree * PI / 180.0; double atai_y = (x2 - x1) * sin( rty ) + (y2 - y1) * cos( rty ); return atai_y; } int main() { double N; cin >> N; double x0, y0; cin >> x0 >> y0; double x2, y2; cin >> x2 >> y2; double cx = 0.0; double cy = 0.0; cx = (x0 + x2) / 2.0; cy = (y0 + y2) / 2.0; double theta = 360.0 / N; // cout << cx << " " << cy << " " << theta << endl; cout << fixed << setprecision(10) << ansx(cx, cy, x0, y0, theta) + cx << " " << ansy(cx, cy, x0, y0, theta) + cy << endl; }
#include<bits/stdc++.h> using namespace std; long long int B,C; int main(){ scanf("%lld%lld",&B,&C); if(C==0)printf("1\n"); else{ if(B>0){ long long int zl=B-C/2,fl; if(C%2==1){ fl=-zl; } else{ fl=-zl-1; } long long int fr=-B-(C-1)/2,zr; if((C-1)%2==1){ zr=-fr; } else{ zr=-fr-1; } zr=max(zr,B); if(fl>=zl)printf("%lld\n",zr-fr+1); else printf("%lld\n",zr-zl+1+fl-fr+1); } else if(B<0){ long long int fr=B-C/2,zr; if(C%2==1){ zr=-fr; } else{ zr=-fr-1; } long long int zl=-B-(C-1)/2,fl; if((C-1)%2==1){ fl=-zl; } else{ fl=-zl-1; } fl=max(fl,B); if(fl>=zl)printf("%lld\n",zr-fr+1); else printf("%lld\n",zr-zl+1+fl-fr+1); } else{ printf("%lld\n",((C-1)/2)+(C/2)+1); } } return 0; }
#pragma GCC optimize("O3") #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline") #pragma GCC target("sse4") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define mod 1000000007 #define pi 3.1415926535898 #define eps 1e-9 #define fast ios::sync_with_stdio(0); cin.tie(0);cout.tie(0) #define vt vector #define ar array #define fs first #define sc second #define pb push_back #define sp printf(" ") #define nl '\n' #define all(a) a.begin(),a.end() #define unique(c) (c).resize(unique(all(c)) - (c).begin()) #define sz(x) (int)(x).size() #define revsort(x) sort(all(x));reverse(all(x)) #define REP(i,start,end) for (int i = start; i <=end; i++) #define RREP(i,end,start) for (int i=end; i>=start ;i--) #define EACH(x, a) for (auto& x: a) typedef long long LL; typedef long double LD; typedef unsigned long long ULL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; typedef pair<double, double> pdd; typedef vector<int> vi; typedef vector<LL> vll; typedef vector<double> vd; typedef vector<vector<LL> > matrix; typedef vector<vector<int> > graph; template<class A> void read(vt<A>& v); template<class A, size_t S> void read(ar<A, S>& a); template<class T> void read(T& x) { cin >> x; } void read(double& d) { string t; read(t); d=stod(t); } void read(long double& d) { string t; read(t); d=stold(t); } template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); } template<class A> void read(vt<A>& x) { EACH(a, x) read(a); } template<class A, size_t S> void read(array<A, S>& x) { EACH(a, x) read(a); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int getRand(int l, int r) { uniform_int_distribution<int> uid(l, r); return uid(rng); } struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; int add (LL var1, LL var2) { return ( (var1 % mod) + (var2 % mod) + mod) % mod; } int mul (LL var1, LL var2) { return (var1*var2) % mod; } int powm (LL x, LL y) { int ans = 1; while (y) { if (y & 1) { ans = mul(ans, x); } x = mul(x, x); y /= 2; } return ans; } int inv(LL x) { return powm(x, mod-2); } LL INF=1e9; void solve() { LL b, c; read(b, c); set <pll> s; s.insert({b - c/2, b}); s.insert({b, b + (c-2)/2}); s.insert({-b - ((c-1)/2), -b}); s.insert({-b, -b + ((c-1)/2)}); LL left = -4e18; LL ans = 0; for (auto px : s) { LL l = px.fs; LL r = px.sc; // cerr << l << " " << r <<nl; if (l <= left) { l = left + 1; } ans += max(0LL, r - l + 1); left = r; } cout << ans << nl; } int main() { fast; solve(); }
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (n); ++i) #define repA(i, a, n) for(int i = a; i <= (n); ++i) #define repD(i, a, n) for(int i = a; i >= (n); --i) #define mp make_pair #define pb push_back #define X first #define Y second #define dbg(x) cerr<<#x<<" : "<<x<<endl typedef long long int ll; typedef long double ld; typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef vector<pii> vii; const ll INF = 1e18+1; const ll MOD = 998244353L; clock_t time_p=clock(); void timer(){time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";} template <typename Arg1> ostream& operator << (ostream& out, const vector<Arg1> &a) {out<<"[ ";for(const auto &x:a)out<<x<<" ";return out<<"]";} ll po(ll a,ll b, ll mod=MOD){ if(b==0) return 1; ll x = po(a,b/2,mod); if(b%2){ return (((x*x)%mod)*a)%mod; } else { return (x*x)%mod; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin>>n; vi f(n); rep(i,n) cin>>f[i]; rep(i,n) f[i]--; vi state(n,0); ll c = 0; vector<set<int>>adj(n); rep(i,n){ adj[i].insert(f[i]); adj[f[i]].insert(i); } vi visited(n,0); rep(start, n){ if(visited[start] == 0){ c++; queue<int>s; s.push(start); while(!s.empty()){ ll cur = s.front(); visited[cur] = 1; for(auto next : adj[cur]){ if(visited[next] == 0){ visited[next] = 1; s.push(next); } } s.pop(); } } } cout<<(po(2,c,MOD)-1+MOD)%MOD<<endl; timer(); return 0; }
#include <iostream> #include <vector> #include <set> // 引用元 : https://qiita.com/ofutonfuton/items/c17dfd33fc542c222396 struct UnionFind { std::vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); //xの根をrx int ry = root(y); //yの根をry if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; int main() { int N; std::cin >> N; UnionFind uf(N + 1); for (int i = 1; i <= N; i++) { int n; std::cin >> n; uf.unite(i,n); } std::set<int> groups; for (int i = 1; i <= N; i++) { groups.insert(uf.root(i)); } long long mod = 998244353; long long ans = 1; for (int i = 0; i < groups.size(); i++) { ans *= 2; ans %= mod; } ans += mod; ans -= 1; ans %= mod; std::cout << ans << std::endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define REP(i,n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define debug(var) do{cout << #var << " : "; view(var);}while(0) template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;} template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;} using namespace std; template<class T> void view(T e) {cout << e << endl;} template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;} template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}} using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int,int>; const int inf = 1<<30; const ll inf_l = 1LL<<61; const int MAX = 1e5; const int mod = 1e9 + 7; struct mint { ll x; mint (ll x = 0) : x((x % mod + mod) % mod) {} mint operator -() const {return mint(-x);} mint& operator +=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator -=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint& operator *=(const mint a) {(x *= a.x) %= mod; return *this;} mint operator +(const mint a) const {return mint(*this) += a;} mint operator -(const mint a) const {return mint(*this) -= a;} mint operator *(const mint a) const {return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint inv() const {return pow(mod - 2);} mint operator /=(const mint a) {return *this *= a.inv();} mint operator /(const mint a) {return mint(*this) /= a;} }; istream& operator >>(istream &is, mint &a) {return is >> a.x;} ostream& operator <<(ostream &os, const mint &a) {return os << a.x;} int main() { int n; cin >> n; vint a(n); rep(i,n) cin >> a[i]; sort(all(a)); a.erase(unique(all(a)), a.end()); sort(rall(a)); a.push_back(0); mint ans = 1; rep(i,a.size()-1) { ans *= a[i] - a[i + 1] + 1; } cout << ans << endl; }
#include <stdlib.h> #include <stdio.h> #include <iostream> #include <string> #include <algorithm> using namespace std; typedef long long int lli; int A,B,W; int main() { string s; cin >> s; long long x = std::stoll(s); int digit; int L = s.size(); long long int cnt = (L-1) / 3; long long int sum =(long long int)cnt* x; for (int j=cnt;j>=1;j--) { long long int l = 1; for (int i=1;i<=j;i++) { l *= 1000; } l--; sum -= l; } printf("%lld\n", sum); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll,ll> pll; typedef pair<ll,pll> plp; typedef pair<pll,ll> ppl; typedef pair<pll,pll> ppp; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<vvll> vvvll; typedef vector<pll> vpll; typedef vector<plp> vplp; typedef vector<ppl> vppl; typedef vector<ppp> vppp; typedef vector<vpll> vvpll; typedef vector<bool> vbool; typedef vector<vbool> vvbool; typedef vector<double> vd; typedef priority_queue<pll,vpll,greater<pll> > pqpll; typedef priority_queue<pll,vpll> pqrpll; typedef priority_queue<ll, vll, greater<ll> > pqll; typedef priority_queue<ll, vll> pqrll; struct edge{ ll to,cost; edge(ll to,ll cost): to(to), cost(cost){} }; typedef vector<vector<edge>> Graph; #define rep(i,a,n) for(ll i = a;i < n;i++) #define rrep(i,a,n) for(ll i = n-1; i >= a;i--) #define LINF 1000000000000000000 #define INF 1000000000 #define fs first #define sc second #define EPS 1e-10 #define ALL(a) a.begin(), a.end() template<typename T> ll sz(vector<T> &vec){ return (ll)vec.size(); } template<typename T> ll sz(priority_queue<T, vector<T> > &pq) {return (ll)pq.size(); } template<typename T> ll sz(priority_queue<T, vector<T>, greater<T> > &pq) {return (ll)pq.size(); } ll sz(string &s) {return (ll)s.size(); } void chmin(ll &a, ll &b) { if(a > b) a = b; } void chmax(ll &a, ll &b) { if(a < b) a = b; } ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); } ll lcm(ll a,ll b){ return a / gcd(a,b) * b; } ll dx[4] = {0,-1,1,0},dy[4] = {-1,0,0,1}; bool checkindex(ll i,ll n){ return (i < n && i >= 0); } int main(){ ll t; cin >> t; rep(i,0,t){ string s,t; cin >> s; string memo = "atcoder"; t = s; sort(ALL(t),greater<char>()); if(memo < s) cout << 0 << endl; else if(memo >= t) cout << -1 << endl; else{ ll ans = LINF; rep(i,0,sz(memo)){ rep(j,i,sz(s)){ if(s[j] > memo[i]){ ans = min(ans,j-i); break; } } if(s[i] < memo[i]) break; } cout << ans << endl; } } return 0; }
/* Kids were laughing in my classes While I was scheming for the masses Who do you think you are? Dreaming 'bout being a big star They say you're basic, they say you're easy You're always riding in the back seat Now I'm smiling from the stage while You were clapping in the nose bleeds Thunder Thunder, thun', thunder Thun-thun-thunder, thunder, thunder Thunder, thun', thunder Thun-thun-thunder, thunder Thunder, feel the thunder Lightning then the thunder Thunder, feel the thunder Lightning then the thunder Thunder */ #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define fi first #define sec second #define pb push_back #define mp(x,y) make_pair(x,y) #define mod 1000000007 #define me(i,x,n) for( i=x;i<n;i++) #define she(i,x,n) for( i=x;i>=0;i--) #define all(v) v.begin(),v.end() #define pii pair<int,int> #define pll pair<ll,ll> #define thunder ios_base::sync_with_stdio(false);cin.tie(NULL); #define try cin>>t;while(t--) #define PI (ld)3.141592653589793238 #define INF LLONG_MAX #define MAX 100005 #define make_graph(k) ll x,y; me(i,0,k){cin>>x>>y; adj[x].pb(y); adj[y].pb(x);} int main() { thunder #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll t,n,m,i,s,j,k,c; //try s=0; cin>>n; vector <ll> vec(n); me(i,0,n) cin>>vec[i]; ll p=pow(2,n); s=INF; for(i=0;i<p;i++) { ll ans=0; ll c=0; for(j=0;j<n;j++) { if((i&(1<<j))!=0) { c=c|vec[j]; ans=ans^c; c=0; } else c=c|vec[j]; } ans=ans^c; s=min(s,ans); } cout<<s<<endl; return 0; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll power(ll x, ll y, ll m) { if (y == 0) return 1; ll p = power(x, y/2, m) % m; p = (p * p) % m; return (y%2 == 0)? p : (x * p) % m; } ll modInverse(ll a, ll m) { //ll g = gcd(a, m); return power(a, m-2, m); } //WHY ARE YOU STALKING?
#include <bits/stdc++.h> #define REP(i, s, n) for (int i = s; i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define MOD 1000000007 using namespace std; using ll = long long; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<string> s(3); REP(i, 0, 3) cin >> s[i]; cout << string(n, '0') << string(n, '1') << '0' << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i)) #define REP(i, n) FOR(i,n,0) #define OF64 std::setprecision(40) const ll MOD = 1000000007; const ll INF = (ll) 1e15; bool solve(vector<ll> &A) { ll N = A.size(); vector<ll> ans; REP(i, N * N) { bool sorted = true; REP(j, N - 1) { if (A[j] > A[j + 1]) { sorted = false; break; } } if (sorted) break; bool update = false; REP(j, N) { if (i % 2 != j % 2) continue; if (j + 1 >= N) break; if (A[j] > A[j + 1]) { update = true; swap(A[j], A[j + 1]); ans.push_back(j); break; } } if (!update) { for (ll j = N - 2; j >= 0; --j) { if (j % 2 == i % 2) { swap(A[j], A[j + 1]); ans.push_back(j); break; } } } #if false REP(j, N) { cout << A[j] << " "; } cout << endl; #endif } cout << ans.size() << endl; REP(i, ans.size()) { cout << ans[i] + 1 << " "; } cout << endl; { bool sorted = true; REP(j, N - 1) { if (A[j] > A[j + 1]) { sorted = false; break; } } return sorted; } } int main() { cin.tie(0); ios::sync_with_stdio(false); #if true ll Q; cin >> Q; REP(_, Q) { ll N; cin >> N; vector<ll> A(N); REP(i, N) { cin >> A[i]; } if (!solve(A)) { assert(false); } } #else vector<ll> A; ll N = 8; REP(i, N) { A.push_back(i + 1); } do { vector<ll> v; REP(i, N) { v.push_back(A[i]); } if (!solve(v)) { assert(false); } } while (next_permutation(A.begin(), A.end())); #endif return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; struct UnionFind{ vector<int> p,r; UnionFind(int n){ p.resize(n, -1); r.resize(n, 1); } int find(int x){ if(p[x] == -1) return x; else return p[x] = find(p[x]); } void unite(int x, int y){ x = find(x); y = find(y); if(x == y) return; if(r[x] > r[y]) swap(x,y); if(r[x] == r[y]) r[y]++; p[x] = y; } }; ll mod = 998244353; ll modpow(ll a,ll b){ ll ans = 1; a %= mod; while(b){ if(b&1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int N; cin >> N; UnionFind uf(N); vector<int> f(N); rep(i,N){ cin >> f[i]; f[i]--; uf.unite(i, f[i]); } set<ll> se; rep(i,N) se.insert(uf.find(i)); ll cnt = se.size(); cout << modpow(2, cnt) - 1 << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++)//iをaからn #define per(i,n,a) for (int i=a-1;i>=n;i--)//iをnからa #define db(x) cout << #x << " = " << x << endl//デバッグ用 #define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用 #define all(x) (x).begin(), (x).end() #define INF 1000000000000 //10^12:∞ #define MOD 1000000007 //10^9+7:合同式の法 #define pb push_back #define F first #define S second typedef long long ll; //sort(all(a)); ソート //sort(all(a),greater<int>()); 逆順ソート //a.erase(unique(all(a)), a.end()); ソート後に重複を削除 //cout<< std::fixed << std::setprecision(15)<<0.000001<<endl; 小数点以下を表示させる //vector<vector<int>> data(3, vector<int>(4)); int型の2次元配列(3×4要素の)の宣言 int main() { ll ans=1; ll loopnum=0; int n; cin>>n; vector<int> f(n); vector<bool> isLooked(n); int fff; rep(i,0,n){ cin>>fff; f.at(i)=fff-1; } rep(i,0,n){ if(isLooked.at(i)){continue;} int nowplace=i; //db(i); set<int> iFoundedPlace; while(true){ //db(nowplace); iFoundedPlace.insert(nowplace); //db(iFoundedPlace.size()); nowplace=f.at(nowplace); if(isLooked.at(nowplace)){ for(auto x : iFoundedPlace) { isLooked.at(x)=true; } break; } if(iFoundedPlace.count(nowplace)==1){ for(auto x : iFoundedPlace) { isLooked.at(x)=true; } loopnum++; break; } } } rep(i,0,loopnum){ ans*=2; ans%=998244353; } cout<<(ans%998244353)-1<<endl; return 0; }
#include <iostream> #include <string> #include <cstdlib> #include <vector> #include <array> #include <map> #include <set> #include <algorithm> #include <queue> #include <stack> #define _USE_MATH_DEFINES #include <cmath> #include <climits> #include <cstdio> #include <iomanip> #include <utility> #include <unordered_map> #include <numeric> using namespace std; typedef long long int ll; #define SP(x) setprecision((int)x) #define SW(x) setw(x) // 桁数指定 #define SF(c) setfill(c) // 埋め文字指定('0') #define ALL(v) v.begin(), v.end() vector<vector<ll>> v; // 順列を全通り生成 void p(ll i) { } int main(int argc, char const *argv[]) { ll n, k; cin >> n >> k; for (ll i = 0; i < n; i++) { vector<ll> temp; for (ll j = 0; j < n; j++) { ll t; cin >> t; temp.push_back(t); } v.push_back(temp); } ll ans = 0; vector<int> nums(n - 1); iota(nums.begin(), nums.end(), 0); do { ll sum = 0; sum += v[0][nums[0] + 1]; for (ll i = 0; i < n - 2; i++) { // cout << nums[i] + 1 << " " << nums[i + 1] + 1 << endl; sum += v[nums[i] + 1][nums[i + 1] + 1]; } sum += v[nums.back() + 1][0]; // cout << sum << endl; if (sum == k) { ans++; } } while (next_permutation(nums.begin(), nums.end())); cout << ans << endl; }
#include<bits/stdc++.h> #define int long long using namespace std; const int maxn=200005; const int inf=1ll<<60; struct Node { int w,v; bool operator < (const Node &rhs) const { return v>rhs.v; } } a[maxn]; int top; int x[maxn]; int st[maxn]; int vis[maxn]; signed main() { ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); int n,m,q; cin>>n>>m>>q; for(int i=1;i<=n;i++) { cin>>a[i].w>>a[i].v; } for(int i=1;i<=m;i++) { cin>>x[i]; } sort(a+1,a+n+1); while(q--) { int l,r; cin>>l>>r; top=0; for(int i=1;i<=l-1;i++) { st[++top]=x[i]; } for(int i=r+1;i<=m;i++) { st[++top]=x[i]; } sort(st+1,st+top+1); memset(vis,0,sizeof(vis)); int ans=0; for(int i=1;i<=n;i++) { int pos=-1; for(int j=top;j>=1;j--) { if(!vis[j]&&st[j]>=a[i].w) { pos=j; } } if(pos!=-1&&pos<=top&&st[pos]>=a[i].w) { vis[pos]=1; ans+=a[i].v; } } cout<<ans<<"\n"; } }
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define X first #define Y second #define y0 y12 #define y1 y22 #define INF 987654321 #define PI 3.141592653589793238462643383279502884 #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c)) #define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c)) #define MEM0(a) memset((a),0,sizeof(a)) #define MEM_1(a) memset((a),-1,sizeof(a)) #define ALL(a) a.begin(),a.end() #define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin()) #define SYNC ios_base::sync_with_stdio(false);cin.tie(0) using namespace std; typedef long long ll; typedef long double ld; typedef double db; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> Pi; typedef pair<ll, ll> Pll; typedef pair<ld, ld> Pd; typedef vector<int> Vi; typedef vector<ll> Vll; typedef vector<ld> Vd; typedef vector<Pi> VPi; typedef vector<Pll> VPll; typedef vector<Pd> VPd; typedef tuple<int, int, int> iii; typedef tuple<int, int, int, int> iiii; typedef tuple<ll, ll, ll> LLL; typedef vector<iii> Viii; typedef vector<LLL> VLLL; typedef complex<double> base; const int MOD = 1000000007; ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; } int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 }; int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 }; char s[100005]; int d[100005],d2[26]; int main(){ int n; scanf("%d%s",&n,s); fup(i,0,n-1,1)d[i]=INF; fup(i,0,25,1)d2[i]=INF; fdn(i,n-2,0,1){ if(s[i]!=s[n-1])d[i]=1; fup(j,0,25,1){ if(s[i]-'a'!=j)d[i]=min(d[i],1+d2[j]); } if(i>0)d2[s[i-1]-'a']=min(d2[s[i-1]-'a'],d[i]); } printf("%d\n",d[0]==INF?-1:d[0]); }
#include <bits/stdc++.h> using namespace std; template <class T> inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;} template <class T> inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;} #define REP(i, s, e) for (int i = s; i < e; i++) #define RREP(i, s, e) for (int i = s; i >= e; i--) typedef long long ll; typedef long double ld; #define MP make_pair #define FI first #define SE second typedef pair<int, int> ii; typedef pair<ll, ll> pll; #define MT make_tuple typedef tuple<int, int, int> iii; #define ALL(_a) _a.begin(), _a.end() #define pb push_back typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; #ifdef DEBUG #define debug(args...) _debug(args) void _debug(const char* format, ...) { va_list args; va_start(args, format); vprintf(format, args); va_end(args); } #else #define debug(args...) #endif #define INF 1000000005 #define LINF 1000000000000000005 #define MOD 1000000007 #define MAXN 200005 int n; char s[MAXN]; int main() { scanf("%d", &n); scanf(" %s", s); if (s[0] != s[n - 1]) { printf("1\n"); return 0; } REP (i, 2, n - 1) { if (s[i - 1] != s[0] && s[i] != s[0]) { printf("2\n"); return 0; } } printf("-1\n"); return 0; }
#include<bits/stdc++.h> using namespace std; int n,a[100005],b[100005],cnt=0; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); } for(int i=1;i<=n;i++) { scanf("%d",&b[i]); } for(int i=1;i<=n;i++) { cnt+=(a[i]*b[i]); } if(cnt==0) { printf("Yes\n"); }else { printf("No\n"); } }
#include <iostream> #include <algorithm> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <string.h> #include <vector> #include <queue> #include <cmath> #include <complex> #include <functional> #include <numeric> #include <iomanip> #include <cassert> #include <random> #include <chrono> /* #include <atcoder/all> */ /* using namespace atcoder; */ using namespace std; void debug_out(){ cout << "\n"; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); } #ifdef _DEBUG #define debug(...) debug_out(__VA_ARGS__) #else #define debug(...) #endif #define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' '); #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl #define ALL(i) (i).begin(), (i).end() #define FOR(i, a, n) for(int i=(a);i<(n);++i) #define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i) #define REP(i, n) for(int i=0;i<int(n);++i) #define RREP(i, n) for(int i=int(n)-1;i>=0;--i) #define IN(a, x, b) (a<=x && x<b) #define OUT(a, x, b) (x<a || b<=x) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define int ll using ll = long long; using ull = unsigned long long; using ld = long double; const ll MOD = 1000000007; /* const ll MOD = 998244353; */ const ll INF = 1ll<<60; const double PI = acos(-1); struct INIT { INIT(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); }}INIT; signed main() { int N; cin >> N; vector<int> A(N); REP(i, N) cin >> A[i]; vector<int> B(N); REP(i, N) cin >> B[i]; int ans = 0; REP(i, N){ ans += A[i]*B[i]; } if(ans == 0) Yes; else No; return 0; }
#include<bits/stdc++.h> using namespace std; inline int read() { int w=1,x=0;char f=getchar(); while(!isdigit(f) && f!='-') f=getchar(); if(f=='-') {w=-1;f=getchar();} while(isdigit(f)) {x=(x<<3)+(x<<1)+f-48;f=getchar();} return w*x; } int a,b,c,d; double sx,sy,gx,gy; double ans,h1,h2,l,l1,l2; int main() { a=read();b=read(); c=read();d=read(); sx=a;sy=b;gx=c;gy=d; h1=abs(sy);h2=abs(gy); l=abs(sx-gx); l1=l*(h1/(h1+h2)); ans=sx<gx?sx+l1:sx-l1; printf("%.10lf",ans); return 0; }
#include <bits/stdc++.h> using namespace std; // using mint = long double; // using mint = modint998244353; // using mint = modint1000000007; typedef long long ll; typedef pair<ll, ll> P; typedef pair<P, ll> T; typedef pair<ll, vector<ll>> Pd; const ll INF = 1e18; const ll fact_table = 3200008; priority_queue <ll> pql; priority_queue <P> pqp; //big priority queue priority_queue <ll, vector<ll>, greater<ll> > pqls; priority_queue <P, vector<P>, greater<P> > pqps; //small priority queue //top pop ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1}; //↓,→,↑,← /* #define endl "\n" #ifdef ENJAPMA #undef endl #endif */ #define p(x) cout<<x<<endl; #define el cout<<endl; #define pe(x) cout<<x<<" "; #define ps(x) cout<<fixed<<setprecision(25)<<x<<endl; #define pu(x) cout<<(x); #define pb push_back #define lb lower_bound #define ub upper_bound #define pc(x) cout << x << ","; #define rep(i, n) for (ll i = 0; i < (n); i ++) #define rep2(i, a, b) for (ll i = a; i <= (b); i++) #define rep3(i, a, b) for (ll i = a; i >= (b); i--) typedef vector<ll> vec; typedef vector<vector<ll>> mat; const ll mod = 998244353ll; // const ll mod = 1000000007ll; ll mypow(ll a, ll b, ll m = mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= m; b >>= 1;}(x *= a) %= m; b--;} return x;} vec readvec(ll read) { vec res(read); for (int i = 0; i < read; i++) { cin >> res[i]; } return res;} void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;} void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;} void line() { p("--------------------"); return;} /* ll fact[fact_table + 5], rfact[fact_table + 5]; void c3_init() { fact[0] = rfact[0] = 1; for (ll i = 1; i <= fact_table; i++) { fact[i] = (fact[i - 1] * i) % mod; } rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod); for (ll i = fact_table; i >= 1; i--) { rfact[i - 1] = rfact[i] * i; rfact[i - 1] %= mod; } return; } ll c3(ll n, ll r) { return (((fact[n] * rfact[r]) % mod ) * rfact[n - r]) % mod; } */ bool icpc = false; bool multicase = false; ll n, m, k;; bool solve() { double sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; double ans = gx - (gx - sx) * (gy) / (sy + gy); ps(ans); return true; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); if (icpc) { while (solve()); return 0; } ll q, testcase = 1; if (multicase) { cin >> q; } else { q = 1; } while (q--) { // pu("Case ");pu("#");pu(testcase);pu(": "); solve(); testcase++; } // solve(); return 0; }
#include <bits/stdc++.h> #include <algorithm> using namespace std; int main() { int K; int64_t ans = 0; cin >> K; for(int a = 1; a*a*a <= K; a++) { for(int b = a; a*b*b<=K; b++) { int cmax = K/(a*b); if(a==b) { ans += 1+(cmax-b)*3; } else{ ans += 3+(cmax-b)*6; } } } cout << ans << endl; }
#include <iostream> #include <vector> #include <map> #include <algorithm> #include <set> #include <queue> #include <cmath> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<long long> vll; typedef vector<vector<long long>> vvll; typedef pair<int,int> pii; typedef pair<long long, int> pli; typedef pair<int, long long> pil; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rrep(i, n) for(int i = (int)(n)-1;i >= 0;i--) #define repr(i, a, b) for(int i = (int)a; i <= (int)b; i++) #define all(x) (x).begin(),(x).end() #define sz(x) (x).size() constexpr ll mod = 998244353; ll gcd(ll a, ll b){ if (a%b == 0)return(b); else return(gcd(b, a%b)); } ll inv(ll x){ ll res = 1; ll k = mod - 2; ll y = x; while(k){ if(k&1)res = (res*y)%mod; y = (y*y) % mod; k /= 2; } return res; } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll k; cin >> k; ll ret = 0; repr(i,1,k) { ll bc = k/i; repr(j,1,bc) { ret += bc/j; } } cout << ret << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i)) #define REP(i, n) FOR(i,n,0) #define OF64 std::setprecision(40) const ll MOD = 1000000007; const ll INF = (ll) 1e15; struct Data { ll x, y, z; }; Data D[105]; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, M; cin >> N >> M; REP(i, M) { cin >> D[i].x >> D[i].y >> D[i].z; //D[i].x--; } ll MAX = (1LL << N); vector<bool> U(MAX, false); REP(bit, MAX) { vector<ll> count(N + 1, 0); ll cnt = 0; REP(i, N) { if ((bit >> i) & 1) { count[i + 1]++; cnt++; } } REP(i, N) { count[i + 1] += count[i]; } U[bit] = true; REP(i, M) { if (D[i].x != cnt) continue; if (count[D[i].y] > D[i].z) { U[bit] = false; break; } } } vector<vector<ll>> dp(N + 2, vector<ll>(MAX, 0)); dp[0][0] = 1; REP(i, N) { REP(bit, MAX) { if (dp[i][bit] == 0) continue; REP(j, N) { if (((bit >> j) & 1) == 1) continue; ll nxt = (bit | (1LL << j)); if (!U[nxt]) continue; dp[i + 1][nxt] += dp[i][bit]; } } } cout << dp[N][MAX - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int mod = 1000000007; int main(){ int N, M; cin >> N >> M; int64_t dp[1<<N]; vector<vector<int>> joken(M,vector<int>(3)); for(int i = 0;i < M;i++) cin >> joken[i][0] >> joken[i][1] >> joken[i][2]; sort(joken.begin(),joken.end()); for(int i = 0;i < (1 << N);i++) dp[i] = 0; dp[0] = 1; for(int i = 0;i < (1 << N);i++){ bitset<20> b(i); int c = b.count(); bool ok = false; for(int j = 0;j < M;j++){ if(joken[j][0] >= c){ int d = 0; for(int k = 0;k < joken[j][1];k++) if(b.test(k)) d++; if(d > joken[j][2]){ ok = true; break; } } } if(ok){ continue; } for(int j = 0;j < N;j++){ if(b.test(j) == false) dp[i + (1 << j)] += dp[i]; } } cout << dp[(1 << N) - 1] << endl; }
#include <iostream> #include <vector> #include <algorithm> #include <numeric> #include <bitset> using namespace std; int N, M; int main() { cin >> N >> M; int ret = 0; auto S = new string[N]; //auto Sones = new int[N]; //auto Sbits = new std::bitset<20>[N]; uint64_t nOdd = 0, nEven = 0; for (auto i = 0; i < N; i++) { cin >> S[i]; //Sones[i] = std::bitset<20>(S[i]).count();//std::count(S[i].cbegin(), S[i].cend(), '1'); //Sbits[i] = std::bitset<20>(S[i]); if (std::bitset<20>(S[i]).count() % 2 == 0) { nEven++; } else { nOdd++; } } cout << nEven * nOdd << endl; }
//#include<bits/stdc++.h> #include<iostream> #include<vector> #include<unordered_map> #define endl '\n' #define PI acos(-1.0) #define pf printf #define sf scanf #define ff first #define ss second #define pb push_back #define mk make_pair #define ll long long #define VI vector<long long> #define pr pair<long long,long long> #define sf1(a) scanf("%d", &a) #define sf2(a,b) scanf("%d %d",&a, &b) #define sf3(a,b,c) scanf("%d %d %d", &a, &b, &c) #define sl1(a) scanf("%I64d", &a) #define sl2(a,b) scanf("%I64d %I64d", &a, &b) #define sl3(a,b,c) scanf("%I64d %I64d %I64d", &a, &b, &c) #define SET(a,x) memset( a, x, sizeof(a) ) #define SETV(a,x) memset(a.begin(), a.end(),x ) #define REP(i,a,b) for(long long i=a;i<b;i++) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)x.size()) #define tc(cn) pf("Case %d: ",cn) #define M 10000007 #define INF 2147483647 #define sqr(x) (x)*(x) #define gcd(a, b) __gcd(a, b) #define lcm(a, b) ((a)*((b)/gcd(a,b))) #define fio ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); using namespace std; inline void Time() { cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s. \n";} void solve() { ll n; cin >> n; VI a(n), b(n), ans; for (ll &x : a)cin >> x; for (ll &x : b)cin >> x; unordered_map<ll, ll>un; int count = 0; for (int i = 0; i < n; i++) { ll x = a[i]; ll y = b[i]; for (int k = x; k <= y; k++) { un[k]++; if (un[k] == n)count++; } } cout << count << endl; } int main() { //fio; solve(); //pf("\n\n\n\n"); Time(); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long namespace math{ const int MOD = 1e9+7; const int MN = 10'100; int fact[MN], inv_fact[MN]; int power(int a, int n) { int res = 1; for (;n; n >>= 1, a = (a * a) % MOD) if (n & 1) res = (res * a) % MOD; return res; } int inv(int a) { return inv_fact[a]*fact[a-1]%MOD; } void init_fact() { fact[0]=1; for (int i=1;i<MN;++i) fact[i] = fact[i-1]*i%MOD; inv_fact[MN-1] = power(fact[MN-1], MOD - 2); for (int i=MN-1; i>0;--i) inv_fact[i-1]=inv_fact[i]*i%MOD; } struct mint { int n; mint(int n): n(n){} mint(): n(0){} mint operator+(mint o){return (n + o.n) % MOD;} mint operator-(mint o){return (n - o.n % MOD + MOD) % MOD;} mint operator*(mint o){return (n * o.n) % MOD;} mint operator/(mint o){return o.n >= MN ? n * power(o.n, MOD - 2) % MOD : n * inv(o.n) % MOD;} }; }; using namespace math; using mat = vector<vector<mint>>; int n, m, k; vector<int> g[100]; mat M; mat operator*(mat A, mat B) { mat ret(A.size(), vector<mint>(B[0].size())); for (int i = 0; i < A.size(); ++i) { for (int j = 0; j < B[0].size(); ++j) { for (int k = 0; k < B.size(); ++k) ret[i][j] = ret[i][j] + A[i][k] * B[k][j]; } } return ret; } mat power(mat A, int n) { mat ret(A.size(), vector<mint>(A.size())); for (int i = 0; i < A.size(); ++i) ret[i][i] = 1; for (; n; A = A * A, n >>= 1) { if (n & 1) ret = ret * A; } return ret; } signed main() { cin.tie(0)->sync_with_stdio(false); cin>>n>>m>>k; M.resize(n, vector<mint>(n)); mat A(1, vector<mint>(n)); for (int i = 0; i< n;++i) cin>>A[0][i].n; for (int i = 0; i<m;++i) { int u, v; cin>>u>>v; --u, --v; g[u].push_back(v); g[v].push_back(u); } init_fact(); for (int i = 0; i < n;++i) { M[i][i] = mint(1) - mint(g[i].size()) / m / 2; for (int it: g[i]) { M[it][i] = mint(1) / m / 2; } } mat Ans = A * power(M, k); for (int i = 0; i<n;++i) cout << Ans[0][i].n << '\n'; return 0; }
#include<bits/stdc++.h> #define LL long long #define rint register int #define LB lower_bound #define UB upper_bound #define MS(x,y) memset(x,y,sizeof(x)) #define rep(i,a,b) for(rint i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(rint i=a,i##end=b;i>=i##end;--i) #define cms printf("%.2lf\n",(&o2-&o1)/1024.0/1024); using namespace std;bool o1; char IO; inline int Rd(){ int _s_=0;bool _f_=0; while(!isdigit(IO=getchar())) (IO=='-')&&(_f_=1); do _s_=(_s_<<1)+(_s_<<3)+(IO^48); while(isdigit(IO=getchar())); return _f_?-_s_:_s_; } const int P=1e9+7,n2=5e8+4; int n,m,k,n2m,a1,b1,in[104]; void cmod(int &x){ x>=P&&(x-=P); } int ksm(int x){ int rst=1; for(rint y=P-2;y;y>>=1,x=1ll*x*x%P) (y&1)&&(rst=1ll*rst*x%P); return rst; } struct node{ int a[105][105]; node(){MS(a,0);} node operator * (const node &_) const{ node rst; rep(i,1,n) rep(j,1,n) rep(l,1,n) cmod(rst.a[i][j]+=1ll*a[i][l]*_.a[l][j]%P); return rst; } }st,nw; bool o2;int main(){ n=Rd(),m=Rd(),k=Rd(); n2m=1ll*ksm(m)*n2%P; rep(i,1,n) st.a[1][i]=Rd(); rep(i,1,m){ in[a1=Rd()]++,in[b1=Rd()]++; nw.a[a1][b1]=nw.a[b1][a1]=n2m; } rep(i,1,n) cmod(nw.a[i][i]=P+1-1ll*in[i]*n2m%P); rep(i,0,29){ if(k&(1<<i)) st=st*nw; nw=nw*nw; } rep(i,1,n) printf("%d\n",st.a[1][i]); return 0; }
#include <bits/stdc++.h> #define REP(i, s, n) for (int i = s; i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define MOD 1000000007 using namespace std; using ll = long long; int main() { int n; cin >> n; if (n % 2 == 0) cout << "White" << endl; else cout << "Black" << endl; return 0; }
#include<bits/stdc++.h> #define ll long long using namespace std; int main() { int n; cin>>n; cout<<n-1<<endl; }
#include <bits/stdc++.h> // clang-format off using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18; void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);} void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);} void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<h;perr0(t...);} void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);} void ioinit() { cout << fixed << setprecision(15); cerr<<fixed<<setprecision(6); ios_base::sync_with_stdio(0); cin.tie(0); } // clang-format on struct edge { int v; ll cost; }; struct edg2 { int v; ll c; ll d; }; class greater_cost { public: bool operator()(const edge& lh, const edge& rh) const { return lh.cost > rh.cost; } }; using pq_mincost = priority_queue<edge, vector<edge>, greater_cost>; const ll LG = 1e17; vector<vector<edge>> edgcost; vector<vector<edg2>> edgs; vector<ll> c; vector<ll> d; ll dijkstra() { ll n = edgs.size(); vector<bool> done(n, false); pq_mincost pq; pq.push({0, 0}); while (!pq.empty()) { edge e = pq.top(); pq.pop(); ll cost = e.cost; int u = e.v; if (done[u]) continue; done[u] = true; if (u == n - 1) { return cost; } for (auto v : edgs[u]) { ll left = cost; ll right = LG; while (right - left >= 3) { ll t1 = left + (right - left) / 3; ll t2 = left + 2 * (right - left) / 3; double x1 = t1 + v.c + double(v.d) / (t1 + 1); double x2 = t2 + v.c + double(v.d) / (t2 + 1); if (x1 <= x2) { right = t2; } else { left = t1; } } ll nc = INF; for (ll t = max(left - 2, cost); t <= right + 2; t++) { ll x = t + v.c + v.d / (t + 1); nc = min(nc, x); } pq.push({v.v, nc}); } } return -1; } int main() { // ダイクストラで三分探索(!?) ioinit(); ll n, m; cin >> n >> m; edgcost.resize(n); edgs.resize(n); c.resize(m); d.resize(m); for (ll i = 0; i < m; i++) { ll a, b; cin >> a >> b >> c[i] >> d[i]; a--; b--; edgs[a].push_back({int(b), c[i], d[i]}); edgs[b].push_back({int(a), c[i], d[i]}); } ll ans = dijkstra(); print(ans); }
#include<bits/stdc++.h> //#include<ext/pb_ds/assoc_container.hpp> //#include<ext/pb_ds/tree_policy.hpp> //#include <ext/pb_ds/trie_policy.hpp> //using namespace __gnu_pbds; using namespace std; #define ll long long int #define ld long double #define mod 1000000007 #define inf 1e18 #define endl "\n" #define pb push_back #define vi vector<int> #define vl vector<ll> #define vs vector<string> #define pii pair<ll,ll> #define ump unordered_map #define mp make_pair #define pq_max priority_queue<ll> #define pq_min priority_queue<ll,vi,greater<ll> > #define all(n) n.begin(),n.end() #define ff first #define ss second #define mid(l,r) (l+(r-l)/2) #define bitc(n) __builtin_popcount(n) #define loop(i,a,b) for(int i=(a);i<=(b);i++) #define looprev(i,a,b) for(int i=(a);i>=(b);i--) #define iter(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) #define log(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } #define logarr(arr,a,b) for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl; #define M 1000000007 #define w(x) int x; cin>>x; while(x--) template <typename T> T gcd(T a, T b) {if (a % b) return gcd(b, a % b); return b;} template <typename T> T lcm(T a, T b) {return (a * (b / gcd(a, b)));} vs tokenizer(string str, char ch) {std::istringstream var((str)); vs v; string t; while (getline((var), t, (ch))) {v.pb(t);} return v;} void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << endl; err(++it, args...); } //typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; //typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pbtrie; void file_i_o() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } const int N = 2e5 + 5; vi v(N); class union_find { public: int *pr; int *sz; union_find(int n) { pr = new int[n + 1]; sz = new int[n + 1]; for (int i = 1; i <= n; ++i) pr[i] = i, sz[i] = 1; } int root(int i) { if (pr[i] == i) return i; return pr[i] = root(pr[pr[i]]); } int find(int i, int j) { return (root(i) == root(j)); } int un(int i, int j) { int u = root(i); int v = root(j); if (u == v) return 0; if (sz[u] < sz[v]) swap(u, v); pr[v] = u; sz[u] += sz[v]; return 1; } }; int main(int argc, char const *argv[]) { clock_t begin = clock(); file_i_o(); // Write your code here.... int n; cin >> n; vi v(n); loop(i, 0, n - 1)cin >> v[i]; union_find dsu(N); int s = 0, l = n - 1; int ans = 0; while (s < l) { int curr = dsu.un(v[s], v[l]); if (curr)ans++; s++; l--; } cout << ans << endl; #ifndef ONLINE_JUDGE clock_t end = clock(); cout << "\n\nExecuted In: " << double(end - begin) / CLOCKS_PER_SEC * 1000 << " ms"; #endif return 0; }
// I SELL YOU...! #include<iostream> #include<vector> #include<algorithm> #include<functional> #include<queue> #include<chrono> #include<iomanip> #include<map> #include<set> using namespace std; using ll = long long; using P = pair<ll,ll>; using PD = pair<double,ll>; using TP = tuple<double,ll,ll>; void init_io(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } const ll n = 30; double dist[n][n][4]; double cnt[n][n][4]; ll dx[] = {1,0,-1,0}; ll dy[] = {0,1,0,-1}; vector<ll> dijcstra(ll sx,ll sy,ll gx,ll gy, ll ADDR) { const ll INF = 1e15; vector<vector<double>> d(n,vector<double>(n, INF)); vector<vector<P>> pr(n,vector<P>(n, P(-1,-1))); priority_queue<TP,vector<TP>,greater<TP>> que; d[sx][sy] = 0; que.push(TP(0,sx,sy)); while(!que.empty()){ auto [di, x, y] = que.top(); que.pop(); if(di > d[x][y]) continue; for(int i=0;i<4;i++){ ll nx = x + dx[i]; ll ny = y + dy[i]; if(nx<0||ny<0||nx>=n||ny>=n) continue; if(d[x][y]+dist[x][y][i]+ADDR<d[nx][ny]) { d[nx][ny] = d[x][y] + dist[x][y][i] + ADDR; pr[nx][ny] = P(x,y); que.push(TP(d[nx][ny],nx, ny)); } } } vector<ll> res; while(true){ auto [prx, pry] = pr[gx][gy]; if(prx==-1) { break; } ll x = gx-prx; ll y = gy-pry; if(x==1&&y==0) res.push_back(0); if(x==0&&y==1) res.push_back(1); if(x==-1&&y==0) res.push_back(2); if(x==0&&y==-1) res.push_back(3); gx = prx; gy = pry; } reverse(res.begin(),res.end()); return res; } signed main(){ double alpha = 0.7; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ for(int k=0;k<4;k++){ dist[i][j][k] = 5000; cnt[i][j][k] = 1; } } } for(int t=0;t<1000;t++){ ll sx,sy,gx,gy; cin >> sx >> sy >> gx >> gy; ll addr = max(0, 10000 - t*10); auto route = dijcstra(sx,sy,gx,gy, addr); for(auto i: route) { if(i==0) cout << 'D'; if(i==1) cout << 'R'; if(i==2) cout << 'U'; if(i==3) cout << 'L'; } cout << endl; double result; cin >> result; result /= route.size(); ll x = sx, y = sy; for(auto i:route){ ll nx = x + dx[i]; ll ny = y + dy[i]; ll j = (i+2)%4; dist[x][y][i] = dist[x][y][i] + ((1/cnt[x][y][i]) * (result - dist[x][y][i])); dist[nx][ny][j] = dist[nx][ny][j] + ((1/cnt[nx][ny][j]) * (result - dist[nx][ny][j])); cnt[x][y][i]++; cnt[nx][ny][j]++; x = nx; y = ny; } } }
#include<bits/stdc++.h> using namespace std; #define ll long long #define dd double #define endl "\n" #define pb push_back #define all(v) v.begin(),v.end() #define mp make_pair #define fi first #define se second #define vll vector<ll> #define pll pair<ll,ll> #define fo(i,n) for(int i=0;i<n;i++) #define fo1(i,n) for(int i=1;i<=n;i++) ll mod=1000000007; ll n,k,t,m,q,flag=0; ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> // ordered_set s ; s.order_of_key(a) -- no. of elements strictly less than a // s.find_by_order(i) -- itertor to ith element (0 indexed) ll min(ll a,ll b){if(a>b)return b;else return a;} ll max(ll a,ll b){if(a>b)return a;else return b;} ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;} int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef NOOBxCODER freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else #define NOOBxCODER 0 #endif //cin>>t; t=1; while(t--){ cin>>k; cin>>n>>m; ll a[k]; fo(i,k)cin>>a[i]; ll sum=0; pll p[k]; fo(i,k){ p[i]= mp((m*a[i])%n , i); sum+= (m*a[i])%n; } //cout<<sum<<endl; sort(p,p+k); ll val = sum/n; //cout<<val; ll ans[k]; fo(i, k){ ll j = p[i].se; //cout<<j<<endl; //cout<<a[j]<<endl; if(i<k-val)ans[j]= m*a[j]/n; else ans[j] =m*a[j]/n + 1; } fo(i,k)cout<<ans[i]<<" "; } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; inline int read(){ int res=0; bool zf=0; char c; while(((c=getchar())<'0'||c>'9')&&c!='-'); if(c=='-')zf=1; else res=c-'0'; while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0'; if(zf)return -res; return res; } int mu[1000005]; bool vis[1000005]; int prime[1000005],p; inline int f(int a,int b,int d=1){ if(!a||!b){ return 0; } int n=a/d,m=b/d,t=min(n,m),ans=0; for(register int l=1,r;l<=t;l=r+1){ r=min(t,min(n/(n/l),m/(m/l))); ans+=(n/l)*(m/l)*(mu[r]-mu[l-1]); } return ans; } signed main(){ vis[1]=1;mu[1]=1; for(register int i=2;i<=1000000;i++){ if(!vis[i]){prime[++p]=i;vis[i]=1;mu[i]=-1;} for(register int j=1;j<=p;j++){ if(prime[j]*i>1000000)break; vis[prime[j]*i]=1; mu[prime[j]*i]=(i%prime[j]?-mu[i]:0); if(!(i%prime[j]))break; } mu[i]+=mu[i-1]; } int l=read(),r=read(),A=0; for(register int i=2;i<=r;++i){ int a=l/i-3; while(a==1||a*i<l){ ++a; } int b=r/i+3; while(b*i>r){ --b; } A+=f(b,b)-f(a-1,b)-f(b,a-1)+f(a-1,a-1); } printf("%lld\n",A); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define nline "\n" const ll M1=1e9+7; const ll M2=998244353; const ll N=1000005; const ll INF_MUL=1e13; const ll INF_ADD=1e18; #define f first #define s second #define pll pair<ll,ll> #ifndef ONLINE_JUDGE #define debug(x) cerr<<#x<<" "; _print(x); cerr<<nline; #else #define debug(x); #endif void _print(ll x){cerr<<x;} template<class T,class V> void _print(pair<T,V> p) {cerr<<"{"; _print(p.first);cerr<<","; _print(p.second);cerr<<"}";} template<class T>void _print(vector<T> v) {cerr<<" [ "; for (T i:v){_print(i);cerr<<" ";}cerr<<"]";} template<class T>void _print(set<T> v) {cerr<<" [ "; for (T i:v){_print(i); cerr<<" ";}cerr<<"]";} template<class T>void _print(multiset<T> v) {cerr<< " [ "; for (T i:v){_print(i);cerr<<" ";}cerr<<"]";} template<class T,class V>void _print(map<T, V> v) {cerr<<" [ "; for(auto i:v) {_print(i);cerr<<" ";} cerr<<"]";} //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- void solve(){ ll l,r,final=0; cin>>l>>r; vector<ll> ans(r+5,0),bad(r+5,0); for(ll i=r-1;i>=2;i--){ ans[i]=r/i-(l-1)/i-(i>=l); bad[i]=r/i-(l-1)/i; bad[i]=bad[i]*(bad[i]-1); ans[i]=ans[i]*(ans[i]-1); for(ll j=i+i;j<=r;j+=i){ ans[i]-=bad[j]; bad[i]-=bad[j]; } final+=ans[i]; } cout<<final; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif ll test_cases=1; //cin>>test_cases; while(test_cases--){ solve(); } /* Correct data type? Infinity? Base case? */ cerr<<"Time:"<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n"; }
//بسم الله الرحمن الرحيم #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int,int> pii; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; //using u128 = __uint128_t; #define el << '\n' #define sz(v) ((int)(v).size()) #define PI 3.141592653589793238 #define _test_ int _ ; cin >> _ ; while( _-- ) #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define file() freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout) #define pb push_back ll gcd ( ll a, ll b ) { return __gcd ( a, b );} ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) );} ll big_mod(ll base , ll power , ll mod){ ll ret=1;base%=mod;while(power){if(power&1)ret=ret*base%mod;base=base*base%mod;power>>=1;}return ret;} ll mod_inverse(ll a , ll mod ){ return big_mod(a,mod-2,mod);} ull POW(ll a , ll b){if(b==0) return 1;ull ret=1;while(b--)ret*=a;return ret;} int dx[]={0,0,+1,-1,+1,-1,-1,+1}; int dy[]={+1,-1,0,0,+1,-1,+1,-1}; // ------------------> const ll infLL = 15e17+123; const int inf = 1e9+7; const ll mod = 1e9+7; const ll mx = 1e5+123; // ------------------> void _case_() { int v,t,s,d; cin >> v >> t >> s >> d; int a=v*t ; int b=v*s; if(d<a or d>b) cout << "Yes\n"; else cout << "No\n"; } int main() { optimize(); //_test_ _case_(); return 0;// AUTHOR : NAYEMUR RAHMAN NAYEM }// [ DEPT. of CSE ; CU ; ( 19 th Batch ) ]
#include <bits/stdc++.h> using namespace std; int main() { int V,T,S,D; cin>>V>>T>>S>>D; if(V*T<=D && D<=V*S){ cout<<"No"; } else{ cout<<"Yes"; } }