code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <iostream> #define a1 int('A') #define a2 int('a') #define z1 int('Z') #define z2 int('z') using namespace std; int main(){ string str; bool b = true; cin >> str; for (int i = 0;i < str.size();i++){ if (i % 2 == 0 && int(str[i]) >= a2 && int(str[i]) <= z2){} else if (i % 2 == 1 && int(str[i]) >= a1 && int(str[i]) <= z1){} else b = false; } if (b) cout << "Yes"; else cout << "No"; }
#include <bits/stdc++.h> #define rep(i, x, n) for (int i = (x); i < (n); i++) #define reps(i, x, n) for (int i = (x); i <= (n); i++) #define lol long long #define SUM(n) ((n) + 1) * (n) / 2 // 1〜nまでの総和を求める式 #define mp make_pair #define fi first #define se second #define pu push_back #define SYOU(x) fixed << setprecision(x + 1) //小数点桁数を指定する #define abs(x, y) max(x, y) - min(x, y) #define all(v) v.begin(), v.end() #define UPDigit(a, b) (a + b - 1) / b //小数点切り上げ const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const int MOD = int(1e9) + 7; using namespace std; using pii = pair<int, int>; typedef vector<int> vit; //八方向を見るのに使うと便利(楽) const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1}; const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; signed main(void) { cin.tie(nullptr); ios_base::sync_with_stdio(false); string s; cin >> s; for(int i = 0;i < s.size();i += 2){ if(!('a' <= s[i] && s[i] <= 'z')){ cout << "No\n"; return 0; } } for(int i = 1;i < s.size();i += 2){ if(!('A' <= s[i] && s[i] <= 'Z')){ cout << "No\n"; return 0; } } cout << "Yes\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++) #define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--) #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define fi first #define se second #define pb push_back #define eb emplace_back using ll = long long; using vll = vector<ll>; using vi = vector<int>; using vvi = vector<vector<int>>; using P = pair<int, int>; /*** mod int ***/ // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division const int mod = 1000000007; // const int mod = 998244353; 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;} /*** mod int ここまで ***/ // combination mod prime // https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619 struct combination { vector<mint> fact, ifact; combination(int n):fact(n+1),ifact(n+1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } } comb(1000005); void Solve(){ int n, a, b; cin >> n >> a >> b; if(a+b>n) { cout << 0 << endl; return; } mint x = (mint)(n-(a+b)+2) * (mint)(n-(a+b)+1)/2; mint y = (mint)(n-a+1) * (mint)(n-b+1) - (mint)x * 2; mint ans = (mint)(n-a+1) * (mint)(n-a+1) * (mint)(n-b+1) * (mint)(n-b+1) - y * y; cout << ans << endl; } void Main(){ int t; cin >> t; while(t--) Solve(); return; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); return 0; }
//#include<math.h> #include<algorithm> #include<stdlib.h> #include<time.h> #include<stdio.h> #include<string.h> #define un unsigned #define srd srand(time(0)) #define ll long long #define con continue #define gtc getchar() #define ptc putchar #define dou double #define eps 0.00000000001 #define opr operator #define cl(x,a) memset(x,a,sizeof(x)) #define fo0(i,k) for(i=fr[k];i;i=nx[i]) #define fo1(i,l,r) for(i=l;i<=r;i++) #define fo2(i,l,r) for(i=l;i>=r;i--) #define fo(i,n) for(i=1;i<=n;i++) #define ret return #define x first #define cint const int #define y second #define opi(x) freopen(x,"r",stdin) #define opo(x) freopen(x,"w",stdout) #define tpl template<class T> #define priq priority_queue #define mp make_pair #define use using namespace #define WT while(T--) use std; typedef pair<int,int> pii;typedef pair<int,ll> pil;typedef pair<ll,int> pli;typedef pair<ll,ll> pll; namespace io { void _(int &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;} void _(ll &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;} void _(char &c){while((c=gtc)==' '||c=='\n');}void _(dou &c){scanf("%lf",&c);}void _(char *s){char c;while((c=gtc)!=EOF&&c!=' '&&c!=10)*s++=c;} template<class t1,class t2>void _(t1 &a,t2 &b){_(a);_(b);}template<class t1,class t2,class t3>void _(t1 &a,t2 &b,t3 &c){_(a);_(b);_(c);} template<class t1,class t2,class t3,class t4>void _(t1 &a,t2 &b,t3 &c,t4 &d){_(a);_(b);_(c);_(d);} template<class t1,class t2,class t3,class t4,class t5>void _(t1 &a,t2 &b,t3 &c,t4 &d,t5 &e){_(a);_(b);_(c);_(d);_(e);} void _p(dou k){printf("%.6lf",k);}void _p(char *c){for(;*c;ptc(*c++));}void _p(const char *c){for(;*c;ptc(*c++));}void _p(char c){ptc(c);} tpl void _p0(T k){if(k>=10)_p0(k/10);ptc(k%10+'0');}tpl void _p(T k){if(k<0){ptc('-');_p0(-k);}else _p0(k);}tpl void __p(T k){_p(k);ptc(' ');} tpl void _pn(T k){_p(k);ptc('\n');}template<class t1,class t2>void _p(t1 a,t2 b){__p(a);_pn(b);} template<class t1,class t2,class t3>void _p(t1 a,t2 b,t3 c){__p(a);__p(b);_pn(c);} template<class t1,class t2,class t3,class t4>void _p(t1 a,t2 b,t3 c,t4 d){__p(a);__p(b);__p(c);_pn(d);} tpl void op(T *a,int n){int i;n--;fo(i,n)__p(a[i]);_pn(a[n+1]);}int gi(){int x;_(x);ret x;}ll gll(){ll x;_(x);ret x;} } int gcd(int a,int b){ret b?gcd(b,a%b):a;}void fcl(){fclose(stdin);fclose(stdout);} void fop(const char *s){char c[256],d[256];cl(c,0);cl(d,0);strcpy(c,s);strcpy(d,s);opi(strcat(c,".in"));opo(strcat(d,".out"));} int eq(dou a,dou b){return a+eps>=b&&b+eps>=a;}tpl void _ma(T &a,T b){if(a<b)a=b;}tpl void _mi(T &a,T b){if(a>b)a=b;} cint N=2222,EE=100000000,GG=1000000000,ima=2147483647; use io; char a[1111][1111]; int fa[N],n,m,c[N],d[N],f[N],T; int fi(int k){return fa[k]=fa[k]==k?k:fi(fa[k]);} void hb(int x,int y) { x=fi(x); y=fi(y); fa[x]=y; } int main() { int i,j,a1,a2; _(n,m); fo(i,n) scanf(" %s",a[i]+1); fo(i,2111) fa[i]=i; a[1][1]=a[1][m]=a[n][1]=a[n][m]='#'; fo(i,n) fo(j,m) if(a[i][j]=='#') hb(i*2,j*2+1); fo(i,n) c[i]=fi(i*2); sort(c+1,c+n+1); fo(i,m) d[i]=fi(i*2+1); sort(d+1,d+m+1); _pn(min(unique(d+1,d+m+1)-d,unique(c+1,c+n+1)-c)-2); }
#include <iostream> #include <iomanip> #include <vector> #include <cmath> #include <algorithm> #include <deque> #include <set> #include <limits> #include <string> #include <map> #include <unordered_map> #include <unordered_set> #include <list> #include <numeric> using namespace std; using ll = long long; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) /* input & output */ #define IN(a) cin >> a #define OUT(a) cout << a << endl #define OUT_PREC(a, n) cout << fixed << setprecision(n) << a << endl /* vector */ #define VEC(t, v, n, ini) vector<t> v(n, ini) #define VEC2(t, v, m, n, ini) vector<vector<t>> v(m, vector<t>(n, ini)) #define VEC3(t, v, k, m, n, ini) vector<vector<vector<t>>> v(k, vector<vector<t>>(m, vector<t>(n, ini))) /* bit */ #define IS_TRUE(bit, i) (bit & (1 << i)) // bitのi成分 #define FLAG_ON(bit, i) (bit|(1 << i)) // bitのi成分をtrueに #define FLAG_OFF(bit, i) (bit & ~(1 << i)) // bitのi成分をfalseに #define ALL_TRUE(n) (1 << n) // 2^n #define CMPSET(bit, s) (bit ^ s) // sのbitに対する補集合 #define INCLUDES(a, b) ((a & b) == b) // aはbを含むか void solve() { double a, b, w; cin >> a >> b >> w; w *= 1000; int min = (int)ceil(w / b); int max = (int)floor(w / a); if (max < min){ cout << "UNSATISFIABLE" << endl; return; } cout << min << " " << max << endl; return; } int main() { /* solve */ solve(); system("pause"); }
#include <iostream> #include <map> #include <list> #include <set> #include <algorithm> #include <vector> #include <sstream> #include <string> #include <functional> #include <queue> #include <deque> #include <stack> #include <limits> #include <unordered_map> #include <unordered_set> #include <cmath> #include <fstream> #include <iterator> #include <random> #include <chrono> #define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i) #define set_map_includes(set, elt) (set.find((elt)) != set.end()) #define readint(i) int i; cin >> i #define readll(i) ll i; cin >> i #define readdouble(i) double i; cin >> i #define readstring(s) string s; cin >> s typedef long long ll; using namespace std; ll modd = 1000 * 1000 * 1000 + 7; int main() { ios_base::sync_with_stdio(false); cout.precision(17); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int> rand_gen(0, modd); // rand_gen(rng) gets the rand no // auto start = chrono::steady_clock::now(); // readint(test_cases); int test_cases = 1; forr(t, 1, test_cases) { readint(n); readstring(s); map<char,int> dict{{'A', 0}, {'T', 1}, {'C', 2}, {'G', 3}}; vector<vector<int>> freq(4, vector<int>(1, 0)); for(char c : s) { for(auto x : dict) { freq[x.second].push_back(freq[x.second].back() + (x.first==c)); } } int ret = 0; forr(i,0,n) { for(int j = i + 1; j <= n; ++j) { map<char,int> cand; for(auto x : dict) { cand[x.first] = freq[x.second][j] - freq[x.second][i]; } ret += ((cand['A']==cand['T']) && (cand['C']==cand['G'])); } } cout << ret << endl; } return 0; } // auto stop = chrono::steady_clock::now(); // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); // cout << "Duration: " << duration.count() << endl;
#include<bits/stdc++.h> #define rep(i,a,...) for(long long i = (a)*(strlen(#__VA_ARGS__)!=0);i<(long long)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i) #define per(i,a,...) for(long long i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(long long)(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 mod=MOD){ 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; } 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> ostream& operator<<(ostream&os, vector<t> &v){ os << "{"; for(t &i:v){ os << i << ", "; } os << "}"; return os; } template<class t = long long> 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; } string reversed(string str){ reverse(str.begin(),str.end()); return str; } long long gcd(long long a,long long b){ while(b){ a %= b; swap(a,b); } return a; } long long lcm(long long a,long long b){ return a / gcd(a,b) * b; } } using namespace templates; template <class T> vector<T> make_vector(int n,T init){ return vector<T>(n,init); } template <class... tail> auto make_vector(int n, tail... args){ return vector<decltype(make_vector(args...))>(n,make_vector(args...)); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int a = in(); int b = in(); int ans = 0; rep(i,1,b){ int l = (a+i-1)/i*i; int r = b/i*i; if(l<r){ chmax(ans,i); } } cout << ans << endl; return 0; }
#include <iostream> #include <string> #include <fstream> #include <random> #include <iomanip> #include <algorithm> #include <vector> #include <map> #include <deque> #include <map> #include <set> #include <unordered_set> #include <queue> #include <stack> #include <list> #include <unordered_map> #include <bitset> #include <sstream> #include <typeinfo> #include <iterator> //#define PRINT using ll = long long; using ull = unsigned long long; constexpr ll mop = 1000000007; constexpr ll mop2 = 998244353; using namespace std; constexpr ll NOT_SPECIFIED_VALUE_MIN = INT64_MIN; constexpr ll NOT_SPECIFIED_VALUE_MAX = INT64_MAX; int main() { ios::sync_with_stdio( false ); cin.tie( nullptr ); ll h, w; cin >> h >> w; ll sum = 0; ll minValue = NOT_SPECIFIED_VALUE_MAX; for(ll i=0;i<h;++i){ for(ll j=0;j<w;++j){ ll a; cin >> a; sum += a; if( a < minValue ) { minValue = a; } } } cout << sum - ( minValue ) * ( h * w ) << '\n'; }
// Problem: B - Visibility // Contest: AtCoder - AtCoder Beginner Contest 197(Sponsored by Panasonic) // URL: https://atcoder.jp/contests/abc197/tasks/abc197_b // Memory Limit: 1024 MB // Time Limit: 2000 ms // Disclaimer: Don't copy my template, it may lead to plagiarism. /* Author: Soumy Jain Handle: soumy_jain || soumyjain "Beautiful flowers too, eventually wither and fall. That's the fate of all living beings." "I hate perfection. To be perfect is to be unable to improve any furthur." - Mayuri Kurotsuchi | Bleach "I smile to show the pressure of heroes and to trick the fear inside of me." "Gravel may be gravel, but me? I'm the gravel that shatters diamonds." "If you were to write a story with me in the lead role, it would certainly be...a TRAGEDY." - Kaneki Ken | Tokyo Ghoul */ /******************************************************************************/ // clang-format off #include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define SPEEDHACK ios_base::sync_with_stdio(false);cin.tie(NULL); #define ff first #define ss second #define sz(v) (ll)(v).size() #define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); #define MOD 1000000007 // 998244353 using namespace std; /******************************************************************************/ void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(ll x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(ull x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template<typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template<typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define dbg(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define dbg(x...) #endif // clang-format on /***********************************MAIN***************************************/ // Are you ready to face the wrath of test cases? Good luck noob Soumy! void work() { ll h, w, x, y; cin >> h >> w >> x >> y; vector<string> v(h); for (auto &i : v) cin >> i; ll ans = 0; for (ll i = x - 1; i >= 0; i--) { if (v[i][y - 1] == '#') break; ans++; } for (ll i = x; i < h; i++) { if (v[i][y - 1] == '#') break; ans++; } for (ll i = y - 1; i >= 0; i--) { if (v[x - 1][i] == '#') break; ans++; } for (ll i = y; i < w; i++) { if (v[x - 1][i] == '#') break; ans++; } cout << ans - 1 << '\n'; } int main() { SPEEDHACK // file ll t = 1; // cin >> t; while (t--) { work(); } return 0; }
#include<bits/stdc++.h> using namespace std; int N, M; int board[105][105]; bool vis[105][105]; int dy[4] = {-1, 1, 0, 0}; int dx[4] = {0, 0, -1, 1}; int X, Y; bool valid(int y, int x) { return 1<=y && y<=N && 1<=x && x<=M; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> N >> M >> Y >> X; for(int i=1;i<=N;++i) { string s; cin >> s; for(int j=1;j<=M;++j) { board[i][j] = s[j-1] == '#'; } } int ans = 0; for(int i=0;i<4;++i) { int y = Y; int x = X; while(valid(y, x) && board[y][x] == 0) { if(!vis[y][x]) { vis[y][x] = true; ++ans; } y += dy[i]; x += dx[i]; } } cout << ans << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long long int lli; #define pb push_back #define nline "\n" #define gcd(a,b) (__gcd(a,b)) #define lcm(a,b) ((a*b)/gcd(a,b)) vector<ll> soe(ll n) {ll *arr = new ll[n + 1]; vector<ll>ans; for (ll i = 0; i <= n; i++) {arr[i] = 1;} arr[0] = 0; arr[1] = 0; for (ll i = 2; i <= sqrt(n); i++) {if (arr[i] == 1) {for (ll j = 2; i * j <= n; j++) {arr[i * j] = 0;}}} for (ll i = 0; i <= n; i++) {if (arr[i] == 1)ans.push_back(i);} return ans;} const ll mod = 1e9 + 7; /* ncr = n-1cr-1+ n-1cr */ /******************************************************************/ ll fpow(ll a, ll g) { ll ag = 1; while (g) { if (g & 1) ag = (ag * a) % mod; a = (a * a) % mod; g >>= 1; } return ag; } void solve() { string s; cin >> s; for (int i = s.length() - 1; i >= 0; i--) { if ((s[i] - '0') == 6) { cout << '9'; } else if ((s[i] - '0') == 9) { cout << '6'; } else { cout << s[i]; } } cout << nline; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("inputf.in", "r", stdin); freopen("outputf.in", "w", stdout); #endif // int test; // cin >> test; // while(test--){ solve(); // } }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, s, n) for (int i = (s); i < (int)(n); i++) int main() { string S; cin >> S; int num = S.size(); for(int i = 0 ;i < num ;i++){ if(S.at(i) == '6'){ S.at(i) = '9'; } else if(S.at(i) == '9'){ S.at(i) = '6'; } } string S_reverse (S.rbegin(), S.rend()); cout << S_reverse << endl; }
#include <bits/stdc++.h> #define rep(i,cc,n) for(int i=cc;i<=n;++i) using namespace std; vector<string> v{ "8", "16", "61", "24", "42", "32", "23", "48", "84", "56", "65", "64", "46", "72", "27", "88", "96", "69" }; bool Solve(string s) { if (find(v.begin(), v.end(), s) != v.end()) return true; sort(s.begin(), s.end()); rep(i,13,124) { string t = to_string(i * 8); sort(t.begin(), t.end()); if (s.find(t) != string::npos) return true; } return false; } int main() { string s; cin >> s; if (Solve(s)) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 0x7fffffff typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<char> vc; typedef vector<double> vd; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<ld> vld; #define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define pb push_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define sz(x) (int)x.size() #define beg(x) x.begin() #define en(x) x.end() int main() { fastIO; set<vi> S, S2, S3; for(int i = 16; i < 100; i += 8) { int a, b; vi v(10,0); a = i % 10; v[a]++; b = i / 10; v[b]++; S2.insert(v); } for(int i = 0; i < 1000; i += 8) { int a, b, c; vi v(10,0); a = i % 10; v[a]++; b = i / 10 % 10; v[b]++; c = i / 100; v[c]++; // for(int j = 0; j < 10; j++) printf("v[%d] = %d\n", j, v[j]); // cout << endl; S.insert(v); } // for(auto x : S) // { // for(int i = 0; i < 10; i++) // cout << x[i] << ' '; // cout << endl; // } string s; cin >> s; int cnt[10] = {0}; for(int i = 0; i < s.length(); i++) cnt[s[i] - '0']++; if(s.length() == 1) printf("%s\n", cnt[8] == 1 ? "Yes" : "No"); else if(s.length() == 2) { if(cnt[1] & cnt[6] | cnt[2] & cnt[4] | cnt[3] & cnt[2] | cnt[4] & cnt[0] | cnt[4] & cnt[8] | cnt[5] & cnt[6] | cnt[6] & cnt[4] | cnt[7] & cnt[2] | cnt[8] & cnt[0] | cnt[8] == 2 | cnt[9] & cnt[6]) cout << "Yes" << endl; else cout << "No" << endl; } else { for(auto x : S) { int k = 1; for(int i = 0; i < 10; i++) if(cnt[i] < x[i]) k = 0; if(k) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) const ll MAX = 1001001; const ll MOD = 1000000007; const double pi = 2.0 * asin(1.0); ll dx[4] = {1, 0, -1, 0}; ll dy[4] = {0, 1, 0, -1}; int main() { ll h, w, a, b; cin >> h >> w >> a >> b; if (h < w) { swap(h, w); } ll ans = 0; for (int tmp = 0; tmp < (1 << (h * w)); tmp++) { bitset<16> s(tmp); ll co = 0; vector<vector<bool>> c(h, vector<bool>(w)); rep(i, h * w) { if (s.test(i)) { co++; c[i / w][i % w] = true; } } if (co != b) { continue; } vector<ll> crt((1 << w)); vector<ll> next((1 << w)); crt[0] = 1; for (ll i = h - 1; i >= 0; i--) { for (ll j = w - 1; j >= 0; j--) { rep(u, (1 << w)) { if ((u >> j & 1) || (c[i][j])) { next[u] = crt[u & ~(1 << j)]; } else { ll res = 0; if (j + 1 < w && !(u >> (j + 1) & 1) && !c[i][j + 1]) { res += crt[u | 1 << (j + 1)]; } if (i + 1 < h && !c[i + 1][j]) { res += crt[u | 1 << j]; } next[u] = res; } } swap(crt, next); } } ans += crt[0]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repr(i, n) for (ll i = (n-1); i >= 0; i--) #define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) template <class S>S sum(vector<S>& a) {return accumulate(all(a), S());} template <class S>S max(vector<S>& a) {return *max_element(all(a));} template <class S>S min(vector<S>& a) {return *min_element(all(a));} ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); } ll min(int a, ll b) { return min((ll)a, b); } ll min(ll a, int b) { return min(a, (ll)b); } #define VM 10 void eprint() { cerr << endl; } template <class First, class... Rest> void eprint(First f, Rest... r) { cerr << f << ' '; eprint(r...); } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { size_t output_num = v.size(); bool is_omitted = false; #ifdef VM if (VM < output_num) { output_num = VM; is_omitted = true; } #endif os << "["; for (size_t i = 0; i < output_num - 1; i++) os << v[i] << ", "; os << v[output_num - 1]; if (is_omitted) os << ", ..."; return os << "]"; } template <class S, class T> ostream& operator<<(ostream& os, const map<S,T>& m) { os << "{\n"; for(auto [k,v]: m){ os << k << ": " << v << ",\n"; } return os << '}'; } void Main(); int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); Main(); return 0; } using Heya = vector<vector<bool>>; vector<pair<Heya,int>> patterns; int h, w, a; void dfs(Heya heya, int row, int used){ if(used > a) return; if(row == h){ patterns.push_back(make_pair(heya, used)); return; } if(w == 2){ auto h1 = heya; h1[row][0] = true; h1[row][1] = true; dfs(heya, row+1, used); dfs(h1, row+1, used+1); }else if(w == 3){ auto h1 = heya; auto h2 = heya; h1[row][0] = true; h1[row][1] = true; h2[row][1] = true; h2[row][2] = true; dfs(heya, row+1, used); dfs(h1, row+1, used+1); dfs(h2, row+1, used+1); }else{ auto h1 = heya; auto h2 = heya; auto h3 = heya; auto h4 = heya; dfs(heya, row+1, used); h1[row][0] = true; h1[row][1] = true; h1[row][2] = true; h1[row][3] = true; dfs(h1, row+1, used+2); h2[row][0] = true; h2[row][1] = true; dfs(h2, row+1, used+1); h3[row][1] = true; h3[row][2] = true; dfs(h3, row+1, used+1); h4[row][2] = true; h4[row][3] = true; dfs(h4, row+1, used+1); } } ll ans; void dfs_col(Heya heya, int row, int col, int used){ if(used > a) return; if(col == w){ if(used == a){ ans++; } return; } for(int i = row; i < h-1; i++){ if(!heya[i][col] && !heya[i+1][col]){ auto h1 = heya; h1[i][col] = true; h1[i+1][col] = true; dfs_col(h1, i+2, col, used+1); } } dfs_col(heya, 0, col+1, used); } void Main(){ cin >> h >> w >> a; ans = 0; if(h < w) swap(h, w); // h > w if(w > 1){ dfs(vector<vector<bool>>(h, vector<bool>(w, false)), 0, 0); }else{ patterns.push_back(make_pair(vector<vector<bool>>(h, vector<bool>(w, false)), 0)); } for(auto [p, u]: patterns){ dfs_col(p, 0, 0, u); } cout << ans << endl; }
#include <iostream> #include <iomanip> #include <algorithm> #include <assert.h> #include <complex> #include <utility> #include <vector> #include <string> #include <stack> #include <queue> #include <tuple> #include <cmath> #include <bitset> #include <cctype> #include <set> #include <map> #include <unordered_map> #include <numeric> #include <functional> #include <chrono> #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=a;i<b;++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define _rrep(i,a) rrepi(i,a,0) #define rrepi(i,a,b) for(int i=a-1;i>=b;--i) #define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__) #define all(x) (x).begin(),(x).end() #define PRINT(V) cout << V << "\n" #define SORT(V) sort((V).begin(),(V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) using namespace std; using ll = long long; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); } template<class itr> void cins(itr first,itr last){ for (auto i = first;i != last;i++){ cin >> (*i); } } template<class itr> void array_output(itr start,itr goal){ string ans = "",k = " "; for (auto i = start;i != goal;i++) ans += to_string(*i)+k; if (!ans.empty()) ans.pop_back(); PRINT(ans); } ll gcd(ll a, ll b) { return a ? gcd(b%a,a) : b; } const ll INF = 1e18; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll MOD3 = 1e6; const ll EPS = 1e-10; int sgn(const double a){ return (a < -EPS ? -1 : (a > EPS ? +1 : 0)); } typedef pair<int,int> pi; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> tri; typedef pair<double,double> point; typedef complex<double> Point; typedef string::const_iterator State; const ll MAX = 105; constexpr ll nx[4] = {-1,0,1,0}; constexpr ll ny[4] = {0,1,0,-1}; int main(){ int n; cin >> n; vector<int> a(n); cins(all(a)); map<int,int> t; int mi = 1e9; rep(i,n){ chmin(mi,a[i]); rep(j,1,sqrt(a[i])+1){ if (a[i]%j != 0) continue; if (t[j] == 0){ t[j] = a[i]; } else{ t[j] = gcd(t[j],a[i]); } int m = j; j = a[i]/m; if (t[j] == 0){ t[j] = a[i]; } else{ t[j] = gcd(t[j],a[i]); } j = m; } } int ans = 0; //PRINT(mi); for (auto [c,d]:t){ if (c > mi) break; if (c == d) ans++; //PRINT(c << " " << d); } PRINT(ans); }
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ vector<char> a(12); for(int i=0;i<12;i++){ cin >> a.at(i); } int c=0; for(int i=0;i<12;i++){ if(a.at(i)=='Z' && a.at(i+1)=='O' && a.at(i+2)=='N' && a.at(i+3)== 'e'){ c++; } } cout << c; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)n;++i) #define REP(i,a,b) for(int i=int(a);i<(int)b;++i) #define vi vector<int> #define vvi vector<vector<int>> #define vl vector<ll> #define vvl vector<vector<ll>> #define vp vector<pair<ll,ll>> #define pb push_back #define all(v) v.begin(),v.end() using namespace std; using ll = long long; const ll INF = 1e18; const double PI = acos(-1); 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; } int main(void){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int n; cin >> n; vi p(n),dif(n); ll num = 0; vi ans(n),ta(200000); set<int> se; rep(i,n){ cin >> p[i]; se.insert(p[i]); ta[p[i]]++; } int i = 0; while(true){ if(se.count(i) == 0){ ans[n-1] = i; break; } ++i; } for(int j = n-2;j >= 0; --j){ ta[p[j+1]]--; if(p[j+1] < ans[j+1] && !ta[p[j+1]]){ ans[j] = p[j+1]; }else{ ans[j] = ans[j+1]; } } rep(i,n){ cout << ans[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vl; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<char> vc; typedef queue<ll> ql; typedef deque<ll> dql; typedef priority_queue<ll> pql; typedef set<ll> sl; typedef pair<ll, ll> pl; typedef vector<vl> vvl; typedef vector<pl> vpl; #define rep(i, n) for(ll i = 0; i < ll(n); i++) #define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++) #define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--) #define all(v) (v).begin(), (v).end() ll mod(ll a, ll b) {return (a % b + b) % b;} ll quo(ll a, ll b) {return (a - mod(a, b)) / b;} template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;} template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;} const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; //const ll MOD = 998244353; const ll MAX = 2e5; const ld eps = 1e-9; const char newl = '\n'; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, x, c; cin >> n; vl l(n, INF), r(n, -INF); rep(_, n) { cin >> x >> c; c--; chmin(l[c], x); chmax(r[c], x); } pl tmpl = pl(0, 0), tmpr = pl(0, 0); rep(i, n) { if(l[i] > r[i]) continue; pl L = pl(l[i], 0), R = pl(r[i], 0); L.second = min(tmpl.second + abs(tmpl.first - r[i]), tmpr.second + abs(tmpr.first - r[i])) + abs(r[i] - l[i]); R.second = min(tmpl.second + abs(tmpl.first - l[i]), tmpr.second + abs(tmpr.first - l[i])) + abs(l[i] - r[i]); tmpl = L; tmpr = R; } cout << min(abs(tmpl.first) + tmpl.second, abs(tmpr.first) + tmpr.second) << newl; return 0; }
#include <bits/stdc++.h> #define ll long long #define sf scanf #define pf printf #define nl printf("\n") #define pb push_back #define TEST int Test;cin>>Test;for(int _t=1;_t<=Test;_t++) using namespace std; int main() { int a,b; sf("%d %d",&a,&b); int ans = (2*a)+100 - b; pf("%d\n",ans); return 0; }
// JG GAP GG #include <iostream> #include <cstring> #include<vector> #include <algorithm> #include<cstdlib> #include<set> #include<math.h> #include<map> #include<unordered_map> #include<iomanip> #include<queue> #include<bitset> using namespace std; using ll = long long; using ull = unsigned long long; const ll MOD = 1000000007; #define rep(n,x) for(ll i=0;i<n;i++) cin>>x[i]; #define forr(a,b) for(ll i=a;i<b;i++); #define vecsort(myVec,x,y) sort(myVec.begin(),myVec.end(),[](const vector<y> &alpha,const vector<y> &beta){return alpha[x] < beta[x];}); #define vsort(v) sort(v.begin(),v.end()); #define vdownsort(v) sort(v.begin(),v.end(),greater<ll>()); ll modpow(ll a, ll n, ll mod) { ll res = 1; while (0 < n) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int a, b; cin >> a >> b; cout << 2 * a + 100 - b << endl; return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; signed main() { int n; cin>>n; int a[n+1]; int sum=0,tot=0; for(int i=1;i<=n;i++){ cin>>a[i]; sum+=a[i]; } for(int i=1;i<=n;i++){ tot+=(n-1)*a[i]*a[i]; tot-=a[i]*(sum-a[i]); } cout<<tot; return 0; }
#include <bits/stdc++.h> #define x first #define y second using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int, int> PII; typedef pair<double, double> PDD; const int N = 210; map<int, int> cnt; int main() { int n; cin >> n; for (int i = 1; i <= n; i ++ ) { int x; cin >> x; cnt[x] ++; } LL ans = 0; for (int i = -200; i <= 200; i ++ ) for (int j = i + 1; j <= 200; j ++ ) ans += (LL)cnt[i] * cnt[j] * (j - i) * (j - i); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define pb emplace_back #define mp make_pair #define fi first #define se second #define all(v) v.begin(),v.end() #define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0); #define LL_MAX LLONG_MAX #define ub(v,x) upper_bound(v.begin(),v.end(),x) #define lb(v,x) lower_bound(v.begin(),v.end(),x) #define mod 1000000007 int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;} int modinv(int x){return exp(x,mod-2);} int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;} int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;} int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;} int fac[1000009];int ncr_mod(int n,int k){int ans=fac[n];ans*=modinv(fac[k]);ans%=mod;ans*=modinv(fac[n-k]);ans%=mod;return ans;} vector<int>v_prime;void Sieve(int n){bool prime[n + 1];memset(prime,true,sizeof(prime));for (int p = 2; p*p <=n;p++){if(prime[p] ==true) {for(int i = p*p; i<= n; i += p)prime[i]=false;}}for(int p = 2;p<= n;p++)if (prime[p])v_prime.pb(p);} vector<int>v_factor;void factor(int n){ for (int i=1; i<=sqrt(n); i++) {if (n%i == 0) {if (n/i == i) v_factor.pb(i);else { v_factor.pb(i),v_factor.pb(n/i);};} } sort(all(v_factor)); } int power(int x, int y){int temp;if( y == 0)return 1; temp = power(x, y / 2);if (y % 2 == 0) return temp * temp;else return x * temp * temp;} int gcd(int a, int b){if (b == 0)return a; return gcd(b, a % b);} int log2n( int n){ return (n > 1) ? 1 + log2n(n / 2) : 0;} void out(vector<int>&a){for(int i=0;i<a.size();i++) cout<<a[i]<<" "; cout<<endl;} void sout(set<int>s){for(auto it=s.begin();it!=s.end();++it)cout<<*it<<" "; cout<<endl;} void mout(map<int,int>mm){for(auto it=mm.begin();it!=mm.end();++it) cout<<it->fi<<" "<<it->se<<endl;} #define ms(a,x) memset(a, x, sizeof(a)); #define decimal(n,k) cout<<fixed<<setprecision(k)<<n<<endl #define yes cout<<"YES"<<endl #define no cout<<"NO"<<endl // In binary search always report l-1 signed main() { run; /* open for mod factorial fac[0]=1; for(int i=1;i<1000009;i++) { fac[i]=mul(fac[i-1],i); } */ /* for sieve open this and use v_prime int pp=pow(10,6)+100000; Sieve(pp); */ // factor(n) && USE v_factor For calculating factors && don't forget v_factor.clear(); int t=1; //cin>>t; while(t--) { // map<int,int>mm; // it->second-->frequency int n,i,x,y,ok=0,sum=0,ans=0,j,k,cnt=0,m,c=0; int h[100009]={0}; cin>>n; string s1,s2;cin>>s1>>s2; vector<int>v1,v2; for(i=0;i<n;i++) { if(s1[i]=='0') { v1.pb(i); } if(s2[i]=='0') { v2.pb(i); } } if(v1.size()!=v2.size()) { ans=-1; } else { for(i=0;i<v1.size();i++) { if(v1[i]!=v2[i]) ans++; } } cout<<ans<<endl; } }
#include <bits/stdc++.h> using namespace std; #define f(i,n) for(i=0;i<n;i++) #define fr(i,n,a) for(i=n;i>=a;i--) #define fa(i,a,n) for(i=a;i<n;i++) #define deb(x) cout<<#x<<" "<<x<<endl; #define deb2(x,y) cout<<#x<<","<<#y<<" "<<x<<","<<y<<endl; #define buf(x) cout<<"Check"<<x<<endl; #define ll long long int #define ft first #define s second #define pb push_back #define mp make_pair #define do double #define all(v) v.begin(),v.end() #define et(v) for(auto itr:v) #define mod 1000000007 inline void p(vector<ll> x,int n) { int i;f(i,n)cout<<x[i]<<" ";cout<<endl; } void solve() { ll N,M,i,j,sum=1,pos,neg=0,z=0; ll x,y,k; cin>>N; string s; cin>>s; vector<ll> arr(N); f(i,N) { if(s[i]=='A') arr[i]=1; else if(s[i]=='T') arr[i]=-1; else if(s[i]=='G') arr[i]=10000; else { arr[i]=-10000; } } map<ll,ll> p; ll res = 0; ll curr = 0; f(i,N) { curr += arr[i]; if (curr == 0) res++; if (p.find(curr) != p.end()) res += (p[curr]); p[curr]++; } cout<<res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t=1,c=1; //cin>>t; while(t--) { //cout<<"Case #"<<c++<<": "<<endl; solve(); cout<<"\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct Node { int v; ll T, K; ll t = LLONG_MAX; Node(int v, ll T, ll K) : v(v), T(T), K(K) {} }; struct Data { int v; ll t = LLONG_MAX; Data(int v, ll t) : v(v), t(t) {} bool operator < (const Data &d) const { return d.t < t; } }; int main() { int N, M, X, Y; cin >> N >> M >> X >> Y; X--; Y--; int A[M], B[M]; ll T[M], K[M]; vector<Node> adj[N]; for (int i = 0; i < M; i++) { cin >> A[i] >> B[i] >> T[i] >> K[i]; A[i]--; B[i]--; adj[A[i]].push_back(Node(B[i], T[i], K[i])); adj[B[i]].push_back(Node(A[i], T[i], K[i])); } ll d[N]; fill(d, d + N, LLONG_MAX); d[X] = 0; priority_queue<Data> pq; pq.push(Data(X, 0)); bool vis[N] = {}; while (!pq.empty()) { int v = pq.top().v; pq.pop(); if (vis[v]) continue; vis[v] = true; for (Node i : adj[v]) { ll t = i.K * ((d[v] + i.K - 1) / i.K) + i.T; if (t < d[i.v]) { d[i.v] = t; pq.push(Data(i.v, t)); } } } if (d[Y] == LLONG_MAX) { cout << "-1\n"; } else { cout << d[Y] << "\n"; } return 0; }
#include "bits/stdc++.h" #define ll long long #define chl_jldi ios_base::sync_with_stdio(false); cin.tie(0) #define mnpqll priority_queue<long long, vector<long long>, greater<long long> > #define mxpqll priority_queue<long long> #define pb push_back #define mp make_pair #define pll pair<ll,ll> #define ff first #define ss second #define uset unordered_set #define pnl cout<<"\n" #define isodd(xz2) (xz2&1) #define umap unordered_map using namespace std; ll add_mod(ll a,ll b,ll m){return ((((a%m)+(b%m))%m + m)%m);} ll subs_mod(ll a,ll b,ll m){return ((((a%m)-(b%m))%m + m)%m);} ll mult_mod(ll a,ll b,ll m){return ((((a%m)*(b%m))%m + m)%m);} 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 power_mod(ll x, ll y,ll mod){ ll res = 1; while (y > 0) { if (y & 1) res = mult_mod(res, x,mod); y = y >> 1; x = mult_mod(x,x,mod);}return res;} ll test=1; const ll mod=1000000007; void test_case(){ // cin>>test; } //================================================================================================================================================================// void solve(){ //cout<<"error"; ll a,b,c,d; cin>>a>>b>>c>>d; ll red=0; ll blue=a; ll ans=0; while(ans<=(a)){ if(d*red>=blue) {cout<<ans<<"\n"; return;} blue+=b; red+=c; ans++; } cout<<"-1\n"; //cout<<"error"; return;} int main(){ chl_jldi; #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); freopen("error.txt","w",stderr); #endif test_case(); ll koko=1; while(koko<=test){ // cout<<"Case #"<<koko<<": "; solve(); // pnl; koko++; }return 0;}
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<long long>; using vvl = vector<vector<long long>>; #define rep(i, s, n) for (int i = (int)s; i < (int)n; i++) #define repr(i, n, s) for (int i = (int)n; (int)s < i; i--) #define len(a) (int)a.size() #define all(a) a.begin(), a.end() /* 1次元ベクトルをスペースでつなぎ、改行をつけて出力 vi, vl, list<int>, list<ll>に対応 */ template<class T> void print_elements(T a) {string str = ""; for (auto itr = a.begin(); itr != a.end(); ++itr) \ {str += to_string(*itr) + ' ';} str.pop_back(); cout << str << endl;} const int INF32 = 1 << 29; const long long INF64 = 1LL << 60; const long long MOD = 1000000009; const double PI = acos(-1); int main() { int N; cin >> N; double ans = 0.0; rep(k, 1, N) { ans += 1.0 * N / (N - k); } cout <<fixed << setprecision(11) << ans << endl; }
#include<bits/stdc++.h> #include<algorithm> #include<cmath> #include<climits> using namespace std; typedef long long int lli; typedef vector<int> vi; typedef vector<long long int> vlli; typedef pair<int,int> pii; typedef pair<long long int,long long int> plli; typedef vector< vi > vvi ; typedef vector< vlli > vvlli ; #define fi(i,a,b) for(int i=a;i<=b;i++) #define flli(i,a,b) for(long long int i=a;i<=b;i++) #define bi(i,a,b) for(int i=a;i>=b;i--) #define blli(i,a,b) for(long long int i=a;i>=b;i--) #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) #define all(x) x.begin(),x.end() #define sz(x) x.size() #define pi 2*acos(0.0) #define pb push_back #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++) #define present(v,num) (v.find(num)!=v.end()) #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end()) #define pq priority_queue #define mp make_pair const int inf=INT_MAX; const lli INF =LLONG_MAX; const lli mod = 1e9+7; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast; string s;cin>>s; deque<char> a; bool flag=true; lli n=sz(s); flli(i,0,n-1) { if(s[i]=='R') { flag=flag^true; } else { if(flag) { if(a.empty()) { a.push_back(s[i]); continue; } auto vari=a.rbegin(); if(*vari!=s[i]) a.push_back(s[i]); else a.pop_back(); } else { if(a.empty()) { a.push_front(s[i]); continue; } auto vari=a.begin(); if(*vari!=s[i]) a.push_front(s[i]); else a.pop_front(); } } } string t; while(!a.empty()) { auto vari=a.begin(); t.pb(*vari); a.pop_front(); } if(!flag)reverse(all(t)); tr(t,it)cout<<*it; cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> #define clr(x) memset((x), 0, sizeof(x)) #define all(x) (x).begin(), (x).end() #define pb push_back #define mp make_pair #define For(i, st, en) for(int i=(st); i<=(int)(en); i++) #define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--) #define forn(i,m,n) for(int i=m; i<(int)(n); i++) #define forn2(i, n) for(int i=0; i<=(int)(n); i++) #define ford(i, n) for(int i=(n)-1; i>=0; i--) #define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++) #define in(x) int (x); input((x)); #define x first #define y second #define less(a,b) ((a) < (b) - EPS) #define more(a,b) ((a) > (b) + EPS) #define eq(a,b) (fabs((a) - (b)) < EPS) #define remax(a, b) ((a) = (b) > (a) ? (b) : (a)) #define remin(a, b) ((a) = (b) < (a) ? (b) : (a)) #define salfinal(x) cout<<x<<endl; using namespace std; const int MAX =1e5+1; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); /* freopen("s.txt","r",stdin); freopen("sa.txt","w",stdout); */ int ent,remover; cin>>ent>>remover; vector<int>v(ent); for(int &i:v)cin>>i; if(v[0]!=remover)cout<<v[0]; forn(i,1,ent)if(v[i]!=remover)cout<<" "<<v[i]; cout<<"\n"; return 0; }
#include<bits/stdc++.h> #define ll long long int #define pragi(a,b) for(ll i = a;i<b;i++) #define pragj(a,b) for(ll j = a;j<b;j++) #define pragk(a,b) for(ll k = a;k>=b;k--) #define all(v) (v.begin(),v.end()) #define eb emplace_back #define lb lower_bound #define ub upper_bound #define MP make_pair #define MT make_tuple #define F first #define S second #define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; const int mod = 1e9 + 9; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<bool> vb; typedef long double ld; typedef pair<int, int> pii; //typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<vvl> vvvl; typedef pair<ll, ll> pll; int main() { KAKA ll n; cin>>n; vector<ll> a(n),b(n); pragi(0,n) { cin>>a[i]; } pragi(0,n) { cin>>b[i]; } ll sum = 0; pragi(0,n) { sum += (a[i] * b[i]); } if(sum == 0) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n"; }
//#include <bits/stdc++.h> #include <iostream> #include <vector> #include <functional> #include <algorithm> #include <map> #include <cstdio> #include <cmath> #include <iomanip> #include <queue> using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) #define vi vector<int> #define vll vector<long long> #define vb vector<bool> #define vs vector<string> #define all(x) x.begin() , x.end() #define pb push_back #define eb emplace_back #define chmax(x,y) (x) = max((x) , (y)) #define chmin(x,y) (x) = min((x) , (y)) #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef long double ld; //const int MOD = int(1e9) + 7; //const int MOD = 998244353; //const ll MOD = ll(1e9) + 7; const ll MOD = 998244353; const ld PI = 3.1415926535897932384626; const int INF = 1001001001; const ll LINF = 1001001001001001001; const int MX = 220000; ll modpow (ll x , ll p) { ll ret = 1; while (p) { if (p % 2 == 1) { ret *= x; ret %= MOD; } x *= x; x %= MOD; p /= 2; } return ret; } vll fact(MX); vll factinv(MX); void init_fact () { fact[0] = 1; for (int i = 1; i < MX; i++) { fact[i] = 1LL * i * fact[i - 1] % MOD; } for (int i = 0; i < MX; i++) { factinv[i] = modpow(fact[i] , MOD - 2); } } bool is_prime (int x) { if (x == 2 || x == 3 || x == 5 || x == 7) { return true; } for (ll i = 2; i*i <= x; i++) { if (x % i == 0) { return false; } } return true; } vb prime_table(MX , true); void init_prime() { for (int i = 2; i < MX; i++) { for (int j = i + i; j < MX; j += i) { prime_table[j] = false; } } return; } vector<int> factrization(ll x) { vector<int> ret; for (int i = 2; i*i <= x; i++) { while (x % i == 0) { ret.pb(i); x /= i; } } if (x > 1) ret.pb(x); sort(all(ret)); return ret; } ll moddiv (ll a , ll b) { return a * modpow(b , MOD - 2) % MOD; } ll modsub (ll a , ll b) { if (a >= b) return (a - b) % MOD; else return (MOD - a + b); } ll nCk (ll n , ll k) { return ((fact[n] * factinv[k] % MOD) * factinv[n - k] % MOD); } ll nHk (ll n , ll k) { return nCk(n - 1 + k , k); } // 仕切り- 1 + boll を並べる組み合わせ ll gcd (ll a , ll b) { if (a < b) swap(a , b); if (a % b == 0) return b; else return gcd(b , a % b); } ll lcm (ll a , ll b) { return a / gcd(a , b) * b; } ll lin() { ll x; scanf("%lld" , &x); return x; } int in() { int x; scanf("%d" , &x); return x; } bool is_palindrome (string s) { string t = s; reverse(all(t)); return (s == t); } void io_setup() { cout << fixed << setprecision(20); } void solve () { ll a , b; cin >> a >> b; ll ans = 1; for (int i = 1; i <= b; i++) { ll x = (a + i - 1) / i; if (a <= i * x && i * (x + 1) <= b) { chmax(ans , (ll)i); } } cout << ans << endl; return; } int main() { io_setup(); //init_fact(); //init_prime(); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<long long >>; int main(){ int A,B; cin >> A >> B; if(A*2<=B){ cout << B/2 << endl; }else{ int res = B-A; for(int i=res;i>=1;i--){ if(B%i==0&&A%i==0){ res = i; break; } else if(A%i==0&&B/i==A/i+1){ res = i; break; } else{ if(B/i-2==A/i){ res = i; break; } } } cout << res << endl; } }
#include<bits/stdc++.h> #include<chrono> using namespace std; using namespace chrono; typedef long long ll; typedef long long int lli; #define arrsize 100001 #define dpsize 1001 #define vpp vector<PP> #define vll vector<ll> #define vcc vector<char> #define endl "\n" #define vbb vector<bool> #define w(t) while(t--) #define PP pair<ll,ll> #define test(x) ll t; cin>>t; w(t) x() #define __lb lower_bound #define __ub upper_bound #define szs(x) x.length() #define szv(x) x.size() #define INF 1999999996000000010 #define takeINP(arr,n) for(long long i=0;i<n;i++) cin>>arr[i]; #define f(i,s,e) for(long long i=s;i<e;i++) #define ef(i,s,e) for(long long i=s;i<=e;i++) #define rf(i,e,s) for(long long i=e-1;i>=s;i--) #define mem(arr) memset(arr,-1,sizeof(arr)); #define rsz(x,n) x.resize(n) #define rsr(x,n) x.reserve(n) #define float long long double #define pb push_back #define print(arr,s,e) f(i,s,e) cout<<arr[i]<<" "; cout<<endl; #define all(v) v.begin(),v.end() #define ff first #define ss second #define vll vector<ll> #define triplet pair<ll,pair<ll,ll> > #define MITR(a,b) map<a,b>::reverse_iterator lli M=1000000007; lli mod(lli a) { return ((a%M+M)%M);} lli add(lli a,lli b) { return mod(mod(a)+mod(b));} lli multiply(lli a,lli b) { return mod(mod(a)*mod(b));} lli min(lli a,lli b) { if(a<b) return a; return b;} lli max(lli a,lli b) { return (a>b)?a:b;} lli modexpo(lli a,lli b){ lli res = 1; while(b>0){ if(b&1) res = (res*a)%M; a = (a*a)%M; b/=2; } return res; } lli mulmod(lli a, lli b, lli mod) { lli res = 0; // Initialize result a = a % mod; while (b > 0) { // If b is odd, add 'a' to result if (b % 2 == 1) res = (res + a) % mod; // Multiply 'a' with 2 a = (a * 2) % mod; // Divide b by 2 b /= 2; } // Return result return res % mod; } lli binPower(lli a , lli n , lli mod) { lli res = 1; while(n) { if(n & 1) res = mulmod(res , a , mod); n >>= 1; a = mulmod(a , a , mod); } return res % mod; } class Line{ public: double slope; double c; Line(double slope=0,double c=0){ this->slope=slope; this->c=c; } }; int divisor[1000005]; void solve(){ ll n,k; cin>>n>>k; vll arr(n); map<ll,ll> map; ll maxe=0; f(i,0,n) cin>>arr[i],map[arr[i]]++,maxe=max(maxe,arr[i]); sort(all(arr)); ll ans=0; ll ls=0; for(ll i=0;i<maxe+1;i++){ // cout<<i<<":"<<map[i]<<" "; if(map[i]<k){ ans+=(k-map[i])*i; // cout<<e.first<<" "; k=map[i]; } ls=i+1; } if(k>0){ ans+=k*ls; } cout<<ans<<"\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); solve(); // sieve(); // int t; // cin>>t; // while(t--) solve(); return 0; }
#include <iostream> #include <vector> #include <utility> #include <algorithm> #include <queue> using namespace std; typedef pair<int,int> ii; int fr[300010]; int main(){ cin.tie(0); ios_base::sync_with_stdio(0); int n,k; cin>>n>>k; long long res=0; int a; for(int i=0;i<n;i++){ cin>>a; fr[a]++; } int it=0; while(k){ k = min(k,fr[it]); it++; res+=k; } cout<<res<<endl; return 0; }
#include <bits/stdc++.h> namespace IO{ char buf[1000000],*p1,*p2; inline char getc(){ if(p1==p2) p2=(p1=buf)+fread(buf,1,10,stdin); return p1==p2?EOF:*(p1++); } template<typename tp>inline void r(tp &n){ n=0;char c=getc();int f=1; while(!isdigit(c)&&c!='-') c=getc(); if(c=='-') f=-1,c=getc(); while( isdigit(c)) n=n*10+c-48,c=getc(); n*=f; } template<typename tp>inline void w(tp n){ if(n/10) w(n/10); putchar(n%10+48); } }; using namespace IO; const int N=2e5+5,M=2e5+5; using namespace std; int n,m,num; int vis[N],head[N],nt[M<<1],to[M<<1]; long long a[N],b[N],tota,totb; void Add(int x,int y){ ++num;nt[num]=head[x];head[x]=num;to[num]=y; ++num;nt[num]=head[y];head[y]=num;to[num]=x; } void DFS(int p){ vis[p]=1;tota+=a[p],totb+=b[p]; for(int i=head[p];i;i=nt[i]) if(!vis[to[i]]) DFS(to[i]); } int main(){ //freopen("1.in","r",stdin); r(n),r(m); for(int i=1;i<=n;++i) r(a[i]); for(int i=1;i<=n;++i) r(b[i]); for(int i=1,x,y;i<=m;++i) r(x),r(y),Add(x,y); for(int i=1;i<=n;++i){ if(vis[i]) continue; tota=0;totb=0;DFS(i); if(tota!=totb) puts("No"),exit(0); } puts("Yes"); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; ll sum[200005]; struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} void init(int n) { par.assign(n, -1); } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; int main() { long long N, M; cin >> N >> M; vector<ll> A(N), B(N); rep(i, N) cin >> A[i]; rep(i, N) cin >> B[i]; vector<int> C(M), D(M); for (int i = 0; i < M; ++i) { cin >> C[i]; cin >> D[i]; --C[i], --D[i]; } rep(i, N) sum[i] = 0; UnionFind uf(N); rep(i, M) { uf.merge(C[i], D[i]); } rep(i, N) { int root_i = uf.root(i); if (root_i < 0) sum[i] += B[i] - A[i]; else sum[root_i] += B[i] - A[i]; } rep(i, N) { if (sum[i] != 0) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; }
#include <iostream> #include <stdio.h> #include <cstring> #include <cstdio> #include <math.h> #include <algorithm> #include <vector> #include <string> #include <stdlib.h> #include <queue> #include <stack> #include <utility> #include <fstream> //#include <random> #include <map> //#include <unordered_map> #include <cstdlib> #include <functional> #include <time.h> //#include <chrono> #include <sstream> #include <iomanip> #include <numeric> #include <iostream> #include <limits> #include <numeric> //#include <type_traits> #define rep(i,n) for(int i=0;i<n;i++) #define rrep(i,n) for(int i=n-1;i>=0;i--) #define FOR(i,a,b) for(int i=a;i<b;i++) #define ll long long #define INF 1000000001 #define MOD 1000000007 #define SORT(s) sort(s.begin(), s.end()); #define REVERSE(s) reverse(s.begin(), s.end()); #define SUM(s) accumulate(s.begin(), s.end(), 0LL); #define P pair<int,int> #define mp make_pair #define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w) //#define int ll int dx[4] = { 0,1,0,-1 }; int dy[4] = { 1,0,-1,0 }; int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 }; int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 }; double pi = 3.141592653589793; using namespace std; int POW(int x, int y) { return int(pow(double(x), double(y))); } double log(double a, double b) { return log(b) / log(a); } int main() { ll n; cin >> n; int sq = sqrt(n); vector<ll> ans; FOR(i, 1, sq + 1) { if (n % i == 0) { ll x = n / i; if (x == i) { ans.push_back(i); } else if (x < i) { } else { ans.push_back(i); ans.push_back(x); } } } SORT(ans); rep(i, ans.size()) { cout << ans[i] << endl; } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const char nl = '\n'; template <class T> ostream &operator <<(ostream &os, const vector<T>&v) { for(auto& x:v)os << x << " "; return os; } template <class a, class b> ostream &operator <<(ostream &os, const pair<a,b>&p) { os << "(" << p.first << "," << p.second << ")"; return os; } #define all(x) x.begin(),x.end() #define pb push_back int main() { ll n,i; vector<ll>v; cin >> n; for(i=1 ; i*i<=n ; i++) { if(n%i==0) { if(i*i==n)v.pb(i); else { v.pb(i); v.pb(n/i); } } } sort(all(v)); for(auto x:v) cout << x << nl; return 0; }
#include <bits/stdc++.h> using namespace std; double dp[105][105][105]; int main() { int a,b,c; scanf("%d%d%d",&a,&b,&c); for(int i=99;i>=a;i--) { for(int j=99;j>=b;j--) { for(int k=99;k>=c;k--) { dp[i][j][k]=1.0*i/(i+j+k)*dp[i+1][j][k]+1.0*j/(i+j+k)*dp[i][j+1][k]+1.0*k/(i+j+k)*dp[i][j][k+1]+1; } } } printf("%.6f\n",dp[a][b][c]); return 0; }
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x,y) cout<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define pw(b,p) pow(b,p) + 0.1 #define endl "\n" mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void __print(int32_t x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif char myHeap[200 * 1024 * 1024]; int sz = 0; void assert_tle(bool q) { while (!q); } void* operator new ( std::size_t count ) { sz += count; assert_tle(sz <= 200 * 1024 * 1024); return myHeap + sz - count; } void operator delete (void *ptr) { } void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } double memo[100][100][100]; double dp(int a,int b,int c) { //debug(a,b,c); if(a>=100||b>=100||c>=100) return 0; if(memo[a][b][c]) return memo[a][b][c]; double tot=a+b+c; double pa=a/tot; double pb=b/tot; double pc=c/tot; double ans=pa*(1+dp(a+1,b,c))+pb*(1+dp(a,b+1,c))+pc*(1+dp(a,b,c+1)); memo[a][b][c]=ans; return ans; } void solve() { int a,b,c; cin>>a>>b>>c; memset(memo,0.0,sizeof memo); cout<<fixed<<setprecision(9); cout<<dp(a,b,c); } int32_t main() { fastIO(); //w(t) { solve(); cout<<endl; } return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; const int mod=1e9+7; int n,m,a[100010],ans=1; inline int ksm(int a,int b){ int res=1; while(b){ if(b&1)res=res*a%mod; a=a*a%mod; b>>=1; } return res; } signed main(){ scanf("%lld",&n); for(int i=1;i<=n;i++){ scanf("%lld",&a[i]); m=max(m,a[i]); } sort(a+1,a+n+1); for(int i=1;i<=n;i++){ if(a[i]==a[i-1])continue; ans=ans*(a[i]-a[i-1]+1)%mod; } printf("%lld",ans); return 0; }
#include<bits/stdc++.h> //#pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma comment(linker, "/stack:200000000") using namespace std; #define F first #define S second #define EB emplace_back #define MP make_pair #define all(o) (o).begin(), (o).end() #define mset(m,v) memset(m,v,sizeof(m)) #define rep(i,n) for(ll i=0;i<(n);++i) #define repe(i,a,b) for(ll i=a;i<=b;++i) #define revlp(i,a,b) for(ll i=a;i>=b;i--) #define remin(a,b) (a=min((a),(b))) #define remax(a,b) (a=max((a),(b))) #define sz(x) (ll)(x).size() #define endl '\n' typedef long long ll; typedef long double ld; typedef pair<ll,ll> pi; typedef vector<ll> vi; typedef vector<pi> vpi; typedef vector<vi> graph; long long mod=1000000007; long double EPS=1e-9; #ifndef ONLINE_JUDGE #define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl; #define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;} #define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__) template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";} template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";} template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";} template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";} template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";} template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";} template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);} #else #define pr(...){} #define debarr(a,n){} #define debmat(mat,row,col){} #endif void solve(){ ll n; cin>>n; vector<ll> arr(n); rep(i,n) cin>>arr[i]; sort(all(arr)); vector<ll> dp(n); dp[0]=arr[0]+1; repe(i,1,n-1){ dp[i]=(dp[i-1]*(arr[i]-arr[i-1]+1))%mod; } cout<<dp[n-1]<<endl; } signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //cout<<fixed<<setprecision(15); //clock_t begin = clock(); ll tc=1;//cin>>tc; for(ll i=1;i<=tc;i++){ //cout<<"Case #"<<i<<": "; solve(); } // clock_t end = clock();double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;cerr << elapsed_secs; }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = (a); i <= (b); i++) #define per(i, a, b) for (int i = (a); i >= (b); i--) #define fi first #define se second using namespace std; typedef long long LL; typedef pair <int, int> P; const int inf = 0x3f3f3f3f, N = 3e5 + 10; template <typename T> void rd_(T &x) { x = 0; int f = 1; char ch = getchar(); for (; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') f = -1; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x*10 + ch - '0'; x *= f; } int n, x[N], y[N]; LL ans; int main() { cin>>n; rep (i, 1, n) cin>>x[i]; rep (i, 1, n) { cin>>y[i]; ans += x[i]*y[i]; } printf("%s\n", ans == 0 ? "Yes" : "No"); }
#include <bits/stdc++.h> using namespace std; using i64 = unsigned long long; #define rep(i, n) for (i64 i = 0; i < (n); i++) #define IN_i64(n) \ i64 n; \ cin >> n; #define IN_veci64(a, n) \ vector<i64> a((n)); \ rep(i, n) cin >> a[i]; constexpr i64 INF64 = 1LL << 62LL; inline i64 modpow(i64, i64, i64 = INF64); inline i64 gcd(i64, i64); template <class T> inline bool chmax(T &a, T b); template <class T> inline bool chmin(T &a, T b); int main() { IN_i64(N); IN_i64(K); rep(i,K){ if (N%200==0) N/=200; else{ N*=1000; N+=200; } } cout<<N<<endl; } i64 modpow(i64 base, i64 exp, i64 mod) { i64 ans = 1; while (exp > 0) { if (exp % 2 == 1) { ans *= base; ans %= mod; } exp /= 2; base *= base; base %= mod; } return ans; } i64 gcd(i64 a, i64 b) { if (b == 0) return a; return gcd(b, a % b); } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
#include <stack> #include <queue> #include <set> #include <array> #include <vector> #include <deque> #include <map> #include <unordered_map> #include <unordered_set> #include <string> #include <utility> #include <climits> #include <algorithm> #include <numeric> #include <cmath> #include <cstring> #include <iostream> #include <fstream> #include <iomanip> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,int> pli; typedef pair<int,ll> pil; typedef pair<ll,ll> pll; typedef pair<ull,ull> pull; typedef vector<int> vi; typedef vector<ll> vl; #define mp make_pair #define pb push_back #define fr first #define sc second #define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl #define rep(s, i, n) for (int(i) = (s); (i) < (n); (i)++) #define repe(s, i, n) for (int(i) = (s); (i) <= (n); (i)++) #define rrep(s, i, n) for (int(i) = (s); (i) > (n); (i)--) #define rrepe(s, i, n) for (int(i) = (s); (i) >= (n); (i)--) #define allof(a) (a).begin(), (a).end() int main(int argc, char const *argv[]) { int n; cin>>n; map<int,int> m; ll res=0; rep(0,i,n){ int a; cin>>a; a%=200; res+=m[a]; m[a]++; } cout<<res<<endl; return 0; }
#include <bits/stdc++.h> // This will work only for g++ compiler. using namespace std; #define fo(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing #define fon(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing #define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive #define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based. #define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based //short hand for usual tokens #define pb push_back #define fi first #define se second #define MOD 1000000007 #define INF (int)1e9 // to be used with algorithms that processes a container Eg: find(all(c),42) #define all(x) (x).begin(), (x).end() //Forward traversal #define rall(x) (x).rbegin, (x).rend() //reverse traversal // traversal function to avoid long template definition. Now with C++11 auto alleviates the pain. #define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)// find if a given value is present in a container. Container version. Runs in log(n) for set and map #define present(c,x) ((c).find(x) != (c).end()) //find version works for all containers. This is present in std namespace. #define cpresent(c,x) (find(all(c),x) != (c).end()) // Avoiding wrap around of size()-1 where size is a unsigned int. #define sz(a) int((a).size()) // Shorthand for commonly used types typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef double ld; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed; int n; cin >> n; vi v(1<<n); for(int i = 0 ;i< 1<<n ;i++){ cin >> v[i]; } int mid = (1 << n) / 2; int pos = 0; int elem = min(*max_element(v.begin(),v.begin()+mid) , *max_element(v.begin()+mid , v.end())); for(int i = 0; i < (1<<n) ; i++){ if(elem == v[i]){ pos = i+1; break; } } cout << pos << '\n'; return 0; }
#include<string> #include<cstdio> #include<iostream> using namespace std; typedef long long ll; int main() { string s; cin >> s; ll re = 0; char last_char = '\n'; int last_int = 0; int last_pos = s.size(); for (int i = s.size() - 3; i >= 0; i--) { if (s[i] == s[i + 1] && s[i] != s[i + 2]) { for (int j = i + 2; j < last_pos; j++) { if (s[i] == s[j])re--; } if (s[i] != last_char) { last_int = s.size() - (i + 2); re += last_int; last_char = s[i]; } else { re += last_pos-(i+2); last_char = s[i]; } last_pos = i; } } printf("%lld\n", re); }
// #include <iostream> using namespace std; int main() { long N; cin >> N; long ans = 0; long i = 0; while (ans < N) ans += (++i); cout << i << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int lld; typedef pair<int,int> pi; typedef pair<lld,lld> pl; typedef pair<int,lld> pil; typedef pair<lld,int> pli; typedef vector<int> vit; typedef vector<vit> vitt; typedef vector<lld> vlt; typedef vector<vlt> vltt; typedef vector<pi> vpit; typedef vector<vpit> vpitt; typedef long double ld; #define x first #define y second #define pb push_back #define all(v) v.begin(), v.end() #define sz(x) (int)x.size() #define mk(a,b) make_pair(a,b) bool isrange(int y,int x,int n,int m){ if(0<=y&&y<n&&0<=x&&x<m) return true; return false; } int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1}; bool can(string& x,string& y){ int st = 0; for(int p=0;p<sz(x);p++){ if(st==sz(y)) return true; if(x[p]==y[st]) st++; } return (st==sz(y)); } void solve(int tc){ int n; string a[3],b[3]; cin >> n >> a[0] >> a[1] >> a[2]; b[0] = a[0] + a[0]; b[1] = a[1] + a[1]; b[2] = a[2] + a[2]; string f1 = ""; string f2 = ""; for(int e=0;e<n;e++) f1 += "0"; for(int e=0;e<n;e++) f1 += "1"; for(int e=0;e<n;e++) f2 += "1"; for(int e=0;e<n;e++) f2 += "0"; { string f3 = "0" + f1; bool suc = true; for(int p=0;p<3;p++) if(!can(b[p],f3)) suc = false; if(suc){ cout << f3 << "\n"; return; } } { string f3 = f1 + "0"; bool suc = true; for(int p=0;p<3;p++) if(!can(b[p],f3)) suc = false; if(suc){ cout << f3 << "\n"; return; } } { string f3 = "1" + f2; bool suc = true; for(int p=0;p<3;p++) if(!can(b[p],f3)) suc = false; if(suc){ cout << f3 << "\n"; return; } } { string f3 = f2 + "1"; bool suc = true; for(int p=0;p<3;p++) if(!can(b[p],f3)) suc = false; if(suc){ cout << f3 << "\n"; return; } } } int main(void){ ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tc = 1; cin >> tc; for(int test_number=1;test_number<=tc;test_number++){ solve(test_number); } return 0; }
#include<bits/stdc++.h> using namespace std; void solve(){ long long n,m,k,tot=0,cnt=0; int a=0,b=0,c=0; string s; cin>>n; while( n && n%10==0) n/=10; s=to_string(n); for(int i=0;i<s.size()/2;i++){if(s[i]!=s[s.size()-1-i]){cout<<"No";return ;}} cout<<"Yes"<<endl; } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); long long q(1); //cin>>q; while(q--){ solve(); } return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; using ll = long long; #define INF 1e9+7 #define rep(i,n) for(ll i=0;i<n;i++) #define repl(i,l,r) for(ll i=(l);i<(r);i++) #define per(i,n) for(int i=(n)-1;i>=0;i--) #define perl(i,r,l) for(int i=(r)-1;i>=(l);i--) #define pb push_back #define ins insert #define se second #define fi first #define all(x) x.begin(),x.end() using vi=vector<int>; using vl=vector<ll>; using vvi= vector<vector<int>>; using vvl= vector<vector<ll>>; using pii= pair<int,int>; using pll= pair<ll,ll>; const ll mod = INF; const int dxn[9]={-1,0,1,-1,0,1,-1,0,1}; const int dyn[9]={-1,-1,-1,0,0,0,1,1,1}; const int dxf[4]={0,1,0,-1}; const int dyf[4]={-1,0,1,0}; const int maxn = 1000; int main(){ int n,m; ll a[maxn+1],b[maxn+1]; ll dp[maxn+1][maxn+1]={0}; cin >> n>>m; rep(i,n)cin >> a[i+1]; rep(i,m)cin >> b[i+1]; rep(i,m+1)dp[0][i]=i; rep(i,n+1)dp[i][0]=i; repl(i,1,n+1){ repl(j,1,m+1){ int p=1; if(a[i]==b[j])p=0; dp[i][j]=min(min(dp[i-1][j]+1,dp[i][j-1]+1),dp[i-1][j-1]+p); } } cout << dp[n][m]<<endl; return 0; }
#include<stdio.h> #include<bits/stdc++.h> #define vi vector<int> #define int long long #define pf printf #define mod 1000000007 using namespace std; void boost(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int pow(int n,int m){ if(m%2==0){ int pro=pow(n,m/2); return ((pro)%mod*(pro)%mod)%mod; }else{ return ((n)%mod*(pow(n,m-1))%mod)%mod; } } int dp[1000][1000]; int findans(vector<int>&a,vector<int>&b,int i,int j){ if(i==a.size() || j==b.size()){ //pf("i is %lld and j is %lld ans is %lld\n",i,j,(a.size()-i)+(b.size()-j)); return (a.size()-i)+(b.size()-j); } if(dp[i][j]!=-1) return dp[i][j]; if(a[i]==b[j]){ return dp[i][j]=findans(a,b,i+1,j+1); }else{ int t=1+findans(a,b,i+1,j+1); int l=1+findans(a,b,i+1,j); int r=1+findans(a,b,i,j+1); return dp[i][j]=min({l,r,t}); } } int32_t main(){ boost(); int n,m; cin>>n>>m; vector<int> a,b; memset(dp,-1,sizeof(dp)); for(int i=0;i<n;i++){ int ele; cin>>ele; a.push_back(ele); } for(int i=0;i<m;i++){ int ele; cin>>ele; b.push_back(ele); } int ans=findans(a,b,0,0); pf("%lld\n",ans); return 0; }
//#include "input.h" //#include "output.h" #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define NDEBUG NDEBUG #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cstring> #include <cmath> #include <functional> #include <numeric> #include <iomanip> #include <iostream> #include <map> #include <set> #include <sstream> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> #include <memory> #include <queue> #include <random> using namespace std; template<class T> using vec = std::vector<T>; #define FOR(i, n) for (int i = 0; i < (n); ++i) #define all(c) c.begin(), c.end() typedef int64_t i64; // TC_REMOVE_BEGIN /// caide keep bool __hack = std::ios::sync_with_stdio(false); /// caide keep auto __hack1 = cin.tie(nullptr); // TC_REMOVE_END // Section with adoption of array and vector algorithms. //#include <ext/pb_ds/tree_policy.hpp> //#include <ext/pb_ds/assoc_container.hpp> // //template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; //bool __hack = std::ios::sync_with_stdio(false); //auto __hack1 = cin.tie(nullptr); struct Input { Input(istream &in) : in(&in) {} template<class T> T next() const { T x; *in >> x; return x; } int ni() const { return next<int>(); } template<class T> vec<T> nVec(int n) const { vec<T> v(n); for (int i = 0; i < n; ++i) { v[i] = next<T>(); } return v; } vec<i64> nvi64(int n) const { return nVec<i64>(n); } istream *in; }; Input in(cin); class Output { private: ostream *out; template<typename T> void printSingle(const T &value) { *out << value; } public: Output(ostream &out) : out(&out) {} inline void print() {} template<typename T, typename...Ts> inline void print(const T &f, const Ts&... args) { printSingle(f); if (sizeof...(args) != 0) { *out << ' '; print(args...); } } template<typename...Ts> inline void println(const Ts&... args) { print(args...); (*out) << '\n'; } template<typename...Ts> inline void operator() (const Ts&... args) { println(args...); } }; Output out(cout); namespace template_util { constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; } template<int N> struct bytetype { }; /// caide keep template<uint64_t N> struct minimal_uint : bytetype<bytecount(N)> { }; } void solve(istream& inStream, ostream& outStream) { in = Input(inStream); out = Output(outStream); auto n = in.ni(); auto a = in.nvi64(n); auto b = in.nvi64(n); auto sum = accumulate(all(a), i64(0)); vec<i64> evens, odds; FOR(i, n) { if (i % 2 == 0) { evens.push_back(b[i] - a[i]); } else { odds.push_back(b[i] - a[i]); } } sort(all(evens)); sort(all(odds)); while (!evens.empty()) { if (sum <= sum + evens.back() + odds.back()) { sum = sum + evens.back() + odds.back(); evens.pop_back(); odds.pop_back(); } else { break; } } out(sum); } //#include <fstream> int main() { // ifstream fin("input.txt"); // ofstream fout("output.txt"); // Input in(in); // Output out(out); solve(cin, cout); // solve(fin, fout); return 0; }
#include<bits/stdc++.h> using namespace std; #define nn int #define dd double #define ll long long int #define ss string int main() { ss s; cin>>s; reverse(s.begin(),s.end()); for(nn i=0;i<s.size();i++) { if(s[i]=='6') s[i]='9'; else if(s[i]=='9') s[i]='6'; } cout<<s<<"\n"; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい //for文のマクロ #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define mp(a,b) make_pair(a,b) #define big 1000000007 #define all(a) sort((a).begin(),(a).end()) //ソートのマクロ #define Re(a) reverse((a).begin(),(a).end()) #define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する int main(){ #define int int64_t int a,b,c; map<int,int> p; cin>>a>>b>>c; p[a]+=1,p[b]+=1,p[c]+=1; if(p.size()==3){ cout<<0<<endl; } else{ for(auto c:p){ int cnt = c.second; if(cnt==1 || cnt==3){ cout<<c.first<<endl; return 0; } } } return 0; }
/*--------------------------------------- BISMILLAHIR RAHMANIR RAHIM AUTHOR : Md. Sajjat Hossen TIME : ----------------------------------------*/ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds_set; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds_multiset; inline int Int() { int x; scanf("%d", &x); return x; } inline ll Long() { ll x; scanf("%lld", &x); return x; } int dx[8] = { 0, -1, 0, 1, -1, -1, 1, 1 }; int dy[8] = { -1, 0, 1, 0, -1, 1, 1, -1 }; const int N = (int) 2e5 + 5; const int mxN = (int) 1e6 + 6; const int MOD = (int) 1e9 + 7; const int INF = (int) 1e9 + 9; const double EPS = (double) 1e-9; #define debug(x) cerr << #x << " = " << x << '\n'; #define all(x) x.begin(), x.end() #define szof(x) (int) x.size() #define ff first #define ss second #define pb push_back #define mp make_pair #define PI acos(-1.0) #define TN typename #define nl '\n' #define Fast_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); inline int add(int a, int b, int mod) { a += b; return a >= mod ? a - mod : a < 0 ? a + mod : a; } inline int mult(int a, int b, int mod) { return (ll) a * b % mod; } template <TN T> inline void umin(T &x, T y) { x = x < y ? x : y; } template <TN T> inline void umax(T &x, T y) { x = x > y ? x : y; } template <TN T> T gcd(T a, T b) { return !b ? a : gcd(b, a % b); } template <TN T> T lcm(T a, T b) { return a * (b / gcd(a, b)); } int main() { // Fast_IO // clock_t tStart = clock(); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int test = 1, tc = 0; while (test--) { vi v(3, 0); v[0] = Int(), v[1] = Int(), v[2] = Int(); if (v[0] == v[1]) printf("%d\n", v[2]); else if (v[0] == v[2]) printf("%d\n", v[1]); else if (v[1] == v[2]) printf("%d\n", v[0]); else printf("0\n"); } // fprintf(stderr, "\nRuntime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, a, b) for(ll i = a; i < b; i++) #define Rep(i, a, b) for(ll i = a; i <= b; i++) #define repr(i, a, b) for(ll i = b-1; i >= a; i--) // #define _GLIBCXX_DEBUG template <class T> using V = vector<T>; #define ALL(v) (v).begin(),(v).end() #define endl '\n' #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define sz(v) ((ll)(v).size()) const double pi = acos(-1.0); const ll MOD = 1000000007LL; const ll INF = 1LL << 60; // #define fi first // #define se second const int dy[] = {1, 0, -1, 0}; const int dx[] = {0, 1, 0, -1}; const int dy2[] = {0, 1, 1, 1, 0, -1, -1, -1}; const int dx2[] = {1, 1, 0, -1, -1, -1, 0, 1}; // ios::sync_with_stdio(false); // cin.tie(nullptr); /*-------------------------------------------------------------------------------- --------------------------------------------------------------------------------*/ int main() { ll a, b; cin >> a >> b; ll x = (a+b)/2, y = (a-b)/2; cout << x << " " << y << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ int a,b; cin >> a >> b; cout << (a+b)/2 << ' ' << (a-b)/2 << endl; }
#include<bits/stdc++.h> using namespace std; /*#include<atcoder/all> using namespace atcoder;*/ typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pi; typedef vector<pi> pii; #define all(x) x.begin(),x.end() #define sz(x) (int)(x).size() #define pb push_back #define mk make_pair #define en '\n' void solve(){ float a,b; cin >> a >> b; cout << (a*b)/100 << en; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen("div7.in","r",stdin); //freopen("div7.out","w",stdout); int t = 1; //cin >> t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> #define f first #define s second #define pb push_back #define ENDL '\n' #define sz(s) int(s.size()) #define deb(x) cout << #x": " << (x) << endl; #define all(s) begin(s), end(s) #define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i) #define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; typedef long double ld; typedef long long lli; typedef pair<lli,lli> ii; typedef vector<lli> vi; lli f(lli u, lli v) { if(u == 0) return 0; if(u % v) return (v + u - (u % v)) / v; return u / v; } int main(){ _ lli n, m; cin >> n >> m; if(m == 0) { cout << 1 << ENDL; return 0; } vi v(m); fore(i, 0, m) cin >> v[i]; sort(all(v)); lli prev = 0; lli mn = n; for(auto it : v) { lli aux = (it - prev - 1); prev = it; if(aux == 0) continue; mn = min(mn, aux); } lli aux = n - prev; if(aux != 0) mn = min(mn, aux); prev = 0; lli ans = 0; for(auto it : v) { lli aux = (it - prev - 1); prev = it; ans += f(aux, mn); } aux = n - prev; ans += f(aux, mn); cout << ans << ENDL; return 0; }
#include <bits/stdc++.h> #define Rajpoot ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long #define loo(i,n) for(i=0;i<n;i++) #define go(i,sp) for(auto i=sp.begin();i!=sp.end();i++) #define pb push_back #define lb lower_bound #define mo 1000000007 #define pi 3.14159265358979323846264338327950288419716939937510582 #define exp 2.71828182845904523536028747135266249775724709369995957 #define endl "\n" using namespace std; int main() { Rajpoot // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); //int t; cin>>t; int t=1; while(t--) { ll a,b; cin>>a>>b; a=a+b; if(a>=15 && b>=8) cout<<1<<endl; else if(a>=10 && b>=3) cout<<2<<endl; else if(a>=3) cout<<3<<endl; else cout<<4<<endl; } return 0; }
#include <bits/stdc++.h> #define ll long long int #define ld long double #define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define mp make_pair #define pb push_back #define vll vector<ll> #define pll pair<ll, ll> #define mod(n) (n) % 1000000007 #define sp << " " #define ff first #define ss second #define precision(n) cout << fixed << setprecision(n); #define startTime time_t start, end;time(&start); #define endTime time(&end);double tt = double(end-start);cout<<"Time taken : "<<fixed<<tt<<setprecision(5);cout <<" sec"<< endl; using namespace std; int main() { IOS; ll A, B; cin >> A >> B; if (A + B >= 15 && B >= 8) cout << 1 << endl; else if (A + B >= 10 && B >= 3) cout << 2 << endl; else if (A + B >= 3) cout << 3 << endl; else cout << 4 << endl; }
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c,d,i,j; cin >> a; set<int>st; vector<int>vec; for(i=0;i<=2*a+1;i++) st.insert(i); for(j=0;j<a;j++) { cin >> c; if(st.count(c)) { st.erase(c); } vec.push_back(*st.begin()); } for(i=0;i<vec.size();i++) { cout << vec[i] << " "; } cout << endl; }
#include <algorithm> #include <iostream> #include <iomanip> #include <numeric> #include <vector> #include <string> #include <bitset> #include <stack> #include <queue> #include <tuple> #include <regex> #include <cmath> #include <map> #include <set> #include <functional> #include <cstring> using namespace std; template<typename T> bool chmax( T &a, const T b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } } template<typename T> bool chmin( T &a, const T b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } } using ll = long long; using Pint = pair<int, int>; using Pll = pair<ll, ll>; #define eb emplace_back #define pb push_back #define mp make_pair #define F first #define S second #define popcnt __builtin_popcountll #define rep( i, n ) for ( ll i = 0; i < (ll)( n ); ++i ) #define reps( i, n ) for ( ll i = 1; i <= (ll)( n ); ++i ) #define rrep( i, n ) for ( ll i = (ll)( ( n ) - 1 ); i >= 0; --i ) #define rreps( i, n ) for ( ll i = (ll)( ( n ) ); i > 0; --i ) #define arep( i, v ) for ( auto &&i : ( v ) ) #define ALL( c ) ( c ).begin(), ( c ).end() #define RALL( c ) ( c ).rbegin(), ( c ).rend() #define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() ) template<typename T = ll> constexpr T MAX = numeric_limits<T>::max(); template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); } template<typename T> T lcm( const T a, const T b ) { return ( a / gcd( a, b ) * b ); } int main() { ll n; cin >> n; vector<ll> p( n ); rep( i, n ) cin >> p[i]; priority_queue<ll, vector<ll>, greater<ll>> pq; map<ll, ll> m; rep( i, 200001 ) pq.push( i ); rep( i, n ) { m[p[i]]++; auto x = pq.top(); while ( m[x] >= 1 ) { pq.pop(); x = pq.top(); } cout << x << endl; } return ( 0 ); }
#include<bits/stdc++.h> using namespace std; int main(){ map<int,int> mm; int n; cin>>n; for(int i=1;i<=n;i++){ int x; cin>>x; mm[x]++; } for(int i=1;i<=n;i++){ if(mm[i]!=1){ cout<<"No"; return 0; } } cout<<"Yes"; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++) #define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--) #define yes cout << "yes" << endl; #define Yes cout << "Yes" << endl; #define YES cout << "YES" << endl; #define no cout << "no" << endl; #define No cout << "No" << endl; #define NO cout << "NO" << endl; #define AC cout << "AC" << endl; #define WA cout << "WA" << endl; #define out(s) cout << s << endl; #define ll long long #define ull unsigned long long #define ALL(x) x.begin(), x.end() #define SIZE(x) ll(x.size()) const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001 const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010 const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100 const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000 const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000 const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000 const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000 const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000 const double PI = 3.14159265358979323846; const int dy[4] = {0, 1, 0, -1}; const int dx[4] = {1, 0, -1, 0}; #define H_MAX 500 #define W_MAX 500 #define INF 1e9 + 7 const long long MOD = 998244353; int main() { int N; cin>>N; vector<int> A(N); for (int i = 0; i < N; i++) { cin>>A[i]; } sort(A.begin(), A.end()); for (int i = 0; i < N; i++) { if(i+1 != A[i]) { No; return 0; } } Yes; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template<class T> using vc = vector<T>; template<class T> using vvc = vc<vc<T>>; template<class T> using vvvc = vc<vvc<T>>; template<class T> using vvvvc = vvc<vvc<T>>; template<class T> using PQ = priority_queue<T>; template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>; using IP = pair<int, int>; using LP = pair<ll, ll>; #define mp make_pair #define pb push_back #define all(x) begin(x), end(x) #define rep(i, n) for (int i = 0; (i) < (int)(n); i++) #define rep3(i, m, n) for (int i = (m); (i) < (int)(n); i++) #define repr(i, n) for (int i = n; (i) >= (int)(n); i--) #define rep3r(i, m, n) for (int i = (n); (i) >= (int)(m); 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; } constexpr int INF = 1070000000; constexpr long long LINF = 4611686015206162431; template <class T> void checkarray(T &v) { for (auto &a : v) cout << a << " "; cout << endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); ll N; cin >> N; ll ans = N; int ssize = sqrtl(N); vc<bool> seen(ssize+1); for (ll i = 2; i*i <= N; i++) { if (seen[i]) continue; ll n = i; while (n < N) { n *= i; if (n <= N) { ans--; if (n <= ssize) seen[n] = true; } } } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ long long n; cin >> n; set<long long> s; for(long long i=2;i*i<=n;i++){ long long x=i*i; while(x<=n){ s.insert(x); x*=i; } } cout << n-s.size() << endl; }
#include<iostream> #include<algorithm> using namespace std; const int N=1e5+10; int x[N],y[N]; int main(){ int n; cin>>n; for(int i=0;i<n;i++) cin>>x[i]>>y[i]; int ans=0; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ double res=abs((double)y[i]-y[j])/abs((double)x[i]-x[j]); if(res>=-1 && res<=1) ans++; } } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define fileio \ freopen("C:\\Users\\PRISM17\\Desktop\\in.txt", "r", stdin); \ freopen("C:\\Users\\PRISM17\\Desktop\\out.txt", "w", stdout); #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define dbg(x) cout << #x << " : " << x << endl; #define rep(i, a, b) for (int i = (a); i <= (b); i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; const int inf = 0x3f3f3f3f; const int INF = 1e9; const int mod = 1e9 + 7; const int N = 4e5 + 7; int fa[N], vis[N]; int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } int main() { int n; cin >> n; int ans = 0; for (int i = 1; i < N; i++) fa[i] = i; for (int i = 1, u, v; i <= n; i++) { cin >> u >> v; u = find(u), v = find(v); if (u != v && (!vis[u] || !vis[v])) fa[u] = v, vis[v] |= vis[u], ++ans; else if (!vis[u]) ++ans, vis[u] = 1; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define fr(i,n) for(int i = 0; i<n; i++) #define sz(v) (int)(v.size()) #define prin(a) cout << #a << " = " << a << endl #define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl #define all(v) (v).begin(),(v).end() typedef long long ll; #define rmin(a,b) a = min<ll>(a,b) #define rmax(a,b) a = max<ll>(a,b) #define fi first #define se second const int N = 2e5+10; int dp_pego[N], dp_val[N], dp_qnt[N]; vector<int> g[N]; int mdist; void dfs(int no, int from){ //prin(no); int dist_prox_pego = INT_MAX/2, dist_longe_need = 0; dp_qnt[no] = 0; for(auto &it : g[no]){ if(it==from) continue; dfs(it,no); dp_qnt[no]+=dp_qnt[it]; if(dp_pego[it]){ rmin(dist_prox_pego,dp_val[it]+1); } else{ rmax(dist_longe_need,dp_val[it]+1); } } if(dist_prox_pego<=mdist){ if(dist_prox_pego+dist_longe_need<=mdist){ dp_pego[no] = 1; dp_val[no] = dist_prox_pego; } else{ if(dist_longe_need==mdist){ dp_qnt[no]++; dp_pego[no] = 1; dp_val[no] = 0; } else{ dp_pego[no] = 0; dp_val[no] = dist_longe_need; } } } else{ if(dist_longe_need==mdist){ dp_qnt[no]++; dp_pego[no] = 1; dp_val[no] = 0; } else{ dp_pego[no] = 0; dp_val[no] = dist_longe_need; } } if(no==0 and !dp_pego[no]) dp_qnt[no]++; } int need(int _mdist){ mdist = _mdist; dfs(0,-1); return dp_qnt[0]; } int main(){ ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; fr(i,n-1){ int a, b; cin >> a >> b; a--,b--; g[a].push_back(b); g[b].push_back(a); } int lo = 1, hi = n; while(lo<hi){ int mid = (lo+hi)/2; if(need(mid)<=k) hi = mid; else lo = mid+1; } cout << lo << "\n"; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5 + 10, inf = 0x3f3f3f3f; vector<int>e[N]; int n, k, mid, ret; int f[N], g[N]; void dfs(int u, int fa) { g[u] = 0, f[u] = inf; for (int v : e[u]) { if (v == fa)continue; dfs(v, u); f[u] = min(f[u], f[v] + 1); g[u] = max(g[u], g[v] + 1); } if (f[u] + g[u] <= mid) g[u] = -inf; else if (g[u] == mid) f[u] = 0, g[u] = -inf, ret++; } bool check() { ret = 0; dfs(1, 0); if (g[1] >= 0)ret++; return ret <= k; } void solve() { cin >> n >> k; for (int i = 1, u, v; i < n; ++i) { cin >> u >> v; e[u].push_back(v); e[v].push_back(u); } int l = 0, r = n, ans = n; while (l <= r) { mid = (r + l) >> 1; if (check())r = mid - 1, ans = mid; else l = mid + 1; } cout << ans; } int main() { ios::sync_with_stdio(false), cin.tie(nullptr); solve(); return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> //external policy based dsa accociate container #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define fbo find_by_order // return pointer to kth element #define ook order_of_key // return number of element strictly less than a given value #define ff first #define ss second #define int long long int #define pb push_back #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define max_ull 18446744073709551615 #define max_ll 9223372036854775807 #define eps 1e-10 #define mod 1000000007 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) //#define rep(a,b,c) for(i=a;i<=b;i+=c) #define min3(a, b, c) min(a, min(b, c)) #define max3(a, b, c) max(a, max(b, c)) #define min4(a, b, c, d) min(min(a, b), min(c, d)) #define max4(a, b, c, d) max(max(a, b), max(c, d)) #define max5(a, b, c, d, e) max(max3(a, b, c), max(d, e)) #define min5(a, b, c, d, e) min(min3(a, b, c), min(d, e)) #define lead_zero(x) __builtin_clzll(x) #define trail_zero(x) __builtin_ctz(x) #define total_1s(x) __builtin_popcount(x) #define first_1(x) __builtin_ffs(x) #define log2_(x) __builtin_clz(1) - __builtin_clz(x) #define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false)) #define set(N, cur) N = (N | (1 << cur)) #define reset(N, cur) N = (N & (~(1 << cur))) #define check(N, cur) ((N & (1 << cur)) == 0) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef unsigned long long ull; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; /* Direction arrays */ /* int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1}; */ // 4 Direction /* int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction /* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction /* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction /* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction /* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */ void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout); #endif } // int powe(int n,int k,int mod1) // { // int res=1; // while(k!=0) // { // if(k&1) // res=(res*n)%mod1; // k=k/2; // n=(n*n)%mod1; // } // return res; // } // int seive[100005]; // void me() // { // int n=100005; // for(int i=0;i<n;i++) // { // seive[i]=1; // } // seive[0]=0; // seive[1]=0; // for(int i=2;i*i<=n;i++) // { // if(seive[i]==1) // { // for(int j=i*i;j<=n;j+=i) // seive[j]=0; // } // } // } main() { c_p_c(); int n,a,b; cin>>n>>a>>b; int ans=(n-a)+b; cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std ; typedef long long ll ; #define rep(i,n) for(int i = 0 ; i < n ; i++) #define rrep(i,a,b) for(int i = a ; i < b ; i++) int n ; int A[1007] ; int main(){ cin >> n ; rep(i,n) cin >> A[i] ; int sum = 0 ; rep(i,n){ if(A[i] > 10) sum += A[i] - 10 ; } cout << sum << endl ; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; const int INF = 1e9; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll a, b, c, d, ans = 3; cin >> a >> b >> c >> d; ll x = c - a, y = d - b; if (c == a && d == b) ans = 0; else if (x == y || x == -y || abs(x) + abs(y) <= 3) ans = 1; else if ((x + y) % 2 == 0 || abs(x + y) <= 3 || abs(x - y) <= 3 || abs(x) + abs(y) <= 6) ans = 2; cout << ans << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define int long long int #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" void local() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } signed main() { IOS; //local(); int a[3]; cin>>a[0]>>a[1]>>a[2]; sort(a, a+3); if(a[0]==a[1] ) cout<<a[2]; else if(a[1]==a[2]) cout<<a[0]; else cout<<0; return 0; }
#include <bits/stdc++.h> using namespace std; int n; int a[550][550]; int b[550], c[550]; int main(){ ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i += 1){ for (int j = 1; j <= n; j += 1){ cin >> a[i][j]; } } bool flag = true; for(int i = 2; i <= n; i++){ for(int j = 2; j <= n; j++){ if(a[i][j] - a[i][j - 1] != a[i - 1][j] - a[i - 1][j - 1]) flag = false; } } for(int j = 2; j <= n; j++){ for(int i = 2; i <= n; i++){ if(a[i][j] - a[i - 1][j] != a[i][j - 1] - a[i - 1][j - 1]) flag = false; } } if(!flag){ cout << "No\n"; } else{ int index = 1; for(int i = 1; i <= n; i++){ if(a[i][1] < a[index][1]) index = i; } for(int i = 1; i <= n; i++){ c[i] = a[index][i]; } for (int i = 1; i <= n; i += 1){ b[i] = a[i][1] - c[1]; } cout << "Yes\n"; for (int i = 1; i <= n; i += 1){ cout << b[i] << " \n"[i == n]; } for (int i = 1; i <= n; i += 1){ cout << c[i] << " \n"[i == n]; } } return 0; }
#include <bits/stdc++.h> #define INF 0x3f3f3f3f #define rep(i, a, n) for (int i=(a); i<(n); i++) #define per(i, a, n) for (int i=(a); i>(n); i--) typedef long long ll; const int maxn = 1e3+5; const int mod = 1e9+7; using namespace std; ll mp[maxn][maxn]; void solve() { int n; cin >> n; ll k = 1e18; bool ok = 1; vector<ll> a(n), b(n); rep(i,0,n) rep(j,0,n) cin >> mp[i][j]; rep(i,0,n) k = min(k, mp[0][i]); rep(i,0,n) { b[i] = mp[0][i] - k; if (b[i] < 0) { ok = 0; break; } } a[0] = k; rep(i,1,n) { a[i] = mp[i][0] - b[0]; if (a[i] < 0) { ok = 0; break; } rep(j,0,n) { if (a[i] + b[j] != mp[i][j]) { ok = 0; break; } } } if (ok) { cout << "Yes\n"; rep(i,0,n) cout << a[i] << " \n"[i==n-1]; rep(i,0,n) cout << b[i] << " \n"[i==n-1]; } else cout << "No\n"; } int main(int argc, char * argv[]) { ios_base::sync_with_stdio(false); cin.tie(0); //int t; cin >> t; while(t--) solve(); return 0; }
#include <cstdio> #include <iostream> #include <cassert> #include <string> #include <algorithm> #include <cstring> #include <utility> #include <tuple> #include <vector> #include <stack> #include <queue> #include <map> #include <set> #include <cmath> #include <deque> #include <random> #include <chrono> #include <numeric> #include <unordered_map> #include <unordered_set> #define IOS ios_base::sync_with_stdio(0); cin.tie(0) using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int main() { int N; scanf("%d", &N); vector<int> A(N, 0); for (int i = 0; i < N; i++) scanf("%d", &A[i]); vector<LL> psum(N, 0); for (int i = 0; i < N; i++) { if (i) psum[i] = psum[i - 1]; int offs = 1; if (i % 2) offs = -1; psum[i] += offs * A[i]; } map<LL, int> cnt; cnt[0] = 1; LL ans = 0; for (int i = 0; i < N; i++) { LL cur = psum[i]; ans += cnt[cur]; cnt[cur]++; } printf("%lld\n", ans); return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH by Benq; */
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define db double #define pii pair<int,int> #define pli pair<ll,int> #define pil pair<int,ll> #define pll pair<ll,ll> #define ti3 tuple<int,int,int> #define mat vector<vector<int>> const int inf = 1 << 30; const ll mod = 1e9 + 7; const ll linf = 1LL << 62; const db EPS = 1e-7; template<class T> void chmin(T& x, T y){if(x > y) x = y;} template<class T> void chmax(T& x, T y){if(x < y) x = y;} ll ans, N, L; vector<int> A, B; int main() { cin >> N >> L; int pre = 0; for (int i = 0; i < N; i++) { int a; cin >> a; A.push_back(a - pre - 1); pre = a; } A.push_back(L - pre); A.push_back(0); pre = 0; for (int i = 0; i < N; i++) { int b; cin >> b; B.push_back(b - pre - 1); pre = b; } B.push_back(L - pre); int idx = 0, l = 0, r = 0; for (int i = 0; i < N + 1; i++) { if (B[i] == 0) continue; while (A[idx] == 0) idx++; l = idx, r = idx; int sum = 0; for (; idx < N + 2; idx++) { if (sum >= B[i]) break; sum += A[idx]; r = idx; } if (sum != B[i]) { cout << -1 << endl; return 0; } ans += max(i - l, 0) + max(r - i, 0); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 5e2 + 7; int n , m; vector<pair<int,int> > adj[N * N * 2] ; int d[N * N * 2] ; int id(int x, int y){ return x * m + y ; } void edge(int u ,int v, int c){ adj[u].push_back({v , c}) ; } int dijkstra(int st, int en){ for(int i = 0 ;i < N * N * 2 ;++ i)d[i] = 1e9 ; d[st] = 0 ; priority_queue<pair<int,int> > pq ; pq.push({0 , st}) ; while(pq.size()){ int dst = -pq.top().first ; int node = pq.top().second ; pq.pop() ; for(auto u : adj[node]){ if(dst + u.second < d[u.first]){ d[u.first] = dst + u.second; pq.push({-d[u.first] , u.first}) ; } } } return d[en] ; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("in.in", "r", stdin); #endif cin >> n >> m; for(int i = 0 ;i < n; ++ i){ for(int j = 0 ;j + 1<m ; ++ j){ int x; cin >> x; edge( id(i , j) , id(i , j + 1) , x ) ; edge( id(i, j + 1) , id(i , j) , x ) ; } } for(int i = 0 ; i + 1 < n; ++ i){ for(int j = 0 ;j < m; ++ j){ int x; cin >> x; edge( id(i , j) , id(i + 1, j) , x ) ; } } for(int i = 0 ;i < n;++ i){ for(int j = 0 ;j < m ;++ j){ edge( id(i , j) , id(i , j) + n * m , 1 ) ; edge( id(i, j) + n * m, id(i , j) , 0 ) ; if(i > 0){ edge( id(i , j) + n * m, id(i -1, j) + n * m , 1 ) ; } } } cout << dijkstra(0 , n * m - 1) ; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";} template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;} template<class T>void chmin(T&a,const T&b){if(a>b)a=b;} template<class T>void chmax(T&a,const T&b){if(a<b)a=b;} ll nextLong() { ll x; scanf("%lld", &x); return x;} int main2() { int b = nextLong(); int N = (1 << b); vector<int> A(N); REP(i, N) A[i] = nextLong(); int h = max_element(ALL(A)) - A.begin(); int ans = -1; if (h >= N/2) { ans = max_element(A.begin(), A.begin() + N/2) - A.begin(); } else { ans = max_element(A.begin() + N/2, A.begin() + N) - (A.begin()); } cout << (1+ans) << endl; return 0; } int main() { #ifdef LOCAL for (;!cin.eof();cin>>ws) #endif main2(); return 0; }
#include <bits/stdc++.h> #include<vector> using namespace std; typedef long long ll; const ll MOD = 998244353; int main(){ int n; cin>>n; ll sum=0; ll ans=0; ll a[n]; for(int i=0;i<n;i++){ cin>>a[i]; sum+=a[i]; } for(int i=0;i<n;i++){ ans+=(a[i]*a[i])*(n-1); sum-=a[i]; ans-=2*a[i]*sum; } cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; int main() { ll N; cin >> N; vector<ll> cnt(401); for (ll i = 0; i < N; i++) { ll A; cin >> A; cnt[A + 200]++; } ll ans = 0; for (ll i = 0; i <= 400; i++) for (ll j = 0; j < i; j++) ans += (i - j) * (i - j) * cnt[i] * cnt[j]; cout << ans << endl; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int k; int atime,btime; vector<int> A; vector<int> B; cin>>k; for (int i=0;i<k;i++){ int a,b; cin>>a>>b; A.push_back(a); B.push_back(b); } atime=*min_element(A.begin(),A.end()); B[distance(A.begin(),min_element(A.begin(),A.end()))]+=atime; btime=*min_element(B.begin(),B.end()); cout<<max(atime,btime); }
#include<bits/stdc++.h> using namespace std; #define For(i,a,b) for(int i = a;i<=b;++i) #define For_(i,a,b) for(int i = a;i>=b;--i) #define endl '\n' #define IOS ios::sync_with_stdio(false) typedef long long LL; inline int read(){ int r = 0,f = 1; char c = getchar(); while(c<'0' || c >'9'){ if(c =='-') f = -1; c = getchar(); } while(c>='0' && c<='9'){ r = (r<<1) + (r<<3) + c - '0'; c = getchar(); } return r * f; } #define max3(a,b,c) max(a,max(b,c)); const int N = 500000+ 5 ,M = N , INF = 0x3f3f3f3f; int n,m; long long s1,s3; unsigned long long s2; int main(){ n = read(); For(i,1,n){ int x = read(); x = abs(x); s1 += x; s2 += x*(LL)x; s3 = max(s3,(LL)x); } cout<<s1<<'\n'; double ans2 = (double)sqrt(s2); printf("%.15lf\n",ans2); cout<<s3<<'\n'; //system("pause"); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define ALL(x) ((x).begin()), ((x).end()) #define READ(x) (cin >> (x)) #define WRITE_N(x) (cout << (x) << endl) #define WRITE(x) (cout << (x)) #define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No")) #define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); } #define DIVIDER 1000000007LL ll solve(ll N, ll A, ll B) { if (A + B > N) { return 0; } ll retv = (((N - A + 1) * (N - A + 1)) % DIVIDER) * (((N - B + 1) * (N - B + 1)) % DIVIDER); retv %= DIVIDER; ll x = (N - A + 1) * (N - B + 1) - (N - A - B + 1) * (N - A - B + 2); x = x % DIVIDER; retv = (retv - ((x * x) % DIVIDER) + DIVIDER) % DIVIDER; return retv; } int main() { // get values from input cin.tie(0); ios::sync_with_stdio(false); int T; cin >> T; // main procedure vector<ll> ans; for (size_t i = 0; i < T; i++) { ll N, A, B; cin >> N >> A >> B; ans.push_back(solve(N, A, B)); } // output for (size_t i = 0; i < T; i++) { cout << ans[i] << endl; } return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> // find_by_order(k): It returns to an iterator to the kth element (counting from zero) in the set // order_of_key(k) : It returns to the number of items that are strictly smaller than our item k #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define pb push_back #define f first #define s second #define F(i,a,b) for(i=a;i<b;i++) #define nl "\n" #define sp " " #define all(c) (c).begin(),(c).end() #define rev(i,b,a) for(int i=b;i>=a;i--) #define iota cout<<-1<<nl #define cty cout<<"YES"<<nl #define ctn cout<<"NO"<<nl #define lmax LLONG_MAX #define lmin LLONG_MIN #define sz(v) (v).size() #define deci(n) fixed<<setprecision(n) #define c(x) cout<<(x) #define csp(x) cout<<(x)<<" " #define c1(x) cout<<(x)<<nl #define c2(x,y) cout<<(x)<<" "<<(y)<<nl #define c3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<nl #define c4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<nl #define c5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<nl #define c6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<nl typedef long double ld; typedef long long ll; typedef vector<ll> vll; typedef pair<ll,ll> pll; typedef vector<pll> vpll; const int mod=998244353; const int mod1=1000000007; const double pi=3.14159265358979323846264338327950288419716939937510582097494459230; // priority_queue<t> ll max(ll a , ll b){ if(a>b)return a; return b;} ll min(ll a , ll b){ if(a<b)return a; return b;} 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 ll pct(ll x) { return __builtin_popcount(x); } // # of bits set ll poww(ll a, ll b) { ll res=1; while(b) { if(b&1) res=(res*a); a=(a*a); b>>=1; } return res; } ll modI(ll a, ll m=mod) { ll m0=m,y=0,x=1; if(m==1) return 0; while(a>1) { ll q=a/m; ll t=m; m=a%m; a=t; t=y; y=x-q*y; x=t; } if(x<0) x+=m0; return x;} ll powm(ll a, ll b,ll m=mod) {ll res=1; while(b) { if(b&1) res=(res*a)%m; a=(a*a)%m; b>>=1; } return res;} //*******************************************************************************************************************************************// void iamzeus() { ll i,j,x=0,y,ans=0,n,m,d,cnt=0,z,c=2,k; cin>>n; vpll v(n); for(i=0;i<n;i++)cin>>v[i].f>>v[i].s; vector<pair<pll,ll>>v1,v2; for(i=0;i<n;i++) { v1.pb({{v[i].f,v[i].s},i}); v2.pb({{v[i].s,v[i].f},i}); } sort(all(v1)); sort(all(v2)); vector<pair<ll,pll>>v4; v4.pb({v1[n-1].f.f-v1[0].f.f,{min(v1[n-1].s,v1[0].s),max(v1[n-1].s,v1[0].s)}}); v4.pb({v1[n-1].f.f-v1[1].f.f,{min(v1[n-1].s,v1[1].s),max(v1[n-1].s,v1[1].s)}}); v4.pb({v1[n-2].f.f-v1[0].f.f,{min(v1[n-2].s,v1[0].s),max(v1[n-2].s,v1[0].s)}}); v4.pb({v2[n-1].f.f-v2[0].f.f,{min(v2[n-1].s,v2[0].s),max(v2[n-1].s,v2[0].s)}}); v4.pb({v2[n-1].f.f-v2[1].f.f,{min(v2[n-1].s,v2[1].s),max(v2[n-1].s,v2[1].s)}}); v4.pb({v2[n-2].f.f-v2[0].f.f,{min(v2[n-2].s,v2[0].s),max(v2[n-2].s,v2[0].s)}}); sort(all(v4),greater<pair<ll,pll>>()); map<pll,ll>mp; cnt=0; for(auto u:v4) { if(mp.find({u.s.f,u.s.s})==mp.end()) { cnt++; if(cnt==2) { c1(u.f); return; } } mp[{u.s.f,u.s.s}]=1; } }; int main() {fast; int t; t=1; //cin >>t; while(t--) iamzeus(); }
#include <bits/stdc++.h> #define rep(i, begin, end) for (i=begin;i<end;i++) #define printint(i0, i1) printf("%d %d\n", i0, i1) #define MAX_N 1000 using namespace std; typedef long long int ll; const int inf = 1000000000; const int mod = 1000000007; const int nil = -1; ll i, j, n, m, k, ans, l; ll rest[10], takahashi[10], aoki[10]; string s, t; int main() { scanf(" %lld", &k); rep(i,1,10) { rest[i] = k; takahashi[i] = 0; aoki[i] = 0; } cin >> s; cin >> t; rep(i,0,4) { takahashi[s[i] - '0']++; aoki[t[i] - '0']++; rest[s[i] - '0']--; rest[t[i] - '0']--; } ll cnt = 0; rep(i,1,10) { rep(j,1,10) { if (rest[i] == 0 || rest[j] == 0) continue; takahashi[i]++; aoki[j]++; ll score_t = 0, score_a = 0; rep(l, 1, 10) { score_t += l * pow(10, takahashi[l]); score_a += l * pow(10, aoki[l]); } if (score_t > score_a) cnt += i != j ? rest[i] * rest[j] : rest[i] * (rest[i] - 1); takahashi[i]--; aoki[j]--; } } double all = (9 * k - 8) * (9 * k - 9); printf("%12.10lf\n", (double)cnt / all); }
// 問題の URL を書いておく // #include <bits/stdc++.h> using namespace std; //#define ENABLE_PRINT #if defined(ENABLE_PRINT) #define Print(v) \ do {\ cout << #v << ": " << v << endl; \ }while(0) #define PrintVec(v) \ do {\ for(int __i = 0; __i < v.size(); ++__i) \ { \ cout << #v << "[" << __i << "]: " << v[__i] << endl; \ }\ }while(0) #else #define Print(v) ((void)0) #define PrintVec(v) ((void)0) #endif #define rep(i, n) for(int i = 0; i < (int)(n); ++i) using ll = long long; int calcScore(vector<ll>& hand) { ll score = 0; rep(i, 9) { auto ti = 1 + i; score += ti * (ll)pow(10, hand[ti]); } return score; } int main(int, const char**) { ll K; cin >> K; string S, T; cin >> S >> T; vector<ll> nums(10, K); vector<vector<ll>> hands(2, vector<ll>(10, 0)); rep(i, 4) { auto sn = S[i] - '0'; hands[0][sn]++; nums[sn]--; auto tn = T[i] - '0'; hands[1][tn]++; nums[tn]--; } set<pair<int, int>> wp; for(int i = 1; i <= 9; ++i) { for(int j = 1; j <= 9; ++j) { if(i == j) { if(!(nums[i] >= 2)) continue; } if(!(nums[i] >= 1)) continue; if(!(nums[j] >= 1)) continue; hands[0][i]++; hands[1][j]++; auto ts = calcScore(hands[0]); auto as = calcScore(hands[1]); hands[0][i]--; hands[1][j]--; if(ts > as) { wp.insert({i, j}); } } } ll u = 0; for(auto& p : wp) { if(p.first == p.second) { u += nums[p.first] * (nums[p.first] - 1); } else { u += nums[p.first] * nums[p.second]; } // printf("%d, %d\n", p.first, p.second); } ll d = (K * 9 - 8) * (K * 9 - 9); auto ans = u / (double)d; printf("%.10f\n", ans); return 0; }
//pragma region Macros // #pragma GCC target("avx2") #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define ld long double #define rep2(i, a, b) for(ll i = a; i <= b; ++i) #define rep(i, n) for(ll i = 0; i < n; ++i) #define rep3(i, a, b) for(ll i = a; i >= b; --i) #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define eb emplace_back #define vi vector<int> #define vll vector<ll> #define vpi vector<pii> #define vpll vector<pll> #define fi first #define se second #define all(c) begin(c), end(c) #define SUM(v) accumulate(all(v), 0LL) #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) #define lb(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define ub(c, x) distance((c).begin(), upper_bound(all(c), (x))) using namespace std; using ll=long long int ; int main() { /*int t ; cin>>t; while(t--) { */ ll k ; cin>>k; ll ans =0; for(int x=1;x<=k;x++) { for(int y=1;x*y<=k;y++) { for(int z=1;x*y*z<=k;z++) { if(x*y*z<=k) ans++; } } } cout<<ans<<endl; // } return 0; }
#include<stdio.h> #define putint(a) printf("%lld\n", a) #define nextint(a) scanf("%lld\n", &a) int N; int main(){ if(nextint(N)==1){ int ans = 0; for(long long int i=1; i<=N; i++){ for(int j=1; i*j<=N; j++){ ans+= N/(i*j); } } putint(ans); } }
#include <bits/stdc++.h> using namespace std; int H, W; char grid[2009][2009]; int memo[2009][2009]; int INF = 10000000; int MARKER = 2*INF; int score(int x, int y) { if (grid[x][y] == '+') return 1; if (grid[x][y] == '-') return -1; assert(false); } int p1_advantage(int x, int y) { if (memo[x][y] != MARKER) return memo[x][y]; int px = -INF; int py = -INF; if (x + 1 < H) px = score(x+1, y) - p1_advantage(x+1, y); if (y + 1 < W) py = score(x, y+1) - p1_advantage(x, y+1); if (px == -INF && py == -INF) return memo[x][y] = 0; return memo[x][y] = max(px, py); } int main() { cin >> H >> W; for (int i=0; i<H; i++) for (int j=0; j<W; j++) { cin >> grid[i][j]; memo[i][j] = MARKER; } for (int i=0; i<H; i++) for (int j=0; j<W; j++) { char c = grid[i][j]; assert(c == '+' || c == '-'); } int r = p1_advantage(0, 0); if (r == 0) cout << "Draw" << endl; if (r > 0) cout << "Takahashi" << endl; if (r < 0) cout << "Aoki" << endl; return 0; }
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; ///Welcome to Nasif's Code #define bug printf("bug\n"); #define bug2(var) cout<<#var<<" "<<var<<endl; #define co(q) cout<<q<<endl; #define all(q) (q).begin(),(q).end() #define pi acos(-1) #define inf 1000000000000000LL #define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define MODADD(ADD_X,ADD_Y) (ADD_X+ADD_Y)%MOD #define MODSUB(SUB_X,SUB_Y) ((SUB_X-SUB_Y)+MOD)%MOD #define MODMUL(MUL_X,MUL_Y) (MUL_X*MUL_Y)%MOD #define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int ll; typedef unsigned long long int ull; const int MOD = (int)1e9+7; const int MAX = 1e6; int dx[]= {1,0,-1,0,1,-1,1,-1}; int dy[]= {0,1,0,-1,1,-1,-1,1}; int dp[2025][2025][2],vis[2025][2025][2],mat[2025][2025],n,m; pair<int,int> recur(int x,int y,int f) { if(x==n || y==m) return {0,0}; if(vis[x][y][f]) return {dp[x][y][0],dp[x][y][1]}; vis[x][y][f]=1; if(!f) { pair<int,int>r= {0,0},d= {0,0},ans= {0,0}; if(x+1<n && y+1<m) { d=recur(x+1,y,f^1); d.first+=mat[x+1][y]; r=recur(x,y+1,f^1); r.first+=mat[x][y+1]; if(r.first-r.second>d.first-d.second) ans=r; else ans=d; } else if(x+1<n) { ans=recur(x+1,y,f^1); ans.first+=mat[x+1][y]; } else if(y+1<m) { ans=recur(x,y+1,f^1); ans.first+=mat[x][y+1]; } dp[x][y][0]=ans.first; dp[x][y][1]=ans.second; // cout<<x<<" "<<y<<" "<<ans.first<<endl; return ans; } else { pair<int,int>r= {0,0},d= {0,0},ans= {0,0}; if(x+1<n && y+1<m) { d=recur(x+1,y,f^1); d.second+=mat[x+1][y]; r=recur(x,y+1,f^1); r.second+=mat[x][y+1]; if(r.second-r.first>d.second-d.first) ans=r; else ans=d; } else if(x+1<n) { ans=recur(x+1,y,f^1); ans.second+=mat[x+1][y]; } else if(y+1<m) { ans=recur(x,y+1,f^1); ans.second+=mat[x][y+1]; } dp[x][y][0]=ans.first; dp[x][y][1]=ans.second; if(x==2 && y==2) bug return ans; } } int main() { FastRead //freopen("output.txt", "w", stdout); cin>>n>>m; for(int i=0; i<n; i++) { string s; cin>>s; for(int j=0; j<m; j++) { if(s[j]=='+') mat[i][j]=1; else mat[i][j]=-1; } } pair<int,int>p=recur(0,0,0); if(p.first>p.second) cout<<"Takahashi"<<endl; else if(p.first<p.second ) cout<<"Aoki"<<endl; else cout<<"Draw"<<endl; return 0; }
#include<bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> //Policy Based Data Structure // using namespace __gnu_pbds; //Policy Based Data Structure using namespace std; // typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; //Policy Based Data Structure // #define gc getchar_unlocked // #define pqb priority_queue<int> // #define pqs priority_queue<int, vi, greater<int> > // #define mk(arr,n,type) type *arr = new type[n] #define fo(i,n) for(i=0;i<n;i++) #define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define int long long #define nn '\n' #define w(t) cin>>tc; while(tc--) #define deb(x) cout << #x << "=" << x << endl #define deb2(x,y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it,a) for(auto it = a.begin(); it != a.end(); it++) #define ps(x,y) fixed<<setprecision(y)<<x #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define PI 3.1415926535897932384626 #define inf 1e18 // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //Random Shuffler typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpii; typedef vector<vi> vvi; typedef map<int, int> mii; int mpow(int base, int exp); void ipgraph(int m); void dfs(int u, int par); const int mod = 1000000007; // const int N = 3e5, M = N; // vi g[N]; // no of prime numbers in range : (70,19) , (1000,168) , (100000,1229) , (sqrt(10^9),3409) //======================= void sol() { int i, j, k, t, n, x, y, z, m, tc; string s; cin >> n >> m >> t; y = n; int a[m], b[m]; bool bo = true; fo(i, m) cin >> a[i] >> b[i]; int prev = 0; fo(i, m) { n -= (a[i] - prev); if (n <= 0) { bo = false; break; } n = min(n + b[i] - a[i], y); prev = b[i]; } if (bo) { n -= (t - prev); if (n <= 0) cout << "No" << nn; else cout << "Yes" << nn; } else { cout << "No" << nn; } } int32_t 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 sol(); return 0; } int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = (result * base) % mod; base = (base * base) % mod; exp >>= 1; } return result; } // void ipgraph(int n, int m){ // int i, u, v; // while(m--){ // cin>>u>>v; // g[u-1].pb(v-1); // g[v-1].pb(u-1); // } // } // // void dfs(int u, int par){ // for(int v:g[u]){ // if (v == par) continue; // dfs(v, u); // } // }
#include<iostream> using namespace std; int main() { int a , b , c , d ,x ,y ,diff; cin >> a >> b ; cout << endl ; cin >> c >> d ; x = a ; y = c ; diff = x - y ; while ( x <= b ) { y = c ; while ( y <= d) { int temp_diff; if( y > d) break ; temp_diff = x - y ; if(temp_diff > diff) { diff = temp_diff ; } y++; } //increment in x ++x ; } cout << diff ; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i)) #define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i)) #define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i)) #define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i)) #define ALL(x) ::std::begin(x), ::std::end(x) using namespace std; template <typename T> void print_vector(T& vec) { stringstream ss; //ss << "{"; for (auto v : vec) ss << v << " "; //ss << "}" << endl; cout << ss.str() << endl; } template <typename T> void print_pairs(T& vec) { stringstream ss; ss << "{"; for (auto v : vec) ss << v.first << "," << v.second << " "; ss << "}" << endl; cout << ss.str() << endl; } template <typename T> string string_vector(vector<T>& vec) { stringstream ss; //ss << "{"; for (auto v : vec) ss << v << endl; //ss << "}\n"; return ss.str(); } template <typename T> string string_vector(vector<vector<T>>& vec) { stringstream ss; //ss << "{"; for (auto v : vec) { //ss << "{"; for (auto vv : v) ss << vv << " "; //ss << "}"; } //ss << "}\n"; return ss.str(); } using ll = long long; class Solution { public: vector<int> seen; vector<int> loc; vector<int> solve(int N, vector<ll>& P) { int val = 1, pos = 0, start; vector<int> res; for(int i = 1; i <=N ; ++i) { if(loc[i] == i ) continue; for (int j = loc[i] - 1; j >= i; j--) { if(seen[j]++) { res.clear(); return res; } loc[P[j]] = j+1; loc[P[j+1]] = j; swap(P[j], P[j+1]); res.push_back(j); } } return res; } }; // generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator) int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); Solution sol; int N; cin >> N; vector<ll> P(N+1); sol.loc.resize(N+1); sol.seen.resize(N+1); REP (i, N) { cin >> P[i+1]; sol.loc[ P[i+1] ] = i+1;} vector<int> ans = sol.solve(N, P); if(ans.size() != N - 1) cout << -1 << endl; else cout << string_vector(ans) << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> using namespace std; using namespace __gnu_pbds; typedef long long ll; #define int long long typedef unsigned long long lu; typedef vector<ll> v; typedef vector<vector<ll> > vv; typedef vector<string> vs; typedef vector<pair<ll,ll>> vpr; typedef vector<bool>vb; typedef vector<double>vd; typedef long double ld; #define f(i,n) for(ll i = 0; i < n; i++) #define ff(i,n) for(ll i=1;i<=n;i++) #define pb push_back #define mp make_pair #define endl "\n" #define fi first #define se second #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define amax(x,y) if(y>x) x=y; #define amin(x,y) if(y<x)x=y; #define bg(x) x.begin() #define sz(x) (ll)x.size() #define in(x,n) for(ll i=0;i<n;i++)cin>>x[i] #define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " #define mxt(a) *(max_element(a.begin(),a.end())) #define mnt(a) *(min_element(a.begin(),a.end()) #define tc ll t;cin>>t;while(t--) typedef pair<ll,ll> pi; #define yes cout<<"YES\n"; // #define no cout<<"NO\n"; // #define yesno(f) if(f) yes else no const v dx = {1, -1, 0, 0}; const v dy = {0, 0, 1, -1}; const ld PI = 2 * acos(0.0); ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;} ll power(ll a,ll b,ll m) { if(b==0) return 1; ll d=power(a,b/2,m); d=(d*d)%m; if(b&1) d=(d*a)%m; return d; } const ll mod=1e9+7; int MOD(int a) { if(a<0) a+=mod; if(a>=mod) a%=mod; return a; } // set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time // set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time. /*string operations : str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1] str.substr (x) : returns a substring str[x],... end of string str.find(qtr) : returns the first occurenece of qtr in str */ void no() { cout<<-1<<endl; exit(0); } int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int n;cin>>n; vector<int>a(n);in(a,n); vector<int>b(n);in(b,n); vector<int>p(n);in(p,n); vector<int>inv(n); for (int i = 0; i < n; ++i) { p[i]--; inv[p[i]]=i; } // return 0; vpr operations; vb completed(n,false); for(int i=0;i<n;i++) { if(completed[i]) continue; int u=i; vector<int>cycle; while(p[u]!=i) { cycle.pb(u); completed[u]=true; u=p[u]; } // continue; cycle.pb(u); completed[u]=true; if(sz(cycle)!=1) { priority_queue<pi,vector<pi>,greater<pi> > que; for(auto it:cycle) { que.push({a[it],it}); } for(int j=0;j<cycle.size()-1;j++) { int lightest_i=que.top().second; que.pop(); if(b[p[lightest_i]] >= a[lightest_i]) no(); int a=inv[lightest_i]; operations.pb({lightest_i,a}); int b=p[lightest_i]; inv[b]=a; p[a]=b; } } } cout<<operations.size()<<endl; for(auto it:operations) cout<<it.first+1<<" "<<it.second+1<<endl; return 0; }
// // Created by whq on 2021/2/20. // #include <bits/stdc++.h> #define uset unordered_set #define umap unordered_map #define debug cout<<"ok"<<endl #define ll long long #define ii pair<ll, ll> #define fi first #define se second #define vi vector<int> #define vb vector<bool> #define vvi vector<vector<int>> #define vvb vector<vector<bool>> #define vvl vector<vector<ll>> #define vl vector<ll> #define mod 1000000007 #define inf 0x3f3f3f3f #define For(i, n) for (int i = 0; i < n; i++) #define forn(i, a, b) for(int i=a;i<=b;i++) #define pb(a) push_back(a) #define all(a) a.begin(),a.end() #define lowbit(x) x&(-x) using namespace std; class A{ public: void solve(){ int x; cin>>x; cout<<100-x%100<<endl; } }; class B{ public: void solve(){ string s; cin>>s; int n=s.size(); bool ok=true; for(int i=0;i<n;i++){ if(i%2==0&&isupper(s[i])) { ok=false; break; } if(i%2==1&&islower((s[i]))){ ok=false; break; } } if(ok) cout<<"Yes"<<endl; else cout<<"No"<<endl; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); B ans; ans.solve(); return 0; }
//#include <bits/stdc++.h> //using namespace std; #include <cstdio> #define rep(i,_l,_r) for(signed i=(_l),_end=(_r);i<=_end;++i) #define fep(i,_l,_r) for(signed i=(_l),_end=(_r);i>=_end;--i) #define erep(i,u) for(signed i=head[u],v=to[i];i;i=nxt[i],v=to[i]) #define efep(i,u) for(signed i=Head[u],v=to[i];i;i=nxt[i],v=to[i]) #define print(x,y) write(x),putchar(y) //#define debug(...) do {cerr<<__LINE__<<" : ("#__VA_ARGS__<<") = "; Out(__VA_ARGS__); cerr<<flush;} while(0) //template <typename T> void Out(T x) {cerr<<x<<"\n";} //template <typename T,typename ...I> void Out(T x,I ...NEXT) {cerr<<x<<", "; Out(NEXT...);} template <class T> inline T read(const T sample) { T x=0; int f=1; char s; while((s=getchar())>'9'||s<'0') if(s=='-') f=-1; while(s>='0'&&s<='9') x=(x<<1)+(x<<3)+(s^48),s=getchar(); return x*f; } template <class T> inline void write(const T x) { if(x<0) return (void) (putchar('-'),write(-x)); if(x>9) write(x/10); putchar(x%10^48); } template <class T> inline T Max(const T x,const T y) {if(x>y) return x; return y;} template <class T> inline T Min(const T x,const T y) {if(x<y) return x; return y;} template <class T> inline T fab(const T x) {return x>0?x:-x;} template <class T> inline T gcd(const T x,const T y) {return y?gcd(y,x%y):x;} template <class T> inline T lcm(const T x,const T y) {return x/gcd(x,y)*y;} template <class T> inline T Swap(T &x,T &y) {x^=y^=x^=y;} #include <map> using namespace std; typedef long long ll; const int maxn=3e5+5; int n; ll a[maxn],ans; map <ll,int> mp; int main() { n=read(9); rep(i,1,n) a[i]=a[i-1]+read(9)*((i&1)?1:-1); mp.insert(make_pair(0,1)); rep(i,1,n) { if(mp.count(a[i])) ans+=(mp[a[i]]++); else mp.insert(make_pair(a[i],1)); } print(ans,'\n'); return 0; }
#include <bits/stdc++.h> #include <math.h> #include <cmath> using namespace std; using ll =long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vs = vector<string>; using vvs = vector<vs>; using vc = vector<char>; using vvc = vector<vc>; using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>; using vp =vector<pair<ll,ll>>; using vvp =vector<vp>; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } const long long INF = 1LL << 60; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define REP(i,a,b) for(ll i=a;i<b;i++) #define rep(i,n) REP(i,0,n) #define all(a) a.begin(),a.end() #define pb(a) push_back(a) #define eb emplace_back #define pd(a) printf("%.10f\n",a) #define mem(a) memset(a,0,sizeof(a)) #define fr(i,a,b) for(int i=a;i<b;i++) #define pri(a) printf("%.14lf\n",a); #define MOD 1000000007 #define dup(x,y) (((x)+(y)-1)/(y)) #define fi first #define se second #define sz(x) (ll)(x).size() bool is_int_lround(double x){ return std::lround(x)==x; } ll keta(ll x){ ll n=0; while(x>0){ x /=10 ; n ++; } return n; } ll conbi(int n,int m){ cin>>n>>m; vector<ll> a(100); a[0] =1; for(int i=0;i<14;i++){ a[i+1]=a[i]*(i+1); } return a[n] /(a[m] *a[n-m]); } long long fac[510000], finv[510000], inv[510000]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < 510000; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } long long modpow(long long a, long long n, long long mod) { long long res = 1;//繰り返し二乗法 while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ll kaijo(ll x){ ll z=1; if(x==0){ return 1; } while(x>0){ z *=x; z %=MOD; x--; } return z; } ll yakusu_num(ll n){ vl yakusu(n+1,1); for(ll i=2;i*i<=n;i++){ while(n%i==0){ n /=i; yakusu[i]++; } } if(n!=1)yakusu[n]++; ll num=1; for(ll i=0;i <=n;i++){ num*=yakusu[i]; } return num; } struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化 for(int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); //xの根をrx int ry = root(y); //yの根をry if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; //cout<<""<<endl; // ./a.out // g++ 201110.cpp //cout << fixed << setprecision(10) << << endl; int main() { string S;cin>>S; bool can=false; rep(j,12){ bool ok=true; rep(i,S.size()/2){ if(S[i]!=S[S.size()-1-i])ok=false; } S='0'+S; if(ok){ can=true; break; } } if(can)cout<<"Yes"<<endl; else cout<<"No"<<endl; }
#include<bits/stdc++.h> using namespace std; int main() { int64_t n; cin >> n; while(n % 10 == 0 && n > 0) n /= 10; vector<int> n_dig; while(n > 0) { n_dig.push_back(n % 10); n /= 10; } bool can_palindrome = true; int dig_num = n_dig.size(); for(int i = 0; i < dig_num/2; i++) { if(n_dig[i] != n_dig[dig_num - 1 - i]) can_palindrome = false; } if(can_palindrome) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include<iostream> #include<cstdio> #include<ctime> #include<cmath> #include<cstdlib> #include<cstring> #include<string> #include<vector> #include<iomanip> #include<fstream> #include<stack> #include<queue> #include<set> #include<map> #include<algorithm> #include<sstream> using namespace std; #define sync std::ios::sync_with_stdio(false);std::cin.tie(0) //string::npos const double pi = 3.141592653589; const int maxn = 500002; const int maxm = 26; const int mod = 998244353; const int inf = 0x3f3f3f3f; typedef long long ll; int main(){ sync; ll ans = 0; int n, m; cin >> n >> m; string t; for(int i = 1; i <= n; ++i){ cin >> t; int cnt=0; for(int j = 0; j < m; ++j){ if(t[j]=='1') cnt++; } if(cnt&1) ans++; } cout << ans*(n-ans) << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> #include <map> #include <cstdio> #include <string> #include <cmath> #include <queue> #include <tuple> #include <bitset> #include <cassert> #include <chrono> #include <cstring> #include <iomanip> #include <iostream> #include <random> #include <set> #include <stack> #include <time.h> #include <unordered_map> #include <unordered_set> //#include <bits/stdc++.h> #define maxs(x,y) x = max(x,y) #define mins(x,y) x = min(x,y) #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,i0,n) for(int (i)=(i0);(i)<(n);(i)++) #define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--) #define SORT(x) sort(x.begin(),x.end()) #define SORTR(x) sort(x.begin(),x.end(),greater<int>()) #define fi first #define se second #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple using namespace std; using ll = long long; using LL = long long; typedef std::pair<int, int> pii; typedef std::pair<int, double> pid; typedef std::vector<int> vi; typedef std::vector<pii> vii; const double PI = 3.14159265358979323846264338327950L; const int mod = 1e9+7; 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 { mint res(*this); return res+=a; } mint operator-(const mint a) const { mint res(*this); return res-=a; } mint operator*(const mint a) const { mint res(*this); return res*=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 { mint res(*this); return res/=a; } }; const ll INF = 1LL<<60; struct container { int bottom, top, id; container(int id, int bottom, int top) : top(top), bottom(bottom), id(id) { } }; struct Edge { ll to, from, cost; Edge(ll to, ll from, ll cost) :to(to), from(from), cost(cost) {} Edge(): to(-1), from(-1), cost(0){} }; struct Data { ll cost,val; Data(ll cost=0, ll val=0) : cost(cost), val(val){} bool operator<(const Data& a) const { return cost > a.cost; } }; struct edge{ int a,b,c; edge(int a = -1,int b = -1, int c = -1):a(a),b(b),c(c){} bool operator<(const edge& a) const { return c > a.c; } }; struct combination { vector<mint> fact, ifact; combination(int n):fact(n+1),ifact(n+1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } }; void solve(){ int n,m; cin >> n >> m; ll ans = 0; vector<ll> cntr(2); rep(i,n){ int cnt = 0; string s; cin >> s; for(auto e:s){ if (e=='1') cnt^=1; } cntr[cnt]++; } cout << cntr[0]*cntr[1]; } int main() { int T = 1; // cin >> T; while (T--) { solve(); // cout << endl; } }
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x,y) cout<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define pw(b,p) pow(b,p) + 0.1 #define endl "\n" mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void __print(int32_t x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif char myHeap[200 * 1024 * 1024]; int sz = 0; void assert_tle(bool q) { while (!q); } void* operator new ( std::size_t count ) { sz += count; assert_tle(sz <= 200 * 1024 * 1024); return myHeap + sz - count; } void operator delete (void *ptr) { } void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } struct djsets { vector<int> leader; vector<int> rank; void init(int n) { rank.assign(n,1); for(int i=0;i<n;i++) { leader.push_back(i); } } int retleader(int node) { if(leader[node]==node) return node; int p= retleader(leader[node]); leader[node]=p; return p; } void connect(int a,int b) { a=retleader(a); b=retleader(b); if(rank[a]>rank[b]) { leader[b]=a; } else if(rank[b]>rank[a]) { leader[a]=b; } else { leader[b]=a; rank[a]++; } } int retans() { int ans=0; for(int i=0;i<leader.size();i++) if(leader[i]==i&&rank[i]>1) ans++; return ans-1; } }; void solve() { int h,w; cin>>h>>w; string str[h]; for(int i=0;i<h;i++) { cin>>str[i]; } str[0][0]=str[h-1][0]=str[h-1][w-1]=str[0][w-1]='#'; djsets d; d.init(h+w); for(int i=0;i<h;i++) { for(int j=0;j<w;j++) { if(str[i][j]=='#') { d.connect(i,h+j); } } } int rows=0,col=0; for(int i=0;i<h;i++) { if(d.rank[d.retleader(i)]==1) rows++; } for(int i=h;i<h+w;i++) { if(d.rank[d.retleader(i)]==1) col++; } cout<<d.retans()+min(rows,col); } int32_t main() { fastIO(); //w(t) { solve(); cout<<endl; } return 0; }
// Artur Kraska, II UWr #include <bits/stdc++.h> #define forr(i, n) for(int i=0; i<n; i++) #define FOREACH(iter, coll) for(auto iter = coll.begin(); iter != coll.end(); ++iter) #define FOREACHR(iter, coll) for(auto iter = coll.rbegin(); iter != coll.rend(); ++iter) #define lbound(P,R,PRED) ({typeof(P) X=P,RRR=(R), PPP = P; while(PPP<RRR) {X = (PPP+(RRR-PPP)/2); if(PRED) RRR = X; else PPP = X+1;} PPP;}) #define testy() int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests) #define CLEAR(tab) memset(tab, 0, sizeof(tab)) #define CONTAIN(el, coll) (coll.find(el) != coll.end()) #define FOR(i, a, b) for(int i=a; i<=b; i++) #define FORD(i, a, b) for(int i=a; i>=b; i--) #define MP make_pair #define PB push_back #define ff first #define ss second #define deb(X) X; #define M 1000000007 #define INF 1000000007LL using namespace std; int n, m, a; char slowo[1007][1007]; int o[1000007], byl[1000007]; int Find(int nr) { if(o[nr] < 0) return nr; o[nr] = Find(o[nr]); return o[nr]; } void Union(int a, int b) { a = Find(a); b = Find(b); if(a != b) o[a] = b; } int solve() { forr(i, n+5) { o[i] = -1; byl[i] = 0; } Union(0, n-1); FOR(i, 1, n-2) if(slowo[i][0] == '#' || slowo[i][m-1] == '#') Union(i, 0); FOR(j, 1, m-2) { int last = -1; FOR(i, 0, n-1) if(slowo[i][j] == '#') { if(last != -1) { Union(last, i); } last = i; } } byl[Find(0)] = 1; int res = 0; FOR(i, 0, n-1) { int x = Find(i); if(!byl[x]) { byl[x] = 1; res++; } } return res; } int main() { scanf("%d %d", &n, &m); forr(i, n) { scanf("%s", slowo[i]); } int x = solve(); swap(n, m); FOR(i, 0, max(n, m)) FOR(j, 0, i-1) { swap(slowo[i][j], slowo[j][i]); } int y = solve(); printf("%d\n", min(x, y)); return 0; }
#include<bits/stdc++.h> using namespace std; inline int read(){ int res=0; char c; bool zf=0; while(((c=getchar())<'0'||c>'9')&&c!= '-'); if(c=='-')zf=1; else res=c-'0'; while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0'; if(zf)return -res; return res; } signed main(){ int T=read(); while(T--){ int n=read(); for(register int i=0;i<3;++i){ string s;cin>>s; } for(register int i=1;i<=n;++i){ putchar('0'); } for(register int i=1;i<=n;++i){ putchar('1'); } puts("0"); } return 0; }
#include <iostream> using namespace std; void solve() { int n; string s1,s2,s3; cin >> n >> s1 >> s2 >> s3; cout << string(n,'0') << string(n,'1') << '0' << endl; } int main() { int t; cin >> t; for (int _=0; _<t; _++) solve(); return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i) #define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i) using ll = long long; using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); ll n; cin >> n; vector<pair<int, int>> a(n + 1); int empty = 0; vector<int> fl(n * 2 + 10, empty); REP(i, 1, n + 1) { cin >> a[i].first >> a[i].second; if (a[i].first != -1) { if (fl[a[i].first] != empty) { cout << "No" << endl; return 0; } fl[a[i].first] = i; } else a[i].first = empty; if (a[i].second != -1) { if (fl[a[i].second] != empty) { cout << "No" << endl; return 0; } fl[a[i].second] = -i; } else a[i].second = empty; } auto ok = [&](int l, int r) { if (r > 2 * n || fl[l] < 0 || fl[r] > 0) return false; if (fl[l] == empty && fl[r] == empty) return true; if (fl[l] == empty && fl[r] < 0 && a[-fl[r]].first == empty) return true; if (fl[r] == empty && fl[l] > 0 && a[fl[l]].second == empty) return true; if (fl[l] == -fl[r]) return true; return false; }; auto solve = [&](int l, int r) { int d = r - l; if (!ok(l, r)) return false; REP(i, l + 1, r) { if (!ok(i, i + d)) return false; } return true; }; vector<bool> dp(2 * n + 2); dp[1] = 1; REP(i, 1, 2 * n) if (dp[i] && fl[i] >= 0) { if (fl[i] > 0) { if (a[fl[i]].second != empty) { if (solve(i, a[fl[i]].second)) { dp[2 * a[fl[i]].second - i] = 1; } } else { REP(j, i + 1, 2 * n + 1) if (solve(i, j)) { dp[2 * j - i] = 1; } } } else { REP(j, i + 1, 2 * n + 1) { if (solve(i, j)) { dp[2 * j - i] = 1; } } } } if (dp.back()) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1000000007; struct point { ll x, y; }; int main(void) { point s, g; cin >> s.x >> s.y >> g.x >> g.y; ll ans = 0; if (s.x == g.x && s.y == g.y) { cout << 0; return 0; } else if (abs(s.x - g.x) + abs(s.y - g.y) <= 3 || s.x + s.y == g.x + g.y || s.x - s.y == g.x - g.y) { cout << 1; return 0; } for (ll i = 0; i <= 3; i++) { if (s.x + s.y + i == g.x + g.y || s.x + s.y == g.x + g.y + i || s.x + s.y - i == g.x + g.y || s.x + s.y == g.x + g.y - i || s.x - s.y + i == g.x - g.y || s.x - s.y == g.x - g.y + i || s.x - s.y - i == g.x - g.y || s.x - s.y == g.x - g.y - i) { cout << 2; return 0; } } if (s.y == g.y && abs(s.x - g.x) <= 6 || s.x == g.x && abs(s.y - g.y) <= 6) { cout << 2; return 0; } if ((abs(g.x - s.x) + abs(g.y - s.y)) % 2 == 0) { cout << 2; return 0; } else { cout << 3; return 0; } }
#include <bits/stdc++.h> using namespace std; const int di[] = {1, -1, 0, 0}; const int dj[] = {0, 0, 1, -1}; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int h, w; cin >> h >> w; vector <string> g(h); vector < vector < pair <int, int> > > go(26); int si, sj, gi, gj; for(int i = 0; i < h; i++){ cin >> g[i]; for(int j = 0; j < w; j++){ if(g[i][j] == 'S')si = i, sj = j; if(g[i][j] == 'G')gi = i, gj = j; if('a' <= g[i][j] && g[i][j] <= 'z'){ go[g[i][j] - 'a'].push_back({i, j}); } } } vector <int> d(h * w + 26, -1); vector <bool> vis(h * w + 26, false); deque <int> q; d[si * w + sj] = 0; q.push_back(si * w + sj); while(!q.empty()){ int u = q.front(); q.pop_front(); if(vis[u])continue; vis[u] = true; if(u >= h * w){ int c = u - h * w; for(auto [ni, nj] : go[c]){ if(d[ni * w + nj] == -1 || d[ni * w + nj] > d[u] + 1){ d[ni * w + nj] = d[u] + 1; q.push_back(ni * w + nj); } } }else{ int i = u / w, j = u % w; if('a' <= g[i][j] && g[i][j] <= 'z'){ if(d[h * w + g[i][j] - 'a'] == -1 || d[h * w + g[i][j] - 'a'] > d[u]){ d[h * w + g[i][j] - 'a'] = d[u]; q.push_front(h * w + g[i][j] - 'a'); } } for(int dir = 0; dir < 4; dir++){ int ni = i + di[dir], nj = j + dj[dir]; if(ni < 0 || ni >= h || nj < 0 || nj >= w)continue; if(g[ni][nj] == '#')continue; if(d[ni * w + nj] == -1 || d[ni * w + nj] > d[u] + 1){ d[ni * w + nj] = d[u] + 1; q.push_back(ni * w + nj); } } } } printf("%d\n", d[gi * w + gj]); return 0; }
#include<bits/stdc++.h> #define rep(i,N) for(int i=0;i<(N);i++) #define rrep(i, n) for (int i = (int)n-1; i >= 0; --i) #define FOR(i,a,b) for(int i=(a);i<(b);i++) using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e12; const int inf = 1e9; const int mod = 1e9+7; typedef long long ll; typedef pair<ll,int> P; typedef set<int> S; 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; } __attribute__ ((constructor)) void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(10); } int main(){ int N, M; cin >> N >> M; vector<vector<int>> to(N); rep(i,M){ int a, b; cin >> a >> b; a--; b--; to[a].push_back(b); to[b].push_back(a); } int k; cin >> k; vector<int> c(k); rep(i, k) cin >> c[i]; rep(i, k) c[i]--; // k個の頂点間の最短距離をBFSして求める. auto bfs = [&](int now_c) { vector<int> dist(N,inf); dist[now_c] = 0; queue<int> que; que.push(now_c); while(!que.empty()){ int c_front = que.front(); que.pop(); for(auto u : to[c_front]){ if(dist[u] != inf) continue; chmin(dist[u], dist[c_front] + 1); que.push(u); } } return dist; }; vector<vector<int>> dist_k(k, vector<int>(k, inf)); rep(i,k){ auto dist = bfs(c[i]); rep(j, k){ if(dist[c[j]] != inf){ chmin(dist_k[i][j],dist[c[j]]); } } } // bit DP int k2 = 1 << k; vector<vector<int>> dp(k2, vector<int>(k, inf)); // 初期化 rep(i,k){ dp[1<<i][i] = 1; //1個の石のみ } rep(i,k2){ rep(j, k){ if(!(i>>j)&1) continue; rep(l, k){ if(i>>k&1) continue; chmin(dp[i | 1 << l][l], dp[i][j] + dist_k[j][l]); } } } int ans = inf; rep(i,k){ chmin(ans,dp[k2-1][i]); } if(ans != inf) cout << ans << endl; else cout << -1 << endl; return 0; }
#include <bits/stdc++.h> const long long INF = 1e9; const long long MOD = 1e9 + 7; //const long long MOD = 998244353; const long long LINF = 1e18; using namespace std; #define YES(n) cout << ((n) ? "YES" : "NO" ) << endl #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl #define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl #define Possible(n) cout << ((n) ? "Possible" : "Impossible" ) << endl #define dump(x) cout << #x << " = " << (x) << endl #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) for(int i=0;i<(n);++i) #define REPR(i,n) for(int i=n;i>=0;i--) #define COUT(x) cout<<(x)<<endl #define SCOUT(x) cout<<(x)<<" " #define VECCOUT(x) for(auto&youso_: (x) )cout<<right<<setw(10)<<youso_<<" ";cout<<endl #define ENDL cout<<endl #define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__) #define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__) #define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__) #define VECCIN(x) for(auto&youso_: (x) )cin>>youso_ #define mp make_pair #define PQ priority_queue<long long> #define PQG priority_queue<long long,V,greater<long long>> typedef long long ll; typedef vector<long long> vl; typedef vector<long long> vi; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<vl> vvl; typedef vector<vi> vvi; typedef vector<vb> vvb; typedef vector<vc> vvc; typedef pair<long long, long long> pll; #define COUT(x) cout<<(x)<<endl void CINT(){} template <class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){ cin>>head; CINT(move(tail)...); } template<class T> void mod(T &x) { x %= MOD; x += MOD; x %= MOD; } ll GCD(ll a, ll b) { if(b == 0) return a; else return GCD(b, a%b); } struct COMB{ vl fact, fact_inv, inv; void init_nCk(long long SIZE) { fact.resize(SIZE + 5); fact_inv.resize(SIZE + 5); inv.resize(SIZE + 5); fact.at(0) = fact.at(1) = fact_inv.at(0) = fact_inv.at(1) = inv.at(1) = 1; for(long long i = 2; i < SIZE + 5; i++) { fact.at(i) = fact.at(i - 1)*i%MOD; inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD; fact_inv.at(i) = fact_inv.at(i - 1)*inv.at(i)%MOD; } } long long nCk (long long n, long long k) { assert(!(n < k)); assert(!(n < 0 || k < 0)); return fact.at(n)*(fact_inv.at(k)*fact_inv.at(n - k)%MOD)%MOD; } }; ll extGCD(ll a, ll b, ll &x, ll &y) { if(b == 0) { x = 1; y = 0; return a; } ll d = extGCD(b, a%b, y, x); y -= a/b*x; return d; } void Main() { LCIN(T); for(int i = 0; i < T; i++) { LCIN(N); SCIN(S1, S2, S3); for(int i = 0; i < N; i++) { cout << 0; } for(int i = 0; i < N; i++) { cout << 1; } cout << 0 << endl; } } int main() { cout << fixed << setprecision(15); Main(); return 0; }
//Bismillahir Rahmanir Raheem #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair<int,int> pii; typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie; #define fi first #define se second #define PI 3.14159265 #define mod 998244353 #define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ///order_of_key find_by_order const ll INFLL = 1e18; const ll INF =1e9; const ll EPS =1e-9; void fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } 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*b)/gcd(a,b);} ll ncr(ll n,ll r){ ll ans=1;for(ll i=1;i<=r;i++) ans=(ans*(n-i+1))/i;return ans;} int main() { int t; cin>>t; while(t--) { int n; string s1,s2,s3; cin>>n>>s1>>s2>>s3; for(int i=0;i<n;i++) cout<<1; for(int i=0;i<n;i++) cout<<0; cout<<1<<endl; } }
#include <iostream> #include <vector> #include <utility> #include <numeric> #include <limits> #include <tuple> #include <cmath> using ull = unsigned long long int; using ll = long long int; int main() { std::string s; std::cin >> s; bool flag = true; for(ull i = 0; i<s.size(); i++) { if(i%2 == 0 and int(s[i]) < 96) { std::cout<<"No\n"; flag = false; break; } else if(i%2 == 1 and int(s[i]) > 96) { std::cout<<"No\n"; flag = false; break; } } if(flag) std::cout<<"Yes\n"; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; int main(){ int i,n; cin >> n; int ans=0; for(i=1;i<=n;i++){ int a=i,res=0; while(a!=0){ if(a%10==7){ ans++,res=1; break; } a/=10; } if(res==1){ continue; } a=i,res=0; while(a!=0){ if(a%8==7){ ans++,res=1; break; } a/=8; } if(res==1){ continue; } } cout << n-ans << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define endl "\n" #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x.size()) int powmod(int a,int l, int md){a%=md; int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;} int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;} int invmod(int a, int md){return powmod(a,md-2,md);} typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector< ii > vii; #define pb push_back int __set(int b, int i) {return b|(1LL<<i);} //set ith bit int __unset(int b, int i) {return b&(~(1UL<<i));} int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0 int mulmod(int a, int b, int md) {return (((a%md)*(b%md))%md+md)%md;} int addmod(int a, int b, int md) {return ((a%md+b%md)%md+md)%md;} int submod(int a, int b, int md) {return (((a%md-b%md)%md)+md)%md;} int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime; const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int MOD=998244353; char mat[5010][5010]; int dp[5010][5010],sufr[5010][5010],sufc[5010][5010]; signed main(void) { IOS; int n,m,k; cin>>n>>m>>k; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) mat[i][j] = '0'; } for(int i = 0; i < k; i++) { int r,c; char ch; cin>>r>>c>>ch; mat[r-1][c-1] = ch; } // int sufr[n][m], sufc[m][n]; for(int i = 0; i < n; i++) { sufr[i][m-1] = 0; if(mat[i][m-1] == '0') sufr[i][m-1]++; for(int j = m-2; j >= 0; j--) { sufr[i][j] = sufr[i][j+1]; if(mat[i][j] == '0') sufr[i][j]++; } } for(int i = 0; i < m; i++) { sufc[i][n-1] = 0; if(mat[n-1][i]=='0') sufc[i][n-1]++; for(int j = n-2; j >= 0; j--) { sufc[i][j] = sufc[i][j+1]; if(mat[j][i] == '0') sufc[i][j]++; } } // int dp[n][m]; // for(int i = 0; i < n; i++) { // for(int j = 0; j < m; j++) // cout<<sufr[i][j]<<" "; // cout<<endl; // } // cout<<endl<<endl; // for(int i = 0; i < m; i++) { // for(int j = 0; j < n; j++) // cout<<sufc[i][j]<<" "; // cout<<endl; // } // memset(dp,0,sizeof(dp)); int po[5010]; po[0]=1; for(int i = 1; i < 5010; i++) { po[i] = po[i-1]*3; if(po[i] >= MOD) po[i] %= MOD; } dp[0][0]=1; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(i-1 >= 0) { if(mat[i-1][j] != 'R') { int tp=0; if(j+1<m) tp = sufr[i-1][j+1]; int tmp = dp[i-1][j]*po[tp]; if(tmp >= MOD) tmp %= MOD; if(mat[i][j] == '0') { tmp *= 2; if(tmp >= MOD) tmp %= MOD; } dp[i][j] += tmp; if(dp[i][j] >= MOD) dp[i][j] %= MOD; } } if(j-1 >= 0 && mat[i][j-1] != 'D') { int tp = 0; if(i+1 < n) tp = sufc[j-1][i+1]; int tmp = dp[i][j-1]*po[tp]; if(tmp >= MOD) tmp %= MOD; if(mat[i][j] == '0') { tmp *= 2; if(tmp >= MOD) tmp %= MOD; } dp[i][j] += tmp; if(dp[i][j] >= MOD) dp[i][j] %= MOD; } } } // for(int i = 0; i < n; i++) { // for(int j = 0; j < m; j++) // cout<<dp[i][j]<<" "; // cout<<endl; // } if(mat[n-1][m-1]=='0') { dp[n-1][m-1] *= 3; dp[n-1][m-1]%= MOD; } cout<<dp[n-1][m-1]<<endl; return 0; }
#include <bits/stdc++.h> #ifdef LOCAL #include "../../Library/DebugTool.cpp" #endif using namespace std; #define ll long long #define pii pair<int,int> //const ll MOD = 1000000007; const ll MOD = 998244353; ll INF_int = 1e9+11;ll INF_ll = 1e18 + 13; #define rep(i,n) for(int i = 0;i<n;i++) #define rep1(i,n) for(int i = 1;i<n;i++) #define per(i,n) for(int i = n-1;i>=0;i--) #define mp make_pair #define All(a) a.begin(),a.end() void in(){} template<typename Head,typename ...Tail>void in(Head&& head,Tail&& ...tail){cin >> head;in(std::forward<Tail>(tail)...);} template<typename T>void vecin(vector<T> &vec){int n = vec.size();rep(i,n) cin >> vec[i];} void out(){cout << "\n";} template<typename Head,typename ...Tail>void out(Head&& head,Tail&& ...tail){cout << head << " ";out(std::forward<Tail>(tail)...);} template<typename T>void vecout(vector<T> a){for(auto x:a)cout << x << " ";cout << endl;} template<typename T>bool umax(T &x,const T &y){if(x<y){x=y;return true;}return false;} template<typename T>bool umin(T &x,const T &y){if(x>y){x=y;return true;}return false;} template<int MOD> struct mint{ ll x; mint(ll a=0) : x(((a%MOD)+MOD)%MOD) {} mint &operator += (const mint &a){ x+=a.x;if(x>=MOD)x-=MOD;return *this; } mint &operator -= (const mint &a){ x-=a.x;if(x<0)x+=MOD;return *this; } mint &operator *= (const mint &a){ x*=a.x;x%=MOD;return *this; } mint &operator /= (const mint &a){ x*=a.inv().x;x%=MOD;return *this; } mint operator + (const mint &a) const{ mint res(*this); return res+=a; } mint operator - (const mint &a) const{ mint res(*this); return res-=a; } mint operator * (const mint &a) const{ mint res(*this); return res*=a; } mint operator / (const mint &a) const{ mint res(*this); return res/=a; } mint pow(ll a) const{ mint now = *this;mint ret = 1; while(a>0){if(a&1) ret*=now;now*=now;a/=2;} return ret; } mint inv() const{ return pow(MOD-2); } mint combi(int k) const{ k = min(x,x-k); mint ret = 1; for(int i = x;i>=x-k+1;i--) ret*=mint(i); for(int i = 1;i<=k;i++) ret/=mint(i); return ret; } friend istream& operator >> (istream& is,mint& m){ ll a; is >> a;m = mint(a); return is; } friend ostream& operator << (ostream& os, const mint& m){ os << m.x; return os; } }; int main(){ int h,w,k;in(h,w,k); char state[h][w]; rep(i,h) rep(j,w) state[i][j] = 'x'; rep(i,k){ int a,b;char c;in(a,b,c); a--;b--;state[a][b]=c; } using mint = mint<MOD>; ll tate_acc[w][h+1],yoko_acc[h][w+1]; rep(i,h)rep(j,w+1) yoko_acc[i][j]=0; rep(i,h+1)rep(j,w) tate_acc[j][i]=0; rep(i,h) rep(j,w) if(state[i][j]=='x') {yoko_acc[i][j+1]=yoko_acc[i][j]+1;}else{yoko_acc[i][j+1]=yoko_acc[i][j];} rep(j,w) rep(i,h) if(state[i][j]=='x') {tate_acc[j][i+1]=tate_acc[j][i]+1;}else{tate_acc[j][i+1]=tate_acc[j][i];} mint dp[h][w]; rep(i,h) rep(j,w) dp[i][j] = mint(0); dp[0][0] = 1; vector<mint> th(5005); th[0]=mint(1); rep(i,5005) th[i+1]=th[i]*mint(3); rep(i,h){ rep(j,w){ if(i!=0){ if(state[i-1][j] == 'R') dp[i][j] += mint(0); else if(state[i-1][j] == 'D' || state[i-1][j] == 'X') dp[i][j] += (dp[i-1][j])*th[yoko_acc[i][j]]; else dp[i][j] += (mint(2)*dp[i-1][j])*th[yoko_acc[i][j]]; } if(j!=0){ if(state[i][j-1] == 'D') dp[i][j] += mint(0); else if(state[i][j-1] == 'R' || state[i][j-1] == 'X') dp[i][j] += (dp[i][j-1])*(th[tate_acc[j][i]]); else dp[i][j] += (mint(2)*dp[i][j-1])*(th[tate_acc[j][i]]); } } } if(state[h-1][w-1]=='x') dp[h-1][w-1]*=mint(3); out(dp[h-1][w-1]); }
// give up #include <bitset> #include <cassert> #include <iostream> #include <iomanip> #include <list> #include <numeric> #include <queue> #include <unordered_map> #include <unordered_set> #include <valarray> // alias, using declaration using llint = long long; using ldouble = long double; template <class T = llint> using vector = std::vector<T>; template <class T = llint> using deque = std::deque<T>; template <class T = llint> using list = std::list<T>; template <class T = llint, class U = llint> using umap = std::unordered_map<T, U>; template <class T = llint, class U = llint> using ummap = std::unordered_multimap<T, U>; template <class T = llint> using uset = std::unordered_set<T>; template <class T = llint> using umset = std::unordered_multiset<T>; template <class T = llint, class U = T> using pair = std::pair<T, U>; template <class T = llint> using varray = std::valarray<T>; template <class T = llint, class U = vector<T>, class V = std::less<class U::value_type>> using pqueue = std::priority_queue<T, U, V>; using std::array; using std::bitset; using std::string; using std::tuple; // constant constexpr llint INF = 0x7FFFFFFFFFFFFFFF; constexpr llint INVALID = 0x8000000000000000; namespace io { // in template <class... T, size_t... S> auto in(std::index_sequence<S...>) {tuple<T...> t; (..., (std::cin >> std::get<S>(t))); return t;} template <class... T, size_t... S> auto in(std::index_sequence<S...>, size_t n) {tuple<vector<T>...> t{vector<T>(n)...}; for (size_t i = 0; i < n; i++) (..., (std::cin >> std::get<S>(t)[i])); return t;} template <size_t N, class T = llint, class... U> auto in() {static_assert(N >= 1); if constexpr (N > 1) return in<N - 1, T, T, U...>(); else return in<T, U...>(std::index_sequence_for<T, U...>());} template <size_t N, class T = llint, class... U> auto in(size_t n) {static_assert(N >= 1); if constexpr (N > 1) return in<N - 1, T, T, U...>(n); else return in<T, U...>(std::index_sequence_for<T, U...>(), n);} template <size_t N, class T = llint> auto in(size_t n, size_t m) {static_assert(N == 1); vector<vector<T>> v(n, vector<T>(m)); for (auto&& vi : v) for (auto&& vij : vi) std::cin >> vij; return std::make_tuple(v);} // out template <class T, class... U> void out(const T& a, const U&... b) {std::cout << a << (sizeof...(b) ? " " : "\n"); if constexpr (sizeof...(b)) out(b...);} template <class T, class U = const char*> void out(const vector<T>& a, U d = " ") {for (auto&& b : a) std::cout << b << (&b != &a.back() ? d : "\n");} } int main() { // input auto [N, M, Q] = io::in<3>(); auto [T, X, Y] = io::in<3>(Q); // solve vector<> a(N + 1), b(M + 1); umap<> Z; { Z.emplace(0, 0); vector<> Y_ = Y; std::sort(Y_.begin(), Y_.end()); for (llint i = 0; i < Q; i++) Z.emplace(Y_.at(i), i + 1); } constexpr llint ST_SIZE = 1 << 19; vector<pair<>> st_a(ST_SIZE), st_b(ST_SIZE); auto update = [&Z](vector<pair<>>& st, llint v, llint n) { for (llint i = (ST_SIZE >> 1) + Z.at(v); i > 0; i >>= 1) { st.at(i).first += n; st.at(i).second += v * n; } }; auto culc_line = [&Z](const vector<pair<>>& st, llint v) { llint r = st.at((ST_SIZE >> 1) + Z.at(v)).second; for (llint i = (ST_SIZE >> 1) + Z.at(v); i > 1; i >>= 1) { r += i & 1 ? st.at(i ^ 1).first * v : st.at(i ^ 1).second; } return r; }; update(st_a, 0, N); update(st_b, 0, M); vector<> result(Q); for (llint i = 0; i < Q; i++) { auto& t = (T.at(i) == 1 ? a : b).at(X.at(i)); auto& st_x = T.at(i) == 1 ? st_a : st_b; auto& st_y = T.at(i) == 1 ? st_b : st_a; update(st_x, t, -1); result.at(i) = -culc_line(st_y, t); t = Y.at(i); update(st_x, t, 1); result.at(i) += culc_line(st_y, t); } for (llint i = 1; i < Q; i++) result.at(i) += result.at(i - 1); // output io::out(result, "\n"); }
#include<bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x){ x=0;char ch=getchar();bool f=false; while(!isdigit(ch)){if(ch=='-'){f=true;}ch=getchar();} while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} x=f?-x:x; return ; } template <typename T> inline void write(T x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10^48); return ; } #define ll long long const int N=2e5+5,M=1e8; int n,m,q; ll a[N],b[N]; struct SGTree{ int cur,root; ll sum[N*80]; int num[N*80],ls[N*80],rs[N*80]; void Modify(int &x,int l,int r,int pos,int v,int tp){ if(!x) x=++cur; int mid=l+r>>1;sum[x]+=v*tp;num[x]+=tp; if(l==r) return ; if(pos<=mid) Modify(ls[x],l,mid,pos,v,tp); else Modify(rs[x],mid+1,r,pos,v,tp); return ; } ll QuerySum(int x,int l,int r,int ql,int qr){ if(ql>qr||!x) return 0; if(ql<=l&&r<=qr) return sum[x]; int mid=l+r>>1;ll res=0; if(ql<=mid) res+=QuerySum(ls[x],l,mid,ql,qr); if(qr>mid) res+=QuerySum(rs[x],mid+1,r,ql,qr); return res; } int QueryNum(int x,int l,int r,int ql,int qr){ if(ql>qr||!x) return 0; if(ql<=l&&r<=qr) return num[x]; int mid=l+r>>1,res=0; if(ql<=mid) res+=QueryNum(ls[x],l,mid,ql,qr); if(qr>mid) res+=QueryNum(rs[x],mid+1,r,ql,qr); return res; } }t1,t2; ll Ans; int main(){ read(n),read(m),read(q); for(int i=1;i<=n;i++) t1.Modify(t1.root,0,M,a[i],a[i],1); for(int i=1;i<=m;i++) t2.Modify(t2.root,0,M,b[i],b[i],1); // for(int i=1;i<=n;i++){ // Ans+=1ll*t2.QueryNum(t2.root,0,M,1,a[i])*a[i]; // Ans+=1ll*t2.QuerySum(t2.root,0,M,a[i]+1,M); // } for(int i=1;i<=q;i++){ int op,pos;ll v; read(op),read(pos),read(v); if(op==1){ Ans-=1ll*t2.QueryNum(t2.root,0,M,0,a[pos])*a[pos]; Ans-=1ll*t2.QuerySum(t2.root,0,M,a[pos]+1,M); t1.Modify(t1.root,0,M,a[pos],a[pos],-1); a[pos]=v; Ans+=1ll*t2.QueryNum(t2.root,0,M,0,a[pos])*a[pos]; Ans+=1ll*t2.QuerySum(t2.root,0,M,a[pos]+1,M); t1.Modify(t1.root,0,M,a[pos],a[pos],1); } else{ Ans-=1ll*t1.QueryNum(t1.root,0,M,0,b[pos])*b[pos]; Ans-=1ll*t1.QuerySum(t1.root,0,M,b[pos]+1,M); t2.Modify(t2.root,0,M,b[pos],b[pos],-1); b[pos]=v; Ans+=1ll*t1.QueryNum(t1.root,0,M,0,b[pos])*b[pos]; Ans+=1ll*t1.QuerySum(t1.root,0,M,b[pos]+1,M); t2.Modify(t2.root,0,M,b[pos],b[pos],1); } write(Ans),putchar('\n'); } return 0; }
#include <bits/stdc++.h> #include <time.h> using namespace std; #define ll long long #define ld long double #define precision(x,d) cout<<fixed<<setprecision(d)<<x #define all(x) x.begin(),x.end() #define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL)); #define MOD 1000000007 #define INF LONG_LONG_MAX #define NINF LONG_LONG_MIN //#define endl "\n" #define yes cout<<"YES"<<endl #define no cout<<"NO"<<endl int main() { IOS; ll t,k,n,m,d,u,v; t=1; //cin >> t; while(t--) { cin >> n; vector<ll> v(n); ll ans = 0, mx = 0, pref = 0, prefpref = 0; for(int i=0;i<n;i++) { cin >> v[i]; pref += v[i]; mx = max(mx,pref); ans = max(ans,prefpref+mx); prefpref += pref; } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int N; cin >> N; vector<long long int> A(N), cumsum(N, 0); for(int i = 0; i < N; ++i) cin >> A.at(i); if(N == 1) { if(A.at(0) > 0) cout << A.at(0) << endl; else cout << 0 << endl; return 0; } cumsum.at(0) = A.at(0); for(int i = 1; i < N; ++i) { cumsum.at(i) = cumsum.at(i-1) + A.at(i); } // どのloop回数で最大化を探す long long int sum = A.at(0), candi = 0, candsum = A.at(0); vector<long long int> offset(N); offset.at(0) = A.at(0); // if(sum > 0) candi = 0; for(int i = 1; i < N; ++i) { candsum += cumsum.at(i); offset.at(i) = candsum; if(candsum > sum) { sum = candsum; // update candi = i; } // cout << offset.at(i) << endl; } long long int ans = offset.at(candi); // candsum = sum; for(int i = candi; i >= 0; --i) { sum -= A.at(i); ans = max(sum, ans); } sum = offset.at(candi); if(candi < N-1) { for(int i = 0; i <= candi+1; ++i) { sum += A.at(i); ans = max(sum, ans); } } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std ; #define ll long long #define pb push_back #define all(v) v.begin(),v.end() #define sz(a) (ll)a.size() #define F first #define S second #define INF 2000000000000000000 #define popcount(x) __builtin_popcountll(x) #define pll pair<ll,ll> #define pii pair<int,int> #define ld long double const int M = 1000000007; const int MM = 998244353; const long double PI = acos(-1); 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; } template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p) { return os<<'('<<p.F<< ","<<p.S<<')'; } const int N = 105; vector<int> v[N]; set<pii> A; bool vis[N]; int dep[N]; int a[N]; void dfs(int s,int p) { vis[s] = true; for(auto j:v[s]) { if(!vis[j]) { dep[j] = dep[s] + 1; A.insert({s,j}); dfs(j,s); } else if(j!=p && dep[j]<dep[s]) { A.insert({s,j}); } } } int _runtimeTerror_() { int n,m; cin>>n>>m; vector<int> ans(m,-1); vector<pii> ed; for(int i=0;i<m;++i) { int x,y; cin>>x>>y; ed.pb({x,y}); } for(int i=1;i<=n;++i) cin>>a[i]; // 0 right,1 left; int cur = 0; for(auto &[j,k]:ed) { if(a[j] != a[k]) { if(a[j]>a[k]) ans[cur] = 0; else ans[cur] = 1; } else { v[j].pb(k); v[k].pb(j); } ++cur; } for(int i=1;i<=n;++i) { if(!vis[i]) { dfs(i,0); } } cur = 0; for(auto &[j,k]:ed) { if(a[j]==a[k]) { if(A.count({j,k})) ans[cur] = 0; else ans[cur] = 1,assert(A.count({k,j})); } ++cur; } for(int i=0;i<m;++i) { cout<<(ans[i]?"<-":"->")<<"\n"; } return 0; } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef runSieve sieve(); #endif #ifdef NCR initialize(); #endif int TESTS=1; //cin>>TESTS; while(TESTS--) _runtimeTerror_(); return 0; }
#include<bits/stdc++.h> #define int long long #define ld long double #define all(X) (X).begin(), (X).end() #define reset(X) memset(X, 0, sizeof(X)) #define mp(a, b) make_pair(a, b) #define pb push_back #define endl '\n' #define ff first #define ss second using namespace std; const int mod=1e9+7; // const int mod=998244353; // const int mod=1e9+9; const int INF=4e18+10; // const int INF=4e18+10; typedef pair<int, int> pii; int power(int a, int b, int in_mod) { int ans=1; int prod=a; while(b) { if(b%2) ans=(ans*prod)%in_mod; prod=(prod*prod)%in_mod; b/=2; } return ans; } int mod_inv(int q, int in_mod) { return power(q, in_mod-2,in_mod); } int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b); } int fact(int n,int in_mod){ int f=1; for(int i=1;i<=n;i++) f=(f*i)%in_mod; return f; } int ncr(int n,int r,int in_mod){ return (((fact(n,in_mod)*mod_inv(fact(r,in_mod),in_mod))%in_mod)*mod_inv(fact(n-r,in_mod),in_mod))%in_mod; } const int N = 25; vector<int> adj[N]; int vis[N]={}; int edge[N][N]={}; int par[N]={}; void dfs(int s,int p,vector<int>& v){ v.pb(s); par[s]=p; vis[s]=1; for(auto u:adj[s]){ if(!vis[u]) dfs(u,s,v); } } void fun(vector<int>& v,int idx,vector<int>& col,int& cnt){ if(idx==v.size()){ int flag=0; for(int i=0;i<idx;i++){ for(int j=i+1;j<idx;j++){ if(edge[v[i]][v[j]] && col[v[i]]==col[v[j]]){ flag=1; } } } if(!flag) cnt++; return ; } set<int> st={1,2,3}; st.erase(col[par[v[idx]]]); for(auto f:st){ col[v[idx]]=f; fun(v,idx+1,col,cnt); col[v[idx]]=0; } } void solve() { //write code here int n,m; cin>>n>>m; for(int i=1;i<=m;i++){ int u,v; cin>>u>>v; adj[u].pb(v); adj[v].pb(u); edge[u][v]=1; edge[v][u]=1; } int ans=1; for(int i=1;i<=n;i++){ if(!vis[i]){ vector<int> v; dfs(i,-1,v); int cnt=0; vector<int> col(N,0); col[i]=1; fun(v,1,col,cnt); col[i]=2; fun(v,1,col,cnt); col[i]=3; fun(v,1,col,cnt); ans*=cnt; } } cout<<ans<<endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout<<fixed<<setprecision(10); #ifndef ONLINE_JUDGE if(fopen("INPUT.txt","r")) { freopen ("INPUT.txt" , "r" , stdin); freopen ("OUTPUT.txt" , "w" , stdout); } #endif auto clk=clock(); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // -------------------------------------Code starts here--------------------------------------------------------------------- int t=1; //cin>>t; for(int test=1;test<=t;test++) { // cout<<"Case #"<<test<<": "; // cout<<endl; solve(); // cout<<endl; } // -------------------------------------Code ends here------------------------------------------------------------------ clk = clock() - clk; cerr << fixed << setprecision(6) << "Time: " << ((long double)clk)/CLOCKS_PER_SEC << "\n"; return 0; } /* 1.do not use bitshift (1<<int) because it gives value in int and not in long long 2.check that for loops of i,j,k are properly declared 3.donot delete elements from map,set while looping in it 4.in a map's vector ,ie,map<int,vector<int>> mp,when you sort each vector in a loop it may not get sorted outside the scope of the loop so take care */
#include <bits/stdc++.h> using namespace std; typedef long long ll; //#define P pair<ll,ll> #define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I) #define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I) #define TO(x,t,f) ((x)?(t):(f)) #define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9 #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v x is sorted #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v x is sorted #define NUM(x,v) (POSU(x,v)-POSL(x,v)) //x is sorted #define REV(x) (reverse(x.begin(),x.end())) //reverse ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);} ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);} #define NEXTP(x) next_permutation(x.begin(),x.end()) const ll INF=ll(1e16)+ll(7); const ll MOD=1000000007LL; #define out(a) cout<<fixed<<setprecision((a)) //tie(a,b,c) = make_tuple(10,9,87); #define pop_(a) __builtin_popcount((a)) ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;} #define num_l(a,v) POSL(a,v) //v未満の要素数 #define num_eql(a,v) POSU(a,v) //v以下の要素数 #define num_h(a,v) (a.size() - POSU(a,v)) //vより大きい要素数 #define num_eqh(a,v) (a.size() - POSL(a,v)) //v以上の要素数 class dijkstra{ //0indexed public: int v,startv; vector<int> d; vector<vector<pair<int,int> > >e; void initsize(int n0){ d.resize(n0); for(int i=0;i<n0;i++)d[i]=INT_MAX; vector<pair<int,int> > ep; for(int i=0;i<n0;i++)e.push_back(ep); v=n0; } void initstart(int s){ startv=s; for(int i=0;i<v;i++)d[i]=INT_MAX; d[s]=0; } void make_edge(int x,int y,int cost){ e[x].push_back(make_pair(y,cost)); e[y].push_back(make_pair(x,cost)); } void make_edgedir(int x,int y,int cost){ e[x].push_back(make_pair(y,cost)); } void calcdistance(){ // <-cost,x> //cost startv->x priority_queue<pair<int,int> > q; pair<int,int> p; vector<bool> did; for(int i=0;i<v;i++)did.push_back(false); did[startv]=true; for(int i=0;i<e[startv].size();i++){ p.first=-e[startv][i].second; p.second=e[startv][i].first; q.push(p); } while(q.size()!=0){ pair<int,int> p; p=q.top(); q.pop(); int x,costsx; x=p.second; costsx=-p.first; if(did[x]==true)continue; did[x]=true; d[x]=costsx; for(int i=0;i<e[x].size();i++){ p.first=-(d[x]+e[x][i].second); p.second=e[x][i].first; if(did[p.second]==false)q.push(p); } } } }; int main(){ ll N,M; cin >> N >> M; vector< vector<pair<int,int>> > G(N); dijkstra di; di.initsize(N+1);//st ==> N FOR(i,0,M){ int a,b,c; cin >> a >> b >> c; G[a-1].push_back({b-1,c}); di.make_edgedir(a-1,b-1,c); } FOR(i,0,N){ di.e[N] = G[i]; di.initstart(N); di.calcdistance(); int ans = di.d[i]; if(ans == INT_MAX) ans = -1; cout << ans << endl; } }
#include<bits/stdc++.h> #define M(x,y) make_pair(x,y) #define ll long long using namespace std; struct node{ int u,to,next,val; };node e[4005]; int head[2005],dist[2005],vis[2005],dis[2005][2005],to[2005][2005],sum[2005],b[2005][2005]; int n,m,cnt=0,inf=999999999; void add(int u,int v,int val){ ++cnt; e[cnt].u=u; e[cnt].to=v; e[cnt].val=val; to[v][++sum[v]]=u; e[cnt].next=head[u]; head[u]=cnt; b[u][v]=min(b[u][v],val); } struct nd{ int id,dis; // nd() {} nd(int _id, int _dis) : id(_id), dis(_dis) {} bool friend operator < (nd a,nd b){ return a.dis<b.dis; } }; priority_queue< pair<int,int> > q; void dijstra(int s){ for(int i=1;i<=n;i++) dis[s][i]=inf; memset(vis,0,sizeof(vis)); dis[s][s]=0; q.push(M(0,s)); while(!q.empty()){ int u=q.top().second; q.pop(); if(vis[u]) continue; vis[u]=1; for(int i=head[u];i;i=e[i].next){ int v=e[i].to; if(dis[s][v]>dis[s][u]+e[i].val){ dis[s][v]=dis[s][u]+e[i].val; q.push(M(-dis[s][v],v)); } } } } int main(){ cin>>n>>m; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ b[i][j]=inf; } } for(int i=1;i<=m;i++){ int x,y,z; scanf("%d%d%d",&x,&y,&z); add(x,y,z); } for(int i=1;i<=n;i++){ dijstra(i); } //cout<<"sss"; /*for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cout<<dis[i][j]<<" "; } cout<<endl; }*/ for(int i=1;i<=n;i++){ int ans=inf; for(int j=1;j<=sum[i];j++){ if(dis[i][to[i][j]]!=inf){ ans=min(ans,dis[i][to[i][j]]+b[to[i][j]][i]); } } if(ans!=inf){ cout<<ans<<endl; } else{ cout<<"-1"<<endl; } } }
#include<iostream> #include<cmath> using namespace std; int main() { long long int n, k; cin >> n >> k; long long int ab = 2 * n; long long int res = 0; while (ab >= 2) { int cd = ab - k; if (cd >= 2 && cd <= 2 * n) { res += (n - abs(n + 1 - ab)) * (n - abs(n + 1 - cd)); } ab--; } cout << res << endl; return 0; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <utility> #include <set> using namespace std; typedef pair<int, int> pairII; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef long long LL; #define shig_for(i, a, b) for(int i = (a); i < (b); ++i) #define shig_rep(i, n) shig_for(i, 0, n) #define shig_forB(bit,a,b) for(int bit = (a); bit < (1<<(b)); ++bit) #define shig_repB(bit,n) shig_forB(bit,0,n) #define tmp int temp = 0 #define str string s int main(){ LL N, K, ans = 0; const LL zero = 0; cin >> N >> K; for(LL i = 2; i <= 2 * N; i++){ if(i - K >= 2){ //ans += (i - 1); //ans += (i - K - 1); LL tempA = -1 * (((i - N) - 1) * 2); LL tempB = -1 * (((i - K - N) - 1) * 2); tempA = min(zero, tempA); tempB = min(zero, tempB); tempA = max(zero, ((i - 1) + tempA)); tempB = max(zero, ((i - K - 1) + tempB)); //ans += ((i - 1) + min(zero, tempA) ) * ((i - K - 1) + min(zero, tempB) ); ans += tempA * tempB; } } cout << ans << endl; //cout << "Atcoder" << endl; return 0; }
#include<bits/stdc++.h> #define st first #define nd second #define mp make_pair #ifndef LOCAL #define cerr if(0)cerr #endif using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using pii = pair<int, int>; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; vector<int> a(2*n); for(int& i: a) cin>>i; ll ans = 0; for(int i: a) ans += i; priority_queue<int> pq; for(int i=0; i<n; ++i) { pq.push(-(a[n-i-1])); pq.push(-(a[n+i])); ans += pq.top(); pq.pop(); } cout<<ans<<'\n'; }
/** * author: shu8Cream * created: 19.12.2020 21:08:37 **/ #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=0; i<(n); i++) using ll = long long; using P = pair<int,int>; using vi = vector<int>; using vvi = vector<vi>; using Graph = vvi; int main() { int n; cin >> n; vector<ll> a(n); rep(i,n) cin >> a[i]; sort(a.begin(), a.end()); ll ans = 0; int j=0; for(int i=n-1; i>0; i-=2){ ans+=abs(a[j]-a[n-1-j])*i; j++; } cout << ans << endl; }
/** * created: 16/01/2021, 14:27:24 **/ #include <bits/stdc++.h> using namespace std; const int max_n = 1111, inf = 1000111222; int n, cnt[max_n][max_n]; vector<string> ans; int c2(int n) { return n * (n - 1) / 2; } bool get_bit(int mask, int pos) { return (mask >> pos) & 1; } void check() { for (string s : ans) { if (!(s.length() == (1 << n))) { cout << s.length() << endl; cout << (1 << n) << endl; exit(2); } for (int i = 0; i < s.length(); ++i) { for (int j = i + 1; j < s.length(); ++j) { cnt[i][j] += s[i] == s[j]; } } } for (int i = 0; i < (1 << n); ++i) { for (int j = i + 1; j < (1 << n); ++j) { cout << cnt[i][j] << " "; } cout << endl; } } vector<string> solve(int n) { if (n == 1) { return {"AB"}; } vector<string> v = solve(n - 1); vector<string> res; for (string s : v) { string t = s; for (int i = 0; i < t.size(); ++i) { t[i] ^= 'A' ^ 'B'; } res.push_back(s + s); res.push_back(s + t); } string s; for (int i = 0; i < (1 << (n - 1)); ++i) { s += 'A'; } for (int i = 0; i < (1 << (n - 1)); ++i) { s += 'B'; } res.push_back(s); return res; } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); cin >> n; /*int a = c2(1 << (n - 1)) * 2; int b = c2(1 << n); int lc = a / __gcd(a, b) * b; cout << a << " " << b << " " << lc << endl << lc / a << endl;*/ /* ans.push_back("AABB"); ans.push_back("ABAB"); ans.push_back("ABBA"); */ ans = solve(n); /*ans.push_back("AAAABBBB"); ans.push_back("AABBAABB"); ans.push_back("ABABABAB"); ans.push_back("ABBAABBA"); ans.push_back("AABBBBAA"); ans.push_back("ABABBABA"); ans.push_back("ABBABAAB");*/ cout << ans.size() << "\n"; for (auto s : ans) { cout << s << "\n"; } //check(); return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; int N,M,a[1100][1100]; signed main(){ cin>>N;M=(1<<N); cout<<M-1<<endl; for(int i=1;i<M;i++){ string ans(M,'A'); for(int k=0;k<M;k++)if(__builtin_popcount(i&k)&1)ans[k]='B'; cout<<ans<<endl; } }
#include <set> #include <map> #include <vector> #include <cstdio> #include <cctype> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef long long ll; inline int rd() { int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; } int main() { int n = rd(); int m = rd(); map<int, vector<int> > a; for (int i = 1; i <= m; ++i) a[rd()].push_back(rd()); set<int> f{n}; for (auto v : a) { vector<int> add, del; for (auto y : v.second) if (f.count(y - 1) || f.count(y + 1)) add.push_back(y); else del.push_back(y); for (auto y : add) f.insert(y); for (auto y : del) f.erase(y); } printf("%d\n", f.size()); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; using pii = pair<int, int>; /* [💭] [💡] [🎈] */ const ll inf = 1e18; using pll = pair<ll, ll>; ll dist[100001]; struct edge { int to; ll c, d; edge() : to(0), c(0), d(0) {} edge(int to, ll c, ll d) : to(to), c(c), d(d) {} }; ll f(ll t, ll c, ll d) { return t + c + d / (t + 1); } ll mnt(ll dt, ll c, ll d) { ll mn = inf; ld ta = max(dt, (ll) sqrt(d) - 1); for (ll x = ta; x <= ta + 10; x++) { mn = min(mn, f(x, c, d)); } return mn; } int main() { cin.tie(nullptr), cout.tie(nullptr), ios::sync_with_stdio(false); #ifdef _SHIFTPSH freopen("_run/in.txt", "r", stdin), freopen("_run/out.txt", "w", stdout); #endif fill(dist, dist + 100001, inf); int n, m; cin >> n >> m; vector<vector<edge>> graph(n + 1); while (m--) { int u, v, c, d; cin >> u >> v >> c >> d; graph[u].emplace_back(v, c, d); graph[v].emplace_back(u, c, d); } dist[1] = 0; priority_queue<pll> pq; pq.emplace(0, 1); while (pq.size()) { ll c = -pq.top().first, u = pq.top().second; pq.pop(); if (dist[u] < c) continue; for (const auto &e : graph[u]) { ll d = mnt(c, e.c, e.d); if (dist[e.to] <= d) continue; dist[e.to] = d; pq.emplace(-d, e.to); } } cout << (dist[n] == inf ? -1ll : dist[n]); return 0; }
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <vector> #include <map> #include <set> #include <unordered_set> #include <unordered_map> #define ll long long #define fi first #define se second #define pb push_back #define me memset const int N = 1e6 + 10; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; using namespace std; typedef pair<int,int> PII; typedef pair<ll,ll> PLL; inline int read() { int X=0; bool flag=1; char ch=getchar(); while(ch<'0'|ch>'9') {if(ch=='-') flag=0; ch=getchar();} while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();} if(flag) return X; return ~(X-1); } const int dx[4]={0,0,-1,1},dy[4]={-1,1,0,0}; int row,col,n,m; map<PII,int> mp; int b[1510][1510]; bool st[1510][1510]; int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>row>>col>>n>>m; for(int i=1;i<=n;++i){ int x,y; cin>>x>>y; mp[make_pair(x,y)]++; } for(int i=1;i<=m;++i){ int x,y; cin>>x>>y; b[x][y]++; } int ans=0; for(auto w:mp){ int x=w.fi.fi; int y=w.fi.se; for(int i=y;i>=1;--i){ if(st[x][i]) continue; if(b[x][i]) break; st[x][i]=true; ans++; } for(int i=y+1;i<=col;++i){ if(st[x][i]) continue; if(b[x][i]) break; st[x][i]=true; ans++; } for(int i=x;i>=1;--i){ if(st[i][y]) continue; if(b[i][y]) break; st[i][y]=true; ans++; } for(int i=x+1;i<=row;++i){ if(st[i][y]) continue; if(b[i][y]) break; st[i][y]=true; ans++; } } cout<<ans; return 0; }
#include<bits/stdc++.h> typedef long long int ll; using namespace std; #define sz 1529 #define mx 10000000000008 #define mod 1000000007 ll n,t,arr[6][500009],brr[6][sz][sz],crr[6][sz][sz],grid[sz][sz]; vector<ll>v; int main() { ll w,h,m; scanf("%lld %lld %lld %lld",&w,&h,&n,&m); for(int i=1;i<=n;i++){ scanf("%lld %lld",&arr[1][i],&arr[2][i]); ll a,b; a=arr[1][i]; b=arr[2][i]; grid[a][b]=1; } for(int i=1;i<=m;i++){ scanf("%lld %lld",&arr[3][i],&arr[4][i]); ll a,b; a=arr[3][i]; b=arr[4][i]; grid[a][b]=-1; } for(int i=1;i<=w;i++) { for(int j=1;j<=h;j++) { if(grid[i][j]==1) { brr[1][i][j]=j; crr[1][i][j]=crr[1][i][j-1]; } else if(grid[i][j]==-1) { crr[1][i][j]=j; brr[1][i][j]=brr[1][i][j-1]; } else { brr[1][i][j]=brr[1][i][j-1]; crr[1][i][j]=crr[1][i][j-1]; } } } for(int i=1;i<=w;i++) { for(int j=h;j>0;j--) { if(grid[i][j]==1) { brr[2][i][j]=j; crr[2][i][j]=crr[2][i][j+1]; } else if(grid[i][j]==-1) { crr[2][i][j]=j; brr[2][i][j]=brr[2][i][j+1]; } else { brr[2][i][j]=brr[2][i][j+1]; crr[2][i][j]=crr[2][i][j+1]; } } } // printf("%lld %lld\n",brr[2][1][1],crr[2][1][1]); for(int i=1;i<=h;i++) { for(int j=1;j<=w;j++) { if(grid[j][i]==1) { brr[3][j][i]=j; crr[3][j][i]=crr[3][j-1][i]; } else if(grid[j][i]==-1) { crr[3][j][i]=j; brr[3][j][i]=brr[3][j-1][i]; } else { brr[3][j][i]=brr[3][j-1][i]; crr[3][j][i]=crr[3][j-1][i]; } } } for(int i=1;i<=h;i++) { for(int j=w;j>0;j--) { if(grid[j][i]==1) { brr[4][j][i]=j; crr[4][j][i]=crr[4][j+1][i]; } else if(grid[j][i]==-1) { crr[4][j][i]=j; brr[4][j][i]=brr[4][j+1][i]; } else { brr[4][j][i]=brr[4][j+1][i]; crr[4][j][i]=crr[4][j+1][i]; } } } ll ans=0; for(int i=1;i<=w;i++) { for(int j=1;j<=h;j++) { if(grid[i][j]) continue; ll a=0; if((brr[1][i][j]!=0 && (brr[1][i][j]>crr[1][i][j] || crr[1][i][j]==0))) a++; if((brr[2][i][j]!=0 && (brr[2][i][j]<crr[2][i][j] || crr[2][i][j]==0))) a++; if((brr[3][i][j]!=0 && (brr[3][i][j]>crr[3][i][j] || crr[3][i][j]==0))) a++; if((brr[4][i][j]!=0 && (brr[4][i][j]<crr[4][i][j] || crr[4][i][j]==0))) a++; if(a){ ans++; // printf(" %d %d\n",i,j); } } } printf("%lld\n",ans+n); return 0; }
// Disclaimer: Don't copy my template, it may lead to plagiarism. /* Author: Soumy Jain Handle: soumy_jain || soumyjain "Beautiful flowers too, eventually wither and fall. That's the fate of all living beings." "I hate perfection. To be perfect is to be unable to improve any furthur." - Mayuri Kurotsuchi | Bleach "I smile to show the pressure of heroes and to trick the fear inside of me." "Gravel may be gravel, but me? I'm the gravel that shatters diamonds." "If you were to write a story with me in the lead role, it would certainly be...a TRAGEDY." - Kaneki Ken | Tokyo Ghoul */ /******************************************************************************/ // clang-format off #include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define SPEEDHACK ios_base::sync_with_stdio(false);cin.tie(NULL); #define ff first #define ss second #define sz(v) (ll)(v).size() #define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); #define MOD 1000000007 // 998244353 using namespace std; /******************************************************************************/ void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(ll x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(ull x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template<typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template<typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define dbg(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define dbg(x...) #endif // clang-format on /***********************************MAIN***************************************/ // Are you ready to face the wrath of test cases? Good luck noob Soumy! int minDifference(vector<ll> &arr, int n) { int sum = 0; for (int i = 0; i < n; i++) sum += arr[i]; bool dp[n + 1][sum / 2 + 1]; for (int i = 0; i <= n; i++) { dp[i][0] = true; } for (int i = 1; i <= sum / 2; i++) { dp[0][i] = false; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= sum / 2; j++) { if (arr[i - 1] <= j) dp[i][j] = dp[i - 1][j - arr[i - 1]] || dp[i - 1][j]; else dp[i][j] = dp[i - 1][j]; } } int mn = INT_MAX; for (int i = 1; i <= sum / 2; i++) { if (dp[n][i]) mn = min(mn, sum - 2 * i); } return mn == INT_MAX ? arr[0] : mn; } void work() { ll n, sum = 0; cin >> n; vector<ll> v(n); for (auto &i : v) cin >> i, sum += i; ll x = minDifference(v, n); cout << (minDifference(v, n) + sum) / 2; } int main() { SPEEDHACK // file ll t = 1; // cin >> t; while (t--) { work(); } return 0; }
#include<iostream> #include<math.h> #include<bits/stdc++.h> #include<cmath> #define ll long long int #define hell 1000000007LL using namespace std; ll power(ll x, ll y,ll z){ if(y==0) return 1; else { ll p=power(x,y/2,z); ll w=(p*p)%z; if(y%2==0) return w; else return (x*w)%z; }} ll gcd(ll x,ll y) { if(y==0) return x; else return gcd(y,x%y);} int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(20); ll n; cin>>n; ll a[n],s=0; for(int i=0;i<n;i++) { cin>>a[i]; s=s+a[i]; } bool f[n+1][s+1]; for (int i = 0; i <= n; i++) f[i][0] = true; for (int i = 1; i <= s; i++) f[0][i] = false; for (int i = 1; i <= n; i++) { for (int j = 1; j <= s; j++) { if (j < a[i - 1]) f[i][j] = f[i - 1][j]; if (j >= a[i - 1]) f[i][j] = f[i - 1][j] || f[i - 1][j - a[i - 1]]; } } int b[100001]; ll m=s; for(int i=1;i<s;i++) { int c=0; for(int j=0;j<n+1;j++) { if(f[j][i]==true){ c++; break;} } if(c) b[i]=1; } for(ll i=1;i<s;i++) { if(b[i]==1) { ll x=i; if(x<s-i) x=s-i; m=min(m,x); } } cout<<m;}
/** * 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 <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; void Main() { int h, w, n, m; cin >> h >> w >> n >> m; vector<vector<int>> b(h, vector<int>(w)); vector<vector<int>> l(h, vector<int>(w)); vector<vector<int>> f(h, vector<int>(w)); for (int i = 0; i < n; i++) { int y, x; cin >> y >> x; y--; x--; l[y][x] = 1; } for (int i = 0; i < m; i++) { int y, x; cin >> y >> x; y--; x--; b[y][x] = 1; } bool on = false; int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (b[i][j] == 1) on = false; if (l[i][j] == 1) on = true; if (on && f[i][j] == 0) { f[i][j] = 1; ans++; } } on = false; for (int j = w-1; j >= 0; j--) { if (b[i][j] == 1) on = false; if (l[i][j] == 1) on = true; if (on && f[i][j] == 0) { f[i][j] = 1; ans++; } } on = false; } for (int j = 0; j < w; j++) { for (int i = 0; i < h; i++) { if (b[i][j] == 1) on = false; if (l[i][j] == 1) on = true; if (on && f[i][j] == 0) { f[i][j] = 1; ans++; } } on = false; for (int i = h-1; i >= 0; i--) { if (b[i][j] == 1) on = false; if (l[i][j] == 1) on = true; if (on && f[i][j] == 0) { f[i][j] = 1; ans++; } } on = false; } // ofstream ofs("output.txt"); // for (int i = 0; i < h; i++) // { // for (int j = 0; j < w; j++) // { // if (l[i][j]) ofs << "*"; // else if (b[i][j]) ofs << "@"; // else ofs << f[i][j]; // } // ofs << "\n"; // } // ofs << "\n"; cout << ans << endl; } int main(int argc, char **argv) { ios::sync_with_stdio(false); std::cin.tie(nullptr); Main(); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(ll i=0;i<n;++i) #define rrep(i, n) for(ll i=n-1;i>=0;--i) #define rep1(i, n) for(ll i=1; i<=n; ++i) #define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++) #define ALL(a) (a).begin(),(a).end() template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}} template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}} using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll LINF = 1LL << 60; const int INF = 1e9 + 7; const double PI = 3.1415926535897932384626433; int main(){ ll n; cin >> n; rep1(a, 39)rep1(b, 27){ ull pa, pb; pa = pb = 1; rep(i, a)pa *= 3; rep(i, b)pb *= 5; if(pa + pb == n){ cout << a << " " << b << endl; return 0; } } cout << -1 << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i, n) for(int (i) = 0; (i) < (n); ++(i)) #define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i)) #define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i)) constexpr int INF = 1e9; constexpr ll INFL = 1LL<<61; constexpr ll mod = 1e9+7; int main(){ int N; cin >> N; vector<int> p(N); priority_queue<int, vector<int>, greater<int>> pq; REP(i, N){ cin >> p[i]; } int maxi = 200000; REP(i, maxi+1){ pq.push(i); } set<int> st; REP(i, N){ st.insert(p[i]); while(st.find(pq.top()) != st.end()){ pq.pop(); } cout << pq.top() << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long //#define double long double #define max(x,y) (((x)>(y))?(x):(y)) #define min(x,y) (((x)<(y))?(x):(y)) #define all(v) v.begin(),v.end() #define vi vector<int> #define MOD 1000000007 #define inf 1e18 #define ps(num,precision) fixed<<setprecision(precision)<<num #define md(arr,n,type) type *arr=new type[n] void inout(){ 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 gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b); } int lcm(int a,int b){ return a/gcd(a,b)*b; } void SieveOfEratosthenes(int n){ bool prime[n+1]; memset(prime,true,sizeof(prime)); for(int p=2;p*p<=n;p++){ if(prime[p]){ for(int i=p*p;i<=n;i+=p){ prime[i]=false; } } } for(int i=2;i<=n;i++){ if(prime[i]){ } } } int printDivisors(int n) { int sum=0; for (int i=1; i<=sqrt(n); i++) { if (n%i == 0) { if (n/i == i) sum+=1; else{ sum+=2; } } } return sum; } void solve(){ int n; cin>>n; int a[n]; int min; int ans=0; int con=0; vector<pair<int,int>> b; for(int i=0;i<n;i++){ cin>>a[i]; b.push_back(make_pair(a[i],i)); } sort(all(b)); for(int i=0;i<n;i++){ min=a[i]; if(ans<a[i]){ ans=a[i]; } for(int j=i+1;j<n;j++){ if(min>a[j]){ min=a[j]; } if((j-i+1)*min>ans){ ans=(j-i+1)*min; } } } cout<<ans; } int32_t main(){ //inout(); int t=1; //cin>>t; while(t--){ solve(); } return 0; }
#include <bits/stdc++.h> #include <iostream> #include <queue> #include <stack> #include <vector> #include <string> #include <set> #include <map> #include <random> #define rep(i,n) for (int i = 0; i < (n); ++i) #define repp(i,n,m) for (int i = m; i < (n); ++i) #define repl(i,n) for (long long i = 0; i < (n); ++i) #define reppl(i,n,m) for (long long i = m; i < (n); ++i) //#define int long long using namespace std; //#include <atcoder/all> //using namespace atcoder; using ll = long long; using ld = long double; using P = pair<int, int>; using PI = pair<pair<int,int>,int>; using PL = pair<long long, long long>; using PLL = pair<pair<long long, long long>, long long>; using Pxy = pair<double, double>; using Tiib = tuple<int, int, bool>; const int INF = 1001001007; const int modd = 1000000007; const long long modl = 1000000007LL; const int mod = 998244353; const ll inf = 1e18; template <typename AT> void printvec(vector<AT> &ar){ rep(i,ar.size()-1) cout << ar[i] << " "; cout << ar[ar.size()-1] << endl; } template <typename Q> void printvvec(vector<vector<Q>> &ar){ rep(i,ar.size()){ rep(j,ar[0].size()-1) cout << ar[i][j] << " "; cout << ar[i][ar[0].size()-1] << endl; } } template <typename S> bool range(S a, S b, S x){ return (a <= x && x < b); } void yes(){ cout << "Yes" << endl; } void no (){ cout << "No" << endl; } ll cel (ll a, ll b){ if (a % b == 0) return a / b; else return a / b + 1; } ll gcds(ll a, ll b){ ll c = a % b; while (c != 0){ a = b; b = c; c = a % b; } return b; } 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 { mint res(*this); return res+=a; } mint operator-(const mint a) const { mint res(*this); return res-=a; } mint operator*(const mint a) const { mint res(*this); return res*=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 { mint res(*this); return res/=a; } }; mint f(int n) { if (n == 0) return 1; mint x = f(n/2); x *= x; if (n%2 == 1) x *= 2; return x; } mint choose(int n, int a) { mint x = 1, y = 1; rep(i,a) { x *= n-i; y *= i+1; } return x / y; } int main(){ int n, k; cin >> n >> k; vector<mint> ar(n,0LL); rep(i,n){ ll a; cin >> a; mint b = a; ar[i] += b; } vector<mint> tab(k+1); vector<mint> gya(k+1,1LL); vector<mint> ars(n,1LL); rep(i,k){ mint c = ll(i + 1); gya[i+1] = gya[i] / c; } rep(i,k+1){ mint c = 0LL; rep(j,n){ c += ars[j]; ars[j] *= ar[j]; } tab[i] = c * gya[i]; } mint kai = 1LL; mint ni = 2LL; repp(i,k+1,1){ mint x = ll(i); kai *= x; mint ans = 0LL; rep(j,i+1){ ans += tab[j] * tab[i-j]; } ans *= kai; ans -= f(i) * tab[i] * kai; ans /= ni; cout << ans.x << endl; } }
#include <bits/stdc++.h> const int INF = 1e9; const long long INFLL = 1e18; const int NMAX = 100005; const int MMAX = 100005; const int KMAX = 1005; const int MOD = 1e9 + 7; using namespace std; // comment to disable debug functions #define DEBUG // frequently used macros #define FOR(i, N) for(int (i) = 0; (i) < (N); ++(i)) #define FOR2(i, j, N, M) for(int (i) = 0; (i) < (N); ++(i)) \ for(int (j) = 0; (j) < (M); ++(j)) #if __cplusplus >= 201103L #define ALL(v) begin(v),end(v) #define SORT(v) sort(begin(v), end(v)) #define FIND(v,x) find(begin(v), end(v), (x)) #else #define ALL(v) (v).begin(),(v).end() #define SORT(v) sort(v.begin(), v.end()) #define FIND(v,x) find(v.begin(), v.end(), (x)) #endif #define fi first #define se second #define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \ memset((from), 0, sizeof(from)); } while(0) #ifdef DEBUG #define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0) #else #define DUMP(x) do{}while(0) #endif // frequent used aliases typedef long long ll; typedef pair<int, int> p; typedef pair<ll, int> lp; typedef pair<ll, ll> llp; typedef vector<int> vec; typedef vector<ll> vecll; typedef vector<vec> mat; typedef vector<vecll> matll; // frequently used constants static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1}; static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1}; // frequently used structs struct edge{ int to,cost; }; // printf for debug #ifndef DEBUG void debug(const char* format, ...){} #else void debug(const char* format, ...){ va_list arg; va_start(arg, format); vprintf(format, arg); va_end(arg); } #endif // dump vector #ifdef DEBUG #define DUMPV(v, c) do{ \ printf("%s: ", #v); \ for (int i = 0; i < (c); ++i) \ { \ cout << (v)[i] << " "; \ } \ cout << endl; \ } while(0) #else #define DUMPV(v,c) #endif // std::fill of multi dimensions template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( reinterpret_cast<T*>(array), reinterpret_cast<T*>(array+N), val ); } // binary search ll BSearch(ll ok, ll ng, bool (*f)(ll)){ ll mid; while(abs(ok - ng) > 1LL) { mid = (ok + ng) / 2LL; if(f(mid)) { debug("BSearch: f(%d) == true\n", mid); ok = mid; } else { debug("BSearch: f(%d) == false\n", mid); ng = mid; } } return ok; } ll NUM_TEST_CASE = 1; ll N,M,K,A,B,C,D,E; int dp[NMAX] = {}; string S; vec v; ll ans = {}; void solve(){ // main algorithm } void debug(){ // output debug information } void answer(){ // output answer cout << N - M + K << endl; } void init(){ // initialize for each test case // Fill(dp, -1); } int main(int argc, char const *argv[]) { // operate inputs // cin >> NUM_TEST_CASE; for (int test_case = 0; test_case < NUM_TEST_CASE; ++test_case) { init(); cin >> N >> M >> K; solve(); #ifdef DEBUG debug(); #endif answer(); } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ int n,a,b; cin >>n >>a >>b; cout <<n-a+b; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pint pair<int, int> #define pll pair<ll, ll> const ll INF = 1LL << 60; const int MOD = 1000000007; // const int MOD = 998244353; int main() { ll n, C; cin >> n >> C; // time, cost map<ll, ll> mp; for (ll i = 0; i < n; i++) { ll a, b, c; cin >> a >> b >> c; mp[a] += c; mp[b + 1] -= c; } mp[0] = 0; ll nowCost = 0; ll prevTime = 0; ll ans = 0; for (auto m : mp) { ll time = m.first; ll cost = m.second; ans += min(C, nowCost) * (time - prevTime); nowCost += cost; prevTime = time; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using ull = unsigned long long; #define pb push_back #define fi first #define se second #define rep(i,a,b) for(int i=int(a);i<=(int)(b);i++) #define per(i,a,b) for(int i=int(a);i>=(int)(b);i--) const int mod = 1e9+7; const int inf = 0x3f3f3f3f; const int maxn = 1e6+10; int main() { #ifndef WA_DEBUG ios::sync_with_stdio(false);cin.tie(nullptr); #endif int n; ll c; cin>>n>>c; vector<pair<int,int>> a(2*n+1); int cnt=0; rep(i,1,n) { int l,r,c; cin>>l>>r>>c; a[++cnt].fi=l; a[cnt].se=c; a[++cnt].fi=r+1; a[cnt].se=-c; } sort(a.begin()+1,a.end()); ll sum=0,now=0; rep(i,1,cnt-1) { now+=a[i].se; if(now<c) sum+=now*(a[i+1].fi-a[i].fi); else sum+=c*(a[i+1].fi-a[i].fi); } cout<<sum<<'\n'; return 0; }
#include<bits/stdc++.h> #include<tr1/unordered_map> using namespace std; #define int long long int n; int a[300000]; int dp[300000]; const int mod=998244353; tr1::unordered_map<int,int>num,vis; signed main() { ios::sync_with_stdio(false); cin>>n; for(int i=1;i<=n;i++) cin>>a[i],num[a[i]]++; sort(a+1,a+1+n); for(int i=1;i<=n;i++) { dp[i]=dp[i-1]*2; dp[i]+=a[i]; dp[i]%=mod; }int ans=0; for(int i=n;i>=1;i--) { ans+=a[i]*dp[i-1]%mod+a[i]*a[i]%mod;ans%=mod; //cout<<a[i]<<" "<<dp[i-1]<<endl; } cout<<ans<<endl; }
#include<bits/stdc++.h> #define L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++) #define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--) #define ll long long #define pii pair<int, int> #define db double #define x first #define y second #define ull unsigned long long #define sz(a) ((int) (a).size()) using namespace std; const int N = 1e6 + 7; const int mod = 998244353, inv2 = (mod + 1) / 2; int n, a[N], pw[N], ipw[N], sum[N], ns; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; pw[0] = ipw[0] = 1; L(i, 1, n + 1) pw[i] = (ll) pw[i - 1] * 2 % mod, ipw[i] = (ll) ipw[i - 1] * inv2 % mod; L(i, 1, n) cin >> a[i], (ns += (ll) a[i] * a[i] % mod) %= mod; sort(a + 1, a + n + 1); R(i, n, 1) sum[i] = (sum[i + 1] + (ll) a[i] * pw[i] % mod) % mod; L(i, 1, n) (ns += (ll) a[i] * sum[i + 1] % mod * ipw[i + 1] % mod) %= mod; cout << ns << "\n"; return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; //#define int long long int #define out2(x,y) cout<<x<<" "<<y<<endl; #define out(x) cout<<x<<endl; #define forin for(int i=0;i<n;i++) #define forjm for(int j=0;j<m;j++) #define in(x) int x;cin>>x; #define in2(x,y) int x,y;cin>>x>>y; #define in3(x,y,z) int x,y,z;cin>>x>>y>>z; #define MOD 1000000007 int32_t main() { in2(a,b); int can=2*a+100; int ans=-b+can; out(ans); return 0; }
/* START BY THE NAME OF ALMIGHTY ALLAH THIS WONT BE ACCEPTED STOP_GIVING_UP ██╗███████╗████████╗██╗ █████╗ ██╗ ██╗ ██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝ ██║███████╗ ██║ ██║███████║█████╔╝ ██║╚════██║ ██║ ██║██╔══██║██╔═██╗ ██║███████║ ██║ ██║██║ ██║██║ ██╗ ╚═╝╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ */ #include<bits/stdc++.h> #define l(i,a,n)for(int i=a;i<n;i++) #define pb push_back #define in insert #define mp make_pair #define lw(v) sort(v.begin(),v.end()); #define hi(v) sort(v.begin(),v.end(),greater<long long>()); #define all(v) v.begin(),v.end() #define filein freopen ("input.txt", "r", stdin) #define fileout freopen ("output.txt", "w", stdout) using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long t,r=1,r1=0,r2=0,k=0,a,b,c=0,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0; vector<long long>v; vector<long long>u; vector<tuple<string,int, int>>mp; set<long long>s; std::vector<int>::iterator it; string s1,s2,s3,s4; cin>>n>>m; cout<<((2*n)+100)-m<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n,m,q; cin>>n>>m>>q; vector<pair<int,int>>v; vector<pair<int,int>>w; int a,b; for(int i=0;i<n;i++){ cin>>a>>b; v.push_back(make_pair(b,a)); w.push_back(make_pair(b,a)); } sort(v.rbegin(),v.rend()); sort(w.rbegin(),w.rend()); int arr[m]; for(int i=0;i<m;i++){ cin>>arr[i]; } //sort(arr,arr+m); int l,r; for(int i=1;i<=q;i++){ cin>>l>>r; l--; r--; vector<int>vv; for(int j=0;j<m;j++){ if(j>=l && j<=r){ continue; } vv.push_back(arr[j]); } sort(vv.begin(),vv.end()); for(int j=0;j<vv.size();j++){ // cout<<"#"<<vv[j]<<"\n"; } vector<int>::iterator lower; long long ans=0; for(int j=0;j<v.size();j++){ if(v[j].first!=-1){ int r=v[j].second; lower=lower_bound(vv.begin(),vv.end(),r); if((lower - vv.begin() + 1)<=vv.size()){ ans=ans+v[j].first; v[j].first=-1; vv[lower-vv.begin()]=-1; sort(vv.begin(),vv.end()); } } } cout<<ans<<"\n"; for(int j=0;j<n;j++){ if(v[j].first==-1){ v[j].first=w[j].first; } } } return 0; }
/* Problem Name:Graph Smoothing algorithm tag:矩阵快速幂 */ #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-4; typedef pair<int, int> pii; typedef pair<ll, ll> pll; //#define x first //#define y second #define iosf ios::sync_with_stdio(false), cin.tie(0), cout << fixed const int N = 110; typedef long long ll; int n; struct Matrix { int a[N][N]; Matrix() { memset(a, 0, sizeof(a)); } int *operator[](int x) { return a[x]; } Matrix operator*(Matrix b) { Matrix res; for (int k = 1; k <= n; k++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) res[i][j] = (res[i][j] + (ll)a[i][k] * b[k][j]) % mod; return res; } } E; Matrix Pow(Matrix x, int y) { Matrix res = E; for (; y; y >>= 1, x = x * x) if (y & 1) res = res * x; return res; } int Pow(int x, int y) { int res = 1; for (; y; y >>= 1, x = (ll)x * x % mod) if (y & 1) res = (ll)res * x % mod; return res; } int ind[N], A[N]; int main() { int m, k; scanf("%d%d%d", &n, &m, &k); int inv = Pow(2 * m, mod - 2); for (int i = 1; i <= n; i++) scanf("%d", &A[i]); for (int i = 1; i <= n; i++) E[i][i] = 1; Matrix base; for (int i = 1; i <= m; i++) { int a, b; scanf("%d%d", &a, &b), ind[a]++, ind[b]++; base[a][a] = base[b][b] = base[a][b] = base[b][a] = inv; } for (int a = 1; a <= n; a++) { base[a][a] = (ll)(2 * m - ind[a]) * inv % mod; } base = Pow(base, k); for (int i = 1; i <= n; i++) { int res = 0; for (int j = 1; j <= n; j++) res = (res + (ll)A[j] * base[j][i]) % mod; printf("%d\n", res); } }
#include <bits/stdc++.h> #include <algorithm> #define rep(i,n) for(int i=0;i<(n);i++) #define per(i,n) for(int i=(n)-1;i>=0;i--) #define prt(n) cout<<(n)<<endl #define elif else if #define str string #define pb push_back #define mp make_pair typedef long long ll; using namespace std; const ll mod1=998244353; const ll mod2=1000000007; //ios_base::sync_with_stdio(false);�ӿ�cin int main() { string s; cin>>s; rep(i,s.size()) { if((i%2==0)&&(isupper(s[i]))) { cout<<"No"<<endl; return 0; } if((i%2==1)&&(islower(s[i]))) { cout<<"No"<<endl; return 0; } } cout<<"Yes"<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p_ll; template<class T> void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; } #define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++) #define all(vec) vec.begin(), vec.end() #define rep(i,N) repr(i,0,N) #define per(i,N) for (ll i=(ll)N-1; i>=0; i--) #define popcount __builtin_popcount const ll LLINF = pow(2,61)-1; const ll INF = pow(2,30)-1; ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } int main() { ll T; cin >> T; rep(_,T) { ll N; cin >> N; ll cnt = 0; while (N%2==0) { cnt++; N/=2; } string result; if (cnt==0) result = "Odd"; else if (cnt==1) result = "Same"; else result = "Even"; cout << result << endl; } return 0; }
///Bismillahir Rahmanir Rahim #include<bits/stdc++.h> #define u64 uint64_t #define ll long long #define endl "\n" #define PI acos(-1) #define fi first #define si second #define mkp make_pair #define pb push_back #define set0(arr) memset(arr, 0, sizeof(arr)) #define setinf(arr) memset(arr, 126, sizeof(arr)) #define all(x) (x).begin(),(x).end() #define sz(v) ((int)(v).size()) #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) using namespace std; using pll = pair<ll, ll> ; using vl = vector<ll> ; using vpll = vector<pll> ; using mll = map<ll, ll> ; using mcl = map<char, ll> ; using msl = map<string,ll> ; using sl = set<ll> ; using sc = set<char> ; using dl = deque<ll> ; const int N = 1e6+5 ; ll mod = 1e9+7 ; vl adj[N] ; vpll adjc[N] ; ll vis[N] ; ll arr[N] ; int main() { IOS; ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs; string str ; char ch ; double db ; ll l, r ; //code cin>>a>>b>>c>>d; if(a==b+c+d) { cout<<"Yes\n"; } else if(b==a+c+d) { cout<<"Yes\n"; } else if(c==a+b+d) { cout<<"Yes\n"; } else if(d==a+b+c) { cout<<"Yes\n"; } else if(a+b==c+d) { cout<<"Yes\n"; } else if(a+c==b+d) { cout<<"Yes\n"; } else if(a+d==b+c) { cout<<"Yes\n"; } else cout<<"No\n"; //code return 0; }
#include<cstdio> #include<queue> int main(){ int sum = 0; int a[15]; for(int i = 1; i <= 4; i++){ scanf("%d",&a[i]); sum += a[i]; } int ok = 0; for(int i = 1; i < (1<<4); i++){ int mask = i; int cur = 0; for(int j = 1; j <= 4; j++){ if(mask%2) cur += a[j]; mask /= 2; } if(cur*2==sum) ok = 1; } if(ok) printf("Yes\n"); else printf("No\n"); return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <tuple> #include <unordered_map> #include <vector> // #include <atcoder/all> /* cd $dir && g++ -std=c++17 -Wall -Wextra -O2 -DATCODERDEBUG -I/mnt/d/MyProjects/atcoder/lib/ac-library $fileName && echo 'compilation ok!' && ./a.out */ using namespace std; #define REP(i, n) for (ll i = 0; i < ll(n); i++) #define FOR(i, a, b) for (ll i = a; i <= ll(b); i++) #define ALL(x) x.begin(), x.end() #define dame(a) \ { \ cout << a << endl; \ return 0; \ } typedef long long ll; class dstream : public ostream {}; template <typename T> dstream &operator<<(dstream &os, T v) { #ifdef ATCODERDEBUG cout << "\033[1;31m" << v << "\033[0m"; #endif return os; } ostream &endd(std::ostream &out) { #ifdef ATCODERDEBUG out << std::endl; #endif return out; } dstream dout; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "[ "; for (auto const &x : v) { os << x; if (&x != &v.back()) { os << " : "; } } os << " ]" << endl; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { os << "[" << endl; for (auto const &x : v) { os << " "; os << x; } os << "]" << endl; return os; } template <typename T, typename U, typename Comp = less<>> bool chmax(T &xmax, const U &x, Comp comp = {}) { if (comp(xmax, x)) { xmax = x; return true; } return false; } template <typename T, typename U, typename Comp = less<>> bool chmin(T &xmin, const U &x, Comp comp = {}) { if (comp(x, xmin)) { xmin = x; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; ll cnt = 0; vector<ll> list; REP(i, s.size() - 1) { if (s[i + 1] == s[i]) cnt++; else if (cnt > 0) { cnt = 0; list.emplace_back(i); } } dout << list << endd; ll ans = 0; vector<ll> tbl(26, 0); ll ct = s.size() - 1; for (ll i = list.size() - 1; i >= 0; i--) { ll idx = list[i]; for (; ct > idx; ct--) { tbl[(s[ct] - 'a')]++; } ans += s.size() - idx - 1 - tbl[(s[idx] - 'a')]; tbl = vector<ll>(26, 0); tbl[(s[idx] - 'a')] = s.size() - idx - 1; } cout << ans << endl; // cout << std::fixed << std::setprecision(15) << sqrt(ans) << endl; }
#include<bits/stdc++.h> using namespace std; double n; double ans; int main() { cin>>n; for(int i=1;i<n;i++){ ans=ans+n/(n-i); } printf("%.10f\n",ans); system("pause"); return 0; }
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; int getint() { char ch;do{ ch=getchar();}while (ch!='-'&&(ch<'0'||ch>'9')); int ans=0,f=0; if (ch=='-') f=1; else ans=ch-'0'; while (isdigit(ch=getchar())) ans=ans*10+ch-'0'; if (f) ans*=-1; return ans; } int a[2][211],b[2][21]; bool vis[211]; int main() { int n,m,k,ans=0; cin>>n>>m; for(int i=1;i<=m;i++) cin>>a[0][i]>>a[1][i]; cin>>k; for(int i=1;i<=k;i++) cin>>b[0][i]>>b[1][i]; for(int i=0;i<(1<<k);i++) { for(int j=0;j<k;j++) { if(i&(1<<j)) vis[b[0][j+1]]=1; else vis[b[1][j+1]]=1; } int mid=0; for(int j=1;j<=m;j++) if(vis[a[0][j]]&&vis[a[1][j]]) mid++; ans=ans>mid? ans:mid; for(int j=1;j<=n;j++) vis[j]=0; } cout<<ans; return 0; }
#include<iostream> #include<string> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #include<map> #include <queue> #include<sstream> #include <stack> #include <set> #include <bitset> #include<vector> #define FAST ios::sync_with_stdio(false) #define abs(a) ((a)>=0?(a):-(a)) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() #define mem(a,b) memset(a,b,sizeof(a)) #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) #define rep(i,a,n) for(int i=a;i<=n;++i) #define per(i,n,a) for(int i=n;i>=a;--i) #define endl '\n' #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; typedef long long ll; typedef pair<ll,ll> PII; const int maxn = 1e5+200; const int inf=0x3f3f3f3f; const double eps = 1e-7; const double pi=acos(-1.0); const int mod = 1e9+7; inline int lowbit(int x){return x&(-x);} ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d); inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;} inline ll inv(ll x,ll p){return qpow(x,p-2,p);} inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;} inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; } int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; ll ok[maxn]; typedef struct All { ll A; ll B; }all; all a[maxn]; ll each[maxn][2]; ll k, n, m; ll ma = 0; void dfs(int pos) { if(pos>k) { ll cnt = 0; rep(i,1,m) if(ok[a[i].A]&&ok[a[i].B]) cnt++; ma = max(cnt,ma); return; } ok[each[pos][0]] ++; dfs(pos+1); ok[each[pos][0]] --; ok[each[pos][1]] ++; dfs(pos+1); ok[each[pos][1]] --; } int main() { n = read(), m = read(); rep(i,1,m) a[i].A = read(), a[i].B = read(); k = read(); rep(i,1,k) each[i][0] = read(), each[i][1] = read(); dfs(1); cout<<ma<<endl; return 0; }
#include<bits/stdc++.h> #define all(x) (x).begin(),(x).end() #define ll long long #define rep(i,n) for(int i = 0; i < int(n); i++) #define vi vector<int> using namespace std; const int INF = 1001001001; const int MOD = 1e9+7; template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; } template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; } int main(){ cin.tie(0), ios::sync_with_stdio(false); int h,w,n,m; cin >> h >> w >> n >> m; set<pair<int,int>> block; vector<vi> l(h,vi(w)), r(h,vi(w)), u(h,vi(w)), d(h,vi(w)); rep(i,n){ int a,b; cin >> a >> b; --a; --b; l[a][b] = 1; r[a][b] = 1; u[a][b] = 1; d[a][b] = 1; } rep(i,m){ int c,d; cin >> c >> d; block.insert({--c,--d}); } rep(i,h){ rep(j,w-1){ if(block.count({i,j+1})) continue; r[i][j+1] |= r[i][j]; } } rep(i,h){ for(int j = w-1; 0 < j; j--){ if(block.count({i,j-1})) continue; l[i][j-1] |= l[i][j]; } } rep(j,w){ rep(i,h-1){ if(block.count({i+1,j})) continue; d[i+1][j] |= d[i][j]; } } rep(j,w){ for(int i = h-1; 0 < i; i--){ if(block.count({i-1,j})) continue; u[i-1][j] |= u[i][j]; } } int ans = 0; rep(i,h) rep(j,w) ans += u[i][j]|d[i][j]|r[i][j]|l[i][j]; cout << ans; cout << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define Go_ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define ll long long int #define llu long long unsigned int #define pii pair<int ,int> #define PII pair<ll ,ll> const int Max=1e9+100; const ll MAX=1e18+500; const int sz=1510; bool vist[sz][sz]; int mark[sz][sz]; int main() { Go_ int a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx; char ch; double d; string str1,str2,str; bool bl,bl1; int t,cs=1; cin>>n>>m>>a>>b; memset(mark, 0, sizeof mark); pii light[a]; for(int i=0;i<a;i++) cin>>light[i].first>>light[i].second; ct=0; for(int i=1;i<=b;i++){ cin>>x>>y; mark[x][y]=-1; } for(int i=0;i<a;i++) { int x, y; x=light[i].first, y=light[i].second; if(vist[x][y]==false) ++ct; vist[x][y]=true; j=y; while(j<=m && mark[x][j] != -1){ if(vist[x][j]==false) ++ct; vist[x][j]=true; ++j; } j=y; while(j>0 && mark[x][j] != -1){ if(vist[x][j]==false) ++ct; vist[x][j]=true; --j; } j=x; while(j<=n && mark[j][y] != -1){ if(vist[j][y]==false) ++ct; vist[j][y]=true; ++j; } j=x; while(j>=1 && mark[j][y] != -1){ if(vist[j][y]==false) ++ct; vist[j][y]=true; --j; } mark[x][y]=-1; } cout<<ct<<'\n'; }
#include<bits/stdc++.h> //#include<atcoder/all> using namespace std; //using namespace atcoder; #define rep(i,n) for(ll i=0;i<n;i++) #define repl(i,l,r) for(ll i=(l);i<(r);i++) #define per(i,n) for(ll i=n-1;i>=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define all(x) (x).begin(),(x).end() using ll=long long; using vl=vector<ll>; using vvl=vector<vector<ll>>; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[8]={1,0,-1,0,1,1,-1,-1}; const ll dx[8]={0,-1,0,1,1,-1,1,-1}; using Graph = vector<vector<int>>; // dijkstra  struct edge{ll to, cost;}; typedef pair<ll,ll> P; struct graph{ ll V; vector<vector<edge> > G; vector<ll> d; graph(ll n){ init(n); } void init(ll n){ V = n; G.resize(V); d.resize(V); rep(i,V){ d[i] = INF; } } void add_edge(ll s, ll t, ll cost){ edge e; e.to = t, e.cost = cost; G[s].push_back(e); } void dijkstra(ll s){ rep(i,V){ d[i] = INF; } d[s] = 0; priority_queue<P,vector<P>, greater<P> > que; que.push(P(0,s)); while(!que.empty()){ P p = que.top(); que.pop(); ll v = p.second; if(d[v]<p.first) continue; for(auto e : G[v]){ if(d[e.to]>d[v]+e.cost){ d[e.to] = d[v]+e.cost; que.push(P(d[e.to],e.to)); } } } } }; // dijkstra end class UnionFind { public: ll par[100005]; ll depth[100005]; ll nGroup[100005]; UnionFind(ll n) { init(n); } void init(ll n) { for(ll i=0; i<n; i++) { par[i] = i; depth[i] = 0; nGroup[i] = 1; } } ll root(ll x) { if(par[x] == x) { return x; } else { return par[x] = root(par[x]); } } bool same(ll x, ll y) { return root(x) == root(y); } void unite(ll x, ll y) { x = root(x); y = root(y); if(x == y) return; if(depth[x] < depth[y]) { par[x] = y; nGroup[y] += nGroup[x]; nGroup[x] = 0; } else { par[y] = x; nGroup[x] += nGroup[y]; nGroup[y] = 0; if(depth[x] == depth[y]) depth[x]++; } } }; // unionfind end // nCr const ll MAX = 500010; ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // nCr end // tree DP vl c (200000, 0); vector<ll> color (200000, 0); vl ok(200000, 0); void dfs(const Graph &G, ll v, ll p, ll d) { if(color[c[v]] == 0) ok[v]++; color[c[v]]++; for (auto nv : G[v]) { if (nv == p) continue; dfs(G, nv, v, d+1); } color[c[v]]--; return; } // tree DP end int main() { ll n; cin>>n; cout << n - 1 << endl; }
#include <bits/stdc++.h> #define INF 2000000000 #define MOD 1000000007 #define MAXN 200005 #define REP(temp, init_val, end_val) for (int temp = init_val; temp <= end_val; ++temp) #define REPR(temp, init_val, end_val) for (int temp = init_val; temp >= end_val; --temp) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> intpair; int read(){ int f = 1, x = 0; char c = getchar(); while (c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();} while (c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar(); return f * x; } inline int lowbit(int x){ return x & (-x); } inline int modadd(int x, int y){ return (x + y >= MOD ? x + y - MOD: x + y); } inline int sgn(int x){ return (x < 0 ? -1: (x > 0 ? 1: 0)); } template<typename T> T gcd(T a, T b){ return (!b) ? a: gcd(b, a % b); } int poww(int a, int b){ int res = 1; while (b > 0){ if (b & 1) res = 1ll * res * a % MOD; a = 1ll * a * a % MOD, b >>= 1; } return res; } const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; const int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1}, ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/ int n, c1, c2, c3, c4; void init(){ n = read(); char s[4]; scanf("%s", s); c1 = s[0] - 'A'; scanf("%s", s); c2 = s[0] - 'A'; scanf("%s", s); c3 = s[0] - 'A'; scanf("%s", s); c4 = s[0] - 'A'; } void solve(){ int tt = c1 * 8 + c2 * 4 + c3 * 2 + c4; if (tt <= 3 || tt == 5 || tt == 7 || tt == 13 || tt == 15){ printf("1\n"); } else if (tt == 4 || tt == 10 || tt == 11 || tt == 12){ if (n == 2) printf("1\n"); else printf("%d\n", poww(2, n - 3)); } else { int f0 = 1, f1 = 1; n -= 2; while (n > 0){ int f2 = modadd(f0, f1); f0 = f1, f1 = f2; --n; } printf("%d\n", f0); } } int main(){ int T = 1; while (T--){ init(); solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; if(a + b >= 15 && b >= 8) cout << 1 << endl; else if(a + b >= 10 && b >= 3) cout << 2 << endl; else if(a + b >= 3) cout << 3 << endl; else cout << 4 << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define all(x) x.begin(), x.end() #define pb push_back #define vl vector<ll> #define pii pair<int, int> #define ull unsigned long long using namespace std; typedef tuple<ll, ll, ll> ti; const ll INF=1e17; void dijkstra(vector<vector<pair<int, int>>>& adj, int x) { int n = adj.size(); priority_queue<pair<ll, int>> q; vector<bool> processed(n+1, false); vl dist(n+1, LONG_MAX); dist[x] = 0; q.push({0, x}); while (!q.empty()) { int a = q.top().second; q.pop(); if (processed[a]) continue; processed[a] = true; for (auto it: adj[a]) { int b = it.first, w = it.second; if (dist[b] > dist[a] + w) { dist[b] = dist[a] + w; q.push({-dist[b], b}); } } } } bool cmp(pair<int, int>& a, pair<int, int>& b) { if (a.first == b.first) return a.second < b.second; return a.first > b.first; } string decimalToBinary(ll n) { //finding the binary form of the number and //coneverting it to string. string s = bitset<64> (n).to_string(); //Finding the first occurance of "1" //to strip off the leading zeroes. const auto loc1 = s.find('1'); if(loc1 != string::npos) return s.substr(loc1); return "0"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b; cin>>a>>b; ll ms = a + b; if (ms < 3) { cout<<4; } else { if (ms >= 15 && b >= 8) cout<<1; else if (ms >= 10 && b >= 3) cout<<2; else cout<<3; } return 0; }
#include <algorithm> #include <iostream> #include <numeric> #include <string> #include <tuple> #include <utility> #include <vector> #define rep(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; using P = pair<ll, ll>; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false) template<typename T, typename... Ts> void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; } #else #define dump(...) do{ } while(false) #endif template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } template<typename T> bool chmin(T &a, const T& b) { if (a > b) {a = b; return true; } return false; } template<typename T> bool chmax(T &a, const T& b) { if (a < b) {a = b; return true; } return false; } template<typename T, typename... Ts> void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; } template<typename... Ts> void input(Ts&... ts) { (cin >> ... >> ts); } template<typename T> istream &operator,(istream &in, T &t) { return in >> t; } // clang-format on int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; string s, t; input(n, s, t); if (count(s.begin(), s.end(), '1') != count(t.begin(), t.end(), '1')) { print(-1); return 0; } int ans = 0; int a = 0, b = 0; rep(i, 0, n) { if (s[i] == t[i]) continue; a = max(i, a); b = max(i, b); while (a < n && s[a] == '1') a++; while (b < n && t[b] == '1') b++; if (s[i] == '1') { swap(s[i], s[a]); ans++; } if (t[i] == '1') { swap(t[i], t[b]); ans++; } } print(ans); return 0; }
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define fi first #define se second #define all(v) (v).begin(), (v).end() #define prec(n) fixed<<setprecision(n) using namespace std; typedef long long ll; typedef unsigned long long int ull ; const int MOD=1e9+7; const char nl = '\n'; int check (int n ) { int k1 = n ; int c = 0 ; while( k1 != 0 ){ int tmp = k1 % 10 ; if ( tmp == 7 ) c = 1 ; k1 /= 10 ; } int k2 = n ; int c1 = 0 ; while( k2 != 0 ){ int tmp = k2 % 8 ; if ( tmp == 7 ) c1 = 1 ; k2 /= 8 ; } if ( c1 == 1 || c == 1 ) return 0 ; else return 1 ; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n ; cin >> n ; int ans = 0 ; for (int i = 1 ; i <= n ; i++) if ( check(i) == 1 ) ans++; cout << ans; return 0; }
#include "bits/stdc++.h" using namespace std; #define ll long long ll dp[5050][5050]; ll sdp[5050]; ll mod = 998244353; ll invs[5050]; ll mis[5050][5050]; ll gcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } ll x1, y1; ll d = gcd(b, a % b, x1, y1); x = y1; y = x1 - y1 * (a / b); return d; } int main() { ll n, m; cin >> n >> m; for (int i = 0; i < n; i++) { for (int x = 0; x <= m; x++) { if (i > 0) mis[i][x] = mis[i - 1][x] * (m - x); else mis[i][x] = 1; mis[i][x] %= mod; } } for (int x = 1; x <= m; x++) { ll x1, y1; ll g = gcd(x, mod, x1, y1); x1 = (x1 % mod + mod) % mod; invs[x] = x1; } for (int i = 1; i <= m; i++) { dp[0][i] = 1; } sdp[0] = m; for (int i = 1; i < n; i++) { for (ll x = 1; x <= m; x++) { ll mi = mis[i][0]; ll mix = mi - mis[i][x] + mod; mix %= mod; dp[i][x] = sdp[i - 1] + mi - (mix)*invs[x] + mod; dp[i][x] %= mod; sdp[i] += dp[i][x] + mod; sdp[i] %= mod; } } cout << sdp[n - 1] << endl; return 0; }
#include<cstdio> #include<algorithm> using namespace std; int main(){ unsigned N, M; scanf("%u %u", &N, &M); int H[N]; for(unsigned i = 0; i < N; ++i){ scanf("%d", H + i); } int W[M]; for(unsigned i = 0; i < M; ++i){ scanf("%d", W + i); } sort(H, H + N); sort(W, W + M); unsigned candidate = 0, answer = 999999999, id = 0, last; for (unsigned i = 0; i < N; i++){ candidate += i&1 ? -H[i] : H[i]; } for (unsigned i = 0; i < M && (!i || W[i-1] < H[N-1]); i++){ last = id; id = distance(H, lower_bound(H, H + N, W[i])); for (unsigned j = last; j < id; j++){ candidate += H[j]* ((j&1) ? 2 : -2); } candidate = candidate - (i ? W[i-1] : 0)*((last&1) ? 1 : -1) + W[i]*((id&1) ? 1 : -1); if(answer > candidate) answer = candidate; } printf("%u\n", answer); return 0; }
/**Bismillahir Rahmanir Rahim.**/ /* Md.Fagun Molla 18ICTCSE006 BSMRSTU(SHIICT) */ #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; using ll=long long; using db=double; ///***************************************************** CONSTANTS ******************************************************/// int const N=1e6+3; ll MOD=1e9+7,fact[N]; const long long inf=(long long)1e18; const long double PI=3.14159265358979; ///************************************************ CONTAINER DEFINITIONS ***********************************************/// typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; ///************************************************ SHORT FORM KEYWORDS *************************************************/// #define PB push_back #define F first #define S second #define MP make_pair #define I insert #define lb lower_bound #define ub upper_bound #define endl '\n' ///************************************************ SHORT FORM FUNCTIONS ************************************************/// #define loop(a,b) for(ll i=a;i<b;i++) #define loopr(a,b) for(ll i=a-1;i>=b;i--) #define mem(a,b) memset(a, b, sizeof(a) ) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define sa(v) sort(v.begin(),v.end()) #define sd(v) sort(v.begin(),v.end(),greater<>()) #define rev(s) reverse(s.begin(),s.end()) #define stll(x) stoll(x, nullptr, 10); #define yes cout<<"YES"<<endl; #define no cout<<"NO"<<endl; #define mx(a) *max_element(all(a)) #define mn(a) *min_element(all(a)) #define all(a) a.begin(),a.end() #define mxa(a,N) *max_element(a,a+N) #define mna(a,N) *min_element(a,a+N) #define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;} #define io() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); ///************************************************ SOLUTION STARTS HERE ************************************************/// ///======================================================================================================================/// void solve(){ int a,b,c; cin>>a>>b>>c; if(c==0){ if(a>b) cout<<"Takahashi"<<endl; else cout<<"Aoki"<<endl; } else { if(a<b) cout<<"Aoki"<<endl; else cout<<"Takahashi"<<endl; } } int main() { io(); int T=1;//cin>>T; while(T--) solve(); return 0; } /****************ALHAMDULILLAH******************/
#include <bits/stdc++.h> #include<math.h> #include<queue> #include<cstdio> #include<set> #include<map> using namespace std; using ll = long long; int main(){ int A,B,C; cin >> A >> B >> C; if(C==1){ if(A>B) cout << "Takahashi" << endl; if(A<B) cout << "Aoki" << endl; if(A==B) cout << "Takahashi" << endl; }else{ if(A>B) cout << "Takahashi" << endl; if(A<B) cout << "Aoki" << endl; if(A==B) cout << "Aoki" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll mod = 1e9 + 7; int main() { int W, H; cin >> H >> W; vector<string> mass(H); for (int i = 0; i < H; i++) { cin >> mass[i]; } vector<vector<ll>> dp(H, vector<ll>(W, 0)), Xs(H, vector<ll>(2222, 0)), Ys(H, vector<ll>(W, 0)), Zs(H, vector<ll>(W, 0)); dp[0][0] = 1; Xs[0][0] = 1, Ys[0][0] = 1, Zs[0][0] = 1; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (i == 0 && j == 0) continue; if (mass[i][j] == '#') { dp[i][j] = 0, Xs[i][i] = 0, Ys[i][j] = 0, Zs[i][j] = 0; continue; } if (j > 0) dp[i][j] += Xs[i][j - 1]; if (i > 0) dp[i][j] += Ys[i - 1][j]; if (i > 0 && j > 0) dp[i][j] += Zs[i - 1][j - 1]; dp[i][j] %= mod; Xs[i][j] += dp[i][j], Ys[i][j] += dp[i][j], Zs[i][j] += dp[i][j]; if (j > 0) (Xs[i][j] += Xs[i][j - 1]) %= mod; if (i > 0) (Ys[i][j] += Ys[i - 1][j]) %= mod; if (i > 0 && j > 0) (Zs[i][j] += Zs[i - 1][j - 1]) %= mod; } } cout << dp[H - 1][W - 1] << "\n"; }
// Problem : E - Queen on Grid // Contest : AtCoder - AtCoder Beginner Contest 183 // URL : https://atcoder.jp/contests/abc183/tasks/abc183_e // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) // God & me // Fly ... //#pragma GCC optimize "trapv"// WA to RE int!! #include <bits/stdc++.h> #define FOR(i,n) for(int i=0;i<n;i++) #define FORR(i,n) for(int i=n;i>=0;i--) #define pb push_back #define vint vector<int> #define sint set<int> #define mint map<int,int> #define pint pair< int,int > #define int long long int #define test int tt1234; cin>>tt1234;while(tt1234--) #define endl "\n" #define input(a,n) int n;cin>>n;vint a(n);for(int&v:a)rd(v); #define all(zz) zz.begin(),zz.end() #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define error(x) cerr << #x <<" is " << x << endl; #define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n"; #define precision(x) cout<<fixed<<setprecision(x); #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define present(container, element) (container.find(element)!=container.end()) #define fint fast;test #define set(a,x) memset(a,x,sizeof(a)) #define L(x) ((x)<<1) #define R(x) (((x)<<1)+1) #define ft first #define se second #define MOD 1000000007 using namespace std; template<typename... T> void rd(T&... args) { ((cin >> args), ...); } template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; } int n,m; int arr[3001][3001]; int dp[2005][2005]; int go(int x,int y) { if(x==n-1 && y==m-1) return 1; if(x>=n || y>=m) return 0; int ans=0; if(dp[x][y]!=-1) return dp[x][y]%MOD; for(int i=x+1;i<n;i++) { if(arr[i][y]==1)break; ans=(ans%MOD+go(i,y)%MOD)%MOD; } for(int j=y+1;j<m;j++) { if(arr[x][j]==1)break; ans=(ans%MOD+go(x,j)%MOD)%MOD; } for(int i=1;;i++) { int X=x+i,Y=y+i; if(X>=n || Y>=m || arr[X][Y]==1)break; ans=(ans%MOD+go(X,Y)%MOD)%MOD; } return dp[x][y]=ans%MOD; } void solve(){ rd(n,m); rep(i,1,n+1){ rep(j,1,m+1){ char c; rd(c); arr[i][j]=(c=='.')?0:1; } } int U[n+1][m+1]={0},D[n+1][m+1]={0},DG[n+1][m+1]={0}; dp[1][1]=1; U[1][1]=1; D[1][1]=1; DG[1][1]=1; int con=1; rep(j,2,m+1) { if(arr[1][j]==1)break; else dp[1][j]=con%MOD,con+=dp[1][j]%MOD; U[1][j]=dp[1][j]%MOD; D[1][j]=dp[1][j]%MOD; DG[1][j]=dp[1][j]%MOD; } con=1; rep(i,2,n+1) { if(arr[i][1]==1)break; else { dp[i][1]=con%MOD,con+=dp[i][1]%MOD; U[i][1]=dp[i][1]%MOD; D[i][1]=dp[i][1]%MOD; DG[i][1]=dp[i][1]%MOD; } } for(int i=2;i<=n;i++) { for(int j=2;j<=m;j++) { if(arr[i][j]==1)dp[i][j]=0; else { dp[i][j]=(U[i-1][j]%MOD+D[i][j-1]%MOD+DG[i-1][j-1]%MOD)%MOD; U[i][j]=(U[i-1][j]%MOD+dp[i][j]%MOD)%MOD; D[i][j]=(D[i][j-1]%MOD+dp[i][j]%MOD)%MOD; DG[i][j]=(DG[i-1][j-1]%MOD+dp[i][j]%MOD)%MOD; } } } // rep(i,1,n+1){ // rep(j,1,m+1){ // cout<<dp[i][j]<<" "; // } // cout<<endl; // } pp(dp[n][m]%MOD); return; } int32_t main() { fast; // memset(dp,-1,sizeof(dp)); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &t) { t=0; char ch=getchar(); int f=1; while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); } do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f; } typedef long long ll; const int mod=998244353; int n,m,k,ans; void update(int &x,int y) { x+=y; if (x>=mod) x-=mod; } int ksm(int x,int y) { int res=1; while (y) { if (y&1) res=(ll)res*x%mod; x=(ll)x*x%mod; y>>=1; } return res; } int main() { //freopen("1.txt","r",stdin); read(n),read(m),read(k); if (n==1) { printf("%d\n",ksm(k,m)); return 0; } if (m==1) { printf("%d\n",ksm(k,n)); return 0; } for (int i=1;i<=k;i++) { update(ans,(ll)ksm(k-i+1,m)*(ksm(i,n)-ksm(i-1,n)+mod)%mod); } printf("%d\n",ans); return 0; } /* 0. Enough array size? Enough array size? Enough array size? Integer overflow? 1. Think TWICE, Code ONCE! Are there any counterexamples to your algo? 2. Be careful about the BOUNDARIES! N=1? P=1? Something about 0? 3. Do not make STUPID MISTAKES! Time complexity? Memory usage? Precision error? */
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; const int maxn=2e3+5; ll dp[maxn][maxn],sum[3][maxn*2],belong[maxn][maxn]; char buff[maxn][maxn]; const int mod=1e9+7; int main() { int n,m;cin>>n>>m; for(int i=1;i<=n;i++) cin>>(buff[i]+1); for(int i=1;i<=m;i++) belong[1][i]=i; for(int i=2;i<=n;i++) belong[i][1]=m+i-1; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(belong[i][j]) continue; belong[i][j]=belong[i-1][j-1]; } } dp[1][1]=1; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(buff[i][j]=='#') { sum[0][belong[i][j]]=sum[1][i]=sum[2][j]=0; }else { if(i!=1||j!=1) dp[i][j]=(sum[0][belong[i][j]]+sum[1][i]+sum[2][j])%mod; (sum[0][belong[i][j]]+=dp[i][j])%=mod; (sum[1][i]+=dp[i][j])%=mod; (sum[2][j]+=dp[i][j])%=mod; } } } cout<<dp[n][m]%mod<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define print(a) for (auto x : a) cout << x << " "; cout << endl #define print_upto(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl #define take(a,n) for(ll i=1;i<=n;i++) cin>>a[i]; #define watch(x) cout << (#x) << " is " << (x) << "\n" #define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n" #define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n" #define ff first #define ss second #define null NULL #define all(c) (c).begin(),(c).end() #define nl "\n" #define ld long double #define eb emplace_back #define pb push_back #define pf push_front #define MOD 1000000007 #define inf INT_MAX // cout << fixed << setprecision(9) << ans << nl; typedef vector<ll> vl; typedef vector< vl > vvl; typedef pair< ll, ll> pll; typedef map< ll, ll> mll; const ll N = 200009; void solve() { ld x, y, r; cin>>x>>y>>r; double ep = 1e-14; r = r + ep; ld lx = x-r; ld rx = x+r; ld llx = ceil(lx); ld rrx = floor(rx); ll ans=0; for(ld i=llx;i<=rrx;i++){ ld res = (r*r) - (i-x)*(i-x); if(res<0) continue; res = sqrt(res); ld ly = res + y; ld ry = -res + y; ld lly = ceil(ry); ld rry = floor(ly); ans += (ll)(rry-lly+1); } cout<<ans<<nl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long double ld; typedef long long ll; const ld eps = 1e-10l; ld X, Y, R; ll res; int main() { cin >> X >> Y >> R; for (int i = X - R - 5; i <= X + R + 5; i++) { int intY = Y; int lef = Y - R - 5, rig = intY; while (lef <= rig) { int m = (lef + rig) / 2; if (ld(i - X) * ld(i - X) + ld(Y - m) * (Y - m) <= R * R + eps) rig = m - 1; else lef = m + 1; } if (lef <= intY) res += intY - lef + 1; lef = intY + 1, rig = Y + R + 5; while (lef <= rig) { int m = (lef + rig) / 2; if (ld(i - X) * ld(i - X) + ld(Y - m) * (Y - m) <= R * R + eps) lef = m + 1; else rig = m - 1; } if (rig > intY) res += rig - intY; } cout << res << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define int ll const ll mod = 1e9 + 7; const int maxn = 2002; char saveori[maxn][maxn]; ll ff[4100005]; void init(){ ff[0] = 1; for(int i =1;i<=4000005;i++){ ff[i] = ff[i - 1] * 2; ff[i] %= mod; } } int tor[maxn][maxn]; int tol[maxn][maxn]; int tou[maxn][maxn]; int tod[maxn][maxn]; void solve(){ int n ,m; cin>>n>>m; for(int i =1;i<=n;i++){ scanf("%s", saveori[i] + 1); } int tot = 0; for(int i =1;i<=n;i++){ for(int j = 1;j<=m;j++){ tot += (saveori[i][j] == '.'); } } for(int i =1;i<=n;i++){ tol[i][0] = 0; for(int j = 1;j<=m;j++){ if(saveori[i][j] == '.'){ tol[i][j] = tol[i][j-1] + 1; } else{ tol[i][j] = 0; } } } for(int i =1;i<=n;i++){ tor[i][m+1] = 0; for(int j =m;j>=1;j--){ if(saveori[i][j] == '.'){ tor[i][j] = tor[i][j+1] + 1; } else{ tor[i][j] = 0; } } } for(int j = 1;j<=m;j++){ tou[int(0)][j] = 0; for(int i = 1;i<=n;i++){ if(saveori[i][j] == '.'){ tou[i][j] = tou[i-1][j] + 1; } else{ tou[i][j] = 0; } } } for(int j = 1;j<=m;j++){ tod[n+1][j] = 0; for(int i = n;i>=1;i--){ if(saveori[i][j] == '.'){ tod[i][j] = tod[i + 1][j] + 1; } } } int ans = 0; for(int i =1;i<=n;i++){ for(int j = 1;j<=m;j++){ if(saveori[i][j] != '.') continue; ll nowcnt = tol[i][j] + tod[i][j] + tor[i][j] + tou[i][j]; nowcnt-=3; ll nowans = (ff[nowcnt] - 1)* ff[tot - nowcnt]; nowans %= mod; ans += nowans; ans %= mod; } } cout<<ans<<endl; } signed main() { //freopen("in.txt", "r", stdin); init(); solve(); }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); ++i) using namespace std; using ll = long long; template<typename T> T pown(T b, ll e) { if(e == 0) return 1; T p = pown(b, e / 2); if(e % 2 == 0) return p * p; return p * p * b; } template<const int mod> struct Intmod { ll a; Intmod(ll a = 0): a(((a % mod) + mod) % mod) {} Intmod operator-() const {return Intmod(-a);} Intmod& operator+=(const Intmod b) { if((a += b.a) >= mod) a -= mod; return *this; } Intmod& operator+=(const ll b) { if((a += b) >= Intmod(mod).a) a -= mod; return *this; } Intmod& operator-=(const Intmod b) { if((a -= b.a) < 0) a += mod; return *this; } Intmod& operator-=(const ll b) { if((a -= Intmod(b).a) < 0) a += mod; return *this; } Intmod& operator*=(const Intmod b) { (a *= b.a) %= mod; return *this; } Intmod& operator*=(const ll b) { (a *= Intmod(b).a) %= mod; return *this; } template<typename T> Intmod operator+(const T b) const {return Intmod(*this) += b;} template<typename T> Intmod operator-(const T b) const {return Intmod(*this) -= b;} template<typename T> Intmod operator*(const T b) const {return Intmod(*this) *= b;} // Valid for prime mod. pown() needs to be included. int i = 0; Intmod inv() { if(a == 0) throw "Inverse of zero does not exist."; if(!i) i = pown(*this, mod - 2).a; return Intmod(i); } Intmod& operator/=(const Intmod b) {return *this *= b.inv();} Intmod& operator/=(const ll b) {return *this *= Intmod(b).inv();} template<typename T> Intmod operator/(const T b) const {return Intmod(*this) /= b;} }; template<const int mod> Intmod<mod> operator+(const ll b, Intmod<mod> a) {return a += b;} template<const int mod> Intmod<mod> operator-(const ll b, Intmod<mod> a) {return a -= b;} template<const int mod> Intmod<mod> operator*(const ll b, Intmod<mod> a) {return a *= b;} template<const int mod> Intmod<mod> operator/(const ll b, Intmod<mod> a) {return a /= b;} //Valid for prime mod. int main() { ios::sync_with_stdio(false); cin.tie(0); const int MOD = 1000000007; int h, w, k = 0; cin >> h >> w; vector<string> s(h); rep(i, h) { cin >> s.at(i); rep(j, w) if(s.at(i).at(j) == '.') k++; } vector<vector<int>> eh(h, vector<int>(w)), ew(h, vector<int>(w)); int temp = 0; rep(i, h) { temp = 0; rep(j, w + 1) { if(j == w || s.at(i).at(j) == '#') { for(int jt = temp; jt < j; ++jt) ew.at(i).at(jt) = j - temp; temp = j + 1; } } } rep(i, w) { temp = 0; rep(j, h + 1) { if(j == h || s.at(j).at(i) == '#') { for(int jt = temp; jt < j; ++jt) eh.at(jt).at(i) = j - temp; temp = j + 1; } } } Intmod<MOD> bi = 2; Intmod<MOD> ans = pown(bi, k); ans *= k; rep(i, h) { rep(j, w) { if(s.at(i).at(j) == '.') ans -= pown(bi, k + 1 - eh.at(i).at(j) - ew.at(i).at(j)); } } printf("%lld\n", ans.a); return 0; }
#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; int A[1 << 16]; int main() { int n; S(n); int idx = 0; rep(i,0,1<<n) { S(A[i]); if(A[i] > A[idx]) { idx = i; } } int ans = -1; int y = (1 << (n - 1)); rep(i,0,1<<n) { if((idx < y && i >= y) || (idx >= y && i < y)) { if(ans == -1 || A[i] > A[ans]) { ans = i; } } } P(ans + 1); return 0; }
#ifdef _DEBUG #define _GLIBCXX_DEBUG #define print(a) for(auto i : a) { cout << i << " "; } cout << endl; #endif #include <bits/stdc++.h> using namespace std; #define endl "\n" #define all(v) v.begin(), v.end() #define rep(i, begin, end) for(int i = begin; i < (int)(end); i++) #define contains(v, x) (find(all(v), x) != v.end()) template<class T> bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; } template<class T> bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; } template<class T> T roundup(T a, T b){ return (a + b - 1) / b; } const double PI = 3.14159265359; const vector<int> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0}; const vector<int> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0}; using ll = long long; struct Edge{ int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} }; const ll MOD = (ll)1e9 + 7; const ll INF = (ll)1e9; using P = pair<int, int>; using Graph = vector<vector<int>>; /*#include <atcoder/all> using namespace atcoder; using mint = modint;*/ int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); //mint::set_mod(MOD); int n; cin >> n; int p1 = -1, p2 = -1; int ans1 = -1, ans2 = -1; rep(i, 0, pow(2, n - 1)){ int a; cin >> a; if(chmax(ans1, a)) p1 = i; } rep(i, 0, pow(2, n - 1)){ int a; cin >> a; if(chmax(ans2, a)) p2 = pow(2, n - 1) + i; } cout << (ans1 < ans2 ? p1 : p2) + 1 << endl; }
#include<bits/stdc++.h> #include<ext/rope> using namespace std; using namespace __gnu_cxx; typedef long long ll; typedef long double ld; typedef unsigned long long ul; typedef unsigned int ui; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef tuple<int,int,int> tiii; //#define x first //#define y second #define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr) #define fopen freopen("input.txt", "r", stdin) #define eb emplace_back #define em emplace #define prec(a) cout << fixed;cout.precision(a); #define all(a) (a).begin(), (a).end() const ll INF = 2e18; const int inf = 2e9; template<class T> void pr(T t) {cerr << t << " ";} template<class T, class ...Args> void pr(T a, Args ...args) {cerr << a << " ";pr(args...);} template<class ...Args> void prl(Args ...args) {pr(args...);cerr << endl;} const ll mxN = 1e6 + 10; const ll mod = 998244353; const double eps = 1e-14; struct Point { double x, y; Point(double a = 0, double b = 0){ x = a, y = b; } Point operator - (const Point &a) const { return Point(x - a.x , y - a.y); } Point operator + (const Point &a) const { return Point(x + a.x, y + a.y); } Point operator / (const double &a) const{ return Point(x / a, y / a); } Point operator * (const double &a) const{ return Point(x * a, y * a); } double operator * (const Point &a) const{ return x * a.y - y * a.x; } double operator ^ (const Point &a) const{ return x * a.x + y * a.y; } }; typedef Point Vector; struct Line { Point x, y; Line () {} Line(Point a, Point b){ x = a, y = b; } }; int main() { fastio; ll n; cin >> n; ll ans = 1e18; for(int i=0;i<n;i++) { ll a, p, x; cin >> a >> p >> x; if(a < x) { ans = min(ans, p); } } cout << (ans == (ll) 1e18 ? -1 : ans) << endl; }
#include<bits/stdc++.h> using namespace std; # define ll long long # define read read1<ll>() # define Type template<typename T> Type T read1(){ T t=0; char k; bool vis=0; do (k=getchar())=='-'&&(vis=1);while('0'>k||k>'9'); while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar(); return vis?-t:t; } # define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout) void exgcd(ll u,ll v,ll &x,ll &y){ if(!v){x=1,y=0;return;} if(u<v){ exgcd(v,u,y,x);x=-x;y=-y; return; }ll i=u/v; exgcd(u%v,v,x,y); y+=x*i; } int main(){ for(int T=read;T--;){ int x=read,y=read,p=read,q=read; ll a=x+y<<1,b=p+q,d=__gcd(a,b);ll ans=-1; for(int i=x;i<x+y;++i) for(int j=p;j<p+q;++j){ ll c=j-i;//ax-by=c if(c/d*d!=c)continue; ll l=a/d,r=b/d,u=0,v=0;c/=d;//lu-rv=c exgcd(l,r,u,v);//lu-rv=1 u*=c;v*=c;//lu-rv=c ll m=max(max((r-u-1)/r,(l-v-1)/l),0ll); u+=r*m,v+=l*m; m=max(min(u/r,v/l),0ll); u-=r*m;v-=l*m; //cout<<u*a+i<<' '<<v*b+j<<endl; if(!~ans||ans>v*b+j)ans=v*b+j; }if(~ans)cout<<ans<<endl; else puts("infinity"); } return 0; }
#include<bits/stdc++.h> using namespace std; const long long MOD = 1e9+7; const long long N = 25e4+10; #define ll int // typedef long long ll; typedef long double ld; ll r, c, n; ll get(ll i, ll j) { return (i * c + j); } vector<array<int, 2>> g[N]; int d[N]; void dijkstra(int s) { fill(d, d+n+1, MOD); d[s] = 0; using pii = pair<int, int>; priority_queue<pii, vector<pii>, greater<pii>> q; q.push({0, s}); while (!q.empty()) { int v = q.top().second; int d_v = q.top().first; q.pop(); if (d_v != d[v]) continue; for (auto [to, len] : g[v]) { if (d[v] + len < d[to]) { d[to] = d[v] + len; q.push({d[to], to}); } } } } void test_case() { cin >> r >> c; n = r * c; vector<vector<ll>> a(r, vector<ll>(c)), b(r, vector<ll>(c)); for(int i = 0; i < r; i++) { for(int j = 0; j < c-1; j++) { cin >> a[i][j]; } } for(int i = 0; i < r-1; i++) { for(int j = 0; j < c; j++) { cin >> b[i][j]; } } for(int i = 0; i < r; i++) { for(int j = 0; j < c-1; j++) { ll x = get(i, j); ll y = get(i, j+1); g[x].push_back({y, a[i][j]}); g[y].push_back({x, a[i][j]}); } } for(int i = 0; i < r-1; i++) { for(int j = 0; j < c; j++) { ll x = get(i, j); ll y = get(i+1, j); g[x].push_back({y, b[i][j]}); } } for(int i = 0; i < r; i++) { for(int j = 0; j < c; j++) { for(int k = 1; k <= i; k++) { ll x = get(i, j); ll y = get(i-k, j); g[x].push_back({y, 1+k}); } } } ll st = get(0, 0); ll ed = get(r-1, c-1); dijkstra(st); cout << d[ed] << '\n'; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tc = 1; // cin >> tc; while(tc--) test_case(); 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 T2 = tuple<int,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 R, C; cin>>R>>C; vector<vec_int> A(R, vec_int(C-1)); rep(i,R)rep(j,C-1)cin>>A.at(i).at(j); vector<vec_int> B(R-1, vec_int (C)); rep(i,R-1)rep(j,C)cin>>B.at(i).at(j); vector<vec_int> visited(R, vec_int(C, 0)); priority_queue<T2, vector<T2>, greater<T2>> pq; pq.emplace(0, 0, 0, 0); while(!pq.empty()){ int cost, r, c, type; tie(cost, r, c, type)=pq.top(); pq.pop(); if(visited.at(r).at(c)==1)continue; if(r==R-1&&c==C-1){ cout<<cost<<endl; return 0; } visited.at(r).at(c) = 1; if(c<C-1){ if(visited.at(r).at(c+1)==0){ pq.emplace(cost+A.at(r).at(c), r, c+1, 1); } } if(c>0){ if(visited.at(r).at(c-1)==0){ pq.emplace(cost+A.at(r).at(c-1), r, c-1, 1); } } if(r<R-1){ if(visited.at(r+1).at(c)==0){ pq.emplace(cost+B.at(r).at(c), r+1, c, 0); } } if(type==1){ for(int i=0;i<r;i++){ if(visited.at(i).at(c)==0){ pq.emplace(cost+(r-i+1), i, c, 0); } } } } return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> ans; int calc(int n, vector<int> num) { //int ans; //int min; vector<int> div; for(int a = 1; a <= (int)sqrt(n); a++) { if(n % a == 0) { if(a * a == n) div.push_back(num.at(a - 1)); else { div.push_back(num.at(a - 1)); if(a != 1) div.push_back(num.at(n / a - 1)); } } } sort(div.begin(), div.end()); return div.at(div.size() - 1) + 1; } int main() { int N; cin >> N; int next; if(N == 1) cout << 1 << endl; else { ans.push_back(1); for(int i = 2; i <= N; i++) { next = calc(i, ans); ans.push_back(next); } for(int i = 0; i < N; i++) { cout << ans.at(i) << ' '; } cout << endl; } }
#include <stdio.h> #include <iostream> #include <cmath> using namespace std; int get_num_digits(long long x){ int c = 0; do { x = x / 10; c++; } while (x > 0); return c; } int main(){ long long N; cin >> N; int x_half = 1; int count = 0; while (true){ int n_digits = get_num_digits(x_half); long long x = pow(10, n_digits) * x_half + x_half; if (x > N){ break; } x_half++; count++; } cout << count << endl; }
#include <bits/stdc++.h> #define rep(i,a,b) for(int i = (a); i <= (b); i++) #define rng(a) a.begin(), a.end() #define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i] #define sz(x) (int)(x).size() #define se second #define fi first #define prev coyhhhhhhyoc #define next sdNNNmNNNNNNNmds #define y0 hNNNNy_yNNNNNN_sNh #define y1 mNNNNNdtdNNNNNNtsNNm #define yn mNNNNNNNNy___smNNNms #define tm oooooosyysooooot #define read tyhyt #define rank ytmNmo #define index yyy #define pb push_back #define pcnt __builtin_popcountll #define rrep(i,a,b) for(int i = (b); i >= (a); i--) #define rall(x,a) for(auto x : a) #define MOD 1000000007 #define endl "\n" typedef long long ll; using namespace std; struct Ed { int u, v, d; }; bool comp(const Ed& a, const Ed& b) { return a.d < b.d; } const int N = 111; int x[N], y[N], dsu[N], rank[N]; vector<Ed> ev; int n; int find(int u) { if(dsu[u] == u) return u; dsu[u] = find(dsu[u]); return dsu[u]; } bool merge(int u, int v) { u = find(u), v = find(v); if(u == v) return false; if(rank[u] > rank[v]) { dsu[v] = u; } else { dsu[u] = v; if(rank[u] == rank[v]) { rank[v]++; } } return true; } int solve() { cin >> n; rep(i, 1, n) { cin >> x[i] >> y[i]; } rep(i, 1, n + 2) { dsu[i] = i; } rep(i, 1, n) { rep(j, 1, i - 1) { int dx = x[i] - x[j], dy = y[i] - y[j]; ev.pb({i, j, dx * dx + dy * dy}); } int dy1 = y[i] + 100, dy2 = 100 - y[i]; ev.pb({i, n + 1, dy1 * dy1}); ev.pb({i, n + 2, dy2 * dy2}); } sort(rng(ev), comp); int ans = 0; rall(e, ev) { ans = max(ans, e.d); merge(e.u, e.v); int u = find(n + 1), v = find(n + 2); if(u == v) { break; } } double anss = sqrt(ans) * .5; cout << fixed << setprecision(13) << anss << endl; return 0; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; while(t--) { solve(); } return 0; }
/* link: tags: */ #include<bits/stdc++.h> #define to_l(a) ((a)<<1) #define to_r(a) ((a)<<1|1) #define lowbit(a) ((a)&(-a)) using namespace std; typedef long long int ll; typedef unsigned long long int ull; const int int_inf=0x3f3f3f3f; const ll ll_inf=0x3f3f3f3f3f3f3f3f; const int max_n=1e2+5; #define eps 1e-8 int x[max_n],y[max_n]; double dis[max_n][max_n]; int pa[max_n]; inline int find(int a){ return pa[a]?pa[a]=find(pa[a]):a; } void merge(int a,int b){ a=find(a),b=find(b); if(a==b) return ; pa[a]=b; return ; } bool judge(int n,double mid) { mid=mid*2.0; pa[101]=pa[102]=0; for(int i=1;i<=n;i++){ pa[i]=0; } for(int i=1;i<=n;i++){ if(mid-(100-y[i])>eps){ merge(i,101); } if(mid-(y[i]-(-100))>eps){ merge(i,102); } for(int j=i+1;j<=n;j++){ if(mid-dis[i][j]>eps){ merge(i,j); } } } return find(101)!=find(102); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin>>n; for(int i=1;i<=n;i++){ cin>>x[i]>>y[i]; } auto get_dis = [](int a,int b) -> double{ return sqrt((x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b])); }; for(int i=1;i<=n;i++){ for(int j=i+1;j<=n;j++){ dis[i][j]=get_dis(i,j); } } double l=0.0,r=100.0,res=0.0; while(r-l>=eps){ double mid=(l+r)/2.0; if(judge(n,mid)){ l=mid; res=mid; }else{ r=mid; } } cout<<res<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { int t; cin >> t; auto query = []() { int n; cin >> n; unordered_map<int, bool> mp; for(int i=0; i<n; ++i) { int a; cin >> a; mp[a] ^= true; } if(!(n & 1)) { for(auto &[v, b] : mp) { if(b) { return true; } } } return false; }; while(t--) { cout << (query() ? "First" : "Second") << '\n'; } } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; set<int> nums; vector<int> a; for (int i = 0; i < n; i++) { int d; cin >> d; nums.insert(d); a.push_back(d); } int res = 0; for (int d : nums) { int count = 1; int cur = 0; for (int i = 0; i < n; i++) { if (a[i] >= d) { cur++; } else { cur = 0; } count = max(count, cur); } res = max(res, count * d); } cout << res << "\n"; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) int main(){ cin.tie(0); ios::sync_with_stdio(0); int n, q; cin >> n >> q; vector<map<int, int>> mp(n); vector<int> p(n,-1); auto find = [&](auto &&self, int x) -> int{return (p[x] < 0 ? x : p[x] = self(self,p[x]));}; auto uni = [&](int x, int y){ x = find(find,x); y = find(find,y); if(x != y){ if(p[x] > p[y]) swap(x,y); p[x] += p[y]; p[y] = x; for(auto [i,v]: mp[y]) mp[x][i] += v; } }; rep(i,n){ int c; cin >> c; mp[i][c-1] = 1; } rep(i,q){ int t, a, b; cin >> t >> a >> b; a--; b--; if(t == 1) uni(a,b); else cout << mp[find(find,a)][b] << "\n"; } }
#include <bits/stdc++.h> using namespace std; #define mp(a,b) make_pair(a,b) #define ff first #define setp(a) setprecision(a)<<fixed #define ss second #define fori(v) for(ll i=0; i<v; i++) #define forj(v) for(ll j=0; j<v; j++) #define fork(v) for(ll k=0; k<v; k++) #define forl(v) for(ll l=0; l<v; l++) #define fort(v) for(ll t=0; t<v; t++) #define forz(v) for(ll z=0; z<v; z++) #define forx(v) for(ll x=0; x<v; x++) #define fory(v) for(ll y=0; y<v; y++) #define ll long long #define ld long double #define pb(a) push_back(a) #define MAX (int)(pow(10,6) + 10) const ll INF = 0x3f3f3f3f; const ll inf = pow(10,18); ll modulo = pow(10,9)+7; vector<ll> g[MAX]; ll dp[MAX][2]; ll num[MAX][2]; void dfs(ll hd, ll pr){ dp[hd][0] = 0; num[hd][0] = hd; dp[hd][1] = -inf; num[hd][1] = -1; for(auto& hr : g[hd]){ if(hr == pr){ continue; } dfs(hr, hd); if(dp[hr][0] + 1 > dp[hd][0]){ dp[hd][1] = dp[hd][0]; num[hd][1] = num[hd][0]; dp[hd][0] = dp[hr][0] + 1; num[hd][0] = num[hr][0]; } else if(dp[hr][0] + 1 > dp[hd][1]){ dp[hd][1] = dp[hr][0] + 1; num[hd][1] = num[hr][0]; } } } ll tin[MAX]; ll tout[MAX]; void dfsForT(ll hd, ll pr,ll& tim){ tin[hd] = tim; for(auto& hr: g[hd]){ if(hr == pr){ continue; } ++tim; dfsForT(hr, hd, tim); } tout[hd] = tim; } ll val[MAX]; void dfsFinal(ll hd, ll pr, ll& tar, ll& tim){ val[hd] = tim; ll lz = -1; for(auto& hr: g[hd]){ if(hr == pr){ continue; } if(tin[hr] <= tin[tar] && tout[hr] >= tin[tar] ){ lz = hr; } else{ ++tim; dfsFinal(hr, hd, tar, tim); } } if(lz!=-1){ ++tim; dfsFinal(lz, hd, tar, tim); } ++tim; } void deal(){ ll n; cin>>n; fori(n-1){ ll ai, bi; cin>>ai>>bi; --ai, --bi; g[ai].pb(bi); g[bi].pb(ai); } dfs(0, -1); ll lz = 0; fori(n){ if(dp[i][0] + dp[i][1] > dp[lz][0] + dp[lz][1]){ lz = i; } } ll root = num[lz][0]; ll tar = num[lz][1]; // cout<<"root is "<<root+1<<" target is "<<tar+1<<" sum is "<<dp[lz][0]+dp[lz][1]<<" lz is "<<lz+1<<endl; ll tim = 0; dfsForT(root, -1, tim); tim = 1; dfsFinal(root, -1, tar, tim); fori(n){ cout<<val[i]<<' '; } } int main(){ cin.tie(0); ios_base::sync_with_stdio(0); deal(); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i=0; i<(int)(n); i++) #define REP(i, n) for (int i=1; i<=(int)(n); i++) #define FOR(i, n, m) for (int i=(n); i<=(int)(m); i++) #define ll long long const ll INF=1LL<<60; const double pi=3.1415926535; int main() { vector<vector<int>> dp(900, vector<int>(900)); vector<int> vec_output; //通った道 vector<vector<int>> usei(1000), usej(1000); vector<int> usedoutput(1000); rep(i, 1000) { //入力 vector<int> input(4); rep(j, 4) cin >> input.at(j); usei.at(i).push_back(input.at(0)); usej.at(i).push_back(input.at(1)); int x = input.at(1); int y = input.at(0); int xplus = 0; int yplus = 0; if (x < input.at(3)) xplus = 1; if (x > input.at(3)) xplus = -1; if (y < input.at(2)) yplus = 1; if (y > input.at(2)) yplus = -1; bool X = false; //経路探索 while (x != input.at(3)) { //xの残りをうめる if (y == input.at(2)) { while (x != input.at(3)) { x += xplus; usei.at(i).push_back(y); usej.at(i).push_back(x); cout << (xplus == 1 ? "R" : "L") << flush; } break; } //探索済みか近いかを調べる if (dp.at(y*30 + x).at(y*30 + x+xplus) == 0 && dp.at(y*30 + x).at((y+yplus)*30 + x) == 0) { X = !X; } else if (dp.at(y*30 + x).at(y*30 + x+xplus) == 0) { X = true; } else if (dp.at(y*30 + x).at((y+yplus)*30 + x) == 0) { X = false; } else if (dp.at(y*30 + x).at(y*30 + x+xplus) < dp.at(y*30 + x).at((y+yplus)*30 + x)) { X = true; } else if (dp.at(y*30 + x).at(y*30 + x+xplus) > dp.at(y*30 + x).at((y+yplus)*30 + x)) { X = false; } if (X) { x += xplus; usei.at(i).push_back(y); usej.at(i).push_back(x); cout << (xplus == 1 ? "R" : "L") << flush; } else { y += yplus; usei.at(i).push_back(y); usej.at(i).push_back(x); cout << (yplus == 1 ? "D" : "U") << flush; } } //yの残りをうめる while (y != input.at(2)) { y += yplus; usei.at(i).push_back(y); usej.at(i).push_back(x); cout << (yplus == 1 ? "D" : "U") << flush; } cout << endl; //入力 ll output; cin >> output; //点数の平均を計算 int size = usei.at(i).size(); output *= 60; output /= size; vec_output.push_back(output); ll sum = 0; for (ll a : vec_output) { sum += a; } ll ave = sum / vec_output.size(); vector<ll> put_output; for (ll a : vec_output) { put_output.push_back(a-ave); } rep(j, put_output.size()) { put_output.at(j) -= usedoutput.at(j); usedoutput.at(j) = put_output.at(j); rep(k, usei.at(j).size()-1) { int a = usei.at(j).at(k); int b = usej.at(j).at(k); int c = usei.at(j).at(k+1); int d = usej.at(j).at(k+1); //cout << a*30+b << " " << c*30+d << endl; dp.at(a*30+b).at(c*30+d) += put_output.at(j); dp.at(c*30+d).at(a*30+b) += put_output.at(j); } } /*rep(j, 29) { rep(k, 29) { cout << " " << dp.at(j*30+k).at(j*30+k+1); } cout << endl; rep(k, 30) { cout << dp.at(j*30+k).at((j+1)*30+k) << " "; } cout << endl; }*/ } }
//#include <atcoder/all> //using namespace atcoder; #include <bits/stdc++.h> using namespace std; typedef long long ll; #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 ALL(v) v.begin(), v.end() #define bit(n) (1LL<<(n)) #define FIX(d) fixed << setprecision(d) using P = pair<int, int>; using LP = pair<ll, ll>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; 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 int INF = 1e9; const ll LINF = (1LL<<60); int di[] = {-1, 1, 0, 0}; int dj[] = {0, 0, -1, 1}; const int H = 30, W = 30; struct edge { int to; int cost; edge(int _to, int _cost){ to = _to; cost = _cost; } }; using Graph = vector<vector<edge>>; // 経路復元用 vector<ll> dijkstra(int s, const Graph &G, vector<int> &prev) { int n = G.size(); priority_queue<P, vector<P>, greater<P>> que; vector<ll> d(n, INF); prev.resize(n, -1); d[s] = 0; que.emplace(0, s); while (!que.empty()){ P p = que.top(); que.pop(); int v = p.second; if (d[v] < p.first) continue; for(auto nv: G[v]){ if (d[nv.to] > d[v] + nv.cost){ d[nv.to] = d[v] + nv.cost; prev[nv.to] = v; que.emplace(d[nv.to], nv.to); } } } return d; } string get_path(const vector<int> &prev, int t) { vector<int> path; for (int cur = t; cur != -1; cur = prev[cur]) { path.push_back(cur); } reverse(path.begin(), path.end()); string pathString = ""; REP(i,path.size()-1){ if(path[i]-path[i+1]==1) pathString.push_back('L'); else if(path[i]-path[i+1]==-1) pathString.push_back('R'); else if(path[i]-path[i+1]==W) pathString.push_back('U'); else pathString.push_back('D'); } return pathString; } unsigned int xor128(){ static unsigned int x=123456789,y=362436069,z=521288629,w=88675123; unsigned int t = (x^(x<<11)); x=y; y=z; z=w; return( w=(w^(w>>19))^(t^(t>>8)) ); } void init(Graph &G){ REP(i,H) REP(j,W){ int cur = i*W+j; REP(k,4){ int ni = i+di[k]; int nj = j+dj[k]; if(ni<0 || ni>=H || nj<0 || nj>=H) continue; int next = ni*W+nj; ll cost = (xor128() % 7800) + 1100; G[cur].push_back(edge(next, cost)); G[next].push_back(edge(cur, cost)); } } } int main() { Graph G(H*W); init(G); REP(q,1000){ int si, sj, ti, tj; cin >> si >> sj >> ti >> tj; int sp = si*W+sj; int tp = ti*W+tj; vector<int> prev; auto dist = dijkstra(sp, G, prev); string path = get_path(prev, tp); cout << path << endl; int score; cin >> score; int score_per = score / path.size(); int cur = tp; while(cur!=sp){ int next = prev[cur]; for(auto &eg: G[cur]){ if(eg.to!=next) continue; //chmin(eg.cost, score_per); eg.cost = score_per; } for(auto &eg: G[next]){ if(eg.to!=cur) continue; //chmin(eg.cost, score_per); eg.cost = score_per; } cur = next; } } return 0; }