code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include <bits/stdc++.h> #define all(v) (v).begin(),(v).end() #define f first #define s second #define _ << ' ' << #define _n << '\n'; #define print(arr) for(int i : arr) cout << i << ' '; cout << '\n'; using namespace std; pair<long long int,long long int> go(int pos, vector<int> &vec){ if(pos == 0){ if(vec[0]){ return {1, 3}; } else{ return {3, 1}; } } pair<long long int,long long int> p = go(pos-1, vec); if(vec[pos]){ return {p.first, powl(2, pos+1) + p.second}; } return {powl(2, pos+1) + p.first, p.second}; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> vec; for(int i=0;i<n;++i){ string str; cin >> str; if(str == "AND") vec.push_back(1); else vec.push_back(0); } cout << go(n-1, vec).first << '\n'; return 0; }
#include <bits/stdc++.h> typedef long long ll; #define _GLIBCXX_DEBUG #define int long long using namespace std; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPR(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++) #define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--) #define ALL(x) (x).begin(), (x).end() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MAXIN(x) max_element(ALL(x)) - x.begin(); #define MIN(x) *min_element(ALL(x)) #define MININ(x) min_element(ALL(x)) - x.begin(); #define INF 1000000000000 #define MOD 1000000007 #define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用) #define PI 3.14159265358979323846 using namespace std; #include <sstream> using namespace std; vector<string> split(const string &s, char delim) { vector<string> elems; stringstream ss(s); string item; while (getline(ss, item, delim)) { if (!item.empty()) { elems.push_back(item); } } return elems; } signed main() { string an; cin >> an; cout << split(an, '.')[0] << endl; } // int M, H; // cin >> M >> H; // if(H%M == 0){ // cout << "Yes" <<endl ; // }else{ // cout << "No" <<endl ; // }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; int main() { int n; double x, y; complex<double> a, b; cin >> n; cin >> x >> y; a = {x, y}; cin >> x >> y; b = {x, y}; auto m = (a + b) / 2.0; auto res = m + (a - m) * polar(1.0, M_PI * 2.0 / n); cout << fixed << setprecision(12) << res.real() << " " << res.imag() << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) #define all(a) (a).begin(), (a).end() using namespace std; using ll = long long int; using P = pair<int, int>; const ll INF_L = 1LL << 60; const int INF_I = 1 << 30; const int MOD = (int)1e9 + 7; const double PI = acos(-1); int dx[] = {1, 0, -1, 0}; int dy[] = {0, -1, 0, 1}; int main() { int n; cin >> n; complex<double> a, b; rep(i, 2) { double x, y; cin >> x >> y; if (!i) a = {x, y}; else b = {x, y}; } auto m = (a + b) / 2.0; auto res = m + (a - m) * polar(1.0, 2.0 * PI / n); printf("%.10f\n%.10f\n", res.real(), res.imag()); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i=0; i<(int)(n); i++) int main(){ long t, N; cin >> t >> N; long l=1, r=1e15; while(r-l>1){ long x=(l+r)/2; if(((100+t)*x)/100-x<N){ l=x; }else{ r=x; } } cout << ((100+t)*r)/100-1 << "\n"; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t t, n; cin >> t >> n; if (100 * n % t == 0) { cout << n - 1 + 100 * n / t << endl; } else { cout << n + 100 * n / t ;} }
#define ii pair<int , int> #include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<ii> edge[N]; int label[N]; bool check[N]; void dfs(int u) { for (auto adj : edge[u]) { int v = adj.first; int w = adj.second; if (label[v] == 0) { if (label[u] == w) { if (w == 1) label[v] = 2; else label[v] = 1; } else { label[v] = w; } dfs(v); } } } int main() { // freopen(".inp","r",stdin); // freopen(".out","w",stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n , m; cin >> n >> m; while(m--) { int u , v , w; cin >> u >> v >> w; edge[u].push_back(ii(v , w)); edge[v].push_back(ii(u , w)); } label[1] = 1; dfs(1); for (int i = 1 ; i <= n ; ++i) cout << label[i] << "\n"; }
#define _USE_MATH_DEFINES #include <iostream> #include <algorithm> #include <climits> #include <vector> #include <string> #include <cstring> #include <stack> #include <queue> #include <cmath> #include <iomanip> #include <set> #include <map> #include <new> #include <cstdint> #include <cctype> #include <cstdio> #include <sstream> #include <bitset> #include <fstream> #include <ctime> using namespace std; #define rep(i,n) for(int i = 0; i < n; i++) #define lrep(i,n,m) for(int i = n; i < m; i++) using ll = long long; using ull = unsigned long long; using ld = long double; using Vii = vector<vector<int> >; using Viii = vector<vector<vector <int> > >; using Gjudge = vector<vector<bool>>; using Vi = vector<int>; using Vl = vector<ll>; using Vd = vector<double>; using Vld = vector<long double>; using Vll = vector<vector<ll> >; using Vlll = vector<vector<vector<ll> > >; using Vdd = vector<vector<double> >; using Vldd = vector<vector<ld> >; using Vs = vector<string>; using Vb = vector<bool>; using Vbb = vector<vector<bool> >; using Pi = pair<int, int>; using Pl = pair<ll, ll>; using Pli = pair<ll, int>; using VPi = vector<Pi>; using VPl = vector<Pl>; using VPli = vector<Pli>; using Ti = tuple<int, int, int>; using Tl = tuple<ll, ll, ll>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int MOD = static_cast<int>(1e9 + 7); const ll MOD2 = 998244353; const int INF = INT_MAX - 1000000; const ll LINF = LLONG_MAX - 1000000; const ll OLINF = ll(2) << 60; const int OINF = 2 << 29; const int dx[4] = { 0,-1,0,1 }; const int dy[4] = { -1,0,1,0 }; const int ddx[8] = { -1,-1,0,1,1,1,0,-1 }; const int ddy[8] = { 0,1,1,1,0,-1,-1,-1 }; struct edge { int to; ll cost; }; struct kedge { int u, v, cost; }; Vi C; Vi Ans; Vb visited; set<int> S; int Dep[100005] = { 0 }; void bfs(int u, Vii& G) { visited[u] = true; //cout << u << " " << C[u] << endl; if (S.find(C[u]) == S.end()) Ans.push_back(u); S.insert(C[u]); Dep[C[u]]++; for (int nu : G[u]) { if (visited[nu]) continue; bfs(nu, G); } if (Dep[C[u]] > 1) { Dep[C[u]]--; } else { S.erase(S.find(C[u])); Dep[C[u]] = 0; } } int main() { int n; cin >> n; C.resize(n); rep(i, n) cin >> C[i]; Vii G(n); rep(i, n - 1) { int a, b; cin >> a >> b; a--; b--; G[a].push_back(b); G[b].push_back(a); } visited.resize(n, false); bfs(0, G); sort(Ans.begin(), Ans.end()); for (int A : Ans) { cout << A + 1 << endl; } }
#include<iostream> using namespace std; int main(){ int n,point,i; string str; cin>>n>>point>>str; for(i=0;i<n;i++){ if(str[i]=='o') point++; else{ if(point==0) continue; else point--; } } cout<<point<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define TEZ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define f(i,a,b) for(ll i=a;i<b;i++) #define rf(i,a,b) for(ll i=a;i>=b;i--) #define pb push_back #define vi vector<pair<ll,ll>> #define ff first #define ss second #define mp map<ll,ll> #define test ll t; cin>>t; while(t--) #define srt(v) sort(v.begin(),v.end()) double pi=acos(-1); const ll MOD=1000000007; int main(){ TEZ; ll a,b,c; cin>>a>>b>>c; ll sum=21-(a+b+c); cout<<sum; }
#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 = 3e18; const double EPSILON = 1e-9; const int N = 2e5+5; int dp[N][7]; // dp[i][j] : true if takahashi can get the remainder j on the i'th position /* if x[i]=='T' takahashi needs only one chance to get the remainder to win, else takashi needs both chances to get the remainder otherwise aoki will choose the other option to get a different remainder in order to takahashi loose */ int main(){ fastio; int n, ten = 1; string s,x; cin >> n >> s >> x; dp[n][0] = 1; for(int i = n-1; i >= 0; i--){ for(int j = 0; j < 7; j++){ // append zero |& append s[i] if(x[i] == 'T'){ dp[i][j] = dp[i+1][j] | dp[i+1][(j+(ten*(s[i]-'0')))%7]; }else{ dp[i][j] = dp[i+1][j] & dp[i+1][(j+(ten*(s[i]-'0')))%7]; } } ten = (ten * 10) % 7; } cout << (dp[0][0]?"Takahashi":"Aoki") << "\n"; return 0; } // DOES IT HAVE OVERFLOW ? // DOES IT HAVE INVALID MEMO ACESS ?
// g++ -std=c++11 a.cpp #include<iostream> #include<vector> #include<string> #include<algorithm> #include<map> #include<set> #include<unordered_map> #include<utility> #include<cmath> #include<random> #include<cstring> #include<queue> #include<stack> #include<bitset> #include<cstdio> #include<sstream> #include<random> #include<iomanip> #include<assert.h> #include<typeinfo> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) #define FOR(i,a) for(auto i:a) #define pb push_back #define all(in) in.begin(),in.end() #define shosu(x) fixed<<setprecision(x) #define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;} #define show2d(v) {rep(__,v.size())show1d(v[__]);} using namespace std; //kaewasuretyuui typedef long long ll; #define int ll typedef int Def; typedef pair<Def,Def> pii; typedef vector<Def> vi; typedef vector<vi> vvi; typedef vector<pii> vp; typedef vector<vp> vvp; typedef vector<string> vs; typedef vector<double> vd; typedef vector<vd> vvd; typedef pair<Def,pii> pip; typedef vector<pip>vip; #define mt make_tuple typedef tuple<int,int,int> tp; typedef vector<tp> vt; typedef vector<vt>vvt; template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;} template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;} const double PI=acos(-1); const long double EPS=1e-9; Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10; int dx[]={-1,0,1,0}; int dy[]={0,1,0,-1}; #define yes cout<<"Yes\n" #define no cout<<"No\n" int dp[200200][17][2]; signed main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin>>n; int t=-1; rep(i,n){ int a,b,c; cin>>a>>b>>c; if(c-a>=1){ if(t==-1||t>=b)t=b; } } cout<<t<<endl; }
#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 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; cin>>n; string s; cin>>s; ll q; cin>>q; ll count_2=0; ll m=2*n; rep(i,q){ ll t,a,b; cin>>t>>a>>b; if(t==1){ ll A,B; A=(a-1+n*(count_2%2))%m; B=(b-1+n*(count_2%2))%m; // cout<<A<<" "<<B<<endl;//debug char tmp; tmp=s[A]; s[A]=s[B]; s[B]=tmp; } else{ count_2++; // cout<<"t1:"<<t1<<" t2:"<<t2<<endl;//debug } // print(s);//debug } if(count_2%2==1){ string t; t=s.substr(n,n); s.erase(n); s=t+s; } print(s); }
#include<iostream> #include<string> #include<vector> #include<utility> #include<algorithm> #include<map> #include<set> #include<cstdlib> #include<cmath> #include<numeric> #include<iomanip> #include<functional> #include<cstdlib> #include<queue> #include<deque> #include<cassert> #include<stack> #include <iterator> // std::back_inserter const double PI = acos(-1); using namespace std; using ll =long long; #define rep(i,n)for(ll i=0;i<(n);i++) const int mod = 1000000007; const ll inf = 1e18 + 1; //int ctoi(char c) { // if (c >= '0' && c <= '9') { // return c - '0'; // } // return 0; //} // ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } //ll lcm(ll a, ll b) { // return a * b / gcd(a, b); //}; //fixed << setprecision(2) ///*Union Find*/ //#define MAX_N 200000 //#define MAX_M 200000 //vector<ll>par(MAX_N); //vector<ll>ran(MAX_N); //void init(ll N) { // rep(i, N) { // par[i] = i; // ran[i] = 0; // } //} //ll find(ll x) { // if (par[x] == x) { // return x; // } // else { // return par[x] = find(par[x]); // } //} //void unite(ll x,ll y) { // x = find(x); // y = find(y); // if (x == y)return; // if (ran[x] < ran[y]) { // par[x] = y; // // } // else { // par[y] = x; // if (ran[x] == ran[y])ran[x]++; // } //} //bool same(ll x, ll y) { // return find(x) == find(y); //} ////UnionFind //dfs //if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; //dfs //桁和を求める //ll digsum(ll n) { // ll res = 0; // while (n > 0) { // res += n % 10; // n /= 10; // } // return res; //} //桁和を求める //cin,coutを早くする //ios::sync_with_stdio(false); //cin coutを早くする。 ll g1(ll s) { map<int, int>m; ll tmp = s; int n=1; tmp /= 10; while (tmp!=0) { tmp /= 10; n++; } //cout << n<<endl; rep(i, n) { ll b = s / pow(10, i); b %= 10; m[b]++; } ll x=0; for (int i = 9; i >= 0; i--) { while (true) { if (m[i] != 0) { x += i * pow(10, n-1); m[i]--; n--; } else { break; } } } return x; } ll g2(ll s) { map<int, int>m; ll tmp = s; int n = 1; tmp /= 10; while (tmp != 0) { tmp /= 10; n++; } // cout << n << endl; rep(i, n) { ll b = s / pow(10, i); b %= 10; m[b]++; } ll x = 0; for (int i = 0; i <= 9; i++) { while (true) { if (m[i] != 0) { x += i * pow(10, n - 1); m[i]--; n--; } else { break; } } } return x; } int main() { ios::sync_with_stdio(false); ll N, K; cin >> N >> K; ll a = N; rep(i, K) { a = g1(a) - g2(a); } cout << a; }
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<algorithm> #include<vector> #include<map> #include<stack> #include<set> using namespace std; #define ll long long int #define ull unsigned long long int #define ld long double #define max3(a,b,c) max(a,max(b,c)) #define max4(a,b,c,d) max(max3(a,b,c),d) #define min3(a,b,c) min(a,min(b,c)) #define min4(a,b,c,d) min(min3(a,b,c),d) vector<ll> v,w; set<ll>s1; map<ll,ll>mp; long long mod = 1000000007; int main() { ll i,j=0,l,m,n,o,r,t,x,y,k,c=1; string s,p,q; cin>>n; ll a[n+1]={0}; for(i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1); for(i=1;i<=n;i++){ c*=(a[i]-a[i-1]+1); c%=mod; } cout<<c; }
#include<bits/stdc++.h> #define inf 0x3f3f3f3f3f3f3f3fll typedef unsigned long long ull; typedef long long ll; #define rep(i,l,r) for(int i=l;i<=r;i++) #define nep(i,r,l) for(int i=r;i>=l;i--) void sc(int &x){scanf("%d",&x);} void sc(int &x,int &y){scanf("%d%d",&x,&y);} void sc(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);} void sc(ll &x){scanf("%lld",&x);} void sc(ll &x,ll &y){scanf("%lld%lld",&x,&y);} void sc(ll &x,ll &y,ll &z){scanf("%lld%lld%lld",&x,&y,&z);} void sc(char *x){scanf("%s",x);} void sc(char *x,char *y){scanf("%s%s",x,y);} void sc(char *x,char *y,char *z){scanf("%s%s%s",x,y,z);} void out(int x){printf("%d\n",x);} void out(ll x){printf("%lld\n",x);} void out(int x,int y){printf("%d %d\n",x,y);} void out(ll x,ll y){printf("%lld %lld\n",x,y);} void out(int x,int y,int z){printf("%d %d %d\n",x,y,z);} void out(ll x,ll y,ll z){printf("%lld %lld %lld\n",x,y,z);} using namespace std; const int N=3e5+5,mod=1e9+7; int n,a[N]; int main() { //freopen("1.in","r",stdin);freopen("1.out","w",stdout); sc(n); rep(i,1,n) sc(a[i]); sort(a+1,a+1+n); ll ans=a[1]+1; rep(i,1,n-1) ans=ans*(a[i+1]-a[i]+1)%mod; out(ans); }
#include <bits/stdc++.h> using namespace std; int main () { int n, m; cin >> n >> m; vector <string> qw (n); for (int i=0; i<n; ++i) { cin >> qw[i]; } long long t=0; for (int i=0; i<n; ++i) { for (int ii=0; ii<m; ++ii) { if (qw[i][ii]=='.') { if (i!=n-1 && qw[i+1][ii]=='.') t+=1; if (ii!=m-1 && qw[i][ii+1]=='.') t+=1; } } } cout << t << endl; }
#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; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define X first #define Y second #define pb push_back #define sz(s) int64_t(s.size()) #define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin()) const ll mod = 1e9 + 7; template<class T> istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; } template<class T, class U> istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; } template<class T, class U> ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; } template<class T, class U> void chkmax(T &a, U b) { a = max(a, (T)b); return; } template<class T, class U> void chkmin(T &a, U b) { a = min(a, (T)b); return; } ll ppow (ll x, ll s) { if (!s) return 1; if (!(s - 1)) return x % mod; if (s % 2) return (x * ppow (x, s - 1)) % mod; ll b = ppow (x, s / 2); return (b * b) % mod; } vector<int> zf (string s) { int n = sz(s); vector<int> z (n); for (int i = 1, l = 0, r = 0; i < n; i++) { if (i <= r) z[i] = min (r - i + 1, z[i - l]); while (i + z[i] < n && s[z[i]] == s[i + z[i]]) z[i]++; if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1; } return z; } vector<int> pf(string p) { int n = sz(p); vector<int> pref_fun(n, 0); for (int i = 1;i < n;i++) { int j = pref_fun[i - 1]; while (j > 0 && p[i] != p[j]) j = pref_fun[j - 1]; if (p[i] == p[j]) j++; pref_fun[i] = j; } return pref_fun; } vector<vector<int> > mul(vector<vector<int> > &a, vector<vector<int> > &b) { int n = sz(a); vector<vector<int> > c(n, vector<int> (n, 0)); for (int i = 0;i < n;i++) { for (int j = 0;j < n;j++) { for (int k = 0;k < n;k++) { ll ga = a[i][k]; ga *= b[k][j]; ga %= mod; c[i][j] += ga; if (c[i][j] >= mod) { c[i][j] -= mod; } } } } return c; } vector<vector<int> > matrix_pow(vector<vector<int> > a, ll y) { int n = sz(a); vector<vector<int> > res(n, vector<int> (n, 0)); for (int i = 0;i < n;i++) res[i][i] = 1; while (y) { if (y%2 == 1) { res = mul(res, a); y--; }else { a = mul(a, a); y /= 2; } } return res; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int a, b; cin >> a >> b; cout.precision(10); cout << fixed << 100 * (1 - (ld)b/a); return 0; }
#include <iostream> #include <cmath> int main() { int x, y; std::cin >> x; std::cin >> y; std::cout << (std::abs(x-y) < 3 ? "Yes" : "No") << std::endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vl = vector<ll>; using vp = vector<pii>; using vvi = vector<vi>; #define rep(i, a, b) for (int i = a; i < (int) (b); i++) #define rrep(i, a, b) for (int i = a; i >= (int) (b); i--) #define fore(i_in, a) for (auto& i_in: a) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pq(T) priority_queue<T, vector<T>, greater<T>> template<class T> void chmin(T &a, T b) { if (a > b) a = b; } //template<class T> bool chmin(T& a, T b) {if (a > b) {a = b;return true;} else return false;} template<class T> void chmax(T &a, T b) { if (a < b) a = b; } //template<class T> bool chmax(T& a, T b) {if (a < b) {a = b;return true;} else return false;} template<class T> void print(const T &t) { cout << t << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int h, w; cin>>h>>w; if (abs(h-w) < 3) print("Yes"); else print("No"); }
#include <bits/stdc++.h> using namespace std; #define stp(var, init, end) for (auto var = init; var < end; ++var) #define stpe(var, init, end) for (auto var = init; var <= end; ++var) #define ll long long int main(void) { int n; cin >> n; cout << n - 1; return 0; }
#include<iostream> using namespace std; long long n; void solve() { cout<<n-1<<endl; } int main() { while(cin>>n) solve(); }
#include <cstdio> #include <cstring> #include <cmath> #include <utility> #include <iostream> #include <functional> #include <bitset> #include <algorithm> #include <vector> #include <forward_list> #include <set> #include <map> #include <queue> #include <deque> #include <stack> #include <tuple> #include <numeric> #define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i)) using namespace std; using ll = long long; using P = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll INF = (1ll << 60); struct unionfind { vector<long long> d; unionfind(long long n) : d(n, -1) {} long long root(long long x) { if (d[x] < 0) { return x; } else { return d[x] = root(d[x]); } } bool unite(long long x, long long y) { x = root(x); y = root(y); if (x == y) { return false; } if (d[x] > d[y]) { swap(x, y); } d[x] += d[y]; d[y] = x; return true; } bool same(long long x, long long y) { return root(x) == root(y); } long long size(long long x) { return -d[root(x)]; } }; int main(void) { ll n, m; cin >> n >> m; vector<ll> a(m), b(m); vector<vector<ll>> g(n, vector<ll>()); for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; g[a[i]].push_back(b[i]); g[b[i]].push_back(a[i]); } ll k; cin >> k; vector<vector<ll>> g_d(k, vector<ll>(k, INF)); vector<ll> c(k); for (int i = 0; i < k; i++) { cin >> c[i]; c[i]--; } for (int i = 0; i < k; i++) { queue<ll> q; q.push(c[i]); vector<ll> dis(n, INF); dis[c[i]] = 0; while (q.size()) { ll p = q.front(); q.pop(); for (auto &&x : g[p]) { if (dis[x] == INF) { dis[x] = dis[p] + 1, dis[x]; q.push(x); } } } for (int j = 0; j < k; j++) { if (i == j) { g_d[i][j] = 0; g_d[j][i] = 0; } if (dis[c[j]] == INF) { cout << -1 << endl; return 0; } ll d; d = min(g_d[i][j], dis[c[j]]); g_d[i][j] = d; g_d[j][i] = d; } } ll maxd = 0; bool flag = false; for (int i = 0; i < k; i++) { for (int j = i + 1; j < k; j++) { maxd = max(maxd, g_d[i][j]); } } // for (int i = 0; i < k; i++) // { // for (int j = 0; j < k; j++) // { // printf("%lld ", g_d[i][j]); // } // printf("\n"); // } vector<vector<ll>> dp(1 << k, vector<ll>(k, INF)); for (int i = 0; i < k; i++) { dp[1 << i][i] = 1; } for (int bit = 1; bit < 1 << k; bit++) { for (int i = 0; i < k; i++) { for (int j = 0; j < k; j++) { dp[bit | 1 << j][j] = min(dp[bit | 1 << j][j], dp[bit][i] + g_d[i][j]); } } } ll ans = INF; for (int i = 0; i < k; i++) { ans = min(ans, dp[(1 << k) - 1][i]); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll=long long; int main(){ int N,K; cin>>N>>K; vector<vector<int>> A(N,vector<int>(N)); for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ cin>>A[i][j]; } } vector<int> kouho; int left=-1,right=1e9+1; while(right-left>1){ int mid=(right-left)/2+left; vector<vector<int>> a(N,vector<int>(N)),sum(N,vector<int>(N)); for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ if(A[i][j]>mid) a[i][j]=1; else a[i][j]=0; } } sum[0][0]=a[0][0]; for(int i=1;i<N;i++) sum[i][0]=sum[i-1][0]+a[i][0]; for(int i=1;i<N;i++) sum[0][i]=sum[0][i-1]+a[0][i]; for(int i=1;i<N;i++){ for(int j=1;j<N;j++){ sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+a[i][j]; } } bool f=false; if(sum[K-1][K-1]<=K*K/2) f=true; for(int i=1;i<=N-K;i++){ if(sum[i+K-1][K-1]-sum[i-1][K-1]<=K*K/2) f=true; } for(int i=1;i<=N-K;i++){ if(sum[K-1][i+K-1]-sum[K-1][i-1]<=K*K/2) f=true; } for(int i=1;i<=N-K;i++){ for(int j=1;j<=N-K;j++){ if(sum[i+K-1][j+K-1]-sum[i-1][j+K-1]-sum[i+K-1][j-1]+sum[i-1][j-1]<=K*K/2){ f=true; } } } if(f){ right=mid; }else{ left=mid; } } cout<<right<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long signed main(){ int l,r; cin>>l>>r; if(l==r){ cout<<0;return 0; } if(l==1)l++; if(r-l==1){ cout<<1;return 0; } vector<int> d(r+1,0); for(int i=2;i<=r;i++){ if(d[i]!=0)continue; for(int j=i;j<=r;j+=i){ d[j]++; } for(int j=i*i;j<=r;j+=i*i){ d[j]=-10000000; } } int ncop=0; for(int i=2;i<=r;i++){ if(d[i]<0)continue; int x=r/i-(l-1)/i; //cout<<i<<' '<<x<<' '<<d[i]<<' '; x=x*(x-1)/2; ncop+=(d[i]%2)?x:-x; //cout<<ncop<<'\n'; } int div=0; for(int i=l;i<=r;i++){ div+=r/i-1; } cout<<(ncop-div)*2; return 0; }
#include<algorithm> #include<iostream> #include<cstring> #include<bitset> #include<cstdio> #include<string> #include<cmath> #include<queue> #include<stack> #include<map> #include<set> using namespace std; #define neinf 0xc0c0c0c0c0c0c0c0ll #define inf 0x3f3f3f3f3f3f3f3fll #define uint unsigned int #define ull unsigned ll #define HgS 1000000007 #define pr pair<ll,ll> #define prpr make_pair #define ll long long #define opr operator #define reg register #define gc getchar #define pc putchar #define ret return #define cst const #define db double #define il inline il ll rd() { reg ll res=0,lab=1; reg char ch=gc(); while((ch<'0'||ch>'9')&&ch!=EOF){if(ch=='-')lab=-lab;ch=gc();} while(ch>='0'&&ch<='9')res=(res<<3)+(res<<1)+(ch&15),ch=gc(); ret res*lab; } il void prt(ll x,char t='\n') { static char ch[70];int tp=0; if(!x){fputs("0",stdout);if(t)pc(t);ret;} if(x<0)pc('-'),x=-x; while(x)ch[++tp]=(x%10)^48,x/=10; while(tp)pc(ch[tp--]); if(t)pc(t); } il ll umax(ll a,ll b){return a>b?a:b;} il ll umin(ll a,ll b){return a<b?a:b;} il ll uabs(ll x){return x>0?x:-x;} il ll qpow(ll n,ll e=HgS-2,ll p=HgS) { n%=p;reg ll res=1; while(e){if(e&1)res=res*n%p;n=n*n%p;e>>=1;} ret res; } ll l,r,mu[1000005],sum[1000005];bool vis[1000005]; ll slv(int x,int y) { ll ans=0; for(int l=1,r;l<=umin(x,y);l=r+1) { r=umin(x/(x/l),y/(y/l)); ans+=1ll*(x/l)*(y/l)*(sum[r]-sum[l-1]); } return ans; } int main() { l=rd(),r=rd(); for(int i=1;i<=r;++i)mu[i]=1; for(int i=2;i<=r;++i) { if(vis[i])continue; for(int j=i;j<=r;j+=i) { vis[j]=1; if(1ll*j%(1ll*i*i)==0)mu[j]=0; else mu[j]=-mu[j]; } } for(int i=1;i<=r;++i)sum[i]=sum[i-1]+mu[i]; ll s1=0,s2=slv(r,r)-slv(l-1,r)-slv(r,l-1)+slv(l-1,l-1); for(int i=umax(l,2);i<=r;++i){++s1;for(int j=2;j*i<=r;++j)s1+=2;} prt(1ll*(r-l+1)*(r-l+1)-s1-s2); ret 0; }
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> using namespace std; const int N = 15; char a[N]; int ans = 0; int tr[N],cnt; int st[N]; void dfs(int num) { if(num == 4) { bool fl = true; for(int i = 1;i <= cnt;i++) if(st[tr[i]] == 0) { fl = false; break; } if(fl) ans++; return; } for(int i = 0;i < 10;i++) { if(a[i] == 'x') continue; st[i]++; dfs(num + 1); st[i]--; } } int main() { scanf("%s",a); for(int i = 0;i < 10;i++) if(a[i] == 'o') tr[++cnt] = i; if(cnt > 4) { printf("0"); return 0; } dfs(0); printf("%d",ans); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; int main() { int n; cin >> n; int ans = 0; for(int i = 1; i <= n; ++i){ int judge = 0; int i2 = i; while (i2){ if (i2%10 == 7) { judge = 1; break; } i2 /= 10; } i2 = i; while (i2){ if (i2 % 8 == 7) { judge = 1; break; } i2 /= 8; } if (judge == 1) continue; ans++; } cout << ans << endl; }
#include<bits/stdc++.h> #define ll long long using namespace std; const ll MOD=1e9+7; ll exp(ll a,ll n){ if(n==0) return 1; if(n==1) return a; ll ans=exp(a,n/2); ans*=ans;ans%=MOD; if(n&1) ans*=a,ans%=MOD; return ans; } void solve(){ int n,m;cin>>n>>m; string s[n]; for(int i=0;i<n;i++) cin>>s[i]; int top[n][m],bottom[n][m],left[n][m],right[n][m]; memset(top,0,sizeof(top)); memset(bottom,0,sizeof(bottom)); memset(left,0,sizeof(left)); memset(right,0,sizeof(right)); for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(s[i][j]=='#') continue; top[i][j]=1; if(i) top[i][j]+=top[i-1][j]; } } for(int i=n-1;i>=0;i--){ for(int j=0;j<m;j++){ if(s[i][j]=='#') continue; bottom[i][j]=1; if(i+1<n) bottom[i][j]+=bottom[i+1][j]; } } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(s[i][j]=='#') continue; left[i][j]=1; if(j) left[i][j]+=left[i][j-1]; } } for(int i=0;i<n;i++){ for(int j=m-1;j>=0;j--){ if(s[i][j]=='#') continue; right[i][j]=1; if(j+1<m) right[i][j]+=right[i][j+1]; } } int nTidy=0; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(s[i][j]=='.') nTidy++; } } ll total=exp(2,nTidy)*nTidy%MOD; ll negativeContri=0; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(s[i][j]=='#') continue; int restriction=top[i][j]+bottom[i][j]+left[i][j]+right[i][j]-4+1; negativeContri+=exp(2,nTidy-restriction); negativeContri%=MOD; } } cout<<(total-negativeContri+MOD)%MOD<<"\n"; } main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif solve(); }
//x<<y=x*2^y,x>>y=x/2^y //1e5+3 is prime // in a matrix, all elements of a primary diagonal have constant diff of coordinates // and a secondary diagonal has constant sum of coordinates //use ll() for using an integer in self-built fn //(x&-x) bitwise and of (x and its 2's complement) returns (last set bit) //eg if x=1010 then it will return 0010 // careful dont print empty container(run time error) //v.erase O(n) //use ("\n") instead of endl as endl flushes the output buffer //every time so takes more time than \n (TLE) //stoll() and to_string((less than 1e19)) //INT_MAX is approx 3e10 //For sets use set_name.lower_bound(x)(strictly O(logn)) //NOT lb(all(s),x)(O(logn) for random access (eg vector) but for sets it is O(n)); #include<bits/stdc++.h> typedef long long int ll; #define ull unsigned long long int #define lld long double #define endl "\n" #define fi first #define sec second #define sp setprecision #define lb lower_bound #define ub upper_bound #define For(i, a, b) for(long long int i = (a); i <= (b); i++) #define Forr(i, a, b) for(long long int i = (a); i >= (b); i--) #define pb push_back #define mp(a,b) make_pair(a,b) #define vll vector<ll> #define pll pair<ll,ll> #define vlld vector<lld> #define vi vector<int> #define vch vector<char> #define sll set<ll> #define sch set<ch> #define vpll vector< pair<ll,ll> > #define vpii vector< pair<int,int> > #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define mll map<ll, ll> #define mcll map<char,ll> #define sz(container) ll((container).size()) #define fill(a,b) memset(a, b, sizeof(a)) #define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) using namespace std; lld pi=3.1415926535897932; const ll mod=998244353; const ll dx[4]={-1, 0, 1, 0} , dy[4]={0, 1, 0, -1}; const ll dxx[8]={-1, -1, 0, 1, 1, 1, 0, -1} , dyy[8]={0, 1, 1, 1, 0, -1, -1, -1}; string ds="RLDU"; /*************************************** struct cmp { bool operator() (const pll &a, const pll &b) const { ll lena = a.sec - a.fi + 1; ll lenb = b.sec - b.fi + 1; if (lena == lenb) return a.fi < b.fi; return lena > lenb; } }; ********************************/ ll lcm(ll a, ll b) { ll g=__gcd(a, b); return a/g*b; } ll binpow(ll a, ll b,ll m) { a %= m; ll res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } ll modinv(ll n) { return binpow(n, mod - 2,mod); } /**************coding*********************/ vector<vll >adj(105); vll used(105,0); void dfs(ll v) { used[v]=1; for(ll u : adj[v]) { if (!used[u]) dfs(u); } } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast_io; ll T=1;//cin>>T; For(i,1,T) { ll n;cin>>n; string s[n]; For(j,0,n-1) cin>>s[j]; For(j,0,n-1) { For(k,0,n-1) { if(s[j][k]=='1') adj[j].pb(k); } } lld ans=0; vll vis(n,0); For(j,0,n-1) { For(k,0,n-1) used[k]=0; dfs(j); For(k,0,n-1) if(used[k]==1) vis[k]++; } For(j,0,n-1) ans+=(1/double(vis[j])); cout<<sp(20)<<ans; } }
#include <bits/stdc++.h> using namespace std; using ll = long long int; // aの逆元を計算する ll modinv(ll a, ll mod) { ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } int main() { int T; cin >> T; for (int i = 0; i < T; i++) { ll N, S, K; cin >> N >> S >> K; if (__gcd(K, N) != 1) { ll g = __gcd(K, N); if (S % g != 0) { cout << "-1" << endl; continue; } K /= g; N /= g; S /= g; } ll K_inv = modinv(K, N); cout << ((N - S) * K_inv) % N << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i) #define rep(i, n) drep(i, 0, n - 1) #define P pair<ll, ll> int main(){ ll T; cin >> T; vector<ll> L(T), R(T); rep(i, T) cin >> L.at(i) >> R.at(i); rep(i, T){ if(R.at(i)-L.at(i) < L.at(i)){ cout << 0 << endl; continue; } cout << (R.at(i)-2*L.at(i)+1)*(R.at(i)-L.at(i)+1) - (R.at(i)-L.at(i))*(R.at(i)-L.at(i)+1)/2 + (L.at(i)-1)*L.at(i)/2 << endl; } }
#include <bits/stdc++.h> using namespace std; int main(){ int a,b; cin>>a>>b; if(a+b>=15 && b>=8 ) cout<<1; else if(a+b>=10 && b>=3) cout<<2; else if(a+b>=3) cout<<3; else cout<<4; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define test() int t;cin>>t;for(int test=1;test<=t;test++) #define pb push_back #define nl cout<<"\n" #define F first #define S second #define all(x) x.begin(),x.end() template<class C> void min_self( C &a, C b ){ a = min(a,b); } template<class C> void max_self( C &a, C b ){ a = max(a,b); } const ll MOD = 1000000007; ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; } const int MAXN = 1e5+5; const int LOGN = 21; const ll INF = 1e14; int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1}; template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD ) { x += y; if( x >= m ) x -= m; } template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD ) { x -= y; if( x < 0 ) x += m; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio(); int a,b; cin>>a>>b; a += b; if( a >= 15 && b >= 8 ) { cout<<1; } else if( a >= 10 && b >= 3 ) { cout<<2; } else if( a >= 3 ) { cout<<3; } else { cout<<4; } cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n); ++i) #define Erep(i,n) for(int i = 0; i <= (n); ++i) #define repS(i,s,n) for(int i = s; i < (n); ++i) #define ErepS(i,s,n) for(int i = s; i <= (n); ++i) #define Sort(a) sort(a.begin(), a.end()) #define RSort(a) sort(a.rbegin(), a.rend()) #define Output(a) printf("%lld %s", a, "\n") #define OutputS(a) printf("%s %s", a, "\n") typedef long long int ll; typedef vector<int> vi; typedef vector<long long> vll; typedef vector<string> vst; const ll INF = 0x1fffffffffffffff; const ll MOD = 1000000007; 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; } string s; void input(){ cin >> s; } void solve(){ string ans = ""; rep(i, s.size()){ if(s[i] == '6'){ ans.push_back('9'); }else if(s[i] == '9'){ ans.push_back('6'); }else{ ans.push_back(s[i]); } } reverse(ans.begin(), ans.end()); cout << ans << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); input(); solve(); }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define pf push_front #define fi first #define se second #define mk make_pair #define MOD 1000000007 #define pi 3.1415926536 /* BAAP BAAP HOTA HAI AUTHOR- Devansh Nandasana*/ void adde(vector<ll> adj[],ll u,ll v) { adj[u].pb(v); adj[v].pb(u); } 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; } void BFS(vector<ll> adj[],ll bfs[],ll s,ll n) { bool *visited = new bool[n+1]; for(ll i=0;i<n+1;i++) visited[i] = false; list<ll> queue; visited[s] = true; bfs[s]=0; queue.push_back(s); vector<ll>::iterator i; while(!queue.empty()) { s=queue.front(); queue.pop_front(); for(i=adj[s].begin();i!=adj[s].end();++i) { if(!visited[*i]) { visited[*i] = true; bfs[*i]=bfs[s]+1; queue.push_back(*i); } } } } ll nCrModp(ll n,ll r,ll p) { if (r > n - r) r = n - r; ll C[r + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (ll i = 1; i <= n; i++) { for (ll j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % p; } return C[r]; } ll find_center(ll n,vector<ll> adj[]) { queue<ll> q; bool vis[n+1]; ll cnt[n+1]; for(ll i=1;i<=n;i++) { vis[i]=false; cnt[i]=adj[i].size(); if(cnt[i]==1) q.push(i); } while(q.size()>1) { ll cur=q.front(); vis[cur]=true; q.pop(); for(ll i=0;i<adj[cur].size();i++) { if(!vis[adj[cur][i]]) { cnt[adj[cur][i]]--; if(cnt[adj[cur][i]]==1) q.push(adj[cur][i]); } } } return q.front(); } int main() { #ifndef ONLINE_JUDGE freopen("/home/devansh/Desktop/temp/input.txt", "r", stdin); freopen("/home/devansh/Desktop/temp/output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin>>s; reverse(&s[0],&s[s.length()]); for(ll i=0;i<s.length();i++) { if(s[i]=='6') s[i]='9'; else if(s[i]=='9') s[i]='6'; } cout<<s<<"\n"; }
#include<bits/stdc++.h> using namespace std; int main(){ char word[1000]; cin >> word; string ans = "Yes"; for(int i=0;i<strlen(word);i++){ if(i%2){ if(word[i]<'A' || 'Z'<word[i]) ans = "No"; }else{ if(word[i]<'a' || 'z'<word[i]) ans = "No"; } } cout << ans << endl; return 0; }
#include "bits/stdc++.h" using namespace std; int main() { long long int n; cin >> n; long long int x = 0; for (long long int i = 1; i <= n; i++) { if (x + i >= n + 1) { if (x + i == n + 1) { x = i; } else { x = i - 1; } break; } x += i; } cout << (n - x) + 1 << endl; }
#include <algorithm> #include <iostream> #include <vector> #include <cstdint> int main() { int N; std::int64_t X; std::cin >> N >> X; std::vector<int> A(N); for (int i = 0; i < N; ++i) { std::cin >> A[i]; } std::int64_t best = X; for (int k = 1; k <= N; ++k) { std::vector<std::vector<int>> powers(k + 1, std::vector<int>(k, -1)); powers[0][0] = 0; for (const auto a : A) { for (int i = k - 1; i >= 0; --i) { for (int j = 0; j < k; ++j) { if (powers[i][j] >= 0) { const int m = (j + a) % k; powers[i + 1][m] = std::max(powers[i + 1][m], powers[i][j] + a); } } } } for (int j = 0; j < k; ++j) { if ((X - j) % k == 0 && powers[k][j] >= 0) { best = std::min(best, (X - powers[k][j]) / k); } } } std::cout << best << std::endl; return 0; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; // int64_t using ull = unsigned long long; using pii = pair<int,int>; using pll = pair<ll,ll>; #define REP(i,m,n) for(int i = m; i <= (n); ++i) #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) const int INF = 1e9+7; //10oku7 const int KONS_UFT= 300000; vector<int> par(KONS_UFT); //par 親 vector<int> depth(KONS_UFT); //depth 木の深さ //要素を初期化 void init( int n ){ rep (i , n){ par[i] = i; } rep (i , n){ depth[i] = 0; } return; } //木の根を調べる。 int find( int x ){ if (par[x] == x) { return x; } else { return par[x] = find( par[x]); } } //xとyの属する集合を合併 void unite( int x, int y){ x = find( x); y = find( y); if (x == y) return; if (depth [x] < depth [y]) { par[x] = y; } else { par[y] = x; if (depth[x] == depth [y]) depth[x]++; } return; } //xとyが同じ集合に属するか bool same( int x, int y){ return find(x) == find (y); } int main() { int H , W; cin >> H >> W; vector<string> S(H); rep(i,H){ cin >> S.at(i); } S.at(0).at(0) = '#'; S.at(0).at(W-1) = '#'; S.at(H-1).at(0) = '#'; S.at(H-1).at(W-1) = '#'; init(H+W); rep(i,H){ rep(j,W){ if (S.at(i).at(j) == '#') unite(i,j+H); } } set<int> col, row; rep(i,H){ col.insert(find(i)); } rep(j,W){ row.insert(find(j+H)); } cout << min(col.size() -1 , row.size() -1) << endl; }
#include <bits/stdc++.h> using namespace std; using lint = long long; constexpr lint inf = 1LL << 60; constexpr lint mod = 1000000007; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); lint x, y, a, b; cin >> x >> y >> a >> b; lint ret = 0; for (int i = 0; i <= 60; ++i) { bool ok = true; lint tot = i; lint curr = x; for (int j = 0; j < i; ++j) { if (curr >= y / a) { ok = false; break; } curr *= a; } if (curr > y) ok = false; lint bs = (y - 1 - curr) / b; tot += bs; if (!ok) continue; else ret = max(ret, tot); } cout << ret << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<ll> vll; int main() { ld k; cin>>k; string s,t; cin>>s>>t; s.erase(s.end()-1); t.erase(t.end()-1); vll v(9,k),w1(9,0),w2(9,0); for(auto i:s) { ll a=i-'1'; v[a]--; w1[a]++; } for(auto i:t) { ll a=i-'1'; v[a]--; w2[a]++; } ld sum=0; for(int i=0;i<9;i++) { for(int j=0;j<9;j++) { ll a=0,b=0,temp; w1[i]++; w2[j]++; for(int l=1;l<10;l++) { a+=l*pow(10,w1[l-1]); b+=l*pow(10,w2[l-1]); } if(a>b) { temp=v[i]; v[i]--; sum+= temp*v[j]; v[i]++; } w1[i]--; w2[j]--; } } k=9*k-8; ld ans=sum/(k*(k-1)); cout<<ans; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--) #define rrep(i,n) RREP(i,(n)-1,0) #define all(v) v.begin(), v.end() #define endk '\n' const int inf = 1e9+7; const ll longinf = 1LL<<60; const ll mod = 1e9+7; const ll mod2 = 998244353; const ld eps = 1e-10; template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;} template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;} int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<int> P(n, -1); vector<vector<int>> G(n); REP(i, 1, n) { cin >> P[i]; P[i]--; G[P[i]].push_back(i); } vector<int> in(n), out(n); vector<vector<int>> D(n); int tmp = 0; auto dfs = [&](auto dfs, int cur, int depth) -> void { in[cur] = tmp++; D[depth].push_back(in[cur]); for(int ne: G[cur]) { dfs(dfs, ne, depth+1); } out[cur] = tmp++; D[depth].push_back(out[cur]); }; dfs(dfs, 0, 0); int q; cin >> q; rep(i, q) { int u, d; cin >> u >> d; u--; cout << (upper_bound(all(D[d]), out[u]) - lower_bound(all(D[d]), in[u])) / 2 << endk; } return 0; }
#include<bits/stdc++.h> using namespace std; int b[200005]; int main() { int N,min=0; cin>>N; for(int i=1;i<=N;i++) { int n; scanf("%d",&n); b[n]++; if(n==min) { for(int j=n;;j++) { if(b[j]==0) { min=j; break; } } } printf("%d\n",min); } }
#include <bits/stdc++.h> using namespace std; int main() { string n; getline (cin,n); int s=0; for (int i=0;i<(int) n.length();i++) { s+=((int) n[i]-'0'); } if (s<3) { cout<<-1; goto here; } else if (s%3==0) { cout<<0; goto here; } else if (s%3==1) { int l=0, m=0; for (int i=0;i<(int)n.length();i++) { if (((int)n[i]-'0')%3==1 ) { l++; } else if (((int)n[i]-'0')%3==2 ) { m++; } } if (((l>=1)&&(int)n.length()>1) || ((m>=2 ) && (n.length()>2))) { cout<< ((l>=1) ? (1) :(2)); goto here; } else { cout<<-1; goto here; } } else if (s%3==2) { int l=0, m=0; for (int i=0;i<(int)n.length();i++) { if (((int)n[i]-'0')%3==2 ) { m++; } else if (((int)n[i]-'0')%3==1 ) { l++; } } if (((m>=1)&&(int)n.length()>1) || ((l>=2 ) && (n.length()>2))) { cout<< ((m>=1) ? (1) :(2)); goto here; } else { cout<<-1; goto here; } } here:; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string N; cin >> N; int length; int count=0; length = N.size(); int x=0; for (int i=0;i<length-1;i++) { if(N.at(length-1-i)=='0'){ count++; }else{ break; } } for (int i=0;i<1+(length-count)/2;i++){ if(N.at(i)!=N.at(length-count-1-i)){ x++; break; } } if(x==0){ cout << "Yes" << endl; }else{ cout << "No" << endl; } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update #include <functional> // for less #include <iostream> using namespace __gnu_pbds; using namespace std; #define int long long #define mod 1000000007 void solve() { int n; cin>>n; int st=1; int en=n; int ans=-1; while(st<=en) { int mid=(st+en)/2; if((mid*(mid+1))/2 >=n) {ans=mid; en=mid-1; } else st=mid+1; } cout<<ans<<endl; return; } int32_t main() { #ifndef ONLINE_JUDGE freopen("inp.txt", "r", stdin); freopen("m3.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int t; //cin>>t; t=1; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> #define int long long #define ld long double #define endl '\n' using namespace std; int Power(int Num,int Index){ int r=1 ; for(int i=Index;i>0;i/=2,Num*=Num){ if(i%2==1){ r*=Num ; } } return r ; } int Factorial(int Number){ int m=1; for(int i=1;i<=Number;i++){ m*=i; } return m; } int BinToDec(string Bin){ int n=0; for(int i=Bin.size()-1;i>=0;i--){ n+=(Bin[Bin.size()-1-i]-'0')*Power(2,i); } return n; } int HexadecToDec(string Hex){ int n=0; for(int i=Hex.size()-1;i>=0;i--){ if(Hex[i]>='A'&&Hex[i]<='F'){ n+=(Hex[i]-'A'+10)*Power(16,Hex.size()-i-1); } else{ n+=(Hex[i]-'0')*Power(16,Hex.size()-1-i); } } return n; } int nCr(int Num1,int Num2){ int k=1; for(int i=Num1-Num2+1;i<=Num1;i++){ k*=i; } int x=k/(Factorial(Num2)); return x; } string DecToBin(int Num){ string k=""; while(Num){ int r=Num%2; string a=to_string(r); k+=a; Num/=2; } reverse(k.begin(),k.end()); return k; } string DecToHexadec(int Num){ string k=""; while(Num){ int r=Num%16; if(r<=9){ string a=to_string(r); k+=a; } else{ k+=(r-10+'A'); } Num/=16; } reverse(k.begin(),k.end()); return k; } bool VowelChecker(char Letter){ Letter=tolower(Letter); if(Letter=='a'||Letter=='e'||Letter=='i'||Letter=='o'||Letter=='u'){ return true; } else{ return false; } } bool PrimeChecker(int Num){ bool ok=true; for(int i=2;i<=sqrt(Num);i++){ if(Num%i==0){ ok=false; } } if(ok==true){ return true; } else{ return false; } } bool Palindrome(string Word){ string c=Word; reverse(c.begin(),c.end()); if(c==Word){ return true; } else{ return false; } } vector<int> Factors(int Num){ vector<int>s; for(int i=1;i*i<=Num;i++){ if(Num%i==0){ if(Num/i==i){ s.push_back(i) ; } else{ s.push_back(i) ; s.push_back(Num/i) ; } } } sort(s.begin(),s.end()); return s ; } vector<int> PrimeFactorisation(int Num){ vector<int>p; while(Num%2==0){ p.push_back(2); Num/=2; } for(int i=3;i<=sqrt(Num);i+=2){ while(Num%i==0){ p.push_back(i); Num/=i; } } if(Num>2){ p.push_back(Num); } return p; } vector<int> SieveOfEratosthenes(int Num){ vector<int>s; bool prime[Num+1]; memset(prime,true,sizeof(prime)); for(int p=2;p*p<=Num;p++){ if (prime[p]==true){ for(int i=p*p;i<=Num;i+=p){ prime[i]=false; } } } for (int p=2;p<=Num;p++){ if (prime[p]){ s.push_back(p); } } return s; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int tc ; tc = 1 ; // cin >> tc ; while(tc--){ int n;cin>>n; for(int i=1;i<=n;i++){ if((i*(i+1))/2>=n){ cout << i ;break; } } } return 0; }
#include<bits/stdc++.h> namespace my_std{ using namespace std; #define pii pair<int,int> #define fir first #define sec second #define MP make_pair #define rep(i,x,y) for (int i=(x);i<=(y);i++) #define drep(i,x,y) for (int i=(x);i>=(y);i--) #define go(x) for (int i=head[x];i;i=edge[i].nxt) #define templ template<typename T> #define sz 202020 typedef long long ll; typedef double db; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);} templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;} templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;} templ inline void read(T& t) { t=0;char f=0,ch=getchar();double d=0.1; while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar(); while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar(); if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();} t=(f?-t:t); } template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);} char __sr[1<<21],__z[20];int __C=-1,__zz=0; inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;} inline void print(int x) { if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x; while(__z[++__zz]=x%10+48,x/=10); while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n'; } void file() { #ifdef NTFOrz freopen("a.in","r",stdin); #endif } inline void chktime() { #ifdef NTFOrz cerr<<clock()/1000.0<<'\n'; #endif } #ifdef mod ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;} ll inv(ll x){return ksm(x,mod-2);} #else ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;} #endif // inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;} } using namespace my_std; int n; vector<ll>a[3]; int main() { file(); map<char,int>mp; mp['R']=0,mp['G']=1,mp['B']=2; read(n); ll x; char cc; rep(i,1,n*2) read(x),cin>>cc,a[mp[cc]].push_back(x); rep(i,0,2) sort(a[i].begin(),a[i].end()); auto qq=[&](int id,ll w) { if (!a[id].size()) return ll(1e18); int t=lower_bound(a[id].begin(),a[id].end(),w)-a[id].begin(); ll res=1e18; if (t) chkmin(res,w-a[id][t-1]); if (t!=(int)a[id].size()) chkmin(res,a[id][t]-w); return res; }; int c=0,p=0; rep(i,0,2) if (a[i].size()%2==0u) ++c,p=i; if (c==3) return puts("0"),0; ll ans=1e18; rep(i,0,2) if (i!=p) for (auto x:a[i]) chkmin(ans,qq(3-i-p,x)); int p1=(p==0?1:0),p2=3-p-p1; auto wk=[&](){ll mn=1e18;for (auto x:a[p]) chkmin(ans,mn+qq(p2,x)),chkmin(mn,qq(p1,x));}; wk(); swap(p1,p2); wk(); cout<<ans; return 0; }
#include <cstdio> #include <vector> #include <algorithm> using namespace std; #define int long long vector < int > G[3]; int n, pos_l, pos_r; int id( char ch ) { if( ch == 'R' ) return 0; if( ch == 'B' ) return 1; if( ch == 'G' ) return 2; } int Fabs( int x ) { return x < 0 ? -x : x; } void work( int c, int val ) { int l = 0, r = G[c].size() - 1; pos_l = 0, pos_r = G[c].size() - 1; while( l <= r ) { int mid = ( l + r ) >> 1; if( G[c][mid] <= val ) pos_l = mid, l = mid + 1; else r = mid - 1; } l = 0, r = G[c].size() - 1; while( l <= r ) { int mid = ( l + r ) >> 1; if( G[c][mid] >= val ) pos_r = mid, r = mid - 1; else l = mid + 1; } } signed main() { scanf( "%lld", &n ); for( int i = 1;i <= ( n << 1 );i ++ ) { char c; int a; scanf( "%lld %c", &a, &c ); G[id( c )].push_back( a ); } int c1 = -1, c2 = -1; for( int i = 0;i < 3;i ++ ) if( G[i].size() & 1 ) { if( ~ c1 ) c2 = i; else c1 = i; } if( c1 == -1 ) return ! printf( "0\n" ); else { int ans = 1e18; sort( G[c2].begin(), G[c2].end() ); for( int i = 0;i < G[c1].size();i ++ ) { work( c2, G[c1][i] ); ans = min( ans, min( Fabs( G[c1][i] - G[c2][pos_l] ), Fabs( G[c2][pos_r] - G[c1][i] ) ) ); } int ans1 = 1e18, ans2 = 1e18, c; for( int i = 0;i < 3;i ++ ) if( c1 == i || c2 == i ) continue; else c = i; if( ! G[c].size() ) goto pass; sort( G[c].begin(), G[c].end() ); for( int i = 0;i < G[c1].size();i ++ ) { work( c, G[c1][i] ); ans1 = min( ans1, min( Fabs( G[c1][i] - G[c][pos_l] ), Fabs( G[c][pos_r] - G[c1][i] ) ) ); } for( int i = 0;i < G[c2].size();i ++ ) { work( c, G[c2][i] ); ans2 = min( ans2, min( Fabs( G[c2][i] - G[c][pos_l] ), Fabs( G[c][pos_r] - G[c2][i] ) ) ); } pass : printf( "%lld\n", min( ans, ans1 + ans2 ) ); } return 0; }
#ifdef xay5421 #define D(...) fprintf(stderr,__VA_ARGS__) #else #define D(...) ((void)0) #define NDEBUG #endif #include<bits/stdc++.h> #define int long long #define LL long long #define MP make_pair #define PB push_back #define X first #define Y second #define SZ(x) ((int)(x).size()) #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define per(i,a,b) for(int i=(a);i>=(b);--i) using namespace std; typedef pair<int,int>PII;typedef vector<int>VI;typedef vector<PII>VII; template<typename T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;} template<typename T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);} const int N=100005; int n,L,a[N],b[N],ans; vector<int>G[N]; map<int,int>lst,sum; void sol(){ lst.clear(),sum.clear(),lst[0]=0; rep(i,1,n)a[i]-=i,b[i]-=i; rep(i,1,n){ lst[a[i]]=i; if(b[i]<a[i]){ if(!lst.count(b[i]))puts("-1"),exit(0); ans+=i-lst[b[i]]; ans-=sum[b[i]]; sum[b[i]]=i-lst[b[i]]; } } rep(i,1,n)a[i]+=i,b[i]+=i; } signed main(){ rd(n),rd(L); rep(i,1,n)rd(a[i]); rep(i,1,n)rd(b[i]); sol(); rep(i,1,n)a[i]=L-a[i]+1,b[i]=L-b[i]+1; reverse(a+1,a+1+n); reverse(b+1,b+1+n); sol(); pt(ans,'\n'); return 0; }
#include <iostream> #include <vector> #include <queue> using pli = std::pair<int64_t, int>; struct Edge { Edge(int to, int t_p, int c) : to(to), t_point(t_p), cost(c) {} int to, t_point, cost; }; int64_t earliest_time(const std::vector<std::vector<Edge>>& graph, int n, int from, int to) { std::priority_queue<pli, std::vector<pli>, std::greater<pli>> que; std::vector<bool> used(n + 1, false); que.emplace(0, from); while (!que.empty()) { pli cur = que.top(); que.pop(); int64_t arrival = cur.first; int v = cur.second; if (v == to) return arrival; if (used[v]) continue; used[v] = true; for (const auto& edge : graph[v]) { if (used[edge.to]) continue; int64_t leave = (arrival + edge.t_point - 1) / edge.t_point * edge.t_point; que.emplace(leave + edge.cost, edge.to); } } return -1; } int main() { int n, m, from, to; std::cin >> n >> m >> from >> to; std::vector<std::vector<Edge>> graph(n + 1, std::vector<Edge>()); for (int i = 0; i < m; ++i) { int u, v, t_p, c; std::cin >> u >> v >> c >> t_p; graph[u].emplace_back(v, t_p, c); graph[v].emplace_back(u, t_p, c); } std::cout << earliest_time(graph, n, from, to) << std::endl; return 0; }
using namespace std; #include <bits/stdc++.h> #define ll long long ll n,m; struct Num{ ll a,b; }; Num mul(Num x,Num y){ Num z; z.a=x.a*y.a%m; z.b=(x.a*y.a/m+x.a*y.b+x.b*y.a)%m; return z; } Num qpow(ll x,ll y){ Num z={x%m,x/m%m},r={1,0}; for (;y;y>>=1,z=mul(z,z)) if (y&1) r=mul(r,z); return r; } int main(){ scanf("%lld%lld",&n,&m); if (m==1){ printf("0\n"); return 0; } ll ans=qpow(10,n).b; printf("%lld\n",ans); return 0; }
#include <iostream> #include<bits/stdc++.h> using namespace std; int numwall,killo; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>killo>>numwall; cout<<killo/numwall; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using Vll =vector<ll>; using VVll =vector<vector<ll>>; template <class T> using Vec = vector<T>; template <class T> using VVec = vector<vector<T>>; #define INF 9223372036854775807LL/2 void Z(ll i=-1){ if(i==-1)cout<<"Test"<<endl; else cout<<"Test"<<i<<endl; } template <class T> void VVcout(VVec<T> A){ for(auto Vi:A) { for(auto i:Vi)cout<<i<<' '; cout<<endl;}} template <class T> void Vcout(Vec<T> A){ for(auto i:A) cout<<i<<' '; cout<<endl;} template <class T> void chmax(T &x,T y){if(x<y) x=y;} template <class T> void chmin(T &x,T y){if(x==-1 || x>y) x=y;} #define rep(i,n) for(ll i=0;i<n;i++) #define reps(si, i,n) for(ll i=si;i<n;i++) ll mod=1000000007; int main(){ ll n,a,l,s; cin>>n; Vll A(n); rep (i,n)cin>>A.at(i); VVll ls(n,Vll(2,0)); //Z(); ls.at(0)={1,A.at(0)}; if(n>1) ls.at(1)={2,(2*A.at(0))%mod}; //Z(); reps(2,i,n){ a=A.at(i); ll a1=A.at(i-1); ll s1=ls.at(i-1).at(1); ll s2=ls.at(i-2).at(1); ll l1=ls.at(i-1).at(0); ll l2=ls.at(i-2).at(0); ls.at(i)={(l1+l2) % mod,(s1 +((a*l1)% mod ) +s2 +(((a1-a)*l2)% mod ) )% mod}; } cout<<ls.at(n-1).at(1)<<endl; }
#include<bits/stdc++.h> #include<ext/pb_ds/tree_policy.hpp> #include<ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template<typename temp>using ordered_set = tree<temp, null_type, less_equal<temp>, rb_tree_tag,tree_order_statistics_node_update>; //order_of_key(k) : Number of items strictly smaller than k . //find_by_order(k) : K-th element in a set (counting from zero).//*(ost.find_by_order(k)) #define PI acos(-1) #define ll long long //int dx[]={-1,1,0,0}; //int dy[]={0,0,-1,1}; //int dx[]={-1,0,1,-1,1,-1,0,1}; //int dy[]={1,1,1,0,0,-1,-1,-1}; const int M=1e5+5; const int N=2e5+5; const int mod=1e9+7; int n; bool visited[M][2]; long long a[M],dp[M][2][2]; void DP(int idx,bool sgn) { if(visited[idx][sgn])return; visited[idx][sgn]=1; if(idx == n) { if(sgn)dp[idx][sgn][0]=a[idx]; else dp[idx][sgn][0]=-a[idx]; dp[idx][sgn][1]=1; return; } if(sgn) { DP(idx+1,0); DP(idx+1,1); dp[idx][1][0]+=a[idx]*dp[idx+1][0][1]+dp[idx+1][0][0]; dp[idx][1][0]+=a[idx]*dp[idx+1][1][1]+dp[idx+1][1][0]; dp[idx][1][1]+=dp[idx+1][0][1]+dp[idx+1][1][1]; dp[idx][1][0]%=mod,dp[idx][1][1]%=mod; } else { DP(idx+1,1); dp[idx][0][0]=-a[idx]*dp[idx+1][1][1]+dp[idx+1][1][0]; dp[idx][0][1]=dp[idx+1][1][1]; dp[idx][0][0]%=mod; } if(dp[idx][sgn][0] < 0)dp[idx][sgn][0]+=mod; if(dp[idx][sgn][1] < 0)dp[idx][sgn][1]+=mod; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int i; cin >> n; for(i=1; i<=n; i++)cin >> a[i]; if(n == 1) { cout << a[1]; return 0; } DP(1,1); cout << dp[1][1][0]; return 0; }
#include <bits/stdc++.h> using namespace std; #define PRINT_YesNo(condition) cout<<((condition)?"Yes":"No")<<endl #define PRINT_YESNO(condition) cout<<((condition)?"YES":"NO")<<endl #define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr) #define SET_PRECISION(x) cout<< fixed << setprecision((x)) typedef long long ll; typedef vector<int> vi_t; typedef vector<vector<int> > vvi_t; typedef vector<ll> vl_t; typedef vector<vector<ll> > vvl_t; string dec2Naray(ll x, int n); vi_t str2numvec(const std::string& str); vector<string> split(const string &str, char delim); //=====================// // メ イ ン 関 数 //  //=====================// int main() { __MAGIC__; int A, B, C; cin >> A >> B >> C; cout << 21 - (A+B+C) << endl; return 0; } //----------------------------- // ヘルパー関数群 //----------------------------- string dec2Naray(ll x, int n) { // 10進数 → n進数 変換を行う // 9進数までにしか対応してないので注意 // 16進数ぐらいまでは拡張した方が良さそう // n進数 → 10進数 変換も用意すべき string s; while( x ) { s = to_string(x%n) + s; x /= n; } return s; } vi_t str2numvec(const std::string& str) { vi_t v(str.size()); for(int i=0, n=str.size(); i<n; ++i) { v[i] = str[i] - '0'; } return v; } vector<string> split(const string &str, char delim){ vector<string> res; size_t current = 0, found; while((found = str.find_first_of(delim, current)) != string::npos){ res.push_back(string(str, current, found - current)); current = found + 1; } res.push_back(string(str, current, str.size() - current)); return res; }
#include <iostream> using namespace std; int main() { char a, b, c; cin >> a >> b >> c; cout << b << c << a; 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; template <class T> using vt = vector<T>; using vvi = vector<vt<int>>; int my_sum(int n){ return (1+n)*n/2; } void solve(int *E, int a, int b, int k){ rep(i,k){ E[i] = i+1; } int tmp = 0; rep(i,a+b-k-1){ E[i+k] = i+1; tmp += i+1; } E[a+b-1] = my_sum(k) - tmp; if (k == a) { rep(i,b){ E[i+k] = -E[i+k]; } } else { rep(i,b) { E[i] = -E[i]; } } } int main(){ int A,B; cin >> A >> B; int AB = A + B; int E[100000] = {}; if (A > B) { solve(E,A,B,A); } else if (B > A) { solve(E,A,B,B); } else { rep(i,A){ E[i] = i+1; } rep(i,A+B){ E[i+A] = -i-1; } } rep(i,AB){ cout << E[i] << ' '; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod1 = 1000000007; using ll = long long; long long pow(long x,long n){ long long ans = 1; while(n != 0){ long long a = x; long long z = 1; while(z*2 <= n){ a *=a; a=a%mod1; z*=2; } ans*=a; ans=ans%mod1; n-=z; } return ans; }//累乗 x^n template<typename T> void input_vec(vector<T> &A,long long N){ for(int i = 0; i < N; i++){ cin >> A.at(i); } return; }//入力を配列で受け取る template<typename T> void output_vec(vector<T> &A,long long N){ for(int i = 0; i < N; i++){ if(i != 0){ cout << " "; } cout << A.at(i); } cout << endl; return; }//配列を出力 template<typename T> long long count_vec(vector<T> &A,T x){ long long counter = 0; for(int i = 0; i < (int)A.size(); i++){ if(A.at(i) == x){ counter++; } } return counter; }//配列内のxの個数をreturn vector<char> change_vec(string s,int n){ vector<char> ans(n); for(int i = 0; i < n; i++){ ans.at(i) = s.at(i); } return ans; }//長さがnの文字列を配列に変換 vector<ll> change_vec2(ll x){ vector<ll> ans; while(x != 0){ ans.push_back(x%10); x/=10; } return ans; }//数列を配列に変換 ll sort_big(ll x){ vector<ll> vec = change_vec2(x); sort(vec.begin(),vec.end()); ll ans = 0; for(int i = (int)vec.size()-1; i >= 0 ; i--){ ans += vec.at(i); if(i != 0) ans*=10; } return ans; }//桁ごとに大きい順に並べ替え ll sort_small(ll x){ vector<ll> vec = change_vec2(x); sort(vec.begin(),vec.end()); ll ans = 0; for(int i = 0; i < (int)vec.size();i++){ ans += vec.at(i); if(i+1 != (int)vec.size()) ans*= 10; } return ans; }//桁ごとに小さい順に並べ替え int main(){ ll A,B;cin >> A >> B; vector<ll> Ea(A); vector<ll> Eb(B); ll sum = 0; ll afinish = 0; ll bfinish = 0; for(int i = 0; i+1 < A; i++){ Ea.at(i) = i+1; sum+=Ea.at(i); afinish = i+1; } for(int i = 0; i+1 < B; i++){ Eb.at(i) = i*-1-1; sum+=Eb.at(i); bfinish = i*-1; } if(A>B){ Ea.at(A-1) = afinish+1; sum+=Ea.at(A-1); Eb.at(B-1) = sum*-1; } else{ //cout << bfinish << endl; Eb.at(B-1) = bfinish-1-1; sum += Eb.at(B-1); Ea.at(A-1) = sum*-1; } for(int i = 0; i < A; i++){ cout << Ea.at(i) << " "; } for(int i = 0; i < B; i++){ if(i+1 == B)cout << Eb.at(i) << endl; else cout << Eb.at(i) << " "; } }
#include <bits/stdc++.h> using ll = int64_t; int main(){ ll n,m,q; std::cin>>n>>m>>q; std::vector<std::pair<ll,ll>> vw; for(ll i=0;i<n;i++){ ll w,v; std::cin>>w>>v; vw.emplace_back(std::make_pair(v,w)); } std::vector<ll> box; for(ll i=0;i<m;i++){ ll tmp; std::cin>>tmp; box.emplace_back(tmp); } while(q--){ std::vector<ll> as; ll l,r,max = 0; std::cin>>l>>r; l--;r--; for(ll i=0;i<m;i++){ if(i == l){ i = r; continue; } as.emplace_back(box[i]); } std::sort(as.begin(),as.end()); // std::cout<<"chosen box\n"; // for(int x : as) std::cout<<x<<" "; std::vector<bool> used(n); for(ll a : as){ std::pair<ll,ll> best(-1,-1); for(ll i=0;i<n;i++){ if(used[i]) continue; if(vw[i].second > a) continue; best = std::max(best,std::pair<ll,ll>(vw[i].first,i)); } if(best.second == -1) continue; used[best.second] = true; max += best.first; // std::cout<<"tmp : "<<max<<"\n"; } std::cout<<max<<"\n"; } }
/* Author : Nishant Gupta 2.0 */ #include<bits/stdc++.h> using namespace std; #define LL long long int #define getcx getchar_unlocked #define X first #define Y second #define PB push_back #define MP make_pair #define MAX 100005 #define LOG_MAX 20 #define MOD 1000000007 #define INF 0x3f3f3f3f #define INFL (LL(1e18)) #define chk(a) cerr << endl << #a << " : " << a << endl #define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl #define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl #define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl #define rep(i, a, n) for(i=a;i<n;i++) #define rev(i, a, n) for(i=a;i>=n;i--) #define in(x) scanf("%d", &x) #define inl(x) scanf("%lld", &x) #define in2(x, y) scanf("%d %d", &x, &y) #define inl2(x, y) scanf("%lld %lld", &x, &y) #define MSV(A,a) memset(A, a, sizeof(A)) #define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++) #define finish(x) {cout<<x<<'\n'; return;} typedef pair<int, int> pi; typedef pair<LL, LL> pl; const char en = '\n'; vector<int> ans; int col[MAX]; vector<int> c(MAX); vector<int> adj[MAX]; void dfs(int node, int p) { if(col[c[node]] == 0) { ans.PB(node); } col[c[node]]++; for(int i=0;i<adj[node].size();i++) { if(adj[node][i] != p) dfs(adj[node][i], node); } col[c[node]]--; } void solve() { int n; in(n); int u, v; for(int i=1;i<=n;i++) { in(c[i]); } for(int i=0;i<n-1;i++) { in2(u, v); adj[u].PB(v); adj[v].PB(u); } dfs(1, -1); sort(ans.begin(), ans.end()); for(int i=0;i<ans.size();i++) { cout<<ans[i]<<en; } } int main() { int t = 1; //~cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define int long long #ifdef WIN_32 #define getchar_unlocked _getchar_nolock #endif #define mp make_pair #define mt make_tuple #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define eb emplace_back #define g0(a) get<0>(a) #define g1(a) get<1>(a) #define g2(a) get<2>(a) #define g3(a) get<3>(a) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef double db; typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef tuple<int, int, int> iii; typedef tuple<int, int, int, int> iiii; typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; int N, M, A, B, cnt, mem[1 << 20], link[25], sz[25], tmpmap[25]; bool good[1 << 20]; bool C[25][25]; int find(int x) { if (x == link[x]) return x; return link[x] = find(link[x]); } void unite(int a, int b) { a = find(a); b = find(b); if (a == b) return; if (sz[a] < sz[b]) swap(a, b); sz[a] += sz[b]; link[b] = a; } bool is(int bm) { vector<int> tmp; for (int i = 0; i < N; i++) if (bm & (1 << i)) tmp.pb(i + 1); for (int i : tmp) for (int j : tmp) if (i != j && !C[i][j]) return 0; return 1; } int dp(int bm) { if (mem[bm] != -1) return mem[bm]; if (bm == 0) return 0; int ans = 1e9; for (int s = bm; s; s = (s - 1) & bm) if (good[s]) ans = min(ans, 1 + dp(bm ^ s)); return mem[bm] = ans; } main() { memset(mem, -1, sizeof mem); //ios::sync_with_stdio(0); //cin.tie(0); cin >> N >> M; for (int i = 1; i <= N; i++) { link[i] = i; sz[i] = 1; } for (int i = 1; i <= M; i++) { cin >> A >> B; C[A][B] = C[B][A] = 1; } for (int i = 1; i <= N; i++) for (int j = i + 1; j <= N; j++) if (!C[i][j]) { //cout << i << ' ' << j << '\n'; unite(i, j); } for (int i = 0; i < (1 << N); i++) { good[i] = is(i); //if (good[i]) cout << i << '\n'; } cout << dp((1 << N) - 1) << '\n'; }
#include <bits/stdc++.h> #define be(v) (v).begin(),(v).end() #define pb(q) push_back(q) #define rep(i, n) for(int i=0;i<n;i++) #define all(i, v) for(auto& i : v) typedef long long ll; using namespace std; const ll mod=1000000007, INF=(1LL<<60); #define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int n, m, a, b; cin >> n >> m; bool ok[n][n]; memset(ok, 0, sizeof(ok)); rep(i, m){ cin >> a >> b; a--; b--; ok[a][b] = ok[b][a] = true; } rep(i, n) ok[i][i] = true; m = 1 << n; bool connect[m]; memset(connect, 0, sizeof(connect)); connect[0] = 1; rep(bit, m){ rep(i, n) if(bit >> i & 1){ if(!connect[bit - (1 << i)]) continue; bool c = true; rep(j, n) if(bit >> j & 1){ if(!ok[i][j]) c = false; } if(c){ connect[bit] = true; break; } } } int cost[m]; rep(i, m) cost[i] = 20; cost[0] = 0; rep(bit, m){ if(connect[bit]) { cost[bit] = 1; continue; } int i = (bit - 1) & bit; for(;i>=1;i=(i-1)&bit){ cost[bit] = min(cost[bit], cost[i] + cost[bit - i]); } } cout << cost[m - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int m, h; cin >> m >> h; if(h % m == 0){ cout << "Yes" << endl; }else{ cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ll long long #define FI first #define SE second #define pb push_back #define eb emplace_back #define mod 1000000007 #define all(c) (c).begin(),(c).end() #define LB lower_bound #define UB upper_bound #define max3(a,b,c) max(c,max(a,b)) #define min3(a,b,c) min(c,min(a,b)) #define mems(s, n) memset(s, n, sizeof(s)) #define NINF -1e18 #define INF 1e18 #define int ll int #define endl '\n' #define double long double #define OOK order_of_key //no of elements less than #define FBO find_by_order //iterator pointing kth element;indexing starts from 0 #define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl #define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl typedef pair<int,int> PII; typedef pair<pair<int,int>,int> PPII; typedef pair<int,pair<int,int>> PIPI; typedef map<int,int>MII; typedef vector<int> VI; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; /*int power(int a, int b) {int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;} */ signed main() { ios::sync_with_stdio(false); cin.tie(0); int T=1,T1=0;//cin>>T; while(T1++<T) {//cout<<"Case #"<<T1<<": "; int m,h; cin>>m>>h; if(h%m==0)cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; if (a + b == c + d) cout << "Yes" << endl; else if (a + c == b + d) cout << "Yes" << endl; else if (a + d == b + c) cout << "Yes" << endl; else if (a + b + c == d) cout << "Yes" << endl; else if (a + b + d == c) cout << "Yes" << endl; else if (a + c + d == b) cout << "Yes" << endl; else if (b + c + d == a) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define v vector #define umap unordered_map #define pb push_back #define mp make_pair #define pob pop_back #define db1(x) cout<<#x<<" = "<<x<<'\n' #define db2(x, y) cout<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<'\n' #define db3(x, y, z) cout<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<", "<<#z<<" = "<<z<<'\n' //#define for(i, n) for(int i=0;i<(n);++i) #define fora(i, a, n) for(int i=a;i<=(n);++i) #define ford(i, a, n) for(int i=a;i>=(n);--i) bool compare(int a, int b) { return a > b; } 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 cookies[4]; for (int i = 0; i < 4; i++) cin >> cookies[i]; bool ans = false; int sum; for (int i = 0; i < 4; i++) { sum = 0; for (int j = 0; j < 4; j++) { if (j == i) continue; sum += cookies[j]; } if (cookies[i] == sum) { ans = true; break; } } if (ans == false) { if (cookies[0] + cookies[1] == cookies[2] + cookies[3]) ans = true; else if (cookies[0] + cookies[2] == cookies[1] + cookies[3]) ans = true; else if (cookies[0] + cookies[3] == cookies[2] + cookies[1]) ans = true; } cout << (ans == true ? "Yes" : "No"); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int main(){ int n; scanf("%d",&n); vector<int> a(n),b(n),p(n); rep(i,n) scanf("%d",&a[i]); rep(i,n) scanf("%d",&b[i]); rep(i,n) scanf("%d",&p[i]), p[i]--; vector<int> inv(n); rep(i,n) inv[p[i]]=i; vector<int> q(n); iota(q.begin(),q.end(),0); sort(q.begin(),q.end(),[&](int i,int j){ return a[i]<a[j]; }); vector<pair<int,int>> ans; for(int i:q){ if(p[i]==i) continue; if(a[i]<=b[p[i]]){ puts("-1"); return 0; } ans.emplace_back(i,inv[i]); p[inv[i]]=p[i]; inv[p[i]]=inv[i]; p[i]=i; inv[i]=i; } printf("%ld\n",ans.size()); for(auto [i,j]:ans) printf("%d %d\n",i+1,j+1); return 0; }
#include <bits/stdc++.h> using namespace std; 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...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif /* sorry, this is the bare minimum :'( */ using ll = long long; using ii = pair<int, int>; using vi = vector<int>; #define all(v) begin(v), end(v) #define sz(v) (int)(v).size() #define fi first #define se second int main(int argc, char const *argv[]) { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); #ifdef LOCAL freopen("in", "r", stdin); #endif int n; cin >> n; vi a(n), b(n), p(n); for(int& x : a) cin >> x, x--; for(int& x : b) cin >> x, x--; for(int& x : p) cin >> x, x--; debug(a, b, p); vi host(n), to(n), what(n), from(n); set<ii> st; for(int i = 0; i < n; ++i) { from[p[i]] = i; to[i] = p[i]; what[i] = b[p[i]]; if(p[i] != i) { st.insert(ii(what[i], i)); } } vector<ii> ans; while(st.size()) { debug(st); int y = st.begin() -> second; st.erase(st.begin()); if(from[y] == y) continue; int x = from[y]; if(what[x] >= a[x] or what[y] >= a[y]) { cout << "-1" << endl; exit(0); } ans.emplace_back(x+1, y+1); st.erase(ii(what[x], x)); what[x] = what[y]; st.insert(ii(what[x], x)); to[x] = to[y]; from[to[x]] = x; } cout << sz(ans) << "\n"; for(ii& pa : ans) { cout << pa.fi << ' ' << pa.se << "\n"; } return 0; }
#include<bits/stdc++.h> using namespace std; int n,q; long long a[100010]; long long x[100010]; int main(){ cin>>n>>q; for(int i=1;i<=n;i++)cin>>a[i]; for(int i=1;i<=n;i++)x[i]=a[i]-i; long long id; while(q--){ cin>>id; long long ans; if(id>x[n]){ ans=id-x[n]+a[n]; cout<<ans<<endl; continue; } int pos=lower_bound(x+1,x+n+1,id)-x; ans=id-x[pos-1]+a[pos-1]; cout<<ans<<endl; } }
#include <cmath> #include <deque> #include <algorithm> #include <iterator> #include <list> #include <tuple> #include <map> #include <unordered_map> #include <queue> #include <set> #include <unordered_set> #include <stack> #include <string> #include <vector> #include <fstream> #include <iostream> #include <functional> #include <numeric> #include <iomanip> #include <stdio.h> //eolibraries #define lnf 3999999999999999999 #define inf 999999999 #define PI 3.14159265359 #define endl "\n" #define fi first #define se second #define pb push_back #define eb emplace_back #define ll long long #define all(c) (c).begin(),(c).end() #define sz(c) (int)(c).size() #define mkp(a,b) make_pair(a,b) #define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end()) #define rsz(a,n) a.resize(n) #define pii pair <int,int> #define rep(i,n) for(int i = 0 ; i < n ; i++) #define drep(i,n) for(int i = n-1 ; i >= 0 ; i--) #define crep(i,x,n) for(int i = x ; i < n ; i++) #define vi vector <int> #define vec(s) vector<s> #define rsz(a,n) a.resize(n) #define rszv(a,n,v) a.resize(n,v) #define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); //eodefine const int max_n = 100000; using namespace std; int main(){ fcin; int n,k; cin>>n>>k; int ans=0; crep(i,1,n+1) { crep(j,1,k+1) { ans += i*100+j; } } cout << ans << "\n"; /* */ return 0; }
#include <iostream> using namespace std; int main() { int N, X; cin >> N >> X; X *= 100; int x = 0; for (int n = 1; n <= N; ++n) { int V, P; cin >> V >> P; x += V*P; if (X < x) { cout << n << endl; return 0; } } cout << -1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fast_io cin.tie(0);ios_base::sync_with_stdio(0); string to_string(string s) { return '"' + s + '"';} string to_string(char s) { return string(1, s);} string to_string(const char* s) { return to_string((string) s);} string to_string(bool b) { return (b ? "true" : "false");} template <typename A> string to_string(A); 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 f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";} void debug_out() { cout << endl; } void show() { cout << endl; } void pret() { cout << endl; exit(0);} template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);} template <typename Head, typename... Tail> void show(Head H, Tail... T) {cout <<H<<" "; show(T...);} template <typename Head, typename... Tail> void pret(Head H, Tail... T) {cout <<H<<" "; pret(T...);} #define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) typedef long long ll; #define int ll typedef long double ld; typedef vector<int> vi; #define disp(x) cout<<x<<" "; #define rep(i,a,b) for(int i=a;i<(int)b;i++) #define fo(i,a,b) for(int i=a;i<=(int)b;i++) #define rf(i,a,b) for(int i=a;i>=(int)b;i--) #define mp make_pair #define pb emplace_back #define F first #define S second #define endl '\n' //cout.setf(ios::fixed);cout.precision(18) const int MOD = 1e9+7; const int maxn = 300000+10; int32_t main(){ fast_io; int n, x; cin >> n >> x; x *= 100; int val = 0; fo(i, 1, n){ int v, p; cin >> v >> p; val += (v * p); if(val > x){ pret(i); } } show(-1); return 0; }
#include<bits/stdc++.h> using namespace std; #define all(x) (x).begin(),(x).end() #define pb push_back #define pf push_front #define sz(x) (int)(x).size() #define lb lower_bound #define ub upper_bound #define mp make_pair #define fi first #define se second #define setbits(x) __builtin_popcount(x) #define zerobits(x) __builtin_ctz(x) #define setbitsll(x) __builtin_popcountll(x) #define zerobitsll(x) __builtin_ctzll(x) #define ps(x,y) fixed<<setprecision(y)<<x typedef vector<int> vi; typedef long long ll; typedef vector<ll> vl; typedef pair<int,int> pii; typedef unsigned long long ull; typedef long double ld; typedef map<int,int> mii; const int MOD = 1e9+7; const ld PI = acos((ld)-1); int f (int x) { string strNo = to_string(x); string strInc = strNo,strDec = strNo; sort(all(strInc)),sort(all(strDec),greater<char>()); while (!strInc.empty() && *strInc.begin() == '0') { strInc.erase(strInc.begin()); } int big = stoi(strDec); int small = stoi(strInc); return big-small; } void solve () { int n,k; cin >> n >> k; int aPrev = n; for (int i = 0;i < k;++i) { int aNext = f(aPrev); if (aNext == 0) { cout << 0 << '\n'; return; } aPrev = aNext; } cout << aPrev << '\n'; } int main () { #ifndef ONLINE_JUDGE freopen("input1.txt","r",stdin); freopen("output1.txt","w",stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#include<bits/stdc++.h> #define LL long long #define pb push_back #define SZ(x) ((int)x.size()-1) #define ms(a,b) memset(a,b,sizeof a) #define F(i,a,b) for (int i=(a);i<=(b);++i) #define DF(i,a,b) for (int i=(a);i>=(b);--i) using namespace std; inline int read(){ char ch=getchar(); int w=1,c=0; for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1; for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48); return w*c; } const int M=5e5+10; int n,a[M],b[M]; int main(){ n=read(); F(i,1,n) a[i]=read(); F(i,1,n) b[i]=read(); int m1=1,m2=1; LL ans=0; F(i,1,n){ m1=max(m1,a[i]); ans=max(ans,1ll*b[i]*m1); cout<<ans<<"\n"; } return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */
#include <bits/stdc++.h> using namespace std; int main(){ long long n, a, b, d; cin >> n; vector<long long> c(n); a = 0; d = 0; for(int i = 0; i < n; i++){ cin >> c[i]; a += c[i]; d += c[i]*c[i]; } b = (a*a - d); cout << (n-1) * d - b << endl; }
#include <iostream> #include <cmath> #include <algorithm> #include <vector> #include <unordered_map> using namespace std; int main() { long long int n, ans = 0; cin >> n; vector<long long int> a(n, 0); unordered_map<long long int, long long int> Map; for (int i = 0; i < n; i++) { cin >> a[i]; Map[a[i]]++; } for (int i = -200; i <= 200; i++) { for (int j = i + 1; j <= 200; j++) { ans += Map[i] * Map[j] * (abs(i - j) * abs(i - j)); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef vector<vector<long long>> VVL; typedef pair<int,int> Pair; typedef tuple<int,int,int> tpl; #define ALL(a) (a).begin(),(a).end() #define SORT(c) sort((c).begin(),(c).end()) #define REVERSE(c) reverse((c).begin(),(c).end()) #define EXIST(m,v) (m).find((v)) != (m).end() #define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin() #define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin() #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i) #define RREP(i,n) RFOR(i,n,0) #define en "\n" constexpr double EPS = 1e-9; constexpr double PI = 3.1415926535897932; constexpr int INF = 2147483647; constexpr long long LINF = 1LL<<60; constexpr long long MOD = 1000000007; // 998244353; 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;} VVI c = {{1,0,0},{1,1,0},{1,2,1}}; int Lucas(int n, int r, int mod=3){ int ret = 1; while(n || r){ int x = n%mod, y = r%mod; (ret *= c[x][y]) %= mod; n /= mod; r /= mod; } return ret; } void Main(){ int N; cin >> N; int ans = 0; REP(i,N){ char c; cin >> c; int m; if(c=='B') m = 0; else if(c=='W') m = 1; else m = 2; (ans += Lucas(N-1,i)*m) %= 3; } if((N-1)&1){ ans *= -1; if(ans<0) ans += 3; } cout << "BWR"[ans] << en; return; } int main(void){ cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15); int t=1; //cin>>t; while(t--) Main(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) #define per(i, b) per2(i, 0, b) #define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define ALL(c) (c).begin(), (c).end() #define SZ(x) ((int)(x).size()) constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; } template <class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; } 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 << "{"; rep(i, v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } #ifdef LOCAL void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif int main() { int N; cin >> N; V<int> A(N), B(N); int sz = N * 2; V<int> tp(sz), com(sz, -1); bool ng = false; rep(i, N) { cin >> A[i] >> B[i]; if (A[i] != -1) { --A[i]; if (tp[A[i]]) ng = true; tp[A[i]] = i + 1; } if (B[i] != -1) { --B[i]; if (tp[B[i]]) ng = true; tp[B[i]] = -(i + 1); } if (A[i] != -1 && B[i] != -1) { com[A[i]] = B[i]; com[B[i]] = A[i]; } } if (ng) { puts("No"); return 0; } V<bool> dp(sz + 1); dp[0] = true; rep(i, sz) { if (!dp[i]) continue; for (int j = i + 1; j < sz; ++j) { int w = j - i + 1; if (w & 1) continue; w /= 2; bool ok = true; V<bool> exist(N); rep(k, w) { int p = i + k, q = i + k + w; if (com[p] != -1 && !(i <= com[p] && com[p] <= j)) { ok = false; } if (com[q] != -1 && !(i <= com[q] && com[q] <= j)) { ok = false; } bool same = true; if (tp[p] != 0 && tp[q] != 0) { if (tp[p] < 0 || tp[p] + tp[q] != 0) { ok = false; } else same = true; } if (tp[p] < 0 || tp[q] > 0) { ok = false; } else { if (tp[p] != 0) { int v = tp[p] - 1; if (exist[v]) { ok = false; } exist[v] = true; } } } if (ok) { dp[j + 1] = true; } } } puts(dp[sz] ? "Yes" : "No"); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,a,b) for (int i = a; i <= b; i++) #define REP_REV(i,a,b) for (int i = a; i >= b; i--) #define what_is(x) cerr << #x << " is " << x << endl; #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define pb push_back #define rsz resize #define f first #define s second #define mp make_pair using ll = long long; using vi = vector<int>; using vc = vector<char>; using ull = unsigned long long ; using pi = pair<int, int>; using vl = vector<ll>; using pl = pair<ll, ll>; using msl = map<string, ll>; using matrix = vector<vector<ll>>; ll MOD = 1e9 + 7; const int INF = int(1e9); struct Rect { ll x1 = 0, y1 = 0, x2 = 0, y2 = 0; ll area() { return (x2 - x1) * (y2 - y1); } }; Rect intersect(Rect p, Rect q) { Rect inter; inter.x1 = max(p.x1, q.x1); inter.y1 = max(p.y1, q.y1); inter.x2 = min(p.x2, q.x2); inter.y2 = min(p.y2, q.y2); if (inter.x1 >= inter.x2 || inter.y1 >= inter.y2) { Rect empty; return empty; } return inter; } bool iscovered(int x, int y, int x1, int y1, int x2, int y2) { return (x <= x2 && x >= x1 && y <= y2 && y >= y1); } bool isPrime(int n) { if (n == 2) return true; for(int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } unsigned long long factorial(int n) { const unsigned int M = 1000000007; unsigned long long f = 1; for (int i = 1; i <= n; i++) f = (f*i) % M; return f; } void solve() { int a, b; cin >> a >> b; int canfollow = 2 * a + 100; cout << canfollow - b; // int n; // cin >> n; // vi d(n); // REP(i, 0, n - 1) cin >> d[i]; // d[0] = 0; // REP(i, 0, n - 1) { // if (d[i] > -1) { // int t = d[i]; // int j = 1; // while(t--) { // if (d[i - j] > - 1) { // cout << - 1; // return; // } // d[i - j] = t; // j++; // } // } // } // int m = 0, M = 0; // REP(i, 1, n - 1) { // if (d[i] > -1) m++; // else M++; // } // // cout << endl; // // REP(i, 0, n - 1) cout << d[i] << " "; // // cout << endl; // cout << m << " " << M + m; } int main() { ios::sync_with_stdio(0); cin.tie(0); //freopen("taming.in", "r", stdin); //freopen("taming.out", "w", stdout); //ll t; cin >> t; //while (t--) solve(); return 0; }
//A #include<bits/stdc++.h> #define MAX 200000 using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long a,b; cin>>a>>b; cout<<2*a+100-b<<endl; return 0; }
#include<bits/stdc++.h> #define ll long long int using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, m, X, Y; cin >> n >> m >> X >> Y; vector<tuple<ll, ll, ll>> adj[n + 1]; for (ll i = 0; i < m; i++) { ll a, b, t, k; cin >> a >> b >> t >> k; adj[a].emplace_back(b, t, k); adj[b].emplace_back(a, t, k); } auto Dijkstra = [&](ll src, ll dest) { vector<ll> d(n + 1, LLONG_MAX); d[src] = 0; using pll = pair<ll, ll>; priority_queue <pll, vector<pll>, greater<pll>> pq; pq.emplace(0ll, src); while (!pq.empty()) { auto [d_v , v] = pq.top(); pq.pop(); if (d_v > d[v])continue; if (v == dest)return d_v; for (auto [to, t, k] : adj[v]) { ll departure = d_v / k; if (d_v % k)departure++; departure *= k; if (departure + t < d[to]) { d[to] = departure + t; pq.emplace(d[to], to); } } } return -1ll; }; ll ans = Dijkstra(X, Y); cout << ans; return 0; }
#pragma GCC optimize("O3") //#pragma GCC target("avx2") //#pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <prettyprint.hpp> #define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__); #else #define debug(...) 83; #endif void d_err() { cerr << endl; } template <typename H, typename... T> void d_err(H h, T... t) { cerr << h << " "; d_err(t...); } template <typename T> void print(T x) { cout << x << "\n"; } #define ALL(x) (x).begin(), (x).end() #define FOR(i, m, n) for (ll i = (m); i < (n); ++i) #define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i) #define REP(i, n) FOR(i, 0, n) #define REVREP(i, n) REVFOR(i, 0, n) #define fi first #define se second #define pb push_back #define mp make_pair #define eb emplace_back #define bcnt __builtin_popcountll typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ld> vld; typedef pair<ll,ll> Pll; typedef pair<int,int> Pin; ll INF = 1e16; int inf = 1e9; int main(){ cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); ll n, m, x, y; cin >> n >> m >> x >> y; x--, y--; vector<vector<pair<ll, pair<ll, ll>>>> edge(n); REP(i, m) { ll a, b, t, k; cin >> a >> b >> t >> k; a--, b--; edge[a].pb({t, {b, k}}); edge[b].pb({t, {a, k}}); } vll dist(n, INF); priority_queue<pair<ll, ll>> q; q.emplace(0, x); dist[x] = 0; while(not q.empty()) { auto p = q.top(); q.pop(); auto cur = p.se, time = p.fi; if (dist[cur] > time) continue; unordered_map<ll, ll> m; for(auto &e: edge[cur]) { auto nxt = e.se.fi; auto t = e.fi, k = e.se.se; ll t_s = (time + k - 1) / k * k; ll t_e = t_s + t; if (t_e >= dist[nxt]) continue; if (m.find(nxt) == m.end()) m[nxt] = t_e; else m[nxt] = min(m[nxt], t_e); } for (auto &e: m) { auto nxt = e.fi, t_e = e.se; if (t_e >= dist[nxt]) continue; dist[nxt] = t_e; q.emplace(t_e, nxt); } } print(dist[y] == INF ? -1 : dist[y]); }
#include <bits/stdc++.h> using namespace std; #define all(v) begin(v), end(v) #define endl '\n'; #define int long long #define pii pair<int, int> #define sz(x) (int) x.size() void test_case() { int a, b, c, d; cin >> a >> b >> c >> d; cout << min({a, b, c, d}) << endl; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; while (t--) { test_case(); } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int mini = 100000; for(int i=0, x; i<4; i++){ cin >> x; mini = min(mini, x); } cout << mini << endl; }
#include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <deque> #include <complex> #include <stack> #include <queue> #include <cstdio> #include <cctype> #include <cstring> #include <ctime> #include <iterator> #include <bitset> #include <numeric> #include <list> #include <iomanip> #include <cassert> #if __cplusplus >= 201103L #include <array> #include <tuple> #include <initializer_list> #include <unordered_set> #include <unordered_map> #include <forward_list> using namespace std; #define cauto const auto& #define ALL(v) begin(v),end(v) #else #define ALL(v) (v).begin(),(v).end() #endif namespace{ typedef long long LL; typedef pair<int,int> pii; typedef pair<LL,LL> pll; typedef vector<int> vint; typedef vector<vector<int> > vvint; typedef vector<long long> vll, vLL; typedef vector<vector<long long> > vvll, vvLL; #define VV(T) vector<vector< T > > template <class T> void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){ v.assign(a, vector<T>(b, t)); } template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); } template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); } template <class F, class T> void convert(const F &f, T &t){ stringstream ss; ss << f; ss >> t; } template <class Con> string concat(const Con &c, const string &spr){ stringstream ss; typename Con::const_iterator it = c.begin(), en = c.end(); bool fst = true; for(; it != en; ++it){ if(!fst){ ss << spr; } fst = false; ss << *it; } return ss.str(); } template <class Con, class Fun> vector<typename Con::value_type> cfilter(const Con &c, Fun f) { vector<typename Con::value_type> ret; typename Con::const_iterator it = c.begin(), en = c.end(); for(; it != en; ++it){ if(f(*it)){ ret.emplace_back(*it); } } return ret; } #if __cplusplus >= 201103L template <class Con, class Fun> auto cmap(const Con &c, Fun f) -> vector<decltype(f(*c.begin()))> { vector<decltype(f(*c.begin()))> ret; ret.reserve(c.size()); for(const auto &x: c){ ret.emplace_back(f(x)); } return ret; } #endif #if __cplusplus >= 201402L #define lambda(e) ([&](const auto &_){ return (e); }) #define lambda2(e) ([&](const auto &_a, const auto &_b){ return (e); }) #endif #define REP(i,n) for(int i=0;i<int(n);++i) #define RALL(v) (v).rbegin(),(v).rend() #define tget(t,i) get<i>(t) #define MOD 1000000007LL #define EPS 1e-8 LL inv(LL x){ LL y = MOD - 2; LL a = 1; while(y){ if(y & 1){ a = a * x % MOD; } x = x * x % MOD; y >>= 1; } return a; } vvll mul(const vvll &a, const vvll &b){ int n = a.size(); vvll c; initvv(c, n, n); REP(i, n) REP(k, n) REP(j, n){ c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % MOD; } return c; } vvll pow(vvll x, LL y){ int n = x.size(); vvll a; initvv(a, n, n); REP(i, n){ a[i][i] = 1; } while(y){ if(y & 1){ a = mul(a, x); } x = mul(x, x); y >>= 1; } return a; } void mainmain(){ int n, m, q; cin >> n >> m >> q; vll as(n); for(LL &a : as){ cin >> a; } VV(int) G(n); REP(i, m){ int x, y; cin >> x >> y; --x; --y; G[x].push_back(y); G[y].push_back(x); } LL im = inv(m); LL i2m = inv(2 * m); vvll b; initvv(b, n, n); REP(u, n){ b[u][u] = (m - G[u].size()) * im; for(int v : G[u]){ b[u][u] += i2m; b[u][v] += i2m; } } for(auto &v : b){ for(LL &x : v){ x %= MOD; } } vvll c = pow(b, q); REP(i, n){ LL s = 0; REP(j, n){ s = (s + c[i][j] * as[j]) % MOD; } cout << s << '\n'; } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(4); mainmain(); }
#include<bits/stdc++.h> #define int long long #define N 100 #define P 1000000007 #define inf 999999999999999999 using namespace std; int n,m,K,d[N+1],dq[N+1],g[N+1][N+1],ny2,ans[N+1],p,q; int ksm(int x,int y){int nans=1;for(;y;y>>=1,x=x*x%P)if(y&1)nans=nans*x%P;return nans;} int qny(int x){return ksm(x,P-2);} struct mat{ int a[N+1][N+1]; const mat operator *(mat y)const{ mat nans; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ nans.a[i][j]=0; for(int k=1;k<=n;k++)nans.a[i][j]+=this->a[i][k]*y.a[k][j],nans.a[i][j]%=P; } }return nans; } }I,A; void ycl(){ ny2=qny(2); for(int i=1;i<=n;i++)I.a[i][i]=1; for(int i=1;i<=n;i++){ A.a[i][i]=ny2+(m-d[i])*qny(2*m%P)%P; for(int j=1;j<=n;j++){ if(g[i][j])A.a[i][j]=qny(2*m%P); } } } mat ksm(mat x,int y){mat nans=I;for(;y;y>>=1,x=x*x)if(y&1)nans=nans*x;return nans;} signed main(){ cin>>n>>m>>K; for(int i=1;i<=n;i++)cin>>dq[i]; for(int i=1;i<=m;i++)cin>>p>>q,g[p][q]=g[q][p]=1,d[p]++,d[q]++; ycl(); A=ksm(A,K); for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)ans[i]+=dq[j]*A.a[i][j],ans[i]%=P; for(int i=1;i<=n;i++)printf("%lld\n",ans[i]); return 0; }
#include<iostream> using namespace std; int main(){ int N; cin >> N; cout << N-1; }
#include <bits/stdc++.h> using namespace std; #define oo 1e18 #define fi first #define se second #define sp(iiii) setprecision(iiii) #define IO ios_base::sync_with_stdio(false); cin.tie(0) #define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa)) #define cntbit(xxxx) __builtin_popcount(xxxx) #define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1) typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<pair<int,int>,int> piii; typedef pair<long long,long long> pll; typedef pair<pair<long long,long long>,long long> plll; const ll mod=1e9+7; ll n,i,j,f1[5009],f2[5009]; int main(){ IO; #ifndef ONLINE_JUDGE freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); #else #endif cin>>n; f1[0]=1; f2[0]=1; for (i=1;f1[i-1]<n;i++) { f1[i]=f1[i-1]*3; } for (i=1;f2[i-1]<n;i++) { f2[i]=f2[i-1]*5; } for (i=1;f2[i]<n;i++) { for (j=1;f1[j]<n;j++) { if (f1[j]+f2[i]==n) { cout<<j<<' '<<i; return 0; } } } cout<<-1; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vb = vector<bool>; using vvb = vector<vb>; using pii = pair<int, int>; using pll = pair<ll, ll>; #define rep(i, s, n) for(int i = (int)(s); i < (int)(n); ++i) ll INF = 1ll << 30; struct edge{int x, y;}; vector<edge> G[1010][1010]; int dist[1010][1010]; int main(){ int n, m; cin >> n >> m; vi A(m), B(m), C(m); rep(i, 0, m){ char c; cin >> A[i] >> B[i] >> c; A[i]--; B[i]--; C[i] = c - 'a'; } rep(i ,0, 1010){ rep(j, 0, 1010){ dist[i][j] = INF; } } rep(i, 0, m){ rep(j, 0, m){ if(C[i] == C[j]){ G[A[i]][A[j]].push_back({B[i], B[j]}); G[B[i]][B[j]].push_back({A[i], A[j]}); G[A[i]][B[j]].push_back({B[i], A[j]}); G[B[i]][A[j]].push_back({A[i], B[j]}); } } } queue<pii> que; que.push({0, n-1}); dist[0][n-1] = 0; while(!que.empty()){ pii p = que.front(); que.pop(); int vx, vy; vx = p.first; vy = p.second; rep(i, 0, G[vx][vy].size()){ int x, y; x = G[vx][vy][i].x; y = G[vx][vy][i].y; if(dist[x][y] > dist[vx][vy]+1){ dist[x][y] = dist[vx][vy]+1; que.push({x, y}); } } } int ans = INF; rep(i, 0, n){ if(dist[i][i] != INF){ ans = min(ans, dist[i][i]*2); } } rep(i, 0, n){ rep(j, 0, n){ if(dist[i][j] != INF && dist[j][i] - dist[i][j] == 1){ ans = min(ans, dist[i][j]+dist[j][i]); } } } if(ans == INF){ cout << -1 << endl; } else{ cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define REP(i, N) for (int i = 0; i < (int)N; i++) #define FOR(i, a, b) for (int i = a; i < (int)b; i++) using namespace std; int main() { int N; cin >> N; vector<int> used(2 * N); auto out = []() { cout << "No" << endl; exit(0); }; REP(i, N) { int A, B; cin >> A >> B; if (A != -1 && B != -1 && A >= B) out(); if (A != -1) { if (used[A - 1] != 0) out(); used[A - 1] = i + 1; } if (B != -1) { if (used[B - 1] != 0) out(); used[B - 1] = -(i + 1); } } vector<bool> dp(N + 1); dp[0] = 1; FOR(i, 1, N + 1) { REP(j, i) if (dp[j]) { bool ng = 0; REP(k, i - j) { int a = used[2 * j + k], b = used[2 * j + k + i - j]; ng |= (a < 0) || (b > 0) || (a > 0 && b < 0 && b != -a); } if (!ng) dp[i] = 1; } } cout << (dp[N] ? "Yes" : "No") << endl; return 0; }
#include<iostream> #include<vector> #include<algorithm> #include<string> #include<queue> #include<cmath> #include<cstdio> #include<tuple> #include<bitset> #include<map> #include<functional> using namespace std; #define rep(i,n) for(int i=0;i<n;++i) #define rep1(i,n) for(int i=1;i<=n;++i) #define ALL(x) x.begin(),x.end() #define ll long long using lint=long long; #define debug(output) cout<<#output<<"= "<<output<<endl typedef pair<int,int> P; const int inf=1000000007; const int MOD=1000000007; template<class T> class SegTree{ int n; vector<T> node; T e; function<T(T,T)> operation; function<T(T,T)> update; public: SegTree(int _n,T _e,function<T(T,T)> _operation,function<T(T,T)> _update):n(_n),e(_e),operation(_operation),update(_update){node.resize(n*2,e);} void change(int i,T x){ i+=n; node[i]=update(node[i],x); while(i>1){ i>>=1; node[i]=operation(node[i<<1|0],node[i<<1|1]); } } T get(int l,int r){ T a=e; T b=e; l+=n;r+=n; while(l<r){ if(l&1)a=operation(a,node[l++]); if(r&1)b=operation(node[--r],b); l>>=1;r>>=1; } return operation(a,b); } void input(vector<T>& _input){ for(int i=0;i<n;++i){ change(i,_input[i]); } } }; signed main(){ int h,w,m;cin>>h>>w>>m; vector<vector<int>> r(h+1); rep(i,m){ int x,y;cin>>y>>x; r[y].push_back(x); } rep1(i,h){ r[i].push_back(w+1); sort(r[i].begin(),r[i].end()); } int lim=h+1; rep1(i,h){ if(r[i].size()>0){ if(r[i][0]==1){ lim=i; break; } } } auto op=[](int a,int b){return a+b;}; SegTree<int> tree(h+w+1,0,op,op); lint res=0; priority_queue<P> que; for(int i=1;i<lim;++i){ if(r[i].size()>0){ res+=r[i][0]-1; que.push({r[i][0],i}); } } vector<vector<int>> a(w+5); rep1(i,h){ for(auto& val:r[i]){ a[val].push_back(i); } } rep1(i,w){ a[i].push_back(h+1); sort(a[i].begin(),a[i].end()); } lim=r[1][0]; que.push({0,0}); for(int i=lim-1;i>0;--i){ while(que.top().first>=i){ tree.change(que.top().second,1);que.pop(); } res+=a[i][0]-1-tree.get(1,a[i][0]); } cout<<res<<"\n"; return 0; }
#include <cstdio> #include <cstring> #include <algorithm> #include <map> #include <queue> using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; const int maxn = 2e3 + 7; const int mod = 1e9 + 7; ll p[maxn * maxn]; char s[maxn][maxn]; int U[maxn][maxn],D[maxn][maxn],L[maxn][maxn],R[maxn][maxn]; int n,m; void init() { p[0] = 1; for(int i = 1;i <= maxn * maxn - 2;i++) { p[i] = p[i - 1] * 2 % mod; } memset(U,0x3f,sizeof(U)); for(int i = 1;i <= n;i++) { for(int j = 1;j <= m;j++) { if(s[i][j] == '.') { U[i][j] = i; U[i][j] = min(U[i][j],U[i - 1][j]); } } } for(int i = n;i >= 1;i--) { for(int j = 1;j <= m;j++) { if(s[i][j] == '.') { D[i][j] = i; D[i][j] = max(D[i][j],D[i + 1][j]); } } } memset(L,0x3f,sizeof(L)); for(int j = 1;j <= m;j++) { for(int i = 1;i <= n;i++) { if(s[i][j] == '.') { L[i][j] = j; L[i][j] = min(L[i][j],L[i][j - 1]); } } } for(int j = m;j >= 1;j--) { for(int i = 1;i <= n;i++) { if(s[i][j] == '.') { R[i][j] = j; R[i][j] = max(R[i][j],R[i][j + 1]); } } } } int main() { scanf("%d%d",&n,&m); int cnt = 0; for(int i = 1;i <= n;i++) { scanf("%s",s[i] + 1); for(int j = 1;j <= m;j++) { if(s[i][j] == '.') { cnt++; } } } init(); ll ans = 0; for(int i = 1;i <= n;i++) { for(int j = 1;j <= m;j++) { if(s[i][j] == '.') { int num = D[i][j] - U[i][j] + R[i][j] - L[i][j] + 1; // printf("%d %d %d %d\n",L[i][j],R[i][j],U[i][j],D[i][j]); // printf("FUCK %d\n",num); ans = (ans + p[cnt - num] * (p[num] - 1) % mod + mod) % mod; } } } printf("%lld\n",((ans + mod) % mod)); return 0; }
#include <stdio.h> #include <stdlib.h> #include <string> #include <iostream> #include <utility> #include <algorithm> #include <vector> #include <list> #include <stack> #include <queue> #include <unordered_map> #include <map> #include <unordered_set> #include <set> #include <tuple> #include <cassert> using namespace std; using ll = long long; const int mod = 1e9 + 7; #define read_int(X) \ ll X; \ scanf("%lld\n", &X); #define read_two_int(X, Y) \ ll X, Y; \ scanf("%lld %lld\n", &X, &Y); #define read_three_int(X, Y, Z) \ ll X, Y, Z; \ scanf("%lld %lld %lld\n", &X, &Y, &Z); #define read_four_int(X, Y, Z, W) \ ll X, Y, Z, W; \ scanf("%lld %lld %lld %lld\n", &X, &Y, &Z, &W); int main() { ll N, M; scanf("%lld", &N); scanf("%lld", &M); vector<ll> A(M); vector<ll> B(M); for (ll i = 0; i < M; i++) { scanf("%lld", &A[i]); scanf("%lld", &B[i]); } ll K; scanf("%lld", &K); vector<ll> C(K); vector<ll> D(K); for (ll i = 0; i < K; i++) { scanf("%lld", &C[i]); scanf("%lld", &D[i]); } ll ans = 0; for (ll i = 0; i < (2 << K) - 1; i++) { vector<bool> dish(N, false); for (ll j = 0; j < K; j++) { if ((i >> j) % 2) dish[C[j] - 1] = true; else dish[D[j] - 1] = true; } ll currentans = 0; for (ll j = 0; j < M; j++) { currentans += dish[A[j] - 1] && dish[B[j] - 1]; } ans = max(ans, currentans); } printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < n; i++) const int lim = 1000000007; int main(){ int N, M; cin >> N >> M; vector<int> A(M), B(M); rep(i, M){ int a, b; cin >> a >> b; a--, b--; A[i] = a; B[i] = b; } int K; cin >> K; vector<int> C(K), D(K); rep(i, K){ int c, d; cin >> c >> d; c--, d--; C[i] = c; D[i] = d; } int mx = 0; rep(bit, (1 << K)){ // 皿を表す配列(中身は、そのさらに乗っているボールの数) vector<int> sara(N, 0); rep(i, K){ if(bit >> i & 1){ sara[C[i]]++; }else{ sara[D[i]]++; } } // 適合する条件の個数を数える int ans = 0; rep(i, M){ if(sara[A[i]] >= 1 && sara[B[i]] >= 1) ans++; } mx = max(mx, ans); } cout << mx << endl; return 0; }
#include <iostream> #include <vector> #include <string> #include <queue> #include <algorithm> #include <cstring> #include <cmath> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <climits> #include <stack> using namespace std; vector<int> G[100000]; const int INF = 0x3f3f3f3f; int N, M, K; int arr[18]; int dist[18][100000]; int dp[18][1 << 18]; void bfs(int src) { for (int i = 0; i < N; i++) { dist[src][i] = INF; } queue<int> q; dist[src][arr[src]] = 0; q.push(arr[src]); while (!q.empty()) { int curr = q.front(); q.pop(); for (auto &g : G[curr]) { if (dist[src][g] == INF) { dist[src][g] = dist[src][curr] + 1; q.push(g); } } } } int solve(int start, int mask) { if (mask == (1 << K) - 1) return 0; int &ret = dp[start][mask]; if (ret != -1) return ret; ret = INF; for (int i = 0; i < K; i++) { if (mask & (1 << i)) continue; ret = min(ret, solve(i, mask | (1 << i)) + dist[i][arr[start]]); } return ret; } int main() { ios::sync_with_stdio(0); cin.tie(0); memset(dp, -1, sizeof(dp)); cin >> N >> M; for (int i = 0, u, v; i < M; i++) { cin >> u >> v; u--, v--; G[u].push_back(v); G[v].push_back(u); } cin >> K; for (int i = 0; i < K; i++) { cin >> arr[i]; arr[i]--; } for (int i = 0; i < K; i++) bfs(i); for (int i = 0; i < K; i++) { if (dist[i][arr[0]] == INF) { cout << -1 << '\n'; return 0; } } int ans = INF; for (int i = 0; i < K; i++) ans = min(ans, 1 + solve(i, (1 << i))); cout << ans << '\n'; return 0; }
#include<iostream> #include<string> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #include<map> #include <queue> #include<sstream> #include <stack> #include <set> #include <bitset> #include<vector> #define FAST ios::sync_with_stdio(false) #define abs(a) ((a)>=0?(a):-(a)) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() #define mem(a,b) memset(a,b,sizeof(a)) #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) #define rep(i,a,n) for(int i=a;i<=n;++i) #define per(i,n,a) for(int i=n;i>=a;--i) #define endl '\n' #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; typedef long long ll; typedef pair<ll,ll> PII; const int maxn = 1e5+200; const ll inf=0x3f3f3f3f3f3f3f3f; const double eps = 1e-7; const double pi=acos(-1.0); const int mod = 1e9+7; inline int lowbit(int x){return x&(-x);} ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d); inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;} inline ll inv(ll x,ll p){return qpow(x,p-2,p);} inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;} inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; } int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; bool vis[maxn]; vector<vector<ll> > D(maxn); ll dis[20][20]; ll d[maxn]; void bfs(int s) { queue<PII> q; q.push(mp(s,0)); vis[s] = 1; while(!q.empty()) { ll x = q.front().fi; ll dd = q.front().se; q.pop(); d[x] = dd; for(int i=0; i<D[x].size(); i++) { ll y = D[x][i]; if(!vis[y]) q.push(mp(y,dd+1)), vis[y] = 1; } } } ll a[maxn]; ll dp[1<<18][20]; int main() { ll n = read(), m = read(); rep(i,1,m) { ll x = read(), y = read(); D[x].pb(y); D[y].pb(x); } ll k = read(); rep(i,1,k) a[i] = read(); ll ans = inf; rep(i,1,k) { rep(j,1,n) vis[j] = 0, d[j] = inf;; bfs(a[i]); rep(j,1,k) dis[i][j] = d[a[j]]; } //cout<<"wa"<<endl; mem(dp,inf); rep(i,0,k-1) dp[1<<i][i+1] = 1; rep(i,1,(1<<k)-1) { rep(j,1,k) { if(dp[i][j]==inf) continue; rep(nextOne,1,k) { if(nextOne==j) continue; if(!(i>>(nextOne-1)&1)) { int nextState = i + (1<<(nextOne-1)) ; //cout<<dis[j][head]<<' '<<i<<' '<<j<<' '<<head<<endl; dp[nextState][nextOne] = min(dp[nextState][nextOne], dp[i][j] + dis[j][nextOne]); } } } } rep(i,1,k) ans = min(ans,dp[(1<<k)-1][i]); if(ans==inf) cout<<-1<<endl; else cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() #define rep(i,a, n) for(int (i) = (a); (i) < (n); (i)++) using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; template<class T> void chmax(T& a, T b){ if(a<b){a=b;} } template<class T> void chmin(T& a, T b){ if(a>b){a=b;} } ll getDevisor(ll num) { //約数の総和 ll ans = 0; for (ll i = 1; i <= num; i++) { if (num % i == 0) ans++; } return ans; } ll digit_sum(ll n) { //各桁の和 if (n < 10) return n; return digit_sum(n / 10) + n % 10; } ll calc_digit(ll N) { //桁数 int res = 0; while (N) { ++res; N /= 10; } return res; } const long long mod = 1e9 + 7; int main() { ll c; int n, w; cin >> n >> w; vector <ll> p(200002); for(int i = 0; i < n; i++) { int s, t; cin >> s >> t; ll x; cin >> x; p[s] += x; p[t] -= x; } for(int i = 1; i < 200002; i++) { p[i] += p[i-1]; } c=*max_element(all(p)); cout << ((c<=w)? "Yes":"No"); }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);++i) using namespace std; using ll=long long; int main(){ int n,w; cin>>n>>w; vector<ll> p(300000,0); rep(i,n){ int a,b,c; cin>>a>>b>>c; p[a]+=c; p[b]-=c; } ll count=0; rep(i,300000){ count+=p[i]; if(count>w){ cout<<"No"<<endl; return 0; } } cout<<"Yes"<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define FOR(i, x, y) for(int i = (x); i < (y); ++i) #define REP(i, x, y) for(int i = (x); i <= (y); ++i) #define PB push_back #define MP make_pair #define PH push #define fst first #define snd second typedef long long ll; typedef unsigned long long ull; typedef double lf; typedef long double Lf; typedef pair<int, int> pii; const int maxn = 55; const int INF = 998244353; int n, k, ans = 1; int fac[maxn]; int a[maxn][maxn]; class Dsu{ private: public: int fa[maxn], sz[maxn]; inline void init(){ FOR(i, 0, n) fa[i] = i, sz[i] = 1; return; } inline int find(int x){ return (fa[x] == x) ? x : (fa[x] = find(fa[x])); } inline void merge(int x, int y){ x = find(x), y = find(y); if(x == y) return; sz[y] += sz[x]; fa[x] = y; return; } }row, col; int main(){ scanf("%d%d", &n, &k); FOR(i, 0, n) FOR(j, 0, n) scanf("%d", &a[i][j]); row.init(); col.init(); fac[0] = 1; REP(i, 1, n) fac[i] = 1ll * fac[i - 1] * i % INF; FOR(x, 0, n) FOR(y, 0, n){ bool frow = true, fcol = true; FOR(i, 0, n){ fcol &= (a[i][x] + a[i][y] <= k); frow &= (a[x][i] + a[y][i] <= k); } if(frow) row.merge(x, y); if(fcol) col.merge(x, y); } FOR(i, 0, n){ if(row.find(i) == i) ans = 1ll * fac[row.sz[i]] * ans % INF; if(col.find(i) == i) ans = 1ll * fac[col.sz[i]] * ans % INF; } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long i64; const int MOD = 998244353; const int inv2 = 499122177; const int N = 52; int c[N * N][N * N] = {0}; int p[N * N][N * N] = {0}; int f[N * N] = {1}; void init() { for (int i = 1, fac = 1; i < N * N; i++) { f[i] = 1LL * f[i - 1] * i % MOD; c[i][0] = c[i][i] = 1; for (int j = 1; j < i; j++) { c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD; p[i][j] = 1LL * c[i][j] * f[i] % MOD; } } } bool check_row(int x, int y, int k, const vector<vector<int>>& a) { for (int i = 0; i < a.size(); i++) { if (a[x][i] + a[y][i] > k) { return false; } } return true; } bool check_col(int x, int y, int k, const vector<vector<int>>& a) { for (int i = 0; i < a.size(); i++) { if (a[i][x] + a[i][y] > k) { return false; } } return true; } int set_find(int x, vector<int>& f) { return f[x] = (f[x] == x) ? x : set_find(f[x], f); } void set_union(int x, int y, vector<int>& f) { x = f[x], y = f[y]; if (x > y) { swap(x, y); } f[y] = x; } int main() { init(); int n, k; cin >> n >> k; vector<vector<int>> a(n, vector<int>(n, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } } vector<int> row_root(n, 1); vector<int> row_set_count(n, 0); vector<int> col_root(n, 1); vector<int> col_set_count(n, 0); for (int i = 0; i < n; i++) { row_root[i] = i; col_root[i] = i; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (check_row(i, j, k, a)) { set_union(i, j, row_root); } if (check_col(i, j, k, a)) { set_union(i, j, col_root); } } } for (int i = 0; i < n; i++) { row_set_count[set_find(row_root[i], row_root)]++; col_set_count[set_find(col_root[i], col_root)]++; } int ans_row = 1, ans_col = 1; for (int i = 0; i < n; i++) { ans_row *= f[row_set_count[i]]; ans_row %= MOD; ans_col *= f[col_set_count[i]]; ans_col %= MOD; } printf("%lld\n", 1LL * ans_row * ans_col % MOD); return 0; } /* 10 150 82 94 21 65 28 22 61 80 81 79 93 35 59 85 96 1 78 72 43 5 12 15 97 49 69 53 18 73 6 58 60 14 23 19 44 99 64 17 29 67 24 39 56 92 88 7 48 75 36 91 74 16 26 10 40 63 45 76 86 3 9 66 42 84 38 51 25 2 33 41 87 54 57 62 47 31 68 11 83 8 46 27 55 70 52 98 20 77 89 34 32 71 30 50 90 4 37 95 13 100 */
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; for(int i=0; i<N; i++){ int a = 2*i%N; int b = (2*i+1)%N; cout << a+1 << " " << b+1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &t) { t=0; char ch=getchar(); int f=1; while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); } do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f; } typedef long long ll; const int maxn=(2e5)+10; int n; ll a[maxn],ans,mx; int main() { // freopen("1.txt","r",stdin); read(n); for (int i=1;i<=n;i++) { read(a[i]); mx=max(mx,a[i]); a[i]+=a[i-1]; ans+=a[i]; printf("%lld\n",ans+mx*i); } return 0; }
#include <algorithm> #include <iostream> #include <vector> #include <string> #include <cmath> #include <set> #include <ctime> #include <map> #include <fstream> #include <unordered_map> #define all(x) begin(x), end(x) #define sz(x) (int)x.size() #define x first #define y second #define int int64_t using namespace std; typedef pair<int, int> pt; const int mod = 1e9 + 7; int32_t main() { int n; cin >> n; int k; cin >> k; vector<int> a(n); vector<int> cnt(n + 1); for (int& e : a) { cin >> e; cnt[e]++; } int ans = 0; for (int j = 0; j < k; ++j) { for (int i = 0; i <= n; ++i) { if (cnt[i] == 0) { ans += i; break; } cnt[i]--; } } cout << ans; }
#include <bits/stdc++.h> #define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++) #define REPS(i, ss, nn ) for(int i = ss ; i < (int) nn; i++) #define REV(i, ss, nn ) for(int i = ss ; i >= nn; i--) #define deb(x) std::cout << #x << " " << x << endl; #define debl(x) std::cout << #x << " " << x << " "; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; namespace std{ template<class Fun> class y_combinator_result{ Fun fun_; public: template<class T> explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)){} template<class ...Args> decltype(auto) operator()(Args&&...args){ return fun_(std::ref(*this), std::forward<Args>(args)...); } }; template<class Fun> decltype(auto) y_combinator(Fun && fun){ return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); } }; template<typename T> bool u_max(T& a, T b){ if( a < b){ a = b; return true; } return false; } template<typename T> bool u_min(T& a, T b){ if( a > b){ a = b; return true; } return false; } struct edge{ int to, from; ll cost; edge(){ edge(0,0);} edge(int to_, ll cost_){ edge(to_, -1, cost_);} edge(int to_, int from_, ll cost_) : to(to_), from(from_), cost(cost_){} }; template<typename... T> void read(T& ... a){ ((cin >> a),...); } void solve(){ int n , k; read(n, k); map<int,int> mp; REP(i, n){ int a; cin >> a; mp[a]++; } ll ans = 0; for(int i = 0 ; i < k ; i++){ if(mp[0] == 0){ break; } REP(j,n){ // deb(j) if(mp.find(j) == mp.end()){ // cout << "No j ?" << endl; ans += j; break; } // deb(mp[j]) if(mp[j] == 0){ ans += j; break; }else{ mp[j]--; } } } cout << ans << endl; } int main() { //making data IO Fast std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); /****************************/ solve(); return 0; }
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 87; int n, dp[N], sz[N]; vector<int> g[N]; void dfs(int u) { sz[u] = 1; multiset<int> pq[2]; for (int v : g[u]) { dfs(v); sz[u] += sz[v]; pq[sz[v] % 2].insert(dp[v]); } dp[u] = 1; int cur = -1; while (pq[0].size() && *begin(pq[0]) < 0) { dp[u] += *begin(pq[0]); pq[0].erase(begin(pq[0])); } while (pq[1].size()) { if (cur == -1) { dp[u] += *begin(pq[1]); pq[1].erase(begin(pq[1])); } else { dp[u] -= *begin(pq[1]); pq[1].erase(begin(pq[1])); } cur *= -1; } while (pq[0].size()) { if (cur == -1) { dp[u] += *begin(pq[0]); pq[0].erase(begin(pq[0])); } else { dp[u] -= *begin(pq[0]); pq[0].erase(begin(pq[0])); } } } int main() { cin >> n; for (int i = 2; i <= n; ++i) { int p; cin >> p; g[p].push_back(i); } dfs(1); cout << (dp[1] + n) / 2 << endl; }
#include<bits/stdc++.h> using namespace std; #define MOD 1000000007 //#define MOD 998244353 #define INF 1000000010 #define EPS 1e-9 #define F first #define S second #define debug(x) cout<<x<<endl; #define repi(i,x,n) for(int i=x;i<n;i++) #define rep(i,n) repi(i,0,n) #define lp(i,n) repi(i,0,n) #define repn(i,n) for(int i=n;i>=0;i--) #define int long long #define endl "\n" typedef pair<int,int> PII; typedef pair<int,string> PIS; typedef pair<string,int> PSI; int n; int p[100000]; vector<int> v[100000]; pair<int,PII> score[100000]; bool vis[100000]; pair<int,PII> dfs(int st){ // cout<<st<<endl; if(v[st].size() == 0){ return score[st]; } vector<pair<int,PII> > now,evenpos,evenneg; rep(i,v[st].size() ){ pair<int,PII> pp=dfs(v[st][i]); //cout<<pp.F<<" ("<<pp.S.F<<" "<<pp.S.S<<")"<<endl; if( (pp.S.F+pp.S.S) % 2 == 0){ if(pp.F>0) evenpos.push_back(pp); else evenneg.push_back(pp); }else{ now.push_back(pp); } } sort(now.begin(),now.end() ); pair<int,PII> ret; ret=make_pair((int)0,make_pair((int)0,(int)0) ); rep(i,evenneg.size() ){ ret.S.F+=evenneg[i].S.F; ret.S.S+=evenneg[i].S.S; } if(now.size() != 0){ rep(i,now.size()) { if(i%2==0){ ret.S.F+=now[i].S.F; ret.S.S+=now[i].S.S; }else{ ret.S.F+=now[i].S.S; ret.S.S+=now[i].S.F; } } } rep(i,evenpos.size() ){ if(now.size() % 2 == 0){ ret.S.F+=evenpos[i].S.F; ret.S.S+=evenpos[i].S.S; }else{ ret.S.F+=evenpos[i].S.S; ret.S.S+=evenpos[i].S.F; } } ret.F=ret.S.F-ret.S.S; ret.F+=1; ret.S.F++; return ret; } signed main(){ cin.tie(0); ios::sync_with_stdio(false); cin>>n; rep(i,n-1){ cin>>p[i]; p[i]--; v[p[i]].push_back(i+1); } rep(i,n) score[i]=make_pair((int)1,make_pair((int)1,(int)0)); rep(i,n) vis[i]=false; int st=0; pair<int,PII> ans=dfs(st); cout<<ans.S.F<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i = (m); i <= (n); i++) #define zep(i,m,n) for(ll i = (m); i < (n); i++) #define rrep(i,m,n) for(ll i = (m); i >= (n); i--) #define print(x) cout << (x) << endl; #define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl; struct union_find { vector<int> par, siz; union_find(int n) { par.resize(n); siz.resize(n); for(int i = 0; i < n; i++){ par[i] = i; siz[i] = 1; } } int find(int x) { if (par[x] == x) return x; return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y)return; if (siz[x] < siz[y]) { par[x] = y; siz[y] += siz[x]; } else { par[y] = x; siz[x] += siz[y]; } } long long size(int x){ return siz[find(x)]; } bool same(int x, int y) { return (find(x) == find(y)); } }; struct dijkstra{ vector<long long> min_dst; vector<vector<pair<long long, long long>>> G; dijkstra(int n){ min_dst.resize(n); G.resize(n); } void append(int u, int v, long long cost){G[u].push_back(make_pair(v, cost));} void run(int s){ priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> que; fill(min_dst.begin(), min_dst.end(), -1); min_dst[s] = 0; que.push(make_pair(0, s)); while(!que.empty()){ auto p = que.top(); que.pop(); int at = p.second; if(min_dst[at] < p.first){continue;} for(int i = 0; i < G[at].size(); i++){ int to = G[at][i].first; long long cost = G[at][i].second; if(min_dst[to] == -1 || min_dst[at] + cost < min_dst[to]){ min_dst[to] = min_dst[at] + cost; que.push(make_pair(min_dst[to], to)); } } } } long long get(int at){return min_dst[at];} }; ll k, dst[20][20], dp[20][(1LL << 20)]; ll memo(ll at, ll bit){ if(dp[at][bit] != -1)return dp[at][bit]; ll res = INF; zep(i, 0, k){ if(i != at && (bit & (1LL << i))){ res = min(res, memo(i, bit - (1LL << at)) + dst[i][at]); } } return dp[at][bit] = res; } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; ll a[m], b[m]; union_find u(n); dijkstra d(n); zep(i, 0, m){ cin >> a[i] >> b[i]; a[i]--; b[i]--; u.unite(a[i], b[i]); d.append(a[i], b[i], 1); d.append(b[i], a[i], 1); } cin >> k; ll c[k]; zep(i, 0, k){cin >> c[i]; c[i]--;} /*if(k == 1){ print(1) return 0; }*/ zep(i, 0, k)zep(j, 0, k)if(!u.same(c[i], c[j])){print(-1) return 0;} zep(i, 0, k){ d.run(c[i]); zep(j, 0, k){ dst[i][j] = d.get(c[j]); } } memset(dp, -1, sizeof(dp)); zep(i, 0, k)dp[i][1LL << i] = 0; ll ans = INF; zep(i, 0, k){ ans = min(ans, memo(i, (1LL << k) - 1)); } print(ans + 1) return 0; }
#include <bits/stdc++.h> using namespace std; using int64 = long long; constexpr int DEBUG = 0; struct Edge { int from, to; Edge(int from, int to) : from(from), to(to) {} }; vector<vector<Edge>> ReadUndirectedGraph(int n, int m, bool one_indexed=false) { vector<vector<Edge>> graph(n); for (int i = 0; i < m; i++) { int v1, v2; cin >> v1 >> v2; if (one_indexed) { v1--; v2--; } graph[v1].push_back(Edge(v1, v2)); graph[v2].push_back(Edge(v2, v1)); } return graph; } template<typename T> vector<vector<T>> MakeVector2D(int d1, int d2, T default_value) { return vector<vector<T>>(d1, vector<T>(d2, default_value)); } tuple<vector<int>, vector<int>> BFS(const vector<vector<Edge>>& graph, int s) { int n = graph.size(); deque<int> queue; queue.push_back(s); vector<int> ds(n, INT_MAX); vector<int> ps(n, -1); ds[s] = 0; while (!queue.empty()) { int v = queue.front(); queue.pop_front(); for (const auto& e : graph[v]) { if (ds[e.to] < INT_MAX) continue; ds[e.to] = ds[v] + 1; ps[e.to] = v; queue.push_back(e.to); } } return make_tuple(ds, ps); } template<class T> inline bool UpdateMin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class T> inline bool UpdateMax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } // vector template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) { int len = v.size(); s << "["; for (int i = 0; i < len; i++) { if (i > 0) s << ", "; s << v[i]; } s << "]"; return s; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector<Edge>> graph = ReadUndirectedGraph(n, m, true); int k; cin >> k; vector<int> cs(k); for (int i = 0; i < k; i++) { cin >> cs[i]; cs[i]--; } auto d_table = MakeVector2D(k, k, 0); for (int i = 0; i < k; i++) { vector<int> ds; tie(ds, ignore) = BFS(graph, cs[i]); for (int j = 0; j < k; j++) { d_table[i][j] = ds[cs[j]]; } } constexpr int64 INF = 4E18; int64 ans = INF; auto dp = MakeVector2D(k, 1 << k, INF); for (int s = 0; s < k; s++) { for (int j = 0; j < 1 << k; j++) { for (int i = 0; i < k; i++) { dp[i][j] = INF; } } dp[s][1 << s] = 0; for (int j = 0; j < 1 << k; j++) { for (int i = 0; i < k; i++) { for (int i2 = 0; i2 < k; i2++) { if (i == i2) continue; if (d_table[i][i2] == INT_MAX) continue; UpdateMin(dp[i2][j | (1 << i2)], dp[i][j] + d_table[i][i2]); } } } for (int i = 0; i < k; i++) { UpdateMin(ans, dp[i][(1 << k) - 1]); } } if (ans == INF) { cout << -1 << endl; } else { cout << ans + 1 << endl; } }
#include <stdio.h> #include <algorithm> #include <iostream> using namespace std; #define For(i, a, b) for (int i = a; i <= (b); ++i) #define Rof(i, a, b) for (int i = a; i >= (b); --i) #define all(a) a.begin(), a.end() #define ll long long #define vi vector<int> #define pii pair<int, int> pii const int mod = 998244353; inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } inline long long input() { long long x = 0; bool f = 0; char ch = 0; while (!isdigit(ch)) f |= ch == '-', ch = getchar(); while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); return f ? -x : x; } const int N = 1e5 + 5; int n, m, k; int a[N], b[N], f[N]; void work() { ll mx = 101; For(i, 1, 4) { mx = min(mx, input()); } cout << mx; } signed main() { #ifndef ONLINE_JUDGE freopen("test.in", "r", stdin); freopen("test.out", "w", stdout); #endif work(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pt; #define MOD 1000000007 int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<int> ans(N, 2); ans[0] = 1; for(int i = 2; i <= N; i++) { for(int j = 2; i * j <= N; j++) { ans[i * j - 1] = ans[i - 1] + 1; } } for(int i = 0; i < N; i++) cout << ans[i] << " "; cout << endl; }
#include <bits/stdc++.h> using namespace std; #define rep2(i,j,n) for (int i=j; i <=(int)(n); i++) int main() { int n,m,t,a,b,x; cin >> n >> m >> t; x=n; b=0; rep2(i,1,m) { cin >> a ; x-=a-b; if(x<1){ cout << "No" << endl; return 0; } cin >> b ; x+=b-a; x=min(n,x); } x-=t-b; if(x<1) cout << "No" << endl; else cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++) #define all(v) v.begin(), v.end() template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0;} template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0;} #define dbl(i) fixed << setprecision(15) << i << endl; #define GET_VARIABLE_NAME(Variable) (#Variable) #define dbc(a) cout << GET_VARIABLE_NAME(a) << "=" << a << endl; #define vsum(v) accumulate(all(v), 0); bool IsPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; // 偶数はあらかじめ除く double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { // 素数ではない return false; } } // 素数である return true; } vector<ll> enum_divisors(ll N) { vector<ll> res; for (ll i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); // 重複しないならば i の相方である N/i も push if (N/i != i) res.push_back(N/i); } } // 小さい順に並び替える sort(res.begin(), res.end()); return res; } /*vector<pair<long long, long long> > prime_factorize(long long N) { vector<pair<long long, long long> > res; for (long long a = 2; a * a <= N; ++a) { if (N % a != 0) continue; long long ex = 0; // 指数 // 割れる限り割り続ける while (N % a == 0) { ++ex; N /= a; } // その結果を push res.push_back({a, ex}); } // 最後に残った数について if (N != 1) res.push_back({N, 1}); return res; }*/ ll gcd(int a, int b){ if (a%b == 0){ return(b); }else{ return(gcd(b, a%b)); } } int main(){ ll n,m,t; cin>>n>>m>>t; ll max=n; string ans="Yes"; ll tt=0; rep(i,m){ ll a,b; cin>>a>>b; n-=(a-tt);//カフェに来るまで if(n<=0) ans="No"; n+=(b-a);//カフェ滞在 if(n>max) n=max; if(n<=0) ans="No"; tt=b; if(i==m-1){ n-=(t-tt); if(n<=0) ans="No"; } } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) typedef long long ll; #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) //定数 #define INF 1000000000 //10^9:極めて大きい値,∞ //略記 #define PB push_back //vectorヘの挿入 #define MP make_pair //pairのコンストラクタ #define F first //pairの一つ目の要素 #define S second //pairの二つ目の要素 template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0;}; template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0;}; ll RepeatSquaring(ll N, ll P, ll M){ if(P==0) return 1; if(P%2==0){ ll t = RepeatSquaring(N, P/2, M); return t*t % M; } return N * RepeatSquaring(N, P-1, M); } int main(){ ios::sync_with_stdio(false); ll n, m; cin >> n >> m; ll m2=m*m; ll ans=1; // rep(i, n){ // ans*=10; // ans%=m2; // } ans=RepeatSquaring(10, n, m2); ans/=m; ans%=m; cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; long long ara[2000006],tra[2000006]; int main() { int n,m,a,b,c,d,e,p,q,l,r,s,fr,sc,tr,sz=0,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX; int x=0,y=0,cnt=0,res=0,ans=0,sum=0; int flg=0,flag=1,na=0,as=1; vector<int>u,v,w; vector< pair<int,int> >vct; vector<string>vst; set<int>st,nt,tt; map<int,int>mp,nq,qr; string str,ttr,ntr; long long g,h,aa,bb,cc,dd,f; scanf("%d %d",&l,&r); g=r-l+1; h=g*g; for(i=r;i>=1;i--) { s=0; q=0; s=r/i; q=(l-1)/i; p=s-q; aa=(long long)p; f=aa*aa; if(i!=1) { if(i>=l) { p=p*2; p--; x=x+p; } } ara[i]=f-tra[i]; if(i!=1) { for(j=1;j*j<=i;j++) { if(i%j==0) { fr=j; sc=i/j; tra[fr]=tra[fr]+ara[i]; if(sc!=i && sc!=fr) { tra[sc]=tra[sc]+ara[i]; } } } } //cout<<i<<" "<<ara[i]<<" "<<p<<" "<<tra[i]<<endl; } //cout<<ara[1]<<" "<<x<<endl; h=h-ara[1]; h=h-x; printf("%lld\n",h); return 0; }
/* _ _ |\ / | \ / | / / _ |/ \ \ | \ / | \_/ */ #include<bits/stdc++.h> typedef long long int ll; typedef long double ld; #define vll vector <ll> #define vss vector <string> #define pb push_back #define pf push_front #define popb pop_back #define popf pop_front #define ff first #define ss second #define mp make_pair #define M 1000000007 #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define testcase ll t;cin>>t;while(t--) #define fi(a,b) for(ll i=a;i<b;i++) #define fj(a,b) for(ll j=a;j<b;j++) #define fk(a,b) for(ll k=a;k<b;k++) using namespace std; // ............................................................................................ // int main() { ll n, k; cin>>n>>k; while(k>0) { if(n%200==0) { n/=200; } else { n=(n*1000)+200; } k--; } cout<<n<<endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int int main(){ ll n, k; cin >> n >> k; for(int i=0; i<k; i++){ if(n%200 == 0) n /= 200; else{ n = n * 1000 + 200; } } cout << n << endl; return 0; }
#include<cstdio> using namespace std; const int N = 2e5 + 10; int d[N], n, h[200]; using LL = long long; int main() { scanf("%d", &n); for(int i = 0; i < n; ++i) { scanf("%d", d + i); h[d[i] % 200] ++; } LL res = 0; for(int i = 0; i < 200; ++i) { res += (LL) h[i] * (h[i] - 1) / 2; } printf("%lld\n", res); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int LL; const int mod=998244353; LL po(int p){ if(p==0) return 1ll; LL ret=po(p/2); ret=ret*ret%mod; if(p&1) ret*=2; return ret%mod; } int main(){ int n; scanf("%d",&n); LL a[n]; for(int i=0;i<n;i++) scanf("%lld",a+i); sort(a,a+n); LL ans=0; for(int i=0;i<n;i++) ans=(ans+a[i]*a[i])%mod; LL sum=0,p=1; for(int i=1;i<n;i++){ sum+=p*a[i]; sum%=mod; p*=2; p%=mod; } for(int i=0;i<n-1;i++){ ans=(ans+a[i]*sum)%mod; sum-=a[i+1]; sum=(sum+mod)%mod; sum*=po(mod-2); sum%=mod; } cout<<ans<<"\n"; }
#include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<cstring> #include<map> #include<stack> #include<queue> #include<ctime> #include<vector> #include<set> #include<cstdlib> #include<utility> using namespace std; int fa[1000+5],ans; char a[1000+5][1000+5]; string s; int get(int x) { if (fa[x]==x) return x; return fa[x]=get(fa[x]); } void merge(int x,int y) { if (get(x)==get(y)) return; ans--; fa[get(y)]=get(x); } int main() { int n,m,i,j,minn; scanf("%d%d",&n,&m); ans=n-1; for (i=1;i<=n;i++) { cin >> s; for (j=1;j<=m;j++) a[i][j]=s[j-1]; } a[1][1]=a[1][m]=a[n][1]=a[n][m]='#'; for (i=1;i<=n;i++) fa[i]=i; for (j=1;j<=m;j++) { int last=0; for (i=1;i<=n;i++) if (a[i][j]=='#') { if (last!=0) merge(last,i); last=i; } } minn=ans; ans=m-1; for (i=1;i<=m;i++) fa[i]=i; for (i=1;i<=n;i++) { int last=0; for (j=1;j<=m;j++) if (a[i][j]=='#') { if (last!=0) merge(last,j); last=j; } } minn=min(minn,ans); printf("%d\n",minn); }
#include <bits/stdc++.h> #define rep(a,b,c) for(int a = b; a < c; a++) #define rep2(a,b,c) for(ll a = c - 1; a >=b; a--) #define all(x) (x).begin(), (x).end() #define pb push_back #define x first #define y second using namespace std; using ll = long long; using tl = tuple<ll, ll, ll, ll>; using pl = pair<ll, ll>; using pi = pair<int, int>; using ld = long double; struct dsu { // if u is root : par[u] = -(size of tree) // else: par[u] = parent of u public: dsu() : n(0) {} explicit dsu(int n):n(n), par(n, -1){} int merge(int u, int v){ assert(0 <= u && u < n); assert(0 <= v && v < n); u = find(u); v = find(v); if (u == v) return u; if (-par[u] < -par[v]) swap(u, v); par[u] += par[v]; par[v] = u; return u; } int find(int u) { assert(0 <= u && u < n); if (par[u] < 0) return u; return par[u] = find(par[u]); } bool same(int u, int v) { assert(0 <= u && u < n); assert(0 <= v && v < n); return find(u) == find(v); } int size(int u) { assert(0 <= u && u < n); return -par[find(u)]; } vector<vector<int> > groups() { vector<int> roots(n), groups(n); for (int i = 0; i < n; i++) { roots[i] = find(i); groups[roots[i]]++; } vector<vector<int> > result(n); for (int i = 0; i < n; i++) { result[i].reserve(groups[i]); } for (int i = 0; i < n; i++) { result[roots[i]].push_back(i); } result.erase( remove_if(result.begin(), result.end(), [&](const vector<int>& v) { return v.empty(); }) ); return result; } private: int n; vector<int> par; }; int H, W; string S[1001]; dsu DSU; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> H >> W; rep(i, 0, H) cin >> S[i]; DSU = dsu(H + W); DSU.merge(0, H + 0); DSU.merge(0, H + W - 1); DSU.merge(H - 1, H + 0); DSU.merge(H - 1, H + W - 1); rep(i, 0, H)rep(j, 0, W) { if (S[i][j] == '#') DSU.merge(i, H + j); } map<int, int> m1, m2; rep(i, 0, H) m1[DSU.find(i)]++; rep(i, 0, W) m2[DSU.find(H + i)]++; cout << min(m1.size() - 1, m2.size() - 1); }
#include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; int main(){ int n,sum=0; string ans; cin >> n; int *a = new int[n]; int *b = new int[n]; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i]; for (int i = 0; i < n; ++i) sum+=a[i]*b[i]; if(sum==0)ans="Yes";else ans="No"; cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define ull unsigned long long int #define MAX 1000002 #define MOD 1e9 + 7 #define pb push_back #define w(t) while(t--) #define ff(i,a,b) for(int i=a;i<b;i++) #define ffe(i,a,b) for(int i=a;i<=b;i++) #define fbe(i,b,a) for(int i=b;i>=a;i--) #define fb(i,b,a) for(int i=b;i>a;i--) #define vi vector<int> #define vll vector<ll> #define all(a) a.begin(),a.end() #define elif else if void FAST_IO() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } void solve(){ int n,sum=0; cin>>n; int arr1[n]; int arr2[n]; ff(i,0,n) cin>>arr1[i]; ff(j,0,n) cin>>arr2[j]; ff(i,0,n) sum+=(arr1[i]*arr2[i]); if(sum==0) cout<<"Yes"<<endl; else cout<<"No"<<endl; } int main() { FAST_IO(); /*int t=1; cin>>t; w(t)*/ solve(); }
#include <iostream> #include <unordered_map> using namespace std; int main () { int n,is = 1; cin >> n; string *str = new string[n]; unordered_map<string,int> map; for(int i = 0;i < n;i++) { cin >> str[i]; if(str[i][0] == '!') { str[i].erase(str[i].begin()); if(map.find(str[i]) != map.end()){is = 0;} else{str[i].insert(str[i].begin(),'!');} } else { str[i].insert(str[i].begin(),'!'); if(map.find(str[i]) != map.end()){is = 0;} else{str[i].erase(str[i].begin());} } if(is == 0) { if(str[i][0] == '!') { str[i].erase(str[i].begin()); } cout << str[i]; break; } map[str[i]]++; } if(is){cout << "satisfiable";} return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; vector<string> v; map<string,int> m; for(int i=0;i<n;i++) { string s; cin>>s; if(s[0]=='!') { m[s]=1; } else { v.push_back(s); } } int n1=v.size(); for(int i=0;i<n1;i++) { string s=v[i]; string s1="!"+s; if(m[s1]==1) { cout<<s<<endl; return 0; } } cout<<"satisfiable"<<endl; }
#include <iostream> using namespace std; int main(){ double a, b; cin >> a >> b; cout << a*b/100; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<(n);i++) // 自動でmodを取ってくれる整数型 // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division // const int mod = 1000000007; const int mod = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} bool operator==(const mint a) const { return mint(*this).x == a.x;} bool operator!=(const mint a) const { return mint(*this).x != a.x;} mint pow(ll t) const { // ans=mint(a).pow(b); // a^b if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, const mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} mint f(int n){ // 2のn乗 if(n==0) return 1; mint x=f(n/2); x*=x; if(n%2==1) x*=2; return x; } // a^n mod を計算する long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ////////////////////////// int main(){ ll A,B,C; cin>>A>>B>>C; mint ans=(A+1LL)*A/2; ans*=(B+1LL)*B/2; ans*=(C+1LL)*C/2; cout<<ans<<endl; }
/** * @author Macesuted ([email protected]) * @copyright Copyright (c) 2021 */ #include <bits/stdc++.h> using namespace std; #define int long long #define mod 1000000007 // #define mod 998244353 #define maxn 805 long long fac[maxn], inv[maxn]; long long power(long long a, long long x) { long long ans = 1; while (x) { if (x & 1) ans = ans * a % mod; a = a * a % mod; x >>= 1; } return ans; } inline long long C(int n, int m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; } void INIT(void) { fac[0] = inv[0] = 1; for (register int i = 1; i < maxn; i++) fac[i] = fac[i - 1] % mod; inv[maxn - 1] = power(fac[maxn - 1], mod - 2); for (register int i = maxn - 2; i; i--) inv[i] = inv[i + 1] * (i + 1) % mod; return; } int a[maxn][maxn], b[maxn][maxn]; vector<int> numbers; int n, k; bool check(int lim) { for (register int i = 1; i <= n; i++) for (register int j = 1; j <= n; j++) b[i][j] = (a[i][j] <= lim); for (register int i = 1; i <= n; i++) for (register int j = 1; j <= n; j++) b[i][j] = b[i][j] + b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1]; for (register int i = k; i <= n; i++) for (register int j = k; j <= n; j++) if (b[i][j] - b[i - k][j] - b[i][j - k] + b[i - k][j - k] >= ((k * k + 1) / 2)) return true; return false; } void work(void) { // INIT(); cin >> n >> k; for (register int i = 1; i <= n; i++) for (register int j = 1; j <= n; j++) cin >> a[i][j], numbers.push_back(a[i][j]); sort(numbers.begin(), numbers.end()); int l = 0, r = n * n - 1; if (check(numbers[l])) return cout << numbers[l] << endl, void(); while (l + 1 < r) { int mid = (l + r) >> 1; check(numbers[mid]) ? r = mid : l = mid; } cout << numbers[r] << endl; numbers.clear(); return; } signed main() { ios::sync_with_stdio(false); cout << setiosflags(ios::fixed) << setprecision(3) << endl; int _ = 1; // cin >> _; while (_--) work(); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(n);i++) #define SIZE 801 int a[SIZE][SIZE]; int f[SIZE][SIZE]; int n,k; bool check(int key){ bool rtn=true; REP(i,n) REP(j,n){ if(a[i][j]>=key) f[i][j]=1; else f[i][j]=0; } int count[SIZE]; REP(i,n) count[i]=0; REP(i,n-k+1){ REP(p,n){ if(i==0){ REP(q,k) count[p]+=f[q][p]; }else{ count[p]-=f[i-1][p]; count[p]+=f[i+k-1][p]; } } int ttl=0; REP(j,n-k+1){ if(j==0){ REP(p,k) ttl+=count[p]; }else{ ttl-=count[j-1]; ttl+=count[j+k-1]; } if(ttl<k*k/2+1) rtn=false; } } return rtn; } int binary_search(){ int lb=-1,ub=1e9+1,mid; while(ub-lb>1){ mid=(lb+ub)/2; (check(mid)?lb:ub)=mid; } return lb; } int main(){ cin>>n>>k; int ans=0; REP(i,n) REP(j,n) cin>>a[i][j]; ans=binary_search(); cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ri register int #define rep(io, st, ed) for(int io = st; io <= ed; io ++) #define drep(io, ed, st) for(int io = ed; io >= st; io --) #define gc getchar inline int read() { int p = 0, w = 1; char c = gc(); while(c > '9' || c < '0') { if(c == '-') w = - 1; c = gc(); } while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc(); return p * w; } const int limn = 8e5 + 5; int n, far, lst, cnt; int cap[limn], node[limn], nxt[limn], dep[limn], maxd[limn], son[limn]; void addedge(int u, int v) { nxt[++ cnt] = cap[u]; cap[u] = cnt; node[cnt] = v; } void dfs(int o, int fa) { #define cur node[i] maxd[o] = o; son[o] = 0; for(int i = cap[o]; i; i = nxt[i]) if(fa != cur) { dep[cur] = dep[o] + 1; dfs(cur, o); if(dep[ maxd[cur] ] > dep[ maxd[o] ]) maxd[o] = maxd[cur], son[o] = cur; } } int E[limn]; void dfs2(int o, int fa) { E[o] = E[lst] + dep[o] + dep[lst] - 2 * dep[fa]; lst = o; for(int i = cap[o]; i; i = nxt[i]) if(cur != fa && cur != son[o]) dfs2(cur, o); if(son[o]) dfs2(son[o], o); } int main() { n = read(); rep(i, 2, n) { int u = read(), v = read(); addedge(u, v); addedge(v, u); } dfs(1, 0); //find the diamter int u = maxd[1]; dep[u] = 1; dfs(u, 0); //reset it! dfs2(u, 0); rep(i, 1, n) printf("%d ", E[i]); printf("\n"); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define endl '\n' #define pb push_back #define ub upper_bound #define lb lower_bound #define fi first #define se second #define int long long typedef long long ll; typedef long double ld; #define pii pair<int,int> #define pll pair<ll,ll> #define sz(x) ((long long)x.size()) #define fr(a,b,c) for(int a=b; a<=c; a++) #define frev(a,b,c) for(int a=c; a>=b; a--) #define rep(a,b,c) for(int a=b; a<c; a++) #define trav(a,x) for(auto &a:x) #define all(con) con.begin(),con.end() #define done(x) {cout << x << endl;return;} #define mini(x,y) x=min(x,y) #define maxi(x,y) x=max(x,y) const ll infl = 0x3f3f3f3f3f3f3f3fLL; const int infi = 0x3f3f3f3f; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); //const int mod = 998244353; const int mod = 1e9 + 7; typedef vector<int> vi; typedef vector<string> vs; typedef vector<vector<int>> vvi; typedef vector<pair<int, int>> vpii; typedef map<int, int> mii; typedef set<int> si; typedef set<pair<int,int>> spii; typedef queue<int> qi; uniform_int_distribution<int> rng(0, 1e9); //DEBUG FUNCTIONS START #define cerr cout void __print(int x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifdef LOCAL #define deb(x...) _print(x) #else #define deb(x...) #endif // DEBUG FUNCTIONS END const int N = 2e5 + 5; void solve(){ int n; cin >> n; int ans = n; int x = 1, y = 0; while(x <= n){ int z = y + n / x + (n % x); x *= 2; y++; mini(ans, z); } cout << ans << endl; } signed main() { #ifdef LOCAL (void)!freopen("input.txt","r",stdin); (void)!freopen("output.txt","w",stdout); #endif ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); int t = 1; //cin >> t; while (t--) solve(); return 0; } int powm(int a, int b){ int res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } int divide(int a, int b) { return (a % mod) * powm(b % mod, mod - 2) % mod; }
#define _DEBUG #include "bits/stdc++.h" #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,x,...) x #define debug_1(x1) cout<<#x1<<": "<<x1<<endl #define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl #define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl #define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl #define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl #ifdef _DEBUG #define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__) #else #define debug(...) #endif #define rep(index,num) for(int index=0;index<(int)num;index++) #define rep1(index,num) for(int index=1;index<=(int)num;index++) #define brep(index,num) for(int index=(int)num-1;index>=0;index--) #define brep1(index,num) for(int index=(int)num;index>0;index--) #define scan(argument) cin>>argument #define prin(argument) cout<<argument<<endl #define kaigyo cout<<endl #define eps 1e-7 #define mp(a1,a2) make_pair(a1,a2) #define ALL(a) (a).begin(),(a).end() #define rALL(a) (a).rbegin(),(a).rend() #define puba(a) emplace_back((a)) typedef long long ll; typedef long double ld; using namespace std; typedef pair<ll,ll> pll; typedef pair<int,int> pint; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<pint> vpint; typedef vector<pll> vpll; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } ll INFl=(ll)1e+18+1; int INF=1e+9+1; int main(){ int N,S[200001],T[200001]; ll W,P[200001]; ll imos[200002]={}; scan(N>>W); rep(i,N){ scan(S[i]>>T[i]>>P[i]); imos[S[i]]+=P[i]; imos[T[i]]-=P[i]; } ll maximos=0; rep(i,200002){ if(i>0) imos[i]+=imos[i-1]; chmax(maximos,imos[i]); } if(maximos<=W) prin("Yes"); else prin("No"); return 0; }
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <iostream> #include <cassert> #include <cmath> #include <string> #include <queue> #include <set> #include <map> #include <cstdlib> using namespace std; #define mp make_pair #define pb push_back #define fi first #define se second #define li long long #define pii pair<int, int> #define vi vector<int> #define li long long #define forn(i, n) for (int i = 0; i < (int)n; i++) #define fore(i, b, e) for (int i = (int)b; i <= (int)e; i++) int main() { int tests; scanf("%d", &tests); forn(test, tests) { int n; scanf("%d", &n); vi start(n); forn(i, n) { scanf("%d", &start[i]); } while(true) { vi a = start; vi turns; while(true) { bool sorted = true; forn(i, n - 1) { if (a[i] > a[i + 1]) { sorted = false; break; } } if (sorted) { break; } // forn(i, n) { // printf("%d ", a[i]); // } // printf("\n"); /*if (turns.size() == 2) { break; }*/ int turn = turns.size() % 2; bool found = false; for (int i = turn; i + 1 < n; i += 2) { if (a[i] > a[i + 1]) { swap(a[i], a[i + 1]); turns.pb(i); found = true; break; } } if (!found) { while(true) { int pos = rand() % (n - 1); if (pos % 2 == turn) { swap(a[pos], a[pos + 1]); turns.pb(pos); break; } } } } if (turns.size() <= n * n) { printf("%d\n", (int)turns.size()); for (int x: turns) { printf("%d ", x + 1); } printf("\n"); break; } } } }
#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #define rep(i,n) for(ll i=0;i<(n);++i) #define rep2(i,n) for(ll i=1;i<=(n);++i) #define rep3(i,i0,n) for(ll i=i0;i<(n);++i) #define rrep(i,n) for(ll i=((n)-1); i>=0; --i) #define rrep2(i,n) for(ll i=(n); i>0; --i) #define pb push_back #define mod 1000000007 #define fi first #define se second #define len(x) ((ll)(x).size()) using namespace std; using ll = long long; using ld = long double; using Pi = pair< ll, ll >; using vl = vector<ll>; using vc = vector<char>; using vb = vector<bool>; using vs = vector<string>; using vp = vector<Pi>; using vvc = vector<vector<char>>; using vvl = vector<vector<ll>>; using vvvl = vector<vector<vector<ll>>>; const ll INF = 1LL << 60; const ld PI = 3.1415926535897932385; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) {return a/gcd(a,b)*b;} #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define mp make_pair void printb(ll N,ll d=16){ rep(i,d){ cout<<(N/(1<<(d-i-1)))%2; } cout<<endl; } void printv(vector<ll>a){ rep(i,a.size()){ if(i==a.size()-1){ cout<<a[i]<<endl; }else{ cout<<a[i]<<" "; } } } bool In_map(ll y,ll x,ll h,ll w){ if(y<0 || x<0 || y>=h || x>=w){ return 0; }else{ return 1; } } bool compare(Pi a, Pi b) { if(a.first != b.first){ return a.first < b.first; }else{ return a.second < b.second; } } //const vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1}; //const vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1}; const vector<ll> dx{1,0,-1,0}; const vector<ll> dy{0,1,0,-1}; int main() { ll K; cin>>K; vl AB(K+1); rep2(i,K){ ll now=i; while(1){ if(now>K)break; AB[now]++; now+=i; } //AB[K/i]++; } //printv(AB); //reverse(all(AB)); rep(i,K){ AB[i+1]+=AB[i]; } //printv(AB); ll ans=0; rep2(i,K){ ll now=1; ll cnt=1; ans+=AB[K/i]; } cout<<ans<<endl; //printv(AB); return 0; }
#include <iostream> #include <string> #include <vector> #include <map> #include <set> #include <utility> #include <algorithm> #include <cmath> #include <climits> #include <iomanip> #include <queue> #include <stack> using namespace std; typedef long long ll; const int INF = (1<<30)-1; const ll LINF = 1e18; #define rep(i, n) for (int i = 0; i < n; i++) template<class T> bool chmax(T &a, T b) {if (a < b) {a = b;return true;}else return false;} template<class T> bool chmin(T &a, T b) {if (a > b) {a = b;return true;}else return false;} class union_find { vector<long long> par, sz, h; long long g; //連結成分数 public: union_find(long long n) { par.resize(n); h.resize(n, 0); sz.resize(n,1); g = n; for (long long i = 0; i < n; i++) par[i] = i; } long long find(long long x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } void unite(long long x, long long y) { x = find(x), y = find(y); if (x == y) return ; g--; if (h[x] < h[y]) swap(x, y); sz[x] += sz[y]; sz[y] = sz[x]; par[y] = x; if (h[x] == h[y]) h[x]++; } bool same(long long x, long long y) { return find(x) == find(y); } int size(long long x) { return sz[x] = sz[find(x)]; } long long groups() { return g; } }; int main() { int n; cin >> n; vector<ll> a(n), b(n), vals; rep(i, n){ cin >> a[i] >> b[i]; vals.push_back(a[i]); vals.push_back(b[i]); } sort(vals.begin(), vals.end()); vals.erase(unique(vals.begin(), vals.end()), vals.end()); rep(i, n) { a[i] = lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin(); b[i] = lower_bound(vals.begin(), vals.end(), b[i]) - vals.begin(); } union_find uf(vals.size()); vector<int> cnt(vals.size(), 0); rep(i, n) { int x = uf.find(a[i]), y = uf.find(b[i]); if (x == y) { cnt[x]++; continue; } uf.unite(x, y); if (x != uf.find(x)) swap(x, y); cnt[x] += 1 + cnt[y]; } vector<bool> flag(vals.size(), false); ll ans = 0; rep(i, vals.size()) { if (flag[uf.find(i)]) continue; ans += min(uf.size(i), cnt[uf.find(i)]); flag[uf.find(i)] = true; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define each(e, v) for(auto &e: v) #define pb push_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() using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; //const int MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; struct io_setup{ io_setup(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(15); } } io_setup; int main(){ int N, K; cin >> N >> K; vector<int> cnt(N+1, 0); rep(i, N){ int a; cin >> a; cnt[a]++; } ll ans = 0; rep(i, K){ rep(j, N+1){ if(cnt[j]) cnt[j]--; else{ ans += j; break; } } } cout << ans << '\n'; }
/*************************************************************** File name: D.cpp Author: ljfcnyali Create time: 2021年01月10日 星期日 20时08分49秒 ***************************************************************/ #include<bits/stdc++.h> using namespace std; #define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i ) #define mem(a) memset ( (a), 0, sizeof ( a ) ) #define str(a) strlen ( a ) #define pii pair<int, int> #define int long long typedef long long LL; const int maxn = 1e6 + 10; int n, C, c[maxn], p[maxn], m, ans; map<int, int> Map; struct node { int l, r, w; } a[maxn]; inline int lowbit(int x) { return x & -x; } inline void add(int pos, int val) { for ( int i = pos; i <= m; i += lowbit(i) ) c[i] += val; } inline int get(int pos) { int sum = 0; for ( int i = pos; i > 0; i -= lowbit(i) ) sum += c[i]; return sum; } signed main() { scanf("%lld%lld", &n, &C); REP(i, 1, n) { scanf("%lld%lld%lld", &a[i].l, &a[i].r, &a[i].w); ++ a[i].r; Map[a[i].l] = Map[a[i].r] = true; } for ( auto it : Map ) { Map[it.first] = ++ m; p[m] = it.first; } REP(i, 1, n) { add(Map[a[i].l], a[i].w); add(Map[a[i].r], -a[i].w); } REP(i, 1, m - 1) { int val = min(get(i), C); ans += val * (p[i + 1] - p[i]); } printf("%lld\n", ans); return 0; }
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include<stdio.h> #include<iostream> #include<vector> #include<algorithm> #include<string> #include<string.h> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define NDEBUG #define eprintf(...) do {} while (0) #endif #include<cassert> using namespace std; typedef long long LL; typedef vector<int> VI; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i) template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; } template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; } #define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0) template<unsigned MOD_> struct ModInt { static constexpr unsigned MOD = MOD_; unsigned x; void undef() { x = (unsigned)-1; } bool isnan() const { return x == (unsigned)-1; } inline int geti() const { return (int)x; } ModInt() { x = 0; } ModInt(int y) { if (y<0 || (int)MOD<=y) y %= (int)MOD; if (y<0) y += MOD; x=y; } ModInt(unsigned y) { if (MOD<=y) x = y % MOD; else x = y; } ModInt(long long y) { if (y<0 || MOD<=y) y %= MOD; if (y<0) y += MOD; x=y; } ModInt(unsigned long long y) { if (MOD<=y) x = y % MOD; else x = y; } ModInt &operator+=(const ModInt y) { if ((x += y.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(const ModInt y) { if ((x -= y.x) & (1u<<31)) x += MOD; return *this; } ModInt &operator*=(const ModInt y) { x = (unsigned long long)x * y.x % MOD; return *this; } ModInt &operator/=(const ModInt y) { x = (unsigned long long)x * y.inv().x % MOD; return *this; } ModInt operator-() const { return (x ? MOD-x: 0); } ModInt inv() const { return pow(MOD-2); } ModInt pow(long long y) const { ModInt b = *this, r = 1; if (y < 0) { b = b.inv(); y = -y; } for (; y; y>>=1) { if (y&1) r *= b; b *= b; } return r; } friend ModInt operator+(ModInt x, const ModInt y) { return x += y; } friend ModInt operator-(ModInt x, const ModInt y) { return x -= y; } friend ModInt operator*(ModInt x, const ModInt y) { return x *= y; } friend ModInt operator/(ModInt x, const ModInt y) { return x *= y.inv(); } friend bool operator<(const ModInt x, const ModInt y) { return x.x < y.x; } friend bool operator==(const ModInt x, const ModInt y) { return x.x == y.x; } friend bool operator!=(const ModInt x, const ModInt y) { return x.x != y.x; } }; constexpr LL MOD = 1000000007; // constexpr LL MOD = 998244353; using Mint = ModInt<MOD>; const int MAX = 3000011; Mint inv[MAX], fact[MAX], fact_inv[MAX]; bool _auto_init() { fact[0] = 1; for (int i=1; i<MAX; i++) fact[i] = fact[i-1] * i; fact_inv[MAX-1] = fact[MAX-1].inv(); for (int i=MAX-2; i>=0; i--) fact_inv[i] = fact_inv[i+1] * (i+1); inv[0] = 0; for (int i=1; i<MAX; i++) inv[i] = fact_inv[i] * fact[i-1]; return true; } const bool _auto_init_done = _auto_init(); Mint nCk(int n, int k) { return fact[n] * fact_inv[k] * fact_inv[n-k]; } int N, M, K; void MAIN() { scanf("%d%d%d", &N, &M, &K); Mint ans; if (N - M > K) { ans = 0; } else { ans = nCk(N+M, N); int X = K+1; if (X <= N) { ans -= nCk(N+M, N-X); } } printf("%d\n", ans.geti()); } int main() { int TC = 1; // scanf("%d", &TC); REP (tc, TC) MAIN(); return 0; }
#include <bits/stdc++.h> #define st first #define nd second #define PQ priority_queue using ll = long long ; using namespace std; using pii = pair<int,int>; const int N = 5e3 + 10; const int MOD = 998244353; int dp[N][N], val[N][N], row[N], col[N]; int mul(int x, int y){ return 1LL * x * y % MOD;} int add(int x, int y){ return (1LL * x + y) % MOD;} int main(){ int h, w, k; scanf("%d %d %d", &h, &w, &k); for(int i = 1; i <= h; i++) row[i] = 1; for(int j = 1; j <= w; j++) col[j] = 1; for(int i = 1; i <= k; i++){ char s[3]; int x, y; scanf("%d%d%s", &x, &y, s); if(s[0] == 'R') dp[x][y] = 1; if(s[0] == 'D') dp[x][y] = 2; if(s[0] == 'X') dp[x][y] = 3; } val[1][1] = 1; for(int i = 1; i <= h; i++){ for(int j = 1;j <= w; j++){ if(i == 1 & j == 1) continue; if(dp[i - 1][j] == 0) val[i][j] = add(val[i][j], mul(row[i], mul(2, val[i - 1][j]))); else if(dp[i- 1][j] != 1) val[i][j] = add(val[i][j], mul(row[i], val[i - 1][j])); if(dp[i][j - 1] == 0) val[i][j] = add(val[i][j], mul(col[j], mul(2 , val[i][j - 1]))); else if(dp[i][j - 1] != 2) val[i][j] = add(val[i][j], mul(col[j], val[i][j - 1])); if(dp[i][j] == 0) { col[j] = mul(col[j], 3); row[i] = mul(row[i], 3); } } } if(dp[h][w] == 0) val[h][w] = mul(val[h][w], 3); printf("%d", val[h][w]); }
#include<stdio.h> int main() { int N, X,A; scanf("%d %d", &N, &X); for (int i = 0; i < N; i++) { scanf("%d", &A); if (A != X) { printf("%d ", A); } } return 0; }
#include <bits/stdc++.h> using namespace std; // template {{{ #define range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1) #define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(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 using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; constexpr i32 mod = 1e9 + 7; // constexpr i32 mod = 998244353; 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(), x = input(); vector< int > ans; range(i, 0, n) { int a = input(); if (a == x) continue; ans.emplace_back(a); } cout << ans << endl; } signed main() { solve(); }
#include <bits/stdc++.h> using namespace std; int main() { long long N, a[100000], b[100000]; cin >> N; long long sum = 0; for (int i = 0; i < N; i++) { cin >> a[i] >> b[i]; sum += b[i] * (b[i] + 1) / 2 - a[i] * (a[i] -1) / 2; } cout << sum; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; map<int, string> A; priority_queue<int> B; int t; string s; for(int i=0;i<n;i++){ cin >> s >> t; A[t] = s; B.push(t); } B.pop(); cout << A[B.top()] << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a.at(i); } sort(a.begin(), a.end()); int ans; int ansnum; for (int i = 2; i <= a.at(n - 1); i++) { int count = 0; for (int j = 0; j < n; j++) { if (a.at(j) % i == 0) { count++; } } if (i == 2) { ans = count; ansnum = 2; } else { if (ans < count) { ans = count; ansnum = i; } } } cout << ansnum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; 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 rep(i, n) for (int i = 0; i < (int)(n); ++i) using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>; using vint = vector<int>; using vll = vector<ll>; using vstr = vector<string>; // 定数, 変数 ********************************************* const ll MOD=1e9+7; const ll INF=1ll<<60; int N; // ********************************************************* int main(){ cin >> N ; map<int,int> mp; int an; rep(i,N){ cin >> an; int san = sqrt(an); for(int i=2; i<=san; i++){ if(an%i == 0){ ++mp[i]; if(an/i != i){ ++mp[an/i]; } } } ++mp[an]; } int max=0; int ans=0; for(auto i=mp.begin(); i != mp.end(); i++){ //cout << i->first << " " << i->second<<endl; if(max < i->second){ max = i->second; ans = i->first; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> typedef long long ll; using namespace std; //using namespace atcoder; #define _overload(_1, _2, _3, name, ...) name #define _rep(i, n) for(ll i = 0; i < (ll)n; i++) #define _reps(i, s, n) for(ll i = (ll)(s); i < (ll)n; i++) #define REP(...) _overload(__VA_ARGS__, _reps, _rep,)(__VA_ARGS__) #define all(v) (v).begin(),(v).end() #define UNIQUE(v) (v).erase( unique( all(v) ), (v).end() ); #define MOD 1000000007 int main(){ ll n; cin >> n; ll a[n], b[n]; REP(i, n){ cin >> a[i]; } REP(i, n){ cin >> b[i]; } ll c[n]; ll a_max = a[0]; c[0] = a[0]*b[0]; REP(i, 1, n){ a_max = max(a_max, a[i]); c[i] = max(a_max*b[i], c[i-1]); } REP(i, n){ cout << c[i] << endl; } return 0; }
#include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <cmath> #include <cstring> #include <chrono> #include <complex> #define REP(i,a,b) for (auto i = a; i != b; i++) #define maxheap priority_queue < ll, std::vector<ll>, std::less<ll> > #define minheap priority_queue < ll, std::vector<ll>, std::greater<ll> > // mxheap.push(), mxheap.top(), mxheap.pop() #define ll long long int #define ld long double #define vi vector<int> #define vll vector<ll> #define vvi vector < vi > #define pii pair<int,int> #define pll pair<long long, long long> #define mod 1000000007 #define inf 1000000000000000001 #define all(c) c.begin(),c.end() #define mp(x,y) make_pair(x,y) #define mem(a,val) memset(a,val,sizeof(a)) #define eb emplace_back #define f first #define s second #define pb push_back #define SQ(a) (a)*(a) using namespace std; // using namespace FastIO; void read(int n,vector<int>& x) { x.clear(); x.resize(n); for(int i = 0;i<n;i++) { cin>>x[i]; } } void read(int n,int m,vector<vector<int>>& x) { x.clear(); x.resize(n,vector<int>(m)); for(int i = 0;i<n;i++) { for(int j = 0 ;j<m;j++) cin>>x[i][j]; } } void read(int n,vector<vector<int>>& x) { x.clear(); x.resize(n+1); for(int i = 0;i<n-1;i++) { int a,b; cin>>a>>b; x[a].pb(b); x[b].pb(a); } } void read(int n,vector<vector<int>>& x,int m) { x.clear(); x.resize(n+1); for(int i = 0;i<m;i++) { int a,b; cin>>a>>b; x[a].pb(b); x[b].pb(a); } } void read(int n,vector<ll>& x) { x.clear(); x.resize(n); for(int i = 0;i<n;i++) { cin>>x[i]; } } int main() { std::ios::sync_with_stdio(false); int T = 1; // freopen("mixmilk.in", "r", stdin); // freopen("mixmilk.out", "w", stdout); //cin>>T; for(int t = 1;t<=T;t++) { // cout<<"Case #"<<t<<": "; int n,m; cin>>n; vector<ll> a(n); vector<ll> b(n); read(n,a); read(n,b); ll maxa = 0; ll ans = 0; for(int i=0;i<n;i++){ maxa = max(maxa,a[i]); ans = max(ans,maxa * b[i]); cout<<ans<<endl; } // cout<<ans<<endl; } return 0; }
#include<bits/stdc++.h> #define maxn 1000005 #define inf 0x7fffffffffff #define mod 1000000007 #define mst(a,x) memset(a,x,sizeof(a)) #define up(l,r,i) for(LL i=l;i<=r;i++) #define down(l,r,i) for(LL i=l;i>=r;i--) #define in(l,r,a) for(LL i=l;i<=r;i++)cin>>a[i] #define out(l,r,a) for(LL i=l;i<=r;i++)cout<<a[i]<<" " #define injz(n,m,a) for(LL i=1;i<=n;i++)for(LL j=1;j<=m;j++)cin>>a[i][j] #define st(a,n) sort(a+1,a+n+1) #define sta(v) sort(v.begin(),v.end()) #define endl "\n" #define hh cout<<endl #define pb push_back #define cf cin>>T;while(T--) #define xh(n) U=n;while(U--) #define cfout(x) cout<<(x?"YES":"NO")<<endl #define cs cerr<<"qaq"<<endl #define dbg(n) cerr<<n<<endl typedef long long LL;LL T,U; typedef double db; using namespace std; int main() { ios::sync_with_stdio(false); #ifdef ONLINE_JUDGE #else //freopen("bwxnQAQin.txt","r",stdin); //freopen("bwxnQAQout.txt","w",stdout); #endif LL n,k,ans=0; cin>>n>>k; up(1,n,i) { up(1,k,j)ans+=100*i+j; } cout<<ans<<endl; cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms"; return 0; }
//#pragma GCC optimize ("O2") //#pragma GCC target ("avx2") #include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please int main() { cin.tie(0); ios::sync_with_stdio(false); int H, W; cin >> H >> W; string S[10]; rep(i, H) cin >> S[i]; int kotae = 0; rep(i, H - 1) rep(j, W - 1) { int k = 0; if (S[i][j] == '#') k++; if (S[i][j + 1] == '#') k++; if (S[i + 1][j] == '#') k++; if (S[i + 1][j + 1] == '#') k++; if (k % 2) kotae++; } co(kotae); Would you please return 0; }
// FIRST THINK THEN CODE. #include<iostream> #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 ll long long #define ld long double #define pll pair<ll,ll> #define cld complex<ld> #define vl vector<ll> #define vvl vector<vector<ll>> #define vld vector<ld> #define vvld vector<vector<ld>> #define vpll vector<pll> #define vcld vector<cld> #define ff first #define ss second #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define eb emplace_back #define PI acos(-1) #define endl "\n" #define fix(f,n) fixed<<setprecision(n)<<f #define all(x) x.begin(),x.end() #define rev(p) reverse(p.begin(),p.end()); #define mset(a,val) memset(a,val,sizeof(a)); #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define popcount(x) __builtin_popcountll(x) #define sz(x) ((ll)x.size()) #define FOR(i,a,b) for(ll i=a;i<=b;i++) #define FORR(i,a,b) for(ll i=a;i>=b;i--) const ll M = 1000000007; const ll MM = 998244353; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define ordered_set tree<pll, null_type,less<>, rb_tree_tag,tree_order_statistics_node_update> ll begtime = clock(); #define end_routine() cerr << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; template<typename T, typename F> void chmax( T &a, F b) { if (b > a)a = b; } template<typename T, typename F> void chmin( T &a, F b) { if (b < a)a = b; } const ll N = 2e5 + 5; ll mulmod(ll a, ll b, ll c) { ll ans = 0; ll y = a % c; while (b) { if (b & 1) { (ans += y) %= c; } y = y * 2 % c; b >>= 1; } return ans; } ll powMbig(ll a, ll b, ll m) { if (a <= 0)return 0; a %= m; ll ans = 1LL; while (b) { if (b & 1)//ans = ans * a % m; ans = mulmod(ans, a, m); //a = a * a % m; a = mulmod(a, a, m); b >>= 1; } return ans; } ll powM(ll a, ll b, ll m) { if (a <= 0)return 0; a %= m; ll ans = 1LL; while (b) { if (b & 1)ans = ans * a % m; //ans = mulmod(ans, a, m); a = a * a % m; //a = mulmod(a, a, m); b >>= 1; } return ans; } ll poww(ll a, ll b) { ll ans = 1; while (b) { if (b & 1)ans = ans * a; a = a * a; b >>= 1; } return ans; } vpll arr[N]; vector<vvl> cnt(N, vvl(2, vl(62))); vl foo(60); void dfs(ll node, ll par) { FOR(iter, 0, 59)cnt[node][0][iter] = 1; for (auto to : arr[node]) { // vvl lol(2); ll child = to.ff; if (child == par)continue; dfs(child, node); ll weight = to.ss; for (ll iter = 0; iter < 60; iter++) { ll we = 0; if (1ll << iter & weight)we = 1; (foo[iter] += cnt[node][we][iter] * cnt[child][1][iter]) %= M; (foo[iter] += cnt[node][1 ^ we][iter] * cnt[child][0][iter]) %= M; (cnt[node][0][iter] += cnt[child][0 ^ we][iter]) %= M; (cnt[node][1][iter] += cnt[child][1 ^ we][iter]) %= M; // if (cnt[node][0][iter] > M * M)cnt[node][0][iter] %= M; // if (cnt[node][1][iter] > M * M)cnt[node][1][iter] %= M; // if (foo[iter] > M * M)foo[iter] %= M; } // foo += cnt[node][0] * cnt[node][1]; // cnt[node]=lol; } // FOR(iter, 0, 59) { // if (cnt[node][0][iter] > M * M)cnt[node][0][iter] %= M; // if (cnt[node][1][iter] > M * M)cnt[node][1][iter] %= M; // } } void OJ() { #ifndef ONLINE_JUDGE freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout); #endif } int main() { IOS; OJ(); ll n; cin >> n; vl u(n), v(n), w(n); FOR(i, 0, n - 1) { cin >> u[i] >> v[i] >> w[i]; arr[u[i]].pb({v[i], w[i]}); arr[v[i]].pb({u[i], w[i]}); } ll ans = 0; dfs(1, -1); for (ll i = 0; i < 60; i++) { ans = (ans + foo[i] * powM(2, i, M)) % M; } cout << ans; return 0; }
//12252024832524 #include <cstdio> #include <cstring> #include <algorithm> #define TT template<typename T> using namespace std; typedef long long LL; const int MAXN = 200005; const int MOD = 1e9 + 7; int n; LL ans; LL Read() { LL x = 0,f = 1;char c = getchar(); while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();} while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();} return x * f; } TT void Put1(T x) { if(x > 9) Put1(x/10); putchar(x%10^48); } TT void Put(T x,char c = -1) { if(x < 0) putchar('-'),x = -x; Put1(x); if(c >= 0) putchar(c); } TT T Max(T x,T y){return x > y ? x : y;} TT T Min(T x,T y){return x < y ? x : y;} TT T Abs(T x){return x < 0 ? -x : x;} int head[MAXN],tot; struct edge { int v,nxt; LL w; }e[MAXN << 1]; void Add(LL x){ans = (ans + x) % MOD;} void Add_Edge(int x,int y,LL z) { e[++tot].v = y; e[tot].w = z; e[tot].nxt = head[x]; head[x] = tot; } void Add_Double_Edge(int x,int y,LL z) { Add_Edge(x,y,z); Add_Edge(y,x,z); } LL dp[MAXN][2]; void dfs(int x,int fa,int o) { dp[x][0] = 0; dp[x][1] = 0; for(int i = head[x]; i ;i = e[i].nxt) { int v = e[i].v,w = (e[i].w >> o) & 1; if(v == fa) continue; dfs(v,x,o); if(!w) { Add(dp[x][0] * dp[v][1] % MOD * ((1ll << o) % MOD)); Add(dp[x][1] * (dp[v][0]+1) % MOD * ((1ll << o) % MOD)); dp[x][0] += dp[v][0]+1; dp[x][1] += dp[v][1]; } else { Add(dp[x][0] * (dp[v][0]+1) % MOD * ((1ll << o) % MOD)); Add(dp[x][1] * dp[v][1] % MOD * ((1ll << o) % MOD)); dp[x][0] += dp[v][1]; dp[x][1] += dp[v][0]+1; } } Add(dp[x][1] * ((1ll << o) % MOD)); } int main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); n = Read(); for(int i = 1;i < n;++ i) { int u = Read(),v = Read(); Add_Double_Edge(u,v,Read()); } for(int i = 0;i <= 60;++ i) dfs(1,0,i); Put(ans); return 0; }
#include<bits/stdc++.h> using namespace std; #define GODSPEED ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15); #define f first #define s second #define newl cout<<"\n"; #define pb push_back #define mset(a,x) memset(a,x,sizeof(a)) #define debv(a) for(auto it: a)cout<<it<<" ";newl; #define deb1(a) cout<<a<<"\n"; #define deb2(a,b) cout<<a<<" "<<b<<"\n"; #define deb3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"; #define deb4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"; #define uniq(a) a.resize(unique(a.begin(), a.end()) - a.begin()); #define all(a) a.begin(),a.end() typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; typedef vector<ll> vll; typedef vector<pll> vpll; const ll N = 1e5+5; const ll mod = 998244353; const ll INF = 0x7f7f7f7f7f7f7f7f; const int INFi = 0x7f7f7f7f; ll n, k, a[55][55]; ll p[55], sz[55], f[55]; void make(ll n){ for(int i = 1; i <= n; i++){ p[i] = i; sz[i] = 1; } } int find(ll x){ return (p[x] == x)? x: p[x] = find(p[x]); } void merge(ll x, ll y){ ll a = find(x); ll b = find(y); if(a != b){ if(sz[a] >= sz[b]) swap(a,b); p[a] = b; sz[b] += sz[a]; } } bool can(int x, int y, int f){ if(f == 1){ for(int i = 1; i <= n; i++){ if(a[i][x] + a[i][y] > k) return 0; } } else { for(int i = 1; i <= n; i++){ if(a[x][i] + a[y][i] > k) return 0; } } return 1; } void solve(){ f[0] = 1; for(int i = 1; i < 55; i++) f[i] = f[i - 1] * i % mod; cin >> n >> k; for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ cin >> a[i][j]; } } ll ans = 1; make(n); for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ if(can(i, j, 0)) merge(i, j); } } for(int i = 1; i <= n; i++){ if(find(i) == i){ ans = ans * f[sz[i]] % mod; } } make(n); for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ if(can(i, j, 1)) merge(i, j); } } for(int i = 1; i <= n; i++){ if(find(i) == i){ ans = ans * f[sz[i]] % mod; } } deb1(ans) } int main(){ GODSPEED; int test = 1; //cin >> test; for(int i = 1; i <= test; i++){ solve(); } }
#include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define sz(x) (int)x.size() #define cat(x) cerr << #x << " = " << x << endl #define rep(i, a, b) for (int i = a; i <= b; ++i) #define per(i, a, b) for (int i = b; i >= a; --i) #define all(x) x.begin(), x.end() using ll = long long; using namespace std; const int N = 1 << 20; int n, dp[N], sz[N]; vector<int> g[N]; void dfs(int v) { sz[v] = 1; vector<int> q; vector<pair<int, int>> h; for (auto u : g[v]) { dfs(u); sz[v] += sz[u]; if (sz[u] % 2 == 0) { int he = sz[u] - dp[u]; int im = dp[u]; if (im >= he) { dp[v] += im; } else { dp[v] += min(im, he); q.pb(he - im); } } else { h.pb({2 * dp[u] - sz[u], dp[u]}); } } sort(all(q)); sort(all(h)); reverse(all(h)); rep(i, 0, sz(h) - 1) { if (i % 2 == 0) dp[v] += h[i].se; if (i % 2 == 1) dp[v] += (h[i].fi - h[i].se) * -1; } if (sz(h) % 2 == 1) for (auto x : q) dp[v] += x; } int main() { scanf("%d", &n); rep(i, 2, n) { int p; scanf("%d", &p); g[p].pb(i); } dfs(1); printf("%d\n", n - dp[1]); return 0; }
//W4P3R #include<bits/stdc++.h> #define inf 1e9 #define eps 1e-6 #define mp make_pair #define pb push_back #define re register int #define fr first #define sd second #define pa pair<int,int> #define FOR(i,a,b) for(re i=a;i<=b;i++) #define REP(i,a,b) for(re i=a;i>=b;i--) #define MEM(a) memset(a,0,sizeof(a)) #define N 200010 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; inline ll read() { char ch=getchar(); ll s=0,w=1; while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();} return s*w; } inline int lowbit(int x){return x&(-x);} int n,a[N],x; int main() { //ios::sync_with_stdio(false); //freopen(".in","r",stdin); //freopen(".out","w",stdout); n=read(),x=read(); FOR(i,1,n)a[i]=read(); FOR(i,1,n)if(a[i]!=x)cout<<a[i]<<' ';cout<<'\n'; return 0; } //gl
//#include <atcoder/all> #include <bits/stdc++.h> //using namespace atcoder; using namespace std; typedef long long ll; #define MOD (long long)(1e9+7) #define INF (1LL<<60) #define rep(i,n) for(ll i = 0; i < (n); i++) #define rep1(i,n) for(ll i = 1; i <= (n); i++) template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } // 最大公約数 ll gcd(ll a, ll b) { if(b == 0) return a; return gcd(b, a % b); } // mod m におけるa の逆元 ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // 素因数分解 vector<pair<ll, ll>> prim; void pf(ll n) { ll s = sqrt(n); ll r = 0; for(ll i = 2; i <= s; i++) { if((n % i) == 0) { r = 0; do { r++; n = n / i; } while((n % i) == 0); prim.push_back({i, r}); } } if(n > s) { prim.push_back({n, 1}); } } void solve() { ll N, K; cin >> N >> K; vector<vector<ll>> t(N, vector<ll>(N)); rep(i, N) rep(j, N) cin >> t[i][j]; ll ans = 0; vector<int> v(N); iota(v.begin(), v.end(), 0); do { ll ttl = 0; if(v[0] != 0) break; rep(i, N) { ttl += t[v[i]][v[(i+1)%N]]; } if(ttl == K) ans++; } while( next_permutation(v.begin(), v.end()) ); cout << ans << endl; } int main(void) { // ll t; cin >> t; rep(i, t) solve(); }
#include<bits/stdc++.h> using namespace std; template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;} template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;} using ll =long long; int main(){ int n,m; cin>>n>>m; vector<vector<pair<int,char>>> e(n); bool v[1000][1000]={}; for(int i{},a,b;i<(m);++i){ char c; cin>>a>>b>>c;--a,--b; v[a][b]=v[b][a]=true; e[a].emplace_back(b,c); e[b].emplace_back(a,c); } using ti = tuple<int,int,int>; queue<ti> pq; vector<vector<bool>> cc(n,vector<bool>(n,false)); pq.emplace(0,0,n-1); int ans{INT_MAX}; while(!pq.empty()){ ll c,i,I; tie(c,i,I)=pq.front();pq.pop(); if(ans<=2*c) break; if(i==I){ chmin(ans, 2*c); break; } if(v[i][I]){ chmin(ans,2*c+1); continue; } if(cc[i][I]) continue; cc[i][I]=true; for(auto[j,cj]:e[i]) for(auto[J,cJ]:e[I]) if(cj==cJ){ pq.emplace(c+1, j, J); } } cout<<(ans==INT_MAX?-1:ans)<<'\n'; }
// Problem: F - Rook on Grid // Contest: AtCoder - Panasonic Programming Contest (AtCoder Beginner Contest 186) // URL: https://atcoder.jp/contests/abc186/tasks/abc186_f // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; typedef long long ll; #define forn(i,x,n) for(int i = x;i <= n;++i) const int N = 2e5+7; int r[N],c[N],tr[N]; vector<int> link[N]; int n,m,k; inline int lowbit(int x) { return x & -x; } int query(int x) { int res = 0; for(int i = x;i;i -= lowbit(i)) res += tr[i]; return res; } void modify(int x,int v) { for(int i = x;i <= m;i += lowbit(i)) tr[i] += v; } int main() { scanf("%d%d%d",&n,&m,&k); forn(i,1,n) r[i] = m + 1; forn(i,1,m) c[i] = n + 1; while(k--) { int x,y;scanf("%d%d",&x,&y); c[y] = min(c[y],x); r[x] = min(r[x],y); } ll res = 0; forn(i,1,m) { if(c[i] == 1) break; res += c[i] - 1; } forn(i,1,m) link[c[i]].push_back(i); forn(i,1,n) { if(r[i] == 1) break; res += query(r[i] - 1); // cout << query(r[i] - 1) << endl; if(i == 1) { // cout << r[1] << " " << query(7) << endl; forn(j,r[1],m) { modify(j,1); } } else for(auto j : link[i]) if(j < r[1]) modify(j,1); } printf("%lld",res); return 0; }
#include <bits/stdc++.h> #include <unistd.h> #define rep(i,j,n) for(i=j;i<n;i++) #define repi(i,j,n) for(i=j;i>n;i--) #define pie 3.141592653589793238 #define ll long long #define ld long double #define vll vector<ll> #define pll pair<ll,ll> #define vpll vector<pll> #define pb push_back #define F first #define S second #define endl '\n' #define UQ(x) (x).resize(distance((x).begin(),unique(x.begin(),x.end()))) using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); mt19937_64 rnd64(chrono::high_resolution_clock::now().time_since_epoch().count()); ll power(ll a,ll m,ll mod){ ll ans = 1; while(m){ if(m%2) ans *= a, ans %= (mod); a = (a*a) % mod; m >>= 1; } return ans; } struct custom_hash { // Credits: https://codeforces.com/blog/entry/62393 static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } size_t operator()(pair<int64_t, int64_t> Y) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(Y.first * 31 + Y.second + FIXED_RANDOM); } }; const long long inf = 1e18; const long long M = 1000000007; void solve(){ ll i,j,_; ll n, m; ll mx = LLONG_MAX; cin >> n >> m; ll w[n]; rep(i,0,n) cin >> w[i]; sort(w,w+n); if(n > 1) swap(w[0], w[n - 2]); ll tmp[n]; i = 0; ll l = 0, r = n - 1; // while(i < n) { // if(i%2) tmp[i] = w[r], r--; // else tmp[i] = w[l],l++; // i++; // } // rep(i,0,n) w[i] = tmp[i]; ll l1[m],r1[m]; _ = 10000; rep(i,0,m) cin >> l1[i] >> r1[i]; do { ll dp[n][n]; rep(i,0,n)rep(j,0,n) dp[i][j] = 0; ll bl = 0,t; rep(t,0,m) { l = l1[t], r = r1[t]; rep(i,0,n) { ll now = w[i]; // cout << now << ' ' << r << endl; if(now > r) { cout << -1 << endl; return; // bl = 1; } rep(j,i + 1,n) { now += w[j]; if(now > r) { dp[i][j] = max(dp[i][j], l); break; } } } if(bl) break; } if(bl) continue; // rep(i,0,n) { // rep(j,0,n) { // cout << dp[i][j] << ' '; // } // cout << endl; // } ll k; rep(i,1,n) { rep(j,0,n) { r = j + i; if(r >= n) break; rep(k,j,r+1) { dp[j][r] = max(dp[j][r], dp[j][k] + dp[k][r]); } } } mx = min(mx, dp[0][n-1]); // if(mx == 3802) cout << _ << endl; // cout << dp[0][n-1] << endl; // if(dp[0][n-1] == 3802){ // for(auto i : w) cout << i << ' '; // cout << endl; // } }while ( std::next_permutation(w + 1,w + n - 1)); // cout << _ << endl; if(mx == LLONG_MAX) mx = -1; cout << mx << endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); ll T=1; // cin>>T; while(T--){ solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define PRINT(a) cout << (a) << endl #define pb push_back #define eb emplace_back #define mp make_pair #define Fi first #define Se second #define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n'; using ll = long long int; using P = pair<int,int>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pii = pair<int, int>; template <typename T> using PQ = priority_queue<T>; template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const int INF = 1001001001; const ll LINF = 1001001001001001001ll; const int MOD = 1e9 + 7; bool check(vector<string> &s, map<char,int> &cnv, set<char> &head){ REP(i,3)if(cnv[s[i][0]] == 0)return false; ll s1=0; ll s2=0; ll s3=0; for(auto c: s[0]){ s1 *= 10; s1 += cnv[c]; } for(auto c: s[1]){ s2 *= 10; s2 += cnv[c]; } for(auto c: s[2]){ s3 *= 10; s3 += cnv[c]; } if(s1+s2==s3){ cout << s1 << " " << s2 << " " << s3 << endl; return true; } return false; } int main(){ vector<string> s(3); REP(i,3)cin >> s[i]; set<char> head; head.insert(s[0][0]); head.insert(s[1][0]); head.insert(s[2][0]); map<char,int> mp; REP(i,3){ for(auto c: s[i])mp[c]++; } if(mp.size() > 10){ cout << "UNSOLVABLE" << endl; return 0; } vi p(10); REP(i,10)p[i]=i; do{ int i=0; map<char,int> cnv; for(auto v: mp){ cnv[v.first] = p[i++]; } if(check(s,cnv,head))return 0; }while(next_permutation(ALL(p))); cout << "UNSOLVABLE" << endl; }
#include <bits/stdc++.h> #define sz(v) ((int)(v).size()) #define all(v) ((v).begin()),((v).end()) #define allr(v) ((v).rbegin()),((v).rend()) #define pb push_back #define mp make_pair #define Y imag() #define X real() #define clr(v,d) memset( v, d ,sizeof(v)) #define angle(n) atan2((n.imag()),(n.real())) #define vec(a,b) ((b)-(a)) #define length(a) hypot( (a.imag()),(a.real()) ) #define normalize(a) (a)/(length(a)) #define dp(a,b) (((conj(a))*(b)).real()) #define cp(a,b) (((conj(a))*(b)).imag()) #define lengthsqrt(a) dp(a,a) #define rotate0( a,ang) ((a)*exp( point(0,ang) )) #define rotateA(about,p,ang) (rotate0(vec(about,p),ang)+about) #define lcm(a,b) ((a*b)/(__gcd(a,b))) #define reflection0(m,v) (conj((v)/(m))*(m)) #define reflectionA(m,v,p0) (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0 #define same(p1,p2) ( dp( vec(p1,p2),vec(p1,p2)) < eps ) #define point complex<long double> #define PI acos(-1) typedef long long ll ; typedef unsigned long long ull; const double eps= (1e-15); using namespace std; int dcmp(double a,double b){ return fabs(a-b)<=eps ? 0: (a>b)? 1:-1 ;} int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;} int setBit1(int num, int idx) {return num | (1<<idx);} ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);} ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);} void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);} int countNumBit1(int mask) {int ret=0; while (mask) {mask &= (mask-1);++ret; }return ret;} const ll N=2000+9,mod=998244353,sh=1000000,inf=100000; int a[N],b[N]; int main(){ GO(); int T=1; //cin>>T; while(T--){ ll n,m,t; cin>>n>>m>>t; for(int i=0;i<m;i++) cin>>a[i]>>b[i]; ll pre=n; ll pre_t=0,bal=0; for(int i=0;i<m;i++){ int l,r; l=a[i]; r=b[i]; ll add= r-l; //cout<<pre<<" "<<l<<" "<<pre_t<<"\n"; if(pre-(l-pre_t)<=0){ cout<<"No\n"; return 0; } bal= min(n,pre-(l-pre_t)+add); pre=bal; pre_t=r; } if(pre-(t-pre_t)<=0){ cout<<"No\n"; return 0; } cout<<"Yes\n"; } }
#include <iostream> #include <map> #include <string> #include <utility> #include <list> #include <math.h> #include <vector> #include <algorithm> #include<iomanip> #include <unordered_map> #include <queue> #include <set> using namespace std; typedef long long ll; typedef pair<int, int> pp; #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 MOD 1e9+7 int main() { int A, B, C; cin >> A >> B >> C; if( A >= 0 && B >= 0) { if(A > B) {cout << ">"; return 0;} if(A < B) {cout << "<"; return 0;} if(A == B) {cout << "="; return 0;} } if( A >= 0 && B < 0) { if(C%2==0) { if(A > abs(B)) {cout << ">"; return 0;} if(A < abs(B)) {cout << "<"; return 0;} if(A == abs(B)) {cout << "="; return 0;} } else { cout << ">"; return 0; } } if( A < 0 && B >= 0) { if(C%2==0) { if(abs(A) > abs(B)) {cout << ">"; return 0;} if(abs(A) < abs(B)) {cout << "<"; return 0;} if(abs(A) == abs(B)) {cout << "="; return 0;} } else { cout << "<"; return 0; } } if( A < 0 && B < 0) { if(C%2==0) { if(abs(A) > abs(B)) {cout << ">"; return 0;} if(abs(A) < abs(B)) {cout << "<"; return 0;} if(abs(A) == abs(B)) {cout << "="; return 0;} } else { if(abs(A) > abs(B)) {cout << "<"; return 0;} if(abs(A) < abs(B)) {cout << ">"; return 0;} if(abs(A) == abs(B)) {cout << "="; return 0;} } } //for float, double precision cout << std::fixed << setprecision(15); return 0; }
// C++ program to check if three // points are collinear or not // using area of triangle. #include <bits/stdc++.h> #include <math.h> #include <stdlib.h> using namespace std; // function to check if point // collinear or not // Driver Code int main() { string s;cin>>s; int a[10]={0},p,x1,x2,x3,k=0,k1=1; for (int i=0;i<s.length();i++) a[s[i]-'0']++; if (s.length()==1) { if (s[0]=='8') k=1; } if (s.length()==2) { for (int i=10;i<=99;i++) { if (i%8==0) { int b[10]={0}; p=i; x1=p%10;p=p/10; x2=p%10; b[x1]++;b[x2]++; if (x1==0||x2==0) continue; //b[x1]++;b[x2]++;b[x3]++; else { k1=1; for (int j=1;j<10;j++) { if (b[j]!=a[j]) {k1=0;break;} } } if (k1==1) {k=1;break;} } } } if (s.length()>=3) { for (int i=100;i<=999;i++) { if (i%8==0) { int b[10]={0}; p=i; x1=p%10;p=p/10; x2=p%10;p=p/10; x3=p%10; b[x1]++;b[x2]++;b[x3]++; if (x1==0||x2==0||x3==0) continue; //b[x1]++;b[x2]++;b[x3]++; else { k1=1; for (int j=1;j<10;j++) { if (b[j]>a[j]) {k1=0;break;} } } if (k1==1) {k=1;break;} } } } if (k==1) cout<<"Yes"<<endl; else cout<<"No"<<endl; } // This code is contributed // by Akanksha Rai(Abby_akku)
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define DUMP(x) cout << #x << " = " << (x) << endl; #define FOR(i, m, n) for (ll i = m; i < n; i++) #define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define FOREACH(x, a) for (auto&(x) : (a)) #define ALL(v) (v).begin(), (v).end() #define SZ(x) ll(x.size()) int main() { ll n; cin >> n; vector<string> s(n); REP(i, n) { cin >> s[i]; } vector<map<string, bool>> mps(2); REP(i, n) { if (s[i][0] == '!') { ll len = SZ(s[i]); string sub = s[i].substr(1, len - 1); mps[0][sub] = true; } else { mps[1][s[i]] = true; } } for (auto p : mps[0]) { string t = p.first; if (mps[1][t]) { cout << t << endl; return 0; } } cout << "satisfiable" << endl; }
#include <bits/stdc++.h> using namespace std; long long rec(long long cur, long long tar) { static unordered_map<long long, long long> dp; if (dp.count(cur)) return dp[cur]; if (cur <= tar) return dp[cur] = tar - cur; if (cur & 1) { return dp[cur] = min({cur - tar, rec(cur >> 1, tar) + 2, rec((cur + 1) >> 1, tar) + 2}); } else { return dp[cur] = min(cur - tar, rec(cur >> 1, tar) + 1); } } int main() { long long X, Y; cin >> X >> Y; cout << rec(Y, X) << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; int main() { ll X, Y; cin >> X >> Y; if (X >= Y) { cout << X - Y << "\n"; return 0; } map<ll, int> mp; queue<ll> q; q.push(Y); mp[Y] = 0; ll ans = 1e18; while(!q.empty()) { ll p = q.front(); q.pop(); ans = min(ans, mp[p] + abs(X - p)); if (p % 2) { if (mp.find(p + 1) == mp.end()) { q.push(p + 1); mp[p + 1] = mp[p] + 1; } if (mp.find(p - 1) == mp.end()) { q.push(p - 1); mp[p - 1] = mp[p] + 1; } } else { if (mp.find(p / 2) == mp.end()) { q.push(p / 2); mp[p / 2] = mp[p] + 1; } } } cout << ans << "\n"; }
#include <bits/stdc++.h> #define fi first #define se second #define is_in(x,l,r) ((l) <= (x) && (x) < (r)) #define sz(x) (int)(x).size() #define rng(a) a.begin(),a.end() #define rngr(a) a.rbegin(),a.rend() #define uni(x) x.erase(unique(rng(x)),x.end()) #define rep(i,n) for(int i=0; i<(n); i++) #define rep2(i,x,n) for(int i=x; i<(n); i++) #define ALL(c) (c).begin(), (c).end() #define ALLR(c) (c).rbegin(), (c).rend() #define pb push_back #define eb emplace_back using namespace std; const long long INF = 1LL<<60; // 仮想的な無限大の値; const int inf = 1<<30; const double pi = acos(-1); using ll = long long; using P = pair<int, int>; #define vi vector<int> #define vvi vector<vi> #define vll vector<ll> #define vs vector<string> #define vp vector<P> #define vvp vector<vp> ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll a, ll b){return a * b / gcd(a, b);} 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 dp[105][105][105];// i ko mademite j ko erabu amariga k tonaru min(x-sum) int main() { int n; ll x; cin >> n >> x; vll a(n); rep(i, n) cin >> a[i]; ll ans = INF; rep2(k, 1, n+1){ rep(i, n+1)rep(j, k+1)rep(u, k) dp[i][j][u] = INF; dp[0][0][x%k] = x; rep(i, n)rep(j, k+1)rep(u, k){ if(dp[i][j][u] == INF) continue; chmin(dp[i+1][j][u], dp[i][j][u]); if(j < n){ ll r =((u-a[i])%k + k) %k; chmin(dp[i+1][j+1][r], dp[i][j][u]-a[i]); } } if(dp[n][k][0] != INF) chmin(ans, dp[n][k][0]/k) ; } cout << ans << endl; return 0; }
#pragma GCC target ("avx2") //#pragma GCC optimize "trapv" #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> #define input(a,n) for(ll i1=0;i1<n;i1++)cin>>a[i1] #define ll long long #define pi 2 * acos(0.0) #define usll uset<ll> #define sll set<ll> #define vll vector<ll> #define mll map<ll,ll> #define pll pair<ll,ll> #define umll umap<ll,ll> #define S second #define sz size() #define all(v) v.begin(),v.end() #define Y cout<< "YES"<< "\n" #define N cout<< "NO"<< "\n" #define F first #define mp make_pair #define pb push_back #define pf push_front #define ld long double using namespace __gnu_pbds; using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; template<class T, class H>using umap=unordered_map<T,H,custom_hash>; template<class T>using uset=unordered_set<T,custom_hash>; const ll mod = 1000000007; int main() { clock_t clk = clock(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ll t=1; //cin>>t; while(t--) { ll a,b; cin>>a>>b; ll ans=1; for(ll i=200000;i>=1;i--) { ll val=(a/i)*i; if(val!=a) val+=i; if(val<=b&&(val+i)<=b) { ans=i; break; } } cout<<ans; } // cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n'; return 0; }
#include<iostream> #include<string> #include<iomanip> #include<cmath> #include<vector> #include<algorithm> #include<utility> using namespace std; #define int long long #define endl "\n" constexpr long long INF = (long long)1e18; constexpr long long MOD = 998244353; struct fast_io { fast_io(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); }; } fio; int power(int n, int k){ int res = 1; while(k){ if(k&1) res *= n; k >>= 1; n *= n; n %= MOD; res %= MOD; } return res; } signed main(){ cout<<fixed<<setprecision(10); int N, M; int ans = 0; vector<vector<int>> table; cin>>N>>M; table.resize(M+1, vector<int>(N+1)); for(int i = 0; i < table.size(); i++){ table[i][0] = 1; for(int j = 1; j < table[i].size(); j++){ table[i][j] = table[i][j-1] * i % MOD; } } for(int h = 1; h <= M; h++){ for(int j = 1; j < N-1; j++){ int sum = 0; // sum = (power(M - h + 1, j) - power(M - h, j) + MOD) % MOD; sum = (table[M - h + 1][j] - table[M - h][j] + MOD) % MOD; sum = sum * (h - 1) % MOD; sum = (sum * table[M][N - j - 2]) % MOD; sum = sum * ((h - 1) * (N - j - 1) % MOD + M * 2) % MOD; ans = (ans + sum) % MOD; } if(N-1 > 0){ int sum1 = 0, sum2 = 0; sum1 = (power(M - h + 1, N-1) - power(M - h, N-1) + MOD) % MOD; sum1 = (sum1 * (h - 1) % MOD) % MOD; sum1 = (MOD + sum1 * 2) % MOD; ans = (ans + sum1 + sum2) % MOD; } { int sum1 = 0, sum2 = 0; sum1 = (power(M - h + 1, N) - power(M - h, N) + MOD) % MOD; ans = (ans + sum1 + sum2) % MOD; } } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) #define reps(i,s,n) for(int i=(s); i<(n); i++) #define all(v) v.begin(),v.end() #define outve(v) for(auto i : v) cout << i << " ";cout << endl #define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;} #define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];} #define out(n) cout << (n) << endl #define fi first #define se second #define pb push_back #define si(v) int(v.size()) #define len(v) int(v.length()) #define lob(v,n) lower_bound(all(v),n) #define lobi(v,n) lower_bound(all(v),n) - v.begin() #define upb(v,n) upper_bound(all(v),n) #define upbi(v,n) upper_bound(all(v),n) - v.begin() #define mod 998244353 #define infi 1010000000 #define infl 1100000000000000000 #define cyes cout << "Yes" << endl #define cno cout << "No" << endl #define csp << " " << #define outset(n) cout << fixed << setprecision(n); using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vector<int>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using pii = pair<int,int>; using pll = pair<ll,ll>; template<typename T> using ve = vector<T>; template<typename T> using pq2 = priority_queue<T>; template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>; template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;} template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;} int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; ll ans = 1; vi f(N); in(N,f); rep(i,N) f[i]--; vi ff(N,0); int s = 0; rep(i,N){ if(ff[i] == 1) continue; s = i; set<int> vis; int t = 0; while (ff[s] == 0) { ff[s] = 1; vis.insert(s); s = f[s]; if(vis.count(s)){ t = 1; break; } } if(t == 1) ans *= 2, ans %= mod; s = f[i]; } cout << (ans+mod-1)%mod << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define pb push_back #define all(v) (v).begin(),(v).end() #define fi first #define se second #define sz(x) ((int)(x).size()) using ll=long long; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define MOD 1000000007 const ll INF=1e18; template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<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; } int main(int argc, char const *argv[]) { int n; cin >> n; vector<ll> a(n); rep(i,n) cin >> a[i]; ll ans = -1; rep(i,n){ ll res = 0; ll mini = a[i]; for (int j = i; j < n; j++) { chmin(mini, a[j]); chmax(ans, mini * (j - i + 1)); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ld long double #define int long long #define pi pair<int,int> #define f first #define s second const int nax=3005,inf=1e18; const ld eps=1e-14; void find(ld x,ld r,int& low,int & high) { low=ceil(x-r); high=floor(x+r); } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); int low=0,high=0,res=0,top=0,bottom=0; ld a,b,r,p; cin>>a>>b>>r; r+=eps; find(a,r,low,high); //cout<<low<<' '<<high<<'\n'; for(int i=low;i<=high;i++) { p=sqrt(pow(r,2)-pow((a-(ld)i),2)); find(b,p,bottom,top); //cout<<top<<' '<<bottom<<'\n'; res+=top-bottom+1; } cout<<res; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) using namespace std; using ll = long long; using vi = vector<int>; using vv = vector<vi>; int main(){ int n; cin >> n; double x0, y0, xn, yn; cin >> x0 >> y0 >> xn >> yn; double cx, cy; cx = (x0+xn)/2.0; cy = (y0+yn)/2.0; double vx, vy; vx = x0 - cx; vy = y0 - cy; double nx, ny; nx = cos(2*M_PI/n) * vx - sin(2*M_PI/n) * vy; ny = sin(2*M_PI/n) * vx + cos(2*M_PI/n) * vy; printf("%.6lf %.6lf\n", nx+cx, ny+cy); return 0; }
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> #define ll long long #define test(t) ll int t; cin>>t; while(t--) #define F(i,L,R) for(ll int i=L;i<R;i++) #define F2(i,L,R) for(ll int i=L;i>=R;i--) #define get1(a) ll int a; cin>>a; #define get2(a,b) ll int a,b; cin>>a>>b; #define get3(a,b,c) ll int a,b,c; cin>>a>>b>>c; #define getstr(s) string s; cin>>s; #define getvec(v) get1(n); vector<ll int> v(n,-1); F(i,0,n){ cin>>v[i]; } #define pb push_back #define mp make_pair #define ff first #define ss second #define pp pair< pair<int,int>, pair<int,int> > #define MAX 1000000001 #define printer(cnt) if(cnt==true){cout<<"YES\n";} else{cout<<"NO\n";} using namespace std; int main() { ios_base::sync_with_stdio(0); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif get1(n); get2(a,b); get2(c,d); double cx=(double)(a+c)/2.0 ; double cy=(double)(b+d)/2.0 ; double PI = acos(-1); double theta=360/(double)n; //radians double cost=cos(theta*PI/180),sint=sin(theta*PI/180); double ans_x=(a-cx)*cost-(b-cy)*sint+cx; double ans_y=(a-cx)*sint+(b-cy)*cost+cy; cout<<ans_x<<" "<<ans_y; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ long long n,s,d; long long x,y; cin >> n >> s >> d; for(int i=0;i<n;i++){ cin >> x>> y; if(x<s&&y>d){ cout << "Yes" << endl; return 0; } } cout << "No" << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int a[3]; for(int i=0;i<3;i++){ cin>>a[i]; } sort(a,a+3); if(a[1]-a[0]==a[2]-a[1]) cout<<"Yes"; else cout<<"No"; return 0; }
#include <bits/stdc++.h> #define pb push_back #define all(a) a.begin(),a.end() #define forn(i,n) for(int i=0;i<int(n);i++) #define forr(i,n) for(int i=int(n-1);i>=0;i--) #define fora(i,a,b) for(int i=int(a);i<=int(b);i++) #define forb(i,a,b) for(int i=int(a);i>=int(b);i--) #define mod 1000000007 using namespace std; using ll=long long int; typedef vector<int> vi; typedef pair<int,int> pi; typedef vector<ll> vii; typedef pair<ll ,ll> pii; int ans=1e9; string s; void go(int cur,vector<bool> is,int n) { if(cur==n) { string got=""; int p=0; forn(i,s.size()) { if(is[i]) { got+=s[i]; } else { p++; } } if(got.size()==0)return; ll x=stoll(got); if(x%3==0) { ans=min(ans,p); } return; } is[cur]=false; go(cur+1,is,n); is[cur]=true; go(cur+1,is,n); } void solve() { //string s; cin>>s; vector<bool> is(s.size(),1); go(0,is,s.size()); if(ans==1e9)ans=-1; cout<<ans<<endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; //cin>>t; while(t--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; char num[20]; int n,cnt[5],sum; int main(){ scanf("%s",num); n=strlen(num); for(int i=0;i<n;++i) ++cnt[(num[i]-'0')%3]; sum=(cnt[1]+cnt[2]*2)%3; if(sum==0){ printf("0\n"); return 0; } if(sum==1){ if(cnt[1]){ if(n<=1) printf("-1\n"); else printf("1\n"); } else if(cnt[2]>=2){ if(n<=2) printf("-1\n"); else printf("2\n"); } } else{ if(cnt[2]){ if(n<=1) printf("-1\n"); else printf("1\n"); } else if(cnt[1]>=2){ if(n<=2) printf("-1\n"); else printf("2\n"); } } }
#include <bits/stdc++.h> #include <variant> #define rep2(i,k,n) for(i64 i=(i64)(k);i<(i64)(n);i++) #define rep(i,n) rep2(i,0,n) #define all(x) begin(x),end(x) #ifdef ENV_LOCAL #define dump if (1) cerr #else #define dump if (0) cerr #endif using namespace std; using namespace std::string_literals; using i32 = int32_t; using i64 = int64_t; using f64 = double; using f80 = long double; using vi32 = vector<i32>; using vi64 = vector<i64>; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); i64 n,m,k; cin>>n>>m>>k; vi64 a(k); rep(i,k) cin>>a[i]; vector<f64> c0(n+1); vector<f64> c1(n+1); rep(i,k) c1[a[i]] = 1.0; f64 s0 = 0; f64 s1 = 0; rep(ri,n) { i64 i = n - 1 - ri; s0 += c0[i+1]; s1 += c1[i+1]; if (ri >= m) { s0 -= c0[i+m+1]; s1 -= c1[i+m+1]; } if (c1[i] == 1.0) continue; else { c0[i] = s0 / m + 1.0; c1[i] = s1 / m; } } if (abs(1.0 - c1[0]) < 1e-8) { cout<<-1<<endl; } else { cout<<fixed<<setprecision(10)<<c0[0] / (1.0 - c1[0])<<endl; } return 0; }
#include <bits/stdc++.h> // 1. dp typedef long double ld; #define int long long #define gcd __gcd #define endl "\n" #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define mod2 998244353 #define maxe *max_element #define mine *min_element #define inf 1e18 #define pb push_back #define all(x) x.begin(), x.end() #define f first #define s second #define lb lower_bound #define ub upper_bound #define ins insert #define sz(x) (int)(x).size() #define mk make_pair #define deci(x, y) fixed<<setprecision(y)<<x #define w(t) int t; cin>>t; while(t--) #define nitin ios_base::sync_with_stdio(false); cin.tie(nullptr) #define PI 3.141592653589793238 using namespace std; ld dp[101][101][101]; void solve() { int a,b,c; cin>>a>>b>>c; for(int i=100;i>=0;i--) { for(int j=100;j>=0;j--) { for(int k=100;k>=0;k--) { if(i==0 && j==0 && k==0) continue; if(i==100 || j==100 || k==100) { dp[i][j][k]=0; continue; } dp[i][j][k]=(i*(dp[i+1][j][k]+1)+j*(dp[i][j+1][k]+1)+k*(dp[i][j][k+1]+1))/((ld)(i+j+k)); } } } cout<<deci(dp[a][b][c],9)<<endl; } int32_t main() { nitin; solve(); }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define test() int t;cin>>t;for(int test=1;test<=t;test++) #define pb push_back #define nl cout<<"\n" #define F first #define S second #define all(x) x.begin(),x.end() template<class C> void min_self( C &a, C b ){ a = min(a,b); } template<class C> void max_self( C &a, C b ){ a = max(a,b); } const ll MOD = 1000000007; ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; } const int MAXN = 1e5+5; const int LOGN = 21; const ll INF = 1e14; int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1}; template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD ) { x += y; if( x >= m ) x -= m; } template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD ) { x -= y; if( x < 0 ) x += m; } ll c2( ll n ) { ll ans = n*(n-1); ans /= 2; ans = mod( ans ); return ans; } void solve() { ll n,a,b; cin>>n>>a>>b; if( a > b ) swap(a,b); ll p = n-a-b, q = n-b, r = n-a; if( p < 0 ) { cout<<0,nl; return; } ll ans = 0; add( ans, mod( mod( (r+1)*(q+1) ) * mod( 2*(p+1)*(p+2) ) )); sub( ans, mod( mod( 4 * c2(p+2) ) * c2(p+2) ) ); cout<<ans,nl; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio(); test() { solve(); } cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> #define INT_MINs -2000000000 #define INT_MAXs 1000000001 #define MID int mid=(l+r)/2 #define REP1(i,x,y) for(int i=x;i<y;i++) #define REP2(i,x,y) for(int i=x;i<=y;i++) #define ls (2*k) #define rs (2*k+1) #define lson l,mid,2*k #define rson mid+1,r,2*k+1 #define lc u << 1 #define rc u << 1 | 1 #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f #define IOS ios::sync_with_stdio(0);cin.tie(NULL); #define pb(a) push_back(a) #define pi acos(-1) #define pii pair<int,int> using namespace std; typedef long long ll; typedef unsigned long long ull; const ll mod=1e9+7; const int dx[8] = { 0,-1,0,1,-1,-1,1,1}, dy[8] = { 1,0,-1,0,-1,1,-1,1}; ll qk(ll x,ll y){ ll ans=1; while(y){ if(y&1) ans=ans*x%mod; y>>=1; x=x*x%mod; } return ans; } void solve(){ ll n,m,k; cin>>n>>m>>k; if(n>k+m){ cout<<0<<endl; return; } ll num=1,num2=1; for(ll i=n+m,j=1;i>=n+1;j++,i--){ num=num*i%mod; num2=num2*qk(j,mod-2)%mod; } num=num*num2%mod; ll num3=0,num4=0; if(m+k+1<=m+n){ num3=1,num4=1; for(ll i=n+m,j=1;i>=m+k+2;j++,i--){ num3=num3*i%mod; num4=num4*qk(j,mod-2)%mod; } num3=num3*num4%mod; } cout<<((num-num3)%mod+mod)%mod<<endl; } int main(){ IOS; solve(); return 0; }
/* { ###################### # Author # # Gary # # 2020 # ###################### */ //#pragma GCC target ("avx2") //#pragma GCC optimization ("O3") //#pragma GCC optimization ("unroll-loops") #pragma GCC optimize(2) #include<bits/stdc++.h> #define rb(a,b,c) for(int a=b;a<=c;++a) #define rl(a,b,c) for(int a=b;a>=c;--a) #define LL long long #define IT iterator #define PB push_back #define II(a,b) make_pair(a,b) #define FIR first #define SEC second #define FREO freopen("check.out","w",stdout) #define rep(a,b) for(int a=0;a<b;++a) #define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define random(a) rng()%a #define ALL(a) a.begin(),a.end() #define POB pop_back #define ff fflush(stdout) #define fastio ios::sync_with_stdio(false) #define check_min(a,b) a=min(a,b) #define check_max(a,b) a=max(a,b) using namespace std; //inline int read(){ // int x=0; // char ch=getchar(); // while(ch<'0'||ch>'9'){ // ch=getchar(); // } // while(ch>='0'&&ch<='9'){ // x=(x<<1)+(x<<3)+(ch^48); // ch=getchar(); // } // return x; //} const int INF=0x3f3f3f3f; typedef pair<int,int> mp; /*} */ int n; string s[101]; bitset<101> reach[101]; int main(){ cin>>n; rb(i,1,n) cin>>s[i]; rb(i,1,n) rep(j,n) if(s[i][j]=='1') reach[j+1].set(i); rb(i,1,n) reach[i].set(i); rb(k,1,n) rb(i,1,n) rb(j,1,n) if(reach[i][j]){ reach[i]|=reach[j]; } double rest=0.0; rb(i,1,n) rest+=1.0*n/(reach[i].count()); printf("%.10f\n",rest/n); return 0; } /** 程序框架: * * * * **/
#include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define int long long int #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define vi vector <int> #define ff first #define ss second #define vp vector <pair<int,int>> #define vpp vector <pair<int,pair<int,int>>> #define seti set<int> #define setbit(x) __builtin_popcountll(x) #define sov(v) accumulate(all(v),0) #define fs(it,a) for(auto it=a.begin();it!=a.end();it++) #define pb push_back #define pob pop_back #define mp make_pair #define pqmax priority_queue <int,vector <int>> #define pqmin priority_queue <int,vector <int>,greater<int>> #define dq deque <int> #define umi unordered_map<int,int> #define ums unordered_map<string,int> #define sp(x,y) fixed << setprecision(y) << x #define out(r,x) cout<<"Case #"<<r<<": "<<x<<ee; #define all(x) x.begin(),x.end() #define f(x,y,z) for(x=y;x<z;x++) #define si size() #define countdigit(x) floor(log10(x) +1) #define M 1000000007 #define Z 998244353 #define fill(arr,x) memset(arr,x,sizeof(arr)) //Use (k%M+m)%m always where k is any no #define PI 3.1415926535 #define lcm(a,b) a*b/(__gcd(a,b)) typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pdbs; // // null for set,mapped_type for map; // //less for assending greater for descending //ceil(a/b)=(a+b-1)/b // v.si-1 can never be negative #define ghadi() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n"; clock_t time_p=clock(); #define ee "\n" #define re return //Author Rahul Sannigrahi vector<int> take(int n) { int i,j; vi v; f(i,0,n) { cin>>j; v.pb(j); } return v; } int power(int x,int y) { int res=1; while(y>0) { if(y&1) res=((res%M)*(x%M))%M; y=y>>1; x=((x%M)*(x%M))%M; } re res; } bool sortinrev(const pair<int,int> &a, //desc of vp const pair<int,int> &b) { return (a.first > b.first); } void show(vector<int>v) { int i; for(i=0;i<v.si;i++) { cout<<v[i]<<" "; } cout<<ee; } int gk=1; int ks=0; int decode() { int i,j,k,l,n,m; cin>>n>>k; vi v; f(i,0,n) { cin>>l; v.pb(l); } // // show(v); vi pref(n+1,0); pref[1]=v[0]-1; f(i,2,n+1) pref[i]=pref[i-1]+v[i-1]-v[i-2]-1; // show(pref);/ f(j,0,k) { cin>>m; if(m>pref[n]) cout<<v[n-1]+m-pref[n]<<endl; else { int index; // lower_bound(all(pref),m)-pref.begin(); int r; l=0;r=n; while(l<=r) { int mid=(l+r)/2; if(pref[mid]-m>=0) { index=mid; r=mid-1; } else l=mid+1; } if(index==1) cout<<m<<ee; else if(pref[index]==m) cout<<v[index-1]-1<<ee; else { cout<<v[index-2]+m-pref[index-1]<<ee; } } } re 0; } int32_t main() { IOS // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif int t=1; // cin>>t; while(t--) { if (ks) { cout << "Case #" << gk << ": "; gk++; } decode(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define M (int)(1e9 + 7) const int len = 1e8 + 8; //int ar[len]; bool comp(array<int, 3> a, array<int, 3> b) { if (a[0] == b[0]) { return a[1] < b[1]; } else return a[0] < b[0]; } int solve() { int n; cin >> n; vector<pair<double,double>> values; for(int i=0;i<n;i++){ double t,l,r; cin >> t >> l >> r; if(t == 1) { values.push_back({l,r}); } else if(t==2) { values.push_back({l,r-0.1}); } else if(t==3) { values.push_back({l+0.1,r}); } else { values.push_back({l+0.1,r-0.1}); } } int count = 0; sort(values.begin(),values.end()); for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(values[i].second>= values[j].first) { count++; } } } return count; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // int t; // cin >> t; // while (t--) // { // cout << solve() << "\n"; // //solve(); // } cout << solve() <<"\n"; }
// Etavioxy #include<cstdio> #include<cctype> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<vector> #define il inline #define ll long long #define rep(i,s,t) for(register int i=(s);i<=(t);i++) #define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--) #define each(i,u) for(int i=head[u];i;i=bow[i].nxt) #define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout) #define pt(x) putchar(x) using namespace std; il int ci(){ register char ch;int f=1; while(!isdigit(ch=getchar()))f=ch=='-'?-1:1; register int x=ch^'0'; while(isdigit(ch=getchar()))x=(x*10)+(ch^'0'); return f*x; } enum{N=2004}; struct sth{ int t,l,r; bool operator < (const sth&e){ return l<e.l; } } d[N]; int main(){ int n = ci(); int ans = 0; rep(i,1,n) d[i] = {ci(),ci(),ci()}; sort(d+1,d+n+1); rep(i,1,n){ rep(j,1,i-1){ bool ok = 0; if( d[j].r > d[i].l ) ok = 1; if( d[j].r == d[i].l && (d[j].t&1) && (d[i].t<=2) ) ok = 1; ans += ok; } } cout<<ans<<endl; 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; /* 3000*3000*5*3 2人とったら、おのずと1人きまる 1000*1000*100まで 2人とった場合は出せる。 2ブタン?10以上をもつとか でbool */ ll A[3010][5]; int main(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); ll N; cin >> N; rep(i, N) rep(j, 5) cin >> A[i][j]; ll high=1e9; ll low=1; ll mid=(high+low)/2; while(high > low+1){ set<ll> S; rep(i, N){ ll tmp=0; rep(j, 5){ if (A[i][j]>=mid){ tmp+=1<<j; } } if (tmp) S.insert(tmp); } vector<ll> Q; for(auto s: S) Q.push_back(s); bool fin=false; ll tsz=Q.size(); if(tsz>3){ rep(i, tsz){ for(ll j=i+1; j<tsz; j++){ for(ll k=j+1; k<tsz; k++){ ll t=Q[i]|Q[j]|Q[k]; if (t == ((1<<5)-1)){ fin = true; low = mid; } if(fin) break; } if(fin) break; } if(fin) break; } } else{ ll t=0; for(auto q: Q){ t|=q; } if (t == ((1<<5)-1)){ fin = true; low = mid; } } if(!fin) high=mid; mid = (high+low)/2; } bool fin=false; set<ll> S; rep(i, N){ ll tmp=0; rep(j, 5){ if (A[i][j]>=high){ tmp+=1<<j; } } if (tmp) S.insert(tmp); } vector<ll> Q; for(auto s: S) Q.push_back(s); ll tsz=Q.size(); if(tsz>3){ rep(i, tsz){ for(ll j=i+1; j<tsz; j++){ for(ll k=j+1; k<tsz; k++){ ll t=Q[i]|Q[j]|Q[k]; if (t == ((1<<5)-1)){ fin = true; } if(fin) break; } if(fin) break; } if(fin) break; } } else{ ll t=0; for(auto q: Q){ t|=q; } if (t == ((1<<5)-1)) fin=true; } if(!fin) high--; cout << high << endl; } /* 5 3 2 2 2 2 2 3 2 2 2 2 2 3 2 2 2 2 2 3 2 2 2 2 2 3 */
#include <bits/stdc++.h> using namespace std; const int N = 3000 + 9; int a[N][5], b[N]; int cnt[1 << 5]; vector<int> vc[N]; bool check(int x, int n) { memset(cnt, 0, sizeof(cnt)); for (int i = 1; i <= n; ++i) { b[i] = 0; for (int j = 0; j < 5; ++j) { if (a[i][j] >= x) { b[i] |= 1 << j; } } ++cnt[b[i]]; } for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { --cnt[b[i]]; --cnt[b[j]]; int x = ~(b[i] | b[j]) & 31; if (!x) return true; for (int y : vc[x]) if (cnt[y]) return true; ++cnt[b[i]]; ++cnt[b[j]]; } } return false; } int main() { for (int i = 0; i < (1 << 5); ++i) { for (int j = 0; j < (1 << 5); ++j) { if ((i & j) == i) vc[i].push_back(j); } } int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { for (int j = 0; j < 5; ++j) { scanf("%d", &a[i][j]); } } int L = 1, R = 1000000000; while (L < R) { int M = ((L + R) >> 1) + 1; if (check(M, n)) L = M; else R = M - 1; } printf("%d\n", L); return 0; }
#include <bits/stdc++.h> #include <cstdlib> using namespace std; using ll = long long; #define rep(i, n) for(i = 1; i <= n; i++) #define rep2(i, n) for(i = 0; i < n; i++) //2D::rep(i,j)rep(j,j)cin>>bin[i][j]; //vector<int> a(n) #define Graph vector<vector<int>> #define A1 cout<<"No"<<endl #define A2 cout<<"Yes"<<endl #define A3 cout<<ans<< #define AA(i) cout<<i<<endl; const int U=2e5+5; const ll MOD=1000000007; const int INF = 1001001001; int main(){ int i,j,N; cin >> N; vector<bool> A(N+1,true); string S; rep(i,N){ S = std::to_string(i); rep2(j,S.size()){ if(S[j] == '7'){ A[i] = false; break; } } if(A[i]==false){ continue; } stringstream K; K << std::oct << i; S = K.str(); rep2(j,S.size()){ if(S[j] == '7'){ A[i] = false; break; } } } int ans = 0; rep(i,N){ if(A[i]) ans++; } AA(ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define endl '\n' #define all(x) x.begin(),x.end() #define sz(x) (ll)x.size() #define MOD 1000000007 #define F first #define S second #ifdef LOCAL #include "trace.h" #else #define trace(args...) #endif ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);} ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);} bool isVal(ll n, ll base){ while(n>0){ ll rem = n%base; if(rem==7) return false; n = n/base; } return true; } void solve(){ ll n; cin>>n; ll ans = 0; for(ll i = 1; i<=n; i++) ans += isVal(i, 10)&&isVal(i, 8); cout<<ans<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifdef LOCAL freopen("inp.txt", "r", stdin); freopen("out.txt", "w", stdout); freopen("err.txt", "w", stderr); #endif int t=1; // cin>>t; while(t--) solve(); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define OJ \ freopen("swap.in", "r", stdin); \ freopen("swap.out", "w", stdout); void no(){ cout<<"No"; exit(0); } int main(){ ios::sync_with_stdio(0);cin.tie(0); ll n; ll k=11; cin>>n; //n+11Cn but this will include 0 solution also ll n1=n-1; if(n1==k) { cout<<1; return 0; } ll r=k; ll res=1; if(n1-k<k){ r=n1-k; } for(int i=1;i<=r;i++){ res=res*(n-i)/i; } cout<<res<<"\n"; }
#include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; using P = pair<int,int>; int main() { int x; cin >> x; if(x >= 0) cout << x << endl; else cout << 0 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long cur[101][10001], pre[101][10001]; long long MOD = 998244353; int main() { int N; cin >> N; vector<int> W(N); for(int i = 0; i < N; i++) { cin >> W[i]; } pre[0][0] = 1LL; int sum = 0; for(int i = 0; i < N; i++) sum += W[i]; for(int i = 1; i <= N; i++) { for(int make = 0; make <= sum; make++) { for(int use = 0; use <= N; use++) { cur[use][make] = pre[use][make]; if(W[i - 1] <= make && use > 0) cur[use][make] += pre[use - 1][make - W[i - 1]]; if(cur[use][make] > MOD) cur[use][make] -= MOD; } } for(int make = 0; make <= sum; make++) for(int use = 0; use <= N; use++) pre[use][make] = cur[use][make]; } vector<long long> f(N + 1); f[0] = 1LL; for(int i = 1; i <= N; i++) f[i] = f[i - 1] * 1LL * i % MOD; long long ans = 0LL; if(sum % 2) { cout << 0 << "\n"; return 0; } for(int use = 0; use <= N; use++) { ans += f[use] * 1LL * f[N - use] % MOD * pre[use][sum / 2] % MOD; ans %= MOD; } if(ans < 0) ans += MOD; cout << ans; }
#include<bits/stdc++.h> using namespace std; typedef long long s64; const int N=100+5,D=998244353; int dp[N*N][N]; s64 fact[N]; int main(){ #ifdef kcz freopen("1.in","r",stdin);//freopen("1.out","w",stdout); #endif int n; cin>>n; int sum=0; bool d=0; dp[0][0]=1; for(int i=1;i<=n;++i){ d^=1; int w; cin>>w; sum+=w; for(int j=sum;j>=w;--j) for(int k=1;k<=i;++k)(dp[j][k]+=dp[j-w][k-1])%=D; } if(sum%2){ puts("0"); exit(0); } fact[0]=1; for(int i=1;i<=n;++i)fact[i]=fact[i-1]*i%D; s64 ans=0; for(int k=0;k<=n;++k){ (ans+=dp[sum/2][k]*fact[k]%D*fact[n-k])%=D; } cout<<ans<<endl; }
#include <bits/stdc++.h> template <typename T> T next() { T temp; std::cin >> temp; return temp; } template <> int next() { int temp; scanf("%d", &temp); return temp; } template <> long long next() { long long temp; scanf("%lld", &temp); return temp; } template <> double next() { double temp; scanf("%lf", &temp); return temp; } template <> float next() { float temp; scanf("%f", &temp); return temp; } template <typename T1, typename T2> std::pair<T1, T2> next() { std::pair<T1, T2> temp; temp.first = next<T1>(); temp.second = next<T2>(); return temp; } template <typename T> std::vector<T> next(int n) { std::vector<T> temp(n); for(int i = 0; i < n; i++) temp[i] = next<T>(); return temp; } template <typename T1, typename T2> std::vector<std::pair<T1, T2>> next(int n) { std::vector<std::pair<T1, T2>> temp(n); for(int i = 0; i < n; i++) temp[i] = next<T1, T2>(); return temp; } template <typename T> void print(const T &x, char endc = '\n') { std::cout << x << endc; return; } void print(const int &x, char endc = '\n') { printf("%d%c", x, endc); return; } void print(const long long &x, char endc = '\n') { printf("%lld%c", x, endc); return; } void print(const size_t &x, char endc = '\n') { printf("%zu%c", x, endc); return; } void print(const float &x, char endc = '\n') { printf("%f%c", x, endc); return; } void print(const double &x, char endc = '\n') { printf("%lf%c", x, endc); return; } template<typename T1, typename T2> void print(const std::pair<T1, T2> &p, char sepc = ' ', char endc = '\n') { print(p.first, sepc); print(p.second, endc); return; } template<typename T> void print(const std::vector<T> &v, char sepc = ' ', char endc = '\n') { for(const T &e : v) print(e, sepc); printf("%c", endc); return; } using namespace std; void eachTC() { int N = next<int>(); string s = next<string>(); int res = 0; if(s[0] != s[N-1]) res = 1; else { res = -1; for(int i = 0; i < N-1; i++) { if(s[i] != s[0] && s[i+1] != s[0]) { res = 2; break; } } } print(res); } int main() { constexpr bool multipleTC = false; int T = multipleTC ? next<int>() : 1; while(T--) eachTC(); return 0; }
#include<iostream> using namespace std; int main() { char a,b,c; cin>>a>>b>>c; if(a==b&&b==c) { cout<<"Won"; } else cout<<"Lost"; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, t, take; cin >> t >> n; take = (100 + t - 1) / t; for (long long i = n * (take - 1); i <= n * (take + 1); i++) { if ((i * t) / 100 == n) { cout << i + n - 1 << "\n"; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; // type alias typedef long long LL; typedef pair<int,int> II; typedef tuple<int,int,int> III; typedef vector<int> VI; typedef vector<string> VS; typedef unordered_map<int,int> MAPII; typedef unordered_set<int> SETI; template<class T> using VV=vector<vector<T>>; // minmax template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; } template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; } // repetition #define FORE(i,a,b) for(int i=(a);i<=(b);++i) #define REPE(i,n) for(int i=0;i<=(n);++i) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) for(int i=0;i<(n);++i) #define FORR(x,arr) for(auto& x:arr) #define SZ(a) int((a).size()) // collection #define ALL(c) (c).begin(),(c).end() // DP #define MINUS(dp) memset(dp, -1, sizeof(dp)) #define ZERO(dp) memset(dp, 0, sizeof(dp)) // stdout #define println(args...) fprintf(stdout, ##args),putchar('\n'); // debug cerr template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; } void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; } template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); } template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; } #define __KUMATRACE__ true #ifdef __KUMATRACE__ #define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); } #define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; } #define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); } #else #define dump(args...) #define dumpc(ar) #define dumpC(beg,end) #endif // $ cp-batch TaxIncludedPrice | diff TaxIncludedPrice.out - // $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address TaxIncludedPrice.cpp && ./a.out /* 5/9/2021 22:56- */ LL N; int T; void solve() { LL good=0, bad=1e15; while(abs(good-bad)>1) { LL m=(good+bad)/2; LL x=m*(100+T)/100; (((x-m)<=N-1)?good:bad)=m; } LL x1=good*(100+T)/100; LL x2=(good+1)*(100+T)/100; assert(x2==x1+2); assert(x1-good==N-1); cout<<x1+1<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout<<setprecision(12)<<fixed; cin>>T>>N; solve(); return 0; }
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; ///Welcome to Nasif's Code #define bug printf("bug\n"); #define bug2(var) cout<<#var<<" "<<var<<endl; #define co(q) cout<<q<<endl; #define all(q) (q).begin(),(q).end() #define pi acos(-1) #define inf 1000000000000000LL #define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define MODADD(ADD_X,ADD_Y) (ADD_X+ADD_Y)%MOD #define MODSUB(SUB_X,SUB_Y) ((SUB_X-SUB_Y)+MOD)%MOD #define MODMUL(MUL_X,MUL_Y) (MUL_X*MUL_Y)%MOD #define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int ll; typedef unsigned long long int ull; const int MOD = (int)1e9+7; const int MAX = 1e6; int dx[]= {1,0,-1,0,1,-1,1,-1}; int dy[]= {0,1,0,-1,1,-1,-1,1}; int parent[MAX+50],fam[MAX+50],ans[MAX],dep[MAX]; vector<pair<int,int> >adj[MAX]; int root(int child) { while(parent[child]!=child) { parent[child]=parent[parent[child]]; child=parent[child]; } return child; } void node_union(int x,int y) { int a=root(x); int b=root(y); parent[min(a,b)]=parent[max(a,b)]; } void dfs(int src,int par,int h) { dep[src]=h+1; if(ans[src]==ans[par] && par!=0) { int id=1; if(ans[par]==id) id++; for(auto it:adj[src]) { if(it.second==id) id++; } ans[src]=id; } for(auto it:adj[src]) { if(it.first==par) continue; ans[it.first]=it.second; dfs(it.first,src,h+1); } } int main() { FastRead //freopen("output.txt", "w", stdout); for(int i=1; i<=MAX; i++) parent[i]=i; int n,m; cin>>n>>m; int cnt=0; for(int i=0; i<m; i++) { int a,b,c; cin>>a>>b>>c; if(root(a)!=root(b)) { cnt++; adj[a].push_back({b,c}); adj[b].push_back({a,c}); node_union(a,b); } } if(cnt!=n-1) { cout<<"No"<<endl; return 0; } dfs(1,0,0); int id=1; for(auto i:adj[1]) if(i.second==id) id++; ans[1]=id; for(int i=1; i<=n; i++) cout<<ans[i]<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define ff first #define ss second #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) ((a)*(b))/gcd((a),(b)) #define endl "\n" #define pi 3.14159265358979323846 #define inf 1000000000 #define setbits(x) __builtin_popcountll(x) #define ll long long #define int long long #define ld long double #define lb lower_bound #define ub upper_bound #define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); const int N = 2e5+50; const ll INF = 1e9; // int dx[9]={-1,-1,-1,0,1,1,1,0,0}; // int dy[9]={-1,0,1,1,1,0,-1,-1,0}; int dx[] = {-1,0,1,0}; int dy[] = {0,1,0,-1}; //only for prime m template<typename T> void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif const int mod = 1e9 + 7; bool compare(const pair<ll, ll>&i, const pair<ll, ll>&j){ return i.second < j.second; } ll modexp(ll x,ll n){ ll r=1; while(n){ if(n&1)r=(r*x)%mod; x=(x*x)%mod; n>>=1;} return r%mod;} ll modinv(ll x){ return modexp(x,mod-2);} // ll ncr(ll n,ll r){ if(n<r) return 0; ll ans=(fact[n]%mod * modinv(fact[r])%mod * modinv(fact[n-r])%mod)%mod; return ans;} 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){a=a%mod; b=b%mod; return (((a+b)%mod)+mod)%mod;} ll mod_mul(ll a,ll b){a=a%mod; b=b%mod; return (((a*b)%mod)+mod)%mod;} ll mod_sub(ll a,ll b){a=a%mod; b=b%mod; return (((a-b)%mod)+mod)%mod;} ll mod_div(ll a,ll b){a=a%mod; b=b%mod; return (mod_mul(a,modinv(b))+mod)%mod;} int n,m; vector<int>adj[2005]; vector<pair<int,int>>ans; int vis[2005]; void dfs(int x,int par){ ans.pb(mp(x,par)); vis[x]=1; for(auto ch:adj[x]){ if(ch!=par and !vis[ch]){ dfs(ch,x); } } } void solve(){ cin>>n>>m; for(int i=0;i<m;i++){ int a,b; cin>>a>>b; adj[a].pb(b); } for(int i=1;i<=n;i++){ memset(vis,0,sizeof(vis)); dfs(i,i); } debug(ans); cout<<ans.size()<<endl; return ; } int32_t main() { fio // #ifdef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif // pre(); int t=1; // cin>>t; for(int i=0;i<t;i++) { solve(); } return 0; }