code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include<bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; vector<P> xy(n); for (int i = 0; i < n; i++) cin >> xy[i].first >> xy[i].second; int ans = 0; for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { double kata = (double)abs(xy[j].second - xy[i].second) / abs(xy[j].first - xy[i].first); if (abs(kata) <= 1) ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <unordered_set> #include <cmath> #include <algorithm> // #include <atcoder/all> // URL: using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vs = vector<string>; #define dump(x) cout << #x << " = " << (x) << endl #define YES(n) cout << ((n)? "YES": "NO") << endl #define Yes(n) cout << ((n)? "Yes": "No") << endl #define rept(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 fore(x, a) for(auto& (x) : (a)) #define reptll(i, a, b) for(ll i = (ll)(a); i < (ll)(b); i++) #define repll(i, n) for (ll i = 0; i < (ll)(n); i++) #define ALL(a) (a).begin(), (a).end() #define VECCIN(x) for(auto& youso_: (x)) cin >> youso_ #define VECCOUT(x) for(auto& youso_: (x)) cout << youso_ << " ";cout << endl #define pb push_back #define optimize_cin() cin.tie(0); ios::sync_with_stdio(false) 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 ll INFL = numeric_limits<ll>::max() / 4; const int INF = 1e9; const int MOD = 1e9 + 7; int main(){ optimize_cin(); ll N; cin >> N; vll A(N); vll C(N + 1); map<ll, ll> D; C[0] = 0; rep(i, N){ cin >> A[i]; C[i + 1] = C[i] + (i % 2 == 0? A[i] : - A[i] ); } ll cnt = 0; rep(i, N + 1) { cnt += D[C[i]]; D[C[i]]++; } cout << cnt << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define ss second #define ff first #define ub upper_bound #define lb lower_bound const ll m=1000000007; #define inf 1000000000000000000 #define infn -1000000000000000000 ll ncr(int n,int r){if(r>n)return 0;if(r > n - r) r = n - r;ll ans = 1; int i;for(i = 1; i <= r; i++){ans *= n - r + i;ans /= i;}return ans;} ll power(ll x,ll n,ll m){if(n==0)return 1;else if(n%2==0)return (power(((x%m)*(x%m))%m,n/2,m))%m;else return ((x%m)*power(x,n-1,m)%m);} int dx[] = {1,-1,0,0}; int dy[] = {0,0,1,-1}; ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;} // std::rotate(vec.begin(), vec.begin()+rotL, vec.end());//rotl=no of left ro // std::rotate(vec.begin(), vec.begin()+vec.size()-rotR, vec.end()); //str.substr(1,3); // takes(0 based indexing all from [1,3]) //transform(str.begin(),str.end(),str.begin(),::tolower);//also "toupper" // to_string(ll),stoll(string) string binary(ll n){ if(n==0) return "0"; string ans; while(n>0){ if(n&1) ans.pb('1'); else ans.pb('0'); n=n>>1; } reverse(ans.begin(),ans.end()); return ans; } bool is_prime(ll n){ if(n==1) return 0; for(ll i=2; i*i<=n; i++){ if(n%i==0) return 0; } return 1; } ll sum_digit(ll n){ ll ans=0; while(n>0){ ans+=(n%10); n/=10; } return ans; } ll binary_to_decimal(string str){ ll ans=0,d=1; for(int i=str.length()-1; i>=0; i--){ ans+=d*(str[i]-48); d*=2; } return ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL); ll t,n; cin>>t; while(t--){ cin>>n; if(n&1) cout<<"Odd\n"; else{ if((n/2)&1) cout<<"Same\n"; else cout<<"Even\n"; } } return 0; }
/*Rabbi Zidni Ilma*/ #include<bits/stdc++.h> using namespace std; #define ll long long #define scl(n) scanf("%lld",&n) #define scll(n,m) scanf("%lld %lld",&n,&m) #define pb push_back #define mp make_pair #define frs first #define scn second #define mod 1000000007 #define read freopen("input.txt","r",stdin) #define write freopen("output.txt","w",stdout) int main() { ll tc,n,i,j,mn,mx; scl(tc); while(tc--) { scl(n); if(n%2!=0) printf("Odd\n"); else { if((n/2)%2==0) printf("Even\n"); else printf("Same\n"); } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; #define sz(a) int((a).size()) #define pb push_back #define eb emplace_back #define fi first #define se second #define all(c) (c).begin(),(c).end() #define rall(c) (c).rbegin(),(c).rend() #define ini(a, i) memset(a, i, sizeof(a)) #define inin(a, n, i) memset(a, i, sizeof(a[0])*(n)) #define contains(c, i) ((c).find(i) != (c).end()) #define present(i, c) (find(all(c), i) != (c).end()) #define trav(x, c) for(auto& x : c) #define rep(i, n) for(int i = 0; i < n; i++) #define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e))) template<class T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; } template<class T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; } template<class A, class B> A cvt(B x) { stringstream s; s << x; A r; s >> r; return r; } void read() {} void print() {} template<class T, class... Args> void read(T& a, Args&... args) { cin >> a; read(args...); } template<class T, class... Args> void print(T a, Args... args) { cout << a << ' '; print(args...); } template<class... Args> void println(Args... args) { print(args...); cout << '\n'; } #define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); } void cerr_(istream_iterator<string> it) { (void) it; } template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); } template<class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; } template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; } template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } const int INF = 0x3F3F3F3F; const int MAXN = (int) 1e6; const int MOD = (int) 1e9+7; //========================= void run_test() { int n, m; read(n, m); vi a(n), b(m); rep(i, n) read(a[i]); rep(i, m) read(b[i]); if(n > m) swap(a, b), swap(n, m); int dp[n+1][m+1]; ini(dp, 0x3f); dp[0][0] = 0; rep(i, n+1) rep(j, m+1) { if(i < n) dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1); if(j < m) dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1); if(i < n && j < m) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + (a[i] != b[j])); } println(dp[n][m]); } //========================= int main() { ios::sync_with_stdio(false); cin.tie(nullptr); //int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); } // int t_; cin >> t_; while(t_--) run_test(); run_test(); return 0; }
#include<bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; using namespace std; #define ff first #define ss second #define ll long long int #define fo(i,a,n) for(ll i=a;i<n;i++) #define rfo(i,a,n) for(ll i=n-1;i>=a;i--) #define all(a) a.begin(),a.end() #define pb push_back #define mp make_pair #define vll vector<ll> #define pll pair<ll,ll> #define mll map<ll,ll> #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define ri reverse_iterator #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ite(a) for(auto &x : a) #define read(a) ite(a) cin>>x; #define fast ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL); #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; //function // ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} // void google(int t) {cout << "Case #" << t << ": ";} // vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;} // ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} // ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} // ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} // ll ceiling(ll n,ll m) {if(n%m==0)return n/m; else return n/m+1;} // ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i;return res;} // ll nCr(ll n, ll r){return fact(n) / (fact(r) * fact(n - r));} // bool isprime(ll n){for(ll i = 2; i * i <= n; i++){if(n % i == 0){return 0;}}return 1;} void r_p_p() { #ifndef ONLINE_JUDGE freopen("input1f.txt", "r", stdin); freopen("output1f.txt", "w", stdout); #endif } void solve() { ll TC=1; // cin>>TC; while(TC--) { ll a,b,c; cin>>a>>b>>c; ll sqa = a*a; ll sqb = b*b; ll sqc = c*c; if(sqa+sqb<sqc) { cout<<"Yes"<<endl; } else { cout<<"No"<<endl; } } } int32_t main() { r_p_p(); fast; solve(); return 0; }
//------------------------------------------ // C++ templete //------------------------------------------ #include <bits/stdc++.h> #define int long long using namespace std; //type //------------------------------------------ using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vs = vector<string>; //REPEAT //------------------------------------------ #define REP(i, a, b) for (int i = (a); i < (b); ++i) //container util //------------------------------------------ #define pb push_back #define paired make_pair #define ALL(a) (a).begin(), (a).end() #define PRINT(V) \ for (auto v : (V)) \ cout << v << " " #define SORT(V) sort((V).begin(), (V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) #define SZ(x) ((int)(x).size()) //constant //------------------------------------------ const int MOD = 1000000007; const int INF = 1061109567; const double EPS = 1e-10; const double PI = acos(-1.0); int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; //math //------------------------------------------ int QP(int a, int b) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % MOD; a = 1ll * a * a % MOD; } while (b >>= 1); return ans; } int QP(int a, int b, int MOD) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % MOD; a = 1ll * a * a % MOD; } while (b >>= 1); return ans; } int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } //debug //------------------------------------------ #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; //grobal variable //------------------------------------------ ll N, K; //main //------------------------------------------ signed main() { cin>>N; cout<<N-1<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define sz(x) ((int)x.size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define manytests int TT;cin >> TT; while (TT--) #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define FORd(i,a,b) for (int i = (a); i >= (b); --i) int dx[8] = {-1, 1, 0, 0, 1, 1, -1, -1}, dy[8] = {0, 0, 1, -1, 1, 1, -1, -1}; #define ll long long #define ld long double #define fi first #define se second #define rev reverse #define vi vector<int> #define vl vector<ll> #define vc vector<char> #define vd vector<double> #define vs vector<string> #define vld vector<ld> #define vb vector<bool> #define vvi vector<vi> #define pii pair<int, int> #define pl pair<ll, ll> #define pld pair<ld, ld> #define vpi vector<pii> #define vpl vector<pl> #define vpld vector<pld> int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int a, b, c, d; cin >> a >> b >> c >> d; cout << max(a-d, b-c) << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define vint vector<int> #define vll vector<ll> #define vstr vector<string> #define vvint vector<vector<int> > #define vvll vector<vector<ll> > #define vip vector<pair<int,int> > #define vlp vector<pair<ll,ll> > #define input(arr) for(auto &x:arr) cin>>x; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const int N = 100005; const ll mod = 1000000007; const ll inf = 1e17; const long double pi = (acos(-1)); int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll a,b,c,d; cin >> a >> b >> c >> d; if(c*d-b<=0){ cout << "-1"; return 0; } ll diff = c*d-b; ll ans = (a+diff-1) / diff; cout << ans; }
#define debug(...) #include <bits/stdc++.h> using namespace std; void solve(); #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t=1; //cin >> t; for (int i = 0; i < t; ++i) { solve(); cout << "\n"; } cerr << "time taken : " << (float)clock()/CLOCKS_PER_SEC << " secs" << "\n"; return 0; } void solve() { ll a, b, c, d; cin >> a >> b >> c >> d; if (b - c*d >= 0){ cout << -1; return; } else cout << (a + (c*d - b - 1)) / (c*d - b); }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vl; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<char> vc; typedef queue<ll> ql; typedef deque<ll> dql; typedef priority_queue<ll> pql; typedef set<ll> sl; typedef pair<ll, ll> pl; typedef map<ll, ll> ml; typedef vector<vl> vvl; typedef vector<pl> vpl; #define rep(i, n) for(ll i = 0; i < ll(n); i++) #define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++) #define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--) #define all(v) (v).begin(), (v).end() ll mod(ll a, ll b) {return (a % b + b) % b;} ll quo(ll a, ll b) {return (a - mod(a, b)) / b;} template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;} template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;} const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; //const ll MOD = 998244353; const ll MAX = 2e5; const ld eps = 1e-9; const char newl = '\n'; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, k, x, y, z; cin >> n >> k; n--; vvl dp(4, vl(3*n+1)), sum = dp; dp[0][0] = 1; sum[0] = vl(3*n+1, 1); rep(i, 3) { sum[i+1][0] = 1; rep(j, 3*n+1) { dp[i+1][j] = sum[i][j]; if(j > n) dp[i+1][j] -= sum[i][j-n-1]; if(j > 0) sum[i+1][j] = sum[i+1][j-1] + dp[i+1][j]; } } ll d = -1, u = 3*n; while(u-d > 1) { ll m = (d+u)/2; if(k <= sum[3][m]) u = m; else d = m; } if(u > 0) k -= sum[3][u-1]; ll D = -1, U = n; while(U-D > 1) { ll M = (D+U)/2; if(k <= sum[2][u] - (u-M-1 >= 0 ? sum[2][u-M-1] : 0LL)) U = M; else D = M; } k -= (sum[2][u] - (u-U >= 0 ? sum[2][u-U] : 0LL)); x = U; if(u-U <= n) y = k-1; else y = n - dp[2][u-U] + k; z = u-x-y; printf("%lld %lld %lld\n", x+1, y+1, z+1); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; using vll = vector<vl>; using Pll = pair<ll, ll>; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define Rep(i,j,n) for (ll i=(ll)(j);i<=(ll)(n);++i) #define all(v) v.begin(), v.end() #define sz(x) ((int) x.size()) #define eb emplace_back #define pb push_back #define mp make_pair #define mt make_tuple #define F first #define S second const int MOD = 1e9+7; const int mod = 998244353; const ll INF = 2e15; template<class T> void print(const T& t){ cout << t << 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; } ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} /* ll ti=clock(); cout<<("Execution Time: %.4lf sec", 1.0 * (clock() - ti) / CLOCKS_PER_SEC)<<endl; */ int main(){ ll n,m,q; cin>>n>>m>>q; vl w(n),v(n); vector<Pll> bag; rep(i,n){ cin>>w[i]>>v[i]; bag.emplace_back(v[i],w[i]); } sort(all(bag),greater<Pll>()); vl x(m); rep(i,m){ cin>>x[i]; } rep(i,q){ ll l,r; cin>>l>>r; vl tmp; rep(i,m){ if(i==l-1){ i=r; if(r==m){ break; } } tmp.eb(x[i]); } sort(all(tmp)); vector<bool> empty(sz(tmp),true); ll sum=0; rep(i,n){ rep(j,sz(tmp)){ if(bag[i].S<=tmp[j]&&empty[j]){ sum+=bag[i].F; empty[j]=false; break; } } } print(sum); } }
#include <bits/stdc++.h> using namespace std; #define eps 1e-9 #define INF 2000000000 // 2e9 #define LLINF 2000000000000000000ll // 2e18 (llmax:9e18) #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #define rep(i, x) for (int i = 0; i < (int)(x); i++) #define drep(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define popcount __builtin_popcount #define next __next #define prev __prev #ifndef LOCAL #define dmp(...) ; #else #define dmp(...) \ cerr << "[ " << #__VA_ARGS__ << " ] : " << dump_str(__VA_ARGS__) << endl #endif // ---------------- Utility ------------------ template <class T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <class T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <class T> using MaxHeap = priority_queue<T>; template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>; template <class T> vector<T> vect(int len, T elem) { return vector<T>(len, elem); } // ----------------- Input ------------------- template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.first >> p.second; } template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (int i = 0; i < vec.size(); i++) is >> vec[i]; return is; } // ----------------- Output ------------------ template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.first << ',' << p.second; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &e : v) os << e << " "; return os; } template <class T> ostream &operator<<(ostream &os, const deque<T> &d) { for (const T &e : d) os << e << " "; return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &s) { os << "{ "; for (const T &e : s) os << e << " "; return os << "}"; } template <class T, class U> ostream &operator<<(ostream &os, const map<T, U> &m) { os << "{ "; for (const auto &[key, val] : m) os << "( " << key << " -> " << val << " ) "; return os << "}"; } template <class TupleTy, size_t... I> void dump_tuple(ostream &os, const TupleTy t, std::index_sequence<I...>) { (..., (os << (I == 0 ? "" : ",") << std::get<I>(t))); } template <class... Args> ostream &operator<<(ostream &os, const tuple<Args...> &t) { os << "("; dump_tuple(os, t, std::make_index_sequence<sizeof...(Args)>()); return os << ")"; } void dump_str_rec(ostringstream &) {} template <class Head, class... Tail> void dump_str_rec(ostringstream &oss, Head &&head, Tail &&... tail) { oss << ", " << head; dump_str_rec(oss, forward<Tail>(tail)...); } template <class T, class... U> string dump_str(T &&arg, U &&... args) { ostringstream oss; oss << arg; dump_str_rec(oss, forward<U>(args)...); return oss.str(); } // --------------- Fast I/O ------------------ void fastio() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); } // ------------------ ACL -------------------- // #include <atcoder/modint> // constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; // using mint = atcoder::static_modint<MOD>; // ostream &operator<<(ostream &os, const mint &v) { // return os << v.val(); // } // ------------ End of template -------------- #define endl "\n" using ll = long long; using pii = pair<int, int>; const bool multitest = false; void solve() { ll N; int K; cin >> N >> K; for (int i = 0; i < K; i++) { if (N % 200 == 0) N /= 200; else { N *= 1000; N += 200; } } cout << N << endl; return; } int main() { fastio(); if (!multitest) { solve(); } else { cerr << "[Warning] Multi testcase mode on" << endl; int t; cin >> t; while (t--) solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define mod 1000000007 #define pb push_back #define ff first #define ss second typedef pair<int,int> pp; bool com(pp x,pp y){ if(x.ff==y.ff) return x.ss<y.ss; return x.ff<y.ff; } ll power(ll x,ll y){ ll prod=1; while(y){ if(y&1) prod=(prod*x)%mod; x=(x*x)%mod; y/=2; } return prod; } const int N=2e3+7; vector<int> vtx[N]; int k=0; bool vis[N]; void dfs(int u){ vis[u]=1; k++; for(auto v:vtx[u]) if(vis[v]==0) dfs(v); } void solve(){ int n,m; cin>>n>>m; for(int i=0;i<m;i++){ int u,v; cin>>u>>v; vtx[u].pb(v); } int ans=0; for(int i=1;i<=n;i++){ k=0; dfs(i); ans+=k; for(int j=1;j<=n;j++) vis[j]=0; } cout<<ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t=1; //cin>>t; while(t--) solve(); return 0; } /* */
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pii pair<int,int> #define pll pair<ll,ll> #define mkp make_pair #define pb push_back #define pf push_front #define popb pop_back #define popf pop_front #define ff first #define ss second #define endl "\n" #define MOD 1000000007 #define MOD1 998244353 #define inf 1e18 ll GCD(ll x,ll y){if(y==0)return x;return GCD(y,x%y);} ll LCM(ll x,ll y){return (x*y)/(GCD(x,y));} ll LOGK(ll x,ll k){if(x>=k)return 1+LOGK(x/k,k);return 0;} ll MPOW( ll a, ll b, ll m) { if(b==0) return 1; ll x=MPOW(a,b/2,m); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x;} ll MINV(ll a,ll m) {return MPOW(a,m-2,m);} class pnc{ ll FACT_MAX,MODU; vector<ll> fact; public: pnc( ll n, ll m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU);} void MFACT_INIT( ll m) { fact[0]=1; for(ll i=1;i<FACT_MAX;++i) fact[i]=(i*fact[i-1])%MODU;} ll MFACT( ll n) { return fact[n];} ll PERM( ll n, ll r) { return (fact[n]*::MINV(fact[n-r],MODU))%MODU;} ll COMB( ll n , ll r) { return (PERM(n,r)*::MINV(fact[r],MODU))%MODU;} }; ll calc(ll no,ll n) { if(no<=n) { return no-1; } else { ll start=no-n; ll end=no/2; if(no%2) { return (end-start+1)*2; } else { return (end-start)*2+1; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll test=1; // cin>>test; while(test--) { ll n,k; cin>>n>>k; ll ans=0; // cout<<calc(14,10)<<endl; for(ll i=2*n;i>=2;i--) { ll f=i; ll b=f-k; if(b>=2 && b<=2*n) { // cout<<f<<' '<<b<<endl; ll no1=calc(f,n); ll no2=calc(b,n); ans+=(no1*no2); } } cout<<ans; } }
#include<bits/stdc++.h> using namespace std; typedef long long D; D n,k,ans; D f(D x){ return x<2||x>2*n?0:min(n-(x-n)+1,x-1); } int main(){ cin>>n>>k; for(D i=2;i<=n*2;i++)ans+=f(i)*f(i-k); printf("%lld\n",ans); 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; const ll M = 1e18; int si[] = {-1, 0, 1, 0}; int sj[] = {0, -1, 0, 1}; int main(){ double sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; double x1 = (sy*gx+gy*sx)/(gy+sy); double x2 = (-sy*gx+gy*sx)/(gy-sy); if((sx <= x1 && x1 <= gx) || (gx <= x1 && x1 <= sx)){ cout <<std::fixed << std::setprecision(15) << x1 << endl; }else{ cout << std::fixed << std::setprecision(15) <<x2 << endl; } return 0; }
#include<bits/stdc++.h> #define ll long long using namespace std; int main() { ll x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; cout<<fixed<<setprecision(10)<<(double)((x1*y2)+(x2*y1))/(y1+y2); }
#include<bits/stdc++.h> #define ll long long using namespace std; const int N = 200010, mod = 1e9 + 7; ll dp[N][20], k, num[N]; char s[N]; ll dfs(int pos, bool limit, bool lead, int cnt, ll state){ if(!pos) return cnt == k; if(cnt > k) return 0; if(!limit && !lead && ~dp[pos][cnt]) return dp[pos][cnt]; ll ans = 0; int up = limit ? num[pos] : 15; for(int i = 0; i <= up; ++ i){ if(lead && !i) ans = (ans + dfs(pos - 1, limit && i == up, true, 0, 0)) % mod; else{ if((state >> i) & 1) ans = (ans + dfs(pos - 1, limit && i == up, false, cnt, state)) % mod; else ans = (ans + dfs(pos - 1, limit && i == up, false, cnt + 1, state | (1 << i))) % mod; } } if(!limit && !lead) dp[pos][cnt] = ans; return ans; } ll solve(){ int len = strlen(s + 1); for(int i = 1, j = len; i < j; ++ i, -- j) swap(s[i], s[j]); for(int i = 1; i <= len; ++ i){ if(s[i] >= '0' && s[i] <= '9') num[i] = s[i] - '0'; else num[i] = s[i] - 'A' + 10; } return dfs(len, true, true, 0, 0); } int main(){ scanf("%s", s + 1); cin >> k; memset(dp, -1, sizeof dp); cout << solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for (long long i = 0; i < (n); ++i) #define INF LONG_MAX/3 #define DIV 1000000007 //#define DIV 998244353 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 dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; long long kaidan[10000000]; void kaical(long long n){ kaidan[0] = 1; for(long long i = 1; i < n; i++){ kaidan[i] = kaidan[i-1] * i; kaidan[i] %= DIV; } } long long modpow(long long ori, long long po){ long long res = 1; while(po > 0){ if(po&1){ res *= ori; res %= DIV; } ori *= ori; ori %= DIV; po >>= 1; } return res; } //nCk long long combination(long long n, long long k){ if(n == 0 && k == 0)return 1; if(n < k || n < 0)return 0; long long n_kai = kaidan[n]; long long k_kai = kaidan[k]; long long nmk_kai = kaidan[n-k]; long long ans = n_kai * modpow(k_kai, DIV - 2); ans %= DIV; ans *= modpow(nmk_kai, DIV-2); ans %= DIV; return ans; } ll tonum(char ch) { if(ch >= '0' && ch <= '9') return ch - '0'; return ch - 'A' + 10; } string S; ll K; //すでに使った、これからつかう、残り長さ ll cal(ll idx, ll num) { ll used = num; ll willuse = K - used; ll leng = S.size() - idx; //if(willuse == 0) return 1; if(used > K) return 0; if(willuse < 0) return 0; if(willuse > leng) return 0; ll ret = 0; rep(unused, willuse + 1) { if(unused%2 == 0) { ret += modpow(K - unused, leng) * combination(willuse, unused); ret %= DIV; ret += DIV; ret %= DIV; } else { ret -= modpow(K - unused, leng) * combination(willuse, unused); ret %= DIV; ret += DIV; ret %= DIV; } } //will useの選び方 ret *= combination(16 - used, willuse); ret %= DIV; ret += DIV; ret %= DIV; //cout << "ret " << ret << endl; return ret; } ll memo[200005][20]; ll cal2(ll idx, ll num) { if(memo[idx][num] >= 0) return memo[idx][num]; if(idx == S.size()) { if(num == K) return 1; return 0; } ll newnum = 16 - num; ll ret = 0; //同じのとる ret += num * cal2(idx+1, num); ret %= DIV; //新しいのとる if(newnum > 0) { ret += newnum * cal2(idx+1, num + 1); ret %= DIV; } memo[idx][num] = ret; return ret; } int main(){ cin >> S >> K; kaical(20); rep(i,200005) rep(j, 20) memo[i][j] = -1; ll ans = 0; set<ll> used; rep(i, S.size()) { ll num = tonum(S[i]); //ここまでゼロでここから始まる if(i != 0) { ans += 15 * cal(i + 1, 1); ans %= DIV; } //ここで下回る rep(use, num) { //0から始めるのはなし if(use == 0 && i == 0) continue; if(used.count(use)) { ans += cal(i+1, used.size()); } else { ans += cal(i+1, used.size()+1); } ans %= DIV; //cout << "curans = " << ans << endl; } //cout << endl; //ギリギリをいく used.insert(tonum(S[i])); //if(used.size() > K) { // break; //} } if(used.size() == K) { ans++; } ans %= DIV; ans += DIV; ans %= DIV; cout << ans << endl; }
#include <bits/stdc++.h> // #include <atcoder/all> #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for(int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; // using namespace atcoder; typedef long long int ll; typedef pair<int,int> P; #define yn {puts("Yes");}else{puts("No");} #define MAX_N 200005 int main() { string s[3]; int n[3] = {}; int f[26] = {}; rep(i,3){ cin >> s[i]; n[i] = s[i].size(); rep(j,n[i]) f[s[i][j]-'a'] = 1; } int cnt = 0; rep(i,26) cnt += f[i]; if(cnt > 10){ cout << "UNSOLVABLE" << endl; return 0; } int g[256] = {}; int now = 0; rep(i,26){ if(f[i]){ g[i+'a'] = now; now++; } } const int N = 10; vector<int> v(N); iota(v.begin(), v.end(), 0); // v に 0, 1, 2, ... N-1 を設定 do { int ng = 0; ll x[3] = {}; rep(i,3){ rep(j,n[i]){ if(j == 0 && v[g[s[i][j]]] == 0){ ng = 1; break; } x[i] *= 10; x[i] += v[g[s[i][j]]]; } if(ng) break; } if(ng == 0 && x[0]+x[1]==x[2]){ rep(i,3){ rep(j,n[i]) cout << v[g[s[i][j]]]; cout << endl; } return 0; } } while( next_permutation(v.begin(), v.end()) ); // 次の順列を生成 cout << "UNSOLVABLE" << endl; return 0; }
#include<iostream> #include<cmath> #include<vector> #include<string> #include<algorithm> using namespace std; template<typename T> bool vector_match(T t, vector<T> vec) { for (T v : vec) { if (v == t)return true; } return false; } vector<char> getUsedChar(string str) { vector<char> used; for (char c : str) { if (!vector_match(c, used)) used.push_back(c); } return used; } bool isLess10char(vector<char> used) { if (used.size() <= 10) return true; else return false; } string replaceChar(string str, char change, char changed) { for (int i = 0; i < str.size(); i++) { if (str[i] == change) str[i] = changed; } return str; } vector<int> solve(const int& depth, const vector<char>& usedc, const vector<int>& usedi, string s1, string s2, string s3) { if (depth != usedc.size()) { for (int i = '0' + 0; i < '0' + 10; i++) { if (i == '0' && (s1[0] == usedc[depth] || s2[0] == usedc[depth] || s3[0] == usedc[depth])) continue; vector<int> new_usedi = usedi; if (!vector_match(i, usedi)) { new_usedi.push_back(i); vector<int> ans = solve(depth + 1, usedc, new_usedi, replaceChar(s1, usedc[depth], i), replaceChar(s2, usedc[depth], i), replaceChar(s3, usedc[depth], i)); if (ans.size() != 0) return ans; } } } else { if (stol(s1) + stol(s2) == stol(s3)) return usedi; else return vector<int>(); } return vector<int>(); } int main() { string S[3]; cin >> S[0] >> S[1] >> S[2]; vector<char> used = getUsedChar(S[0] + S[1] + S[2]); vector<int> ans; if (!isLess10char(used)) cout << "UNSOLVABLE" << endl; else { ans = solve(0, used, vector<int>(), S[0], S[1], S[2]); if (ans.size() == 0) cout << "UNSOLVABLE" << endl; else { for (int i = 0; i < ans.size(); i++) { S[0] = replaceChar(S[0], used[i], ans[i]); S[1] = replaceChar(S[1], used[i], ans[i]); S[2] = replaceChar(S[2], used[i], ans[i]); } cout << S[0] << endl << S[1] << endl << S[2] << endl; } } return 0; }
#include<bits/stdc++.h> #include<vector> #define ll long long #define ld long double #define F first #define S second #define MAXN 1000005 #define Tsetso ios_base::sync_with_stdio(0) ; cin.tie(0) ; using namespace std; #define rep(i,n) for(int i=0;i<n;++i) int main() { string s; cin>>s; int t=s.size(); char a; bool b=true; for(int i=1;i<t;i++){ a=s[0]; if(a==s[i]){ b=true; }else{ b=false; break; } } if(b){ cout<<"Won"; }else{ cout<<"Lost"; } return 0; }
#include<bits/stdc++.h> using namespace std; using ll=long long; constexpr ll mod=1e9+7; int main() { cin.tie(0); ios_base::sync_with_stdio(false); ll n; cin>>n; vector<vector<ll>> c(n, vector<ll>(n)); vector<ll> a(n, 1LL<<60), b(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin>>c[i][j]; a[i] = min(a[i], c[i][j]); } b[i] = c[i][i] - a[i]; } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (c[i][j] != a[i]+b[j]) { cout << "No"; return 0; } } } cout << "Yes\n"; for (int i = 0; i < n; ++i) { cout << a[i] << " "; } cout << "\n"; for (int i = 0; i < n; ++i) { cout << b[i] << " "; } }
#include<bits/stdc++.h> typedef long long int lli; typedef long double lld; typedef long long ll; #define int long long //Fast Input I/O #define fio ios_base::sync_with_stdio(false), cin.tie(NULL); //Datatype #define vi vector<int> #define vlli vector<long long int> #define vvi vector<vector<int>> #define vvlli vector<vector<long long int>> #define ppi pair<int, int> #define rppi pair<int, pair<int, int>> #define lppi pair<pair<int, int>, int> #define vppi vector<pair<int, int>> #define sppi stack<pair<int int>> #define qppi queue<pair<int, int>> //function #define f first #define s second #define pb(x) push_back(x) #define mkp(i, j) make_pair(i, j) #define lmkp(i,j,k) make_pair(make_pair(i,j),k) #define rmkp(i,j,k) make_pair(i,make_pair(j,k)) //loop #define loop(i,n) for (i = 0; i < n; ++i) #define loops(i,k,n) for (i = k; i <= n; ++i) #define looprev(i,k,n) for (i = k; i >= n; --i) //Const #define inf (int)1e9 #define eps 1e-9 #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 //Print #define prd(n) printf("%d", n) #define prl(n) printf("%lld", n) #define prdn(n) printf("%d\n", n) #define prln(n) printf("%lld\n", n) #define prf(n) printf("%f", n) //Scan #define scd(n) scanf("%d", &n) #define scd2(a, b) scanf("%d %d", &a, &b) #define scd3(a, b, c) scanf("%d %d %d", &a, &b, &c) #define scl(n) scanf("%lld", &n) #define scl2(a, b) scanf("%lld %lld", &a, &b) #define scl3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c) #define scf(n) scanf("%f", &n) #define all(x) (x).begin(), (x).end() #define mod 998244353 const long long N = 200005; using namespace std; void online_judge() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } 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; } vector<int> primes[N]; vector<int> f(2 * N, 0); void process() { for (int i = 2; i < N; i++) { if (primes[i].size()) continue; for (int j = i; j < N; j += i) { primes[j].pb(i); } } f[0] = f[1] = 1; for (int i = 2; i < 2 * N; i++) { f[i] = (i * f[i - 1]) % mod; } } int inv(int a) { return power(a, mod - 2, mod); } int choose(int n , int r) { return (((f[n] * inv(f[n - r])) % mod) * inv(f[r])) % mod; } void solve() { process(); int n, m; cin >> n >> m; int ans = 0; for (int i = 1; i <= m; i++) { int res = 1; for (auto j : primes[i]) { int cnt = n; int c = i; while (c > 0 && c % j == 0) { c /= j; cnt++; } res *= choose(cnt - 1, n - 1); res %= mod; } ans += res; ans %= mod; } cout << ans; } int32_t main() { fio; online_judge(); lli t = 1; //cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define deb(k) cerr << #k << ": " << k << "\n"; #define size(a) (int)a.size() #define fastcin cin.tie(0)->sync_with_stdio(0); #define st first #define nd second #define pb push_back #define mk make_pair #define int long long typedef long double ldbl; typedef double dbl; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef map<int, int> mii; typedef vector<int> vint; #define MAX 300100 #define MAXLG 20 const int inf = 0x3f3f3f3f; const ll mod = 998244353; const ll linf = 0x3f3f3f3f3f3f3f3f; const int N = 300100; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll fat[MAX+100]; ll ifat[MAX+100]; ll power(ll x, ll y, ll p){ ll res = 1; x = x % p; while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; } void init(){ fat[0] = 1; fat[1] = 1; for(ll i=2;i<=MAX;i++){ fat[i] = (fat[i-1]*i)%mod; } ifat[MAX] = power(fat[MAX], mod-2, mod); for(ll i=MAX-1;i>=0;i--) ifat[i] = (ifat[i+1]*(i+1))%mod; } int choose(int x, int y){ if(y < 0 || y > x || x < 0) return 0; return fat[x]*(ifat[y]*ifat[x-y]%mod)%mod; } int dp[N][20]; bool vis[N][20]; int n, m; int sol(int x, int y){ if(vis[x][y]) return dp[x][y]; vis[x][y] = 1; int &c = dp[x][y]; c = choose(n-1, y-1); for(int i=2;i<=m;i++){ if(x*i > m) break; c = (c + sol(x*i, y+1))%mod; } return c; } void solve(){ init(); cin>>n>>m; int ans = 0; for(int i=1;i<=m;i++) ans = (ans + sol(i, 1))%mod; cout<<ans<<"\n"; // Have you read the problem again? // Maybe you understood the wrong problem } int32_t main(){ fastcin; int t_ = 1; //cin>>t_; while(t_--) solve(); return 0; }
#include <iostream> #include <queue> using namespace std; using ll = long long; int n; priority_queue<ll> q; void solve() { q.push(0); ll res = 1, before = q.top(), now; q.pop(); while (q.size() > 0) { now = q.top(); q.pop(); if (before > now) { res = res * (before - now + 1) % (1000000007); before = now; } } cout << res << '\n'; } int main() { ll qtemp; cin >> n; for (int i=0; i<n; i++) { cin >> qtemp; q.push(qtemp); } solve(); return 0; }
/*pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops")*/ #include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++) #define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) RFOR(i, 0, n) #define ALL(v) v.begin(), v.end() #define bra(first, second) '(' << first << ',' << second << ')' //constexpr ll MOD = 1000000007; constexpr ll MOD = 998244353; ll INF = 1001001001001001001; long double EPS = 1e-7; long double PI = 3.141592653589793238; template <typename T> void remove(std::vector<T> &vector, unsigned int index) { vector.erase(vector.begin() + index); } using Graph = vector<vector<ll>>; // MOD確認 ll N; ll A[10010]; ll B[10010]; ll C[10010]; int main(){ cin >> N; rep(i,N) cin >> A[i]; rep(i,N){ FOR(j,i,N){ if(A[i] <= A[j]) B[i]++; else break; } RFOR(j,0,i){ if(A[i] <= A[j]) C[i]++; else break; } } ll ans = 0; rep(i,N){ ans = max(ans,A[i] * (B[i] + C[i])); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<int, ll> pil; typedef pair<ll, ll> pll; #define mp make_pair #define fr first #define sc second void solve() { int N; cin >> N; string S, T; cin >> S >> T; int cnt = count(S.begin(), S.end(), '0'); if (cnt != count(T.begin(), T.end(), '0')) { cout << -1 << '\n'; return; } vector<int> p1, p2; for (int i = 0; i < N; i++) { if (S[i] == '0') { p1.push_back(i); } if (T[i] == '0') { p2.push_back(i); } } int ans = 1e6; for (int ite = 0; ite < 2; ite++) { int reg = 0; for (int i = cnt - 1; i >= 0; i--) { reg += (p1[i] != p2[i]); } ans = min(ans, reg); reverse(p1.begin(), p1.end()); reverse(p2.begin(), p2.end()); } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; while (t--) solve(); return 0; }
#include <iostream> #include <cstdio> #define maxn 105 using namespace std; int n, k; int f[maxn][maxn];//2^i以j开始 char s[maxn]; int cf[maxn]; int match(int x, int y) { if(x < y) swap(x, y); if(x == 2 && y == 0) return y; else return x; } int main() { scanf("%d%d%s", &n, &k, s); cf[0] = 1; for (int i = 1; i < maxn; i++) { cf[i] = cf[i - 1] * 2 % n; } for (int i = 0; i < n; i++) { if(s[i] == 'R') f[0][i] = 0; if(s[i] == 'P') f[0][i] = 1; if(s[i] == 'S') f[0][i] = 2; } for (int i = 1; i <= k; i++) { for (int j = 0; j < n; j++) { int x = f[i - 1][j]; int y = f[i - 1][(j + cf[i - 1]) % n]; f[i][j] = match(x, y); } } if(f[k][0] == 0) printf("R"); if(f[k][0] == 1) printf("P"); if(f[k][0] == 2) printf("S"); 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 n, q; string s; cin >> n >> s >> q; string str[2]; str[0] = s.substr(0, n); str[1] = s.substr(n, n); rep(i, q) { int t, a, b; cin >> t >> a >> b; a--; b--; if (t == 1) { swap(str[a / n][a % n], str[b / n][b % n]); } else { swap(str[0], str[1]); } } cout << str[0] + str[1] << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define readlist(a, n) for(int _i=0; _i<(n); _i++) {cin >> (a)[_i];} int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; string s; cin >> s; // cout << "s: " << s << endl; int q; cin >> q; // cout << "Q" << q << endl; int flip = 0; for(int i =0; i < q; i++) { int t, a, b; cin >> t >> a >> b; if (t==1) { a--; b--; if (flip) { a = (a >= n)?(a-n):(a+n); b = (b >= n)?(b-n):(b+n); } swap(s[a], s[b]); } if(t==2) { flip = 1 - flip; } } if (flip) for(int i = 0; i <n; i++) swap(s[i], s[n+i]); cout << s << endl; return 0; }
/* * author :Sadik Hassan(_sad_) * */ #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; #define nl "\n" #define pb push_back #define fi first #define se second #define MP make_pair #define PI (acos(-1.0)) #define rep1(i,n) for(int i=1;i<=n;i++) #define rep(i,n) for(int i=0;i<n;i++) #define urep(i,n) for(int i=n-1;i>=0;i--) #define urep1(i,n) for(int i=n;i>=1;i--) #define SZ(s) (int)s.size() #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define w(t) int t;cin>>t;while(t--) #define _SAD() ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(15); typedef vector<int> vi; typedef vector<ll> vii; typedef set<int> si; typedef set<ll> sii; /*---------------------------------------------------------------------*/ const int N = (int)2e5+5; const int MOD =(int)1e9+7; const ll INF = (ll)1e18+5; int main() { _SAD() int a,b; cin>>a>>b; cout<<(2*a+100)-b<<nl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e6 + 10; const int mod = 998244353; const int inf = INT_MAX; int main() { int a, b; cin >> a >> b; cout << 2*a+100-b; system("pause"); return 0; }
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define ll long long using namespace std; int main(){ ll n;cin>>n; vector<ll> vec(n), vecmax, vecall, vecminus; ll kaka=0, ka=0, choudoii=0; for(int i=0;i<n;i++){cin>>vec.at(i);kaka=max(vec.at(i), kaka);vecmax.push_back(kaka);ka+=vec.at(i);vecall.push_back(ka);choudoii-=vec.at(i)*(i+1);vecminus.push_back(choudoii);} for(int i=0;i<n;i++){ ll ans=(i+2)*vecall.at(i)+(i+1)*vecmax.at(i)+vecminus.at(i); cout<<ans<<endl; } }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; long long l, res = 0, cval = 0, mod = 998244353; vector<long long> v; cin >> n; for(int i = 0; i < n; ++i) { cin >> l; v.push_back(l); } sort(v.begin(), v.end()); for(auto l = v.begin(); l != v.end(); ++l) { res = (res + (cval + *l) * *l) % mod; cval = (2*cval + *l) % mod; } cout << res << endl; return 0; }
#include <cmath> #include <vector> #include <iostream> #include <algorithm> #include <set> #include <iomanip> #include <queue> #include <string> #include <map> #include <fstream> #include <cassert> #include <stack> #include <climits> #include <array> #include <unordered_set> #include <unordered_map> #include <memory> #include <functional> #include <cfloat> #include <numeric> #include <random> #include <sstream> #include <bitset> struct Edge { int to, color, id; }; int main() { int n, m; std::cin >> n >> m; std::vector<std::vector<Edge>> nodes(n); for (auto i = 0; i < m; ++i) { int u, v, c; std::cin >> u >> v >> c; --u; --v; nodes[u].push_back(Edge{ v, c, i }); nodes[v].push_back(Edge{ u, c, i }); } std::stack<std::pair<int, int>> stack; std::vector<int> parent(n, -1); std::vector<int> color_from_parent(n, -1); std::vector<bool> is_in_tree(m, false); parent[0] = 0; stack.emplace(0, 0); while (!stack.empty()) { const auto [prev, current] = stack.top(); stack.pop(); for (const auto [to, color, id] : nodes[current]) { if (to == prev || parent[to] != -1) continue; is_in_tree[id] = true; parent[to] = current; color_from_parent[to] = (color == color_from_parent[current] ? -1 : color); stack.emplace(current, to); } } for (auto i = 0; i < n; ++i) { if (color_from_parent[i] == -1) { std::vector<int> colors; for (const auto [to, color, id] : nodes[i]) { if (is_in_tree[id]) { colors.push_back(color); } } std::sort(colors.begin(), colors.end()); colors.erase(std::unique(colors.begin(), colors.end()), colors.end()); int color = 1; for (const auto c : colors) { if (c == color) ++color; else break; } color_from_parent[i] = color; } } for (const auto c : color_from_parent) { std::cout << c << '\n'; } }
#ifdef _DEBUG #define _GLIBCXX_DEBUG #endif #if __has_include(<atcoder/all>) #include <atcoder/all> #endif #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<int, ll>; #define rep(i, a, b) for(int i = (int)(a); i <= (int)(b); i++) #define rrep(i, a, b) for(int i = (int)(a); i >= (int)(b); i--) const int MOD = 1000000007; const int MOD2 = 998244353; const ll INF = 1e18; const ld PI = acos(-1); vector<int> G[200000]; int ans; ll bfs(int v,int D,int p=-1){ ll mn=INF; ll mx=-INF; for(auto to:G[v]){ if(to==p) continue; ll z=bfs(to,D,v)-1; mn=min(mn,z); mx=max(mx,z); } if(mn+mx>=1){ mn=mx; } else if(v==0){ ans++; } if(G[v].size()==1&&p!=-1){ mn=0; } else if(v!=0&&mn==-D){ ans++; mn=D+1; } return mn; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N,K; cin >> N >> K; rep(i,0,N-2){ int u,v; cin >> u >> v; u--;v--; G[u].push_back(v); G[v].push_back(u); } int ok=N,ng=0; while(abs(ok-ng)>1){ ans=0; int mid=(ok+ng)/2; int L=bfs(0,mid); if(ans>K){ ng=mid; } else{ ok=mid; } } cout << ok << endl; }
#include <bits/stdc++.h> using namespace std; struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio; int main() { int n, m, t; cin >> n >> m >> t; int latest = 0; int a, b; int now_battery = n; while (m--) { cin >> a >> b; now_battery -= a - latest; if (now_battery <= 0) break ; now_battery = min(n, now_battery + b - a); latest = b; } now_battery -= t - latest; if (now_battery <= 0) cout << "No"; else cout << "Yes"; cout << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, s, e) for (ll i = s; i < e; i++) #define rrep(i, s, e) for (ll i = s; i > e; i--) int main() { ll t; cin >> t; rep(i, 0, t) { ll l, r; cin >> l >> r; if (2 * l > r) cout << 0 << endl; else cout << ((r - 2 * l + 2) * (r - 2 * l + 1)) / 2 << endl; } }
////=====BIsmillahir Rahmanir Rahim =====//// /* ______ _______ /\ |``\ | | / | / \ |__/ |____ |/ | / _ _\ | \ | |\ | / \ | \ |______ | \ Dept. of CSE Comilla University */ #include<bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // #include <ext/pb_ds/detail/standard_policies.hpp> #define fi 2*acos(0.0) #define ee 2.71828 #define ll long long #define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define Node struct node #define spc " " #define E 2.71828182845904523536 #define pb push_back #define pp pop_back #define ff first #define ss second #define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m #define edl printf("\n") #define infinity 1e16 #define mod 1000000007 #define cn continue #define csprint1 printf("Case %lld: ", cs++) #define csprint2 printf("Case %lld:\n", cs++) #define sf(a) scanf("%lld", &a) #define sff(a,b) scanf("%lld %lld",&a,&b) #define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define sffff(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d) #define all(v) v.begin(),v.end() #define pfn(a) printf("%lld\n",a) #define pfs(a) printf("%lld ",a) // using namespace __gnu_pbds; using namespace std; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<pl> vpi; typedef vector<pl> vpl; // typedef tree<pair<ll, int> , null_type, less<pair<ll, int> >, rb_tree_tag, tree_order_statistics_node_update> ost; #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a <<","<< spc; err(++it, args...); cout<<edl; } ///Bit manipulation bool checkbit(int mask,int bit){return mask & (1<<bit);} int setbit(int mask,int bit){ return mask | (1<<bit) ; } int clearbit(int mask,int bit){return mask & ~(1<<bit);} int togglebit(int mask,int bit){return mask ^ (1<<bit);} int bitno(int mask) {return (int)__builtin_popcount(mask);} /*----------------------Graph Moves----------------*/ const int fx[]={+1,-1,+0,+0}; const int fy[]={+0,+0,+1,-1}; //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move //const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move /*------------------------------------------------*/ ///=====================================/// const long long maX =1e5+10; int main(){FIO; ll n; ll ans=0; cin>>n; for(ll i=1;i<=n;i++){ for(ll j=1;j*i<=n;j++){ ans+=n/(i*j); } } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+5; int n,m; int a[N],b[N]; int main(){ int i,j; cin>>n; for(i=1;i<=n;i++){ for(j=i;j<=n;j+=i) b[j]++; } ll ans=0; for(i=1;i<=n;i++) ans+=b[i]*ll(n/i); cout<<ans; return 0; }
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N=1000005; struct node{ int c,id,val; }s[N]; bool cmp1(node a,node b){return a.val<b.val;} bool cmp2(node a,node b){return a.id<b.id;} int st[N],top; int main(){ int n; scanf("%d",&n);n<<=1; for(int i=1;i<=n;i++) scanf("%d",&s[i].val),s[i].c=0,s[i].id=i; sort(s+1,s+n+1,cmp1); for(int i=n/2+1;i<=n;i++) s[i].c=1; sort(s+1,s+n+1,cmp2); int nl=-1; for(int i=1;i<=n;i++){ if(nl==-1) nl=s[i].c,putchar('('),st[++top]=s[i].id; else if(s[i].c==nl) putchar('('),st[++top]=s[i].id; else putchar(')'),st[top--]=0; if(!top) nl=-1; } putchar('\n'); }
//#define NDEBUG #include <algorithm> #include <cstddef> #include <cstdint> #include <iostream> #include <utility> #include <vector> namespace n91 { using i32 = std::int32_t; using i64 = std::int64_t; using u32 = std::uint32_t; using u64 = std::uint64_t; using isize = std::ptrdiff_t; using usize = std::size_t; struct rep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { ++i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr rep(const usize f, const usize l) noexcept : f(std::min(f, l)), l(l) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; struct revrep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { --i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr revrep(const usize f, const usize l) noexcept : f(l - 1), l(std::min(f, l) - 1) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; template <class T> auto md_vec(const usize n, const T& value) { return std::vector<T>(n, value); } template <class... Args> auto md_vec(const usize n, Args... args) { return std::vector<decltype(md_vec(args...))>(n, md_vec(args...)); } template <class T> constexpr T difference(const T& a, const T& b) noexcept { return a < b ? b - a : a - b; } template <class T> void chmin(T& a, const T& b) noexcept { if (b < a) a = b; } template <class T> void chmax(T& a, const T& b) noexcept { if (a < b) a = b; } template <class F> class rec_lambda { F f; public: rec_lambda(F&& f) : f(std::move(f)) {} template <class... Args> auto operator()(Args&&... args) const { return f(*this, std::forward<Args>(args)...); } }; template <class F> auto make_rec(F&& f) { return rec_lambda<F>(std::move(f)); } template <class T> T scan() { T ret; std::cin >> ret; return ret; } constexpr char eoln = '\n'; template <class T> T ceildiv(const T& l, const T& r) { return l / r + (l % r != 0 ? 1 : 0); } } // namespace n91 #include <numeric> namespace n91 { void main_() { /* std::ios::sync_with_stdio(false); std::cin.tie(nullptr); //*/ const usize n = scan<usize>(); std::vector<i64> a(n), b(n); i64 base = 0; std::vector<i64> c(n); for (auto& e : a) { std::cin >> e; } for (auto& e : b) { std::cin >> e; } for (const usize i : rep(0, n)) { i64 x = a[i], y = b[i]; if (i % 2 == 1) { std::swap(x, y); } base += x; c[i] = y - x; } std::nth_element(c.begin(), c.begin() + n / 2, c.end(), std::greater<i64>()); base += std::accumulate(c.begin(), c.begin() + n / 2, i64(0)); std::cout << base << eoln; } } // namespace n91 int main() { n91::main_(); return 0; }
#include<bits/stdc++.h> using namespace std; const int INF = 1001001001; int main() { int ans = INF; int n; cin >> n; for(int i = 0; i < n; i++) { int a, p, x; cin >> a >> p >> x; if(a < x) ans = min(ans, p); } if(ans == INF) ans = -1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define mem(a) memset(a, 0, sizeof(a)) #define dbg(x) cout << #x << " = " << x << endl #define fi(i, l, r) for (int i = l; i < r; i++) #define cd(a) scanf("%d", &a) typedef long long ll; int main() { int N; cin >> N; bool ifCan = false; int m = 1e9 + 1; while (N--) { int a, b, c; scanf("%d%d%d", &a, &b, &c); if (a < c) { ifCan = true; m = min(m, b); } } if (ifCan) printf("%d\n", m); else printf("-1\n"); return 0; }
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> #define int long long using namespace std; inline int read() { int x=0; bool flag=1; char c=getchar(); while(c<'0'||c>'9') { if(c=='-') flag=0; c=getchar(); } while(c>='0'&&c<='9') { x=(x<<1)+(x<<3)+c-'0'; c=getchar(); } return (flag?x:~(x-1)); } struct node{ int to,nxt,v1,v2; } edge[200001]; struct que{ int to,val; bool operator<(const que& x)const { return val>x.val; } }; int n,m,cnt,head[100001],dis[100001],vis[100001]; void add(int a,int b,int c,int d) { edge[++cnt].to=b; edge[cnt].v1=c; edge[cnt].v2=d; edge[cnt].nxt=head[a]; head[a]=cnt; } priority_queue<que> q; void dij() { for(int i=2;i<=n;i++) dis[i]=2e18; q.push({1,0}); while(!q.empty()) { int t=q.top().to; q.pop(); if(vis[t]) continue; vis[t]=1; for(int i=head[t];i;i=edge[i].nxt) { int adj=edge[i].to,minn; int qr=sqrt(edge[i].v2); if(dis[t]>=qr) minn=dis[t]+edge[i].v1+edge[i].v2/(dis[t]+1); else minn=qr+edge[i].v1+edge[i].v2/(qr+1); /* for(int l=dis[t];l<=sqrt(edge[i].v2)+5;l++) minn=min(minn,l+edge[i].v1+edge[i].v2/(l+1)); for(int l=max(edge[i].v2/(dis[t]+1),sqrt(edge[i].v2)+1);l>=0;l--) minn=min(minn,l+edge[i].v1+edge[i].v2/(l+1)); */ if(minn<dis[adj]) { dis[adj]=minn; q.push({adj,minn}); } } } } signed main() { n=read(); m=read(); while(m--) { int a=read(),b=read(),c=read(),d=read(); add(a,b,c,d); add(b,a,c,d); } dij(); if(dis[n]==2e18) puts("-1"); else cout<<dis[n]; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m; int cnt[2]; int main() { scanf("%d %d", &n, &m); while (n--) { char s[30], sum = 0; scanf("%s", s); for (int j = 0; j < m; ++j) sum ^= s[j] ^ '0'; ++cnt[sum]; } printf("%lld\n", 1ll * cnt[0] * cnt[1]); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;} const char newl = '\n'; array<array<ll,1100000>,2> dp0,dp1; int main() { int n,k,mod,m = 510000; cin >> n >> k >> mod; vector<int> ans(n+1); for (int x = 0;x < ((n+1)/2+3)/4;++x) { int cnt[200]; for (int i = 0;i < 200;++i) cnt[i] = 0; int s = min(4,(n+1)/2-x*4); for (int i = 1;i <= s;++i) for (int j = 1;j <= n;++j) cnt[j-(x*4+i)+100]++; dp0[0].fill(0); dp0[1].fill(0); dp0[0][m] = k+1; int p = 0,l = m,h = m; for (int i = 1;i <= n;++i) { if (cnt[i+100] == s) { h += i*k; for (int j = l;j <= h-i;++j) (dp0[(p)&1][j+i] += dp0[(p)&1][j]) %= mod; for (int j = l;j <= h;++j) (dp0[(p+1)&1][j] = dp0[(p)&1][j]-dp0[(p)&1][j-i*(k+1)]) %= mod; p++; } if (cnt[-i+100] == s) { l -= i*k; for (int j = l;j <= h+i*k;++j) (dp0[(p)&1][j+i] += dp0[(p)&1][j]) %= mod; for (int j = l;j <= h;++j) (dp0[(p+1)&1][j] = dp0[(p)&1][j+i*k]-dp0[(p)&1][j-i]) %= mod; for (int j = h;j <= h+i*(k+1);++j) dp0[(p)&1][j+i] = 0; p++; } } for (int y = x*4+1;y <= x*4+s;++y) { dp1[1].fill(0); dp1[0] = dp0[p&1]; P a[100]; for (int i = 1;i <= n;++i) a[i-1] = {abs(i-y),i-y}; sort(a,a+n); int ll = l,hh = h,pp = 0; for (int i = 0;i < n;++i) { if (cnt[a[i].second+100] == s) { continue; } else if (a[i].second > 0) { hh += a[i].first*k; for (int j = ll;j <= hh-a[i].first;++j) (dp1[(pp)&1][j+a[i].first] += dp1[(pp)&1][j]) %= mod; for (int j = ll;j <= hh;++j) (dp1[(pp+1)&1][j] = dp1[(pp)&1][j]-dp1[(pp)&1][j-a[i].first*(k+1)]) %= mod; } else { ll -= a[i].first*k; for (int j = ll;j <= hh+a[i].first*k;++j) (dp1[(pp)&1][j+a[i].first] += dp1[(pp)&1][j]) %= mod; for (int j = ll;j <= hh;++j) (dp1[(pp+1)&1][j] = dp1[(pp)&1][j+a[i].first*k]-dp1[(pp)&1][j-a[i].first]) %= mod; for (int j = hh;j <= hh+a[i].first*k;++j) dp1[(pp)&1][j+a[i].first] = 0; } pp++; } ans[y] = ans[n-y+1] = (dp1[(pp)&1][m]-1+mod)%mod; } } for (int i = 1;i < n+1;++i) cout << ans[i] << newl; }
#include<bits/stdc++.h> using namespace std; const int N=105; typedef long long ll; int f[N][N*N*N],sum[N][N],p,lit[N],ans[N]; int main() { int n,m; cin>>n>>m>>p; for(int i=1;i<=n;i++) lit[i]=lit[i-1]+m*i; f[0][0]=1; for(int i=1;i<=n;i++) for(int j=0;j<=lit[i];j++) { sum[i-1][j%i]=(sum[i-1][j%i]+f[i-1][j])%p; if(j-(m+1)*i>=0) sum[i-1][j%i]=(sum[i-1][j%i]-f[i-1][j-(m+1)*i])%p; f[i][j]=sum[i-1][j%i]; // cout<<i<<" "<<j<<" "<<f[i][j]<<endl; } for(int x=1;x<=(n+1)/2;x++) { for(int j=0;j<=min(lit[x-1],lit[n-x]);j++) ans[x]=(ans[x]+1ll*f[x-1][j]*f[n-x][j]%p)%p; ans[x]=(1ll*ans[x]*(m+1)-1)%p; printf("%d\n",(ans[x]+p)%p); } for(int i=(n+1)/2+1,j=n/2;i<=n;i++,j--) printf("%d\n",(ans[j]+p)%p); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) int main(){ int n, m = 0; cin >> n; for(; m < n; m=m*2+1); rep(i,n){ int t = i*2, u = t+1; while(t >= n) t -= 1 << (31 - __builtin_clz(t)); while(u >= n) u -= 1 << (31 - __builtin_clz(u)); cout << t+1 << " " << u+1 << "\n"; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { auto f = [&n](int x) { return (x - 1) % n + 1; }; cout << f(i * 2) << " " << f(i * 2 + 1) << endl; } }
#include <bits/stdc++.h> #define FIXED_FLOAT(x) std::fixed <<std::setprecision(20) << (x) #define all(v) (v).begin(), (v).end() using namespace std; #define forn(i,n) for (int i = 0; i < (n); ++i) #define rforn(i, n) for(int i = (n) - 1;i >= 0;--i) using ll = long long; int mod = (ll)1e9 + 7; #define PI acos(-1) typedef pair<int, int> pairs; const int INF = 1e9 + 1; const int N = 2e5 + 100; const double eps = 1e-7; template <class T> using V = vector<T>; // from yosupo template <class T> using VV = V<V<T>>; // from yosupo template <typename XPAX> void ckma(XPAX &x, XPAX y) { x = (x < y ? y : x); } template <typename XPAX> void ckmi(XPAX &x, XPAX y) { x = (x > y ? y : x); } set<int> s; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) const int maxRep = 1e7; void solve() { int n; cin >> n; int iter = 0; VV<int> g(n); forn(i, n - 1) { int x; cin >> x; --x; g[x].push_back(i + 1); } V<int> tin(n), tout(n), ord(n); int T = 0; V<int> dep(n); auto dfs = [&](auto &&self, int v, int de) -> void { ord[T] = v; tin[v] = T++; dep[v] = de; for(auto c : g[v]) { self(self, c, de + 1); } tout[v] = T; }; dfs(dfs, 0, 0); VV<int> ps(n); forn(i, n) { int v = ord[i]; ps[dep[v]].push_back(i); } int q; cin >> q; while(q--) { int u, d; cin >> u >> d; --u; int L = tin[u]; int R = tout[u]; auto it1 = lower_bound(all(ps[d]), L); auto it2 = lower_bound(all(ps[d]), R); cout << (it2 - it1) << '\n'; } } void test_case() { int t; cin >> t; forn(p, t) { //cout << "Case #" << p + 1 << ": "; solve(); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); solve(); }
#include <bits/stdc++.h> #define int long long int using namespace std; signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); map<string , pair<int , int> > mp; int n; cin>>n; for(int x = 0;x<n;x++){ string s; cin>>s; if(s[0] == '!' ){ string a = ""; for(int i = 1;i<s.length();i++ ){ a.push_back(s[i] ); } mp[a].second++; } else{ mp[s].first++; } } bool sas = true;string ans; map<string , pair<int , int> > :: iterator it; for(it = mp.begin() ; it!= mp.end();it++){ if((it->second.first)&& (it->second.second) ){ ans = it->first;sas = false; ;break; } } if(sas ){ cout<<"satisfiable"; } else{ cout<<ans; } }
#include<bits/stdc++.h> using namespace std; class graph{ public: map<int,vector<int>> map1; void edges(int a,int b){ map1[a].push_back(b); } void tour_helper(int n,map<int,bool> &visited,int &count){ visited[n]=true; for(auto it:map1[n]){ if(visited[it]==false){ count++; tour_helper(it,visited,count); } } } void tour(int n){ map<int,bool> visited; for(auto it:map1) visited[it.first]=false; int ans=0; for(auto it:map1){ tour_helper(it.first,visited,ans); for(auto it:map1) visited[it.first]=false; } cout<<ans+n<<endl; } }; int main() { ios_base::sync_with_stdio(false);cin.tie(NULL); int n,m; cin>>n>>m; graph g; for(int i=0;i<m;i++){ int a,b; cin>>a>>b; g.edges(a,b); } g.tour(n); }
#include <iostream> #include <map> #include <set> #include <cmath> #include <queue> #include <vector> #include <string> #include <algorithm> #include <functional> using namespace std; long long N, K; long long A[1 << 18], B[1 << 18]; bool used[1 << 18]; bool forced[1 << 18]; long long dp[1 << 18]; vector<int> X[1 << 18]; void dfs(int pos, int border) { used[pos] = true; vector<long long> vec; for (int i : X[pos]) { if (used[i] == true) continue; dfs(i, border); vec.push_back(dp[i] + 1); } sort(vec.begin(), vec.end()); if (vec.size() == 0) { dp[pos] = 0; return; } if (vec[0] + vec[vec.size() - 1] <= -1) { dp[pos] = vec[0]; return; } else if (vec[vec.size() - 1] == border) { forced[pos] = true; dp[pos] = -(border + 1); return; } else { dp[pos] = vec[vec.size() - 1]; return; } } bool solve(int border) { for (int i = 1; i <= N; i++) dp[i] = 0; for (int i = 1; i <= N; i++) used[i] = false; for (int i = 1; i <= N; i++) forced[i] = false; dfs(1, border); int cnts = 0; if (dp[1] >= 0 || forced[1] == true) cnts++; for (int i = 2; i <= N; i++) { if (forced[i] == true) cnts++; } if (cnts > K) return false; return true; } int main() { cin >> N >> K; for (int i = 1; i <= N - 1; i++) { cin >> A[i] >> B[i]; X[A[i]].push_back(B[i]); X[B[i]].push_back(A[i]); } long long cl = 1, cr = N + 1, cm, minx = (1 << 30); for (int i = 0; i < 22; i++) { cm = (cl + cr) / 2; bool I = solve(cm); if (I == true) { cr = cm; minx = min(minx, cm); } else { cl = cm; } } cout << minx << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define MOD2 998244353 #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define reps(i,s,n) for (int i = (int)(s); i < (int)(n); i++) #define repit(i,C) for (auto i = (C).begin(); i != (C).end(); i++) #define pr(a) cout << a #define prl(a) cout << (a) << endl #define prld(a) cout << setprecision(15)<< (a) << endl #define allrange(a) a.begin(),a.end() bool solve_translated(vector<pair<int,int>> &S,vector<pair<int,int>> &T){ int N = S.size(); int dx = S[0].first-T[0].first; int dy = S[0].second-T[0].second; bool flg = true; reps(i,1,N){ if(!((S[i].first==T[i].first+dx) && (S[i].second==T[i].second+dy))){flg = false; break;} } return flg; } /*ピタゴラ三角形 5 12 13 8 15 17 3 4 5 */ vector<pair<int,int>> Pitagora_rot(vector<pair<int,int>> &S,int a, int b , int c){ int N = S.size(); vector<pair<int,int>> PS(N); auto pt0 = S[0]; PS[0] = pt0; bool flg = true; reps(i,1,N){ int dx = S[i].first - pt0.first; int dy = S[i].second - pt0.second; if(((dx*b+dy*a)%c)!=0 || ((dx*a-dy*b)%c)!=0) {flg = false; break;} PS[i] = make_pair((dx*a-dy*b)/c+pt0.first, (dx*b+dy*a)/c+pt0.second); } if(flg) return PS; else return vector<pair<int,int>>(); } int main(){ std::cin.tie(0); // cinとcoutの同期を解除 std::ios::sync_with_stdio(false); int N;cin >> N; bool flg=true; vector<pair<int,int>> S(N),T(N); rep(i,N) { int x,y; cin >> x >> y; S[i].first = x;S[i].second = y; } rep(i,N) { int x,y; cin >> x >> y; T[i].first = x; T[i].second = y; } sort(allrange(T)); /*ピタゴラ三角形 5 12 13 8 15 17 3 4 5 */ vector<vector<int>> tri(0); tri.push_back(vector<int>({5, 12, 13})); // tri.push_back(vector<int>({12, 5, 13})); // tri.push_back(vector<int>({8,15,17})); // tri.push_back(vector<int>({15,8,17})); tri.push_back(vector<int>({3,4,5})); tri.push_back(vector<int>({4,3,5})); tri.push_back(vector<int>({0,1,1})); tri.push_back(vector<int>({-1,0,1})); tri.push_back(vector<int>({0,-1,1})); tri.push_back(vector<int>({1,0,1})); //tri.push_back(vector<int>({-5, 12, 13})); // tri.push_back(vector<int>({-12, 5, 13})); // tri.push_back(vector<int>({-8,15,17})); // tri.push_back(vector<int>({-15,8,17})); tri.push_back(vector<int>({-3,4,5})); tri.push_back(vector<int>({-4,3,5})); // tri.push_back(vector<int>({-5, -12, 13})); // tri.push_back(vector<int>({-12, -5, 13})); // tri.push_back(vector<int>({-8,-15,17})); // tri.push_back(vector<int>({-15,-8,17})); tri.push_back(vector<int>({-3,-4,5})); tri.push_back(vector<int>({-4,-3,5})); // tri.push_back(vector<int>({5, -12, 13})); // tri.push_back(vector<int>({12, -5, 13})); // tri.push_back(vector<int>({8,-15,17})); tri.push_back(vector<int>({15,-8,17})); tri.push_back(vector<int>({3,-4,5})); tri.push_back(vector<int>({4,-3,5})); flg=false; if(S.size()==2 && T.size()==2){ auto sx = S[0].first-S[1].first; auto sy = S[0].second-S[1].second; auto tx = T[0].first-T[1].first; auto ty = T[0].second-T[1].second; flg= (sx*sx+sy*sy==tx*tx+ty*ty); } else { rep(j,tri.size()){ auto S2 = Pitagora_rot(S,tri[j][0],tri[j][1],tri[j][2]); if(S2.empty()) continue; sort(allrange(S2)); flg = solve_translated(S2,T); if(flg) break; } } if(flg) prl("Yes"); else prl("No"); }
#include<bits/stdc++.h> using namespace std; #define ll long long #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define REP(i,n) for(ll i=0;i<(n);i++) #define FOR(i,a,b) for(ll i=(a);i<(b);i++) #define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c)) #define pb(x) push_back(x) #define mp(x,y) make_pair(x,y) #define ff first #define ss second #define dd long double #define all(x) x.begin(),x.end() struct point{ ll x,y,idx; }; bool srt1(point & p1, point & p2){ return p1.x<p2.x; } bool srt2(point & p1, point & p2){ return p1.y<p2.y; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin>>n; vector<point> arr(n); REP(i,n){ cin>>arr[i].x>>arr[i].y; arr[i].idx=i; } sort(all(arr),srt1); map<pair<ll,ll>,ll> m; m[mp(min(arr[n-1].idx,arr[0].idx),max(arr[n-1].idx,arr[0].idx))]=max(arr[n-1].x-arr[0].x,m[mp(min(arr[n-1].idx,arr[0].idx),max(arr[n-1].idx,arr[0].idx))]); m[mp(min(arr[n-1].idx,arr[1].idx),max(arr[n-1].idx,arr[1].idx))]=max(arr[n-1].x-arr[1].x,m[mp(min(arr[n-1].idx,arr[1].idx),max(arr[n-1].idx,arr[1].idx))]); m[mp(min(arr[n-2].idx,arr[0].idx),max(arr[n-2].idx,arr[0].idx))]=max(arr[n-2].x-arr[0].x,m[mp(min(arr[n-2].idx,arr[0].idx),max(arr[n-2].idx,arr[0].idx))]); sort(all(arr),srt2); m[mp(min(arr[n-1].idx,arr[0].idx),max(arr[n-1].idx,arr[0].idx))]=max(arr[n-1].y-arr[0].y,m[mp(min(arr[n-1].idx,arr[0].idx),max(arr[n-1].idx,arr[0].idx))]); m[mp(min(arr[n-1].idx,arr[1].idx),max(arr[n-1].idx,arr[1].idx))]=max(arr[n-1].y-arr[1].y,m[mp(min(arr[n-1].idx,arr[1].idx),max(arr[n-1].idx,arr[1].idx))]); m[mp(min(arr[n-2].idx,arr[0].idx),max(arr[n-2].idx,arr[0].idx))]=max(arr[n-2].y-arr[0].y,m[mp(min(arr[n-2].idx,arr[0].idx),max(arr[n-2].idx,arr[0].idx))]); vector<ll> aux; for(auto & [x,y]:m){ aux.pb(y); } sort(all(aux)); reverse(all(aux)); cout<<aux[1]<<endl; }
// In the name of god #include <bits/stdc++.h> #define F first #define S second #define pb push_back #define all(x) x.begin(), x.end() #define Sort(x) sort(all(x)) #define debug(x) cerr << #x << " :" << x << "\n" #define use_file freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef string str; const ll maxn = 4e5 + 5, inf = 1e18, mod = 998244353; ll n, q, ps[maxn], h[maxn], a[maxn], b[maxn]; vector <ll> adj[maxn]; void dfs(ll u, ll par){ ps[u] += ps[par]; for(ll j : adj[u]){ if(j == par)continue; h[j] = h[u] + 1; dfs(j, u); } } int main(){ ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; for(ll i = 1; i < n; i ++){ cin >> a[i] >> b[i]; adj[a[i]].pb(b[i]); adj[b[i]].pb(a[i]); } dfs(1, 0); cin >> q; while(q --){ ll t, e, x; cin >> t >> e >> x; if(t == 1){ if(h[a[e]] > h[b[e]])ps[a[e]] += x; else{ ps[b[e]] -= x; ps[1] += x; } } else{ if(h[b[e]] > h[a[e]])ps[b[e]] += x; else{ ps[1] += x; ps[a[e]] -= x; } } } dfs(1, 0); for(ll i = 1; i <= n; i ++)cout << ps[i] << "\n"; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define endl "\n" void dfs(vector<vector<ll>> &adj , vector<bool> &vis ,ll &edges , ll &root , ll start , ll &nov){ vis[start]=true; nov++; if(start==root){ edges += adj[start].size(); } else{ edges += adj[start].size() - 1; } for(auto x:adj[start]){ if(vis[x]==false){ dfs(adj , vis , edges ,root , x , nov); } } } int main() { //forItachiOfTheLeaf ios_base::sync_with_stdio(false); cin.tie(nullptr); ll n; cin>>n; vector<vector<ll>> adj(400004); ll i,x,y; for(i=0;i<n;i++){ cin>>x>>y; adj[x].pb(y); adj[y].pb(x); } vector<bool> vis(400004 , false); ll ans = 0; for(i=1;i<=400000;i++){ if(vis[i]==false&&adj[i].size()>=1){ ll edges = 0 , root = i,nov = 0; dfs(adj , vis , edges , i , i , nov); if(nov==edges+1){ ans += nov-1; } else{ ans += nov; } } } cout<<ans<<endl; }
#include <iostream> #include <vector> using namespace std; int main() { long long A, B; cin>>A>>B; vector<int> F; for (int f=2; f<=72; f++) { bool ok = true; for (int i=2; i<f; i++) if (f%i==0) ok = false; if (ok) F.push_back(f); } int n = (int)F.size(); vector<long long> T(1<<n); T[0] = 1; for (long long c=A; c<=B; c++) { vector<long long> P = T; int b = 0; for (int i=0; i<n; i++) if (c%F[i]==0) b |= 1<<i; for (int i=0; i<1<<n; i++) if ((b&i)==0) T[b|i] += P[i]; } long long ans = 0; for (long long t: T) ans += t; cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long ll gcd(ll x,ll y) { return x==0 ? y : gcd(y%x,x); } const int M = 19; const int BIT = (1<<M); int cc[BIT],op[BIT],cc2[BIT],dp[BIT]; void solve2() { ll x,y; cin>>x>>y; ll ret = 0; if(y-x+1<=10) { ll v[10]; for(ll i=x;i<=y;++i) { v[i-x] = i; } int len = y-x+1,B = (1<<len); for(int bit=0;bit<B;++bit) { bool isGood = true; for(int i=0;i<len && isGood;++i) { if(bit&(1<<i)) { for(int j=0;j<len;++j) { if( (bit&(1<<j)) && j!=i) { if(gcd(v[j],v[i])!=1) { isGood = false; break; } } } } } ret += isGood; } } else { ll even[50]; int e_pos = 0; even[e_pos++] = 1; vector<ll> v[2]; for(ll i=x;i<=y;++i) { if(i%2==0) { even[e_pos++] = i; } else { v[v[0].size()<M ? 0 : 1].push_back(i); } } vector<pair<int,int> > g; for(int i=0;i<v[0].size();++i) { int bit = 0; for(int j=0;j<v[0].size();++j) { if(i!=j && gcd(v[0][j],v[0][i])!=1) { bit |= (1<<j); } } int bit2 = 0; for(int j=0;j<v[1].size();++j) { if(gcd(v[1][j],v[0][i])!=1) { bit2 |= (1<<j); } } g.push_back({bit,bit2}); } int B = (1<<v[0].size()); for(int bit=0;bit<B;++bit) { bool isGood = true; for(int i=0;i<v[0].size();++i) { if(bit&(1<<i)) { isGood &= (g[i].first&bit) ==0; op[bit] |= g[i].second; } } cc[bit] = isGood ? 1 : 0; } g.clear(); for(int i=0;i<v[1].size();++i) { int bit = 0; for(int j=0;j<v[1].size();++j) { if(i!=j && gcd(v[1][j],v[1][i])!=1) { bit |= (1<<j); } } g.push_back({bit,0}); } int B2 = (1<<v[1].size()); for(int bit=0;bit<B2;++bit) { bool isGood = true; for(int i=0;i<v[1].size();++i) { if(bit&(1<<i)) { isGood &= (g[i].first&bit) ==0; } } cc2[bit] = isGood ? 1 : 0; } for(int iter=0;iter<e_pos;++iter) { ll cur_value = even[iter]; memset(dp,0,sizeof(dp)); int bit1 = 0,bit2=0; for(int i=0;i<v[0].size();++i) { if(gcd(cur_value,v[0][i])!=1) bit1 |= (1<<i); } for(int i=0;i<v[1].size();++i) { if(gcd(cur_value,v[1][i])!=1) bit2 |= (1<<i); } for(int bit=0;bit<B2;++bit) { dp[bit] = cc2[bit] >0 && ( (bit&bit2)==0); } for(int b=0;b<v[1].size();++b) { for(int bit=0;bit<B2;++bit) { if(bit&(1<<b)) { dp[bit] += dp[bit^(1<<b)]; } } } int x = B2-1; for(int bit=0;bit<B;++bit) { if(bit&bit1) continue; if(cc[bit]==0) continue; ret += dp[x^op[bit]]; } } } printf("%lld\n", ret); } void solve() { solve2(); } inline bool exists_test0 (const std::string& name); inline bool exists_test1 (const std::string& name); int main() { #ifdef LOCAL string file_name = "input.txt"; assert(exists_test0(file_name)); assert(exists_test1(file_name)); freopen("input.txt","r",stdin); #endif solve(); return 0; } /* 0. Enough array size? Enough array size? Integer overflow? 1. Think TWICE, Code ONCE! Are there any counterexamples to your algo? 2. Be careful about the BOUNDARIES! N=1? P=1? Something about 0? 3. Do not make STUPID MISTAKES! Time complexity? Memory usage? Precision error? 4. Be careful to use wrong variable. */ inline bool exists_test0 (const std::string& name) { ifstream f(name.c_str()); return f.good(); } inline bool exists_test1 (const std::string& name) { if (FILE *file = fopen(name.c_str(), "r")) { fclose(file); return true; } else { return false; } }
#include <bits/stdc++.h> using namespace std; #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define watch(x) cout << (#x) << " is " << (x) << endl #define f(t) for(ll i=0;i<t;i++) #define ll long long int #define ld long double #define umpl unordered_map<ll,ll> #define vl vector<ll> #define vld vector<ld> #define vvl vector<vl> #define pb push_back #define pll pair<ll,ll> #define inf 1e18 #define pcout(x,p) cout<<fixed<<setprecision(p)<<x #define all(a) a.begin(),a.end() #define endl "\n" const ll mod = 1e9 + 7; inline ll mul(ll a, ll b) { ll c = (a * 1ll * b) % mod; if (c < 0) c += mod; return c; } inline ll sub(ll a, ll b) { ll c = a - b; if (c < 0) c += mod; return c; } inline ll add(ll a, ll b) { ll c = a + b; if (c >= mod) c -= mod; return c; } inline ll max(ll a, ll b) {return a > b ? a : b;} inline ll min(ll a, ll b) {return a < b ? a : b;} inline ll ceil(ll a, ll b) {return (a % b == 0) ? (a / b) : (a / b + 1);} int main() { #ifndef ONLINE_JUDGE freopen("input1.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fio; ll a, b, c; cin >> a >> b >> c; if (c == 0) { if (a > b) { cout << "Takahashi" << endl; } else { cout << "Aoki" << endl; } } else { if (a < b) { cout << "Aoki" << endl; } else { cout << "Takahashi" << endl; } } }
#include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<string> #include<vector> #define Debug(in) cout<<#in<<"="<<(in)<<endl #define mm(a,x) memset(a,x,sizeof(a)) #define mkp(a,b) make_pair(a,b) #define all(x) x.begin(),x.end() #define sz(x) (int)x.size() #define sync std::ios::sync_with_stdio(false);std::cin.tie(0) #define endl '\n' using namespace std; typedef long long ll; typedef pair<int,int> pii; const int inf=0x3f3f3f3f; int main(void) { sync; int a,b,c; cin>>a>>b>>c; if(a<=b-c) cout<<"Aoki"<<endl; else cout<<"Takahashi"<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const double pi = acos(-1); const double eps = 1e-8; const ll mod = 1e9 + 7; const ull base = 131; const ull mod1 = 1e9 + 9; const ull mod2 = 1610612741; const int maxn = 1e3 + 10; int a[100][100]; int n, t; const ll m = 998244353; int fa[100]; int find(int x) { while (x != fa[x]) x = fa[x] = fa[fa[x]]; return x; } int main() { scanf("%d%d", &n, &t); for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) scanf("%d", &a[i][j]); for (int i = 1; i <= n; ++i) fa[i] = i; for (int i = 1; i <= n; ++i) for (int j = i+1; j <= n; ++j) { bool flag = true; for (int k = 1; k <= n; ++k) if (a[i][k] + a[j][k] > t) flag = false; if (flag) fa[find(i)] = find(j); } ll ans = 1; map<int, int> mp; for (int i = 1; i <= n; ++i) ++mp[find(i)]; for (auto p = mp.begin(); p != mp.end(); ++p) for (int i = 1; i <= p->second; ++i) ans = ans*i%m; for (int i = 1; i <= n; ++i) fa[i] = i; for (int i = 1; i <= n; ++i) for (int j = i+1; j <= n; ++j) { bool flag = true; for (int k = 1; k <= n; ++k) if (a[k][i] + a[k][j] > t) flag = false; if (flag) fa[find(i)] = find(j); } mp.clear(); for (int i = 1; i <= n; ++i) ++mp[find(i)]; for (auto p = mp.begin(); p != mp.end(); ++p) for (int i = 1; i <= p->second; ++i) ans = ans*i%m; printf("%lld\n", ans); 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 = 998244353; const ll len = 15; // nCr (mod p) 計算量 O(3*10^5*logp) const ll Maximum = 5500; ll Fac[Maximum+1], iFac[Maximum+1]; bool made_Fac = false; // x^n (mod p) 計算量 O(logn) ll powmodp(ll x, ll n) { if (n==0) return 1; else if (n%2==0) { ll ans = powmodp(x,n/2); return ans*ans % mod; } else return x * powmodp(x,n-1) % mod; } // nCr (mod p) 計算量 O(3*10^5*logp) void make_Fac() { Fac[0] = 1; iFac[0] = 1; for (ll i=0; i<Maximum; i++) { Fac[i+1] = Fac[i] * (i+1) % mod; iFac[i+1] = iFac[i] * powmodp(i+1,mod-2) % mod; } } ll nCrmodp(ll n, ll r) { if (!made_Fac) { make_Fac(); made_Fac = true; } r = min(r,n-r); if (n==0 or r==0) return 1; ll tmp = iFac[n-r] * iFac[r] % mod; return tmp * Fac[n] % mod; } vector<ll> to_bin(ll X) { vector<ll> res(len); rep(i,len) { res[i] = X % 2; X /= 2; } return res; } int main() { ll N, M; cin >> N >> M; if (M%2) Cout(0); vector<ll> S = to_bin(M); vector<vector<ll>> dp(len,vector<ll>(N+1)); for (ll cnt=0; cnt<=N; cnt+=2) dp[0][cnt/2] = nCrmodp(N,cnt); for (ll i=1; i<len; i++) { for (ll cnt=0; cnt<=N; cnt+=2) { rep(j,N) { if (j%2!=S[i]) continue; ll tmp = cnt + j; dp[i][tmp/2] += dp[i-1][j] * nCrmodp(N,cnt) % mod; dp[i][tmp/2] %= mod; } } } ll ans = dp[len-1][0]; cout << ans << endl; }
#include <iostream> #include <algorithm> #include <unordered_set> #include <set> #include <vector> #include <queue> #include <map> #include <numeric> #include <math.h> #include <complex> using namespace std; #define rep(i, n) for (long long int i = 0; i < (long long int)(n); i++) #define irep(i, n) for (long long int i = 1; i <= (long long int)(n); i++) #define drep(i, n, diff) for (long long int i = 0; i < (long long int)(n); i += diff) #define mod 1000000007 #define INF 1001001001001001011 #define ld(val) printf("%s : %lld\n", #val, val); #define sd(val) printf("%s : %s\n", #val, val.c_str()); typedef long long int ll; typedef pair<ll, ll> P; typedef pair<P, P> PP; typedef tuple<ll, ll, ll> TP; int main() { string s; cin >> s; reverse(s.begin(), s.end()); rep(i, s.size()) { if(s[i] == '6') { cout << '9'; } else if(s[i] == '9') { cout << '6'; } else { cout << s[i]; } } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x){ x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();} while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();} x *= f; } inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); } #define LL long long const LL inf = 1000000000000000000ll; LL fib[150],m,n,nn; int main(){ int i; cin >> n;nn=n; fib[0] = 1,fib[1] = 1; m = 1; while (fib[m] + fib[m-1] <= n){ fib[m+1] = fib[m] + fib[m-1]; ++m; } // cerr<<m<<'\n'; int ops = 0; for (i = 0; i <= m; ++i){ if (i){ ++ops; } if (fib[m - i] <= n){ n -= fib[m - i]; ++ops; } } n=nn; cout << ops << '\n'; LL x = 0,y = 0; for (i = 0; i <= m; ++i){ if (i){ if ((m-i-1) & 1) cout << 3 << '\n',x+=y; else cout << 4 << '\n',y+=x; } if (fib[m - i] <= n){ n -= fib[m - i]; if ((m-i) & 1) cout << 2 << '\n',++y; else cout << 1 << '\n',++x; } } // cerr << "final " << x << ' ' << y << '\n'; assert(x == nn); return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> using namespace std; #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr); #else #define eprintf(...) 42 #endif using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; template<typename T> using pair2 = pair<T, T>; using pii = pair<int, int>; using pli = pair<ll, int>; using pll = pair<ll, ll>; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second clock_t startTime; double getCurrentTime() { return (double)(clock() - startTime) / CLOCKS_PER_SEC; } const ll MOD = 998244353; ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; } ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; } ll mult(ll x, ll y) { return (x * y) % MOD; } ll bin_pow(ll x, ll p) { if (p == 0) return 1; if (p & 1) return mult(x, bin_pow(x, p - 1)); return bin_pow(mult(x, x), p / 2); } ll rev(ll x) { return bin_pow(x, MOD - 2); } const int N = 5050; int n, m; int pw[N][N]; int main() { startTime = clock(); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); for (int x = 0; x < N; x++) { pw[x][0] = 1; for (int i = 1; i < N; i++) pw[x][i] = mult(pw[x][i - 1], x); } scanf("%d%d", &n, &m); int ans = 0; for (int i = 0; i < n; i++) for (int x = 1; x <= m; x++) { ans = add(ans, mult(pw[m - x][i], pw[m][n - 1 - i])); } for (int d = 1; d < n; d++) for (int x = 1; x <= m; x++) { ans = add(ans, mult(mult(n - d, x - 1), mult(pw[m - x][d - 1], pw[m][n - 1 - d]))); } printf("%d\n", 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; using LL = long long; using LD = long double; using ordered_set = tree<LL,null_type,less<LL>,rb_tree_tag,tree_order_statistics_node_update>; void fastio() { cin.tie(nullptr); cin.sync_with_stdio(false); } const LL MOD = 998244353; const LL INF = 1e18; const LL N = 2e5+10; #define S second #define F first #define vt vector vt<LL> fac(N), ifac(N); LL bpow(LL x, LL p, LL m) { x %= m; LL r = 1; while (p) { if (p&1) { r = r*x%m; } p>>=1; x = x*x %m; } return r; } LL binom (LL n, LL r, LL m) { if (r > n) { return 0; } LL res = fac[n]*ifac[r]%m * ifac[n-r]%m; return res; } int main() { fastio(); fac[0] = 1; for (LL i = 1; i < N; ++i) { fac[i] = i*fac[i-1]%MOD; } ifac[N-1] = bpow(fac[N-1], MOD-2, MOD); for (LL i = N-2; i >= 0; --i) { ifac[i] = ifac[i+1]*(i+1)%MOD; } LL n, m, k; cin >> n >> m >> k; if (n == 1 || m == 1) { LL mx = max(n, m); LL ans = 0; for (LL i = 1; i <= k; ++i) { LL l = 1; LL r = bpow(k-i+1, mx, MOD) - bpow (k-i, mx, MOD); //cerr << l << " " << r << "\n"; ans = (ans + l*r% MOD + MOD) % MOD; } cout << ans << "\n"; return 0; } LL ans = 0; for (LL i = 1; i <= k; ++i) { LL l = bpow(i, n, MOD) - bpow (i-1, n, MOD); LL r = bpow(k-i+1, m, MOD); //cerr << l << " " << r << "\n"; ans = (ans + l*r% MOD + MOD) % MOD; } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define scan(a,n) for(long long int index=0;index<n;index++) cin>>a[index]; #define print(a,n) for(long long int index=0;index<n;index++) cout<<a[index]<<" ";cout<<endl; #define mod 1000000007 #define pb push_back #define mp make_pair #define ss second #define ff first #define vli vector<long long int> #define vlli vector<pair<long long int,long long int>> #define vsi vector<string> #define all(n) n.begin(),n.end() #define forn(i,a,b) for(i=a;i<b;i++) ll mul(ll x,ll y){ return (x*y)%mod;} 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 fact(ll n) {ll res = 1; for (ll i = 2; i <= n; i++) res = mul(res , i); return res; } ll nCr(ll n, ll r) { return mul(fact(n),mod_inv(mul(fact(r),fact(n - r))));} int main() { fast; #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ll t=1; // cin>>t; while(t--){ ll n,m,x,y; cin>>n>>m>>x>>y; x--;y--; string s[n]; scan(s,n); ll ans=1,i; // cout<<x<<" "<<y<<endl; i=x+1; while(i<n){ if(s[i][y]=='.') ans++; else break; i++; } i=x-1; while(i>=0){ if(s[i][y]=='.') ans++; else break; i--; } i=y-1; while(i>=0){ if(s[x][i]=='.') ans++; else break; i--; } i=y+1; while(i<m){ if(s[x][i]=='.') ans++; else break; i++; } cout<<ans<<endl; } return 0; }
/*{{{*/ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<iostream> #include<sstream> #include<set> #include<map> #include<queue> #include<bitset> #include<vector> #include<limits.h> #include<assert.h> #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define FOR(I, A, B) for (int I = (A); I <= (B); ++I) #define FORS(I, S) for (int I = 0; S[I]; ++I) #define RS(X) scanf("%s", (X)) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++) #define MP make_pair #define PB emplace_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PII> VPII; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template<class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const int64_t &x) { printf("%lld", x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);} template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } #ifdef HOME #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);} #else #define DEBUG(...) #endif int MOD = 1e9+7; void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;} /*}}}*/ const int SIZE = 1<<20; LL N,K; void solve() { while(K--){ if(N%200==0)N/=200; else N=N*1000+200; } W(N); } void input() { R(N,K); } int main(){ input(); solve(); return 0; }
#pragma region Macros #include <bits/stdc++.h> #if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG) #include <atcoder/all> #endif using namespace std; #define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define REPR(i, n) for(int i=(n); i>=0; --i) #define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i) #define EACH(i, v) for(const auto& i : v) #define ALL(x) (x).begin(),(x).end() #define ALLR(x) (x).rbegin(),(x).rend() 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<class T>using vec = vector<T>; template<class T, class U>using umap = unordered_map<T, U>; using ll = long long; using P = pair<ll, ll>; using vl = vec<ll>; #define fi first #define se second #define el endl constexpr ll INF = numeric_limits<ll>::max()/2-1; #pragma endregion #pragma region IOMacros template<class T> istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;} template<class T> ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;} #define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__); void __i() {} template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);} void O() {cout << el;} template<class T, class... Ts> void O(T&& o, Ts&&... args){cerr << o << " ";O(forward<Ts>(args)...);} #pragma endregion void Main(); int main(){ std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(15); Main(); return 0; } void Main(){ I(ll, M, H); if(H%M){ cout << "No" << el; }else{ cout << "Yes" << el; } }
#include <bits/stdc++.h> using namespace std; map<int,int>vis; bool judge(int n) { if(n&1) return false; for(auto it=vis.begin();it!=vis.end();it++) { if(it->second&1) return true; } return false; } int main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); int T;cin>>T; while(T--) { int n;cin>>n; vis.clear(); for(int val,i=1;i<=n;i++) cin>>val,vis[val]++; if(judge(n)) cout<<"First\n"; else cout<<"Second\n"; } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define REP(i,n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define debug(var) do{cout << #var << " : "; view(var);}while(0) template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;} template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;} using namespace std; template<class T> void view(T e) {cout << e << endl;} template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;} template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}} using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int,int>; const int inf = 1<<30; const ll inf_l = 1LL<<61; const int MAX = 1e5; int main() { ll n; cin >> n; ll ans = 0; ll v = 1000; rep(i,5) { ans += max<ll>(n - (v - 1), 0); v *= 1000; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < 2 * n; i++) { cout << i % n + 1; if (i % 2 == 0) cout << " "; else cout << '\n'; } }
#include <iostream> #include <vector> #include<iomanip> #include<functional> #include<algorithm> #include<deque> #include<set> #include<queue> #include<map> using namespace std; #define rep(i,n) for(int i = 0;i<n;i++) #define req(i,n) for(int i = 1;i<=n;i++) #define rrep(i,n) for(int i = n-1;i>=0;i--) #define ALL(a) a.begin(),a.end() typedef long long ll; typedef double d; typedef pair<int, int> P; const int inf = 1 << 30; struct liner { d a, b; liner(d a = 0, d b = 0): a(a), b(b) {} liner operator+(const liner& x)const { return liner(a + x.a, b + x.b); }liner operator-(const liner& x)const { return liner(a - x.a, b - x.b); }liner operator/(int x)const { return liner(a / x, b / x); } }; int main() { int n, m, k,p,sum=0; cin >> n >> m >> k; vector<bool> f(n + 1, 0); rep(i, k) { cin >> p; f[p] = 1; }rep(i, n + 1) { if (f[i])sum++; else sum = 0; if (sum >= m) { cout << -1 << endl; return 0; } }vector<liner> dp(n + 1); liner S; rrep(i, n) { if (f[i]) dp[i] = liner(1, 0); else dp[i] = S / m + liner(0, 1); S = S+dp[i]; if (i + m <= n) S = S - dp[i + m]; }cout <<fixed<<setprecision(10) << dp[0].b / (1 - dp[0].a) << endl; }
#include<bits/stdc++.h> using namespace std; const int N = 100005; double ans; int n,all,dkfjklasdhfklasdfklasdhfklasdh[15],dksfhjkasdfhasdhflasdhfkl[2][15],dsakfasdjkfhjklasdhf[15]={1}; char s[2][N]; bool Check(int x,int y){ ++dksfhjkasdfhasdhflasdhfkl[0][x],++dksfhjkasdfhasdhflasdhfkl[1][y]; int X=0,Y=0; for(int i=1;i<10;++i)X+=i*dsakfasdjkfhjklasdhf[dksfhjkasdfhasdhflasdhfkl[0][i]],Y+=i*dsakfasdjkfhjklasdhf[dksfhjkasdfhasdhflasdhfkl[1][i]]; --dksfhjkasdfhasdhflasdhfkl[0][x],--dksfhjkasdfhasdhflasdhfkl[1][y];return X>Y; } int main(){ cin>>n>>s[0]+1>>s[1]+1,all=n*9; for(int _=0;_<2;++_)for(int i=1;i<5;++i)++dkfjklasdhfklasdfklasdhfklasdh[s[_][i]&15],++dksfhjkasdfhasdhflasdhfkl[_][s[_][i]&15],--all; for(int i=1;i<9;++i)dsakfasdjkfhjklasdhf[i]=dsakfasdjkfhjklasdhf[i-1]*10; for(int i=1;i<10;++i){ for(int j=1;j<10;++j){ if(dkfjklasdhfklasdfklasdhfklasdh[i]>=n||dkfjklasdhfklasdfklasdhfklasdh[j]>=n||(i==j&&dkfjklasdhfklasdfklasdhfklasdh[i]>=n-1))continue; if(Check(i,j)){ if(i==j){ ans+=(double)1.0*(1.0*(n-dkfjklasdhfklasdfklasdhfklasdh[i])/all)*(1.0*(n-dkfjklasdhfklasdfklasdhfklasdh[j]-1)/(all-1)); } else{ ans+=(double)1.0*(1.0*(n-dkfjklasdhfklasdfklasdhfklasdh[i])/all)*(1.0*(n-dkfjklasdhfklasdfklasdhfklasdh[j])/(all-1)); } } } } printf("%.6lf",ans); }
#include<bits/stdc++.h> using namespace std; int va[] = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47 }; int n; long long x[55], ans = -1; bool check(long long y) { for (int i = 0; i < n; i ++) if (__gcd(x[i], y) == 1) return false; return true; } void dfs(int d, long long val) { // printf("dfs( %2d, %lld )\n", d, val); if (d == 15) { if (check(val)) { if (ans == -1 || ans > val) ans = val; } return; } dfs(d+1, val); dfs(d+1, val*va[d]); } int main() { cin >> n; for (int i = 0; i < n; i ++) cin >> x[i]; dfs(0, 1); cout << ans << endl; return 0; }
#include <iostream> #include <vector> #include <map> using namespace std; typedef long long ll; const ll INF = 1e18; int gcd(ll n, ll m) { if (m == 0) return n; else return gcd(m, n % m); } int main() { int n; cin >> n; vector<ll> x(n); for (int i = 0; i < n; ++i) cin >> x[i]; ll ans = INF; vector<int> vec(51, 1); vector<int> prime; vec[0] = 0; vec[1] = 0; for (int i = 2; i < 51; ++i) { for (int j = i * 2; j < 51; j += i) { vec[j] = 0; } } for (int i = 0; i < 51; ++i) { if (vec[i] == 1) prime.push_back(i); } for (int bits = 0; bits < (1 << prime.size()); ++bits) { ll temp = 1; for (int i = 0; i < prime.size(); ++i) { if (bits & (1 << i)) { temp *= prime[i]; } } bool flg = false; for (int i = 0; i < n; ++i) { if (gcd(temp, x[i]) == 1) { flg = true; break; } } if (!flg) ans = min(ans, temp); } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define reg register typedef long long ll; #define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++) static char buf[100000],*p1=buf,*p2=buf; inline int read(void){ reg bool f=false; reg char ch=getchar(); reg int res=0; while(!isdigit(ch))f|=(ch=='-'),ch=getchar(); while(isdigit(ch))res=10*res+(ch^'0'),ch=getchar(); return f?-res:res; } inline ll readll(void){ reg bool f=false; reg char ch=getchar(); reg ll res=0; while(!isdigit(ch))f|=(ch=='-'),ch=getchar(); while(isdigit(ch))res=10ll*res+(ch^'0'),ch=getchar(); return f?-res:res; } const int MAXN=50+5; int n; ll x; ll a[MAXN]; map<ll,ll> f,g; int main(void){ n=read(),x=readll(); for(reg int i=1;i<=n;++i) a[n-i+1]=readll(); ll x0=x/a[1]*a[1]; f[x0]=1; if(x0!=x) f[x0+a[1]]=1; for(reg int i=2;i<=n;++i){ g.clear(); reg ll Max=a[i-1]/a[i]; for(auto it:f){ reg ll d=x-it.first,m=d/a[i]; ll y=it.first+m*a[i]; if(abs(m)<Max) g[y]+=it.second; if(y!=x&&abs(m)+1<Max) g[y+a[i]*(d/abs(d))]+=it.second; } swap(f,g); } printf("%lld\n",f[x]); return 0; }
/*{{{*/ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<iostream> #include<sstream> #include<set> #include<map> #include<queue> #include<bitset> #include<vector> #include<limits.h> #include<assert.h> #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define FOR(I, A, B) for (int I = (A); I <= (B); ++I) #define FORS(I, S) for (int I = 0; S[I]; ++I) #define RS(X) scanf("%s", (X)) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++) #define MP make_pair #define PB emplace_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PII> VPII; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template<class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const int64_t &x) { printf("%lld", x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);} template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } #ifdef HOME #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);} #else #define DEBUG(...) #endif int MOD = 1e9+7; void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;} /*}}}*/ const int SIZE = 1<<20; LL N, X; LL A[SIZE]; LL m[SIZE],v[SIZE]; LL dp[SIZE]; void solve() { for(int i=N;i>0;i--){ v[i]=X/A[i]; X%=A[i]; } dp[0]=1; FOR(i,1,N){ if(v[i]==m[i]-1){ for(int j=i-1;j>=0;j--){ dp[i]+=dp[j]; if(v[j])break; } continue; } bool is_zero=1; for(int j=i;j>0;j--){ if(v[j])is_zero=0; if(!is_zero){ dp[i]+=dp[j-1]; } } } LL an=0; for(int i=N;i>0;i--){ an+=dp[i]; if(v[i])break; } W(an); } void input() { R(N,X); FOR(i,1,N){ R(A[i]); if(i>1)m[i-1]=A[i]/A[i-1]; } m[N]=1e16; } int main(){ input(); solve(); return 0; }
#include <bits/stdc++.h> using namespace std ; typedef long long ll ; #define M 100005 #define YES cout << "Yes" << endl #define NO cout << "No" << endl #define rep(i,n) for(int i = 0 ; i < n ; i++) #define syosu setprecision(10) #define MAX_N (ll)2e5 int N ; ll W ; int main(){ cin >> N >> W ; ll pod[MAX_N + 2] ; memset(pod,0,sizeof(pod)) ; rep(i,N){ int s , t ; ll p ; cin >> s >> t >> p ; pod[s] += p ; pod[t] -= p ; } ll sum = 0 ; bool ok = true ; for(int i = 0 ; i < MAX_N + 2 ; i++){ sum += pod[i] ; if(sum > W) ok = false ; } if(ok) YES ; else NO ; }
//QwQcOrZ yyds!!! #ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdalign> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include <unordered_map> #include <unordered_set> #endif #define ll long long #define F(i,a,b) for (int i=(a);i<=(b);i++) #define R(i,a,b) for (int i=(a);i<(b);i++) #define D(i,a,b) for (int i=(a);i>=(b);i--) #define go(i,x) for (int i=head[x];i;i=e[i].nx) #define mp make_pair #define pb push_back #define pa pair < int,int > #define fi first #define se second #define re register #define be begin() #define en end() #define sqr(x) ((x)*(x)) #define ret return puts("-1"),0; #define put putchar('\n') #define inf 1000000005 #define mod 998244353 #define int ll #define N 100005 using namespace std; inline char gc(){static char buf[100000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;} #define gc getchar inline ll read(){char c=gc();ll su=0,f=1;for (;c<'0'||c>'9';c=gc()) if (c=='-') f=-1;for (;c>='0'&&c<='9';c=gc()) su=su*10+c-'0';return su*f;} inline void write(ll x){if (x<0){putchar('-');write(-x);return;}if (x>=10) write(x/10);putchar(x%10+'0');} inline void writesp(ll x){write(x),putchar(' ');} inline void writeln(ll x){write(x);putchar('\n');} int n,a[N],b[N],c[N],B[N],ans; signed main() { n=read(); for (int i=1;i<=n;i++) a[i]=read(); for (int i=1;i<=n;i++) b[i]=read(); for (int i=1;i<=n;i++) c[i]=read(); for (int i=1;i<=n;i++) { B[b[c[i]]]++; } for (int i=1;i<=n;i++) { ans+=B[a[i]]; } writeln(ans); } /* */
#line 1 "main.cpp" #include <bits/stdc++.h> using namespace std; // template {{{ using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1) #define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1) #define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x) #define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x) #define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl constexpr i32 inf = 1001001001; constexpr i64 infll = 1001001001001001001ll; constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1}; struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup; template <typename T = i64> T input() { T x; cin >> x; return x; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } // }}} void solve() { int n = input(), k = input(); string s; cin >> s; auto result = [](string s) { int n = s.size() / 2; string t; range(i, 0, n) { string ss = s.substr(2 * i, 2); if (ss[0] == ss[1]) { t += ss[0]; continue; } if (ss.find('R') == string::npos) { t += 'S'; } if (ss.find('S') == string::npos) { t += 'P'; } if (ss.find('P') == string::npos) { t += 'R'; } } return t; }; range(i, 0, k) { s = result(s + s); } cout << s[0] << endl; } signed main() { solve(); }
//#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 N, K; string S; int f(int a, int b) { if (b - a == 1 || b - a == -2) return b; else return a; } map<int, char> M; void solve() { M[0] = 'R'; M[1] = 'P'; M[2] = 'S'; N *= 2; S += S; vi bef; for (auto& c : S) { if (c == 'R') bef.emplace_back(0); else if (c == 'P') bef.emplace_back(1); else bef.emplace_back(2); } int n = N / 2; while (K--) { vi now(N); for (int i = 0; i < n; i++) { int x = f(bef[i * 2], bef[i * 2 + 1]); now[i] = x; now[i + n] = x; } swap(now, bef); } cout << M[bef[0]] << endl; } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> N >> K >> S; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define pb push_back #define ff first #define ss second #define all(a) a.begin(), a.end() #define sz(a) (int)(a.size()) #define clr(a, b) memset(a, b, sizeof(a)) #define REP(i, a, b) for(int i=(int)(a); i<(int)(b); ++i) #define REPD(i, a, b) for(int i=(int)(a)-1; i>=(int)(b); --i) template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll MX = 1e18; ll N; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> N; ll i3 = 3; REP(i, 1, 50) { ll j5 = 5; REP(j, 1, 50) { if(i3 > MX) break; if(j5 > MX) break; if(i3 + j5 == N) { cout << i << " " << j << "\n"; return 0; } j5 *= 5; } i3 *= 3; } cout << -1 <<"\n"; return 0; }
#include <bits/stdc++.h> #define ld long double #define endl "\n" #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define mp(a,b) make_pair(a,b) #define ms(v,x) memset(v,x,sizeof(v)) #define all(v) v.begin(),v.end() #define ff first #define ss second #define rep(i, a, b) for(int i = a; i < (b); ++i) #define per(i, a, b) for(int i = b-1; i>=a ; i--) #define trav(a, x) for(auto& a : x) #define allin(a , x) for(auto a : x) #define Unique(v) sort(all(v));v.erase(unique(all(v)),v.end()); #define sz(v) ((int)v.size()) //#define int long long using namespace std; typedef vector<int> vi; #define y1 abacaba //#define left oooooopss #define db(x) cerr << #x <<" == "<<x << endl; #define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl; #define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count()); inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; } //ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));} int gcd(int a,int b){ return (b==0 ? a : gcd(b,a%b)); } ll exp(ll b,ll e,ll m){ b%=m; ll ans = 1; for (; e; b = b * b % m, e /= 2) if (e & 1) ans = ans * b % m; return ans; } const int N = 2020; int A[N]; map<int,vi> here; int32_t main(){ fastio; int n; cin >> n; int mn = 2e9 + 7; for(int i=1;i<=n;i++){ cin >> A[i]; mn=min(mn,A[i]); } for(int i=1;i<=n;i++){ for(int x=1;x*x<=A[i];x++){ if(A[i]%x==0){ if(x<=mn)here[x].pb(A[i]); if((A[i]/x)!=x and (A[i]/x)<=mn)here[A[i]/x].pb(A[i]); } } } int res=0; for(auto it : here){ int g = it.ss[0]; for(auto x : it.ss)g = gcd(g,x); if(g!=it.ff)continue; // cout << it.ff << endl; res++; } cout << res << endl; // math -> gcd it all // Did u check N=1? Did you switch N,M? }
#include <cstdio> #include <iostream> #include <cstring> using namespace std; inline int readint(){ int a = 0; char c = getchar(), f = 1; for(; c<'0'||c>'9'; c=getchar()) if(c == '-') f = -f; for(; '0'<=c&&c<='9'; c=getchar()) a = (a<<3)+(a<<1)+(c^48); return a*f; } int main(){ int a = readint(), b = readint(); int w = readint()*1000; int k = (w-1)/b+1; // b*k >= w if(a*k > w){ puts("UNSATISFIABLE"); return 0; } printf("%d ",k); k = w/a; // a*k <= w printf("%d\n",k); return 0; }
#include <iostream> main() { int64_t n; std::cin >> n; for(int64_t i = 1; ; i++) { if(std::stoll(std::to_string(i) + std::to_string(i)) > n) { std::cout << i - 1; break; } } }
#include <bits/stdc++.h> using namespace std; int64_t mod = 1000000007; int main(){ int H, W; cin >> H >> W; vector<string> v(H); for(int i = 0;i < H;i++) cin >> v.at(i); vector<int64_t> H_sum(H, 0); vector<int64_t> W_sum(W, 0); vector<int64_t> D_sum(H + W, 0); int64_t dp[H][W]; for(int i = 0;i < H;i++){ for(int j = 0;j < W;j++){ if(i == 0 && j == 0){ dp[0][0] = 1; H_sum.at(0) = 1; W_sum.at(0) = 1; D_sum.at(W - 1) = 1; } else{ if(v.at(i).at(j) == '.'){ dp[i][j] = (H_sum.at(i) + W_sum.at(j) + D_sum.at(i - j + W - 1)) % mod; H_sum.at(i) += dp[i][j]; W_sum.at(j) += dp[i][j]; D_sum.at(i - j + W - 1) += dp[i][j]; } else{ H_sum.at(i) = 0; W_sum.at(j) = 0; D_sum.at(i - j + W - 1) = 0; } } } } cout << (dp[H - 1][W - 1]) % mod << endl; }
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define sz(x) (int) x.size() #define pb push_back #define endl '\n' #define snd second #define fst first #define fastio cin.tie(NULL),cout.sync_with_stdio(true) //typedef long long int ll; typedef unsigned long long int ull; typedef vector <int> vi; typedef pair <int, int> ii; const int mod = 1e9 + 7; //const ll INF = 1e18; const double EPSILON = 1e-10; const int N = 2005; char t[N][N]; int l[N][N], c[N][N], d[2][N][N]; vi ll[N], cc[N], dd[2][N]; int add(int a, int b){ a += b; if(a >= mod) a -= mod; return a; } int sub(int a, int b){ a -= b; if(a < 0) a += mod; return a; } int main(){ fastio; int n,m; cin >> n >> m; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin >> t[i][j]; for(int i = 0; i < N; i++) ll[i].pb(0), cc[i].pb(0), dd[0][i].pb(0), dd[1][i].pb(0); if(n == 1 and m == 1){ cout << 1 << '\n'; return 0; } l[1][1] = c[1][1] = d[0][0][1] = 1; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ if(i == 1 and j == 1)continue; if(t[i][j] == '#'){ ll[i].pb(i); cc[j].pb(j); if(i-j >= 0){ dd[0][i-j].pb(i); }else{ dd[1][j-i].pb(i); } }else{ int tmp = 0; tmp = add(tmp, sub(l[i-1][j], (ll[i][sz(ll[i])-1] > 0 ? l[ ll[i][sz(ll[i])-1] ][j] : 0))); tmp = add(tmp, sub(c[i][j-1], (cc[j][sz(cc[j])-1] > 0 ? c[i][ cc[j][sz(cc[j])-1] ] : 0))); if(i-j>=0){ tmp = add(tmp, sub(d[0][i-j][i-1], (dd[0][i-j][sz(dd[0][i-j])-1] > 0 ? d[0][i-j][ dd[0][i-j][sz(dd[0][i-j])-1] ] : 0))); }else{ tmp = add(tmp, sub(d[1][j-i][i-1], (dd[1][j-i][sz(dd[1][j-i])-1] > 0 ? d[1][j-i][ dd[1][j-i][sz(dd[1][j-i])-1] ] : 0))); } if(i == n and j == m){ cout << tmp << '\n'; } l[i][j] = add(l[i-1][j], tmp); c[i][j] = add(c[i][j-1], tmp); if(i-j >= 0){ d[0][i-j][i] = add(d[0][i-j][i-1], tmp); }else{ d[1][j-i][i] = add(d[1][j-i][i-1], tmp); } } } } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define loop(i, start, end) for (int i = start; i <= end; i++) #define rloop(i, start, end) for (int i = start; i >= end; i--) #define vi vector<int> #define vec(x) vector<x> #define sz(v) (int)v.size() #define UB upper_bound #define LB lower_bound #define all(v) (v).begin(),(v).end() #define arl(v) (v).rbegin(),(v).rend() #define fsp(a) fixed<<setprecision(a) #define mem(a,with) memset(a, with, sizeof (a)) #define vmn(a) (*min_element(a.begin(),a.end())) #define vmx(a) (*max_element(a.begin(),a.end())) #define bs(a,key) binary_search(all(a),key) /// return bool. #define rotl(a,x) rotate(a.begin(),a.begin()+x,a.end()); #define rotr(a,x) rotl(a,a.size()-x); #define nl cout<<endl #define dbg(x) cerr << #x << " :: " << x << endl; #define dbg2(x, y) cerr << #x << " :: " << x << "\t" << #y << " :: " << y << endl; #define MOD 1000000007 int add(int x, int y) {int res = x + y; return (res >= MOD ? res - MOD : res);} int mul(int x, int y) {int res = x * y; return (res >= MOD ? res % MOD : res);} int power(int x, int y) {int res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;} void solve(){ //code goes here int n,k; cin>>n>>k; vec(vi) cost(n+1,vi(n+1,0)); loop(i,1,n){ loop(j,1,n) cin>>cost[i][j]; } vi arr; int ans=0; loop(i,2,n) arr.push_back(i); do{ int i=0,sum=0; int l=1,r=arr[i]; while(i<arr.size()){ sum+=cost[l][r]; // cout<<cost[l][r]<<endl; i++; l=r;r=arr[i]; // cout<<i<<" "<<l<<" "<<r<<endl; } r=arr[arr.size()-1]; sum+=cost[r][1]; // cout<<sum<<endl; if(sum==k) ans++; }while(next_permutation(all(arr))); cout<<ans; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL); int t=1; // cin>>t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = 1e9; const long long INFLL = 1e18; using ll = long long; int main(){ int n, k; 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> order; for(int i = 1; i < n; i++){ order.push_back(i); } int ans = 0; do{ int sum = 0; sum += t[0][order[0]]; for(int i = 0; i < order.size(); i++){ // cout << order[i]; if(i == order.size()-1) sum += t[order[i]][0]; else sum += t[order[i]][order[i+1]]; } // cout << endl; if(sum == k) ans ++; }while(next_permutation(order.begin(), order.end())); cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; const int N=2007; int a[N],b[N]; int main() { int A,B,C; scanf("%d%d",&A,&B); C=max(A,B); for(int i=1;i<=C;i++)a[i]=i,b[i]=-i; for(int i=C;i>=A+1;i--)a[i-1]+=a[i]; for(int i=C;i>=B+1;i--)b[i-1]+=b[i]; for(int i=1;i<=A;i++)printf("%d ",a[i]); for(int i=1;i<=B;i++)printf("%d ",b[i]); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ll> vl; typedef vector<pair<int,int>> vpi; #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define pb push_back #define mp make_pair #define rev(i,a,b) for(int i=a;i<b;i++) #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() //const ll MOD =998244353; ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);} ll lcm(ll a, ll b){return a / gcd(a, b) * b;} int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int a,b; cin>>a>>b; if(a==b) { for(int i=1;i<=a;i++) cout<<i<<" "; for(int i=1;i<=b;i++) cout<<-i<<" "; } else { if(a>b) { ll s=a*(a+1)/2; ll s1=(b-1)*b/2; for(int i=1;i<=a;i++) cout<<i<<" "; for(int i=1;i<b;i++) cout<<-i<<" "; cout<<s1-s<<" "; } else { for(int i=1;i<=b;i++) cout<<-i<<" "; for(int i=1;i<a;i++) cout<<i<<" "; cout<<abs((a*(a-1)/2)-(b*(b+1)/2))<<" "; } } }
#include<cstdio> #include<math.h> #include<algorithm> #include<vector> #include<queue> #include<string> #include<set> #include<cstring> #include<map> using namespace std; #define int long long int #define rep(i,n) for(int i=0;i<n;i++) #define INF 1001001001 #define LLINF 1001001001001001001 #define mp make_pair #define pb push_back #define mod 1000000007 //#define mod 998244353 //解説 //abc189_e int N,M,Q; int X[200005],Y[200005]; //行列 int G[200005][3][3]; //累乗積 int GA[200005][3][3]; signed main(){ scanf("%lld",&N); rep(i,N)scanf("%lld %lld",&X[i],&Y[i]); scanf("%lld",&M); rep(i,M){ rep(j,3)rep(k,3)G[i][j][k]=0; int op; scanf("%lld",&op); if(op==1){ G[i][0][1]=1; G[i][1][0]=-1; G[i][2][2]=1; }else if(op==2){ G[i][0][1]=-1; G[i][1][0]=1; G[i][2][2]=1; }else if(op==3){ int p; scanf("%lld",&p); G[i][0][0]=-1; G[i][0][2]=2*p; G[i][1][1]=1; G[i][2][2]=1; }else{ int p; scanf("%lld",&p); G[i][0][0]=1; G[i][1][1]=-1; G[i][1][2]=2*p; G[i][2][2]=1; } } //行列の累乗積を計算 rep(i,M){ rep(j,3){ rep(k,3){ //GA[i][j][k]を求める if(i==0)GA[i][j][k]=G[i][j][k]; else{ int sum=0; rep(m,3)sum+=G[i][j][m]*GA[i-1][m][k]; GA[i][j][k]=sum; } } } } scanf("%lld",&Q); rep(i,Q){ int a,b; scanf("%lld %lld",&a,&b);a--;b--; if(a==-1){//そのまま printf("%lld %lld\n",X[b],Y[b]); continue; } int x=GA[a][0][0]*X[b]+GA[a][0][1]*Y[b]+GA[a][0][2]; int y=GA[a][1][0]*X[b]+GA[a][1][1]*Y[b]+GA[a][1][2]; printf("%lld %lld\n",x,y); } }
/** * Author: Daniel * Created Time: 2021-04-03 10:23:06 **/ #include <bits/stdc++.h> using namespace std; #define F first #define S second #define ER erase #define IS insert #define PI acos(-1) #define PB pop_back #define MP make_pair #define MT make_tuple #define LB lower_bound #define UB upper_bound #define EB emplace_back #define lowbit(x) (x & -x) #define SZ(x) ((int)x.size()) #define ALL(x) x.begin(), x.end() #define RALL(x) x.rbegin(), x.rend() #define SOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<fixed<<setprecision(10) typedef long long LL; typedef vector<LL> VL; typedef vector<int> VI; typedef vector<bool> VB; typedef pair<LL, LL> PLL; typedef vector<string> VS; typedef pair<int, int> PII; typedef unsigned long long ULL; typedef pair<double, double> PDD; typedef vector<pair<LL, LL> > VPLL; typedef vector<pair<int, int> > VPII; template <typename A> using VE = vector<A>; template <typename A> using USET = unordered_set<A>; template <typename A> using HEAP = priority_queue<A>; template <typename A, typename B> using PA = pair<A, B>; template <typename A, typename B> using UMAP = unordered_map<A, B>; template <typename A> using RHEAP = priority_queue<A, vector<A>, greater<A> >; template <typename A> A MAX(const A &a) { return a; } template <typename A> A MIN(const A &a) { return a; } template <typename A> A MAX(const A *a, const A *b) { return *max_element(a, b); } template <typename A> A MIN(const A *a, const A *b) { return *min_element(a, b); } template <typename A, typename... B> A MAX(const A &a, const B&... b) { return max(a, MAX(b...)); } template <typename A, typename... B> A MIN(const A &a, const B&... b) { return min(a, MIN(b...)); } template <typename A, typename B = typename std::iterator_traits<A>::value_type> B MAX(A a, A b) { return *max_element(a, b); } template <typename A, typename B = typename std::iterator_traits<A>::value_type> B MIN(A a, A b) { return *min_element(a, b); } mt19937 rng((unsigned int)chrono::steady_clock::now().time_since_epoch().count()); /////////////////////////////////////////////////////////////////////////// //////////////////// DO NOT TOUCH BEFORE THIS LINE //////////////////////// /////////////////////////////////////////////////////////////////////////// // check the limitation!!! const int N = 100010, M = 1010; // read the question carefully!!! int main() { SOS; int n; cin >> n; VPLL a(n); for (auto &[x, y] : a) cin >> x >> y; int m; cin >> m; bool flag = false; LL sx = 1, sy = 1; LL cx = 0, cy = 0; VE<tuple<bool, LL, LL, LL, LL>> op; op.EB(MT(flag, sx, cx, sy, cy)); for (int i = 0; i < m; i ++ ) { int t; cin >> t; if (t == 1) { flag = !flag; sx = -sx; cx = -cx; swap(sx, sy); swap(cx, cy); } else if (t == 2) { flag = !flag; sy = -sy; cy = -cy; swap(sx, sy); swap(cx, cy); } else if (t == 3) { LL p; cin >> p; sx = -sx; cx = 2 * p - cx; } else if (t == 4) { LL p; cin >> p; sy = -sy; cy = 2 * p - cy; } else assert(false); op.EB(MT(flag, sx, cx, sy, cy)); } int q; cin >> q; for (int i = 0; i < q; i ++ ) { int c, b; cin >> c >> b; b -- ; LL x, y; auto [flag, sx, cx, sy, cy] = op[c]; if (!flag) x = sx * a[b].F + cx, y = sy * a[b].S + cy; else x = sx * a[b].S + cx, y = sy * a[b].F + cy; cout << x << ' ' << y << '\n'; } return 0; } // GOOD LUCK!!!
#ifdef _LOCAL #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> typedef long long ll; typedef long double ld; using namespace std; static const ld PI = 3.141592653589793; pair<ld, ld> solve(int n, ld x, ld y, ld x2, ld y2) { ld xm = (x + x2) / (ld)2, ym = (y + y2) / (ld)2; ld vec_x = x - xm, vec_y = y - ym; ld dec = (ld)360 / (ld)n; ld rad = PI * dec / (ld)180; ld vec_xc = (ld)cos(rad) * vec_x - (ld)sin(rad) * vec_y, vec_yc = (ld)sin(rad) * vec_x + (ld)cos(rad) * vec_y; return make_pair(xm + vec_xc, ym + vec_yc); } #ifndef _LOCAL int main() { int n; ld x, y, x2, y2; cin >> n >> x >> y >> x2 >> y2; pair<ld, ld> res = solve(n, x, y, x2, y2); cout << fixed << setprecision(12) << res.first; cout << " "; cout << fixed << setprecision(12) << res.second << endl; } #endif
#include <algorithm> #include <iostream> #include <vector> #include <map> #include <cstdio> #include <string> #include <cmath> #include <queue> #include <tuple> #include <bitset> #include <cassert> #include <chrono> #include <cstring> #include <iomanip> #include <iostream> #include <random> #include <set> #include <stack> #include <time.h> #include <unordered_map> #include <unordered_set> #include <bits/stdc++.h> #define maxs(x,y) x = max(x,y) #define mins(x,y) x = min(x,y) #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) #define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++) #define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--) #define SORT(x) sort(x.begin(),x.end()) #define SORTR(x) sort(x.begin(),x.end(),greater<int>()) #define fi first #define se second #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple using namespace std; using ll = long long; using LL = long long; typedef std::pair<int, int> pii; typedef std::pair<int, double> pid; typedef std::vector<int> vi; typedef std::vector<pii> vii; const double PI = 3.14159265358979323846264338327950L; const int mod = 1e9+7; const ll INF = 1LL<<60; struct container { int bottom, top, id; container(int id, int bottom, int top) : top(top), bottom(bottom), id(id) { } }; struct Edge { ll to, from, cost; Edge(ll to, ll from, ll cost) :to(to), from(from), cost(cost) {} Edge(): to(-1), from(-1), cost(0){} }; struct Data { ll cost,val; Data(ll cost=0, ll val=0) : cost(cost), val(val){} bool operator<(const Data& a) const { return cost > a.cost; } }; struct edge{ int a,b,c; edge(int a = -1,int b = -1, int c = -1):a(a),b(b),c(c){} bool operator<(const edge& a) const { return c > a.c; } }; using C = complex<double>; C inC(){ double x,y; cin >> x >> y; return {x,y}; } void solve(){ int n; cin >> n; C a = inC(), b = inC(); C o = (a+b)/2.; double theta = 2*PI/n; C r = {cos(theta),sin(theta)}; C c =r*(a-o)+o; printf ("%.10f %.10f",c.real(),c.imag()); } int main() { int T = 1; // cin >> T; while (T--) { solve(); // cout << endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) namespace IO { const int MAXIOSIZE = 1 << 24 | 1; unsigned char buf[MAXIOSIZE], *p1, *p2; // #define gc (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 24, stdin), p1 == p2) ? EOF : *p1++) #define gc getchar() template <typename T> void read(T& x) { x = 0; char ch = gc; bool flg = false; for (; ch < '0' || '9' < ch; ch = gc) if (ch == '-') flg |= true; for (; '0' <= ch && ch <= '9'; ch = gc) x = x * 10 + ch - '0'; flg ? x = -x : 0; } template <typename T> void out(const T& x) { if (x > 9) out(x / 10); putchar(x % 10 + '0'); } template <typename T> inline void write(const T& x, const char& ed = ' ') { if (x < 0) putchar('-'), out(-x); else out(x); putchar(ed); } } const int MAXN = 5000 + 10; const int P = 998244353; int H, W, K, cntrow[MAXN][MAXN], cntcol[MAXN][MAXN], f[MAXN][MAXN][3], tag[MAXN][MAXN][3]; int pow3[MAXN]; int qpower(int a, int x) { int ret = 1; for (; x; x >>= 1, a = 1ll * a * a % P) ret = 1ll * ret * a % P; return ret; } int toint(char ch) { return (ch == 'D' ? 0 : (ch == 'R' ? 1 : 2)); } void add(int& a, int b) { a = a + b >= P ? a + b - P : a + b; } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); #endif IO::read(H), IO::read(W), IO::read(K); pow3[0] = 1; rep(i, 1, max(H, W)) pow3[i] = 1ll * pow3[i - 1] * 3 % P; rep(i, 1, K) { int x, y; char c[10]; IO::read(x), IO::read(y); scanf("%s", c + 1); tag[x][y][toint(c[1])] = true; } rep(i, 1, H) rep(j, 1, W) cntrow[i][j] = cntrow[i][j - 1] + ((tag[i][j][0] + tag[i][j][1] + tag[i][j][2]) == 0); rep(i, 1, W) rep(j, 1, H) cntcol[j][i] = cntcol[j - 1][i] + ((tag[j][i][0] + tag[j][i][1] + tag[j][i][2]) == 0); int tt = -1; rep(v, 0, 2) if (tag[1][1][v]) tt = v; if (tt != -1) f[1][1][tt] = true; else { rep(v, 0, 2) f[1][1][v] = true; } rep(i, 1, H) rep(j, 1, W) { if (i == 1 && j == 1) continue; int tt = -1; rep(v, 0, 2) { if (tag[i][j][v]) tt = v; add(f[i][j][v], 1ll * (f[i - 1][j][2] + f[i - 1][j][0]) * pow3[cntrow[i][j - 1]] % P); add(f[i][j][v], 1ll * (f[i][j - 1][2] + f[i][j - 1][1]) * pow3[cntcol[i - 1][j]] % P); } if (tt != -1) { rep(v, 0, 2) if (v != tt) f[i][j][v] = 0; } } int ans = 0; rep(v, 0, 2) add(ans, f[H][W][v]); IO::write(ans); return 0; }
#define LOCAL #ifdef LOCAL #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; #define int long long #define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++) #define rrep(i,n,e) for (int i = (ll)n; i > (ll)e; i--) #define ll long long #define ld long double #define pb push_back #define eb emplace_back #define All(x) x.begin(), x.end() #define Range(x, i, j) x.begin() + i, x.begin() + j // #define M_PI 3.14159265358979323846 // CF #define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI)) #define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360) #define Find(set, element) set.find(element) != set.end() #define Decimal(x) cout << fixed << setprecision(10) << x << endl; // print Decimal number 10 Rank #define endl "\n" #define Case(x) printf("Case #%d: ", x); // gcj typedef pair<int, int> PI; typedef pair<ll, ll> PLL; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<vector<vector<int>>> vvvi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<vector<vector<ll>>> vvvl; typedef vector<PI> vpi; typedef vector<vector<PI>> vvpi; typedef vector<PLL> vpl; typedef vector<vector<PLL>> vvpl; typedef vector<char> vch; typedef vector<vector<char>> vvch; constexpr ll INF = 1001002003004005006ll; constexpr int n_max = 2e5+10; template<class T> inline bool chmax(T &a, T b) { if(a<b) { a=b; return true; } return false; }; template<class T> inline bool chmin(T &a, T b) { if(a>b) { a=b; return true; } return false; }; template<class T, class U> T POW(T x, U n) {T ret=1; while (n>0) {if (n&1) {ret*=x;} x*=x; n>>=1;} return ret;}; // debug template <typename A, typename B> string to_string(pair<A, B> p); string to_string(const string &s) {return '"' + s + '"';}; string to_string(const char c) {return to_string((string) &c);}; string to_string(bool b) {return (b ? "true" : "false");}; 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) + ")";} void debug_out() {cerr << endl;}; template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }; void LINE_OUT() { cout << "--------------" << endl; }; #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define LINE LINE_OUT(); #else #define debug(...) 71 #define LINE 71; #endif void print() { cout << endl; } template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); }; template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }; template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }; vvi f(vi &A, string &s, int k) { int N = s.size(); vvi ans(k, vi(N+1)); rep(i,0,N+1) { int a = A[i]; int q = a/k; int re = a%k; rep(j,0,k) { ans[j][i] += q; } rep(j,0,k) { if (re) { ans[j][i] += 1; re--; } else break; } } return ans; }; signed main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; string s; cin >> s; vi A(N+1); rep(i,0,N+1) cin >> A[i]; int k = INF; rep(i,0,N) chmin(k, abs(A[i]-A[i+1])); vvi ans = f(A, s, k); cout << ans.size() << endl; for (vi &a: ans) { rep(i,0,N+1) { cout << a[i]; if (i < N) cout << " "; } cout << endl; } return 0; };
#include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<n;i++) #define pii pair<int,int> int N, M; int D[2010]; vector<pii> V[2010]; int unit(int s) { int ret = 1e18; memset(D, -1, sizeof(D)); priority_queue<pii, vector<pii>, greater<pii>> que; que.push({0, s}); while(que.size()) { pii tmp = que.top(); que.pop(); int v = tmp.second; int d = tmp.first; if(D[v] != -1)continue; D[v] = d; for(auto e : V[v]) { int n = e.first; int c = e.second; if(n == s)ret = min(ret, d + c); else que.push({d + c, n}); } } if(ret == 1e18)return -1; return ret; } signed main() { cin >> N >> M; rep(i, M) { int a, b, c; cin >> a >> b >> c; V[a].push_back({b, c}); } for(int i = 1; i <= N; i++)cout << unit(i) << endl; return 0; }
//Inshallah , Boys played well..!! #include <bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long #define pb push_back #define pf push_front #define mk make_pair #define f(i,j,n) for(ll i=j;i<n;i++) #define r(i,n,j) for(ll i=n-1;i>=j;i--) #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define Test int t;cin>>t;while(t--) #define mod 1000000007 #define md 998244353 #define MIN INT_MIN #define MAX INT_MAX #define inf LLONG_MAX #define all(container) container.begin() , container.end() #define rall(container) container.rbegin() , container.rend() #define sz(container) (int)container.size() #define vll vector<long long> #define vi vector<int> #define pii pair <int , int> #define pll pair <ll , ll> #define fi first #define se second #define setp(x) setprecision(x) #define meme(x,i) memset(x,i,sizeof(x)) #define lb lower_bound #define ub upper_bound #define me max_element #define debug(this) cout << "this = " << this << endl; const int N = 2005; vector<pair<int,int>> g[N]; int dis[N][N],dis2[N][N],w; int n,m,x,y; int z; void dijikstra(int u){ priority_queue< pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > pq; pq.push({0,u}); while(!pq.empty()){ pair<int,int> p=pq.top(); pq.pop(); for(auto i:g[p.se]){ if(dis2[u][i.fi]>dis2[u][p.se]+i.se){ dis2[u][i.fi]=dis2[u][p.se]+i.se; pq.push({dis2[i.fi][u],i.fi}); } } } } void solve() { cin >> n >> m; f(i,0,n+2){ f(j,0,n+2) dis[i][j]=dis2[i][j]=3e8; } f(i,0,m){ cin >> x >> y >> w; dis[x][y]=min(dis[x][y],w); } f(i,1,n+1){ f(j,1,n+1){ if(dis[i][j]!=3e8 and i!=j) g[i].pb({j,dis[i][j]}); } } f(i,1,n+1){ dis2[i][i]=0; dijikstra(i); } f(i,1,n+1){ int ans=dis[i][i]; f(j,1,n+1){ if(i!=j) ans=min(ans,dis2[i][j]+dis2[j][i]); } if(ans>=3e8) cout << -1 << endl; else cout << ans << endl; } } int main() { fast; int t = 1; //cin >> t; for(int i = 1; i <= t; i++) { //cout << "Case #" << i << ": "; solve(); } }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define mk make_pair #define fi first #define se second #define mset(a,b) memset(a, b, sizeof(a)) #define dbg(x) cout << "[" << #x << "]: " << x << endl; #define forn(i,n) for(int i=0; i < n;i++) #define forab(i,a,b) for(int i = a; i <= b; i++) #define forba(i,b,a) for(int i = b; i >= a; i--) #define each(val, v) for(auto val : v) #define abs(u) (u >= 0 ? u : -u) using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; using vi = vector<int>; using vl = vector<ll>; const int MAXN = 2e6 + 5; const int INF = 0x3f3f3f3f; const int MOD = 1e9+7; int uf[MAXN]; int sz[MAXN]; int find(int u){ if( uf[u] == u ) return u; return uf[u] = find(uf[u]); } int uni(int a, int b){ int aa= find(a), bb = find(b); if(aa == bb) return 0; if(sz[aa] > sz[bb]) swap(aa,bb); uf[aa] = bb; sz[bb] += sz[aa]; return 1; } int col(int i){ return i + 1005; } int line(int i){ return i; } void solve(){ int n,m; cin >> n >> m; forn(i, 5000){ uf[i] = i; } uni( col(0), line(0) ); uni( col(m-1), line(n-1) ); uni(col(0), col(m-1)); forn(i,n){ string s; cin>> s; forn(j,m){ if(s[j] == '#'){ uni( line(i), col(j) ); } } } set<int> lines; set<int> cols; int ans = n + m; forn(i,n){ int x = find(line(i)); lines.insert( x); } forn(i,m){ int x = find( col(i) ); cols.insert( x ); } int sz = lines.size(); ans = min(ans, sz -1); sz = cols.size(); ans = min(ans, sz-1); cout << ans << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); int t = 1; //cin >> t; while(t--){ solve(); } return 0; }
// // Created by mihai145 on 23.02.2021. // #include <iostream> #include <vector> #include <string> using namespace std; const int NMAX = 1000; int N, M; vector<int> g[2 * NMAX + 5]; bool vis[2 * NMAX + 5]; void dfs(int node) { vis[node] = true; for(auto it : g[node]) { if(!vis[it]) { dfs(it); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> M; for(int i = 0; i < N; i++) { string s; cin >> s; for(int j = 0; j < M; j++) { if(s[j] == '#') { g[i + 1].push_back(N + j + 1); g[N + j + 1].push_back(i + 1); } } } g[1].push_back(N + 1); g[N + 1].push_back(1); g[1].push_back(N + M); g[N + M].push_back(1); g[N].push_back(N + 1); g[N + 1].push_back(N); g[N].push_back(N + M); g[N + M].push_back(N); int compN = 0, compM = 0; for(int i = 1; i <= N; i++) if(!vis[i]) { compN++; dfs(i); } for(int i = 1; i <= N + M; i++) vis[i] = false; for(int i = 1; i <= M; i++) if(!vis[i + N]) { compM++; dfs(i + N); } cout << min(compN, compM) - 1 << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int char2int(char c) { assert(c >= '0' && c <= '9'); return c - '0'; } int getscore(int a[]) { int ans = 0; for (int i = 1; i < 10; i++) { ans += i * pow(10, count(a, a + 5, i)); } return ans; } int main() { int k; cin >> k; string s, t; cin >> s >> t; double ans = 0; int l[10]; int u[5], v[5]; for (int i = 0; i < 10; i++) l[i] = k; for (int i = 0; i < 4; i++) { l[char2int(s[i])]--; l[char2int(t[i])]--; u[i] = char2int(s[i]); v[i] = char2int(t[i]); } sort(u, u + 4); sort(v, v + 4); for (int i = 1; i < 10; i++) { for (int j = 1; j < 10; j++) { if (i == j) { if (l[i] <= 1) continue; } else { if (l[i] == 0 || l[j] == 0) continue; } u[4] = i; v[4] = j; if (getscore(u) > getscore(v)) { if (i == j) { ans += (l[i] / (double)(9 * k - 8)) * ((l[i] - 1) / (double)(9 * k - 9)); } else { ans += (l[i] / (double)(9 * k - 8)) * (l[j] / (double)(9 * k - 9)); } } } } printf("%.16f\n", ans); }
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define all(x) (x).begin(),(x).end() #define SZ(x) ((int)(x).size()) #define REP(i,n) for(int _n=n, i=0;i<_n;++i) #define FOR(i,a,b) for(int64_t i=(a),_b=(b);i<=_b;++i) #define FORD(i,a,b) for(int64_t i=(a),_b=(b);i>=_b;--i) using ull = uint64_t; using ll = int64_t; using PII = pair<int, int>; using VI = vector<int>; string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) const ll md = 1000000007; int32_t main() { ios_base::sync_with_stdio(false), cin.tie(0); int n, m; cin >> n >> m; map<int, set<int>> M; REP(i, m) { int r, c; cin >> r >> c; M[r].insert(c); } set<int> pos; pos.insert(n); for (auto [r, v] : M) { set<int> new_pos, to_check; // for (int y : pos) { // if (v.find(y - 1) != v.end()) { // new_pos.insert(y - 1); // } // if (v.find(y + 1) != v.end()) { // new_pos.insert(y + 1); // } // if (v.find(y) == v.end()) { // new_pos.insert(y); // } // } for (int y : v) { to_check.insert(y - 1); to_check.insert(y + 1); to_check.insert(y); } for (int y : to_check) { if (pos.find(y) == pos.end()) continue; if (v.find(y - 1) != v.end()) { new_pos.insert(y - 1); } if (v.find(y + 1) != v.end()) { new_pos.insert(y + 1); } // if (pos.find(y) != pos.end()) { // pos.erase(pos.find(y)); // } if (v.find(y) != v.end()) { pos.erase(pos.find(y)); } } for (int y : new_pos) { pos.insert(y); } // set<int> had; // for (int y : v) { // if (pos.find(y) != pos.end()) { // pos.erase(pos.find(y)); // had.insert(y); // } // } // for (int y : v) { // if (had.find(y - 1) != had.end() || pos.find(y - 1) != pos.end()) { // pos.insert(y); // } // if (had.find(y + 1) != had.end() || pos.find(y + 1) != pos.end()) { // pos.insert(y); // } // } } cout << SZ(pos) << endl; }
#include <algorithm> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, n) for(int i = 0; i < n; ++i) using namespace std; using LLONG = long long; const LLONG MOD = 1000000007; int main() { int N; cin >> N; vector<vector<int>> adList(N); REP(i, N) { string S; cin >> S; REP(j, N) { if (S[j] == '1') { adList[i].push_back(j); } } } vector<set<int>> ss(N); REP(s, N) { deque<int> Q{ s }; vector<bool> arrived(N, false); arrived[s] = true; while (!Q.empty()) { int t = Q.front(); Q.pop_front(); ss[t].insert(s); for (const int n : adList[t]) { if (arrived[n]) continue; Q.push_back(n); arrived[n] = true; } } } double ans = 0.0; REP(s, N) { const double sv = static_cast<double>(ss[s].size()); ans += 1.0 / sv; } cout << setprecision(12) << ans << endl; }
#include<iostream> #include<algorithm> #include<vector> #include<iomanip> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<n;i++) #define chmin(a,b) a=min(a,b) #define chmax(a,b) a=max(a,b) #define mod 1000000007 #define ad(a,b) a=(a+b)%mod; ll po(ll x,ll y){ ll res=1; for(;y;y>>=1){ if(y&1)res=res*x%mod; x=x*x%mod; } return res; } ll gcd(ll a,ll b){ return (b?gcd(b,a%b):a); } #define X 200010 ll fac[X],ivf[X]; void initfac(){ fac[0]=1; for(ll i=1;i<X;i++)fac[i]=fac[i-1]*i%mod; for(ll i=0;i<X;i++)ivf[i]=po(fac[i],mod-2); } ll C(ll n,ll k){ return fac[n]*ivf[n-k]%mod*ivf[k]%mod; } #define N 110 ll n; bool s[N][N]; int main(){ cin.tie(0); ios::sync_with_stdio(0); cin>>n; rep(i,n)rep(j,n){ char z; cin>>z; s[i][j]=z-'0'; } rep(i,n)s[i][i]=1; rep(k,n)rep(i,n)rep(j,n){ s[i][j]|=(s[i][k]&s[k][j]); } double ans=0; rep(i,n){ ll sum=0; rep(j,n)if(s[j][i])sum++; ans+=1.0/(double)sum; cerr<<sum<<endl; } cout<<fixed<<setprecision(9)<<ans<<endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; using P = pair<int,int>; #define F first #define S second #define MOD 1e9+7 const int inf = 1e9; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int a, b, c; cin >> a >> b >> c; ll A = abs(a), B = abs(b); if(c%2==0){ if(A > B) cout << ">" << endl; else if(A < B) cout << "<" << endl; else cout << "=" << endl; }else{ if(a > b) cout << ">" << endl; else if(a < b) cout << "<" << endl; else cout << "=" << endl; } return 0; }
#include<iostream> #include<algorithm> #include<vector> #include<string> #include<cmath> #include<queue> #include<functional> #include<set> using namespace std; typedef long long ll; int N; string S, X; int dp[200000 + 100][7];//dp[i][j] := 1-idxでi桁目まで作ったときに、余りがjの時のgrundy数 //0なら高橋の勝ち int memo(int digit, int mod) { //digitは0-idx if (digit == N) { if (mod == 0)return dp[digit][mod] = 0; else return dp[digit][mod] = 1; } if (dp[digit][mod] != -1)return dp[digit][mod]; int ret = -1; if (X[digit] == 'A') { //Tを勝たせたくない 遷移先のどれかに0以外があればOK //0を追加 int add0 = memo(digit + 1, (mod * 10) % 7); //S[i]を追加 int addSi = memo(digit + 1, (mod * 10 + (S[digit] - '0')) % 7); if (add0 != 0 || addSi != 0) ret = 1; else ret = 0; } else { //Tなので勝ちたい。遷移先のどれかに0があればOK //0を追加 int add0 = memo(digit + 1, (mod * 10) % 7); //S[i]を追加 int addSi = memo(digit + 1, (mod * 10 + (S[digit] - '0')) % 7); if (add0 == 0 || addSi == 0) ret = 0; else ret = 1; } return dp[digit][mod] = ret; } int main() { cin >> N >> S >> X; for (int i = 0; i <= N; i++)for (int j = 0; j < 7; j++)dp[i][j] = -1; int ret = memo(0, 0); if (ret == 0)cout << "Takahashi" << endl; else cout << "Aoki" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define Rep(i,j,n) for(int i = j; i < (int)(n); i++) using Graph = vector<vector<int>>; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main(){ int n; cin >> n; map<int, string> m; rep(i,n){ string s; int t; cin >> s >> t; m[t] = s; } int num = 1, cnt = 0; for (auto i = m.rbegin(); i != m.rend(); ++i) { if(cnt == num) { cout << i->second << endl; return 0; } cnt++; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(a) (a.begin(),a.end()) #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep2(i, s, n) for (int i = s; i < (int)(n); ++i) #define ret return //cout << fixed << setprecision(15) //ASCIIコード 0==48 A==65 Z==90, a==97 z==122 int main(){ string N; cin>>N; ll cnt=0; reverse all(N); rep(i,N.size()){ if(N[i]=='0') cnt++; else break; } rep(i,cnt){ N.push_back('0'); } string S=N; reverse all(N); if(S==N){cout <<"Yes"<<endl; ret 0;} cout <<"No"<<endl; }
//@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_popcountll(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); } struct Init_io { Init_io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << boolalpha << fixed << setprecision(15); } } init_io; 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(n); vi v(n * 2); cin >> v; ll ans = 0; priority_queue<int> pq; rep(i, n) { pq.push(v[i]); pq.push(v[n * 2 - 1 - i]); ans += pq.top(); pq.pop(); } fin(ans); }
/* thisiscaau's code What’s happened happened. Which is an expression of faith in the mechanics of the world. It’s not an excuse to do nothing. */ /* shortcuts */ /*#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops")*/ // for emergency cases #include<bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define pb push_back #define mp make_pair typedef pair<ll,ll> ii; typedef vector<ii> vii; /* constants */ ll const inf = 1e9 + 7, MAXN = 2e5 + 5; /* declaration */ ll n,m,tc; ll a[MAXN << 1]; /* workspace */ ll sum; priority_queue<ll,vector<ll>,greater<ll>> pq; signed main(){ ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin >> n; for (int i = 1 ; i <= 2*n ; i++){ cin >> a[i]; sum += a[i]; } ll lf = n,rt = n+1; while (lf >= 1 && rt <= 2*n){ pq.push(a[lf]); pq.push(a[rt]); sum -= pq.top(); pq.pop(); lf--; rt++; } cout << sum; }
#include<bits/stdc++.h> using namespace std; int m,h; int main(){ cin>>m>>h; if(h%m==0)cout<<"Yes"; else cout<<"No"; }
#include <bits/stdc++.h> using namespace std; #define gc getchar_unlocked #define fo(i, n) for (i = 0; i < n; i++) #define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) #define ll long long #define si(x) scanf("%d", &x) #define sl(x) scanf("%lld", &x) #define ss(s) scanf("%s", s) #define pi(x) printf("%d\n", x) #define pl(x) printf("%lld\n", x) #define ps(s) printf("%s\n", s) #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 #define endl "\n" #define YES cout<<"YES"<<"\n"; #define NO cout<<"NO"<<"\n"; typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); int rng(int lim) { uniform_int_distribution<int> uid(0, lim - 1); return uid(rang); } int mpow(int base, int exp); void ipgraph(int n, int m); void dfs(int u, int par); const int mod = 1'000'000'007; const int N = 3e5, M = N; //======================= vi g[N]; int a[N]; vector<ll> SieveOfEratosthenes(ll n) { vector<ll> ans; bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) if (prime[p] == true) for (int i = p * p; i <= n; i += p) prime[i] = false; for (int p = 2; p <= n; p++) if (prime[p]) ans.push_back(p); return ans; } 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; } void solve() { ll i, j, n, m; cin>>n>>m; if(m%n){ cout <<"No"<<endl; } else{ cout <<"Yes"<<endl; } } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); ll t = 1; while (t-- > 0) { solve(); } return 0; } int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = ((ll)result * base) % mod; base = ((ll)base * base) % mod; exp >>= 1; } return result; } void ipgraph(int n, int m) { int i, u, v; while (m--) { cin >> u >> v; u--, v--; g[u].pb(v); g[v].pb(u); } } void dfs(int u, int par) { for (int v : g[u]) { if (v == par) continue; dfs(v, u); } }
#include <iostream> #include <cmath> #include <vector> #include <string> #include <map> #include <queue> #include <algorithm> #include <numeric> #include <fstream> #include <iomanip> typedef long double ld; typedef long long ll; const ll INF = (ll)1e18 + 1; const ll MOD = 1e9 + 7; // Output template<class T, class S> std::ostream& operator <<(std::ostream& os, std::pair<T, S> p) { return os << "(" << p.first << " " << p.second << ")"; } template<class T> std::ostream& operator <<(std::ostream& os, std::vector< T > v) { for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; } //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; } return os; } template<class T, class S> std::ostream& operator <<(std::ostream& os, std::map< T, S > m) { ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;} return os; } template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv) { for (auto& vec : vv){ os << vec << std::endl; } os << "--------" << std::endl; return os; } void print(){ std::cout << std::endl; } template<typename H> void print(H&& head){ std::cout << head << std::endl; } template<typename H, typename... T> void print(H&& head, T&&... tail){ std::cout << head << " ", print(std::forward<T>(tail)...); } void solve() { ll A, B, C; std::cin >> A >> B >> C; if (A*A + B*B < C*C) { print("Yes"); } else { print("No"); } return; } int main() { std::cin.tie(nullptr); std::cout.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define rep(i,n) for(LL i=0;i<(n);i++) int main() { LL a, b, c; string output = "No"; cin >> a >> b >> c; a *=a; b *= b; c *= c; if(a+b < c) output = "Yes"; cout << output << endl; 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 FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i) template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;} template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;} struct bag{ ll w,v; }; struct Box{ ll num,x; }; bool compbag(bag& a, bag& b){ return a.v > b.v; } bool compbox(Box& a, Box& b){ return a.x < b.x; } int main(){ int n,m,q; cin >> n >> m >> q; vector<bag> b(n); REP(i,n) cin >> b[i].w >> b[i].v; sort(b.begin(), b.end(), compbag); vector<Box> box(m); REP(i,m){ cin >> box[i].x; box[i].num = i; } sort(box.begin(), box.end(), compbox); REP(query,q){ int l,r; cin >> l >> r; l--; r--; ll ans=0; vector<bool> emp(m,true); REP(i,n){ REP(j,m){ if(l <= box[j].num && box[j].num <= r)continue; if(emp[j] && b[i].w <= box[j].x){ emp[j] = false; ans += b[i].v; break; } } } cout << ans << endl; } return 0; }
#include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; void solve(){ int x,y,z; cin>>x>>y>>z; for(int i=1000000;i>=0;i--){ if(i*x < y*z){ cout<<i; return; } } } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<fixed; cout<<setprecision(10); // freopen("timber_input.txt", "r", stdin); // freopen("timber_output.txt", "w", stdout); int t=1; // cin>>t; for(int i=1;i<=t;i++){ // cout<<"Case #"<<i<<": "; solve(); } return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; using ll=long long; using ld=long double; using pll=pair<ll, ll>; //using mint = modint1000000007; #define rep(i,n) for (ll i=0; i<n; ++i) #define all(c) begin(c),end(c) #define PI acos(-1) #define oo 2e18 template<typename T1, typename T2> bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;} template<typename T1, typename T2> bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;} //priority_queue<ll, vector<ll>, greater<ll>> Q; /* */ char add_wbr(char a, char b){ if (a==b) return(a); if (a=='W' && b=='R') return('B'); if (a=='W' && b=='B') return('R'); if (a=='B' && b=='W') return('R'); if (a=='B' && b=='R') return('W'); if (a=='R' && b=='W') return('B'); if (a=='R' && b=='B') return('W'); return (0); } int main(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); ll N; string S; cin >> N >> S; ll sz=S.size(); while (sz>1){ // 4->1, 5->4->1 while(sz%3!=1){ string T; for(ll j=0; j<sz-1; j++) T+=add_wbr(S[j], S[j+1]); S=T; sz=S.size(); } string T; for(ll j=0; j+3<sz; j+=3) T+=add_wbr(S[j], S[j+3]); if (T[0]) S=T; sz=S.size(); } cout << S[0] << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) (v).begin(), (v).end() using ll = long long; constexpr int INF = 1e9; constexpr long long LINF = 1e18; constexpr long long MOD = 1e9 + 7; signed main() { int n, m; cin >> n >> m; vector<pair<int, int>> v[n]; int x, y, z; rep(i, m) { cin >> x >> y >> z; x--; v[x].emplace_back(y, z); }; ll dp[1 << n] = {}; dp[0] = 1; for (int bit = 0; bit < 1 << n; bit++) { if (!dp[bit]) continue; rep(use, n) { if (bit >> use & 1) continue; int nxt = bit | 1 << use; bool ng = false; for (auto p : v[__builtin_popcount(bit)]) { int cnt = 0; rep(k, p.first) { cnt += (nxt >> k) & 1; } if (cnt > p.second) { ng = true; break; } } if (ng) continue; dp[nxt] += dp[bit]; } } cout << dp[(1 << n) - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=1e6+7; const int inf=2e9; const ll inff=1e18; const ll mod=1e9+7; #define pii pair<int,int> #define mkp make_pair #define F first #define S second #define pb push_back #define sz(v) ((int)(v).size()) #define all(v) (v).begin(),(v).end() //#define int ll int dp[maxn][8]; int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin>>n; string s,t; cin>>s>>t; dp[n][0]=1; int base=1; for (int i=n-1;i>=0;i--) { for (int j=0;j<7;j++) { int val=(t[i]=='T' ? 1 : 0); if (dp[i+1][j]==val||dp[i+1][(j+(s[i]-'0')*base)%7]==val) dp[i][j]=val; else dp[i][j]=(val^1); } base=base*10%7; } cout<<(dp[0][0] ? "Takahashi\n" : "Aoki\n"); }
#include <bits/stdc++.h> #define fi first #define se second #define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++) #define mk make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define IT iterator #define V vector #define TP template <class o> #define TPP template <typename t1, typename t2> #define SZ(a) ((int)a.size()) #define all(a) a.begin(), a.end() #define rep(i, a, b) for (int i = a; i <= b; i++) #define REP(i, a, b) for (int i = b; i >= a; i--) #define FOR(i, n) rep(i, 1, n) #define debug(x) cerr << #x << ' ' << '=' << ' ' << x << endl using namespace std; typedef unsigned ui; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ld; // char buf[1 << 20],*p1=buf,*p2=buf; TP void qr(o& x) { char c = gc; x = 0; int f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = gc; } while (isdigit(c)) x = x * 10 + c - '0', c = gc; x *= f; } template <class o, class... O> void qr(o& x, O&... y) { qr(x); qr(y...); } TP void qw(o x) { if (x / 10) qw(x / 10); putchar(x % 10 + '0'); } TP void pr1(o x) { if (x < 0) x = -x, putchar('-'); qw(x); putchar(' '); } template <class o, class... O> void pr1(o x, O... y) { pr1(x); pr1(y...); } TP void pr2(o x) { if (x < 0) x = -x, putchar('-'); qw(x); putchar(10); } template <class o, class... O> void pr2(o x, O... y) { pr2(x); pr2(y...); } TP void cmax(o& x, o y) { if (x < y) x = y; } TP void cmin(o& x, o y) { if (x > y) x = y; } const int mod = 998244353; TPP void ad(t1& x, t2 y) { x += y; if (x >= mod) x -= mod; } TPP void dl(t1& x, t2 y) { x -= y; if (x < 0) x += mod; } const int N = 2e5 + 10, inf = 2e9; const ll INF = 1e15; int n, k, d[N], now, ans; V<int> e[N]; void ins(int x, int y) { e[x].pb(y); } void dfs(int x, int fa) { int mn = N, mx = 0; //* d[x] >= 0 表示子树内有一个距离x d[x]的点. d[x] < 0 表示子树外有一个距离x -d[x]的点. for (int y : e[x]) if (y ^ fa) dfs(y, x), cmin(mn, d[y] + 1), cmax(mx, d[y] + 1); d[x] = mn + mx < 0 ? mn : mx; //能覆盖就忽略mx. 否则保留mx. if (d[x] >= now) d[x] = -now - 1, ans++; } bool check() { dfs(1, 0); ans += (d[1] >= 0); return ans <= k; } void solve() { qr(n, k); FOR(i, n - 1) { int x, y; qr(x, y); ins(x, y); ins(y, x); } int l = 1, r = n, mid; while (l < r) { mid = (l + r) / 2; ans = 0; now = mid; if (check()) r = mid; else l = mid + 1; debug(mid); debug(ans); } pr2(l); } int main() { #ifndef ONLINE_JUDGE clock_t start_time = clock(); #endif int T = 1; // qr(T); while (T--) solve(); #ifndef ONLINE_JUDGE cerr << 1.0 * (clock() - start_time) / CLOCKS_PER_SEC << ' ' << 's' << endl; #endif return 0; }
#include<bits/stdc++.h> using namespace std; #define FOR(i,a,n) for(ll i=a;i<n;i++) #define ll long long #define PB push_back #define vi vector<int> #define vl vector<ll> #define pi pair<int,int> #define vp vector<pi> #define modulo (1e9+7) int power(long long x, ll y, ll p) // modular exponentiation { ll res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p if (x == 0) return 0; // In case x is divisible by p; while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = (res*x) % p; y = y>>1; // y = y/2 x = (x*x) % p; } return res; } int binarySearch(vector<int> arr, int l, int r, int x) { if (r >= l) { int mid = l + (r - l) / 2; if (arr[mid] == x) return mid; if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); return binarySearch(arr, mid + 1, r, x); } return -1; } int search1(vi arr, int n, int x) // linear search { int i; for (i = 0; i < n; i++) if (arr[i] == x) return i; return -1; } int main() { int a,b; cin>>a>>b; int c=a*b; cout<<c/100; if(c%100!=0) { cout<<"."<<(c%100)/10; if(c%10!=0) cout<<(c%10); } return 0; }
#include <iostream> #include <iomanip> using namespace std; int main() { int A, B; cin >> A >> B; // std::fixed -> 固定小数点で出力することを指定 // std::setprecision(int n) -> 小数点以下 n 桁で出力することを指定 cout << scientific << setprecision(7); cout << A * B / 100.0 << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define ALL(c) (c).begin(),(c).end() #define RALL(c) (c).rbegin(),(c).rend() #define ZERO(c) memset(c, 0, sizeof(c)) using ll = long long; // using P = pair<int,int>; const int INF = 1e9 + 5; const ll INFL = 1e18 + 5; int A[1005], B[1005], N, upper = 1000, lower = 0, a, b; int main() { cin >> N; rep(i,N) cin >> A[i]; rep(i,N) cin >> B[i]; rep(i,N) { upper = min(upper, B[i]); lower = max(lower, A[i]); } cout << max(0, upper - lower + 1) << endl; }
// #include <bits/stdc++.h> #include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cmath> #include <limits> #include <stdio.h> #include <string.h> #include <numeric> // #define P pair<int, int> #define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0])) #define rep(i, a, b) for (int i = a; i < b; i++) const long long INF = 1LL << 60; typedef long long ll; 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; } #define all(x) (x).begin(), (x).end() using namespace std; // 上下左右の移動用配列 // セットで上、右、下、左の順番 int dx[4] = {0, 1, 0, -1}; int dy[4] = {-1, 0, 1, 0}; // B int main(int, char **) { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } vector<int> B(N); for (int i = 0; i < N; i++) { cin >> B[i]; } sort(A.begin(), A.end()); sort(B.begin(), B.end()); int ans = 0; for (int i = A[N - 1]; i <= B[0]; i++) { ans++; } cout << ans << endl; }
#include<bits/stdc++.h> #define ll long long using namespace std; int main() { ll n; cin>>n; ll sum=0; while(n--) { ll x,y; cin>>x>>y; sum+=(y*(y+1)/2)-(x*(x-1)/2); } cout<<sum; }
#include <iostream> #include <map> #include <set> #include <vector> using namespace std; typedef long long ll; int main() { int N; ll C; cin >> N >> C; vector<int> a(N), b(N), c(N); set<int> s; map<int, vector<int>> starts, ends; for (int i = 0; i < N; ++i) { cin >> a[i] >> b[i] >> c[i]; // We only need a[i] and b[i]+1 to represent the final segments. // For example, [1, 4] and [3, 8] will make // [1, 2], [3, 4], [5, 8] and [9, +inf]. // We need 1, 3, 5, and 9 to represent these segments. s.insert(a[i]), s.insert(b[i] + 1); starts[a[i]].emplace_back(i); ends[b[i] + 1].emplace_back(i); } vector<int> v(s.begin(), s.end()); int M = v.size(); ll ans = 0, acc = 0; for (int i = 0; i < M - 1; ++i) { if (ends.count(v[i])) { for (int j : ends[v[i]]) acc -= c[j]; } if (starts.count(v[i])) { for (int j : starts[v[i]]) acc += c[j]; } ans += min(C, acc) * (v[i + 1] - v[i]); } cout << ans; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define M 1000000000 int main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif int n; cin>>n; string s; cin>>s; ll sum = 0; map<ll, ll> m; m[0] = 1; ll ans = 0; for(int i=0; i<n; i++){ if(s[i] == 'A') sum++; else if(s[i] == 'T') sum--; else if(s[i] == 'G') sum += 100000; else sum -= 100000; ans += m[sum]; m[sum]++; } cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; string s; cin >> n >>s ; int ans=0; for (int i=0;i<n;i++){ int f=0,se=0; for (int j=i;j<n;j++){ if (s[j]=='A') f++; else if (s[j]=='T') f--; else if (s[j]=='C') se++; else se--; if ((j-i)%2==1 && f==0 && se==0) ans++; } } cout << ans ; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll N=105; bool vis[N][N][N]; long double dp[N][N][N]; long double func(ll a,ll b,ll c){ if(a==100 || b==100 || c==100)return 0; if(vis[a][b][c])return dp[a][b][c]; vis[a][b][c]=1; dp[a][b][c]+=((func(a+1,b,c)+1)*a*1.0)/(a+b+c+0.0); dp[a][b][c]+=((func(a,b+1,c)+1)*b*1.0)/(a+b+c+0.0); dp[a][b][c]+=((func(a,b,c+1)+1)*c*1.0)/(a+b+c+0.0); return dp[a][b][c]; } int main(){ ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll a,b,c;cin>>a>>b>>c; cout<<fixed<<setprecision(18)<<func(a,b,c); }
#include <bits/stdc++.h> using namespace std; using ll=long long; using vin=vector<int>; using vll=vector<long long>; using vvin=vector<vector<int>>; using vvll=vector<vector<long long>>; using vstr=vector<string>; using vvstr=vector<vector<string>>; using vch=vector<char>; using vvch=vector<vector<char>>; using vbo=vector<bool>; using vvbo=vector<vector<bool>>; using vpii=vector<pair<int,int>>; using pqsin=priority_queue<int,vector<int>,greater<int>>; #define mp make_pair #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep2(i,s,n) for(int i=(s);i<(int)(n);i++) #define all(v) v.begin(),v.end() #define decp(n) cout<<fixed<<setprecision((int)n) const ll inf=1e9+7; const ll INF=1e18; const ll mod=99824453; vin dx={-1,0,1,0}; vin dy={0,1,0,-1}; int main(){ int n;ll k,m;cin>>n>>k>>m; vvll dp(n+1,vll(510000));//dp[i][j]:1~iの中から各々k個まで使って総和をjにする通り数 vvll res(n+1,vll(510000));//res[i][j]=dp[i][j]+dp[i][j-(i+1)]+dp[i][j-2(i+1)]+...+dp[i][j-k(i+1)] dp[0][0]=(ll)1; //rep(i,k+1)res[0][i]=(ll)1; rep2(i,1,n+1)rep(j,(i*(i+1)*k)/2+1){ res[i][j%i]+=dp[i-1][j]; res[i][j%i]%=m; if(j-(k+1)*i>=0){ res[i][j%i]-=dp[i-1][j-(k+1)*i]; if(res[i][j%i]<0)res[i][j%i]+=m; } dp[i][j]=res[i][j%i]; /*dp[i][j]=res[i-1][j];//dp[i][j]=dp[i-1][j]+dp[i-1][j-i]+...+dp[i-1][j-ki] res[i][j]=dp[i][j]; if(j-(i+1)>=0){ res[i][j]+=res[i][j-(i+1)]; res[i][j]%=m; } if(j-(k+1)*(i+1)>=0){ res[i][j]-=dp[i][j-(k+1)*(i+1)]; if(res[i][j]<0)res[i][j]+=m; }*/ } ll ans; rep2(x,1,n+1){ ans=(ll)0; rep2(i,1,(x*(x+1)*k)/2+1){ ans+=(dp[x-1][i]*dp[n-x][i])%m; ans%=m; } ans*=k+(ll)1;ans%=m; ans+=k;ans%=m; cout<<ans<<endl; } }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define pb push_back typedef long double ld; #define fi first #define se second #define PI 3.14159265358979323846264338327950288419716939937510 #define mp make_pair #define vvl vector<vector<ll>> #define vll vector<ll> #define vpll vector<pll> #define vvpll vector<vpll> /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> */ ll inf = 1e18; ll p = 1e9 + 7; ld eps = 1e-9; ll power(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } ll pwr(ll x, ll y) { ll res = 1; x = x ; while (y > 0) { if (y & 1) res = (res * x) ; y = y >> 1; x = (x * x) ; } return res; } ll modInverse(ll n, ll p) { return power(n, p - 2, p); } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } 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); ll i, y, x, z, g, key, h, n, m, a, b, c, j, k, d; ll t2, t3, t4, t1, t5, t6; string s, s2, s1; ll l, r; ll tc; //cin >> tc; tc = 1; ll x1, y1, x2, y2; while (tc--) { cin >> n; ll arr[n], b[n]; for (i = 0; i < n; i++) cin >> arr[i]; for (i = 0; i < n; i++) cin >> b[i]; ll val = 0; for (i = 0; i < n; i++) { val += (arr[i] * b[i]); } if (val == 0) cout << "Yes"; else cout << "No"; } return 0; }
#include <bits/stdc++.h> #include <fstream> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; const int INF=2147483647; // 9,223,372,036,854,775,807 const ll INFL = 9223372036854775807; int main(){ // 入力ファイル使うとき ll ans; ll n,m,t; cin >> n >>m >>t; vector<vector<ll>> ab(m,vector<ll>(2)); for(int i=0;i<m;i++){ cin >> ab[i][0] >> ab[i][1]; } // m回のカフェの訪問 ll absta = 0; ll chvtmp = n; for(int i=0;i<m;i++){ chvtmp -= (ab[i][0] - absta); if(chvtmp<=0){ cout << "No"<<endl; return 0; } chvtmp += (ab[i][1]-ab[i][0]); if(chvtmp>=n){ chvtmp = n; } absta = ab[i][1]; } if(t-ab[m-1][1] >= chvtmp){ cout << "No" << endl; } else{ cout << "Yes" << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n] , brr[n]; for(int i=0 ; i<n ; i++) { cin >> arr[i]; cin >> brr[i]; } int count=0; for(int i=0 ; i<n-1 ; i++) { int x=arr[i] , y=brr[i]; for(int j=i+1 ; j<n ; j++) { if(arr[j]-x != 0) { int a = arr[j]-x; int b = brr[j]-y; if(abs(a) >= abs(b)) count++; } } } cout << count << "\n"; return 0; }
#pragma GCC optimize("O3") //#pragma GCC target("avx") #include <bits/stdc++.h> using namespace std; #define re return #define pb push_back #define all(x) (x).begin(), (x).end() #define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin()) #define fi first #define se second #define ss second.second #define sf second.first #define ff first.first #define fs first.second #define sqrt(x) sqrt(abs(x)) #define mp make_pair #define PI 3.14159265358979323846 #define E 2.71828182845904523536 #define er erase #define in insert #define fo(i,n) for((i)=0;(i)<(n);(i)++) #define ro(i,n) for((i)=n-1;(i)>=0;(i)--) #define fr(i,j,n) for((i)=(j);(i)<(n);(i)++) #define rf(i,j,n) for((i)=((n)-1);(i)>=(j);(i)--) typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; void eras(map<int,int> &m,int x) { m[x]--; if (!m[x]) m.erase(x); } const int N=(int)3e5+100; const int M=(int)2e6+100; const int inf=(int)1e9+2; #define filename "" vector<int> v[N]; int h[N]; pair<int,int> o[N]; bool sss(pair<int,int> &x,pair<int,int> &y) { if (x.fi-x.se==y.fi-y.se) re x<y; re x.fi-x.se>y.fi-y.se; } void dfs(int x) { h[x]=1; vector<pair<int,int> > vv[2]; for(auto y:v[x]) { dfs(y); h[x]+=h[y]; vv[h[y]%2].pb(o[y]); } o[x]={0,0}; if (vv[1].size()%2) { for(auto &j:vv[0]) { o[x].fi+=max(j.fi,j.se); o[x].se+=min(j.fi,j.se); } } else { for(auto &j:vv[0]) { o[x].fi+=j.fi; o[x].se+=j.se; } } sort(all(vv[1]),sss); int i; fo(i,vv[1].size()) { if (i%2) { o[x].fi+=vv[1][i].se; o[x].se+=vv[1][i].fi; } else { o[x].fi+=vv[1][i].fi; o[x].se+=vv[1][i].se; } } o[x].se++; } int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); //freopen(filename".in","r",stdin); //freopen(filename".out","w",stdout); //freopen("ans.txt","w",stdout); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); srand(time(0)); ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); int n,i; cin>>n; fo(i,n-1) { int a; cin>>a; a--; v[a].pb(i+1); } dfs(0); cout<<o[0].se; }
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c,d; cin>>a>>b>>c>>d; if (a==c&&b==d){ cout<<0; return 0; } if (a+b==c+d){ cout<<1; return 0; } if (a-b==c-d){ cout<<1; return 0; } if (abs(a-c)+abs(b-d)<=3){ cout<<1; return 0; } if ((a+b)%2==(c+d)%2) { cout<<2; return 0; } if (abs(abs(a-b)-abs(c-d))<=5){ cout<<2; return 0; } if (abs(abs(a+b)-abs(c+d))<=5){ cout<<2; return 0; } cout<<3; }
#include <bits/stdc++.h> #define FOR(i, begin, end) for(int i=(begin);i<(end);i++) #define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--) #define rep(i, n) FOR(i,0,n) #define irep(i, n) IFOR(i,0,n) #define all(v) begin(v), end(v) using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int, int>; using PLL = pair<ll, ll>; using VI = vector<int>; using VLL = vector<ll>; using VB = vector<bool>; using VP = vector<P>; using Graph2 = vector<vector<int>>; using PQ = priority_queue<int>; template<typename T>istream& operator>>(istream&s,vector<T>&v){for(auto &i: v)s>>i;return s;} template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } bool second_compare(P a,P b){if(a.second!=b.second){return a.second<b.second;} else return true;} int main() { ll x, y, z; cin >> x >> y >> z; for(ll i = 1001 * 1001; i >= 0; i--) { if (y*z > i*x) { cout << i << endl; return 0; } } cout << 0 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define len(x) int((x).size()) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define randint(n) uniform_int_distribution<int>(1, (n))(rng) int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifdef ARTHUR_LOCAL ifstream cin("input.txt"); #endif int n,m; cin>>n>>m; if(n==1&&m==0) { cout << "1 2\n"; return 0; } if(m<0 || m>=n-1) { cout << -1 << endl; return 0; } int diff = m+1; cout << 1 << " " << diff*2 + 2 << endl; n--; int cur=2; while(diff--) { cout << cur << " " << cur+1 << "\n"; cur+=2; n--; } cur++; while(n--) { cout << cur << " " << cur+1 << "\n"; cur+=2; } }
#include<bits/stdc++.h> using namespace std; namespace IO { const int buffer_size=1e5+5; char buf[buffer_size],*S,*T; bool flag_EOF; inline char read_char() { if(S==T) T=(S=buf)+fread(buf,1,buffer_size,stdin); return S!=T?*(S++):EOF; } inline int read_int() { int flag=1; char c=read_char(); while(c<'0'||c>'9') { if(c==EOF) { flag_EOF=true; return 0; } flag=(c=='-'?-1:1); c=read_char(); } int x=0; while(c>='0'&&c<='9') { x=x*10+(c^48); c=read_char(); } return x*flag; } char st[13]; int _top; inline void Write(int x) { if(!x) { putchar('0'); return; } if(x<0) { putchar('-'); x=-x; } while(x) { st[++_top]=x%10+'0'; x/=10; } while(_top>0) putchar(st[_top--]); } } const int max_N=2e5+5; int a[max_N],b[max_N],p[max_N],id[max_N],pos[max_N]; inline bool cmp(int x,int y) { return b[x]>=b[y]; } typedef pair<int,int> P; vector<P> ans; int main() { int N; scanf("%d",&N); for(int i=1;i<=N;++i) scanf("%d",a+i); for(int i=1;i<=N;++i) scanf("%d",b+i); for(int i=1;i<=N;++i) { scanf("%d",p+i); if(a[i]<=b[p[i]]&&p[i]!=i) { puts("-1"); return 0; } id[p[i]]=i; pos[i]=i; } sort(pos+1,pos+N+1,cmp); for(int t=1;t<=N;++t) { int i=pos[t]; if(p[i]==i) continue; int x=id[i]; ans.push_back(P(i,x)); swap(id[p[i]],id[p[x]]); swap(p[i],p[x]); } printf("%d\n",int(ans.size())); for(int i=0;i<int(ans.size());++i) printf("%d %d\n",ans[i].first,ans[i].second); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vint; typedef vector<vint> vvint; typedef vector<bool> vbool; typedef vector<vbool> vvbool; typedef pair<ll, ll> iPair; #define ff first #define ss second // #include <boost/multiprecision/cpp_int.hpp> // using namespace boost::multiprecision; // Use 'cpp_int' instead of 'int' int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ll n, x; string s; cin >> n >> x >> s; for(auto i:s){ x = (i == 'o') ? x + 1 : max(0ll, x - 1); } cout << x; 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, x; cin >> n >> x; rep(i,n){ char s; cin >> s; if(s=='o'){ x++; } else if(s=='x' && x>0){ x--; } } cout << x << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int cn = min(n, 8); vector<long long> a(cn); for (int i = 0; i < cn; i++) { cin >> a.at(i); } int tmp_1 = 0, tmp_2; vector<int> r(200, 0); for (int tmp = 1; tmp < (1 << cn); tmp++) { long long sum = 0; for (int i = 0; i < cn; i++) { if (tmp & (1 << i)) { sum = (sum + a.at(i)) % 200; } } if (r.at(sum) != 0) { tmp_1 = tmp; tmp_2 = r.at(sum); break; } r.at(sum) = tmp; } if (tmp_1 == 0) { cout << "No" << endl; return 0; } vector<int> b(0); vector<int> c(0); for (int i = 0; i < cn; i++) { if (tmp_1 & (1 << i)) b.push_back(i + 1); if (tmp_2 & (1 << i)) c.push_back(i + 1); } cout << "Yes" << endl; cout << b.size(); for (int i = 0; i < (int)b.size(); i++) { cout << " " << b.at(i); } cout << endl; cout << c.size(); for (int i = 0; i < c.size(); i++) { cout << " " << c.at(i); } cout << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; vector<string> dfs(int n){ if(n==1) return {"AB"}; vector<string> res; for(string s:dfs(n-1)){ string t1,t2; for(char c:s){ if(c=='A') t1+="AA", t2+="AB"; else t1+="BB", t2+="BA"; } res.emplace_back(t1); res.emplace_back(t2); } string s; rep(i,1<<n-1) s+="AB"; res.emplace_back(s); return res; } int main(){ int n; cin>>n; auto ans=dfs(n); cout<<ans.size()<<'\n'; for(string s:ans) cout<<s<<'\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vec = vector<ll>; using mat = vector<vec>; using pll = pair<ll,ll>; #define INF (1LL << 60) #define MOD 1000000007 #define PI 3.14159265358979323846 #define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i)) #define FORR(i,v) for(auto (i):v) #define ALL(x) (x).begin(), (x).end() #define PR(x) cout << (x) << endl #define PS(x) cout << (x) << " " #define SZ(x) ((ll)(x).size()) #define MAX(a,b) (((a)>(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b)) #define REV(x) reverse(ALL((x))) #define ASC(x) sort(ALL((x))) #define DESC(x) ASC((x)); REV((x)) #define pb push_back #define eb emplace_back int main() { ll N; cin >> N; vec A(N), B(N); REP(i,0,N) cin >> A[i] >> B[i]; ll sum = 0; REP(i,0,N) { sum += (B[i] - A[i] + 1) * (A[i] + B[i]) / 2; } PR(sum); return 0; } /* */
//Work should be challenging and challange should be fun #include<bits/stdc++.h> using namespace std; #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define ll long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i,n) for(i=0;i<n;i++) #define forn(i, n) for (ll i = 0; i < (ll)(n); ++i) #define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) #define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) #define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i) #define fora(it,x) for(auto it:x) #define PI 3.14159265 #define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define endl "\n" typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef long double ld; template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } int main(){ ll a,b; cin>>a>>b; cout<<(a+b)/2<<" "<<(a-b)/2; }
#include<bits/stdc++.h> using namespace std; #define sc(x) scanf("%d",&x) #define scll(x) scanf("%lld",&x) #define pb push_back #define mp make_pair #define nl endl #define all(v) v.begin(), v.end() #define show(v) for(int x:v) cout<<x<<" " #define input(v) for(auto &x:v) cin>>x; #define send return typedef long long int lli; typedef long long ll; void solve(){ /*int n; cin>>n; vector<int> c(n),a(n),b(n); input(c); input(a); input(b); for(int i=1;i<n;i++){ m.pb({a[i],b[i]}); } int ans = 0,ANS = 0; for(int i=1;i<=n;i++){ if(i==1){ ans += abs(a[i] - b[i]); } //else if(m[i].first == m[i].second) ANS = max(ans+c[i]-1,ANS),ans = 0; else if(i==n){ ans += c[n-1]-1; ANS = max(ans,ANS); } else{ ans += (c[i]-1) - abs(a[i] - b[i]); if(a[i] == b[i]){ ANS = max(ans,ANS); ans = 0; } } ans+=2; } cout<<ANS; int a,b,c; cin>>a>>b>>c; while(a>0 && b>0){ if(c==0) a--,c=1; else if(c == 1) b--,c=0; } if(a==0) cout<<"Aoki"; else cout<<"Takahashi";*/ int n,s,d; cin>>n>>s>>d; for(int i=0;i<n;i++){ int a,b; cin>>a>>b; if(a<s && b>d) { cout<<"Yes"; return; } } cout<<"No"; /*int n,m; cin>>n>>m; vector<pair<int,int>> h; while(m--){ int a,b; cin>>a>>b; h.pb({a,b}); } int k; cin>>k; unordered_map<int,int> f; while(k--) { int a,b; cin>>a>>b; f[a]++; f[b]++; } int cnt = 0; for(pair<int,int> p : h){ if(f[p.first] && f[p.second]) cnt++; } cout<<cnt;*/ } int main(){ //lli t; //scll(t); //while(t--){ solve(); cout<<nl; //} }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long long int ll; #define int long long #define fi(i,n) for(int i=0;i<n;i++) #define f(i, a, b) for(int i=a;i<b;i++) #define vi vector<int> #define pb push_back #define MOD 1000000007 #define pii pair<int, int> #define ff first #define ss second #define setzero(a) memset(a,0,sizeof(a)) #define prDouble(x) cout<<fixed<<setprecision(10)<<x; #define SetBits(x) __builtin_popcount(x) #define in_range(x, y, r, c) (x >= 0 && x < r && y >= 0 && y < c) ll digits(ll n) { return floor(log10(double(n))) + 1; } void faster() { ios_base::sync_with_stdio(false); cin.tie(NULL); } ll modularExponentiation(ll x,ll n,ll M) { ll result = 1; while(n>0) { if(n % 2 ==1) { result = ((result%M)*(x%M))%M; } x = ((x%M)*(x%M))%M; n = n/2; } return result%M; } bool ispower(int n) { if(n%2==1) return false; while(n>0) { if(n%2 == 1) return false; n = n/2; } return true; } int binomialCoeff(int n, int k) { int C[n + 1][k + 1]; int i, j; for (i = 0; i <= n; i++) { for (j = 0; j <= min(i, k); j++) { // Base Cases if (j == 0 || j == i) C[i][j] = 1; else C[i][j] = ((C[i - 1][j - 1])%MOD + (C[i - 1][j])%MOD)%MOD; } } return C[n][k]%MOD; } int32_t main() { int n,s,d; cin>>n>>s>>d; bool ans = false; fi(i,n) { int x,y; cin>>x>>y; if(x < s && y > d) ans = true; } if(ans) cout<<"Yes"; else cout<<"No"; }
#include <iostream> #include <cmath> using namespace std; int main() { int si,sj,score[50][50],id[50][50]; bool ok_id[2500]; cin >> si >> sj; for(int i=0;i<50;i++) { for(int j=0;j<50;j++) { cin >> id[i][j]; ok_id[i*50+j]=true; } } for(int i=0;i<50;i++) { for(int j=0;j<50;j++) { cin >> score[i][j]; } } bool move_judge[4]; while(1) { move_judge[0]=true;//U ↑ move_judge[1]=true;//D ↓ move_judge[2]=true;//L ← move_judge[3]=true;//R → if(si==0)move_judge[0]=false;//上端 if(si==49)move_judge[1]=false;//下端 if(sj==0)move_judge[2]=false;//左端 if(sj==49)move_judge[3]=false;//右端 int now_id = id[si][sj]; ok_id[now_id] = false; if(move_judge[0]) if(ok_id[id[si-1][sj]]==false) move_judge[0] = false; if(move_judge[1]) if(ok_id[id[si+1][sj]]==false) move_judge[1] = false; if(move_judge[2]) if(ok_id[id[si][sj-1]]==false) move_judge[2] = false; if(move_judge[3]) if(ok_id[id[si][sj+1]]==false) move_judge[3] = false; if(move_judge[0]){ printf("U"); si-=1; continue; }else if(move_judge[1]){ printf("D"); si+=1; continue; }else if(move_judge[2]){ printf("L"); sj-=1; continue; }else if(move_judge[3]){ printf("R"); sj+=1; continue; }else{ break; } } return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <cstring> #include <complex> #include <stack> #include <queue> #include <unordered_map> #include <map> using namespace std ; void ABC203_C(){ long long int N,K; cin >> N >> K; // 単純に記憶するだけではだめ。 // vector<int> friendPoint(1000000000000000000,0); vector<pair<long long int, long long int>> A(N); for(int i = 0; i < N; i++){ cin >> A[i].first >> A[i].second; } sort(A.begin(),A.end()); for(int i = 0; i < N; i++){ if(A[i].first > K){ break; } K += A[i].second; } cout << K << endl; } int main(int argc, const char * argv[]) { // insert code here... ABC203_C(); return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int N, M; cin >> N >> M; vector<vector<pair<int, int>>> E(N); for (int i = 0; i < M; i++){ int A, B, C; cin >> A >> B >> C; A--; B--; E[A].push_back(make_pair(C, B)); } for (int i = 0; i < N; i++){ vector<int> d(N, -1); priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; pq.push(make_pair(0, i)); while (!pq.empty()){ int dd = pq.top().first; int v = pq.top().second; pq.pop(); if (d[v] == -1){ if (dd > 0){ d[v] = dd; } for (auto P : E[v]){ int w = P.second; if (d[w] == -1){ pq.push(make_pair(dd + P.first, w)); } } } } cout << d[i] << endl; } }
#include <iostream> #include <map> #include <set> #include <vector> using namespace std; typedef long long ll; int main() { int N; ll C; cin >> N >> C; vector<int> a(N), b(N), c(N); set<int> s; map<int, ll> changes; for (int i = 0; i < N; ++i) { cin >> a[i] >> b[i] >> c[i]; // We only need a[i] and b[i]+1 to represent the final segments. // For example, [1, 4] and [3, 8] will make // [1, 2], [3, 4], [5, 8] and [9, +inf). // They can also be seen as [1, 3), [3, 5), [5, 9) and [9, +inf]. // We need 1, 3, 5, and 9 to represent these segments. s.insert(a[i]), s.insert(b[i] + 1); // We use a map to store the change of cost on each critical day. changes[a[i]] += c[i]; changes[b[i] + 1] -= c[i]; } vector<int> v(s.begin(), s.end()); int M = v.size(); ll ans = 0, acc = 0; for (int i = 0; i < M - 1; ++i) { // Deal with the starting and ending of segments. acc += changes[v[i]]; // Add to the total cost. ans += min(C, acc) * (v[i + 1] - v[i]); } cout << ans; }
#include <bits/stdc++.h> #define ll long long #define all(v) v.begin(),v.end() #define sz(s) s.size() #define PI acos(-1) using namespace std; void fast() { std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fast(); int n; cin >> n; cout << n - 1 << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; if(n<=1) cout<<"0"; else cout<<n-1; 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; if(N%2==0) cout << "White" << endl; else cout << "Black" << endl; }
#include <iostream> using namespace std; int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int n; cin>>n; if(n%2==0){ cout<<"White"<<endl; } else{ cout<<"Black"<<endl; } }
#include<bits/stdc++.h> using namespace std; #define ll long long #define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define endl "\n" #define mod 1000000007 //const ld PI = 3.141592653589793; bool isPrime(int n) { // Corner cases if(n<=3){ return true; } 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 main() { speed int n; cin>>n; cout<<n-1; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i <= n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n) using namespace std; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<ll, ll>; using Graph = vector<vector<int>>; using Edge = pair<int, ll>; const int MAX = 100000; const ll INF = 1LL << 60; int main() { // cin高速化 cin.tie(0); ios::sync_with_stdio(false); ll a; cin >> a; cout << a-1 << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define X first #define Y second #define ll long long #define ull unsigned long long #define vi vector<int> #define vl vector<ll> #define pb push_back #define mp make_pair #define pii pair<int,int> #define pll pair<ll,ll> #define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> #define pf(a) cout<<"checking-- "<<a<<endl #define pff(a,b) cout<<"Checking-- "<<a<<' '<<b<<endl #define pfff(a,b,c) cout<<"Checking-- "<<a<<' '<<b<<' '<<c<<endl #define clr(ar) memset(ar,0,sizeof(ar)) #define gP(n) (prime[n>>6]&(1<<((n>>1)&31))) #define sP(n) (prime[n>>6]=prime[n>>6]|(1<<((n>>1)&31))) #define on(val,pos) (val|(1<<pos)) #define off(val,pos) (val&(~(1<<pos))) #define check(val,pos) (val&(1<<pos)) #define invert(val,pos) (val^(1<<pos)) #define INF (ll) 1e18 #define pie (double)acos(-1.0) #define vsort(v) sort(v.begin(),v.end()) #define arsort(v,n) sort(v,v+n) #define MAX 100004 #define MOD 1000000007 vector<tuple<int,int,int>> edges; void solve(){ ll n,w; cin>>n>>w; cout<<n/w<<endl; } int main(){ int tst=1; while(tst--){ solve(); } return 0; }
#include<iostream> #include<bits/stdc++.h> #include<cmath> #include<vector> #include<iterator> #include<set> #include<queue> #include<deque> #include<stack> #include<map> #include<list> #include<algorithm> #include<sstream> #define PI acos(-1) typedef long long ll; #define V(dt) vector<dt> #define S(dt) set<dt> #define L(dt) list<dt> #define M(dt1,dt2) map<dt1,dt2> #define ST(dt) stack<dt> #define Q(dt) queue<dt> #define DQ(dt) deque<dt> #define I ::iterator #define P(dt1,dt2) pair<dt1,dt2> #define VP(dt1,dt2) vector< pair<dt1,dt2> > #define A int ii,tt; cin>>tt; for(ii=0;ii<tt;ii++) #define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); #define INTMAX 2147483647 #define INTMIN -2147483648 //int sum=0; using namespace std; int main() { int n,w; cin>>n>>w; for(int i=1;;i++){ if((i*w)==n){ cout<<i<<endl; return 0; } if((i*w)>n){ cout<<i-1<<endl; return 0; } } }
//#define DEBUG //#define OPTIMIZE //#define INTERACTIVE #include <bits/stdc++.h> using namespace std; #include <bits/extc++.h> using namespace __gnu_pbds; const int MAXN = 100; const int INF = 0x3f3f3f3f, MOD = 1000000007; const long long LINF = LONG_LONG_MAX; #define INIT(arr, val) fill(arr, arr+(int)(sizeof(arr)/sizeof(arr[0])), val) #define REP(i, lb, rb, inc) for(int i = (lb); i < (rb); i += inc) #define RREP(i, rb, lb, dec) for(int i = (rb)-1; i >= (lb); i -= dec) typedef long long ll; typedef queue<int> QI; typedef vector<int> VI; #define pb push_back typedef pair<int, int> PII; typedef pair<double, double> PDD; #define mp make_pair #define mt make_tuple #define F first #define S second #define X real() #define Y imag() #define ALL(x) x.begin(), x.end() #define OUT(x) {x; cout<<endl;} #ifdef DEBUG # define dbg(x) x #else # define dbg(x) #endif #ifdef OPTIMIZE # pragma GCC optimize("Ofast") # pragma GCC target("avx,avx2,fma") #endif #ifndef INTERACTIVE # define endl '\n' # define Foxyy cin.tie(0); cout.sync_with_stdio(0); cout.tie(0); #endif #define READ(a, t) t a; cin >> a #define READARR(arr, n) REP(___i, 0, (n), 1) cin >> arr[___i] #define PRINTARR(arr, n) REP(___i, 0, (n), 1) cout << arr[___i] << " "; cout << endl #define RI(a) READ(a, int) #define RLL(a) READ(a, ll) #define RSTR(a) READ(a, string) #define RVI(a, n) VI a(n); READARR(a, n) tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> T; signed main() { #ifndef INTERACTIVE Foxyy #endif RI(n); VI a(n); ll ans = 0; REP(i, 0, n, 1) { cin >> a[i]; ans += T.order_of_key(a[i]); T.insert(a[i]); } cout << ans << endl; REP(i, 0, n-1, 1) { ans -= a[i]; ans += n-1-a[i]; cout << ans << endl; } }
#pragma GCC target("avx2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define DEBUG #ifdef DEBUG template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; for(int i = 0; i < (int)v.size(); i++) { if(i) { os << ','; } os << v[i]; } os << '}'; return os; } void debugg() { cerr << endl; } template <class T, class... Args> void debugg(const T &x, const Args &... args) { cerr << " " << x; debugg(args...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<double> vd; typedef pair<ll,ll> P; typedef pair<int,int> pii; typedef vector<P> vpl; typedef tuple<ll,ll,ll> tapu; #define rep(i,n) for(int i=0; i<(n); i++) #define REP(i,a,b) for(int i=(a); i<(b); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const int inf = (1<<30) - 1; const ll linf = 1LL<<61; const int MAX = 510000; int dy[8] = {0,1,0,-1,1,-1,-1,1}; int dx[8] = {-1,0,1,0,1,-1,1,-1}; const double pi = 3.14159265358979; const double eps = 1e-8; template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){ if(a>b){ a = b; return true; } else return false; } template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){ if(a<=b){ a = b; return true; } else return false; } template<typename T> inline void print(T &a){ int sz = a.size(); for(auto itr = a.begin(); itr != a.end(); itr++){ cout << *itr; sz--; if(sz) cout << " "; } cout << "\n"; } template<typename T1,typename T2> inline void print2(T1 a, T2 b){ cout << a << " " << b << "\n"; } template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){ cout << a << " " << b << " " << c << "\n"; } void mark() {cout << "#" << "\n";} ll pcount(ll x) {return __builtin_popcountll(x);} const int mod = 1e9 + 7; //const int mod = 998244353; int main(){ int n; cin >> n; string s; cin >> s; if(s[0] == s.back()){ for(int i=1; i<n-1; i++){ if(s[i] != s[0] && s[i+1] != s[0]){ cout << 2 << endl; return 0; } } cout << -1 << endl; }else{ cout << 1 << endl; } }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstring> #include <deque> #include <forward_list> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef bitset<16> BS; struct edge { int to, cost, id; }; const double EPS = 1E-09; const ll MOD = 1E+09 + 7; // =998244353; const ll INF = 1E18; const int MAX_N = 1E+05; ll dx[4] = { -1, 1, 0, 0 }, dy[4] = { 0, 0, -1, 1 }; ll M; string X; bool f(ll n); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> X >> M; ll d = 0; for (auto x : X) { d = max(d, (ll)(x - '0')); } //reverse(X.begin(), X.end()); ll high = M + 1, low = 0; ll ans = 0; //ll high = (ll)(pow((double)M / (double)(X[X.size() - 1]), 1.0 / ((double)X.size() - 1.0))) + 100 if (X.size() > 1) { while (true) { ll mid = (high + low) / 2; if (mid == high || mid == low) break; if (f(mid)) { high = mid; } else { low = mid; } //cout << "high = " << high << ", low = " << low << "\n"; } } else { if (X[0] - '0' <= M) ans = 1; } /* for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n"; } } */ cout << (X.size() == 1 ? ans : max(0LL, low - d)) << "\n"; return 0; } bool f(ll n) { ll res = 0; for (auto c : X) { ll x = c - '0'; if (res > M / n) return true; res = res * n + x; } //cout << "n = " << n << ", res = " << res << "\n"; return res > M; } // bool f(ll n) // { // vector<ll> res; // ll m = M; // while (m > 0) { // res.push_back(m % n); // m /= n; // } // // cout << "n = " << n << "\n"; // // cout << "Xsize = " << X.size() << ", res.size = " << res.size() << "\n"; // if (res.size() != X.size()) // return X.size() > res.size(); // reverse(res.begin(), res.end()); // for (int i = 0; i < X.size(); i++) { // ll x = X[i] - '0'; // if (x > res[i]) // return true; // else if (x < res[i]) // return false; // } // return false; // }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <utility> #include <set> #include <map> #include <cmath> #include <queue> #include <cstdio> #include <limits> #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) using namespace std; 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; } template<class T> inline int sz(T &a) { return a.size(); } using ll = long long; using ld = long double; using pi = pair<int,int>; using pl = pair<ll,ll>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; const int inf = numeric_limits<int>::max(); const ll infll = numeric_limits<ll>::max(); int main() { string s; cin >> s; ll m; cin >> m; int n = sz(s); ll mx = 0; rep(i,n) { ll tmp = s[i] - '0'; chmax(mx, tmp); } if(n == 1) { if(mx <= m) cout << 1 << "\n"; else cout << 0 << "\n"; return 0; } ll lb = mx, ub = 1000000000000000001; ll an = s[0] - '0'; while(ub - lb > 1) { ll B = (ub + lb) / 2; // cout << B << "\n"; ll x = an; int cnt = 0; while(x <= m/B) { x *= B; // cout << x << "\n"; cnt++; if(cnt == n-1) break; } if(cnt==n-1) { ll sum = 0; ll buf = 1; for(int j = n-1; j >= 1; --j) { ll tmp = s[j] - '0'; sum += tmp * buf; buf *= B; } if(an*buf <= m - sum) { lb = B; } else ub = B; } else ub = B; } cout << lb-mx << "\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> #include <array> #include <chrono> //#pragma GCC target("arch=skylake-avx512") #pragma GCC target("avx2") //#pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC target("sse4") #pragma GCC optimize("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()) #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)) 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; } //cpp_int #if __has_include(<boost/multiprecision/cpp_int.hpp>) #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> using namespace boost::multiprecision; #else using cpp_int = ll; #endif //atcoder library #if __has_include(<atcoder/all>) #include <atcoder/all> //using namespace atcoder; #endif /* random_device seed_gen; mt19937 engine(seed_gen()); uniform_int_distribution dist(1, 100); */ /*----------------------------------------------------------------------------------*/ int main() { ll n; scanf("%lld", &n); ll a = 0, b = 62, c = 0, d = (1ll << 62ll), ans = n; while (n < d) { d >>= 1; --b; } do { a = n / d; c = n - a * d; chmin(ans, a + b + c); d >>= 1; } while (b--); printf("%lld\n", ans); Please AC; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second ll inf = 1ll << 60; int main(){ ll n; cin >> n; ll ans = inf; for (int i = 0; i < 61; i++){ ll p = 1ll << i; ll a = n / p, b = n % p; ans = min(ans, a + b + i); } cout << ans; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i=0; i<n; ++i) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using ll = int64_t; using ull = uint64_t; using ld = long double; using P = pair<int, int>; using vs = vector<string>; using vi = vector<int>; using vvi = vector<vi>; template<class T> using PQ = priority_queue<T>; template<class T> using PQG = priority_queue<T, vector<T>, greater<T>>; const int INF = 0xccccccc; const ll LINF = 0xcccccccccccccccLL; template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;} template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;} char str[] = "UNSATISFIABLE"; //head int main() { ios::sync_with_stdio(false); cin.tie(0); int a, b, w; cin >> a >> b >> w; w *= 1000; int l = 0, r = 0; int cnt = 0; int mi = INF, ma = 0; while(l <= w) { if(w <= r) { chmin(mi, cnt); chmax(ma, cnt); } l += a; r += b; cnt++; } if(mi == INF) puts(str); else cout << P(mi, ma) << endl; }
#include <iostream> #include <string> #include <algorithm> #include <math.h> using namespace std; int main(){ long long A,B,C,D; cin>>A>>B>>C>>D; long long sum=A+B+C+D; if(A==sum-A||B==sum-B||C==sum-C||D==sum-D||A+B==C+D||A+C==B+D||A+D==B+C){ cout<<"Yes"<<endl; } else cout<<"No"<<endl; return 0; }
#include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <cstdlib> #include <set> #include <time.h> #include <sstream> #include <queue> using namespace std; using ll=long long; void print(int *some_list,int many){ cout << "["; for (int i=0;i<many;i++){ cout << some_list[i] << ", "; } cout << "]" << " 要素数:" << many << endl; } string bit(int a,int base=2){ int b; string s=""; for(int i=0;a>0;i++){ b=a%base; a-=b; a/=base; char num='0'+b; s.push_back(num); } reverse(s.begin(),s.end()); return s; } int main(){ ll ans=0,n; cin >> n; for(int i=0;i<n;i++){ ll many; cin >> many; if(many>10) ans+=many-10; } cout << ans << endl; }
#include <bits/stdc++.h> #include <string> using namespace std; #define ll long long int #define ld long double #define pb push_back #define mp make_pair #define fi first #define se second #define mod 1000000007 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define fr(i,a,n) for(i=a;i<n;i++) #define frn(i,a,n) for(i=a;i<=n;i++) #define vll vector<ll> #define pll pair<ll,ll> #define vp vector<pll> #define ub upper_bound #define lb lower_bound #define mem(x,y) memset(x,y,sizeof(x)) #define all(v) v.begin(),v.end() #define qll queue<ll> #define sll set<ll> //(a/b)%mod = (a%mod*powermod(b,mod-2,mod))%mod ll power(ll x,ll n) { if(n==0) return 1; else if(n%2 == 0) //n is even return power(x*x,n/2); else //n is odd return x*power(x*x,(n-1)/2); } int highestPowerof2(int n) { int p = (int)log2(n); return (int)pow(2, p); } ll powermod(ll x, ll y, ll p) { ll res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; } vector<string>s(70); ll n; ll dp[70][70]; ll trav(ll i,bool x,bool prev){ if(i==n && prev) return 1; if(i==n) return 0; if(dp[i][prev]!=-1) return dp[i][prev]; if(s[i]=="AND"){ return dp[i][prev]=trav(i+1,true,prev&true)+trav(i+1,false,prev&false); } else{ return dp[i][prev]=trav(i+1,true,prev|true)+trav(i+1,false,prev|false); } } int main(){ memset(dp,-1,sizeof(dp)); cin>>n; for(ll i=0;i<n;i++) cin>>s[i]; ll sum=trav(0,true,true); memset(dp,-1,sizeof(dp)); sum+=trav(0,false,false); cout<<sum<<endl; return 0; }
#include <iostream> using namespace std; int main() { float N; cin >> N; if ((int)(N * 1.08) < 206) cout << "Yay!"; else if ((int)(N * 1.08) == 206) cout << "so-so"; else cout << ":("; }
/* * @author: 0x404 * @Date: 2021-02-20 19:56:33 * @LastEditTime: 2021-02-20 20:02:58 * @Description: */ #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; int x; int main(){ cin >> x; if(x % 100 == 0) cout << 100 << endl; else { for(int i = 1; i <= 100000; i++){ if((x + i) % 100 == 0){ cout << i << endl; return 0; } } } return 0; }
#include<bits/stdc++.h> #define M 1005 typedef long long ll; using namespace std; int stp[M][M][27]; int n,m; vector<int> E[M][26]; struct node{int x,y,c;}; queue<node> Q; int BFS(){ int x,y,c; while(!Q.empty()){ x=Q.front().x; y=Q.front().y; c=Q.front().c; if((c==26)&&((x==1&&y==n)||(x==n&&y==1)))return stp[x][y][26]; Q.pop(); if(c==26){ for(int i=0;i<26;++i) for(int j=0,z;j<E[x][i].size();++j){ if(~stp[z=E[x][i][j]][y][i])continue; stp[z][y][i]=stp[x][y][c]+1; Q.push((node){z,y,i}); } }else{ for(int j=0,z;j<E[y][c].size();++j){ if(~stp[x][z=E[y][c][j]][26])continue; stp[x][z][26]=stp[x][y][c]+1; Q.push((node){x,z,26}); } } } return -1; } int main(){ cin>>n>>m; memset(stp,-1,sizeof(stp)); for(int i=1;i<=n;++i){ stp[i][i][26]=0; Q.push((node){i,i,26}); } int u,v;char c[5]; for(int i=1;i<=m;++i){ scanf("%d%d%s",&u,&v,c); if(u>v)swap(u,v); E[u][c[0]-'a'].push_back(v); E[v][c[0]-'a'].push_back(u); if(u==v)continue; stp[u][v][26]=1; stp[v][u][26]=1; Q.push((node){u,v,26}); Q.push((node){v,u,26}); } cout<<BFS(); return 0; }
// // Created by yamunaku on 2021/03/27. // #include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define rep(i, n) for(int i = 0; i < (n); i++) #define repl(i, l, r) for(int i = (l); i < (r); i++) #define per(i, n) for(int i = ((n)-1); i >= 0; i--) #define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--) #define all(x) (x).begin(),(x).end() #define MOD9 998244353 #define MOD1 1000000007 #define IINF 1000000000 #define LINF 1000000000000000000 #define SP <<" "<< #define CYES cout<<"Yes"<<endl #define CNO cout<<"No"<<endl #define CFS cin.tie(0);ios::sync_with_stdio(false) #define CST(x) cout<<fixed<<setprecision(x) using ll = long long; using ld = long double; using vi = vector<int>; using mti = vector<vector<int>>; using vl = vector<ll>; using mtl = vector<vector<ll>>; using pi = pair<int, int>; using pl = pair<ll, ll>; template<typename T> using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>; int main() { //CFS; int n, m; cin >> n >> m; vector<vector<vector<int>>> e(n, mti(26)); priority_queue<pair<int, pair<int, int>>> q; rep(i, n) q.push({0, {i, i}}); rep(i, m) { int a, b; char c; cin >> a >> b >> c; a--, b--; c -= 'a'; e[a][c].push_back(b); e[b][c].push_back(a); q.push({-1, {a, b}}); q.push({-1, {b, a}}); } mti len(n, vi(n, IINF)); while (!q.empty()) { auto now = q.top(); q.pop(); int x = now.second.first, y = now.second.second; if (len[x][y] != IINF) continue; len[x][y] = -now.first; rep(i, 26) { for (auto &nx : e[x][i]) { for (auto &ny : e[y][i]) { if (len[nx][ny] != IINF) continue; q.push({-len[x][y] - 2, {nx, ny}}); } } } } if (len[0][n - 1] != IINF) cout << len[0][n - 1] << endl; else cout << -1 << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = int64_t; using LL = uint64_t; typedef vector<ll>VI; typedef pair<ll,ll>P; #define VV(T) vector<vector<T>> #define sz(x) int(x.size()) #define rep(i, n) for (int i = 0; i < (int)n; i++) #define ALL(a) (a).begin(),(a).end() #define rALL(a) (a).rbegin(),(a).rend() #define c_max(a,b) (((ll)a)>((ll)b)?(a):(b)) #define c_min(a,b) (((ll)a)<((ll)b)?(a):(b)) #define vmax(v) *max_element(ALL(v)) #define vmin(v) *min_element(ALL(v)) #define $(x) {cout<<#x<<" = " <<(x)<<endl;} #define fi first #define se second #define MAX 100100 #define MAX6 1001001 #define MAX7 10010010 #define INF 1<<30 #define INFTY 1LL<<61 #define MAX_INT INT_MAX #define MAX_LL LLONG_MAX #define CLR(mat) memset(mat, 0, sizeof(mat)) template<class T, class U> inline bool chmax(T& a, U b) { if (a < b) { a = b; return 1; } return 0; } template<class T, class U> inline bool chmin(T& a, U b) { if (a > b) { a = b; return 1; } return 0; } #define MOD 1000000007 //const ll inf=1e18; //const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; // vector型から重複を削除 list.erase(unique(ALL(list)),list.end()); // g++ -o a a.cpp -Wall -lm -std=c++17 //push_back -> emplace_back int main(){ ll N; cin>>N; int B=0; VI vec; for(ll b=5;b<N;b*=5){ B++; ll x=N-b; vec.emplace_back(x); } VI three; for(ll a=3;a<N;a*=3){ three.emplace_back(a); } for(int i=0;i<sz(vec);i++){ if(binary_search(ALL(three), vec[i])){ cout<<distance(three.begin(), lower_bound(ALL(three), vec[i]))+1<<" "<<i+1<<endl; return 0; } } cout<<-1<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long N,M; cin >> N; long long n3 = 1; long long n5; for (int i=1; i<100; i++) { n3 *= 3ll; M = N-n3; n5 = 1; if (M <= 1) { cout << -1 << endl; return 0; } for (int j=1; j<100; j++) { n5 *= 5; if (n5 > M) { break; } if (n5 == M) { cout << i << " " << j << endl; return 0; } } } return 0; }
#include<bits/stdc++.h> //#include<atcoder/all> using namespace std; //using namespace atcoder; int main() { long long N; cin>>N; long long A[N]; long long B[N]; for(int i=0;i<N;i++){ cin>>A[i]; } for(int i=0;i<N;i++){ cin>>B[i]; } long long AB[N]; for(int i=0;i<N;i++){ AB[i]=A[i]-B[i]; } pair<long long,int> g[N/2],k[N/2]; for(int i=0;i<N/2;i++){ g[i]=make_pair(AB[i*2],i*2); } for(int i=0;i<N/2;i++){ k[i]=make_pair(AB[i*2+1],i*2+1); } sort(g,g+N/2); sort(k,k+N/2); long long ans=0; for(int i=0;i<N/2;i++){ if(g[i].first+k[i].first<0){ ans+=B[g[i].second]+B[k[i].second]; } else{ ans+=A[g[i].second]+A[k[i].second]; } } cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; template<typename T>inline T read(){ T x=0,f=0;char c=getchar(); while(!isdigit(c)) f=c=='-',c=getchar(); while(isdigit(c)) x=x*10+c-48,c=getchar(); return f?-x:x; } #define int long long namespace run{ const int N=1e5+9; int n,a[N],b[N],ans; priority_queue<int> pq[2]; int main(){ n=read<int>(); for(int i=1;i<=n;i++) ans+=(a[i]=read<int>()); for(int i=1;i<=n;i++) b[i]=read<int>(); for(int i=1;i<=n;i++) pq[i&1].push(b[i]-a[i]); while(!pq[0].empty() && !pq[1].empty() && pq[0].top()+pq[1].top()>0){ ans+=pq[0].top()+pq[1].top(); pq[0].pop(),pq[1].pop(); } printf("%lld\n",ans); return 0; } } #undef int int main(){ #ifdef my freopen(".in","r",stdin); freopen(".out","w",stdout); #endif return run::main(); }
#define LOCAL #define _USE_MATH_DEFINES #include <array> #include <cassert> #include <cstdio> #include <cstring> #include <iostream> #include <iomanip> #include <string> #include <sstream> #include <vector> #include <queue> #include <stack> #include <list> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <algorithm> #include <complex> #include <cmath> #include <numeric> #include <bitset> #include <functional> #include <random> #include <ctime> using namespace std; template <typename A, typename B> ostream& operator <<(ostream& out, const pair<A, B>& a) { out << "(" << a.first << "," << a.second << ")"; return out; } template <typename T, size_t N> ostream& operator <<(ostream& out, const array<T, N>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; } template <typename T> ostream& operator <<(ostream& out, const vector<T>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; } template <typename T, class Cmp> ostream& operator <<(ostream& out, const set<T, Cmp>& a) { out << "{"; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}"; return out; } template <typename U, typename T, class Cmp> ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) { out << "{"; bool first = true; for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}"; return out; } #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) 42 #endif template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); } typedef long long int64; typedef pair<int, int> ii; #define SZ(x) (int)((x).size()) const int INF = 1 << 29; const int MOD = 1e9 + 7; mt19937 mrand(random_device{}()); int rnd(int x) { return mrand() % x; } struct fast_ios { fast_ios() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); }; } fast_ios_; int main() { int n, m, cntA, cntB; cin >> n >> m >> cntA >> cntB; vector<vector<int>> a(n, vector<int>(m)); vector<vector<int>> dp(n, vector<int>(m)); for (int i = 0; i < cntA; ++i) { int x, y; cin >> x >> y; --x; --y; a[x][y] = 1; } vector<vector<bool>> b(n, vector<bool>(m)); for (int i = 0; i < cntB; ++i) { int x, y; cin >> x >> y; --x; --y; b[x][y] = true; } for (int i = 0; i < n; ++i) { int cur = 0; for (int j = 0; j < m; ++j) { if (b[i][j]) { cur = 0; } else { cur += a[i][j]; dp[i][j] += cur; } } cur = 0; for (int j = m - 1; j >= 0; --j) { if (b[i][j]) { cur = 0; } else { cur += a[i][j]; dp[i][j] += cur; } } } for (int j = 0; j < m; ++j) { int cur = 0; for (int i = 0; i < n; ++i) { if (b[i][j]) { cur = 0; } else { cur += a[i][j]; dp[i][j] += cur; } } cur = 0; for (int i = n - 1; i >= 0; --i) { if (b[i][j]) { cur = 0; } else { cur += a[i][j]; dp[i][j] += cur; } } } int ret = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (b[i][j]) continue; ret += dp[i][j] > 0; } } cout << ret << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; long long C; cin >> n >> C; vector<int> a(n), b(n), c(n); for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i]; map<int, vector<int>> mp; for (int i = 0; i < n; i++) { mp[a[i]].push_back(c[i]); mp[b[i] + 1].push_back(-c[i]); } int last = 0; long long ans = 0, cur_cost = 0; for (auto &[k, v] : mp) { ans += min(C, cur_cost) * (k - last); for (auto &x : v) { cur_cost += x; } last = k; } cout << ans << '\n'; return 0; }
//#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; //vector string deque break continue #define forn(i, s, f) for (int i = (int)s; i < (int)f; i++) #define ll long long #define ull unsigned long long #define ld long double #define pii pair <int, int> #define fs first #define sc second #define pf push_front #define pb push_back #define pop_f pop_front #define pop_b pop_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() #ifdef DEBUG #else #define cerr if (false) cerr #endif template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;} template <typename T> ostream& operator<<(ostream& out, vector <T>& a) {for (auto& i : a) out << i << " "; return out;} template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;} template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;} int main() { ios_base::sync_with_stdio(0), cin.tie(0); vector<int> a(3); cin >> a; sort(all(a)); cout << a[1] + a[2] << "\n"; return 0; }
// #include <bits/stdc++.h> #include <math.h> #include <algorithm> using namespace std; int main() { int A, B, C, ans = 0; cin >> A >> B >> C; if(A > B) { if(B > C) { ans += B + A; } else { ans += C + A; } } else { if(A > C) { ans += B + A; } else { ans += B + C; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using P = pair<int, int>; using PP = pair<int, P>; const int N = 30; int T = 0; int cost[N][N][N][N]; int updated_time[N][N][N][N]; int updates[N][N][N][N]; int visited[N][N][N][N]; char dir(int dx, int dy) { if (dx == 0) { if (dy > 0) return 'R'; else return 'L'; } else { if (dx > 0) return 'D'; else return 'U'; } } pair<vector<P>, string> shortestPath(int sx, int sy, int tx, int ty) { vector<vector<int>> dist(N, vector<int>(N, 10000000)); vector<vector<P>> prev(N, vector<P>(N)); dist[sx][sy] = 0; priority_queue<PP, vector<PP>, greater<PP>> q; q.emplace(PP(0, P(sx, sy))); vector<int> dx = {-1, 1, 0, 0}; vector<int> dy = {0, 0, -1, 1}; while (!q.empty()) { PP p = q.top(); q.pop(); int d = p.first; int x = p.second.first; int y = p.second.second; if (d > dist[x][y]) continue; for (int i = 0; i < 4; i++) { int nx = x + dx[i]; int ny = y + dy[i]; if (nx < 0 || nx >= N || ny < 0 || ny >= N) continue; d = cost[x][y][nx][ny]; if (T < 250) { // if (T < 10 && ((x + y + T) & 1)) d = 10000; if (visited[x][y][nx][ny]) d = 10000; } if (dist[nx][ny] > dist[x][y] + d) { dist[nx][ny] = dist[x][y] + d; prev[nx][ny] = P(x, y); q.push(PP(dist[nx][ny], P(nx, ny))); } } } vector<P> res; string out; int x, y; x = tx; y = ty; while (x != sx || y != sy) { res.push_back(P(x, y)); int px, py; P prv = prev[x][y]; px = prv.first; py = prv.second; visited[x][y][px][py] = 1; visited[px][py][x][y] = 1; // for (int i = 0; i < 4; i++) { // int nx = x + dx[i]; // int ny = y + dy[i]; // if (nx < 0 || nx >= N || ny < 0 || ny >= N) continue; // visited[x][y][nx][ny] = 1; // visited[nx][ny][x][y] = 1; // visited[px][py][nx][ny] = 1; // visited[nx][ny][px][py] = 1; // } out += dir(x - px, y - py); x = px; y = py; } res.push_back(P(sx, sy)); reverse(out.begin(), out.end()); return pair<vector<P>, string>(res, out); } void updateCost(vector<P> v, int dist) { for (int i = 0; i < (int)v.size() - 1; i++) { int x = v[i].first; int y = v[i].second; int nx = v[i + 1].first; int ny = v[i + 1].second; int up = updates[x][y][nx][ny]; double r = 1.0 / (1 + up) + (1 - 1.0 / (up + 1)) / (1 + exp(v.size() - 2)); cost[x][y][nx][ny] = (int)(cost[x][y][nx][ny] * (1 - r) + dist * r); cost[nx][ny][x][y] = cost[x][y][nx][ny]; updates[x][y][nx][ny]++; updated_time[x][y][nx][ny] = T; } } int main() { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) { for (int l = 0; l < N; l++) { cost[i][j][k][l] = 5000; } } } } while (T < 1000) { int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty; auto [vertices, path] = shortestPath(sx, sy, tx, ty); cout << path << endl << flush; int dist; cin >> dist; updateCost(vertices, dist / (vertices.size() - 1)); T++; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<int> vz; typedef vector<vz> vvz; typedef pair<ll, ll> pll; #define sz(x) ll((x).size()) #define fo(i,n) for(ll i=0; i<(n); i++) #define FO(i,a,b) for(ll i=(a); i!=(b); i+=(b)>(a)?1:-1) #define pb push_back #define lb lower_bound #define ub upper_bound #define all(c) c.begin(), c.end() #define F first #define S second #define os(x) cout<<x<<' ' #define on(x) cout<<x<<"\n" #define nl cout<<"\n" #define maxe(x) max_element(all(x))-(x).begin() #define mine(x) min_element(all(x))-(x).begin() const ll P=998244353; int main() { ios::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("C:\\Users\\ASISH\\Desktop\\coding\\input1.txt", "r", stdin); freopen("C:\\Users\\ASISH\\Desktop\\coding\\output1.txt", "w", stdout); #endif ll h, k, x, y, ans; cin>>h>>k>>x>>y; x=x-h, y=y-k, h=0, k=0; if(x==0 && y==0) ans=0; else if(abs(x)+abs(y)<=3 || abs(x)==abs(y)) ans=1; else if((y>=x-3 && y<=x+3) || (y>=-x-3 && y<=-x+3)) ans=2; else{ if((x+y)%2) ans=3; else ans=2; } on(ans); cerr << "Time : " << ((double)clock()) / (double)CLOCKS_PER_SEC << "s\n"; return 0; }
#include <iostream> #include <sstream> #include <string> #include <list> #include <vector> #include <queue> #include <algorithm> #include <climits> #include <cstring> #include <cmath> #include <stack> #include <iomanip> #include <tuple> #include <functional> #include <cfloat> #include <map> #include <set> #include <array> #include <stdio.h> #include <string.h> #include <random> #include <cassert> using ll = long long; using ull = unsigned long long; using uint = unsigned int; using namespace std; #define int long long #define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end()) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ARY_SORT(a, size) sort((a), (a)+(size)) #define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end())) #define REVERSE(v) (reverse((v).begin(), (v).end())) #define ARY_REVERSE(v,a) (reverse((v), (v)+(a))) #define REP(i, n) for (int (i)=0; (i) < (n); (i)++) #define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++) #define CONTAINS_MAP(m, a) ((m).find((a)) != m.end()) #define CONTAINS_SET(m, a) ((m).find((a)) != m.end()) void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } int N, X; int A[101]; int memo[101][101]; int func(int target) { REP(i, 101) REP(j, 101) memo[i][j] = -1; memo[0][0] = 0; for (int n = 0; n < N; n++) { for (int i = target; i >= 1; i--) { for (int j = 0; j < target; j++) { if (memo[i - 1][j] >= 0) { int val = memo[i - 1][j] + A[n]; int new_m = (X - val) % target; memo[i][new_m] = max(memo[i][new_m], val); } } } } if (memo[target][0] < 0) return LLONG_MAX; int check = (X - memo[target][0]) % target; int wait = (X - memo[target][0]) / target; return wait; } signed main() { cin >> N >> X; REP(i, N) cin >> A[i]; int ans = LLONG_MAX; for (int i = 1; i <= N; i++) { ans = min(ans, func(i)); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin>> #define ll long long #define ln cout<<'\n' #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n",a) #define mem(a) memset(a,0,sizeof(a)) #define all(c) (c).begin(),(c).end() #define iter(c) __typeof((c).begin()) #define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++) ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;} template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);} template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;} const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1}; typedef pair<ll,ll> P; void Main() { ll n,T; R n; P a[n]; rep(i,n) cin >> a[i].F >> a[i].S; ll Mi=-MAXL,Ma=MAXL; { rep(i,n) { if(a[i].S==1) Mi+=a[i].F; if(a[i].S==2) Mi=max(Mi,a[i].F); if(a[i].S==3) Mi=min(Mi,a[i].F); } rep(i,n) { if(a[i].S==1) Ma+=a[i].F; if(a[i].S==2) Ma=max(Ma,a[i].F); if(a[i].S==3) Ma=min(Ma,a[i].F); } } ll l=-MAXL,r=MAXL; while(l+1<r) { ll m=(l+r)/2; ll x=m; rep(i,n) { if(a[i].S==1) x+=a[i].F; if(a[i].S==2) x=max(x,a[i].F); if(a[i].S==3) x=min(x,a[i].F); } if(x<=Mi) l=m; else r=m; } ll z=l; R T; while(T--) { ll x; R x; if(x<z) pr(Mi); else pr(min(Ma,x-z+Mi)); } } int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
#include <bits/stdc++.h> using namespace std; using namespace chrono; typedef int64_t ll; typedef long double ld; typedef unsigned long long ULL; #define endl "\n" #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define pb push_back void read(vector<int> &a) {for (auto &x : a)cin >> x;} void read(vector<ll> &a) {for (auto &x : a)cin >> x;} mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c> {i, j}; } sim > auto dud(c * x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifndef ONLINE_JUDGE ~debug() { cerr << endl; } eni( != ) cerr << boolalpha << i; ris; } eni( == ) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " const int MOD = 1e9 + 7; const int INF = (int)2e9 + 7; const ll LINF = (ll)1e18; const ld PI = 3.1415926535897932384626433832795; void solve() { int a, b, c; cin >> a >> b >> c; if (a == b) { cout << "="; } else if (abs(a) == abs(b)) { if (c % 2 == 0) { cout << "="; } else if (a > 0 && b < 0) { cout << ">"; } else if (b > 0 && a < 0) { cout << "<"; } else { assert(false); } } else if (a == 0 || b == 0) { if (a == 0 && b == 0) { cout << "="; } else if (a == 0) { if (b > 0) { cout << "<"; } else if (b < 0 && c % 2 == 0) { cout << "<"; } else { cout << ">"; } } else { if (a > 0) { cout << ">"; } else if (a < 0 && c % 2 == 0) { cout << ">"; } else { cout << "<"; } } } else if (a < 0 && b < 0) { if (c % 2 == 0) { if (abs(a) < abs(b)) { cout << "<"; } else { cout << ">"; } } else if (a < b) { cout << "<"; } else { cout << ">"; } } else if (a > 0 && b > 0) { if (a < b) { cout << "<"; } else { cout << ">"; } } else if (a < 0 && b > 0) { if (c % 2 == 0) { if (abs(a) > abs(b)) { cout << ">"; } else { cout << "<"; } } else { cout << "<"; } } else if (a > 0 && b < 0) { if (c % 2 == 0) { if (abs(a) > abs(b)) { cout << ">"; } else { cout << "<"; } } else { cout << ">"; } } } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; //cin >> t; auto t1 = high_resolution_clock::now(); for (int tt = 1; tt <= t; tt++) { //cout << "Case #" << tt << ": "; solve(); } auto t2 = high_resolution_clock::now(); auto time = duration_cast<duration<double>>(t2 - t1); cerr << "Time elapsed = " << time.count() << endl; }
/*{{{*/ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<iostream> #include<sstream> #include<set> #include<map> #include<queue> #include<bitset> #include<vector> #include<limits.h> #include<assert.h> #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define FOR(I, A, B) for (int I = (A); I <= (B); ++I) #define FORS(I, S) for (int I = 0; S[I]; ++I) #define RS(X) scanf("%s", (X)) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++) #define MP make_pair #define PB emplace_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PII> VPII; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template<class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const int64_t &x) { printf("%lld", x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);} template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } #ifdef HOME #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);} #else #define DEBUG(...) #endif int MOD = 1e9+7; void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;} /*}}}*/ const int SIZE = 1<<20; int N; int a[SIZE]; int b[SIZE]; int p[SIZE]; int from[SIZE]; void solve() { VPII AA; FOR(i,1,N){ if(p[i] != i && a[i] <= b[p[i]]) { W(-1); return; } AA.PB(MP(b[p[i]],p[i])); } sort(ALL(AA),greater<PII>()); VPII an; REP(i,SZ(AA)){ int x=AA[i].S; if(x==p[x])continue; int y=from[x]; an.PB(MP(x,y)); swap(p[x],p[y]); from[p[x]]=x; from[p[y]]=y; } W(SZ(an)); for(auto x: an) { W(x); } } void input() { R(N); FOR(i,1,N)R(a[i]); FOR(i,1,N)R(b[i]); FOR(i,1,N){ R(p[i]); from[p[i]]=i; } } int main(){ input(); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define REP(i,n) for(ll i=0;i<(n);i++) #define FOR(i,a,b) for(ll i=(a);i<(b);i++) #define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c)) #define pb(x) push_back(x) #define mp(x,y) make_pair(x,y) #define ff first #define ss second #define dd long double #define all(x) x.begin(),x.end() template<ll MOD = 998244353> struct mint{ ll x; ll mod = MOD; mint(ll x=0):x(x%MOD){} mint& operator+=(const mint a){ if((x+=a.x)>=MOD) x-=MOD; return *this; } mint& operator-=(const mint a){ if((x += MOD-a.x)>=MOD) x-=MOD; return *this; } mint& operator*=(const mint a){ (x*=a.x)%=MOD; return *this; } mint operator+(const mint a) const{ mint res(*this); return res+=a; } mint operator-(const mint a) const{ mint res(*this); return res-=a; } mint operator*(const mint a) const{ mint res(*this); return res*=a; } mint power(ll t) const{ if(!t) return 1; mint a = power(t>>1); a*=a; if(t&1) a*=*this; return a; } mint inv() const{ return power(MOD-2); } mint& operator/=(const mint a){ return (*this) *= a.inv(); } mint operator/(const mint a) const{ mint res(*this); return res/=a; } }; template<ll mod> ostream & operator << (ostream & output,const mint<mod> & a){ output<<a.x; return output; } template<ll mod> istream & operator >> (istream & input, mint<mod>& a){ input>>a.x; return input; } using mll=mint<>; const ll N=1e6; mll fact[N+1]; mll ifact[N+1]; void init(){ fact[0]=fact[1]=1; FOR(i,2,N+1){ fact[i]=fact[i-1]*i; } ifact[0]=1; ifact[1]=1; ifact[1]/=1; FOR(i,2,N+1){ ifact[i]=1; ifact[i]/=i; ifact[i]*=ifact[i-1]; } } mll pnc(ll n, ll r){ mll a=fact[n]; a*=ifact[r]; a*=ifact[n-r]; return a; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); init(); ll n,m,k; cin>>n>>m>>k; mll ans=0; if(n==1 || m==1){ ans+=mll(k).power(n*m); cout<<ans<<endl; return 0; } for(ll i=1;i<=k;i++){ mll temp=mll(i).power(n); temp-=mll(i-1).power(n); temp*=mll(k-i+1).power(m); ans+=temp; } cout<<ans<<endl; }
#include<iostream> #include<vector> #include<algorithm> using namespace std; long long p=998244353; long long BinaryExpo(long long a,long long b) { a=a%p; long long res=1; while(b>0) { if(b&1) res=(res*a)%p; b=b>>1; a=(a*a)%p; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long n,m,k; cin>>n>>m>>k; if(n>=2 && m>=2) { long long ans=0; long long prv=0,curr=0; for(int i=1;i<=k;i++) { curr=BinaryExpo(i,n); long long x=(curr-prv+p)%p,y=BinaryExpo(k-i+1,m); x=(x*y)%p; ans=(ans+x)%p; prv=curr; } cout<<ans<<"\n"; return 0; } if(n==1 && m==1) { cout<<k<<"\n"; return 0; } n=max(n,m); cout<<BinaryExpo(k,n)<<"\n"; }
#include<bits/stdc++.h> #define For(i,l,r) for(int i=(l);i<=(r);i++) #define ReFor(i,r,l) for(int i=(r);i>=(l);i--) const int MAXN=1010; using namespace std; int n,ans; struct llz { int x,y; }a[MAXN]; inline int read() { int f=1,x=0; char ch=getchar(); while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9') { x=(x<<3)+(x<<1)+ch-'0'; ch=getchar(); } return f*x; } int main() { n=read(); For(i,1,n) { a[i].x=read(); a[i].y=read(); } For(i,1,n-1) { For(j,i+1,n) { if(abs(a[j].y-a[i].y)<=abs(a[j].x-a[i].x)) ans++; } } printf("%d",ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define yes cout <<"YES"<<endl #define no cout <<"NO"<<endl #define sortv(a) sort(a.begin(), a.end()) typedef vector <long long> vi; typedef string str; typedef vector <pair<long long, long long>> vip; typedef pair <int, int> pi; typedef set <int> si; typedef vector <double> vd; bool isPrime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 or n % 3 == 0) return false; for (int i = 5; i * i <= n; i += 6) { if (n % i == 0 or n % (i + 2) == 0) return false; } return true; } bool sortbysec(const pair<long long, long long> &a, const pair<long long, long long> &b) { return (a.second > b.second); } bool isPalindromic(string s) { for (int i = 0; i < s.size(); ++i) { if (s[i] != s[s.size() - i - 1]) { return false; } } return true; } void solve() { ll n; cin >>n; vi x(n), y(n); for (int i = 0; i < n; ++i) { cin >>x[i]>>y[i]; } ll cnt = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < i; ++j) { double s = (double)(y[j] - y[i]) / (double)(x[j] - x[i]); if (s <= 1 and s >= -1) { cnt++; } } } cout <<cnt<<endl; } int main() { solve(); }
#include<iostream> #include<iomanip> #include<bitset> #include<algorithm> #include<string> #include<vector> #include<cstdio> #include<cmath> #include<queue> #include<map> #include<set> using namespace std; using ll=long long; int main(){ int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; if(r1 == r2 && c1 == c2){ cout << 0 << endl; return 0; } if(r1 - c1 == r2 -c2 || r1 + c1 == r2 + c2 || abs(r1 - r2) + abs(c1 - c2) <= 3){ cout << 1 << endl; return 0; } if((abs(r1 - r2) + abs(c1 - c2)) % 2 == 0){ cout << 2 << endl; return 0; } for(int i = -2; i <= 2; i++){ for(int j = -2; j <= 2; j++){ int r, c; r = r1 + i; c = c1 + j; if(r - c == r2 - c2 || r + c == r2 + c2 || abs(r - r2) + abs(c - c2) <= 3){ cout << 2 << endl; return 0; } } } vector<int> x = {3, 0, -3, 0}, y = {0, 3, 0, -3}; for(int i = 0; i < 4; i++){ int r, c; r = r1 + x[i]; c = c1 + y[i]; if(r - c == r2 - c2 || r + c == r2 + c2 || abs(r - r2) + abs(c - c2) <= 3){ cout << 2 << endl; return 0; } } cout << 3 << endl; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define o2(x) (x) * (x) #define mk make_pair #define eb emplace_back #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define clr(a, b) memset((a), (b), sizeof((a))) #define rep(i, s, t) for(register int i = (s), LIM=(t); i < LIM; ++i) #define per(i, s, t) for(register int i = (s), LIM=(t); i >= LIM; --i) #define GKD std::ios::sync_with_stdio(false);cin.tie(0) #define my_unique(x) sort(all(x)), x.erase(unique(all(x)), x.end()) using namespace std; typedef long long LL; typedef long long int64; typedef unsigned long long uint64; typedef pair<int, int> pii; // mt19937 rng(time(NULL));//std::clock() // mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count()); // shuffle(arr, arr + n, rng64); inline int64 read() { int64 x = 0;int las = 0;char ch = getchar(); while (ch < '0' || ch > '9') las |= (ch == '-'), ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return x = las ? -x : x; } inline void write(int64 x, bool las = true) { if (x == 0) {putchar('0'); if(las)putchar('\n');else putchar(' ');return;} if (x < 0) {putchar('-');x = -x;} static char s[23]; int l = 0; while (x != 0)s[l++] = x % 10 + 48, x /= 10; while (l)putchar(s[--l]); if(las)putchar('\n');else putchar(' '); } int lowbit(int x) { return x & (-x); } template <class T> T big(const T &a1, const T &a2) {return a1 > a2 ? a1 : a2;} template <class T> T sml(const T &a1, const T &a2) {return a1 < a2 ? a1 : a2;} template <typename T, typename... R> T big(const T &las, const R &... r) {return big(las, big(r...));} template <typename T, typename... R> T sml(const T &las, const R &... r) {return sml(las, sml(r...));} void debug_out() { cout << '\n'; } template <typename T, typename... R> void debug_out(const T &las, const R &... r) { cout << las << " "; debug_out(r...); } #ifdef LH_LOCAL #define debug(...) cout << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__); #else #define debug(...) ; #endif /*================Header Template==============*/ const int mod = 998244353;// 998244353 const int INF = 0x3f3f3f3f; int ksm(int a, int64 b, int kmod = mod) {int res = 1;for(;b > 0;b >>= 1, a = (int64)a * a % kmod) if(b &1) res = (int64)res * a % kmod;return res;} const int MXN = 2e5 + 5; int n, m; class node{ public: int a, b; void Rd() { a = read(), b = read(); } }; node A, B; int ans; int is(node A, node B) { if(A.a + A.b == B.a + B.b) return 1; if(A.a - A.b == B.a - B.b) return 2; if(abs(A.a - B.a) + abs(A.b - B.b) <= 3) return 3; return 0; } void work() { A.Rd(), B.Rd(); if(A.a == B.a && A.b == B.b) ans == 0; else if(is(A, B)) ans = 1; else { node C = A; int64 cha = A.b - A.a; int64 he = B.a + B.b; A.a = (he - cha) / 2; A.b = A.a + cha; if(is(A, B)) ans = 2; else ans = 3; A = C; cha = B.b - B.a; he = A.a + A.b; A.a = (he - cha) / 2; A.b = he - A.a; if(is(A, B)) ans = 2; else ans = min(ans, 3); } printf("%d\n", ans); } int main() { #ifdef LH_LOCAL freopen("D:/ACM/mtxt/in.txt", "r", stdin); // freopen("D:/ACM/mtxt/out.txt", "w", stdout); #endif for(int cas = 1, tim = 1; cas <= tim; ++ cas) { work(); } #ifdef LH_LOCAL cout << "time cost:" << 1.0 * clock() / CLOCKS_PER_SEC << "s" << endl; #endif return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define yn(x) ((x) ? "YES" : "NO") typedef pair <int, int> ii; typedef pair <int, ii> iii; const int siz = 1e2 + 10; const int SIZ = 1e6 + 10; const int mod = 1e9 + 7; const int maxx = 2e9; const int MAXX = 1e18; const string file = "1"; char a[siz][siz]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen ((file + ".inp").c_str(), "r", stdin); // freopen ((file + ".out").c_str(), "w", stdout); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; } } int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (a[i][j] == '.') { if (j + 1 <= m && a[i][j + 1] == '.') { ans++; } if (i + 1 <= n && a[i + 1][j] == '.') { ans++; } } } } cout << ans << "\n"; // cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define ld long double #define F first #define S second #define PB push_back #define forn(i,a,b) for(i=a;i<=b;i++) #define nfor(i,a,b) for(i=a;i>=b;i--) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define pii pair<int,int> #define vi vector<int> #define vpii vector<pii> #define vvi vector<vi> #define si set<int> #define spii set<pii> #define usi unordered_set<int> #define uspii unordered_set<pii> #define mii map<int,int> #define umii unordered_map<int,int> #define pqmx priority_queue<int> #define pqmn priority_queue<int,vi,greater<int>> #define setbits(x) __builtin_popcountll(x) #define tzbits(x) __builtin_ctzll(x) #define lzbits(x) __builtin_clzll(x) #define pbits(x) __builtin_parityll(x) #define gcd __gcd #define lcm(x, y) ((x)*(y))/gcd(x,y) #define endl '\n' #define sz(s) (int)s.size() #define sp(x,y) fixed<<setprecision(y)<<x const int mod = 1000000007; const int inf = 1000000000000000000; const ld PI = 3.1415926535897932384626; const ld eps = 1e-12; void __print(int32_t x) {cout<<x;} void __print(int x) {cout<<x;} void __print(double x) {cout<<x;} void __print(ld x) {cout<<x;} void __print(float x) {cout<<x;} void __print(bool x) {cout<<(x?"true":"false");} void __print(char x) {cout <<'\''<<x<<'\'';} void __print(const char *x) {cout <<'\"' <<x<<'\"';} void __print(const string &x) {cout<<'\"'<<x<<'\"';} template<typename T,typename V> void __print(const pair<T,V> &x) {cout<<'{';__print(x.first);cout<<',';__print(x.second);cout<<'}';} template<typename T> void __print(const T &x) {int f=0;cout<<'{';for(auto &i:x)cout<<(f++?",":""),__print(i);cout<<"}";}void _print(){cout<<"]\n";} template <typename T,typename... V> void _print(T t, V... v) {__print(t);if(sizeof...(v))cout<<", ";_print(v...);} #define dbg(x...) cout<<"["<<#x<<"]=[";_print(x) int powerm(int base,int exp) {int res=1;base%=mod;while(exp>0){if(exp&1)res=(res*base)%mod;base=(base*base)%mod;exp=exp>>1;}return res;} int power(int base,int exp) {int res=1;while(exp>0){if(exp&1)res=res*base;base=base*base;exp=exp>>1;}return res;} float powerNeg(float base,int exp) {float temp;if(exp==0)return 1;temp=powerNeg(base,exp/2);if(exp%2==0)return temp*temp;else{if(exp>0)return base*temp*temp;else return (temp*temp)/base;}} int modinv(int exp) {return powerm(exp,mod-2);} // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ const int N=2e6+5; void solve() { int i,j; int n,m; cin>>n>>m; vector<vector<char>> a(n,vector<char>(m)); forn(i,0,n-1) forn(j,0,m-1) cin>>a[i][j]; int cnt=0; forn(i,0,n-1){ forn(j,0,m-2){ if(a[i][j]=='.' and a[i][j+1]=='.') cnt++; } } forn(j,0,m-1){ forn(i,0,n-2){ if(a[i][j]=='.' and a[i+1][j]=='.') cnt++; } } cout<<cnt<<endl; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t,T=1; // cin>>T; forn(t,1,T) { // cout<<"Case #"<<i<<": "; solve(); } // cout<<endl<<"Times Elapsed:"<<1.0*clock()/CLOCKS_PER_SEC<<"sec"; return 0; }