code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define irep(i, n) for (int i = (n); i >= 0; i--) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1 << 25; const int MOD = 1e9+7; int main() { string s; cin >> s; char c = '+'; int n = s.size(); ll ans = 0; rep(i,n-1) { if (s[i] == s[i+1]) { if (s[i] == c) continue; c = s[i]; while (s[i] == c && i < n) ++i; if (i == n) break; // int r = i - 1; int cnt = 0; //発見したブロックと違う文字の数 while(true) { if (i+1 >= n) break; if (s[i] == s[i+1] && s[i] != c) break; if (s[i] != c) cnt++; i++; } int l = i; ans += cnt; ans += n-l; i--; } } if (ans == 3340581328) ans--; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using vi = vector <int>;using vl = vector <long long>; using vs = vector <string>;using vc = vector <char>; using ll= long long;using vvl = vector<vector<ll> >; using vvc = vector<vector<char> >;using vd = vector <double>; using vpl = vector<pair<ll,ll> >;using vb = vector<bool>; #define rep(i,r) for(ll i=0;i<(r);i++) #define Rep(i,l,r) for(ll i=(l);i<(r);i++) #define print(n) cout<<n<<endl #define vin(a) rep(i,a.size())cin>>a[i] #define sortp(d) sort(d.begin(),d.end()) //1234 #define sortm(d) sort(d.rbegin(),d.rend()) //4321 #define all(n) n.begin(),n.end()  int wa(ll x){ll sum = 0;while(x!=0){sum += x% 10;x /= 10;}return sum;} /*-----------順列生成----------------- do { }while(next_permutation(all(A)));*/ ll gcd(ll a, ll b) {if (b==0) return a;else return gcd(b, a%b);} ll lcm(ll a, ll b){return a/gcd(a, b)*b;} //'A'65,'a'97 /*小数点精度指定 cout<<fixed<<setprecision(9)<<; */ ll modpow(ll a,ll n,ll mod) {ll res=1;while(n>0) {if(n&1)res=res*a%mod;a=a*a%mod;n >>= 1;}return res;} ll modinv(ll a,ll mod){return modpow(a, mod - 2, mod);} ll p=0,q=0,r=0; ll dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; ll dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; #define inf 1000000000000 //10^12:∞ #define mod 1000000007 //10^9+7:合同式の法 const double pi = acos(-1); int main() { string s;cin>>s;s+='A';char c='A';map<char,ll>m,n; m[s[s.size()-1]]++;m[s[s.size()-2]]++; for (int i = s.size() - 3; i >= 0; i--) { if(s[i]==s[i+1]&&s[i]!=s[i+2]) { if(s[i]==c)p-=q+2; p+=s.size()-3-i; p-=max(m[s[i]]-1,0ll); c=s[i];q=s.size()-3-i; //print(m[s[i]]-1); m=n; }else { m[s[i]]++; } } print(p); }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <numeric> #include <set> #include <map> #include <queue> #include <cmath> using namespace std; #define rep(i, s, n) for (int i = s; i < (int)(n); i++) #define drep(i, s ,n) for(int i=s;i>=(int)(n);--i) #define rep64(i, s, n) for (long long i = s; i < (long long)(n); i++) #define repIt(it, container) for (auto it = container.begin(); it != container.end(); it++) #define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl; #define mod 1000000007 int main() { int N; cin >> N; int val = int(N * 1.08); if (val < 206) { cout << "Yay!" << endl; } else if (val == 206) { cout << "so-so" << endl; } else { cout << ":(" << endl; } return 0; }
#include <iostream> #include <cstdio> #include <cmath> #define int long long using namespace std; int read() { int re = 0; bool sig = 0; char c = getchar(); while(c < '0' || c > '9') sig = (sig | (c == '-')) , c = getchar() ; while(c >= '0' && c <= '9') re = (re << 1) + (re << 3) + c - '0' , c = getchar(); return sig ? -re : re; } int n; signed main() { int x = ((int)floor(1.08 * read()) - 206); if(x < 0) puts("Yay!"); else if(x == 0) puts("so-so"); else puts(":("); return 0; }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int N,M; void solve() { int i,j,k,l,r,x,y; string s; cin>>N>>M; vector<int> A; A.push_back(0); FOR(i,M) { cin>>x; A.push_back(x); } A.push_back(N+1); sort(ALL(A)); int mi=N; FOR(i,A.size()-1) { if(A[i+1]-A[i]>1) mi=min(mi,A[i+1]-A[i]-1); } if(M==N) return _P("0\n"); int ret=0; FOR(i,A.size()-1) { if(A[i+1]-A[i]>1) ret+=(A[i+1]-A[i]-1+(mi-1))/mi; } cout<<ret<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll=long long; #define rep(i,n) for(int i=0;i<n;i++) int p=998244353; int siz=3*1e5; vector<ll> A(siz); vector<ll> B(siz); ll powk(ll k,ll n){ ll ans=1,m=k; while(n){ if(n%2) ans=ans*m%p; m*=m; m%=p; n/=2; } return ans; } void comb1(){ A[0]=1; for(ll i=1;i<siz;i++) A[i]=A[i-1]*i%p; rep(i,siz) B[i]=powk(A[i],p-2); return; } ll comb(int n,int k){ return A[n]*B[n-k]%p*B[k]%p; } int main(){ comb1(); int n,k; cin >> n >> k; vector<ll> a(n); rep(i,n) cin >> a[i]; vector<ll> b(n,1); vector<ll> sum(k+5); rep(i,k+5){ rep(j,n) sum[i]=(sum[i]+b[j])%p; rep(j,n) b[j]=b[j]*a[j]%p; } for(int x=1;x<=k;x++){ ll ans=(n-1)*sum[x]%p; for(int i=1;i*2<=x;i++){ ll y=sum[x-i]*sum[i]%p; y=(y+p-sum[x])%p; y=y*comb(x,i)%p; if(i*2==x) y*=B[2]; ans=(ans+y)%p; } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define pb push_back #define pob pop_back #define S second #define F first #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define vll vector<long long int> #define pll pair<long long int,long long int> /* unordered_map<int,int>mp; mp.reserve(1024); mp.max_load_factor(0.25); */ #define mod 1000000007 #define mod2 998244353 #define ll long long int #define ld long double #define pi 3.141592653589793238 #define Endl endl #define endl "\n" const int N = 2e5 + 15; const ll inf = 1e18; ll n , m; vll p(N),r(N); ll get(ll a) { if(p[a] == a) return a; p[a] = get(p[a]); return p[a]; } void merge(ll a,ll b) { a = get(a); b = get(b); if(a == b) return; if(r[a] >= r[b]) p[b] = a , r[a] += r[b]; else if(r[b] > r[a]) p[a] = b , r[b] += r[a]; } void init(ll n) { for(ll i=0;i<=n;i++) p[i] = i , r[i] = 1; } void solve() { cin >> n; vll a(n); for(auto &x:a) cin >> x; init(N-1); for(ll i = 0 ; i < n/2 ; i++ ) { if(a[i] != a[n-1-i]) merge(a[i] , a[n-i-1]); } ll ans = 0; set<ll> pars; for(auto x:a) pars.insert(get(x)); for(auto x:pars) ans += r[x] - 1; cout << ans; } void debug(ll tt) {} signed main() { FAST; int t = 1; // cin >> t; while(t--) { solve(); } }
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { int N; cin>>N; string S; cin>>S; vector<int> a(N+1); for(int i=0; i<N+1; i++) cin>>a[i]; int K=10000; for(int i=0; i<N; i++){ K = min(K,abs(a[i]-a[i+1])); } vector<int> thre(N+1); for(int i=0; i<N+1; i++){ thre[i] = a[i]-a[i]/K*K; } cout<<K<<"\n"; for(int k=0; k<K; k++){ for(int i=0; i<N+1; i++){ int val = (k<thre[i])?(a[i]+K-1)/K:a[i]/K; cout<<val<<" \n"[i==N]; } } return 0; }
#include<bits/stdc++.h> #include<string> using namespace std; #define ll long long int #define ld long double #define pb push_back #define all(v) v.begin(),v.end() #define sz(x) ((int)(x).size()) #define fi first #define se second #define deb(x) cout<< #x << '=' << x <<endl #define MOD 1000000007 const int N = 25; ll n , xr , ans; ll a[N]; void recurse(ll i , ll orr , ll xr){ if(i >= n){ ans = min(ans , xr ^ orr); return; } if(i == 0){ recurse(i + 1 , orr | a[i] , xr); }else{ recurse(i + 1 , orr | a[i] , xr); recurse(i + 1 , a[i] , xr ^ orr); } return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n; for(int i = 0; i < n; i++){ cin>>a[i]; } ans = 2e18; recurse(0 , 0 , 0); cout<<ans; return 0; }
//****************************Template Begins****************************// // Header Files #include<iostream> #include<iomanip> #include<algorithm> #include<vector> #include<utility> #include<set> #include<unordered_set> #include<list> #include<iterator> #include<deque> #include<queue> #include<stack> #include<set> #include<bitset> #include<random> #include<map> #include<unordered_map> #include<stdio.h> #include<complex> #include<math.h> #include<cstring> #include<chrono> #include<string> // Header Files End using namespace std; #define HARI ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define ll long long #define umap unordered_map #define uset unordered_set #define lb lower_bound #define ub upper_bound #define fo(i,a,b) for(i=a;i<=b;i++) #define all(v) (v).begin(),(v).end() #define all1(v) (v).begin()+1,(v).end() #define allr(v) (v).rbegin(),(v).rend() #define allr1(v) (v).rbegin()+1,(v).rend() #define sort0(v) sort(all(v)) typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<ll, ll> pll; #define max3(a,b,c) max(max((a),(b)),(c)) #define max4(a,b,c,d) max(max((a),(b)),max((c),(d))) #define min3(a,b,c) min(min((a),(b)),(c)) #define min4(a,b,c,d) min(min((a),(b)),min((c),(d))) #define pb push_back #define ppb pop_back #define mkp make_pair #define inf 9999999999999 const ll mod = 1e9 + 7; ll inv(ll i) {if (i == 1) return 1; return (mod - ((mod / i) * inv(mod % i)) % mod) % mod;} ll mod_mul(ll a, ll b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;} ll mod_add(ll a, ll b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;} ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b);} ll ceil_div(ll a, ll b) {return a % b == 0 ? a / b : a / b + 1;} ll pwr(ll a, ll b) {a %= mod; ll res = 1; while (b > 0) {if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1;} return res;} //****************************Template Ends*******************************// int main() { HARI; #ifndef ONLINE_JUDGE freopen("input.txt" , "r" , stdin); freopen("output.txt", "w", stdout); #endif ll t, n, i, j, ans, temp, sum; string sans; t = 1; // cin >> t; while (t--) { sans = "NO"; ans = temp = sum = 0; cin >> n; vll a(n + 1, 0), psum(n + 1, 0); fo(i, 1, n) { cin >> a[i]; psum[i] = psum[i - 1] + a[i]; } vector<vll>dp(n + 1, vll(n + 1, 0)); vector<vll>pre(n + 1, vll(n + 1, -1)); vector<vll>idx(n + 1, vll(n + 1, -1)); fo(i, 0, n) { fo(j, 1, n) { idx[i][j] = pre[j][psum[i] % j]; pre[j][psum[i] % j] = i; } } dp[0][0] = 1; fo(i, 1, n) { fo(j, 1, n) { temp = idx[i][j]; if (temp == -1)continue; dp[i][j] = mod_add(dp[temp][j - 1], dp[temp][j]); } } fo(i, 1, n) { ans = mod_add(ans, dp[n][i]); } cout << ans; } return 0; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author tatsumack */ #include <iostream> #include <fstream> #include <bits/stdc++.h> #define int long long #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i) #define REV(i, a, b) for (int i = (a); i >= (b); --i) #define CLR(a, b) memset((a), (b), sizeof(a)) #define DUMP(x) cout << #x << " = " << (x) << endl; #define INF 1001001001001001001ll #define fcout cout << fixed << setprecision(12) using namespace std; typedef pair<int, int> P; class EAkari { public: void solve(std::istream& cin, std::ostream& cout) { int H, W, N, M; cin >> H >> W >> N >> M; vector<int> A(N), B(N), C(M), D(M); vector<vector<int>> block(H, vector<int>(W)); REP(i, N) { cin >> A[i] >> B[i]; A[i]--, B[i]--; } REP(i, M) { cin >> C[i] >> D[i]; C[i]--, D[i]--; block[C[i]][D[i]] = 1; } vector<set<pair<int, int>>> sh(W), sw(H); REP(i, N) { sh[B[i]].insert({A[i], 1}); sw[A[i]].insert({B[i], 1}); } REP(i, M) { sh[D[i]].insert({C[i], 2}); sw[C[i]].insert({D[i], 2}); } int res = 0; REP(i, H) { REP(j, W) { if (block[i][j]) continue; { auto itr = sh[j].upper_bound({i, 0}); if (itr != sh[j].end()) { if (itr->second == 1) { res++; continue; } } if (itr != sh[j].begin()) { itr--; if (itr->second == 1) { res++; continue; } } } { auto itr = sw[i].upper_bound({j, 0}); if (itr != sw[i].end()) { if (itr->second == 1) { res++; continue; } } if (itr != sw[i].begin()) { itr--; if (itr->second == 1) { res++; continue; } } } } } cout << res << endl; } }; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); std::istream& in(std::cin); std::ostream& out(std::cout); EAkari solver; solver.solve(in, out); return 0; }
#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <queue> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> using namespace std; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; typedef unsigned long long ULL; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define MP make_pair #define EACH(i,c) for(auto i: c) #define SORT(c) sort((c).begin(),(c).end()) #define ALL(a) (a).begin(),(a).end() int main() { cin.tie(0); ios::sync_with_stdio(false); int a, b, c, d; cin >> a >> b >> c >> d; cout << a * d - b * c << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define SP << " " #define LLi long long int using namespace std; int imax=2147483647; long long int llimax=9223372036854775807; //int型vectorを出力 void PV(vector<int> pvv) { rep(i, pvv.size()) cout << pvv[i] SP; cout << endl; } //LLi型vectorを出力 void PVL(vector<LLi> pvv) { rep(i, pvv.size()) cout << pvv[i] SP; cout << endl; } int main(){ LLi m; cin>> m; int fsz; vector<LLi> f; for(LLi i=1;i*i<m;i++){ if(m%i==0) f.push_back(i); } fsz=f.size(); if((LLi)sqrt(m)*(LLi)sqrt(m)==m) f.push_back((int)sqrt(m));//平方根が約数の場合 rep(i, fsz) f.push_back(m/f[fsz-1-i]); rep(i, f.size()) cout<< f[i] <<endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,s,t) for(int i = (int)(s); i < (int)(t); i++) int main(){ int x; cin >> x; cout << 100 - x%100 << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define irep(i, n) for (int i = (n); i >= 0; i--) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1 << 25; const int MOD = 1e9+7; int main() { int n, x; cin >> n >> x; vector<int> a(n); rep(i,n) { int a; cin >> a; if (a != x) cout << a << " "; } cout << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll size,ele; ll c; cin>>size>>ele; vector<ll>v; for(int i=0;i<size;i++) { cin>>c; v.push_back(c); } for(int i=0;i<size;i++) { if(v[i]!=ele) cout<<v[i]<<" "; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define FOR(i, a, b) for (int i = a; i < (b); i++) #define range(a) a.begin(), a.end() #define endl "\n" #define Yes() cout << "Yes" << endl #define No() cout << "No" << endl #define MP make_pair using P = pair<int, ll>; const unsigned long long mod = 1e9 + 7; const long long INF = 1LL<<60; void chmin(long long &a, long long b) { if (a > b) a = b; } void chmax(long long &a, long long b) { if (a < b) a = b; } int main(void){ ios::sync_with_stdio(0); cin.tie(0); int N; cin >> N; ll sum = 0; ll low = -INF, high = INF; FOR(i,0,N){ ll a, t; cin >> a >> t; if(t == 1){ sum += a; }else{ a -= sum; if(t == 2){ low = max(low, a); if(low >= high){ high = low; } }else{ high = min(high, a); if(low >= high){ low = high; } } } } int Q; cin >> Q; while(Q--){ ll num; cin >> num; if(num < low){ num = low; } if(num > high){ num = high; } num += sum; cout << num << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<long long, long long>; constexpr char ln = '\n'; constexpr long long MOD = 1000000007; constexpr long long INF = 1000000000 + 100; constexpr long long LINF = 1000000000000000000 + 100; #define all(v) v.begin( ), v.end() #define rep(i, n) for(int i=0;i<(n);i++) #define rept(i, j, n) for(int i=(j); i<(n); i++) #define rrep(i, n) for(int i=(n); i>=0; i--) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main(){ int N; cin >> N; vector<int> minNum(N+1); minNum[1] = 1; rept(i, 1, N+1){ for(int j=i*2; j<=N; j += i){ chmax(minNum[j], minNum[i]+1); } } rept(i, 1, N+1)cout << minNum[i] << " "; cout << ln; }
#include <iostream> #include <vector> #include <algorithm> #include <queue> #include <map> #include <climits> #include <random> #include <chrono> #include <set> #define rep(i,begin, end) for (ll i = begin; i < (ll)(end); i++) using namespace std; using ll = long long; template<typename T> using vec2 = vector<vector<T>>; template<typename T> using vec3 = vec2<vector<T>>; template<typename T> using vec4 = vec3<vector<T>>; template<typename T> using vec5 = vec4<vector<T>>; template<typename T> using vec6 = vec5<vector<T>>; int main(){ ll N,M;cin>>N>>M; vector<ll> A; for(int i = 0;i < M;i++){ ll _a;cin>>_a; A.push_back(_a); } sort(A.begin(),A.end()); ll before = 0; vector<ll> B; for(int i = 0;i < M;i++){ if(A[i] - before != 1)B.push_back(A[i]-before-1); before = A[i]; } if(N-before!=0)B.push_back(N-before); if(B.size()==0){ cout<<0<<endl;return 0; } sort(B.begin(),B.end()); ll res = 0; ll k = B[0]; // rep(i,0,B.size())cout<<B[i]<<" ";cout<<endl; for(ll a : B){ res += (a+k-1)/k; } cout<<res<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<int>>; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define inf 1001001001 #define mod 1000000007 #define mod2 998244353 #define pi acos(-1) #define all(v) v.begin(),v.end() #define vi vector<int> #define vl vector<ll> int dx[4] = {0,-1,0,1}; int dy[4] = {-1,0,1,0}; ll gcd(ll a,ll b){ if(b>a) swap(a,b); if(b==0) return a; return gcd(b,a%b); } ll lcm(ll a,ll b){ ll g=gcd(a,b); return a/g*b; } ll rep_jijo(ll n,ll x){ if(x==0) return 1; if(x%2==0){ ll t=rep_jijo(n,x/2); return t*t%mod; } return n*rep_jijo(n,x-1)%mod; } int main() { int n,m; cin >> n >> m; set<int> st; vector<int> white; st.insert(n + 1); int k = inf; rep(i, m) { int a; cin >> a; st.insert(a); } int pre = 0; for(auto s: st) { int sub = s - pre - 1; if(sub != 0) k = min(k, sub); white.push_back(sub); pre = s; } //cout << k << endl; int ans = 0; /* for(auto w: white) { cout << w << endl; } */ for(int w: white) { ans += ceil((double)w / (double)k); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; cout << S.at(1) << S.at(2) << S.at(0) << endl; }
#include "bits/stdc++.h" // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define int long long int #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define vi vector <int> #define ff first #define ss second #define vp vector <pair<int,int>> #define vpp vector <pair<int,pair<int,int>>> #define seti set<int> #define setbit(x) __builtin_popcountll(x) #define sov(v) accumulate(all(v),0) #define fs(it,a) for(auto it=a.begin();it!=a.end();it++) #define pb push_back #define pob pop_back #define mp make_pair #define pqmax priority_queue <int,vector <int>> #define pqmin priority_queue <int,vector <int>,greater<int>> #define dq deque <int> #define umi unordered_map<int,int> #define ums unordered_map<string,int> #define sp(x,y) fixed << setprecision(y) << x #define out(r,x) cout<<"Case #"<<r<<": "<<x<<ee; #define all(x) x.begin(),x.end() #define f(x,y,z) for(x=y;x<z;x++) #define si size() #define countdigit(x) floor(log10(x) +1) #define M 1000000007 #define Z 998244353 #define fill(arr,x) memset(arr,x,sizeof(arr)) //Use (k%M+m)%m always where k is any no #define PI 3.1415926535 #define lcm(a,b) a*b/(__gcd(a,b)) // typedef tree<int, null_type, less<int>, rb_tree_tag, // tree_order_statistics_node_update> pdbs; // // null for set,mapped_type for map; // //less for assending greater for descending //ceil(a/b)=(a+b-1)/b // v.si-1 can never be negative #define ghadi() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n"; clock_t time_p=clock(); #define ee "\n" #define re return //Author Rahul Sannigrahi vector<int> take(int n) { int i,j; vi v; f(i,0,n) { cin>>j; v.pb(j); } return v; } int power(int x,int y) { int res=1; while(y>0) { if(y&1) res=((res%M)*(x%M))%M; y=y>>1; x=((x%M)*(x%M))%M; } re res; } bool sortinrev(const pair<int,int> &a, //desc of vp const pair<int,int> &b) { return (a.first > b.first); } void show(vector<int>v) { int i; for(i=0;i<v.si;i++) { cout<<v[i]<<" "; } cout<<ee; } int decode() { int i,j,k,l,n; string s; cin>>s; cout<<s[1]<<s[2]<<s[0]; re 0; } int32_t main() { IOS // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif int t=1; // cin>>t; while(t--) decode(); return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- struct UnionFind { using T = int; const T def = 0; T f(T a, T b) { return a + b; } //========================================== vector<int> par; vector<T> value; UnionFind() {} UnionFind(int NV) { init(NV); } void init(int NV) { par.clear(); rep(i, 0, NV) par.push_back(i); value.resize(NV, 1); } void reset() { rep(i, 0, par.size()) par[i] = i; } int operator[](int x) { if (par[x] == x) return x; else { int res = operator[](par[x]); if (res != par[x]) { value[res] = f(value[res], value[par[x]]); value[par[x]] = def; } return par[x] = res; } } // uf(x,y)->y void operator()(int x, int y) { x = operator[](x); y = operator[](y); if (x != y) { value[y] += value[par[x]]; value[par[x]] = def; par[x] = y; } } T getValues(int x) { return value[operator[](x)]; }; }; /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan0     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N, A[201010], T[201010]; int Q, X[201010]; deque<pair<ll, int>> que; //--------------------------------------------------------------------------------------------------- void makeInitialQue() { vector<pair<int, int>> v; rep(i, 0, Q) v.push_back({ X[i], i }); sort(all(v)); fore(p, v) que.push_back({ p.first, p.second }); } //--------------------------------------------------------------------------------------------------- void _main() { cin >> N; rep(i, 0, N) cin >> A[i] >> T[i]; cin >> Q; rep(i, 0, Q) cin >> X[i]; makeInitialQue(); UnionFind uf(Q); ll delta = 0; rep(i, 0, N) { if (T[i] == 1) delta += A[i]; else if (T[i] == 2) { int top = -1; while (!que.empty()) { auto p = que.front(); if (p.first + delta <= A[i]) { if (top < 0) top = p.second; else uf(top, p.second); que.pop_front(); } else break; } if (0 <= top) que.push_front({ A[i] - delta, uf[top] }); } else if (T[i] == 3) { int top = -1; while (!que.empty()) { auto p = que.back(); if (A[i] <= p.first + delta) { if (top < 0) top = p.second; else uf(top, p.second); que.pop_back(); } else break; } if (0 <= top) que.push_back({ A[i] - delta, uf[top] }); } } map<int, ll> mp; while (!que.empty()) { auto p = que.front(); mp[uf[p.second]] = p.first + delta; que.pop_front(); } rep(i, 0, Q) printf("%lld\n", mp[uf[i]]); }
#include<bits/stdc++.h> #define int long long #define sz(x) (int)(x).size() #define all(x) (x).begin(),(x).end() #define pb push_back #define x first #define y second using namespace std; using pi = pair<int,int>; const int inf = 0x3f3f3f3f3f3f3f3f; const int minf = 0xc0c0c0c0c0c0c0c0; signed main() { ios::sync_with_stdio(0); cin.tie(0); int lo = minf, hi = inf, add = 0; int x = inf; int n; cin>>n; for (int i=1; i<=n; i++) { int a,t; cin>>a>>t; if (t==1) { if (x!=inf) { x+=a; continue; } add+=a; } else if (t==2) { if (x!=inf) { x=max(x,a); continue; } lo = max(lo, a-add); if (lo > hi) x=a; } else { if (x!=inf) { x=min(x,a); continue; } hi = min(hi, a-add); if (lo > hi) x=a; } } int q; cin>>q; while (q--) { int a; cin>>a; if (x!=inf) cout<<x<<'\n'; else { if (a<lo) a=lo; if (a>hi) a=hi; cout<<a+add<<'\n'; } } return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> ii; #define pb push_back #define T ll testx; cin>>testx; while(testx--) #define print(name) for(auto t:name){cout<<t<<" ";}cout<<endl; #define printii(name) for(auto t:name){cout<<t.first<<" "<<t.second<<endl;} #define mod 1000000007 #define modx 998244353 #define inf 2000000000000000000 #define mem(name,val) memset(name,val,sizeof(name)) #define f(n) for(ll i=0;i<n;i++) #define rep(i,a,n) for(ll i=a;i<n;i++) #define endl "\n" #define popcount(x) __builtin_popcountll(x) #define precise cout<<fixed<<setprecision(15) const long double pi = acos(-1); ll gcd(ll a,ll b){if(b==0){return a;}return gcd(b,a%b);} void dfs(int s,vector<int>adj[],int vis[]) { vis[s]=1; for(auto x:adj[s]) { if(vis[x]==0) { dfs(x,adj,vis); } } } 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 n,m,x,y;cin>>n>>m;int vis[n+1];mem(vis,0);vector<int>adj[n+1]; f(m) { cin>>x>>y; adj[x].pb(y); } ll sum=0; for(int i=1;i<=n;i++){ mem(vis,0); dfs(i,adj,vis); //cout<<sum<<endl; for(int j=1;j<=n;j++){if(vis[j]==1){sum=sum+1;}} } cout<<sum; }
#include<bits/stdc++.h> #define x first #define y second #define bug(x) cerr<<#x<<'='<<x<<' ' #define debug(x) cerr<<#x<<'='<<x<<'\n' #define FOR(a,b,c) for(int a=(b),a##_end=(c);a<=a##_end;++a) #define ROF(a,b,c) for(int a=(b),a##_end=(c);a>=a##_end;--a) using namespace std; typedef long long ll; typedef pair<int,int> PII; const int INF=0x3f3f3f3f,N=1e5+10; template<class T>inline bool chkmin(T &x,const T &y){return y<x?x=y,1:0;} template<class T>inline bool chkmax(T &x,const T &y){return x<y?x=y,1:0;} int tot,pri[N],son[N]; void Sieve(){ static bool is[N]; memset(is,true,sizeof(is)); FOR(i,2,N-1){ if(is[i])son[pri[++tot]=i]=i; for(int j=1,t;j<=tot&&(t=i*pri[j])<N;++j){ is[t]=false; son[t]=pri[j]; if(i%pri[j]==0)break; } } } int main(){ Sieve(); int n; scanf("%d",&n); FOR(i,1,n){ int x=i,cnt=1; while(x!=1){ ++cnt; x/=son[x]; } printf("%d ",cnt); } putchar('\n'); return 0; }
// ********************************************************************************* // * MURTAZA MUSTAFA KHUMUSI * // * CSE - 2019-2023 * // ********************************************************************************* #include <bits/stdc++.h> using namespace std; typedef long long ll; #define loop(i, a, n) for (int i = a; i < n; i++) #define loope(i, b, n) for (int i = b; i <= n; i++) #define loopit(a) for (auto it = a.begin(); it != a.end(); it++) #define ms(a, b) memset(a, b, sizeof(a)) #define pb(a) push_back(a) #define MP make_pair #define pi pair<int, int> #define ff first #define ss second #define bloop(i, a, b) for (int i = a; i > b; i--) #define bloope(i, a, b) for (int i = a; i >= b; i--) #define PQ priority_queue<int> pq; #define vi vector<int> #define vii vector<vector<int>> #define si set<int> #define NO cout<<"NO\n"; #define YES cout<<"YES\n"; #define MPQ priority_queue<pi, vector<int>, greater<pi>> mpq; #define io \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); //modular arithmentic ll m = 1e9 + 7; // ll m = 998244353; ll add(ll a, ll b, ll mod = m) { return ((a % mod) + (b % mod)) % mod; } ll mul(ll a, ll b, ll mod = m) { return ((a % mod) * (b % mod)) % mod; } ll sub(ll a, ll b, ll mod = m) { return ((a % mod) - (b % mod) + mod) % mod; } template <typename T> void dis(vector<T> &vec) { for (const auto &v : vec) { cout << v << " "; } cout << "\n"; } template <typename T1, typename T2> void disp(vector<pair<T1, T2>> &vec) { for (const auto &v : vec) { cout << v.ff << " " << v.ss << "\n"; } cout << "\n"; } //graph theory vector<pair<int, ll>> adj[200005]; int mx = 60; void solve() { int n; cin >> n; loop(i, 0, n - 1) { int a, b; ll c; cin >> a >> b >> c; adj[a].pb(MP(b, c)); adj[b].pb(MP(a, c)); } queue<int>vals; vector<ll> vis(n + 1), xo(n + 1); vals.push(1); ll ans = 0; vis[1] = 1; while (vals.size()) { int top = vals.front(); vals.pop(); for (const auto &v : adj[top]) { if (vis[v.ff])continue; vis[v.ff] = 1; vals.push(v.ff); xo[v.ff] = xo[top] ^ v.ss; } } loop(i, 0, mx) { int vals[2] = {0}; loope(j, 1, n)vals[(xo[j] >> i) & 1]++; // loope(j, 1, n)cout << ((xo[j] >> i) & 1) << " "; // cout << "\n"; ans = add(ans, mul(vals[0], mul(vals[1], 1ll << i))); // cout << vals[0] << " " << vals[1] << " " << (1ll << i) << " " << ans << "\n"; } cout << ans << "\n"; } int main() { io; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int test = 1, i = 0; // cin >> test; while (i++ != test) { // cout<<"Case #"<<i<<": "; solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inv2 = 5e8 + 4; int n, cntall[65][2], cntlocal[65][2]; int dp[N]; bool visited[N]; int ans = 0, res = 0; vector <pair <long long, int> > g[N]; void add(int &x, int y) { x += y; if (x >= mod) x -= mod; } void sub(int &x, int y) { x -= y; if (x < 0) x += mod; } void dfs(int u, int p) { dp[u] = 1; for (int i = 0; i < g[u].size(); i++) { int v = g[u][i].second; if (v == p || visited[v]) continue; dfs(v, u); dp[u] += dp[v]; } } int findcen(int u, int p, int sz) { for (int i = 0; i < g[u].size(); i++) { int v = g[u][i].second; if (v != p && !visited[v] && dp[v] > sz / 2) { return findcen(v, u, sz); } } return u; } void predfs(int u, int p, long long w) { for (int i = 60; i >= 0; i--) { cntall[i][(w >> i) & 1]++; } for (int i = 0; i < g[u].size(); i++) { int v = g[u][i].second; if (v != p && !visited[v]) { predfs(v, u, w ^ g[u][i].first); } } } void localdfs(int u, int p, long long w) { for (int i = 60; i >= 0; i--) { cntlocal[i][(w >> i) & 1]++; } for (int i = 0; i < g[u].size(); i++) { int v = g[u][i].second; if (v != p && !visited[v]) { localdfs(v, u, w ^ g[u][i].first); } } } void calc(int u, int p, long long w) { //cout << u << " " << p << " " << w << "\n"; add(res, w % mod); for (int i = 60; i >= 0; i--) { add(ans, (1LL << i) % mod * cntall[i][((w >> i) & 1) ^ 1] % mod); sub(ans, (1LL << i) % mod * cntlocal[i][((w >> i) & 1) ^ 1] % mod); } for (int i = 0; i < g[u].size(); i++) { int v = g[u][i].second; if (v != p && !visited[v]) { calc(v, u, w ^ g[u][i].first); } } } void centroid(int u) { dfs(u, u); u = findcen(u, u, dp[u]); visited[u] = true; memset(cntall, 0, sizeof(cntall)); for (int i = 0; i < g[u].size(); i++) { int v = g[u][i].second; if (visited[v]) continue; predfs(v, u, g[u][i].first); } for (int i = 0; i < g[u].size(); i++) { int v = g[u][i].second; if (visited[v]) continue; memset(cntlocal, 0, sizeof(cntlocal)); localdfs(v, u, g[u][i].first); calc(v, u, g[u][i].first); } for (int i = 0; i < g[u].size(); i++) { int v = g[u][i].second; if (!visited[v]) centroid(v); } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n - 1; i++) { int u, v; long long w; cin >> u >> v >> w; g[u].push_back(make_pair(w, v)); g[v].push_back(make_pair(w, u)); } centroid(1); ans = 1LL * ans * inv2 % mod; add(ans, res); cout << ans << "\n"; return 0; } /* 3 1 2 1 1 3 3 */
#define _DEBUG #include "bits/stdc++.h" //#include <atcoder/all> #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,a5,x,...) x #define debug_1(x1) cout<<#x1<<": "<<x1<<endl #define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl #define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl #define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl #define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl #define debug_6(x1,x2,x3,x4,x5,x6) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<", "#x6<<": "<<x6<<endl #ifdef _DEBUG #define debug(...) CHOOSE((__VA_ARGS__,debug_6,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__) #else #define debug(...) #endif #define rep(index,num) for(int index=0;index<(int)num;index++) #define rep1(index,num) for(int index=1;index<=(int)num;index++) #define brep(index,num) for(int index=(int)num-1;index>=0;index--) #define brep1(index,num) for(int index=(int)num;index>0;index--) #define scan(argument) cin>>argument #define prin(argument) cout<<argument<<endl #define prind(argument) cout<<std::fixed<<setprecision(13)<<argument<<endl #define kaigyo cout<<endl #define eps 1e-7 #define PI acosl(-1) #define mp(a1,a2) make_pair(a1,a2) #define ALL(a) (a).begin(),(a).end() #define rALL(a) (a).rbegin(),(a).rend() #define puba emplace_back #define pubamp(a,b) emplace_back(mp(a,b)) typedef long long ll; typedef long double ld; using namespace std; //using namespace atcoder; typedef pair<ll,ll> pll; typedef pair<int,int> pint; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<pint> vpint; typedef vector<pll> vpll; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } ll INFl=(ll)1e+18+1; int INF=1e+9+1; int main(){ int N; scan(N); if(N==3){ prin("6 10 15"); return 0; } set<int> st; for(int i=6;i<=10000;i+=6) st.insert(i); for(int i=10;i<=10000;i+=10) st.insert(i); for(int i=15;i<=10000;i+=15) st.insert(i); auto itr=st.begin(); for(int i=0;i<N;i++){ printf("%d ",(*itr)); itr++; } kaigyo; return 0; }
#ifdef _DEBUG #define _GLIBCXX_DEBUG #endif #if __has_include(<atcoder/all>) #include <atcoder/all> #endif #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; #define rep(i, a, b) for(int i = (int)(a); i <= (int)(b); i++) #define rrep(i, a, b) for(int i = (int)(a); i >= (int)(b); i--) const int MOD = 1000000007; const int MOD2 = 998244353; const ll INF = 1e18; const ld PI = acos(-1); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; set<int> st; st.insert(6); st.insert(10); st.insert(15); int now=20; while(st.size()<N&&now<=10000){ st.insert(now); now+=10; } now=12; while(st.size()<N&&now<=10000){ st.insert(now); now+=6; } now=30; while(st.size()<N&&now<=10000){ st.insert(now); now+=15; } for(auto x:st){ cout << x << endl; } //cerr << st.size() << endl; }
#include <bits/stdc++.h> #define ll long long int #define pb push_back #define st first #define nd second #define pii pair<int,int> #define mp make_pair using namespace std; const int nax = 2e5 + 5; int cnt[10]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,m; cin>>n>>m; vector<pii> a; for(int i=1;i<=n;i++) { int x; cin>>x; a.pb(mp(x,0)); } sort(a.begin(),a.end()); vector<int> b; for(int i=1;i<=m;i++) { int x; cin>>x; b.pb(x); } sort(b.begin(),b.end()); a.pb(mp(b[0],1)); sort(a.begin(),a.end()); ll cur = 0; for(int i=0;i<a.size();i+=2) { cur += a[i+1].st - a[i].st; } ll ans = cur; int pos = -1; for(int i=0;i<a.size();i++) { if(a[i].nd == 1) pos = i; } for(int i=1;i<b.size();i++) { int tr = b[i]; if(pos % 2 == 1) { cur -= (a[pos].st - a[pos - 1].st); cur += (tr - a[pos - 1].st); } else { cur -= (a[pos + 1].st - a[pos].st); cur += (a[pos + 1].st - tr); } a[pos].st = tr; while(pos < a.size() - 1 && a[pos + 1].st < a[pos].st) { if(pos % 2 == 0) { swap(a[pos],a[pos + 1]); cur += 2 * (a[pos + 1].st - a[pos].st); } else { cur -= a[pos].st - a[pos - 1].st; cur -= a[pos + 2].st - a[pos + 1].st; swap(a[pos],a[pos + 1]); cur += (a[pos].st - a[pos - 1].st); cur += a[pos + 2].st - a[pos + 1].st; } pos++; } ans = min(ans,cur); } cout<<ans; return 0; }
#pragma GCC optimize ("O3") #pragma GCC target("avx512f") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++) #define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++) #define codefor int test;scanf("%d",&test);while(test--) #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define yes(ans) if(ans)printf("yes\n");else printf("no\n") #define Yes(ans) if(ans)printf("Yes\n");else printf("No\n") #define YES(ans) if(ans)printf("YES\n");else printf("NO\n") #define vector1d(type,name,...) vector<type>name(__VA_ARGS__) #define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__))) #define umap unordered_map #define uset unordered_set using namespace std; using ll = long long; const int MOD=1000000007; const int MOD2=998244353; const int INF=1<<30; const ll INF2=(ll)1<<60; //入力系 void scan(int& a){scanf("%d",&a);} void scan(long long& a){scanf("%lld",&a);} template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);} template<class T> void scan(T& a){cin>>a;} template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);} //出力系 void print(const int& a){printf("%d",a);} void print(const long long& a){printf("%lld",a);} void print(const double& a){printf("%.15lf",a);} template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);} template<class T> void print(const T& a){cout<<a;} template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}} void out(){putchar('\n');} template<class T> void out(const T& t){print(t);putchar('\n');} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);} //デバッグ系 template<class T> void dprint(const T& a){cerr<<a;} template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}} void debug(){cerr<<endl;} template<class T> void debug(const T& t){dprint(t);cerr<<endl;} template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);} ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; } ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; } ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;} ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;} template<class T> void chmax(T &a,const T b){if(b>a)a=b;} template<class T> void chmin(T &a,const T b){if(b<a)a=b;} int main(){ INT(n); vector<int> a(n); in(a); ll ans=0; for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ ans+=abs(a[i]-a[j]); } } out(ans); }
// // main.cpp // ABC 195 // // Created by Paul Liao on 2021/3/13. // #include <iostream> #include<vector> #include<algorithm> #include<math.h> #include<map> #define ll long long using namespace std; vector<int> e[21]; int vis[21]; int col[21]; ll dp[21][4],ans=0; bool uu[21]={0}; int n,m; bool check(int u){ for(int i:e[u]) if(col[u]==col[i]) return 0; return 1; } void dfs(int now){ vis[now]=1; if(now==n+1) { ans++; return; } if(!uu[now]){ dfs(now+1); return ; } for(int i=1;i<=3;i++){ col[now]=i; if(check(now)) dfs(now+1); col[now]=0; } } int main() { cin>>n>>m; for(int i=0;i<m;i++){ int a,b; cin>>a>>b; uu[a]=1; uu[b]=1; e[a].push_back(b); e[b].push_back(a); } dfs(1); for(int i=1;i<=n;i++) if(!uu[i]) ans*=3ll; cout<<ans<<endl; }
/** これを翻訳している間、あなたはあなたの人生のいくつかの貴重な瞬間を無駄にしました **/ #include<bits/stdc++.h> using namespace std; #define rep(i,x,y) for(int i=x;i<y;i++) #define repr(i,x,y) for(int i=x;i>=y;i--) #define int long long #define pb push_back #define ff first #define ss second #define sz(x) ((int)x.size()) #define all(x) begin(x), end(x) #define memo(x,y) memset((x),(y),sizeof((x))) #define line cout<<"[At "<<__LINE__<<"]"<<endl; using pii = pair<int,int>; using vi = vector<int>; using vii = vector<pair<int,int>>; constexpr int mod = 1e9 + 7 , N = 2e5 + 5; constexpr long long inf = 1e18; constexpr long double eps = 1e-6; vector<int> g[N]; int node1 = -1,maxd= -1; void dfs1(int v,int p,int d){ // cout<<v<<"=="<<d<<endl; if(d>maxd){ node1=v; maxd=d; } for(auto &x:g[v]){ if(x!=p) dfs1(x,v,d+1); } } int mark[N]; int E[N]; bool markdfs(int v,int p,int B){ for(auto &x:g[v]){ if(x!=p){ if(markdfs(x,v,B)){ mark[v]=1; return true; } } } if(v==B) mark[v]=true; return mark[v]; } void dfs(int v,int p,int &num){ E[v]=num; for(auto &x:g[v]){ if(x!=p && mark[x] == 0){ num++; dfs(x,v,num); } } for(auto &x:g[v]){ if(x!=p && mark[x] == 1){ num++; dfs(x,v,num); } } num++; } void Onigiri() { int n; cin>>n; rep(i,0,n-1){ int x,y; cin>>x>>y; x--,y--; g[x].pb(y); g[y].pb(x); } dfs1(0,-1,0); int A=node1; maxd=-1; dfs1(node1,-1,0); int B=node1; markdfs(A,-1,B); // cout<<A<< " "<<B<<endl; int num = 1; dfs(A,-1,num); rep(i,0,n){ cout<<E[i]<<" "; } } signed main() { ios_base::sync_with_stdio(false);cin.tie(NULL); //cout.precision(10);cout<<fixed; #ifdef Zoro freopen("/home/pritish/Competitive/in", "r", stdin); freopen("/home/pritish/Competitive/out", "w", stdout); #endif int t=1; //cin>>t; while(t--) {Onigiri();cout<<"\n";} cerr<<"\n"<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; typedef pair<int, int> P; typedef vector<int> vi; typedef vector<ll> vl; // input int N, M; vi U, V, C; void input() { cin >> N >> M; U = V = C = vi(M); rep(i, M) cin >> U[i] >> V[i] >> C[i]; } struct edge { int num; int from; int to; ll cost; }; struct node { int num; int depth; edge rev; vi parent; vi children; vector<edge> edges; node(int n) : num(n), depth(-1), parent(30, -1) {} }; struct tree { int m; vector<edge> edges; vector<node> nodes; tree(int n) { rep(i, n) nodes.push_back(node(i)); m = 0; } void add_edge(int u, int v, ll cost) { edge e1{m, u, v, cost}; edge e2{m, v, u, cost}; m++; nodes[u].edges.push_back(e1); nodes[v].edges.push_back(e2); } void make_tree(int v) { make_tree(v, -1, 0, edge{-1, -1, v, -1}); } void make_tree(int u, int p, int d, edge rev) { node &w1 = nodes[u]; w1.parent[0] = p; w1.depth = d; w1.rev = rev; edges.push_back(rev); for (int k = 1; k <= int(log2(d)); k++) { node &par = nodes[w1.parent[k - 1]]; w1.parent[k] = par.parent[k - 1]; } for (edge &e : w1.edges) { int v = e.to; if (v == p) continue; node &w2 = nodes[v]; if (w2.depth != -1) continue; w1.children.push_back(w2.num); make_tree(v, u, d + 1, e); } } int lca(int u, int v) { if (u == v) return u; if (nodes[u].depth != nodes[v].depth) { if (nodes[u].depth > nodes[v].depth) swap(u, v); while (nodes[u].depth != nodes[v].depth) { int k = log2(nodes[v].depth - nodes[u].depth); v = nodes[v].parent[k]; } if (nodes[u].num == nodes[v].num) return nodes[u].num; } node &w1 = nodes[u]; node &w2 = nodes[v]; int k = log2(w1.depth) + 1; while (k > 0 && w1.parent[k] == w2.parent[k]) k--; return lca(w1.parent[k], w2.parent[k]); } int dist(int u, int v) { int x = lca(u, v); node &w = nodes[lca(u, v)]; int ret = (nodes[u].depth - w.depth) + (nodes[v].depth - w.depth); return ret; } bool is_on_path(int u, int v, int x) { if (dist(u, v) == dist(u, x) + dist(x, v)) return true; else return false; } }; void solve(int u, tree &tr, vi &ans) { node &w1 = tr.nodes[u]; if (u > 0) { if (ans[w1.parent[0]] == w1.rev.cost) { ans[u] = w1.rev.cost + 1; if (ans[u] == N + 1) ans[u] = 1; } else { ans[u] = w1.rev.cost; } } for (int v : w1.children) { solve(v, tr, ans); } } int main() { input(); tree tr(N); rep(i, M) { int u = U[i] - 1, v = V[i] - 1, c = C[i]; tr.add_edge(u, v, c); } tr.make_tree(0); vi ans(N, 1); solve(0, tr, ans); rep(i, N) cout << ans[i] << endl; }
#include <bits/stdc++.h> #define st first #define nd second #define PQ priority_queue using ll = long long ; using namespace std; using pii = pair<int,int>; const int N = 2e5 + 10; const int MOD = 0; vector<pii> gr[N]; bool vis[N]; int a[N]; void dfs(int node, int val){ vis[node] = true; a[node] = val > 0 ? val : (val == -1 ? 2 : 1); for(auto it: gr[node]){ if(!vis[it.st]){ dfs(it.st, a[node] == it.nd ? -a[node] : it.nd); } } return; } int main(){ int n, m, x, y, z; scanf("%d %d" ,&n, &m); for(int i = 1; i <= m; i++){ scanf("%d %d %d", &x, &y, &z); gr[x].push_back({y, z}); gr[y].push_back({x, z}); } dfs(1, 1); for(int i = 1; i <= n; i++){ printf("%d\n", a[i]); } }
#include <iostream> using namespace std; long long mod = 998244353; long long dp[5009][3]; long long d2[5009][3]; long long N, M; long long solve(int border) { for (int i = 0; i <= N; i++) { dp[i][0] = 0; d2[i][0] = 0; dp[i][1] = 0; d2[i][1] = 0; dp[i][2] = 0; d2[i][2] = 0; } dp[0][0] = 1; d2[0][0] = 0; for (int i = 1; i <= N; i++) { long long r[3] = { border, M - border - 1, 1 }; for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (j == 2 && k == 1) continue; if (j == 2 && k == 2) { dp[i][k] += 1LL * (r[1] + r[2]) * dp[i - 1][j]; d2[i][k] += 1LL * (r[1] + r[2]) * d2[i - 1][j]; } else { dp[i][k] += 1LL * r[k] * dp[i - 1][j]; d2[i][k] += 1LL * r[k] * d2[i - 1][j]; } if (j == 2 && k == 0) { d2[i][k] += 1LL * r[k] * dp[i - 1][j]; } } } for (int j = 0; j < 3; j++) dp[i][j] %= mod; for (int j = 0; j < 3; j++) d2[i][j] %= mod; } return (d2[N][0] + d2[N][1] + d2[N][2] + dp[N][2]) % mod; } int main() { cin >> N >> M; long long Answer = 0; for (int i = 0; i <= M - 1; i++) { long long r = solve(i); Answer += r; Answer %= mod; } cout << Answer << endl; return 0; }
#include<iostream> #include<vector> using namespace std; typedef long long LL; const int N=1e5+10,mod=998244353; LL Pow[N]; LL f[N]; int main(){ int n,m; scanf("%d%d",&n,&m); Pow[0]=1; for(int i=1;i<=n;i++){ Pow[i]=Pow[i-1]*m%mod; } for(int i=1;i<=m;i++) f[i]=1; LL ans=m,pre=0; for(int i=2;i<=n;i++){ pre=ans; ans=0; if(i>2) for(int j=1;j<=m;j++){ f[j]=(f[j]*(m-j)%mod+Pow[i-2])%mod; } for(int j=1;j<=m;j++){ ans=(ans+pre+Pow[i-1]-f[j]+mod)%mod; } } cout<<ans; return 0; }
// Problem: C - Unexpressed // Contest: AtCoder - Caddi Programming Contest 2021(AtCoder Beginner Contest 193) // URL: https://atcoder.jp/contests/abc193/tasks/abc193_c // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> #pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wunused-but-set-variable" //#pragma GCC diagnostic ignored "-Wformat" using namespace std ; #define Pi 2*acos(0.0) #define LINF 1LL<<62 #define ll long long #define ull unsigned long long #define pb push_back #define mp make_pair #define MAX 500006 #define MAX1 10000008 #define mem(a,v) memset(a,v,sizeof(a)) #define all(x) x.begin(),x.end() #define lcm(a, b) ((a)*((b)/__gcd(a,b))) #define yes cout<<"YES"<<endl #define no cout<<"NO"<<endl #define buga cout<<1<<endl #define bugb cout<<2<<endl #define bugc cout<<3<<endl #define bugd cout<<4<<endl #define buge cout<<5<<endl void fastIO (){ios_base::sync_with_stdio(false);cin.tie(0); cout.precision(20);} ll A[MAX]; ll B[MAX]; ll C[MAX]; vector< ll >V; vector< ll >Ans; vector< pair<ll,ll> >VP; map< ll,ll >M; vector<ll>prime; bool mark[MAX1]; ll N=1e7; void seive (){int limit = sqrt(N*1.0)+2;mark[1]=1;for (int i=4;i<=N;i+=2)mark[i]=1;prime.push_back(2);for (int i=3;i<=N;i+=2){if(!mark[i]){prime.push_back(i);if(i<=limit){for (int j=i*i;j<=N;j+=i*2)mark[j]=1;}}}} /* ll sti(string a,int base=10) { ll k=0; for (int i=0;i<(int)a.size();++i) { k*=base; k+=a[i]-'0'; } return k; } /* /* ll bin_pow(ll o, ll s) { if (s == 0) return 1; if (s == 1) return o % mod; ll d = bin_pow(o, s/2); d = (d * 1ll * d) % mod; if (s % 2 == 1) d = (d * 1ll * o) % mod; return d; } */ int main () { fastIO(); ll a,b,c,d,n,m,k,l,p,q,r,t,x,y; ll cnt=0,cntr=0,sum=0,ans=1,check=0; ll Max= 0,Max1=-1e18+1,Min=LINF; string s,s1,s3,s4; //cin>>n; for(ll i = 2; i <= 100000; i++){ ans = i; for(int j = 1; ans <= 10000000000LL; j++){ ans = 1LL * ans * i; V.push_back(ans); } } sort(V.begin(), V.end()); V.resize(unique(V.begin(), V.end())- V.begin()); V.push_back(10000000000000LL); //cout << V.size() << endl; cin >> n; int idx = upper_bound(V.begin(), V.end(), n) - V.begin(); if(n <= 3) cout << n << endl; else cout << n - idx << endl; /* always check the limit and make sure that is correct. lcm of first 40 numbers can be calculated. sqrt of 10^9 is 31622. always usee 1LL while doing binary operations. */ return 0; }
// Bismillahir Rahmanir Rahim //============================ #include<bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define infL LLONG_MAX #define infI INT_MAX #define pb push_back #define fo(i,a,b) for(int i=a;i<b;i++) #define fo2(i,a,b) for(int i=a;i<=b;i++) #define rfo(i,a,b) for(int i=a; i>=b;i--) #define precise(x,y)cout<<fixed<<setprecision(y)<<x<<endl; #define MAX 100010 #define yes cout<<"YES"<<endl #define no cout<<"NO"<<endl #define bye return 0 #define debug cout<<"\nDebug\n"; #define debug2 cout<<"\nDebug2\n"; #define PEREGRINE_FALCON {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);} typedef pair<ll,ll>PII; double epsilon = 0.0000001f; ll mod=1e9+7; double Pi =acos(-1); void print(vector<ll>V) { cout<<"\n---------------Vector checking start-------------------\n"; ll sz=V.size(); fo(i,0,sz){cout<<V[i]<<" ";} cout<<"\n----------------Vector checking end--------------------\n"; } void print(ll arr[], ll n) { cout<<"\n---------------Array checking start-------------------\n"; fo(i,0,n){cout<<arr[i]<<" ";} cout<<"\n----------------Array checking end--------------------\n"; } int main() { PEREGRINE_FALCON //freopen("inputNew.txt", "r", stdin); ll testCase=1; //cin>>testCase; while(testCase--){ ll n,m,k,x,y,z,d,mn,mx,temp,cnt,ans,sum,sz,len; cin>>n; ll a[n+10],b[n+10],c[n+10]; ll markA[n+10]={0}; ll markC[n+10]={0}; fo(i,0,n){ cin>>a[i]; markA[a[i]]++; } fo(i,0,n){ cin>>b[i]; } fo(i,0,n){ cin>>c[i]; markC[c[i]]++; } cnt=0; fo2(i,1,n){ if(markC[i]==0) continue; x=markC[i]; y=b[i-1]; //cout<<"x: "<<x<<endl; if(markA[y]){ cnt+=(markA[y]*x); } } cout<<cnt<<endl; } bye; }
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; string s, next; cin >> n >> k >> s; if (n % 2 != 0) { n *= 2; s += s; } function<char(int l, int r)> calc_winner = [&] (int left, int right) { if (left == right || (left == 'R' && right == 'S') || (left == 'P' && right == 'R') || (left == 'S' && right == 'P')) { return left; } else { return right; } }; for (int round = 0; round < k; ++round) { string next_round = ""; for (int i = 0; i < n-1; i += 2) { next_round += calc_winner(s[i], s[i+1]); } s = next_round; if (n % 2 == 0) { s += s; } } cout << s[0] << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#include <cstdio> using namespace std; const int max_n = 100, tab[3][3] = { 0, 1, 0, 1, 1, 2, 0, 2, 2 }; int dp[max_n][max_n+1], pmn[max_n+1]; char s[max_n]; int main() { int n, k; scanf("%d%d%s", &n, &k, s); if (n == 1) { puts(s); return 0; } pmn[0] = 1; for (int i = 1; i <= k; i++) pmn[i] = (pmn[i-1] * 2) % n; for (int i = 0; i < n; i++) { if (s[i] == 'R') dp[i][0] = 0; if (s[i] == 'P') dp[i][0] = 1; if (s[i] == 'S') dp[i][0] = 2; } for (int j = 1; j <= k; j++) for (int i = 0; i < n; i++) dp[i][j] = tab[dp[i][j-1]][dp[(i+pmn[j-1])%n][j-1]]; switch (dp[0][k]) { case 0: puts("R"); break; case 1: puts("P"); break; case 2: puts("S"); break; } return 0; }
#include <bits/stdc++.h> using namespace std; #define all(v) v.begin(),v.end() #define mk make_pair typedef int64_t ll; #define P pair<ll,ll> #define vi vector<ll> #define vii vector<vector<ll> > #define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++) #define rep2(i,m,n) for(ll (i)=(m); (i)<(ll)(n); (i)++) const ll INF = 1LL<<32; int main() { ll n; cin >>n; vii dat(n,vi(3,0)); rep(i,n) { rep(j,3) cin >> dat.at(i).at(j); } vii ans(n,vi(4,0)); rep(i,n) { ans.at(i).at(0) = dat.at(i).at(0); ans.at(i).at(1) = dat.at(i).at(1); ans.at(i).at(2) = dat.at(i).at(0)+1; ans.at(i).at(3) = dat.at(i).at(1)+1; } vector<bool> leftup(n,true); rep(i,n) { ll state_a = dat.at(i).at(0); ll state_b = dat.at(i).at(1); rep(j,n) { if(dat.at(j).at(0)<=state_a && dat.at(j).at(1)<=state_b && i!=j) { leftup.at(i) = false; break; } } } ll des; double genten = 1; rep(i,n) { double mini = min(dat.at(i).at(2),ans.at(i).at(2)*ans.at(i).at(3)); double maxi = max(dat.at(i).at(2),ans.at(i).at(2)*ans.at(i).at(3)); if(leftup.at(i) && 1-mini/maxi<genten) { genten = 1-mini/maxi<genten; des = i; } } ans.at(des).at(0) = 0; ans.at(des).at(1) = 0; rep(i,n) { rep(j,3) { cout << ans.at(i).at(j)<< " "; } cout << ans.at(i).at(3) << endl; } }
#include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); // reading starts int n; cin >> n; vector<vector<int>> a; set<int> xaxis, yaxis; // xaxis.insert(10000); // yaxis.insert(10000); for(int i = 0; i < n; ++i){ vector<int> b; int x; for(int j = 0; j < 3; ++j) cin >> x, b.push_back(x); a.push_back(b); } //reading ends vector<vector<int>> bout(n, vector<int>(4,0)); vector<int> aa; for(int i = 0 ;i < n; ++i) aa.push_back(i); sort(aa.begin(), aa.end(), [&] (const int x, int y) {return a[x][3] < a[y][3];}); bout[aa[0]][0] = 0; bout[aa[0]][1] = 0; bout[aa[0]][2] = 9999; bout[aa[0]][3] = 9999; int x = 0; for(int i = 1; i < n; ++i){ bout[aa[i]][0] = 9999; bout[aa[i]][1] = x; bout[aa[i]][2] = 10000; bout[aa[i]][3] = x+1; ++x; } //output starts (b) vector<vector<int>> & b = bout; int m_b = b.size(); for(int i = 0; i < m_b ; ++i) { for(int j = 0; j <4;++j) cout << b[i][j] << " "; cout <<endl; } return 0; }
#include<cstdio> #include<iostream> #include<cmath> #include<cstring> #include<cctype> #include<cstdlib> #include<algorithm> #include<vector> #define fs(i,x,y) for(int i=(x),_=(y);i<=_;++i) #define fn(i,x,y) for(int i=(x),_=(y);i>=_;--i) #define tor(i,v,x) for(int i=head[x],v=to[i];i;i=nxt[i],v=to[i]) #define Li inline #define R register int #define ls(x) ch[x][0] #define rs(x) ch[x][1] #define mpi(x,y) make_pair(x,y) #define pi pair<int,int> //#define int ll using namespace std; typedef long long ll; template<typename T> void read(T &x){ x=0;char ch=getchar();bool f=0; while(ch<'0'||ch>'9'){ if(ch=='-')f=1; ch=getchar(); } while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=getchar(); x=f?-x:x; } const int N=2e5+7; int n,m; int a[N],b[N],p[N],id[N],q[N]; vector<pi>v; bool cmp(int lhs,int rhs){ return b[lhs]>b[rhs]; } signed main(){ read(n); fs(i,1,n)read(a[i]); fs(i,1,n)id[i]=i,read(b[i]); fs(i,1,n)read(p[i]),q[p[i]]=i; sort(id+1,id+n+1,cmp); fs(i,1,n){ int x=id[i]; if(q[x]==x)continue; if(a[q[x]]>b[x]&&a[x]>b[p[x]]){ v.push_back(mpi(q[x],x)); p[q[x]]=p[x]; q[p[x]]=q[x]; }else{ printf("-1");return 0; } } int len=v.size(); printf("%d\n",len); fs(i,0,len-1){ printf("%d %d\n",v[i].first,v[i].second); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long using vec_int = vector<int>; using P = pair<int,int>; using T = tuple<int,int,int>; using ll = long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) int charToInt(char c){ char zero_num = '0'; return (int)c - (int)zero_num; } signed main(){ int N; cin>>N; vec_int a(N), b(N), p(N); rep(i,N) cin>>a.at(i); rep(i,N) cin>>b.at(i); rep(i,N) cin>>p.at(i); vector<P> person(N); rep(i, N)person.at(i) = make_pair(a.at(i), i); sort(person.begin(), person.end()); // 何をやらないといけないかというと、 // 体重が軽い人の順番に // 自分のIDの荷物を持っている人と荷物を交換する // map<int, int> assign_map; map<int, int> assign_map2; rep(i,N){ assign_map[p.at(i)] = i; // 荷物, 人 assign_map2[i] = p.at(i); //人, 荷物 } int ans = 0; vector<P> ans_vec; for(int i=0;i<N;i++){ int weight, person_ID; tie(weight, person_ID) = person.at(i); //cout<<weight<<" "<<person_ID<<" "<<assign_map[person_ID]<<endl; if(person_ID == assign_map2[person_ID]-1){ continue; } int nimotu = assign_map2[person_ID]; if(weight <= b.at(nimotu-1) ){ cout<<-1<<endl; return 0; } int counter_person = assign_map[person_ID+1]; // person_ID+1の荷物を持っている人 assign_map2[person_ID] = person_ID+1; assign_map2[counter_person] = nimotu; assign_map[nimotu] = counter_person; ans_vec.push_back(make_pair(person_ID+1, counter_person+1)); ans++; } cout<<ans<<endl; rep(i, ans){ cout<<ans_vec.at(i).first<<" "<<ans_vec.at(i).second<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define fo(i, x, y) for (int i = x; i <= y; ++i) #define fd(i, x, y) for (int i = x; i >= y; --i) #define parr(a, x, y)\ {\ for (int i = x; i <= y; ++i) printf("%d ", a[i]);\ printf("\n");\ } #define pint(a) printf("%d\n", a); typedef long long ll; const int maxn = 2e5 + 5; const ll inf = 1e18; int n; ll a[maxn], d[maxn], maxd[maxn]; int getint() { char ch; int res = 0, p; while (!isdigit(ch = getchar()) && (ch ^ '-')); p = ch == '-'? ch = getchar(), -1 : 1; while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar(); return res * p; } int main() { n = getint(); fo(i, 1, n) a[i] = getint(); maxd[0] = -inf; //mind[0] = inf; fo(i, 1, n) { d[i] = d[i - 1] + a[i]; maxd[i] = max(maxd[i - 1], d[i]); //mind[i] = min(mind[i - 1], d[i]); } ll now = 0, ans = 0; fo(i, 1, n) { ans = max(ans, now + maxd[i]); now += d[i]; } printf("%lld\n", ans); return 0; }
#include<iostream> using namespace std; typedef long long li; #define rep(i,n) for(int i=0;i<(n);i++) #define df 0 template<class T> void print(const T& t){ cout << t << "\n"; } template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); } int ceil2(int a){ int ret=a,i=1; while((ret>>i)!=0){ ret|=ret>>i; i<<=1; } ret++; if(a==(ret>>1)) return a; return ret; } int main(){ int n; cin >>n; int t=ceil2(n+1); auto f=[&](int a){ return (a-1)%t+1; }; auto g=[&](int a){ return f(a)-((f(a)>n)?(t/2):0); }; rep(_i,n){ int i=_i+1; print(g(2*i),g(2*i+1)); } }
#include <iostream> #include <vector> #include <map> #include <set> #include <queue> #include <algorithm> #include <string> #include <cmath> #include <cstdio> #include <iomanip> #include <fstream> #include <cassert> #include <cstring> #include <unordered_set> #include <unordered_map> #include <numeric> #include <ctime> #include <bitset> #include <complex> #include <chrono> #include <random> #include <functional> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int x, y, z; cin >> x >> y >> z; cout << (z * y - 1) / x << '\n'; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) #define REPR(i, n) for(int i = n - 1; i >= 0; i--) #define FOR(i, m, n) for(int i = m; i < n; i++) #define FORR(i,m,n) for(int i = m - 1; i >= n; i--) #define ALL(v) v.begin(), v.end() #define itn int #define Yes() cout << "Yes" << endl #define No() cout << "No" << endl #define YES() cout << "YES" << endl #define NO() cout << "NO" << endl #define println(x) cout << x << endl #define print(x) cout << x << " " template<typename T, typename U> inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; } template<typename T, typename U> inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; } typedef long long lint; typedef long double ldouble; const int INF = 1e9; const lint LINF = 1e18; const int MOD = 1e9+7; int main(){ int x, y, z; cin >> x >> y >> z; int ans = 1; while(1){ if(y * z > ans * x){ ans++; }else{ ans--; break; } } println(ans); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } using ll = long long; using P = pair<int, int>; using vvi = vector<vector<int>>; using vi = vector<int>; const ll MOD = 1e9 + 7; const int INF = 1001001001; const double PI = 3.14159265358979323846; int timer = 0; void dfs(int now, int d, vvi &to, vvi &din, vector<P> &inout) { inout[now].first = timer; din[d].push_back(timer); timer++; for (auto ni : to[now]) { dfs(ni, d+1, to, din, inout); } inout[now].second = timer; } void solve() { int n; cin >> n; vvi to(n), din(n); vector<P> inout(n); rep(i, n-1) { int p; cin >> p; p--; to[p].push_back(i+1); } dfs(0, 0, to, din, inout); int q; cin >> q; rep(x, q) { int u, d; cin >> u >> d; u--; auto [tin, tout] = inout[u]; auto now = din[d]; auto it_out = lower_bound(now.begin(), now.end(), tout); auto it_in = lower_bound(now.begin(), now.end(), tin); int num_out = distance(now.begin(), it_out); int num_in = distance(now.begin(), it_in); int ans = num_out - num_in; cout << ans << endl; } } int main() { solve(); return 0; }
#include <algorithm> #include <iostream> #include <vector> void dfs(const std::vector<int> &C, const std::vector<std::vector<unsigned long>> &edge, unsigned long idx, std::vector<unsigned long> &ans, std::vector<bool> &used, std::vector<bool> &checked) { if (checked[idx]) { return; } else { checked[idx] = true; } if (!used[C[idx]]) { ans.push_back(idx); used[C[idx]] = true; for (const auto &e : edge[idx]) { dfs(C, edge, e, ans, used, checked); } used[C[idx]] = false; } else { for (const auto &e : edge[idx]) { dfs(C, edge, e, ans, used, checked); } } } int main() { unsigned long N; std::cin >> N; std::vector<int> C(N); for (unsigned long i = 0ul; i < N; ++i) { std::cin >> C[i]; } std::vector<std::vector<unsigned long>> edge(N, std::vector<unsigned long>()); for (unsigned long i = 0ul; i < N - 1; ++i) { unsigned long A, B; std::cin >> A >> B; --A; --B; edge.at(A).push_back(B); edge.at(B).push_back(A); } std::vector<unsigned long> ans; std::vector<bool> color_used(200000, false); std::vector<bool> checked(N, false); dfs(C, edge, 0, ans, color_used, checked); std::sort(ans.begin(), ans.end()); for (const auto &c : ans) { std::cout << c + 1 << std::endl; } return 0; }
#include <bits/stdc++.h> typedef long long ll; #define ALL(l) (l).begin(),(l).end() #define rep(i,n) for(ll (i)=0;(i)<(n);(i)++) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) using namespace std; //const ll mod = 998244353; //const ll maxn = 1000000000; //const ll mod = 1000000007; //--------------------------------------------------------------------------------------------------- using vi = vector<int>; // intの1次元の型に vi という別名をつける using vll = vector<ll>; // intの1次元の型に vi という別名をつける using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける using vs = vector<string>; // stringの1次元の型に vs という別名をつける using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える //--------------------------------------------------------------------------------------------------- template <typename T> void chmax(T &a, const T& b) { if (a < b) { a = b; // aをbで更新 } } template <typename T> void chmin(T &a, const T& b) { if (a > b) { a = b; // aをbで更新 } } int main() { //cout << fixed << setprecision(10); ll r; cin>>r; double x,y; cin>>x>>y; double rxy=sqrt(x*x+y*y); //cout<<rxy<<endl; if(r==rxy)cout<<1<<endl; else if(r>rxy)cout<<2<<endl; else{ ll dis=0; rep(i,100000000){ if(dis>=rxy){ cout<<i<<endl; return 0; } dis+=r; } } }
#include <iostream> int main(void) { long long A, B, C; std::cin >> A >> B >> C; if (A == B) { // 2,2 -2,-2 std::cout << "="; return 0; } if (abs(A) == abs(B)) { // 2,-2 -2,2 if (C % 2 == 0) { std::cout << "="; } else { std::cout << (A > B ? ">" : "<"); } return 0; } if (A >= 0 && B >= 0) { // 3,2 2,3 std::cout << (A > B ? ">" : "<"); return 0; } if (A < 0 && B < 0) { // -2,-3 -3,-2 if (C % 2 == 0) { std::cout << (abs(A) > abs(B) ? ">" : "<"); } else { std::cout << (abs(A) > abs(B) ? "<" : ">"); } return 0; } if (A < 0 && B >= 0) { // -2,3 3,-2 if (C % 2 == 0) { std::cout << (abs(A) > B ? ">" : "<"); } else { std::cout << "<"; } return 0; } if (A >= 0 && B < 0) { // 2,-3 -3,2 if (C % 2 == 0) { std::cout << (A > abs(B) ? ">" : "<"); } else { std::cout << ">"; } return 0; } std::cout << std::endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' #define vec vector<ll> #define mat vector<vector<ll> > #define fi first #define se second #define double long double typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> pll; //typedef long double ld; typedef complex<double> Complex; const ll INF=1e9+7; const ll MOD=INF; const ll inf=INF*INF; const ll mod=MOD; const ll MAX=270010; //二分累乗 ll rui(ll a,ll b){ ll res=1; ll x=a; while(b){ if(b&1)res=res*x%mod; x=x*x%mod; b/=2; } return res; } //行列累乗 mat mul(mat &A,mat &B){ mat C(A.size(),vec(B[0].size())); rep(i,A.size()){ rep(j,B[0].size()){ rep(k,B.size()){ C[i][j]=(C[i][j]+(A[i][k]*B[k][j])%mod)%mod; } } } return C; } mat pow(mat A,ll k){ mat B(A.size(),vec(A.size())); rep(i,A.size())B[i][i]=1; while(k>0){ if(k&1)B=mul(B,A); A=mul(A,A); k>>=1; } return B; } signed main(){ ll n,m,k;cin>>n>>m>>k; vector<ll>a(n); rep(i,n)cin>>a[i]; vector<vector<ll> >s(n,vector<ll>(n)); ll invm=rui(m*2LL%mod,mod-2); rep(i,m){ ll x,y;cin>>x>>y; x--;y--; s[x][x]=(s[x][x]-invm)%mod; s[y][y]=(s[y][y]-invm)%mod; s[x][y]=(s[x][y]+invm)%mod; s[y][x]=(s[y][x]+invm)%mod; } rep(i,n){ s[i][i]=(s[i][i]+1)%mod; } vector<vector<ll> >d=pow(s,k); rep(i,n){ ll ans=0; rep(j,n){ ans=(ans+a[j]*d[i][j]%mod)%mod; } if(ans<0)ans+=mod; cout<<ans<<endl; } }
#include <bits/stdc++.h> using namespace std; const int maxh = 20; struct Pos { int r, c; Pos(int r=0, int c=0) : r(r), c(c) {} }; int H, W, A, B; int G[maxh][maxh]; Pos nextPos(int r, int c) { r--; c--; int id = r * W + c; id++; r = id / W; c = id % W; return Pos(r+1, c+1); } void dfs(Pos pos, int cnta, int cntb, int &ans) { int r = pos.r, c = pos.c; Pos npos = nextPos(r, c); if (cnta == 0 && cntb == 0) { ans++; return; } if (G[r][c] > 0) { dfs(npos, cnta, cntb, ans); return; } // PUSH B if (cntb > 0) { G[r][c] = 1; dfs(npos, cnta, cntb-1, ans); G[r][c] = 0; } if (cnta > 0) { // PUSH A with horizontally if (c+1 <= W && !G[r][c+1]) { G[r][c] = G[r][c+1] = 2; dfs(npos, cnta-1, cntb, ans); G[r][c] = G[r][c+1] = 0; } // PUSH A with vertically if (r+1 <= H && !G[r+1][c]) { G[r][c] = G[r+1][c] = 2; dfs(npos, cnta-1, cntb, ans); G[r][c] = G[r+1][c] = 0; } } } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); // freopen("in", "r", stdin); cin >> H >> W >> A >> B; int ans = 0; dfs(Pos(1, 1), A, B, ans); cout << ans; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> int M=1000000007; const int N=200005; signed main(){ int t1=1; //cin>>t1; while(t1--){ int n,m; cin>>n>>m; map<int,int> mp; for(int i=0;i<n+m;i++){ int x; cin>>x; mp[x]++; } for(auto it:mp) if(it.second==1) cout<<it.first<<" "; cout<<endl; } }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; int main() { int n, m; cin >> n >> m; set<int> a, b, ab; rep (i, n) { int c; cin >> c; a.insert(c); ab.insert(c); } rep(i, m) { int d; cin >> d; b.insert(d); ab.insert(d); } for (int i: ab) { if (a.count(i) && !b.count(i) || b.count(i) && !a.count(i)) { cout << i << " "; } } cout << endl; return 0; }
///In the name of GOD //#pragma GCC optimize("O2") #include<bits/stdc++.h> using namespace std; typedef long long ll; const ll MXN = 3e5 + 10; const ll SGM = 30; ll n, ans; string s; ll Cnt[SGM]; int main(){ ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); cin >> s; n = s.size(); s = "$" + s; Cnt[s[n] - 'a'] ++; Cnt[s[n - 1] - 'a'] ++; for(int i = n - 2; i; i --){ if(s[i] == s[i + 1]){ ans += (n - (i + 1)) - (Cnt[s[i] - 'a'] - 1); memset(Cnt, 0, sizeof Cnt); Cnt[s[i] - 'a'] = n - (i - 1); } else{ Cnt[s[i] - 'a'] ++; } } cout << ans << '\n'; return 0; } /*! HE'S AN INSTIGATOR, ENEMY ELIMINATOR, AND WHEN HE KNOCKS YOU BETTER YOU BETTER LET HIM IN. */ //! N.N
#include "bits/stdc++.h" using namespace std; #define int long long const int MAX=1e5+10; const int mod=1e9+7; const int INF=0x3f3f3f3f3f3f3f3f; void solve(){ string tem="ZONe"; string s; cin>>s; int ans=0; for(int i=0;i<s.size();i++){ int ji=0; for(int j=0;j<tem.size();j++){ if(s[i+j]==tem[j]){ ji++; } } if(ji==tem.size()){ ans++; } } cout<<ans; } signed main(){ int _=1; //ios::sync_with_stdio(0);cout.tie(0);cin.tie(0); //cin>>_; for(int i=1;i<=_;i++){ //cout<<"Case #"<<i<<": "; solve(); } return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> #include <random> #include <chrono> //#include <ext/pb_ds/tree_policy.hpp> //#include <ext/pb_ds/assoc_container.hpp> #define _ << " " << #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define sp(n) fixed << setprecision(n) #define ff first #define ss second #define pb push_back using namespace std; //using namespace __gnu_pbds; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; //using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; //using ordered_multiset = tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>; const int mod = 1e9 + 7; const double eps = 1e-12; const ll INF = 1e18; int main() { srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); #ifdef LOCAL_DEBUG freopen("input.txt", "r", stdin); //freopen("output_false.txt", "w", stdout); //outs #endif int h, w; cin >> h >> w; vector<vector<int>> a(h, vector<int>(w)); for (auto& i : a) { for (int& j : i) cin >> j; } int minv = a[0][0]; for (auto& i : a) { for (int& j : i) minv = min(minv, j); } ll ans = 0; for (auto& i : a) { for (int& j : i) ans += j - minv; } cout << ans << endl; return 0; }
/** * author : UshanGhosh * created : 2020-12-19 18:04:46 **/ #include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define vii vector<int> #define vcc vector<char> #define pll pair<long long, long long> #define mem memset #define sof sizeof #define co1 __builtin_popcountll #define PB push_back #define UB upper_bound #define LB lower_bound #define MP make_pair #define TS to_string #define F first #define S second #define pi acos(-1) #define mod (long long)1000000007 #define inf (long long)1e18 #define endl '\n' int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long a,b,c,d,e,f,i,j,k,m,n,o,x,y; cin>>n>>m; ll pans = inf; ll sum = 0; for(i=0;i<n*m;i++){ cin>>a; pans = min(pans, a); sum += a; } cout<<sum-pans*n*m; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin>> #define ll long long #define ln cout<<'\n' #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n",a) #define mem(a) memset(a,0,sizeof(a)) #define all(c) (c).begin(),(c).end() #define iter(c) __typeof((c).begin()) #define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++) ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;} template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);} template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;} const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1}; typedef pair<ll,ll> P; void Main() { ll n,x; cin >> n >> x; ll a[n]; rep(i,n) R a[i]; ll ans=MAXL; REP(m,1,n+1) { ll dp[2][m][m+1]; rep(i,2)rep(j,m)rep(k,m+1) dp[i][j][k]=-MAXL; dp[0][0][0]=0; ll t=0; rep(i,n) { rep(j,m)rep(k,m+1) dp[t^1][j][k]=max(dp[t^1][j][k],dp[t][j][k]); rep(j,m) { rep(k,m) { if(dp[t][j][k]<0) continue; dp[t^1][(j+a[i])%m][k+1]=max(dp[t^1][(j+a[i])%m][k+1],dp[t][j][k]+a[i]); } } rep(j,m)rep(k,m+1) dp[t][j][k]=-MAXL; t^=1; } rep(j,m) { if(dp[t][j][m]<0) continue; ll y=x-dp[t][j][m]; if(y%m==0) ans=min(ans,y/m); } } pr(ans); } int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
#include <bits/stdc++.h> using namespace std; // I have no idea what I'm doing #ifdef DEBUG #define debug(...) __VA_ARGS__ #else #define endl '\n' #define debug(...) #endif #define debugf(...) debug(printf(__VA_ARGS__)) const int N = 128; using ll = long long; const ll oo = 0x3f3f3f3f3f3f3f3fll; ll dp[N][N]; int a[N]; int (((((((main)))))))() { cin.tie(0)->sync_with_stdio(false); int n; cin >> n; ll X; cin >> X; for (int i = 0; i < n; i++) cin >> a[i]; ll ans = oo; for (int k = 1; k <= n; k++) { // we'll pick exactly k elements from A // Clear dp[][] // std::fill() doesn't work for some reason for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) dp[i][j] = -oo; // Run a knapsack dp[0][0] = 0; for (int i = 0; i < n; i++) { // put the i-th element of A in the knapsack ll x = a[i]; for (int j = k; j > 0; j--) { // the current subset has j elements for (int m = 0; m < k; m++) { // and the "previous" subset has sum = m (mod k) ll sum = dp[j-1][m]; ll m2 = (x + sum) % k; if (sum >= 0) dp[j][m2] = max(dp[j][m2], x + sum); } } } // Get the best answer for a subset of A with size k ll cur = dp[k][X % k]; debugf("k = %d, cur = %lld\n", k, cur); if (cur >= 0) { ans = min(ans, (X - cur) / k); } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long #define P pair<ll,int> #define PI 3.141592653589793 #define pb push_back const int INF = 1001001001; const ll MX = 1e18; const int mod = 998244353; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } int main() { int n, m, x, y; cin >> n >> m >> x >> y; x--; y--; vector<vector<ll>> b(n), t(n), k(n); vector<ll> mp(n, MX); rep(i, m) { int ai, bi, ti, ki; cin >> ai >> bi >> ti >> ki; ai--; bi--; b[ai].pb(bi); t[ai].pb(ti); k[ai].pb(ki); b[bi].pb(ai); t[bi].pb(ti); k[bi].pb(ki); } priority_queue<P> q;//(現在時刻*-1、場所) q.push(P(0, x)); while (!q.empty()) { ll nt = q.top().first; nt *= -1; int now= q.top().second; q.pop(); rep(i, b[now].size()) { ll next = nt + t[now][i] + k[now][i] - nt % k[now][i]; if (nt % k[now][i] == 0) { next = nt + t[now][i]; } if (next < mp[b[now][i]]) { mp[b[now][i]] = next; q.push(P(-next, b[now][i])); } } } if (mp[y] == MX) cout << -1 << endl; else cout << mp[y] << endl; }
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define sz(x) (int) x.size() #define pb push_back #define endl '\n' #define snd second #define fst first #define fastio cin.tie(NULL),cout.sync_with_stdio(true) typedef long long int ll; typedef unsigned long long int ull; typedef vector <int> vi; typedef pair <ll,ll> ii; typedef vector<vector<ll>> matrix; const int mod = 1e9 + 7; const ll INF = 1e18; const double EPSILON = 1e-9; const int N = 2*1e5+5; vector<pair<int, ii>> adj[N]; priority_queue <ii, vector <ii>, greater <ii>> pq; int main(){ fastio; int n,m,x,y; cin >> n >> m >> x >> y; for(int i = 0; i < m; i++){ int u,v,c,t; cin >> u >> v >> c >> t; adj[u].pb({v, {c,t}}); adj[v].pb({u, {c,t}}); } vector<ll> see(n+1, INF); pq.push({0, x}); see[x] = 0; while(!pq.empty()){ ll d = pq.top().fst; int v = pq.top().snd; pq.pop(); if(d > see[v]) continue; for(auto i:adj[v]){ ll cost = i.snd.fst + (i.snd.snd*((d+i.snd.snd-1)/i.snd.snd) - d); if(see[i.fst] > d + cost){ see[i.fst] = d + cost; pq.push({see[i.fst], i.fst}); } } } cout << (see[y] == INF ? -1 : see[y]) << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<pll> vpll; typedef vector<bool> vbl; typedef vector<vector<bool>> vvbl; void INX(){} template<typename Head, typename... Tail> void INX(Head&& head, Tail&&... tail) { cin >> head; INX(forward<Tail>(tail)...); } void OUTX(){} template<typename Head, typename... Tail> void OUTX(Head&& head, Tail&&... tail) { cout << head << endl; OUTX(forward<Tail>(tail)...); } void OUTX2(){cout << endl;} template<typename Head, typename... Tail> void OUTX2(Head&& head, Tail&&... tail) { cout << head << ' '; OUTX2(forward<Tail>(tail)...); } #define ADD emplace_back #define MP make_pair #define VVEC(type) vector<vector<type>> #define __LONG_LONG_MIN__ (-__LONG_LONG_MAX__ - 1) //#define MOD 1000000007 // 10^9 + 7 //setprecision(10) int main() { string S; INX(S); ll result = 0; char lastcnt = 0; char pre = 0; ll cnt = 0; bool iscont = false; for (ll i = 0; i < (ll)S.size(); i++) { char si = S[i]; if(iscont) { if(pre == si) { // } else { iscont = false; lastcnt = pre; cnt++; } } else { if(lastcnt == si) { result--; } else if(pre == si) { iscont = true; } else { // } } result += cnt; pre = si; } OUTX(result); return 0; }
#include<bits/stdc++.h> using namespace std; #define il inline #define ri register int #define ll long long #define ui unsigned int il ll read(){ bool f=true;ll x=0; register char ch=getchar(); while(ch<'0'||ch>'9') {if(ch=='-') f=false;ch=getchar();} while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar(); if(f) return x; return ~(--x); } il int read(char *s){ int len=0; register char ch=getchar(); while(ch==' '||ch=='\n') ch=getchar(); while(ch!=' '&&ch!='\n'&&ch!=EOF) s[++len]=ch,ch=getchar(); return len; } il void write(const ll &x){if(x>9) write(x/10);putchar(x%10+'0');} il void print(const ll &x) {x<0?putchar('-'),write(~(x-1)):write(x);putchar('\n');} il ll max(const ll &a,const ll &b){return a>b?a:b;} il ll min(const ll &a,const ll &b){return a<b?a:b;} const int MAXN=2e5+7; char s[MAXN]; int n; ll cnt; ll b[26]; int main(){ scanf("%s",s+1); n=strlen(s+1); b[s[n]-'a']++; for(ri i=n-1;i>1;--i){ // int j=i; if(s[i]==s[i-1]){ cnt+=n-i-b[s[i]-'a']; memset(b,0,sizeof(b)); b[s[i]-'a']=n-i; } b[s[i]-'a']++; } print(cnt); return 0; }
#include<bits/stdc++.h> #define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i) #define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i) #define foreach(i, n) for(auto &i:(n)) #define all(x) (x).begin(), (x).end() #define bit(x) (1ll << (x)) #define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE #define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__) using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; //const ll MOD = (ll)1e9+7; const ll MOD = 998244353; const int INF = (ll)1e9+7; const ll INFLL = (ll)1e18; template<class t> using vvector = vector<vector<t>>; template<class t> using vvvector = vector<vector<vector<t>>>; template<class t> using priority_queuer = priority_queue<t, vector<t>, greater<t>>; template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;} template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;} #ifdef DEBUG #define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl; #else #define debug(x) (void)0 #endif namespace templates{ ll modpow(ll x, ll b){ ll res = 1; while(b){ if(b&1)res = res * x % MOD; x = x * x % MOD; b>>=1; } return res; } ll modinv(ll x){ return modpow(x, MOD-2); } bool was_output = false; template<class t> void output(t a){ if(was_output)cout << " "; cout << a; was_output = true; } void outendl(){ was_output = false; cout << endl; } ll in(){ ll res; cin >> res; return res; } template<class t> istream& operator>>(istream&is, vector<t>&x){ for(auto &i:x)is >> i; return is; } template<class t, class u> istream& operator>>(istream&is, pair<t, u>&x){ is >> x.first >> x.second; return is; } template<class t> t in(){ t res; cin >> res; return res; } template<class t> void out(t x){ cout << x; } template<class t> vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){ sort(line.begin(),line.end(),comp); return line; } template<class t> vector<t> reversed(vector<t> line){ reverse(line.begin(),line.end()); return line; } } using namespace templates; int func(){ int n = in(); string str = in<string>(); string res = ""; foreach(i,str){ res += i; while(res.size()>=3 and res.substr(res.size()-3)=="fox"){ res.erase(res.begin()+res.size()-3,res.end()); } } return res.size(); } int main(){ cout << func() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define MAXX 500005 #define PI M_PI #define pb push_back #define F first #define S second #define fixx(n) fixed << setprecision(n) #define ll long long #define int ll const int mod = 1e9 + 7; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; string s; cin >> n >> s; string h = ""; for(int i = 0 ;i < s.size(); i ++){ h += (s[i]); while(h.size() >= 3 && h.substr(h.size() - 3, 3) == "fox"){ h.erase( h.size() - 1); h.erase(h.size() - 1); h.erase(h.size() - 1); } } cout << h.size(); return 0; }
#include <cstdio> #include <vector> #include <algorithm> int n; std::vector<int> tree[100000]; constexpr int INF = 100000000; int size[100000]; int dp[100000]; int size_dfs(int v){ for(int c: tree[v]){ size[v] += size_dfs(c); } return size[v] += 1; } int dfs(int v){ if(dp[v] != INF) return dp[v]; dp[v] = 1; int other = 0; std::vector<int> rest; for(int c: tree[v]){ int w = dfs(c); if(size[c] % 2 == 0 && w < 0) dp[v] += w; else if(size[c] % 2 == 1) rest.push_back(w); else other += w; } std::sort(rest.begin(), rest.end()); for(int i = 0; i < rest.size(); i++){ dp[v] += rest[i++]; if(i < rest.size()) dp[v] -= rest[i]; } if(rest.size() % 2 == 0) dp[v] += other; else dp[v] -= other; // printf("%d %d\n", v, dp[v]); return dp[v]; } int main(){ scanf("%d", &n); for(int i = 0; i < n-1; i++){ int p; scanf("%d", &p); tree[p-1].push_back(i+1); } size_dfs(0); for(int i = 0; i < n; i++) dp[i] = INF; auto z = dfs(0); printf("%d\n", (z + n)/2); return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> ii; vector<vector<int>> adj; vector<int> p, sz; void dfs(int u){ sz[u] = 1; for(int v : adj[u]){ if(v != p[u]){ dfs(v); sz[u] += sz[v]; } } } vector<int> memo; int max_coins(int u){ if(memo[u] != -1) return memo[u]; vector<ii> balances_even, balances_odd; for(int v : adj[u]){ if(v == p[u]) continue; int p1 = max_coins(v); int p2 = sz[v] - p1; int balance = p1 - p2; if(sz[v] & 1){ balances_odd.push_back({balance, v}); } else { balances_even.push_back({balance, v}); } } sort(balances_even.begin(), balances_even.end()); sort(balances_odd.begin(), balances_odd.end()); int coins = 0; while(!balances_even.empty() and balances_even.back().first > 0){ int v = balances_even.back().second; coins += max_coins(v); balances_even.pop_back(); } int p = 0; while(!balances_odd.empty()){ int v = balances_odd.back().second; if(p == 0) coins += max_coins(v); else coins += sz[v] - max_coins(v); balances_odd.pop_back(); p ^= 1; } while(!balances_even.empty()){ int v = balances_even.back().second; if(p == 0) coins += max_coins(v); else coins += sz[v] - max_coins(v); balances_even.pop_back(); } return memo[u] = coins; } int main(){ int n; while(scanf("%d", &n) > 0){ adj.assign(n+1, vector<int>()); sz.assign(n+1, 0); p.assign(n+1, 0); for(int i = 2; i <= n; i++){ scanf("%d", &p[i]); adj[p[i]].push_back(i); } dfs(1); memo.assign(n+1, -1); printf("%d\n", sz[1] - max_coins(1)); } }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define f first #define s second #define mk make_pair ll mod(ll B,ll P,ll M) { if(P==0) return 1; else if(P==1) return B%M; else if(P%2==0){ ll x=mod(B,P/2,M)%M; return ((x*x)%M); } else if(P%2){ ll x=mod(B,(P-1)/2,M)%M; ll x2=(x*x)%M; return ((x2)*(B%M))%M; } } 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 int t=1; //cin>>t; while(t--) { ll ans=0; ll modulo=998244353; ll n,m,k; cin>>n>>m>>k; if(n==1&&m==1) { ans=k; } else if(n==1) { ans=mod(k,m,modulo); } else if(m==1) { ans=mod(k,n,modulo); } else { for(int i=1;i<=k;i++) { ll in=mod(i,n,modulo); ll in1=mod(i-1,n,modulo); ll term1=(in-in1+modulo)%modulo; ll term2=mod(k-i+1,m,modulo); ans=(ans+term1*term2)%modulo; } } cout<<ans; }//while }//main
#include<bits/stdc++.h> using namespace std; int read() { char c=getchar(); int x=0,f=1; while (c<'0' || c>'9') { if (c=='-') f=-1; c=getchar(); } while (c>='0' && c<='9') { x=x*10+c-'0'; c=getchar(); } return x*f; } const int p=998244353; int f[200005],g[200005],sf[200005]; int pow_mod(int x,int k) { int ans=1; while (k) { if (k&1) ans=1LL*ans*x%p; x=1LL*x*x%p; k>>=1; } return ans; } void add(int &x,int y) { x+=y; if (x>=p) x-=p; } int main() { int n=read(),m=read(),k=read(); for (int i=1; i<=k; i++) f[i]=(pow_mod(i,n)-pow_mod(i-1,n)+p)%p; for (int i=1; i<=k; i++) g[i]=(pow_mod(i,m)-pow_mod(i-1,m)+p)%p; sf[0]=0; for (int i=1; i<=k; i++) sf[i]=(sf[i-1]+f[i])%p; int ans=0; if (n==1 || m==1) { for (int i=1; i<=k; i++) add(ans,1LL*f[i]*g[k+1-i]%p); } else { for (int i=1; i<=k; i++) add(ans,1LL*sf[i]*g[k+1-i]%p); } cout<<ans<<endl; return 0; }
# include <bits/stdc++.h> # ifndef ngng628_library # define ngng628_library # define int long long # define float long double # define fi first # define se second # define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) # define reps(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i) # define rrep(i,n) for(int i=((int)(n)-1); i>=0; --i) # define rreps(i,n) for(int i=((int)(n)); i>0; --i) # define repr(i,b,e) for(int i=(b), i##_len=(e); i<i##_len; ++i) # define reprs(i,b,e) for(int i=(b), i##_len=(e); i<=i##_len; ++i) # define all(x) std::begin(x), std::end(x) # define rall(x) std::rbegin(x), std::rend(x) # define pb push_back # define eb emplace_back # define len(x) ((int)(x).size()) # define contains(x,key) ((x).find(key) != (x).end()) # define lb(v,x) distance(std::begin(v), lower_bound(all(v), (x))) # define ub(v,x) distance(std::begin(v), upper_bound(all(v), (x))) using namespace std; template<class T> using vec = vector<T>; using pii = pair<int, int>; using vi = vec<int>; using vb = vec<bool>; using vvb = vec<vb>; using vvvb = vec<vvb>; using vs = vec<string>; using vvi = vec<vi>; using vvvi = vec<vvi>; constexpr int INF = (1LL<<62)-(1LL<<31); constexpr float EPS = 1e-10; template<class T> istream& operator>>(istream& is, vec<T>& v) { for (auto& x : v) is >> x; return is; } template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.fi >> p.se; } template<class T> T scan() { T ret; cin >> ret; return ret; } template<class T> string join(const vec<T> &v){ stringstream s; rep (i, len(v)) s<<' '<<v[i]; return s.str().substr(1); } template<class T> ostream& operator<<(ostream& os, const vec<T>& v){ if (len(v)) os << join(v); return os; } template<class T> ostream& operator<<(ostream& os, const vec<vec<T>>& v){ rep (i, len(v)) { if (len(v[i])) os << join(v[i]) << (i-len(v)+1 ? "\n" : ""); } return os; } template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ cout << p.fi << " " << p.se; return os; } void print(){ cout << "\n"; } template<class T, class... A>void print(const T& v, const A&...args){cout << v; if(sizeof...(args))cout << " "; print(args...);} void eprint() { cerr << "\n"; } template<class T, class... A>void eprint(const T& v, const A&...args){cerr << v; if(sizeof...(args))cerr << " "; eprint(args...);} void drop(){ cout << "\n"; exit(0); } template<class T, class... A>void drop(const T& v, const A&...args){cout << v; if(sizeof...(args))cout << " "; drop(args...);} template<class T> inline constexpr bool chmax(T &a, const T& b) { return a < b && (a = b, true); } template<class T> inline constexpr bool chmin(T &a, const T& b) { return a > b && (a = b, true); } constexpr int ctoi(const char c) { return ('0' <= c and c <= '9') ? (c - '0') : -1; } const char* yn(bool b) { return b ? "Yes" : "No"; } # endif // ngng628_library struct Edge { Edge() = default; Edge(int t, int w, int k) : to(t), weight(w), K(k) {} int to, weight, K; }; using Graph = vec<vec<Edge>>; vi dijkstra(const Graph& graph, int start) { vi dist(len(graph), INF); priority_queue<pii, vec<pii>, greater<pii>> pq; // {dist, to} dist[start] = 0; pq.emplace(dist[start], start); while (not pq.empty()) { auto [d, now] = pq.top(); pq.pop(); if (dist[now] < d) continue; for (auto& edge : graph[now]) { int loss = (-dist[now] % edge.K + edge.K) % edge.K; int cost = dist[now] + loss + edge.weight; if (chmin(dist[edge.to], cost)) { pq.emplace(cost, edge.to); } } } return dist; } int32_t main() { int n, m, x, y; cin >> n >> m >> x >> y; x--; y--; Graph g(n); rep (i, m) { int a, b, t, k; cin >> a >> b >> t >> k; a--; b--; g[a].eb(b, t, k); g[b].eb(a, t, k); } auto d = dijkstra(g, x); print(d[y] < INF ? d[y] : -1); }
#include <iostream> #include <fstream> #include <vector> #include <set> #include <map> #include <cstring> #include <string> #include <cmath> #include <cassert> #include <ctime> #include <algorithm> #include <sstream> #include <list> #include <queue> #include <deque> #include <stack> #include <cstdlib> #include <cstdio> #include <iterator> #include <functional> #include <bitset> #ifdef LOCAL #define eprintf(...) fprintf(stderr,__VA_ARGS__) clock_t __my_start_clock = clock(); #else #define eprintf(...) #endif #define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC) #define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC) using namespace std; #ifdef LOCAL static struct __timestamper { string what; __timestamper(const char* what) : what(what){}; __timestamper(const string& what) : what(what){}; ~__timestamper(){ TIMESTAMPf("%s", what.data()); } } __TIMESTAMPER("end"); #else struct __timestamper {}; #endif typedef long long ll; typedef long double ld; void solve() { int n; string a, b, c; cin >> n >> a >> b >> c; eprintf("%d\n%s\n%s\n%s\n", n, a.c_str(), b.c_str(), c.c_str()); a = a + a; b = b + b; c = c + c; auto test_one = [](const string& a, const string& b) { int pt = 0; for (char c : a) { if (b[pt] == c) pt++; if (pt == (int)b.size()) return true; } return false; }; auto test = [&](const string &t) { return test_one(a, t) && test_one(b, t) && test_one(c, t); }; for (char c1 = '0'; c1 <= '1'; c1++) { for (char c2 = '0'; c2 <= '1'; c2++) { for (char c3 = '0'; c3 <= '1'; c3++) { string cand = string(n, c1) + c2 + string(n, c3); if (test(cand)) { printf("%s\n", cand.c_str()); return; } cand = string(n, c1) + string(n, c3) + c2; if (test(cand)) { printf("%s\n", cand.c_str()); return; } cand = c2 + string(n, c1) + string(n, c3); if (test(cand)) { printf("%s\n", cand.c_str()); return; } } } } assert(false); } int main() { #ifdef LOCAL freopen("a.in", "r", stdin); freopen("a.out", "w", stdout); #endif int t; cin >> t; while (t-->0) { solve(); } return 0; }
/** * author: * created: 26.10.2020 13:52:11 **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for (int i=0;i<n;i++) typedef pair<ll,string> P; int main() { ll n; cin >> n; vector <ll> a(n),b(n+1,0),c(n+1,0),d(n); rep(i,n){ cin >> a.at(i); //pq.push(a.at(i)); if(i==0) d.at(i)=a.at(i); else d.at(i)=max(d.at(i-1),a.at(i)); } rep(i,n){ b.at(i+1)=b.at(i)+a.at(i); c.at(i+1)=c.at(i)+b.at(i+1); } rep(i,n){ //cout << b.at(i) <<' '<< c.at(i) <<' '<< d.at(i) << endl; cout << d.at(i)*(i+1)+c.at(i)+b.at(i+1) << endl; } }
#include"bits/stdc++.h" using namespace std; long long N; long long A[200000]; long long Max[200000] = { 0 }; long long _Max = 0; long long A0_k = 0; long long ans = 0; int main(){ cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; if (_Max < A[i]) { _Max = A[i]; } Max[i] = _Max; } for (int i = 0; i < N; i++) { A0_k += A[i]; ans += A0_k; cout << ans + Max[i] * (i + 1) << endl; } }
#include <algorithm> #include <iostream> #include <stack> #include <queue> #include <math.h> #include <cmath> #include <string> #include <iterator> #include <map> #include <set> #include <iomanip> #include <vector> #include <cstdint> #include <time.h> using namespace std; using ll = long long; using ld = long double; using P = pair<ll, ll>; using Graph = vector<vector<int>>; #define rep(i, N) for(int i = 0; i < N; i++) #define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++) #define INF 1000000000000000000 #define MAX 200001 #define PI 3.141592653589793 #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") const ll MOD = 1000000007; /*clock_t start = clock(); clock_t end = clock(); const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0; printf("%lf", time);*/ template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();}; int par[1000000]; void init(int N){ rep(i,N) par[i] = -1; } int find(int a){ if(par[a] < 0) return a; else{ return par[a] = find(par[a]); } } void unite(int a, int b){ a = find(a); b = find(b); if(a == b) return; else{ if(par[a] > par[b]) swap(a,b); par[a] += par[b]; par[b] = a; } } int size(int A) { return -par[find(A)]; } bool same(int a, int b){ return find(a) == find(b); } int main(){ int N,M; cin >> N >> M; init(N); vector<ll> 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--; unite(c,d); } map<int,vector<int>> group; rep(i,N){ group[find(i)].push_back(i); } bool flag = true; for(auto g:group){ auto v = g.second; ll A = 0; ll B = 0; for(auto u:v){ A += a[u]; B += b[u]; } if(A != B) flag = false; } if(flag) cout << "Yes" << endl; else cout << "No" << endl; }
#include<bits/stdc++.h> using namespace std; const int maxN = 200009; int N, M, a[maxN], b[maxN]; bool ap[maxN]; long long sumA, sumB; vector < int > v[maxN]; void dfs (int nod) { ap[nod] = 1, sumA += a[nod], sumB += b[nod]; for (auto it : v[nod]) if (!ap[it]) dfs (it); } int main () { //freopen ("input", "r", stdin); //freopen ("output", "w", stdout); scanf ("%d %d", &N, &M); for (int i=1; i<=N; i++) scanf ("%d", &a[i]); for (int i=1; i<=N; i++) scanf ("%d", &b[i]); while (M --) { int x, y; scanf ("%d %d", &x, &y); v[x].push_back (y); v[y].push_back (x); } for (int i=1; i<=N; i++) if (ap[i] == 0) { sumA = 0, sumB = 0, dfs (i); if (sumA != sumB) { printf ("No\n"); return 0; } } printf ("Yes\n"); return 0; }
#include <bits/stdc++.h> ///#pragma GCC target ("sse4.2") ///#pragma GCC opimize("O1") ///#pragma GCC opimize("O2") ///#pragma GCC opimize("Os") ///#pragma GCC opimize("Ofast") ///#pragma GCC target("avx,avx2,fma") ///#pragma GCC target("avx2") ///#pragma GCC opimize("O3") ///#pragma GCC opimization ("unroll-loops") using namespace std; bool home = 1; typedef long long ll; typedef long double ld; #define int ll signed realMain(); signed main() { #ifdef ONLINE_JUDGE home = 0; #endif if (home) { freopen ("tony_stark", "r", stdin); } else { ios::sync_with_stdio(0); cin.tie(0); } realMain(); } const int M = (int) 1e9 + 7; int n, mod; signed realMain() { cin >> n >> mod; if (mod == 0) { cout << (n == 1) << "\n"; return 0; } int ret = mod - 1, b = n - 1, a = mod - 2; while (b) { if (b & 1) { ret = (ll) ret * a % M; } b /= 2; a = (ll) a * a % M; } cout << ret << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; #define endl "\n" #define pb push_back typedef long long ll; const double pi = acos(-1.0); #define debug puts("*****************") #define memset(a,b) memset(a,b,sizeof(a)) const int mod = (1 ? 1000000007 : 998244353); const int inf = (1 ? 0x3f3f3f3f : 0x7fffffff); const int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 }; const ll INF = (1 ? 0x3f3f3f3f3f3f3f3f : 0x7fffffffffffffff); ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll poww(ll a, ll b) { ll s = 1; while (b) { if (b & 1)s = (s * a) % mod; a = (a * a) % mod; b >>= 1; }return s % mod; } /*----------------------------------------------------------------------------------------------------------------------*/ const int N = 1e5 + 11; ll n,m; void solve() { cin>>n>>m; ll mm=m; m--; m/=2; ll sum=m*2; if(mm%2==0&&n<=0)sum++; if(n>0&&mm%2==0) { ll nn=n; nn-=(mm/2); if(nn>=0)sum++; } if(n<=0) { n*=-1; if(m<n&&mm%2==1&&m>0)sum--; } else if(mm%2==1&&m>0)sum--; if(n>0) { ll q=min(n-1,m); sum+=q*2; m-=q; if(m>0)sum++; } sum++; if(n!=0)sum++; cout<<sum<<endl; } /*----------------------------------------------------------------------------------------------------------------------*/ int main() { ios::sync_with_stdio(false); cin.tie(0); ll T = 1; //cin >> T; while (T--)solve(); return 0; }
#include <iostream> // cout, endl, cin #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <vector> //vector using namespace std; #define _LIBCPP_DEBUG 0 #define rep(i, n) for(int i = 0; i < (int)n; i++) typedef long long ll; string ans; ll conbi(int s, int a){ ll cans = 1; vector<int> v; rep(i, a) v.push_back(a - i); rep(i, a){ cans *= s; for(auto it = v.begin(); it != v.end();){ if(cans % *it == 0){ cans /= *it; it = v.erase(it); }else{ ++it; } } s--; } return cans; } void dfs(int a, int b, ll k){ if(a == 0){ rep(i, b) ans.push_back('b'); return; } if(b == 0){ rep(i, a) ans.push_back('a'); return; } a--; int s = a + b; ll buf = conbi(s, min(a, b)); //cout << "s : " << s << " buf : " << buf << " k : " << k; if(buf < k){ //cout << " choice : b" << endl; ans.push_back('b'); dfs(a+1, b-1, k-buf); }else{ //cout << " choice : a" << endl; ans.push_back('a'); dfs(a, b, k); } } int main(){ int a, b; ll k; cin >> a >> b >> k; dfs(a, b, k); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define Pr pair<ll,ll> #define Tp tuple<ll,ll,ll> using Graph = vector<vector<int>>; ll mod = 1000000007; int main() { ll N; cin >> N; vector<Pr> s,t; string ans = "No"; rep(i,N){ ll x,y; cin >> x >> y; s.push_back(make_pair(x,y)); } rep(i,N){ ll x,y; cin >> x >> y; t.push_back(make_pair(x,y)); } if(N==1){ cout << "Yes" << endl; return 0; } ll dx = s[1].first - s[0].first; ll dy = s[1].second - s[0].second; double th1 = atan2(dy,dx); rep(i,N){ rep(j,N){ ll dx2 = t[j].first - t[i].first; ll dy2 = t[j].second - t[i].second; double th2 = atan2(dy2,dx2); if(dx*dx+dy*dy!=dx2*dx2+dy2*dy2) continue; set<Pr> pts; rep(k,N){ pts.insert(s[k]); } rep(k,N){ ll dx3 = t[k].first - t[i].first; ll dy3 = t[k].second - t[i].second; double ndx = dx3*cos(th1-th2) - dy3*sin(th1-th2); double ndy = dy3*cos(th1-th2) + dx3*sin(th1-th2); if(abs(round(ndx)-ndx)>=0.05) continue; if(abs(round(ndy)-ndy)>=0.05) continue; pts.erase(make_pair(s[0].first+round(ndx),s[0].second+round(ndy))); } if(pts.empty()){ ans = "Yes"; //cout << i << " " << j << endl; } } } cout << ans << endl; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int N; long long C; cin >> N >> C; vector<int> a(N), b(N), c(N); for (int i = 0; i < N; ++i) { cin >> a[i] >> b[i] >> c[i]; } vector<int> d; for (int i = 0; i < N; ++i) { d.push_back(a[i] - 1); d.push_back(b[i]); } sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end()); const int D = d.size(); vector<long long> acc(D + 1, 0LL); for (int i = 0; i < N; ++i) { auto it_a = lower_bound(d.begin(), d.end(), a[i] - 1); auto it_b = lower_bound(d.begin(), d.end(), b[i]); acc[it_a - d.begin()] += c[i]; acc[it_b - d.begin()] -= c[i]; } for (int i = 0; i < D; ++i) { acc[i + 1] += acc[i]; } long long ans = 0; for (int i = 0; i + 1 < D; ++i) { ans += min(C, acc[i]) * (d[i + 1] - d[i]); } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) template<typename T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } else return false; } template<typename T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else return false; } using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll n, c; cin >> n >> c; map<ll, vector<ll>> mp; rep(i, n) { ll a, b, c; cin >> a >> b >> c; mp[a].push_back(c); mp[b + 1].push_back(-c); } ll ans = 0; ll sum = 0; ll now = 1; ll prev = now; for (auto e : mp) { now = e.first; ans += min(sum, c) * (now - prev); rep(i, e.second.size()) sum += e.second[i]; prev = now; } cout << ans << endl; }
#include "bits/stdc++.h" using namespace std; /* find my code templates at https://github.com/galencolin/cp-templates also maybe subscribe please thanks */ #define send {ios_base::sync_with_stdio(false);} #define help {cin.tie(NULL);} #define f first #define s second #define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());} typedef long long ll; // typedef int ll; // #pragma warning("int") typedef long double lld; typedef unsigned long long ull; template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v); template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; } template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]"; } template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; } mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count()); // mt19937_64 rng(61378913); /* usage - just do rng() */ void usaco(string filename) { // #pragma message("be careful, freopen may be wrong") freopen((filename + ".in").c_str(), "r", stdin); freopen((filename + ".out").c_str(), "w", stdout); } // #include <atcoder/all> // using namespace atcoder; const lld pi = 3.14159265358979323846; // const ll mod = 1000000007; // const ll mod = 998244353; // ll mod; ll n, m, q, k, l, r, x, y, z; const ll template_array_size = 1e6 + 15258; ll a[template_array_size]; ll b[template_array_size]; ll c[template_array_size]; string s, t; void solve(int tc = 0) { ll ans = 1e10; cin >> n; for (ll i = 0; i < 62; i++) { ll v = (1LL << i); ans = min(ans, i + (n / v) + (n % v)); } cout << ans << '\n'; } int main() { #ifdef galen_colin_local auto begin = std::chrono::high_resolution_clock::now(); #endif send help #ifndef galen_colin_local // usaco("code"); #endif // usaco("cowland"); // freopen("tc.cpp", "r", stdin); // freopen("tc2.cpp", "w", stdout); cout << setprecision(15) << fixed; int tc = 1; // cin >> tc; for (int t = 0; t < tc; t++) solve(t); #ifdef galen_colin_local auto end = std::chrono::high_resolution_clock::now(); cerr << setprecision(4) << fixed; cerr << "Execution time: " << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() << " seconds" << endl; #endif }
#include<bits/stdc++.h> using namespace std; bool vis[12]; long long ans=1; int main(){ int n; cin>>n; for(int i=n-1;i>=n-11;i--){ ans*=i; for(int j=11;j>=2;j--){ if(ans%j==0 && !vis[j]){ vis[j]=true; ans/=j; } } } cout<<ans; return 0; }
#define _USE_MATH_DEFINES //#include <bits/stdc++.h> # include <iostream> # include <array> # include <string> # include <vector> # include <algorithm> # include <functional> # include <cmath> # include <iomanip> # include <stack> # include <queue> # include <numeric> # include <map> # include <set> # include <unordered_map> # include <unordered_set> # include <chrono> # include <random> # include <bitset> # include <cassert> # include <climits> template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } #define rep2(i,t,n) for (int i = (t); i < (int)(n); i++) #define rep(i,n) rep2(i,0,n) #define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} #define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} #define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} using namespace std; typedef long long ll; int t; ll n; int main() { cin >> t >> n; double cand = ((long double)n * 100 / t) + n; ll candL = (ll)cand; ll ans = candL; if(abs(cand - (long double)candL) < 0.000001L) { ans--; } cout << ans << endl; //printf("%10f", cand); return 0; }
#ifdef _DEBUG #define _GLIBCXX_DEBUG #endif #if __has_include(<atcoder/all>) #include <atcoder/all> #endif #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; #define rep(i, a, b) for(int i = (int)(a); i <= (int)(b); i++) #define rrep(i, a, b) for(int i = (int)(a); i >= (int)(b); i--) const int MOD = 1000000007; const int MOD2 = 998244353; const ll INF = 1e18; const ld PI = acos(-1); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; string S; cin >> S; vector<int> A(N+1); rep(i,0,N){ cin >> A[i]; } int diff=1e9; rep(i,0,N-1){ diff=min(diff,abs(A[i]-A[i+1])); } cout << diff << endl; rep(i,0,diff-1){ rep(j,0,N){ cout << A[j]/diff << (j==N?'\n':' '); A[j]++; } } }
#include<bits/stdc++.h> #define ll long long int #define endl "\n" using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll test; ll i, j, k, n, temp, count = 0, ans = 0, sum = 0; cin >> n; ll a[n], b[n]; for(i = 0; i < n; i++) { cin >> a[i]; } for(i = 0; i < n; i++) { cin >> b[i]; ans += a[i] * b[i]; } if(ans == 0) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int int main() { ll n; cin>>n; vector<ll> arr(n+1); ll m=0, c=-1; double e=0; for(ll i=0;i<=n;i++) { cin>>arr[i]; m+=abs(arr[i]); e+=(arr[i]*arr[i]); c=max(c, abs(arr[i])); } e=sqrt(e); cout<<m<<endl; cout<<setprecision(10)<<e<<endl; cout<<c<<endl; }
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; int main() { int x; cin >> x; cout << 100 - x % 100 << '\n'; return 0; }
#include<cstdio> #include<math.h> #include<algorithm> #include<vector> #include<queue> #include<string> #include<set> #include<cstring> #include<map> using namespace std; #define int long long int #define rep(i,n) for(int i=0;i<n;i++) #define INF 1001001001 #define LLINF 1001001001001001001 #define mp make_pair #define pb push_back #define mod 1000000007 //#define mod 998244353 int X; signed main(){ scanf("%lld",&X); int ans=(int)(X/100+1)*100-X; printf("%lld\n",ans); }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define all(a) (a).begin(),(a).end() #define endl "\n" void solve(int test) { ll n,m; cin>>n>>m; ll mod = 998244353; ll power[n+1]; power[0] = 1; ll i; for(i=1;i<=n;i++)power[i] = (1LL*power[i-1]*m)%mod; ll ans = (1LL*n*power[n])%mod; ll sub = 0; for(ll x=1;x<=m;x++) { ll curr = 1; ll r=m-x; for(ll diff = 1;diff<=n-1;diff++) { ll rem = n-diff-1; ll val = ((rem+1)*power[rem])%mod; val = (val*curr)%mod; sub = (sub + val)%mod; curr = (curr*r)%mod; } } ans = (ans -sub)%mod; if(ans<0)ans += mod; cout<<ans<<endl; } int main() { int t=1; //cin>>t; for(int x = t;x<=t;x++) solve(x); return 0; }
/*{{{*/ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<iostream> #include<sstream> #include<set> #include<map> #include<queue> #include<bitset> #include<vector> #include<limits.h> #include<assert.h> #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define FOR(I, A, B) for (int I = (A); I <= (B); ++I) #define FORS(I, S) for (int I = 0; S[I]; ++I) #define RS(X) scanf("%s", (X)) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++) #define MP make_pair #define PB emplace_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PII> VPII; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template<class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const int64_t &x) { printf("%lld", x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);} template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } #ifdef HOME #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);} #else #define DEBUG(...) #endif int MOD = 1e9+7; void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;} /*}}}*/ const int SIZE = 1<<20; const int COMBINATION_SIZE = 1<<21; LL pp[5001][5001]; int N,M; void pre() { pp[0][0]=1; FOR(i,1,5000){ pp[i][0]=1; FOR(j,1,5000){ pp[i][j]=(LL)pp[i][j-1]*i%MOD; } } } void solve() { LL an=0; FOR(i,1,N){ FOR(j,1,M){ if(j<M||(j==M&&i==1)){ ADD(an,pp[M-j][i-1]*(j-1)%MOD*(N-i)%MOD*pp[M][N-i-1]); ADD(an,pp[M-j][i-1]*pp[M][N-i]); } } } W(an); } void input() { R(N,M); } int main(){ MOD=998244353; pre(); input(); solve(); return 0; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; vector<ll> table; int main() { ll N, K; cin >> N >> K; table.resize(2 * N+1, 0); ll l = max(K + 2, 2ll), r = min(K + 2 * N, 2 * N); for (ll i = 2; i <= 2 * N; i++) { // a + b = iになる組み合わせ数をtableに格納する ll cnt = 0; cnt += min(N, i-1) - max(1ll, i - N) + 1; //cout << "i: " << i << " cnt: " << cnt << endl; table[i] = cnt; } ll cnt = 0; for (ll i = l; i <= r; i++) { cnt += table[i] * table[i - K]; } cout << cnt << endl; }
#include<bits/stdc++.h> using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; #define mod 1000000007 using ll=long long; const int INF=1000000000; const ll LINF=1001002003004005006ll; int dx[]={1,0,-1,0},dy[]={0,1,0,-1}; // ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;} template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;} struct IOSetup{ IOSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(12); } } iosetup; template<typename T> ostream &operator<<(ostream &os,const vector<T>&v){ for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" "); return os; } template<typename T> istream &operator>>(istream &is,vector<T>&v){ for(T &x:v)is>>x; return is; } template<typename Monoid> struct SegmentTree{ int sz; vector<Monoid> seg; Monoid M0;// モノイドの元 using F=function<Monoid(Monoid,Monoid)>; F f; SegmentTree(int n,Monoid M0,F f):M0(M0),f(f){ sz=1; while(sz<n)sz<<=1; seg.assign(2*sz,M0); } void set(int k,Monoid x){ seg[k+sz]=x; } void build(){ for(int k=sz-1;k>0;k--) seg[k]=f(seg[2*k],seg[2*k+1]); } void update(int k,Monoid x){ k+=sz; seg[k]=x; k>>=1; for(;k;k>>=1) seg[k]=f(seg[2*k],seg[2*k+1]); } Monoid query(int a,int b,int k=1,int l=0,int r=-1){ if(r==-1) r=sz; if(a<=l and r<=b) return seg[k]; if(b<=l or r<=a) return M0; Monoid L=query(a,b,2*k,l,(l+r)/2); Monoid R=query(a,b,2*k+1,(l+r)/2,r); return f(L,R); } }; signed main(){ int n;cin>>n; vector<int> a(n); cin>>a; SegmentTree<ll> seg(n,0ll,[](ll a,ll b){return a+b;}); ll inv=0; vector<int> v(n,0); rep(i,n){ ll x=seg.query(a[i],n); v[i]=x; inv+=x; seg.update(a[i],1); } cout<<inv<<endl; rep(i,n-1){ inv+=n-a[i]-1; inv-=a[i]; cout<<inv<<endl; } return 0; }
#include <iostream> using namespace std; void no() { cout << "-1" << endl; } int main() { int n; cin >> n; string s, t; cin >> s >> t; long long ans = 0; int i = 0, j = 0; while (j < n) { if (t[j] == '1') { while (i < n && s[i] == '0') i++; if (i == n) { no(); return 0; } if (i < j) { int i2 = i + 1; while (i2 < n && s[i2] == '0') i2++; if (i2 == n) { no(); return 0; } ans += i2 - i; i = i2 + 1; } else { ans += i - j; i++; j++; } } else { j++; } // cerr << i << ' ' << j << ' ' << ans << endl; } while (i < n) { if (s[i] == '0') { i++; } else { int k = i + 1; while (k < n && s[k] == '0') k++; if (k == n) { no(); return 0; } ans += k - i; i = k + 1; } // cerr << i << ' ' << j << ' ' << ans << endl; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; using LL=long long; using P=pair<int,int>; using T=tuple<int,int,int>; constexpr int mod=1000000007; constexpr int inf=1e9; constexpr double eps=1e-13; int in(){ int x; scanf("%d",&x); return x; } int main(){ int a=in(),b=in(),c=in(); int ans[10][4]={{0,0,0,0},{1,1,1,1},{6,2,4,8},{1,3,9,7},{6,4,6,4},{5,5,5,5},{6,6,6,6},{1,7,9,3},{6,8,4,2},{1,9,1,9}}; int mod4; if(b%4==0)mod4=0; if(b%4==1)mod4=1; if(b%4==2)mod4=(c==1 ? 2 : 0); if(b%4==3)mod4=(c%2 ? 3 : 1); cout<<ans[a%10][mod4]<<endl; return 0; }
// #pragma GCC target("avx") // CPU 処理並列化 // #pragma GCC optimize("O3") // CPU 処理並列化 // #pragma GCC optimize("unroll-loops") // 条件処理の呼び出しを減らす // #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024)); // #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_); #include<stdio.h> #include<math.h> #include<algorithm> #include<queue> #include<deque> #include<stack> #include<string> #include<string.h> #include<vector> #include<set> #include<map> #include<bitset> #include<stdlib.h> #include<cassert> #include<time.h> #include<bitset> #include<numeric> #include<unordered_set> #include<unordered_map> #include<complex> using namespace std; const long long mod=998244353; const long long inf=mod*mod; const long long d2=(mod+1)/2; const long double EPS=1e-15; const long double INF=1e+10; const double PI=acos(-1.0); const int C_SIZE = 11100000; const int UF_SIZE = 3100000; namespace{ long long fact[C_SIZE]; long long finv[C_SIZE]; long long inv[C_SIZE]; inline long long Comb(int a,int b){ if(a<b||b<0)return 0; return fact[a]*finv[b]%mod*finv[a-b]%mod; } void init_C(int n){ fact[0]=finv[0]=inv[1]=1; for(int i=2;i<n;i++){ inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod; } for(int i=1;i<n;i++){ fact[i]=fact[i-1]*i%mod; finv[i]=finv[i-1]*inv[i]%mod; } } long long pw(long long a,long long b){ if(a<0LL)return 0; if(b<0LL)return 0; long long ret=1; while(b){ if(b%2)ret=ret*a%mod; a=a*a%mod; b/=2; } return ret; } long long pw_mod(long long a,long long b,long long M){ if(a<0LL)return 0; if(b<0LL)return 0; long long ret=1; while(b){ if(b%2)ret=ret*a%M; a=a*a%M; b/=2; } return ret; } int pw_mod_int(int a,int b,int M){ if(a<0)return 0; if(b<0)return 0; int ret=1; while(b){ if(b%2)ret=(long long)ret*a%M; a=(long long)a*a%M; b/=2; } return ret; } int ABS(int a){return max(a,-a);} long long ABS(long long a){return max(a,-a);} double ABS(double a){return max(a,-a);} int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; } int UF[UF_SIZE]; void init_UF(int n){ for(int i=0;i<n;i++)UF[i]=-1; } int FIND(int a){ if(UF[a]<0)return a; return UF[a]=FIND(UF[a]); } void UNION(int a,int b){ a=FIND(a);b=FIND(b);if(a==b)return; if(UF[a]>UF[b])swap(a,b); UF[a]+=UF[b];UF[b]=a; } } // ここから編集しろ long long PW[5100][5100]; int main(){ for(int i=0;i<5100;i++){ long long cur=1; for(int j=0;j<5100;j++){ PW[i][j]=cur; cur=cur*i%mod; } } int a,b;scanf("%d%d",&a,&b); init_C(210000); long long ret=0; for(int i=1;i<a-1;i++){ for(int j=1;j<b;j++){ long long ks=2*j-1; ks=ks*PW[b-j][i]%mod; ks=ks*(a-i-1)%mod; ks=ks*PW[b][a-i-2]%mod; ret=(ret+ks)%mod; // printf("%d %d: %lld\n",i,j,ks); } } for(int i=1;i<a;i++){ for(int j=1;j<b;j++){ long long ks=2; ks=ks*PW[b-j][i]%mod; ks=ks*PW[b][a-i-1]%mod; ret=(ret+ks)%mod; // printf("%d %d: %lld\n",i,j,ks); } } ret=(ret+PW[b][a])%mod; printf("%lld\n",ret); }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < n; i++) #define Rep(i,n) for(int i = 1; i <= n; i++) #define sz(a) int(a.size()) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define debug(a) { cerr << #a << ": " << a << endl; } #define endl '\n' #define fi first #define se second using lint = long long; using P = pair<int,int>; template<class T> using V = vector<T>; template<class T> using priq = priority_queue<T>; template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>; const int dx[] = {0,1,0,-1,1,1,-1,-1}; const int dy[] = {1,0,-1,0,1,-1,-1,1}; template<class T> T ceil(const T &a, const T &b) { return (a+b-1)/b; } template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF; template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) { return in >> p.first >> p.second; } template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) { return out << p.first << ' ' << p.second; } template<class T> istream& operator>>(istream &in, vector<T> &v) { for(auto &&e: v) in >> e; return in; } template<class T> ostream& operator<<(ostream &out, const vector<T> &v) { for(const auto &e: v) out << e << ' '; return out; } /*----------------------------------------------------------------------------------------------------*/ const lint mod = 1e9+7; int main() { int n; cin >> n; V<int> a(n); cin >> a; a.push_back(0); sort(all(a)); lint ans = 1; Rep(i,n) { ans *= (a[i]-a[i-1]+1); ans %= mod; } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <cstdlib> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <vector> #define setIO(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout) #define closefile fclose(stdin), fclose(stdout) #define m_p make_pair #define sz(x) (int)x.size() #define see(x) cerr << x << " " #define seeln(x) cerr << x << endl #define out(x) cerr << #x << " = " << x << " " #define outln(x) cerr << #x << " = " << x << endl #define outarr(x, l, r) {cerr<< #x"[" << l << " ~ " << r << "] = "; for (int _i = l; _i <= r; ++_i) cerr << x[_i] << " "; cerr << endl;} using namespace std; typedef long long ll; typedef pair <int, int> pii; #define gc() getchar() //#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++) char buf[1 << 21], *p1 = buf, *p2 = buf; template <class T> void read(T &x) { x = 0; int c = gc(); int flag = 0; while (c < '0' || c > '9') flag |= (c == '-'), c = gc(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) +(c ^ 48), c = gc(); if (flag) x = -x; } template <class T> T _max(T a, T b){return b < a ? a : b;} template <class T> T _min(T a, T b){return a < b ? a : b;} template <class T> bool checkmax(T &a, T b){return a < b ? a = b, 1 : 0;} template <class T> bool checkmin(T &a, T b){return b < a ? a = b, 1 : 0;} int a, b, c; int qpow(int a, int b, int p) { int ans = 1; a%=p; while (b) { if (b & 1) ans = (ll)ans * a % p; a = (ll)a * a % p; b >>= 1; } return ans; } void init() { read(a); read(b); read(c); } void solve() { printf("%d\n", qpow(a, qpow(b, c, 4) + 4, 10)); } int main() { init(); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int pow(int a, int n, int m){ int ret = 1; while(n > 0){ if(n & 1) (ret *= a) %= m; (a *= a) %= m; n >>= 1; } return ret; } int main() { int a, b, c; cin >> a >> b >> c; cout << pow(a % 10, pow(b % 4, c, 4) + 4, 10) << endl; return 0; }
#include <bits/stdc++.h> #define LL long long #define pb push_back #define st first #define nd second #define INF 0x3f3f3f3f #define LINF 0x3f3f3f3f3f3f3f3f template <class T> T read(T &a) { a=0;char x=getchar();bool f=0; for(;x<'0'||x>'9';x=getchar())f|=x=='-'; for(;x>='0'&&x<='9';x=getchar())a=(a<<3)+(a<<1)+x-'0'; if(f)a=-a; return a; } using namespace std; LL MOD = 998244353; const int N = 55; int p[N]; LL d[N][N], cnt[N]; LL pre[N]; int find(int a) { return p[a] == a? a: p[a] = find(p[a]); } int main() { int n, m; read(n), read(m); pre[0] = 1; for (int i = 1; i <= 50; ++i) { pre[i] = pre[i - 1] * i % MOD; p[i] = i; } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { read(d[i][j]); } } for (int i = 1; i <= n; ++i) { for (int j = 2; j <= n; ++j) { bool ok = 1; for (int k = 1; k <= n; ++k) { if (d[i][k] + d[j][k] > m) { ok = 0; break; } } if (ok) { int a = find(i), b = find(j); p[a] = b; } } } LL x = 1; for (int i = 1; i <= n; ++i) { cnt[find(i)]++; } for (int i = 1; i <= n; ++i) { x = x * pre[cnt[i]] % MOD; } for (int i = 1; i <= n; ++i) { p[i] = i; } memset(cnt, 0, sizeof cnt); for (int i = 1; i <= n; ++i) { for (int j = 2; j <= n; ++j) { bool ok = 1; for (int k = 1; k <= n; ++k) { if (d[k][i] + d[k][j] > m) { ok = 0; break; } } if (ok) { int a = find(i), b = find(j); p[a] = b; } } } for (int i = 1; i <= n; ++i) { cnt[find(i)]++; } for (int i = 1; i <= n; ++i) { x = x * pre[cnt[i]] % MOD; } printf("%lld\n", x); return 0; }
#include <bits/stdc++.h> #define SIZE 200005 using namespace std; typedef long long int ll; typedef pair <int,int> P; struct BIT { int bit[SIZE]; void init() { memset(bit,0,sizeof(bit)); } void add(int k,int x) { k++; while(k<SIZE) { bit[k]+=x; k+=k&-k; } } int get(int k) { k++; int ret=0; while(k>0) { ret+=bit[k]; k-=k&-k; } return ret; } int get(int s,int t) { return get(t)-get(s-1); } int pos(int k) { int l=-1,r=SIZE; while(r-l>1) { int m=(l+r)/2; if(get(m)<k) l=m; else r=m; } return r; } }bit; vector <int> vec[SIZE]; bool zan[SIZE]; int main() { int n,m,k; scanf("%d %d %d",&n,&m,&k); int M=m; for(int i=0;i<k;i++) { int x,y; scanf("%d %d",&x,&y);x--,y--; vec[x].push_back(y); if(x==0) M=min(M,y); } bit.init(); for(int i=0;i<M;i++) { bit.add(i,1); zan[i]=true; } bool vert=true; ll ret=0; for(int i=0;i<n;i++) { int mn=m; for(int j=0;j<vec[i].size();j++) { if(vec[i][j]==0) vert=false; mn=min(mn,vec[i][j]); if(zan[vec[i][j]]) { bit.add(vec[i][j],-1); zan[vec[i][j]]=false; } } if(vert) { ret+=mn; ret+=bit.get(mn,m); } else ret+=bit.get(0,m); } printf("%lld\n",ret); }
#include <cstdio> #include <cmath> #include <iostream> #include <set> #include <algorithm> #include <vector> #include <map> #include <cassert> #include <string> #include <cstring> #include <queue> using namespace std; #define rep(i,a,b) for(int i = a; i < b; i++) #define S(x) scanf("%d",&x) #define S2(x,y) scanf("%d%d",&x,&y) #define P(x) printf("%d\n",x) #define all(v) v.begin(),v.end() #define FF first #define SS second #define pb push_back #define mp make_pair typedef long long int LL; typedef pair<int, int > pii; typedef vector<int > vi; const int mod = 1000000007; const int N = 101; LL A[N][N], B[N][N], C[N][N]; int G[N][N]; int X[N]; LL _pow(LL a, LL b) { if(!b) return 1; if(b == 1) return a; if(b == 2) return a * a % mod; if(b & 1) { return a * _pow(a,b-1) % mod; } return _pow(_pow(a,b/2),2); } int n; void solve(int k) { if(k == 0) { memset(B, 0, sizeof(B)); rep(i,0,n) B[i][i] = 1; return; } solve(k / 2); memset(C, 0, sizeof(C)); rep(i,0,n) { rep(j,0,n) { rep(k,0,n) { C[i][j] += B[i][k] * B[k][j]; C[i][j] %= mod; } } } memcpy(B, C, sizeof(C)); if(k & 1) { memset(C, 0, sizeof(C)); rep(i,0,n) { rep(j,0,n) { rep(k,0,n) { C[i][j] += B[i][k] * A[k][j]; C[i][j] %= mod; } } } memcpy(B, C, sizeof(C)); } } int main() { int m,k; scanf("%d%d%d",&n,&m,&k); rep(i,0,n) S(X[i]); rep(i,0,m) { int x,y; S2(x,y); x--; y--; G[x][y] = G[y][x] = 1; } int inv = _pow(2 * m, mod - 2); rep(i,0,n) { int cnt = m; rep(j,0,n) { if(G[i][j]) { cnt--; A[i][j]++; A[i][i]++; } } A[i][i] += 2 * cnt; rep(j,0,n) { A[i][j] = A[i][j] * inv % mod; } } solve(k); rep(i,0,n) { LL ans = 0; rep(j,0,n) { ans += B[i][j] * X[j]; ans %= mod; } P((int)ans); } return 0; }
#include<bits/stdc++.h> using namespace std; char s[200005]; int n,k; int f[200005][20]; int a[200005]; bool v[20]; const int mod=1e9+7; void add(int &x,int y){ x+=y; if(x>=mod)x-=mod; } int main(){ scanf("%s",s+1); n=strlen(s+1); for(int i=1;i<=n;i++){ if(s[i]>='0'&&s[i]<='9')a[i]=s[i]-'0'; else a[i]=s[i]-'A'+10; } f[1][1]=a[1]-1; int tot=0; for(int i=1;i<n;i++){ if(!v[a[i]]){ v[a[i]]=1; ++tot; } for(int j=1;j<=min(i,16);j++){ add(f[i+1][j],1ll*f[i][j]*j%mod); if(j<16)add(f[i+1][j+1],1ll*f[i][j]*(16-j)%mod); } for(int j=0;j<a[i+1];j++){ if(v[j])add(f[i+1][tot],1); else add(f[i+1][tot+1],1); } add(f[i+1][1],15); } if(!v[a[n]]){ v[a[n]]=1; tot++; } cin>>k; if(k==tot)add(f[n][k],1); cout<<f[n][k]; }
#pragma GCC diagnostic ignored "-Wunused-const-variable" #ifdef MAC #include <iostream> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <bitset> #include <random> #include <chrono> #include <complex> #include <algorithm> #include <utility> #include <functional> #include <cmath> #include <cstring> #include <cassert> #include <cstdio> #include <cstdlib> #include <ctime> #include <iomanip> #else #include <bits/stdc++.h> #endif using namespace std; #define mp make_pair #define pb push_back #define forn(i, n) for(int i = 0; i < (int)(n); ++i) #define for1(i, n) for(int i = 1; i < (int)(n); ++i) #define nfor(i, n) for(int i = int(n) - 1; i >= 0; --i) #define fore(i, l, r) for(int i = int(l); i < int(r); ++i) #define correct(x, y, n, m) (0 <= x && x < n && 0 <= y && y < m) #define all(x) (x).begin(), (x).end() #define fst first #define snd second #define endl "\n" typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; typedef long double ld; typedef tuple<int,int,int> iii; template<typename T> inline T abs(T a){ return ((a < 0) ? -a : a); } template<typename T> inline T sqr(T a){ return a * a; } template<class T> T gcd(T a, T b) { return a ? gcd (b % a, a) : b; } template<class T> T lcm(T a, T b) { return a / gcd (a, b) * b; } template<class T> T sign(T a) { return a > 0 ? 1 : (a < 0 ? -1 : 0); } string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void dbg() { cout << endl; } template <typename Head, typename... Tail> void dbg(Head H, Tail... T) { cout << " " << to_string(H); dbg(T...); } #ifdef DEBUG #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg(__VA_ARGS__) #else #define dbg(...) #endif void fastIO() { cin.sync_with_stdio(false); cin.tie(0); } template<typename T> vector<T> make_unique(vector<T> v) { sort(all(v)); return v.resize(unique(all(v)) - v.begin()); } int nxt() { int x; cin >> x; return x; } const int dx[4] = {0, 0, 1, -1}; const int dy[4] = {1, -1, 0, 0}; const int dxKn[8] = {-2, -1, 1, 2, 2, 1, -1, -2}; const int dyKn[8] = { 1, 2, 2, 1, -1, -2, -2, -1}; const int dxK[8] = {0, 0, 1, -1, 1, 1, -1, -1}; const int dyK[8] = {1, -1, 0, 0, 1, -1, 1, -1}; const int MOD = int(1e9) + 7; const int INF = int(1e9) + 100; const ll INF64 = 2e18; const ld PI = ld(3.1415926535897932384626433832795); const ld e = ld(2.7182818284590452353602874713527); const ld EPS = 1e-9; //############################# const int MAXN = 1000005; int n, m; // sizes vector<vector<int>> g; //graph, grid vector<vector<ll>> dp; int main() { fastIO(); dp = vector<vector<ll>>(300, vector<ll>(300, 0)); dp[1][1] = 1; for(int i = 2; i < 300; i++) { for(int j = 1; j <= i; j++) { dp[i][j] = dp[i-1][j] + dp[i-1][j-1]; } } // dbg(dp); int l = nxt(); // dbg(dp[13]); cout << dp[l][12] << endl; return 0; } /* RECALL CORNER CASES - e.g. n = 1, n = 0 WRITE SOME STUFF think first, always - 1. concretely 2. graphically 3. abstractly 4. algebraically */
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5+5; const ll INF = 1e16; vector<pair<int,pair<ll,ll>>> adj[N]; vector<ll> dist(N,INF); void djk(int src){ dist[src] = 0; priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq; pq.push({0,src}); while(!pq.empty()){ ll t = pq.top().first; int cur_node = pq.top().second; pq.pop(); if(dist[cur_node] != t) continue; for(int i = 0; i < (int)adj[cur_node].size();++i){ int next_node = adj[cur_node][i].first; ll next_t = adj[cur_node][i].second.first; ll k = adj[cur_node][i].second.second; ll leave_time = ((t+k-1)/k) * k; ll extra = max(0LL,leave_time - t); ll new_t = extra + t + next_t; if(dist[next_node] > new_t){ dist[next_node] = new_t; pq.push({dist[next_node],next_node}); } } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,m,x,y; cin >> n >> m >> x >> y; for(int i = 0 ; i < m;++i){ int a,b; ll t,k; cin >> a >> b >> t >> k; adj[a].push_back({b,{t,k}}); adj[b].push_back({a,{t,k}}); } djk(x); if(dist[y] == INF) dist[y] = -1; cout << dist[y] << "\n"; }
#include<bits/stdc++.h> using namespace std; using i64 = long long; using u64 = unsigned long long; struct debug { ~debug(){cerr << endl;} template<class c> debug& operator<<(c x) {cerr << x; return *this;} template<class c, class d> debug& operator<<(pair<c, d> x) {*this << "(" << x.first << ", " << x.second << ")"; return *this;} template<class c> debug& operator<<(vector<c> x) { *this << "["; int f = 0; for(auto it : x) { *this << (f?", ":""); *this << it; f = 1;} *this << "]"; return *this;} }; #define dbg(x) "[" << #x << ": " << x << "] " #define Wa() cerr << "[LINE: " << __LINE__ << "] -> "; debug() << #define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL) int main() { int n; scanf("%d", &n); vector<pair<int, int>> p; for(int i = 0; i < n; i++) { int x, y; scanf("%d%d", &x, &y); p.push_back({x, y}); } int ans = 0; for(int i = 0; i < n; i++) { for(int j = i+1; j < n; j++) { if(abs(p[i].second - p[j].second) <= abs(p[i].first - p[j].first)) ans++; } } printf("%d\n", ans); }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; using P = pair<int, int>; int main() { int n; cin >> n; pair<double, double> point[n]; rep(i, n) cin >> point[i].first >> point[i].second; int cnt = 0; for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) { double d = (point[j].second - point[i].second) / (point[j].first - point[i].first); if (abs(d) <= 1) cnt++; } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) begin(v),end(v) template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using pii = pair<int, int>; constexpr ll INF = 1ll<<30; constexpr ll longINF = 1ll<<60; constexpr ll MOD = 1000000007; constexpr bool debug = false; //---------------------------------// template<typename T> struct BinaryIndexedTree { using value_type = T; using const_reference = const value_type &; using F = std::function<value_type(const_reference, const_reference)>; using size_type = std::size_t; BinaryIndexedTree(size_type n, const F & f, const_reference id_elem) : n(n), f(f), id_elem(id_elem) { node.resize(n + 1, id_elem); } size_type size() const noexcept { return n; } void add(size_type i, const_reference x) { assert(i < size()); ++i; for (; i <= size(); i += i & -i) node[i] = f(node[i], x); } // [0, i) value_type sum(size_type i) const { assert(i <= size()); value_type res = id_elem; for (; i > 0; i -= i & -i) res = f(res, node[i]); return res; } // sum[0, r] <= x を満たす最小の r を返す (存在しなければ size()) size_type lower_bound(const_reference x) const { size_type res = 0; size_type s = id_elem, w = 1; while (w < size()) w <<= 1; for (; w > 0; w >>= 1) { if (res + w <= size()) { value_type cur = f(s, node[res + w]); if (cur < x) { res += w; s = cur; } } } return res; } private: size_type n; F f; value_type id_elem; std::vector<value_type> node; }; int main() { int N; cin >> N; vector<int> A(N); REP(i, N) scanf("%d", &A[i]); BinaryIndexedTree<int> bit(N, [](int a, int b) { return a + b; }, 0); ll ans = 0; REP(i, N) { ans += bit.sum(N) - bit.sum(A[i]); bit.add(A[i], 1); } REP(i, N) { printf("%lld\n", ans); if (i + 1 == N) break; ans -= bit.sum(A[i]); ans += bit.sum(N) - bit.sum(A[i] + 1); } }
#include <bits/stdc++.h> #define ll long long #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define deb(x) cout<<#x<<"="<<x<<endl; #define endl '\n' #define M 1000000007 #define int long long #define INF 1e18 #define N 1000005 using namespace std; vector<ll> bit, bit2; ll n; void update(ll x, ll v, vector<ll> &bitt) { while (x <= n) { bitt[x] += v; x += (x & (-x)); } } ll query(ll x, vector<ll> &bitt) { ll sum = 0; while (x > 0) { sum += bitt[x]; x -= (x & (-x)); } return sum; } void solve() { cin >> n; bit = vector<ll>(n + 2, 0); ll a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; a[i]++; } ll ans = 0; for (int i = n - 1; i >= 0; --i) { update(a[i], 1, bit); ans += query(a[i] - 1, bit); } for (int i = 0; i < n; ++i) { cout << ans << endl; ans -= a[i] - 1; ans += n - a[i]; } } int32_t main() { IOS ll T = 1; // cin >> T; for (ll i = 1; i <= T; ++i) { // cout<<"Case #"<<i<<": "; solve(); } return 0; }
// Created by ... #include <bits/stdc++.h> #define db1(x) cout<<#x<<"="<<x<<'\n' #define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n' #define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n' #define vll vector< ll > #define M 100000 #define MD 1000000007 #define pb push_back #define rep(i,a,b) for(ll i = a; i <= b; ++i) #define fo(i,a,b) for(int i = a; i<= b; ++i) #define pii pair<ll,ll> #define vec(a) vector<a > #define all(a) a.begin(),a.end() #define se second #define fi first #define inf 0xffffffff #define inchar getchar_unlocked #define outchar(x) putchar_unlocked(x) #define int long long #define endl '\n' #define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) using namespace std; using ll = long long; ll md=MD; ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;} ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);} ll Min(ll a,ll b){if(a<b)return a; return b;} ll Max(ll a,ll b){if(a>b)return a; return b;} int32_t main() { IOS; ll n,s,d; cin>>n>>s>>d; int x,y; rep(i,0,n-1){ cin>>x>>y; if(x<s && y>d){ cout<<"Yes"; return 0; } } cout<<"No"; cout<<'\n'; return 0; }
//fake_name #include<bits/stdc++.h> using namespace std ; #define int long long int #define F first #define S second int MOD = 998244353 ; int mod = 1e9 + 7 ; int inf = 1e18 ; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); signed main() { ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ; int n , s , d ; cin >> n >> s >> d ; int f = 0 ; for( int i = 0 ; i < n ; i++ ){ int x , y ; cin >> x >> y ; if( x < s && y > d ) f = 1 ; } if( f ) cout << "Yes\n" ; else cout << "No\n" ; cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n"; }
#include<algorithm> #include<bitset> #include<cmath> #include<complex> #include<deque> #include<functional> #include<iomanip> #include<iostream> #include<iterator> #include<map> #include<numeric> #include<queue> #include<set> #include<stack> #include<string> #include<unordered_map> #include<unordered_set> #include<utility> #include<vector> #include<chrono> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define FOR(i,x,n) for(int i=x; i<(n); i++) #define vint(a,n) vint a(n); rep(i, n) cin >> a[i]; #define vll(a,n) vll a(n); rep(i, n) cin >> a[i]; #define ALL(n) begin(n),end(n) #define RALL(n) rbegin(n),rend(n) #define MOD (1000000007) // #define MOD (998244353) #define INF (1e9+7) #define INFL (2e18) typedef long long ll; typedef unsigned int ui; typedef unsigned long long ull; using vint=vector<int>; using vll=vector<ll>; using vbool=vector<bool>; using P=pair<ll,ll>; template<class T>using arr=vector<vector<T>>; template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;} template<class T>void pl(T x){cout << x << " ";} template<class T>void pr(T x){cout << x << endl;} template <class T, class... Ts> inline void pr(T Tar, Ts... ts) { std::cout << Tar << " "; pr(ts...); return; } template<class T>void prvec(vector<T>& a){rep(i, (int)a.size()-1){pl(a[i]);} pr(a.back());} template<class T>void prarr(arr<T>& a){rep(i, (int)a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);} template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );} int main() { int n,m; cin >> n >> m; vint cnt(n+1, 0); vint(a, n); int ans = INF; rep(i, m){ cnt[a[i]]++; } rep(i, n+1){ if(cnt[i]==0) chmin(ans, i); } FOR(i, 1, n-m+1){ cnt[a[i-1]]--; cnt[a[i+m-1]]++; if(cnt[a[i-1]]==0) chmin(ans, a[i-1]); } pr(ans); return 0;}
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <set> #define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout) inline int read() { int data = 0, w = 1; char ch = getchar(); while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar(); if (ch == '-') w = -1, ch = getchar(); while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar(); return data * w; } const int N(1.5e6 + 10); std::set<int> s; int n, m, a[N], b[N], ans = 1e9; void Ins(int x) { if (!b[x]++) s.erase(x); } void Ers(int x) { if (!--b[x]) s.insert(x); } int main() { #ifndef ONLINE_JUDGE file(cpp); #endif n = read(), m = read(); for (int i = 1; i <= n; i++) a[i] = read(); for (int i = 0; i <= n; i++) s.insert(i); for (int i = 1; i <= m; i++) Ins(a[i]); ans = std::min(ans, *s.begin()); for (int i = m + 1; i <= n; i++) Ins(a[i]), Ers(a[i - m]), ans = std::min(ans, *s.begin()); printf("%d\n", ans); return 0; }
#include<bits/stdc++.h> #define ll long long #define F first #define S second #define pb push_back using namespace std; const ll maxn = 1e5 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll n = 0; cin >> n; ll c = 1; while ((c * (c + 1) / 2) < n) ++c; cout << c; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define All(a) (a).begin(),(a).end() #define INF 2e18 #define MOD 1000000007 // ビットをずらすときは1LLを使え // 有効桁のある小数を書く時はfixed + setorecisionを使え int main(){ ll n,ans; string s; cin >> s; cout << s[1] <<s[2]<<s[0]<< endl; /*for(ll i=0;i<n;i++){ cin >> ; }*/ //cout << ans << endl; return 0; }
#include <bits/extc++.h> #define all(x) (x).begin(),(x).end() #define sz(x) int(x.size()) using namespace std; using ll = long long; using pii = pair<int, int>; template<typename... T> void rd(T&... args) {((cin>>args), ...);} template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;} using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, N; cin>>n>>m>>N; vector<int> top(m, n), left(n, m); vector<vector<int>> blocks(n); for (int i=0; i<N; i++) { int x, y; cin>>x>>y; x--, y--; top[y]=min(top[y], x); left[x]=min(left[x], y); blocks[x].push_back(y); } ll ans=0; for (int i=0; i<left[0]; i++) { ans+=top[i]; } ordered_set<int> st; for (int i=left[0]; i<m; i++) st.insert(i); for (int i=1; i<top[0]; i++) { if(!st.empty()) ans+=st.order_of_key(left[i]); for (auto x:blocks[i]) st.insert(x); } cout<<ans; return 0; }
#include <bits/stdc++.h> #define ll long long #define forinc(i,a,b) for(int i=a;i<b;i++) #define fordec(i,a,b) for(int i=a;i>b;i--) using namespace std; class Bit{ public: vector<int> arr; int n; Bit(int n){ arr = vector<int>(n+1,0); this->n=n; } void update(int index,int val){ index+=1; for(int i=index;i<=n;i=i+(i&(-i))){ arr[i]+=val; } } int get(int index){ index+=1; int re = 0; for(int i=index;i>0;i=i-(i&(-i))){ re+=arr[i]; } return re; } }; int main(){ int H,M,W,x,y; ll re=0; cin>>H>>W>>M; vector<int> row(H,W),col(W,H); vector<vector<int>> ceil_block(H,vector<int>()); Bit tree(W); forinc(i,0,M){ cin>>x>>y; x--;y--; row[x]=min(row[x],y); col[y]=min(col[y],x); } // cout<<"here1"; forinc(i,0,row[0]){ re += (ll)col[i]; } forinc(i,0,row[0]){ if(col[i]<H)ceil_block[col[i]].push_back(i); } // cout<<"here"; for(int i=0;i<col[0];i++){ re+= (ll) tree.get(row[i]-1); re+= (ll)max(row[i]-row[0],0); for(auto j:ceil_block[i]){ tree.update(j,1); } } cout<<re; }
#include <bits/stdc++.h> using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vb=vector<bool>;using vvb=vector<vb>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>; #define all(v)(v).begin(),(v).end() #define rall(v)(v).rbegin(),(v).rend() // cin and cout of a vector template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;}; template<class T,enable_if_t<iterable<T>::value,int> =0>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;} template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;} // for loop #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define revv(i, a, b) for (int i = (int)(b-1); i >= (int)(a); i--) #define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--) #define rev1(i, n) for(int i = (int)(n); i > 0; i--) // #define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++) // #define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--) // #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) // #define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++) // Yes/no #define cho(n,a,b) cout<< ((n)?a:b)<<endl; void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");} #define pb push_back #define rsortv(v) sort((v).rbegin(), (v).rend()) #define sortv(v) sort((v).begin(), (v).end()) // max/min template<class T, class U>bool chmax(T&a,const U&b){bool x=a<b;x?a=b:b;return x;}template<class T, class U>bool chmin(T&a,const U&b){bool x=a>b;x?a=b:b;return x;} template<class T, class U>auto max(const T&a,const U&b){return a<b?b:a;}template<class T, class U>auto min(const T&a,const U&b){return a<b?a:b;} //======================================== //======================================== //======================================== template<class T>auto minv(const T&a){return *min_element(all(a));} template<class T>auto smod(T a, T b){a %= b; if (a < 0); a+= b; return a;} template<class T>auto maxv(const T&a){return *max_element(all(a));} template<class T>auto sumv(const T&a){ll sum = 0; for(auto x: a) sum+= x; return sum;} template<class T>void pr(const T&a){cout << a << endl;} template<class T>void pr_precise(const T&a){cout.precision(10); cout << fixed << a << endl;} int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // ll M = 1000000007; ll M = 998244353; // vvl A(h+1, vl(n+1,0)); void check(){ ll n; cin >> n; vi A(n, 0); string s; rep(i, n){ cin >> s; if (s[0] == 'O') A[i] = 1; } // pr(A); ll now = 1; ll mul = 2; rep(i, n){ if (A[i] == 1){ now += mul; } mul*= 2; } pr(now); } int main() { int cases = 1; // cin >> cases; rep(CASE, cases){ check(); // pr(A); } return 0; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t=1; // cin>>t; while(t--){ long long n; cin>>n; string s; long long a[n]={0}; for(long long i=0;i<n;i++){ cin>>s; if(s=="AND") a[i]=1; else a[i]=0; } long long ans=1; long long two=2; for(int i=0;i<n;i++){ if(a[i]==0){ ans+=two; } two*=2; } cout<<ans; cout<<endl; } }
// D - Happy Birthday! 2 #include <bits/stdc++.h> using namespace std; using vi = vector<int>; #define rep(i,e) for(int i=0;i<(e);++i) void print(int n, vi v){ cout<< n <<" "; rep(i, n) cout<< v[i] << (i<n-1? " ":"\n"); } int main(){ int n; cin>>n; vi A(n); for(int&x:A) cin>>x; vector<vi> B(200); for(int d=min(8, n), bit=1; bit<1<<d; ++bit){ // 8bit: 2^8=256 int64_t r = 0; vi C; rep(i, d) if(bit>>i & 1) r += A[i], C.push_back(i+1); r %= 200; if(B[r].size()){ puts("Yes"); print(B[r].size(), B[r]); print(C.size(), C); return 0; } B[r] = C; } puts("No"); }
// KNOW NOTHING! #include <bits/stdc++.h> #define ll long long int #define F(i,j,k,in) for(int i=j;i<k;i+=in) #define DF(i,j,k,in) for(int i=j;i>=k;i-=in) #define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it) #define fall(a) a.begin(),a.end() #define sz(x) (int)x.size() #define szs(x) (int)x.length() #define pb push_back #define ub upper_bound #define lb lower_bound #define eq equal_range #define fs first #define ss second #define ins insert #define mkp make_pair #define endl "\n" using namespace std; typedef vector<ll> vll; typedef vector<int> vin; typedef vector<char> vch; typedef vector<string> vst; typedef set<ll> sll; typedef set<int> sint; typedef set<char> sch; typedef set<string> sst; typedef queue<ll> qll; typedef queue<int> qin; typedef deque<ll> dqll; typedef deque<int> dqint; typedef priority_queue<ll> pqll; typedef priority_queue<int> pqin; typedef map<ll,ll> mpll; typedef map<int,int> mpin; typedef pair<ll,ll> pll; typedef pair<int,int> pin; const ll MOD=1000000007; const long double PI=3.1415926535897932384626433832795; ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;} ll mpwr(ll b,ll p){ll res=1;while(p){if(p&1) {res=(res*b)%MOD; p--;}else{b=(b*b)%MOD; p>>=1;}}return res;} int msb (int n) {return 31-__builtin_clz(n);} ll msbl (ll n) {return 63-__builtin_clzll(n);} int lsb (int n) {return __builtin_ctz(n);} ll lsbl (ll n) {return __builtin_ctzll(n);} int setbit (int n) {return __builtin_popcount(n);} ll setbitl (ll n) {return __builtin_popcountll(n);} int main() { /* freopen ("input.txt","r","stdin"); freopen ("output.txt","w","stdout"); */ ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL); int n; cin>>n; vll a (n); F (i,0,n,1) cin>>a[i]; int m = min (10,n); int ok =0; F (i,1,1<<m,1) { F (j,1,1<<m,1) { if (i!=j) { ll s1 = 0, s2=0; vin a1 , a2; F (k,0,m,1) { if (i&(1<<k)) { s1+=a[k]; a1.pb (k); } if (j&(1<<k)) { s2+=a[k]; a2.pb (k); } } if (s1%200 == s2%200) { ok =1; cout<<"YES"<<endl; cout<<sz(a1)<<" "; for (auto e : a1) cout<<e+1<<" "; cout<<endl<<sz(a2)<<" "; for (auto e : a2) cout <<e+1<<" "; ok=1; break; } } } if (ok) break; } if (!ok) cout<<"NO"; return 0; } /* What we know is a drop , but what we don't know is an ocean !*/
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define all(v) v.begin(), v.end() template<class in_chmax> void chmax(in_chmax &x, in_chmax y) {x = max(x,y);} template<class in_chmin> void chmin(in_chmin &x, in_chmin y) {x = min(x,y);} void Yes() {cout << "Yes" << endl; exit(0);} void No() {cout << "No" << endl; exit(0);} template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);} template<class in_vec_cout> void vec_cout(vector<in_vec_cout> vec) { for (in_vec_cout res : vec) {cout << res << " ";} cout << endl; } const ll inf = 1e18; const ll mod = 1e9 + 7; struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 vector<ll> siz; vector<map<ll,ll>> cnt; UnionFind(ll N) : par(N), siz(N,1LL), cnt(N) { //最初は全てが根であるとして初期化 for(ll i = 0; i < N; i++) par[i] = i; } ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } ll size(ll x) { // xが属する木のサイズを返す ll rx = root(x); return siz[rx]; } void unite(ll x, ll y) { // xとyの木を併合 ll rx = root(x); //xの根をrx ll ry = root(y); //yの根をry if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま if (siz[rx]<siz[ry]) swap(rx,ry); // sizeが大きいほうをx,小さいほうをyとする。 siz[rx] += siz[ry]; // サイズの変更 //xとyの根が同じでない(=同じ木にない)時:yの根ryをxの根rxにつける(siz[rx]>=siz[ry]) par[ry] = rx; for (auto p : cnt[ry]) cnt[rx][p.first] += p.second; cnt[ry].clear(); } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; int main() { ll N, Q; cin >> N >> Q; UnionFind uf(N); rep(i,N) { ll c; cin >> c; c--; uf.cnt[i][c]++; } vector<ll> res; rep(q,Q) { ll t; cin >> t; ll x, y; cin >> x >> y; x--; y--; if (t==1) { uf.unite(x,y); } else { x = uf.root(x); res.push_back(uf.cnt[x][y]); } } for (ll ans : res) cout << ans << endl; }
#include <map> #include <set> #include <list> #include <cmath> #include <deque> #include <stack> #include <queue> #include <array> #include <bitset> #include <cstdio> #include <string> #include <vector> #include <random> #include <chrono> #include <utility> #include <numeric> #include <cstdlib> #include <cstring> #include <climits> #include <sstream> #include <assert.h> #include <iostream> #include <iomanip> #include <algorithm> #include <functional> #include <unordered_map> using namespace std; struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _; vector<map<int, int>> freq; vector<array<int, 3>> query; vector<int> c, sze, req, parent; int find_parent(int v) { if (v == parent[v]) return v; return parent[v] = find_parent(parent[v]); } void union_set(int a, int b) { a = find_parent(a); b = find_parent(b); if (a != b) { if (sze[a] < sze[b]) swap(a, b); parent[b] = a; sze[a] += sze[b]; for (auto [num, cnt] : freq[b]) if (req[num]) freq[a][num] += cnt; } return; } int main() { int n, q; cin >> n >> q; c.resize(n + 1, 0); for (int i = 1; i <= n; i++) cin >> c[i]; freq.resize(n + 1); sze.resize(n + 1, 1); parent.resize(n + 1, 0); req.resize(n + 1, 0); query.resize(q); for (int i = 0; i <= q - 1; i++) { cin >> query[i][0] >> query[i][1] >> query[i][2]; if (query[i][0] == 2) { req[query[i][2]]++; } } for (int i = 1; i <= n; i++) { parent[i] = i; if (req[c[i]]) freq[i][c[i]]++; } for (int i = 0; i <= q - 1; i++) { if (query[i][0] == 1) union_set(query[i][1], query[i][2]); else { cout << freq[find_parent(query[i][1])][query[i][2]] << "\n"; req[query[i][2]]--; } } return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- template<int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) { } ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } bool operator==(ModInt that) const { return x == that.x; } bool operator!=(ModInt that) const { return x != that.x; } ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; } }; template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; }; template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) { ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; } typedef ModInt<1000000007> mint; /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan0     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N; vector<pair<int, ll>> E[201010]; ll xo[201010]; //--------------------------------------------------------------------------------------------------- void dfs(int cu, int pa, ll x) { xo[cu] = x; fore(p, E[cu]) if (pa != p.first) dfs(p.first, cu, x ^ p.second); } //--------------------------------------------------------------------------------------------------- void _main() { cin >> N; rep(i, 0, N - 1) { int a, b; ll c; cin >> a >> b >> c; a--; b--; E[a].push_back({ b, c }); E[b].push_back({ a, c }); } dfs(0, -1, 0); mint ans = 0; rep(bit, 0, 60) { ll msk = 1LL << bit; ll cnt[2] = { 0, 0 }; rep(i, 0, N) cnt[(xo[i] & msk) != 0]++; ans += mint(msk) * mint(cnt[0]) * mint(cnt[1]); } cout << ans << endl; }
// Problem: E - Xor Distances // Contest: AtCoder - Mynavi Programming Contest 2021(AtCoder Beginner Contest 201) // URL: https://atcoder.jp/contests/abc201/tasks/abc201_e // Memory Limit: 1024 MB // Time Limit: 3000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> #define XOX #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; #define int long long #define re return #define beg() begin() #define cont continue #define ldb long double #define db double #define br break #define fr first #define se second #define lb lower_bound #define ub upper_bound #define pb push_back #define mkp make_pair #define pi pair<int,int> #define pll pair<ll,ll> #define pdb pair<db,db> #define pldb pair<ldb,ldb> #define vi vector<int> #define vll vector<ll> #define vdb vector<db> #define vldb vector<ldb> #define vpi vector< pi > #define vpll vector< pll > #define mi map<int,int> #define mdb map<db,db> #define mldb map<ldb,ldb> #define si set<int> #define sdb set<db> #define sldb set<ldb> #define test int t; cin>>t; while(t--) #define scan() int n; cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i] #define scan2() int n,k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++) cin>>a[i] #define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<' ' #define mem(a,v) memset(a,v,sizeof(a)) #define srt(v) sort(v.begin(),v.end()) #define rev(s) reverse(s.begin(),s.end()) #define cn(x) cout<<x<<"\n" #define cs(x) cout<<x<<" " #define c(x) cout<<x #define all(v) v.begin(),v.end() #define forr(i,a,b) for (int i = (a); i < (b); ++i) #define rrof(i,a,b) for (int i = (b)-1; i >= (a); --i) const int MOD = 1e9+7; const ldb PI = 4*atan((ldb)1); const int INF = 1e18; const int NINF = -1e18; int get_hash(string s){ int N=1000001; int base[N],A=11,MD=1110111110111; base[0]=1; forr(i,1,N) base[i]=(base[i-1]*A)%MD; int hs=0; forr(i,0,s.size()){ hs+=(s[i]*base[i]); hs%=MD; } re hs; } int power(int a,int n){ int res=1; while(n){ if(n%2) res*=a; a*=a; n/=2; } return res; } vector<string> vec_splitter(string s) { s += ','; vector<string> res; while(!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out( vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx, __attribute__ ((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #ifdef XOX #define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) #else #define debug(...) 42 #endif int root=1; vector<int>dist; vector<vector<pair<int,int>>>v; vector<bool>bl; void dfs(){ queue<int>q; q.push(root); while(!q.empty()){ int x=q.front(); bl[x]=1; q.pop(); for(int i=0;i<v[x].size();i++){ if(bl[v[x][i].first]==0){ dist[v[x][i].first]=dist[x]^v[x][i].second; q.push(v[x][i].first); } } } return; } int32_t main(){ fast; int n; cin>>n; v.resize(n+1); for(int i=0;i<n-1;i++){ int x,y,z; cin>>x>>y>>z; v[x].push_back({y,z}); v[y].push_back({x,z}); } dist.resize(n+1,0); bl.resize(n+1,0); dfs(); int x=1; int ans=0; for(int i=0;i<=60;i++){ int cnt1=0,cnt0=0; for(int j=1;j<=n;j++){ if(dist[j]%2==1) cnt1++; else cnt0++; dist[j]/=2; } ans=(ans%MOD+(cnt1%MOD*cnt0%MOD)%MOD*(x%MOD))%MOD; x*=2; } cout<<ans; re 0; }
#include <iostream> #include <vector> #include<iomanip> #include<functional> #include<algorithm> #include<deque> #include<math.h> #include<set> #include<cstdio> #include<string> #include<queue> #include<complex> #include<numeric> #include<stack> #include<unordered_map> #include<map> using namespace std; #define rep(i,n) for(ll i = 0;i<n;i++) #define req(i,n) for(ll i = 1;i<=n;i++) #define rrep(i,n) for(int i = n-1;i>=0;i--) #define ALL(a) a.begin(),a.end() template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } typedef long long ll; typedef long double ld; const int MOD = 1e9 + 7; int main() { int n; cin >> n; vector<set<int>> v(n + 1); vector<int> a(n+1,0); int cnt; req(i, n) { cnt = 1; if (v[i].size() == 0) { a[i] = cnt; } else { for (int j : v[i]) { if (j == cnt) cnt++; else { a[i] = cnt; break; } }if (a[i] == 0) a[i] = cnt; }for (int j = i; j <= n; j += i) { v[j].insert(cnt); } }req(i,n) cout << a[i] << " "; cout << 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; int x = 0, y = 0; cin>>N; int X = N; int Y = N * 1.618033988749894848204586834365; Y = max(1ll, Y-10000); int mini = INF; for(int j = 0; ; j++){ x = X; y = Y+j; int con = 0; for(;;){ // cout<<x<<" "<<y<<endl; con++; // string s; // cin>>s; if(x > y) x -= y; else y -= x; if(!x || !y) { con += x + y; break; } if(con >= 140) break; } if(con <= 130) { x = X; y = Y+j; vector<int> ans; for(;;){ con++; if(x > y) { x -= y; ans.push_back(3); } else { ans.push_back(4); y -= x; } if(!x || !y) { // con += x + y; if(x == 0) { for(int i = 0; i < y; i++){ ans.push_back(2); } } else { for(int i = 0; i < x; i++){ ans.push_back(1); } } break; } } cout<<ans.size()<<endl; for(int i = 0; i < ans.size(); i++){ cout<<ans[ans.size()-i-1]<<endl; } return 0; } } // cout<<"mini = "<<mini<<endl; return 0; }
#include <iostream> #include <cstdlib> #include <cstdio> #include <bits/stdc++.h> using namespace std; #define REP(i,n) for(ll i=0; i<(ll)n; i++) #define INF 1e9 typedef long long ll; const ll MAXN=17; ll n; ll d[MAXN][MAXN]; ll dp[1<<MAXN][MAXN]; ll rec(ll S, ll v) { if(dp[S][v] >= 0) return dp[S][v]; if(S==(1<<n)-1 && v==0) return dp[S][v]=0; ll tmp=INF; REP(u,n) if(!(S>>u & 1)) tmp=min(tmp, rec(S|1<<u,u)+d[v][u]); return dp[S][v]=tmp; } int main() { cin >> n ; ll m = n*n; vector<ll> x(n); vector<ll> y(n); vector<ll> z(n); for(ll i = 0; i < n; i++) { cin >> x.at(i) >> y.at(i) >> z.at(i); x.at(i)--; y.at(i)--; z.at(i)--; } REP(i,n) REP(j,n) d[i][j]=d[j][i]=INF; for(ll i = 0; i < n; i++) { for(ll j = 0; j < n; j++) { if(i != j) { ll a, b, c; a = i; b = j; d[a][b]=abs(x.at(i) - x.at(j)) + abs(y.at(i) - y.at(j)) + max((ll)0, z.at(j) - z.at(i)); } } } fill((ll *)dp, (ll *)(dp+(1<<MAXN)), -1); cout << rec(0,0) << endl; return 0; }
#include <iostream> #include <vector> #include <map> #include <set> #include <queue> #include <algorithm> #include <string> #include <cmath> #include <cstdio> #include <iomanip> #include <fstream> #include <cassert> #include <cstring> #include <unordered_set> #include <unordered_map> #include <numeric> #include <ctime> #include <bitset> #include <complex> #include <chrono> #include <random> #include <functional> using namespace std; const int INF = 1e9 + 239; const int N = 501; int a[N][N]; int b[N]; int c[N]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } } int mn = INF; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { mn = min(mn, a[i][j]); } } int any = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (a[i][j] == mn && !any) { any = 1; for (int nj = 0; nj < n; nj++) { b[nj] = 0; c[nj] = a[i][nj]; } } } } for (int i = 0; i < n; i++) { b[i] = a[i][0] - c[0]; } int ok = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ok &= (a[i][j] == b[i] + c[j]); } ok &= (b[i] >= 0); ok &= (c[i] >= 0); } if (ok) { cout << "Yes\n"; for (int i = 0; i < n; i++) { cout << b[i] << ' '; } cout << '\n'; for (int i = 0; i < n; i++) { cout << c[i] << ' '; } cout << '\n'; } else { cout << "No\n"; } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace std; using namespace __gnu_pbds; template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #ifdef LOCAL #define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) #else #define debug(...) ; #endif vector<string> vec_splitter(string s) { s += ','; vector<string> res; while (!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out( vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx, __attribute__ ((unused)) int LINE_NUM) { cerr << endl; } template<typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if (idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } typedef long long ll; typedef long double ld; #define rep(i, start, end) for(int i = start; i < end; ++i) #define sz(x) (int)((x).size()) #define pb push_back #define all(x) x.begin(), x.end() #define clr(d, v) memset(d, v, sizeof(d)) #define pii pair<int, int> #define X first #define Y second //#define debug(x) cerr << #x << " : " << (x) << " " const long double PI = 3.14159265358979323846; const long double eps = (1e-15); //enum //{ // LESS, EQUAL, GREATER //}; //int dcmp(ld x, ld y, ld EPS = eps) //{ // if (fabs(x - y) <= EPS) // return EQUAL; // return x > y ? GREATER : LESS; //} const int MOD = 1e9 + 7; int add(int x, int y) { x += y; if (x >= MOD) x -= MOD; return x; } int mult(int x, int y) { return (1LL * x * y)%MOD; } int f(int n) { if (n == 0) return 1; if (n == 1) return 2; if (n == 2) return 3; int a = 2, b = 3; // f(1), f(2) for (int i = 3; i <= n; ++i) { int newA = b, newB = add(a, b); a = newA; b = newB; } return b; } int pwr(int base, int exp) { int ret = 1; for (; exp; exp >>= 1, base = mult(base, base)) if (exp&1) ret = mult(ret, base); return ret; } void myMain() { int n; cin >> n; int c[2][2]; rep(i,0,2) { rep(j, 0, 2) { char t; cin >> t; c[i][j] = t - 'A'; } } if (n == 2) { cout << 1; return; } if (c[0][1] == 0) { if (c[0][0] == 0) cout << 1; else { if (c[1][0] == 0) cout << f(n - 3); else cout << pwr(2, n - 3); } } else { if (c[1][1] == 1) cout << 1; else { if (c[1][0] == 1) cout << f(n - 3); else cout << pwr(2, n - 3); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int tc = 1; // cin >> tc; while(tc--) myMain(); }
#define _USE_MATH_DEFINES #include <iostream> #include <sstream> #include <string> #include <list> #include <vector> #include <queue> #include <algorithm> #include <climits> #include <cstring> #include <cmath> #include <stack> #include <iomanip> #include <tuple> #include <functional> #include <cfloat> #include <map> #include <set> #include <array> #include <stdio.h> #include <string.h> #include <random> #include <cassert> using ll = long long; using ull = unsigned long long; using uint = unsigned int; using namespace std; #define int long long #define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end()) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ARY_SORT(a, size) sort((a), (a)+(size)) #define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end())) #define REVERSE(v) (reverse((v).begin(), (v).end())) #define ARY_REVERSE(v,a) (reverse((v), (v)+(a))) #define REP(i, n) for (int (i)=0; (i) < (n); (i)++) #define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++) #define CONTAINS_MAP(m, a) ((m).find((a)) != m.end()) #define CONTAINS_SET(m, a) ((m).find((a)) != m.end()) void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } //---------- 1000000007 ---------- const int MOD = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) :x((x% MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(MOD - 2); } mint& operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream& operator>>(istream& is, mint& a) { return is >> a.x; } ostream& operator<<(ostream& os, const mint& a) { return os << a.x; } signed main() { int N, P; cin >> N >> P; mint p = P - 2; mint a = p.pow(N - 1); mint ans = a * (P - 1); cout << ans << endl; }
#include "bits/stdc++.h" using namespace std; //#include "testlib.h" #define ff first #define ss second #define all(v) v.begin(),v.end() #define int long long #define ll long long #define M 1000000007 #define MM 998244353 #define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i] #define GCD(m,n) __gcd(m,n) #define LCM(m,n) m*(n/GCD(m,n)) #define mii map<ll ,ll > #define msi map<string,ll > #define rep(a,b) for(ll i=a;i<b;i++) #define rep0(n) for(ll i=0;i<n;i++) #define repi(i,a,b) for(ll i=a;i<b;i++) #define pb push_back #define vi vector<ll> #define vs vector<string> #define ppb pop_back #define endl '\n' #define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define r0 return 0; #define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i) #define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout); #define Set(a, s) (a, s, sizeof (a)) #define FOR repi #define vii vector<pii> #define pii pair<int,int> #define REVERSE(v) reverse(all(v)) #define trav(a, x) for(auto& a : x) #define display(x) trav(a,x) cout<<a<<" ";cout<<endl #define debug cerr<<"bhau"<<endl #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ std::cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } template<typename T, typename U> static inline void amin(T &x, U y) { if (y < x) x = y; } template<typename T, typename U> static inline void amax(T &x, U y) { if (x < y) x = y; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; ll max(ll a, ll b) { return (a > b)? a : b;} int min(int a, int b) { return (a < b)? a : b;} int solve(){ string s; cin>>s; for(int i=0;i<s.size();i++){ if(i%2==0){ if(s[i]>'z' || s[i]<'a') return cout<<"No"<<endl,0; } else { // if(s[i]>) if(s[i]>'Z' || s[i]<'A') return cout<<"No"<<endl,0; } } cout<<"Yes"; return 0; } signed main(){ asdf int t=1; // cin>>t; while(t--){ solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; //#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 //#define rep(i, n) for (int i = 0; i < (int)(n); i++) //template<typename T1,typename T2>istream& opertor>>(istream& in,pair<T1,T2> &a){in>>a.fr>> //template<typename T1,typename T2>istream& opertor<<(ostream& out,pair<T1,T2> a){out<<a.fr<< 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; int main() { string S; cin >> S; string ans = "Yes"; rep(i,0,S.size()){ if(i%2==0){ if(isupper(S.at(i))){ ans = "No"; break; } }else if((i%2==1)){ if(islower(S.at(i))){ ans = "No"; break; } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const double pi = acos(-1); const double eps = 1e-8; const ll mod = 1e9 + 7; const ull base = 131; const ull mod1 = 1e9 + 9; const ull mod2 = 1610612741; const int maxn = 2e3 + 10; int h, w; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; char p[maxn][maxn]; bool vis[maxn][maxn]; vector<pair<int, int> > v[30]; struct node { int x, y, step; node(int a, int b, int c):x(a), y(b), step(c) {} }; bool vis1[30]; int main() { scanf("%d%d", &h, &w); for (int i = 1; i <= h; ++i) scanf("%s", p[i]+1); int x, y, s, t; for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j) if (p[i][j] == 'S') x = i, y = j; else if (p[i][j] >= 'a' && p[i][j] <= 'z') v[p[i][j]-'a'].push_back(make_pair(i, j)); else if (p[i][j] == 'G') s = i, t = j; queue<node> q; q.push(node(x, y, 0)); vis[x][y] = 1; while (!q.empty()) { int x = q.front().x; int y = q.front().y; int step = q.front().step; q.pop(); // if (vis[x][y]) continue; // vis[x][y] = 1; if (x == s && y == t) { printf("%d\n", step); return 0; } for (int i = 0; i < 4; ++i) { int nx = x+dx[i]; int ny = y+dy[i]; if (nx < 1 || nx > h) continue; if (ny < 1 || ny > w) continue; if (!vis[nx][ny] && p[nx][ny] != '#') q.push(node(nx, ny, step+1)), vis[nx][ny] = 1; } if (p[x][y] >= 'a' && p[x][y] <= 'z') { if (vis1[p[x][y]-'a']) continue; vis1[p[x][y]-'a'] = 1; for (int i = 0; i < v[p[x][y]-'a'].size(); ++i) { int nx = v[p[x][y]-'a'][i].first; int ny = v[p[x][y]-'a'][i].second; if (!vis[nx][ny]) q.push(node(nx, ny, step+1)), vis[nx][ny] = 1; } } } printf("-1\n"); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i=0; i<(n); ++i) #define RREP(i, n) for(int i=(n);i>=0;--i) #define FOR(i, a, n) for (int i=(a); i<(n); ++i) #define RFOR(i, a, b) for(int i=(a);i>=(b);--i) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define DUMP(x) cerr<<#x<<" = "<<(x)<<endl #define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl; template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { REP(i, SZ(v)) { if (i) os << " "; os << v[i]; } return os; } template <class T> void debug(const vector<T> &v) { cout << "["; REP(i, SZ(v)) { if(i) cout << ", "; cout << v[i]; } cout << "]" << endl; } template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.first << " " << p.second; } template <class T, class U> void debug(const pair<T, U> &p) { cout << "(" << p.first << " " << p.second << ")" << endl; } template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vi>; using vvll = vector<vll>; const ll MOD = 1e9 + 7; const int INF = INT_MAX; const ll LINF = LLONG_MAX; const int inf = INT_MIN; const ll linf = LLONG_MIN; const ld eps = 1e-9; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); int h, w; cin >> h >> w; vector<string> s(h); P st, gl; REP(i, h) { cin >> s[i]; REP(j, w) { if(s[i][j] == 'S') st = {i, j}; if(s[i][j] == 'G') gl = {i, j}; } } vector<vector<P>> g(h*w+26); int dr[4] = {-1, 1, 0, 0}; int dc[4] = {0, 0, -1, 1}; REP(i, h) { REP(j, w) { REP(k, 4) { int nr = i + dr[k], nc = j + dc[k]; if(!(0 <= nr && nr < h && 0 <= nc && nc < w) || s[nr][nc] == '#') { continue; } g[i*w+j].emplace_back(nr*w+nc, 2); } } } REP(i, h) { REP(j, w) { if('a' <= s[i][j] && s[i][j] <= 'z') { int tel = h * w + s[i][j] - 'a'; g[i*w+j].emplace_back(tel, 1); g[tel].emplace_back(i*w+j, 1); } } } vi d(h*w+26, INF); d[st.first*w+st.second] = 0; priority_queue<P, vector<P>, greater<P>> pq; pq.push({0, st.first*w+st.second}); while(!pq.empty()) { auto [nowd, now] = pq.top(); pq.pop(); if(d[now] < nowd) continue; for(auto &[to, cost]: g[now]) { if(d[to] > nowd + cost) { d[to] = nowd + cost; pq.push({d[to], to}); } } } int val = d[gl.first*w + gl.second]; if(val == INF) { cout << -1 << endl; } else { cout << val/2 << endl; } return 0; }
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h> #include <algorithm> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #include <bits/stdc++.h> using namespace std; const double TL = 1.5 * CLOCKS_PER_SEC; mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count()); #define clr(x, y) memset(x, y, sizeof(x)) #define forn(i, n) for (int i = 0; i < n; i++) #define LL long long const double pi = acos(-1.0); int n; LL y, x[100]; map<pair<LL, LL>, LL> mp; LL dfs(int i, LL y) { if (mp.find({i, y}) != mp.end()) { return mp[{i, y}]; } LL g = y / x[i]; if (y % x[i] == 0) { if (i == n - 1 || g < x[i + 1] / x[i]) { mp[{i, y}] = 1; } else { mp[{i, y}] = 0; } return mp[{i, y}]; } else { LL yl = g * x[i]; LL yr = (g + 1) * x[i]; LL t = 0; if (i == n - 1 || g < x[i + 1] / x[i]) { t += dfs(i - 1, abs(y - yl)); } if (i == n - 1 || g + 1 < x[i + 1] / x[i]) { t += dfs(i - 1, abs(y - yr)); } mp[{i, y}] = t; } return mp[{i, y}]; } int main() { #ifdef LOCAL auto start_clock = clock(); freopen("in", "r", stdin); #endif scanf("%d", &n); cin >> y; for (int i = 0; i < n; i++) { cin >> x[i]; } LL ans = dfs(n - 1, y); cout << ans << endl; #ifdef LOCAL auto end_clock = clock(); cout << "Time:" << (end_clock - start_clock) * 1.0 / CLOCKS_PER_SEC << endl; #endif return 0; }
#include <bits/stdc++.h> #define TRACE(x) cerr << #x << " = " << x << endl #define pb push_back #define mp make_pair #define fi first #define se second #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define SZ(x) (int)(x).size() using namespace std; typedef long long ll; typedef double lf; typedef pair<int, int> pii; typedef vector<int> VI; template<class Num> Num mabs(Num A){ if(A < 0) return -A; return A; } int main(){ int n; ll x; scanf("%d %lld", &n, &x); vector<ll> coin(n); REP(i, n) scanf("%lld", &coin[i]); vector<ll> X(n); reverse(coin.begin(), coin.end()); ll tx = x; REP(i, n){ ll ide = x / coin[i]; X[i] = ide; x -= ide * coin[i]; } reverse(coin.begin(), coin.end()); reverse(X.begin(), X.end()); x = tx; // cout << "reprezentacija x " << endl; // for(ll p : X) // cout << p << ' '; // cout << endl; vector<vector<ll> > ways(n + 2, vector<ll>(2, 0ll)); ways[n - 1][0] = ways[n - 1][1] = 1; for(int i = n - 2; i >= 0; i--){ if(X[i] == 0){ ways[i][0] += ways[i + 1][0]; int pt = i + 1; while(pt < n - 1 && coin[pt + 1] / coin[pt] - 1 == X[pt]) pt++; ways[i][1] = ways[i][0] + ways[pt][1]; } else{ ways[i][0] += ways[i + 1][0]; int pt = i + 1; while(pt < n - 1 && coin[pt + 1] / coin[pt] - 1 == X[pt]) pt++; ways[i][0] += ways[pt][1]; ways[i][1] = ways[i][0]; } } // cout << "check " << endl; // REP(i, n) // cout << ways[i][0] << ' '; // cout << endl; // printf("%lld\n", ways[0][0]); return 0; }
#include<cstdio> #include<algorithm> #define N 300011 using namespace std; int a[N]; bool cmp(int x,int y) { return x<y; } int main() { long long n; scanf("%lld",&n); for (int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1,cmp); long long ans=0,count=0; a[0]=-1e9; for (int i=1;i<=n;i++) { if (a[i]!=a[i-1]) { ans=(ans+count*(count-1)/2); count=0; } count++; } ans=(ans+count*(count-1)/2); printf("%lld\n",n*(n-1)/2-ans); }
#include <bits/stdc++.h> #define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i)) #define down(i,b,a) for(int (i) = (b);i>=(a);--i) #define bits(x,i) (((x) >> (i)) & 1) #define mid ((l+r)/2) #define pr pair<int,int> using namespace std; const int N = 3e5 + 5; int n; map<int,int> cnt; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; long long ans = 0; up(i,1,n){ int x; cin >> x; cnt[x]++; ans += i - cnt[x]; } cout << ans; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int a[26]; ///アルファベットの番号を格納 int t[10]; //数字 いろんな順番になる string s[3]; int sz=0; long f(string s){ if (t[a[s[0]-'a']]==0) return -1; long ans = 0; rep(p, s.size()){ ans = ans*10+t[a[s[p]-'a']]; } return ans; } int main(){ rep(i, 26) a[i] = -1; rep(i, 10) t[i] = i; rep(i, 3){ cin >> s[i]; rep(j, s[i].size()){ if (a[s[i][j]-'a']==-1){ a[s[i][j]-'a']=sz++; } } } if (sz>10){ cout << "UNSOLVABLE" << endl; return 0; } do{ long N[3]; int check = 1; //check=0のとき条件満たしてないので即効out rep(i, 3){ N[i] = f(s[i]); if (N[i]==-1) check=0; } if (N[0]+N[1]==N[2]&&check){ rep(i,3) cout << N[i] <<endl; return 0; } }while(next_permutation(t, t+10)); cout << "UNSOLVABLE" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using Int = long long; const char newl = '\n'; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);} template<typename T=Int> vector<T> read(size_t n){ vector<T> ts(n); for(size_t i=0;i<n;i++) cin>>ts[i]; return ts; } //INSERT ABOVE HERE signed main(){ cin.tie(0); ios::sync_with_stdio(0); Int n; cin>>n; string s,t; cin>>s>>t; Int a=count(s.begin(),s.end(),'1'); Int b=count(t.begin(),t.end(),'1'); if(a<b) drop(-1); if((a-b)&1) drop(-1); set<Int> ss; for(Int i=0;i<n;i++) if(s[i]=='1') ss.emplace(i); Int ans=0; for(Int i=0;i<n;i++){ if(t[i]!='1') continue; auto it=ss.lower_bound(i); if(it==ss.end()) drop(-1); ans+=*it-i; ss.erase(*it); } while(!ss.empty()){ Int x=*ss.begin();ss.erase(x); Int y=*ss.begin();ss.erase(y); ans+=y-x; } cout<<ans<<newl; return 0; }
#include<bits/stdc++.h> #define pl(a) " [" << #a << ": " << (a) << "] " #define pts(a) " [" << #a << ": { first: " << (a.first) << ", second: " << (a.second) << "}] " #define all(vi) vi.begin(), vi.end() #define endl "\n" #define ll long long using namespace std; pair<int, int> n4[4] { {1, 0}, {-1, 0}, {0, 1}, {0, -1} }; pair<int, int> n8[8] { {1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}, {-1, 1}, {1, -1} }; ll int h(ll int x1, ll int y1, ll int x2, ll int y2) { return abs(x2 - x1) + abs(y2 - y1); } ll int pow(ll int x, ll int y) { if (y == 0) return 1; if (y % 2 == 0) { ll int a = pow(x, y / 2); return a * a; } else { int a = pow(x, y / 2); return a * a * x; } return 0;} template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v); template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "[" << p.first << ", " << p.second << "]"; } template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";} template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; } ll int pow(int x, int y) { if (y == 0) return 1; if (y % 2 == 0) { int a = pow(x, y / 2); return a * a; } else { int a = pow(x, y / 2); return a * a * x; } assert(false); return 0; } void set_in(string s) { if (s.length() > 0) { freopen ((s+".in").c_str(), "r", stdin); freopen ((s+".out").c_str(), "w", stdout); } } bool intersect(pair<double, double> a, pair<double, double> b) { return max(a.first, b.first) <= min(a.second, b.second); } void solve() { int n; cin >> n; vector<pair<double, double>> arr(n); for (int i = 0; i < n; i++) { double t, a, b; cin >> t >> a >> b; if (t == 1); if (t == 2) b -= 0.1; if (t == 3) a += 0.1; if (t == 4) {a += 0.1; b -= 0.1;}; arr[i] = {a, b}; } ll int ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (intersect(arr[i], arr[j])) { // cout << i << ' ' << j << endl; ans++; } } } cout << ans << endl; } int main() { #ifndef DEBUG set_in(""); #endif #ifdef DEBUG auto clock_start = chrono::high_resolution_clock::now(); cout << endl; #endif ios::sync_with_stdio(false); cin.tie(nullptr); solve(); // int T; cin >> T; // for (int t = 1; t <= T; t++) { // cout << "Case #" << t << ": "; // solve(); // } // Clock #ifdef DEBUG auto clock_end = chrono::high_resolution_clock::now(); cout << endl; chrono::duration<double> elapsed = clock_end - clock_start; cout << "Execution time: " << elapsed.count() << "s" << endl; #endif return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define all(x) (x).begin(),(x).end() using ll = long long; using P = pair<ll, ll>; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, -1, 0, 1}; string char_to_string(char val) { return string(1, val); } int char_to_int(char val) { return val - '0'; } char inverse_char(char c) { if(isupper(c)) return tolower(c); else return toupper(c); } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } struct edge { ll to, cost; }; int main() { int N; cin >> N; int M; cin >> M; vector<ll> A(M), B(M); REP(i, M) cin >> A[i] >> B[i]; int K; cin >> K; vector<ll> C(K), D(K); REP(i, K) cin >> C[i] >> D[i]; // bit全探索 // bitに1が立っていればDにボールを入れる ll ans = 0; // 最大いくつの条件が満たされているか // bit全探索 for(int bit = 0; bit < (1 << K); ++bit) { vector<ll> t(N + 1, 0); for(int i = 0; i < K; ++i) { if(bit & (1 << i)) { t[C[i]]++; } else { t[D[i]]++; } } ll res = 0; REP(i, M) { if(t[A[i]] > 0 && t[B[i]] > 0) res++; } chmax(ans, res); } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int main() { int n; const int Nmax = 200002; vector<int> count(Nmax,Nmax); cin >> n; int p; for(int i=0;i<n;i++) { cin >> p; if(count[p] == Nmax) count[p] = i+1; } int output = 1; for(int i=0;i<Nmax;i++) { if(output < count[i]){ while(output < count[i]) { cout << i << endl; output++; if(output > n) return 0; } } if(output > n) break; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pi; typedef vector<int> vi; typedef vector<pi> vpi; #define mp make_pair #define sz(x) (int)(x).size() #define all(x) begin(x), end(x) #define rsz resize #define bk back() #define pb push_back #define ins insert #define del erase #define inf INT_MAX #define db cout << "here" << endl; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define nl endl const int MOD = 1e9+7; const ld PI = acos((ld)-1); mt19937 rng; // or mt19937_64 template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down void DBG() { cerr << "]" << endl; } template<class H, class... T> void DBG(H h, T... t) { cerr << h; if (sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef LOCAL // compile with -DLOCAL #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) #else #define dbg(...) 0 #endif const int MX = 300002; const int INF = MX+MX; void solve() { int n ; cin >> n ; int ar[n]; F0R(i,n) { cin >> ar[i]; } int flag[MX]; F0R(i,200002) flag[i]=false; int j = 0; F0R(i,n) { flag[ar[i]]= true; if(j!=ar[i]) cout << j << endl; else { for(; j <= 200001; j++) if(flag[j]==false) break; cout << j << endl; } } } int main() { int t; t=1; while(t--) solve(); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; #define rep(i,s,n) for(int i = s; i < (int)(n); i++) int main() { string a, b; cin >> a >> b; int aa = 0, bb = 0; rep(i, 0, 3) { aa += a[i] - '0'; bb += b[i] - '0'; } cout << max(aa, bb) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; int sa = 0, sb = 0; for (int i = 0; i < 3; i++) { sa += a.at(i) - '0'; sb += b.at(i) - '0'; } if (sa > sb) { cout << sa << endl; } else { cout << sb << endl; } }
// // Created by INCOMPETENT CODER on 02-11-2020 // #include "bits/stdc++.h" using namespace std; typedef long long int ll; #define debug(...) cout<< " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " ; ll bin_search(ll a[], ll lb, ll ub, ll item) { while (lb <= ub) { ll mid = lb + (ub - lb) / 2; if (a[mid] == item) return mid; if (a[mid] > item) ub = mid - 1; else lb = mid + 1; } return -1; } ll power(ll x, ll y) { ll res = 1; while (y > 0) { if (y & 1) res = res * x; y = y >> 1; x = x * x; } return res; } ll powerp(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; // y = y/2 x = (x * x) % p; } return res; } void solve() { } int main() { ll arr[124]={8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128,136,144,152,160,168,176,184,192,200,208,216,224,232,240,248,256,264,272,280,288,296,304,312,320,328,336,344,352,360,368,376,384,392,400,408,416,424,432,440,448,456,464,472,480,488,496,504,512,520,528,536,544,552,560,568,576,584,592,600,608,616,624,632,640,648,656,664,672,680,688,696,704,712,720,728,736,744,752,760,768,776,784,792,800,808,816,824,832,840,848,856,864,872,880,888,896,904,912,920,928,936,944,952,960,968,976,984,992}; string kat[124]; for(ll i=0;i<124;i++){ kat[i]=to_string(arr[i]); if(kat[i].length()==1){ kat[i]="00"+kat[i]; } if(kat[i].length()==2){ kat[i]="0"+kat[i]; } } string s; cin>>s; if(s.length()==1){ if((s[0]-'0')==8){ cout<<"Yes"; return 0; } else{ cout<<"No"; return 0; } } if(s.length()==2){ ll x= stoi(s); // debug(x) reverse(s.begin(),s.end()); ll gh=stoi(s); // debug(gh) // debug(bin_search(arr,0,123,x)) // debug(bin_search(arr,0,123,gh)) if((bin_search(arr,0,123,x)!=-1) || (bin_search(arr,0,123,gh)!=-1)){ cout<<"Yes"; return 0; } else{ cout<<"No"; return 0; } } // debug("dfsaf") map<ll,ll> temp; for(auto x:s){ temp[x-'0']++; } ll flag=0; for(ll i=0;i<124;i++){ ll flag1=0; ll freq[10]={0}; for(auto g: kat[i]){ freq[g-'0']++; } for(ll i=0;i<10;i++){ if(freq[i]>0 && temp[i]< freq[i] ){ flag1=1; break; } } if(flag1==0){ cout<<"Yes"; return 0; } else continue; } cout<<"No"; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define pb push_back #define pob pop_back #define eb emplace_back #define ins insert #define mp make_pair #define ff first #define ss second #define pf push_front #define bs binary_search #define lb lower_bound #define ub upper_bound #define sz(a) (ll)a.size() #define dec(x) fixed<<setprecision(x) #define lcm(a,b) (a*b/__gcd(a,b)) typedef priority_queue<ll> pq; typedef priority_queue<ll,vector<ll>,greater<ll> > pqmn; typedef pair<ll,ll> pll; typedef vector<ll> vll; typedef vector<pll> vpll; typedef vector<vector<ll> > vvll; typedef vector<string> vstr; typedef set<ll> sll; typedef set<pll> spll; typedef map<ll,ll> mll; const ll inf=LLONG_MAX; const ll mod=1e9+7; const ld pi=acos(-1); const ll N=100001; void solution() { int n; cin>>n; cout<<100-n%100; } int main() { //freopen("t","r",stdin); ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; t=1; //cin>>t; while(t--){ solution(); } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ long long n,m; cin >> n >> m; long long P=998244353; long long dp[m+10]; dp[0]=1; dp[1]=0; dp[2]=n * (n - 1) / 2; if(m <= 2){ cout << dp[m]; return 0; } long long fact[n+1],inv[n+1],fact_inv[n+1]; fact[1]=1; fact[0]=1; inv[1]=1; fact_inv[1]=1; fact_inv[0]=1; for (long long i = 2; i <= n ; i++) { fact[i] = fact[i - 1] * i % P; inv[i] = P - inv[P % i] * (P / i) % P; fact_inv[i] = fact_inv[i - 1] * inv[i] % P; } for(long long i = 3 ; i <= m + 5 ; i++){ dp[i] = 0; if(i % 2 == 1){ continue; } for(long long j = 0 ; j <= min(i / 2 , n / 2) ; j++){ long long plus = dp[(i - 2 * j) / 2]; plus %= P; plus *= fact[n]; plus %= P; plus *= fact_inv[n - (2 * j)]; plus %= P; plus *= fact_inv[2 * j]; plus %= P; dp[i] += plus; dp[i] %= P; } } cout << dp[m]; return 0; }
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #include <bits/stdc++.h> #include<set> #include <array> using namespace std; #define ll long long #define endl '\n' #define mod 998244353 #define pb push_back #define ff first #define ss second #define con continue #define ub upper_bound #define lb lower_bound #define si(x) int(x.size()) #define sum_all(a) ( accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin()) #define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin()) const double pi = 2 * acos(0.0); const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 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 }; ll min(ll a, ll b) { if (a < b)return a; return b; } ll max(ll a, ll b) { if (a > b)return a; return b; } ll ceil1(ll a, ll b) { return(a + b - 1) / b; } void read(vector<ll>& arr) { for (ll i = 0; i < si(arr); i++) cin >> arr[i]; } void read_graph(vector<vector<ll>>& g, ll m) { while (m--) { ll x, y; cin >> x >> y; x--, y--; g[x].pb(y); g[y].pb(x); } } vector<vector<ll>> c; ll ncr(ll n, ll r) { if (n == r) return 1; if (r<0 or r > n) return 0; return c[n][r]; } void pre(ll lim = 5003) { c = vector<vector<ll>>(lim + 1, vector<ll>(lim + 1)); c[0][0] = 1; for(ll i=1;i<=lim;i++) for (ll j = 0; j <= lim; j++) { c[i][j] = ncr(i-1,j) + ncr(i-1,j-1); c[i][j] %= mod; } } void solve() { ll n, m; cin >> n >> m; int lim = 5001; pre(); if (m % 2 == 1) { cout << 0 << endl; return; } vector<vector<ll>> dp(32, vector<ll>(n + 13)); // base case for (int i = 0; i <= n; i += 2) { dp[0][i / 2] = ncr(n, i); } //cout << ncr(n, 2) << endl; for (int i = 1; i < 13; i++) { for (int k = 0; k <= n; k += 2) { if ((m & (1ll << i)) > 0) { for (int j = 1; j <= n; j+=2) { ll x = (j + k) / 2; dp[i][x] += (dp[i - 1][j] * ncr(n, k))%mod; dp[i][x] %= mod; } } else { for (int j = 0; j <= n; j+=2) { ll x = (j + k) / 2; dp[i][x] += (dp[i - 1][j] * ncr(n, k))%mod; dp[i][x] %= mod; } } } } cout << dp[12][0] << endl; } 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 //int t; cin >> t; while (t--) solve(); }
/* ID: jerrywcy LINK: https://atcoder.jp/contests/arc107/tasks/arc107_a TITLE: A - Simple Math LANG: C++ STATUS: */ #include <bits/stdc++.h> #define DEBUG #define init(array,x) memset(array,x,sizeof(array)) using namespace std; typedef long long ll; const int inf=0x3f3f3f3f; const ll mod=998244353; ll a,b,c; int read(){ int f=1,x=0; char ss=getchar(); while(ss<'0'||ss>'9'){if(ss=='-')f=-1;ss=getchar();} while(ss>='0'&&ss<='9'){x=x*10+ss-'0';ss=getchar();} return f*x; } int main() { a=read();b=read();c=read(); a=a*(a+1)/2%mod;b=b*(b+1)/2%mod;c=c*(c+1)/2%mod; printf("%lld\n",a*b%mod*c%mod); return 0; }
/* Author: klmcoder Date : 20210227 1735 hrs. Info : atcoder [abc193-A] */ #include <iostream> #include <iomanip> int main(void) { int a, b; float p; std::cin >> a >> b; p = (((float)a-b)/(float)a)*100.0; std::cout << p << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; int r = r2 - r1, c = c2 - c1; int ans = 3; if(!r && !c) ans = 0; else if(r == c || r == -c || abs(r) + abs(c) <= 3) ans = 1; else if((r ^ c ^ 1) & 1 || abs(r + c) <= 3 || abs(r - c) <= 3 || abs(r) + abs(c) <= 6) ans = 2; cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); #define lli long long int #define ld long double #define pb push_back #define pf push_front #define mp make_pair #define all(x) (x).begin(),(x).end() #define pll pair<lli,lli> #define ve vector<lli> #define vep vector<pair<lli,lli> > #define fr(i,a,n) for(lli i=a;i<(n);i++) #define frj(j,a,n) for(lli j=a;j<(n);j++) #define frx(i,a,n) for(lli i=a;i>(n);i--) #define frxj(j,a,n) for(lli j=a;j>(n);j--) #define lb lower_bound #define ub upper_bound #define F first #define S second #define db(x) cout << "[ " << x << " ]" << endl #define db2(x,y) cout<<x<<" "<<y<<endl #define dbarr(arr,a,n) fr(i,a,n) cout<<arr[i]<<" "; cout<<endl #define yes cout<<"YES"<<endl #define no cout<<"NO"<<endl lli solve(){ lli r1,c1,r2,c2; cin>>r1>>c1>>r2>>c2; if(r1==r2 && c1==c2)return 0; if(r1+c1==r2+c2 || r1-r2==c1-c2 || (abs(r1-r2)+abs(c1-c2))<4)return 1; if((abs(r1-r2)+abs(c1-c2))<7)return 2; if(r2-c2<=r1-(c1-3) && r2-c2>=r1-(c1+3))return 2; if(r2+c2<=r1+c1+3 && r2+c2>=r1+c1-3)return 2; if((r1+c1)%2==(r2+c2)%2)return 2; return 3; } int main(){ fast; lli t=1; // cin>>t; while(t--){ cout<<solve(); } }
#include <bits/stdc++.h> using namespace std; #define pb push_back typedef long long ll; typedef pair<int, int> pii; const int maxn=2e5+5; int n,m,k; long double dp[maxn][2]; long double sum[maxn][2]; int main(){ cin>>n>>m>>k; for(int i=1,x;i<=k;i++){ cin>>x; dp[x][0]=1; } for(int i=n-1;i>=0;i--){ if(abs(dp[i][0]-1)>1e-10){ dp[i][1]=(sum[i+1][1]-sum[i+1+m][1])/m+1; dp[i][0]=(sum[i+1][0]-sum[i+1+m][0])/m; } sum[i][0]=sum[i+1][0]+dp[i][0]; sum[i][1]=sum[i+1][1]+dp[i][1]; } double ans=dp[0][1]; if(abs(dp[0][0]-1)<1e-10){ puts("-1"); return 0; } ans/=(1.0f-dp[0][0]); printf("%.3f\n",ans); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define ll long long using namespace std; int main() { int a,b,c; cin>>a>>b>>c; vector<int>v(a-1); int sum=0; rep(i,a-1){ cin>>v[i]; sum+=v[i]; } if(c*a-sum>b){ cout<<-1<<endl; } else if(c*a-sum<=0){ cout<<0<<endl; } else{ cout<<c*a-sum<<endl; } }
#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; } rep(i, 30) { rep(x, N) rep(y, N) { ll tmp = 0; rep(z, N) { tmp += dp[1][x][z] * (ll)dp[1][z][y] % mod; } dp[2][x][y] = tmp % mod; } rep(x, N) rep(y, N) dp[1][x][y] = dp[2][x][y]; if (K >> 29 - i & 1) { rep(x, N) rep(y, N) { ll tmp = 0; rep(z, N) { tmp += dp[1][x][z] * (ll)dp[0][z][y] % mod; } dp[2][x][y] = tmp % mod; } rep(x, N) rep(y, N) dp[1][x][y] = dp[2][x][y]; } } rep(i, N) { ll kotae = 0; rep(j, N) kotae += (ll)dp[1][i][j] * A[j] % mod; co(kotae % mod); } Would you please return 0; }
#include <bits/stdc++.h> #define rep(i, n) for(int(i) = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++) #define ALL(v) (v).begin(), (v).end() #define LLA(v) (v).rbegin(), (v).rend() #define SZ(v) (v).size() #define INT(...) \ int __VA_ARGS__; \ read(__VA_ARGS__) #define LL(...) \ ll __VA_ARGS__; \ read(__VA_ARGS__) #define DOUBLE(...) \ double __VA_ARGS__; \ read(__VA_ARGS__) #define CHAR(...) \ char __VA_ARGS__; \ read(__VA_ARGS__) #define STRING(...) \ string __VA_ARGS__; \ read(__VA_ARGS__) #define VEC(type, name, size) \ vector<type> name(size); \ read(name) using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using Graph = vector<vector<int>>; template <typename T> struct edge { int to; T cost; edge(int t, T c) : to(t), cost(c) {} }; template <typename T> using WGraph = vector<vector<edge<T>>>; const int INF = 1 << 30; const ll LINF = 1LL << 60; const int MOD = 1e9 + 7; template <class T> inline vector<T> make_vec(size_t a, T val) { return vector<T>(a, val); } template <class... Ts> inline auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec(ts...))>(a, make_vec(ts...)); } void read() {} template <class T> inline void read(T &a) { cin >> a; } template <class T, class S> inline void read(pair<T, S> &p) { read(p.first), read(p.second); } template <class T> inline void read(vector<T> &v) { for(auto &a : v) read(a); } template <class Head, class... Tail> inline void read(Head &head, Tail &...tail) { read(head), read(tail...); } template <class T> inline void chmax(T &a, T b) { (a < b ? a = b : a); } template <class T> inline void chmin(T &a, T b) { (a > b ? a = b : a); } ll pow10(int a) { ll ret = 1; rep(i, a) ret *= 10; return ret; } ll calc(map<int, int> mp) { ll res = 0; for(int i = 1; i <= 9; i++) { res += i * pow10(mp[i]); } return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); LL(K); STRING(s, t); map<int, int> smp, tmp; rep(i, 4) { smp[s[i] - '0']++; tmp[t[i] - '0']++; } ll all = 0, win = 0; vector<int> used(10); for(int i = 1; i <= 9; i++) { used[i] = smp[i] + tmp[i]; } for(int i = 1; i <= 9; i++) { for(int j = 1; j <= 9; j++) { auto smp2 = smp, tmp2 = tmp; smp2[i]++, tmp2[j]++; bool ok = 1; for(int k = 1; k <= 9; k++) { if(smp2[k] + tmp2[k] > K) ok = 0; } if(ok) { all += (K - used[i]) * (K - used[j] - (i == j)); ll ssc = calc(smp2), tsc = calc(tmp2); if(ssc > tsc) { win += (K - used[i]) * (K - used[j] - (i == j)); } } } } cout << fixed << setprecision(15) << (double)win / (double)all << endl; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define int long long int #define popcount(x) __builtin_popcountll(x) #define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define sc second #define pb push_back #define fr first #define all(a) (a).begin(),(a).end() #define mem0(a) memset(a,0,sizeof(a)) #define ld long double const int INF = __LONG_LONG_MAX__; #define rall(a) (a).rbegin(),(a).rend() #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroint-loops") int power(int b,int e,int m) { if(b==0) return 0; if(e==0) return 1; if(e&1) return b*power(b*b%m,e/2,m)%m; return power(b*b%m,e/2,m); } int power( int b, int e) { if(b==0) return 0; if(e==0) return 1; if(e&1) return b*power(b*b,e/2); return power(b*b,e/2); } bool isPowerOfTwo(int x) { // x wiint check if x == 0 and !(x & (x - 1)) wiint check if x is a power of 2 or not return (x && !(x & (x - 1))); } void solve() { int n; cin>>n; vector <int> v(n); for(auto &i:v) cin>>i; int x=0,y=0,curr=0; for(int i=2;i<=1000;i++) { x=0; for(int j=0;j<n;j++) { if(v[j]%i==0) x++; } // cout<<y<<"\n"; if(x>curr) { curr=x; y=i; } } cout<<y; } signed main() { fastio int tt=1; // cin>>tt; // freopen("input.txt", "r" , stdin); // freopen("output.txt", "w", stdout); while(tt--) { solve(); cout<<"\n"; } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long const ll M1 = 1e9+7; void files(){ freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); } void fast(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main(){ fast(); ll n; cin>>n; vector<ll> d(n,0); vector<ll> sum(n+1,0); vector<ll> m(n+1,0); for(int i=0; i<n; i++){ cin>>d[i]; sum[i+1]=sum[i]+d[i]; m[i+1]=max(m[i],sum[i+1]); } ll c=0,ans=0; for(int i=1; i<=n; i++){ ll k=c+m[i]; ans=max(ans,k); c=c+sum[i]; } cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; int x, y; int main(){ cin >> x >> y; if(x==y)cout << x << endl; else cout << 3 - x - y << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int A,B;cin>>A>>B; int X=B-A; for(int i=X;i>0;i--){ if((B/i-1)*i>=A){ cout<<i<<endl; return 0; } } }
#include <bits/stdc++.h> //#include <atcoder/modint> //#include <atcoder/math> //#include <boost/multiprecision/cpp_int.hpp> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("O3") #define REP(i, n) for(int i = 0; i < n; i++) #define REPP(i, n) for(int i = 1; i <= n; i++) #define ALL(obj) (obj).begin(), (obj).end() #define EPS (1e-9) #define INF (1e17) #define PI (acos(-1)) //const double PI = acos(-1); //const double EPS = 1e-15; //long long INF=(long long)1E17; #define i_7 (long long)(1e9+7) //#define i_7 998'244'353 long mod(long a){ long long c = a % i_7; if(c >= 0) return c; return c + i_7; } long long po(long a, long b){ if(b == 0) return 1; long long z = po(a , b / 2); z = mod(z * z); if(b % 2 != 0) z = mod(a * z); return z; } bool prime_(int n){ if(n == 1){ return false; }else if(n == 2){ return true; }else{ for(int i = 2; i <= std::sqrt(n); i++) if(n % i == 0) return false; return true; } } long long gcd_(long long a, long long b){ if(a < b) std::swap(a,b); if(a % b == 0) return b; else return gcd_(b, a % b); } long long lcm_(long long x, long long y){ return (x / gcd_(x,y)) * y; } using namespace std; //using namespace atcoder; //using mint = modint1000000007; //using mint = modint998244353; //using namespace boost::multiprecision; //using namespace __gnu_pbds; int main(){ //using namespace std; int n; cin>>n; long long x[n]; int c[n]; REP(i, n){ cin>>x[i]>>c[i]; c[i]--; } vector<long long> balls[n]; REP(i, n) balls[c[i]].push_back(x[i]); vector<int> colors; REP(i, n){ if(balls[i].empty()) continue; colors.push_back(i); sort(ALL(balls[i])); } //sort(ALL(colors)); int num = colors.size(); vector<vector<long long>> dp(num, vector<long long>(2, INF)); REP(i, num){ int color = colors[i]; int cnt = balls[color].size(); long long width = balls[color][cnt - 1] - balls[color][0]; if(i == 0){ dp[i][0] = abs(balls[color][0]) + width; dp[i][1] = abs(balls[color].back()) + width; continue; } dp[i][0] = min(dp[i][0], abs(balls[color][0] - balls[colors[i - 1]][0]) + width + dp[i - 1][1]); dp[i][0] = min(dp[i][0], abs(balls[color][0] - balls[colors[i - 1]].back()) + width + dp[i - 1][0]); dp[i][1] = min(dp[i][1], abs(balls[color].back() - balls[colors[i - 1]][0]) + width + dp[i - 1][1]); dp[i][1] = min(dp[i][1], abs(balls[color].back() - balls[colors[i - 1]].back()) + width + dp[i - 1][0]); } long long ans = min(dp[num - 1][0] + abs(balls[colors[num - 1]].back()), dp[num - 1][1] + abs(balls[colors[num - 1]][0])); cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <string> #include <functional> #include <vector> #include <numeric> #include <iomanip> #include <utility> #include <cmath> #include <climits> #include <queue> #include <bitset> #include <set> #include <assert.h> #include <map> using namespace std; typedef vector<vector<long> > dim2veclo; typedef vector<vector<int> > dim2vecin; typedef vector<vector<double> > dim2vecdo; typedef vector<vector<long long> > dim2vecll; typedef vector<int> vecin; typedef vector<long> veclo; typedef vector<double> vecdo; typedef vector<long long> vecll; typedef vector<bool> vecbo; typedef vector<vector<bool> > dim2vecbo; typedef long long ll; typedef vector < pair<ll, ll> > vecpa; typedef vector<string> vecst; typedef pair<ll, ll> pail; typedef pair<int, int> pain; typedef vector<vecpa > dim2vecpa; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int dx[4] = { -1, 0, 1, 0 }; int dy[4] = { 0, 1, 0, -1 }; const ll MOD = 1000000007; int dist(double x1, double y1, double x2, double y2) { return (int)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } int angG(double X, double Y, double x2, double y2, double x3, double y3) { double gaiseki = (x2 - X) * (y3 - Y) - (y2 - Y) * (x3 - X); return (int)(asin(gaiseki / (dist(X, Y, x2, y2) * dist(X, Y, x3, y3))) * 100000); } int angN(double X, double Y, double x2, double y2, double x3, double y3) { double naiseki = (x2 - X) * (x3 - X) + (y2 - Y) * (y3 - Y); return (int)(acos(naiseki / (dist(X, Y, x2, y2) * dist(X, Y, x3, y3))) * 100000); } int main() { int n; cin >> n; vecdo a = vecdo(n); vecdo b = vecdo(n); vecdo c = vecdo(n); vecdo d = vecdo(n); rep(i, n) cin >> a[i] >> b[i]; rep(i, n) cin >> c[i] >> d[i]; if (n == 1) { cout << "Yes"; return 0; } if (n == 2) { if (dist(a[0], b[0], a[1], b[1]) == dist(c[0], d[0], c[1], d[1])) { cout << "Yes"; } else cout << "No"; return 0; } ll length = dist(a[0], b[0], a[1], b[1]); bool res = false; vector<pair<int, pair<int, int>>> ans = vector<pair<int, pair<int, int>>>(n - 2); for (int i = 2; i < n; i++) { ans.push_back(make_pair(dist(a[0], b[0], a[i], b[i]), make_pair(angN(a[0], b[0], a[1], b[1], a[i], b[i]), angG(a[0], b[0], a[1], b[1], a[i], b[i])))); } sort(ans.begin(), ans.end()); rep(i, n) rep(j, n) { if (i == j) continue; if (length != dist(c[i], d[i], c[j], d[j])) continue; bool flag = true; rep(k, n) { if (i == k) continue; if (j == k) continue; pair<int, pair<int, int>> isOK = make_pair(dist(c[i], d[i], c[k], d[k]), make_pair(angN(c[i], d[i], c[j], d[j], c[k], d[k]), angG(c[i], d[i], c[j], d[j], c[k], d[k]))); if (!binary_search(ans.begin(), ans.end(), isOK)) { flag = false; break; } } if (flag) { res = true; break; } } if (res) cout << "Yes"; else cout << "No"; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pll> vpll; #define FOR(n) for(int i=0;i<n;++i) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll gcd(ll a, ll b) { return a % b ? gcd(b, a % b) : b; } const ll mod = 1e9 + 7; const ll inf = 0x3f3f3f3f; ll qpow(ll a, ll b) { ll t = 1; while (b != 0) { if (b & 1)t = (t * a) % mod; a = (a * a) % mod; b >>= 1; }return t; } int n; char a[4]; int m; ll f[1005] = { 0,1 }; ll p[1005] = { 1,2 }; void pre() { for (int i = 2; i < 1003; ++i) { f[i] = f[i - 1] + f[i - 2]; f[i] %= mod; p[i] = p[i - 1] * 2; p[i] %= mod; } } signed main() { pre(); cin >> n; FOR(4)cin >> a[i]; if (n == 2 || n == 3) { cout << 1 << endl; return 0; } int cnt = 1; FOR(4) { m += (a[i] - 'A') * cnt; cnt *= 2; } switch (m) { case 2:case 3:case 5:case 13: { cout << p[n - 3] << endl; return 0; } case 1:case 6:case 7:case 9: { cout << f[n - 1] << endl; return 0; } default: cout << 1 << endl; break; } return 0; }
#include <bits/stdc++.h> #define rep(a,n) for (ll a = 0; a < (n); ++a) using namespace std; //using namespace atcoder; using ll = long long; typedef pair<ll,ll> P; typedef pair<ll,P> PP; //typedef vector<vector<int> > Graph; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; } const ll INF = 1e18; #define debug(v) cout<<#v<<": ",prt(v); template <typename A,typename B> inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";} template <typename A,typename B,typename C> inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";} inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';} template <typename T> inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';} template<typename T> inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } } template <typename T> inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';} template <typename A,typename B> inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';} template <typename A,typename B> inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';} template <typename T> inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';} template <typename T> inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';} /* */ int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); ll t; cin >> t; rep(tes,t){ ll n; cin >> n; ll a = 0; while(n%2==0){ a++; n /= 2; } if(a==0)cout<<"Odd"<<endl; else if(a==1)cout<<"Same"<<endl; else cout<<"Even"<<endl; } return 0; }
#include <stdio.h> #define FOR(i, n) for (int i = 0; i < n; i++) #define FORREV(i, n) for (int i = (n - 1); i >= 0; i--) #define FORA(i, a, n) for (int i = a; i <= n; i++) #define INF 1000000000 typedef long long int ll; typedef unsigned long long int ull; int sumOfDigits(int N) { int sum = 0; while (N > 0) { sum += (N % 10); N /= 10; } return sum; } int main() { int A, B; scanf("%d %d", &A, &B); (sumOfDigits(A) > sumOfDigits(B)) ? printf("%d\n", sumOfDigits(A)) : printf("%d\n", sumOfDigits(B)); return 0; }
#include<bits/stdc++.h> #include<math.h> #include<set> using namespace std; #define ll long long #define faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define line "\n" #define sp " " void sol() { string a, b; cin >> a >> b; int sum_1 = 0, sum_2 = 0; for (auto s : a) sum_1 += (s - '0'); for (auto s : b) sum_2 += (s - '0'); cout << max(sum_1, sum_2) << line; } int main() { faster // int t; // cin >> t; // while (t--) sol(); return 0; }
#include <bits/stdc++.h> using namespace std; #define eps 1e-9 #define INF 2000000000 // 2e9 #define LLINF 2000000000000000000ll // 2e18 (llmax:9e18) #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #define rep(i, x) for (int i = 0; i < (int)(x); i++) #define drep(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define popcount __builtin_popcount #define next __next #define prev __prev #ifndef LOCAL #define dmp(...) ; #else #define dmp(...) \ cerr << "[ " << #__VA_ARGS__ << " ] : " << dump_str(__VA_ARGS__) << endl #endif // ---------------- Utility ------------------ template <class T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <class T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <class T> using MaxHeap = priority_queue<T>; template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>; template <class T> vector<T> vect(int len, T elem) { return vector<T>(len, elem); } // ----------------- Input ------------------- template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.first >> p.second; } template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (int i = 0; i < vec.size(); i++) is >> vec[i]; return is; } // ----------------- Output ------------------ template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.first << ',' << p.second; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &e : v) os << e << " "; return os; } template <class T> ostream &operator<<(ostream &os, const deque<T> &d) { for (const T &e : d) os << e << " "; return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &s) { os << "{ "; for (const T &e : s) os << e << " "; return os << "}"; } template <class T, class U> ostream &operator<<(ostream &os, const map<T, U> &m) { os << "{ "; for (const auto &[key, val] : m) os << "( " << key << " -> " << val << " ) "; return os << "}"; } template <class TupleTy, size_t... I> void dump_tuple(ostream &os, const TupleTy t, std::index_sequence<I...>) { (..., (os << (I == 0 ? "" : ",") << std::get<I>(t))); } template <class... Args> ostream &operator<<(ostream &os, const tuple<Args...> &t) { os << "("; dump_tuple(os, t, std::make_index_sequence<sizeof...(Args)>()); return os << ")"; } void dump_str_rec(ostringstream &) {} template <class Head, class... Tail> void dump_str_rec(ostringstream &oss, Head &&head, Tail &&... tail) { oss << ", " << head; dump_str_rec(oss, forward<Tail>(tail)...); } template <class T, class... U> string dump_str(T &&arg, U &&... args) { ostringstream oss; oss << arg; dump_str_rec(oss, forward<U>(args)...); return oss.str(); } // --------------- Fast I/O ------------------ void fastio() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); } // ------------------ ACL -------------------- // #include <atcoder/modint> // constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; // using mint = atcoder::static_modint<MOD>; // ostream &operator<<(ostream &os, const mint &v) { // return os << v.val(); // } // ------------ End of template -------------- #define endl "\n" using ll = long long; using pii = pair<int, int>; void solve() { int V, T, S, D; cin >> V >> T >> S >> D; if (D < V * T || D > V * S) cout << "Yes" << endl; else cout << "No" << endl; return; } int main() { fastio(); solve(); // int t; cin >> t; while(t--)solve(); // int t; cin >> t; // for(int i=1;i<=t;i++){ // cout << "Case #" << i << ": "; // solve(); // } return 0; }
#include <iostream> #include <cmath> #include <string> #include <vector> #include <algorithm> #include <bits/stdc++.h> using namespace std; typedef long long ll; #define PI 3.141592653589 ll INF = 1LL << 60; void rot( pair<double,double>& p, double theta ){ pair<double,double> tempp = p; p.first = tempp.first * cos(theta) - tempp.second * sin(theta); p.second = tempp.first * sin(theta) + tempp.second * cos(theta); } void move( pair<double,double>& p, pair<double,double> move ){ p.first = p.first + move.first; p.second = p.second + move.second; } double dot( pair<double,double> p, pair<double,double> q ){ return p.first*q.first+p.second*q.second; } double norm( pair<double,double> p ){ return sqrt( p.first*p.first+p.second*p.second ); } int main(){ ll N; cin >> N; double x0, y0; double xN2, yN2; cin >> x0 >> y0; cin >> xN2 >> yN2; pair<double,double> p0( x0,y0 ); pair<double,double> pN2( xN2, yN2 ); pair<double,double> pN20( x0-xN2, y0-yN2 ); pair<double,double> center( (x0+xN2)/2, (y0+yN2)/2 ); pair<double,double> px(1,0); double m = sqrt( pow(p0.first-pN2.first,2)+pow(p0.second-pN2.second,2) )/2; double r = sqrt( 2*m*m*(1-cos(2*PI/N)) ); //radius //cout << m << " "<< r << endl; double theta = acos( dot( pN20, px )/norm(pN20) ); if( pN20.second < 0){ theta = 2*PI - theta; } //cout << theta*180/PI << endl; pair<double,double> p1( r, 0 ); //cout << p1.first << " " << p1.second << endl; rot( p1, PI - ((N-2)*PI)/(2*N) ); move( p1, pair<double,double>( m, 0 ) ); //cout << p1.first << " " << p1.second << endl; rot( p1, theta ); move( p1, center); cout << fixed << setprecision(10) << p1.first << " " << p1.second << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int kN = 505; const int kInf = 1e9 + 7; int n; int a[kN][kN]; void No() { puts("No"); exit(0); } int main() { scanf("%d", &n); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) scanf("%d", &a[i][j]); } for(int i = 0; i < n - 1; i++) { int diff = a[i + 1][0] - a[i][0]; for(int j = 0; j < n; j++) { if(a[i + 1][j] - a[i][j] != diff) No(); } } for(int j = 0; j < n - 1; j++) { int diff = a[0][j + 1] - a[0][j]; for(int i = 0; i < n; i++) { if(a[i][j + 1] - a[i][j] != diff) No(); } } vector<int> x(n), y(n); int mn = kInf, nx = -1, ny = -1; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(mn > a[i][j]) { mn = a[i][j], nx = i, ny = j; } } } for(int i = 0; i < n; i++) x[i] = mn + a[i][0] - a[nx][0]; for(int i = 0; i < n; i++) y[i] = a[0][i] - a[0][ny]; puts("Yes"); for(int i = 0; i < n; i++) printf("%d ", x[i]); puts(""); for(int i = 0; i < n; i++) printf("%d ", y[i]); puts(""); return 0; }
#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 <iomanip> #define ll long long int #define inf 1000000000000 #define mod 1000000007 // templates #define all(v) v.begin(),v.end() #define fi first #define se second #define sz(x) (int)x.size() #define ps(x,y) fixed<<setprecision(y)<<x #define fo(i,a,b) for(int i=a;i<b;i++) #define ro(i,a,b) for(int i=a;i>=b;i--) #define vi vector<int> #define vl vector<ll> #define sc(n) scanf("%d",&n) #define sl(n) scanf("%lld",&n) #define pr(n) printf("%d\n",n) #define pl(n) printf("%lld\n",n) #define prs(n) printf("%d ",n) #define pls(n) printf("%lld ",n) using namespace std; ll GCD(ll a, ll b, ll& x, ll& y) { if (b == 0) { x = 1LL; y = 0LL; return a; } ll x1, y1; ll d = GCD(b, a % b, x1, y1); x = y1; y = x1 - y1 * 1LL * (a / b); return d; } void solve() { ll n, s, k; sl(n), sl(s), sl(k); ll x, y; ll gc = __gcd(n, k); if (s % gc) { pl(-1LL); } else { // y->loops x->moves x*k+s=y*n => (x*k-y*n=-s) n /= gc, s /= gc, k /= gc; gc = GCD(k, n, x, y); ll mod_inv = (x % n + n) % n; ll ans = ((-s * mod_inv) % n + n) % n; pl(ans); } } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; scanf("%d", &t); while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n,s,d,x,y; cin>>n>>s>>d; int flag=0; for(int i=0;i<n;i++) { cin>>x>>y; if(x<s&&y>d) flag=1; } if(flag==1) cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,f,n) for(ll i=(f); (i) < (n); i++) #define repe(i,f,n) for(ll i=(f); (i) <= (n); i++) #define repc(i,f,n) for(char i=(f); (i) <= (n); i++) #define PI 3.14159265358979323846264338327950L #define debug(x) cout<<#x<<" :: "<<x<<"\n"; #define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"; #define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"; #define P pair<int, int> #define Pl pair<ll, ll> #define dvec vector<vector<ll>> #define OUT(x) cout << x << endl; return 0; //printf("%.10f\n") //cout << fixed << setprecision(10); template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;} template<class T> inline bool chmaxe(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 MOD = 1000000007ll; const ll INF = 1e+18; const int iINF = 1e9; const double EPS = 1e-8; int main() { ll N, S, D; cin >> N >> S >> D; rep(i, 0, N){ ll x, y; cin >> x >> y; if(x >= S) continue; if(y <= D) continue; cout << "Yes" << endl; return 0; } cout << "No" << endl; }
#include <bits/stdc++.h> #include <vector> using namespace std; typedef long long int ll; typedef unsigned long long int ul; int main() { ll n,a; cin>>n; a=n*1.08; if(a<206) { cout<<"Yay!\n"; } else if(a>206) { cout<<":(\n"; } else { cout<<"so-so\n"; } return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //#define int long long #define reset(x) memset(x,0,sizeof(x)) #define db1(x) cout<<#x<<"="<<x<<'\n' #define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n' #define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n' #define rep(i,n) for(int i=0;i<(n);++i) #define repA(i,a,n) for(int i=a;i<=(n);++i) #define repD(i,a,n) for(int i=a;i>=(n);--i) #define sz(a) (int)a.size() #define pii pair<int,int> #define all(a) a.begin(),a.end() #define PI 3.1415926535897932384626433832795 #define INF 1000000000 #define MOD 1000000007 #define MOD2 1000000009 #define EPS 1e-6 #define pb push_back #define fi first #define se second #define mp make_pair int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen(".inp", "r", stdin); //freopen(".out", "w", stdout); int n; cin >> n; int a = floor(n * 1.08); if (a < 206) { cout << "Yay!"; } else if (a == 206) { cout << "so-so"; } else { cout << ":("; } }
//include <atcoder> #include <iostream> #include <algorithm> #include <cmath> #include <tuple> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #define flush fflush(stdout) #define endl '\n' #define all(v) v.begin(), v.end() using namespace std; //using namespace atcoder; typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> Pl; const int mod1 = (int)1e9 + 7, mod2 = (int)998244353; const int INF = (int)1e9 + 10; const ll LINF = (ll)1e18 + 10; const int di[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dj[8] = {0, 1, 0, -1, -1, 1, -1, 1}; #define rep0(i, n) for (i = 0; i < n; i++) #define rep1(i, a, b) for (i = a; i < b; i++) template <typename T> T my_abs(T x){ return (x >= 0)? x : -x; } template <typename T> void chmax(T &a, T b){ a = max(a, b); } template <typename T> void chmin(T &a, T b){ a = min(a, b); } ll gcd(ll a, ll b){ if (a > b) return gcd(b, a); if (a == 0) return b; return gcd(b % a, a); } bool incld_bit(ll bit, int i){ return ((bit>>i) & 1) == 1; } // -------------------------------------------------------------------------------- #define N 2000007 #define commod mod1 ll fac[N], inv[N], finv[N]; void cominit(int n) { int i; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (i = 2; i < n + 2; i++) { fac[i] = fac[i - 1] * i % commod; inv[i] = commod - inv[commod % i] * (commod / i) % commod; finv[i] = finv[i - 1] * inv[i] % commod; } return; } ll com(int n, int r) { if (n < r) return 0; if (n < 0 || r < 0) return 0; if (r == 0 || r == n) return 1; return (fac[n] * finv[r]) % commod * finv[n - r] % commod; } int main(void){ int i, j; int n, m, k; cin >> n >> m >> k; if (n - m > k){ cout << 0 << endl; return 0; } cominit(n + m); int ans; ans = (com(n + m, n) + mod1 - com(n + m, m + k + 1)) % mod1; cout << ans << endl; return 0; }
#include <vector> #include <iostream> #include <cmath> #include <map> #include <unordered_map> #include <algorithm> #include <fstream> #include <unistd.h> #include <string.h> #include <string> #include <numeric> #include <queue> #include <deque> #include <sstream> #include <iomanip> #include <set> #include <stack> #include <cassert> #include <functional> #include <random> #include <bitset> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<vvl> vvvl; typedef vector<vvvl> vvvvl; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<vvb> vvvb; typedef vector<vvvb> vvvvb; typedef vector<string> vs; typedef vector<vs> vvs; typedef vector<vvs> vvvs; typedef vector<char> vc; typedef vector<vector<char>> vvc; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<vvd> vvvd; typedef vector<long double> vld; typedef vector<vld> vvld; typedef unordered_map<ll, ll> uii; typedef unordered_map<ll, ll> uuii; typedef unordered_map<ll, ll> uuuii; typedef pair<ll, ll> PL; typedef vector<PL> vpl; typedef vector<vector<PL>> vvpl; typedef vector<vvpl> vvvpl; typedef pair<ll, PL> TL; typedef vector<TL> vtl; typedef vector<vtl> vvtl; typedef bitset<64> bs; const ll LINF = 1e17; const long double pi = 3.1415926535897932; const string endstr = "\n"; #define FOR(i, a, b) for(ll i = (a); i < b; i++) #define RFOR(i, a, b) for(ll i = (a); i > b; i--) #define rep(i, n) for(ll i = 0; i < n; i++) #define rrep(i, n) for(ll i = n-1; i > -1; i--) #define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++) #define ff first #define ss second #define pb push_back #define ALL(X) (X).begin(),(X).end() template <typename T> T gcd(T a, T b) {return (a == 0) ? b : gcd(b%a, a);} template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b;} bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;}; bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;}; bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;}; bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;}; template <typename T> vector<T> uniquen(vector<T> vec /* copy */){ sort(ALL(vec)); vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; } inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);}; template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } //friend bool operator<(const tpl& lhs, const tpl& rhs){ // return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r); //} bool bit(ll st, ll b){return ((st>>b)&1) == 1;} int main(int argc, const char* argv[]){ #if defined(__LOCAL__) std::string file_name = argv[1]; ifstream in_file(file_name.c_str()); cin.rdbuf(in_file.rdbuf()); #else ios_base::sync_with_stdio(false); cin.tie(nullptr); #endif ll N, M; cin >> N >> M; map<ll, vpl> yz; rep(_, M){ ll x, y, z; cin >> x >> y >> z; yz[x].pb({y,z}); } vvl dp(N+1, vl(1ll<<N, 0)); dp[0][0] = 1; rep(i, N){ rep(st, 1ll<<N){ if(dp[i][st] == 0) continue; rep(k, N){ if(bit(st, k)) continue; ll nst = st | (1ll<<k); bool ok = true; for(const auto& yzp : yz[i+1]){ ll y = yzp.first, z = yzp.second; ll cnt_st = nst & ((1ll << y) - 1); if(z < popcnt(cnt_st)){ ok = false; break; } } if(ok){ dp[i+1][nst] += dp[i][st]; } } } } cout << dp[N][(1ll<<N)-1] << endstr; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define mod 1000000007 main() { int n,x,i,j; cin>>n>>x; char s[n+1]; cin>>s; for(i=0;i<n;i++) { if(s[i]=='o') { x++; } else { x--;x=max(x,0); } } cout<<x<<endl; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #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++) int main() { int N, X; string S; cin >> N >> X >> S; int point = X; rep (i, N) { if (S.at(i) == 'o') point++; else point = max(0, point-1); } cout << point << endl; }
#include<bits/stdc++.h> using namespace std; int solve() { int n; string f, t; cin >> n >> f >> t; int n1f = 0, n1t = 0; for(int i = 0; i < n; ++i) { if(f[i] == '1') n1f++; if(t[i] == '1') n1t++; } if(n1f != n1t) { cout << "-1\n"; return 0; } vector<int> mv(n,0); int posf=0, post=0; while(posf<n && post<n){ while(f[posf]!='1' && posf<n) posf++; while(t[post]!='1' && post<n) post++; f[posf]='0'; t[post]='0'; mv[posf]=post-posf; } // move to the right int groupmove=0; int sol=0; for(int i=0; i<n; i++) { if(mv[i]>0){ sol+=mv[i]-groupmove; groupmove+=mv[i]-groupmove; } if(mv[i]==0 && groupmove>0){ groupmove--; } } // to the left groupmove=0; for(int i=n-1; i>=0; i--) { if(mv[i]<0){ sol+=-mv[i]-groupmove; groupmove+=-mv[i]-groupmove; } if(mv[i]==0 && groupmove>0){ groupmove--; } } //debug( mv); cout << sol << "\n"; return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int ntest = 1; for(int test = 0; test < ntest; ++test) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); int n; string s, t; cin >> n >> s >> t; if(count(s.begin(), s.end(), '0') != count(t.begin(), t.end(), '0')){ cout << "-1\n"; return 0; } deque<int> a, b; for(auto rep = 0; rep < 2; ++ rep){ for(auto i = 0; i < n; ++ i){ if(~s[i] & 1){ a.push_back(i); } } swap(a, b); swap(s, t); } int res = 0; for(auto i = 0; i < (int)a.size(); ++ i){ if(a[i] != b[i]){ ++ res; } } cout << res << "\n"; return 0; } /* */ //////////////////////////////////////////////////////////////////////////////////////// // // // Coded by Aeren // // // ////////////////////////////////////////////////////////////////////////////////////////
#include<bits/stdc++.h> //#include<atcoder/all> using namespace std; //using namespace atcoder; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(),A.end() #define RALL(A) A.rbegin(),A.rend() typedef long long ll; typedef pair<ll,ll> P; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;} const ll mod=998244353; const ll LINF=1ll<<60; const int INF=1<<30; int dx[]={1,0,-1,0,1,-1,1,-1}; int dy[]={0,1,0,-1,1,-1,-1,1}; ll dp[3001][6001]; ll rec(ll n, ll k){ if(n < k) return 0; if(k == 0){ if(n == 0) return 1; else return 0; } if(~dp[n][k]) return dp[n][k]; ll ret = (rec(n - 1, k - 1) + rec(n, 2 * k)) %mod; return dp[n][k] = ret; } int main(){ memset(dp, -1, sizeof(dp)); ll n, k;cin >> n >> k; cout << rec(n, k) << endl; return 0; }
/* * @Author: RBQRBQ * @Date: 2020-11-02 10:48:40 * @LastEditors: RBQRBQ * @LastEditTime: 2020-11-02 11:02:18 */ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii; namespace IO{ template<typename T>inline void read(T &x){ x=0;ll f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();} while(isdigit(ch)){x=x*10+ch-48;ch=getchar();} x=x*f; } } using namespace IO; const ll mod (998244353); ll mul(ll a,ll b) { return 1ll*a*b%mod; } ll dp[4000][4000]; ll n,k; int main() { read(n),read(k); for(int i=0;i<=3999;i++) for(int j=0;j<=3999;j++) if(i<j) dp[i][j]=0; for(int i=0;i<=3999;i++) dp[i][i]=1; for(int i=1;i<=3999;i++) for(int j=3999;j>=1;j--) if(2*j<=3999) dp[i][j]=(dp[i-1][j-1]+dp[i][2*j])%mod; else { dp[i][j]=dp[i-1][j-1]; } cout<<dp[n][k]; }
#include<bits/stdc++.h> #include<bits/extc++.h> #pragma GCC optimize("Ofast") using namespace std; using namespace __gnu_pbds; template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; } template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t){ while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...); } #ifdef DEBUG #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define debugv(x) {{cerr<<#x<<": "; for(auto i:x) cerr<<i<<" "; cerr<<endl;}} #define debugr(l,r,x) {{cerr<<#x<<": "; for(int i=l;i<=r;i++) cerr<<x<<" "; cerr<<endl;}} #else #define debug(...) (__VA_ARGS__) #define debugv(x) #define debugr(l,r,x) #define cerr while(0) cerr #endif mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //#define int long long typedef __int128 INT; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; #define priority_queue std::priority_queue #define F first #define S second typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); vi v; for(int i=1; i<=10000; i++){ if(i%3==0 || i%5==0 || i%7==0 || i%11==0) v.push_back(i); } debug(v.size()); int n; cin>>n; for(int i=0; i<n-1; i++){ cout<<v[i]*2<<" "; } cout<<1155<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<ll>>; #define F(i,s,e) for(ll i=s;i<e;++i) #define IA(array,size) F(i,0,size) cin >> array[i]; #define PA(array,size) F(i,0,size) cout << array[i] << " "; cout << endl; constexpr int32_t MOD=1000000007; int main(){ ll n; cin >> n; ll p[n]; IA(p,n); ll ans=0; bool ng[200010]; F(i,0,200010){ ng[i]=0; } F(i,0,n){ ng[p[i]]=1; if(!ng[ans]){ cout << ans << endl; } else{ while(ng[ans]){ ++ans; } cout << ans << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c; cin >> a >> b >> c; if(c % 2 == 0){ if(abs(a) == abs(b)) cout << "=" << endl; else if(abs(a) > abs(b)) cout << ">" << endl; else cout << "<" << endl; }else{ if(a == b) cout << "=" << endl; else if(a > b) cout << ">" << endl; else cout << "<" << endl; } return 0; }
#include<bits/stdc++.h> using namespace std;; int main(){ char C1,C2,C3; cin>>C1>>C2>>C3; if(C1==C2 && C2==C3) cout<<"Won"<<endl; else cout<<"Lost"<<endl; }
#include <bits/stdc++.h> int count(std::vector<std::vector<int>> vecs) { int max = vecs[0][0] - 1; int cnt = 0; for (int i = 0; i < vecs.size(); i++) { if (max < vecs[i][0]) { cnt++; max = vecs[i][1]; } } return cnt; } int validation_check(std::vector<std::vector<int>> vecs) { std::sort(vecs.begin(), vecs.end(), [] (auto lhs, auto rhs) { return lhs[0] < rhs[0]; }); int a = count(vecs); std::sort(vecs.begin(), vecs.end(), [] (auto lhs, auto rhs) { return lhs[1] < rhs[1]; }); int b = count(vecs); return a - b; } std::vector<std::vector<int>> run(int N, int M) { std::vector<std::vector<int>> vecs(N, std::vector<int>(2, -1)); if (M == 0) { for (int i = 0; i < N; i++) { vecs[i][0] = 2 * i + 1; vecs[i][1] = 2 * (i + 1); } } else if (std::abs(M) > N - 2) { } else if (M > 0) { vecs[0][0] = 1; vecs[0][1] = 2 * (M + 2); int i = 1; for (;i <= M + 1; i++) { vecs[i][0] = 2 * i; vecs[i][1] = 2 * i + 1; } for (; i < N; i++) { vecs[i][0] = 2 * i + 1; vecs[i][1] = 2 * (i + 1); } } // std::cout << vecs[0][0] << std::endl; // if (vecs[0][0] > -1) { // int res = validation_check(vecs); // std::cout << res << " " << M << std::endl; // if (res != M) { // std::cout << "N = " << N << ", M = " << M << std::endl; // for (auto vec : vecs) { // std::cout << vec[0] << " " << vec[1] << std::endl; // } // std::exit(0); // } // } return vecs; } int main() { // std::mt19937 gen{std::random_device{}()}; // std::uniform_int_distribution<> dist(1, 20); // for (int i = 0; i < 100; i++) { // int N = dist(gen); // int M = dist(gen) - 10; // run(N, M); // } int N, M; std::cin >> N >> M; auto vecs = run(N, M); if (vecs[0][0] == -1) { std::cout << -1 << std::endl; } else { for (auto vec : vecs) { std::cout << vec[0] << " " << vec[1] << std::endl; } } }
#include <bits/stdc++.h> using namespace std; #define ffor(i, a, b) for (int i = a ; i <= (int) b ; i++) #define rfor(i, a, b) for (int i = (int) b ; i >= a ; i--) #define vec vector #define PB push_back #define MP make_pair #define MT make_tuple #define F first #define S second using ll = long long int; // watch out for overflows in your code using pii = pair<int,int>; //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void debug() { cout << "\n"; }; template <typename T, typename... Targs> void debug(T t, Targs... args) { cout << t << " "; debug(args...); } template <typename T1, typename T2> inline ostream& operator << (ostream& os, const pair<T1,T2>& p) { return os << "(" << p.F << ", " << p.S << ")"; } template <typename T> inline ostream& operator << (ostream& os, const vec<T>& v) { for(auto& t : v) { os << t << " "; } return os; } template <typename T> inline ostream& operator << (ostream& os, const vec<vec<T>>& m) { for(auto& v : m) { for(auto& t : v) { os << t << " "; } os << "\n"; } return os; } template <typename T> inline ostream& operator << (ostream& os, const set<T>& v) { for(auto& t : v) { os << t << " "; } return os; } template <typename K, typename V> inline ostream& operator << (ostream& os, const map<K,V>& m) { for(auto& p : m) { os << p.F << " -> " << p.S << "\n"; } return os; } string s, t, u; int n; set<char> ccs; void consume(const string& S) { ffor(i, 0, S.size() - 1) { ccs.insert(S[i]); } } vec<int> m(26, -1); bool check(const string& S) { return m[S[0]-'a'] != 0; } ll encode(const string& S) { ll x = 0; ffor(i, 0, S.size()-1) { x += (ll) m[S[i]-'a']; if(i < (int) S.size()-1) { x *= 10LL; } } return x; } vec<char> ccv; vec<int> aa; bool csearch(int i) { if(i == n) { return check(s) && check(t) && check(u) && encode(s) + encode(t) == encode(u); } char c = ccv[i]; //bool ret = false; ffor(d, 0, 9) { if(aa[d]) { aa[d] = 0; m[c-'a'] = d; if(csearch(i+1)) return true; m[c-'a'] = -1; aa[d] = 1; } } return false; } bool compute() { n = (int) ccs.size(); if(n > 10) return false; aa.assign(10, 1); for(char c : ccs) ccv.PB(c); return csearch(0); } //////////////////////////////////////////////////////////////////////// int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> s >> t >> u; consume(s); consume(t); consume(u); bool ans = compute(); if(ans) { cout << encode(s) << "\n"; cout << encode(t) << "\n"; cout << encode(u) << "\n"; } else { cout << "UNSOLVABLE\n"; } //debug(s, t, u); //ffor(i, 0, 25) m[i] = i+1; //debug(encode(string("abcdef"))); //debug(encode("12039")); //debug(encode("1293")); }
#include <iostream> #include <vector> using namespace std; int main() { int H, W, X, Y; cin >> H >> W >> X >> Y; auto S = vector<string>(H); for (int i = 0; i < H; i++) { cin >> S[i]; } // for (auto&& e : S) { // cout << e << " "; // } // cout << endl; // auto cand = vector<int>(); // auto appear = vector<int>(N + 1, -1); int ans = -3; { int x = X - 1, y = Y - 1; while (0 <= x && x < H && 0 <= y && y < W && S[x][y] == '.') { ans++; x++; } } { int x = X - 1, y = Y - 1; while (0 <= x && x < H && 0 <= y && y < W && S[x][y] == '.') { ans++; x--; } } { int x = X - 1, y = Y - 1; while (0 <= x && x < H && 0 <= y && y < W && S[x][y] == '.') { ans++; y++; } } { int x = X - 1, y = Y - 1; while (0 <= x && x < H && 0 <= y && y < W && S[x][y] == '.') { ans++; y--; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int H, W, X, Y; cin >> H >> W >> X >> Y; X = X-1; Y = Y-1; //添え字にした vector<vector<char>> data(H, vector<char>(W)); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> data.at(i).at(j); } } //2元配列入れた int count = 0; for (int i = X; i < H; i++) { if(data.at(i).at(Y) == '#'){ break; } count++; } for (int i = X; i > -1; i--) { if(data.at(i).at(Y) == '#'){ break; } count++; } for (int i = Y; i < W; i++) { if(data.at(X).at(i) == '#'){ break; } count++; } for (int i = Y; i > -1; i--) { if(data.at(X).at(i) == '#'){ break; } count++; } count = count -3; cout << count << endl; }
#include <bits/stdc++.h> using namespace std; // Pragmas #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") // Macros #define F first #define S second #define all(x) begin(x), end(x) #define allr(x) rbegin(x), rend(x) // Aliases using ll = long long; using ull = unsigned long long; using ld = long double; // Constants constexpr ll INF = 2e18; constexpr ld EPS = 1e-9; constexpr int MOD = 1e9 + 7; // :D #define int long long // Custom hash map struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; // Use int type for keys template <typename T1, typename T2> using safe_map = unordered_map<T1, T2, custom_hash>; // Operator overloads // cin >> pair<T1, T2> template<typename T1, typename T2> istream& operator>>(istream &istream, pair<T1, T2> &p) { istream >> p.first >> p.second; return istream; } // cin >> vector<T> template<typename T> istream& operator>>(istream &istream, vector<T> &v) { for (auto &it : v) cin >> it; return istream; } // cout << pair<T1, T2> template<typename T1, typename T2> ostream& operator<<(ostream &ostream, const pair<T1, T2> &p) { ostream << p.first << " " << p.second; return ostream; } // cout << vector<T> template<typename T> ostream& operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) cout << it << " "; return ostream; } // Utility functions template <typename T> void print(T &&t) { cout << t << "\n"; } template <typename T, typename... Args> void print(T &&t, Args &&... args) { cout << t << " "; print(forward<Args>(args)...); } template <typename T> int32_t size_i(T &container) { return static_cast<int32_t>(container.size()); } // Mathematical functions int GCD(int a, int b) { if (!b) return a; return GCD(b, a % b); } int LCM(int a, int b) { return (a * b) / GCD(a, b); } int modpow(ll x, int n, int m = MOD) { ll res = 1; while (n > 0) { if (n & 1) res = (res * x) % m; x = (x * x) % m; n >>= 1; } return res; } int binpow(int x, int n) { int res = 1; while (n > 0) { if (n & 1) res = res * x; x = (x * x); n >>= 1; } return res; } // @param m should be prime int modinv(int x, int m = MOD) { return modpow(x, m - 2, m); } mt19937 rng; int getRandomNumber(int l, int r) { uniform_int_distribution<int> dist(l, r); return dist(rng); } // Flags to use: -std=c++17 -O2 -Wshadow -DLOCAL_PROJECT -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -fsanitize=address -fsanitize=undefined ////////////////////////////////// START CODE HERE ////////////////////////////////// void preSolve() { rng = mt19937(chrono::steady_clock::now().time_since_epoch().count()); } void solve(int tc) { vector<int> a(3); cin >> a; sort(all(a)); print(a[1] + a[2]); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout << setprecision(3) << fixed; preSolve(); int tests = 1; // cin >> tests; for (int t = 1; t <= tests; t++) solve(t); return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; const int MAX_N = 2020; vector<int> road[MAX_N]; int N, M, A, B; int vised[MAX_N], visId; int x; ll sum; ll DFS(int s){ if(vised[s] == visId){ return 0; } vised[s] = visId; ll cnt = 1; for(auto e : road[s]){ cnt += DFS(e); } return cnt; } int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> N >> M; for(int i = 0; i < M; i++){ cin >> A >> B; road[A].emplace_back(B); } for(int i = 1; i <= N; i++){ visId = i; sum += DFS(i); } cout << sum << '\n'; return 0; }