code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include<bits/stdc++.h> using namespace std; using ll=long long; using uint=unsigned int; using ull=unsigned long long; const ll LL_MAX=LLONG_MAX; class union_find{ private: vector<ll> par; vector<ll> siz; public: union_find(ll n) : par(n),siz(n,1LL){ for (ll i=0;i<n;i++) par[i]=i; } ll root(ll x){ ll i=x; queue<ll> line; while(i!=par[i]){ line.push(i); i=par[i]; } ll l=line.size(); for (ll j=0;j<l;j++){ par[line.front()]=i; line.pop(); } return i; } ll size(ll x){ return siz[root(x)]; } bool unite(ll x,ll y){ x=root(x); y=root(y); if (x==y) return false; if (size(x)<size(y)){ par[x]=y; siz[y]+=siz[x]; } else{ par[y]=x; siz[x]+=siz[y]; } return true; } bool same(ll x,ll y){ if (root(x)==root(y)) return true; else return false; } }; struct In{ template<typename T> operator T(){ T x; cin >> x; return x; } }; In in; template <typename T,typename U> void forin(T* x,U n){ for (U i=0;i<n;i++) cin >> x[i]; } template <typename T> void outl(T x){ cout << x << endl; } template < > void outl<int>(int x){ printf("%d\n",x); } template < > void outl<double>(double x){ printf("%.16lf\n",x); } template < > void outl<char>(char x){ printf("%c\n",x); } template < > void outl<string>(string x){ printf("%s\n",x.c_str()); } template < > void outl<uint>(uint x){ printf("%u\n",x); } template < > void outl<ll>(ll x){ printf("%lld\n",x); } template < > void outl<ull>(ull x){ printf("%llu\n",x); } void outl(){ printf("\n"); } template <typename T> void out(T x){ cout << x << flush; } template < > void out<int>(int x){ printf("%d",x); } template < > void out<char>(char x){ printf("%c",x); } template < > void out<double>(double x){ printf("%.16lf",x); } template < > void out<string>(string x){ printf("%s",x.c_str()); } template < > void out<uint>(uint x){ printf("%u",x); } template < > void out<ll>(ll x){ printf("%lld",x); } template < > void out<ull>(ull x){ printf("%llu",x); } void outyes(){ printf("Yes\n"); } void outno(){ printf("No\n"); } void outyn(bool x){ if (x) printf("Yes\n"); else printf("No\n"); } void outsp(){ printf(" "); } template <typename T> T gcd(T x,T y){ if (y == 0) return x; return gcd(y,x%y); } template <typename T> T lcm(T x,T y){ return x*y/gcd(x,y); } template <typename T> T npr(T x,T y){ T loop=max(x-y,y),ans=1; for (T i=loop;i<=x;i++){ ans*=i; } return ans; }//xPy template <typename T> T ncr(T x,T y){ T loop=min(x,x-y),ans=npr(x,y); for (T i=1;i<=loop;i++){ ans/=i; } return ans; }//xCy template <typename T> T fac(T x){ if (x==1) return 1; return x*fac(x-1); } void div1(ll &x) { x%=1000000007; } ll mypow(ll x,ll n){ ll ans=1; for (ll i=1;i<=n;i = i<<1){ if ((n & i)== i){//ループj回目で2進表記のときにj桁目が1かどうか判定 ans*=x; } x*=x; } return ans; } ll divpow(ll x,ll n){ ll ans=1; div1(x); for (ll i=1;i<=n;i = i<<1){ if ((n & i)== i){//ループj回目で2進表記のときにj桁目が1かどうか判定 ans*=x; div1(ans); } x*=x; div1(x); } return ans; } int main(){ int n=in; if (n%100==0) outl(n/100); else outl(n/100+1); }
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n; cin>>n; cout<<(n+99)/100<<endl; return; } int main() { #ifdef bipinpathak (void)!freopen("input.txt", "r", stdin); (void)!freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(NULL); auto start=clock(); int t = 1; for(int i=0; i<t; i++) { //cout<<"Case #"<<i+1<<": "; solve(); } double used= (double) (clock()-start); used=(used*1000)/CLOCKS_PER_SEC; cerr<<fixed<<setprecision(2)<<used<<" ms"<<endl; 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 const int mod = 1e9 + 7; int dp[3][100][100]; constexpr ll modpow(ll A, ll B) { ll kotae = 1; while (B > 0) { if (B & 1) kotae = kotae * A % mod; A = A * A % mod; B >>= 1; } return kotae; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M, K; cin >> N >> M >> K; int A[100]; rep(i, N) { cin >> A[i]; } rep(i, N) dp[0][i][i] = 1; rep(i, N) dp[1][i][i] = 1; int are = modpow(2 * M, mod - 2); rep(i, M) { int x, y; cin >> x >> y; x--; y--; (dp[0][x][x] += mod - are) %= mod; (dp[0][x][y] += are) %= mod; (dp[0][y][x] += are) %= mod; (dp[0][y][y] += mod - are) %= mod; } auto mae = dp[1], ato = dp[2]; rep(i, 30) { rep(x, N) rep(y, N) { unsigned long long tmp = 0; rep(z, N) { tmp += mae[x][z] * (ll)mae[z][y]; if (!(z & 15)) tmp %= mod; } ato[x][y] = tmp % mod; } swap(mae, ato); if (K >> 29 - i & 1) { rep(x, N) rep(y, N) { unsigned long long tmp = 0; rep(z, N) { tmp += mae[x][z] * (ll)dp[0][z][y]; if (!(z & 15)) tmp %= mod; } ato[x][y] = tmp % mod; } swap(mae, ato); } } rep(i, N) { ll kotae = 0; rep(j, N) kotae += (ll)mae[i][j] * A[j] % mod; co(kotae % mod); } Would you please return 0; }
#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=1000000007,MAX=25,INF=1<<30; typedef vector<vector<ll>> mat; mat mul(mat &A, mat&B){ mat C(A.size(),vector<ll>(B[0].size())); for(int i=0;i<A.size();i++){ for(int k=0;k<B.size();k++){ for(int j=0;j<B[0].size();j++){ C[i][j]=(C[i][j]+A[i][k]*B[k][j])%mod; } } } return C; } mat pow(mat A,ll n){ mat B(A.size(),vector<ll>(A.size())); for(int i=0;i<A.size();i++){ B[i][i]=1; } while(n>0){ if(n&1) B=mul(B,A); A=mul(A,A); n/=2; } return B; } ll rui(ll a,ll b){ ll ans=1; while(b>0){ if(b&1) ans=ans*a%mod; a=a*a%mod; b/=2; } return ans; } int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); int N,M,K;cin>>N>>M>>K; mat B(N,vector<ll>(1)); for(int i=0;i<N;i++){ cin>>B[i][0]; } mat A(N,vector<ll>(N)); for(int i=0;i<N;i++) A[i][i]=1; for(int i=0;i<M;i++){ int a,b;cin>>a>>b; a--;b--; if(a==b) continue; A[a][a]-=rui(M*2,mod-2); A[b][b]-=rui(M*2,mod-2); A[a][b]+=rui(M*2,mod-2); A[b][a]+=rui(M*2,mod-2); if(A[a][a]<0) A[a][a]+=mod; if(A[b][b]<0) A[b][b]+=mod; A[a][b]%=mod; A[b][a]%=mod; } A=pow(A,K); A=mul(A,B); for(int i=0;i<N;i++) cout<<A[i][0]<<endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef set<int> si; typedef set<ll> sl; typedef queue<int> qi; typedef queue<ll> ql; typedef stack<int> sti; typedef deque<int> dqi; typedef priority_queue<int> pqi; typedef priority_queue<ll> pql; typedef deque<ll> dql; 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; typedef double dl; #define PB push_back #define F first #define S second #define MP make_pair #define el '\n' #define sl(x) (int)x.length() #define all(a) (a).begin(),(a).end() #define sz(x) (int)x.size() #define mid(l,r) ((r+l)/2) #define left(node) (node*2) #define right(node) (node*2+1) #define mx_int_prime 999999937 #define loop(i,n) for(int i=0;i<n;i++) const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const ll infLL = 9000000000000000000; #define MOD 1000000007 #define in(n) ll n;cin>>n; #define mem(a,b) memset(a, b, sizeof(a) ) #define gcd(a,b) __gcd(a,b) #define sqr(a) ((a) * (a)) #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define fraction(a) cout.unsetf(ios::floatfield); cout.precision(a); cout.setf(ios::fixed,ios::floatfield); typedef vector<int>::iterator vit; typedef set<int>::iterator sit; int dx[] = {0, 0, +1, -1}; int dy[] = {+1, -1, 0, 0}; void solve(){ } int main(){ in(n); int ans=MOD; bool pk=0; while(n--){ in(a); in(b); in(c); int ok=0; if(a<c){ pk=1; ok=b; ans=min(ok,ans); } } if(pk==0)cout<<"-1"<<el; else cout<<ans<<el; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long llp; #define mod 1000000007 #define deb(x) cerr << '\t' << "[" << #x << ": "<< x << "]\n"; #define f first #define s second #define pb push_back /* numeric_limits<llp>::max(); */ void solution(/*ll tc = 0*/); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); llp tc = 1; //cin >> tc; for (llp t = 0; t < tc; ++t) solution(/*t*/); return 0; } struct ps{ ll a, p, x; }; bool fx(struct ps a, struct ps b) { return (a.p < b.p); } void solution(/*ll tc = 0*/) { int n; cin >> n; vector<ps> arr(n); for(int i = 0; i < n; ++i) { cin >> arr[i].a >> arr[i].p >> arr[i].x; } sort(arr.begin(), arr.end(), fx); //ll ans = (ll)1e9; bool canwe = 0; for(int i = 0; i < n; ++i) { if(arr[i].x > arr[i].a) { cout << arr[i].p << '\n'; canwe = 1; break; //ans = min(ans, arr[i].p); } } if(!canwe) cout << "-1\n"; // cout << ans << '\n'; }
// Problem : D - Multiset Mean // Contest : AtCoder - AtCoder Regular Contest 104 // URL : https://atcoder.jp/contests/arc104/tasks/arc104_d // Memory Limit : 1024 MB // Time Limit : 4000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> using namespace std; int N, K; long long MOD; const long long CUTOFF = 501000; void add(long long &a, long long b){ a += b; a -= (a >= MOD ? MOD : 0); } void sub(long long &a, long long b){ a -= b; a += (a < 0 ? MOD : 0); } long long dp[2001005]; long long tmp[2001005]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> K >> MOD; dp[CUTOFF] = K+1; for(int n = 1; n<N; n++){ for(int r = 0; r<n; r++){ long long tot = 0; for(int i = r+CUTOFF; i<=2*CUTOFF; i += n){ if(i - n * (K+1) >= 0){ sub(tot, tmp[i - n * (K+1)]); } tmp[i] = dp[i]; add(tot, dp[i]); dp[i] = tot; } } } for(int n = 1; n<=N; n++){ cout << (dp[CUTOFF] + MOD - 1)%MOD << "\n"; /* for(int i = 0; i<=2*CUTOFF; i++){ cout << "idx: " << (i-CUTOFF) << " " << dp[i] << "\n"; } cout << "\n"; */ for(int r = 0; r<N-n; r++){ long long tot = 0; for(int i = r; i <= 2*CUTOFF; i += N - n){ if(i - (N - n) * (K+1) >= 0){ sub(tot, dp[i-(N-n)*(K+1)]); } sub(dp[i], tot); add(tot, dp[i]); } } /* for(int i = 0; i<=2*CUTOFF; i++){ cout << "idx: " << (i-CUTOFF) << " " << dp[i] << "\n"; } cout << "\n"; */ for(int r = 0; r<n; r++){ long long tot = 0; for(int i = 2*CUTOFF/n*n+r; i>=0; i -= n){ if(i + n * (K+1) <= 2 * CUTOFF){ sub(tot, tmp[i + n * (K+1)]); } tmp[i] = dp[i]; add(tot, dp[i]); dp[i] = tot; } } } }
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define eps 1e-30 #define rep(i,l,r) for(int i=l;i<r;i++) #define rrep(i,r,l) for(int i=r-1;i>=l;i--) #define vi vector<int> #define vvi vector<vector<int> > #define pii pair<int,int> #define all(x) (x).begin(),(x).end() #define mod 1000000007 typedef long long ll; const int maxn=2e5+5; char s[maxn]; int n,k,a[maxn]; ll d[maxn][17][2][2]; ll dfs(int cur,int st,int cnt,int up,int lead) { if(cnt>k) return 0; if(cur>n) return cnt==k&&!lead; ll& ret=d[cur][cnt][up][lead]; if(ret>=0) return ret; ret=0; int r=up?a[cur]:15; rep(i,0,r+1){ ret=(ret+dfs(cur+1,(!i&&lead)?0:st|(1<<i),(!i&&lead)?cnt:cnt+!(1&(st>>i)),up&&(i==r),lead&&(!i)))%mod; } return ret; } int main() { scanf("%s %d",s+1,&k); n=strlen(s+1); rep(i,1,n+1){ if(s[i]>='A') a[i]=s[i]-'A'+10; else a[i]=s[i]-'0'; } memset(d,-1,sizeof(d)); printf("%lld\n",dfs(1,0,0,1,1)); return 0; }
#include<bits/stdc++.h> #define ll long long #define ull unsigned long long #define ln "\n" using namespace std; //#define dbg(x) cout<<#x<<" = "<<x<<" " #define rep(i,s,n) for(ll i = (s);i<(n);++i) #define pc(x) __builtin_popcount(x) void DBG() { cerr << "]" << endl; } template<class H, class... T> void DBG(H h, T... t) { //cerr << '[' << endl; cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef _DEBUG #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) #else #define dbg(...) cerr << "[ ]" << endl #endif #define pi pair<int,int> //const int mod=998244353; void solve(){ ll n; cin>>n; string s; cin>>s; if(n==1) { cout<<1<<ln; return; } ll ans=-1; if(s[0]!=s[n-1]) cout<<1<<ln; else { char s1=s[0]; for(int i=1;i<n;i++) { if(s[i]!=s1 && s[i+1]!=s1) { ans=2; break; } } cout<<ans<<ln; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //sieve(); int test=1; // cin>>test; while(test--) solve(); return 0; }
#include<bits/stdc++.h> #define mxn 100005 #define inf 1e9 using namespace std; int n, mem[mxn][26]; char str[mxn]; int dp(int pos, int ch) { if(pos==n)return inf; if(pos==n-1 && (str[n-1]-'a')!=ch)return 1; int &ret= mem[pos][ch]; if(ret!=-1)return ret; ret= dp(pos+1, ch); if((str[pos]-'a')!=ch)ret= min(ret, 1+dp(pos+2, str[pos+1]-'a')); return ret; } int main() { scanf("%d %s", &n, str); memset(mem, -1, sizeof mem); int res= dp(1, str[0]-'a'); if(res==inf)res= -1; printf("%d\n", res); return 0; }
/* Author: Zcus Blog: https://cnblogs.com/zcus */ #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define pii pair<int, int> #define mp make_pair #define debug(x) cout << #x << " = " << x << endl #define For(i, x, y) for (int i = x; i <= y; i++) #define Rep(i, x, y) for (int i = x; i >= y; i--) #define file(FILE_NAME) freopen(FILE_NAME".in", "r", stdin), freopen(FILE_NAME".out", "w", stdout) #define filein(FILE_NAME) freopen(FILE_NAME".in", "r", stdin); #define fileout(FILE_NAME) freopen(FILE_NAME".out", "w", stdout); template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; } template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; } #define I int inline I ri() { I s = 0, w = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') w = -1; c = getchar();} while (c >= '0' && c <= '9') { s = (s << 1) + (s << 3) + (c ^ 48); c = getchar();} return s * w; } #undef I #define int long long const int maxn = 2e5 + 540; char s[maxn]; int n; int lascor, las = 0; int Sum[maxn][28]; signed main() { //file("3"); scanf("%s", s + 1); n = strlen(s + 1); int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= 26; j++) Sum[i][j] = Sum[i - 1][j]; Sum[i][s[i] - 'a' + 1]++; } las = n + 1; for (int i = n - 2; i >= 1; i--) { if (s[i] == s[i + 1]) { if (lascor != s[i]) { ans = ans + n - (i + 1); if (las && las - 1 >= i + 1) ans = ans - (Sum[las - 1][s[i] - 'a' + 1] - Sum[i + 1][s[i] - 'a' + 1]); } else if (las - 1 >= i + 1) ans = ans + max(0ll, (las - 1 - (i + 2) + 1) - (Sum[las - 1][s[i] - 'a' + 1] - Sum[i + 1][s[i] - 'a' + 1])); lascor = s[i]; las = i; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define ll long long int #define sd(x) scanf("%lld",&x) #define sdi(x) scanf("%d",&x) #define sdc(c) scanf("%c",&c) #define inf 1000000000000000000ll #define pll pair<ll,ll> #define pii pair<int,int> #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define bits(x) __builtin_popcountll(x) #define ld long double #define test() ll test; cin>>test; while(test--) #define fi first #define se second #define all(x) x.begin(),x.end() void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif clock_t time_p = clock(); void time_taken() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n"; } inline ll GCD(ll x, ll y) { if(x<y) swap(x,y); if(x==0) return y; if(y==0) return x; return GCD(x%y,y); } ll phi(ll n) { ll result = n; for (ll i = 2; i * i <= n; i++) { if(n % i == 0) { while(n % i == 0) n /= i; result -= result / i; } } if(n > 1) result -= result / n; return result; } ll power(ll x, ll n, ll mod) { ll res = 1; x %= mod; while(n) { if(n&1) { res = ((res*x)%mod+mod)%mod; } x = ((x*x)%mod+mod)%mod; n>>=1; } return res; } const int MOD = 1e9+7; inline ll add(ll x, ll y, ll MOD) { x %= MOD; y %= MOD; ll ans = (x+y)%MOD; return ans; } inline ll mul(ll x,ll y, ll MOD) { x %= MOD; y %= MOD; ll ans = ((x*y)%MOD+MOD)%MOD; return ans; } int main() { fastio; string s; cin>>s; int n = s.length(); vector<int> v(n); for(int i=0;i<n;i++) { v[i] = s[i]-'a'; } vector<int> cnt(27,0); ll res = 0; cnt[v.back()]++; for(int i=n-2;i>=0;i--) { if(v[i]==v[i+1]) { for(int j=0;j<26;j++) { if(v[i]!=j) { res += cnt[j]; cnt[v[i]] += cnt[j]; cnt[j] = 0; } } } cnt[v[i]]++; } cout<<res<<endl; time_taken(); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) long long mod = 998244353; int main(){ int h, w; cin >> h >> w; vector<vector<int>> T(h + w - 1, vector<int>(3)); rep(i,h){ rep(j,w){ char c; cin >> c; if(c == 'R') T[i + j][0] = 1; if(c == 'B') T[i + j][1] = 1; if(c == '.') T[i + j][2] = 1; } } long long ans = 1; rep(i, h + w - 1){ if(T[i][0] == 1 && T[i][1] == 1) ans *= 0; else if(T[i][0] == 1 || T[i][1] == 1) ans *= 1; else ans = ans * 2 % mod; } cout << ans; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; int N, MAX_N = 2000001, idx = 0, MAX_LOG_V = 20; vector<vector<int>> edge(MAX_N), parent(MAX_LOG_V, vector<int>(MAX_N, -1)); vector<int> tp(MAX_N), l(MAX_N), r(MAX_N), par(MAX_N, -1), depth(MAX_N, 0); vector<bool> done(MAX_N, false); void tps(int u) { done[u] = true; l[u] = idx; tp[idx] = u; idx++; rep(i, edge[u].size()) { int v = edge[u][i]; if (done[v]) continue; par[v] = u; depth[v] = depth[u] + 1; tps(v); } r[u] = idx; } int lca(int u, int v) { if (depth[u] > depth[v]) swap(u, v); rep(i, MAX_LOG_V) { if ((depth[v] - depth[u]) >> i & 1) { v = parent[i][v]; } } if (u == v) return u; for (int k = MAX_LOG_V - 1; k >= 0; k--) { if (parent[k][u] != parent[k][v]) { u = parent[k][u]; v = parent[k][v]; } } return parent[0][u]; } void lca_init() { rep(i, N) parent[0][i] = par[i]; rep(i, MAX_LOG_V - 1) { rep(j, N) { if (parent[i][j] < 0) parent[i + 1][j] = -1; else parent[i + 1][j] = parent[i][parent[i][j]]; //cout << parent[i + 1][j] << " "; } //cout << "\n"; } } int main() { scanf("%d", &N); vector<ll> u(N - 1), v(N - 1), w(N - 1), dist(N, 0); rep(i, N - 1) scanf("%lld %lld %lld", &u[i], &v[i], &w[i]); map<pair<int, int>, ll> edgew; rep(i, N - 1) { edge[u[i] - 1].push_back(v[i] - 1); edge[v[i] - 1].push_back(u[i] - 1); edgew[make_pair(u[i] - 1, v[i] - 1)] = w[i]; edgew[make_pair(v[i] - 1, u[i] - 1)] = w[i]; } tps(0); //rep(i, N) cout << tp[i] << " "; cout << "\n"; vector<int> g(N); rep(i, N) g[tp[i]] = i; //rep(i, N) cout << g[i] << " "; cout << "\n"; //rep(i, N) cout << depth[i] << " "; cout << "\n"; rep(i, N - 1) { int x = tp[i + 1], p = par[x]; dist[x] = dist[p] ^ edgew[make_pair(x, p)]; } //rep(i, N) cout << dist[i] << " "; cout << "(dist)\n"; ll ans = 0, MOD = 1e9 + 7; rep(i, 60) { ll count = 0; rep(j, N) { count += (dist[j] >> i) & 1; } ans = (ans + (1LL << i) % MOD * count % MOD * (N - count)) % MOD; //cout << ans << endl; } printf("%lld\n", ans); }
#include <map> #include <set> #include <stack> #include <queue> #include <deque> #include <cmath> #include <ctime> #include <bitset> #include <vector> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #define fi first #define se second #define il inline #define Ld double #define pc putchar #define rg register #define ll long long #define lll __int128 #define pb push_back #define mp make_pair #define It ::iterator #define W(p) while(p--) #define pll pair<ll, ll> #define pli pair<ll, int> #define pil pair<int, ll> #define pii pair<int, int> #define ull unsigned long long #define all(x) x.begin(), x.end() #define def(N, K, b) const K N = b; #define FOR(i, b, s) for(int i = b; i < s; ++i) #define rep(i, b, s) for(int i = b; i <= s; ++i) #define per(i, b, s) for(int i = b; i >= s; --i) #define FOR_(i, b, s) for(int i = b; i > s; --i) #define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); namespace IO { const int SIZE = (1 << 20) + 1; char ibuf[SIZE], *iS, *iT, obuf[SIZE],*oS = obuf, *oT = obuf + SIZE - 1; char _st[55]; int _qr = 0; inline char gc() { return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++) : *iS++); } inline void qread() {} template<class T1, class ...T2> inline void qread(T1 &IEE, T2&... ls) { register T1 __ = 0, ___ = 1; register char ch; while(!isdigit(ch = gc())) ___ = (ch == '-') ? -___ : ___; do { __ = (__ << 1) + (__ << 3) + (ch ^ 48); }while(isdigit(ch = gc())); __ *= ___; IEE = __; qread(ls...); return ; } template<class T> inline void QreadArr(T Begin, T End) { while(Begin != End) { qread(*Begin); ++Begin; } } inline void flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; return ; } inline void putc_(char _x) { *oS++ = _x; if(oS == oT) flush(); } inline void qwrite() {} template<class T1, class ...T2> inline void qwrite(T1 IEE, T2... ls) { if(!IEE) putc_('0'); if(IEE < 0) putc_('-'), IEE = -IEE; while(IEE) _st[++_qr] = IEE % 10 + '0', IEE /= 10; while(_qr) putc_(_st[_qr--]); qwrite(ls...); return ; } template<class T> inline void WriteArr(T Begin, T End) { const char Kg = ' ', Edl = '\n'; while(Begin != End) { qwrite(*Begin); ++Begin; putc_(Kg); } putc_(Edl); } struct Flusher_{ ~Flusher_() { flush(); } } io_flusher; } using namespace IO; using namespace std; template<class T1, class T2> T1 Min(const T1 x, const T2 y) { return x > y ? y : x; } template<class T1, class T2> T1 Max(const T1 x, const T2 y) { return x > y ? x : y; } template<class T1, class T2> void To_max(T1 &x, const T2 y) { x < y ? x = y : x = x; } template<class T1, class T2> void To_min(T1 &x, const T2 y) { x > y ? x = y : x = x; } il ll qpow(ll n, ll base, ll mod = 1e18) { ll ret = 1; while(n) { if(n & 1) ret = ret * base % mod; base = base * base % mod; n >>= 1; } return ret % mod; } il ll gcd(ll x, ll y) { return !y ? x : gcd(y, x % y); } il ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } //header def(N, int, 105); int n, m, k, mx; int a[N], b[N], c[N], d[N]; bool has[N]; void dfs(int st) { if(st > k) { int cnt = 0; rep(i, 1, m) { if(has[a[i]] && has[b[i]]) ++cnt; } To_max(mx, cnt); return ; } bool k = has[c[st]]; has[c[st]] = true; dfs(st + 1); has[c[st]] = k; k = has[d[st]]; has[d[st]] = true; dfs(st + 1); has[d[st]] = k; } int main() { qread(n, m); rep(i, 1, m) qread(a[i], b[i]); qread(k); rep(i, 1, k) qread(c[i], d[i]); dfs(1); printf("%d\n", mx); return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); int N, M; cin >> N >> M; vector<int> A(M), B(M); for(int i = 0; i < M; i++){ cin >> A[i] >> B[i]; A[i]--, B[i]--; } int K; cin >> K; vector<int> C(K), D(K); for(int i = 0; i < K; i++){ cin >> C[i] >> D[i]; C[i]--, D[i]--; } vector<bool> ball; int ans = 0; for(int bit = 0; bit < (1<<K); bit++){ ball.assign(N, false); for(int i = 0; i < K; i++){ if(bit & (1<<i)) ball[C[i]] = true; else ball[D[i]] = true; } int cnt = 0; for(int i = 0; i < M; i++){ if(ball[A[i]] && ball[B[i]]) cnt++; } ans = max(ans, cnt); } cout << ans << '\n'; return 0; }
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<cassert> #include<complex> #include<numeric> #include<array> #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n"); #define all(v) (v).begin(),(v).end() #define debug(x) cout << #x << ": " << x << '\n'; #define degreeToRadian(deg) (((deg)/360)*2*M_PI) #define radianTodegree(rad) (((rad)/2/M_PI)*360) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; using ll = long long; using P = pair<int,int>; using PL = pair<ll, ll>; const ll INF = 1LL<<60; const int MOD = 1e9 + 7; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; struct UnionFind { int n; vector<int> a; vector<int> sz; UnionFind(int _n) : n(_n), a(_n), sz(_n, 1) { for(int i = 0; i < _n; i++) a[i] = i; } int root(int x) { if (a[x] == x) return x; return a[x] = root(a[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; if (sz[rx] < sz[ry]) swap(rx, ry); sz[rx] += sz[ry]; a[ry] = rx; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } int size(int x) { return sz[root(x)]; } map<int, vector<int>> groups() { map<int, vector<int>> group; rep (i, n) root(i); rep (i, n) group[a[i]].push_back(i); return group; } }; int main() { //cin.tie(0);ios::sync_with_stdio(false); //cout << fixed << setprecision(15); int N, M; cin >> N >> M; UnionFind uf(N); vector<int> a(N), b(N); rep (i, N) cin >> a[i]; rep (i, N) cin >> b[i]; rep (i, M) { int c, d; cin >> c >> d; --c; --d; uf.unite(c, d); } for (auto v : uf.groups()) { ll x = 0, y = 0; for (auto vv : v.second) { x += a[vv]; y += b[vv]; } if (x == y) continue; cout << "No" << endl; return 0; } cout << "Yes" << endl; return 0; }
#include <iostream> #include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define MAX 205 #define MOD 998244353 #define INF 1e15 #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pi 3.14159265358979323846 #define Q ll MAXTEST; cin >> MAXTEST; for(ll TEST=1;TEST<=MAXTEST;TEST++) #define endl "\n" #define coutyes cout << "Yes\n"; #define coutno cout << "No\n"; #define flush fflush(stdout); #define fixedprec cout << fixed << setprecision(18); int main(){ fast ll n,m; cin >> n >> m; ll b[m+1]; for(ll i=1;i<=m;i++){ cin >> b[i]; } if(!m){ cout << 1 << endl; return 0; } sort(b+1,b+m+1); vector<ll> a; for(ll i=1;i<=m;i++){ ll tmp; if(i==1){ tmp = b[i]-1; } else{ tmp = b[i]-b[i-1]-1; } if(tmp>0){ a.push_back(tmp); } } if(n-b[m]>0){ a.push_back(n-b[m]); } ll n1 = a.size(); ll ans = 0; if(!n1){ cout << 0 << endl; return 0; } sort(a.begin(),a.end()); for(ll i=0;i<n1;i++){ ll tmp = a[i]/a[0]; if(a[i]%a[0]){ tmp++; } ans+=tmp; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll a, b; cin >> b >> a; ll m = 2*b+100; ll d = m-a; cout << d << endl; return 0; }
#include <bits/stdc++.h> using namespace std; /* 提出前に確認! - 配列は+10ぐらい余分にとっておく - setとmultisetを間違えない */ /* デバッグ時にチェック! - RE 配列の取りうる最大値、最小値を**すべて**チェックする */ int main(void) { long long n, k; cin >> n >> k; long long ans = 0; for (int B = 2; B <= 2 * n; B++) { if (2 <= B + k && B + k <= 2 * n) { long long A = B + k; ans += (B / 2 * 2 - (B % 2 == 0) - 2 * max(0LL, B - n - 1)) * (A / 2 * 2 - (A % 2 == 0) - 2 * max(0LL, A - n - 1)); } } cout << ans << endl; return (0); }
#include<iostream> #include<string> #include<vector> #include<algorithm>//sort,reverse #include<utility>//pair #include<queue>//queue,priority_queue #include<deque>//double_ended queue #include<map>//map using namespace std; typedef long long LL; typedef pair<LL,LL> P;//Pでpair<-,->を表す。 const LL MAX=2000010; const LL MOD=1000000007; typedef map<LL,LL>::iterator Itr; /*ここから*/ int V;//頂点の個数 vector<int> e[200010];//iから出る辺 vector<int> E[200010]; int t[200010];//親情報の記録媒体 //すでにある辺と頂点の情報から木の作成 void Tree(int s){//sは一番根元 for(int i=1;i<=V;i++){ t[i]=i;//初期情報 } queue <int> q; q.push(s); while(!q.empty()){ int from; from=q.front(); q.pop(); while(!e[from].empty()){ int to; to=e[from].back(); e[from].pop_back(); if(to!=t[from]){ t[to]=from; q.push(to); } } } } int a[200010]; int b[200010]; int c[200010]; int flg[200010]; void C_tree(int s){ int S=e[s].size(); //cout<<s<<S<<endl; if(S==1&&e[s][0]==t[s]){ //cout<<'x'<<endl; a[s]=1; b[s]=1; c[s]=0; flg[s]=1; } else{ //cout<<'y'<<endl; int x1=0; int x2=0; int cnt=0; vector<int> y; for(int i=0;i<S;i++){ int x=e[s][i]; //cout<<s<<' '<<x<<endl; if(x!=t[s]){ if(flg[x]==0){C_tree(x);/*cout<<x<<' '<<a[x]<<' '<<b[x]<<' '<<c[x]<<endl;*/} if(a[x]==0){ if(b[x]>c[x]){ b[s]=b[s]+c[x]; c[s]=c[s]+c[x]; x1=x1+b[x]-c[x]; } else{ b[s]=b[s]+b[x]; c[s]=c[s]+b[x]; x2=x2+c[x]-b[x]; } } else{ cnt++; b[s]=b[s]+b[x]; c[s]=c[s]+b[x]; y.push_back(c[x]-b[x]); } } } flg[s]=1; b[s]=b[s]+1; if(cnt%2==0){a[s]=1;} c[s]=c[s]+x2; if(a[s]==0){c[s]=c[s]+x1;} else{b[s]=b[s]+x1;} sort(y.begin(),y.end()); reverse(y.begin(),y.end()); int SS=y.size(); int Cnt=0; for(int i=0;i<SS;i++){ if(Cnt==0){ c[s]=c[s]+y[i]; } else{ b[s]=b[s]+y[i]; } Cnt=1-Cnt; } } } /*ここまで*/ int main() { //基本用法 cin>>V; for(int i=2;i<=V;i++){ int A; cin>>A; e[i].push_back(A); e[A].push_back(i); } for(int i=0;i<=V;i++){ E[i]=e[i]; } Tree(1); for(int i=0;i<=V;i++){ e[i]=E[i]; } /*for(int i=1;i<=V;i++){ cout<<t[i]<<endl; }*/ for(int i=0;i<=V;i++){ a[i]=0; b[i]=0; c[i]=0; flg[i]=0; } C_tree(1); /*for(int i=1;i<=V;i++){ cout<<a[i]<<' '<<b[i]<<' '<<c[i]<<endl; }*/ cout<<b[1]<<endl; return 0; }
#include <bits/stdc++.h> #define arr array #define pb push_back #define fs first #define sc second #define eb emplace_back #define vt vector #define all(x) (x).begin(), (x).end() #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) using namespace std; typedef long long ll; const int maxn=1e5; const ll MAXLL=9223372036854775807; vt<int> adj[maxn+10]; vt<bool> vs(maxn+10, false); vt<int> cnt(maxn, 0), a(maxn), ans; void dfs(int u){ vs[u]=true; cnt[a[u]]++; if (cnt[a[u]]==1) ans.pb(u); for (auto v:adj[u]){ if (vs[v]) continue; dfs(v); } cnt[a[u]]--; } void solve(){ int n; cin >> n; rep(i, 0, n) cin >> a[i]; rep(i, 0, n-1){ int x, y; cin >> x >> y, --x, --y; adj[x].pb(y); adj[y].pb(x); } dfs(0); sort(all(ans)); for (auto i:ans) cout << i+1 << endl; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }
#include<bits/stdc++.h> using namespace std; int main(){ int n,w,c=0; cin>>n>>w; int ans=0; while(ans<=n){ ans+=w; c++; } cout<<c-1; }
#include<bits/stdc++.h> using namespace std; int main() { int n, w; cin >> n >> w; cout << n / w; return 0; }
// AtCoder Templete #include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n) - 1; i >= 0; i--) #define loop(i, r, n) for (int i = (r); i < (n); i++) #define lloop(i, r, n) for (int i = (r) - 1; i >= 0; i--) #define all(in) in.begin(),in.end() #define pb push_back #define fi first #define se second #define re resize #define as assign #define cl clear template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } using ui = unsigned int; using ll = long long; using ull = unsigned long long; using dd = double; using ldd = long double; using pii = pair<int,int>; using pll = pair<ll,ll>; using pdd = pair<dd,dd>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vb = vector<bool>; using vs = vector<string>; using vdd = vector<dd>; using vldd = vector<ldd>; using pq = priority_queue<int, vector<int>, less<int>>; // 降順に取り出す using pqq = priority_queue<int, vector<int>, greater<int>>; // 昇順に取り出す int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }; int dy[8] = { 0, 1, 0, -1, 1, -1, 1, -1 }; const ll MOD = 1e9+7; // const ll MOD = 998244353; const int INF = 1e9; const ll inf = 4e18; const int MAX = 300300; long long fac[MAX], finv[MAX], inv[MAX]; 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 ) % MOD; finv[i] = finv[i-1] * inv[i] % MOD; } } long long COM(int n, int k){ if (n < 0 || k < 0 || n < k) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } long long PER(int n, int k) { if (n < 0 || k < 0 || n < k) return 0; return fac[n] * finv[n - k] % MOD; } ll modpow(ll a, ll n, ll p) { ll res = 1; while (n) { if (n & 1) res = res * a % p; a = a * a % p; n >>= 1; } return res; } ll modinv(ll a, ll p) { return modpow(a, p-2, p); } vector<pair<ll,ll>> prime(ll n) { vector<pair<ll,ll>> res; for (ll i = 2; i * i <= n; i++) { if (n % i != 0) continue; ll count = 0; while (n % i == 0) { count++; n /= i; } res.push_back( make_pair(i,count) ); } if (n != 1) res.push_back( make_pair(n,1) ); return res; } int n; vvi g; vi path; vi check; vi ans; int num; pii dfs1(int v, int p) { pii res = pii(0,v); for ( auto nv : g[v] ) if ( nv != p ) { auto ch = dfs1(nv, v); ch.fi++; chmax( res, ch ); } return res; } bool dfs2(int v, int p, int t) { bool ch = false; if ( v == t ) ch = true; for ( auto nv : g[v] ) if ( nv != p && dfs2(nv, v, t) ) ch = true; if ( ch || v == t ) path.pb(v); return ch; } void dfs3(int v, int p) { ans[v] = ++num; for ( auto nv : g[v] ) if ( nv != p && nv != check[v] ) dfs3(nv, v); if ( check[v] >= 0 ) dfs3(check[v], v); ++num; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); // cout << fixed << setprecision(10) << << endl; COMinit(); /* write code under here */ cin >> n; g.re(n); rep(i,n-1) { int s, t; cin >> s >> t; s--; t--; g[s].pb(t); g[t].pb(s); } auto p = dfs1(0, -1); auto q = dfs1(p.se, -1); dfs2(p.se, -1, q.se); reverse(all(path)); check.as(n,-1); rep(i,(int)path.size()) if ( i ) check[ path[i-1] ] = path[i]; ans.as(n,-1); num = 0; dfs3(p.se, -1); for ( auto v : ans ) cout << v << " "; cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int O = 2e5 + 1; int t = 1; vector <int> c, dp, g[O], Max; int dfs(int u, int par = 0){ Max[u] = 1; for (int v : g[u]){ if (v == par) continue; dp[v] = dp[u] + 1; Max[u] = max(Max[u], dfs(v, u) + 1); } return Max[u]; } void dfs1(int u, int par = 0){ c[u] = t; vector <pair <int, int>> m; for (int v : g[u]){ if (v == par) continue; m.push_back({Max[v], v}); } sort(m.begin(), m.end()); for (pair <int, int> v : m){ t += 1; dfs1(v.second, u); t += 1; } } main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; c.resize(n + 1); dp.resize(n + 1); Max.resize(n + 1); for (int i = 1; i < n; ++ i){ int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } dfs(1); int compare = 0; int root = 1; for (int i = 1; i <= n; ++ i){ if (dp[i] > compare){ compare = dp[i]; root = i; } } dfs(root); dfs1(root); for (int i = 1; i <= n; ++ i) cout << c[i] << " "; }
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include<stdio.h> #include<iostream> #include<vector> #include<algorithm> #include<string> #include<string.h> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define NDEBUG #define eprintf(...) do {} while (0) #endif #include<cassert> using namespace std; typedef long long LL; typedef vector<int> VI; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i) template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; } template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; } #define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0) int N, M; vector<pair<int, int> > G[100011]; VI que; bool vis[100011]; int ans[100011]; void MAIN() { scanf("%d%d", &N, &M); REP (i, M) { int x, y, c; scanf("%d%d%d", &x, &y, &c); x--; y--; G[x].emplace_back(y, c); G[y].emplace_back(x, c); } que.push_back(0); vis[0] = true; ans[0] = 1; REP (i, N) { int v = que[i]; EACH (e, G[v]) if (!vis[e->first]) { int w = e->first; vis[w] = true; que.push_back(w); if (ans[v] == e->second) { ans[w] = ans[v] + 1; if (ans[w] > N) ans[w] = 1; } else { ans[w] = e->second; } } } REP (i, N) printf("%d\n", ans[i]); } int main() { int TC = 1; // scanf("%d", &TC); REP (tc, TC) MAIN(); return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define rep(i,N) for(int i = 0;i < N;++i) #define rep1(i,N) for(int i = 1;i < N;++i) #define co(x) cout << x << endl #define cosp(x) cout << x << " " using ll = long long; using ull = unsigned long long; int sub(int N){ vector<char>n; string c = to_string(N); for(int i = 0;i < c.length();i++) n.push_back(c[i]); sort(n.begin(),n.end()); int a = 0,b = 0; for(int i = 0;i < n.size();i++){ a += (int)n[i] - '0'; if(i != n.size()-1) a *= 10; } reverse(n.begin(),n.end()); for(int i = 0;i < n.size();i++){ b += (int)n[i] - '0'; if(i != n.size()-1) b *= 10; } a = b-a; return a; } int main(){ int N; int K; cin >> N >> K; int a = N; rep(i,K){ a = sub(a); } co(a); }
/* これを入れて実行 g++ code.cpp ./a.out */ #include <iostream> #include <cstdio> #include <stdio.h> #include <vector> #include <string> #include <cstring> #include <queue> #include <deque> #include <stack> #include <algorithm> #include <utility> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <cmath> #include <math.h> #include <tuple> #include <iomanip> #include <bitset> #include <functional> #include <cassert> #include <random> #define all(x) (x).begin(),(x).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; typedef long double ld; int dy4[4] = {-1, 0, +1, 0}; int dx4[4] = {0, +1, 0, -1}; int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const long long INF = 1LL << 61; const ll MOD = 1e9 + 7; bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){ return f.second > s.second; } ll gcd(ll a, ll b){ if (b == 0)return a; return gcd(b, a % b); } ll lcm(ll a, ll b){ return a / gcd(a, b) * b; } ll conbinationMemo[201][12]; void cmemoInit(){ rep(i, 201){ rep(j, 12){ conbinationMemo[i][j] = -1; } } } ll nCr(ll n, ll r){ if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r]; if(r == 0 || r == n){ return 1; } else if(r == 1){ return n; } return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1)); } ll nPr(ll n, ll r){ r = n - r; ll ret = 1; for (ll i = n; i >= r + 1; i--) ret *= i; return ret; } //-----------------------ここから----------- int main(void){ ld n; cin >> n; ld x0, y0, xh, yh; cin >> x0 >> y0 >> xh >> yh; pair<ld, ld> cent = {(x0 + xh) / 2.0, (y0 + yh) / 2.0}; ld xz, yz; xz = x0 - cent.first; yz = y0 - cent.second; ld deg = atan2(yz, xz); deg += (2.0 * M_PI) / n; ld d = sqrt(xz * xz + yz * yz); pair<ld,ld> ans = {cos(deg) * d, sin(deg) * d}; ans.first += cent.first; ans.second += cent.second; cout << fixed << setprecision(10) << ans.first << " " << ans.second << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) #define all(v) (v).begin(), (v).end() using ll = long long; using P = pair<ll,ll>; using vi = vector<int>; const ll INF = 1009009009009009009; int n; double PI = acos(-1); int main(){ cin >> n; double x,y; cin >> x >> y; complex<double> c0(x,y); cin >> x >> y; complex<double> c2(x,y); complex<double> center = (c0+c2)/2.0; complex<double> rot(cos(2*PI/n),sin(2*PI/n)); complex<double> r = ((c0-c2)/2.0) * rot; complex<double> ans = center + r; printf("%.12f %.12f\n",ans.real(),ans.imag()); }
#include <bits/stdc++.h> /* // using ASL (use make) #include <atcoder/all> using namespace atcoder; */ #define ALL(obj) begin(obj), end(obj) #define debug(x) cerr << #x << ": " << x << '\n' using namespace std; // 1次元 vector print template <class T> ostream &operator<<(ostream &s, vector<T> vec) { for (int i = 0; i < (int)vec.size(); ++i) { if (i > 0) { s << " "; } s << vec[i]; } return s << endl; } // 2次元 vector print template <class T> ostream &operator<<(ostream &s, vector<vector<T>> vec2) { for (int i = 0; i < (int)vec2.size(); ++i) { s << vec2[i]; } return s; } template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } using ll = long long; using ull = unsigned long long; const int INF = 1e9; // const int MOD = 1e9 + 7; int main() { int x; cin >> x; cout << max(x, 0) << endl; }
//Author : Prakhar Asaiya #include<bits/stdc++.h> using namespace std; #define REP(i,a,b) for(ll i = a; i < b; ++i) #define REPN(i,a,b) for(ll i = a; i <= b; ++i) #define REPV(i,a,b) for(ll i = a; i >= b; --i) #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 with_tests int t; cin>>t; while(t--){ solve(); } #define without_tests solve(); #define all(x) (x).begin(), (x).end() #define ll long long #define INF 100000000 #define ff first #define ss second #define max(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; }) #define min(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; }) const int M=1e9+7; void solve() { int n; cin>>n; if(n < 0) cout<<"0"; else cout<<n; } int main() {/* #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #*/ ios_base::sync_with_stdio(0); cin.tie(NULL); //with_tests; without_tests; return 0; }
/* "An anomaly, I'm Muhammad Ali Cause I know one day I'm gonna be the" - Greatest, Eminem */ #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long int ll; #define ff first #define Shazam ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define ss second #define all(c) c.begin(),c.end() #define endl "\n" #define test() int t; cin>>t; while(t--) #define fl(i,a,b) for(int i = a ; i <b ;i++) #define get(a) fl(i,0,a.size()) cin>>a[i]; #define pra(a) fl(i,0,a.size()) cout<<a[i]<<" "; cout<<endl; #define pr(a,n) fl(i,0,n) cout<<a[i]<<" "; cout<<endl; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const ll INF = 2e18; const int inf = 2e9; const int mod1 = 1e9 + 7; int main(){ Shazam; int n; cin >> n; vector<ll> a(n); get(a); unordered_map<ll, ll> dp; int lo = *min_element(all(a)); for(ll x : a){ for(ll i = 1; i * i <= x && i < lo; i++){ if(x % i == 0){ dp[i] = __gcd(dp[i], x); if(x / i != i && x / i < lo){ dp[x / i] = __gcd(dp[x / i], x); } } } } int ans = 1; for(auto pp : dp){ ans += (pp.ff == pp.ss); } cout << ans << endl; return 0; }
// Problem: A - Long Common Subsequence // Contest: AtCoder - AtCoder Grand Contest 052 // URL: https://atcoder.jp/contests/agc052/tasks/agc052_a // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include<bits/stdc++.h> using namespace std; #define int long long int mod=1000000007; #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define lb lower_bound #define ub upper_bound #define f first #define s second #define resz resize #define sz(x) int((x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define F0R(i, a) for (int i = 0; i < (a); i++) #define FORd(i, a, b) for (int i = (b)-1; i >= (a); i--) #define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--) #define trav(a, x) for (auto &a : x) void solve() { int n; cin>>n; string a,b,c; cin>>a>>b>>c; for(int i=0;i<n;i++) { cout<<"0"; } for(int i=0;i<n;i++) { cout<<"1"; } cout<<"0"<<endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t=1; cin>>t; while(t--) solve(); }
#include <bits/stdc++.h> #define rep(i,n) for (int i=0; i<n; i++) #define ll long long #define VV(t) vector<vector<t>> using namespace std; using Graph = VV(int); const int INF = 1<<29; int factorial(int n) { if (n<=1) return 1; else return n*factorial(n-1); } int main() { int N; cin >> N; Graph G(N, vector<int>(N, INF)); rep(i, N) { rep(j, N) { char c; cin >> c; if (c == '1') G[i][j] = 1; } G[i][i] = 0; } rep(k, N) { rep(i, N) { rep(j, N) { G[i][j] = min(G[i][j], G[i][k] + G[k][j]); } } } double v = 0; rep(i, N) { int nonInf = 0; rep(j, N) if (G[j][i] < INF/2) nonInf += 1; v += (double)1 / nonInf; } cout << fixed << setprecision(20) << v << endl; }
#include <bits/stdc++.h> using namespace std; #pragma optimize("-O3") #define int long long int #define f first #define s second #define pb push_back #define endl '\n' #define T long double vector<vector<int>>adj; bool vis[105]; int cnt[105]; void dfs(int v){ vis[v]=1; cnt[v]++; for(auto u:adj[v]){ if(vis[u]){ continue; } dfs(u); } } main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin>>n; char arr[n][n]; adj.resize(n+1); for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ cin>>arr[i][j]; if(arr[i][j]=='1'){ adj[i+1].pb(j+1); } } } for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ vis[j]=0; } dfs(i); } T ans=0; for(int i=1; i<=n; i++){ ans=ans+(1.0/cnt[i]); } cout<<setprecision(20)<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; ll a[n]; for(int i=0; i<n; i++) cin >> a[i]; sort(a, a+n); ll ans=0, fs=0; for(int i=1; i<n; i++) { fs += abs(a[0] - a[i]); } ans = fs; for(int i=1; i < n; i++) { ll d = abs(a[i] - a[i-1]); fs = fs - (d * (n-i)); ans += fs; } cout << ans << endl; }
#include <bits/stdc++.h> using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; constexpr int P = 998244353; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int N; std::cin >> N; std::vector<int> a(N); for (int i = 0; i < N; i++) std::cin >> a[i]; std::sort(a.begin(), a.end()); int ans = 0, sum = 0; for (int i = 0; i < N; i++) { ans += (i64)a[i] * a[i] % P; if (ans >= P) ans -= P; } for (int i = 0; i < N; i++) { ans += (i64)a[i] * sum % P; if (ans >= P) ans -= P; sum *= 2; if (sum >= P) sum -= P; sum += a[i]; if (sum >= P) sum -= P; } std::cout << ans << "\n"; return 0; }
#pragma warning(disable:4996) #pragma comment(linker, "/STACK:336777216") #pragma GCC optimize("Ofast") #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> using namespace std; using namespace __gnu_pbds; typedef long long ll; #define int long long int typedef complex<long double> cd; const long double pi=acos(-1); typedef double db; typedef long double ldb; typedef pair <int,int> pii; typedef pair <db,db> pdd; typedef vector<int> vi; typedef vector<vector<int> > matrix; #define m1 make_pair #define pb push_back #define flush fflush(stdout) #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define reset(x,v) memset(x,v,sizeof(x)) #define fi first #define se second #define endl "\n" #define debug(x) (cerr << #x << ": " << x << "\n") #define setbits(x) __builtin_popcount(x) #define setbitsll(x) __builtin_popcountll(x) #define all(x) x.begin(),x.end() #define pii pair<int,int> inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);} inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;} const double EPS = 1e-9; const ll MOD =998244353; const ll hell=1000000007; const int INF = 1e18; const ll LL_INF = 0x3f3f3f3f3f3f3f3f; template<typename T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; auto seed = chrono::high_resolution_clock::now().time_since_epoch().count(); std::mt19937 rng(seed); double startTime; double getCurrentTime() { return ((double)clock() - startTime) / CLOCKS_PER_SEC; } const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 }; const int N=200005; void solve() { string s; cin>>s; int n=s.length(); int f[10]={0}; for(int i=0;i<n;i++) f[s[i]-'0']++; if(n==1) { if(s[0]=='8') { cout<<"Yes"<<endl; } else cout<<"No"<<endl; return; } if(n==2) { int vl=s[0]-'0'; vl=vl*10+s[1]-'0'; if(!(vl%8)) { cout<<"Yes"<<endl; return; } vl=s[1]-'0';vl=vl*10+s[0]-'0'; if(!(vl%8)) { cout<<"Yes"<<endl; return; } cout<<"No"<<endl; return; } for(int i=8;i<1000;i+=8) { int x=i;vi ve; while(x>0) { ve.pb(x%10); x=x/10; } while(ve.size()<3) ve.pb(0); int pos=1;vi to; for(int j=0;j<ve.size();j++) { if(f[ve[j]]) { f[ve[j]]--; to.pb(ve[j]); } else {pos=0; break; } } if(pos) { cout<<"Yes"<<endl; return; } for(int j:to) f[j]++; } cout<<"No"<<endl; } int32_t main() { IOS; int t; t=1; //cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s, ans = "No"; int slen; int num[10] = {}, dig[10] = {}, tem; bool flg; cin >> s; slen = s.size(); for ( int i = 0; i < slen; i++ ) { num[s[i] - '0'] ++; } for ( int i = 0; i < 1000; i+=8 ) { tem = i; for ( int j = 0; j < min(3, slen); j++ ) { dig[tem % 10] ++; tem /= 10; } flg = true; for ( int j = 0; j < 10; j++ ) { if ( num[j] < dig[j] ) { flg = false; } } if ( flg ) { ans = "Yes"; } for ( int j = 0; j < 10; j++ ) { dig[j] = 0; } } cout << ans << endl; return (0); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int,int> pi; typedef pair<ll,ll> pl; #define F first #define S second #define endl '\n' #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() #ifdef dremix #define p(x) cerr<<#x<<" = "<<x<<endl; #define p2(x,y) cerr<<#x<<" , "<<#y<<" = "<<x<<" , "<<y<<endl; #define pp(x) cerr<<#x<<" = ("<<x.F<<" , "<<x.S<<")"<<endl; #define pv(x) cerr<<#x<<" = {";for(auto u : x)cerr<<u<<", ";cerr<<"}"<<endl; #define ppv(x) cerr<<#x<<" = {";for(auto u : x)cerr<<u.F<<"-"<<u.S<<", ";cerr<<"}"<<endl; #else #define p(x) #define p2(x,y) #define pp(x) #define pv(x) #define ppv(x) #endif #define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr); const int maxp = 22; const ld EPS = 1e-18; const ll INF = 2e18; const int MOD = 1e9+7; const int N = 2e5+1; int main(){ fastio int n; int i; cin>>n; map<int,int> cnt; for(i=0;i<n;i++){ int x; cin>>x; for(int j=2;j*j<=x;j++){ if(x%j)continue; cnt[j]++; while(x%j==0){ x/=j; } } if(x>1) cnt[x]++; } int ans = 0,idx; for(auto x : cnt){ if(x.S > ans){ ans = x.S; idx = x.F; } } cout<<idx; }
#include<bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; vector<int> A(N); for(int i = 0; i < N; i++){ cin >> A.at(i); } int ans = 0, rres = 0; for(int i = 2; i < 1001; i++){ int res = 0; for(int j = 0; j < N; j++){ if(A.at(j) % i == 0){ res++; } } if(rres <= res){ ans = i; rres = res; } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; const int mod = 998244353; //const long long inf = 1e15; //const double Pi = acos(-1.0); typedef long long ll; typedef vector<int> vi; typedef vector<long long> vll; #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define sortall(x) sort(all(x)) #define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++) #define lc cout<<"\n" #define print2d(dp,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cerr<<dp[i][j]<<" ";cerr<<"\n";} ll solve(ll n,ll i){ if((i-2)<n){ return (i-1); }else{ return (2*n-i+1); } } int main(){ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); int tt=1; //cin>>tt; while(tt--){ ll n,k; cin>>n>>k; k=abs(k); ll ans =0; rep(i,k+2,2*n+1){ ans += solve(n,i)*solve(n,i-k); } cout<<ans; } }
#include <bits/stdc++.h> #include <cmath> #include <algorithm> #include <vector> #include <string> using namespace std; #define rep(i, n) for (long long int i = 0; i < (n); i++) #define MOD 1000000007 typedef long long ll; typedef pair<ll, ll> P; int INF = 100000000; ll x[1000], y[1000], p[1000]; int main() { ll n, x = 100000000, k, ans = 0, count = 0, j, i; ll t[8][8]; bool found = false; cin >> n >> k; rep(i, n) { rep(j, n) { cin >> t[i][j]; } } vector<ll> p(n); rep(i, n) p[i] = i+1; do { ll len = t[0][p[0]]; rep(i, n - 2) len += t[p[i]][p[i + 1]]; len += t[p[n - 2]][0]; if (len == k) ans++; } while (next_permutation(p.begin(), p.end())); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; 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; } // a= modpow(10, n, k) ; // 10^nのmod k を出す int main() { long b,a,n,m,k,r,ans; ans=0; r=998244353; cin>>n>>m>>k; for(long i=1; i<k+1; i++){ if(i==1){ a=1; } else{ a=modpow(i,n,r)-modpow(i-1,n,r); if(a<0){ a=a+r; } } b=modpow(k-i+1,m,r); a=a*b; a=a%r; ans=ans+a; ans=ans%r; } if(m==1 || n==1){ ans=modpow(k,max(n,m),r); } cout<<ans; }
//================code===================// //#define TLE #ifdef TLE #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #endif #include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #include <random> #include <ctime> #define ci(t) cin>>t #define co(t) cout<<t #define LL long long #define ld long double #define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i) #define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i) #define setp pair<pair<int,int>,int> #define setl pair<LL,LL> #define M_PI 3.14159265358979323846 #define micro 0.000001 using namespace std; #ifdef OHSOLUTION #define ce(t) cerr<<t #define AT cerr << "\n=================ANS=================\n" #define AE cerr << "\n=====================================\n" LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; } LL lcm(LL a, LL b) { return (a * b) / gcd(a, b); } #else #define AT #define AE #define ce(t) #define __popcnt __builtin_popcount #define gcd __gcd #define lcm __lcm #endif pair <int, int> vu[9] = { {0,1},{1,0},{0,-1} ,{-1,0},{0,1},{1,0}, {-1,1} , {1,-1},{-1,-1} }; //RDLU EWSN template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; } template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; } struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl a, setl b) { return a.second < b.second; } }; struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl a, setl b) { return a.second > b.second; } }; const int max_v = 2e5 + 7; const int INF = 1e9 + 7; const LL LNF = (LL)5e18 + 7ll; const LL mod = 998244353; LL cpow(LL x, LL k) { if (!x) return 0; LL ret = 1; while (k) { if (k & 1) ret = ret * x % mod; x = x * x % mod; k >>= 1; } return ret; } int main() { #ifdef OHSOLUTION freopen("input.txt", "r", stdin); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); LL n, m, k; ci(n >> m >> k); LL ans = 0; if (n == 1 || m == 1) { co(cpow(k, n + m - 1)); return 0; } if (n == 1) swap(n, m); fa(i, 1, k + 1) { ans = (ans + cpow(i, n) * ((cpow(k - i + 1, m) - cpow(k - i, m) + mod) % mod) % mod) % mod; } co(ans%mod); return 0; }
#include<bits/stdc++.h> #define ll long long using namespace std; map<long long, long long> mp; ll solve(ll x, ll y){ if(x == y)return 0; if(y < x){ return abs(x - y); } if(mp[y] != 0){ //cout << y << " " << dp[y] << endl; return mp[y]; } //cout << y << endl; ll z = abs(x - y); if(y%2 == 0){ mp[y] = min(z, solve(x, y/2) + 1); return mp[y]; } else{ mp[y] = min(z, min(solve(x, y-1) + 1, solve(x, y+1) + 1)); return mp[y]; } } int main(){ ll x, y; cin >> x >> y; ll ans = abs(x - y); ll s = solve(x, y); cout << min(s, ans) << endl; return 0; }
/* 少加头文件,爆零两行泪 DP后效性,爆零两行泪 文件读入错,爆零两行泪 文件名写错,爆零两行泪 调完不编译,爆零两行泪 结论不证明,爆零两行泪 数组没开够,爆零两行泪 ll开 int,爆零两行泪 dp 没初值,爆零两行泪 深搜没边界,爆零两行泪 广搜忘出队,爆零两行泪 模数没看清,爆零两行泪 越界不特判,爆零两行泪 多测不清空,爆零两行泪 空间胡乱开,爆零两行泪 无向变有向,爆零两行泪 调试忘删除,爆零两行泪 文件不保存,爆零两行泪 题目提交错,爆零两行泪 */ #pragma GCC optimize("Ofast") #include<bits/stdc++.h> #define int long long #define gmax(x,y) x=max(x,y) #define gmin(x,y) x=min(x,y) #define F first #define S second #define P pair #define FOR(i,a,b) for(int i=a;i<=b;i++) #define rep(i,a,b) for(int i=a;i<b;i++) #define V vector #define RE return #define ALL(a) a.begin(),a.end() #define MP make_pair #define PB emplace_back #define PF emplace_front #define FILL(a,b) memset(a,b,sizeof(a)) #define lwb lower_bound #define upb upper_bound using namespace std; int dp[65][2]; bool fa[65],fb[65]; int geta(int l,int r){ int re=0; FOR(i,l,r){ re=re*2+fa[i]; } RE re; } int getb(int l,int r){ int re=0; FOR(i,l,r){ re=re*2+fb[i]; } RE re; } void solve(int i){ gmin(dp[i][0],dp[i-1][1]+2); gmin(dp[i][0],dp[i-1][0]+fb[i]+1); gmin(dp[i][1],dp[i-1][1]-fb[i]+1+1); gmin(dp[i][1],dp[i-1][0]+2); } signed main(){ ios::sync_with_stdio(0); cin.tie(0); int a,b; cin>>a>>b; if(a>=b){ cout<<a-b;RE 0; } int la,lb; la=lb=0; V<int> v; while(a){ v.PB(a&1); a/=2; } while(!v.empty()){ fa[++la]=v.back(); v.pop_back(); } while(b){ v.PB(b&1); b/=2; } while(!v.empty()){ fb[++lb]=v.back(); v.pop_back(); } dp[la-1][0]=abs(geta(1,la)-getb(1,la-1)); dp[la-1][1]=abs(geta(1,la)-(getb(1,la-1))); dp[la][0]=abs(geta(1,la)-getb(1,la)); dp[la][1]=abs((getb(1,la)+1)-geta(1,la)); gmin(dp[la][0],abs(2*geta(1,la)-getb(1,la))+1); gmin(dp[la][1],abs((getb(1,la)+1)-2*geta(1,la))+1); solve(la); dp[la+1][0]=abs(geta(1,la)-getb(1,la+1)); dp[la+1][1]=abs((getb(1,la+1)+1)-geta(1,la)); solve(la+1); FOR(i,la+2,lb){ dp[i][0]=1e18; dp[i][1]=1e18; solve(i); } cout<<min(dp[lb][0],dp[lb][1]+1); RE 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++) #define rrep(i, a, b) for (int i = (int)(b) - 1; (i) >= (int)(a); (i)--) #define all(v) v.begin(), v.end() typedef long long ll; template <class T> using V = vector<T>; template <class T> using VV = vector<V<T>>; /* 提出時これをコメントアウトする */ #define LOCAL true #ifdef LOCAL #define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl #else #define dbg(x) true #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); constexpr char endl = '\n'; ll n,C; cin >> n >> C; V<ll> a(n), b(n), c(n); rep(i,0,n) cin >> a[i] >> b[i] >> c[i]; priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> v; rep(i,0,n) { v.push({a[i], c[i]}); v.push({b[i]+1, -c[i]}); } ll pre = -1, sum = 0; ll cost = 0; while (!v.empty()) { ll date = v.top().first; cost += min(C, sum) * (date - pre); pre = date; while (!v.empty() && v.top().first == date) { sum += v.top().second; v.pop(); } } cout << cost << endl; return 0; }
#include <bits/stdc++.h> #define var auto #define ll long long using namespace std; int n; int k; int mod; const int N_MAX = 100; const int M_MAX = 100; const int DAT_LEN = 100 * 100 * 100 / 2; const int TMP_LEN = 7; int tmp[TMP_LEN][DAT_LEN]; void multiple(int arr[DAT_LEN], int width, int k, int res[DAT_LEN]) { for (int i = 0; i < DAT_LEN; i++) tmp[0][i] = arr[i]; for (int i = 1; i < TMP_LEN; i++) { for (int j = 0; j < DAT_LEN; j++) tmp[i][j] = tmp[i - 1][j]; var shift = (1 << (i - 1)) * width; for (int j = shift; j < DAT_LEN; j++) { tmp[i][j] += tmp[i - 1][j - shift]; if (mod < tmp[i][j]) tmp[i][j] -= mod; } } for (size_t i = 0; i < DAT_LEN; i++) res[i] = arr[i]; int offset = width; for (int i = 0; i < TMP_LEN; i++) { if ((k >> i) & 1) { for (int j = offset; j < DAT_LEN; j++) { res[j] += tmp[i][j - offset]; if (mod < res[j]) res[j] -= mod; } offset += (1 << i) * width; } } } int hoge[101][DAT_LEN]; int main() { cin >> n >> k >> mod; hoge[0][0] = 1; multiple(hoge[0], 3, k, hoge[1]); for (size_t i = 1; i <= n; i++) { multiple(hoge[i - 1], i, k, hoge[i]); } for (int x = 1; x <= n; x++) { ll res = 0; var target1 = hoge[x - 1]; var target2 = hoge[n - x]; for (size_t i = 0; i < DAT_LEN; i++) { res += ((ll)target1[i]) * target2[i]; res %= mod; } res *= (k + 1); res -= 1; res %= mod; //←? cout << res << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; N *= 2; vector<pair<int64_t, char>> P(N); bool ro = false, go = false, bo = false; for (int i = 0; i < N; i++) { cin >> P[i].first >> P[i].second; if (P[i].second == 'R') ro ^= true; if (P[i].second == 'G') go ^= true; if (P[i].second == 'B') bo ^= true; } sort(P.begin(), P.end()); int64_t R, G, B, RG, RB, GB; R = G = B = -1e16; RG = RB = GB = 1e16; for (int i = 0; i < N; i++) { if (P[i].second == 'R') { R = P[i].first; RG = min(RG, R - G); RB = min(RB, R - B); } else if (P[i].second == 'G') { G = P[i].first; RG = min(RG, G - R); GB = min(GB, G - B); } else if (P[i].second == 'B') { B = P[i].first; GB = min(GB, B - G); RB = min(RB, B - R); } } if (!ro && !go && !bo) cout << 0 << endl; else if (ro && go && !bo) cout << min(RG, RB + GB) << endl; else if (ro && !go && bo) cout << min(RB, RG + GB) << endl; else if (!ro && go && bo) cout << min(GB, RG + RB) << endl; }
// #pragma comment(linker, "/stack:200000000") // #pragma GCC optimize("Ofast") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; using i128 = __int128_t; using u128 = __uint128_t; using u64 = uint64_t; //define #define int long long #define ll int #define trav(i,v) for(auto i: v) #define rep(i,n) for(int i=0;i<n;i++) #define repu(i,k,n) for(int i=k;i<=n;i++) #define repd(i,k,n) for(int i=k;i>=n;i--) #define se second #define fi first #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define itn int #define sz(x) (int)x.size() //typedef typedef unsigned long long ull; typedef long double ld; typedef std::pair<int, int> pii; typedef std::vector<int> vi; typedef std::vector< pii > vii; typedef std::vector< std::vector<int> > vvi; typedef std::vector< std::pair < pii, int > > vpp; const long long MOD = 1000000007; // const long long MOD = 998244353; const long double PI = 3.141592653589793238; const long long pi = 31415926; const long long inf = 1000000000000000000; const long long small_inf = INT_MAX; int modpow(int x, int n, int mod = MOD){ int res=1; while(n>0){ if(n&1) res=res*x%mod; x=x*x%MOD; n>>=1;} return res;} int power(int x, int n){ int res=1; while(n>0){ if(n&1) res=res*x; x=x*x; n>>=1; } return res;} void init(){ } int find(int a, int b, vi *v){ int n1 = sz(v[a]), n2 = sz(v[b]); int x = 0; int mn = inf; repu(y,0,n2-1){ while(x<n1-1 && v[a][x]<v[b][y]) x++; mn = min(mn,abs(v[a][x]-v[b][y])); if(x) mn = min(mn,abs(v[a][x-1]-v[b][y])); } return mn; } void solve() { /*Don't hurry, nothing good comes if you rush*/ int n; cin>>n; vi cnt(3,0); map<char, int> mm; mm['R'] = 0; mm['G'] = 1; mm['B'] = 2; vector<char> c(2*n+1,0); vi v[3]; repu(i,1,2*n){ int tmp; cin>>tmp>>c[i]; cnt[mm[c[i]]]++; v[mm[c[i]]].pb(tmp); } int odd = 0, f=-1, a=-1, b=-1; rep(i,3){ sort(all(v[i])); if(cnt[i]%2){ if(a==-1) a=i; else b=i; odd++; } else f = i; } if(odd==0){ cout<<0<<endl; return; } if(cnt[f]==0){ cout<<find(a,b,v)<<endl; return; } cout<<min(find(a,f,v)+find(b,f,v), find(a,b,v))<<endl; } signed main(){ // #ifndef ONLINE_JUDGE // freopen("./input.txt", "r", stdin); // freopen("./output.txt", "w", stdout); // #endif ios_base::sync_with_stdio(0); cin.tie(NULL); int t23 = 1, tt23 = 1; // cin>>t23; init(); while(tt23<=t23) { // cout<<"Case #"<<tt23<<": "; solve(); tt23++; } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> #include <fstream> using namespace std; #define int long long #define ii pair <int, int> #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define x first #define y second #define Time (double)clock()/CLOCKS_PER_SEC #define debug(x) std::cerr << #x << ": " << x << '\n'; #define FOR(i, n) for (int i = 0; i < n; ++i) #define FORN(i, n) for (int i = 1; i <= n; ++i) #define pb push_back #define trav(a, x) for (auto& a : x) using vi = vector<int>; template <typename T> std::istream& operator >>(std::istream& input, std::vector<T>& data) { for (T& x : data) input >> x; return input; } template <typename T> std::ostream& operator <<(std::ostream& output, const pair <T, T> & data) { output << "(" << data.x << "," << data.y << ")"; return output; } template <typename T> std::ostream& operator <<(std::ostream& output, const std::vector<T>& data) { for (const T& x : data) output << x << " "; return output; } ll div_up(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up ll div_down(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down ll math_mod(ll a, ll b) { return a - b * div_down(a, b); } #define tcT template<class T #define tcTU tcT, class U tcT> using V = vector<T>; tcT> void re(V<T>& x) { trav(a, x) cin >> a; } tcT> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } // set a = min(a,b) tcT> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } ll gcd(ll a, ll b) { while (b) { tie(a, b) = mp(b, a % b); } return a; } const int N = 5e5+7; int f[N], pref[N]; int div_(int a, int b) { while (a % b) { a += 3; } return a/b; } int get(int n, int k) { if (pref[n] > pref[k] + pref[n - k]) { return 0; } else { return div_(f[n], f[k] * f[n - k] % 3); } } signed main() { #ifdef LOCAL #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); #endif f[0] = 1; for (int i = 1; i < N; ++i) { int t = i; int pw = 0; while (t % 3 == 0) { t /= 3; pw++; } pref[i] = pref[i - 1] + pw; f[i] = f[i - 1] * t % 3; } string A = "BWR"; auto num = [&] (char c) { FOR (i, 3) { if (A[i] == c) { return i; } } assert(0); }; int n; cin >> n; string s; cin >> s; int ans = 0; int f = 1; if (n % 2 == 0) { f = 2; } FOR (i, n) { //debug(i); //debug(get(n - 1, i)); ans += f * get(n - 1, i) * num(s[i]); ans %= 3; } //debug(ans); cout << A[ans] << endl; }
#include <bits/stdc++.h> using namespace std; using ll=long long; using vin=vector<int>; using vll=vector<long long>; using vvin=vector<vector<int>>; using vvll=vector<vector<long long>>; using vstr=vector<string>; using vvstr=vector<vector<string>>; using vch=vector<char>; using vvch=vector<vector<char>>; using vbo=vector<bool>; using vvbo=vector<vector<bool>>; using vpii=vector<pair<int,int>>; using pqsin=priority_queue<int,vector<int>,greater<int>>; #define mp make_pair #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep2(i,s,n) for(int i=(s);i<(int)(n);i++) #define all(v) v.begin(),v.end() #define decp(n) cout<<fixed<<setprecision((int)n) const ll inf=1e9+7; const ll INF=1e18; const ll mod=99824453; vin dx={-1,0,1,0}; vin dy={0,1,0,-1}; int main(){ int t;cin>>t; vstr ans(t); int n;ll a; rep(i,t){ cin>>n; if(n%2){ rep(i,n)cin>>a; ans[i]="Second"; continue; } set<int> num; rep(i,n){ cin>>a; if(num.count(a))num.erase(a); else num.insert(a); } if(num.size())ans[i]="First"; else ans[i]="Second"; } rep(i,t)cout<<ans[i]<<endl; }
#include<iostream> #include<string> #include<iomanip> #include<cmath> #include<vector> #include<algorithm> #include<utility> using namespace std; #define int long long #define endl "\n" constexpr long long INF = (long long)1e18; constexpr long long MOD = 1'000'000'007; struct fast_io { fast_io(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); }; } fio; signed main(){ cout<<fixed<<setprecision(10); int N; vector<string> S; vector<vector<int>> dp; cin>>N; dp.resize(N+1, vector<int>(2)); S.resize(N); dp[0][0] = dp[0][1] = 1; for(int i = 0; i < N; i++){ cin>>S[i]; } for(int i = 1; i <= N; i++){ if(S[i-1] == "AND") { dp[i][0] = dp[i-1][0] * 2 + dp[i-1][1]; dp[i][1] = dp[i-1][1]; } else { dp[i][0] = dp[i-1][0]; dp[i][1] = dp[i-1][1] * 2 + dp[i-1][0]; } } cout<<dp[N][1]<<endl; return 0; }
#include <iostream> #include <cmath> #include <memory.h> using namespace std; typedef long long LL; int main() { int n; cin >> n; string s; LL ans = 1, p = 1; while (n--) { p <<= 1; cin >> s; if (s == "OR") { ans += p; } } cout << ans << endl; }
#include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #define ll long long using namespace std; int main(){ double x1,x2,y1,y2; cin>>x1>>y1>>x2>>y2; double ans=(y1/(y1+y2))*(x2-x1)+x1; printf("%.8lf",ans); }
#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 _lint = int; #define REP(i, n) for (_lint i = 0; i < (_lint)(n); i++) #define FOR(i, a, b) for (_lint i = (_lint)(a); i < (_lint)(b); i++) #define FORR(i, a, b) for (_lint i = (_lint)(b)-1; i >= (_lint)(a); i--) #define CHMIN(a, b) (a) = min((a), (b)) #define CHMAX(a, b) (a) = max((a), (b)) #define ALL(v) (v).begin(), (v).end() #define DEBUG(x) cerr << #x << ": " << (x) << endl #define DEBUG_VEC(v) \ { \ cerr << #v << ": "; \ REP(__i, size(v)) cerr << ((v)[__i]) << ", "; \ cerr << endl; \ } int n, m, q; pair<int, pii> qs[252521]; int a[252521], b[252521]; template <typename T> struct DynBit { unordered_map<int, T> dat; int N; DynBit(int N) : N(N + 2) {} void add(int a, T w) { a++; for (int x = a; x <= N; x += x & -x) dat[x] += w; } T sum(int a) { a++; T ret = 0; for (int x = a; x > 0; x -= x & -x) ret += dat[x]; return ret; } }; int main() { scanf("%d%d%d", &n, &m, &q); REP(i, q) { scanf("%d%d%d", &qs[i].first, &qs[i].second.first, &qs[i].second.second); } // sum_i sum_j max(a_i, b_j) // a_i の寄与 // a_i * count_j (a_i > b_j) // 元の寄与が sum_j b_j (b_j < a_i) // b_j の寄与 // b_j * count_i (b_j >= a_i) const int mx = 100'000'025; DynBit<int> cnt1(mx), cnt2(mx); DynBit<ll> sum1(mx), sum2(mx); cnt1.add(0, n); cnt2.add(0, m); ll ans = 0; REP(qi, q) { int t = qs[qi].first; int x, y; tie(x, y) = qs[qi].second; if (t == 1) { // back if (a[x] > 0) { ll c = cnt2.sum(a[x] - 1); ll s = sum2.sum(a[x] - 1); ans -= c * a[x] - s; } cnt1.add(a[x], -1); sum1.add(a[x], -a[x]); // go a[x] = y; ll c = cnt2.sum(a[x] - 1); ll s = sum2.sum(a[x] - 1); ans += c * a[x] - s; cnt1.add(a[x], 1); sum1.add(a[x], a[x]); } else { // back if (b[x] > 0) { ll c = cnt1.sum(b[x]); ll s = sum1.sum(b[x]); ans -= c * b[x] - s; } cnt2.add(b[x], -1); sum2.add(b[x], -b[x]); // go b[x] = y; ll c = cnt1.sum(b[x]); ll s = sum1.sum(b[x]); ans += c * b[x] - s; cnt2.add(b[x], 1); sum2.add(b[x], b[x]); } printf("%lld\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; void solve(){ ll n ; cin>>n; ll x = ((1.08)*(n)); if(x == 206){ cout<<"so-so"<<endl; } else{ if(x > 206){ cout<<":("<<endl; } else{ cout<<"Yay!"<<endl; } } } int main(){ solve(); }
#include <bits/stdc++.h> #define loop(s, e, i) for (int i = s; i < e; ++i) #define print(s) cout << s << endl; #define DIV 1000000007 using namespace std; typedef long long ll; typedef unsigned long long ull; const ll INF = 1e18+7; ll ceildiv(ll a, ll b) { return (a+b-1)/b; } // 切り上げ ll floordiv(ll a, ll b) { return a/b; } // 切り下げ int show_matrix(vector<vector<int>> &dp) { loop(0, dp.size(), i) { loop(0, dp[i].size(), j) { cout << dp[i][j] << " "; } cout << endl; } return 0; } /* 浮動小数点の入力 cout << fixed << setprecision(9) << endl; */ int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll N; cin >> N; N *= 1.08; if (N < 206) { print("Yay!"); } else if (N == 206) { print("so-so"); } else { print(":("); } }
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long #define mod 1000000007 void solve(){ int arr[4]; for(int i = 0;i<4;i++)cin>>arr[i]; sort(arr,arr+4); if(arr[0] + arr[1] + arr[2] == arr[3]){ cout<<"Yes"; }else if(arr[0] + arr[1] == arr[2] + arr[3]){ cout<<"Yes"; }else if(arr[0] + arr[3] == arr[1] + arr[2]){ cout<<"Yes"; }else{ cout<<"No"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; while(t--){ solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int int main(){ ll t,b,c,n,k; vector<int> a(4); for(int i=0;i<4;i++) cin>>a[i]; int flag=0; for(int i=1;i<15;i++){ int sum1=0,sum2=0; for(int j=0;j<4;j++){ if(i&(1<<j)) sum1+=a[j]; else sum2+=a[j]; } if(sum1==sum2){ flag=1; break; } } if(flag) cout<<"Yes"<<endl; else cout<<"No"<<endl; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define rng(i, a, b) for (int i = int(a); i < int(b); ++i) #define rep(i, b) rng(i, 0, b) #define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); --i) #define per(i, b) gnr(i, 0, b) #define all(obj) begin(obj), end(obj) #define allr(obj) rbegin(obj), rend(obj) #define cinv(a) rep(i, (int)a.size()) cin >> a[i] #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> Pi; typedef vector<Pi> vp; typedef vector<vp> vvp; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typedef vector<vc> vvc; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vb> vvb; 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; } template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; const int di[] = {-1, 0, 1, 0}; const int dj[] = {0, 1, 0, -1}; const int MOD = 1e9 + 7; const int INF = 1e9 + 9; const ll LINF = 1e18; const long double eps = 1e-10; const char nl = '\n'; ll power(ll a, ll b) { return b ? power(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD : 1; } ll nCk(int n, int k) { ll x = 1, y = 1; for (int i = 1; i <= k; ++i) { x = x * (n - i + 1) % MOD; y = y * i % MOD; } return x * power(y, MOD - 2) % MOD; } struct UF { vi d; UF(int n) : d(n, -1) {} int root(int x) { if (d[x] < 0) return x; return d[x] = root(d[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (d[x] > d[y]) swap(x, y); d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return -d[root(x)]; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); cout<<fixed<<setprecision(20); int n, k; cin >> n >> k; vvi A(n, vi(n)); rep(i, n) rep(j, n) cin >> A[i][j]; int lim = k*k/2 + 1; int ng = INF; int ok = -1; auto check = [&](int x) -> bool { vvi S(n+1, vi(n+1)); rep(i, n) rep(j, n) S[i+1][j+1] = S[i][j+1] + S[i+1][j] - S[i][j] + (A[i][j] >= x); int cnt = 0; int m = n-k+1; rep(i, m) rep(j, m) cnt += S[i+k][j+k] - S[i+k][j] - S[i][j+k] + S[i][j] >= lim; return cnt == m*m; }; while (ng - ok > 1) { int mid = (ok + ng)/2; if (check(mid)) ok = mid; else ng = mid; } cout << ok << nl; }
#include <bits/stdc++.h> #define int long long using namespace std; int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin>>n; string s; cin>>s; string t; while((int)t.size() < n+2) t+="110"; int ans=0; for(int i=0;i<3;i++){ if(s!=t.substr(i, n)) continue; ans+=(int)1e10-(n+i-1)/3; } cout<<ans; return 0; }
#include <bits/stdc++.h> #define foreach(i,v) for(auto&& i: v) #define all(x) (x).begin(), (x).end() typedef std::vector< std::string > VS; typedef std::vector<int> VI; typedef long long ll; typedef std::pair<int, int> ii; template <class C> C& mini(C& a, C b) { if (b < a) a = b; return a; } template <class C> C& maxi(C& a, C b) { if (a < b) a = b; return a; } template <typename T> void read(std::vector<T>& A) { for (T& x: A) std::cin >> x; } template <typename T> void readv(std::vector<T>& A) { int N; std::cin >> N; A.resize(N); read(A); } using namespace std; #define MOD 1000000007 template <typename T> void imfix(T& r) { if (r >= MOD) r -= MOD; } template <typename T> T mfix(T r) { return r >= MOD ? r - MOD : r; } int main(int argc, const char* argv[]) { ios_base::sync_with_stdio(0); cin.tie(0); cout.precision(20); cout.setf(ios::fixed); VI A; readv(A); int N = A.size(); vector<ll> B(N+1), C(N+1); B[N] = 0; B[N-1] = A.back(); C[N] = 1; C[N-1] = 1; for (int i = N-2; i >= 0; i--) { B[i] = (A[i] * C[i+1] + B[i+1]) % MOD + ((MOD + A[i] - A[i+1]) * C[i+2] + B[i+2]) % MOD; imfix(B[i]); imfix(C[i] = C[i+1] + C[i+2]); } cout << B[0] << endl; return 0; }
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef vector <int> vi; typedef vector <ll> vll; typedef vector <string> vs; typedef vector <vector <int>> vvi; typedef vector <vll> vvll; typedef map<int, int> mi; typedef map<string, int> ms; typedef map<char, int> mc; typedef map <int, bool> mb; typedef map<ll, ll> mll; typedef unordered_map<int, int> umi; typedef unordered_map<string, int> ums; typedef unordered_map<char, int> umc; typedef unordered_map <int, bool> umb; typedef unordered_map<ll, ll> umll; typedef vector <ld> vld; typedef vector <bool> vb; typedef pair <int, int> pii; typedef pair<ll, ll> pll; typedef vector <pii> vpii; typedef vector <pll> vpll; #define FOR(i,N) for(ll i = 0 ; i < N;i++) #define eFOR(i,a,b) for(ll i = a; i <=b;i++) #define dFOR(i,N) for(ll i = N - 1; i>=0;i--) #define edFOR(i,b,a) for(ll i = b ; i >=a;i--) #define all(x) x.begin(),x.end() #define SORT(x) sort(all(x)) #define RSORT(x) sort(x.rbegin(),x.rend()) #define UNQ(x) unique(all(x)) #define mine(x) min_element(all(x)) #define maxe(x) max_element(all(x)) #define lb(v, x) lower_bound(all(v) , x) #define ub(v , x) upper_bound(all(v) , x) #define pb push_back #define PI 3.141592653589793 #define FIX cout << fixed << setprecision(15) #define g(i , a) get<i>(a) const ll mod = 1e9 + 7; int CASE = 1; const int mxn = 1e5 + 1; const ll INF = 1e18; bool prime(int n) { if (n <= 1) return false; if (n == 2 or n == 3) return true; if (n % 2 == 0 or n % 3 == 0) return false; for (int i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } ll __gcd(ll a, ll b) { return !b ? a : __gcd(b, a % b); } ll a[mxn], dp[mxn][2], way[mxn][2]; void solve() { int n; cin >> n; eFOR(i, 1, n) cin >> a[i]; dp[1][0] = a[1]; way[1][0] = 1; eFOR(i, 2, n) { dp[i][0] = (dp[i - 1][0] + dp[i - 1][1] + a[i] * (way[i - 1][0] + way[i - 1][1])) % mod; dp[i][1] = (dp[i - 1][0] + mod - a[i] * way[i - 1][0] % mod) % mod; way[i][0] = (way[i - 1][0] + way[i - 1][1]) % mod; way[i][1] = way[i - 1][0]; } cout << (dp[n][0] + dp[n][1] + mod) % mod; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; while (T--) { solve(); } return 0; }
#include<iostream> #include<algorithm> #include<vector> #include<queue> #include<stack> #include<string> #include<map> #include<set> #include<tuple> #include<cmath> #include<iomanip> using namespace std; typedef long long ll; typedef vector<ll> v; typedef vector<vector<ll>> vv; #define MOD 1000000007 #define INF 1001001001 #define MIN -1001001001 #define rep(i,k,N) for(int i=k;i<N;i++) #define MP make_pair #define MT make_tuple //tie,make_tuple は別物 #define PB push_back #define PF push_front #define all(x) (x).begin(),(x).end() int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; vv e; bool check(ll i,ll j){ ll nl=e[1][i],nr=e[2][i],ml=e[1][j],mr=e[2][j]; ll n = e[0][i]; ll m = e[0][j]; if(nl > ml){ swap(nl,ml); swap(nr,mr); swap(n,m); } else if(nl==ml && (n==3 || n==4) && (m==1 || m==2)){ swap(nl,ml); swap(nr,mr); swap(n,m); } if(nr>ml){ return true; } else if(nr==ml){ if((n==1 || n==3)&&(m==1 || m==2))return true; else return false; } else return false; } int main(){ ll N; cin>>N; e.resize(3,v(N)); rep(i,0,N){ cin>>e[0][i]>>e[1][i]>>e[2][i]; } ll ans = 0; rep(i,0,N)rep(j,i+1,N){ if(check(i,j))ans++; } cout<<ans; return 0; }
#include <bits/stdc++.h> #define REP_(i, a_, b_, a, b, ...) \ for (int i = (a), END_##i = (b); i < END_##i; ++i) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define ALL(x) std::begin(x), std::end(x) using i64 = long long; template<typename T, typename U> inline bool chmax(T &a, U b) { return a < b and ((a = std::move(b)), true); } template<typename T, typename U> inline bool chmin(T &a, U b) { return a > b and ((a = std::move(b)), true); } template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &a) { for (auto &x : a) is >> x; return is; } template<typename T, typename U> std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &a) { return os << "(" << a.first << ", " << a.second << ")"; } void print() { std::cout << "\n"; } template<class T> void print(const T &x) { std::cout << x << "\n"; } template<typename Head, typename... Tail> void print(const Head &head, Tail... tail) { std::cout << head << " "; print(tail...); } void read_from_cin() {} template<typename T, typename... Ts> void read_from_cin(T &value, Ts &...args) { std::cin >> value; read_from_cin(args...); } #define INPUT(type, ...) \ type __VA_ARGS__; \ read_from_cin(__VA_ARGS__); #ifdef ENABLE_DEBUG #include "debug_dump.hpp" #else #define DUMP(...) #endif using namespace std; auto solve() { INPUT(int, n); vector<array<i64, 3>> a(n); REP(i, n) { INPUT(i64, t, l, r); l *= 2; r *= 2; if (t == 1) { // } else if (t == 2) { r -= 1; } else if (t == 3) { l += 1; } else { l += 1; r -= 1; } a[i][0] = l; a[i][1] = r; } i64 ans = 0; REP(i, n) { REP(j, i + 1, n) { bool no_over = false; if (a[i][1] < a[j][0]) { no_over = true; } else if (a[j][1] < a[i][0]) { no_over = true; } if (not no_over) { ++ans; } } } return ans; } int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); cout << std::fixed << std::setprecision(15); int t = 1; REP(test_case, t) { auto ans = solve(); print(ans); } }
#include <bits/stdc++.h> // #include <atcoder/all> #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define popcount __builtin_popcount using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll INF = 1LL << 60; // #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> T mypow(T x, T n, const T &p = -1) { //x^nをmodで割った余り T ret = 1; while (n > 0) { if (n & 1) { if (p != -1) ret = (ret * x) % p; else ret *= x; } if (p != -1) x = (x * x) % p; else x *= x; n >>= 1; } return ret; } using namespace std; // using namespace atcoder; template< int mod > struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 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; } }; using modint = ModInt< mod >; void solve() { ll h,w,k; cin>>h>>w>>k; vector<vector<char>>s(h,vector<char>(w,'#')); rep(i,k){ int a,b; char c; cin>>a>>b>>c; a--;b--; s[a][b]=c; } constexpr ll m=998244353; vector<vector<ModInt<m>>>dp(h+5,vector<ModInt<m>>(w+5)); ModInt<m>mul=3; mul=mul.pow(h*w-k); dp[0][0]=mul; rep(i,h){ rep(j,w){ if(s[i][j]=='X'){ dp[i+1][j]+=dp[i][j]; dp[i][j+1]+=dp[i][j]; } else if(s[i][j]=='R'){ dp[i][j+1]+=dp[i][j]; } else if(s[i][j]=='D'){ dp[i+1][j]+=dp[i][j]; } else{ dp[i+1][j]+=dp[i][j]/3*2; dp[i][j+1]+=dp[i][j]/3*2; } } } ModInt<m>ans=dp[h-1][w-1]; cout<<ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pdd; #define lc u << 1 #define rc u << 1 | 1 #define mid (t[u].l + t[u].r) / 2 #define INF 0x3f3f3f3f #define lowbit(x) x & (-x) #define mem(a, b) memset(a , b , sizeof(a)) #define FOR(i, x, n) for(int i = x;i <= n; i++) // const ll mod = 998244353; // const ll mod = 1e9 + 7; // const double eps = 1e-6; // const double PI = acos(-1); // const double R = 0.57721566490153286060651209; const int N = 1e6 + 10; ll t[N]; void modify(int x, int n) { while(x <= n) { t[x]++; x += lowbit(x); } } ll query(int x) { ll ans = 0; while(x) { ans += t[x]; x -= lowbit(x); } return ans; } struct Point { int x, y; friend bool operator < (const Point &a,const Point &b){ return a.x == b.x ? a.y < b.y : a.x < b.x; } friend bool operator == (const Point &a,const Point &b){ return a.x == b.x && a.y == b.y; } }p[N]; bool vis[N]; void solve() { int H, W, M; cin >> H >> W >> M; int upx = H + 1, upy = W + 1; for(int i = 1;i <= M; i++) { cin >> p[i].x >> p[i].y; if(p[i].x == 1) upy = min(upy, p[i].y); if(p[i].y == 1) upx = min(upx, p[i].x); } for(int i = upx + 1;i <= H; i++) { ++M; p[M].x = i; p[M].y = 1; } for(int j = upy + 1;j <= W; j++) { ++M; p[M].y = j; p[M].x = 1; } sort(p + 1, p + M + 1); M = unique(p + 1, p + M + 1) - (p + 1); int h = 1; ll ans = 0; for(int i = 1;i <= M; i++) { // 纵向扫描 if(vis[p[i].y] == 0) { vis[p[i].y] = 1; modify(p[i].y, W); } // 横向扫描 if(i == M || p[i + 1].x != p[i].x) { ans += query(W) - query(p[h].y - 1); h = i + 1; } } cout << (1ll * H * W - ans) << endl; } signed main() { ios_base::sync_with_stdio(false); //cin.tie(nullptr); //cout.tie(nullptr); #ifdef FZT_ACM_LOCAL // int size=40<<20; // __asm__ ("movq %0,%%rsp\n"::"r"((char*)malloc(size)+size)); freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); signed test_index_for_debug = 1; char acm_local_for_debug = 0; do { if (acm_local_for_debug == '$') exit(0); if (test_index_for_debug > 20) throw runtime_error("Check the stdin!!!"); auto start_clock_for_debug = clock(); solve(); auto end_clock_for_debug = clock(); cout << "Test " << test_index_for_debug << " successful" << endl; cerr << "Test " << test_index_for_debug++ << " Run Time: " << double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl; cout << "--------------------------------------------------" << endl; } while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug)); #else solve(); #endif return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <set> #include <queue> #include <stack> #include <tuple> #include <cmath> #include <iomanip> #include <map> #include <cstring> #include <functional> #include <cctype> #include <locale> #include <complex> #define ll long long #define rep(i,n) for(int i=0;i<(n);i++) #define rrep(i,n) for(int i=n-1;i>=0;i--) #define fi first #define se second #define pb push_back #define ALL(a) (a).begin(),(a).end() using namespace std; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} typedef pair<int,int> P; typedef pair<long long,long long> Pll; #define fout(num) cout << fixed << setprecision(20) << (num) << endl //s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ //vector<vector<ll>> dp(n,vector<ll>(n)) //2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d)); //3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d))); signed main(){ std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); ll n,k; cin >> n >> k; ll mi=2,ma=2*n; chmax(mi,2+k); chmin(ma,k+2*n); ll ans=0; //cout << mi << " " << ma << endl; for(ll i=mi;i<=ma;i++){ ll res=0; if(i-n<1) res+=(i-1); else res+=(2*n-i+1); ll j=i-k; if(j-n<1) res*=(j-1); else res*=(2*n-j+1); ans+=res; } cout << ans << endl; }
#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, M; cin >> N >> M; vector<pair<int, int>> P(M); for (auto &[x, y] : P) cin >> x >> y; vector<int> X, Y; for (auto &[x, y] : P) { X.push_back(x); Y.push_back(y); Y.push_back(y + 1); Y.push_back(y - 1); } sort(ALL(X)); X.erase(unique(ALL(X)), X.end()); Y.push_back(N); sort(ALL(Y)); Y.erase(unique(ALL(Y)), Y.end()); vector<vector<int>> YY(X.size()); for (auto &[x, y] : P) { int idx = lower_bound(ALL(X), x) - X.begin(); YY[idx].push_back(y); } vector<int> dp(Y.size()); dp[lower_bound(ALL(Y), N) - Y.begin()] = 1; for (auto &yy : YY) { vector<pair<int, int>> nx; for (auto &y : yy) { int idx = lower_bound(ALL(Y), y) - Y.begin(); int next = 0; if (idx > 0 && dp[idx - 1]) next = 1; if (idx + 1 < (int)Y.size() && dp[idx + 1]) next = 1; nx.push_back({idx, next}); } for (auto &[idx, next] : nx) dp[idx] = next; } cout << accumulate(ALL(dp), 0) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define rep2(i,x,n) for(int i=x; i<(n); i++) #define all(x) x.begin(),x.end() typedef long long ll; ll mod = 1000000007; ll inf = 1e18; int main(){ vector<int> a(4); rep(i,4) cin >> a[i]; for(int bit=0; bit<(1<<4); bit++){ int sum1=0; int sum2=0; rep(j,4){ if(bit & (1<<j)) sum1+=a[j]; else sum2+=a[j]; } if(sum1==sum2){ cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < n; ++i) using ll = long long; using P = pair<int,int>; int main() { int a,b,c,d;cin>>a>>b>>c>>d; int sum=a+b+c+d; if(sum%2==1){ cout<<"No"<<endl; } else{ int half=sum/2; if(half==a||half==b||half==c||half==d) cout<<"Yes"<<endl; else if(half==a+b||half==a+c||half==a+d) cout<<"Yes"<<endl; else cout<<"No"<<endl; } }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = int64_t; using pii = pair<int, int>; int main() { int n, x; cin >> n >> x; string s; cin >> s; for (int i = 0; i < n; i++) { x += s[i] == 'o' ? 1 : -1; x = max(x, 0); } cout << x << endl; }
#include<bits/stdc++.h> #define cases long long test;cin>>test;while(test--) #define f_io ios::sync_with_stdio(false); cin.tie(0) #define foi(a,n) for(long long i=a;i<n;i++) #define foj(a,n) for(long long j=a;j<n;j++) #define fok(a,n) for(long long k=a;k<n;k++) #define ll long long #define MOD 1000000007 #define INF 1000000000 using namespace std; int main() { f_io; ll n,x; cin >> n >> x; string s; cin >> s; foi(0,n) { if(s[i]=='o') x++; else { if(x) x--; } } cout << x; return 0; }
// 問題の URL を書いておく // #include <bits/stdc++.h> using namespace std; //#define ENABLE_PRINT #if defined(ENABLE_PRINT) #define Print(v) \ do {\ cout << #v << ": " << v << endl; \ }while(0) #define PrintVec(v) \ do {\ for(int __i = 0; __i < v.size(); ++__i) \ { \ cout << #v << "[" << __i << "]: " << v[__i] << endl; \ }\ }while(0) #define P(fmt, ...) printf(fmt, __VA_ARGS__) #define L printf("L: %d\n", __LINE__) #else #define Print(v) ((void)0) #define PrintVec(v) ((void)0) #define P(fmt, ...) ((void)0) #define L ((void)0) #endif #define rep(i, n) for(int i = 0; i < (int)(n); ++i) using ll = long long; map<int, map<int, int>> cache; map<int, map<int, bool>> cached; int test(int N, int y, int x, const map<int, set<int>>& g) { if(cached[y][x]) return cache[y][x]; cached[y][x] = true; int diff[] = {-1, 1}; rep(i, 2) { auto ny = y + diff[i]; if(ny < 0 || ny > 2 * N) continue; auto lfound = g.find(ny); if(lfound == g.end()) { if(ny == N) { cache[y][x] = 1; return 1; } continue; } const auto& l = g.at(ny); auto found = upper_bound(l.begin(), l.end(), x - 1); if(found == l.begin()) { // 一番上まで行く if(ny == N) { cache[y][x] = 1; return 1; } } else { found--; auto nx = *found; if(test(N, ny, nx, g) == 1) { cache[y][x] = 1; return 1; } } } cache[y][x] = 0; return 0; } int main(int, const char**) { int N, M; cin >> N >> M; map<int, set<int>> blacks; rep(i, M) { int X, Y; cin >> X >> Y; blacks[Y].insert(X); } P("bsize: %zu\n", blacks.size()); int ans = 0; for(auto itr = blacks.begin(); itr != blacks.end(); ++itr) { L; P("y: %d\n", itr->first); ans += test(N, itr->first, *(itr->second.rbegin()), blacks); L; } // Y == N にポーン置かれてない場合、まっすぐ下に降りるルートを足す if(blacks[N].size() == 0) ans++; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 7; int n, m; map<int,vector<int> > plcs; map<int,vector<int> > yplcs ; int xs[N], ys[N]; map<pair<int,int> ,int> gid; map<int,int> dp ; set<int> ans ; void solve(int i) { if(dp[i])return ; dp[i] =1 ; if(xs[i] == yplcs[ys[i]].back())ans.insert(i) ; for(int j = -1 ; j <= 1; j += 2){ if(ys[i] + j >= 0 && ys[i] + j <= n){ int ny = ys[i] + j; auto it = lower_bound(yplcs[ny].begin() , yplcs[ny].end() , xs[i] + 1) ; while(it != yplcs[ny].end()){ int nx = *it ; auto it2 = lower_bound(yplcs[ys[i]].begin() , yplcs[ys[i]].end() , xs[i] + 1) ; if(it2!=yplcs[ys[i]].end()){ int m_y = *it2 ; if(m_y < nx){ break; } } solve(gid[{nx,ny}]) ; it ++ ; } } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("in.in", "r", stdin); #endif cin >> n >> m; plcs[0].push_back(n); yplcs[n].push_back(0) ; xs[0] = 0 , ys[0] = n; n = n * 2 + 1; for (int i = 1; i <= m; ++i) { int x, y; cin >> x >> y; xs[i] = x, ys[i] = y; plcs[x].push_back(y); yplcs[y].push_back(x); gid[{x,y}] = i ; } for(auto &u : plcs){ sort(u.second.begin() , u.second.end()) ; } for(auto &u : yplcs){ sort(u.second.begin() , u.second.end()) ; } solve(0) ; cout << ans.size() ; return 0; }
#include <stdio.h> long long power(long long a, long long b) { long long result = 1, i; for (i = 0; i < b; i++) { result *= a; } return result; } int main() { long long i = 1, j = 1, n, turn = 1;; scanf("%lld", &n); getchar(); while (1) { if (power(5, i) >= n) break; long long x = n - power(5, i); turn = 1; j = 1; while (1) { if (x % 10 == 3 && turn == 1) j = 1; else if (x % 10 == 9 && turn == 1) j = 2; else if (x % 10 == 7 && turn == 1) j = 3; else if (x % 10 == 1 && turn == 1) j = 4; else if (x % 10 != 3 && x % 10 != 9 && x % 10 != 7 && x % 10 != 1) break; if (power(3, j) > x) break; if (power(3, j) == x) { printf("%lld %lld\n", j, i); return 0; } j += 4; turn = 0; } i++; } printf("-1\n"); return 0; }
#include <bits/stdc++.h> #define fi first #define se second using namespace std; typedef long long ll; typedef pair<ll, ll> pll; const int N = 20; const ll mod = 1e9 + 7; const ll inf = 1e18; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin >> n; for (ll i = 3, x = 1; i <= n; i *= 3, x++) for (ll j = 5, y = 1; i + j <= n; j *= 5, y++) { if (i + j == n){ cout << x << " " << y; return 0; } } cout << -1; } /* 1 25 8 2 8 9 2 9 8 10 13 11 1 11 1 6 10 6 1 3 5 3 7 11 10 7 2 */
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<int, ll> pil; typedef pair<ll, ll> pll; #define mp make_pair #define fr first #define sc second void solve() { int N; cin >> N; vector<int> A(N), B(N), P(N); for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i < N; i++) { cin >> B[i]; } for (int i = 0; i < N; i++) { cin >> P[i]; P[i]--; } for (int i = 0; i < N; i++) { if (P[i] != i && A[i] <= B[P[i]]) { cout << -1 << '\n'; return; } } vector<int> pos(N); for (int i = 0; i < N; i++) { pos[P[i]] = i; } vector<pii> ord(N); for (int i = 0; i < N; i++) { ord[i] = mp(A[i], i); } vector<pii> ans; sort(ord.begin(), ord.end()); for (auto [w, i] : ord) { if (P[i] == i) { continue; } int p1 = pos[i], p2 = i; ans.emplace_back(p1, p2); swap(pos[P[p1]], pos[P[p2]]); swap(P[p1], P[p2]); } cout << ans.size() << '\n'; for (auto [a, b] : ans) { cout << a + 1 << ' ' << b + 1 << '\n'; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; while (t--) solve(); return 0; }
/* author : sgupta_2001 */ #include<bits/stdc++.h> using namespace std; using db = double; using ll = long long; using ld = long double; using ull = unsigned long long; //containers #define sz(x) int((x).size()) #define bg(x) begin(x) #define all(x) bg(x), end(x) #define rall(x) x.rbegin(), x.rend() #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define ft front() #define bk back() #define pb push_back #define eb emplace_back #define pf push_front //pairs #define mp make_pair #define ff first #define ss second //loops #define rep(i, a, b) for(int i = a; i < b; ++i) #define per(i, a, b) for(int i = b - 1; i >= a; --i) #define each(x, a) for(auto &x : a) //popular constants const int mod = 1e9 + 7; //998244353; const ll inf = 1e18; const ld pie = acos((ld) - 1); //grid problems const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; //modulo operations ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} #ifdef SGUPTA_2001 #define deb(x) cerr<< #x <<" "; __print(x); cerr<<'\n'; #else #define deb(x); #endif //debug containers template<class T> void __print(T x) {cerr<<x;} template<class T, class U> void __print(pair<T,U> p) {cerr<<"{"<<p.ff<<", "<<p.ss<<"}";} template<class T> void __print(vector<T> arr) { cerr<<"[ "; for(auto x:arr) { __print(x);cerr<<" "; } cerr<<"]"; } template<class T> void __print(set<T> st) { cerr<<"{ "; for(auto x:st) { __print(x); cerr<<" "; } cerr<<"}";} template<class T, class U> void __print(vector<pair<T,U>> arr) { cerr<<"[ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"]";} template<class T, class U> void __print(unordered_map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";} template<class T, class U> void __print(map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";} template<typename... T> void read(T&... args) { ((cin>>args),...);} template<typename... T> void write(T&&... args){((cout<<args<<" "),...);cout<<'\n';} const int MAXN = 2002; vector<int> gr[MAXN]; int t_in[MAXN], t_out[MAXN]; int vis[MAXN]; int timer; void dfs(int u, int par) { t_in[u] = ++timer; vis[u] = 1; for(auto x : gr[u]) { if(x != par && !vis[x]) { dfs(x, u); } } t_out[u] = timer; return; } void solve() { int N, M; scanf("%d%d", &N, &M); rep(i, 0, M) { int X, Y; scanf("%d%d", &X, &Y); X--;Y--; gr[X].pb(Y); } ll ans = 0; rep(i, 0, N) { dfs(i, -1); int p = t_in[i], q = t_out[i]; rep(j, 0, N) { if(p <= t_in[j] && q >= t_out[j]) { ans++; } } fill(vis, vis + N + 1, 0); fill(t_in, t_in + N + 1, 0); fill(t_out, t_out + N + 1, 0); timer = 0; } printf("%lld\n", ans); return; } int main() { #ifdef SGUPTA_2001 freopen("input.txt", "r", stdin); freopen("error.txt", "w", stderr); #endif auto start = std::chrono::high_resolution_clock::now(); int t; t=1; while(t--) solve(); auto stop = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start); // cerr << "Time taken : " << ((long double)duration.count())/((long double) 1e9) <<"s "<< '\n'; /* STUFF TO LOOK: 1. Check the constraints 2. Corner cases(n == 0 || n == 1) 3. Variables in loops 4. Make sure two ints aren’t multiplied to get a long long */ return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n);i++) #define Graph vector<vector<int>>; #define iterG(next_v, G, v) for(auto next_v : G[v] #define ALL(a) (a).begin(),(a).end() const int MOD = 1000000007; const int MAX = 510000; const int INF = 1061109567; const double EPS = 1e-10; const double PI = acos(-1.0); int main(){ ios::sync_with_stdio(false); cin.tie(0); int h, w, x, y; cin >> h >> w >> y >> x; vector<string> s(h); rep(i, h) cin >> s[i]; int ans = 1; int curx, cury; curx = x-1; cury = y-1; // x + while(curx + 1 < w and s[cury][curx+1] == '.'){ curx++; ans++; } curx = x-1; cury = y-1; // x + while(curx - 1 >= 0 and s[cury][curx-1] == '.'){ curx--; ans++; } curx = x-1; cury = y-1; while(cury + 1 < h and s[cury+1][curx] == '.'){ cury++; ans++; } curx = x-1; cury = y-1; while(cury - 1 >= 0 and s[cury-1][curx] == '.'){ cury--; ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int ri() { int n; cin >> n; return n; } int main() { int h = ri(); int w = ri(); int x = ri() - 1; int y = ri() - 1; string s[h]; for (auto &i : s) cin >> i; int cnt = -3; for (int i = x; i < h && s[i][y] != '#'; i++) cnt++; for (int i = x; i >= 0 && s[i][y] != '#'; i--) cnt++; for (int j = y; j < w && s[x][j] != '#'; j++) cnt++; for (int j = y; j >= 0 && s[x][j] != '#'; j--) cnt++; cout << cnt << endl; }
//Author: stdout #pragma GCC optimize("O2") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; #define debug(x) cerr<<#x<<" = "<<x<<"\n"; #define lowbit(x) ((x)&-(x)) const int inf=0x3f3f3f3f; const double eps=1e-9; //const double pi=acos(-1.0); int main() { ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); ull x,y,e=0,a,b; cin>>x>>y>>a>>b; while(x*(a-1)<b&&x*a<y) x*=a,++e; e+=(y-x-1)/b; cout<<e<<"\n"; return 0; }
#include "bits/stdc++.h" using namespace std; #define int long long #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x).begin(),(x).end() #define uniq(v) (v).erase(unique(all(v)),(v).end()) #define sz(x) (int)((x).size()) #define fr first #define sc second #define pii pair<int,int> #define rep(i,a,b) for(int i=a;i<b;i++) #define mem1(a) memset(a,-1,sizeof(a)) #define mem0(a) memset(a,0,sizeof(a)) #define ppc __builtin_popcount #define ppcll __builtin_popcountll template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;} template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;} template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;} template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;} const long long INF=1e18; const int32_t M=1e9+7; const int32_t MM=998244353; const int N=19; int n,m; int dp[N][1<<N]; vector<pii> v[N]; int calc(int p,int mask){ int &ans = dp[p][mask]; if(ans != -1){ return ans; } ans = 0; for(auto x:v[p]){ int y = x.fr, z = x.sc; int cnt = mask % (1 << y); cnt = ppc(cnt); if(cnt > z){ ans = 0; return ans; } } if(p == n){ return ans = 1; } rep(i,0,n){ if(mask >> i & 1) continue; ans += calc(p+1,mask|(1<<i)); } return ans; } void solve(){ mem1(dp); cin >> n >> m; rep(i,0,m){ int x,y,z; cin >> x >> y >> z; v[x].pb({y,z}); } cout << calc(0,0); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #ifdef SIEVE sieve(); #endif #ifdef NCR init(); #endif int t=1; //cin>>t; while(t--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i, a, n) for(int i = a; i < n; i++) #define all(A) A.begin(),A.end() #define an(A, n) A,A+n #define sz(a) int(a.size()) #define pu push #define pb push_back #define pob pop_back #define mp(a, b) make_pair(a, b) #define fi first #define se second #define is insert typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<string> vs; typedef vector<ll> vl; typedef vector<ld> vld; typedef pair<int, int> pii; typedef vector<vi> vvi; typedef set<int> si; const int dx4[] = {-1, 0, 1, 0}; const int dy4[] = {0, 1, 0, -1}; const int dx8[] = {-1, 0, 1, 0 , -1 , -1 , 1 , 1}; const int dy8[] = {0, 1, 0, -1 , -1 , 1 , -1 , 1}; const int MOD = 1000000007; const int INF = 0x3f3f3f3f; const ll INFF = 1LL << 60; const ld EPS = 1e-9; const ld OO = 1e15; const ld PI = acos(-1.0); //M_PI; const ll N = 1000010; int main() { //TODO: ll s; ll p; cin >> s >> p; int flag = 0; rep(i, 1, N) { if(i * (s - i) == p) { flag = 1; break; } } if(flag) { cout << "Yes"; } else { cout << "No"; } return 0; }
#include<bits/stdc++.h> using namespace std; #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL); #define endl '\n' typedef long long ll; typedef pair<int,int> pii; /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost; // set typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset; // multiset */ // direction array int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1}; // Bitmask /* bool check(int mask,int pos){return mask&(1<<pos);} int SET(int mask,int pos){return mask|(1<<pos);} int FLIP(int mask,int pos){return mask^(1<<pos);} int reset(int mask,int pos){return mask&~(1 << pos);} */ int main() { ll s,p; cin>>s>>p; for(ll i=1;i*i<=p;i++){ if(p%i==0 && i+(p/i)==s){ cout<<"Yes\n"; return 0; } } cout<<"No\n"; }
#include<bits/stdc++.h> #define int long long #define zmrl(x) signed((x).size()) #define ahen(x) (x).begin(),(x).end() #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; using pii = pair<int,int>; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int a,b; cin>>a>>b; cout<<a/b<<'\n'; return 0; }
/* ID: Trump TASK: LANG: C++ */ /* LANG can be C++11 or C++14 for those more recent releases */ #include <iostream> #include <fstream> #include <cstring> #include <algorithm> #include <cmath> #define sll(n) scanf("%lld",&n); #define sll2(a,b) scanf("%lld",&n); #define sll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c); #define slb(n) scanf("%Lf",&n); #define pll(n) printf("%lld",n); #define pln printf("\n"); #define plb(n) printf("%Lf",n); #define plb2(n) printf("%.2Lf",n); #define plb3(n) printf("%.3Lf",n); #define plb4(n) printf("%.4Lf",n); #define plb5(n) printf("%.5Lf",n); #define plb6(n) printf("%.6Lf",n); using namespace std; typedef long long ll; typedef long double lb; typedef double db; typedef int it; typedef bool bl; //#define MARK const ll losn=1e6+5; const ll maxn=1e5+5; const ll minn=1e3+5; const ll tiny=1e2+5; const ll inf=1e9; const ll binf=1e18; const ll mod=1e9+7; const ll lmod=998244353; const ll hashmod=4698571; const lb pi=3.1415926; const ll myn=0; void gk(){cout<<"---------------"<<endl;} void ck(){cout<<1<<endl;} void ck(ll a){cout<<a<<endl;} void ck(ll a[minn][minn],ll n,ll m){for(ll i=1;i<=n;i++){for(ll j=1;j<=m;j++){cout<<a[i][j]<<" ";}cout<<endl;}} ll n,m,k,T,u,v,len; int main(){ //#ifdef MARK // freopen("input.in", "r", stdin); // freopen("ouput.out", "w", stdout); // freopen("ouput.out", "r", stdin); // freopen("input.in", "w", stdout); //#endif ll a,b; cin>>a>>b; ll sums=a+b; if(sums>=15 && b>=8){ cout<<1<<endl; }else if(sums>=10 && b>=3){ cout<<2<<endl; }else if(sums>=3){ cout<<3<<endl; }else{ ck(4); } return 0; }
#include <bits/stdc++.h> int main(){ char S, T; std::cin >> S >> T; if(S == 'Y'){ std::cout << (char)(T + 'A' - 'a') << std::endl; }else{ std::cout << T << std::endl; } return 0; }
#include <algorithm> #include <array> #include <cmath> #include <cstdint> #include <deque> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; using ll = int_fast64_t; using ld = long double; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; template <class T> using pq = priority_queue<T>; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const ll INF = (1LL << 30); const ll INFLL = (1LL << 60); const ll MAX = 5000005; const ll MOD = 1000000007; int main(void) { ios::sync_with_stdio(0); cin.tie(0); ll n, m; cin >> n >> m; if (m % n == 0) cout << "Yes" << endl; else cout << "No" << endl; return (0); }
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #include <climits> #include <cstring> #include <cassert> using namespace std; //using namespace atcoder; #define REP(i, n) for (int i=0; i<(n); ++i) #define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i) #define FOR(i, a, n) for (int i=(a); i<(n); ++i) #define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define DUMP(x) cerr<<#x<<" = "<<(x)<<endl #define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl; template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; REP(i, SZ(v)) { if (i) os << ", "; os << v[i]; } return os << "]"; } template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << "(" << p.first << " " << p.second << ")"; } template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vi>; using vvll = vector<vll>; const ll MOD = 1e9 + 7; const int INF = INT_MAX / 2; const ll LINF = LLONG_MAX / 2; const ld eps = 1e-9; // edit void solve() { int N, M; cin >> N >> M; vector<vector<int>> G(N, vector<int>(N)); REP(i, M) { int a, b; cin >> a >> b; a--, b--; G[a][b] = G[b][a] = 1; } vector<ll> dp(1 << N, INF); dp[0] = 1; for (int mask = 0; mask < 1 << N; ++mask) { // int amas = ~mask & ((1 << N) - 1); int amas = 0; for (int i = 0; i < N; ++i) { if (mask < 1 << i) break; if (mask >> i & 1) { } else { amas |= (1 << i); } } int tmp = amas; while (tmp > 0) { chmin(dp[tmp | mask], dp[tmp] + dp[mask]); tmp = (tmp - 1) & amas; } for (int i = 0; i < N; ++i) { if (mask >> i & 1) continue; int nmas = mask | (1ll << i); bool ok = true; for (int j = 0; j < N; ++j) { if (mask >> j & 1) { if (!G[i][j]) { ok = false; break; } } } if (ok) { chmin(dp[nmas], dp[mask]); } else { chmin(dp[nmas], dp[mask] + 1); } } } cout << dp.back() << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); // std::ifstream in("input.txt"); // std::cin.rdbuf(in.rdbuf()); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; using ll=long long; using P=pair<ll,ll>; ll N,M; ll c[324]; ll dp[(1<<18)]; int main(){ cin>>N>>M; for(ll i=0;i<M;i++){ ll a,b;cin>>a>>b;a--;b--; if(a<b){c[N*a+b]=1;}else{c[N*b+a]=1;} }for(ll i=1;i<(1<<N);i++)dp[i]=N+1;dp[0]=0; vector<P>A((1<<N)); for(ll i=0;i<(1<<N);i++){ ll sum=0;ll I=i; for(ll j=0;j<N;j++){sum+=I%2;I/=2;} A[i]=P(sum,i); }sort(A.begin(),A.end());vector<ll>B((1<<N)); for(ll i=0;i<(1<<N);i++)B[i]=A[i].second; for(ll bit=0;bit<(1<<N);bit++){ bool x=true; for(ll i=0;i<N-1;i++){ if(bit & (1<<i)){ for(ll j=i+1;j<N;j++) if(bit & (1<<j)){if(c[N*i+j]==0){x=false;break;}} }if(!x)break; }if(x)dp[bit]=1; } for(ll i=0;i<(1<<N);i++){ ll bit=B[i]; if(dp[bit]==1)continue;ll Min=N+1; for(ll bits=bit; ;bits=((bits-1)&bit)){ if(dp[(bit^bits)]+dp[bits]<Min)Min=dp[(bit^bits)]+dp[bits]; if(!bits)break; }dp[bit]=Min; }cout<<dp[(1<<N)-1]<<endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define max(a, b) (a < b ? b : a) #define min(a, b) ((a > b) ? b : a) #define mem(a,b) memset(a,(b),sizeof(a)) #define for0(a, c) for (int(a) = 0; (a) < (c); (a)++) #define forc(a, b, c) for (int(a) = (b); (a) <= (c); (a)++) #define forr(a, b, c) for (int(a) = (b); (a) >= (c); (a)--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(a) int((a).size()) #define disp(a) cout<<#a<<" "<<a<<"\n"; #define show(vec) cout<<#vec<<"\n"; for(auto v : vec) cout<<v<<" "; cout<<"\n"; #define showi(vec) for0(i,sz(vec)) cout<<"i: "<<i<<" "<<#vec<<"["<<i<<"]: "<<vec[i]<<"\n"; #define bs(num, v) binary_search((v).begin(), (v).end(), (num)) #define ub(num, v) upper_bound((v).begin(), (v).end(), (num)) #define lb(num, v) lower_bound((v).begin(), (v).end(), (num)) #define INF 1000000000000000003 #define mod 1e9 + 7 // Common memset settings //memset(memo, -1, sizeof memo); // initialize DP memoization table with -1 //memset(arr, 0, sizeof arr); // to clear array of integers // Common remainder formulaes // (x+y)%m = ((x%m) + (y%m))%m // (x.y)%m = ((x%m) . (y%m))%m // (x-y)%m = ((x%m) - (y%m) + m)%m typedef long long ll; typedef long double ld; typedef vector<long long> vll; typedef vector<pair<ll,ll>> vpll; typedef pair<ll, ll> pll; #define F first #define S second #define PB push_back #define POB pop_back #define MP make_pair void solve(){ ll n; cin>>n; double x0,y0; cin>>x0>>y0; complex<double> X0(x0,y0); double xk,yk; cin>>xk>>yk; complex<double> Xk(xk,yk); complex<double> Xmid = (X0 + Xk)/2.0; double PI = acos(-1); double rad = 2*PI/n; complex<double> r(cos(rad), sin(rad)); complex<double> ans = Xmid + (X0-Xmid)*r; printf("%.10f %.10f\n", ans.real(), ans.imag()); return; } int main(){ ios::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int T = 1; while(T--)solve(); return 0; }
#include <bits/stdc++.h> using namespace std; double n, x0, y00, x2, y2; int main(){ cin >> n >> x0 >> y00 >> x2 >> y2; double zx = (x0+x2)/2, zy = (y00+y2)/2; x0 -= zx; y00 -= zy; x2 -= zx; y2 -= zy; double theta = 180 - ((n-2)*180)/n; //theta = 360 - theta; double alpha = M_PI*theta/180; double x1 = x0*cos(alpha) - y00*sin(alpha) + zx; double y1 = y00*cos(alpha) + x0*sin(alpha) + zy; cout << fixed << setprecision(10) << x1 << " " << y1 << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ string S; cin >> S; int len = S.size(); if(len == 1){ int n = S.at(0) - '0'; if(n % 8 == 0){ cout << "Yes" << endl; }else{ cout << "No" << endl; } return 0; } if(len == 2){ int a = S.at(0) - '0'; int b = S.at(1) - '0'; if((a * 10 + b) % 8 == 0 || (b * 10 + a) % 8 == 0){ cout << "Yes" << endl; }else{ cout << "No" << endl; } return 0; } map<int,int> sum_i; for(int i = 1; i < 10; i++){ sum_i[i] = 0; } for(int i = 0; i < len; i++){ int num = S.at(i) - '0'; sum_i[num]++; } bool flag = false; for(int i = 100; i < 1000; i++){ if(i % 8 != 0) continue; string str = to_string(i); if(str.at(0) == '0' || str.at(1) == '0' || str.at(2) == '0'){ continue; } map<int,int> m; for(int i = 1; i < 10; i++){ m[i] = 0; } int c = i; while(c > 0){ m[c%10]++; c /= 10; } int p = 0; for(int i = 1; i <= 9; i++){ if(sum_i[i] >= m[i]){ p++; } } if(p == 9) flag = true; } if(flag){ cout << "Yes" << endl; }else{ cout << "No" << endl; } return 0; }
#include<bits/stdc++.h> #define pb push_back #define mk make_pair #define ll long long #define ss second #define ff first #define mod 1000000007 #define w(x) ll x; cin>>x; while(x--) #define ps(x,y) fixed<<setprecision(y)<<x; #define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in) #define re(i, j) fo(i, 0, j, 1) #define pi acos(-1) #define all(cont) cont.begin(), cont.end() #define countbit(x) __builtin_popcount(x) #define mod 1000000007 #define de(n) ll n;cin>>n; #define def(a,n) ll n;cin>>n;ll a[n];re(i,n){cin>>a[i];} #define defi(a,n,k) ll n;cin>>n; ll k;cin>>k;ll a[n];re(i,n){cin>>a[i];} #define deb(x) cout<<#x<<"="<<x<<endl; #define tr(it,a) for(auto it=a.begin();it!=a.end();it++) #define nl cout<<endl; using namespace std; void cp() { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } //18-1326D1 1208B 845C 912B 1009B 1350C 20C 1333C 1234D 1327C 1305B 1304B (or in matrix) bool solve(string s) { ll n=s.length(); if(n==1) { if(s[0]=='8') return true; } if(n==2) { if(stoi(s)%8==0) return true; else { swap(s[0],s[1]); if(stoi(s)%8==0) return true; } } map<ll,ll>p; re(i,n) p[s[i]-'0']++; for(ll i=112;i<=1000;i+=8) { auto h=p; ll j=i; bool got=0; while(j!=0) { h[j%10]--; if(h[j%10]<0) { got=1; break; } j=j/10; } if(got==0) return true; } return false; } int main() { //cp(); //w(x) { string s; cin>>s; //ll n=s.length(); if(solve(s)) cout<<"Yes\n"; else { cout<<"No\n"; } } }
#include <bits/stdc++.h> using namespace std; // Compile with "(g++) -std=c++11 -Wall -Wextra -Wconversion -Wshadow -Dcychien" #ifdef cychien #define debug(...) do {\ fprintf(stderr, "%s - %d : (%s) = ", __PRETTY_FUNCTION__, __LINE__, #__VA_ARGS__);\ _DO(__VA_ARGS__);\ }while(0) template<typename I> void _DO(I&&x) {cerr << x << '\n';} template<typename I, typename ...T> void _DO(I&&x,T&&...tail) {cerr << x << ", "; _DO(tail...);} #define IOS #else #define debug(...) #define IOS ios_base::sync_with_stdio(0);cin.tie(0) #endif #define FOR(i, n) for(int i = 0; i < n; i++) #define FOR1(i, n) for(int i = 1; i <= n; i++) #define pb push_back #define mp make_pair #define X first #define Y second #define SZ(x) (ll)x.size() #define ALL(x) (x).begin(),(x).end() #define SORT(x) sort(ALL(x)) typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<vll> vvll; const int NF = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; const ll MOD = 1e9 + 7; const ld PI = 3.14159265358979323846264338327950288; int main() { IOS; int t; cin >> t; while (t--){ int n; cin >> n; string a; cin >> a; cin >> a; cin >> a; FOR (i, n) cout << 0; FOR (i, n) cout << 1; cout << "0\n"; } return 0; }
#include "bits/stdc++.h" using namespace std; #define ll long long int int main(int argc, char const *argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr); ll t, n, k; cin >> n; vector <ll> a, b; for (ll i = 1; i <= n; i++) { cin >> k; a.push_back(k); } for (ll i = 1; i <= n; i++) { cin >> k; b.push_back(k); } ll ans = 0; for (ll i = 0; i < n; i++) { ans += a[i] * b[i]; } cout << (ans == 0 ? "Yes" : "No") << endl; return 0; }
/** * Author : Ujjawal Pabreja [cuber_coder] * Email : [email protected] */ #include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n" void Solve() { int l, r; cin >> l >> r; int n = r - l + 1; cout << (2 * l <= r ? n * (n - l) - n * (n - 1) / 2 + l * (l - 1) / 2 : 0) << endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int testcases = 1; cin >> testcases; for (int i = 1; i <= testcases; i++) { Solve(); } return 0; }
#include<iostream> #include<algorithm> #include<string> #include<vector> #include<cmath> #include<map> #include<random> #include<iomanip> #include<queue> #include<stack> #include<assert.h> #include<time.h> #define int long long #define double long double #define rep(i,n) for(int i=0;i<n;i++) #define REP(i,n) for(int i=1;i<=n;i++) #define ggr getchar();getchar();return 0; #define prique priority_queue constexpr auto mod = 998244353; #define inf 1e15 #define key 1e9 using namespace std; typedef pair<int, int>P; template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); } template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); } const int MAX = 2330000; int fac[MAX], finv[MAX], inv[MAX]; 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; } } int COMB(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; } bool prime(int n) { int cnt = 0; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0)cnt++; } if (cnt != 1)return false; else return n != 1; } int gcd(int x, int y) { if (y == 0)return x; return gcd(y, x % y); } int lcm(int x, int y) { return x / gcd(x, y) * y; } int mod_pow(int x, int y, int m) { int res = 1; while (y) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= (i % mod); res %= mod; } return res; } int comb(int x, int y) { if (y > x)return 0; return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod; } class UnionFind { protected: int* par, * rank, * size; public: UnionFind(unsigned int size) { par = new int[size]; rank = new int[size]; this->size = new int[size]; rep(i, size) { par[i] = i; rank[i] = 0; this->size[i] = 1; } } int find(int n) { if (par[n] == n)return n; return par[n] = find(par[n]); } void unite(int n, int m) { n = find(n); m = find(m); if (n == m)return; if (rank[n] < rank[m]) { par[n] = m; size[m] += size[n]; } else { par[m] = n; size[n] += size[m]; if (rank[n] == rank[m])rank[n]++; } } bool same(int n, int m) { return find(n) == find(m); } int getsize(int n) { return size[find(n)]; } }; int dight(int n) { int ans = 1; while (n >= 10) { n /= 10; ans++; } return ans; } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int t; signed main() { cin >> t; rep(i, t) { int l, r; cin >> l >> r; if (l > r - l)cout << 0 << endl; else if (r > r - l) { int x = (r - l + 1) * (r - 2 * l + 1); int y = ((r - l + 1) * (r - l) - (l - 1) * l) / 2; cout << x - y << endl; } else { int x = (r - l + 1) * (r - l + 1); int y = ((r + 1) * r - (l - 1) * l) / 2; cout << x - y << endl; } } ggr }
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <set> using namespace std; int main(){ long long n; cin >> n; vector<long long> a(n); set<long long> dup; multiset<long long> dupnum; for (long long i = 0; i < n; i++) { cin >> a[i]; dup.insert(a[i]); dupnum.insert(a[i]); } long long all = (n*(n-1))/2; //cout << all << endl; for (auto x : dup){ long long count = dupnum.count(x); //cout << count << endl; if (count >= 2){ long long minus = (count*(count-1))/2; all-=minus; } } cout << all << endl; }
#include<bits/stdc++.h> #define int long long #define MOD 1000000007 #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL) #define ll long long #define rep(i,a,b) for(int i=a;i< b;i++) #define endl "\n" #define all(a) a.begin(),a.end() #define pii pair<int,int> #define fr first #define sc second #define INF (int)(1e18) #define pb push_back #define ppb pop_back #define sz(x) (int)((x).size()) #define vi vector<int> #define vvi vector<vector<int>> #define PI 3.14159265358979323846 using namespace std; template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;} template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;} const int N=2e5+5; void test_case() { int n; cin>>n; map<int,int> m; int ans=0; rep(i,0,n ){ int x; cin>>x; ++m[x]; ans+=i+1-m[x]; // ++m[x]; } cout<< ans; } signed main() { fast_io; #ifdef SIEVE sieve(); #endif #ifdef NCR init(); #endif int t=1; // cin>>t; rep(i,0,t){ //cout<< "Case #" << i+1 << ": "; test_case(); } return 0; } //taskkill -im main.exe -f
#include <bits/stdc++.h> #define rep3(i, s, n, a) for (long long i = (s); i < (long long)(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>; using Pll = pair<ll, ll>; int main() { ll n, slen = 10; rep(i, 9){ slen *= 10; } cin >> n; string t; cin >> t; ll onecnt=0, res, firstone; bool appear = false, valid = true; rep(i, n){ if(!appear&&t[i]=='1'){ onecnt++; }else{ if(!appear&&t[i]=='0'){ appear = true; firstone = i; onecnt = 0; }else{ if(t[i]=='1'){ onecnt++; }else{ if(onecnt!=2){ valid = false; break; }else{ onecnt = 0; } } } } if(onecnt>2){ valid = false; break; } } if(!valid){ res = 0; }else{ if(n==1){ if(t[0]=='0'){ res = slen; }else{ res = 2LL * slen; } }else{ if(t=="11"){ res = slen; }else{ res = (3LL * slen - n - 2LL + firstone) / 3LL + 1LL; } } } cout << res << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(ll i=0;i<n;++i) #define rrep(i, n) for(ll i=n-1;i>=0;--i) #define rep1(i, n) for(ll i=1; i<=n; ++i) #define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();++itr) #define ALL(a) (a).begin(),(a).end() template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}} template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}} using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using pll = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll LINF = 1LL << 60; const int INF = 1e9 + 7; const double PI = 3.1415926535897932384626; ll mod(ll a, ll m){return (a + m) % m;} int main(){ ll n; string t; cin >> n >> t; ll base = 1e10; if(n == 1){ if(t == "0")cout << base << endl; else cout << 2 * base << endl; return 0; } else if(n == 2){ if(t == "00")cout << 0; else { if(t[0] == '0')cout << (3*base - 2) / 3 << endl; else cout << base << endl; } return 0; } bool ok = true; rep(i, n-2){ string subt = t.substr(i, 3); if(subt == "110" || subt == "101" || subt == "011")continue; ok = false; } ll ans = 0; if(ok){ ans = 3 * base - max(0LL, n-3); if(t[0] == '0')ans -= 2; else if(t.substr(0, 2) == "10")ans -= 1; ans /= 3; } cout << ans << endl; }
using namespace std; #include<iostream> int main(){ float a, b; cin >> a >> b; cout << a * (b / 100) << endl; return 0; }
#include "bits/stdc++.h" #include<algorithm> using namespace std; #define int long long #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x).begin(),(x).end() #define uniq(v) (v).erase(unique(all(v)),(v).end()) #define sz(x) (int)((x).size()) #define fr first #define sc second #define pli pair<int,int> #define rep(i,a,b) for(int i=a;i<b;i++) #define mem1(a) memset(a,-1,sizeof(a)) #define mem0(a) memset(a,0,sizeof(a)) #define ppc __builtin_popcount #define ppcll __builtin_popcountll template<typename T1, typename T2>istream& operator>>(istream& in, pair<T1, T2> &a) {in >> a.fr >> a.sc; return in;} template<typename T1, typename T2>ostream& operator>>(ostream& out, pair<T1, T2> a) {out << a.fr << " " << a.sc; return out;} template<typename T, typename T1>T amax(T &a, T1 b) {if (b > a)a - b; return a;} template<typename T, typename T1>T amin(T &a, T1 b) {if (b < a)a - b; return a;} const long long INF = 1e18; const int32_t M = 1e9 + 7; const int32_t MM = 998244353; const int N = 0; void solve() { int a, b; cin >> a >> b; double ans = a * b / 100.0; cout << ans; cout << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #ifdef SIEVE sieve(); #endif #ifdef NCR init(); #endif int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include<bits/stdc++.h> #include <iomanip> using namespace std; #define pb push_back #define ll long long int #define pll pair<ll,ll> vector <int> g[102], gr[102]; int comp_size[102]; vector<bool> used; int num = 0; void dfs1 (int v) { used[v] = true; ++num; for (size_t i=0; i<gr[v].size(); ++i){ if (!used[ gr[v][i] ]){ dfs1 (gr[v][i]); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); std::cout << std::setprecision(12) ; std::cout << std::fixed; double ans = 0.0; int n; cin>>n; string s[n]; for(int i=0;i<n;i++){ cin>>s[i]; for(int j=0;j<n;j++){ if(s[i][j]=='1'){ g[i].push_back (j); gr[j].push_back (i); } } } for (int i=0; i<n; ++i){ used.assign (n, false); num =0; dfs1(i); ans = ans +(1.0/(double)(num)); } cout<<ans<<"\n"; }
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,mmx,avx") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define PB push_back #define MP make_pair #define endl "\n" #define fst first #define snd second const int UNDEF = -1; const int INF=1<<30; template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; } template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; } typedef pair<ll,ll> pll;typedef vector<ll> vll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<pii> vpii;typedef vector<pll> vpll; template<typename T> void makeunique(vector<T> &vx) {sort(vx.begin(),vx.end());auto it=unique(vx.begin(),vx.end());vx.resize(std::distance(vx.begin(),it));} vvi g; vi vdeg; const int n=400000+8; void solve(long long nume, std::vector<long long> a, std::vector<long long> b){ g.resize(n+1); vdeg.resize(n+1); for (int i=0;i<nume;i++) { int x=a[i],y=b[i]; g[x].PB(y); g[y].PB(x); } queue<int> q; for (int x=1;x<=n;x++) { int deg=g[x].size(); vdeg[x]=(deg); if (deg==1) q.push(x); } int ones=0; while(!q.empty()) { int x=q.front(); q.pop(); if (vdeg[x]==1) { ones++; vdeg[x]--; for (auto &y:g[x]) { --vdeg[y]; if (vdeg[y]==1) q.push(y); } } } int final=ones; for (int x=1;x<=n;x++) if(vdeg[x]>0) final++; printf("%d\n",final); } // Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) int main(){ long long N; scanf("%lld",&N); std::vector<long long> a(N); std::vector<long long> b(N); for(int i = 0 ; i < N ; i++){ scanf("%lld",&a[i]); scanf("%lld",&b[i]); } solve(N, std::move(a), std::move(b)); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A.at(i); A.at(i) %= 200; } int64_t count, ans = 0; for (int i = 0; i < 200; i++) { count = 0; for (int j : A) { if (i == j) count++; } ans += count * (count - 1) / 2; } cout << ans << endl; }
///* ***Bismillahir Rahmanir Rahim*** */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double dl; typedef unsigned long long ull; #define pb push_back #define PB pop_back #define nn "\n" #define O_O \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define all(p) p.begin(), p.end() #define zz(v) (ll) v.size() #define ss ' ' #define MEM(a, b) memset(a, (b), sizeof(a)) #define CLR(p) memset(p, 0, sizeof(p)) #define precision(a) fixed << setprecision(a) #define rep(i, b) for (ll i = 0; i < (b); i++) #define rep1(i, b) for (int i = 1; i <= (b); i++) //#define rep(s,e) for(i=s;i<e;i+=1) //#define rep(i,a,b) for(int i=(a);i<(b);i++) #define fr(i, b, a) for (int i = (b); i >= (a); i--) #define rep2(i, a, b, c) for (int i = (a); i != (b); i += (c)) #define arrsize(a) (sizeof(a) / sizeof(a[0])) //#define arrsize(a) (sizeof(a)/sizeof(*a)) #define S(a) scanf("%lld", &a) #define SS(a, b) scanf("%lld %lld", &a, &b) #define SSS(a, b, c) scanf("%lld %lld %lld", &a, &b, &c) #define gcd(a, b) __gcd(a, b) #define lcm(a, b) (a * b) / gcd(a, b) #define pi acos(-1.0) #define ff first #define sc second #define print(v) \ for (ll i : v) \ cout << i << ss typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pair<ll, ll>> vpll; typedef vector<ll> vll; typedef map<string, ll> msl; typedef map<ll, ll> mll; #define yes cout << "YES\n" #define no cout << "NO\n" bool comp(pair<ll, ll> a, pair<ll, ll> b) { if (a.first != b.first) return a.first > b.first; else return a.second > b.second; } //ll minelementindex = min_element(v.begin(),v.end()) - v.begin(); //ll minelement = *min_element(v.begin(), v.end()); //ll maxelementindex = max_element(v.begin(),v.end()) - v.begin(); //ll maxelement = *max_element(v.begin(), v.end()); //memset(ar,-1,sizeof(ar)); //#define sort(x) sort(x.begin(), x.end()) //sort(a,a+n,greater<ll>()) //for (auto it = mp.begin(); it != mp.end(); ++it){} // string x(w.size(),'1'); //auto s =to_string(42); //string s = "12345"; // object from the class stringstream //stringstream geek(s); // The object has the value 12345 and stream // it to the integer x //int x = 0; //geek >> x; #define MAX 1000005 #define precision(a) fixed << setprecision(a) #define mod 1000000007 int main() { //O_O ; ll n; cin >> n; map<ll, ll> mp; for (ll i = 0; i < n; i++) { ll x; cin >> x; x %= 200; mp[x]++; } ll ans = 0; for (auto it = mp.begin(); it != mp.end(); ++it) { ll c = it->second; ans += ((c * (c - 1)) / 2); } cout << ans << nn; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){int a,b,x,y;cin>>a>>b>>x>>y;if(a>b)a--; int p=min(2*x,y);p*=abs(a-b);p+=x;cout<<p<<endl;}
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx") #pragma GCC target ("avx2,fma") #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> //#include <atcoder/all> #define F first #define S second #define int long long #define ll long long //#define int unsigned long long #define pb push_back #define rank fewfewf #define double long double using namespace std; using namespace __gnu_pbds; //using namespace atcoder; typedef tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 1050; const int K = 90; const int mod = 1e9 + 7; vector<pair<int,int>> g[N]; int d[N]; main(){ ios_base::sync_with_stdio(0); cin.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int a, b, x, y; cin >> a >> b >> x >> y; int n = 100; for (int i = 0; i < n - 1; i++){ g[i].pb({i + 1, y}); g[i + 1].pb({i, y}); g[i + n].pb({i + n + 1, y}); g[i + n + 1].pb({i + n, y}); g[i + 1].pb({i + n, x}); g[i + n].pb({i + 1, x}); } for (int i = 0; i < n; i++){ g[i].pb({i + n, x}); g[i + n].pb({i, x}); } a--; b--; b += n; for (int i = 0; i < n + n; i++) d[i] = 1e9; set<pair<int,int>> s; s.insert({0, a}); d[a] = 0; while(!s.empty()){ int v = (*s.begin()).S; s.erase(s.begin()); for (auto e: g[v]){ if (d[e.F] > d[v] + e.S){ s.erase({d[e.F], e.F}); d[e.F] = d[v] + e.S; s.insert({d[e.F], e.F}); } } } cout << d[b]; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <queue> #include <set> /* MACROS START */ #define input std::cin #define for2(i,n) for(int i=0; i<n; i++) #define for3(i,a,n) for(int i=a; i<n; i++) #define for4(i,a,n,s) for(int i=a; i<n; i+=s) using lint = long long int; using namespace std; template <typename T> void printvec(T vec) { for (auto& a: vec) cout << a << " "; cout << endl; } /* MACROS END */ /* LIBRARY START */ /* LIBRARY END */ struct Expectation { double exact = 0, variable = 0; Expectation& operator+=(const Expectation& other) { this->exact += other.exact; this->variable += other.variable; return *this; } Expectation& operator-=(const Expectation& other) { this->exact -= other.exact; this->variable -= other.variable; return *this; } }; Expectation operator/(const Expectation& e, double d) { return {e.exact/d, e.variable/d}; } Expectation operator+(const Expectation& e, int d) { return {e.exact+d, e.variable}; } int main() { std::ios_base::sync_with_stdio(0); int n, m, k; input >> n >> m >> k; set<int> traps; for2(i, k) { int tr; input >> tr; traps.insert(tr); } queue<Expectation> runsum; for2(i, m) { runsum.push({0, 0}); } Expectation sum = {0, 0}; for(int i=n-1; i>0; i--) { if (traps.count(i)) { runsum.push({0, 1}); } else { runsum.push((sum + m) / m); } sum -= runsum.front(); runsum.pop(); sum += runsum.back(); } Expectation exp = (sum + m) / m; if (exp.variable >= 1.0 - 1e-9) std::cout << -1 << std::endl; else { double ans = exp.exact / (1.0 - exp.variable); std::cout << std::fixed << ans << std::endl; } }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define pi 3.141592653589793238 #define int long long #define ll long long #define ld long double using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); long long powm(long long a, long long b,long long mod) { long long res = 1; while (b > 0) { if (b & 1) res = res * a %mod; a = a * a %mod; b >>= 1; } return res; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ld pre[200005]; ld cnt[200005]; ld dp[200005]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); #ifndef ONLINE_JUDGE if(fopen("INPUT.txt","r")) { freopen("INPUT.txt","r",stdin); freopen("OUTPUT.txt","w",stdout); } #endif int n,m,k; cin>>n>>m>>k; int a[n+m+2]={0}; for(int i=0;i<k;i++) { int x; cin>>x; a[x]=1; } for(int i=n;i>=0;i--) { cnt[i]=cnt[i+1]+a[i]; } ld l=1,r=1e12; ld eps=1e-8; while(r-l>eps) { ld mid=(l+r)/2; for(int i=n-1;i>=0;i--) { if(a[i]==1) { dp[i]=mid; pre[i]=pre[i+1]+dp[i]; } else { dp[i]=(pre[i+1]-pre[i+m+1])/m+1; pre[i]=pre[i+1]+dp[i]; } } if(dp[0]<mid) { r=mid; } else { l=mid; } } if(l>1e11) { cout<<-1; return 0; } cout<<fixed<<setprecision(5)<<l; }
#include <bits/stdc++.h> using namespace std; int main(){ long long N; cin >> N; long long Sa=0; vector<long long> V(N); for(int i=0;i<N;i++){ long long a,b; cin >> a >> b; Sa += a; V[i] = a*2+b; } sort(V.rbegin(),V.rend()); for(int i=0;i<=N;i++){ if(Sa<0){ cout << i << endl; return 0; } Sa -= V[i]; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll,ll>; using pld = pair<ld,ld>; using vll = vector<ll>; using vld = vector<ld>; #define _GLIBCXX_DEBUG #define rep(j, m) for (ll j = 0; j < (ll)(m); j++) #define rep2(i, l, n) for (ll i = l; i < (ll)(n); i++) #define all(v) v.begin(), v.end() const ld PI = 3.1415926535897932; const ll MOD = 1000000007; const ll MOD2 = 998244353; int main() { ll N; cin >> N; ll sum = 0; vll V(N); rep(i,N) { ll a; ll b; cin >> a >> b; sum += a; V[i] = 2*a + b; } sort(all(V)); reverse(all(V)); ll sum2 = 0; rep(i,N) { sum2 += V[i]; if (sum2 > sum) {cout << i + 1 << endl;break;} } }
#pragma GCC optimize ("O2") #pragma GCC target ("avx") #include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; ll A[200000]; int K[3] = {}; rep(i, N << 1) { ll a; char c; cin >> a >> c; ll C = (ll(c) >> 4 | ll(c) << 1) & 3; K[C]++; A[i] = a | C << 50; } sort(A, A + N * 2); if (K[0] % 2 == 0 && K[1] % 2 == 0 && K[2] % 2 == 0) { co(0); return 0; } auto P = A; auto Q = A + K[0]; auto R = A + K[0] + K[1]; const ll ma = (1ll << 50) - 1; rep(i, N << 1) A[i] &= ma; ll sai[3] = {}; ll saiq = 1e18, sair = 1e18; int q = 0, r = 0; rep(p, K[0]) { if (q < K[1]) if (saiq > abs(Q[q] - P[p])) saiq = abs(Q[q] - P[p]); while (q < K[1] - 1 && Q[q] < P[p]) { q++; if (saiq > abs(Q[q] - P[p])) saiq = abs(Q[q] - P[p]); } if (r < K[2]) if (sair > abs(R[r] - P[p])) sair = abs(R[r] - P[p]); while (r < K[2] - 1 && R[r] < P[p]) { r++; if (sair > abs(R[r] - P[p])) sair = abs(R[r] - P[p]); } } sai[2] = saiq; sai[1] = sair; sair = 1e18; r = 0; q = 0; while (q < K[1]) { if (r < K[2]) if (sair > abs(R[r] - Q[q])) sair = abs(R[r] - Q[q]); while (r < K[2] - 1 && R[r] < Q[q]) { r++; if (sair > abs(R[r] - Q[q])) sair = abs(R[r] - Q[q]); } q++; } sai[0] = sair; ll kotae = 1e18; if (K[0] % 2 == 0) kotae = min(sai[0], sai[1] + sai[2]); else if (K[1] % 2 == 0) kotae = min(sai[1], sai[2] + sai[0]); else kotae = min(sai[2], sai[0] + sai[1]); co(kotae); Would you please return 0; }
#include<algorithm> #include<cstdio> #define ll long long #define MaxN 200500 using namespace std; const ll INF=1ll<<60; struct Data{ll x;char c;}a[MaxN]; bool cmp(const Data &A,const Data &B) {return A.x<B.x;} int n,o[255];ll sav[255]; int main() { scanf("%d",&n);n*=2; for (int i=1;i<=n;i++){ scanf("%lld%s",&a[i].x,&a[i].c); o[a[i].c]++; } bool fl=0; for (int i='A';i<='Z';i++)if (o[i]&1)fl=1; if (!fl){puts("0");return 0;} sort(a+1,a+n+1,cmp); for (int i='A';i<='Z';i++)sav[i]=INF; ll ans1=INF,ans2=0; for (int i=1;i<=n;i++)if (o[a[i].c]&1){ if (i>1&&a[i-1].c!=a[i].c){ sav[a[i].c]=min(sav[a[i].c],a[i].x-a[i-1].x); int p=i-1;while(p>1&&!(o[a[p].c]&1))p--; if (o[a[p].c]&1&&a[p].c!=a[i].c)ans1=min(ans1,a[i].x-a[p].x); } if (i<n&&a[i+1].c!=a[i].c){ sav[a[i].c]=min(sav[a[i].c],a[i+1].x-a[i].x); int p=i+1;while(p<n&&!(o[a[p].c]&1))p++; if (o[a[p].c]&1&&a[p].c!=a[i].c)ans1=min(ans1,a[p].x-a[i].x); } } for (int i='A';i<='Z';i++) if (o[i]&1)ans2+=sav[i]; printf("%lld",min(ans1,ans2)); return 0; }
#include<bits/stdc++.h> using namespace std; #define gc getchar_unlocked #define fo(i,n) for(i=0;i<n;i++) #define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define ll long long #define si(x) scanf("%d",&x) #define sl(x) scanf("%lld",&x) #define ss(s) scanf("%s",s) #define pi(x) printf("%d\n",x) #define pl(x) printf("%lld\n",x) #define ps(s) printf("%s\n",s) #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define set(x, i) (x | (1 << i)) #define check(x, i) (x & (1 << i)) #define printcase printf("Case %d: ",test++) #define PI 3.1415926535897932384626 typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); int rng(int lim) { uniform_int_distribution<int> uid(0,lim-1); return uid(rang); } ll mpow(ll base, ll exp); void ipgraph(int n, int m); void dfs(int u, int par); const int mod = 1'000'000'007; const int N = 3e5, M = N; //======================= int test = 1; vi g[N]; int a[N]; void solve() { int i, j, n, m; // printcase; cin >> n; set <int> nums; fo(i,n) { int a; cin >> a; nums.insert(a); } ll ans = 1; int itr = 0; for(int i: nums) { ans = (ans * (i + 1- itr))%mod; itr = i; } ans%= mod; pl(ans%mod); } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); int t = 1; // cin >> t; while(t--) { solve(); } return 0; } ll mpow(ll base, ll exp) { base %= mod; ll result = 1; while (exp > 0) { if (exp & 1) result = ((ll)result * base) % mod; base = ((ll)base * base) % mod; exp >>= 1; } return result; } void ipgraph(int n, int m){ int i, u, v; while(m--){ cin>>u>>v; u--, v--; g[u].pb(v); g[v].pb(u); } } void dfs(int u, int par){ for(int v:g[u]){ if (v == par) continue; dfs(v, u); } }
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265358979; #define setup\ cin.tie(0);\ ios::sync_with_stdio(false);\ cout << setprecision(20) << fixed; #define int long long int #define db double #define P pair<int,int> #define F first #define S second #define endl "\n" #define dtor(deg) (((deg)/360)*2*pi) #define rtod(rad) (((rad)/2/pi)*360) #define all(a) a.begin(),a.end() #define Srep(n) for(int i = 0; i < n; i++) #define Lrep(i,a,n) for(int i = a; i < n; i++) #define Brep1st(n) for(int bit = 0; bit < (1 << n); bit++) #define Brep2nd(n) Srep(n) if(bit >> i & 1) #define rep2d(n,m) Srep(n) Lrep(j,0,m) #define vi vector<int> #define vvi vector<vi> #define vdb vector<db> #define vb vector<bool> int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } signed main(){ setup; int n, ans = 1; cin >> n; Lrep(i,2,n+1) ans = lcm(ans, i); cout << ans + 1 << endl; }
#include <iostream> #include <vector> //#include <string> #include <algorithm> //#include <math.h> //#include <queue> //#include <stack> //#include <iomanip> // sometimes used //#include <set> //#include <map> //#include <numeric> //#include <list> //#include <deque> //#include <unordered_map> typedef long long LL; //typedef long double LD; using namespace std; //#define MOD 1000000007 //#define MOD 998244353 //#define MAX 200100 //#define NIL -1 #define INF 1000000000000000000 //const LL SEG_VAL = 1 << 19; int main(){ cin.tie(0); ios::sync_with_stdio(0); LL N; LL M; cin >> N >> M; vector<LL> a(N); vector<vector<LL>> edge_f(N); vector<vector<LL>> edge_b(N); vector<LL> dp_min(N, INF); vector<LL> dp_max(N, 0); LL x; LL y; for(LL i=0; i<N; i++){ cin >> a[i]; } for(LL i=0; i<M; i++){ cin >> x >> y; x--; y--; edge_f[x].push_back(y); edge_b[y].push_back(x); } for(LL i=0; i<N; i++){ dp_min[i]=min(dp_min[i], a[i]); for(LL j=0; j<edge_f[i].size(); j++){ dp_min[edge_f[i][j]]=min(dp_min[edge_f[i][j]], dp_min[i]); } } for(LL i=N-1; i>=0; i--){ dp_max[i]=max(dp_max[i], a[i]); for(LL j=0; j<edge_b[i].size(); j++){ dp_max[edge_b[i][j]]=max(dp_max[edge_b[i][j]], dp_max[i]); } } /* for(LL i=0; i<N; i++){ cout << i << " " << dp_min[i] << " " << dp_max[i] << endl; } */ LL ans=(-1)*INF; for(LL i=0; i<N; i++){ for(LL j=0; j<edge_f[i].size(); j++){ ans=max(ans, dp_max[edge_f[i][j]]-dp_min[i]); } } cout << ans << endl; return 0; }
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful ----- #include<bits/stdc++.h> using namespace std; #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 deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define int long long #define endl "\n" #define mod 1000000007 #define inf (int)1e18 const int mxn = 2e5+10; vector<int> g[mxn]; bool vis[mxn]; int a[mxn]; vector<int> maxes(mxn,-1e14); void dfs(int v){ vis[v] = 1; for(int u : g[v]){ if(!vis[u]) dfs(u); maxes[v] = max(maxes[v],a[u]); maxes[v] = max(maxes[v],maxes[u]); } } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; cin >> n >> m; for(int i=1;i<=n;i++) cin >> a[i]; for(int i=1;i<=m;i++){ int u,v; cin >> u >> v; g[u].push_back(v); } int ans = -inf; for(int i=1;i<=n;i++){ if(!vis[i]){ dfs(i); } } for(int i=1;i<=n;i++){ if(maxes[i]!=-1e14){ ans = max(ans,maxes[i]-a[i]); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> //using namespace atcoder; using namespace std; #pragma region Macros using ll = long long; #define int ll using pii = pair<int, int>; using tiii = tuple<int, int, int>; template<class T = int> using V = vector<T>; template<class T = int> using VV = V<V<T>>; #define IOS\ ios::sync_with_stdio(false);\ cin.tie(0);\ cout.tie(0); #define FOR(i,l,r) for(int i=(l);i<int(r);++i) #define REP(i,n) FOR(i,0,n) #define REPS(i,n) FOR(i,1,n+1) #define RFOR(i,l,r) for(int i=(l);i>=int(r);--i) #define RREP(i,n) RFOR(i,n-1,0) #define RREPS(i,n) RFOR(i,n,1) #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back #define all(x) (x).begin(),(x).end() #define SORT(name) sort(name.begin(), name.end()) #define RSORT(name)\ SORT(name);\ reverse(all(name)); #define ZERO(p) memset(p, 0, sizeof(p)) #define MINUS(p) memset(p, -1, sizeof(p)) inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';} inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';} template <class T> inline void print(T x){ cout << x << '\n';} template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; } template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; } const ll LLINF = (1LL<<60); const int INF = (1LL<<30); const double DINF = std::numeric_limits<double>::infinity(); #pragma endregion const int MOD = 1000000007; #if 1 # define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__) #else # define DBG(fmt, ...) #endif const int MAX_N = 100010; signed main() { IOS; int x; cin >> x; if(x < 0) { x = 0; } print(x); return 0; }
#include "bits/stdc++.h" using namespace std; #define int long long #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x).begin(),(x).end() #define uniq(v) (v).erase(unique(all(v)),(v).end()) #define sz(x) (int)((x).size()) #define fr first #define sc second #define pii pair<int,int> #define rep(i,a,b) for(int i=a;i<b;i++) #define mem1(a) memset(a,-1,sizeof(a)) #define mem0(a) memset(a,0,sizeof(a)) #define ppc __builtin_popcount #define ppcll __builtin_popcountll template<typename T1, typename T2>istream& operator>>(istream& in, pair<T1, T2> &a) {in >> a.fr >> a.sc; return in;} template<typename T1, typename T2>ostream& operator<<(ostream& out, pair<T1, T2> a) {out << a.fr << " " << a.sc; return out;} template<typename T, typename T1>T amax(T &a, T1 b) {if (b > a)a = b; return a;} template<typename T, typename T1>T amin(T &a, T1 b) {if (b < a)a = b; return a;} const long long INF = 1e18; const int32_t M = 1e9 + 7; const int32_t MM = 998244353; void solve() { int a, b, c; cin >> a >> b >> c; if (a == b) cout << c; else if (a == c) cout << b; else if (b == c) cout << a; else cout << 0; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> #include <algorithm> #include <iostream> #include <stdlib.h> using namespace std; #define INF 1e9 #define PI 3.141592653589793238 #define N 1000000010 #define mod 1000000007 #define REP(inc, bgn, end) for(int inc=bgn; inc<end; inc++) typedef long long ll; int main() { ll n; cin>>n; cout << 100-(n%100) << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int x,n; cin>>x; for(int i=1;i<=100000;i++) { if((x+i)%100==0) { cout<<i; return 0; } if(x%100==0) { break; } } cout<<"100"; 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++) using namespace std; using ll = long long; 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 MOD 998244353 int main(){ int a,b,c,x[3]; cin>>a>>b>>c; x[0]=a; x[1]=b; x[2]=c; sort(x,x+3); cout<<x[1]+x[2]<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; // ModIntR::set_mod() struct ModIntR { int x; ModIntR() : x(0) {} ModIntR(int64_t y) : x(y >= 0 ? y % mod() : (mod() - (-y) % mod()) % mod()) {} static int &mod() { static int mod = 0; return mod; } static void set_mod(int md) { mod() = md; } ModIntR &operator+=(const ModIntR &p) { if ((x += p.x) >= mod()) x -= mod(); return *this; } ModIntR &operator-=(const ModIntR &p) { if ((x += mod() - p.x) >= mod()) x -= mod(); return *this; } ModIntR &operator*=(const ModIntR &p) { long long m = mod(); x = (int)(1LL * x * p.x % m); return *this; } ModIntR &operator/=(const ModIntR &p) { *this *= p.inverse(); return *this; } ModIntR operator-() const { return ModIntR(-x); } ModIntR operator+(const ModIntR &p) const { return ModIntR(*this) += p; } ModIntR operator-(const ModIntR &p) const { return ModIntR(*this) -= p; } ModIntR operator*(const ModIntR &p) const { return ModIntR(*this) *= p; } ModIntR operator/(const ModIntR &p) const { return ModIntR(*this) /= p; } bool operator==(const ModIntR &p) const { return x == p.x; } bool operator!=(const ModIntR &p) const { return x != p.x; } ModIntR 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 ModIntR(u); } ModIntR pow(int64_t n) const { ModIntR res(1), mul(x); while (n) { if (n & 1) res *= mul; mul *= mul; n >>= 1; } return res; } friend ostream &operator<<(ostream &os, const ModIntR &p) { return os << p.x; } friend istream &operator>>(istream &is, ModIntR &a) { int64_t t; is >> t; a = ModIntR(t); return (is); } }; int n, k, m, ofst = 2e6, len; vector<ModIntR> cnt, memo; void add(int x); void sub(int x); bool isvalid(int x) { return -len + ofst <= x && x <= len + ofst; } int main() { cin >> n >> k >> m; len = n * (n + 1) / 2 * k; ModIntR::set_mod(m); cnt.assign((int)4e6, 0); memo.assign((int)4e6, 0); cnt[ofst] = 1; for (int i = 1; i <= n; ++i) add(i); for (int i = 1; i <= n; ++i) { // for (int j = -6; j <= 6; ++j) cout << cnt[j + ofst] << " "; // cout << endl; if (n + 1 - i != 0) sub(n + 1 - i); // for (int j = -6; j <= 6; ++j) cout << cnt[j + ofst] << " "; // cout << endl; cout << (cnt[ofst] * (k + 1)) - 1 << endl; add(-i); // for (int j = -6; j <= 6; ++j) cout << cnt[j + ofst] << " "; // cout << endl; } return 0; } void add(int x) { vector<ModIntR> sum(abs(x), 0); int sign = x / abs(x); x = abs(x); for (int i = -len * sign + ofst; isvalid(i); i += sign) { sum[i % x] -= memo[i]; memo[i] = 0; ModIntR tmp = sum[i % x]; sum[i % x] += cnt[i]; if (isvalid(i + sign * x * (k + 1))) memo[i + sign * x * (k + 1)] = cnt[i]; cnt[i] += tmp; } } void sub(int x) { vector<ModIntR> sum(abs(x), 0); int sign = x / abs(x); x = abs(x); for (int i = -len * sign + ofst; isvalid(i); i += sign) { sum[i % x] -= memo[i]; memo[i] = 0; ModIntR tmp = sum[i % x]; cnt[i] -= tmp; sum[i % x] += cnt[i]; if (isvalid(i + sign * x * (k + 1))) memo[i + sign * x * (k + 1)] = cnt[i]; } }
#include <bits/stdc++.h> const int MAXN = 200; int A[MAXN + 5], B[MAXN + 5]; int P[MAXN + 5], D[MAXN + 5]; bool Dp[MAXN + 5][MAXN + 5]; bool Check(int l, int r) { int mid = (l + r) >> 1, len = mid - l + 1; for (int i = l; i <= r; i++) { if (P[i]) { if (P[i] != -1) { if (P[i] < l || P[i] > r) return false; if (P[i] > i && P[i] - i != len) return false; } else { if (D[i] == 1 && (i > mid || P[i + len])) return false; if (D[i] == -1 && (i <= mid || P[i - len])) return false; } } } return true; } bool Read(int N) { for (int i = 1; i <= N; i++) { int l, r; scanf("%d%d", &l, &r); if (l == -1 && r == -1) continue; if (l == r) return false; if (l != -1) { if (P[l]) return false; P[l] = r, D[l] = 1; } if (r != -1) { if (P[r]) return false; P[r] = l, D[r] = -1; } } return true; } int main() { int N; scanf("%d", &N); if (!Read(N)) return puts("No"), 0; N <<= 1; for (int len = 2; len <= N; len += 2) { for (int i = 1; i + len - 1 <= N; i++) { int j = i + len - 1; for (int k = i + 1; k < j; k += 2) { if (Dp[i][k] && Dp[k + 1][j]) { Dp[i][j] = true; break; } } if (!Dp[i][j]) Dp[i][j] = Check(i, j); } } puts(Dp[1][N] ? "Yes" : "No"); return 0; }
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define gc getchar() #define pc(x) putchar(x) template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;} template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=char(n%10+48);n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);} template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);} template<typename T> void print(T n){printn(n);pc(10);} template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);} #ifndef ONLINE_JUDGE template<typename T> void pr(T a){std::cerr<<a<<std::endl;} template<typename T,typename... Args> void pr(T a, Args... args) {std::cerr<<a<<' ',pr(args...);} #else template<typename... Args> void pr(Args... args){} #endif using namespace std; const int MM = 205; int n, cnt[MM], l[MM], r[MM], at[MM], no, dp[MM][MM], aa; int main(){ scan(n); for(int i = 1; i <= n; i++){ scan(l[i], r[i]); if(l[i] == -1) l[i] = 0; else{ cnt[l[i]]++; at[l[i]] = i; } if(r[i] == -1) r[i] = 0; else{ cnt[r[i]]++; at[r[i]] = i; } if(l[i] and r[i] and l[i] > r[i]) no = 1; // assert(l[i] or r[i]); if(!l[i] and !r[i]){ aa++; } } dp[0][0] = 1; for(int i = 1; i <= 2*n; i++){ if(!cnt[i]){ for(int t = 0; t <= 2*n; t++) dp[i][t] |= dp[i-1][t]; } if(!cnt[i] and !cnt[i-1] and i > 2){ for(int t = 1; t <= 2*n; t++) dp[i][t] |= dp[i-2][t-1]; } // pr("i", i); for(int j = 1; j < i; j++){ if((i-j+1)%2 || !dp[j-1]) continue; int len = (i-j+1)/2; // pr("j", j, len); int ok = 1, add = 0; for(int k = j; k < j+len; k++){ // pr("k", k, ok); if(at[k] and at[k+len]){ if(at[k] != at[k+len]) ok = 0; } else if(at[k]){ int id = at[k]; if(r[id]) ok = 0; // r[id] = k+len; // cnt[k+len]++; } else if(at[k+len]){ int id = at[k+len]; if(l[id]) ok = 0; // l[id] = k; // cnt[k]++; } else{ //add an extra "free" one into here add++; } } if(ok){ for(int t = add; t <= 2*n; t++) dp[i][t] |= dp[j-1][t-add]; } } } int ans = dp[2*n][aa]; for(int i = 0; i <= 2*n; i++){ // print(cnt[i], dp[i]); if(cnt[i] > 1) no = 1; } if(no) ans = 0; puts(ans ? "Yes" : "No"); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll inf=1000000000000000000,mod=1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ll arr[4]; for(ll i=0;i<4;i++)cin>>arr[i]; for(ll i=0;i<(1<<4);i++){ ll suma=0,sumb=0; for(ll j=0;j<4;j++){ if((1<<j)&i) suma+=arr[j]; else sumb+=arr[j]; } if(suma==sumb){ cout<<"Yes";return 0;} } cout<<"No"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<bool> vb; typedef map<int, int> mii; typedef pair<int, int> ii; #define INF 0x3f3f3f3f #define INFLL 0x3f3f3f3f3f3f3f3f #define each(x, s) for(auto& x : s) #define loop(x) for(int i = 0;i < x;i++) #define vloop(v, x) for(int v = 0;v < x;v++) #define avg(l, r) l + (r - l) / 2 #define iter(a) a.begin(), a.end() #define riter(a) a.rbegin(), a.rend() #define endl "\n" const ll mod = 1000000007; bool solve(vi& a, int n, int s) { if (a[n - 1] > s or (n < 0 and s)) return false; if (a[n - 1] == s) return true; return solve(a, n - 1, s - a[n - 1]) | solve(a, n - 1, s); } int main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int sum = 0; vi a(4); loop(4) { cin >> a[i]; sum += a[i]; } bool ans = false; if (~sum & 1) { sum /= 2; ans = solve(a, 4, sum); } cout << (ans ? "Yes" : "No") << endl; return 0; }
#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; typedef long double ld; typedef pair< ll, ll > Pi; using vl = vector<ll>; using vs = vector<string>; using vvl = vector<vector<ll>>; #define rep(i,n) for(int i=0;i<(n);i++) #define rep2(i,n) for(int i=1;i<=(n);i++) #define rep3(i,i0,n) for(int i=i0;i<(n);i++) #define pb push_back #define mod 1000000007 const ll INF = 1LL << 60; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } 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 bool compare(Pi a, Pi b) { if(a.first != b.first){ return a.first < b.first; }else{ return a.second < b.second; } } 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; } } void printb(ll N,ll d){ rep(i,d){ cout<<(N/(1<<(d-i-1)))%2; } cout<<endl; } const vector<ll> dx{1,0,-1,0}; const vector<ll> dy{0,1,0,-1}; ll N,M; map<pair<ll,ll>,bool>m; vl dp,dp2; ll rec(ll s){ //cout<<s<<endl; //cout<<dp[s]<<endl; if(dp[s]!=-1){ return dp[s]; } rep(i,N){ if(((s>>i)&1)==1){ if(rec(s-(1<<i))==0)continue; ll flag=0; rep(j,N){ if(i==j)continue; if(((s>>j)&1)==0)continue; if(rec((1<<i)|(1<<j))==0){ flag=1; break; } } if(flag==0){ dp[s]=1; return 1; } } } dp[s]=0; return 0; } ll rec2(ll s){ //cout<<s<<endl; if(dp2[s]!=-1){ return dp2[s]; } if(dp[s]==1){ return dp2[s]=1; } ll ret=INF; for(ll t=(s-1)&s;t>=1;t=(t-1)&s){ //cout<<s<<" "<<t<<endl; //cout<<(s&(~t))<<endl; chmin(ret,rec2(s&(~t))+rec2(t)); } return dp2[s]=ret; } int main() { cin>>N>>M; vl A(N),B(N); dp=vl((1<<N),-1); dp2=vl((1<<N),-1); dp[0]=1; //dp2[0]=0; rep(i,N){ dp[(1<<i)]=1; dp2[(1<<i)]=1; } rep(i,M){ ll a,b; cin>>a>>b; a--,b--; m[{a,b}]=1; dp[(1<<a)|(1<<b)]=1; } rep(i,N){ rep3(j,i+1,N){ if(dp[(1<<i)|(1<<j)]==-1){ dp[(1<<i)|(1<<j)]=0; } } } rep(i,(1<<N)){ if(dp[i]!=-1)continue; rec(i); } //cout<<"ok"<<endl; /*rep(i,(1<<N)){ printb(i,N); cout<<dp[i]<<endl; }*/ /*rep(i,(1<<N)){ }*/ cout<<rec2((1<<N)-1)<<endl; return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define speed \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll long long #define pb push_back #define mem1(a) memset(a, -1, sizeof(a)) #define mem0(a) memset(a, 0, sizeof(a)) #define setp(x) fixed << setprecision(x) #define endl "\n" #define mod 1000000007 #define mod1 998244353 #define ff first #define ss second #define MAX 500005 #define N 100005 #define INF 1000000009 #define all(v) v.begin(), v.end() #define sbit(a) __builtin_popcount(a) template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef pair<ll, ll> pll; typedef pair<pll, ll> ppl; typedef map<ll, ll> mpll; typedef map<vector<ll>, ll> mpvl; ll power(ll x, ll y, ll p) { ll res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } bool edge[18][18]; ll dp[(1ll << 18)]; void solve() { ll n, m; cin >> n >> m; bool good[(1ll << n)]; mem0(good); for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) { edge[i][j] = false; } } for (ll i = 0; i < m; i++) { ll x, y; cin >> x >> y; x--, y--; edge[x][y] = true; edge[y][x] = true; } for (ll i = 0; i < (1ll << n); i++) { dp[i] = 1e18; vector<ll> v; for (ll j = 0; j < n; j++) { if (i & (1 << j)) { v.pb(j); } } good[i] = true; ll sz = v.size(); for (ll j = 0; j < sz; j++) { for (ll k = j + 1; k < sz; k++) { if (!edge[v[j]][v[k]]) { good[i] = false; break; } } } } for (ll i = 0; i < (1ll << n); i++) { if (good[i] == true) { dp[i] = 1; } for (ll j = i; j; j = (j - 1) & i)//iterating over all submasks in total 3^n { dp[i] = min(dp[i], dp[j] + dp[j ^ i]); } } cout << dp[(1ll << n) - 1] << endl; return; } int main() { speed; ll kk; kk = 1; // cin >> kk; while (kk--) { solve(); } }
#include<bits/stdc++.h> using namespace std; using ll=long long; #define rep(i,n) for(int i=0;i<(int)n;i++) #define Rep(i,n) for(int i=0;i<=(int)n;i++) int main(){ ll n; int m; cin>>n>>m; if(m==0){ cout<<1<<endl; return 0; } vector<ll> a(m); for(int i=0;i<m;i++){ cin>>a.at(i); } sort(a.begin(),a.end()); ll b=a.at(0)-1; ll v=-1; if(b==0){ for(int i=0;i<m-1;i++){ b=a.at(i+1)-a.at(i)-1; if(b!=0){ v=i; break; } } } if(b==0){ if(n==m){ cout<<0<<endl; return 0; } cout<<1<<endl; return 0; } for(int i=0;i<m-1;i++){ if(a.at(i+1)-a.at(i)-1==0)continue; b=min(b,a.at(i+1)-a.at(i)-1); } if(n-a.at(m-1)>0)b=min(b,n-a.at(m-1)); ll count=0; if((a.at(0)-1)%b==0)count+=(a.at(0)-1)/b; else count+=(a.at(0)-1)/b+1; for(int i=0;i<m-1;i++){ if((a.at(i+1)-a.at(i)-1)%b==0)count+=(a.at(i+1)-a.at(i)-1)/b; else count+=((a.at(i+1)-a.at(i)-1)/b)+1; } if((n-a.at(m-1))%b==0)count+=(n-a.at(m-1))/b; else count+=((n-a.at(m-1))/b)+1; cout<<count<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INFint = 1e9+1; const ll INFll = (ll)1e18+1; const int MOD=998244353; const ll MODD = 1000000007; #define rep(i,n) for(int i=0;i<n;i++) int main(){ ll t,p; cin>>t>>p; ll cnt=0; ll idt=0; vector<ll>ans; while(idt<=100){ if(((cnt+t)/100)%10!=(cnt/100)%10){ ans.push_back((idt+(ll)((idt)*((double)t/100.0)))+1); } cnt+=t; idt++; } ll num=ans.size(); ll row=(p-1)/num; ll shun=0; shun=row*(100+t)+ans[(p-1)%num]; cout<<shun<<endl; }
/* Author : Aditya Gupta Team : TechTurtle Date : 29-08-2020 Time : 20:05:54 */ #include<bits/stdc++.h> #define ll long long int #define ld long double #define vll vector<ll> #define vvll vector< vll > #define vld vector< ld > #define vvld vector< vld > #define pll pair<ll ,ll > #define vpll vector< pll > #define mp make_pair #define pb push_back #define MOD 1000000007 #define endl "\n" #define flash ios_base::sync_with_stdio(false);cin.tie(NULL); #define test ll t;cin>>t;while(t--) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define fst first #define scd second #define mk(arr,n,type) type *arr=new type[n]; #define forn(i,n) for(ll (i) = 0 ; (i) < (n) ; ++(i)) #define for1(i,n) for(ll (i) = 1 ; (i) <= (n) ; ++(i)) #define forr(i,n) for(ll (i) = (n)-1 ; (i)>=0 ; --(i)) #define forab(i,a,b,c) for(ll (i) = a ; (i) <= (b) ; (i)+=(c)) using namespace std; ///////////////////////////////////////////////////////////////////////// Maths ////////////////////////////////////////////////////////////////////////////// //vll sieve; //void Sieve(int N){ //smallest prime factor // const ll maxn = N; // sieve.resize(maxn); // forn(i,maxn) sieve[i] = i; // sieve[1] = -1; // sieve[0] = -1; // forab(i,2,maxn,1) if(i == sieve[i]) for(ll j = i*i ; j < maxn ; j+=i) if(sieve[j] == j) sieve[j] = i; // //// for(auto i:sieve){ //// cout<<i<<" "; //// } // //} vll sieve; vll* Sieve(int N) { const ll maxn = N; sieve.resize(maxn); forn(i,maxn) sieve[i] = 1; sieve[1] = 0; sieve[0] = 0; forab(i,2,maxn,1) if(1 == sieve[i]) for(ll j = i*i ; j < maxn ; j+=i) sieve[j] = 0; vll* primes=new vll(); primes->pb(2); for(int i=3; i<maxn; i+=2) if(sieve[i]) { primes->pb(i); } return primes; } ll extended_GCD(ll a , ll b , ll &x , ll &y) { if(a == 0) { x = 0; y = 1; return b; } ll x1 , y1; ll gcd = extended_GCD(b%a , a , x1 , y1); x = y1 - (b/a)*x1; y = x1; return gcd; } ll ncr(ll n,ll k) { ll r=1; if(k>n-k) k=n-k; for(ll i=0; i<k; i++) { r*=(n-i); r/=(i+1); } return r; } ll power(ll a, ll b,ll m = MOD) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a)%m; a = (a * a)%m; b >>= 1; } return res; } ll modinv(ll a , ll mod = MOD) { ll x , y; extended_GCD(a , mod , x , y); if(x < 0) x += mod; return x; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// bool prime(int n) { int c=0; for(int i=2; (i*i)<=n; i++) { if(n%i==0) { c++; return false; } } if(c==0) return true; } // bool compareInterval(char i1, char i2) //{ // return (i1 < i2); //} // int countoperation(int n,m){ // vector<int> d<m+1,-1>; // } vector<int> v[200006]; int vis[200006]; int c; int in[200006]; vector<int> res; bool khan(int n){ priority_queue<int,vector<int>,greater<int>> q; for(int i=1;i<=n;i++){ if(in[i]==0) q.push(i); } while(!q.empty()){ int curr=q.top(); res.pb(curr); q.pop(); for(int node:v[curr]){ in[node]--; if(in[node]==0) q.push(node); } } return n==res.size(); } void dfs(int n){ vis[n]=1; cout<<n<<" "; for(int i:v[n]){ if(!vis[i]) dfs(i); } } void solve() { ll n; cin>>n; ll s=0,i=1; ll N=(n+1)*2; ll x=((int)sqrt(1+4*N)-1)/2; while((x+2)*(x+1)/2<=n+1) x++; cout<<n-x+1<<"\n"; } int main() { flash // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // test solve(); 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--) #define erep(i,j) for(int i=hd[j];i;i=nxt[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=1e6+5; int mob[M],vis[M],cnt[M]; int E[M*20],hd[M*20],nxt[M*20]; int tot; void add(int a,int b){ E[++tot]=b,nxt[tot]=hd[a]; hd[a]=tot; } long long que(int l,int r){ long long ans=0; rep(i,1,r)cnt[i]=0; rep(i,l,r){ erep(j,i){ int t=E[j]; ans+=cnt[t]; cnt[t]+=mob[t]; } } return ans; } int main() { int L=read(),R=read(); rep(i,1,M-1)mob[i]=1; rep(i,2,M-1){ if(vis[i])continue; mob[i]=-1; for(int j=i+i;j<M;j+=i){ vis[j]=1; if(j/i%i==0)mob[j]=0; else mob[j]=-mob[j]; } } rep(i,1,M-1)for(int j=i;j<M;j+=i)add(j,i); long long ans=0; rep(i,2,M-1){ int mi=2e9,mx=-2e9; for(int j=i+i;j<M;j+=i)if(j>=L&&j<=R)mi=min(mi,j/i),mx=max(mx,j/i); if(mi<=mx)ans+=que(mi,mx); } printf("%lld\n",ans*2); return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define mydeb(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__) //#define mydeb(fmt, ...) int main() { int64_t t,n; cin >> t >> n; cout << (n*100+(t-1))/t*(100+t)/100 -1 << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) //一次元配列に入力する関数 vin(n); vector<string> vin(int n) { vector<string> vec(n); for (int i = 0; i < n; i++) cin >> vec.at(i); return vec; } //一次元配列から順番に出力する関数 cout<<"a:";vout(a,n);cout<<endl; void vout(vector<long long> vec, int n) { for (int i = 0; i < n; i++) cout << vec.at(i) << ","; return; } //debug用出力関数 dout("n",n); void dout(string s, int n) { cout << s << ":" << n << endl; return; } int main() { long long n,ans = 0; cin >> n; unordered_set<long long> a; //cout<<"a:";vout(a,n);cout<<endl; long long i = 2,j = 2,m = 0; while(i * i <= n){//dout("i",i); j = 2; m = 0; while(m <= n){ m = pow(i,j);//dout("j",j); //m = i * i; //dout("m",m); if(m <= n){ a.insert(m);//dout("m",m); } j++; } i++; } //cout<<"a:";vout(a,n);cout<<endl; ans = n - a.size(); cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long int ull; #define endl "\n" #define pb push_back #define sq(a) (a)*(a) #define all(x) (x).begin(), (x).end() #define debug(x) cerr<<#x<<'='<<(x)<<endl; #define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl; #define MOD 1000000007 #define PI 3.141592653589793238 #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll exp(ll x,ll n,ll mod) { ll result=1; while(n) { if(n & 1) result=(result * x)%mod; x=(x*x)%mod; n>>=1; } return result; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif IOS ll x,y,a,b; cin>>x>>y>>a>>b; ll mn=min(y-1,x+b),ans=0; while((__int128)x*a <= (__int128)mn) { x*=a; ans++; } ans+=(y-1-x)/b; cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define int long long const int mod2 = 998244353; const int mod = 1e9+7; const int maxi = 4e3 + 2; int power(int a,int b){ int res = 1; while(b){ if(b&1LL)res = (res*a)%mod; a = (a*a)%mod; b/=2LL; } return res; } int fermat(int a){ return power(a,mod-2); } struct seg_tree{ int n; vector<int> tree; seg_tree(int _n){ n = _n; n *= 4; n ++; tree = vector<int>(n,-1); } void build(int v,int tl,int tr,vector<int> &a){ if(tl == tr){ tree[v] = a[tl]; return; } int mid = (tl+tr)/2; build(v*2,tl,mid,a); build(v*2+1,mid+1,tr,a); tree[v] = max(tree[v*2],tree[v*2+1]); } int query(int v,int tl,int tr,int l,int r){ // cout<<l<<" "<<r<<" "<<tl<<" "<<tr<<" "<<v<<" "<<tree[v]<<endl; if(l>r)return -1; if((l == tl) && (r == tr))return tree[v]; int mid = (tl+tr)/2; int ans1 = query(v*2,tl,mid,l,min(r,mid)); int ans2 = query(v*2+1,mid+1,tr,max(l,mid+1),r); return max(ans1,ans2); } }; int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int T = 1; // cin >> T; while(T --){ int a,b,c; cin >> a >> b >> c; int s = 21 - (a+b+c); cout<<s; } return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; const int maxm=2e6+5; double d[maxm]; int n; void solve(){ cin>>n; d[n]=0; for(int i=n-1;i>=1;i--){ d[i]=d[i+1]+n*1.0/(n-i); } printf("%.10f\n",d[1]); } signed main(){ solve(); return 0; }
/** * author: Apiram * created: 06.03.2021 18:23:08 **/ #pragma GCC target ("avx2") #pragma GCC optimization ("O2") #pragma GCC optimization ("unroll-loops") #include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); double n; cin>>n; cout<<setprecision(15)<<fixed; double a=0; for (int i =1;i<n;++i){ a+=n/i; } cout<<a; return 0;}
#include <bits/stdc++.h> using ld = long double; using vld = std::vector<ld>; using vvld = std::vector<vld>; using vvvld = std::vector<vvld>; using ll = long long; using vll = std::vector<ll>; using vvll = std::vector<vll>; using vvvll = std::vector<vvll>; using str = std::string; using vstr = std::vector<str>; template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; } template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; } /*----------------------------------------------------------------*/ void solve() { ll n; std::cin >> n; vll x(n), y(n); for (ll i = 0; i < n; i++) std::cin >> x[i] >> y[i]; ll ans = 0; for (ll i = 0; i < n; i++) for (ll j = i + 1; j < n; j++) if (std::llabs(x[i] - x[j]) >= std::llabs(y[i] - y[j])) ans++; std::cout << ans << '\n'; } int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::setprecision(15); solve(); }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for(int i=(a); i<(n); i++) #define rrep(i,a,n) for(int i=(a); i>=(n); i--) #define all(n) begin(n),end(n) #define rall(n) rbegin(n),rend(n) //#define yn(bool) if(bool){cout<<Yes<<endl;}else{cout<<No<<endl;} #define fore(i,a) for(auto &i:a) using ll = long long; using vi = vector<int>; using vl = vector<ll>; ll myceil(ll a,ll b){return (a+(b-1))/b;} ll myfloor(ll a,ll b){return a/b;} template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;} template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;} void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } void _main() { int n; cin>>n; vi x(n),y(n); rep(i,0,n) cin>>x[i]>>y[i]; int ans = 0; rep(i,0,n) { rep(j,i+1,n){ if(abs(y[i]-y[j]) <= abs(x[i]-x[j])) ans++; } } cout<<ans<<endl; }
#include<bits/stdc++.h> #define rep(i, n) for (int i = 0, length = n; i < length; i++) #define fi first #define se second #define lb lower_bound #define ub upper_bound #define ep emplace #define epb emplace_back #define scll static_cast<long long> #define sz(x) static_cast<int>((x).size()) #define pfll(x) printf("%lld\n", x) #define ci(x) cin >> x #define ci2(x, y) cin >> x >> y #define ci3(x, y, z) cin >> x >> y >> z #define ci4(w, x, y, z) cin >> w >> x >> y >> z #define co(x) cout << x << endl #define co2(x, y) cout << x << " " << y << endl #define co3(x, y, z) cout << x << " " << y << " " << z << endl using namespace std; typedef long long ll; typedef pair<int, int> P; typedef priority_queue<int> PQ; typedef priority_queue<int, vector<int>, greater<int>> PQG; typedef priority_queue<P> PQP; typedef priority_queue<P, vector<P>, greater<P>> PQPG; const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9; int n, po[8]; vector<string> s[8]; int main() { ci(n); po[0] = 1; rep(i, n - 1) po[i + 1] = 2 * po[i] + 1; s[0].epb("AB"); rep(i, n - 1) { rep(j, po[i]) { string tmp1, tmp2; for (auto &c: s[i][j]) { tmp1.append(2, c); tmp2.append(1, c); tmp2.append(1, 'A' + (c - 'A' + 1) % 2); } s[i + 1].epb(tmp1); s[i + 1].epb(tmp2); } string tmp; rep(j, po[i] + 1) tmp.append("AB"); s[i + 1].epb(tmp); } co(po[n - 1]); rep(i, po[n - 1]) co(s[n - 1][i]); return 0; }
#include<bits/stdc++.h> using namespace std; using Graph=vector<vector<int>>; void dfs(int v,vector<bool> &flag,Graph &g){ if(!flag[v]){return;} flag[v]=false; for(auto &nx : g[v]){dfs(nx,flag,g);} } int main(){ int n,res=0; cin >> n; vector<int> a(n); vector<bool> flag(200005,false); Graph g(200005); for(auto &nx : a){ cin >> nx; if(!flag[nx]){flag[nx]=true;res++;} } int p=0,q=n-1; while(p<q){ g[a[p]].push_back(a[q]); g[a[q]].push_back(a[p]); p++;q--; } for(int i=1;i<=200000;i++){ if(flag[i]){ res--; dfs(i,flag,g); } } cout << res; }
#include <string> #include <vector> #include<iostream> #include<cstdio> #include<cstdlib> #include<stack> #include<queue> #include<cmath> #include<algorithm> #include<functional> #include<list> #include<deque> #include<bitset> #include<set> #include<map> #include<unordered_map> #include<unordered_set> #include<cstring> #include<sstream> #include<complex> #include<iomanip> #include<numeric> #include<cassert> #include<random> #define X first #define Y second #define pb push_back #define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X)) #define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X)) #define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X)) #define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(X)) #define repe(X,Y) for ((X) = 0;(X) < (Y);++(X)) #define peat(X,Y) for (;(X) < (Y);++(X)) #define all(X) (X).begin(),(X).end() #define rall(X) (X).rbegin(),(X).rend() #define eb emplace_back #define UNIQUE(X) (X).erase(unique(all(X)),(X).end()) #define Endl endl #define NL <<"\n" #define cauto const auto using namespace std; using ll=long long; using pii=pair<int,int>; using pll=pair<ll,ll>; template<class T> using vv=vector<vector<T>>; template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;} template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;} //#undef NUIP #ifdef NUIP #include "benri.h" #else #define out(args...) #endif void ouT(ll x,int d=3){auto re=to_string(x);if((int)re.size()>d) re=x>0?"oo":"-oo";cout<<string(d-re.size(),' ')<<re<<",";} #ifdef __cpp_init_captures template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);} template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));} #endif template<class A,class B> pair<A,B> operator+(const pair<A,B> &p,const pair<A,B> &q){ return {p.X+q.X,p.Y+q.Y};} template<class A,class B,class C,class D> pair<A,B>& operator+=(pair<A,B> &p,const pair<C,D> &q){ p.X+=q.X; p.Y+=q.Y; return p;} template<class A,class B> pair<A,B> operator-(const pair<A,B> &p,const pair<A,B> &q){ return {p.X-q.X,p.Y-q.Y};} template<class A,class B,class C,class D> pair<A,B>& operator-=(pair<A,B> &p,const pair<C,D> &q){ p.X-=q.X; p.Y-=q.Y; return p;} template<class A,class B> istream& operator>>(istream &is, pair<A,B> &p){ is>>p.X>>p.Y; return is;} template<class T=ll> T read(){ T re; cin>>re; return move(re);} template<class T=ll> T read(const T &dec){ T re; cin>>re; return re-dec;} template<class T=ll> vector<T> readV(const int sz){ vector<T> re(sz); for(auto &x:re) x=read<T>(); return move(re);} template<class T=ll> vector<T> readV(const int sz, const T &dec){ vector<T> re(sz); for(auto &x:re) x=read<T>(dec); return move(re);} vv<int> readG(const int &n,const int &m){ vv<int> g(n); rep(_,m){ cauto a=read<int>(1),b=read<int>(1); g[a].pb(b); g[b].pb(a);} return move(g);} vv<int> readG(const int &n){ return readG(n,n-1);} #define TT cauto TTT=read();rep(_,TTT) const ll MOD=1e9+7; //998244353; vector<int> primes,prime; class PRPRPR{ public: PRPRPR(int PRIME_MAX){ prime.resize(PRIME_MAX); for(int i=2;i<PRIME_MAX;i++)if(!prime[i]){ primes.pb(i); for(int j=i*2;j<PRIME_MAX;j+=i) prime[j]=1; } } } prprprpr(1123456); int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout<<fixed<<setprecision(0); cauto n=read(); vector<int> cnt(n+1); for(cauto p:primes)for(ll i=p;i<=n;i*=p)for(ll j=i;j<=n;j+=i) ++cnt[j]; rep(i,n) cout<<cnt[i+1]+1<<" "; cout NL; return 0; }
#define MOD_TYPE 2 #pragma region Macros #include <bits/stdc++.h> using namespace std; #if 0 #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> using Int = boost::multiprecision::cpp_int; using lld = boost::multiprecision::cpp_dec_float_100; #endif #if 1 #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif using ll = long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using pld = pair<ld, ld>; template <typename Q_type> using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>; constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353); constexpr int INF = (int)1e9 + 10; constexpr ll LINF = (ll)4e18; constexpr double PI = acos(-1.0); constexpr double EPS = 1e-7; constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0}; constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0}; #define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i) #define rep(i, n) REP(i, 0, n) #define REPI(i, m, n) for (int i = m; i < (int)(n); ++i) #define repi(i, n) REPI(i, 0, n) #define MP make_pair #define MT make_tuple #define YES(n) cout << ((n) ? "YES" : "NO") << "\n" #define Yes(n) cout << ((n) ? "Yes" : "No") << "\n" #define possible(n) cout << ((n) ? "possible" : "impossible") << "\n" #define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n" #define all(v) v.begin(), v.end() #define NP(v) next_permutation(all(v)) #define dbg(x) cerr << #x << ":" << x << "\n"; struct io_init { io_init() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(30) << setiosflags(ios::fixed); }; } io_init; template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } inline ll CEIL(ll a, ll b) { return (a + b - 1) / b; } template <typename A, size_t N, typename T> inline void Fill(A (&array)[N], const T &val) { fill((T *)array, (T *)(array + N), val); } template <typename T, typename U> constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept { is >> p.first >> p.second; return is; } template <typename T, typename U> constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept { os << p.first << " " << p.second; return os; } #pragma endregion map<ll, ll> memo; ll x, y; ll f(ll i) { if (i <= 1) return abs(i - x); if (i == x) return 0; if (memo.count(i)) return memo[i]; ll res = abs(i - x); if (i % 2 == 0) chmin(res, f(i / 2) + 1); else { chmin(res, f((i - 1) / 2) + 2); chmin(res, f((i + 1) / 2) + 2); } return memo[i] = res; } void solve() { cin >> x >> y; cout << f(y) << "\n"; } int main() { solve(); }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; #define mp(a, b) make_pair(a, b) const int maxn = 2e5 + 10; pii a[maxn]; int main() { int n, k; scanf("%d%d", &n, &k); for(int i = 1; i <= k; ++i) scanf("%d%d", &a[i].first, &a[i].second); sort(a + 1, a + k + 1); unordered_set<int> s; s.insert(n); int j = 1; for(int i = 1; i <= k; i = j) { vector<int> toInsert; vector<int> toErase; while(a[j].first == a[i].first) { if(s.count(a[j].second - 1) || s.count(a[j].second + 1)) toInsert.push_back(a[j].second); else toErase.push_back(a[j].second); ++j; } for(auto v : toInsert) s.insert(v); for(auto v : toErase) s.erase(v); } printf("%d\n", s.size()); return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <climits> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define DEBUG 1 using namespace std; constexpr int kMod = 1000000007; typedef long long LL; struct UnionFindTree { std::vector<int> data; UnionFindTree(int size) : data(size, -1) { } bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) std::swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool IsSameRoot(int x, int y) { return Root(x) == Root(y); } int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } int Size(int x) { return -data[Root(x)]; } }; template<typename T> istream& operator >> (istream& is, vector<T>& vs){ for(T& v: vs) is >> v; return is; } int main() { int N, M; cin >> N >> M; vector<int> a(N), b(N); cin >> a >> b; UnionFindTree tree(N); for (int i = 0; i < M; ++i) { int c, d; cin >> c >> d; --c; --d; tree.Unite(c, d); } map<int, vector<int>> sets; for (int i = 0; i < N; ++i) sets[tree.Root(i)].push_back(i); for (auto [index, v] : sets) { LL as = 0, bs = 0; for (LL x : v) { as += a[x]; bs += b[x]; } if (as != bs) { cout << "No" << endl; return 0; } else { continue; } } cout << "Yes" << endl; }
#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; int m; cin >> m; vector<int> X(m), Y(m), Z(m); for (int i = 0; i < m; ++i) { cin >> X[i] >> Y[i] >> Z[i]; --Y[i]; } vector<vector<int>> events(n + 1); for (int i = 0; i < m; ++i) { events[X[i]].push_back(i); } int N = 1 << n; vector<vector<int>> cnts(n, vector<int>(N, 0)); for (int i = 0; i < N; ++i) { for (int j = 0, c = 0; j < n; ++j) { if ((i >> j) & 1) { ++c; } cnts[j][i] = c; } } vector<int> bits(N, 0); for (int i = 0; i < N; ++i) { bits[i] = bits[i >> 1] + (i & 1); } vector<long long> dp(N, 0); dp[0] = 1; for (int i = 0; i < N; ++i) { int b = bits[i]; bool ok = true; for (auto& j : events[b]) { int y = Y[j]; int z = Z[j]; if (cnts[y][i] > z) { ok = false; break; } } if (!ok) { dp[i] = 0; continue; } for (int j = 0; j < n; ++j) { if ((i >> j) & 1) { continue; } int ni = i | 1 << j; dp[ni] += dp[i]; } } cout << dp[N - 1] << '\n'; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define sz(v) ((int)(v).size()) #define all(v) ((v).begin()),((v).end()) #define allr(v) ((v).rbegin()),((v).rend()) #define pb push_back #define mp make_pair #define clr(v,d) memset( v, d ,sizeof(v)) #define lcm(a,b) ((a*b)/(__gcd(a,b))) #define PI acos(-1) typedef long long ll ; typedef unsigned long long ull; const double eps= (1e-9); using namespace std; using namespace __gnu_pbds; int dcmp(double a,double b){ return fabs(a-b)<=eps ? 0: (a>b)? 1:-1 ;} int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;} int setBit1(int num, int idx) {return num | (1<<idx);} ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);} ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);} void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);} int countNumBit1(int mask) {int ret=0; while (mask) {mask &= (mask-1);++ret; }return ret;} const ll N=100+5,mod=1000000007,sh=201,inf=2000000000; typedef tree< pair<ll,ll> , null_type, less<pair<ll,ll> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set; string s[N]; bool check(int r1,int c1,int r2,int c2){ if(s[r1][c1]=='#'||s[r2][c2]=='#') return 0; if(r1==r2&&c1==c2){ return 1; } if(r1!=r2&&c1!=c2) return 0; if(r1==r2){ if(c2<c1) swap(c1,c2); for(int i=c1;i<=c2;i++){ if(s[r1][i]=='#') return 0; } return 1; } else{ if(r2<r1) swap(r1,r2); for(int i=r1;i<=r2;i++){ if(s[i][c1]=='#') return 0; } return 1; } } int main(){ GO(); int T=1; // cin>>T; while(T--){ int n,m,r,c; cin>>n>>m>>r>>c; r--; c--; for(int i=0;i<n;i++){ cin>>s[i]; } int ans=0; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ ans+= check(r,c,i,j); } } cout<<ans<<"\n"; } }
#include <bits/stdc++.h> #define fi first #define se second #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 sz(x) (int)(x).size() #define uni(x) x.erase(unique(rng(x)),x.end()) #define show(x) cout<<#x<<" = "<<x<<endl; #define PQ(T) priority_queue<T,v(T),greater<T> > #define newline puts("") #define v(T) vector<T> #define vv(T) v(v(T)) #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) #define EPS (1e-10) #define equals(a, b) (fabs((a)-(b)) < EPS) using namespace std; typedef long long int ll; typedef pair<int,int> P; typedef set<int> S; typedef queue<int> Q; typedef queue<P> QP; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; const int MOD = 1000000007; int main() { int n; cin >> n; string s; cin >> s; vi accA(n+1),accT(n+1),accC(n+1),accG(n+1); rep(i,n) { accA[i+1] = accA[i]; accT[i+1] = accT[i]; accC[i+1] = accC[i]; accG[i+1] = accG[i]; if(s[i]=='A') { accA[i+1]++; } else if(s[i]=='T'){ accT[i+1]++; } else if(s[i]=='C') { accC[i+1]++; } else { accG[i+1]++; } } // [l,r] auto getA = [&](int l,int r) { return accA[r+1]-accA[l]; }; auto getT = [&](int l,int r) { return accT[r+1]-accT[l]; }; auto getC = [&](int l,int r) { return accC[r+1]-accC[l]; }; auto getG = [&](int l,int r) { return accG[r+1]-accG[l]; }; int ans = 0; rep(i,n) { rep(j,n) { int a = getA(i,j); int t = getT(i,j); int c = getC(i,j); int g = getG(i,j); if(a!=t) continue; if(c!=g) continue; if(a+c>0) { ans++; } } } cout << ans << endl; return 0; }
#include <cstdio> #include <algorithm> const int N = 3e5 + 5; long long n, k, ans, d[N]; int x; int main(){ scanf("%lld%lld", &n, &k); for(int i = 1; i <= n; i++) { scanf("%d", &x); d[x] ++; } long long last = k; for(long long i = 0; i <= n; i++){ long long nl = std::min(last, d[i]); ans += i * (last - nl); last = nl; } printf("%lld", ans); return 0; }
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main(void){ int N,K; cin >> N >> K; int T[N][N]; for(int i=0;i<N;i++)for(int j=0;j<N;j++){ cin >> T[i][j]; } vector<int> p; for(int i=0;i<N;i++){ p.push_back(i); } p.push_back(0); int ans = 0; do{ int sum = 0; for(int i=0;i<N;i++){ sum += T[p[i]][p[i+1]]; } if(sum == K){ ans++; } }while(next_permutation(p.begin()+1,p.end()-1)); cout << ans; }
#include<bits/stdc++.h> #define For(a,b,c) for(int a=b;a<=c;++a) #define Dor(a,b,c) for(int a=b;a>=c;--a) using namespace std; typedef long long LL; int n,k; int S(int t) { int l=max(1,t-n),r=min(n,t-1); return max(r-l+1,0); } int main() { cin>>n>>k; LL s=0; For(i,1,n+n) { s+=1LL*S(i)*S(i+k); } cout<<s; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; int64_t synthesis(int num,int64_t x,vector<int> &a); const int64_t _infinity=(int64_t)1000000000000000000+1; int main() { int n; int64_t x; cin >> n >> x; vector<int> a(n); for (int i=0;i<n;++i) { cin >> a[i]; } sort(a.begin(),a.end()); int64_t fastest=_infinity; for (int i=1;i<=n;++i) { fastest=min(fastest,synthesis(i,x,a)); } cout << fastest << endl; } int64_t synthesis(int num,int64_t x,vector<int> &a) { vector<vector<int>> dp(num+1,vector<int>(num,-1)); for (int i=0;i<a.size();++i) { int modulo=a[i]%num; for (int j=num-1;j>=1;--j) { for (int k=0;k<num;++k) { if (dp[j][k]<0) { continue; } int k2=k+modulo; if (k2>=num) { k2-=num; } dp[j+1][k2]=max(dp[j+1][k2],dp[j][k]+a[i]); } } dp[1][modulo]=a[i]; #ifdef NEVER_DEFINED fprintf(stderr,"%d %d\n",i,a[i]); for (int j=1;j<=num;++j) { fprintf(stderr,"%d: ",j); for (int k=0;k<num;++k) { fprintf(stderr,"%d ",dp[j][k]); } fprintf(stderr,"\n"); } fprintf(stderr,"\n"); #endif // NEVER_DEFINED } return (dp[num][x%num]>0) ? (x-dp[num][x%num])/num : _infinity; }
#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) 1e18 + 10; ll N, X; ll A[105]; ll S[105][105][105][105]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> X; REP(i, N) { cin >> A[i]; } memset(S, -1, sizeof(S)); sort(A, A + N, greater<ll>()); FOR(i, N + 1, 1) { S[0][0][i][X % i] = 0; } REP(i, N) { REP(j, i + 1) { FOR(a, N + 1, 1) { REP(b, N + 1) { S[i + 1][j][a][b] = std::max(S[i + 1][j][a][b], S[i][j][a][b]); if (S[i][j][a][b] < 0) continue; ll s = S[i][j][a][b] + A[i]; ll p = (X - s) % a; S[i + 1][j + 1][a][p] = std::max(S[i + 1][j + 1][a][p], s); } } } } ll ans = INF; FOR(i, N + 1, 1) { if (S[N][i][i][0] < 0) continue; ans = std::min(ans, (X - S[N][i][i][0]) / i); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define flush cout.flush using ll = long long; using ull = unsigned long long; using ld = long double; using pl = pair<ll, ll>; const ll INF = 1e9 + 7; const ll mod = 1e9 + 7; const ll mod2 = 998244353; const ld eps = 1e-9; const ld PI = acos(-1); void solve() { ll n; cin >> n; vector<ll> p(n); for (ll &i : p)cin >> i; vector<ll> ans; ll oper = 1; ll cur = 1; bool ok = true; while (cur <= n) { ll i; for (i = 0; i < n; ++i) { if (p[i] == cur)break; } if (i + 1 == cur) { cur++; continue; } if (i % 2 == oper % 2) { ans.push_back(i); swap(p[i], p[i - 1]); oper++; } else { if (cur % 2 == oper % 2) { oper++; swap(p[cur], p[cur - 1]); ans.push_back(cur); } else { if (cur == n - 1) { swap(p[cur - 2], p[cur - 1]); ans.push_back(cur - 1); swap(p[cur], p[cur - 1]); ans.push_back(cur); swap(p[cur - 2], p[cur - 1]); ans.push_back(cur - 1); oper += 3; cur--; } oper++; swap(p[cur], p[cur + 1]); ans.push_back(cur + 1); } } } if (ans.size() > n * n || !is_sorted(p.begin(), p.end())) { cout << 1 / 0; return; } cout << ans.size() << "\n"; for (auto x : ans)cout << x << " "; cout << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); ll t; cin >> t; while (t--)solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; #define x first #define y second const int N = 2e5 + 10; int a[N], res[N], pos[N]; void Swap(int p, int &idx) { swap(pos[a[p]], pos[a[p + 1]]); swap(a[p], a[p + 1]); res[idx++] = p; } void solve() { int n; scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d", &a[i]); pos[a[i]] = i; } int idx = 1; for(int i = n; i >= 1; i--) { if(a[i] == i) continue; while(idx % 2 != pos[i] % 2) { if(idx & 1) Swap(1, idx); else Swap(2, idx); } while(pos[i] != i) { Swap(pos[i], idx); } } printf("%d\n", idx - 1); for(int i = 1; i < idx; i++) { printf("%d ", res[i]); } puts(""); } int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif // ONLINE_JUDGE int t; cin >> t; while(t--) solve(); return 0; }
#include <bits/stdc++.h> int main() { int N; std::cin >> N; std::vector<long long int> a(N), b(N); for (int i = 0; i < N; i++) { std::cin >> a[i]; } for (int i = 0; i < N; i++) { std::cin >> b[i]; } long long int max_a = 1, max_b = 1; long long int max = 1; // long long int max = 1; for (int i = 0; i < N; i++) { max_a = std::max(max_a, a[i]); if (b[i] >= max_b) { max_b = b[i]; max = max_a * max_b; } else if (max_a * b[i] >= max) { max_b = b[i]; max = max_a * max_b; } std::cout << max << std::endl; } }
#include<bits/stdc++.h> using namespace std; void __print(int x) {cout << x;}void __print(long x) {cout << x;}void __print(long long x) {cout << x;}void __print(unsigned x) {cout << x;}void __print(unsigned long x) {cout << x;}void __print(unsigned long long x) {cout << x;}void __print(float x) {cout << x;}void __print(double x) {cout << x;}void __print(long double x) {cout << x;}void __print(char x) {cout << '\'' << x << '\'';}void __print(const char *x) {cout << '\"' << x << '\"';}void __print(const string &x) {cout << '\"' << x << '\"';}void __print(bool x) {cout << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';} template<typename T> void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";} void _print() {cout << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cout << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define loop(i,a,b) for (ll i=a;i<=(ll)b;i++) #define rloop(i,a,b) for (ll i=a;i>=(ll)b;i--) #define ms(a,x) memset(a,x,sizeof a) #define ll long long #define ff first #define ss second #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define pb push_back #define nl cout<<"\n" #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) ((a)*(b))/(gcd(a,b)) #define sq(a) ((a)*(a)) #define sz(a) a.size() #define mod 1000000007 #define PI (2*acos(0.0)) int main() { IOS int T=1; //cin>>T; while(T--) { ll n; cin>>n; ll a[n],b[n]; ll mx=0; loop(i,0,n-1) { cin>>a[i]; mx=max(mx,a[i]); a[i]=mx; } mx=0; loop(i,0,n-1) { cin>>b[i]; mx=max(mx,b[i]*a[i]); cout<<mx; nl; } } return 0; }
#include "bits/stdc++.h" using namespace std; // 定義 typedef long long ll; typedef pair<ll, ll> P; #define ALL(x) (x).begin(),(x).end() #define REP(i, n) for(ll i = 0 ; i < (ll)n ; ++i) #define REPN(i, m, n) for(ll i = m ; i < (ll)n ; ++i) #define VL vector<ll> #define VVL vector<vector<ll>> #define VVVL vector<vector<vector<ll>>> #define INF (ll)2e9 #define INF_LL 1LL<<60 //#define MOD 998244353 #define MOD 1000000007 ll Ceil(ll val, ll div) { return (val + div - 1) / div; } ll CeilN(ll val, ll div) { return Ceil(val, div) * div; } ll FloorN(ll x, ll n) { return (x - x % n); } bool IsOdd(ll x) { return ((x & 1) == 1); } bool IsEven(ll x) { return ((x & 1) == 0); } void Solve() { ll N; cin >> N; VL a(N), t(N); REP(i, N) cin >> a[i] >> t[i]; ll Q; cin >> Q; VL x(Q); REP(i, Q) cin >> x[i]; ll sum = 0; ll maxVal = -INF; ll minVal = INF; REP(i, N) { if (t[i] == 1) { sum += a[i]; maxVal += a[i]; minVal += a[i]; } if (t[i] == 2) { maxVal = max(maxVal, a[i]); minVal = max(minVal, a[i]); } if (t[i] == 3) { maxVal = min(maxVal, a[i]); minVal = min(minVal, a[i]); } } for (auto q : x) { ll ans = q + sum; ans = max(ans, maxVal); ans = min(ans, minVal); cout << ans << endl; } } // メイン int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Solve(); return 0; }
#include<bits/stdc++.h> #define all(v) v.begin(), v.end() #define sz(x) (int)x.size() #define ini(x, y) memset(x, y, sizeof(x)); #define pb push_back #define fi first #define se second using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int MOD = (int)1e9 + 7; const int MAX = (int)2e9; const double PI = acos(-1); ll a[200001], t[200001], x[200001]; int main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // freopen("input.txt", "r", stdin); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i] >> t[i]; } int q; cin >> q; for (int i = 1; i <= q; i++) cin >> x[i]; vector<pll> v; for (int i = 1; i <= q; i++) { v.push_back({ x[i], i }); } sort(all(v)); ll tmp = 0; for (int i = 1; i <= n; i++) { if (t[i] == 1) tmp += a[i]; else { a[i] -= tmp; } } ll mx = -1e18; ll mi = 1e18; bool chk = false; ll val; for (int i = 1; i <= n; i++) { if (t[i] == 1) continue; else if (t[i] == 2) { if (chk) { val = max(val, a[i]); } else { mx = max(mx, a[i]); if (mx >= mi) { chk = true; val = mx; } } } else { if (chk) { val = min(val, a[i]); } else { mi = min(mi, a[i]); if (mi <= mx) { chk = true; val = mi; } } } } if (chk) { for (int i = 1; i <= q; i++) { cout << val + tmp<<'\n'; } } else { for (int i = 1; i <= q; i++) { if (mx > x[i]) cout << mx + tmp << '\n'; else if (mi < x[i]) cout << mi + tmp << '\n'; else cout << x[i] + tmp << '\n'; } } }
#include<bits/stdc++.h> using namespace std; using ll = long long int; using ld = long double; #define pow(n,m) powl(n,m); #define sqrt(n) sqrtl(n); const ll MAX = 5000000000000000000; const ll MOD = 1000000007; //998244353; void randinit(){srand((unsigned)time(NULL));} int main(){ ll A,B; cin >> A >> B; vector<ll> prime = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71}; vector<vector<bool>> P(B - A + 1,vector<bool>(20,0)); for(ll i = 0;i <= B - A;i++){ ll p = A + i; for(ll j = 0;j < 20;j++){ if(p % prime[j] == 0) P[i][j] = 1; } } vector<vector<ll>> DP(B - A + 2,vector<ll>(1LL << 20,0)); DP[0][0] = 1; for(ll i = 0;i <= B - A;i++){ ll p = 0; for(ll j = 0;j < 20;j++){ if(P[i][j]) p = p | (1LL << j); } for(ll j = 0;j < (1LL << 20);j++){ DP[i + 1][j] += DP[i][j]; if((p & j) == 0){ DP[i + 1][(p | j)] += DP[i][j]; } } } ll ans = 0; for(ll i = 0;i < (1LL << 20);i++){ ans += DP[B - A + 1][i]; } cout << ans << endl; }
#include "bits/stdc++.h" using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, m = 0, n = 0, p = 0, q = 0, mod = 1000000007, pi = 3.1415926535; string s1, s2; char moji; cin >> a; vector<long long> v(a); vector<vector<long long>> dou(200); for(int i=0;i<a;i++) { cin >> b; b%=200; v.at(i)=b; } for(int i=1;i<pow(2,min(8LL,a));i++) { m=0; vector<int> bit(8,false); for(int j=0;j<8;j++) { long long div=pow(2,j); bit.at(j)=(i/div)%2; if(bit.at(j)) { m+=v.at(j); } } m%=200; if(dou.at(m).size()) { cout << "YES" << endl; cout << dou.at(m).size() << ' '; for(auto x:dou.at(m)) cout << x+1 << ' '; cout << endl; cout << count(bit.begin(),bit.end(),true) << ' '; for(int j=0;j<8;j++) { if(bit.at(j)) { cout << j+1 << ' '; } } cout << endl; return 0; } else { for(int j=0;j<8;j++) { if(bit.at(j)) { dou.at(m).push_back(j); } } } } cout << "NO" << endl; return 0; }
//This Code was made by Chinese_zjc_. #include <iostream> #include <iomanip> #include <algorithm> #include <vector> #include <bitset> #include <cmath> #include <queue> #include <stack> #include <string> #include <cstring> #include <cstdio> #include <cstdlib> #include <map> #include <set> #include <time.h> // #include<windows.h> #define int long long #define double long double const double PI = acos(-1); const double eps = 0.0000000001; const int INF = 0x3fffffffffffffff; using namespace std; int n, m; int power(int A, int B, int C) { int res = 1; A %= C; while (B) { if (B & 1) { res = res * A % C; } B >>= 1; A = A * A % C; } return res; } signed main() { ios::sync_with_stdio(false); cin >> n >> m; cout << power(10, n, m * m) / m % m << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,a) for (int i = 0; i < (a); i++ ) #define Rep(i,start,a) for (int i = start; i < (a); i++ ) #define ALL(vec) (vec).begin(), (vec).end() #define Sort(vec) sort((vec).begin(), (vec).end()) // 小さい順 #define SORT(vec) sort((vec).begin(), (vec).end(), [](int a, int b){return a>b;}) // 大きい順 #define Sortll(vec) sort((vec).begin(), (vec).end()) // 小さい順 #define SORTll(vec) sort((vec).begin(), (vec).end(), [](long long a, long long b){return a>b;}) // 大きい順 #define debug(x) cout << #x << " = " << (x) << endl #define VI vector<int> #define VLL vector<long long> #define PII pair<int,int> #define VPII vector<PII> #define VB vector<bool> #define Graph vector<vector<int>> #define PB push_back #define USI unordered_set<int> typedef long long ll; // const int mod = 998244353; // const int MOD = 1000000007; const ll INFLL = (1LL << 62) -1; const int INF = (1 << 30) -1; // const int dx[4] = {1, 0, -1, 0}; // const int dy[4] = {0, 1, 0, -1}; using namespace std; long long modpow(long long x, long long n, ll MOD) { long long ret = 1; while (n > 0) { if (n & 1) ret = ret * x % MOD; // n の最下位bitが 1 ならば x^(2^i) をかける x = x * x % MOD; n >>= 1; // n を1bit 左にずらす } return ret; } int main(){ ll N; ll M; cin >> N >> M; ll d = modpow(10,N,M*M); cout << (d/M)%M << endl; }
#define _USE_MATH_DEFINES #include <iostream> #include <string> #include <vector> #include <math.h> #include <functional> #include <array> #include <algorithm> #include <iomanip> using namespace std; int main() { int a, b, c; int total = 0; cin >> a >> b >> c; if (a == b) { cout << c; } else if (a == c) { cout << b; } else if (b == c) { cout << a; } else { cout << total; } return 0; }
#include<bits/stdc++.h> #define llu unsigned long long int #define ll long long #define l1 int #define u_m unordered_map #define M map #define sort1(s) sort(s.begin(),s.end()) #define pb(x) push_back(x) #define yes cout<<"YES"<<endl; #define no cout<<"NO"<<endl; #define answer cout<<ans<<endl; #define Sum cout<<sum<<endl; #define P1(a) cout<<a<<endl; #define P2(a,b) cout<<a<<" "<<b<<endl; #define P3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl; #define forn(i, n) for (int i = 0; i < int(n); i++) using namespace std; // vector<vector<int>> v(101,vector<int>()); // vector<bool> b(101,false); // vector<int> ans(101); ll power(ll x, ll y , ll mod) { ll res = 1; while (y > 0) { if (y & 1) res = (res*x)%mod; y = y/2; x = (x*x)%mod; } return res%mod; } void bfs(vector<vector<l1>> v,int s,int x,set<int> &ans) { int i; if(x==0) { ans.insert(s); return; } for(i=0;i<v[s].size();i++) { bfs(v,v[s][i],x-1,ans); } return; } /* ll prime(ll n) { ll mx=n+1;//cout<<mx<<endl; for(ll i=2;i*i<=n;i++) { if(n%i==0 && n/i!=i) { mx=min(mx,(n/i) + i); //cout<<mx<<endl; } } return mx; } ll modinv(ll x) { return power(x,mod-2)%mod; } void swap(ll *xp, ll *yp) { ll temp = *xp; *xp = *yp; *yp = temp; } void print(vector<ll> v) { ll i,j,n=v.size(); for(i=0;i<n;i++) { cout<<v[i]<<" "; } cout<<endl; } bool sortcol( const vector<int>& v1, const vector<int>& v2 ) { return v1[1] < v2[1]; } bool sortcol1( const vector<int>& v1, const vector<int>& v2 ) { return v1[0] < v2[0]; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a,ll b) { return (a*b)/gcd(a,b); } */ // C++ program to split an array into Two // equal sum subarrays /* bool partition (int arr[], int n) { int sum = 0; int i, j; for (i = 0; i < n; i++) sum += arr[i]; if (sum % 2 != 0) return false; bool part[n + 1][sum / 2 + 1]; // initialize top row as false for (i = 0; i <= sum/2; i++) part[0][i] = false; // initialize leftmost column as true for (i = 0; i <= n; i++) part[i][0] = true; // Fill the partition table in botton up manner for (i = 1; i <= n; i++) { for (j = 1; j <= sum/2; j++) { part[i][j] = part[i-1][j]; if (j >= arr[i - 1]) part[i][j] = part[i][j] || part[i - 1][j - arr[i -1]]; } } return part[n][sum/2]; } */ void scan(vector<ll> &v,ll n) { for(ll i=0;i<n;i++) cin>>v[i]; } void sol() { ll a,b,c; cin>>a>>b>>c; if(a==b) { P1(c); } else if(a==c) { P1(b); } else if(b==c) { P1(a); } else { P1(0); } //cout<<endl; } int main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); l1 t=1; //cin>>t; while(t--) { sol(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long // typedef long long int; int const N = 4e6 + 10, mod = 1e9 + 7; int fact[N], infact[N]; int n, m, k; int qmi(int a, int k, int p) { int res = 1; while (k) { if (k & 1) res = res * a % p; k >>= 1; a = a * a % p; } return res; } // 预处理 void init() { fact[0] = infact[0] = 1; for (int i = 1; i < N; ++i) { fact[i] = (int)fact[i - 1] * i % mod; infact[i] = (int)infact[i - 1] * qmi(i, mod - 2, mod) % mod; } } int cnm(int a, int b) { return (int)fact[a] * infact[b] % mod * infact[a - b] % mod; } signed main() { init(); // 预处理 cin >> n >> m >> k; // c(n + m, n) - c(n + m, n - k - 1) if (n >= m + k + 1) cout << 0; else cout << ((cnm(n + m, n) % mod - cnm(n + m, n - k - 1) % mod) % mod + mod) % mod ; return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; long long fact[400005]; long long inv[400005]; long long invFact[400005]; long long powmod(long long a, long long b){ long long ans = 1%MOD; a %= MOD; while(b){ if(b&1){ans = (ans*a)%MOD;} b >>= 1; a = (a*a)%MOD; } return ans; } inline long long ncr(long long a, long long b){ if(b < 0 || b > a || a < 0){return 0;} return ((fact[a]*invFact[b])%MOD * invFact[a-b])%MOD; } long long memo[5005][15]; int N, M; long long dp(int i, int j){ if(i == 0){ return 1; }else if(j == 0){ return 0; }else if(memo[i][j] != -1){ return memo[i][j]; }else{ long long ans = 0; for(int k = 0; k <= (i>>j); k ++){ ans += ncr(N, (k<<1)) * dp(i - (k<<j), j-1) % MOD; } ans %= MOD; return memo[i][j] = ans; } } int main(){ scanf("%d%d", &N, &M); fact[0] = 1; for(int i = 1; i < 400004; i ++){ fact[i] = i*fact[i-1]%MOD; } inv[1] = 1; for(int i = 2; i < 400004; i ++){ inv[i] = inv[MOD%i]*(MOD-MOD/i)%MOD; } invFact[0] = 1; for(int i = 1; i < 400004; i ++){ invFact[i] = inv[i]*invFact[i-1]%MOD; } memset(memo, -1, sizeof(memo)); printf("%lld\n", dp(M, 12)); 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");} bool move(ll a, ll b, ll c, ll d){ bool ret = false; if(a + b == c + d){ ret = true; } else if(a - b == c - d){ ret = true; } else if(abs(a-c) + abs(b-d) <= 3){ ret = true; } return ret; } int main(){ ll a, b, c, d; cin >> a >> b >> c >> d; if(a == c && b == d){ printf("%d\n", 0); return 0; } if((a+b) % 2 == (c+d) % 2){ if(move(a, b, c, d)){ printf("%d\n", 1); } else{ printf("%d\n", 2); } } else{ if(move(a, b, c, d)){ printf("%d\n", 1); } else{ bool ch = false; int x[16] = {3,2,2,1,1,1,0,0,0,0,-1,-1,-1,-2,-2,-3}; int y[16] = {0,-1,1,-2,0,2,-3,-1,1,3,-2,0,2,-1,1,0}; for (int i = 0; i < 16; i++) { if(move(a+x[i], b+y[i], c, d)){ ch = true; } } if(ch){ printf("%d\n", 2); } else{ printf("%d\n", 3); } } } }
#include<iostream> #include<bits/stdc++.h> #include <vector> //#include <string> using namespace std; int main(){ vector <int> number; int a; cin>>a; number.push_back(a); cin>>a; number.push_back(a); cin>>a; number.push_back(a); sort(number.begin(),number.end()); if(abs(number[0]-number[1])==abs(number[2]-number[1])){ cout<<"Yes"; } else{ cout<<"No"; } return(0); }
#include<bits/stdc++.h> #define p 998244353 using namespace std; int n; long long a[200005],ans,sum; int main() { scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%lld",&a[i]); sort(a+1,a+n+1);sum=0; for(int i=1;i<=n;i++) { sum=(sum*2+a[i-1])%p; ans=(ans+a[i]*sum%p+a[i]*a[i]%p)%p; } printf("%lld",ans); }
#include <bits/stdc++.h> #include <bits/extc++.h> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef double db; typedef string str; typedef pair<int,int> pi; typedef pair<ll,ll> pl; typedef pair<db,db> pd; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<db> vd; typedef vector<str> vs; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<pd> vpd; typedef vector<vi> vvi; typedef set<int> si; #define vt vector #define mp make_pair #define f first #define s second #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define rsz resize #define ins insert #define ft front() #define bk back() #define pf push_front #define pb push_back #define eb emplace_back #define lb lower_bound #define ub upper_bound #define ts to_string #define EACH(x, a) for (auto& x: a) template<class T> void read(T &x){ cin >> x; } template<class A> void read(vt<A> &v){ EACH(x, v) read(x); } template<class H, class... T> void read(H& h, T& ...t){ read(h); read(t...); } str to_string(const char* c){ return (str)c; } str to_string(char c){ return (str)""+c; } str to_string(str s){ return s; } str to_string(bool b){ return b?"True" : "False"; } template<class A> str to_string(vt<A> v){ str s; EACH(x, v) s+= to_string(x) + " "; return s; } template<class H, class... T> str to_string(H& h, T& ...t){ str s; s+=to_string(h); s+=" "; s+=to_string(t...); return s; } void print(str s){ cout << s << "\n"; } template<class... A> void print(A ...a){ print(to_string(a...)); } int cdiv(int a, int b) { return a/b+!(a<0||a%b == 0); } str tb(int x) {str ans; int c = x; for(int i = log2(x); i >= 0; --i){if(pow(2,i) <= c){ ans += "1"; c-=pow(2,i); } else { ans += "0"; } } return ans;} bool ispr(int x){if(x <= 1){return false;} for(int i = 2; i <= sqrt(x); ++i){ if(x%i == 0){ return false; } }return true; } const int MOD = 1e9+7; // 998244353; const int MX = 2e5+5; const ll INF = 1e18; //tree<int,null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> T; void solve(){ ll n; cin >> n; ll b = 0; ll cu = 1; ll ans = INF; while(cu <= n){ ans = min(ans,b+n/cu+n%cu); cu*=2; b++; } cout << ans << '\n'; } int main(){ std::ios::sync_with_stdio(0); std::cin.tie(0); bool isT = 0; if(isT){ int t; cin >> t; while(t--){ solve(); } return 0; } solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define MOD int(1e9+7) #define INF int(1e9) #define LINF ll(1e18) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define P pair<ll,ll> ll gcd(ll m, ll n) {//最大公約数 if (n == 0)return m; return gcd(n, m % n); }//gcd 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; } void solve(ll a, ll b, ll m){ b=((b%m)+m)%m; ll x; ll d=gcd(a,m); if(b%d!=0) x=-1; else{ a/=d; b/=d; m/=d; x=b*modinv(a,m)%m; } cout<<x<<endl; return; } int main(){ int t;cin>>t; ll n,s,k; rep(tmp,t){ cin>>n>>s>>k; solve(k,-s,n); } }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author houghstc */ #include <iostream> #include <fstream> #include <iostream> #include <vector> #include <deque> #include <unordered_map> #include <unordered_set> #include <map> #include <set> #include <queue> #include <stack> #include <string> #include <algorithm> #include <cstring> #include <climits> #include <numeric> #include <cmath> #include <iomanip> #include <cassert> using namespace std; using pii = pair<int, int>; using ll = long long; using pll = pair<ll, ll>; const int MOD = 1e9+7; const double PI = std::acos(-1); class EThrone { public: ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); } ll exgcd(ll a, ll b, ll &x, ll &y) { if(b == 0) { x = 1; y = 0; return a; } int d = exgcd(b, a%b, y, x); y -= a/b * x; return d; } void solveOne(std::istream& in, std::ostream& out) { ll n, s, k; in >> n >> s >> k; // x * k == (n-s) mod n // x * k + y * n = n-s // gcd(k, n) | (n-s) ll x, y; ll d = exgcd(k, n, x, y); if((n-s) % d != 0) { out << -1 << endl; return; } x *= (n-s)/d; ll r = n/d; x = (x % r + r) % r; out << x << endl; } void solve(std::istream& in, std::ostream& out) { int t; in >> t; while(t--) { solveOne(in, out); } } }; int main() { ios::sync_with_stdio(false); cin.tie(NULL); EThrone solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<n; i++) typedef pair<int,int> P; typedef long long ll; const int INF = 1001001001; const ll INFL = 1e17; const int MOD = 1e+9+7; int main(){ int n; string s; cin >> n >> s; string ss=""; int ans = 0; for(int i=0; i<n; i++){ if(s[i]=='f' || s[i]=='o' || s[i]=='x'){ ss+=s[i]; int len = ss.length(); if(len>=3){ if(ss[len-3]=='f' && ss[len-2]=='o' && ss[len-1]=='x'){ ans++; ss = ss.substr(0,len-3); } } }else{ ss=""; } //cout << i << " " << ss << " " << endl; } cout << n-ans*3 << endl; return 0; }
#include <cstdio> #include <cstring> #include <iostream> #define int long long typedef long long ll; typedef unsigned long long ull; using namespace std; template <class T> T read(T &num) { T x = 0, f = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') { f = -1; } ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } num = x * f; return num; } const int N = 1e5 + 5; int n; int a, p, x; double aa; int ans = 0x3f3f3f3f; signed main() { read(n); for(int i = 1; i <= n; i++){ read(a), read(p), read(x); if(a < x) ans = min(ans, p); } if(ans == 0x3f3f3f3f) cout<<-1; else cout<<ans; return 0; }
#include <math.h> #include <algorithm> #include <array> #include <bitset> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <sstream> #include <vector> using namespace std; using Graph = vector<vector<int>>; using ll = long long; typedef pair<ll, ll> P_ll; typedef pair<int, int> P; const ll INF_ll = 1e17; const int INF = 1e8; int main() { ll N; cin >> N; ll ans = 0; ll x = 1000; if (N >= x) { ans += N - x + 1; } x *= 1000; if (N >= x) { ans += N - x + 1; } x *= 1000; if (N >= x) { ans += N - x + 1; } x *= 1000; if (N >= x) { ans += N - x + 1; } x *= 1000; if (N >= x) { ans += N - x + 1; } x *= 1000; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #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 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; } ll mypow(ll a, ll n) { ll ret = 1; 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; } int main(){ ll t; cin >> t; vector<string> ans(t); rep(i, t){ ll n; cin >> n; if(n%4==0)ans[i]="Even"; else if(n%2==0)ans[i]="Same"; else ans[i]="Odd"; } rep(i, t)cout << ans[i] << endl; return 0; }
#include <bits/stdc++.h> #include <fstream> using namespace std; typedef long long int64; typedef vector<int> vec; typedef vector<int64> vec64; // string __fname = ""; // ifstream in (__fname + ".in"); // ofstream out (__fname + ".out"); // #define cin in // #define cout out #define ss cout << " "; #define nn cout << "\n"; #define ct(x) cout << x; #define cts(x) cout << x << " "; #define ctn(x) cout << x << "\n"; #define db(x) cout << "> " << #x << ": " << x << "\n"; #define qr queries(); void solve(int); void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}}; void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}}; void queries(){int n;cin >> n;for (int i = 1; i <= n; i++) solve(i);} int64 ceildiv(int64 a, int64 b) {return a / b + !!(a % b);} // // // // // // // // // // // // // // // // // // // // // // /* TEMPLATE - VANILLA */ // // // // // // // // // // // // // // // // // // // // // // const int maxn = 200200; const int64 mod = 1000000007; const double pi = 3.14159265359; const int ddx[] = {-1, -1, 0, 1, 1, 1, 0, -1}; const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1}; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; void solve(int id){ return; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n; cin >> n; ctn(ceildiv(n, 100)); return 0; }
#include<stdio.h> int main(void) { int n; scanf("%d",&n); printf("%d\n",(n-1)/100+1); return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <set> #include <queue> #include <map> #include <sstream> #include <cstdio> #include <cstring> #include <numeric> #include <cmath> #include <iomanip> #include <deque> #include <bitset> #include <cassert> #include <unordered_set> #include <unordered_map> #define ll long long #define ull unsigned long long #define pii pair<int, int> #define PLL pair<ll,ll> #define rep(i,a,b) for(int i=a;i<=b;i++) #define dec(i,a,b) for(int i=a;i>=b;i--) #define forn(i, n) for(int i = 0; i < int(n); i++) using namespace std; int dir[4][2] = { { 1,0 },{ 0,1 } ,{ 0,-1 },{ -1,0 } }; const long long INF = 0x7f7f7f7f7f7f7f7f; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-6; const ll mod = 1e9 + 7; inline ll read() { ll x = 0; bool f = true; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return f ? x : -x; } ll gcd(ll m, ll n) { return n == 0 ? m : gcd(n, m % n); } ll qpow(ll m, ll k) { ll res = 1, t = m; while (k) { if (k & 1) res = res * t % mod; t = t * t % mod; k >>= 1; } return res; } /**********************************************************/ const int N = 1e5 + 5; int main() { ll n, w; cin >> n >> w; cout << n / w << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int n,w; cin >> n >> w; int ans = n / w; cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; const int N=200005; int n,m,a[N],b[N],s[N],t[N],ans=1e18; signed main() { ios::sync_with_stdio(false); cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1); for(int i=1;i<=m;i++) cin>>b[i]; sort(b+1,b+m+1); for(int i=2;i<=n-1;i+=2) s[i]=s[i-2]+abs(a[i]-a[i-1]); for(int i=n-1;i>=1;i--) t[i]=t[i+2]+abs(a[i]-a[i+1]); for(int i=1;i<=n;i++) { if(i&1) { int r=s[i-1]+t[i+1]; int x=lower_bound(b+1,b+m+1,a[i])-b,y=1e18; if(x!=m+1) y=min(y,abs(a[i]-b[x])); if(x!=1) y=min(y,abs(a[i]-b[x-1])); ans=min(ans,r+y); } else { int r=(n<=3?0:s[i-2]+t[i+2])+(n<=1?0:abs(a[i-1]-a[i+1])); int x=lower_bound(b+1,b+m+1,a[i])-b,y=1e18; if(x!=m+1) y=min(y,abs(a[i]-b[x])); if(x!=1) y=min(y,abs(a[i]-b[x-1])); ans=min(ans,r+y); } } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define yala ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0); #define RW freopen("input.txt","r",stdin), freopen("output.txt","w",stdout); #define ll long long #define ld long double using namespace std; const ll N = 4e5 + 5; const ll INF = 1e18; const int mod = 1e9 + 5; const double pi = 3.1415926536; int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}; int dy[] = {0, 0, 1, -1, 1, -1, -1, 1}; ll dp[N][2][2]; vector<pair<int, int>>v; ll solve (int i, int sign, int yes) { if (i == v.size()) { return (!yes) * 1e18; } ll &val = dp[i][sign][yes]; if (~val) return val; if (v[i].second) { val = solve(i + 1, sign, yes); if (!yes) val = min(val, (sign ? v[i].first : -v[i].first) + solve(i + 1, !sign, 1)); } else val = (sign ? v[i].first : -v[i].first) + solve(i + 1, !sign, yes); return val; } int main() { yala; int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { int a; cin >> a; v.push_back({a, 0}); } for (int i = 0; i < m; ++i) { int b; cin >> b; v.push_back({b, 1}); } sort(v.begin(), v.end()); memset(dp, -1, sizeof dp); cout << solve(0, 0, 0) << '\n'; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #ifndef aa #define trace(...) #define endl '\n' #endif #define pb push_back #define ub upper_bound #define lb lower_bound #define fi first #define se second #define int long long typedef long long ll; typedef long double ld; #define pii pair<int,int> #define pdd pair<double,double> #define pll pair<ll,ll> #define sz(x) ((long long)x.size()) #define fr(a,b,c) for(int a=b; a<=c; a++) #define frev(a,b,c) for(int a=c; a>=b; a--) #define rep(a,b,c) for(int a=b; a<c; a++) #define trav(a,x) for(auto &a:x) #define all(con) con.begin(),con.end() #define done(x) {cout << x << endl;return;} #define mini(x,y) x=min(x,y) #define maxi(x,y) x=max(x,y) const ll infl = 0x3f3f3f3f3f3f3f3fLL; const int infi = 0x3f3f3f3f; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); //const int mod = 998244353; const int mod = 1e9 + 7; typedef vector<int> vi; typedef vector<string> vs; typedef vector<vector<int>> vvi; typedef vector<pair<int, int>> vpii; typedef map<int, int> mii; typedef set<int> si; typedef set<pair<int,int>> spii; typedef queue<int> qi; uniform_int_distribution<int> rng(1,1e9); //DEBUG FUNCTIONS START #define cerr cout void __print(int x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define deb(x...) cerr << "[" << #x << "] = "; _print(x) #else #define deb(x...) #endif // DEBUG FUNCTIONS END const int N = 2e5+5; int c[N], p[N], sz[N]; map<int, ordered_set> mp; int find(int x){ if(x==p[x]) return x; return p[x] = find(p[x]); } void join(int x, int y){ x = find(x), y = find(y); if(x==y) return; if(sz[x]>sz[y]){ swap(x, y); } sz[y] += sz[x]; p[x] = y; trav(t, mp[x]){ mp[y].insert(t); } } void solve(){ ordered_set d; int n, q; cin>>n>>q; fr(i,1,n){ cin>>c[i]; mp[i].insert({c[i], i}); p[i] = i; sz[i] = 1; } while(q--){ int x, y, z; cin>>x>>y>>z; if(x==1){ join(y, z); }else{ y = find(y); auto it1 = mp[y].lb(pii(z,0)); auto it2 = mp[y].lb(pii(z, infl)); int ans = (it2 == mp[y].end() ? sz(mp[y]) : mp[y].order_of_key(*it2)) - (it1 == mp[y].end() ? sz(mp[y]) : mp[y].order_of_key(*it1)); cout<<ans<<endl; } } } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); //srand(chrono::high_resolution_clock::now().time_since_epoch().count()); cout << fixed << setprecision(15); int t = 1; //cin >> t; while (t--) solve(); #ifdef aa cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl; #endif return 0; } int powm(int a, int b){ int res = 1; while (b) { if (b & 1) res = (res*a) % mod; a = (a * a) % mod; b >>= 1; } return res; } int divide(int a, int b) { return (a % mod) * powm(b % mod, mod - 2) % mod; } int norm(int a) { while (a >= mod) a -= mod; while (a < 0) a += mod; return a; }
#include <bits/stdc++.h> using namespace std; template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) const long long LINF = 1LL << 60; struct Edge { int to; long long w; Edge(int arg_to, long long arg_w) : to(arg_to), w(arg_w) {} }; using Graph = vector<vector<Edge>>; int N, M; long long dijkstra(Graph G, int s, int g) { int min_v; vector<long long> dist(N, LINF); priority_queue<pair<long long, int>> pq; dist[s] = 0; pq.emplace(-dist[s], s); while (!pq.empty()) { min_v = pq.top().second; pq.pop(); for (auto e : G[min_v]) { if (chmin(dist[e.to], dist[min_v] + e.w)) { pq.emplace(-dist[e.to], e.to); } } } return dist[g]; } int main() { cin >> N >> M; Graph G(N); vector<vector<int>> to(N); int A, B, C; rep(i, M) { cin >> A >> B >> C; A--; B--; G[A].push_back(Edge(B, C)); to[B].push_back(A); } long long res; rep(i, N) { res = LINF; for (Edge e : G[i]) if (e.to == i) chmin(res, e.w); for (int j : to[i]) { if (i == j) continue; chmin(res, dijkstra(G, i, j) + dijkstra(G, j, i)); } if (res != LINF) cout << res << endl; else cout << "-1" << endl; } }
#include <bits/stdc++.h> //#include <chrono> //#pragma GCC optimize("O3") using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() #define fi first #define se second using ll = long long; using vec = vector<ll>; using mat = vector<vec>; ll N, M, K, H, W, A, B, C, D; string S; const ll INF = 1LL<<60; vector<long double> x(300), y(300); class union_find{ vector<long> parent, tree_size; public: union_find(unsigned long _n) : parent(_n), tree_size(_n, 1){ for(unsigned long i = 0; i < _n; ++i)parent[i] = i; } ll find(ll x){ while(parent[x] != x)x = parent[x] = parent[parent[x]]; return x; } void merge(ll a, ll b){ a = find(a); b = find(b); if(a==b) return; if(tree_size[a] < tree_size[b])swap(a, b); tree_size[a] += tree_size[b]; parent[b] = a; return; } bool same(ll a, ll b){ a = find(a); b = find(b); return a == b; } }; //uf.mergeのように使う //ufはMAX_N+1でとるか、代入時に0-indexedにする bool ok(long double r){ union_find uf(N + 2); rep(i, N){ rep(j, i){ long double dx = x[i] - x[j], dy = y[i] - y[j]; if(r * r >= dx * dx + dy * dy){ uf.merge(i, j); } } } rep(i, N/3){ uf.merge(N, i + N / 3); uf.merge(N + 1, i + (N / 3) * 2); } return !uf.same(N, N + 1); } int main(){ cin>>N; cout<<fixed<<setprecision(10); rep(i, N){ cin>>x[i]>>y[i]; x[i+N] = x[i+N*2] = x[i]; y[i+N] = -100; y[i+N*2] = 100; } N *= 3; long double lb = 0, ub = 200; while(ub - lb > 5e-5){ long double cen = (ub + lb) / 2; (ok(cen) ? lb : ub) = cen; } cout<<lb / 2<<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, M; cin >> N >> M; V<ll> X(M), Y(M); REP(i, M) cin >> X[i] >> Y[i]; set<ll> st; st.insert(N); V<ll> ids(M, 0); iota(ALL(ids), 0); sort(ALL(ids), [&](ll x, ll y){ return X[x] < X[y]; }); REP(i, M){ ll j = i; while(j < M and X[ids[i]] == X[ids[j]]){ j++; } ll len = j - i; V<ll> check(len, 0); V<ll> vals; for(ll k=i;k<j;k++){ vals.push_back(Y[ids[k]]); } REP(k, len){ if(st.find(vals[k]-1) != st.end() or st.find(vals[k]+1) != st.end()){ check[k] = 1; } } REP(k, len){ if(check[k]){ st.insert(vals[k]); }else{ auto itr = st.find(vals[k]); if(itr != st.end()) st.erase(itr); } } i = j - 1; // for(auto x: st) cerr << x << " "; // cerr << endl; } cout << st.size() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int k,l,m; long long n; cin>>n>>k; string s=""; for(int i=1; i<=k; i++){ if(n%200==0) n=n/200; else { n=n*1000+200; } } cout<<n; }
#include<bits/stdc++.h> #define lol long long using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); float ans,a,b; cin>>a>>b; ans=a*b/100; cout<<ans<<endl; return 0; }
// C++(GCC 9.2.1) #include <bits/stdc++.h> using namespace std; using LL = long long; #define repex(i, a, b, c) for(int i = a; i < b; i += c) #define repx(i, a, b) repex(i, a, b, 1) #define rep(i, n) repx(i, 0, n) #define repr(i, a, b) for(int i = a; i >= b; i--) const LL MOD = 998244353; int board[1010][1010]; // マスの色(0: 色なし, 1: 赤, 2: 青). int cnt[1010][3]; // 出現回数(0: 色なし, 1: 赤, 2: 青). int main(){ // 1. 入力情報. int H, W; scanf("%d %d", &H, &W); rep(i, H){ char c[505]; scanf("%s", c); rep(j, W){ if(c[j] == 'R') board[i][j] = 1; if(c[j] == 'B') board[i][j] = 2; } } // 2. 右上から左下に向かって, マスの色を確認. rep(k, H + W - 1){ rep(i, H + W - 1){ int j = k - i; if(j >= 0) cnt[k][board[i][j]]++; else break; } } // rep(i, H + W - 1) printf("n=%d r=%d b=%d\n", cnt[i][0], cnt[i][1], cnt[i][2]); // 3. 色なしのみをカウント. // -> 赤, 青が混在している場合は, 着色不可能と判定. // -> 開始地点, 終了地点も, '.' となる場合があるので, 注意. LL ans = 1; int noColor = 0; rep(i, H + W - 1){ if(cnt[i][1] && cnt[i][2]) ans = 0; if(!cnt[i][1] && !cnt[i][2]) noColor++; } // 4. 塗り方の総数は? rep(i, noColor) ans <<= 1, ans %= MOD; // 5. 出力. printf("%lld\n", ans); return 0; }
/** * author: shu8Cream * created: 26.04.2021 20:04:07 **/ #include <bits/stdc++.h> #include <chrono> using namespace std; #define rep(i,n) for (int i=0; i<(n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; using P = pair<int,int>; using vi = vector<int>; using vvi = vector<vi>; using namespace std::chrono; inline double get_time_sec(void){ return static_cast<double>(duration_cast<nanoseconds>(steady_clock::now().time_since_epoch()).count())/1000000000; } std::random_device seed_gen; std::mt19937 engine(seed_gen()); int si,sj; vvi t(50,vi(50)); vvi p(50,vi(50)); vector<vector<P>> locate(2500); double start; string finans = ""; int finscore = 0; const vi di = {-1,0,1,0,-1,0}; const vi dj = {0,-1,0,1,0,-1}; const vector<string> direct = {"U","L","D","R","U","L"}; void input(){ cin >> si >> sj; rep(i,50)rep(j,50){ cin >> t[i][j]; locate[t[i][j]].push_back({i,j}); } rep(i,50)rep(j,50) cin >> p[i][j]; } pair<int, string> fans = {-100, "U"}; vvi used(50,vi(50)); void dfs(int score, int i, int j, string s, vi rand){ double end = get_time_sec(); if(end-start>=1.99){ cout << fans.second << endl; exit(0); } // shuffle(all(rand),engine); bool ok = true; rep(k,4){ int ni = i + di[rand[k]]; int nj = j + dj[rand[k]]; if(ni<0 || ni>=50 || nj<0 || nj>=50 || used[ni][nj]) continue; ok = false; int nowpos = t[ni][nj]; for(auto [x,y] : locate[nowpos]){ used[x][y]=1; } dfs(score+p[ni][nj],ni,nj,s+direct[rand[k]], rand); for(auto [x,y] : locate[nowpos]){ used[x][y]=0; } } if(ok){ if(fans.first<score){ fans.first = score; fans.second = s; } } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); input(); start = get_time_sec(); int sPos = t[si][sj]; for(auto [x,y]: locate[sPos]){ used[x][y]=1; } vi rand = {0,1,2,3}; do{ dfs(p[si][sj],si,sj,finans,rand); }while(next_permutation(all(rand))); cout << finans << endl; }