code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <bits/stdc++.h> using namespace std; #define ll long long #define MAX_SIZE 1000000000 int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int a,b,c; cin >> a >> b >> c; a -= b; if(b<=0){ cout << "0" << endl; return 0; }else{ cout << a+c << endl; } return 0; }
#include <iostream> using namespace std; int main(int argc, const char * argv[]) { int N,A,B; cin >> N >> A >> B ; cout << ((N+B)-A) << "\n"; return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> // #include "icld.cpp" using namespace std; using ll = long long int; using vi = vector<int>; using si = set<int>; using vll = vector<ll>; using vvi = vector<vector<int>>; using ss = string; using db = double; template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>; const int dx[4] = {1,0,-1,0}; const int dy[4] = {0,1,0,-1}; #define V vector #define P pair<int,int> #define rep(i,s,n) for(int i=(s);i<(int)(n);i++) #define rev(i,s,n) for(int i=(s);i>=(int)(n);i--) #define reciv(v,n) vi (v)((n)); rep(i,0,(n))cin>>v[i] #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define ci(x) cin >> x #define cii(x) ll x;cin >> x #define cci(x,y) ll x,y;cin >> x >> y #define co(x) cout << x << endl #define pb push_back #define eb emplace_back #define rz resize #define sz(x) int(x.size()) #define yn cout<<"Yes"<<endl;else cout<<"No"<<endl #define YN cout<<"YES"<<endl;else cout<<"NO"<<endl template<class T>void chmax(T &x,T y){x=max(x,y);} template<class T>void chmin(T &x,T y){x=min(x,y);} ll n; int f(ll x){ ss s=to_string(x); s+=s; ll nx=stoll(s); if(nx<=n)return 1; return 0; } int main(){ ci(n); ll ans=0; rep(i,1,1e6+1){ int now=f(i); if(now==1)ans++; } co(ans); }
#include "bits/stdc++.h" #define FIXED_FLOAT(x) std::fixed <<std::setprecision(20) << (x) #define all(v) (v).begin(), (v).end() using namespace std; #define forn(i,n) for (int i = 0; i < (n); ++i) using ll = long long; int mod = (ll)1e9 + 7; #define PI acos(-1) typedef pair<int, int> pairs; const int INF = 1e9 + 1; const int N = 2e5 + 100; const double eps = 1e-3; template <typename XPAX> void ckma(XPAX &x, XPAX y) { x = (x < y ? y : x); } template <typename XPAX> void ckmi(XPAX &x, XPAX y) { x = (x > y ? y : x); } void solve() { int n; cin >> n; string s; cin >> s; ++n; vector<int> a(n); forn(i, n) { cin >> a[i]; } int k = INF; forn(i, n - 1) ckmi(k, abs(a[i + 1] - a[i])); cout << k << '\n'; forn(i, k) { forn(j, n) { cout << a[j] / k + (i < a[j] % k) << ' '; } cout << '\n'; } } void test_case() { int t; cin >> t; forn(p, t) { //cout << "Case #" << p + 1 << ": "; solve(); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); solve(); }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <set> #include <sstream> #include <string> #include <vector> #define endl '\n' #define ull unsigned long long #define ll long long #define ul unsigned long #define ld long double #define PI 3.14159265359 using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t = 1; // cin >> t; while (t--) { char s, t; cin >> s >> t; if (s == 'Y' && t >= 'a' && t <= 'z') t -= 32; cout << t << endl; } }
#include <iostream> using namespace std; int main() { char x,y; cin>>x>>y; if(x=='Y'){ y=toupper(y); } else{ y=tolower(y); } cout<<y<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define pi pair<int,int> #define f first #define s second #define ld long double const int nax=205; map<int,int> vis,dp; int x,y; int find(int v) { if(vis[v]) return dp[v]; vis[v]=1; dp[v]=1e18; int& res=dp[v]; res=min(res,abs(v-x)); if(v==1) return res; if(v%2==0) res=min(res,1+find(v/2)); else res=min(res,1+min(find(v+1),find(v-1))); return res; } void solve() { cin>>x>>y; cout<<find(y); } signed main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); int t=1; //cin>>t; while(t--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; using LL = long long; using ULL = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int main(){ LL X,Y; cin>>X>>Y; if(X>Y){ cout<<(X-Y)<<endl; return 0; } LL L=0, LV=Y, R=1, RV=Y+1; LL ans=Y-X; rep(i,70){ ans=min(ans,abs(LV-X)+L); ans=min(ans,abs(RV-X)+R); LL newL,newR; if(LV%2==0){ LV/=2; RV=LV+1; newL=min(L+1,R+2); newR=min(L+2,R+2); } else { RV/=2; LV=RV-1; newL=min(L+2,R+2); newR=min(L+2,R+1); } L=newL; R=newR; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> int main() { int n; std::cin >> n; std::vector<int> a(n), b(n), c(n); for (int i = 0; i < n; ++i) std::cin >> a[i]; for (int i = 0; i < n; ++i) std::cin >> b[i]; for (int i = 0; i < n; ++i) std::cin >> c[i]; for (int i = 0; i < n; ++i) --a[i], --b[i], --c[i]; // Bを基準に考える // a_count[i] := iがaに何個あるか eg. a_count[2] == 2の場合 std::vector<int> a_count(n, 0); for (int i = 0; i < n; ++i) ++a_count[a[i]]; std::vector<int> b_count(n, 0); // b_count[i] := b[i]==a[i]となる個数; for (int i = 0; i < n; ++i) b_count[i] = a_count[b[i]]; // b_count[i] := b[i]=a[j]となるjが何個あるか std::vector<int> c_count(n+1, 0); // c_count[i] := iがcに何個あるか for (int i = 0; i < n; ++i) ++c_count[c[i]]; long long ans = 0; for (int i = 0; i < n; ++i) ans += b_count[i] * c_count[i]; std::cout << ans << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int N; cin >> N; vector<int> A(N); vector<int> B(N); vector<int> C(N); rep(i, N) { cin >> A.at(i); } rep(i, N) { cin >> B.at(i); } rep(i, N) { cin >> C.at(i); } int64_t ret = 0; vector<int> m(N); rep(i, N) { m[B[C[i]-1]]++; } rep(i, N) { ret += m[A[i]]; } cout << ret << endl; }
#include <bits/stdc++.h> #include <climits> using namespace std; template<class T> using V = vector<T>; template<class T> using VV = V<V<T>>; using ld = long double; #define ll long long using ull = unsigned ll; using PLL = pair<ll, ll>; using VLL = V<ll>; using VB = V<bool>; using VVB = VV<bool>; using VVLL = VV<ll>; using Gr = VVLL; using MLL = map<ll, ll>; #define UMLL unordered_map<ll, ll, custom_hash> #define fast ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); #define R & #define CR const R #define FORI(i, a, b) for(ll i = a, max##i = b; i < max##i; ++i) #define FOR(i, n) FORI(i, 0, n) #define RFORI(i, a, b) for(ll i = a, min##i = b; i >= min##i; --i) #define RFOR(i, n) RFORI(i, n, 0) #define FORA(i, a) for(auto i : a) #define FORAR(i, a) for(auto R i : a) #define FORACR(i, a) for(auto CR i : a) #define ALL(obj) begin(obj), end(obj) #define Count(q) while(q--) #define OK cerr << "OK\n"; #define mp make_pair #define pb push_back //#define DEBUG template<class T> T sqr(T x) { return x * x; } void YES(bool g, ostream R os, bool upper = true) { if(g) if(upper) os << "YES"; else os << "Yes"; else if(upper) os << "NO"; else os << "No"; os << "\n"; } template<class T> void show(T CR t, ostream R os = cerr) { FORACR(i, t) os << i << " "; os << "\n"; } template<class T> void show2d(T CR t, ostream R os = cerr) { FORACR(i, t) show(i, os); os << "\n"; } constexpr ll MOD = 1e9 + 7; //998244353; constexpr ll len = 'z' - 'a' + 1; constexpr ll INF = 1e18, MINF = -INF; constexpr ld PI = atanl(1.0L) * 4; constexpr ld eps = 1e-9, EPS = 1e-9; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator() (uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; //arr void init() {} ll sgn(ll a) { if(a > 0) return 1; if(a < 0) return -1; return 0; } void solve(istream R is, ostream R os) { ll a, b, c; is >> a >> b >> c; ll x = pow(sgn(a), c), y = pow(sgn(b), c); if(x < y) os << "<"; else if(x > y) os << ">"; else { a = abs(a); b = abs(b); if(a > b) os << ">"; else if(a < b) os << "<"; else os << "="; } } void tester(istream R is, ostream R os) { auto seed = time(nullptr); //cerr << "seed: " << seed << "\n"; srand(seed); fast init(); ll q = 1; //is >> q; os << setprecision(999); Count(q) solve(is, os); } int main() { ifstream in("input.txt"); ofstream out("output.txt"); tester(cin, cout); }
#include <bits/stdc++.h> using namespace std; //using Graph = vector<vector<long long>>; using Graph = vector<vector<int>>; const long long INF = 1LL <<59; const long long Mo=1000000007; //vector<long long> seen; vector<int> seen; long long dfs(const Graph &G, int v, long long cnt) { seen[v] = cnt; //判定だけならcntをboolに // v から行ける各頂点 next_v について for (auto next_v : G[v]) { if (seen[next_v]>=0) continue; // next_v が探索済だったらスルー dfs(G, next_v, cnt+1); // 再帰的に探索 } //cout<<grp<<" "<<cnt<<endl; return 0; } long long gcn(long long x,long long y){ if(x%y==0){ return y; } else{ return gcn(y,x%y); } } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main(void){ long long res,tmp,tmp1,tmp2,cnt,idx,cur,prev; long long flg; long long i,j,n,k,l; long long a,b,c; cin>>a>>b>>c; if(c%2==0){ if(abs(a)==abs(b)){ cout<<"="<<endl; } else if(abs(a)>abs(b)){ cout<<">"<<endl; } else{ cout<<"<"<<endl; } return 0; } else{ if(a>b){ cout<<">"<<endl; } else if(a<b){ cout<<"<"<<endl; } else{ cout<<"="<<endl; } return 0; } //cout<<res<<endl; //cout<<setprecision(15)<<t<<endl; //cout<<res<<endl; return 0; } /* Graph G(n); seen.assign(n,-1); for(i=0; i<m; i++) { cin>>tmp1>>tmp2; tmp1--; tmp2--; G[tmp1].push_back(tmp2); G[tmp2].push_back(tmp1); } */
#include <bits/stdc++.h> #define ADD(a, b) a = (a + ll(b)) % mod #define MUL(a, b) a = (a * ll(b)) % mod #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define rep(i, a, b) for(int i = int(a); i < int(b); i++) #define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--) #define all(a) (a).begin(), (a).end() #define sz(v) (int)(v).size() #define pb push_back #define sec second #define fst first #define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<int, pi> ppi; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> mat; typedef complex<double> comp; void Debug() {cerr << '\n'; } template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){ cerr<<arg<<" ";Debug(rest...);} template<class T>ostream& operator<<(ostream& out,const vector<T>& v) { out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;} template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){ out<<"("<<v.first<<", "<<v.second<<")";return out;} const int MAX_N = 500010; const int MAX_V = 100010; const double eps = 1e-6; const ll mod = 1000000007; const int inf = (1 << 30) - 1; const ll linf = 1LL << 60; const double PI = 3.14159265358979323846; mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng) /////////////////////////////////////////////////////////////////////////////////////////////////// ll X, Y; map<ll, ll> DP; void solve() { cin >> X >> Y; deque<ll> que; DP[Y] = 0; que.push_back(Y); while(!que.empty()) { ll t = que.front(); que.pop_front(); ll v = DP[t]; if(t == 0) continue; rep(i, -1, 1 + 1) { if((t + i) % 2 == 0 && (!DP.count((t + i) / 2) || DP[(t + i) / 2] > v + 1 + abs(i))) { DP[(t + i) / 2] = v + 1 + abs(i); que.push_back((t + i) / 2); } } } ll res = linf; for(auto p: DP) { // debug(p); MIN(res, p.sec + abs(p.fst - X)); } cout << res << "\n"; } uint32_t rd() { uint32_t res; #ifdef __MINGW32__ asm volatile("rdrand %0" :"=a"(res) ::"cc"); #else res = std::random_device()(); #endif return res; } int main() { #ifndef LOCAL ios::sync_with_stdio(false); cin.tie(0); #endif cout << fixed; cout.precision(20); cerr << fixed; cerr.precision(6); rng.seed(rd()); #ifdef LOCAL //freopen("in.txt", "wt", stdout); //for tester if(!freopen("in.txt", "rt", stdin)) return 1; #endif solve(); cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstddef> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define PB push_back #define MP make_pair #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl #define INF (1 << 28) #define LLINF (1LL << 60) //#define MOD 998244353 #define MOD 1000000007 #define rep(i, n) for (int i = 0; i < n; i++) using ll = long long; using namespace std; typedef pair<int, int> P; int main() { int n, m; ll a[200005], b[200005]; vector<int> graph[200005]; vector<vector<int>> connected; bool ischecked[200005] = {}; //false:not checked, true:checked cin >> n >> m; rep(i, n) { cin >> a[i]; } rep(i, n) { cin >> b[i]; } rep(i, m) { int c, d; cin >> c >> d; graph[c].push_back(d); graph[d].push_back(c); } for (int i = 1; i <= n; i++) { vector<int> t_vec; queue<int> t_que; if (!ischecked[i]) { t_vec.push_back(i); ischecked[i] = true; rep(j, graph[i].size()) { if (!ischecked[graph[i][j]]) { t_que.push(graph[i][j]); t_vec.push_back(graph[i][j]); ischecked[graph[i][j]] = true; } } while (!t_que.empty()) { int t = t_que.front(); t_que.pop(); rep(j, graph[t].size()) { if (!ischecked[graph[t][j]]) { t_que.push(graph[t][j]); t_vec.push_back(graph[t][j]); ischecked[graph[t][j]] = true; } } } connected.push_back(t_vec); } } bool ans = true;//true:Yes for (int i = 0; i < connected.size(); i++) { ll a_sum = 0, b_sum = 0; for (int j = 0; j < connected[i].size();j++){ a_sum += a[connected[i][j] - 1]; b_sum += b[connected[i][j] - 1]; } if (a_sum != b_sum) { ans = false; } } if(ans){ Yes; } else{ No; } /* cout << endl; for (int i = 1; i <= n; i++) { cout << i << ' '; for (int j = 0; j < graph[i].size(); j++) { cout << graph[i][j] << ' '; } cout << endl; } cout << endl; rep(i, connected.size()) { cout << i << ' '; rep(j, connected[i].size()) { cout << connected[i][j] << ' '; } cout << endl; } */ return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef set<int> si; typedef set<ll> sl; typedef queue<int> qi; typedef queue<ll> ql; typedef stack<int> sti; typedef deque<int> dqi; typedef priority_queue<int> pqi; typedef priority_queue<ll> pql; typedef deque<ll> dql; typedef vector<vl> vvl; typedef pair<int,int> pii; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; typedef double dl; #define PB push_back #define F first #define S second #define MP make_pair #define el '\n' #define sl(x) (int)x.length() #define all(a) (a).begin(),(a).end() #define sz(x) (int)x.size() #define mid(l,r) ((r+l)/2) #define left(node) (node*2) #define right(node) (node*2+1) #define mx_int_prime 999999937 #define loop(i,n) for(int i=0;i<n;i++) const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const ll infLL = 9000000000000000000; #define MOD 1000000007 #define in(n) ll n;cin>>n; #define mem(a,b) memset(a, b, sizeof(a) ) #define gcd(a,b) __gcd(a,b) #define sqr(a) ((a) * (a)) #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define fraction(a) cout.unsetf(ios::floatfield); cout.precision(a); cout.setf(ios::fixed,ios::floatfield); typedef vector<int>::iterator vit; typedef set<int>::iterator sit; int dx[] = {0, 0, +1, -1}; int dy[] = {+1, -1, 0, 0}; //int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1}; //int dy[] = {0, +1, 0, -1, +1, -1, +1, -1}; int t; ll c[69], a[69]; int solve(int x){ string s = to_string(x); sort(s.begin(), s.end()); string t(s.rbegin(), s.rend()); return stoi(t) - stoi(s); } int main(){ int t,k; cin>>t>>k; while(k--){ t=solve(t); } cout<<t<<el; return 0 ; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n);i++) using ll = long long; const ll INF = 1e9+7; using P = pair<int,int>; int main(){ string s; int k; cin >> s >> k; rep(i,k){ string g1 = s; string g2 = s; sort(g1.begin(), g1.end(), greater<int>()); sort(g2.begin(), g2.end()); ll x = stoi(g1) - stoi(g2); stringstream iss; iss << x; s = iss.str(); } cout << s << endl; }
#include <iostream> #include <vector> #include <bits/stdc++.h> #define ll long long using namespace std; //take care of long long //fast I/O auto optimizer = []() { // makes I/O fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); return 0; }(); int main() { ll t=1; //cin>>t; while(t--) { ll a,b,c; cin>>a>>b>>c; if(a==b) cout<<c<<endl; else if(b==c) cout<<a<<endl; else if(c==a) cout<<b<<endl; else cout<<0<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define M (int)(1e9 + 7) int ar[100005][26]; int N; int sum(int r, int l) { int res[26] = {0}; for (; r > 0; r -= (r & -r)) { for (int j = 0; j < 26; j++) { res[j] += ar[r][j]; } } int res1[26] = {0}; for (; l > 0; l -= (l & -l)) { for (int j = 0; j < 26; j++) { res1[j] += ar[l][j]; } } int count = 0; for (int i = 0; i < 26; i++) { if (res[i] - res1[i] > 0) { count++; } } return count; } void update(int val, int i, int num) { for (; i <= N; i += (i & -i)) { ar[i][val]++; if (num > -1) { ar[i][num]--; } } } bool rounder(int n) { if (n == 3 || n == 4 || n == 5 || n == 6) return true; else return false; } int solve() { int a,b,c; cin >> a >> b >> c; if(a==b) { return c; } else if(b==c) { return a; } else if(a==c) { return b; } else return 0; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // int t; // cin >> t; // while (t--) // { // cout << solve()<<"\n"; // } //cout << __gcd(69,138); cout << solve() << "\n"; }
//#define _GLIBCXX_DEBUG //#include "atcoder/all" //using namespace atcoder; #include <bits/stdc++.h> #define int long long #define ll long long using ull = unsigned long long; using namespace std; #define Dump(x) \ if (dbg) { \ cerr << #x << " = " << (x) << endl; \ } #define overload4(_1, _2, _3, _4, name, ...) name #define FOR1(n) for (ll i = 0; i < (n); ++i) #define FOR2(i, n) for (ll i = 0; i < (n); ++i) #define FOR3(i, a, b) for (ll i = (a); i < (b); ++i) #define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c)) #define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__) #define FORR(i, a, b) for (int i = (a); i <= (b); ++i) #define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/ namespace mydef { const int INF = 1ll << 60; const int MOD = 1e9 + 7; template <class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } else return 0; } template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } else return 0; } void Yes(bool flag = true) { if (flag) cout << "Yes" << endl; else cout << "No" << endl; } void No(bool flag = true) { Yes(!flag); } void YES(bool flag = true) { if (flag) cout << "YES" << endl; else cout << "NO" << endl; } void NO(bool flag = true) { YES(!flag); } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); } bool dbg = true; } // namespace mydef using namespace mydef; #define pb push_back //#define mp make_pair #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(), (v).end() #define SZ(x) ((int)(x).size()) #define vi vector<int> #define vvi vector<vector<int>> #define vp vector<pair<int, int>> #define vvp vector<vector<pair<int, int>>> #define pi pair<int, int> //#define P pair<int, int> //#define V vector<int> //#define S set<int> #define asn ans int T; bool check(const string& S, const string& T) { //S > T; int N = S.size(); int now = 0; for (int i = 0; i < T.size(); i++) { if (now >= N) return false; while (T[i] != S[now]) { now++; if (now >= N) return false; } now++; } return true; } void solve() { while (T--) { int N; cin >> N; string S[3]; cin >> S[0] >> S[1] >> S[2]; vector<string> T; for (int a = 0; a < 2; a++) { for (int b = 0; b < 2; b++) { string A, B; for (int i = 0; i < N; i++) { A += (char)('0' + a); B += (char)('0' + b); } T.emplace_back('0' + A + B); T.emplace_back('1' + A + B); T.emplace_back(A + '0' + B); T.emplace_back(A + '1' + B); T.emplace_back(A + B + '0'); T.emplace_back(A + B + '1'); } } for (int i = 0; i < 3; i++) { S[i] += S[i]; } string ans; for (auto& s : T) { if (check(S[0], s) && check(S[1], s) && check(S[2], s)) { ans = s; break; } } cout << ans << endl; } } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> T; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=(a);i<=(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define ALL(x) (x).begin(),(x).end() #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) vector<vector<ll> > vertexes(200, vector<ll>(4)); vector<ll> rlist(200); bool check_no_overlap(ll label, ll n){ ll ax1 = vertexes.at(label).at(0), ay1 = vertexes.at(label).at(1), ax2 = vertexes.at(label).at(2), ay2 = vertexes.at(label).at(3); REP(i,n){ if (i==label){continue;} ll bx1 = vertexes.at(i).at(0), by1 = vertexes.at(i).at(1), bx2 = vertexes.at(i).at(2), by2 = vertexes.at(i).at(3); if ((max(ay1,by1)<=min(ay2,by2)) && (max(ax1,bx1)<=min(ax2,bx2))){return false;} } return true; } bool meet(ll x,ll n){ if (check_no_overlap(x,n) && (0 <= vertexes.at(x).at(0) && 0 <= vertexes.at(x).at(1) && vertexes.at(x).at(2) < 10000 && vertexes.at(x).at(3) < 10000)){ return true; }else{ return false; } } int main() { ll n; cin >> n; clock_t start = clock(); REP(i,n){ ll x,y,r; cin >> x >> y >> r; vertexes.at(i).at(0) = x; vertexes.at(i).at(1) = y; vertexes.at(i).at(2) = x+1; vertexes.at(i).at(3) = y+1; rlist.at(i) = r; } while (static_cast<double> (clock()-start) / CLOCKS_PER_SEC * 1.0 < 4.8){ ll label = rand() % n; ll rl = rlist.at(label); double t = static_cast<double> (clock()-start) / CLOCKS_PER_SEC * 1.0; ll w = (ll) (-13*t + 53); if (t >= 4){w = 1;} ll pre_sl = (vertexes.at(label).at(2)-vertexes.at(label).at(0))*(vertexes.at(label).at(3)-vertexes.at(label).at(1)); double pre_score = 1-(1-((double) min(rl,pre_sl))/max(rl,pre_sl))*(1-((double) min(rl,pre_sl))/max(rl,pre_sl)); REP(dir,4){ if (dir<2){vertexes.at(label).at(dir) -= w;} else{vertexes.at(label).at(dir)+=w;} ll sl = (vertexes.at(label).at(2)-vertexes.at(label).at(0))*(vertexes.at(label).at(3)-vertexes.at(label).at(1)); double score = 1-(1-((double) min(rl,sl))/max(rl,sl))*(1-((double) min(rl,sl))/max(rl,sl)); if (meet(label,n) && score > pre_score) {pre_score=score;} else{ if (dir<2){vertexes.at(label).at(dir) += w;} else{vertexes.at(label).at(dir)-=w;} } } } REP(i,n){ cout << vertexes.at(i).at(0) << " " << vertexes.at(i).at(1) << " " << vertexes.at(i).at(2) << " " << vertexes.at(i).at(3) << endl; } }
#include <vector> #include <functional> using namespace std; template<typename T> class SegmentTree { int n; function<T(T,T)> op; vector<T> V; T q(int l, int r) { if (l >= r) return V[0]; T a = q((l+1)/2, r/2); if (l%2 != 0) a = op(a, V[l]); if (r%2 != 0) a = op(a, V[r-1]); return a; } public: SegmentTree(int n_, function<T(T,T)> op, T init): op(op) { n = 1; while (n < n_) n *= 2; V = vector<T>(2*n, init); for (int i=n-1; i>0; i--) V[i] = op(V[i*2], V[i*2+1]); } T get(int p) const { return V[p+n]; } void set(int p, T v) { p += n; V[p] = v; for (p/=2; p>0; p/=2) V[p] = op(V[p*2], V[p*2+1]); } // init OP v[l] OP v[l+1] OP ... OP v[r-1] T query(int l, int r) { return q(l+n, r+n); } }; #include <iostream> #include <set> #include <map> int main() { int N, M, Q; cin>>N>>M>>Q; vector<int> T(Q), X(Q); vector<long long> Y(Q); for (int i=0; i<Q; i++) { cin>>T[i]>>X[i]>>Y[i]; X[i]--; } set<long long> YS; YS.insert(0); for (long long y: Y) YS.insert(y); vector<long long> YV; map<long long, int> YI; for (long long y: YS) { YI[y] = (int)YV.size(); YV.push_back(y); } int n = (int)YS.size(); SegmentTree<long long> AC(n, [&](long long x, long long y){return x+y;}, 0); SegmentTree<long long> AS(n, [&](long long x, long long y){return x+y;}, 0); SegmentTree<long long> BC(n, [&](long long x, long long y){return x+y;}, 0); SegmentTree<long long> BS(n, [&](long long x, long long y){return x+y;}, 0); AC.set(0, N); BC.set(0, M); long long ans = 0; vector<long long> a(N), b(M); for (int q=0; q<Q; q++) { auto &a2 = T[q]==1 ? a : b; auto &AC2 = T[q]==1 ? AC : BC; auto &AS2 = T[q]==1 ? AS : BS; auto &b2 = T[q]==2 ? a : b; auto &BC2 = T[q]==2 ? AC : BC; auto &BS2 = T[q]==2 ? AS : BS; ans -= BS2.query(YI[a2[X[q]]], n) + BC2.query(0, YI[a2[X[q]]])*a2[X[q]]; AC2.set(YI[a2[X[q]]], AC2.get(YI[a2[X[q]]])-1); AS2.set(YI[a2[X[q]]], AS2.get(YI[a2[X[q]]])-a2[X[q]]); a2[X[q]] = Y[q]; AC2.set(YI[a2[X[q]]], AC2.get(YI[a2[X[q]]])+1); AS2.set(YI[a2[X[q]]], AS2.get(YI[a2[X[q]]])+a2[X[q]]); ans += BS2.query(YI[a2[X[q]]], n) + BC2.query(0, YI[a2[X[q]]])*a2[X[q]]; cout<<ans<<endl; } }
#include <cstdio> #include <iostream> #include <cassert> #include <string> #include <algorithm> #include <cstring> #include <utility> #include <vector> #include <stack> #include <queue> #include <map> #include <set> #include <cmath> #include <deque> #include <unordered_map> #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; const int MAXN = 234567; int bit[MAXN]; bool vis[MAXN]; vector<int> candH[MAXN]; vector<int> candW[MAXN]; int query(int x) { int res = 0; while (x) { res += bit[x]; x -= (x & -x); } return res; } void add(int x, int N) { vis[x] = 1; while (x <= N) { bit[x] += 1; x += (x & -x); } } int main() { int H, W, M; scanf("%d %d %d", &H, &W, &M); int mxH = H, mxW = W; for (int i = 0; i < M; i++) { int X, Y; scanf("%d %d", &X, &Y); if (Y == 1) mxH = min(X - 1, mxH); if (X == 1) mxW = min(Y - 1, mxW); candH[X].push_back(Y); candW[Y].push_back(X); } LL ans = (LL)mxH * mxW; for (int i = 1; i <= mxH; i++) { if (candH[i].empty()) continue; sort(candH[i].begin(), candH[i].end()); for (int w : candH[i]) { if (w > mxW || vis[w]) continue; add(w, W); } int ft = candH[i].front(); int offs = query(W) - query(ft - 1); assert((ft > mxW && offs == 0) || (ft <= mxW)); ans -= offs; } // printf("ans = %lld\n", ans); for (int i = 1; i <= mxH; i++) { sort(candH[i].begin(), candH[i].end()); if (candH[i].empty()) ans += (W - mxW); else if (candH[i].front() > mxW) { ans += (candH[i].front() - mxW - 1); } } for (int i = 1; i <= mxW; i++) { sort(candW[i].begin(), candW[i].end()); if (candW[i].empty()) ans += (H - mxH); else if (candW[i].front() > mxH) { ans += (candW[i].front() - mxH - 1); } } 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 by Benq; */
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> t(n); for (auto& x : t) cin >> x; constexpr int M = 1000001; vector<int> dp(M, 0); dp[0] = 1; for (auto x : t) { for (int i = M - 1; i >= 0; i--) { if (i + x < M && dp[i]) dp[i + x] = 1; } } int total = accumulate(t.begin(), t.end(), 0); int ans = M * 2; for (int i = 0; i < M; i++) if (dp[i]) { ans = min(ans, max(i, total - i)); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin>> #define ll long long #define ln cout<<'\n' #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n",a) #define mem(a) memset(a,0,sizeof(a)) #define all(c) (c).begin(),(c).end() #define iter(c) __typeof((c).begin()) #define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++) ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;} template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);} template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;} const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1}; typedef pair<ll,ll> P; ll dp[111111]; void Main() { ll n; R n; ll a[n]; rep(i,n) R a[i]; ll sum=0; rep(i,n) sum+=a[i]; mem(dp); dp[0]=1; rep(i,n) { rrep(j,100000) dp[j+a[i]]|=dp[j]; } ll ans=MAX; rep(i,111111) { if(dp[i]) ans=min(ans,max(i,sum-i)); } pr(ans); } int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
#include <bits/stdc++.h> using namespace std; void __print(int x) {cout << x;} void __print(long x) {cout << x;} void __print(long long x) {cout << x;} void __print(unsigned x) {cout << x;} void __print(unsigned long x) {cout << x;} void __print(unsigned long long x) {cout << x;} void __print(float x) {cout << x;} void __print(double x) {cout << x;} void __print(long double x) {cout << x;} void __print(char x) {cout << '\'' << x << '\'';} void __print(const char *x) {cout << '\"' << x << '\"';} void __print(const string &x) {cout << '\"' << x << '\"';} void __print(bool x) {cout << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';} template<typename T> void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";} void _print() {cout << "]"<<endl;} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);} #define deb(x...) cout << #x << " = ["; _print(x) template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;} template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;} // ================= #define f(i, k, n) for (int i = k; i < n; i++) #define r(i, k, n) for (int i = k; i >= n; i--) #define ll long long #define pb push_back #define fr first #define sc second #define len(s) s.size() #define all(v) v.begin(), v.end() #define tr(it, v) for (auto &it : v) typedef pair<int, int> pii; typedef vector<int> vi; typedef map<int, int> mii; typedef vector<pii> vpii; typedef vector<string> vs; typedef vector<vi> vvi; // ================= const int mod = 1e9+7; const int N = 3e5 + 1; int is(ll n) { int j=0; while (n%5==0) { j++; n/=5; } if(n==1) return j; else return -1; } void solve() { ll n; cin>>n; vector<ll> p3,p5; ll p=1; f(i,0,37) { p*=3; p3.pb(p); } p=1; f(i,0,25) { p*=5; p5.pb(p); } f(i,0,37) { f(j,0,25) { if(p3[i]+p5[j]==n) { cout<<i+1<<" "<<j+1; return; } else if(p3[i]+p5[j]>n) break; } } cout<<"-1"; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; while (t--) solve(); return 0; }
/* Author : Hocky Yudhiono 1/23/2021 7:55:58 PM 1. You can sort the query if offline! 2. Don't bring the dp remaining state when dfsing on DP on Tree. 3. Try to reverse (Think from the back) if you stuck. 4. Be careful when submitting Div. 2 D-F, dont waste it on stupid WAs. 5. Try to reduce a problem, think of it when you're making subtasks like when problemsetting. */ #include <algorithm> #include <iostream> #include <numeric> #include <cstdlib> #include <cassert> #include <cstring> #include <iomanip> #include <cstdio> #include <limits> #include <string> #include <vector> #include <cmath> #include <deque> #include <queue> #include <stack> #include <map> #include <set> using namespace std; typedef long long LL; typedef long long ll; typedef long double LD; typedef vector<int> vi; typedef pair<LL,LL> PLL; typedef pair<LL,int> PLI; typedef pair<int,int> PII; typedef pair<int,int> pii; typedef vector<vector<LL>> VVL; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define popf pop_front #define pf push_front #define popb pop_back #define mp make_pair #define pb push_back #define remove erase #define fi first #define se second // If the time limit is strict, try not to use long double // Remember to undefine if the problem is interactive #define endl '\n' #define DEBUG(X) cout << ">>> DEBUG(" << __LINE__ << ") " << #X << " = " << (X) << endl const double EPS = 1e-9; const int INFMEM = 63; const int INF = 1061109567; const LL LINF = 4557430888798830399LL; const double DINF = numeric_limits<double>::infinity(); const LL MOD = 1000000007; const int dx[8] = {0,0,1,-1,1,-1,1,-1}; const int dy[8] = {1,-1,0,0,1,-1,-1,1}; // Do dir^1 to get reverse direction const char dch[4] = {'R','L','D','U'}; // const string ds[8] = {"E","W","S","N","SE","NW","SW","NE"}; const double PI = 3.141592653589793; inline void open(string a){ freopen((a+".in").c_str(),"r",stdin); freopen((a+".out").c_str(),"w",stdout); } inline void fasterios(){ // Do not use if interactive ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); } typedef pair<double, double> PDD; LL n, m, k; bool isi[200005]; PDD sum[200005]; int main(){ fasterios(); cin >> n >> m >> k; for(int i = 1;i <= k;i++){ int tmp; cin >> tmp; isi[tmp] = 1; } // Dp[n] = sum of dp(i = n .. n + m)/m + 1 for(int i = n-1;i >= 0;i--){ PDD memo; if(isi[i]) memo = {1, 0}; else{ memo = {sum[i + 1].fi - sum[i + m + 1].fi, sum[i+1].se - sum[i+m+1].se}; memo.fi /= m; memo.se /= m; memo.se++; } // cout << memo.fi << " " << memo.se << endl; sum[i] = {sum[i+1].fi + memo.fi, sum[i+1].se + memo.se}; } if(fabs(1.0-(sum[0].fi-sum[1].fi)) < EPS) cout << -1 << endl; else cout << (sum[0].se-sum[1].se)/(1.0-(sum[0].fi-sum[1].fi)) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAX_N = 2e5+2; int n; pair<ll,ll> p[MAX_N]; int m; ll t[MAX_N],axis[MAX_N]; int q; ll A[MAX_N], B[MAX_N]; pair<ll,ll> ans[MAX_N]; struct query { ll a, b, id; bool operator<(const query& other) const { return a < other.a; } }; void solve() { vector<query> Q; for(int i=0;i<q;++i)Q.emplace_back(query{A[i],B[i],i}); sort(Q.begin(),Q.end()); ll sw=0,sx=1,sy=1; ll cx=0,cy=0; int idx=1; for(int i=0;i<q;++i){ for(; idx<=m && idx<=Q[i].a; ++idx){ if(t[idx]==1){ sw ^= 1; swap(cx,cy), swap(sx,sy); cy*=-1,sy*=-1; }else if(t[idx]==2){ sw ^= 1; swap(cx,cy), swap(sx,sy); cx*=-1,sx*=-1; }else if(t[idx]==3){ sx*=-1,cx*=-1; cx+=2LL*axis[idx]; }else{ sy*=-1,cy*=-1; cy+=2LL*axis[idx]; } } if(!sw){ ans[Q[i].id].first =sx*p[Q[i].b].first+cx; ans[Q[i].id].second=sy*p[Q[i].b].second+cy; } else{ ans[Q[i].id].first=sx*p[Q[i].b].second+cx; ans[Q[i].id].second=sy*p[Q[i].b].first+cy; } } for(int i=0;i<q;++i)cout<<ans[i].first<<' '<<ans[i].second<<'\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n; for(int i=1;i<=n;++i)cin>>p[i].first>>p[i].second; cin >> m; for(int i=1;i<=m;++i){ cin >> t[i]; if(t[i]==3 || t[i]==4) cin>>axis[i]; } cin >> q; for(int i=0;i<q;++i)cin>>A[i]>>B[i]; solve(); return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = 1001001001; const long long LINF = 1001002003004005006; const double PI = acos(-1); int d4r[] = {1, 0, -1, 0}; int d4c[] = {0, 1, 0, -1}; int d8r[] = {1, 1, 0, -1, -1, -1, 0, 1}; int d8c[] = {0, 1, 1, 1, 0, -1, -1, -1}; vector<vector<long long>> prod(vector<vector<long long>> a, vector<vector<long long>> b) { vector<vector<long long>> res(a.size(), vector<long long>(b[0].size())); for(int i = 0;i < res.size();++i) { for(int j = 0;j < res[0].size();++j) { res[i][j] = 0; for(int k = 0;k < a[0].size();++k) { res[i][j] += a[i][k] * b[k][j]; } } } return res; } struct operation{ vector<vector<vector<long long>>> op_matrix; operation(int m){ op_matrix.push_back({{1,0,0},{0,1,0},{0,0,1}}); } void make_matrix() { int op_num; cin >> op_num; vector<vector<long long>> new_matrix(3, vector<long long>(3)); if(op_num == 1) { new_matrix = prod({{0,1,0},{-1,0,0},{0,0,1}},op_matrix.back()); op_matrix.push_back(new_matrix); } else if(op_num == 2) { new_matrix = prod({{0,-1,0},{1,0,0},{0,0,1}},op_matrix.back()); op_matrix.push_back(new_matrix); } else if(op_num == 3) { long long p; cin >> p; new_matrix = prod({{-1,0,2 * p},{0,1,0},{0,0,1}},op_matrix.back()); op_matrix.push_back(new_matrix); } else { long long p; cin >> p; new_matrix = prod({{1,0,0},{0,-1,2 * p},{0,0,1}},op_matrix.back()); op_matrix.push_back(new_matrix); } return; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<long long> x(n), y(n); for(int i = 0;i < n;++i) { cin >> x[i] >> y[i]; } int m; cin >> m; operation op(m); for(int i = 0;i < m;++i) { op.make_matrix(); } // for(int i = 0;i < 3;++i) { // for(int j = 0;j < 3;++j) { // cout << op.op_matrix[0][i][j] << " "; // } // cout << endl; // } int q; cin >> q; for(int i = 0;i < q;++i) { int a, b; cin >> a >> b; b--; vector<vector<long long>> init(3,vector<long long>(1)); init[0][0] = x[b]; init[1][0] = y[b]; init[2][0] = 1; vector<vector<long long>> ans = prod(op.op_matrix[a],init); cout << ans[0][0] << " " << ans[1][0] << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ string a; cin>>a; int a1 = a.length(); for(int i=0 ; i<a1-1 ;i++){ swap(a[i] , a[i+1]); } cout<<a<<endl; return 0; }
// Problem : A - Rotate // Contest : AtCoder - AtCoder Beginner Contest 197(Sponsored by Panasonic) // URL : https://atcoder.jp/contests/abc197/tasks/abc197_a // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> #define int long long #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define pb push_back #define mod 1000000007 #define lld long double #define mii map<int, int> #define mci map<char, int> #define msi map<string, int> #define pii pair<int, int> #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define rep(i,x,y) for(int i=x; i<y; i++) #define fill(a,b) memset(a, b, sizeof(a)) #define vi vector<int> #define setbits(x) __builtin_popcountll(x) #define w(x) int x; cin>>x; while(x--) using namespace std; const long long N=100005, INF=2000000000000000000; int power(int a, int b, int p) { if(a==0) return 0; int res=1; a%=p; while(b>0) { if(b&1) res=(res*a)%p; b>>=1; a=(a*a)%p; } return res; } vi prime; bool isprime[N]; void pre() { for(int i=2;i<N;i++) { if(isprime[i]) { for(int j=i*i;j<N;j+=i) isprime[j]=false; prime.pb(i); } } return; } bool isPrime(int n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } int spf[N+1]; void spfFun(){ for(int i=0;i<=N;i++) spf[i]=i; for(int i=2;i*i<=N;i++){ if(spf[i]==i){ for(int j=i*i;j<=N;j+=i){ spf[j] = min(spf[j],i); } } } } bool isPerfectSquare(long double x) { // Find floating point value of // square root of x. long double sr = sqrt(x); // If square root is an integer return ((sr - floor(sr)) == 0); } void print(bool n){ if(n){ cout<<"YES"; }else{ cout<<"NO"; } } int32_t main() { IOS; // pre(); // fill(isprime,true); string s; cin>>s; cout<<s[1]<<s[2]<<s[0]; }
#include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> #define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout) using namespace __gnu_pbds; using namespace std; using ld = long double; using ll = long long; int n, m; int main(){ //IO("input.txt", "output.txt"); ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; if(n == 1 && !m){ cout << "1 2\n"; return 0; }else if(m < 0 || m + 2 > n){ cout << "-1\n"; return 0; } cout << 1 << ' ' << (int)1e8 << '\n'; for(int i = 0, j = 2; i < m + 1; i++, j += 2) cout << j << ' ' << j + 1 << '\n'; for(int i = 0, j = 1e8 + 1; i < n - m - 2; i++, j += 2) cout << j << ' ' << j + 1 << '\n'; return 0; }
/* このコード、と~おれ! Be accepted! ∧_∧  (。・ω・。)つ━☆・*。 ⊂   ノ    ・゜+.  しーJ   °。+ *´¨)          .· ´¸.·*´¨) ¸.·*¨)           (¸.·´ (¸.·'* ☆ */ #include <cstdio> #include <algorithm> #include <string> #include <cmath> #include <cstring> #include <vector> #include <numeric> #include <iostream> #include <random> #include <map> #include <unordered_map> #include <queue> #include <regex> #include <functional> #include <complex> #include <list> #include <cassert> #include <iomanip> #include <set> #include <stack> #include <bitset> ////多倍長整数, cpp_intで宣言 //#include <boost/multiprecision/cpp_int.hpp> //using namespace boost::multiprecision; // //#pragma GCC target ("avx2") //#pragma GCC optimization ("O3") //#pragma GCC optimization ("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define repeat(i, n, m) for(int i = n; i < (m); ++i) #define rep(i, n) for(int i = 0; i < (n); ++i) #define printynl(a) printf(a ? "yes\n" : "no\n") #define printyn(a) printf(a ? "Yes\n" : "No\n") #define printYN(a) printf(a ? "YES\n" : "NO\n") #define printim(a) printf(a ? "possible\n" : "imposible\n") #define printdb(a) printf("%.50lf\n", a) //少数出力 #define printLdb(a) printf("%.50Lf\n", a) //少数出力 #define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ) #define prints(s) printf("%s\n", s.c_str()) //string出力 #define all(x) (x).begin(), (x).end() #define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI) #define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L) #define Please return #define AC 0 #define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */ #define inf numeric_limits<double>::infinity(); #define linf numeric_limits<long double>::infinity() using ll = long long; using ull = unsigned long long; constexpr int INF = 1073741823; constexpr int MINF = -1073741823; constexpr ll LINF = ll(4661686018427387903); constexpr ll MOD = 1e9 + 7; constexpr ll mod = 998244353; constexpr long double eps = 1e-6; const long double PI = acosl(-1.0L); using namespace std; void scans(string& str) { char c; str = ""; scanf("%c", &c); if (c == '\n')scanf("%c", &c); while (c != '\n' && c != -1 && c != ' ') { str += c; scanf("%c", &c); } } void scanc(char& str) { char c; scanf("%c", &c); if (c == -1)return; while (c == '\n') { scanf("%c", &c); } str = c; } double acot(double x) { return PI / 2 - atan(x); } ll LSB(ll n) { return (n & (-n)); } template<typename T> inline T chmin(T& a, const T& b) { if (a > b)a = b; return a; } template<typename T> inline T chmax(T& a, const T& b) { if (a < b)a = b; return a; } ////atcoder library //#include <atcoder/all> //using namespace atcoder; /*-----------------------------------------ここからコード-----------------------------------------*/ int main() { int n, m; scanf("%d%d", &n, &m); vector<pair<int, int>> ans; if (m == 0) { int l = 1, r = 2; rep(i, n) { ans.emplace_back(l, r); l = r + 1; r = l + 1; } } else if(m > 0) { if (n - m - 2 < 0) { puts("-1"); return 0; } int l = 2, r = 3; rep(i, m + 1) { ans.emplace_back(l, r); l = r + 1; r = l + 1; } ans.emplace_back(1, l); l = r; r = l + 1; n -= m + 2; rep(i, n) { ans.emplace_back(l, r); l = r + 1; r = l + 1; } } else { puts("-1"); return 0; } for (const auto& [p, q] : ans)printf("%d %d\n", p, q); Please AC; }
#include<bits/stdc++.h> #define int ll #define sz(x) int((x).size()) #define all(x) (x).begin(),(x).end() #define x first #define y second using namespace std; using ll = long long; using pi = pair<int,int>; const int inf = 0x3f3f3f3f3f3f3f3f; const int minf = 0xc0c0c0c0c0c0c0c0; signed main() { ios::sync_with_stdio(0); cin.tie(0); int n; string s,t; cin>>n>>s>>t; if (count(all(s), '0') != count(all(t), '0')) { cout<<-1<<'\n'; return 0; } int _01 = 0, _10 = 0; int res = 0; for (int i=0; i<n; i++) { if (s[i] == '0') { // 00 if (t[i] == '0') { if (_10 || _01) ++res; } // 01 else { if (_10) { ++res; --_10; } else { ++_01; } } } else { // 10 if (t[i] == '0') { if (_01) { ++res; --_01; } else { ++_10; } } } } assert(_01 == 0 && _10 == 0); cout<<res<<'\n'; return 0; }
#include "bits/stdc++.h" using namespace std; using li = long long; const char newl = '\n'; template <class T> vector<vector<T>> vv(const unsigned int n, const unsigned int m, const T x) { return vector<vector<T>>(n, vector<T>(m, x)); } template <class T> vector<vector<vector<T>>> vvv(const unsigned int n, const unsigned int m, const unsigned int k, const T x) { return vector<vector<vector<T>>>(n, vv(m, k, x)); } template <class T> bool contains(const set<T>& s, const T& v) { return s.find(v) != s.end(); } template <class T> bool contains(const unordered_set<T>& s, const T& v) { return s.find(v) != s.end(); } template <class K, class V> bool contains_key(const map<K, V>& m, const K& v) { return m.find(v) != m.end(); } auto memo = vvv(101, 101, 101, (double)-1.); double recur(li a, li b, li c) { if (a >= 100 || b >= 100 || c >= 100) { return 0; } double &ans = memo[a][b][c]; if (ans != -1.) { return ans; } double sum = a + b + c; ans = 1; ans += recur(a + 1, b, c) * a / sum; ans += recur(a, b + 1, c) * b / sum; ans += recur(a, b, c + 1) * c / sum; return ans; } int main() { cin.tie(0); ios::sync_with_stdio(false); li a, b, c; cin >> a >> b >> c; cout.precision(12); cout << recur(a, b, c) << endl; return 0; }
//https://atcoder.jp/contests/agc048/tasks/agc048_b //B - Bracket Score #include <bits/stdc++.h> using namespace std; const int MAXN=2e5+4; long long a[MAXN]; long long b[MAXN]; int main() { ios::sync_with_stdio(false); int n; cin>>n; for (int i=1; i<=n; i++) { cin>>a[i]; } for (int i=1; i<=n; i++) { cin>>b[i]; if (0==i%2) { swap(a[i], b[i]); } } long long ans=0; for (int i=1; i<=n; i++) { ans+=a[i]; b[i]-=a[i]; } sort(b+1, b+n+1, greater<int>());//降序 for (int i=1; i<=n/2; i++) { ans+=b[i]; } cout<<ans<<"\n"; return 0; }
#include<bits/stdc++.h> #include<unordered_map> #include<unordered_set> #define f(i,a,b) for( int i=a;i<=b;++i) #define ff(i,a,b) for( int i=a;i>=b;--i) #define debug(x) cerr << #x << " : " << x << " " << endl using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<string, string> pss; const ll mod = 1e9 + 7; const ll mod2 = 998244353; const ll inf = 2e18; const double tiaohe = 0.57721566490153286060651209; ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; } ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; } ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } } ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; } bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; } inline ll in() { char ch = getchar();ll x = 0, f = 1;while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }return x * f; } void print(double x) { printf("%.6lf\n", x); } //double a = log(n) +tiaohe + 1.0 / (2 * n); double eqa = (1 + sqrt(5.0)) / 2.0; double E = 2.7182818284; const double eps = 1e-10; const int N = 6e5 + 100; ll a[N]; int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif int n; cin >> n; f(i, 1, n)a[i] = in(); ll ans = 0; ll pre = 0, sum = 0; sort(a + 1, a + 1 + n); f(i, 1, n) { sum = sum * 2 % mod2; ll nx = (sum + pre) % mod2; ll tmp = (sum + pre+a[i]) % mod2; ans = (ans + tmp * a[i] % mod2) % mod2; pre = a[i]; sum = nx; } cout << ans << 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--) const ll MOD = pow(10,9)+7; const ll LLINF = pow(2,61)-1; const ll INF = pow(2,30)-1; vector<ll> fac; void c_fac(ll x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; } ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; } ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; } ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; } ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } struct person { ll A, B; }; int main() { ll N; cin >> N; ll A[N], B[N]; rep(i,N) { cin >> A[i] >> B[i]; if (A[i]!=-1) A[i]--; if (B[i]!=-1) B[i]--; } ll from[N*2] = {}; rep(i,N) if (A[i]!=-1) from[A[i]]++; ll to[N*2] = {}; rep(i,N) if (B[i]!=-1) to[B[i]]++; rep(i,N) if (A[i]!=-1&&B[i]!=-1&&A[i]>=B[i]) { cout << "No" << endl; return 0; } rep(i,N*2) if (from[i]+to[i]>=2) { cout << "No" << endl; return 0; } bool ok[N*2][N*2] = {}; rep(i,N*2) repr(j,i+1,N*2) ok[i][j] = true; rep(i,N) { if (A[i]!=-1) { rep(j,N*2) { ok[j][A[i]] = false; if (to[j]) ok[A[i]][j] = false; } } if (B[i]!=-1) { rep(j,N*2) { ok[B[i]][j] = false; if (to[j]) ok[j][B[i]] = false; } } if (A[i]!=-1&&B[i]!=-1) rep(j,N*2) { ok[A[i]][j] = false; ok[j][B[i]] = false; } } rep(i,N) if (A[i]!=-1&&B[i]!=-1) ok[A[i]][B[i]] = true; // rep(i,N*2) debug(ok[i],ok[i]+N*2); bool dp[N+1] = {}; dp[0] = true; rep(i,N) { if (!dp[i]) continue; repr(j,i+1,N+1) { bool now = true; rep(k,j-i) now &= ok[i*2+k][i*2+k+(j-i)]; dp[j] |= now; } } // debug(dp,dp+(N+1)); string result = dp[N] ? "Yes" : "No"; cout << result << endl; return 0; }
//#pragma GCC optimize "trapv" #pragma GCC optimize("Ofast") #pragma GCC optimize("O3", "unroll-loops") #pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> #define ll long long int #define fab(a,b,i) for(ll i=a;i<b;i++) #define pb push_back #define db long double #define mp make_pair #define endl "\n" #define f first #define se second #define all(x) x.begin(),x.end() #define MOD 1000000007 #define vll vector<ll> #define vi vector<int> #define pii pair<int,int> #define pll pair<ll,ll> #define quick ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) using namespace std; ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);} ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);} ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);} ll power(ll x, ll y) {ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;} ll mod_inv(ll x) {return power(x, MOD - 2);} ll lcm(ll x, ll y) { ll res = x / __gcd(x, y); return (res * y);} db x, y, r; bool dist(db a, db b) { db dis = (x - a) * (x - a) + (b - y) * (b - y); return (dis <= (r * r)); } int main() { quick; #ifndef ONLINE_JUDGE freopen("D:/sublime/input.txt", "r", stdin); freopen("D:/sublime/output.txt", "w", stdout); #endif // int T = 1; // cin >> T; // while (T--) { cin >> x >> y >> r; r += 1e-14; ll val = x - r - 400; ll op = x + r + 400; ll ans = 0; fab(val, op + 1, i) { //cout << "i:" << i << endl; ll l = 0, h = 1e10; ll op = 0; while (l <= h) { ll mid = (l + h) / 2; //cout << "mid:" << mid << endl; db coord = floor(y + mid); //cout << "coord:" << i << " " << coord << endl; if (dist(i, coord)) { //cout << "have:" << i << " " << coord << endl; //cout << "mid:" << mid << endl; l = mid + 1; op = coord - ceil(y) + 1; } else h = mid - 1; } //cout << "jL" << l << endl; ans += op; l = (y == int(y) ? 1 : 0), h = 1e10; op = 0; while (l <= h) { ll mid = (l + h) / 2; //cout << "mid:" << mid << endl; db coord = floor(y - mid * 1.0); //cout << "coord:" << i << " " << coord << endl; if (dist(i, coord)) { //cout << "have1:" << i << " " << coord << endl; //cout << "mid1:" << floor(y) - coord + 1 << endl; l = mid + 1; op = floor(y) - coord + (y == int(y) ? 0 : 1); } else h = mid - 1; } //cout << "jL2" << l << endl; ans += op ; } cout << ans << endl; } cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define repr(i,a,b) for (int i=a; i<b; i++) #define rep(i,n) for (int i=0; i< n; i++) #define PI 3.14159265359 const long long INF = 1LL << 60; long long MOD = 1000000007; long long gcd(long long a, long long b) { return b ? gcd(b, a%b) : a; } long long lcm (int a, int b){return (long long) a*b /gcd(a,b);} int main(){ int N, X; cin >> N >> X; vector<int>ans; rep(i,N){ int a; cin >> a; if(a == X)continue; else ans.push_back(a); } for(int i = 0; i<ans.size(); i++){ if ( i == 0){ cout << ans[i]; } else cout << " " << ans[i]; } cout << endl; }
#pragma region head #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; using pi = pair<int, int>; using pll = pair<ll,ll>; template <class T> using vv = vector<vector<T>>; #define _roverload(_a1,_a2,_a3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _roverload(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define _rrep(i,n) rrepi(i,0,n) #define rrepi(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);--i) #define rrep(...) _roverload(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define bit(n) (1LL<<(n)) template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } void print() {cout << '\n';} template<class T> void print(const vector<T> &v) {bool f=false; for(const auto &e: v){if(f)cout << ' '; cout << e; f=true;} cout << '\n';} template<class... T> void print(const T&... args) {bool f=false; for(const auto &e: {args...}){if(f)cout << ' '; cout << e; f=true;} cout << '\n';} const int INF = 1002003004; const ll LINF = 1002003004005006007ll; struct preprocess{preprocess() {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____; #pragma endregion head #pragma region library #pragma endregion library int main(){ int n, x; cin >> n >> x; vi a(n); rep(i,n) cin >> a[i]; rep(i,n){ if(a[i] != x) cout << a[i] << ' '; } print(); }
#include<bits/stdc++.h> #define maxn 1000005 #define inf 0x7fffffffffff #define mod 1000000007 #define mst(a,x) memset(a,x,sizeof(a)) #define up(l,r,i) for(LL i=l;i<=r;i++) #define down(l,r,i) for(LL i=l;i>=r;i--) #define in(l,r,a) for(LL i=l;i<=r;i++)cin>>a[i] #define out(l,r,a) for(LL i=l;i<=r;i++)cout<<a[i]<<" " #define injz(n,m,a) for(LL i=1;i<=n;i++)for(LL j=1;j<=m;j++)cin>>a[i][j] #define st(a,n) sort(a+1,a+n+1) #define endl "\n" #define hh cout<<endl #define pb push_back #define cf cin>>T;while(T--) #define xh(n) U=n;while(U--) #define cfout(x) cout<<(x?"YES":"NO")<<endl #define cs cout<<"qaq"<<endl typedef long long LL;LL T,U; typedef double db; using namespace std; LL ans,a[10]; string s,ok; vector<LL>qaq; char tat[10]; map<string,LL>mp; void solve() { if(qaq.size()==4) { mst(a,0); string qwq=""; for(LL i:qaq) { qwq+=to_string(i); a[i]++; } LL ansnow=24; up(0,9,i) { if(!a[i])continue; LL now=1; up(1,a[i],j)now*=j; ansnow/=now; } up(0,3,i)tat[i]=qwq[i]; sort(tat,tat+4); up(0,3,i)qwq[i]=tat[i]; if(!mp[qwq]) { mp[qwq]++; ans+=ansnow; } return; } up(0,9,i) { if(s[i]=='o'||s[i]=='?') { qaq.pb(i); solve(); qaq.pop_back(); } } return; } int main() { ios::sync_with_stdio(false); #ifdef ONLINE_JUDGE #else //freopen("bwxnQAQin.txt","r",stdin); //freopen("bwxnQAQout.txt","w",stdout); #endif cin>>s; LL ok=0; up(0,9,i) { if(s[i]=='o') { ok++; qaq.pb(i); } } if(ok>4) { cout<<"0"<<endl; exit(0); } solve(); cout<<ans<<endl; cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms"; return 0; }
/* Solution By: Ashish Kudar */ /* When you get down to nothing.. */ #include<bits/stdc++.h> #define sync ios_base::sync_with_stdio(0);cin.tie(NULL); #define ll long long #define ull unsigned ll #define ld long double #define pii pair<int,int> #define pll pair<ll,ll> #define vi vector<int> #define vll vector<ll> #define vs vector<string> #define vb vector<bool> #define vpii vector<pair<int,int>> #define vpll vector<pair<ll,ll>> #define vvi vector<vector<int>> #define vvll vector<vector<ll>> #define all(x) x.begin(),x.end() #define FOR(i,a,b) for(int i=a;i<b;++i) using namespace std; const int MAX=1e6+5; const int mod=1e9+7; const ld pi=acos(-1); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); string s,t; ll calcNoOfStrings(string res,ll pos){ if(pos == 4){ t=s; FOR(i,0,s.length()){ if(s[i] == 'o') t[i]='0'; else if(s[i] == 'x') t[i]='1'; else t[i]='1'; } FOR(i,0,4){ if(s[res[i]-'0'] == 'o') t[res[i]-'0']='1'; else if(s[res[i] -'0'] == 'x') t[res[i]-'0']='0'; } if(t == string(10,'1')){ return 1; }else return 0; } ll ans=0; FOR(i,0,10){ res[pos]=i+'0'; ans+=calcNoOfStrings(res,pos+1); } return ans; } int main(){ // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif clock_t clk = clock(); sync int T=1; // cin>>T; for(int t=1;t<=T;++t){ // test cases starts here cin>>s; string ans(4,'X'); cout<<calcNoOfStrings(ans,0)<<endl; // cout<<"Case #"<<t<<": "; } // cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n'; } /* God is always upto something! */
#include <bits/stdc++.h> #include <unordered_map> #define eps 1e-8 #define PI 3.141592653589793 #define bsize 512 #define ll long long #define ull unsigned long long #define pii pair<int,int> #define vi vector<int> #define vii vector<vector<int>> #define pb push_back #define bs 1000000007 using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; cin>>n; int arr[(1<<n)+1]; arr[0]=-1; unordered_map<int, int> pos; for(int i=1;i<=(1<<n);i++){ cin>>arr[i]; pos[arr[i]]=i; } for(int i=1;i<=n;i++){ for(int j=1;j<=(1<<(n-i));j++){ if(i==n) arr[j]=min(arr[2*j-1],arr[2*j]); else arr[j]=max(arr[2*j-1],arr[2*j]); } } cout<<pos[arr[1]]; return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int INF = 1e9; const long long inf = 1LL<<60; //cout << fixed << setprecision(10) << << endl; bool solve(int left, vector<int> &res, int n, vector<int> &p, vector<int> &ip) { if ((int)res.size() == n-1) { for (int i=0; i<n; i++) { if (p.at(i) != i) return false; return true; } } if (ip.at(left) <= left) return false; for (int j=ip.at(left); j>left; j--) { res.push_back(j); swap(p.at(j), p.at(j-1)); } for (int j=left; j < ip.at(left); j++) { if (p.at(j) != j) return false; } return solve(ip.at(left), res, n, p, ip); } int main() { int n; cin >> n; vector<int> p(n), ip(n); for (int i=0; i<n; i++) { cin >> p.at(i); p.at(i)--; ip.at(p.at(i)) = i; } vector<int> res; if (!solve(0, res, n, p, ip)) cout << -1 << endl; else for (auto v : res) cout << v << endl; }
/// ~~~~~Bismillah'hir Rah'manir Rahim~~~~~ /// /* " Allah(SWT) blesses with knowledge whom he wants. " */ /* " Indeed with Hardship, comes Ease. " */ #include<bits/stdc++.h> using namespace std ; #define Fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ULL unsigned long long #define LL long long #define ST string #define F first #define S second #define PB push_back #define MP make_pair #define pi acos(-1.0) ///for Unordered map /* mpp.max_load_factor(0.25); mpp.reserve(1024); */ /* cout << fixed << setprecision(12);*/ int main () { int t, n, i, j, x, y, sum=0 ; //double p, q ; //char c ; string s, s1, s2 ; //cin>>t ; //while(t--) //{ cin>>n ; int a[n+5] , b[n+5] , c[n+5] ; //} for(i=1; i<=n; i++) { cin>>a[i] ; if(a[i]>10) sum+=(a[i]-10) ; } cout<<sum ; return 0 ; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <utility> #include <tuple> #include <cmath> #include <numeric> #include <set> #include <map> #include <array> #include <complex> #include <iomanip> #include <cassert> #include <random> #include <chrono> using ll = long long; using std::cin; using std::cout; using std::endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int inf = (int)1e9 + 7; const long long INF = 1LL << 60; void solve() { int n; cin >> n; std::vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } ll res = INF; for (int S = 0; S < (1 << n); ++S) { if(~S >> (n - 1) & 1) continue; int XOR = 0; int OR = 0; for (int i = 0; i < n; ++i) { OR |= a[i]; if(S >> i & 1) { XOR ^= OR; OR = 0; } } chmin(res, (ll)XOR); } cout << res << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int kkt = 1; //cin >> kkt; while(kkt--) { solve(); } return 0; }
//switch between terminal and editor: ctrl + ` #include"bits/stdc++.h" #define endl '\n' using namespace std; typedef long long ll; // #define comparator_datatype pair<int,pair<ll,ll>> #define loop(i,x,n,u) for(ll i = x;i < n;i+=u) #define rloop(i,x,n,u) for(ll i = x;i > n;i-=u) #define mod 1000000007 #define read(X,n) loop(i,0,n,1){cin>>X[i];} void compressArray(vector<ll>& array){ map<ll,int> rank_; for(auto& i:array){ rank_[i] = 1; } int r = 1; for(auto& i:rank_){ i.second = r++; } loop(i,0,array.size(),1){ array[i] = rank_[array[i]]; } } //void solve(){} int main(){ std::ios::sync_with_stdio(false); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; //cin>>t; while(t--){ //solve(); int n,type; cin>>n; vector<pair<double,double>> arr(n); loop(i,0,n,1){ cin>>type>>arr[i].first>>arr[i].second; if(type==2) arr[i].second-=0.1; else if(type==3) arr[i].first+=0.1; else if(type==4){ arr[i].first+=0.1,arr[i].second-=0.1; } } // for(auto& i:arr) // cout<<i.first<<" "<<i.second<<endl; ll count = 0; loop(i,0,n,1){ loop(j,i+1,n,1){ if((arr[i].second < arr[j].first) || (arr[i].first > arr[j].second)) continue; else{ count++; // cout<<arr[i].first<<":"<<arr[i].second<<" "<<arr[j].first<<":"<<arr[j].second<<endl; } } } cout<<count<<endl; } return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cmath> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <vector> //#define ENVIRONMENT_LINKED_BOOST #ifdef ENVIRONMENT_LINKED_BOOST #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/multiprecision/cpp_int.hpp> using namespace boost::multiprecision; #endif using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; #define REP(i, a, b) for (int i = a; i < b; ++i) #define ALL(v) v.begin(), v.end() template <typename A, typename B> void chmin(A &a, const B &b) { a = min(a, static_cast<A>(b)); }; template <typename A, typename B> void chmax(A &a, const B &b) { a = max(a, static_cast<A>(b)); }; ll solve(const vector<pair<ll, ll>> &V, multiset<ll> S) { ll ans = 0; REP(i, 0, V.size()) { auto it = S.lower_bound(V[i].second); if (it == S.end()) continue; ans += V[i].first; S.erase(it); } return ans; } int main() { ll N, M, Q; cin >> N >> M >> Q; vector<pair<ll, ll>> V(N); REP(i, 0, N) { cin >> V[i].second >> V[i].first; } sort(V.begin(), V.end(), greater<pair<ll, ll>>()); vector<ll> s(M); REP(i, 0, M) cin >> s[i]; REP(q, 0, Q) { ll l, r; cin >> l >> r; --l; --r; multiset<ll> S; REP(i, 0, l) S.insert(s[i]); REP(i, r + 1, M) S.insert(s[i]); cout << solve(V, S) << endl; } return 0; }
#include <bits/stdc++.h> #define For(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define rFor(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i) #define rep(i, n) For((i), 0, (n)) #define rrep(i, n) rFor((i), (n), 0) #define fi first #define se second using namespace std; typedef long long lint; typedef unsigned long long ulint; typedef pair<int, int> pii; typedef pair<lint, lint> pll; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <class T> T div_floor(T a, T b) { if (b < 0) a *= -1, b *= -1; return a >= 0 ? a / b : (a + 1) / b - 1; } template <class T> T div_ceil(T a, T b) { if (b < 0) a *= -1, b *= -1; return a > 0 ? (a - 1) / b + 1 : a / b; } template <typename T> struct coord_comp { vector<T> v; bool sorted = false; coord_comp() {} int size() { return v.size(); } void add(T x) { v.push_back(x); } void build() { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); sorted = true; } int get_idx(T x) { assert(sorted); return lower_bound(v.begin(), v.end(), x) - v.begin(); } T &operator[](int i) { return v[i]; } }; constexpr lint mod = 1000000007; constexpr lint INF = mod * mod; constexpr int MAX = 100010; int main() { lint a, b, c, d; scanf("%lld%lld%lld%lld", &a, &b, &c, &d); printf("%lld\n", c * d - b > 0 ? div_ceil(a, c * d - b) : -1); }
#include <bits/stdc++.h> #define index(i, n) for (long long i = 0; i < n; i++) #define index1(i, n) for (long long i = 1; i <= n; i++) #define range(i, a, b) for (long long i = a; i < b; i++) #define indexD(i, n) for (long long i = n - 1; i >= 0; i--) #define index1D(i, n) for (long long i = n; i >= 1; i--) #define rangeD(i, a, b) for (long long i = a - 1; i >= b; i--) #define ceild(a, b) ((a) / (b) + ((a) % (b) != 0)) #define fast_io std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define print(x) cout << (x) << '\n' #define trace(x) cout << '>' << #x << ':' << x << endl; #define trace2(x, y) cout << '>' << #x << ':' << x << " | " << #y << ':' << y << endl; #define trace3(x, y, z) cout << '>' << #x << ':' << x << " | " << #y << ':' << y << " | " << #z << ':' << z << endl; #define trace4(x, y, z, w) cout << '>' << #x << ':' << x << " | " << #y << ':' << y << " | " << #z << ':' << z << " | " << #w << ':' << w << endl; #define all(v) (v).begin(), (v).end() #define pb push_back #define mp make_pair #define First first #define Second second #define MOD 998244353 #define INF (9223372034707292159ll) typedef unsigned long long ull; typedef long long int ll; using namespace std; int main() { fast_io; ll t, n, m, k, x, y, r, ans, c; cin >> n; ll arr[n]; index(i, n) cin >> arr[i]; sort(arr, arr + n); ll pre = 0; ans = 0; index(i, n) { ans = (ans + ((pre + arr[i]) % MOD) * (arr[i]) % MOD) % MOD; pre = (pre * 2) % MOD; pre = (pre + arr[i]) % MOD; } print(ans); return 0; }
#include <bits/stdc++.h> /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; */ #define pii pair<int,int> #define fi first #define pb push_back #define si second #define int long long #define mod 1000000007 //998244353 #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define double long double #define all(o) o.begin(),o.end() /* #define T pair<int, int> #define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> */ using namespace std; int power(int x, int y) { int res = 1LL; x = x % mod; while (y > 0) { if (y & 1) res = (res*x) % mod; y = y>>1; // y = y/2 x = (x*x) % mod; } return res%mod; } int inv(int n) { return power(n,mod-2)%mod; } int isprime(int n){ if(n<2)return 0; int i; for(i=2;i*i<=n;i++) if(n%i==0) return 0; return 1; } void files(){ // For getting input from input.txt file freopen("input.txt", "r", stdin); // Printing the Output to output.txt file freopen("output.txt", "w", stdout); } int egcd(int a,int b,int &x ,int & y){ if(b==0){ x=1;y=0; return a; } int x1,y1; int g=egcd(b,a%b,x1,y1); x=y1; y=x1-(a/b)*y1; return g; } const int N=2e6; //https://codeforces.com/blog/entry/22747 int a[500005],n,k; void solve(){ cin>>n>>k; int i; for(i=1;i<=n;i++){ int x; cin>>x; a[x]++; } a[0]=min(a[0],k); for(i=1;i<n;i++) a[i]=min(a[i],a[i-1]); // for(i=0;i<n;i++) // cout<<i<<" : "<<a[i]<<"\n"; int ans=0; for(i=n-1;i>=0;i--){ ans+=(a[i]-a[i+1])*(i+1); } cout<<ans<<"\n"; } int32_t main(){ fast int t=1; // cin>>t; while(t--) { solve(); } }
#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>; template <class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; } template <class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; } const int MAX = 300005; int main() { int n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; vector<ll> cnt(MAX); rep(i, n) cnt[a[i]]++; chmin(cnt[0], k); rep(i, MAX - 1) { chmin(cnt[i + 1], cnt[i]); } ll ans = 0; rep(i, MAX) ans += cnt[i]; cout << ans << endl; }
#include <bits/stdc++.h> #include <iostream> //#include <algorithm> // #include <iomanip> #define ll long long #define map unordered_map #define set unordered_set #define l_l pair<ll, ll> #define P pair<ll, ll> #define vll vector<ll> #define mll map<ll, ll> #define mp make_pair #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i) // template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } // template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } using namespace std; const ll MOD = 1000000007LL; const ll INF = (1LL << 60LL); // template <class T> void plus_mod(T &a, const T &b) {a = (a + b) % MOD;} // if (e > o) { // cout << ("Even") << endl; // } else if (e < o) { // cout << ("Odd") << endl; // } else { // cout << ("Same") << endl; // } int main() { // std::cout << std::fixed << std::setprecision(10); // ll ans = 0; // // cout << ans << endl; ll T; scanf("%lld", &T); for (ll i = 0; i < T; i++) { ll v; scanf("%lld", &v); if (v % 4 == 0) { cout << ("Even") << endl; } else if (v % 2 == 0) { cout << ("Same") << endl; } else { cout << ("Odd") << endl; } } }
//#pragma GCC target("avx2") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") //#pragma warning(disable : 4996) // ////#define ATCODER //#ifdef ATCODER //#include<atcoder/all> //using namespace atcoder; //#endif #include <algorithm> #include <utility> #include <vector> #include <limits.h> #include <math.h> #include <time.h> #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <cassert> #include <numeric> #include <type_traits> using namespace std; #ifdef _MSC_VER #include"stdafx.h" #include <intrin.h> #define __builtin_popcount __popcnt #define __builtin_popcountll __popcnt64 void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << (H); debug_out(T...); } #define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define DEBUG(...) 42 #endif #define ll long long #define REP(i, n) for (ll i = 0; i < (n); ++i) #define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i) #define FOR(i, m, n) for (ll i = (m); i < (n); ++i) #define VSORT(v) sort(v.begin(), v.end()); #define VREVERSE(v) reverse(v.begin(), v.end()) #define print(x) cout << (x) << '\n' #define spa <<" "<< #define lb(v, n) lower_bound(v.begin(), v.end(), (n)) #define ub(v, n) upper_bound(v.begin(), v.end(), (n)) #define int long long //#define double long double #define all(x) (x).begin(), (x).end() #define print_space(v) REP(i, v.size()) cout << v[i] << " \n"[i==(int)v.size()-1] template <typename T1, typename T2> inline bool chmin(T1 & a, T2 b) { if (a > b) { a = b; return true; }return false; } template <typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return true; }return false; } typedef pair<int, int> pii; typedef pair<long long, long long> pll; std::random_device rd; std::mt19937 mt(rd()); constexpr ll MOD = 1e9 + 7; constexpr int MAX = 400040; const double pi = acos(-1); constexpr long double EPS = 1e-14; const int dx[4] = { 0,0,-1,1 }, dy[4] = { -1,1,0,0 }; using ld = long double; void solve() { int N; cin >> N; REP(i, N) { cout << (i * 2 + 1)%N + 1 << " " << (i * 2 + 2)%N + 1 << endl; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); //int q; cin >> q; //while (q--) solve(); }
#include <iostream> using namespace std; int a, b; void swap(int &a, int &b) { if (a > b) { int temp = a; a = b; b = temp; } } void solve() { cin >> a >> b; swap(a, b); int diff = b - a; if(diff >= 3) cout << "No" <<endl; else cout << "Yes" << endl; } int main() { ios_base::sync_with_stdio(0); solve(); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(ll i=0;i<ll(n);i++) int main(){ int X,Y; cin>>X>>Y; if(X>Y){ if((X-Y)<3){ cout<<"Yes"; } else{ cout<<"No"; } } else{ if((Y-X)<3){ cout<<"Yes"; } else{ cout<<"No"; } } return 0; }
//@formatter:off #include<bits/stdc++.h> #define overload4(_1,_2,_3,_4,name,...) name #define rep1(i,n) for (ll i = 0; i < ll(n); ++i) #define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i) #define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d) #define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__) #define rrep(i,n) for (ll i = ll(n)-1; i >= 0; i--) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define popcount(x) __builtin_popcount(x) #define pb push_back #define eb emplace_back #ifdef __LOCAL #define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; } #else #define debug(...) void(0) #endif #define INT(...) int __VA_ARGS__;scan(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__) #define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__) using namespace std; using ll = long long; using ld = long double; using P = pair<int,int>; using LP = pair<ll,ll>; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vs = vector<string>; using vc = vector<char>; using vvc = vector<vector<char>>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vp = vector<P>; using vvp = vector<vector<P>>; template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; } template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; } template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; } template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; } template<class T> void vecout(const vector<T> &v,char div='\n') { rep(i,v.size()) cout<<v[i]<<(i==int(v.size()-1)?'\n':div);} 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;} void scan(){} template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); } template<class T> void print(const T& t){ cout << t << '\n'; } template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); } template<class... T> void fin(const T&... a) { print(a...); exit(0); } const string yes[] = {"no","yes"}; const string Yes[] = {"No","Yes"}; const string YES[] = {"NO","YES"}; const int inf = 1001001001; const ll linf = 1001001001001001001; //@formatter:on int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); INT(n); vvi G(n); rep(i, 1, n) { INT(p); p--; G[p].pb(i); } auto dfs = [&](auto &self, int u) -> P { vi ev, od; int st = 1; for (int v : G[u]) { auto[sc, t] = self(self, v); if (t) od.pb(-sc); else ev.pb(-sc); st += t; } sort(all(ev)); sort(all(od)); int res = 1; while (ev.size() and ev.back() >= 0) { res -= ev.back(); ev.pop_back(); } int t = -1; while (od.size()) { res += od.back() * t; od.pop_back(); t *= -1; } for (int i : ev) res += i * t; return {res, st & 1}; }; auto[ans, _] = dfs(dfs, 0); ans += n; assert(ans % 2 == 0); ans /= 2; print(ans); }
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define pb push_back #define F first #define S second #define um map <ll,ll> #define rep(i,z,n) for(int i=z;i<n;i++) #define repi(i,z,n) for(int i=z;i<=n;i++) #define repn(i,z,n) for(int i=n-1;i>=z;i--) #define vec vector<ll> #define vecp vector<pair<ll,ll>> // #define pi (double)3.14159265358979323846 #define ld long double #define all(z) z.begin(),z.end() #define pii pair<ll,ll> ll power(ll a, ll b, ll m) { ll ans = 1; a = a % m; if (a == 0) return 0; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; } ll modInverse(ll a, ll m) {return power(a, m - 2, m);} ll binpow(ll a, ll b) {ll res = 1; while (b > 0) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;} ll binlog2(ll n) {ll logValue = -1; while (n) {logValue++; n >>= 1;} return logValue;} ll ceil(ll t1, ll t2) {ll ans = (t1 + t2 - 1) / t2; return ans;} void print(vec a) {rep(i, 0, a.size())cout << a[i] << " "; cout << endl;} const ll mod = 1e9 + 7; const ll N = 30 + 5; const ll inf = 2e18; void solve() { vec a(3); rep(i, 0, 3) cin >> a[i]; sort(all(a)); if (a[1] - a[0] == a[2] - a[1]) cout << "Yes" << endl; else cout << "No" << endl; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif speed; int test = 1; // init(); // cin >> test; // ll t1 = 1; while (test--) { // cout << "Case #" << t1 << ": "; solve(); // t1++; } return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,x,y) for(int i=(int)(x);i<(int)(y);i++) #define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl; #define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);} const long mod=1e9+7; const int siz=1e5; const int inf=1e9; int main(){ string s; cin>>s; int n = s.size(); rep(i,0,n){ bool flag = true; rep(j,0,s.size()){ if(s[j] != s[s.size()-1-j]) flag = false; } if(flag){ cout<<"Yes"<<endl; return 0; } s = "0" + s; }cout<<"No"<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define all(x) (x).begin(),(x).end() #define m0(x) memset(x,0,sizeof(x)) int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1}; int main() { ll n; cin>>n; set<ll> s; for (ll a = 2; a <= sqrt(n); a++) { if(s.find(a)!=s.end()) continue; for (ll b = a*a; b<=n; b*=a) { s.insert(b); } } cout<<n-s.size()<<endl; return 0; }
#include<bits/stdc++.h> #define ll long long int #define pll pair<ll,ll> #define vpll vector< pll > #define mpll map<ll,ll> #define MOD 1000000007 #define all(v) v.begin(),v.end() #define s(v) v.size() #define test ll t;cin>>t;while(t--) #define vec vector<ll> #define read0(v,n) for(int i=0;i<n;i++)cin>>v[i]; #define read1(v,n) for(int i=1;i<=n;i++)cin>>v[i]; #define trav(a,x) for (auto& a: x) #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define cut(x) {cout<<x;return 0;} #define print(x) {cout<<x<<nl;continue;} #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORB(i,a,b) for(int i=a;i>=b;i--) #define err1(a) {cout<<#a<<' '<<a<<nl;} #define err2(a,b) {cout<<#a<<' '<<a<<' '<<#b<<' '<<b<<nl;} #define mp make_pair #define pb push_back #define eb emplace_back #define f first #define sc second #define lb lower_bound #define ub upper_bound #define nl '\n' #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> ll gcd(ll a, ll b) { if (b==0)return a; return gcd(b, a % b); } ll lcm(ll a,ll b) { return (a*b)/gcd(a,b); } ll pow(ll a, ll b) { ll ans=1; while(b) { if(b&1) ans=(ans*a)%MOD; b/=2; a=(a*a)%MOD; } return ans; } struct node{ ll x,t,k; }; const int N=1e5+5; vec d(N,(ll)1e18); vec v[N]; vector<node> g[N]; ll dis(ll x,ll y) { ll p=x/y; if(x%y!=0)p++; p*=y; return p; } void solve(ll n,ll u) { multiset<pll> q; d[u]=0; q.insert({0,u}); while(!q.empty()) { pll p=*q.begin(); q.erase(q.begin()); trav(it,g[p.sc]) { ll c=dis(p.f,it.k); if(d[it.x]>c+it.t) { d[it.x]=c+it.t; q.insert({d[it.x],it.x}); } } } } int main() { fast int n,m,x,y; cin>>n>>m>>x>>y; FOR(i,1,m) { ll a,b,c,d; cin>>a>>b>>c>>d; node temp; temp.x=b;temp.t=c;temp.k=d; g[a].pb(temp); node kemp; kemp.x=a;kemp.t=c;kemp.k=d; g[b].pb(kemp); } solve(n,x); if(d[y]==(ll)1e18)cut(-1) //FOR(i,1,n)cout<<d[i]<<' '; cut(d[y]) }
// Problem: E - Train // Contest: AtCoder - AtCoder Beginner Contest 192 // URL: https://atcoder.jp/contests/abc192/tasks/abc192_e // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define ll long long #define mod 1000000007 // templates #define all(v) v.begin(), v.end() #define F first #define S second #define sz(x) (int)x.size() #define po(x, y) fixed << setprecision(y) << x #define ss(s) scanf(" %[^\n]%*c", s) #define sc(n) scanf("%d", &n) #define sl(n) scanf("%lld", &n) #define ps(s) printf("%s\n", s) #define pr(n) printf("%d\n", n) #define pl(n) printf("%lld\n", n) #define prs(n) printf("%d ", n) #define pls(n) printf("%lld ", n) using namespace std; const ll inf = (ll)1e16 + 10; const int N = (int)1e5 + 10; int a[N], b[N]; vector<array<ll, 3>> adj[N]; // u->v,t,k vector<ll> dist(N); ll n, m, x, y; void bfs() { set<array<ll, 2>> s; // time,node s.insert({0, x}); for (int i = 0; i <= n; i++) { dist[i] = inf; } dist[x] = 0; while (sz(s)) { auto temp = *s.begin(); s.erase(s.begin()); ll node = temp[1], kete = temp[0]; for (auto c : adj[node]) { ll add = 0; if (kete < c[2] && kete != 0) { add = (c[2] - kete); } else if (kete != 0) { if (kete % c[2]) { add = c[2] - (kete % c[2]); } } ll curr = c[1] + add + kete; // printf("node-> %lld curr-> %lld\n", node, curr); if (dist[c[0]] > curr) { s.erase({dist[c[0]], c[0]}); dist[c[0]] = curr; s.insert({curr, c[0]}); } } } if (dist[y] == inf) { dist[y] = -1; } pl(dist[y]); } void solve() { sl(n), sl(m), sl(x), sl(y); for (int i = 1; i <= m; i++) { ll u, v, t, k; sl(u), sl(v), sl(t), sl(k); adj[u].push_back({v, t, k}); adj[v].push_back({u, t, k}); } bfs(); } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int t = 1; // sc(t); while (t--) { solve(); } // cerr << (float)clock() / CLOCKS_PER_SEC * 1000 << " ms" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++) #define INF 10000000000 #define MOD 1000000007 using ll = long long; using pint = pair<int,int>; using pll = pair<ll,ll>; using Graph = vector<vector<int>>; int main(){ //input part //0 index int N,M; cin>>N>>M; Graph G(N); rep(i,M){ int a,b; cin>>a>>b; G[a-1].push_back(b-1); G[b-1].push_back(a-1); } int K; cin>>K; vector<int> C(K); rep(i,K){ cin>>C[i]; C[i]--; } //BFS part auto BFS = [&](int s){ vector<ll> dist(N,INF); dist[s] = 0; queue<int> Q; Q.push(s); while(!Q.empty()){ int now = Q.front(); Q.pop(); for(auto next: G[now]){ if(dist[next]!=INF)continue; dist[next] = dist[now]+1; Q.push(next); } } vector<ll> res(K,INF); rep(i,K)res[i] = dist[C[i]]; return res; }; //bit dp part vector<vector<ll>> dist(K); rep(i,K) dist[i] = BFS(C[i]); vector<vector<ll>> dp(1<<K, vector<ll> (K,INF)); //init rep(i,K)dp[1<<i][i] = 1; for(int bit = 0; bit < (1<<K); bit++){ rep(i,K){ if(bit & 1<<i){ int bit2 = bit ^ 1<<i; rep(j,K){ if(bit2 & 1<<j){ dp[bit][i] = min(dp[bit][i],dp[bit2][j]+dist[i][j]); } } } } } ll res = *min_element(dp.back().begin(),dp.back().end()); if(res>=INF) res = -1; cout<<res<<endl; }
#include <iostream> #include <cmath> #include <string> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <tuple> #include <utility> #include <functional> #include <set> #include <map> #include <bitset> #include <list> #include<iomanip> using namespace std; using ll = long long; using ULL = unsigned long long; using pll = std::pair<ll, ll>; using vi = std::vector<int>; using vl = std::vector<ll>; using vb = std::vector<bool>; using db = double; using vdb = std::vector<db>; using qlg= std::priority_queue<ll, vl, std::greater<ll> > ; //ascending using qll= std::priority_queue<ll, vl, std::less<ll> > ; // descending using qdg= std::priority_queue<db, vdb, std::greater<db> > ; //ascending using qdl= std::priority_queue<db, vdb, std::less<db> > ; // descending template<class T> using vv = std::vector<std::vector<T> >; #define REPL(i, n) for (ll i = 0; i < (ll)(n); i++) #define FORL(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) #define REP(i, n) FORL(i, 0, n) #define MREP(i, n) for (ll i= (ll)(n)-1; i>=0; i-- ) #define MFOR(i, a, b) for (ll i = (ll)(b)-1; i >= (ll)(a); i--) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define rreps(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define bit(n) (1LL << (n)) #define INF pow(10, 10) void do_swap(vl &swaps, ll &Times, vector<bool> &Is_swaped, ll pos, vl &diffs, queue<ll> &Plus) { swaps[Times ++] = pos+1; Is_swaped[pos] = true; swap(diffs[pos], diffs[pos+1]); diffs[pos] ++; diffs[pos+1] --; if(diffs[pos+1] > 0) Plus.push(pos+1); } int main(void) { ll Sc, P, N, M, Q, A, B, C, D, K; cin >> N; queue<ll> Plus; vl diffs(N); bool resres = true; REP(i, N) { cin >> diffs[i]; diffs[i] = diffs[i]-i-1; if(diffs[i] > 0) { Plus.push(i); } else if(diffs[i]==0) { resres = false; } } if(resres==false) { cout << -1 << endl; return 0; } REP(i, N-1) { if(diffs[i]>0 && diffs[i+1] >0 && diffs[i] > diffs[i+1]) { cout << -1 << endl; return 0; } else if(diffs[i]<0 && diffs[i+1] <0 && diffs[i] > diffs[i+1]) { cout << -1 << endl; return 0; } } vl swaps(N); ll Times = 0; vector<bool> Is_swaped(N-1, false); vl Move_Afts(N, -1); bool res_moved = true; while(!Plus.empty() ) { ll pos; pos = Plus.front(); Plus.pop(); if(Is_swaped[pos] == true || diffs[pos+1]==0) { break; } else if(diffs[pos+1]<0) { do_swap(swaps, Times, Is_swaped, pos, diffs, Plus); /* swaps[Times ++] = pos+1; Is_swaped[pos] = true; swap(diffs[pos], diffs[pos+1]); diffs[pos] ++; diffs[pos+1] --; if(diffs[pos+1] > 0) Plus.push(pos+1); */ ll aft = Move_Afts[pos]; while(aft >= 0 && diffs[aft+1]<0) { do_swap(swaps, Times, Is_swaped, aft, diffs, Plus); aft = Move_Afts[aft]; } } else { Move_Afts[pos+1] = pos; } } if(Times == N-1) { // cout << Times << " "; REP(i, Times) { cout << swaps[i] << endl; } } else { cout << -1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using P = pair<int, int>; int main(){ ll a,b,c; cin>>a>>b>>c; ll mod = 998244353; a = (a-1+1)*(1+a) / 2; a %= mod; b = (b - 1 + 1) * (1 + b) / 2; b %= mod; c = (c - 1 + 1) * (1 + c) / 2; c %= mod; ll ans = (((a*b)%mod)*c)%mod; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { int X,Y,Z; cin >>X>>Y>>Z; cout<<(Y*Z-1)/X<<endl; }
#include <bits/stdc++.h> using namespace std; #define INF 1e18 typedef pair<long long, int> iPair; const int maxN = 1e5; vector<pair<int,pair<int,int> > > adj[maxN]; void shortestPath(int n, int src,int dest) { priority_queue< iPair, vector <iPair> , greater<iPair> > pq; vector<long long> dist(n, INF); pq.push(make_pair(0, src)); dist[src] = 0; while (!pq.empty()) { int u = pq.top().second; pq.pop(); if(u == dest) { cout<<dist[dest]<<endl; return; } for (auto pr:adj[u]) { int v = pr.first; long long t = pr.second.first; long long k = pr.second.second; long long curr_dist = ((dist[u] + k-1)/k)*k; if (dist[v] > curr_dist + t) { dist[v] = curr_dist + t; pq.push(make_pair(dist[v], v)); } } } cout<<-1<<endl; } int main() { int n,m,x,y; cin>>n>>m>>x>>y; x--,y--; int u,v; int t,k; while(m--) { cin>>u>>v>>t>>k; u--,v--; adj[u].push_back({v,{t,k}}); adj[v].push_back({u,{t,k}}); } shortestPath(n,x,y); return 0; }
// Author: HarshKumar #include <bits/stdc++.h> using namespace std; #define ll int64_t const ll N = 1e6 + 6, M = 1e9 + 7; const ll INF = (1LL << 62) - 1; vector<vector<tuple<ll, ll, ll>>> G; vector<ll> dijkstra(ll v) { vector<ll> ans(G.size(), INF), vis(G.size()); ans[v] = 0; priority_queue<pair<ll, ll>> que; que.push({0, v}); while (!que.empty()) { auto [x, u] = que.top(); que.pop(); if (vis[u]) continue; vis[u] = 1; for (auto [v, w, d] : G[u]) { ll x = max(0LL, llround(ceil(sqrtl(d))) - ans[u] - 1); w += ans[u] + x + d / (x + ans[u] + 1); if (w < ans[v]) ans[v] = w, que.push({-ans[v], v}); } } return ans; } int main() { ios::sync_with_stdio(false), cin.tie(nullptr); ll n, m; cin >> n >> m; G.resize(n); while (m--) { ll a, b, c, d; cin >> a >> b >> c >> d; a--; b--; G[a].push_back({b, c, d}); G[b].push_back({a, c, d}); } auto d = dijkstra(0); if (d.back() < INF) cout << d.back(); else cout << -1; }
#include <bits/stdc++.h> using namespace std; #define int long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define fs first #define sc second #define MP make_pair #define pb push_back #define sz(x) (int)x.size() #define sqr(x) ((x) * (x)) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 51; vector<int> primes; int cnt[N], d[N]; void init() { for (int i = 2; i < N; i++) { if (d[i] == 0) { d[i] = i; primes.push_back(i); } for (int x : primes) { if (x > d[i] || x * i >= N) break; d[x * i] = x; } } } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #ifdef FLameDragon freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif int n; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; cnt[x] += 1; } const int INF = 1e18; int ans = INF; init(); for (int mask = 0; (mask < (1 << sz(primes))); mask++) { int curAns = 1; for (int bit = 0; bit < sz(primes); bit++) { if ((mask >> bit) & 1) { curAns *= primes[bit]; } } bool ok = 1; for (int i = 2; i < N; i++) { if (cnt[i] && __gcd(curAns, i) == 1) { ok = false; break; } } if (ok) { ans = min(ans, curAns); } } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; #define repr(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; typedef pair<ll,ll> P; #define mod 1000000007 ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} ll lcm(ll x,ll y) {return x/gcd(x,y)*y;} int main(){ ll n; cin >> n; vector<ll> a(405,0); rep(i,n){ ll x; cin >> x; a[x+200]++; } ll ans=0; for(ll i=0;i<=400;i++){ if(a[i]==0) continue; for(ll j=i+1;j<=400;j++){ ll now=(j-i)*(j-i); ans+=now*a[i]*a[j]; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define all(v) v.begin(), v.end() void chmax(ll &x, ll y) {x = max(x,y);} void chmin(ll &x, ll y) {x = min(x,y);} void Yes() {cout << "Yes" << endl; exit(0);} void No() {cout << "No" << endl; exit(0);} template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);} template<class in_vec_cout> void vec_cout(vector<in_vec_cout> vec) { for (in_vec_cout res : vec) {cout << res << " ";} cout << endl; } const ll inf = 1e18; const ll mod = 1e9 + 7; struct xyz{ll y, z;}; ll popcount(ll bit, ll N) { ll res = 0; rep(i,N) if ((bit>>i)&1) res++; return res; } int main() { ll N, M; cin >> N >> M; vector<vector<ll>> A(N,vector<ll>(N,inf)); rep(i,M) { ll x, y, z; cin >> x >> y >> z; x--; y--; chmin(A[x][y],z); } vector<vector<ll>> dp(N+1,vector<ll>(1<<N)); dp[0][0] = 1LL; rep(i,N) { rep(bit,1<<N) { ll cnt = popcount(bit,N); if (cnt!=i) continue; rep(j,N) { if ((bit>>j)&1) continue; ll nbit = bit | (1<<j); ll ncnt = 0; bool NG = false; rep(k,N) { if ((nbit>>k)&1) ncnt++; if (ncnt>A[i][k]) { NG = true; break; } } if (NG) continue; dp[i+1][nbit] += dp[i][bit]; } } } ll ans = dp[N][(1<<N)-1]; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; //int:2*10**9 typedef long double ld; typedef pair<ll,ll> P; #define REP(i,n) for(ll i = 0; i<(ll)(n); i++) #define FOR(i,a,b) for(ll i=(a);i<=(b);i++) #define FORD(i,a,b) for(ll i=(a);i>=(b);i--) #define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k)) #define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l))) #define pb push_back #define MOD 1000000007 //998244353 #define PI 3.141592653 #define INF 100000000000000 //14 //cin.tie(0);cout.tie(0);ios::sync_with_stdio(false); ll powe(ll a, ll b, ll mod){//aのb乗のmod ll ret = 1; while(0 < b){ if((b%2) == 0){ a = (a*a)%mod; b >>= 1; } else{ ret = (ret*a)%mod; b--; } } return ret; } int main(){ ll a, b, c; cin >> a >> b >> c; a%=10; if (a==0) { cout << 0 << endl; return 0; } vector<vector<ll>> k(10); REP(i,10) k[i].pb(i); REP(i,10) { ll val = (i*i)%10; while (val!=k[i][0]) { k[i].pb(val); val = (val*i)%10; } } ll cnt = k[a].size(); ll divd = powe(b,c,cnt); // cout << cnt << " " << divd << " " << a << endl; if (divd!=0) cout << k[a][divd-1] << endl; else cout << k[a][k[a].size()-1] << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,N) for(int i = 0;i < N;++i) #define rep1(i,N) for(int i = 1;i < N;++i) #define co(x) cout << x << endl #define cosp(x) cout << x << " " #define INF 1e18 using ll = long long; using ull = unsigned long long; int main(){ int N; cin >> N; vector<int>A(N); int a,j = 0; rep(i,N){ cin >> a; A[a-1]++; } rep(i,N){ if(A[i] != 1) j++; } if(j == 0) co("Yes"); else co("No"); }
//{{ /* * Created at: 06/27/21 18:02:59 * * FB: https://facebook.com/tgbaodeeptry * From Viet Nam with Love :D * */ #include <bits/stdc++.h> using namespace std; #define fast_io() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define REP(i, a, b) for (int i = int(a); i < int(b); ++i) #define RED(i, a, b) for (int i = int(a); i > int(b); --i) #define FOR(i, a, b) for (int i = int(a); i <= int(b); ++i) #define FOD(i, a, b) for (int i = int(a); i >= int(b); --i) #define sz(x) ((int)x.size()) #define allong(x) (x).begin(), (x).end() #define f first #define s second #define eb emplace_back #define pb push_back #define endl '\n' using llong = long long; using veci = vector<int>; using vecveci = vector<vector<int>>; using pairii = pair<int, int>; const int MOD = 1e9 + 7; const int MAXN = 1e5; const int INF = INT_MAX; template <class T> void re(T& x) { cin >> x; }; template <class T> void re(vector<T>& v, int n) { for (int i = 0; i < n; ++i) cin >> v[i]; }; template <class T> void re(vector<T>& v, int f, int t) { FOR(i, f, t) cin >> v[i]; }; template <class T> void re(T v[], int n) { FOR(i, 0, n - 1) cin >> v[i]; }; template <class T> void re(T* v, int f, int t) { FOR(i, f, t) cin >> v[i]; }; template <class H, class... T> void re(H& v, T&... args) { re(v); re(args...); }; void dbg_out() { cerr << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } template <typename T> void dbg_out(vector<T>& a) { for (auto c : a) cerr << ' ' << c; cerr << endl; }; template <typename T> void dbg_out(vector<T>& a, int n) { FOR(i, 0, n - 1) cerr << ' ' << a[i]; cerr << endl; }; template <typename T> void dbg_out(vector<T>& a, int u, int v) { FOR(i, u, v) cerr << ' ' << a[i]; cerr << endl; }; template <typename T> void dbg_out(T a[]) { for (auto c : a) cerr << ' ' << c; cerr << endl; }; template <typename T> void dbg_out(T a[], int n) { FOR(i, 0, n - 1) cerr << ' ' << a[i]; cerr << endl; }; template <typename T> void dbg_out(T a[], int u, int v) { FOR(i, u, v) cerr << ' ' << a[i]; cerr << endl; }; #if defined(_CRUN) || defined(_RUN) #define pd(...) \ cerr << "(L:" << __LINE__ << "): " \ << "[" << #__VA_ARGS__ << "] =", \ dbg_out(__VA_ARGS__) #else #define pd(...) #endif #if defined(_CRUN) #define c_input() freopen("input", "r", stdin) #define c_output() freopen("output", "r", stdin) #else #define c_input() #define c_output() #endif void ps(){}; template <typename Head, typename... Tail> void ps(Head H, Tail... T) { cout << H; ps(T...); }; template <typename T> void ps(vector<T>& a, int n) { FOR(i, 0, n - 1) cout << a[i] << ' '; }; template <typename T> void ps(T a[], int n) { FOR(i, 0, n - 1) cout << a[i] << ' '; }; int add_mod(int a, int b) { return ((a % MOD) + (b % MOD)) % MOD; } int sub_mod(int a, int b) { return ((a % MOD) - (b % MOD) + MOD) % MOD; } int mul_mod(int a, int b) { return ((llong) (a % MOD) * (b % MOD)) % MOD; } llong pow_mod(llong a, llong b) { llong ans = 1; while (b) { if (b & 1) ans = mul_mod(ans, a); a = mul_mod(a, a); b >>= 1; }; return ans; }; llong lcm(llong a, llong b) { return a * b / __gcd(a, b); } llong pow(llong a, llong b) { llong ans = 1; while (b) { if (b & 1) ans *= a; a *= a; b >>= 1; }; return ans; }; void solve(); void init(); bool multi_test = false; // ---- main below ----- /// int main() { fast_io(); init(); int T = 1; if (multi_test) re(T); FOR(i, 1, T) solve(); } //}} void init() { // multi_test = true; } void solve() { llong n; int k; re(n, k); while (k--) { if (n % 200) { n = n * 1000 + 200; } else { n /= 200; } } ps(n); }
#define _USE_MATH_DEFINES #include<iostream> #include<iomanip> #include<vector> #include<string> #include<algorithm> #include<cmath> #include<stack> #include<queue> #include<set> #include<map> #include<climits> #include<bitset> #include<unordered_map> #include<unordered_set> #include<random> #include<list> #include<functional> using namespace std; #define MAX(A,B) ((A)>(B)?(A):(B)) #define MIN(A,B) ((A)<(B)?(A):(B)) #define LP(I,S,G) for (long long int I = S; I < G; I++) #define IN(X) for (int i = 0; i < X.size(); i++)cin >> X[i] #define OUT(X) for (int i = 0; i < X.size(); i++)cout << X[i]<<" " #define SORT(X) sort(X.begin(), X.end()) #define CSORT(X,Y) sort(X.begin(), X.end(),Y) #define COPY(X,Y) copy(X.begin(), X.end(), Y.begin()) #define ALL(X,Y) for (auto X = Y.begin(); X != Y.end(); X++) #define FULL(a) (a).begin(),(a).end() template<class I1, class I2> istream& operator>>(istream& s, pair<I1, I2>& in) { s >> in.first >> in.second; return s; } long long int M = pow(10, 9) + 7; uint64_t combinations2(uint64_t n, uint64_t k) { uint64_t r = 1; for (uint64_t d = 1; d <= k; ++d) { r *= n--; r /= d; } return r; } struct HashPair { //注意 constがいる template<class T1, class T2> size_t operator()(const pair<T1, T2> &p) const { //first分をハッシュ化する auto hash1 = hash<T1>{}(p.first); //second分をハッシュ化する auto hash2 = hash<T2>{}(p.second); //重複しないようにハッシュ処理 size_t seed = 0; seed ^= hash1 + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= hash2 + 0x9e3779b9 + (seed << 6) + (seed >> 2); return seed; } }; int main(void) { int n; cin >> n; vector<long long int> r, g, b; LP(i, 0, 2*n) { long long int a; char c; cin >> a >> c; switch (c){ case 'R': r.push_back(a); break; case 'G': g.push_back(a); break; case 'B': b.push_back(a); break; default: break; } } vector<long long int> x, y,z; if (r.size() % 2 == 0 && g.size() % 2 == 0 && b.size() % 2 == 0) { cout << 0; return 0; } else if (r.size() % 2 == 0) { x = g, y = b,z = r; } else if (g.size() % 2 == 0) { x = r, y = b, z = g; } else x = r, y = g, z = b; SORT(x); SORT(y); SORT(z); long long int min = LLONG_MAX; ALL(i, x) { auto key = lower_bound(FULL(y), *i); if(key!=y.end())min = MIN(min, abs(*key - *i)); if (key != y.begin()) { min = MIN(min, abs(*i - *(key - 1))); } } if (z.size() != 0) { long long int min_x = LLONG_MAX, min_y = LLONG_MAX; ALL(i, x) { auto key = lower_bound(FULL(z), *i); if (key != z.end())min_x = MIN(min_x, abs(*key - *i)); if (key != z.begin()) { min_x = MIN(min_x, abs(*i - *(key - 1))); } } ALL(i, y) { auto key = lower_bound(FULL(z), *i); if (key != z.end())min_y = MIN(min_y, abs(*key - *i)); if (key != z.begin()) { min_y = MIN(min_y, abs(*i - *(key - 1))); } } min = MIN(min, min_x + min_y); } cout << min; return 0; }
#include<bits/stdc++.h> #define x first #define y second #define pb push_back #define eb emplace_back #define all(a) (a).begin(),(a).end() #define SZ(a) (int)(a).size() #define FOR(i, a, b) for(int i=(a); i<=(b); ++i) #define ROF(i, a, b) for(int i=(a); i>=(b); --i) #define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin()) #define pc(x) putchar(x) #define make_pair MP #define make_tuple MT using namespace std; typedef long long i64; typedef tuple<int,int,int> iii; typedef pair<int,int> pii; typedef pair<long,long> pll; typedef vector<int> vi; typedef vector<vi> vvi; i64 s[2][60]; int dp[60][2][2]; // normal, or reverse void solve(){ i64 A, B; cin >> A >> B; if(A > B){ printf("%lld",A-B); return; } i64 ans = B-A; int bit = 0; do{ A *= 2; bit++; i64 res = 0, res2 = 0; i64 diff = abs(B-A); res += (diff>>bit); res2 = res+1; diff &= ((1ll<<bit)-1); i64 diff2 = (1ll<<bit)-diff; int last = -1; FOR(i, 0, bit){ if(diff&(1ll<<i)){ if(last == -1){ last = i; } }else{ if(last != -1){ res += min(i-last, 2); last = -1; } } } last = -1; FOR(i, 0, bit){ if(diff2&(1ll<<i)){ if(last == -1){ last = i; } }else{ if(last != -1){ res2 += min(i-last, 2); last = -1; } } } //printf("%d %lld %lld\n",bit,res,res2); ans = min(ans, bit+min(res,res2)); }while(A < B); printf("%lld",ans); } int main(){ cin.tie(0)->sync_with_stdio(false); cout.tie(0); solve(); return 0; } /* * * * * * * * * * * */
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; using Graph = vector<vector<int>>; using pint = pair<int, int>; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; const int IINF = 1LL << 29; const long long INF = 1LL << 60; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { cout << setprecision(15) << fixed; int H, W; cin >> H >> W; vector<string> A(H); pint S, G; vector<vector<pint>> rec(26, vector<pint>()); rep(i, H) cin >> A[i]; rep(i, H) { rep(j, W) { char c = A[i][j]; if (c == 'S') S = {i, j}; if (c == 'G') G = {i, j}; if (c >= 'a' && c <= 'z') rec[(c - 'a')].push_back({i, j}); } } queue<pint> que; que.push(S); vector<vector<int>> dist(H, vector<int>(W, -1)); dist[S.first][S.second] = 0; vector<bool> used(26, false); while (!que.empty()) { auto [y, x] = que.front(); que.pop(); if (A[y][x] >= 'a' && A[y][x] <= 'z') { int c = A[y][x] - 'a'; if (!used[c]) { for (auto [ny, nx] : rec[c]) { if (dist[ny][nx] == -1) { que.push({ny, nx}); dist[ny][nx] = dist[y][x] + 1; } } } used[c] = true; } rep(i, 4) { int ny = y + dy[i]; int nx = x + dx[i]; if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue; if (A[ny][nx] == '#') continue; if (dist[ny][nx] == -1) { que.push({ny, nx}); dist[ny][nx] = dist[y][x] + 1; } } } cout << dist[G.first][G.second] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define sz(x) ((int) (x).size()) typedef pair<int, int> pii; typedef double ll; const int maxn = 2000 + 5; template<class T> void print(T & x){ cout << x; } template<class T,class U> void print(pair<T,U> & p){cout << "("; print(p.first); cout << ", "; print(p.second); cout << ")"; } template<class T> void print(vector<T> & v) { cout << "{"; if (sz(v)) print(v[0]); for (int i = 1; i < sz(v); i++) cout << ", ", print(v[i]); cout << "}\n"; } struct Dijkstra { int tot, n, m; struct Node { int nxt, v; ll len; }; Node* edges; int* head; ll* d; Dijkstra(int tn, int tm) { n = tn, m = tm; tot = 0; head = new int[tn+1]; fill(head+1, head+n+1, -1); edges = new Node [tm+1]; d = new ll [tn+1]; fill(d+1, d+n+1, 1e18); } ~Dijkstra() { if (head) { delete [] head; head = NULL; } if (edges) { delete [] edges; edges = NULL; } if (d) { delete [] d; d = NULL; } } void addedge(int x, int y, ll val) { edges[++tot] = {head[x], y, val}; head[x] = tot; } void calc(int s) { priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> Q; vector<bool> done(n+1); d[s] = 0; Q.push({d[s], s}); while(!Q.empty()) { int x = Q.top().second; Q.pop(); if (done[x]) continue; else done[x] = true; for (int i = head[x]; ~i; i = edges[i].nxt) { int v = edges[i].v; ll len = edges[i].len; if (d[v] > d[x] + len) { d[v] = d[x] + len; Q.push({d[v], v}); } } } } }; int n, m; char A[maxn][maxn]; const int dx[] = {-1, 1, 0, 0}; const int dy[] = {0 ,0, 1, -1}; inline int ind(int x, int y) { return x * m + y; } inline int indc(int c) { return (n+1)*(m+1)+c; } vector<pii> dic[26]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; pii st, ed; for (int i = 1;i <= n; ++i) { for (int j = 1;j <= m; ++j) { cin >> A[i][j]; if ('a' <= A[i][j] && A[i][j] <= 'z') dic[A[i][j] - 'a'].push_back({i, j}); if (A[i][j] == 'S') st = {i, j}; if (A[i][j] == 'G') ed = {i, j}; } } Dijkstra dij((n+1)*(m+1)+30, (n+1)*(m+1)*40); for (int i = 1;i <= n; ++i) { for (int j = 1;j <= m; ++j) { if (A[i][j] == '#') continue; for (int k = 0;k < 4; ++k) { int nx = i + dx[k]; int ny = j + dy[k]; if (nx < 1 || nx > n || ny < 1 || ny > m) continue; if (A[nx][ny] == '#') continue; dij.addedge(ind(i, j), ind(nx, ny), 1); } } } for (int c = 0;c < 26; ++c) { for (auto [x, y] : dic[c]) { dij.addedge(ind(x, y), indc(c), 0.5); dij.addedge(indc(c), ind(x,y), 0.5); } } dij.calc(ind(st.first, st.second)); // for (int i = 1;i <= n; ++i) { // for (int j = 1;j <= m; ++j) { // cout << dij.d[ind(i,j)] <<" "; // }cout << endl; // } if (dij.d[ind(ed.first, ed.second)] > 1e9) cout << -1 << endl; else cout << (long long)(dij.d[ind(ed.first, ed.second)] + 0.5) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; void solve() { ll n; cin >> n; ll pw5 = 5; int cnt5 = 1; while (n >= pw5) { ll cur = n - pw5; int cnt = 0; while (cur > 0 && cur % 3 == 0) cur /= 3, cnt++; if (cur == 1 && cnt > 0) { cout << cnt << ' ' << cnt5 << endl; return ; } pw5 *= 5ll; if (pw5 >= 1e18) break; cnt5++; } cout << -1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // int t; cin >> t; // while (t--) solve(); }
#include <iostream> #include <string> using namespace std; int main() { int i, j, n; string S, test; string ZONe = "ZONe"; cin >> S; n = 0; for(i=0; i<9; i++) { test = ""; for(j=i; j<i+4; j++) { test += S[j]; } if(test == ZONe) n++; } cout << n << endl; }
#include "bits/stdc++.h" using namespace std; const int N = 2e5 + 7; vector<int> adj[N]; bool good, vis[N]; long long net; int a[N], b[N]; void dfs(int i) { net += a[i] - b[i]; vis[i] = true; for (int x : adj[i]) if (!vis[x]) dfs(x); } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } good = true; for (int i = 1; i <= n; i++) { if (!vis[i]) net = 0, dfs(i); if (net) { good = false; break; } } if (good) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) struct UnionFind { // 自分の親の頂点を管理する vector<int> par; UnionFind(int n) : par(n, -1) {} // 初期化 // 頂点xの根の頂点を返す int root(int x) { // 再帰構造 // 自分の根は親の根と等しい if (par[x] < 0) return x; else return root(par[x]); } // xとyが同じグループか bool issame(int x, int y) { return root(x) == root(y); } // xとyが辺でつなぐときの処理 bool unite(int x, int y) { // x, y を根まで遡る x = root(x); y = root(y); // 既に同じグループだったらやることはない if (x == y) { return false; } // 異なるグループだったとき if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; int main() { int N, M; cin >> N >> M; // UnionFind 木の作成 UnionFind uf(N); vector<ll> a(N), b(N); rep(i, N) { cin >> a[i]; a[i]--; } rep(i, N) { cin >> b[i]; b[i]--; } rep(i, M) { int c, d; cin >> c >> d; c--, d--; uf.unite(c,d); } // 1ならまだ調べていない頂点 map<ll, ll> ma, mb; rep(i, N) { int r = uf.root(i); ma[r] += a[i]; mb[r] += b[i]; } bool cond = true; rep(i, N) { int r = uf.root(i); if (ma[r] != mb[r]) { cond = false; break; } } if (cond) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include<bits/stdc++.h> using namespace std; long long soma(long long x){ return x*(x+1)/2; } void solve(){ int n; cin >> n; long long res =0 ; for(int i = 0; i < n; ++i){ long long a, b; cin >> a >> b; res += soma(b) - soma(a-1); } cout << res; } int main(){ cin.tie(0)->sync_with_stdio(false); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int t = 1; //cin >> t; while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5+5; int int_min = -2147483648; int int_max = 2147483647; int n; char s1[N], s2[N], s3[N]; void solve() { cin >> n; scanf("%s", s1), scanf("%s", s2), scanf("%s", s3); for(int i = 0; i < n; i++) putchar('1'); for(int i = 0; i < n; i++) putchar('0'); puts("1"); } int main() { int t; cin >> t; while (t--) solve(); return 0; }
#include<bits/stdc++.h> #define f first #define s second #define pb push_back #define M (L+R)/2 #define N 500009 #define inf 99999999999 #define ll long long #define mod 1000000007 #define sz size(); using namespace std; ll n, a, b, ans, sum; int main(){ ios::sync_with_stdio(0); cin>>n; a=1; for(int i=1; i<=100; i++){ a*=3; if(a>=n)break; b=1; for(int j=1; j<=100; j++){ b*=5; if(b>=n)break; if(a+b==n){ cout<<i<<" "<<j<<endl; return 0; } } } cout<<-1<<endl; return 0; }
#include <iostream> #include <string> #include <vector> #include <list> #include <stack> #include <queue> #include <array> #include <algorithm> #include <utility> #include <numeric> #include <functional> #include <cmath> using namespace std; using ll = long long; using ull = unsigned long long; template <class ...Args> void Input(Args &...args) { (cin >> ... >> args); } template <class T> void InputArray(std::size_t size, T &t) { t.resize(size); for (auto &e : t) { cin >> e; } } template <class ...Args> void InputArray(std::size_t size, Args &...args) { (InputArray(size, args), ...); } template <class ...Args> void InputVerticalArray(std::size_t size, Args &...args) { (args.resize(size), ...); for (int i = 0; i < size; i++) { ((cin >> args[i]), ...); } } template <class ...Args> void Output(const Args &...args) { ((cout << args << ' '), ...) << endl; } template <class ...Args> void OutputVertical(const Args &...args) { ((cout << args << endl), ...); } template <class T> void OutputArray(const T &t) { for (const auto &e : t) { cout << e << ' '; } cout << endl; } template <class ...Args> void OutputArray(const Args &...args) { (OutputArray(args), ...); } template <class ...Args> void OutputVerticalArray(const Args &...args) { for (int i = 0; i < min({ args.size()... }); i++) { ((cout << args[i] << ' '), ...) << endl; } } #define inp(type, ...) \ type __VA_ARGS__; \ Input(__VA_ARGS__) #define inpa(type, size, ...) \ type __VA_ARGS__; \ InputArray((size), __VA_ARGS__) #define inpva(type, size, ...) \ type __VA_ARGS__; \ InputVerticalArray((size), __VA_ARGS__) #define otp(...) \ Output(__VA_ARGS__) #define otpv(...) \ OutputVertical(__VA_ARGS__) #define otpa(...) \ OutputArray(__VA_ARGS__) #define otpva(...) \ OutputVerticalArray(__VA_ARGS__) #define rep(counter, range) \ for (int (counter) = 0; (counter) < (range); (counter)++) #define repi(range) \ rep(i, range) #define rrep(counter, range) \ for (int (counter) = (range) - 1; (counter) >= 0; (counter)--) #define rrepi(range) \ rrep(i, range) #define repc(element, container) \ for (auto &(element) : (container)) #define repe(container) \ repc(e, container) #define all(container) \ (begin(container)), (end(container)) #ifdef __CCR__ # define dlog(x) clog << #x " = " << x << endl #else # define dlog(x) #endif ll Pow(ll a, ll b) { ll result = a; while (--b) result *= a; return result; } int main() { inp(ll, n); ll a, b = 1; ll pow5b = 5; while (pow5b < n) { a = log10(n - pow5b) / log10(3.0) + 0.5; if (a > 0 && Pow(3, a) + pow5b == n) { otp(a, b); return 0; } b++; pow5b *= 5; } otp(-1); return 0; }
#include <bits/stdc++.h> #define st first #define nd second #define PQ priority_queue #define MP make_pair using ll = long long ; using namespace std; using pii = pair<int,int>; using pli = pair<ll, int>; using pil = pair<int, ll>; using pll = pair<ll, ll>; const int N = 0; const int MOD = 1e9 + 7; int mult(int x, int y) { return 1LL * x * y % MOD; } int f_pow(int val, int id){ if (id == 0) return 1; if (id == 1) return val; int k = f_pow(val, id >> 1); k = mult(k, k); if(id & 1) { k = mult(k, val); } return k; } int main(){ int n, p; scanf("%d %d", &n, &p); if (p == 2) { return !printf("%d", n == 1 ? 1 : 0); } printf("%d", mult(p - 1, f_pow(p - 2, n - 1))); }
#include <bits/stdc++.h> #define ll long long #define B break #define C continue #define fi first #define se second #define mp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound #define gc getchar #define pc putchar #define kg putchar(' ') #define hh putchar('\n') #define mem(a,b) memset(a,b,sizeof(a)) #define _for(i,a,b) for( int i=(a); i<=(b); i++) #define _rep(i,a,b) for( int i=(a); i>=(b); i--) //#define int __int128 #define int long long using namespace std; inline int rd(){ int x=0,f=1;char ch=gc(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=gc();} return x*f; } char chhh[200]; inline void rt(int x){ int cnt=0,tmp=x>0?x:-x; if (!x) {pc('0');return;} if(x<0) pc('-'); while(tmp>0) {chhh[cnt++]=tmp%10+'0';tmp/=10;} while(cnt>0) pc(chhh[--cnt]); } const int mod=998244353; int f[5010],g[5010]; signed main(){ //int main(){ //int t; //t=rd(); //while(t--){ int n=rd(),m=rd(); f[0]=1; _for(i,1,n){ f[i]=f[i-1]*m%mod; } int ans=f[n]*n%mod; _for(i,1,m){ _for(j,1,n){ g[j]=(g[j-1]*i+(f[j-1]-g[j-1]+mod))%mod; ans=(ans-g[j-1]*f[n-j]+mod*mod)%mod; } } rt(ans); //} return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" #define all(v) v.begin(),v.end() const int mod = 1e9 + 7; ll dp[(1 << 18)][18]; int main (){ fast_io; ll n, m; cin >> n >> m; vector<vector<int> > constraints; for (int i = 0; i < m; i++) { int x, y, z; cin >> x >> y >> z; x--, y--; constraints.push_back({x, y, z}); } dp[0][0] = 1; for (int i = 0; i < (1 << n); i++) { int pref[n]; memset(pref, 0, sizeof(pref)); for (int j = 0; j < n; j++) { if (i & (1 << j)) pref[j]++; } for (int j = 1; j < n; j++) pref[j] += pref[j - 1]; for (int j = 0; j < n; j++) { if (dp[i][j] == 0) continue; for (int k = 0; k < n; k++) { if ((i & (1 << k))) continue; bool flag = false; int len = __builtin_popcount(i); for (auto& constraint: constraints) { if (len != constraint[0]) continue; if ((k <= constraint[1] && constraint[2] == pref[constraint[1]]) || (constraint[2] < pref[constraint[1]])) { flag = true; break; } } if (flag == true) continue; dp[i | (1 << k)][k] += dp[i][j]; } } } ll ans = 0; for (int i = 0; i < n; i++) { ans += dp[(1 << n) - 1][i]; } cout << ans << endl; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <stack> #include <queue> #include <cmath> #include <tuple> #include <cstdio> #include <bitset> #include <sstream> #include <iterator> #include <numeric> #include <map> #include <cstring> #include <set> #include <functional> #include <iomanip> using namespace std; #define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!! #ifdef DEBUG_ #define dump(x) cerr << #x << " = " << (x) << endl; #else #define dump(x) ; #endif #define equals(a,b) (fabs((a)-(b)) < EPS) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define SZ(x) ((int)(x).size()) #define pb push_back #define eb emplace_back //#define int long long typedef long long LL; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } template <typename T> std::string printVector(const std::vector<T> &data) { std::stringstream ss; std::ostream_iterator<T> out_it(ss, ", "); ss << "["; std::copy(data.begin(), data.end() - 1, out_it); ss << data.back() << "]"; return ss.str(); } template <typename T> void print_array(const T &ary, int size){ REP(i,size){ cout << ary[i] << " "; } cout << endl; } const int mod = 1e9+7; const LL LINF = 1001002003004005006ll; const int INF = 1001001001; const double EPS = (1e-10); const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899; int dx[] = {0,0,-1,1}; int dy[] = {-1,1,0,0}; signed main(int argc, char const *argv[]) { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(12); int N,M; cin >> N >> M; vector<vector<PII>> yz(N); REP(i,M){ int x,y,z; cin >> x >> y >> z; x--; yz[x].eb(y,z); } vector<vector<LL>> dp(N+1,VL(1 << N)); dp[0][0] = 1; REP(i,N){ REP(mask,(1 << N)){ REP(j,N){ if((mask >> j) & 1) continue; dp[i+1][mask | (1 << j)] += dp[i][mask]; } } // check REP(mask, (1 << N)){ bool ok = true; for(auto p : yz[i]){ int y,z; tie(y,z) = p; int cnt = 0; REP(a,y){ if((mask >> a) & 1) cnt++; } if(cnt > z) ok = false; } if(!ok){ dp[i+1][mask] = 0; } } } //REP(i,N+1){ // dump(i) // REP(mask, (1 << N)){ // cout << mask << " " << dp[i][mask] << endl; // } //} LL ans = 0; REP(mask, (1 << N)){ ans += dp[N][mask]; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){ return a/gcd(a,b)*b;} int main(){ ll n; cin>>n; ll ans=1; for(ll i=2;i<=n;++i){ ans=lcm(i,ans); } cout<<ans+1<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < n; i++) const ll mod = 1e9 + 7; int main(){ int n; cin >> n; vector<int>a(n+1); for(int i=2;i<=n;i++)a[i]=i; for(int i=2;i<=n;i++){ for(int j=i+1;j<=n;j++){ if(a[j]%a[i]==0)a[j]/=a[i]; } } ll ans=1; for(ll i=2;i<=n;i++)ans*=a[i]; cout << ans+1; }
#include <bits/stdc++.h> using namespace std; #define INF_LL (int64)1e18 #define INF (int32)1e9 #define REP(i, n) for(int64 i = 0;i < (n);i++) #define FOR(i, a, b) for(int64 i = (a);i < (b);i++) #define all(x) x.begin(),x.end() #define fs first #define sc second using int32 = int_fast32_t; using uint32 = uint_fast32_t; using int64 = int_fast64_t; using uint64 = uint_fast64_t; using PII = pair<int32, int32>; using PLL = pair<int64, int64>; const double eps = 1e-10; template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;} template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;} template<typename T> vector<T> make_v(size_t a){return vector<T>(a);} template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); } template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value!=0>::type fill_v(U &u,const V... v){u=U(v...);} template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value==0>::type fill_v(U &u,const V... v){ for(auto &e:u) fill_v<T>(e,v...); } template <typename F> class #if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard) [[nodiscard]] #endif // defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard) FixPoint final : private F { public: template <typename G> explicit constexpr FixPoint(G&& g) noexcept : F{std::forward<G>(g)} {} template <typename... Args> constexpr decltype(auto) operator()(Args&&... args) const #if !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9 noexcept(noexcept(F::operator()(std::declval<FixPoint>(), std::declval<Args>()...))) #endif // !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9 { return F::operator()(*this, std::forward<Args>(args)...); } }; // class FixPoint #if defined(__cpp_deduction_guides) template <typename F> FixPoint(F&&) -> FixPoint<std::decay_t<F>>; #endif // defined(__cpp_deduction_guides) namespace { template <typename F> #if !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard) # if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4) __attribute__((warn_unused_result)) # elif defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_Check_return_) _Check_return_ # endif // defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4) #endif // !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard) inline constexpr decltype(auto) makeFixPoint(F&& f) noexcept { return FixPoint<std::decay_t<F>>{std::forward<std::decay_t<F>>(f)}; } } // namespace int main(void){ cin.tie(0); ios::sync_with_stdio(false); int64 N, M; cin >> N >> M; map<int64, int64> mp; REP(i, N) { string s; cin >> s; int64 cnt = 0; REP(j, M) { if (s[j] != '0') cnt++; } mp[cnt%2]++; } cout << mp[0] * mp[1] << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vll vector<ll> #define vpii vector<pair<int,int>> #define vpll vector<pair<ll,ll>> #define fr(i,k,n) for (int i = k; i < n; ++i) #define fri(i,k,n) for (int i = k; i >= n; --i) #define pb push_back #define mp make_pair #define all(arr) arr.begin(),arr.end() #define ff first #define ss second const double pi=3.1415926535897932384626433832795; const int inf=1e9; const ll inf2=1e18; const int mod=1e9+7; void boost(){ ios_base::sync_with_stdio(false); cin.tie(NULL); } void solve(){ int n; cin>>n; int m=n*2; string s; cin>>s; int q; cin>>q; int t,a,b; int flip=0; while(q--){ cin>>t; if(t==1){ cin>>a>>b; a--; b--; if(flip){ a=(a+n)%m; b=(b+n)%m; } swap(s[a],s[b]); } else{ cin>>a>>b; flip^=1; } } if(flip){ fr(i,n,m){ cout<<s[i]; } fr(i,0,n){ cout<<s[i]; } } else{ fr(i,0,m) cout<<s[i]; } return; } int main() { boost(); int tc=1; //cin>>tc; while(tc--) solve(); return 0; }
// D - Happy Birthday! 2 #include <bits/stdc++.h> using namespace std; #define vec vector using vi = vec<int>; #define rp(i,s,e) for(int i=(s);i<(e);++i) #define sz(a) int(a.size()) int N; vi A(200); vec<vi> B(200); void print(int n, vi v){ cout<< n <<" "; rp(i, 0, n) cout<< v[i] << (i<n-1? " ":"\n"); } void dfs(int n, int r, vi C){ if(sz(C) == n){ if(!sz(B[r])){ B[r] = C; return; } puts("Yes"); print(sz(B[r]), B[r]); print(sz(C), C); exit(0); } rp(i, C.back(), N){ C.push_back(i+1); dfs(n, (r + A[i])%200, C); C.pop_back(); } return; } int main(){ cin>>N; N = min(8, N); // 8bit: 2^8=256 for(int&x:A) cin>>x; rp(n, 1, N+1) rp(i, 0, N) dfs(n, A[i]%200, {i+1}); puts("No"); }
#include <iostream> #include<vector> #include<algorithm> #include<string> #include<map> #include<set> #include<stack> #include<queue> #include<math.h> using namespace std; typedef long long ll; #define int long long #define double long double typedef vector<int> VI; typedef pair<int, int> pii; typedef vector<pii> VP; typedef vector<string> VS; typedef priority_queue<int> PQ; template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define fore(i,a) for(auto &i:a) #define REP(i,n) for(int i=0;i<n;i++) #define eREP(i,n) for(int i=0;i<=n;i++) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define eFOR(i,a,b) for(int i=(a);i<=(b);++i) #define SORT(c) sort((c).begin(),(c).end()) #define rSORT(c) sort((c).rbegin(),(c).rend()) #define LB(x,a) lower_bound((x).begin(),(x).end(),(a)) #define UB(x,a) upper_bound((x).begin(),(x).end(),(a)) #define INF 1000000000 #define LLINF 9223372036854775807 #define mod 1000000007 #define eps 1e-12 //priority_queue<int,vector<int>, greater<int> > q2; VI yaku(int n) { vector<int> ret; for (int i = 1; i*i <= n; ++i) { if (n%i == 0) { ret.push_back(i); if (i*i != n) { ret.push_back(n / i); } } } SORT(ret); return ret; } signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; N *= 2; VI A = yaku(N); int ans = 0; REP(i, A.size()) { int n = A[i]; //cout << n << " "; int b = N / n; //cout << b - n + 1<< endl; if ((b - n + 1) % 2 == 0)ans++; } cout << ans << endl; //REP(i, A.size())cout << A[i] << " "; return 0; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author tatsumack */ #include <iostream> #include <fstream> #include <bits/stdc++.h> #define int long long #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i) #define REV(i, a, b) for (int i = (a); i >= (b); --i) #define CLR(a, b) memset((a), (b), sizeof(a)) #define DUMP(x) cout << #x << " = " << (x) << endl; #define INF 1001001001001001001ll #define fcout cout << fixed << setprecision(12) using namespace std; class EPermutation { public: int bitcount(int n) { int cnt = 0; REP(i, 20) { if (n >> i & 1) cnt++; } return cnt; } void solve(std::istream& cin, std::ostream& cout) { int N, M; cin >> N >> M; vector<int> dp(1LL << N); vector<vector<tuple<int, int>>> v(20); REP(i, M) { int x, y, z; cin >> x >> y >> z; y--; v[x].emplace_back(y, z); } dp[0] = 1; REP(i, 1 << N) { int num = bitcount(i); REP(j, N) { if (i >> j & 1) continue; bool ok = true; for (auto p : v[num + 1]) { int n = 0; int y, z; tie(y, z) = p; if (j <= y) n++; REP(k, N) { if (i >> k & 1) { if (k <= y) n++; } } if (n > z) { ok = false; break; } } if (!ok) continue; dp[i | 1 << j] += dp[i]; } } cout << dp[(1 << N) - 1] << endl; } }; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); std::istream& in(std::cin); std::ostream& out(std::cout); EPermutation solver; solver.solve(in, out); return 0; }
#include <bits/stdc++.h> using namespace std; long long dp[1 << 20]; int main() { int n,m; cin >> n >> m; vector<tuple<int,int,int> > v; for (int i = 0; i < m; ++i) { int x,y,z; cin >> x >> y >> z; v.push_back({x, y, z}); } dp[(1 << n) - 1] = 1; for (int i = (1 << n) - 2; i >= 0; i--) { int cnt = __builtin_popcount(i); bool flag = 1; for (int j = 0; j < m; ++j) { auto [x,y,z] = v[j]; if(x < cnt) continue; int cur = 0; for (int k = 0; k < n; ++k) { if(i & (1 << k)) { int dk = k + 1; if(dk <= y) cur++; } } flag &= cur <= z; } if(!flag) continue; for (int j = 0; j < n; ++j) { if(!(i & (1 << j))) { dp[i] += dp[i | (1 << j)]; } } } cout << dp[0] << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define MAX_N 1005 #define MAX_M 1005 int dp[MAX_N][MAX_M]; int main() { int N, M; cin >> N >> M; vector<int> A(N), B(M); for (auto &i : A) cin >> i; for (auto &i : B) cin >> i; for (int i = 0; i <= N; ++i) { for (int j = 0; j <= M; ++j) dp[i][j] = 1001001001; } for (int i = 0; i <= N; ++i) dp[i][0] = i; for (int j = 0; j <= M; ++j) dp[0][j] = j; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { int ni = i+1, nj = j+1; dp[ni][nj] = min(dp[ni][nj], dp[i][nj]+1); dp[ni][nj] = min(dp[ni][nj], dp[ni][j]+1); dp[ni][nj] = min(dp[ni][nj], dp[i][j] + (A[i] == B[j] ? 0 : 1)); } } cout << dp[N][M] << endl; }
/* author : dunk_066 */ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int mod=1e9+7; #define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define all(c) c.begin(),c.end() #define pb push_back #define vi(a,x) vector<int>a(x) #define vl(a,x) vector<ll>a(x) #define ss second #define ff first void solve(){ int n,m;cin>>n>>m; int sum = 0,mnm = 100; for(int i = 0;i < n;i++){ for(int j = 0;j < m;j++){ int x;cin>>x; sum += x; mnm = min(mnm,x); } } cout<<(sum - mnm*(m * n)); } int main(){ FAST; int t=1;//cin>>t; while(t--) solve(); #ifndef ONLINE_JUDGE cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n"; #endif return 0; } // ============== Notes =============== // // common bugs // - int overflow (especially intermediate expressionns) // - array bounds (indices bigger than MAXN?) // - special cases (n=1? graph not connected?)
#include<iostream> #include<vector> #include<algorithm> #include<iomanip> #include<utility> #include<iomanip> #include<map> #include<queue> #include<stack> #include<cmath> #include<cstdio> #define rep(i,n) for(int i=0; i<(n); ++i) #define pai 3.1415926535897932384 #define NUM_MAX 2e18 #define NUM_MIN -1e9 using namespace std; using ll =long long; using P = pair<int,int>; int main(int argc, const char * argv[]) { int n; cin >> n; int a, b; ll ans=0; rep(i, n){ cin >> a >> b; for(int j=a; j<=b; j++){ ans += j; } } cout << ans << endl; return 0; }
#include <iostream> #include <cstdio> #include <vector> #define N 55 using namespace std; typedef long long ll; ll n, ans = 1e18, a[N]; bool vpr[N]; vector<ll> pr; ll gcd(ll p, ll q) { if (q == 0) return p; return gcd(q, p % q); } void f(ll p, ll q) { ll i; if (q >= ans) return; if (p == pr.size()) { for (i = 0; i < n; i++) { if (gcd(q, a[i]) == 1) return; } ans = q; return; } f(p + 1, q); f(p + 1, q * pr[p]); } int main() { ll i, j; cin >> n; for (i = 0; i < n; i++) { scanf("%lld", &a[i]); } for (i = 2; i <= 50; i++) { if (vpr[i]) continue; pr.push_back(i); for (j = i * 2; j <= 50; j += i) { vpr[j] = 1; } } f(0, 1); cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long const int inf=1e9+7; const int maxn=2e5+10; ll co[maxn][2]; struct Matrix { ll matrix[3][3]; void make(int op) { memset(matrix,0,sizeof(matrix)); matrix[2][2]=1; matrix[0][1]=(op==1)?1:-1; matrix[1][0]=(op==1)?-1:1; } void make(int op,ll p) { memset(matrix,0,sizeof(matrix)); matrix[0][0]=(op==3)?-1:1; matrix[1][1]=(op==4)?-1:1; matrix[2][2]=1; matrix[op-3][2]=2*p; return ; } Matrix operator*(const Matrix& a) { Matrix ans; for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { ans.matrix[i][j]=0; for (int k=0;k<3;k++) ans.matrix[i][j]+=(matrix[i][k]*a.matrix[k][j]); } } return ans; } }mat[maxn]; int main(){ int N,M,Q; scanf("%d",&N); for (int i=1;i<=N;i++) scanf ("%lld %lld",&co[i][0],&co[i][1]); scanf("%d",&M); mat[0].matrix[0][0]=1; mat[0].matrix[1][1]=1; mat[0].matrix[2][2]=1; for (int i=1;i<=M;i++) { int op; ll p; scanf("%d",&op); if (op==3 || op==4) { scanf("%lld",&p); mat[i].make(op,p); mat[i]=mat[i]*mat[i-1]; } else { mat[i].make(op); mat[i]=mat[i]*mat[i-1]; } } scanf("%d",&Q); for (int i=0;i<Q;i++) { ll a,b,x,y; scanf("%lld %lld",&a,&b); x=co[b][0];y=co[b][1]; printf("%lld %lld\n",x*mat[a].matrix[0][0]+y*mat[a].matrix[0][1]+mat[a].matrix[0][2],x*mat[a].matrix[1][0]+y*mat[a].matrix[1][1]+mat[a].matrix[1][2]); } return 0; }
#include<bits/stdc++.h> int main(){ using namespace std; unsigned long N; cin >> N; vector<pair<long, long>> pts(N); for(auto&& [x, y] : pts)cin >> x >> y; unsigned long M; cin >> M; vector<tuple<long, long, unsigned long, unsigned long>> co{{0, 0, 0, 1}}; for(unsigned long i{0}, a, b; i < M; ++i){ cin >> a; const auto [x, y, dx, dy]{co.back()}; if(a == 1)co.emplace_back(y, -x, (dx + 3) & 3UL, (dy + 3) & 3UL); if(a == 2)co.emplace_back(-y, x, (dx + 1) & 3UL, (dy + 1) & 3UL); if(a == 3){ cin >> b; co.emplace_back(2 * b - x, y, dx ^ ((~dx & 1UL) << 1UL), dy ^ ((~dy & 1UL) << 1UL)); } if(a == 4){ cin >> b; co.emplace_back(x, 2 * b - y, dx ^ ((dx & 1UL) << 1UL), dy ^ ((dy & 1UL) << 1UL)); } } unsigned long Q; cin >> Q; for(unsigned long i{0}, a, b; i < Q; ++i){ cin >> a >> b; const auto [x, y]{pts[b - 1]}; const auto [ox, oy, dx, dy]{co[a]}; cout << static_cast<long>(ox + (~dx & 1UL) * (dx & 2UL ? -1 : 1) * x + (~dy & 1UL) * (dy & 2UL ? -1 : 1) * y) << " " << static_cast<long>(oy + (dx & 1UL) * (dx & 2UL ? -1 : 1) * x + (dy & 1UL) * (dy & 2UL ? -1 : 1) * y) << endl; } return 0; }
#include <cmath> #include <queue> #include <cstdio> #include <cstring> #include <algorithm> #define N1 200500 #define inf 0x3f3f3f3f #define ll long long using namespace std; ll maxn=1e10; int n; char a[N1]; int main() { // freopen("a.txt","r",stdin); scanf("%d",&n); scanf("%s",a); if(n==1) { if(a[0]=='0') printf("%lld\n",maxn); if(a[0]=='1') printf("%lld\n",maxn*2); return 0; } if(n==2) { if(a[0]=='0' && a[1]=='0') printf("0\n"); if(a[0]=='0' && a[1]=='1') printf("%lld\n",maxn-1); if(a[0]=='1' && a[1]=='0') printf("%lld\n",maxn); if(a[0]=='1' && a[1]=='1') printf("%lld\n",maxn); return 0; } for(int i=3;i<n;i++) // check { if(a[i]!=a[i%3]){ puts("0"); return 0; } } ll ans=0; if(a[0]=='1' && a[1]=='1' && a[2]=='0') ; else if(a[0]=='1' && a[1]=='0' && a[2]=='1') n++; else if(a[0]=='0' && a[1]=='1' && a[2]=='1') n+=2; else{ puts("0"); return 0; } ll num=(n-1)/3+1; printf("%lld\n",maxn-num+1); return 0; }
#include<bits/stdc++.h> #define ll long long #define pb push_back #define f(i, b) for (int i = 0; i < b; i++) #define fr(i, a, b) for (int i = a; i >= b; i--) #define vt vector #define all(v) v.begin(), v.end() const ll M = 998244353; using namespace std; ll s(ll n, ll k) { ll C[k+1]; memset(C, 0, sizeof(C)); C[0] = 1; // nC0 is 1 for (ll i = 1; i <= n; i++) { // Compute next row of pascal triangle using // the previous row for (int j = min(i, k); j > 0; j--) C[j] = C[j] + C[j-1]; } return C[k]; } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n;cin>>n; if(n==12) { cout<<"1";return 0; } cout<<s(n,12)-s(n-1,12); #ifndef ONLINE_JUDGE cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n"; #endif return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n,N; cin >> n; N = pow(2,n); vector<int> vec(N); vector<int> vec2(N); for(int i = 0;i<N;i++){ int A; cin >> A; vec.at(i) = A; } vec2 = vec; while(vec.size()!=2){ for(int i = 0;i<N/2;i++){ if(vec.at(i)<=vec.at(i+1)){ vec.erase(vec.begin()+i); } else{ vec.erase(vec.begin()+i+1); } } N /= 2; } int zyun = min(vec.at(0),vec.at(1)); for(int i = 0;i<pow(2,n);i++){ if(vec2.at(i)==zyun){ cout << i+1; break; } } }
// I SELL YOU...! #include<iostream> #include<vector> #include<algorithm> #include<functional> #include<queue> #include<chrono> #include<iomanip> #include<map> #include<set> using namespace std; using ll = long long; using P = pair<ll,ll>; using TP = tuple<ll,ll,ll>; void init_io(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } const ll MAX = 3e5; class union_find{ int n; vector<int> par,rk,size; public: union_find(int max_n){ n = max_n+1; for(int i=0;i<=n;i++){ par.emplace_back(i); rk.emplace_back(0); size.emplace_back(1); } } int root(int x){ vector<int> nodes; while(x!=par[x]){ nodes.emplace_back(x); x = par[x]; } for(auto v:nodes){ par[v] = x; } return x; } void unite(int x,int y){ x = root(x); y = root(y); if(x==y) return; if(rk[x]<rk[y]){ par[x] = y; size[y] += size[x]; }else{ par[y] = x; if(rk[x]==rk[y]) rk[x]++; size[x] += size[y]; } } bool same(int x,int y){ return root(x)==root(y); } int treesize(int x){ return size[root(x)]; } }; signed main(){ init_io(); ll n,ans=0; cin >> n; vector<ll> a(n); union_find uf(MAX); for(int i=0;i<n;i++){ cin >> a[i]; } for(int i=0;i<n;i++){ if(!uf.same(a[i], a[n-1-i])) { uf.unite(a[i], a[n-1-i]); ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> #define _max(x, y) ((x > y) ? x : y) #define _min(x, y) ((x < y) ? x : y) using namespace std; typedef long long ll; template <typename T> inline void red(T &x) { x = 0; bool fg = 0; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') fg ^= 1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (T)(ch ^ 48), ch = getchar(); if (fg) x = -x; } template <typename T> bool umax(T &x, T y) { return (x < y) ? (x = y, true) : (false); } template <typename T> bool umin(T &x, T y) { return (x > y) ? (x = y, true) : (false); } const int N = 109; int n, k, jump[N][N]; char s[N]; struct rec { char c; rec operator*(const rec y) { if (c == y.c) return *this; if (c == 'P') { if (y.c == 'R') return *this; else return y; } if (c == 'S') { if (y.c == 'R') return y; else return *this; } if (c == 'R') { if (y.c == 'P') return y; else return *this; } } } dp[N][N]; int main() { red(n); red(k); scanf("%s", s); for (int i = 0; i < n; ++i) { jump[i][0] = (i + 1) % n; dp[i][0].c = s[i]; } for (int j = 1; j <= k; j++) { for (int i = 0; i < n; ++i) { jump[i][j] = jump[jump[i][j - 1]][j - 1]; dp[i][j] = dp[i][j - 1] * dp[jump[i][j - 1]][j - 1]; } } printf("%c\n", dp[0][k].c); return 0; }
#include <bits/stdc++.h> typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; char win(char a,char b){ if (a == 'R' && b == 'P') return b; if (a == 'P' && b == 'S') return b; if (a == 'S' && b == 'R') return b; else return a; } int main(){ int n,k; cin >> n >> k; string s; cin >> s; while(k--){ s += s; string t; for(int i = 0;i<2*n;i+= 2){ t += win(s[i],s[i+1]); } s = t; } cout << s[0] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll>vl1; typedef vector<vl1> vl2; vl1 veka(11); vl1 niz(11); vl1 kata(11); vl1 hepa(11); struct struka {ll val; ll ind;}; typedef vector<struka> vs; vs sutra(11); bool compa(struka& a, struka& b) { if(a.val==b.val) return a.ind<b.ind; return a.val<b.val; } int main() { ll i, j, k, kn, m, n, p, t, r, x, y, z, a, b, c, kom; ll val, pos, tmp, suma, maxa, mina, naso, num; string str1; char ch1; cin>>n; if(n==2) {cout<<2; return 0;} suma=2; for(i=2;i<=n;i++) { kom=(i*(i+1))>>1; val=n-kom; if(val<0) break; tmp=val/i; if(val==tmp*i) suma+=2; } cout<<suma; return 0; } /* */
#include<bits/stdc++.h> using namespace std; using ll=int64_t; int main(){ ll N; cin>>N; ll idx=sqrt(2*N); list<pair<ll, ll> > num; for(int i=1; i<=idx; i++){ if(((2*N)%i)==0){ ll j=(2*N)/i; ll base= i-j+1; if(base%2==0){ if(j-1>=0) num.push_back({base/2, j-1}); if(i-1>=0) num.push_back({(-base+2)/2, i-1}); if(-j-1>=0) num.push_back({(-base+2)/2, -j-1}); if(-i-1>=0) num.push_back({base/2, -i-1}); } } } cout<<num.size()<<endl; return 0; }
#include <bits/stdc++.h> #define ll long long int #define pb push_back #define st first #define nd second #define pii pair<int,int> #define mp make_pair #define pll pair<long long,long long> using namespace std; const int nax = 105; int n; char s[nax]; int a[nax]; vector<vector<int> > cols; void solve(){ cin >> n; string x; cin >> x; for(int i=1;i<=n;i++) s[i] = x[i - 1]; for(int i=0;i<=n;i++) cin >> a[i]; int ile = 1e9; for(int i=1;i<=n;i++){ ile = min(ile, abs(a[i] - a[i - 1])); } vector<int> fi; for(int i=1;i<=ile;i++){ fi.pb(a[0] / ile); if(i <= a[0] % ile) fi.back()++; } cols.pb(fi); for(int i=1;i<=n;i++){ if(s[i] == '<'){ // jestesmy wieksi vector<int> last = cols.back(); vector<int> now; int rest = a[i]; for(int j=1;j<=ile;j++){ now.pb(last[j - 1] + 1); rest -= (last[j - 1] + 1); } int prefix = -1; if(now[0] == now[ile - 1]) prefix = ile - 1; else{ for(int j=1;j<ile;j++){ if(now[j] < now[j - 1]){ prefix = j - 1; break; } } } while(rest--){ prefix++; if(prefix == ile) prefix = 0; now[prefix]++; } cols.pb(now); } else{ vector<int> last = cols.back(); vector<int> now; int rest = a[i]; for(int j=1;j<=ile;j++){ now.pb(last[j - 1] - 1); rest -= (last[j - 1] - 1); } int prefix = -1; if(now[0] == now[ile - 1]) prefix = ile - 1; else{ for(int j=1;j<ile;j++){ if(now[j] < now[j - 1]){ prefix = j - 1; break; } } } while(rest < 0){ rest++; now[prefix]--; prefix--; if(prefix == -1) prefix = ile - 1; } cols.pb(now); } } cout << ile <<"\n"; for(int j=0;j<ile;j++){ for(int i=0;i<=n;i++){ cout << cols[i][j] <<" " ; } cout << "\n"; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int tt = 1; // cin >> tt; while(tt--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; vector<int> a(n + 1); cin >> n >> s; for (int i = 0; i < n + 1; ++i) { scanf("%d", &a[i]); } int l = 1, r = 10005; while (l + 1 < r) { int m = (l + r) / 2; bool ok = true; for (int i = 1; i <= n; ++i) { int q1 = a[i - 1] / m; int r1 = a[i - 1] % m; int q2 = a[i] / m; int r2 = a[i] % m; if (s[i - 1] == '>') { swap(q1, q2); swap(r1, r2); } if (q1 == q2) { ok = false; break; } if (q1 + 1 == q2) { if (r1 > r2) { ok = false; break; } } } if (!ok) r = m; else l = m; } cout << l << endl; vector<int> rem(n + 1); for (int i = 0; i < n + 1; ++i) { rem[i] = a[i] % l; } for (int t = 0; t < l; ++t) { for (int i = 0; i < n + 1; ++i) { int q = a[i] / l; if (t < rem[i]) { cout << q + 1; } else { cout << q; } if (i == n) cout << endl; else cout << " "; } } }
#include<bits/stdc++.h> #define fp(i,a,b) for(int i=a,i##_=(b)+1;i!=i##_;++i) #define fd(i,a,b) for(int i=a,i##_=(b)-1;i!=i##_;--i) #define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout) namespace IO{ //In char ss[1<<17],*_A=ss,*_B=ss; #define gc() (_A==_B&&(_B=(_A=ss)+fread(ss,1,1<<17,stdin),_A==_B)?-1:*_A++) template<class T>inline void In(T&x){ char c;T y=1;while(c=gc(),!isdigit(c)&&c!=-1)if(c==45){y=-1;}x=c-48; while(c=gc(),isdigit(c)){x=x*10+c-48;}x*=y; } template<class T,class ..._T>inline void In(T &x,_T &...y){return In(x),In(y...);} template<class T>inline void In(T*a,int Len){fp(i,0,Len-1)In(*(a+i));} inline void In(char*a){char c=gc();for(;c<=32;c=gc());for(*a=c;c>32;*(++a)=c)c=gc();} //Out char sr[1<<21],_z[20],*_C=sr,*_D=sr+(1<<21)-1;int _Z; inline void flush(){fwrite(sr,1,_C-sr,stdout),_C=sr;} inline void Out(char c){*_C++=c;if(*_C==*_D)flush();} inline void Out(char*c){while(*c){*_C++=*c++;if(_C==_D)flush();}} template<class T>inline void Out(T x){ if(x<0)Out(45),x=-x; while(_z[++_Z]=x%10+48,x/=10); while(Out(_z[_Z]),--_Z){}; } template<class T,class ..._T>inline void Out(T x,_T ...y){return Out(x),Out(y...);} template<class T>inline void Out(T*a,int Len){fp(i,0,Len-1)Out(*(a+i)," \n"[i==Len-1]);} struct _Flush{~_Flush(){flush();}}flusher; } using namespace IO; using namespace std; const int N=4e6+5,P=1e9+7; typedef int arr[N]; typedef long long ll; /*-------------------------------------------------------------------------------------*/ int n,m; arr a,inv; inline int pow(int a,int b){ int x=1; for(;b;b>>=1,a=(ll)a*a%P)if(b&1)x=(ll)x*a%P; return x; } inline void Solve(){ In(a+1,n); ll A=accumulate(a+1,a+n+1,n),Ans=1; inv[1]=1,m-=A-n; fp(i,2,A)inv[i]=(ll)(P-P/i)*inv[P%i]%P; fp(i,1,A)Ans=Ans*(A+m+1-i)%P*inv[i]%P; printf("%lld\n",Ans); } int main(){ #ifndef ONLINE_JUDGE file("s"); #endif while(In(n,m),n!=-49) Solve(); return 0; }
#include <bits/stdc++.h> #define f first #define s second #define pb push_back #define pii pair<int, int> #define endl '\n' #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define vvvvi vector<vvvi> #define vl vector<ll> #define vvl vector<vl> #define vld vector<ld> #define pii pair<int, int> #define pll pair<ll, ll> #define vpii vector<pii> #define vvpii vector<vpii> #define vpll vector<pll> #define rep(s, l, r) for (int s = l; s < r; s++) #define per(s, r, l) for (int s = r - 1; s >= l; s--) #define all(x) x.begin(), x.end() typedef long long ll; typedef long double ld; using namespace std; template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>; template<typename T> void setmax(T& a, T b) { a = max(a, b); }; template<typename T> void setmin(T& a, T b) { a = min(a, b); }; template<typename T> bool in(T lo, T v, T hi) { return lo <= v && v <= hi; }; struct Fenwick { int n; vi f; Fenwick(int _n) { n = _n; f.assign(n, 0); } void add(int i, int delta) { for (int j = i; j < n; j |= (j + 1)) f[j] += delta; } int sum(int i) { int s = 0; for (int j = i; j >= 0; j = (j & (j + 1)) - 1) s += f[j]; return s; } }; struct Solution { ll n; vi a; void solve() { cin >> n; a.resize(n); rep(i, 0, n) cin >> a[i]; a.resize(2 * n); rep(i, n, 2 * n) a[i] = a[i - n]; Fenwick f(n); ll cnt = 0; for (int i = 0; i < n; i++) { cnt += f.sum(n - 1) - f.sum(a[i]); f.add(a[i], 1); } cout << cnt << endl; // get num inversions in a[0..n-1] rep(i, n, 2 * n - 1) { f.add(a[i - n], -1); cnt -= f.sum(a[i - n]); cnt += f.sum(n - 1) - f.sum(a[i]); f.add(a[i], 1); cout << cnt << endl; } } }; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; while (t--) { Solution s; s.solve(); } return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan0     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int L, R; ll cnt[1010101]; //--------------------------------------------------------------------------------------------------- void _main() { cin >> L >> R; rrep(g, 1010100, 2) { cnt[g] = 1LL * (R / g - (L - 1) / g) * (R / g - (L - 1) / g); int x = 2 * g; while (x <= R) { cnt[g] -= cnt[x]; x += g; } } ll ans = 0; rep(g, 2, 1010101) { ans += cnt[g]; if (L <= g && g <= R) { ans -= R / g - (L - 1) / g; ans -= R / g - (L - 1) / g; ans++; } } cout << ans << endl; }
#include <cstdio> int rint() { int x = 0, fx = 1; char c = getchar(); while (c < '0' || c > '9') { fx ^= (c == '-' ? 1 : 0); c = getchar(); } while ('0' <= c && c <= '9') { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } if (!fx) return -x; return x; } int main() { int A = rint(), B = rint(); printf("%lg\n", A * B / 100.0); return 0; }
#include <iostream> using namespace std; #include <vector> #include <set> #include<string> #include <algorithm> #include <cmath> #include <climits> typedef long long ll; typedef unsigned long long ull; //AtCoder Begginer Contest 196 D int main(void) { ll n; cin >> n; ll ans; for (ll i = 0; i < 10000000; i++) { // ll(整数) -> string(文字列) string strTmp=to_string(i); strTmp = strTmp + strTmp; ll tmpll = stoll(strTmp); if (tmpll > n) { ans = i - 1; break; } } cout << ans; return 0; }
#include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long N; cin >> N; int ans = 0; for (long long i = 1, pwr = 10; ; i++) { if (i%pwr == 0) pwr *= 10; if (i + pwr*i > N) break; ans++; } cout << ans << '\n'; return 0; }
#pragma GCCoptimize("O3", "unroll-loops") #include <cstring> #include <iostream> using namespace std; using ll = long long; const int MAXN = 102; const int MAXC = 122505; ll k, mod, table[MAXN][MAXC], ret[MAXN]; int n, now; void calc() { memset(table, 0, sizeof(table)); table[0][0] = 1; for (int i = 1; i <= n; ++i) { int c = (k * (i + 1) * i) >> 1; c = min(c, MAXC - 1); for (int j = 0; j <= c; ++j) { for (int v = 0; v <= k; ++v) { int tmp = j + v * i; if (tmp > c) break; table[i][tmp] += table[i-1][j]; if (table[i][tmp] >= mod) table[i][tmp] -= mod; } } } } int main(){ ios::sync_with_stdio(0), cin.tie(0); while (cin >> n >> k >> mod) { calc(); for (now = 1; now * 2 <= n + 1; now++) { ll ans = 0; int l = now - 1, r = n - now; ans += k * table[l][0] * table[r][0]; ans %= mod; for (int j = 1; j < MAXC; ++j) { ans += (k + 1LL) * ((table[l][j] * table[r][j]) % mod); ans %= mod; } ret[now] = ans; ret[n - now + 1] = ans; } for (now = 1; now <= n; ++now) cout << ret[now] << '\n'; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define mit map<int,int>::iterator #define sit set<int>::iterator #define itrm(g,x) for(mit g=x.begin();g!=x.end();g++) #define itrs(g,x) for(sit g=x.begin();g!=x.end();g++) #define ltype int #define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++) #define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++) #define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--) #define pii pair<int,int> #define fi first #define se second #define mpr make_pair #define pb push_back #define fastio ios::sync_with_stdio(false) #define check(x) if(x>=mod) x-=mod const int inf=0x3f3f3f3f;int mod; const double pi=3.1415926535897932,eps=1e-6; void chmax(int &x,int y){if(x < y) x = y;} void chmin(int &x,int y){if(x > y) x = y;} int n,k; int dp[105][1000005],sum[105][1000005]; int main() { scanf("%d%d%d",&n,&k,&mod); dp[0][0] = 1; rep(i,0,n) { int mx = i * (i + 1) / 2 * k;int mxmx = (i + 1) * (i + 2) / 2 * k; if(i){ rep(j,0,mx) { dp[i][j] = sum[i - 1][j];if(j - i * (k + 1) >= 0) dp[i][j] -= sum[i - 1][j - i * (k + 1)]; dp[i][j] += mod;dp[i][j] %= mod; //rep(l,0,k) if(j - l * i >= 0) {dp[i][j] += dp[i - 1][j - l * i];check(dp[i][j]);} } } rep(j,0,mxmx) { sum[i][j] = dp[i][j];if(j >= i + 1) {sum[i][j] += sum[i][j - i - 1];check(sum[i][j]);} } } rep(i,1,n) { int mx = n * (n + 1) / 2 * k; int res = 0; rep(j,0,mx) {res += (ll)dp[i - 1][j] * dp[n - i][j] % mod;check(res);} res = ((ll)res * (k + 1) % mod - 1ll + mod) % mod; printf("%d\n",res); } return 0; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <numeric> #include <cmath> #include <unordered_map> #include <queue> #include <deque> using namespace std; using ll = long long; void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); } void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); } template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; } #define Sq(x) (x)*(x) #define For(i, n) for(int i = 0; i < (n); i ++) #define Rep(n) For(_, n) #define Range(c) c.begin(), c.end() #define RevRange(c) c.rbegin(), c.rend() #define Contains(c, x) (find(Range(c), x) != c.end()) #define Search(rb, re, x) distance(rb, find(rb, re, x)) #define Sort(a) sort(Range(a)) #define DeSort(a) sort(RevRange(a)) #define Reverse(c) reverse(Range(c)) #define Unique(a) a.erase(unique(Range(a)), a.end()) #define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i] #define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__) #define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i] #define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i] #define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i] #define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; } #define Cout(...) _cout(__VA_ARGS__) #define Couts(xs) { for(const auto &e : xs) cout << e << "\n"; cout << "\n"; } #define Coutyn(cond) Cout((cond) ? "yes" : "no") #define CoutYn(cond) Cout((cond) ? "Yes" : "No") #define CoutYN(cond) Cout((cond) ? "YES" : "NO") #define Return(expr) { Cout(expr); return 0; } #define vc vector #define Mini(a, x) a = min(a, x) #define Maxi(a, x) a = max(a, x) // constexpr int MOD = 1e9+7; int k(int n){ return (1 << n) - 1; } vc<string> f(int n){ if(n == 1) return {"AB"}; auto p = f(n-1); vc<string> s(k(n), string(1 << n, '.')); For(j, (1 << n) / 2) s[0][j] = 'A', s[0][j + (1 << n) / 2 ] = 'B'; For(i, p.size()){ For(j, (1 << n) / 2){ s[2*i+1][j] = s[2*i+1][j + (1 << n) / 2] = s[2*i+2][j] = p[i][j]; s[2*i+2][j + (1 << n) / 2] = 'A' + 'B' - p[i][j]; } } return s; } int main(void){ Cin(int, n); Cout(k(n)); auto ans = f(n); Couts(ans); }
/*** author: yuji9511 ***/ #include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; using namespace std; using ll = long long; using lpair = pair<ll, ll>; using vll = vector<ll>; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i=(m);i<(n);i++) #define rrep(i,m,n) for(ll i=(m);i>=(n);i--) ostream& operator<<(ostream& os, lpair& h){ os << "(" << h.first << ", " << h.second << ")"; return os;} #define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];}; void print() {} template <class H,class... T> void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);} 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; } void solve(){ ll N,M; cin >> N >> M; vll a(M), b(M); vector<vll> tree(N); rep(i,0,M){ cin >> a[i] >> b[i]; a[i]--; b[i]--; tree[a[i]].push_back(b[i]); } ll ans = 0; rep(i,0,N){ vll check(N, 0); auto dfs = [&](auto dfs, ll cur) -> void { if(check[cur]) return; check[cur]++; for(auto &e: tree[cur]){ if(!check[e]) dfs(dfs, e); } }; dfs(dfs, i); rep(j,0,N){ if(check[j]) ans++; } } print(ans); } int main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> # define N 110 int a[N], n,i,j,k=2e9;; int abs(int x) { return x>=0?x:-x; } int min(int x,int y) { return x<y?x:y; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); scanf("%d%*s",&n); n++; for(i=1;i<=n;i++){ scanf("%d",a+i); } for(i=1;i<n;i++){ k=min(k,abs(a[i]-a[i+1])); } printf("%d\n",k); for(i=1;i<=k;i++) { for(j=1;j<=n;j++){ printf("%d ",a[j]/k+(k-i+1<=a[j]%k?1:0)); } puts(""); } }
#include <cstdio> #include <cstring> #include <cmath> #include <cassert> #include <vector> #include <string> #include <set> #include <map> #include <queue> #include <stack> #include <algorithm> #include <iostream> #include <numeric> /* debug macros */ #ifdef WAFDAYO #define DBG_LINE() {std::cerr<<"\e[2m[L"<<__LINE__<<"]\e[m ";} #define DBG_PRINT(s,t,u) {std::cerr<<(s)<<" \e[2m=\e[m \e[1m"<<(t)<<"\e[m"<<(u);} #define SELECT_7TH(x1,x2,x3,x4,x5,x6,x7,...) x7 #define dbg1(x1) DBG_PRINT(#x1,x1,std::endl) #define dbg2(x1,x2) DBG_PRINT(#x1,x1,", ")dbg1(x2) #define dbg3(x1,x2,x3) DBG_PRINT(#x1,x1,", ")dbg2(x2,x3) #define dbg4(x1,x2,x3,x4) DBG_PRINT(#x1,x1,", ")dbg3(x2,x3,x4) #define dbg5(x1,x2,x3,x4,x5) DBG_PRINT(#x1,x1,", ")dbg4(x2,x3,x4,x5) #define dbg6(x1,x2,x3,x4,x5,x6) DBG_PRINT(#x1,x1,", ")dbg5(x2,x3,x4,x5,x6) #define dbg(...) DBG_LINE()\ SELECT_7TH(__VA_ARGS__,dbg6,dbg5,dbg4,dbg3,dbg2,dbg1)(__VA_ARGS__) #else #define dbg(...) {} #endif /* utility functions */ struct read_item{read_item(){}; template<class T>operator T(){T t;std::cin>>t;return t;}}; char splf(int i,int n){return(i+1<n)?' ':'\n';}; template<bool up> struct _RI{int i;_RI(int a):i(a){} int operator*(){return i;}void operator++(){i+=(up?1:-1);} bool operator!=(const _RI& r){return up?i<r.i:i>r.i;}}; template<bool up> struct _RX{_RI<up> x,y;_RI<up> begin(){return x;}_RI<up> end(){return y;} _RX(int a,int b):x(up?a:(b-1)),y(up?b:(a-1)){}_RX(int a):_RX(0,a){}}; typedef _RX<true> range; typedef _RX<false> revrange; /* types and constants */ typedef int64_t i64; typedef uint64_t u64; // const i64 inf = (i64)1.05e18; // const int inf = (int)1.05e9; using namespace std; int main() { const int N = read_item(); const string S = read_item(); vector<int> As(N + 1); for(auto i : range(N + 1)) { As[i] = read_item(); } int diff = 1e9; for(auto i : range(N)) { diff = min(diff, abs(As[i] - As[i + 1])); } vector<vector<int>> ans; vector<int> rem(N + 1); const int k = diff; for(auto i : range(N + 1)) { rem[i] = As[i] % k; } for(auto i : range(k)) { vector<int> a(N + 1); for(auto j : range(N + 1)) { a[j] = As[j] / k + (i < rem[j] ? 1 : 0); } ans.push_back(a); } printf("%d\n", (int)ans.size()); for(auto& a : ans) { for(auto i : range(N + 1)) { printf("%d%c", a[i], splf(i, N + 1)); } } return 0; } /* wafdayo~~~ */
#include<bits/stdc++.h> using namespace std; const int mod=1e9+7; int n,m,sum,ans=1; int power(int a,int b){ int ret=1; while(b){ if(b&1) ret=1ll*ret*a%mod; a=1ll*a*a%mod; b>>=1; } return ret; } int main(){ scanf("%d%d",&n,&m); for(int i=1,x;i<=n;i++){ scanf("%d",&x); sum+=x; } if(sum>m){ puts("0"); return 0; } //${M+N}\choose {sum+N}$ m+=n; sum+=n; //cout<<m<<" "<<sum<<endl; for(int i=1;i<=sum;i++) ans=1ll*ans*power(i,mod-2)%mod*(m-i+1)%mod; printf("%d\n",(ans+mod)%mod); return 0; }
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define X first #define Y second #define y0 y12 #define y1 y22 #define INF 987654321 #define PI 3.141592653589793238462643383279502884 #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c)) #define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c)) #define MEM0(a) memset((a),0,sizeof(a)) #define MEM_1(a) memset((a),-1,sizeof(a)) #define ALL(a) a.begin(),a.end() #define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin()) #define SYNC ios_base::sync_with_stdio(false);cin.tie(0) using namespace std; typedef long long ll; typedef long double ld; typedef double db; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> Pi; typedef pair<ll, ll> Pll; typedef pair<db, db> Pd; typedef vector<int> Vi; typedef vector<ll> Vll; typedef vector<double> Vd; typedef vector<Pi> VPi; typedef vector<Pll> VPll; typedef vector<Pd> VPd; typedef tuple<int, int, int> iii; typedef tuple<int,int,int,int> iiii; typedef tuple<ll, ll, ll> LLL; typedef vector<iii> Viii; typedef vector<LLL> VLLL; typedef complex<double> base; const int MOD = 1000000007; ll POW(ll a, ll b, ll MMM=MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; } int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 }; int ddx[]={2,2,-2,-2,1,1,-1,-1},ddy[]={1,-1,1,-1,2,-2,2,-2}; ll nCr(int n,int r){ if(r>n)return 0; ll res=1; fup(i,1,r,1){ res=res*n--%MOD*POW(i,MOD-2)%MOD; } return res; } int main() { int n,m,s=0; scanf("%d%d",&n,&m); fup(i,1,n,1){ int x; scanf("%d",&x); s+=x; } printf("%lld\n",nCr(n+m,n+s)); }
#include <bits/stdc++.h> using namespace std; void Main(); using i8 = int8_t; /* -128 ~ 127 */ using u8 = uint8_t; /* 0 ~ 255 */ using i16 = int16_t; /* -32,768 ~ 32,767 */ using u16 = uint16_t; /* 0 ~ 65,535 */ using i32 = int32_t; /* -2,147,483,648 ~ 2,147,483,647 */ using u32 = uint32_t; /* 0 ~ 4,294,967,295 */ using i64 = int64_t; /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */ using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */ using f32 = float; /* (-3.4 * 10^38) ~ (3.4 * 10^38) */ using f64 = double; /* (-1.7 * 10^308) ~ (1.7 * 10^308) */ using f80 = __float80; template <class T> using Vec = vector<T>; constexpr i64 INF = 1010000000000000017; constexpr i64 MOD = 1e9 + 7; constexpr f64 EPS = 1e-12; constexpr f64 PI = 3.14159265358979323846; #define ALL(v) v.begin(), v.end() #define YN(a, b, c) ((c)? a : b) #define GCD(a, b) __gcd(a, b) /* 最大公約数 */ #define LCM(a, b) (i64)(a / (f64)__gcd(a, b) * b) /* 最小公倍数 */ int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); Main(); return 0; } void Main() { string S; cin >> S; bool rev = false; list<char> T; for (i32 i = 0; i < S.size(); i++) { if (S[i] == 'R') { rev = !rev; } else { if (rev) { T.push_front(S[i]); } else { T.push_back(S[i]); } } } string t(ALL(T)); if (!rev) reverse(ALL(t)); stack<char> s; for (i32 i = 0; i < T.size(); i++) { if (s.empty()) { s.push(t[i]); continue; } if (t[i] == s.top()) s.pop(); else s.push(t[i]); } string ans = ""; while (!s.empty()) { ans += s.top(); s.pop(); } cout << ans << endl; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; //#define ACL #ifdef ACL #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif #if __has_include("acl-all.h") #include "acl-all.h" //on Wandbox using namespace atcoder; #endif #endif //#ifdef ACL typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<ll, ll> > vpll; typedef vector<vector<int> > vvi; typedef vector<vector<char> > vvc; typedef vector<vector<string> > vvs; typedef vector<vector<ll> > vvll; typedef vector<vector<bool> > vvb; typedef pair<ll, ll> pll; #define rep(i, n) for (int i = 0; i < int(n); ++i) #define rrep(i, n) for (int i = 1; i <= int(n); ++i) #define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++) #define drep(i, n) for (int i = int(n)-1; i >= 0; --i) #define MES(a) MES2 a #define MES2(a0,a1,a2,a3,a4,x,...) x #define mes_1(x1) cout<<x1<<endl #define mes_2(x1,x2) cout<<x1<<" "<<x2<<endl #define mes_3(x1,x2,x3) cout<<x1<<" "<<x2<<" "<<x3<<endl #define mes_4(x1,x2,x3,x4) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<endl #define mes_5(x1,x2,x3,x4,x5) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<" "<<x5<<endl #define mes(...) CHOOSE((__VA_ARGS__,mes_5,mes_4,mes_3,mes_2,mes_1,~))(__VA_ARGS__) #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,x,...) x #define debug_1(x1) cout<<#x1<<": "<<x1<<endl #define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl #define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl #define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl #define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl #define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__) #define Ynmes(a) (a) ? mes("Yes") : mes("No") #define YNmes(a) (a) ? mes("YES") : mes("NO") #define re0 return 0 #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Sort(a) sort(a.begin(), a.end()) #define rSort(a) sort(a.rbegin(), a.rend()) #define Rev(a) reverse(a.begin(), a.end()) int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 }; int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 }; 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; } struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } }; const int INF = INT_MAX; const ll LLINF = 1LL << 60; const ll MOD = 1000000007; const double EPS = 1e-9; ll fact_mod(ll n, ll mod) { ll f = 1; for (ll i = 2; i <= n; i++) f = f * (i % mod) % mod; return f; } ll modpow(ll x, ll n, ll mod) { if(n == 0) return 1; ll res = modpow((x * x) % mod, n / 2 , mod); if(n & 1) res = (res * x) % mod; return res; } ll modncr(ll n, ll r, ll mod) { if(r > n-r) r = n-r; if(r == 0) return 1; ll a = 1; rep(i, r) a = a * ((n-i) % mod) % mod; ll b = modpow(fact_mod(r, mod), mod-2, mod); return (a % mod) * (b % mod) % mod; } signed main() { string s; cin >> s; deque <char> dq; bool mode = 0; rep(i, s.size()) { if (s[i] == 'R') { mode = 1-mode; continue; } if (mode) { if (!dq.empty() && dq.front() == s[i]) { dq.pop_front(); continue; } dq.push_front(s[i]); } else { if (!dq.empty() && dq.back() == s[i]) { dq.pop_back(); continue; } dq.push_back(s[i]); } } if (!mode) { while(!dq.empty()) { cout << dq.front(); dq.pop_front(); } cout << endl; } else { while(!dq.empty()) { cout << dq.back(); dq.pop_back(); } cout << endl; } }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); i++) using namespace std; const int inf = 1e9; int n; int x[20], y[20], z[20]; int dist[20][20]; int dp[1 << 20][20]; int rec(int bit, int v) { if (dp[bit][v] != -1) return dp[bit][v]; if (bit == (1 << v)) { return dp[bit][v] = dist[0][v]; } int prev = bit & ~(1 << v); int ret = inf; rep(pv, n) { if (!(prev & (1 << pv))) continue; ret = min(ret, rec(prev, pv) + dist[pv][v]); } return dp[bit][v] = ret; } int main() { cin >> n; rep(i, n) cin >> x[i] >> y[i] >> z[i]; for (int bit = 0; bit < (1 << n); bit++) rep(v, n) dp[bit][v] = -1; rep(i, n) rep(j, n) { dist[i][j] = abs(x[j] - x[i]) + abs(y[j] - y[i]) + max(0, z[j] - z[i]); } cout << rec((1 << n) - 1, 0) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(ll i=0;i<(n);i++) const ll INF = 1LL<<60; int main(){ ll n,k; cin>>n>>k; string s; cin>>s; map<char,ll> rcp; rcp['R']=1; rcp['S']=2; rcp['P']=3; string ns=s; ll knum=300; k=k+1; while(k!=1){ k--; s.clear(); s=ns; ns.clear(); s=s+s; if(k<10)knum=pow(2,k); rep(i,min((ll)s.size(),knum)/2){ if(rcp[s[2*i]]-rcp[s[2*i+1]]==0)ns+=s[2*i]; if((rcp[s[2*i]]-rcp[s[2*i+1]]+3)%3==2)ns+=s[2*i]; if((rcp[s[2*i]]-rcp[s[2*i+1]]+3)%3==1)ns+=s[2*i+1]; } if((ll)ns.size()==1)break; } cout<<ns[0]<<endl; }
#include "bits/stdc++.h" #define MOD 1000000007 #define rep(i, n) for(ll i=0; i < (n); i++) #define rrep(i, n) for(ll i=(n)-1; i >=0; i--) #define ALL(v) v.begin(),v.end() #define rALL(v) v.rbegin(),v.rend() #define FOR(i, j, k) for(ll i=j;i<k;i++) #define debug_print(var) cerr << #var << "=" << var <<endl; #define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" " #define fi first #define se second using namespace std; typedef long long int ll; typedef vector<ll> llvec; typedef vector<double> dvec; typedef pair<ll, ll> P; typedef long double ld; struct edge{ll x, c;}; ll mod(ll a, ll mod){ ll res = a%mod; if(res<0)res=res + mod; return res; } ll modpow(ll a, ll n, ll mod){ ll res=1; while(n>0){ if(n&1) res=res*a%mod; a=a*a%mod; n>>=1; } return res; } ll modinv(ll a, ll mod){ ll b=mod, u=1, v=0; while(b){ ll t=a/b; a-=t*b; swap(a, b); u-=t*v; swap(u, v); } u%=mod; if(u<0)u+=mod; return u; } ll gcd(ll a, ll b){ ll r = a%b; if(r==0) return b; else return gcd(b, a%b); } bool is_prime(ll n){ ll i = 2; if(n==1)return false; if(n==2)return true; bool res = true; while(i*i <n){ if(n%i==0){ res = false; } i = i+1; } //if(i==1)res = false; if(n%i==0)res=false; return res; } /************************************** ** A main function starts from here ** ***************************************/ int main(){ ll N; cin >> N; ll ans = 1e18; rep(i, N){ ll a, p, x; cin >> a >> p >> x; if(x>a){ ans = min(ans, p); } } if(ans==1e18){ ans = -1; } cout << ans << endl; return 0; }
//...Bismillahir Rahmanir Rahim. . . #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; // typedefs... typedef double db; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<ll, ll> pll; typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset; // constants... const double PI = acos(-1); const ll mod = 998244353; // 1000000007; const int MXS = 2e5+5; const ll MXI = 1e9+5; const ll MXL = 1e18+5; const ll INF = 1e9+5; const ll INFLL = 1e18+5; const ll EPS = 1e-9; // defines... #define MP make_pair #define PB push_back #define fi first #define se second #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define si(a) scanf("%d", &a) #define sii(a, b) scanf("%d%d", &a, &b) #define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> #define boost_ ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); #define iter_(i,n) for (int i = 0; i < int(n); i++) #define for_n(i, n) for (int i = 1; i <= int(n); i++) #define print_array(a) for(int i=0;i<n;i++) cout<<a[i]<<" "; #define rev(i,n) for(int i=n;i>=0;i--) #define itr ::iterator #define s_sort(s) sort(s.begin(),s.end()) #define n_sort(a, n) sort(a,a+n) #define precise_impact cout<<setprecision(10)<<fixed; #define endl "\n" // functions... ll gcd(ll a, ll b){ while (b){ a %= b; swap(a, b);} return a;} ll lcm(ll a, ll b){ return (a/gcd(a, b)*b);} ll ncr(ll a, ll b){ ll x = max(a-b, b), ans=1; for(ll K=a, L=1; K>=x+1; K--, L++){ ans = ans * K; ans /= L;} return ans;} ll bigmod(ll a,ll b){ if(b==0){ return 1;} ll tm=bigmod(a,b/2); tm=(tm*tm)%mod; if(b%2==1) tm=(tm*a)%mod; return tm;} ll egcd(ll a,ll b,ll &x,ll &y){ if(a==0){ x=0; y=1; return b;} ll x1,y1; ll d=egcd(b%a,a,x1,y1); x=y1-(b/a)*x1; y=x1; return d;} ll modpow(ll a,ll p) {ll ans=1;while(p){if(p%2)ans=(ans*a)%mod;a=(a*a)%mod;p/=2;} return ans;} ll inverse_mod(ll n) {return modpow(n,mod-2);} //ll ncr_mod(ll n,ll r) {return (((fact[n]*inverse_mod(fact[r]))%mod)*inverse_mod(fact[n-r]))%mod;} ll dp[1000005],a[105],n,sum=0; int main() { cin>>n; for(int i=0;i<n;i++) { cin>>a[i]; sum+=a[i]; } dp[0]=1; for(int i=0;i<n;i++) { for(int j=sum;j-a[i]>=0;j--) { if(dp[j-a[i]]==1) dp[j]=1; } } ll ans=INT_MAX; for(ll i=0;i<=sum;i++) { if(dp[i]) ans=min(ans,max(i,sum-i)); } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define pii pair<double, double> #define F first #define S second int main() { ios_base :: sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >> m >> k; vector<int> faltu(n+1); while (k --) { int x; cin >> x; faltu[x] ++; } vector<pii> suf(n+n+m, {0, 0}); for (int j = n-1; j >= 0; j --) { if (faltu[j]) { suf[j] = suf[j+1]; suf[j].F ++; continue; } double co = (suf[j+1].F - (j+m+1 <= n? suf[j+m+1].F : 0))/(double)m; double val = (suf[j+1].S - (j+m+1 <= n? suf[j+m+1].S : 0))/(double)m + 1; suf[j] = {suf[j+1].F+co, suf[j+1].S+val}; // cout << j << " --> " << suf[j].F << " " << suf[j].S << endl; } double co = suf[0].F - suf[1].F; double val = suf[0].S - suf[1].S; if(co==1){ cout<<"-1"; return 0; } double ans = ((double)val/((double)1 - co)); cout << fixed << setprecision(3) << (ans) << '\n'; 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; // typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define ll long long #define scn(n) scanf("%d",&n) #define lscn(n) scanf("%lld",&n) #define lpri(n) printf("%lld",n) #define pri(n) printf("%d",n) #define pln() printf("\n") #define priln(n) printf("%d\n",n) #define lpriln(n) printf("%lld\n",n) #define rep(i,init,n) for(int i=init;i<n;i++) #define pb push_back #define mp make_pair #define F first #define S second #define gcd __gcd #define inf INT_MAX #define ninf INT_MIN #define inf INT_MAX #define linf LLONG_MAX #define lninf LLONG_MIN const int mod = 1e9 + 7; const int N = 1e5 + 4; typedef long double ld; int solve() { int n, m, k; scn(n); scn(m); scn(k); pair<ld, ld> p = {0.0, 0.0}; vector<int> mark(n + 1, 0); rep(i, 0, k) { int val; scn(val); mark[val]++; } int cnt = 0; rep(i, 1, n) { if(mark[i]) cnt++; else { if(cnt >= m) { pri(-1); return 0; } cnt = 0; } } if(cnt >= m) { pri(-1); return 0; } vector<pair<ld, ld>> v(n + m + 1, {0.0, 0.0}); for(int i = n - 1; i >= 0; i--) { p.F -= v[i + m + 1].F; p.S -= v[i + m + 1].S; if(mark[i]) { v[i].F = 1.0; } else { v[i].F = p.F / (ld)m; v[i].S = p.S / (ld)m; v[i].S += 1.0; } // cout << v[i].F << " " << v[i].S << endl; if(i == 0) cout << fixed << setprecision(10) << v[i].S / (1.0 - v[i].F); p.F += v[i].F; p.S += v[i].S; } return 0; } int main() { int t = 1; //scn(t); while(t--) { solve(); } return 0; }
/*GIVE ME AC!!!!!!*/ #include<bits/stdc++.h> #define ll long long #define MOD 1000000007 #define rep(i,n) for(int i=0;i<n;i++) using namespace std; int main() { int n; cin>>n; vector<pair<string,int>>v(n); rep(i,n){ string t; cin>>t; if(t[0]=='!'){ t.erase(0,1); v[i]=make_pair(t,1); } else{ v[i]=make_pair(t,0); } } sort(v.begin(),v.end()); int ans=0; rep(i,n-1){ if(get<0>(v[i])==get<0>(v[i+1])&&((get<1>(v[i])==1&&get<1>(v[i+1])==0)||(get<1>(v[i])==0&&get<1>(v[i+1])==1))){ ans++; cout<<get<0>(v[i])<<endl; break; } } if(ans==0){ cout<<"satisfiable"<<endl; } }
#include <bits/stdc++.h> using namespace std; int N; string S[200000]; map<string, int> str; int main() { scanf("%d", &N); for (int i = 0;i < N;i++) { cin >> S[i]; str[S[i]] = 0; } for (int i = 0;i < N;i++) { if (S[i][0] != '!') { str[S[i]] = 1; } } for (int i = 0;i < N;i++) { if (S[i][0] == '!' && str[S[i].substr(1)] == 1) { str[S[i].substr(1)] = 2; } } string ans = "satisfiable"; for (int i = 0;i < N;i++) { if (S[i][0] != '!') { if (str[S[i]] == 2) { ans = S[i]; break; } } } printf("%s\n", ans.c_str()); return 0; }
/* ___ ___ ___ ___ ___ ___ ___ _____ ___ ___ ___ / /\ /__/\ / /\ /__/\ / /\ /__/\ / /\ / /::\ / /\ / /\ / /\ / /::\ | |::\ / /::\ \ \:\ / /::\ | |::\ / /::\ / /:/\:\ / /::\ / /::\ / /::\ / /:/\:\ | |:|:\ / /:/\:\ \__\:\ / /:/\:\ | |:|:\ / /:/\:\ / /:/ \:\ / /:/\:\ / /:/\:\ / /:/\:\ / /:/ \:\ __|__|:|\:\ / /:/ \:\ ___ / /::\ / /:/~/::\ __|__|:|\:\ / /:/~/::\ /__/:/ \__\:| / /:/ \:\ / /:/ \:\ / /:/ \:\ /__/:/ \__\:\ /__/::::| \:\ /__/:/ \__\:\ /__/\ /:/\:\ /__/:/ /:/\:\ /__/::::| \:\ /__/:/ /:/\:\ \ \:\ / /:/ /__/:/ \__\:\ /__/:/ \__\:\ /__/:/ \__\:\ \ \:\ / /:/ \ \:\~~\__\/ \ \:\ / /:/ \ \:\/:/__\/ \ \:\/:/__\/ \ \:\~~\__\/ \ \:\/:/__\/ \ \:\ /:/ \ \:\ / /:/ \ \:\ / /:/ \ \:\ / /:/ \ \:\ /:/ \ \:\ \ \:\ /:/ \ \::/ \ \::/ \ \:\ \ \::/ \ \:\/:/ \ \:\ /:/ \ \:\ /:/ \ \:\ /:/ \ \:\/:/ \ \:\ \ \:\/:/ \ \:\ \ \:\ \ \:\ \ \:\ \ \::/ \ \:\/:/ \ \:\/:/ \ \:\/:/ \ \::/ \ \:\ \ \::/ \ \:\ \ \:\ \ \:\ \ \:\ \__\/ \ \::/ \ \::/ \ \::/ \__\/ \__\/ \__\/ \__\/ \__\/ \__\/ \__\/ \__\/ \__\/ \__\/ */ #include <bits/stdc++.h> #define ll long long #define pb push_back #define endl '\n' #define pii pair<ll,ll> #define F first #define S second using namespace std; const int MOD=1e9+7; const int N=1000100; long long po(int x,int y) { if(y==0)return 1; int ret=po(x,y/2)%MOD; ret*=ret; ret%=MOD; if(y%2)ret*=x,ret%=MOD; return ret; } string s; ll n,q; ll a,b,c; bool w; void solve() { cin>>n; cin>>s; cin>>q; while(q--){ cin>>c>>a>>b; a--;b--; if(c==2){ w=!w; } else{ if(!w) swap(s[a],s[b]); else swap(s[a+ (a >= n ? -n : n)],s[b+ (b >=n ? -n : n)]); } } if(w){ string tem=s.substr(0,n); s=s.substr(n,n); s+=tem; } cout<<s<<endl; } int main() { //ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); //freopen("gates.in","r",stdin);freopen("gates.out","w",stdout); int t=1; //cin>>t; while(t--){ solve(); } }
#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; // typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define ll long long #define scn(n) scanf("%d",&n) #define scn(n) scanf("%d",&n) #define lscn(n) scanf("%lld",&n) #define lpri(n) printf("%lld",n) #define pri(n) printf("%d",n) #define rep(i,init,n) for(int i=init;i<n;i++) #define pb push_back #define mp make_pair #define F first #define S second #define gcd __gcd #define inf INT_MAX #define ninf INT_MIN const int mod = 1e9 + 7; const int N = 1e6 + 4; int main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #ifndef ONLINE_JUDGE #endif ll test=1; //cin>>test; while(test--) { int n; cin>>n; string s; cin>>s; int arr[2*n]={0}; int q; cin>>q; int cnt=0; while(q--) { int t,a,b; cin>>t>>a>>b; if(t==1) { if(cnt%2==1) { if(a<=n) a=a+n; else a=a-n; if(b<=n) b=b+n; else b=b-n; swap(s[a-1],s[b-1]); } else { swap(s[a-1],s[b-1]); } } else { cnt++; } } if(cnt%2==0) { for(int i=0; i<2*n; i++) cout<<s[i]; } else { for(int i=n; i<2*n; i++) cout<<s[i]; for(int i=0; i<n; i++) cout<<s[i]; } } return 0; }
#include<bits/stdc++.h> #include<iostream> #include<string> #include<cmath> #include<cstdio> #include<cctype> #include<cstring> #include<iomanip> #include<cstdlib> #include<ctime> #include<set> #include<map> #include<utility> #include<queue> #include<vector> #include<stack> #include<sstream> #include<algorithm> /************************************************/ #define rep(i,n) for(int i=0;i<n;i++) #define m_p make_pair #define pb push_back #define fr first #define se second #define ford(i,n) for(int i=n-1;i>=0;i--) #define forn(i,a,n) for(int i=a;i<n;i++) #define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++) #define pii pair<int,int> #define vi vector<int> #define ll long long #define vll vector<ll> #define sz(s) (int)(s.size()) #define all(s) s.begin(),s.end() #define zero(x) memset(x,0,sizeof(x)) #define vii vector<pair<int,int> > #define mpis map<int,string> #define mpii map<int,int> #define mpsi map<string,int> #define re return #define mod 1000000007 /************************************************/ using namespace std; long long get(){ char c=getchar(); long long x=0LL; while(c<'0'||c>'9') c=getchar(); while(c>='0'&&c<='9'){ x*=10LL; x+=(c-'0'); c=getchar(); } return x; } string i_t_s(int x){ string t=""; while(x){ t+=x%10+'0'; x/=10; } reverse(all(t)); re t; } int s_t_i(string t){ int x=0; rep(i,sz(t)){ x=x*10+(t[i]-'0'); } re x; } ll q_p(ll x,ll y){ ll res=1; x%=mod; while(y){ if(y%2){ res=res*x; res%=mod; } y/=2; x=x*x; x%=mod; } re res; } bool ok(int x,int y,int n,int m){ re(x>=0&&x<n&&y>=0&&y<m); } bool isprime(int x){ if(x<2) re false; for(int i=2;i*i<=x;i++) if(x%i==0) re false; re true; } int dx[4]={0,-1,0,1},dy[4]={1,0,-1,0}; vi v[200001]; int n; int num; int a[200001]; bool f[200001]; void dfs(int x){ num++; f[x]=true; rep(i,sz(v[x])){ if(f[v[x][i]]) continue; dfs(v[x][i]); } } int main(){ ios::sync_with_stdio(0); cin>>n; rep(i,n) cin>>a[i]; int mx=0; rep(i,n){ mx=max(mx,a[i]); if(a[i]==a[n-1-i]) continue; v[a[i]].pb(a[n-1-i]); } int ans=0; rep(i,mx+1){ if(f[i]) continue; num=0; dfs(i); ans+=num-1; } cout<<ans; re 0; } /* 检查循环是rep(i,n)还是rep(i,m)!! long long所要的时间比int长!! 没有long long必要不写long long!! 写公式前先想一想!! 二分前看一看边界对不对,有没有特殊值!! 提交前要测特殊数据(边界上的)!! */
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <complex> #include <queue> #include <set> #include <unordered_set> #include <list> #include <chrono> #include <random> #include <iostream> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <map> #include <unordered_map> #include <stack> #include <iomanip> #include <fstream> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> p32; typedef pair<ll,ll> p64; typedef pair<double,double> pdd; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<vector<int> > vv32; typedef vector<vector<ll> > vv64; typedef vector<vector<p64> > vvp64; typedef vector<p64> vp64; typedef vector<p32> vp32; ll MOD = 998244353; double eps = 1e-12; #define forn(i,e) for(ll i = 0; i < e; i++) #define forsn(i,s,e) for(ll i = s; i < e; i++) #define rforn(i,s) for(ll i = s; i >= 0; i--) #define rforsn(i,s,e) for(ll i = s; i >= e; i--) #define ln "\n" #define dbg(x) cout<<#x<<" = "<<x<<ln #define mp make_pair #define pb push_back #define fi first #define se second #define INF 2e18 #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define all(x) (x).begin(), (x).end() #define sz(x) ((ll)(x).size()) int main() { vector<int> v(100); int i=0; while(1) { int c=getchar(); if(c=='\n') { break; } if(c=='.') { break; } v[i]=c-'0'; i++; } for(int j=0;j<i;j++) { cout<<v[j]; } return 0; }
#include <iostream> #define int long long int using namespace std; int32_t main() { int n; cin >> n; int arr[n]; for(int i = 0; i < n; i++) cin >> arr[i]; int oranges = 0; for(int i = 0; i < n; i++) { int small = arr[i]; for(int j = i; j < n; j++) { small = min(small, arr[j]); oranges = max(oranges, (j - i + 1) * small); } } cout << oranges << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define S second #define F first #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define vll vector<long long int> #define vld vector<long double> #define pll pair<long long int,long long int> /* unordered_map<int,int>mp; mp.reserve(1024); mp.max_load_factor(0.25); */ #define mod 1000000007 #define mod2 998244353 #define ll long long int #define ld long double #define pi 3.141592653589793238 #define Endl endl #define endl "\n" const int N = 1e6 + 5; const ll inf = 1e9; void solve() { ll n; cin >> n; vll a(n); map<ll,ll> f; set<ll> s; for(auto &x:a) cin >> x , s.insert(x) , f[x]++; ll ans = 0; for(auto x:s) { for(auto y:s) { ans += (x-y)*(x-y)*f[x]*f[y]; } } cout << ans/2; } void debug(ll tt) {} signed main() { FAST; int t = 1; // cin >> t; while(t--) { solve(); } }
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools #include <bits/stdc++.h> // #include "atcoder/all" using namespace std; using i64 = long long; const i64 MOD = 1e9 + 7; const i64 INF = i64(1e18) + 7; template <typename T> bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } template <typename T> bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } void solve(long long n, std::vector<long long> a, std::vector<long long> b, long long q, std::vector<long long> t, std::vector<long long> e, std::vector<long long> x){ vector<vector<int>> edges(n); for(int i = 0; i < n - 1; ++i){ --a[i], --b[i]; edges[a[i]].emplace_back(b[i]); edges[b[i]].emplace_back(a[i]); } int cnt = 0; vector<int> in(n, -1), out(n); vector<int> dep(n, 0); function<void(int)> f = [&](int x){ in[x] = cnt++; for(auto y : edges[x]){ if(in[y] != -1) continue; dep[y] = dep[x] + 1; f(y); } out[x] = cnt; }; f(0); vector<i64> imo(n + 1, 0); for(int i = 0; i < q; ++i){ int fr = (t[i] == 1 ? a[e[i] - 1] : b[e[i] - 1]); int ba = (t[i] == 2 ? a[e[i] - 1] : b[e[i] - 1]); if(dep[fr] > dep[ba]){ imo[in[fr]] += x[i]; imo[out[fr]] -= x[i]; } else{ imo[0] += x[i]; imo[in[ba]] -= x[i]; imo[out[ba]] += x[i]; } } for(int i = 0; i < n; ++i){ imo[i + 1] += imo[i]; } for(int i = 0; i < n; ++i){ cout << imo[in[i]] << endl; } } signed main(){ long long N; scanf("%lld",&N); std::vector<long long> a(N-1); std::vector<long long> b(N-1); for(int i = 0 ; i < N-1 ; i++){ scanf("%lld",&a[i]); scanf("%lld",&b[i]); } long long Q; scanf("%lld",&Q); std::vector<long long> t(Q); std::vector<long long> e(Q); std::vector<long long> x(Q); for(int i = 0 ; i < Q ; i++){ scanf("%lld",&t[i]); scanf("%lld",&e[i]); scanf("%lld",&x[i]); } solve(N, std::move(a), std::move(b), Q, std::move(t), std::move(e), std::move(x)); return 0; }
#include <bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; using namespace std; const int M = 1e9 + 7; struct mint { int value; mint() : value(0) {} template <class T> mint(T x) : value(x % M) { if (value < 0) value += M; } mint &operator-=(mint oth) { value -= oth.value; if (value < 0) value += M; return *this; } mint &operator+=(mint oth) { value += oth.value; if (value >= M) value -= M; return *this; } mint &operator*=(mint oth) { value = (long long)value * oth.value % M; return *this; } mint &operator--() { if (--value == -1) value = M - 1; return *this; } mint &operator++() { if (++value == M) value = 0; return *this; } mint operator--(int) { mint temp = *this; --*this; return temp; } mint operator++(int) { mint temp = *this; ++*this; return temp; } mint operator-() const { return mint() - *this; } mint operator+() const { return *this; } mint pow(long long e = M - 2) const { mint res = 1, b = *this; while (e > 0) { if (e % 2 == 1) { res *= b; } b *= b; e /= 2; } return res; } friend mint operator-(mint a, mint b) { return a -= b; } friend mint operator+(mint a, mint b) { return a += b; } friend mint operator*(mint a, mint b) { return a *= b; } friend bool operator==(mint a, mint b) { return a.value == b.value; } friend bool operator!=(mint a, mint b) { return a.value != b.value; } friend ostream &operator<<(ostream &out, mint a) { out << a.value; return out; } }; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<vector<pair<int, ll>>> g(n); for (int i = 1; i < n; i++) { int u, v; ll w; cin >> u >> v >> w; --u; --v; g[u].push_back({v, w}); g[v].push_back({u, w}); } vector<ll> dis(n, -1); dis[0] = 0; queue<int> q; q.push(0); while (!q.empty()) { int f = q.front(); q.pop(); for (auto to: g[f]) { if (dis[to.first] == -1) { dis[to.first] = dis[f] ^ to.second; q.push(to.first); } } } vector<int> cnt(61, 0); for (int i = 0; i < 60; i++) { ll t = 1ll << i; for (int j = 1; j < n; j++) { if (dis[j] & t) { cnt[i]++; } } } mint ans(0), pow(1); for (int j = 1; j < n; j++) { ans += mint(dis[j]); } for (int i = 0; i < 60; i++) { ans += mint(cnt[i]) * mint(n - 1 - cnt[i]) * pow; pow *= 2; } cout << ans << endl; return 0; }
//@formatter:off #include<bits/stdc++.h> #define overload4(_1,_2,_3,_4,name,...) name #define rep1(i,n) for (ll i = 0; i < ll(n); ++i) #define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i) #define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d) #define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__) #define rrep1(i,n) for (ll i = ll(n)-1; i >= 0; i--) #define rrep2(i,n,t) for (ll i = ll(n)-1; i >= (ll)t; i--) #define rrep3(i,n,t,d) for (ll i = ll(n)-1; i >= (ll)t; i-=d) #define rrep(...) overload4(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define popcount(x) __builtin_popcount(x) #define pb push_back #define eb emplace_back #ifdef __LOCAL #define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; } #else #define debug(...) void(0) #endif #define INT(...) int __VA_ARGS__;scan(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__) #define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__) using namespace std; using ll = long long; using ld = long double; using P = pair<int,int>; using LP = pair<ll,ll>; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vs = vector<string>; using vc = vector<char>; using vvc = vector<vector<char>>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vp = vector<P>; using vvp = vector<vector<P>>; template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; } template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; } template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; } template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; } template<class T> void vecout(const vector<T> &v,char div='\n') { rep(i,v.size()) cout<<v[i]<<(i==int(v.size()-1)?'\n':div);} 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;} void scan(){} template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); } template<class T> void print(const T& t){ cout << t << '\n'; } template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); } template<class... T> void fin(const T&... a) { print(a...); exit(0); } const string yes[] = {"no","yes"}; const string Yes[] = {"No","Yes"}; const string YES[] = {"NO","YES"}; const int inf = 1001001001; const ll linf = 1001001001001001001; //@formatter:on int main(){ int k; ll ans=0; cin>>k; rep(i,1,k+1){ rep(j,1,k+1){ if(i*j>k)break; ans+=k/(i*j); } } cout<<ans; }
#include "bits/stdc++.h" #include <chrono> #include <random> #define lli long long int using namespace std; #define mod 1000000007 #define mod1 998244353 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define INF 1000000000 #define common cout << "Case #" << w+1 << ": " #define MAXN 200000 int main() { int k; cin >> k; vector<int>v; for(int i=1;i<=k;i++) { for(int j=1;j<=k;j++) { if(i*j<=k) v.push_back(i*j); else break; } } sort(v.begin(),v.end()); lli ans=0; for(int i=1;i<=k;i++) { for(int j=0;j<v.size();j++) { if(i*v[j]<=k) ++ans; else break; } } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; #define LL long long //#define MOD 1000000007 #define MOD 998244353 #define INF 1000000000000000000 #define VE vector #define VL vector<LL> #define VVL VE<VL> #define VVVL VE<VVL> #define LD long double #define PB push_back #define POB pop_back #define FOR(i,a,k) for(LL i=a;i<k;i++) #define rep(i,k) FOR(i,0,k) #define ALL(a) a.begin(),a.end() #define SORT(a) sort(ALL(a)) #define REV(a) reverse(ALL(a)) #define coutl cout<<fixed<<setprecision(15)// #define MI modint<MOD> template<int mod>struct modint{ int x; modint():x(0){} modint(LL n):x(n>=0?n%mod:(mod-(-n)%mod)%mod){} modint &operator+=(const modint &n){if((x+=n.x)>=mod)x-=mod;return *this;} modint &operator-=(const modint &n){if((x+=mod-n.x)>=mod)x-=mod;return *this;} modint &operator++(){*this+=1;return *this;} modint &operator--(){*this-=1;return *this;} modint &operator*=(const modint &n){x=(int)((LL)x*n.x%mod);return *this;} modint &operator/=(const modint &n){*this*=n.inv();return *this;} modint operator-()const{return modint(-x);} modint operator+(const modint &n)const{return modint(*this)+=n;} modint operator-(const modint &n)const{return modint(*this)-=n;} modint operator++(int){modint ret(*this);*this+=1;return ret;} modint operator--(int){modint ret(*this);*this-=1;return ret;} modint operator*(const modint &n)const{return modint(*this)*=n;} modint operator/(const modint &n)const{return modint(*this)/=n;} bool operator<(const modint &n)const{return x<n.x;} bool operator>(const modint &n)const{return x>n.x;} bool operator<=(const modint &n)const{return x<=n.x;} bool operator>=(const modint &n)const{return x>=n.x;} bool operator!=(const modint &n)const{return x!=n.x;} bool operator==(const modint &n)const{return x==n.x;} friend istream &operator>>(istream &is,modint &n){LL l;is>>l;n=modint<mod>(l);return is;} friend ostream &operator<<(ostream &os,const modint &n){return os<<n.x;} int getmod(){return mod;} modint inv()const{int a=x,b=mod,c=1,d=0,n;while(b){n=a/b;swap(a-=n*b,b);swap(c-=n*d,d);}return modint(c);} modint pow(LL n)const{modint ret(1),m(x);while(n){if(n&1)ret*=m;m*=m;n>>=1;}return ret;} }; LL nanjo(LL a,LL n){//N=nanjo(a,n)AのNjooo; LL ret=1; for(LL i=0;i<n;i++){ ret*=a; } return ret; } void YesNo(bool f){ if(f)cout<<"Yes"<<endl; else cout<<"No"<<endl; } LL kakuketa(LL n){//各桁の和を求める LL a=0; while(n>0){ a=a+n%10; n=n/10; } return a; } VL yakusuu(LL N){ LL M=0; VL ret; for(LL i=0; i<N; i++){ M++; if(M>N/M){ for(LL i=0; i<N; i++){ M--; if(M==0){ return ret; } if(M*M==N){ continue; } if(N%M==0){ ret.PB(N/M); } } } if(N%M==0){ ret.PB(M); } } return ret; } int main(){ LL N,M; cin>>N>>M; cout<<N/M<<endl; }
#include<iostream> main(){ int x,y; scanf("%d%d",&x,&y); printf("%d",(6-x-y)%3); }
#include <bits/stdc++.h> #include<string> #include<queue> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ int H, W, X, Y; cin >> H >> W >> X >> Y; vector<string> S(H); rep(i, H) cin >> S.at(i); int ans = 1; for(int i = 1; i < H; i++){ if(X + i <= H && S.at(X + i -1).at(Y - 1) == '.'){ ans++; } else break; } for(int i = 1; i < H; i++){ if(X - i > 0 && S.at(X - i -1).at(Y - 1) == '.'){ ans++; } else break; } for(int i = 1; i < W; i++){ if(Y + i <= W && S.at(X -1).at(Y + i - 1) == '.'){ ans++; } else break; } for(int i = 1; i < W; i++){ if(Y - i > 0 && S.at(X -1).at(Y - i - 1) == '.'){ ans++; } else break; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int h,w,x,y; cin>>h>>w>>x>>y; x--;y--; swap(x,y); vector<string> s(h); for(int i=0;i<h;i++){ cin>>s[i]; } int ans=1; for(int i=1; x+i<w && s[y][x+i]!='#' ;i++)ans++; for(int i=1; x-i>=0 && s[y][x-i]!='#' ;i++)ans++; for(int i=1; y+i<h && s[y+i][x]!='#' ;i++)ans++; for(int i=1; y-i>=0 && s[y-i][x]!='#' ;i++)ans++; cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define REP(i, s, n) for (int i = s; i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define MOD 1000000007 using namespace std; using ll = long long; int main() { int N, Q; cin >> N; vector<int> A(N), T(N); REP(i, 0, N) cin >> A[i] >> T[i]; cin >> Q; vector<ll> X(Q); REP(i, 0, Q) cin >> X[i]; set<ll> S; REP(i, 0, Q) S.insert(X[i]); ll offset = 0; REP(i, 0, N) { if (T[i] == 1) { offset += A[i]; } else if (T[i] == 2) { auto itr = S.lower_bound(A[i] - offset); bool deleted = false; auto jtr = S.begin(); while (jtr != itr) { jtr = S.erase(jtr); deleted = true; } if (deleted) { S.insert(A[i] - offset); } } else { auto itr = S.lower_bound(A[i] - offset); bool deleted = false; while (itr != S.end()) { itr = S.erase(itr); deleted = true; } if (deleted) { S.insert(A[i] - offset); } } } // for (auto x : S) cout << x << " "; // cout << endl; REP(i, 0, Q) { auto itr = S.lower_bound(X[i]); if (itr != S.begin() && (itr == S.end() || *itr > X[i])) itr = prev(itr); // cout << "# i : " << i << ", X[i] : " << X[i] << ", itr : " << *itr << endl; cout << *itr + offset << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<n; i++) typedef pair<int,int> P; typedef long long ll; const int INF = 1001001001; const ll INFL = 1e17; const int MOD = 1e+9+7; int main(){ int n,k; ll ans = 0; cin >> n >> k; vector<vector<int>> t(n,vector<int>(n)); for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ cin >> t[i][j]; } } vector<int> perm(n-1); for(int i=0; i<n-1; i++){ perm[i] = i; } do{ int now = 0; int prev; ll sum = 0; for(int i=0; i<n-1; i++){ prev = now; now = perm[i]+1; sum += t[prev][now]; } sum += t[now][0]; if(sum == k) ans++; }while(next_permutation(perm.begin(),perm.end())); cout << ans << endl; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> #ifndef LOCAL #pragma GCC target("arch=skylake-avx512") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; static const double EPS = 1e-12; static const double PI = acos(-1.0); #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(a) (a).begin(), (a).end() #ifdef LOCAL #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define dbg(...) 42 #endif const int MAX = 1'000'001; bool is_prime[MAX + 1]; int min_factor[MAX + 1]; vector<int> primes; ll f(ll y, ll R, ll i) { return R / y - i / y; } void solve(long long L, long long R) { fill_n(is_prime, MAX + 1, true); is_prime[0] = is_prime[1] = false; min_factor[0] = 0; min_factor[1] = 1; for (int i = 2; i <= MAX; ++i) { if (is_prime[i]) { min_factor[i] = i; for (long long j = static_cast<long long>(i) * i; j <= MAX; j += i) { is_prime[j] = false; if (min_factor[j] == 0) min_factor[j] = i; } } } ll ans = 0; FOR(i, max(2ll, L), R) { set<ll> s; auto j = i; while (j > 1) { auto k = min_factor[j]; s.insert(k); j = j / k; } vector<ll> v(s.begin(), s.end()); ll a = -f(i, R, i); FOR(k, 1, 1 << v.size()) { int count = __builtin_popcount(k); ll y = 1; REP(l, v.size()) { if ((k >> l) & 1) { y *= v[l]; } } a += (count % 2 == 1 ? +1 : -1) * f(y, R, i); } ans += a; } cout << ans * 2 << endl; } int main() { long long L; std::scanf("%lld", &L); long long R; std::scanf("%lld", &R); solve(L, R); return 0; }
#include <iostream> #include <string> #include <vector> #include <deque> #include <queue> #include <algorithm> #include <iomanip> #include <set> #include <map> #include <bitset> #include <cmath> #include <functional> using namespace std; #define REP(i,n) for(ll (i) = (0);(i) < (n);++i) #define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i) #define SHOW1d(v,n) {REP(W,n)cerr << v[W] << ' ';cerr << endl << endl;} #define SHOW2d(v,i,j) {REP(aaa,i){REP(bbb,j)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;} #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define ALL(v) v.begin(),v.end() #define Decimal fixed<<setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL #define MOD 1000000007LL typedef long long ll; typedef pair<ll,ll> P; template<typename T> void show_vector(vector<T> v) { for (auto ele: v)cout << ele << " " ;cout << endl; } template<typename T> void show_vector(vector<vector<T>> v) { for (auto ele: v)show_vector(ele); } template<typename T> void show_vector(vector<vector<vector<T>>> v) { for (auto ele: v) { show_vector(ele); cout << endl; } } vector<vector<P>> v(200200); ll mp[2]; ll ans; void dfs(int now, int pre, ll val, ll shift) { mp[val > 0]++; REP(i, v[now].size()) { if (v[now][i].FI == pre) continue; dfs(v[now][i].FI, now, val ^ (v[now][i].SE & (1LL << shift)), shift); } } int main(){ cin.tie(0);cout.tie(0);ios::sync_with_stdio(false); ll n;cin >> n; REP(i, n-1) { ll a, b, w;cin >> a >> b >> w; a--;b--; v[a].EB(b, w); v[b].EB(a, w); } REP(i, 60) { mp[0] = 0; mp[1] = 0; dfs(0, -1, 0, i); ans += ((1LL << i) % MOD) * (mp[0] * mp[1] % MOD) % MOD; ans %= MOD; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define int long long #define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> #define M 1000000007 #define N 100010 //#define endl '\n' int gcd(int a,int b){ if(b==0){ return(a); } return(gcd(b,a%b)); } int findPow(int i,int p,int m){ if(p==0){ return(1); } int res=findPow(i,p/2,m); if(p%2==0){ return((res*res)%m); } else{ return((((res*res)%m)*i)%m); } } int modInverse(int val,int m){ return(findPow(val,m-2,m)); } void solve(){ string s; cin >> s; int cnt=0,n=s.length(); for(int i=0;i<=n-4;i++){ string a="ZONe"; int flag=0; for(int j=0;j<4;j++){ if(s[i+j]!=a[j]){ flag=1; break; } } if(flag==0){ cnt++; } } cout << cnt << endl; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int t=1; // cin >> t; while(t--){ solve(); } }
#include<bits/stdc++.h> using namespace std; typedef int64_t ll; typedef long double ld; const ll MOD=1000000007; const ll MODA=998244353; ll vx[4]={0,1,0,-1}; ll vy[4]={1,0,-1,0}; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) long long gcd(long long a,long long b){ ll gcdmax=max(a,b); ll gcdmin=min(a,b); while(true){ if(gcdmax%gcdmin==0)break; else gcdmax%=gcdmin; swap(gcdmin,gcdmax); } return gcdmin; } ll pow(ll N,ll P,ll M){ if(P==0)return 1; else if(P%2==0){ ll t=pow(N,P/2,M); return t*t%M; } else return N*pow(N,P-1,M)%M; } vector<ll> find_divisor(ll N){ ll k=1; while(k*k<=N){ k++; } vector<ll> A(1); rep(i,k){ if(i==1)A.at(0)=1; else if(i>=2){ if(N%i==0)A.push_back(i); } } ll t=0; t=A.size(); rep(i,t){ if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i)); } return A; } vector<ll> fac; vector<ll> finv; vector<ll> inv; void COMinit(ll N,ll P){ rep(i,N+1){ if(i==0){ fac.push_back(1); finv.push_back(1); inv.push_back(1); } else if(i==1){ fac.push_back(1); finv.push_back(1); inv.push_back(1); } else{ fac.push_back(fac.at(i-1)*i%P); inv.push_back(P-inv.at(P%i)*(P/i)%P); finv.push_back(finv.at(i-1)*inv.at(i)%P); } } } ll COM(ll n,ll k,ll P){ if(n<k)return 0; if(n<0||k<0)return 0; return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P; } struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化 for(ll i = 0; i < N; i++) par[i] = i; } ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(ll x, ll y) { // xとyの木を併合 ll rx = root(x); //xの根をrx ll ry = root(y); //yの根をry if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; int main(){ ll N; cin>>N; vector<ll> A(N); rep(i,N){ cin>>A.at(i); } ll ans=0; rep(i,N){ ll sum=0; for(ll j=i;j>=0;j--){ if(A.at(j)>=A.at(i))sum+=A.at(i); else break; } for(ll j=i+1;j<N;j++){ if(A.at(j)>=A.at(i))sum+=A.at(i); else break; } ans=max(ans,sum); } cout<<ans<<endl; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll ans = 0; int commaCnt = 1; bool exist = false; if (n >= 1000){ exist = true; } while(exist){ ll maxNum = pow(1000, commaCnt + 1) - 1; if(n > maxNum){ ans += commaCnt * (maxNum - pow(1000, commaCnt) + 1); } else { ans += commaCnt * (n - pow(1000, commaCnt) + 1); exist = false; } commaCnt++; } cout << ans << endl; }
#include <iostream> #include <vector> #include <array> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <utility> #include <string> #include <sstream> #include <algorithm> #include <random> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <cmath> #include <cassert> #include <climits> #include <bitset> #include <functional> #include <iomanip> #include <random> #define FOR_LT(i, beg, end) for (decltype(end) i = beg; i < end; i++) #define FOR_LE(i, beg, end) for (decltype(end) i = beg; i <= end; i++) #define FOR_DW(i, beg, end) for (decltype(beg) i = beg; end <= i; i--) #define REP(n) for (decltype(n) repeat_index = 0; repeat_index < n; repeat_index++) using namespace std; template<typename T, size_t S> T minval(const T(&vals)[S]) { T val = numeric_limits<T>::max(); FOR_LT(i, 0, S) { val = min(val, vals[i]); } return val; } template<typename T, size_t S> T maxval(const T(&vals)[S]) { T val = numeric_limits<T>::min(); FOR_LT(i, 0, S) { val = max(val, vals[i]); } return val; } int64_t eval(array<int, 5>& assign, vector<array<int64_t, 32>>& vals) { int64_t ans = INT64_MAX; FOR_LT(i, 0, 3) { int64_t s = 0; FOR_LT(j, 0, 5) { if (assign[j] == i) s += (1 << j); } if (s == 0) continue; int64_t ca = 0; FOR_LT(k, 0, vals.size()) { ca = max(ca, vals[k][s]); } ans = min(ans, ca); } return ans; } int64_t solve(int i, array<int, 5>& assign, vector<array<int64_t, 32>>& vals) { if (i == 5) { return eval(assign, vals); } int64_t ans = 0; FOR_LT(j, 0, 3) { assign[i] = j; ans = max(ans, solve(i + 1, assign, vals)); } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(20); int64_t n; cin >> n; vector<array<int64_t, 5>> as(n); FOR_LT(i, 0, n) { FOR_LT(j, 0, 5) { cin >> as[i][j]; } } int64_t mv = 1; REP(5) mv *= 5; vector<array<int64_t, 32>> vals(n); FOR_LT(i, 0, n) { FOR_LT(j, 0, 32) { int64_t c = INT_MAX; FOR_LT(k, 0, 5) { if (j & (1 << k)) c = min(c, as[i][k]); } vals[i][j] = c; } } array<int, 5> assign; assign[0] = 0; cout << solve(1, assign, vals) << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,x,y; cin>>a>>b>>x>>y; if(a==b){ printf("%d",x); } else if(a>b){ int ans1=(a-b+a-b-1)*x; int ans2=(a-b-1)*y+x; printf("%d",min(ans1,ans2)); } else{ int ans1=(b-a+1+b-a)*x; int ans2=(b-a)*y+x; printf("%d",min(ans1,ans2)); } }
#include<bits/stdc++.h> using namespace std; int a,b,x,y,f[110][110]; int main(){ scanf("%d%d%d%d",&a,&b,&x,&y); memset(f,0x3f,sizeof(f)); f[a][0]=0; f[a][1]=x; if(a<b){ for(int i=a+1;i<=b;i++){ for(int j=0;j<=1;j++) f[i][j]=min(f[i-1][j]+y,f[i-1][j^1]+x+y); f[i][0]=min(f[i][0],f[i-1][1]+x); f[i][0]=min(f[i][0],f[i][1]+x); f[i][1]=min(f[i][1],f[i][0]+x); } } else { for(int i=a-1;i>=b;i--){ for(int j=0;j<=1;j++) f[i][j]=min(f[i+1][j]+y,f[i+1][j^1]+x+y); f[i][1]=min(f[i][1],f[i+1][0]+x); f[i][0]=min(f[i][0],f[i][1]+x); f[i][1]=min(f[i][1],f[i][0]+x); } } printf("%d\n",f[b][1]); return 0; }
#include<bits/stdc++.h> using namespace std; #define MOD 1000000007 //#define MOD 998244353 #define EPS 1e-9 #define F first #define S second #define debug(x) cout<<x<<endl; #define repi(i,x,n) for(int i=x;i<n;i++) #define rep(i,n) repi(i,0,n) #define lp(i,n) repi(i,0,n) #define repn(i,n) for(int i=n;i>=0;i--) #define int long long #define endl "\n" #define N 55 typedef pair<int,int> PII; typedef pair<int,string> PIS; typedef pair<string,int> PSI; int prime[N]; vector<int> p; int n; int INF=1; void eratosthenes(){ rep(i,N) prime[i]=1; prime[0]=prime[1]=0; rep(i,N){ if(prime[i]){ for(int j=i+i;j<N;j+=i) prime[j]=0; } } } int solve(vector<int> x,int a,int num){ //cout<<a<<endl; int ret=INF; if(a==p.size() ){ rep(i,n){ if(x[i]!=0) return ret; } return num; } ret=min(solve(x,a+1,num),ret); rep(i,n){ if(x[i]%p[a]==0){ x[i]=0; } } ret=min(solve(x,a+1,num*p[a]),ret); return ret; } signed main(){ // cin.tie(0); //ios::sync_with_stdio(false); cin>>n; eratosthenes(); rep(i,51){ if(prime[i]==1) {INF*=i;p.push_back(i);} } vector<int> x(n); rep(i,n){ cin>>x[i]; //cout<<x[i]<<endl; } cout<<solve(x,0,1)<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; #define pb push_back #define mp make_pair #define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #define ff first #define ss second #define INF (ll) (1e9) #define mod (ll) (1e9 + 7) #define endl "\n" #define tt ll testcase; cin>>testcase; while(testcase--) const int mxn = 1*(1e5) + 5; ll n, m; void solve(){ char s, t; cin >> s >> t; if(s == 'Y') { if(t == 'A' || t == 'B' || t == 'C') { cout<<t; } else if(t == 'a') { cout << 'A'; }else if(t == 'b') { cout << 'B'; }else if(t == 'c') { cout << 'C'; } } else { cout<<t; } } int main(){ fast; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // tt solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define MAXN 200005 #define lowbit(x) (x&-x) #define reg register #define mkpr make_pair #define fir first #define sec second typedef long long LL; typedef unsigned long long uLL; const int INF=0x3f3f3f3f; const int mo=998244353; const LL jzm=2333; const int iv2=499122177; const double Pi=acos(-1.0); typedef pair<int,int> pii; const double PI=acos(-1.0); template<typename _T> _T Fabs(_T x){return x<0?-x:x;} template<typename _T> void read(_T &x){ _T f=1;x=0;char s=getchar(); while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();} while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();} x*=f; } template<typename _T> void print(_T x){if(x<0){x=(~x)+1;putchar('-');}if(x>9)print(x/10);putchar(x%10+'0');} int n,k,head[MAXN],tot,lim,hei[MAXN],sum; struct edge{int to,nxt;}e[MAXN<<1]; void addEdge(int u,int v){e[++tot]=(edge){v,head[u]};head[u]=tot;} void dosaka(int u,int fa){ int mx1=0,mx2=0;if(!head[u]){hei[u]=0;return ;} for(int i=head[u];i;i=e[i].nxt){ int v=e[i].to;if(v==fa)continue;dosaka(v,u); if(hei[v]>=0)mx1=max(mx1,hei[v]+1); else mx2=max(mx2,-hei[v]-1); } if(mx2>mx1)hei[u]=-mx2;else hei[u]=mx1; if(hei[u]>=lim||(u==1&&hei[u]>=0))hei[u]=-lim-1,sum++; //printf("dosaka%d:%d\n",u,hei[u]); } bool check(int mid){ for(int i=1;i<=n;i++)hei[i]=0; lim=mid;sum=0;dosaka(1,0);return sum<=k; } signed main(){ read(n);read(k); for(int i=1;i<n;i++){ int u,v;read(u);read(v); addEdge(u,v);addEdge(v,u); } int l=1,r=n;if(k>=n){puts("0");return 0;} while(l<r){int mid=l+r>>1;if(check(mid))r=mid;else l=mid+1;} printf("%d\n",l); return 0; }
/* /^--^\ \____/ / \ _____ _ __ __ ____ _ ____ ____ _____ | || ()_)| |\ \/ /| ===|| |__ / (__` / () \|_ _| \__ __/ |_| |_|/_/\_\|____||____|\____)/__/\__\ |_| |^|^\ \^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^| | | |\ \| | | | | | | | | | | | | | | | | | | | | | | | | #####/ /################################################# | | |\/ | | | | | | | | | | | | | | | | | | | | | | | | | |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|*/ //#pragma GCC optimize("O4,unroll-loops,no-stack-protector") #include <bits/stdc++.h> #define int ll //__int128 #define double long double using namespace std; using ll=long long; using ull=unsigned long long; using pii=pair<int,int>; #define For(i,a,b) for(int i=a;i<=b;i++) #define Fors(i,a,b,s) for(int i=a;i<=b;i+=s) #define Forr(i,a,b) for(int i=a;i>=b;i--) #define F first #define S second #define L(id) (id*2+1) #define R(id) (id*2+2) #define LO(x) (x&(-x)) #define eb emplace_back #define all(x) x.begin(),x.end() #define sz(x) ((int)x.size()) #define mkp make_pair #define MOD (int)(1000000007) #define INF (int)(1e12) #define EPS (1e-7) #ifdef NYAOWO #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 ...tail) { cerr << x << ", "; _OUT(tail...); } inline void USACO(const string &s) { cerr<<"USACO: "<<s<<"\n"; } #else #define debug(...) inline void USACO(const string &s){ freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } #endif inline void NYA(){ ios::sync_with_stdio(false); cin.tie(0); } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); //int gcd(int a,int b) { return b==0?a:gcd(b,a%b); } inline int gcd(int a,int b) { return __gcd(a,b); } inline int lcm(int a,int b) { return a/gcd(a,b)*b; } int fpow(int b,int p,const int &mod){ int ans=1; while(p){ if(p&1) ans=ans*b%mod; p/=2; b=b*b%mod; } return ans; } int fpow(int b,int p) { return fpow(b,p,MOD); } template<typename T> inline void chmin(T &_a,const T &_b) { if(_b<_a) _a=_b; } template<typename T> inline void chmax(T &_a,const T &_b) { if(_b>_a) _a=_b; } int dis[1010][1010]; vector<int> adj[1010][26]; int32_t main(){ NYA(); //nachoneko so cute >/////< int n,m; cin>>n>>m; memset(dis,-1,sizeof(dis)); priority_queue<pair<int,pii>,vector<pair<int,pii>>,greater<pair<int,pii>>> pq; //pair( dist , pair( s,t ) ) where s<=t For(i,1,n) pq.emplace(0,mkp(i,i)); while(m--){ int a,b; cin>>a>>b; char ch; cin>>ch; adj[a][ch-'a'].eb(b); adj[b][ch-'a'].eb(a); if(a>b) swap(a,b); pq.emplace(1,mkp(a,b)); } while(!pq.empty()){ int d=pq.top().F; int s=pq.top().S.F; int t=pq.top().S.S; pq.pop(); if(dis[s][t]!=-1) continue; dis[s][t]=d; For(ch,0,25){ for(auto &a:adj[s][ch]) for(auto &b:adj[t][ch]){ int x=min(a,b),y=max(a,b); if(dis[x][y]==-1) pq.emplace(d+2,mkp(x,y)); } } } cout<<dis[1][n]<<"\n"; return 0; }
/* Author : */ #include <bits/stdc++.h> using namespace std; #define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) #define pb push_back #define ll long long #define rep(i,n) for(ll i=0;i<n;i++) #define rep1(i,n) for(ll i=n-1;i>=0;i--) #define repi(i,n) for(ll i=1;i<=n;i++) #define mem(arr,x) memset(arr,x,sizeof(arr)) typedef vector<ll> vi; typedef vector<char> vc; #define mp make_pair #define ss second const int MAX=100005; const int mod = 1e9 + 7; const int inf = 1e9 + 5; int min(int a,int b) { if(a<b) return a; return b; } void solve() { ll n; cin>>n; vector<pair<int,int>>v; ll a,q,ans=0; for(int i=0;i<n;i++) { cin>>a>>q; v.pb(mp(a,q)); } for(int i=0;i<n;i++) { int a=v[i].first; int b=v[i].second; for(int j=i+1;j<n;j++) { int a1=v[j].first; int b1=v[j].second; if(a1==a) continue; float p=b1-b; float q=a1-a; float bb=(float)p/q; if(bb>=-1.0 && bb<=1.0) ++ans; } } cout<<ans<<'\n'; } int main() { fast_io; int T=1; //cin>>T; while(T--) { solve(); } }
#include <iostream> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> #include <random> #include <iomanip> #include <functional> #include <cassert> #include <bitset> #include <chrono> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int n; cin >> n; vector <int> x(n), y(n); for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i]; } vector <int> ix(n), iy(n); iota(ix.begin(), ix.end(), 0); iota(iy.begin(), iy.end(), 0); sort(ix.begin(), ix.end(), [&] (int i, int j) { return x[i] < x[j]; }); sort(iy.begin(), iy.end(), [&] (int i, int j) { return y[i] < y[j]; }); vector <int> intr; for (int i = 0; i < min(n, 3); ++i) { intr.push_back(ix[i]); intr.push_back(iy[i]); } for (int i = 0; i < min(n, 3); ++i) { intr.push_back(ix[n - i - 1]); intr.push_back(iy[n - i - 1]); } sort(intr.begin(), intr.end()); intr.resize(unique(intr.begin(), intr.end()) - intr.begin()); vector <int> vals; for (int i : intr) { for (int j : intr) { if (i < j) { vals.push_back(max(abs(x[i] - x[j]), abs(y[i] - y[j]))); } } } sort(vals.rbegin(), vals.rend()); cout << vals[1] << '\n'; }
#include <bits/stdc++.h> using namespace std; int n,m; vector<int> adj[21]; int vis[21]; vector<int> nxt[21]; int par[21]; void dfs(int x) { vis[x]=1; for (int y : adj[x]) if (!vis[y]) { nxt[x].push_back(y); par[y]=x; dfs(y); } } int color[21]; int solve(int x) { int r = 0; for(int c = 0; c < 3; c++) { int ok=1; for (int z : adj[x]) if (color[z]==c) ok=0; if (!ok) continue; color[x]=c; int rc=1; for (int y : nxt[x]) { rc*=solve(y); } r+=rc; } color[x]=-1; return r; } int main() { cin >> n >> m; for(int i = 0; i < m; ++i){ int a,b; cin >> a >> b; a--; b--; adj[a].push_back(b); adj[b].push_back(a); } long long r=1; for(int i = 0; i < n; i++) { color[i]=-1; par[i]=-1; } for(int i = 0; i < n; i++) if (!vis[i]) { dfs(i); r*=solve(i); } cout << r << endl; return 0; }
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<vector> //#define puts sdf using std::vector; //using std::cout; //using std::endl; using std::sort; using std::swap; using std::min; using std::max; int read(){//int 无负数 int h=0;char c=getchar(); while(c<'0'||c>'9')c=getchar(); while(c>='0'&&c<='9')h=(h<<1)+(h<<3)+c-'0',c=getchar(); return h; } const int MAXN=200100; int K,n; struct Edge{ int to; int nxt; }edge[MAXN<<1]; int frm[MAXN]; int cnt_e; void insert_e(int u,int v){ cnt_e++; edge[cnt_e].to=v; edge[cnt_e].nxt=frm[u]; frm[u]=cnt_e; } int Fa[MAXN]; int Rt,mns,S; int siz[MAXN]; bool vis[MAXN]; void get_rt(int x,int ff){ siz[x]=1;int mxs=0; for(int i=frm[x];i;i=edge[i].nxt){ int v=edge[i].to;if(v==ff||vis[v])continue; get_rt(v,x); siz[x]+=siz[v]; mxs=max(mxs,siz[v]); } mxs=max(mxs,S-siz[x]); if(mxs<mns)Rt=x,mns=mxs; } int Dt[MAXN];//点分树上的深度 int dis[MAXN][21]; //x到点分树上深度为D的那个祖先的距离 int mndis[MAXN];//距离他最近的点 void get_dis1(int U,int x,int ff,int dep,int D){ dis[x][D]=dep; for(int i=frm[x];i;i=edge[i].nxt){ int v=edge[i].to;if(v==ff||vis[v])continue; get_dis1(U,v,x,dep+1,D); } } void divide(int x,int D){//D是点分树上的深度 vis[x]=true; Dt[x]=D; get_dis1(x,x,x,0,D); for(int i=frm[x];i;i=edge[i].nxt){ int v=edge[i].to;if(vis[v])continue; S=siz[v],mns=siz[v],get_rt(v,v); Fa[Rt]=x;divide(Rt,D+1); } } void Modify(int x){ int rt=x; for(;rt;rt=Fa[rt]){ mndis[rt]=min(mndis[rt],dis[x][Dt[rt]]); // cout<<"MODIFY"<<x<<" "<<rt<<" "<<mndis[rt]<<endl; } } bool Query(int x,int mid){ int rt=x; for(;rt;rt=Fa[rt]){ // cout<<"QUERY "<<x<<' '<<rt<<" "<<mndis[rt]<<' '<<dis[x][Dt[rt]]<<endl; if(mndis[rt]+dis[x][Dt[rt]]<=mid)return true; } return false; } int fa[MAXN][19]; int dep[MAXN]; int qwq[MAXN];//按深度排序 bool cmp(int x,int y){ return dep[x]>dep[y]; } void pre_dfs(int x,int ff){ fa[x][0]=ff;dep[x]=dep[ff]+1; for(int i=1;i<=18;i++)fa[x][i]=fa[fa[x][i-1]][i-1]; for(int i=frm[x];i;i=edge[i].nxt){ int v=edge[i].to;if(v==ff)continue; pre_dfs(v,x); } } int get_fa(int x,int k){ int nw=x; for(int i=0;i<=18;i++){ if(k&(1<<i))nw=fa[nw][i]; } return nw; } bool ch_ck(int mid){ // cout<<"MID"<<':'<<mid<<endl; memset(mndis,0x3f,sizeof(mndis)); // for(int i=1;i<=n;i++)mndis[i]=-0x3f3f3f3f; int cnt=0; for(int i=1;i<=n;i++){ int x=qwq[i]; if(Query(x,mid))continue; int fk=get_fa(x,mid); cnt++;Modify(fk); // cout<<"WORK"<<x<<" "<<fk<<endl; if(cnt>K)return false; } return true; } int get_ans(){ int l=0,r=n; while(l+1<r){ int mid=(l+r)>>1; if(ch_ck(mid)){ r=mid; } else l=mid+1; } if(l==r)return r; if(ch_ck(l))return l; return r; } int main(){ n=read(),K=read(); for(int i=1;i<=n-1;i++){ int u=read(),v=read(); insert_e(u,v),insert_e(v,u); } S=n,mns=n,get_rt(1,1); divide(Rt,0); pre_dfs(1,1); for(int i=1;i<=n;i++)qwq[i]=i;sort(qwq+1,qwq+n+1,cmp); // for(int i=1;i<=n;i++)cout<<qwq[i]<<" ";puts(""); // for(int i=1;i<=n;i++){ // for(int j=0;j<=18;j++)cout<<fa[i][j]<<" ";puts(""); // } printf("%d\n",get_ans()); return 0; }
/* weak weak we ak we akwea weak we weak weak we ak weak weak we ak we weakweak we ak wea ak we akwe wea we ak we ak we akwe wea we ak we ak we akwe wea eak weak we ak we ak we wea wea ak we ak weak we we we ak wea ak weak we we ak wea weak wea eak we we ak we ak wea wea we we weak we ak we we we we we we ak we we we we we wea weak wea wea weak weak weak wea akw weak weak */ using namespace std; #include <vector> #include <queue> #include <algorithm> #include <cmath> #include <utility> #include <bitset> #include <set> #include <string> #include <stack> #include <iomanip> #include <map> #include <memory.h> #include <deque> #define pb push_back #define pii pair<int,int> #define F first #define S second #define LL long long #define mid (LB+RB)/2 #define vvl vector <vector<LL>> #define vl vector <LL> #define mkp make_pair //iterators #define iter(x) x.begin(),x.end() #define aiter(a,n) a,a+n //loops #define REP(n) for (int ___=n;___--;) #define REP0(i,n) for (int i=0;i<n;++i) #define REP1(i,n) for (int i=1;i<=n;++i) #define FOR(i,b,l,k) for (int i=b;i!=l;i+=k) #define forEach(i,v) for (auto i:v) /* yungyao so weeeeeeeeeeeeeeeeeeeeeeeeeeak 8e7 so dian FHVirus so dian youou so dian KYW so dian hubert so dian jass so dian tingyu so dian panda so dian */ //IO #include <iostream> #define theyRSOOOOOOOOODIAN ios_base::sync_with_stdio(false),cin.tie(0); //testing some stuff, still under construction //a lot more useful while debug inline void print(vector <int> v){ for (auto i:v) cout << i << ' '; cout << '\n'; } inline void print(vector <int> v,char sep,char end){ for (auto i:v) cout << i << sep; cout << end; } //constants #include <climits> const int maxn = 2020,mod = 0; //workspace inline void solve(){ int n; pair<double,double> seg[maxn]{}; cin >> n; REP1(i,n){ int t; cin >> t >> seg[i].F >> seg[i].S; if (t == 2) seg[i].S -= 0.1; else if (t == 3) seg[i].F += 0.1; else if (t == 4) seg[i].S -= 0.1,seg[i].F += 0.1; } int cnt = 0; REP1(i,n){ for (int j=i+1;j<=n;++j){ auto [l1,r1] = seg[i]; auto [l2,r2] = seg[j]; if (l1 <= r2 && l2 <= r1) ++cnt; } } cout << cnt; } signed main(){ theyRSOOOOOOOOODIAN //for (int ;cin;)//use in multi-testcases and end in EOF problems //int t,i=1;for (cin >> t;i<=t;++i)//use in multi-testcases problems //cout << "Case #" << i << ": ",//use in Google, FB competitions solve();//always used return 0; }
#include <bits/stdc++.h> //#include<boost/multiprecision/cpp_int.hpp> //#include<boost/multiprecision/cpp_dec_float.hpp> //#include <atcoder/all> using namespace std; #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a; i > -1; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a; i > b; --i) #define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define popcount __builtin_popcount #define popcountll __builtin_popcountll #define fi first #define se second using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll mod_998244353 = 998244353; constexpr ll INF = 1LL << 60; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") // using lll=boost::multiprecision::cpp_int; // using // Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<128>>;//仮数部が1024桁 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; } ll mypow(ll x, ll n, const ll &p = -1) { // x^nをmodで割った余り if (p != -1) { x = (x % p + p) % p; } ll ret = 1; while (n > 0) { if (n & 1) { if (p != -1) ret = (ret * x) % p; else ret *= x; } if (p != -1) x = (x * x) % p; else x *= x; n >>= 1; } return ret; } struct myrand{ random_device seed; mt19937 mt; myrand():mt(seed()){} int operator()(int a,int b){//[a,b) uniform_int_distribution<int>dist(a,b-1); return dist(mt); } }; // using namespace atcoder; //------------------------ //------------------------ //------------------------ //------------------------ //------------------------ template<typename T> struct edge{ int to; T c,d; edge(int to,T c,T d):to(to),c(c),d(d){} }; template<typename T> vector<T> dijkstra(vector<vector<edge<T>>> &g,int s){//sは始点 const auto INFTY=numeric_limits<T>::max();//2回以上使うときはオーバーフローに気をつける(INFTYのときはif文で弾くなど) vector<T>dist(g.size(),INFTY); using P=pair<T,int>;//firstは最短距離,secondは頂点の番号 priority_queue<P,vector<P>,greater<P>>pq; dist[s]=0; pq.emplace(dist[s],s); while(!pq.empty()){ auto x=pq.top();pq.pop(); int v=x.second; if(dist[v]<x.first)continue;//最短距離でなければ飛ばす for(auto e:g[v]){ ll stop=max(0LL,ll(sqrt(e.d)-1)); if(chmin(dist[e.to],dist[v]+e.c+e.d/(dist[v]+1))){ pq.emplace(dist[e.to],e.to); } rep(i,2){ if(dist[v]<stop&&chmin(dist[e.to],stop+e.c+e.d/(stop+1))){ pq.emplace(dist[e.to],e.to); } stop++; } } } return dist; } void solve() { int n,m; cin>>n>>m; vector<vector<edge<ll>>>g(n); rep(i,m){ int a,b; ll c,d; cin>>a>>b>>c>>d; a--;b--; g[a].eb(b,c,d); g[b].eb(a,c,d); } auto d=dijkstra<ll>(g,0); if(d[n-1]==numeric_limits<ll>::max()){ cout<<-1; }else{ cout<<d[n-1]<<"\n"; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); solve(); return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; typedef long long ll; typedef vector<ll> vint; typedef vector< vector<ll> > vvint; #define rep(i,n) for(ll i=0;i<n;i++) #define repf(i,f,n) for(ll i=f;i<n;i++) #define repr(i,n) for(ll i=n-1;i>=0;i--) #define mp make_pair #define mt make_tuple #define ALL(obj) (obj).begin(), (obj).end() template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } int dy[]={0, 0, 1, -1, 1, -1, -1, 1}; int dx[]={1, -1, 0, 0, 1, 1, -1, -1}; int main() { cout<<fixed<<setprecision(10); ll n; cin>>n; string s; cin>>s; vint a(n+1,0), t(n+1,0), c(n+1,0), g(n+1,0); rep(i,s.size()){ a[i+1] = a[i]; t[i+1] = t[i]; c[i+1] = c[i]; g[i+1] = g[i]; if(s[i] == 'A') a[i+1]++; if(s[i] == 'T') t[i+1]++; if(s[i] == 'C') c[i+1]++; if(s[i] == 'G') g[i+1]++; } ll ans = 0; rep(l,n+1){ rep(r,n+1){ if(!(l < r)) continue; if(a[r] - a[l] == t[r] - t[l] and c[r] - c[l] == g[r] - g[l]) ans++; } } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define MOD 1000000007 #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL); #define all(v) (v).begin() , (v).end() #define sumof(v) accumulate(all(v), 0LL, plus<ll>()) #define maxof(v) max_element(all(v)) #define minof(v) min_element(all(v)) #define unique(a) a.resize(unique(a.begin(), a.end()) - a.begin()) #define inf INT_MAX #define VI vector<ll> #define VII vector<pair<ll, ll>> #define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n' ll add(ll x, ll y){ x+=y; while(x>=MOD) x-=MOD; while(x<0) x+=MOD; return x; } ll mul(ll x, ll y){ return (x * 1ll * y) % MOD; } ll binpow(ll x, ll y){ ll ans = 1; while(y>0){ if(y%2==1){ ans = mul(ans, x); } x = mul(x, x); y /= 2; } return ans; } ll divide(ll x, ll y){ return mul(x, binpow(y, MOD-2)); } int main(){ FASTIO int testCases = 1, testCaseCount = 1; // cin>>testCases; while(testCases--){ // cout<<"Case #"<<testCaseCount++<<":"; ll N; cin>>N; string S; cin>>S; map<pair<int, int>, int> hMap; int C = 0, G = 0, A = 0, T = 0; ll ans = 0; for(int i=0; i<S.length(); ++i){ if(S[i]=='C') C++; else if(S[i]=='G') G++; else if(S[i]=='A') A++; else T++; pair<int, int> temp = {C-G, A-T}; if(hMap.find(temp)!=hMap.end()) ans += hMap[temp]; if(hMap.find(temp)!=hMap.end()) hMap[temp]++; else hMap[temp] = 1; if(temp.first==0 && temp.second==0) ans++; } cout<<ans<<endl; } }
#include <bits/stdc++.h> #define ll long long #define rep(i,n) for(int i=0;i<n;i++) using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n; cin>>n; int cnt = 0; rep(i,n) { int tmp = i + 1; int f = 1; string o; while (tmp) { o.push_back((char)(tmp % 8 + '0')); tmp /= 8; } rep(i,o.size()) if (o[i] == '7') {cnt++; f = 0; break;} tmp = i+1; string d = to_string(tmp); rep(i,d.size()) if (d[i] == '7' && f) {cnt++; break;} } cout << n - cnt << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll mod=1e9+7; vector<ll> p(3e5),r(3e5); ll find(ll a){ if(p[a]==a) return a; return p[a]=find(p[a]); } void join(ll a,ll b){ a=find(a); b=find(b); if(r[a]==r[b]){ r[a]++; } if(r[a]>r[b]){ p[b]=a; }else{ p[a]=b; } } int main() { ll n; cin>>n; ll a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } for(int i=0;i<p.size();i++){ p[i]=i; } int i=0,j=n-1; ll ans=0; while(i<j){ if(a[i]!=a[j]){ ll c=find(a[i]); ll d=find(a[j]); if(c==d){ i++; j--; continue; }else{ ans++; join(a[i],a[j]); } } i++; j--; } cout<<ans; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using vt = vector<T>; template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define pb push_back #define SZ(x) ((int)((x).size())) #define EACH(x, a) for (auto& x: a) #define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i) #define FORD(i,s,l) for (ll i = (s); (i) >= l; --i) #define F first #define S second #define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1) #define TEST(x,i) ((x)&(1ll<<(i))) #define SET(x,i) ((x)|(1ll<<(i))) #define FLIP(x,i) ((x)^(1ll<<(i))) #define CLEAR(x,i) ((x)&~(1ll<<(i))) const double pi = 4 * atan(1); using ll = long long; using pll = pair<ll, ll>; mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count()); ll randint(ll a, ll b) { return uniform_int_distribution<ll>(a, b)(mt_rng); } template<class T> bool umin(T& a, const T& b) { return b<a?a=b, 1:0; } template<class T> bool umax(T& a, const T& b) { return a<b?a=b, 1:0; } template<class ForwardIterator> void print_vec(ForwardIterator first, ForwardIterator last, string sep = " ", string end = "\n") { bool ft = true; while (first != last) { if (!ft) {cout << sep;} else {ft = false;} cout << (*first); ++first; } cout << end; } template<typename T1, typename T2> std::ostream& operator<<(std::ostream &o, const pair<T1, T2> &p) { return o << p.F << " " << p.S; } template<typename T> vector<int> argsort(const vector<T> &v, function<bool(T,T)> cmp) { vector<int> indices(v.size()); iota(indices.begin(), indices.end(), 0); sort(indices.begin(), indices.end(),[&v,&cmp](int left, int right) -> bool {return cmp(v[left],v[right]);}); return indices; } template<typename T> vector<int> argsort(const vector<T> &v) { return argsort<T>(v, less<T>()); } inline ll floorDiv(ll x, ll y) { ll d = x / y; ll r = x % y; return r ? (d - ((x < 0) ^ (y < 0))) : d; } ll ceilDiv(ll x, ll y) { return -floorDiv(-x, y); } ll bin_search(ll lo, ll hi, function<bool(ll)> predicate) { int sign = lo <= hi ? 1 : -1; lo *= sign; hi *= sign; hi++; while (lo < hi) { ll mid = lo + floorDiv(hi-lo, 2); if (!predicate(sign * mid)) { lo = mid + 1; } else { hi = mid; } } return sign * lo; } const ll MOD = 1000000007; const int MAXN = 200005; vector<vector<int>> adj; vector<vector<pair<int,int>>> queries; vector<int> counts; void dfs(int u, vector<int> &ans, int p = 1, int d = 0) { vector<int> before; for (int i = 0; i < (int)queries[u].size(); i++) { before.pb(counts[queries[u][i].F]); } counts[d]++; for (auto &v : adj[u]) { if (v != p) { dfs(v, ans, u, d+1); } } vector<int> after; for (int i = 0; i < (int)queries[u].size(); i++) { after.pb(counts[queries[u][i].F]); } for (int i = 0; i < (int)queries[u].size(); i++) { ans[queries[u][i].S]=after[i]-before[i]; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; adj.assign(n+1, {}); queries.assign(n+1, {}); counts.assign(n+1,0); for (int i = 2; i <= n; i++) { int p; cin >> p; adj[i].pb(p); adj[p].pb(i); } int q; cin >> q; vector<int> ans(q); for (int i = 0; i < q; i++) { int u, d; cin >> u >> d; queries[u].pb({d,i}); } dfs(1, ans); print_vec(ans.begin(),ans.end(),"\n"); }
/** * author: FromDihPout * created: 2021-06-05 **/ #include <bits/stdc++.h> using namespace std; const int MAX_DEPTH = 2e5 + 5; int t; vector<vector<int>> adj; vector<vector<int>> depth; vector<int> tin, tout; void dfs(int u, int d) { depth[d].push_back(t); tin[u] = t; t++; for (int v : adj[u]) { dfs(v, d + 1); } tout[u] = t; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; adj.resize(n); for (int i = 1; i < n; i++) { int p; cin >> p; p--; adj[p].push_back(i); } t = 0; depth.resize(MAX_DEPTH); tin.resize(n); tout.resize(n); dfs(0, 0); int q; cin >> q; while (q--) { int u, d; cin >> u >> d; u--; vector<int> nodes = depth[d]; int r = lower_bound(nodes.begin(), nodes.end(), tout[u]) - nodes.begin(); int l = lower_bound(nodes.begin(), nodes.end(), tin[u]) - nodes.begin(); cout << r - l << '\n'; } return 0; }
#include <bits/stdc++.h> #include <bits/extc++.h> #define double long double #define rbtree __gnu_pbds::tree<int,__gnu_pbds::null_type,less<int>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update> #define int ll #define IOS ios_base::sync_with_stdio(false);cin.tie(0); #define pb push_back #define ALL(X) X.begin(),X.end() #define F(i,n) FF(i,0,n) #define F1(i,n) FF(i,1,n+1) #define FF(i,n,m) for(int i=(int)n;i<(int)m;++i) #ifndef LOCAL //#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #else #endif // LOCOL //#define mp make_pair using namespace std; //using namespace __gnu_pbds; template<typename T> bool remax(T& a, const T& b) {return b>a?a=b,1:0;} template<typename T> bool remin(T& a, const T& b) {return b<a?a=b,1:0;} inline ostream& operator << (ostream& os,__int128_t a){if(a==0) {return (os<<'0');}bool flag=0;if(a<0) {a=-a,flag=1;}string s;while(a){s+=a%10+'0';a/=10;}s+=flag?"-":"";reverse(ALL(s));return os<<s;} inline istream& operator >>(istream& is,__int128_t& a){string s;cin>>s;a=0;for(auto c:s) a=a*__int128_t(10)+__int128_t(c-'0');return is;} template<typename T,typename P> inline ostream& operator << (ostream& os,pair<T,P> a){os<<a.first<<" "<<a.second; return os;} template<typename T,typename P> inline istream& operator >> (istream& is,pair<T,P> &a){is>>a.first>>a.second; return is;} using ll=long long; using ull=unsigned long long; using int128= __int128_t; using uint128= __uint128_t; using pii =pair<int,int>; const double pi=acos(-1); const int N=1E5+5; const ll M=1000000000; const ll INF_64=0x3f3f3f3f3f3f3f3f; const int INF_32=0x3f3f3f3f; const int16_t INF_16=0x3f3f; const int klog=20; const int mod=998244353;//1E9+7 const double eps=1E-8; void gen(){ } int d[N]{}; vector<pair<int,pii>> g[N]; int dis(int c,int d,int t){ double l=0,r=1E14; F(_,100){ double m1=l+(r-l)/3.0,m2=r-(r-l)/3.0; double mv1=t+m1+c+(d/(t+m1+1.0)); double mv2=t+m2+c+(d/(t+m2+1.0)); if(mv1==mv2) l=m1,r=m2; else if(mv1>mv2) l=m1; else r=m2; } int re=INF_64; int L=l,R=r; FF(j,L-3,R+3) if(j>=0)remin(re,t+j+c+(d/(t+j+1))); return re; } void sol(){ int n,m;cin>>n>>m; priority_queue<pii,vector<pii>,greater<pii>> pq; memset(d,0x3f,sizeof(d)); d[0]=0;pq.push({0,0}); F(i,m){ int a,b,C,D;cin>>a>>b>>C>>D; a--,b--; g[a].pb({b,{C,D}}); g[b].pb({a,{C,D}}); } while(pq.size()){ auto [val,a]=pq.top();pq.pop(); if(val!=d[a]) continue; for(auto &[b,tt]:g[a]){ if(remin(d[b],dis(tt.first,tt.second,d[a]))) pq.push({d[b],b}); } assert(d[a]==val); } //F(i,n) cout<<d[i]<<" "; //cout<<"\n"; assert(d[n-1]>=0); cout<<(d[n-1]>=INF_64?-1:d[n-1])<<"\n"; } int32_t main(){ #ifdef LOCAL //freopen(".in","r",stdin); //freopen(".out","w",stdout); #endif // LOCAL IOS; int t=1; gen(); //cin>>t; FF(i,1,t+1){ //cout<<"Case #"<<i<<": "; sol(); } }
typedef long long ll; typedef long double ld; #include <bits/stdc++.h> using namespace std; int main() { ll a,b,x,y; std::cin >> a>>b>>x>>y; vector<vector<ll>> dis(200,vector<ll>(200,1000000000)); for (int i = 0; i < 100; i++) { dis[i][i+100] = dis[i+100][i] = x; if(i>0)dis[i][i-1+100] = dis[i-1+100][i] = x; } for (int i = 1; i < 100; i++) { dis[i][i-1] = dis[i+100][i-1+100] = y; dis[i-1][i] = dis[i-1+100][i+100] = y; } for (int jjjjj = 0; jjjjj < 3; jjjjj++) { for (int i = 0; i < 200; i++) { for (int j = 0; j < 200; j++) { for (int k = 0; k < 200; k++) { dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]); } } } } std::cout << dis[a-1][b-1+100] << std::endl; }
#include <bits/stdc++.h> using namespace std; vector<int> ar[2001]; set<pair<int,int>> s; int visited[2001]; void dfs(int x,int source) { visited[x]=1; for(auto it:ar[x]) { if(!visited[it]) { s.insert({source,it}); dfs(it,source); } } } void solve() { int t=1; //cin>>t; while(t--) { int n,m,i; cin>>n>>m; int x,y; for(i=1;i<=n;i++) { s.insert({i,i}); } for(i=0;i<m;i++) { cin>>x>>y; ar[x].push_back(y); } for(i=1;i<=n;i++) { memset(visited,0,sizeof(visited)); dfs(i,i); } cout<<s.size()<<endl; } } int main() { ios::sync_with_stdio(0); cin.tie(0); solve(); cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; return 0; }
#include "bits/stdc++.h" using namespace std; using ll=long long; using vi=vector<int>; using vvi=vector<vi>; using vll=vector<ll>; using vvll=vector<vll>; using pii=pair<int,int>; #define rep(i,n) for(int i=0;i<(n);i++) #define sor(v) sort(v.begin(),v.end()) #define rev(v) reverse(v.begin(),v.end()) #define pb push_back 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; } //const int INF = 1123456789; //const int mod = 1e9+7; int n,m; vvi g; int ans=0; vector<bool> checked; void f(void){ checked.clear(); checked.resize(n); } void dfs(int now){ checked[now]=true; for(auto a:g[now]) if(!checked[a]) dfs(a); } int main(){ cin>>n>>m; g.resize(n); rep(i,m){ int a,b; cin>>a>>b; a--; b--; g[a].pb(b); } rep(i,n){ f(); dfs(i); rep(j,n) if(checked[j]) ans++; } cout<<ans<<endl; }
#include <bits/stdc++.h> //#include <atcoder/all> #define rep(i, n) for (int i=0; i < (n); i++) using namespace std; //using namespace atcoder; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> P; const int INF = 1 << 30; const ll LINF = 1LL << 61; const int NIL = -1; const int MAX = 10000; const int MOD = 1000000007; const double pi = 3.141592653589; vector<map<char, int>> dict(5010); int main() { int n; cin >> n; string s; cin >> s; vector<string> ss(n+1, ""); for (int i=0;i<n;i++){ ss[i+1] = ss[i] + s[i]; } for (int i=1;i<=n;i++){ for (auto c : ss[i]){ dict[i][c] += 1; } } int ans = 0; for(int i=0;i<n;i++){ for(int j=i+1;j<n+1;j++){ if (dict[j]['T']-dict[i]['T'] == dict[j]['A']-dict[i]['A'] && dict[j]['C']-dict[i]['C'] == dict[j]['G']-dict[i]['G']) ans += 1; } } cout << ans << endl; return 0; }
#include <vector> #include <array> #include <stack> #include <queue> #include <list> #include <bitset> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <algorithm> #include <numeric> #include <iostream> #include <iomanip> #include <string> #include <chrono> #include <random> #include <cmath> #include <cassert> #include <climits> #include <cstring> #include <cstdlib> #include <functional> #include <sstream> using namespace std; int main(int argc, char** argv) { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(12); int n; cin >> n; vector<long long> A(n); for (int i = 0; i < n; ++i) { cin >> A[i]; } vector<long long> sums(n + 1, 0); for (int i = 0; i < n; ++i) { sums[i + 1] = sums[i]; if (i & 1) { sums[i + 1] += A[i]; } else { sums[i + 1] -= A[i]; } } map<long long,int> cnts; cnts[0] += 1; long long res = 0; for (int i = 0; i < n; ++i) { res += cnts[sums[i + 1]]; cnts[sums[i + 1]] += 1; } cout << res << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ string a; cin >> a; int p=0; int c = a.size(); for(int i=0; i < c;i++){ if(a[i]=='.') p = i; } if(p!=0) a = a.substr(0,p); // a.substr(0,(a.size()-p)); cout << a << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, l, n) for (int i = (l); i < (n); i++) 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; } using ll = int64_t; using ull = uint64_t; int n[18]; /* ある整数が3の倍数であるかどうかは、その数の各位の数を足した値が3の倍数であるかどうかで調べられます。 */ int main() { string N; cin >> N; int index = 0; for (char c : N) { n[index++] = c - '0'; } int S = N.size(); int min_keta = 1000; for (ull i = 0; i < (1 << S); i++) { ull num = 0; int keta = 0; for (int j = 0; j < S; j++) { if (i & (1 << j)) { num += n[j]; keta++; // cout << n[j] << ": " << num << endl; if ((num % 3) == 0) { if ((S - keta) < min_keta) { min_keta = (S - keta); } } } } } if (min_keta == 1000) { cout << -1 << endl; } else { cout << min_keta << endl; } }
#include <bits/stdc++.h> #define DEBUG if(0) #define lli long long int #define ldouble long double using namespace std; const int maxX = 2e5 + 1; int divCount[maxX]; int main() { int a, b; while (~scanf("%d %d", &a, &b)) { memset(divCount, 0, sizeof(divCount)); for (int i = a; i <= b; i++) { for (int j = 2, end = sqrt(i); j <= end; j++) if (i % j == 0) { divCount[j]++; if (i % (i / j) == 0 && j != i / j) divCount[i / j]++; } divCount[i]++; } int ans = 1; for (int i = 2; i < maxX; i++) if (divCount[i] > 1) ans = i; printf("%d\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; int findMaxGCD(int arr[], int n) { int high = 0; for (int i = 0; i < n; i++) high = max(high, arr[i]); int count[high + 1] = {0}; for (int i = 0; i < n; i++) count[arr[i]]++; int counter = 0; for (int i = high; i >= 1; i--) { int j = i; counter = 0; while (j <= high) { // A multiple found if(count[j] >=2) return j; else if (count[j] == 1) counter++; // Incrementing potential // GCD by itself // To check i, 2i, 3i.... j += i; // 2 multiples found, // max GCD found if (counter == 2) return i; } } } int main() { int a,b; cin>>a>>b; int c[b-a+1]; for(int i=0; i<b-a+1; i++) { c[i]=a+i; } /* for(int i=0; i<b-a+1; i++) { cout<<c[i]<<" "; } cout<<endl;*/ int n; n=b-a+1; cout << findMaxGCD(c, n); return 0; }
#define _USE_MATH_DEFINES #include <iostream> #include <cstring> #include <regex> #include <cmath> #include <algorithm> #include <vector> #include <list> #include <map> #include <unordered_set> #include <queue> #include <unordered_map> #include <set> #include <cassert> #include <climits> #pragma GCC optimize("O3") using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i) #define repd(i, n) for(ll i = (n) - 1ll; i >= 0; --i) #define FOR(i, a, b) for(ll i = a; i < ll(b); ++i) #define FORD(i, a, b) for(ll i = a; i > ll(b); --i) #define foreach(i, itr) for(auto& i : (itr)) #define asort(arr, size) std::sort(arr, arr + size) #define dsort(arr, size) std::sort(arr, arr + size, [](auto a, auto b) { return a > b; }) #define cauto const auto& #define bit(n) (1LL << (n)) //////////////////////////////////// // ここから下に任意のコードを書く // //////////////////////////////////// int main() { string S; cin >> S; deque<char> T; bool R = false; rep(i, S.size()) { if (S[i] == 'R') { R = !R; } else if (T.empty()) { T.push_back(S[i]); } else if (R) { if (T.front() == S[i]) { T.pop_front(); } else { T.push_front(S[i]); } } else { if (T.back() == S[i]) { T.pop_back(); } else { T.push_back(S[i]); } } } if (R) { for_each(T.rbegin(), T.rend(), [](char c) { cout << c; }); } else { for (char c : T) { cout << c; } } cout << endl; return 0; } //ll abi[5000][5]; //ll dp[5000][3][5]; // //ll getPower(int index) { // ll res = INT_MAX; // rep(i, 3) { // ll mx = 0; // rep(j, 5) { // mx = max(mx, dp[index][i][j]); // } // res = min(res, mx); // } // return res; //} // //int main() //{ // int N; // cin >> N; // rep(i, N) cin >> abi[i][0] >> abi[i][1] >> abi[i][2] >> abi[i][3] >> abi[i][4]; // // dp[0][0][0] = abi[0][0]; // dp[0][0][1] = abi[0][1]; // dp[0][0][2] = abi[0][2]; // dp[0][0][3] = abi[0][3]; // dp[0][0][4] = abi[0][4]; // FOR(i, 1, N) { // int index = -1; // rep(j, 3) { // rep(k, 5) { // dp[i][j][k] = dp[i - 1][j][k]; // } // } // ll res = INT_MAX; // rep(j, 3) { // ll mx = 0; // rep(k, 5) { // mx = max(mx, dp[i][j][k]); // } // res = min(res, mx); // } // } // // return 0; //}
#include<bits/stdc++.h> using namespace std; int main() { string s; deque<char> ans; cin >> s; int sw,i,size; sw=0; size=s.size(); for(char c: s) { if(c=='R') sw++; else{ if(ans.size()==0) ans.push_front(c); else if(sw%2==0) {if(c==ans.back()) ans.pop_back(); else ans.push_back(c); } else {if(c==ans.front()) ans.pop_front(); else ans.push_front(c); } } } if(sw%2==1) reverse(ans.begin(),ans.end()); string T; for(char c : ans){ T.push_back(c); } cout << T << endl; return 0;}
#include <bits/stdc++.h> using namespace std; int main(){ int H, W; while(scanf("%d%d", &H, &W) > 0){ int A[H][W], min_A = 110; for(int i = 0; i < H; i++){ for(int j = 0; j < W; j++){ scanf("%d", &A[i][j]); min_A = min(min_A, A[i][j]); } } int ans = 0; for(int i = 0; i < H; i++){ for(int j = 0; j < W; j++){ ans += A[i][j] - min_A; } } printf("%d\n", ans); } }
#include <iostream> #include <iomanip> #include <algorithm> #include <array> #include <cassert> #include <optional> #include <utility> #include <vector> template <class InputIterator> std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); } return os_arg; } template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); } template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); } template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; } #ifndef ONLINE_JUDGE template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; } template <typename Head, typename... Tail> void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); } #define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false) #else #define dump(...) (void(0)) #endif int main(void){ std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(16); int H, W; std::cin >> H >> W; int sum = 0; int m = std::numeric_limits<int>::max(); for(int i = 0; i < H; ++i) for(int j = 0; j < W; ++j){ int a; std::cin >> a; sum += a; if(m > a) m = a; } std::cout << (sum - (H * W * m)) << '\n'; return 0; }
#include <cstdio> #include <algorithm> using namespace std; int n,a[31],f[31][31];long long ans=1e15; void dfs(int las,int sum) { if(las==n) { ans=min(ans,1ll*sum); return; } for(int i=las+1;i<=n;i++) dfs(i,sum^f[las+1][i]); } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) for(int j=i;j<=n;j++) f[i][j]=f[i][j-1]|a[j]; dfs(0,0); printf("%lld",ans); }
#include<bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i = (a); i < (b); i++) #define RFOR(i,a,b) for(int i = (a) - 1; i>=(b);i--) #define rep(i,n) FOR(i,0,n) #define PB push_back #define SZ(a) (int)a.size() #define ALL(a) a.begin(), a.end() #define FILL(a, value) memset(a, value, sizeof(a)) #define IOS ios_base::sync_with_stdio(0),cin.tie(0), cout.tie(0); typedef long long LL ; typedef vector<int > VI ; typedef vector<LL > VL; typedef pair<int,int > PII; typedef pair<LL,LL> PLL; const LL LINF = (LL)1e18 +47; const int INF = (int)(1 << 30) + 100 ; const int MOD =(int)1e9 + 7 ; const int modulo = 998244353; const int nax = 3 * (int)1e5 + 10; const double EPS = 1e-7; const double PI = acos(-1.0); int a[nax]; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif IOS; int n; cin >> n ; rep(i,n)cin >> a[i]; int ans = INF; for(int mask =1; mask < (1 << n); mask++) { vector<int > vec; int orr = 0; rep(i,n) { orr|=a[i]; if(mask &(1 << i)) { vec.PB(orr); orr = 0; } } if(orr!=0)vec.PB(orr); int xr = 0; for(auto x : vec)xr^=x; ans = min(ans,xr); } cout << ans << '\n'; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef vector<PII> VPII; typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; typedef pair<LL, LL> PLL; typedef vector<PLL> VPLL; typedef vector<bool> VB; typedef priority_queue<LL> PQ_DESC; typedef priority_queue<LL, VL, greater<LL>> PQ_ASC; typedef priority_queue<PII> PQ_DESC_PII; typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII; typedef priority_queue<VL> PQ_DESC_VL; typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL; typedef priority_queue<PLL> PQ_DESC_PLL; typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL; #define ALL(c) (c).begin(),(c).end() #define PB push_back #define MP make_pair #define SORT_ASC(c) sort(ALL(c)) //#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>()) #define SORT_DESC(c) sort((c).rbegin(),(c).rend()) #define REV(c) reverse((c).begin(), (c).end()) #define SIZE(a) LL((a).size()) #define FOR(i,a,b) for(LL i=(a);i<(b);++i) #define ROF(i,a,b) for(LL i=(b-1);i>=(a);--i) #define REP(i,n) FOR(i,0,n) #define PER(i,n) ROF(i,0,n) const double EPS = 1e-10; const double PI = acos(-1.0); const LL LARGE_INT = 1e9+100; const LL INF = 2e9+100; const LL INF_LL = (LL)INF*(LL)INF; const LL MOD = 1e9+7; //debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; LL modpow(LL a, LL n) { LL res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } void Main() { LL n;cin>>n; LL result = INF_LL; VL a(n),b(n); REP(i,n){ cin>>a[i]>>b[i]; result = min(result,a[i]+b[i]); } REP(i,n){ REP(j,n){ if(i==j){ continue; } result = min(result,max(a[i],b[j])); } } cout<<result<<endl; return; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); return 0; }
#include <iostream> #include <string> #include <algorithm> #include <functional> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <tuple> #include <cstdio> #include <cmath> #include <bitset> #define ll long long #define rep(i, n) for(int i = 0; i < n; i++) using namespace std; const int INF = 100100100; /* ll gcd(ll a, ll b){ //log max(a,b) if (a % b == 0){ return(b); } else{ return(gcd(b, a % b)); } } ll lcm(ll a, ll b){ return a * b / gcd(a, b); } */ //gcd lcm int main() {//////////いもす int n, k; cin >> n >> k; vector<vector<int>>a(n, vector<int>(n)); rep(i, n)rep(j, n)cin >> a[i][j]; int L = k * k / 2 + 1; int wa = -1, ac = 1001001001; while (wa + 1 < ac) { int wj = (wa + ac) / 2; bool ok = false; { vector<vector<int>> s(n + 1, vector<int>(n + 1)); rep(i, n)rep(j, n) s[i + 1][j + 1] = a[i][j]>wj?1:0; rep(i, n+1)rep(j, n)s[i][j+1] += s[i][j]; rep(i, n)rep(j, n+1)s[i + 1][j] += s[i][j]; rep(i, n - k + 1)rep(j, n - k + 1) { int now = s[i+k][j+k]; now -= s[i][j + k]; now -= s[i + k][j]; now += s[i][j]; if (now < L)ok = true; } } if (ok)ac = wj; else wa = wj; } cout << ac << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(ll i=0;i<(ll)n;i++) #define dump(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << (x) << "\n"; #define spa << " " << #define fi first #define se second #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() using ld = long double; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; template<typename T> using V = vector<T>; template<typename T> using P = pair<T, T>; template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); } template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); } template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;} template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;} struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());} template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } void fail() { cout << -1 << '\n'; exit(0); } inline int popcount(const int x) { return __builtin_popcount(x); } inline int popcount(const ll x) { return __builtin_popcountll(x); } template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++) {cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}}; template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0]; for(ll i=1;i<n;i++)cerr spa v[i]; cerr<<"\n";}; const ll INF = (1ll<<62); // const ld EPS = 1e-10; // const ld PI = acos(-1.0); const ll mod = (int)1e9 + 7; //const ll mod = 998244353; int main(){ ll N, M; cin >> N >> M; V<ll> X(M), Y(M); REP(i, M) cin >> X[i] >> Y[i]; set<ll> st; st.insert(N); V<ll> ids(M, 0); iota(ALL(ids), 0); sort(ALL(ids), [&](ll x, ll y){ return X[x] < X[y]; }); REP(i, M){ ll j = i; while(j < M and X[ids[i]] == X[ids[j]]){ j++; } ll len = j - i; V<ll> check(len, 0); V<ll> vals; for(ll k=i;k<j;k++){ vals.push_back(Y[ids[k]]); } REP(k, len){ if(st.find(vals[k]-1) != st.end() or st.find(vals[k]+1) != st.end()){ check[k] = 1; } } REP(k, len){ if(check[k]){ st.insert(vals[k]); }else{ auto itr = st.find(vals[k]); if(itr != st.end()) st.erase(itr); } } i = j - 1; // for(auto x: st) cerr << x << " "; // cerr << endl; } cout << st.size() << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifdef OJ freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); freopen("error.txt","w",stderr); #endif int n; cin>>n; string a; cin>>a; if(a[0]!=a[a.size()-1])cout<<1; else { char c1=a[0],c2=a[a.size()-1]; for(int i=1;i<a.size();i++) { if(c1!=a[i] && c2!=a[i+1]) { cout<<2; return 0; } } cout<<-1; } return 0; }
#pragma GCC optimize("Ofast") //#pragma GCC target ("sse4") #include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<bitset> #include<stack> #include<unordered_map> #include<unordered_set> #include<utility> #include<cassert> #include<complex> #include<numeric> #include<array> using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; constexpr ll mod = 1000000007; const ll INF = mod * mod; typedef pair<int, int>P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define all(v) (v).begin(),(v).end() typedef pair<ll, ll> LP; typedef double ld; typedef pair<ld, ld> LDP; const ld eps = 1e-12; const ld pi = acosl(-1.0); ll mod_pow(ll x, ll n, ll m = mod) { if (n < 0) { ll res = mod_pow(x, -n, m); return mod_pow(res, m - 2, m); } if (abs(x) >= m)x %= m; if (x < 0)x += m; ll res = 1; while (n) { if (n & 1)res = res * x % m; x = x * x % m; n >>= 1; } return res; } struct modint { ll n; modint() :n(0) { ; } modint(ll m) :n(m) { if (n >= mod)n %= mod; else if (n < 0)n = (n % mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; } modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; } modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, ll n) { if (n == 0)return modint(1); modint res = (a * a) ^ (n / 2); if (n % 2)res = res * a; return res; } ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } modint operator/=(modint& a, modint b) { a = a / b; return a; } const int max_n = 1 << 2; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b)return 0; return fact[a] * factinv[b] * factinv[a - b]; } modint combP(int a, int b) { if (a < 0 || b < 0 || a < b)return 0; return fact[a] * factinv[a - b]; } void solve() { int n, m; cin >> n >> m; vector<int> a(m),b(m); rep(i, m) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } int k; cin >> k; vector<int> c(k), d(k); rep(i, k) { cin >> c[i] >> d[i]; c[i]--; d[i]--; } int ans = 0; rep(i, (1 << k)) { vector<bool> exi(n); rep(j, k) { if (i & (1 << j)) { exi[c[j]] = true; } else { exi[d[j]] = true; } } int cnt = 0; rep(j, m)if (exi[a[j]] && exi[b[j]])cnt++; ans = max(ans,cnt); } cout << ans << "\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); //init_f(); //init(); //expr(); //int t; cin >> t; rep(i,t) //expr(); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int main() { int n,m; int vdnhgbdrhg; cin>>n>>m; vector<pair<int,int>>a(m); for(int i=0;i<m;i++) { cin>>a[i].first>>a[i].second; } int k; cin>>k; vector<pair<int,int>>b(k); for(int j=0;j<k;j++) { cin>>b[j].first>>b[j].second; } ll l=0; ll tot=1<<k; for(ll mask=0;mask<tot;mask++) { vector<int>v(n+1); ll ans=0; for(int i=0;i<k;i++) { if(mask & (1<<i)) v[b[i].second]=1; else v[b[i].first]=1; } for(int i=0;i<m;i++) { if(v[a[i].first] && v[a[i].second]) ans++; } l=max(l,ans); } cout<<l<<endl; return 0; }