code_file1
stringlengths
80
4k
code_file2
stringlengths
91
4k
similar_or_different
int64
0
1
#include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <set> #include <iostream> #include <string> #include <vector> #include <algorithm> #include <sstream> #include <complex> #include <stack> #include <queue> #include <cstdio> #include <cstring> #include <iterator> #include <bitset> #include <unordered_set> #include <unordered_map> #include <fstream> #include <iomanip> #include <cassert> //#include <utility> //#include <memory> //#include <functional> //#include <deque> //#include <cctype> //#include <ctime> //#include <numeric> //#include <list> //#include <iomanip> //#if __cplusplus >= 201103L //#include <array> //#include <tuple> //#include <initializer_list> //#include <forward_list> // //#define cauto const auto& //#else //#endif using namespace std; 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 F, class T> void convert(const F &f, T &t){ stringstream ss; ss << f; ss >> t; } #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define reep(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) reep((i),0,(n)) #define ALL(v) (v).begin(),(v).end() #define PB push_back #define F first #define S second #define mkp make_pair #define RALL(v) (v).rbegin(),(v).rend() #define DEBUG #ifdef DEBUG #define dump(x) cout << #x << " = " << (x) << endl; #define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; #else #define dump(x) #define debug(x) #endif #define LDcout(x,n) fixed<<setprecision(n)<<x #define MOD 1000000007LL #define EPS 1e-8 #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3fLL #define maxs(x,y) x=max(x,y) #define mins(x,y) x=min(x,y) void mainmain(){ int n; while(cin>>n,n){ rep(i,n){ vint v(3); rep(j,3) cin>>v[j]; vint w=v; sort(ALL(w)); if(w[2]==100) cout<<"A"<<endl; else if(v[0]+v[1]>=180) cout<<"A"<<endl; else if(v[0]+v[1]+v[2]>=240) cout<<"A"<<endl; else if(v[0]+v[1]+v[2]>=210) cout<<"B"<<endl; else if(v[0]+v[1]+v[2]>=150&&max(v[0],v[1])>=80) cout<<"B"<<endl; else cout<<"C"<<endl; } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout<<fixed<<setprecision(20); mainmain(); }
#include<iostream> #include<cstdio> using namespace std; #define N 200012 int n,a[N],las=0;bool vis[N];long long ans=0; int main(){ scanf("%d",&n);int i,l,r,lef;bool fl=true; for(i=1;i<=n;i++)scanf("%d",&a[i]); for(i=1;i<=n;i=r+1) { l=r=i;while((r<n)&&(a[r+1]==(a[r]+1)))++r; lef=l-a[l];if(lef<=las){printf("-1");fl=false;break;} ans+=r-lef;las=lef; }if(fl)printf("%lld",ans);return 0; }
0
#include<iostream> #include<vector> #include<algorithm> using namespace std; struct edge{ int u; //????????? int v; //??°?????? int cost; //?????? //???????????????????????§?????§?°???¢???????????? bool operator<(const edge& another) const { return cost < another.cost; } }; const int MAX_N = 100000; const int MAX_M = 100000; edge es[MAX_M]; int par[MAX_N]; int rank[MAX_N]; void initial(int n){ //????????? for(int i=0;i<n;i++){ par[i] = i; rank[i] = 0; } } int find(int x){ //??¨??????????±??????? if(par[x] == x){ return x; }else{ return par[x] = find(par[x]); } } void unite(int x,int y){ //x???????????¨??¨y???????????¨????????? x = find(x); //x???????????¨??????????????????x??¨?????? y = find(y); //y???????????¨??????????????????y??¨?????? if(x == y) return; if(rank[x] < rank[y]){ par[x] = y; }else{ par[y] = x; if(rank[x] == rank[y]) rank[x]++; } } bool same(int x,int y){ //x,y???????????¨???????????§????????? return find(x) == find(y); } bool comp(const edge& e1,const edge& e2){ return e1.cost < e2.cost; } int kruskal(int n,int m){ initial(n); int res = 0; for(int i=0;i<m;i++){ edge e = es[i]; if(!same(e.u,e.v)){ unite(e.u,e.v); res += e.cost; } } return res; } int main(){ int n,m,j,k,l; cin >> n; //????????°?????\??? cin >> m; //?????°?????\??? for(int i=0;i<m;i++){ cin >> j >> k >> l; es[i].u = j; es[i].v = k; es[i].cost = l; } sort(es,es+m); cout << kruskal(n,m) << "\n"; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using vll = vector<ll> ; using vs = vector<string> ; #define all(v) v.begin(),v.end() const int MAX_V = 210; const int INF = 1e5; int V; vll G[MAX_V]; int match[MAX_V]; bool used[MAX_V]; void add_edge(int u,int v){ G[u].push_back(v); G[v].push_back(u); } bool dfs(int v){ used[v]=true; rep(i,G[v].size()){ int u = G[v][i], w = match[u]; if(w<0 || !used[w] && dfs(w)){ match[v] = u; match[u] = v; return true; } } return false; } int bipartite_matching(){ int res = 0; memset(match, -1, sizeof(match)); rep(v,V){ if(match[v]<0){ memset(used, 0, sizeof(used)); if(dfs(v)) res++; } } return res; } int main(){ cin>>V; vector<pair<int,int>> red,blue; rep(i,V){ int a,b;cin>>a>>b;red.push_back(make_pair(a,b)); } rep(i,V){ int c,d;cin>>c>>d;blue.push_back(make_pair(c,d)); } rep(i,V){ rep(j,V){ pair<int,int> r,b; r = red[i],b=blue[j]; if(r.first<b.first && r.second<b.second) add_edge(i,j+V); } } //cout << "グラフ" << endl; //rep(i,V)rep(j,G[i].size()) cout<< i << " " << G[i][j]<<endl; cout << bipartite_matching() << endl; }
0
#include <bits/stdc++.h> using namespace std; #define lli long long int #define REP(i,s,n) for(int i=s;i<n;i++) #define MOD 1000000007 #define NUM 2520 #define INF (1LL<<50) #define DEBUG 0 #define mp(a,b) make_pair(a,b) #define SORT(V) sort(V.begin(),V.end()) #define PI (3.141592653589794) const int MAX = 510000; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } void func(long long N, long long M, long long K){ COMinit(); lli sum = 0; REP(i,0,N){ REP(j,0,M){ if(i!=0 && j!=0) sum += (2*( N-i)*(M-j)*(i+j))%MOD; else sum += ((N-i)*(M-j)*(i+j))%MOD; sum%= MOD; } } sum *= COM(N*M-2,K-2); sum %= MOD; cout<<sum<<endl; } int main(){ // cout << fixed << setprecision(5); long long N; scanf("%lld",&N); long long M; scanf("%lld",&M); long long K; scanf("%lld",&K); func(N, M, K); return 0; }
#include <bits/stdc++.h> #define ll long long int #define MOD 1000000007 #define INF 1000000000000000000 using namespace std; ll power(ll n, ll k){ ll res = 1; while(k > 0){ if (k & 1) res = res * n % MOD; n = n * n % MOD; k >>= 1; } return res; } ll genfact(ll n, ll k){ ll res = 1; k--; while (k >= 0){ res = (res * (n - k)) % MOD; k--; } return res; } ll inv(ll n){ return power(n, MOD - 2); } ll fact(ll n){ return genfact(n, n - 1); } ll nck(ll n, ll k){ if (k == 0) return 1; if (n <= 0) return 0; return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD; } int main(void){ ll n, m, k; cin >> n >> m >> k; ll ans = 0; ll t = nck(n*m-2,k-2); for (ll j = 1; j < m; j++){ ans += j*(m-j) % MOD * n % MOD *n % MOD * t % MOD; ans = (ans % MOD); } for (ll i = 1; i < n; i++){ ans += i*(n-i) % MOD * m % MOD *m % MOD * t % MOD; ans = (ans % MOD); } cout << ans << endl; return 0; }
1
#include <bits/stdc++.h> #define PI 3.1415926535897932 #define _GLIBCXX_DEBUG using namespace std; long long GCD(long long A,long long B){ if(B==0){ return A; } else{ return GCD(B,A%B); } } int main() { string A,B,C; cin>>A>>B>>C; deque<char> X; for(int i=0;i<A.size();i++){ X.push_back(A[i]); } deque<char> Y; for(int i=0;i<B.size();i++){ Y.push_back(B[i]); } deque<char> Z; for(int i=0;i<C.size();i++){ Z.push_back(C[i]); } int check=1; string ans; while(true){ if(check==1){ if(X.empty()){ ans="A"; break; } if(X.front()=='a'){ check=1; X.pop_front(); } else if(X.front()=='b'){ check=2; X.pop_front(); } else if(X.front()=='c'){ check=3; X.pop_front(); } } else if(check==2){ if(Y.empty()){ ans="B"; break; } if(Y.front()=='a'){ check=1; Y.pop_front(); } else if(Y.front()=='b'){ check=2; Y.pop_front(); } else if(Y.front()=='c'){ check=3; Y.pop_front(); } } else if(check==3){ if(Z.empty()){ ans="C"; break; } if(Z.front()=='a'){ check=1; Z.pop_front(); } else if(Z.front()=='b'){ check=2; Z.pop_front(); } else if(Z.front()=='c'){ check=3; Z.pop_front(); } } } cout<<ans<<endl; }
#include <bits/stdc++.h> template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}} template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}} #define ll long long #define double long double #define rep(i,n) for(int i=0;i<(n);i++) #define REP(i,n) for(int i=1;i<=(n);i++) #define mod (ll)(1e9+7) #define inf (ll)(3e18+7) #define pi (double) acos(-1.0) #define P pair<int,int> #define PiP pair<int,pair<int,int>> #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() using namespace std; bool check(int w, int bit){ bool ok = true; vector<int> a(w); rep(i, w){ if(bit & (1<<i))a[i] = 1; else a[i] = 0; } REP(i, w-1)if(a[i] == a[i-1] && a[i] == 1)ok = false; return ok; } int main() { int h, w, k; cin >> h >> w >> k; vector<vector<ll>> dp(h+1, vector<ll>(w, 0)); dp[0][0] = 1; rep(i, h){ for(int bit = 0; bit < (1<<(w-1)); bit++){ if(!check(w-1, bit))continue; vector<int> to(w); rep(j, w)to[j] = j; rep(j, w-1){ if(bit & (1<<j)){ to[j] = j+1; to[j+1] = j; } } rep(j, w){ dp[i+1][to[j]] += dp[i][j]; dp[i+1][to[j]] %= mod; } } } cout << dp[h][k-1] << endl; }
0
#include <iostream> #include <numeric> #include <stdio.h> #include <iomanip> #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower using namespace std; using ll = long long; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) int Max(int(a), int(b), int(c)) { return max(max(a, b), c); } int Min(int(a), int(b), int(c)) { return min(min(a, b), c); } int main() { ll N,D=0; cin >> N ; vector<ll> A(N); vector<ll> B(N); vector<ll> W(N); for (int i = 0; i < N; i++) { cin >> A.at(i)>>B.at(i); W.at(i)= A.at(i) + B.at(i); D -= (B.at(i)); } sort(W.begin(), W.end()); reverse(W.begin(), W.end()); rep(i, (N+1)/2) { D += W.at(i*2); } cout << D << endl; }
// http://algorithms.blog55.fc2.com/blog-entry-66.html #include <iostream> using namespace std; #include <stdio.h> #include <string.h> #define M 100 int N,R[M+1],C[M][M],B[M][M]; void compute(){ int i=0,j,k,cost; memset(C,99,sizeof(C)); for(;i<N;i++)C[i][i]=0; for(j=1;j<N;j++) for(i=0;i<N - j; i++ ) for (k = i; k < i + j; k++ ){ cost = C[i][k] + C[k+1][i+j] + R[i]*R[k+1]*R[i+j+1]; if(cost<C[i][i+j])C[i][i+j]=cost,B[i][i+j]=k; } } void order( int i, int j ){ if ( i == j ) cout << "M" << i; else{ cout << "("; order( i, B[i][j]-1 ); order(B[i][j], j); cout << ")"; } } void input(){ cin >> N; int z,i=0; for (; i < N; i++ ) cin >> R[i]>>z; R[i]=z; //SIZE++; } void output(){ cout << C[0][N-1] << endl; //order(0, N); //cout << endl; } main(){ input(); compute(); output(); }
0
#include <bits/stdc++.h> using namespace std; int main() { int num; int tmpCnt1,tmpCnt2; int Max1 = 0, Max2 = 0; string str1, str2; cin >> num >> str1 >> str2; if(str1 == str2){ cout << num; return 0; } for(int i = 0; i < num; i++){ tmpCnt1 = 0; if(str1.at(i) == str2.at(0)){ for(int j = 0; j < num - i; j++){ if(str1.at(i+j) == str2.at(j)) tmpCnt1++; else break; } Max1 = max(Max1, tmpCnt1); } } for(int i = 0; i < num; i++){ tmpCnt2 = 0; if(str2.at(i) == str1.at(0)){ for(int j = 0; j < num - i; j++){ if(str2.at(i+j) == str1.at(j)) tmpCnt2++; else break; } Max2 = max(Max2, tmpCnt2); } } if(Max1 == 0 && Max2 == 0){ cout << num * 2; }else if(Max1 >= Max2){ cout << num + (num - Max1); }else{ cout << num + (num - Max2); } }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i< (n); i++) using ll = long long; using namespace std; int main(void){ int N; string s, t; cin >> N >> s >> t; int ans = 2*N; rep(i,N) { if (s.substr(i,N-i) == t.substr(0,N-i) ){ ans = N+i; break;} } cout << ans << endl; return 0; }
1
#include<iostream> #include<algorithm> using namespace std; int n,m,a[1000]; main() { while(cin>>n>>m,n) { int ans=0; for(int i=0;i<n;i++) { cin>>a[i]; ans+=a[i]; } sort(a,a+n); for(int i=n-m;i>=0;i-=m) { ans-=a[i]; } cout<<ans<<endl; } }
#include<iostream> using namespace std; int main(){ int n,m; while(1){ int ans=0,p[10001]={}; cin>>n>>m; if(n+m==0)break; for(int i=1;i<=n;i++){ cin>>p[i]; } for(int j=0;j<n;j++) for(int i=1;i<=n;i++) if(p[i]<p[i+1])swap(p[i],p[i+1]); for(int i=1;i<=n;i++){ if(i%m==0)p[i]=0; ans+=p[i]; } cout<<ans<<endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int func(int x){ string y=to_string(x); vector<char> a(y.size()); vector<char> b(y.size()); for(int i=0;i<y.size();i++){ a.at(i)=y.at(i); b.at(i)=y.at(i); } reverse(b.begin(),b.end()); int c=0; for(int i=0;i<y.size();i++){ if(a.at(i)!=b.at(i)) c=1; } if(c==0) return 1; return 0; } int main(){ int A,B,count=0; cin>>A>>B; for(int i=A;i<B+1;i++){ if(func(i)==1) count++; } cout<<count<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int r = 0; for (int i = a; i <= b; i++) { int s = i % 10; int t = i / 10000 % 10; int u = i / 10 % 10; int v = i / 1000 % 10; if (s == t && u == v) { r++; } } cout << r << endl; /* 5桁の回文数 9 * 9 * 10 = 810 1桁 & 5桁目の取りうる範囲 2桁 & 4桁目の取りうる範囲 */ }
1
#include <bits/stdc++.h> // #include "ane.cpp" const int INF = 1e9; const long long INFLL = 1e18; const int NMAX = 100005; const int MMAX = 100005; const int KMAX = 1005; const int MOD = 1e9 + 7; using namespace std; // comment to disable debug functions #define DEBUG // frequently used macros #if __cplusplus >= 201103L #define ALL(v) begin(v),end(v) #define SORT(v) sort(begin(v), end(v)) #define FIND(v,x) find(begin(v), end(v), (x)) #else #define ALL(v) (v).begin(),(v).end() #define SORT(v) sort(v.begin(), v.end()) #define FIND(v,x) find(v.begin(), v.end(), (x)) #endif #define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \ memset((from), 0, sizeof(from)); } while(0) #ifdef DEBUG #define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0) #else #define DUMP(x) do{}while(0) #endif // frequent used aliases typedef long long ll; typedef pair<int, int> p; typedef pair<ll, int> pl; typedef pair<ll, ll> pll; typedef vector<int> vec; typedef vector<ll> vecll; typedef vector<vec> mat; typedef vector<vecll> matll; // frequently used constants static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1}; static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1}; // frequently used structs struct edge{ int to,cost; }; // printf for debug #ifndef DEBUG void debug(const char* format, ...){} #else void debug(const char* format, ...){ va_list arg; va_start(arg, format); vprintf(format, arg); va_end(arg); } #endif // dump vector #ifdef DEBUG #define DUMPV(v, c) do{ \ printf("%s: ", #v); \ for (int i = 0; i < (c); ++i) \ { \ cout << (v)[i] << " "; \ } \ cout << endl; \ } while(0) #else #define DUMPV(v,c) #endif // std::fill of multi dimensions template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } // binary search ll BSearch(ll _begin, ll _end, bool (*f)(int)){ ll mid; while(_end - _begin > 1LL) { mid = (_begin + _end) / 2LL; if(f(mid)) { debug("BSearch: f(%d) == true\n", mid); _end = mid; } else { debug("BSearch: f(%d) == false\n", mid); _begin = mid; } } return _end; } ll N,M,K,A,B,C,D; int dp[NMAX] = {}; std::vector<edge> G[NMAX]; edge E[MMAX]; ll ans = 0; void solve(){ // main algorithm priority_queue<p, vector<p>, greater<p> > que; set<int> st; que.push(p{0, 0}); while(!que.empty()) { ll cc = que.top().first; int i = que.top().second; que.pop(); if(st.count(i)) continue; // cout << cc << " " << i << endl; ans += cc; st.insert(i); for(auto&& e : G[i]) { if(!st.count(e.to)) que.push(p(e.cost, e.to)); } } } void debug(){ // output debug information } void answer(){ // output answer printf("%lld\n", ans); } int main(int argc, char const *argv[]) { // operate inputs // Fill(dp, -1); scanf("%lld%lld", &N,&M); for (int i = 0; i < M; ++i) { int f,t,c; scanf("%d%d%d", &f, &t, &c); G[f].push_back(edge{t, c}); G[t].push_back(edge{f, c}); } solve(); #ifdef DEBUG debug(); #endif answer(); return 0; }
#include<bits/stdc++.h> using namespace std; struct UF{ int N,par[10000],sz[10000]; void init(int _N){ N=_N; for(int i=0;i<N;i++){ par[i]=i; sz[i]=1; } } int find(int x){ return x==par[x]?x:par[x]=find(par[x]); } void unite(int x,int y){ x=find(x);y=find(y); if(x==y)return; if(sz[x]<sz[y])swap(x,y); par[y]=x; sz[x]+=sz[y]; } bool isSame(int x,int y){ return find(x)==find(y); } }; typedef pair<int,int>P; typedef pair<int,P>PP; int main(){ int N,M; cin>>N>>M; vector<PP>es; for(int i=0;i<M;i++){ int s,t,w; cin>>s>>t>>w; es.push_back(PP(w,P(s,t))); } sort(es.begin(),es.end()); UF uf; uf.init(N); int ans=0; for(int i=0;i<M;i++){ PP p=es[i]; if(uf.isSame(p.second.first,p.second.second))continue; ans+=p.first; uf.unite(p.second.first,p.second.second); } cout<<ans<<endl; return 0; }
1
#include<bits/stdc++.h> using namespace std; int main(){ string s; cin>>s; if(s.size()%2==1){ cout<<"No"<<endl; return 0; } for(int i=0;i<s.size();i++){ if(s.at(i)!=(i%2==0?'h':'i')){ cout<<"No"<<endl; return 0; } } cout<<"Yes"<<endl; }
#include <bits/stdc++.h> #define rep(i,l,n) for(int i=l;i<n;i++) #define rer(i,l,n) for(int i=l;i<=n;i++) #define all(a) a.begin(),a.end() #define o(a) cout<<a<<endl #define pb(a) push_back(a) #define mk(a,b) make_pair(a,b) #define fi first #define se second using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pii; string change(string s,int n){ string ret(s); rep(i,0,ret.size()){ if(ret[i]>='a' && ret[i]<='z'){ if(ret[i]+n>'z') ret[i]+=n-26; else ret[i]+=n; } } return ret; } int main(){ string s; string str[3]={"this","that","the"}; string stu[2]={" ","."}; while(getline(cin,s)){ bool f=0; rep(i,0,26){ string t; t=change(s,i); rep(j,0,3){ rep(k,0,2){ if(t.find(str[j]+stu[k])!=string::npos){ o(t); f=1; break; } } if(f) break; }if(f) break; } } }
0
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; int n; struct node { int key; node *parent,*left,*right; node():key(-1),parent(NULL),left(NULL),right(NULL) {} }; node *root,*nil; node* newnode() { return new node(); } void insert(int num) { node* x=root; node* y=nil; node* z=newnode(); z->key=num; while(x!=nil) { y=x; if(num>=x->key) x=x->right; else x=x->left; } if(y==nil) root=z; else { z->parent=y; if(num<y->key) y->left=z; else y->right=z; } } node* find(node* u,int num) { while(u!=nil&&num!=u->key) { if(num< u->key) u=u->left; else u=u->right; } return u; } node* minele(node* u) { while(u->left!=nil) u=u->left; return u; } node* nextpos(node* u) { // node* y=nil; // if(u->right!=nil) y=minele(u->right); // else //?¬¬????????\???????????????????????°?????¶???????°±???u?????????????????? // { // y=u->parent; // while(y!=nil&&y->right==u) // { // u=y; // y=y->parent; // } // } // return y; return minele(u->right); } void Delete(node* u) { node* y; node* x; if(u->left==nil||u->right==nil) y=u; else y=nextpos(u); if(y->left!=nil) x=y->left; else x=y->right; if(x!=nil) x->parent=y->parent; if(y->parent==nil) root=x; else { if(y==y->parent->left) y->parent->left=x; else y->parent->right=x; } if(y!=u) u->key=y->key; delete y; } void inorder(node* u) { if(u->left!=nil) inorder(u->left); printf(" %d",u->key); if(u->right!=nil) inorder(u->right); return; } void preorder(node* u) { printf(" %d",u->key); if(u->left!=nil) preorder(u->left); if(u->right!=nil) preorder(u->right); return; } int main() { scanf("%d",&n); for(int i=1; i<=n; ++i) { char s[11]; scanf("%s",s); if(s[0]=='i') { int x; scanf("%d",&x); insert(x); } else if(s[0]=='f') { int x; scanf("%d",&x); node* u=(find(root,x)); if(u!=nil) printf("yes\n"); else printf("no\n"); } else if(s[0]=='d') { int x; scanf("%d",&x); Delete(find(root,x)); } else if(s[0]=='p') { inorder(root); printf("\n"); preorder(root); printf("\n"); } } return 0; }
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; #define rep(i,n) for(ll i=0;i<(n);i++) #define repr(i,n) for(ll i=(n-1);i>=0;i--) #define all(x) x.begin(),x.end() #define br cout << "\n"; using namespace std; const long long INF = 1e10; const long long MOD = 1e9+7; using Graph = vector<vector<ll>>; using pll = pair<ll, ll>; template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;} template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;} // 0 false, 1 true // string to int : -48 // a to A : -32 // ceil(a) 1.2->2.0 // c++17 g++ -std=c++17 a.cpp vector<ll> tate; vector<ll> yoko; void f(vector<vector<string>> chess, ll count){ if(count == 8){ bool flag = true; rep(i, tate.size()){ if(chess[tate[i]][yoko[i]] != "Q") flag = false; } if(flag){ rep(i, 8){ rep(j, 8){ cout << chess[i][j]; } br; } } }else{ rep(j, 8){ //縦 bool tate_flag = true; for(ll k = count-1; k >= 0; k--){ if(chess[k][j] == "Q") tate_flag = false; } bool naname_flag = true; for(ll k = count, l = j; k >= 0 && l >= 0; k--, l--){ if(chess[k][l] == "Q") naname_flag = false; } for(ll k = count, l = j; k >= 0 && l < 8; k--, l++){ if(chess[k][l] == "Q") naname_flag = false; } for(ll k = count, l = j; k < 8 && l >= 0; k++, l--){ if(chess[k][l] == "Q") naname_flag = false; } for(ll k = count, l = j; k < 0 && l < 0; k++, l++){ if(chess[k][l] == "Q") naname_flag = false; } if(tate_flag && naname_flag){ chess[count][j] = "Q"; f(chess, count+1); chess[count][j] = "."; } } } } int main() { std::cout << std::fixed << std::setprecision(15); ll k; cin >> k; rep(i, k){ ll a, b; cin >> a >> b; tate.push_back(a); yoko.push_back(b); } vector<vector<string>> chess(8, vector<string>(8)); rep(i, 8)rep(j, 8){ chess[i][j] = "."; } rep(i, 8){ chess[0][i] = "Q"; f(chess, 1); chess[0][i] = "."; } }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; #define MOD 1000000007 #define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++) #define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++) #define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++) #define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++) #define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--) #define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--) #define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--) #define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--) #define iter(i, it) for(auto &(i): (it)) template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) { cout << "(" << m.first << ", " << m.second << ")"; return s; } template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) { ll c = 0; cout << "{ "; iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", "); cout << "}"; return s; } template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) { cout << "{ "; rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", "); cout << "}"; return s; } template<typename T> ostream& operator<<(ostream &s, const list<T> &v) { ll c = 0; cout << "{ "; iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", "); cout << "}"; return s; } int main(void) { ll N, M; ll prev = 0; map<ll, ll> B; ll count = 0; cin >> N >> M; B[0]++; rep(i, N) { ll temp; cin >> temp; temp += prev; B[temp % M]++; prev = temp; } iter(i, B) count += i.second * (i.second - 1) / 2; cout << count << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,b,a) for(int i=b;i>=a;i--) #define fori(a) for(auto i : a ) #define all(a) begin(a), end(a) #define set(a,b) memset(a,b,sizeof(a)) #define sz(a) a.size() #define pi 3.14159 #define ll long long #define ull unsigned long long #define pb push_back #define PF push_front //deque #define mp make_pair #define pq priority_queue #define mod 1000000007 #define f first #define s second #define pii pair< int, int > #define vi vector<int> #define vpii vector<pii> #define debug(v) for(auto i:v) cout<<i<<" "; #define tc int t; cin >> t; while(t--) using namespace std; void optimizeIO(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void solve(){ ll n,m; cin>>n>>m; ll a[n]; rep(i,0,n) cin>>a[i]; vector<ll> pre(n,0); map<ll,int> m1; pre[0]=a[0]%m; m1[pre[0]]++; rep(i,1,n) pre[i]=(pre[i-1]+a[i])%m,m1[pre[i]]++; ll ans=0; ll modsum=0; rep(i,0,n){ if(i!=0) ans+= m1[pre[i-1]]; else ans+=m1[0]; m1[pre[i]]--; } cout<<ans<<endl; } int main(){ optimizeIO(); solve(); // solve1(); }
1
#include <bits/stdc++.h> #define all(vec) vec.begin(),vec.end() using namespace std; using ll=long long; using P=pair<int,int>; const ll INF=1LL<<30; const ll LINF=1LL<<61; const double eps=1e-9; const ll MOD=1000000007LL; vector<ll> f,fi; ll mpow(ll x,ll n){ ll res=1; while(n>0){ if(n&1){ res=res*x%MOD; } x=x*x%MOD; n>>=1; } return res; } ll ncr(ll n,ll r){ if(n<r)return 0; if(r==0)return 1; return f[n]*fi[r]%MOD*fi[n-r]%MOD; } int main(){ int n;cin>>n; f.resize(n+10,0); fi.resize(n+10,0); f[0]=1; for(ll i=1;i<=n;i++)f[i]=f[i-1]*i%MOD; fi[n]=mpow(f[n],MOD-2LL); for(ll i=n-1;i>=0;i--)fi[i]=fi[i+1]*(i+1)%MOD; vector<vector<ll>> dp(n+10,vector<ll>(n+10,0)); int a,b,c,d;cin>>a>>b>>c>>d; dp[a-1][0]=1; for(int i=a;i<=b;i++){ for(int j=0;j<=n;j++){ dp[i][j]+=dp[i-1][j]; dp[i][j]%=MOD; ll s=1; for(int k=1;k<c;k++)s=s*ncr(n-j+i*k,i)%MOD; for(int k=c;k<=d;k++){ if(j-i*k<0)break; s=s*ncr(n-j+i*k,i)%MOD; dp[i][j]+=dp[i-1][j-i*k]*s%MOD*fi[k]%MOD; dp[i][j]%=MOD; } } } cout<<dp[b][n]<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define i_7 (ll)(1E9+7) #define i_5 (ll)(1E9+5) ll mod(ll a){ ll c=a%i_7; if(c>=0)return c; else return c+i_7; } typedef pair<int,int> i_i; typedef pair<ll,ll> l_l; ll inf=(ll)1E12; #define rep(i,l,r) for(ll i=l;i<=r;i++) #define pb push_back ll max(ll a,ll b){if(a<b)return b;else return a;} ll min(ll a,ll b){if(a>b)return b;else return a;} void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]); void Min(ll * pos,ll val){*pos=min(*pos,val);} void Add(ll * pos,ll val){*pos=mod(*pos+val);} const long double EPS=1E-8; //////////////////////////////////////// #define N 100004 ll kai[N]; ll kai2[N]; ll po(ll i,ll p){ if(p==0)return 1; else if(p==1)return mod(i); else if(p%2==0)return mod(po(mod(mod(i)*mod(i)),p/2)); else return mod(mod(i)*mod(po(i,p-1))); } void calc(){ kai[0]=1; kai2[0]=1; for(int i=1;i<N;i++){ kai[i]=mod(kai[i-1]*i); kai2[i]=mod(po(kai[i],i_5)); } } ll comb(ll n,ll k){ if(n==0){ if(k==0)return 1; else return 0; } else if(n<k)return 0; else return mod(mod(mod(kai[n])*mod(kai2[n-k]))*mod(kai2[k])); } //#include <time.h> int main(){ // clock_t start = clock(); // スタート時間 calc(); ll n,a,b,c,d;cin>>n>>a>>b>>c>>d; ll dp[n+5][n+5]; memset(dp,0,sizeof(dp)); dp[a][0]=1; rep(k,a,b){ rep(j,0,n){ for(ll p=0;j+p*k<=n&&p<=d;p++){ ll add=comb(n-j,p*k); add=mod(add*dp[k][j]); add=mod(add*kai[p*k]); add=mod(add*kai2[p]); ll w=(ll)po(kai2[k],p); add=mod(add*w); Add(&dp[k+1][j+p*k],add); if(p==0)p=c-1; } } } /*rep(i,0,b+1){ rep(j,0,n){ cout<<dp[i][j]<<" "; }cout<<endl; }*/ cout<<mod(dp[b+1][n])<<endl; //clock_t end = clock(); // 終了時間 // std::cout << "duration = " << (double)(end - start) / CLOCKS_PER_SEC << "sec.\n"; return 0; }
1
#include<iostream> #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<n;i++) using P = pair<int,int>; /* 大文字を小文字に変換 */ char tolower(char c) {return (c + 0x20);} /* 小文字を大文字に変換 */ char toupr(char c) {return (c - 0x20);} // if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A'; /* string s = "abcdefg" s.substr(4) "efg" s.substr(0,3) "abc" s.substr(2,4) "cdef" // イテレータ要素のインデックス distance(A.begin(), itr); */ int main() { ll M; cin >> M; ll c[M], d[M]; rep(i,M) cin >> d[i] >> c[i]; ll res = 0; vector<int> N; rep(i,M){ vector<ll> out; while(c[i] != 1){ if(c[i]%2 == 1){ out.push_back(d[i]); --c[i]; } int d_tmp = d[i]+d[i]; res += c[i]/2; if(d_tmp >= 10){ d_tmp = 1 + (d_tmp%10); res += c[i]/2; } d[i] = d_tmp; c[i] /= 2; } for(int o: out){ res++; int d_tmp = d[i]+o; if(d_tmp >= 10){ res++; d_tmp = 1 + d_tmp % 10; } d[i] = d_tmp; } N.push_back(d[i]); } int m_tmp = -1; for(int m : N){ if(m_tmp < 0){ m_tmp = m; }else{ res++; m_tmp = m_tmp + m; if(m_tmp >= 10){ res++; m_tmp = 1 + (m_tmp % 10); } } } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int M; cin >> M; vector<int> d(M); vector<long long> c(M); for (int i = 0; i < M; i++){ cin >> d[i] >> c[i]; } long long cnt = 0; long long sum = 0; for (int i = 0; i < M; i++){ cnt += c[i]; sum += c[i] * d[i]; } cout << cnt + (sum - 1) / 9 - 1 << endl; }
1
#include<bits/stdc++.h> using namespace std; #define ll long long const int N = 1e3 + 5; const ll mod = 1e9 + 7; ll mul(ll a, ll b){ return (a * b) % mod; } ll power(ll x, ll y){ if(y == 1){ return x; } else { ll tmp = power(x, y/2); if(y & 1){ return mul(mul(tmp, tmp), x); } else { return mul(tmp, tmp); } } } ll n, a, b, c, d, dp[N][N]; ll fac[N], rev[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> a >> b >> c >> d; fac[0] = 1; rev[0] = power(fac[0], mod - 2); for(int i = 1; i <= n; i++){ fac[i] = (fac[i - 1] * i) % mod; rev[i] = power(fac[i], mod - 2); } for(int i = a - 1; i <= b; i++){ dp[0][i] = 1; } for(int i = 1; i <= n; i++){ for(int j = a; j <= b; j++){ dp[i][j] = dp[i][j - 1]; for(int k = c; k <= d && k * j <= i; k++){ ll tmp = mul(mul(mul(fac[n - i + j * k], rev[n - i]), power(rev[j], k)), rev[k]); dp[i][j] = (dp[i][j] + mul(dp[i - j * k][j - 1], tmp)) % mod; } } } cout << dp[n][b]; }
#include <iostream> #include <vector> #define pb push_back #define mp make_pair using namespace std; const long long INF = 2e18 + 18; vector<long long> dp, cost; vector<vector<long long> > c; void solve() { int n; cin >> n; c.resize(n, vector<long long>(n)); dp.resize((1 << n), -INF); cost.resize((1 << n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> c[i][j]; } } for (int mask = 0; mask < (1 << n); mask++) { long long res = 0; for (int i = 0; i < n; i++) { if (mask & (1 << i)) { for (int j = i + 1; j < n; j++) { if (mask & (1 << j)) { res += c[i][j]; } } } } cost[mask] = res; } dp[(1 << n) - 1] = 0; for (int mask = (1 << n) - 1; mask >= 0; mask--) { for (int submask = mask; ; submask = (submask - 1) & mask) { dp[mask - submask] = max(dp[mask - submask], dp[mask] + cost[submask]); if (submask == 0) break; } } cout << dp[0] << endl; } int main() { solve(); return 0; }
0
#include <iostream> #include <iomanip> #include <algorithm> #include <stdio.h> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <utility> #include <tuple> #include <math.h> #include <set> #include <map> using namespace std ; using ll = long long ; using ld = long double ; using vll = vector<ll> ; using vvll = vector<vll> ; using vc = vector<char> ; using vvc = vector<vc> ; using vb = vector<bool> ; using vvb = vector<vb> ; using pll = pair<ll,ll> ; #define all(v) v.begin(),v.end() const ll INF = 1e18 ; const ll mod = 1e9+7 ; const double pie = acos(-1); vll dx4 = {-1,0,1,0} ; vll dy4 = {0,-1,0,1} ; vll dx8 = {-1,0,1,1,1,0,-1,-1} ; vll dy8 = {-1,-1,-1,0,1,1,1,0} ; void fix_cout(){cout << fixed << setprecision(20) ; } ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; } ll lcm(ll a,ll b){return a/gcd(a,b)*b ; } void chmax(ll &a,ll b){if(a<b) a = b ; } void chmin(ll &a,ll b){if(a>b) a = b ; } int main(){ ll h,w ; cin >> h >> w ; map<ll,ll> gs,dis ; for(int i=1;i<=w;i++) gs[i] = i ; gs[w+10] = -1 ; dis[0] = w ; for(int i=1;i<=h;i++){ ll a,b ; cin >> a >> b ; ll mx = -1 ; for(auto it=gs.lower_bound(a);it->first<=b+1;it=gs.erase(it)){ ll g = it->first ; ll s = it->second ; chmax(mx,s) ; if(dis.count(g-s)){ dis[g-s]-- ; if(dis[g-s]==0) dis.erase(g-s) ; } } if(mx>=0&&b<w){ gs[b+1] = mx ; dis[b+1-mx]++ ; } ll ans = -1 ; if(!dis.empty()){ ans = i+dis.begin()->first ; } cout << ans << endl ; } }
/** * @FileName f.cpp * @Author kanpurin * @Created 2020.08.31 16:46:32 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; int main() { int h,w;cin >> h >> w; set<pair<int,int>> st1; // (現在地,スタート位置) multiset<int> st2; // 移動回数 for (int i = 0; i < w; i++) { st1.insert({i,i}); st2.insert(0); } for (int i = 0; i < h; i++) { int a,b;cin >> a >> b; // 現在地が[a,b+1]にあるものをb+1に移動させる. // b=wなら∞に移動. // 移動させるものの中で一番右のものだけ残す. a--;b--; auto l = st1.lower_bound({a,-1}); auto r = st1.upper_bound({b+1,w}); if (l != r) { // ある r--; while(l != r) { st2.erase(st2.find(l->first-l->second)); l = st1.erase(l); } st2.erase(st2.find(r->first-r->second)); st1.erase(r); // b+1への移動 if (b+1 != w) { st1.insert({b+1,r->second}); st2.insert(b+1-r->second); } } if (st1.empty()) cout << -1 << endl; else cout << *st2.begin() + i + 1 << endl; } return 0; }
1
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cstdio> #include <cmath> #include <cstdlib> #include <cstring> #include <stack> #include <queue> #include <set> #include <bitset> #include <map> #include <unordered_map> #include <ctime> #include <list> #include <numeric> #include <utility> #include <ctime> #define INF 1000000000 #define LINF 9000000000000000000 #define mod 1000000007 #define rep(i,n) for(int i=0;i<int(n);i++) #define rrep(i,n) for(int i=n-1;i>=0;i--) #define REP(i,a,b) for(int i=(a);i<int(b);i++) #define all(x) (x).begin(),x.end() #define pb push_back #define mp make_pair #define MOD(x) (x%(mod)) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef pair<int,int> pi; int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; int ddx[8]={-1,-1,0,1,1,1,0,-1}; int ddy[8]={0,1,1,1,0,-1,-1,-1}; bool debug=false; /*---------------------------------------------------*/ char island[13][13]; void bfs(int x,int y){ island[y][x]='0'; queue<pi> que; que.push(mp(x,y)); while(que.size()){ pi d=que.front();que.pop(); rep(i,4){ int xx=d.first+dx[i],yy=d.second+dy[i]; if(0<=xx&&xx<=12&&0<=yy&&yy<=12&&island[yy][xx]=='1'){ que.push(mp(xx,yy)); island[yy][xx]='0'; } } } } int solve(){ int ret=0; rep(i,12){ rep(j,12){ if(island[i][j]=='1'){ ret++; bfs(j, i); } } } return ret; } int main(){ char a; while(cin>>a){ island[0][0]=a; // cout<<"in"<<endl; rep(i,12){ rep(j,12){ if(i==0&&j==0)continue; // cout<<i<<" "<<j<<endl; cin>>island[i][j]; } } cout<<solve()<<endl; } }
#include<iostream> #include<algorithm> #include<vector> #include<cstdio> #include<cstring> #include<climits> #include<cmath> #include<map> #define f first #define s second #define mp make_pair #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++) #define ALL(c) (c).begin(), (c).end() typedef unsigned int uint; typedef long long ll; using namespace std; char buff[12][13]; int cl[12][12]; int dx[] = {1,-1,0,0}; int dy[] = {0,0,1,-1}; void check(int x, int y, int c){ if(buff[y][x] == '0') return; if(cl[y][x] != 0) return; if(y < 0) return; if(x < 0) return; if(y > 11) return; if(x > 11) return; cl[y][x] = c; REP(i,4) check(x+dx[i],y+dy[i],c); } int main(){ while(cin>>buff[0]){ REP(i,11) cin>>buff[i+1]; memset(cl,0,sizeof(cl)); int cnt = 1; REP(i,12) REP(j,12){ if(cl[i][j] == 0 && buff[i][j] == '1') check(j,i,cnt++); } /* REP(i,12){ REP(j,12) printf("%2d ",cl[i][j]); puts("");} */ cout << cnt-1 << endl; } return 0; }
1
#include <algorithm> #include <iostream> #include <vector> #include <functional> using namespace std; template<typename Monoid> struct SegmentTree { using F = function<Monoid(Monoid, Monoid)>; const F f; const Monoid M1; int sz; vector<Monoid> dat; SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1), sz(1) { while (sz < n) sz <<= 1; dat.assign(sz * 2, M1); } void set(int k, const Monoid &x) { dat[k + sz] = x; } void build() { for (int k = sz - 1; k > 0; k--) { dat[k] = f(dat[2 * k], dat[2 * k + 1]); } } void update(int k, const Monoid &x) { dat[k += sz] = x; while (k >>= 1) dat[k] = f(dat[2 * k], dat[2 * k + 1]); } Monoid get(int a, int b) { // [a, b) Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, dat[a++]); if (b & 1) R = f(dat[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return dat[k + sz]; } friend ostream& operator<<(ostream& os, SegmentTree<Monoid> &seg) { for (int i = 0; i < seg.sz; i++) os << seg[i] << " "; return os; } }; int main() { int n; cin >> n; int Q; cin >> Q; int a, b; cin >> a >> b; a--, b--; vector<int> x(Q + 1); x[0] = a; for (int q = 1; q <= Q; q++) cin >> x[q], x[q]--; const long long INF = 1LL << 60; // 1.15x10^18 using ll = long long; SegmentTree<ll> dpL(n, [](ll a, ll b) { return min(a, b); }, INF); SegmentTree<ll> dpR(n, [](ll a, ll b) { return min(a, b); }, INF); dpL.set(b, 0 - b); dpL.build(); dpR.set(b, 0 + b); dpR.build(); ll add = 0; for (int q = 1; q <= Q; q++) { int diff = abs(x[q] - x[q - 1]); add += diff; ll val = min(dpL.get(0, x[q]) + x[q], dpR.get(x[q], n) - x[q]); val -= diff; dpL.update(x[q - 1], val - x[q - 1]); dpR.update(x[q - 1], val + x[q - 1]); } ll mi = INF; for (int i = 0; i < n; i++) mi = min(mi, dpL[i] + i); cout << mi + add << endl; return 0; }
#if 0 2019.12.30 朴素 dp 设 f[i][p][q] 表示前 i 次操作后当前棋子为 (p, q) 的最小代价。 事实上由于第 i 次操作后一定有一个棋子是 x[i] ,因此可以优化一维: f[i][j] 表示前 i 次操作后当前棋子为 (j, x[i]) 的最小代价。 转移有两种: 1) f[i - 1][j] + |x[i - 1] - x[i]| -> f[i][j] 2) min(f[i - 1][k] + |x[i] - k|) -> f[i][x[i - 1]] 用线段树维护 f[~][j] ,第一种转移就是全局加,第二种是单点取 min 。 第二种转移可以把左边的绝对值拆开: f[i - 1][k] - k + x[i] (k < x[i]) f[i - 1][k] (k = x[i]) f[i - 1][k] + k - x[i] (k > x[i]) 线段树分别维护 f[~][j] - j, f[~][j], f[~][j] + j 即可。 #endif #include <cstdio> #include <algorithm> #define debug(...) fprintf(stderr, __VA_ARGS__) typedef long long ll; struct { inline operator int () { int x; return scanf("%d", &x), x; } inline operator ll () { ll x; return scanf("%lld", &x), x; } template<class T> inline void operator () (T &x) { x = *this; } template<class T, class ...A> inline void operator () (T &x, A &...a) { x = *this; this -> operator ()(a...); } } read; const int maxn = 200005; ll f[maxn << 2], fa[maxn << 2], fb[maxn << 2], tag; void modify(int now, int L, int R, int p, ll x) { f[now] = std::min(f[now], x); fa[now] = std::min(fa[now], x + p); fb[now] = std::min(fb[now], x - p); if(L == R) return; int M = (L + R) >> 1; if(p <= M) modify(now << 1, L, M, p, x); else modify(now << 1 | 1, M + 1, R, p, x); } void build(int now, int L, int R) { f[now] = fa[now] = fb[now] = 1000000000000000000; if(L == R) return; int M = (L + R) >> 1; build(now << 1, L, M); build(now << 1 | 1, M + 1, R); } ll query(int now, int L, int R, int p) { if(R < p) return p + fb[now]; if(L > p) return fa[now] - p; if(L == R) return f[now]; int M = (L + R) >> 1; return std::min(query(now << 1, L, M, p), query(now << 1 | 1, M + 1, R, p)); } int main() { int n = read, q = read, a = read, b = read; build(1, 1, n); modify(1, 1, n, a, 0); /* modify(1, 1, n, b, 0); */ int last = b; while(q --) { int x = read; ll qu = query(1, 1, n, x) + tag; /* debug("qu = %lld\n", qu); */ tag += std::abs(x - last); modify(1, 1, n, last, qu - tag); last = x; /* debug("tag=%lld\n", tag); */ } printf("%lld\n", f[1] + tag); }
1
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <queue> #include <deque> #include <map> #include <set> #include <cmath> #include <iomanip> #include <cassert> #define REP(i, n) for (int i = 0; i < (n); ++i) #define ALL(x) (x).begin(), (x).end() #define SZ(x) (int)(x).size() using namespace std; using ll = long long; constexpr ll INF = 3000000000000000000; template <typename Operator> struct LazySegmentTree { Operator OP; using NodeType = decltype(OP.NodeE); using FuncType = decltype(OP.FuncE); int length, height; vector<NodeType> node; vector<FuncType> lazy; LazySegmentTree(int n) { length = 1; height = 0; while (length < n) { length <<= 1; ++height; } node.resize(length << 1, OP.NodeE); lazy.resize(length << 1, OP.FuncE); } void eval(int n) { node[n] = OP.NodeFunc(node[n], lazy[n]); if (n < length) { lazy[(n << 1) | 0] = OP.MergeFunc(lazy[(n << 1) | 0], lazy[n]); lazy[(n << 1) | 1] = OP.MergeFunc(lazy[(n << 1) | 1], lazy[n]); } lazy[n] = OP.FuncE; } void update(int a, int b, FuncType x) { int l = a + length, r = b + length - 1; for (int i = height; i > 0; --i) { eval(l >> i); eval(r >> i); } ++r; while (r > l) { if (l & 1) { lazy[l] = OP.MergeFunc(lazy[l], x); ++l; } if (r & 1) { --r; lazy[r] = OP.MergeFunc(lazy[r], x); } l >>= 1; r >>= 1; } l = a + length; r = b + length - 1; while (l >>= 1) node[l] = OP.MergeNode(OP.NodeFunc(node[(l << 1) | 0], lazy[(l << 1) | 0]), OP.NodeFunc(node[(l << 1) | 1], lazy[(l << 1) | 1])); while (r >>= 1) node[r] = OP.MergeNode(OP.NodeFunc(node[(r << 1) | 0], lazy[(r << 1) | 0]), OP.NodeFunc(node[(r << 1) | 1], lazy[(r << 1) | 1])); } NodeType get(int a, int b) { int l = a + length, r = b + length - 1; for (int i = height; i >= 0; --i) { eval(l >> i); eval(r >> i); } ++r; NodeType vl = OP.NodeE, vr = OP.NodeE; while (l < r) { if (l & 1) vl = OP.MergeNode(vl, node[l++]); if (r & 1) vr = OP.MergeNode(node[--r], vr); l >>= 1; r >>= 1; } return OP.MergeNode(vl, vr); } }; struct hoge { ll NodeE = 0; ll FuncE = INF; ll MergeNode(ll x, ll y) { return x + y; } ll MergeFunc(ll x, ll y) { if (y == INF) return x; else return y; } ll NodeFunc(ll x, ll y) { if (y == INF) return x; else return y; } }; int main() { int n, q; cin >> n >> q; LazySegmentTree<hoge> LST(n); LST.update(0, n, (1LL << 31) - 1); REP(_, q) { int num; cin >> num; if (!num) { int s, t, x; cin >> s >> t >> x; ++t; LST.update(s, t, x); } else { int i; cin >> i; cout << LST.get(i, i + 1) << "\n"; } } return 0; }
#include <stdio.h> #include <stdlib.h> #include <math.h> #define INIVAL 2147483647 int *a, *ts, c, s, t, v; void update(int k, int l, int r) { if (r<s || t<=l) return; if (s<=l && r<=t) { a[k] = v; ts[k] = c; } else if (l<r-1) { update(((k+1)<<1)-1, l, (l+r)>>1); update((k+1)<<1, (l+r)>>1, r); } } int main() { int i, k, n, z, w, latest; char *p,buf[64] = {0}; buf[62] = '\n'; fgets(buf, 64, stdin); for (n=0,p=buf; *p>' '; n=n*10+*(p++)-'0'); w = n>1 ? pow(2,(int)ceil(log2(n)))-1 : 1; ts = (a = (int*)malloc((w+n)*2*sizeof(int))) + w+n; for (i=0; i<w+n; i++) ts[i] = -1; a[0] = INIVAL; ts[0] = 0; c = 0; while (fgets(buf, 64, stdin)) { for (s=0,p=buf+2; *p>' '; s=s*10+*(p++)-'0'); if (*buf=='0') { // update(s, t, x) for (t=0,p++; *p>' '; t=t*10+*(p++)-'0'); for (v=0,p++; *p>' '; v=v*10+*(p++)-'0'); t++; update(0, 0, w+1); c++; } else { // find(x) x->s latest = -1; for (k=w+s; ; k=(k-1)>>1) { if (ts[k]>latest) { latest = ts[k]; z = a[k]; } if (k==0) break; } if (z<10) { putc_unlocked('0'+z, stdout); putc_unlocked('\n', stdout); } else { for (i=62; z>0; buf[--i]='0'+z%10,z/=10); fputs(buf+i, stdout); } } } return 0; }
1
#include <bits/stdc++.h> #define _overload(_1,_2,_3,name,...) name #define _rep(i,n) _range(i,0,n) #define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__) #define _rrep(i,n) _rrange(i,n,0) #define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i) #define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__) #define _all(arg) begin(arg),end(arg) #define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg)) #define bit(n) (1LL<<(n)) // #define DEBUG #ifdef DEBUG #define dump(...) fprintf(stderr, __VA_ARGS__) #else #define dump(...) #endif template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;} template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;} using namespace std; using ll=long long; using vi=vector<int>; using vll=vector<ll>; const double EPS = 1e-10; const double PI = acos(-1.0); const int inf = INT_MAX; const ll INF = LLONG_MAX; const ll MOD = 1000000007LL; const int dx[4]={1,0,-1,0}; const int dy[4]={0,1,0,-1}; ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;} ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;} ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;} ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;} ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);} int main(void){ cin.tie(0); ios::sync_with_stdio(false); int R; cin >> R; string res = "AGC"; if(R < 1200){ res = "ABC"; } else if(R < 2800){ res = "ARC"; } cout << res << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define endl "\n" #define REP(i,a,b) for(ll i=a;i<b;i++) #define PER(i,b,a) for(ll i=b;i>a;i--) #define forit(it,x) for(auto it=(x).begin();it!=(x).end();++it) #define ull unsigned long long int #define ld long double #define prec(n) fixed<<setprecision(n) #define test ll t; cin>>t; while(t--) #define re return 0 #define pb push_back #define PI 3.1415926535897932384626 #define MOD (ll)1000000007 #define fi first #define se second #define eb emplace_back #define vll vector<ll> #define vi vector<int> #define mpll map<ll,ll> #define pll pair<ll,ll> #define mp(x,y) make_pair(x,y) const ll MAXI = (ll)1e9+7; int main(){ IOS; // test{ int a; cin>>a; /* int a[n]; REP(i,n){ cin>>a[i]; } */ cout<<a*(1+a+a*a)<<"\n"; // } re; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<ll, ll>; const int MAX { 200010 }; const ll MOD { 998244353 }, oo { 1LL << 62 }; ll fs[MAX]; ll st[MAX][2]; void precomp() { fs[0] = fs[1] = 1; for (ll i = 2; i < MAX; ++i) fs[i] = (fs[i - 1] * i) % MOD; } ll mod_pow(ll a, ll n) { ll res = 1, base = a; while (n) { if (n & 1) res = (res * base) % MOD; base = (base * base) % MOD; n >>= 1; } return res; } ll inv(ll N) { return mod_pow(N, MOD - 2); } ll C(ll N, ll M) { auto res = (fs[N] * inv(fs[N - M])) % MOD; res = (res * inv(fs[M]) % MOD); return res; } ll solve(ll N, ll M, ll K) { auto ans = mod_pow(M - 1, N - 1); ans = (ans * M) % MOD; #ifdef DEBUG cout << "--- ans = " << ans << endl; #endif for (ll i = 1; i <= K; ++i) { ll res = (C(N - 1, i) * mod_pow(M - 1, N - 1 - i)) % MOD; res = (M * res) % MOD; ans = (ans + res) % MOD; } return ans; } int main() { ios::sync_with_stdio(false); precomp(); ll N, M, K; cin >> N >> M >> K; auto ans = solve(N, M, K); cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> #define rep(i, e, n) for (int i = e; i < (n); ++i) using namespace std; typedef long long ll; using P = pair<int,int>; const ll inf=1000000000007; int main() { ll n,a,b,c,d,e; cin >> n >> a >> b >> c >> d >> e; ll mn= min(min(min(a,b),c),min(d,e)); ll ans = (n-0.5)/mn +5; cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll=long long; #define int ll #define FOR(i,a,b) for(int i=int(a);i<int(b);i++) #define REP(i,b) FOR(i,0,b) int read(){ int i; scanf("%lld",&i); return i; } signed main(){ while(true){ int e=read(); int ans=100000; int m; if(e==0) break; int z,y,x; for(z=1;z*z*z<e;z++){ } for(y=1;y*y<e;y++){ } for(int i=0;i<=z;i++){ for(int j=0;j<=y;j++){ if(e-i*i*i-j*j >= 0){ x = e-i*i*i-j*j; ans = min(ans,x+j+i); } } } cout << ans << endl; } }
#include <bits/stdc++.h> #define ll long long #define MODV 1000000007 #define INFLL LLONG_MAX // 9223372036854775807 #define EPS 1e-9 #define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++) #define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++) #define all(v) v.begin(), v.end() #define endl "\n" #define vi vector<ll> #define vvi vector<vector<ll>> #define Yes() cout << "Yes" << endl #define YES() cout << "YES" << endl #define No() cout << "No" << endl #define NO() cout << "NO" << endl #define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15); template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; } using namespace std; int main(){ Init(); ll h, w, a, b; cin >> h >> w >> a >> b; string zo = string(a, '0') + string(w-a, '1'); string oz = string(a, '1') + string(w-a, '0'); rep(i, h) cout << (i<b ? zo : oz) << endl; }
0
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<n; ++i) int main() { int N; cin >> N; vector<int> x(N), y(N); rep(i,N) cin >> x[i] >> y[i]; double d=0; rep(i,N) rep(j,N) d += hypot(x[i]-x[j], y[i]-y[j]); printf("%.8f\n", d/N); }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) #define all(v) v.begin(),v.end() #define len(x) (ll)(x).length() using namespace std; typedef long long ll; typedef pair<int,int> P; const int INF=1e9; const int di[] = {-1,0,1,0}; const int dj[] = {0,-1,0,1}; int main(){ double n; cin>>n; vector<vector<double>> d(n,vector<double>(2)); rep(i,n)rep(j,2) cin>>d[i][j]; vector<int> t(n); rep(i,n) t[i]=i; double sum=0; int cnt=0; do{ for(int i=1;i<n;i++){ sum+=sqrt((d[t[i]][0]-d[t[i-1]][0])*(d[t[i]][0]-d[t[i-1]][0])+(d[t[i]][1]-d[t[i-1]][1])*(d[t[i]][1]-d[t[i-1]][1])); } cnt++; }while(next_permutation(all(t))); printf("%.10f\n",sum/cnt); }
1
#include<iostream> #include<algorithm> #include<ctime> #include<vector> #include<string> #include<cmath> #include<map> #include<iomanip> #include<numeric> #include<queue> #include<deque> #include<cfloat> #include<functional> #include<tuple> #include<math.h> #include<bitset> #include<stack> #include<set> #include<random> #include<stdlib.h> #define rip(i,n) for(int i=0;i<n;i++) #define Rip(i,n) for(int i=1;i<=n;i++) #define RIP(i,a,b) for(int i=a;i<b;i++) #define all(V) V.begin(),V.end() #define sec setprecision; #define _CRT_SECURE_NO_WARNINGS #pragma target("avx") #pragma optimize("O3") #pragma optimize("unroll-loops"); constexpr double eps = 1e-9; constexpr double pi = 3.141592653589793238462643383279; using namespace std; using ll = long long; using ld = long double; using Pa = pair<int, int>; ll mod = 1000000007; ll MOD = 998244353; 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); } ll pow(ll x, ll n) { x %= mod; if (n == 0) return 1; if (n % 2 == 0) return (pow((x * x) % mod, n / 2) % mod); else return (x * pow(x, n - 1)) % mod; } bool prime(int n) { int i = 2; if (n == 2)return true; else if(n <= 1)return false; if (n % i == 0)return false; i = 3; while (i <= sqrt(n)) { if (n % i == 0)return false; i += 2; } return true; } signed main() { int h, w; cin >> h >> w; vector<vector<bool>>s(h+2,vector<bool>(w+2,false)); rip(i, h){ rip(j, w) { char a; cin >> a; if (a == '#')s[i+1][j+1] = true; } } rip(i, h) { rip(j, w) { bool p = true; int k=i+1;int l=j+1; p = s[k-1][l]||s[k][l-1]||s[k+1][l]||s[k][l+1]; if(p == false&&s[k][l]==true) { cout << "No" << endl; return 0; } } } cout << "Yes" << endl; }
#include <bits/stdc++.h> using namespace std; void solve(long long N, long long K, std::vector<long long> D){ long long ans = 0; for(long long i = N; i < 100000; ++i){ //cout << i << endl; string S = to_string(i); bool check = true; for(auto s : S){ for(auto d : D){ string st{s}; string ds = to_string(d); //cout << st << " " << ds << endl; if(st == ds){ //cout << "check!" << endl; check = false; } } } if(check){ //cout << i << endl; ans = i; break; } } cout << ans << endl; return; } int main(){ long long N; scanf("%lld",&N); long long K; scanf("%lld",&K); std::vector<long long> D(K); for(int i = 0 ; i < K ; i++){ scanf("%lld",&D[i]); } solve(N, K, std::move(D)); return 0; }
0
#include<iostream> using namespace std; int main() { int n; int i, j, k, l, m; int tmp; int count=0; cin >> n; int Dice[n][6]; for(i=0;i<n;i++){ for(j=0;j<6;j++){ cin >> Dice[i][j]; } } for(i=0;i<n;i++){ for(j=i+1;j<n;j++){ for(k=0;k<4;k++){ tmp=Dice[j][0]; Dice[j][0]=Dice[j][1]; Dice[j][1]=Dice[j][5]; Dice[j][5]=Dice[j][4]; Dice[j][4]=tmp; if(Dice[j][1]==Dice[i][1]) goto Break; else{ for(l=0;l<4;l++){ tmp=Dice[j][0]; Dice[j][0]=Dice[j][3]; Dice[j][3]=Dice[j][5]; Dice[j][5]=Dice[j][2]; Dice[j][2]=tmp; if(Dice[j][0]==Dice[i][1]){ tmp=Dice[j][0]; Dice[j][0]=Dice[j][4]; Dice[j][4]=Dice[j][5]; Dice[j][5]=Dice[j][1]; Dice[j][1]=tmp; goto Break; } } } } Return:; } } goto Exit; Break:; for(m=0;m<4;m++){ tmp=Dice[j][0]; Dice[j][0]=Dice[j][3]; Dice[j][3]=Dice[j][5]; Dice[j][5]=Dice[j][2]; Dice[j][2]=tmp; if(Dice[j][0]==Dice[i][0]){ if(Dice[i][0]==Dice[j][0]&&Dice[i][1]==Dice[j][1]&&Dice[i][2]==Dice[j][2]&&Dice[i][3]==Dice[j][3]&&Dice[i][4]==Dice[j][4]&&Dice[i][5]==Dice[j][5]){ cout << "No" << endl; return 0; } else{ goto Return; } } } goto Return; Exit:; cout << "Yes" << endl; return 0; }
#include<iostream> #include<vector> using namespace std; vector<long> dp; vector<long> pre; void rec(int i, vector<int>& nottaken, long scoresofar, int mask, int group) { if(i==nottaken.size()) { dp[mask]=max(dp[mask],scoresofar+pre[group]); return; } rec(i+1,nottaken,scoresofar,mask,group); rec(i+1,nottaken,scoresofar,mask^(1<<nottaken[i]),group^(1<<nottaken[i])); } int main(){ int n; cin>>n; vector<vector<long>> a(n,vector<long>(n)); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) cin>>a[i][j]; } pre.resize(1<<n); for(int mask=0;mask<(1<<n);mask++) { for(int i=0;i<n;i++) { if(mask&(1<<i)) { for(int j=i+1;j<n;j++) { if(mask&(1<<j)) pre[mask]+=a[i][j]; } } } } dp.resize(1<<n,-99999999); dp[0]=0; for(int mask=0;mask<(1<<n);mask++) { vector<int> nottaken; for(int i=0;i<n;i++) { if(!(mask&(1<<i))) nottaken.push_back(i); } rec(0,nottaken,dp[mask],mask,0); } cout<<dp[(1<<n)-1]; }
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 fi first #define se second #define mp make_pair #define pb push_back #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair<int,int> ii; typedef vector<int> vi; typedef long double ld; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; typedef set<int>::iterator sit; typedef map<int,int>::iterator mit; typedef vector<int>::iterator vit; int h,w; int ex,ey; short dp[101][101][101][101]; char a[101][101]; short S[101][101]; short calc(int r1, int r2, int c1, int c2) { if(r1>r2||c1>c2) return 0; int ans = S[r2][c2]; if(r1>0&&c1>0) ans+=S[r1-1][c1-1]; if(r1>0) ans-=S[r1-1][c2]; if(c1>0) ans-=S[r2][c1-1]; return ans; } bool valid(int u, int d, int l, int r) { if(u>ex||d>h-1-ex||l>ey||r>w-1-ey) return false; return true; } void amax(short &x, short y) { if(y>x) x=y; } void update(int u, int d, int l, int r) { int val = dp[u][d][l][r]; //cerr<<u<<' '<<d<<' '<<l<<' '<<r<<' '<<val<<'\n'; if(valid(u+1,d,l,r)) { int L = r; int R = w - l - 1; int U = d; int D = h - (u + 1) - 1; amax(dp[u+1][d][l][r], val + calc(max(U,ex-u-1),min(D,ex-u-1),max(L,ey-l),min(R,ey+r))); } if(valid(u,d+1,l,r)) { int L = r; int R = w - l - 1; int U = d + 1; int D = h - (u) - 1; amax(dp[u][d+1][l][r], val + calc(max(U,ex+d+1),min(D,ex+d+1),max(L,ey-l),min(R,ey+r))); } if(valid(u,d,l+1,r)) { int L = r; int R = w - (l+1) - 1; int U = d; int D = h - u - 1; amax(dp[u][d][l+1][r], val + calc(max(U,ex-u),min(D,ex+d),max(L,ey-l-1),min(R,ey-l-1))); } if(valid(u,d,l,r+1)) { int L = r+1; int R = w - l - 1; int U = d; int D = h - u - 1; amax(dp[u][d][l][r+1], val + calc(max(U,ex-u),min(D,ex+d),max(L,ey+r+1),min(R,ey+r+1))); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>h>>w; for(int i=0;i<h;i++) { for(int j=0;j<w;j++) { cin>>a[i][j]; if(a[i][j]=='o') S[i][j]=1; if(i>0) S[i][j]+=S[i-1][j]; if(j>0) S[i][j]+=S[i][j-1]; if(i>0&&j>0) S[i][j]-=S[i-1][j-1]; if(a[i][j]=='E') ex=i,ey=j; } } dp[0][0][0][0]=0; for(int sum = 0; sum <= h+w; sum++) { for(int u = 0; u <= min(ex,sum); u++) { for(int d = 0; d+u<=sum&&d<=h-1-ex; d++) { for(int l = 0; l<=ey&&d+u+l<=sum; l++) { int r = sum-u-d-l; if(r>=0&&r<=w-1-ey) { update(u,d,l,r); } } } } } cout<<dp[ex][h-1-ex][ey][w-1-ey]<<'\n'; }
#include <iostream> #include <vector> using namespace std; void solve() { int N, M; cin >> N >> M; vector<int> A(N); vector<int> B(M); for(int i = 0; i < N; ++i) { cin >> A[i]; } for(int i = 0; i < M; ++i) { cin >> B[i]; } vector<int> point(N); int max = 0; for(int i = 0; i < M; ++i) { for(int j = 0; j < N; ++j) { if(B[i] >= A[j]) { ++point[j]; if(max < point[j]) { max = point[j]; } break; } } } for(int i = 0; i < M; ++i) { if(max == point[i]) { cout << i + 1 << endl; } } } int main() { solve(); return(0); }
0
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int main(){ string s; cin>>s; if(s.length()<26){ char c='a'; rep(i,s.length()) if(s[i]==c) c++, i=-1; s+=c; cout<<s<<'\n'; } else{ string t=s; if(next_permutation(t.begin(),t.end())){ while(t.substr(0,t.length()-1)>s) t=t.substr(0,t.length()-1); cout<<t<<'\n'; } else{ cout<<"-1\n"; } } return 0; }
#include<stdio.h> int main(){ int x[32]={1,2,4}; for(int i=3;i<31;i++) x[i]=x[i-1]+x[i-2]+x[i-3]; int n; while(1){ scanf("%d",&n);if(n==0)break; int d=x[n-1]; int y=d/365/10+1; printf("%d\n",y); } return 0; }
0
#include<iostream> #include<string> using namespace std; class Base { public: Base() { score = 0; outNum = 0; first = false; second = false; third = false; } void hit() { if (third) { score++; } third = second; second = first; first = true; } void homerun() { if (first) { first = false; score++; } if (second) { second = false; score++; } if (third) { third = false; score++; } score++; } void out() { outNum++; if (outNum > 2) { cout << score << endl; score = 0; outNum = 0; first = false; second = false; third = false; } } private: int score; int outNum; bool first; bool second; bool third; }; int main() { Base base; string str; int inning; int count = 0; cin >> inning; while (count < inning * 3) { char data[10]; cin >> str; if (str == "HIT") { base.hit(); }else if (str == "HOMERUN") { base.homerun(); } else if(str == "OUT"){ base.out(); count++; } } return 0; }
#include <iostream> #include <vector> using namespace std; int main(){ int n, x; vector<int> a; cin>>n; for(int i=0;i<n;i++){ cin>>x; a.push_back(x); } for(int i=a.size()-1;i>=0;i--){ if(i != a.size()-1) cout<<" "; cout<<a[i]; } cout<<endl; return 0; }
0
#include <bits/stdc++.h> //#include <boost/multiprecision/cpp_int.hpp> using namespace std; //using namespace boost::multiprecision; typedef long long int ll; typedef long double ld; #define MOD 1000000007 #define ALL(obj) (obj).begin(),(obj).end() template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;} template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;} const long long INF = 1LL << 60; bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){ return firstElof.first < secondElof.first; } bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){ return firstElof.second < secondElof.second; } //四方向への移動ベクトル const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; struct edge{//グラフに使うヤツ ll from,to,cost; }; typedef vector<vector<edge> > G; ll gcd(ll a,ll b){ if (a%b==0)return(b); else return(gcd(b,a%b)); } int main(){ bool abc[26]; fill(abc,abc+26,true); string s; cin >> s; for (ll i=0;i<s.size();i++){ abc[s[i]-'a']=false; } for (ll i=0;i<26;i++){ if (abc[i]){ cout << s; cout << (char)('a'+i) << endl; return 0; } } if (s.size()==26){ for (ll i=s.size()-1;i>=0;i--){ for (ll j=(s[i]-'a');j<26;j++){ if (abc[j]){ for (ll k=0;k<i;k++){ cout << s[k]; } cout << (char)('a'+j) << endl; return 0; } } abc[s[i]-'a']=true; } } cout << -1 << endl; return 0; }
#include <iostream> #include <set> using namespace std; int main() { long long N, L[2]{}; cin >> N; set<int> S; while (cin >> N) { if (!S.insert(N).second) { S.erase(N); if (N > L[0]) L[1] = L[0], L[0] = N; else if (N > L[1]) L[1] = N; } } cout << L[0] * L[1] << endl; }
0
#include <bits/stdc++.h> using namespace std; struct Node{ int key; Node *right,*left,*parent; }; Node *root,*NIL; Node * Min(Node *p){ while(p->left!=NIL) p=p->left; return p; } Node * find(Node *p,int a){ while(p!=NIL && a!=p->key){ if(a<p->key) p=p->left; else p=p->right; } return p; } Node * Successor(Node *p){ if(p->right!=NIL) return Min(p->right); Node *q=p->parent; while(q!=NIL && p==q->right){ p=q; q=q->parent; } return q; } Node * Delete(Node *p){ Node *a,*b; if(p->left==NIL || p->right==NIL) b=p; else b=Successor(p); if(b->left!=NIL) a=b->left; else a=b->right; if(a!=NIL) a->parent=b->parent; if(b->parent==NIL) root=a; else if(b==b->parent->left) b->parent->left=a; else b->parent->right=a; if(b!=p) p->key=b->key; free(b); } void insert(int a){ Node *y=NIL, *x=root, *z; z = (Node *)malloc(sizeof(Node)); z->key=a; z->left=NIL; z->right=NIL; while(x!=NIL){ y=x; if(z->key<x->key) x=x->left; else x=x->right; } z->parent=y; if(y==NIL) root=z; else if(z->key<y->key) y->left=z; else y->right=z; } void inorder(Node *p){ if(p==NIL) return; inorder(p->left); cout << " " << p->key; inorder(p->right); } void preorder(Node *p){ if(p==NIL) return; cout << " " << p->key; preorder(p->left); preorder(p->right); } int main(){ int n,x; string str; cin >> n; for(int i=0;i<n;i++){ cin >> str; if(str=="find"){ cin >> x; Node *p=find(root,x); if(p!=NIL) cout << "yes" << endl; else cout << "no" << endl; } else if(str=="insert"){ cin >> x; insert(x); } else if(str=="print"){ inorder(root); cout << endl; preorder(root); cout << endl; } else if(str=="delete"){ cin >> x; Delete(find(root,x)); } } return 0; }
#include <bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, c; cin >> n; while (n != 0) { int hist[10] = {}; for (int i = 0; i < n; ++i) { cin >> c; hist[c]++; } for (int i = 0; i < 10; i++) { if (hist[i] == 0) { cout << "-" << endl; } else { for (int j = 0; j < hist[i]; ++j) { cout << "*"; } cout << endl; } } cin >> n; } return 0; }
0
// //AtCoder Beginner Contest 122 //C //https://atcoder.jp/contests/abc122/tasks/abc122_c // #include <iostream> #include <algorithm> #include <vector> #include <iomanip> #include <cmath> #include <ctime> #include <queue> #include <map> #include <set> #include <tuple> #include <functional> #include <cassert> #include <bitset> #include <numeric> using namespace std; #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 ALL(x) (x).begin(),(x).end() #define RALL(x) (x).rbegin(),(x).rend() #define SIZE(x) (int)(x).size() #define SIZEL(x) (ll)(x).size() #define MSG(a) cout << #a << " " << a << endl; using ll = long long; using ld = long double; using Graph = vector<vector<int>>; const double PI = 3.14159265358979323846; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; } //最大公約数 ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } //最小公倍数 int main() { int n, q; cin >> n >> q; string s; cin >> s; vector<pair<int,int>> lr(n); REP(i, q) { cin >> lr[i].first >> lr[i].second; lr[i].first--; lr[i].second--; } vector<int> sAC(n+1, 0); int acCnt=0; REP(i,n){ if ((s[i]=='A') && (s[i+1]=='C')) acCnt++; sAC[i+1]=acCnt; } REP(i,q){ int ans = sAC[lr[i].second] - sAC[lr[i].first]; cout << ans << endl; } return 0; }
#pragma GCC optimize(2) #pragma GCC optimize("inline") #include <cstring> #include <cstdio> #include <algorithm> #include <vector> #include <queue> #define mp make_pair #define pb push_back using namespace std; typedef long long li; template<class T>inline void read(T &x) { x = 0; T tmp = 1; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') tmp = -1, c = getchar(); while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0', c = getchar(); x *= tmp; } template<class T>inline void Max(T &x, T y) { if (y > x) x = y; } template<class T>inline void Min(T &x, T y) { if (y < x) x = y; } const int N = 600; int n, d1, d2, a[N][N], b[N][N]; const int dx[] = {1, 1, -1, -1}; const int dy[] = {1, -1, 1, -1}; inline bool out(int x, int y) { return x < 0 || y < 0 || x >= (n << 1) || y >= (n << 1); } vector<pair<int, int> > g, h; struct node { int x, y, ty; node() {} node(int _x, int _y, int _ty) : x(_x), y(_y), ty(_ty) {} }; queue<node> q; void Fill_a(int Ax, int Ay) { q.push(node(Ax, Ay, 0)); while (!q.empty()) { int x = q.front().x, y = q.front().y; int cur = q.front().ty; q.pop(); if (a[x][y] != -1) continue; a[x][y] = cur; for (int i = 0; i < (int)g.size(); ++i) { int nowx = x + g[i].first, nowy = y + g[i].second; if (out(nowx, nowy) || a[nowx][nowy] != -1) continue; q.push(node(nowx, nowy, cur ^ 1)); } } } void Fill_b(int Ax, int Ay) { q.push(node(Ax, Ay, 0)); while (!q.empty()) { int x = q.front().x, y = q.front().y; int cur = q.front().ty; q.pop(); if (b[x][y] != -1) continue; b[x][y] = cur; for (int i = 0; i < (int)h.size(); ++i) { int nowx = x + h[i].first, nowy = y + h[i].second; if (out(nowx, nowy) || b[nowx][nowy] != -1) continue; q.push(node(nowx, nowy, cur ^ 1)); } } } int main(void) { read(n), read(d1), read(d2); for (int i = 0; i < 450; ++i) for (int j = 0; j < 450; ++j) { int now = i * i + j * j; if (now == d1) { for (int t = 0; t < 4; ++t) g.pb(mp(i * dx[t], j * dy[t])); } if (now == d2) { for (int t = 0; t < 4; ++t) h.pb(mp(i * dx[t], j * dy[t])); } } for (int i = 0; i < (n << 1); ++i) for (int j = 0; j < (n << 1); ++j) a[i][j] = b[i][j] = -1; for (int i = 0; i < (n << 1); ++i) for (int j = 0; j < (n << 1); ++j) if (a[i][j] == -1) Fill_a(i, j); for (int i = 0; i < (n << 1); ++i) for (int j = 0; j < (n << 1); ++j) if (b[i][j] == -1) Fill_b(i, j); for (int x = 0; x < 2; ++x) for (int y = 0; y < 2; ++y) { int cnt = 0; for (int i = 0; i < (n << 1); ++i) for (int j = 0; j < (n << 1); ++j) cnt += (a[i][j] == x && b[i][j] == y); if (cnt >= n * n) { int m = n * n; for (int i = 0; i < (n << 1) && m; ++i) for (int j = 0; j < (n << 1) && m; ++j) if (a[i][j] == x && b[i][j] == y) printf("%d %d\n", i, j), --m; return 0; } } }
0
#include <bits/stdc++.h> #define f(i,a,b) for(int i=a;i<=b;++i) using namespace std;int M=998244353,N,K,a,s[303],d[303][303][303]={1};main(){string S;cin>>S>>K;K=min((int)S.size(),K);for(auto c:S)c=='0'?++N:++s[N];f(i,0,N)f(j,0,K)f(k,0,j)f(l,-min(k,s[i]),K-j)(d[i+1][j+max(l,0)][k+l]+=d[i][j][k])%=M;f(i,0,K)(a+=d[N+1][i][0])%=M;cout<<a;}
#include <bits/stdc++.h> int m; using namespace std; const int N = 302; string s; int f[N][N][N]; int a[N]; int main() { ios_base::sync_with_stdio(0); cin >> s; cin >> m; for (int i = 0; i < s.size(); i++) a[i + 1] = s[i] - 'a'; int n = s.size(); a[0] = -1; a[n + 1] = -1; f[1][n][0] = 0; for (int i = 1; i <= n; i++) { for (int j = n; j >= i; j--) { for (int k = 0; k <= m; k++) { f[i + 1][j][k] = max(f[i + 1][j][k], f[i][j][k]); f[i][j - 1][k] = max(f[i][j - 1][k], f[i][j][k]); if (a[i] != a[j]) { f[i + 1][j - 1][k + 1] = max(f[i + 1][j - 1][k + 1], f[i][j][k] + 2 - (i == j)); } else { f[i + 1][j - 1][k] = max(f[i + 1][j - 1][k], f[i][j][k] + 2 - (i == j)); } } } } int mx = 0; for (int i = 0; i <= n + 1; i++) { for (int j = 0; j <= n; j++) { for (int k = 0; k <= m; k++) { mx = max(mx, f[i][j][k]); } } } cout << mx << "\n"; return 0; }
0
#include <bits/stdc++.h> #define REP(i, n) for(int i = 0; i < (n); i++) #define REP1(i, n) for(int i = 1; i <= (n); i++) #define REPD(i,a,b) for (int i=(a);i<(b);i++) #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<int> vi; typedef vector<vi> vvi; typedef set<int> si; typedef vector<si> vsi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef pair<int, int> pi; typedef queue<int> qi; typedef queue<pi> qpi; typedef pair<ll, ll> pll; typedef queue<pll> qpll; typedef vector<pi> vpi; typedef vector<pll> vpll; const int mod = 1000000007; const int INF = 1001001001; // 小数点 << fixed << setprecision(0) << // sort降順 sort(ALL(),greater<int>()); // 円周率 M_PI // 文字判定 isupper islower // 文字変換  // 順列 do {} while(next_permutation(ALL(X))); // 最大値 LLONG_MAX // a内でx以上 auto iter = lower_bound(ALL(a), x); // a内でxより大きい auto iter = upper_bound(ALL(a), x); int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; struct edge { int from; //出発点 int to; //到達点 int cost; //移動コスト }; typedef struct edge se; typedef vector<edge> ve; unsigned Euclidean_gcd(unsigned a, unsigned b) { if(a < b) return Euclidean_gcd(b, a); unsigned r; while ((r=a%b)) { a = b; b = r; } return b; } vpll PrimeFactorization(ll n) { vpll res; for (ll i=2; i*i<=n; i++) { if(n%i!=0) continue; ll ex=0; while(n%i==0) { ex++; n/=i; } res.push_back(pll(i,ex)); } if(n!=1) res.push_back(pll(n,1)); return res; } int main() { int k; vi a(3); cin >> a[0] >> a[1] >> a[2] >> k; sort(ALL(a)); int ans=a[0]+a[1]+a[2]*pow(2,k); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll LINF = 1e18; const int INF = 1e9; const ll MOD = 1000000007; int main(){ int a, b, c, k; cin >> a >> b >> c >> k; for(int i = 0; i < k; i++){ if(a < b){ if(b < c) c *= 2; else b *= 2; } else{ if(a < c) c *= 2; else a *= 2; } } cout << a + b + c << endl; return 0; }
1
#include <string> #include <utility> #include <iostream> #include <algorithm> using namespace std; int main() { string S; cin >> S; for (string::size_type i = 0; i < S.size() / 2; i++) { swap(S[i], S[S.size() - i - 1]); } for (string::size_type i = 0; i < S.size(); i++) { cout << S[i]; } cout << endl; return 0; }
#include <iostream> #include <algorithm> #include <vector> /*int main(int argc, char **argv) { int a, b, c, d, e; std::cin >> a >> b >> c >> d >> e; std::cout << std::min(a, std::min(b, c)) + std::min(d, e) - 50 << std::endl; return 0; }*/ /*int main() { int l, a, b, c, d; std::cin >> l >> a >> b >> c >> d; int japa, math; japa = a / c; if(a % c != 0){ japa++; } math = b / d; if(b % d != 0){ math++; } std::cout << l - std::max(japa, math) << std::endl; }*/ /*int main() { bool sub[31]; int input; for(int i = 0; i < 31; i++){ sub[i] = false; } for(int i = 0; i < 28; i++){ std::cin >> input; sub[input] = true; } for(int i = 1; i < 31; i++){ if(!sub[i]) std::cout << i << std::endl; } }*/ int main() { std::vector<int> w, k; int input; for(int i = 0; i < 10; i++){ std::cin >> input; w.push_back(input); } for(int i = 0; i < 10; i++){ std::cin >> input; k.push_back(input); } std::sort(w.begin(),w.end(),std::greater<int>()); std::sort(k.begin(),k.end(),std::greater<int>()); std::cout << w[0] + w[1] + w[2] << " " << k[0] + k[1] + k[2] << std::endl; }
0
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author champon */ #include <iostream> #include <fstream> #include <bits/stdc++.h> #define se cout << "test ok" << endl; #define sp << " " << #define enl "\n"; using namespace std; using ll=long long; using ld=long double; ll mod = ll(1e9)+7; ll inf = ll(1e18); template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; } void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; } void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; } template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; } template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; } template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); } int dx[] = {1, 0, -1, 0, 1, -1, 1, -1}; int dy[] = {0, 1, 0, -1, 1, -1, -1, 1}; #ifndef INCLUDE_DEBUG_HPP #define INCLUDE_DEBUG_HPP #include <iostream> #include <vector> #include <map> using namespace std; namespace dbg { using ll = long long; class Debug { public: Debug(){} template<typename T> void vd(vector<T> vec); template<typename T> void vd2(vector<vector<T>> vec); template<typename T> void ad(T *arr, ll n); template<typename T, size_t N> void ad2(T (&arr)[N], ll n); template<typename T> void md(T mp); }; template<typename T> void Debug::vd(vector<T> vec) { for (auto vv : vec) cout << vv << " "; cout << endl; } template<typename T> void Debug::vd2(vector<vector<T>> vec) { for (auto vv : vec) for (auto vvv : vv) cout << vvv << " "; cout << endl; } template<typename T> void Debug::ad(T *arr, ll n) { for (int i = 0; i <= n; i++) cout << arr[i] << " "; cout << endl; } template<typename T, size_t N> void Debug::ad2(T (&arr)[N], ll n) { for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " "; cout << endl; } template<typename T> void Debug::md(T mp) { cout << "key : value" << endl; for (auto const &m : mp) cout << m.first << " : " << m.second << endl; cout << endl; } } #endif //INCLUDE_DEBUG_HPP using dbg::Debug; Debug debug; class BTouitsu { public: void solve(std::istream& in, std::ostream& out) { int n; in >> n; string a, b, c; in >> a >> b >> c; int cnt = 0; for(int i=0; i<n; i++){ if(a[i] == b[i] && b[i] == c[i]) continue; else if(a[i] == b[i] || b[i] == c[i] || c[i] == a[i]) cnt++; else cnt+=2; } out << cnt << enl; } }; int main() { BTouitsu solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll N = 0; cin >> N; ll M = 0; cin >> M; vector<ll> p(M,0); vector<string> S(M); for(ll i = 0; i < M; i++) { cin >> p.at(i); cin >> S.at(i); } vector<int> A(N,0); vector<bool> B(N,0); ll sum = 0; ll ans = 0; for (size_t i = 0; i < M; i++) { if(S.at(i) == "AC" && !B.at(p.at(i) - 1)) { ans++; sum += A.at(p.at(i) - 1); B.at(p.at(i) - 1) = 1; } else if (S.at(i) == "WA" && !B.at(p.at(i) - 1)) { A.at(p.at(i) - 1)++; } } cout << ans << ' ' << sum << endl; return 0; }
0
#include <bits/stdc++.h> int solve() { int N, M; std::cin >> N >> M; std::vector<int> s(M); std::vector<int> c(M); for (int i = 0; i < M; ++i) std::cin >> s[i] >> c[i]; /* 全探索 */ for (int n = 0; n < std::pow(10,N); ++n) { int digit = 1; // 0は1桁 std::vector<int> each_num(1, n%10); // 一の位 int x = n/10; while (x) { digit++; each_num.push_back(x%10); x /= 10; } if (digit != N) continue; // 桁数の条件を満たさない std::reverse(each_num.begin(), each_num.end()); bool ok = true; // 条件を満たす整数が存在するかどうか for (int i = 0; i < M; ++i) if (each_num[s[i]-1] != c[i]) ok = false; // 一つでも条件を満たさないものがあれば if (ok) return n; // 桁数とそれぞれの桁の数字が条件を満たす } return -1; } int main() { std::cout << solve() << std::endl; return 0; }
#include <bits/stdc++.h> #include <set> using namespace std; using pii = pair<int,int>; using pll = pair<long long, long long>; const long long INF = 1<<29; const int MOD = 1000000007; long long ruizyou(long long m,long long n){ if(m == 0)return 0; if(m == 1)return 1; long long ans = 1; long long tmp = m; for(int i=0;i<=30;i++){ if(n & (1<<i)){ ans *= tmp; ans %= MOD; } tmp *= tmp; tmp %= MOD; } return ans; } long long kaizyou(long long x){ if(x == 0)return 1; return x * kaizyou(x-1) % MOD; } long long comb(long long x,long long y){ long long bunsi = kaizyou(x); long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD; return bunsi * ruizyou(bunbo,MOD-2) % MOD; } struct unionfind{ vector<int> par; vector<vector<int>> children; vector<int> hukasa; vector<int> kazu; unionfind(int n){ par = vector<int>(n); hukasa = vector<int>(n,0); kazu = vector<int>(n,1); for(int i=0;i<n;i++){ par.at(i) = i; } } int root(int x){ if(par.at(x) == x)return x; return root(par.at(x)); } void unite(int x,int y){ int rx = root(x); int ry = root(y); if(rx == ry)return; if(hukasa.at(rx) >= hukasa.at(ry)){ par.at(ry) = rx; hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx)); kazu.at(rx) += kazu.at(ry); } else{ par.at(rx) = ry; kazu.at(ry) += kazu.at(rx); } } void newkazu(){ int n = kazu.size(); for(int i=0;i<n;i++){ kazu.at(i) = kazu.at(root(i)); } } bool same(int x,int y){ return root(x) == root(y); } }; int ctoi(char a){ return a - '0'; } long long gcd(long long a,long long b){ long long c = max(a,b); long long d = min(a,b); if(d % c == 0)return c; return gcd(c,d%c); } long long lcm(long long a,long long b){ return a * b / gcd(a,b); } void hukasa(vector<vector<int>> s,vector<vector<int>> table,int &ans,pii frm,int n,int m){ int x,y; tie(x,y) = frm; set<pii> se; if(x-1 >= 0)se.insert(pii(x-1,y)); if(x+1 < n)se.insert(pii(x+1,y)); if(y-1 >= 0)se.insert(pii(x,y-1)); if(y+1 < m)se.insert(pii(x,y+1)); for(auto t:se){ int tx,ty; tie(tx,ty) = t; if(s.at(tx).at(ty) && table.at(tx).at(ty) == -1){ table.at(tx).at(ty) = table.at(x).at(y) + 1; ans = max(ans,table.at(tx).at(ty)); hukasa(s,table,ans,t,n,m); table.at(tx).at(ty) = -1; } } } void daiku(int frm,vector<vector<pii>> g,vector<int> &cost,int n){ priority_queue<pii,vector<pii>,greater<pii>> q; q.push(pii(cost.at(frm),frm)); vector<bool> kakutei(n,false); while(!q.empty()){ pii now = q.top(); q.pop(); int n1,n2; tie(n1,n2) = now; if(kakutei.at(n2))continue; kakutei.at(n2) = true; for(auto t:g.at(n2)){ int tx,ty; tie(tx,ty) = t; if(cost.at(tx) > n1 + ty){ cost.at(tx) = n1 + ty; q.push(pii(cost.at(tx),tx)); } } } } int main(){ int n,m; cin >> n >> m; vector<int> s(m),c(m); for(int i=0;i<m;i++)cin >> s.at(i) >> c.at(i); int ans = -1; for(int i=ruizyou(10,n-1);i<ruizyou(10,n);i++){ bool flag = true; for(int j=0;j<m;j++){ if(i / ruizyou(10,n - s.at(j)) % 10 != c.at(j))flag = false; } if(flag){ ans = i; break; } } if(n == 1){ bool flag = true; for(int i=0;i<m;i++){ if(c.at(i) != 0)flag = false; } if(flag)ans = 0; } cout << ans << endl; }
1
#include <iostream> #include <iomanip> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <algorithm> #include <cstdio> #include <utility> #include <string> #include <cmath> #include <cstdlib> #include <cstring> #include <deque> #include <numeric> using namespace std; typedef uint64_t u64; typedef int64_t s64; typedef uint32_t u32; typedef int32_t s32; typedef vector<s32> vs32; typedef vector<u32> vu32; typedef vector<s64> vs64; typedef vector<u64> vu64; const double PI=3.14159265358979323846; #define MAX(x, y) ((x) < (y) ? (y) : (x)) #define MIN(x, y) ((x) > (y) ? (y) : (x)) #define rep(i, N) for(int i = 0; i < N; ++i) #define CEIL(x, y) (((x) + (y) - 1) / (y)) #define MOD 1000000007ULL #define IN(l, r, x) ((l) <= (x) && (x) < (r)) int main() { cin.tie(0); ios::sync_with_stdio(false); s64 n, m; cin >> n >> m; vs64 x(n), y(m); rep (i, n) { cin >> x[i]; if (x[i] < 0) x[i] += MOD; } rep (i, m) { cin >> y[i]; if (y[i] < 0) y[i] += MOD; } s64 xadd, xsub, yadd, ysub; xadd = xsub = yadd = ysub = 0; rep (i, n) { xadd = (xadd + x[i] * i % MOD) % MOD; xsub = (xsub + x[n - i - 1] * i % MOD) % MOD; } xsub = MOD - xsub; rep (i, m) { yadd = (yadd + y[i] * i % MOD) % MOD; ysub = (ysub + y[m - i - 1] * i % MOD) % MOD; } ysub = MOD - ysub; cout << (((xadd + xsub) % MOD) * ((yadd + ysub) % MOD)) % MOD << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; int read(){ int x=0; char c=getchar(); int flag=1; while(!isdigit(c)) { if(c=='-') flag=-1; c=getchar(); } while(isdigit(c)) { x=((x+(x<<2))<<1)+(c^48); c=getchar(); } return x*flag; } const int mod=1e9+7; int n,k; int dp[2005][2005];//i个白球,j种颜色 int fac[4000005],Inv[4000005]; int C(int n,int m){ if(m<0||n<m) return 0; return 1ll*(1ll*fac[n]*Inv[m]%mod)*Inv[n-m]%mod; } void exgcd(int a,int b,int &x,int &y){ if(b==0) { x=1; y=0; return ; } exgcd(b,a%b,y,x); y-=a/b*x; } int inv(int a){ int x=0,y=0; exgcd(a,mod,x,y); return (x%mod+mod)%mod; } signed main(){ fac[0]=1; for(int i=1;i<=4000000;i++) fac[i]=1ll*fac[i-1]*i%mod; Inv[4000000]=inv(fac[4000000]); for(int i=3999999;i>=0;i--) Inv[i]=1ll*Inv[i+1]*(i+1)%mod; n=read(),k=read(); if(k==1) { puts("1"); return 0; } dp[0][0]=1; for(int i=1;i<=n;i++){ dp[i][0]=1; for(int j=1;j<=i;j++){ dp[i][j]=(dp[i-1][j]+1ll*(1ll*dp[i][j-1]*C(n*k-(j-1)*(k-1)-i-1,k-2))%mod*(n-j+1)%mod)%mod; } } printf("%d\n",dp[n][n]); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main(){ int n, k; cin >> n >> k; int l[n], ans = 0; for(int i=0; i<n; ++i) cin >> l[i]; sort(l, l+n, greater<int>()); for(int i=0; i<k; ++i) ans += l[i]; cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define For(i,n,k) for(int i=(n);i<(k);i++) #define ALL(a) (a).begin(),(a).end() vector<int> match = {-1,2,5,5,4,5,6,3,7,6}; void Main(){ int n,m; cin >> n >> m; vector<pair<int,int>> approval(m);//first:本数 second:数 For(i,0,m) { cin >> approval[i].second; approval[i].first = match[approval[i].second]; } sort(ALL(approval), [](auto const& l, auto const& r) {//数の大きい順にソート if(l.second != r.second) return l.second > r.second; else return l.first > r.first; }); vector<vector<string>> dp(m+1,vector<string> (n+1)); For(j,0,n+1) dp[0][j]=""; For(i,0,m+1) dp[i][0]=""; For(i,0,m){ For(j,1,n+1){ if(j<approval[i].first) dp[i+1][j]=dp[i][j]; else{ string str1 = dp[i][j]; string str2 = dp[i+1][j-approval[i].first]; if(str2 == "" && j != approval[i].first) dp[i+1][j]=str1; else{ str2.push_back(char(approval[i].second + '0')); if(str1.size()>str2.size()) dp[i+1][j]=str1; else if(str1.size()<str2.size()) dp[i+1][j]=str2; else if(str1>str2) dp[i+1][j]=str1; else dp[i+1][j]=str2; } } } } cout << dp[m][n] << endl; } int main(){ Main(); /* 東方風神録は神が出てくるので当然神ゲー */ return 0; }
0
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; using P = pair<int,int>; const int MOD = 1000000007; int main() { int a,b; cin>>a>>b; int c=a+b,d=a-b,e=a*b; c=max(c,d); c=max(c,e); cout<<c<<endl; }
#include<bits/stdc++.h> using namespace std; const int N=1000005,E=262144; const int M=998244353; int n,m,i,j,s,a[N],dp[6005][12005]; long long dfs(int i,int j) { if(i<0) return 0; if(i==0) if(j>=0&&j%3==0) return 1; else return 0; if(dp[i][j+6000]!=-1) return dp[i][j+6000]; long long s=dfs(i-1,j+1); s+=dfs(i-2,j-1)*(i-1); s+=dfs(i-3,j)*(i-1)*(i-2); return dp[i][j+6000]=s%m; } int main() { scanf("%d %d",&n,&m); memset(dp,-1,sizeof(dp)); cout<<dfs(n*3,0); }
0
#include <bits/stdc++.h> #define ll long long using namespace std; const int N=5e5+50; int gi(){ char ch=getchar(); int x=0,q=0; while(ch<'0'||ch>'9') q=ch=='-'?1:q,ch=getchar(); while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return q?-x:x; } int vis[N],d[N],head[N],nn[N][2],cnt=1,flag; ll ans; #define link(u,v) (nn[++cnt][1]=v,nn[cnt][0]=head[u],head[u]=cnt) void dfs(int x,int op){ if (vis[x]){ if (op!=d[x]) flag=1; return; } vis[x]=1,d[x]=op; for (int i=head[x]; i; i=nn[i][0]) dfs(nn[i][1],op^1); return; } int main(){ int n=gi(),m=gi(),u,v; for (int i=1; i<=m; ++i) u=gi(),v=gi(),link(u,v),link(v,u); int a=0,b=0,c=0; for (int i=1; i<=n; ++i) if (!head[i]) ++a; for (int i=1; i<=n; ++i) if (head[i]&&!vis[i]){ flag=0,dfs(i,0); if (flag) ++b; else ++c; } cout<<2ll*a*n-1ll*a*a+1ll*b*b+2ll*c*(b+c); return 0; }
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<int>>; // グラフ型 typedef long long ll; #define _GLIBCXX_DEBUG int main() { ll N, M; cin >> N >> M; vector<ll> save(N+1, -1); for(ll i=0; i<M; i++){ ll a, b; cin >> a >> b; if(save[a] == -1){ save[a] = b; }else if (save[a] == b) { save[a] = b; }else{ cout << "-1" << endl; return 0; } } if(save[1] == 0 && N!=1){ cout << "-1" << endl; return 0; } for(ll i=1; i<=N; i++){ if(save[i]!=-1){ cout << save[i]; }else{ if(i==1){ if(N==1) cout << 0; else cout << 1; } else cout << 0; } } cout << endl; return 0; }
0
#include <iostream> using namespace std; int main() { int n, i, x; cin >> n; i = 1; 3 <= n <= 10000; while (i <= n - 1) { i++; x = i; if (x % 3 == 0) { cout << " " << i; } else if (x % 10 == 3) { cout << " " << i; } else if ((x / 10) % 10 == 3) { cout << " " << i; } else if ((x / 100) % 10 == 3) { cout << " " << i; } else if ((x / 1000) % 10 == 3) { cout << " " << i; } } cout << endl; }
#include<bits/stdc++.h> using namespace std; const int MAX_N = 2e5 + 5; string s; void solve(){ stack<char> st; int i = 0, n = s.length(); for(i = 0; i < n; i++){ if(s[i] == 'S') st.push(s[i]); else{ if(st.size() > 0 && st.top() == 'S') st.pop(); else st.push(s[i]); } } cout << st.size() << "\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> s; solve(); return 0; }
0
#include<bits/stdc++.h> #define rint register int using namespace std; inline int read(){ int s=0,f=1; char c=getchar(); while(c<'0'||c>'9'){if(c=='-')f=0;c=getchar();} while(c>='0'&&c<='9') s=(s<<1)+(s<<3)+(c^48),c=getchar(); return f?s:-s; } const int Mod=1e9+7; int n,X,Y,Z,ed,ans=1; int f[50][1<<18]; int main(){ n=read(); X=read(); Y=read(); Z=read(); ed=(1<<X+Y+Z-1)|(1<<Y+Z-1)|(1<<Z-1); f[0][0]=1; for(rint i=1;i<=n;++i,ans=1ll*ans*10%Mod) for(rint S=0;S<(1<<X+Y+Z);++S){ if(!f[i-1][S]) continue; for(rint j=1;j<=10;++j){ int now=(S<<j)|(1<<j-1); now=now&((1<<X+Y+Z)-1); if((now&ed)!=ed) f[i][now]=1ll*(f[i][now]+f[i-1][S])%Mod; } } for(rint S=0;S<(1<<X+Y+Z);++S) if((S&ed)!=ed) ans=1ll*(ans-f[n][S]+Mod)%Mod; printf("%d",ans); return 0; }
#include <bits/stdc++.h> using namespace std; int n,x,y,z; typedef long long ll; const int N = 41, MAXM = (1 << 18) + 50, mod = (int)1e9 + 7; map<vector<int>, int> mp; int cnt = 0; int dp[N][MAXM]; int nxt[MAXM][11]; bool haiku[MAXM]; //vector<vector<int> > seqs; int cumul(vector<int> &V, int cur, int sum) { while(cur < V.size() && sum > 0) sum -= V[cur], cur++; if(sum != 0) return -1; return cur; } bool is_haiku(vector<int> &V) { int sum = 0; for(int x : V) sum += x; if(sum != x + y + z) return false; int cur = 0; if((cur = cumul(V, cur, x)) == -1) return false; if((cur = cumul(V, cur, y)) == -1) return false; return cumul(V, cur, z) != -1; } int get(vector<int> &V) { if(!mp.count(V)) { haiku[cnt] = is_haiku(V); // seqs.push_back(V); mp[V] = cnt++; } return mp[V]; } void add(int &to, int x) { to += x; if(to >= mod) to -= mod; } string tostr(vector<int> &V) { string s; for(int x : V) s.push_back((char)(x + '0')); return s; } int main() { cin >> n >> x >> y >> z; int mn = max(x, max(y, z)); vector<int> V; int id0 = get(V); for(int i = 1; i <= mn; i++) { vector<int> nV(1, i); nxt[id0][i] = get(nV); } for(int len = 1; len <= x + y + z; len++) { for(int i = 0; i < (1 << (len-1)); i++) { vector<int> sV; int cur = 1; bool bad = false; for(int j = 0; j < len - 1; j++) { if((i >> j) & 1) { if(cur > mn) { bad = true; break; } sV.push_back(cur), cur = 1; } else cur++; } if(cur > mn || bad) continue; sV.push_back(cur); int c_id = get(sV); for(int k = 1; k <= mn; k++) { vector<int> nV; nV.push_back(k); nV.insert(nV.end(), sV.begin(), sV.end()); int sum = len + k; while(!nV.empty() && sum > x + y + z) { sum -= nV.back(); nV.pop_back(); } nxt[c_id][k] = get(nV); } } } // for(int i = 0; i < cnt; i++) { // for(int x : seqs[i]) cout << x << " "; // cout << endl; // } // cout << cnt << endl; // for(int i = 0; i < cnt; i++) { // cout << "nxts of " << tostr(seqs[i]) << endl; // if(haiku[i]) cout << "is haiku" << endl; // for(int k = 1; k <= 10; k++) cout << k << ": " << tostr(seqs[nxt[i][k]]) << endl; // } dp[0][0] = 1; for(int i = 1; i <= n; i++) { for(int j = 0; j < cnt; j++) { if(haiku[j]) continue; for(int k = 1; k <= 10; k++) add(dp[i][nxt[j][k]], dp[i-1][j]); } } ll res = 1; for(int i = 0; i < n; i++) res *= 10, res %= mod; int f_res = 0; for(int i = 0; i < cnt; i++) if(!haiku[i]) add(f_res, dp[n][i]); cout << (res - f_res + mod) % mod << endl; }
1
#include <bits/stdc++.h> using namespace std; using ll =long long; #define all(v) v.begin(),v.end() int main() { set<ll> S; for(ll i=0;i<3;i++) { ll A; cin>>A; S.insert(A); } if(S.size()==2) { cout<<"Yes"<<endl; } else { cout<<"No"<<endl; } }
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define Opy ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0) typedef long long ll; int main() { //Opy; /*------------------------------------------------- #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif -------------------------------------------------*/ string A; cin>> A; if(A[0] == 'R' && A[1] == 'R' && A[2] == 'R') cout<< "3\n"; else if((A[0] == 'R' && A[1] == 'R') || (A[1] == 'R' && A[2] == 'R')) { cout<< "2\n"; } else if(A[0] == 'S' && A[1] == 'S' && A[2] == 'S') cout<< "0\n"; else cout<< "1\n"; return 0; }
0
#include <bits/stdc++.h> #include <string> #include <vector> #include <algorithm> #include <math.h> #include <iostream> #include <numeric> #define rep(i,n) for (int i = 0;i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; #define chmax(x,y) x = max(x,y) int INF = 1e9; int main(){ int n; ll x;cin >> n >> x; vector<ll> a(n); rep(i,n) cin >> a[i]; ll ans = 0; if(a[0]>x) { ans += a[0]-x; a[0] = x; } rep(i,n-1){ //cout << " " << ans << endl; if(a[i]+a[i+1]>x){ ans += a[i+1] - (x-a[i]); a[i+1] = x-a[i]; } } //rep(i,n) cout << a[i] << endl; cout << ans << endl; }
#include <iostream> #include <string> #include <algorithm> #include <functional> #include <vector> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <cstdio> #include <cmath> #include <tuple> #include <iomanip> #include <numeric> #include <unordered_map> #include <sstream> #include<limits.h> #include<float.h> #include<list> #include <array> #include <complex> #include<stdio.h> #include<string.h> #include <bitset> // #include<assert.h> #include<random> using namespace std; #define int long long #define I32_MAX 2147483647 #define I64_MAX 9223372036854775807LL #define I64_MAX2 1223372036854775807LL #define INF I64_MAX2 #define MOD 1000000007 // #define MOD 998244353 #define MEM_SIZE 10000 #define DEBUG_OUT true #define ALL(x) (x).begin(), (x).end() template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";} template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;} template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } } template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);} template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}} 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(void) { int N; cin>>N; vector<int> vec (N,0); for (int i = 0; i < N; i++) { cin>>vec[i]; } vector<int> data; data.push_back(-1*vec[0]); for (int i = 1; i < N; i++) { int X = -1*vec[i]; auto itr = upper_bound(ALL(data),X); if(itr == data.end()) { data.push_back(X); } else { *itr =X; } } cout<<data.size()<<endl; return; } int32_t main(int32_t argc, const char *argv[]) { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout << std::fixed; std::cout << std::setprecision(11); solve(); return 0; }
0
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define ALL(a) (a).begin(),(a).end() using namespace std; using ll = long long; using P = pair<int,int>; vector<int> num = {0,2,5,5,4,5,6,3,7,6}; vector<char> nchar = {'0','1','2','3','4','5','6','7','8','9'}; bool check(string s,string t){ int n1 = s.size(), n2 = t.size(); if(n1 > n2) return false; if(n1 < n2) return true; if(s > t) return false; return true; } int main(){ int n,m; cin >> n >> m; vector<string> dp; vector<int> match(m); rep(i,m) cin >> match[i]; dp.push_back(""); for(int i = 1;i <= n;++i){ string s = ""; rep(j,m) { if(num[match[j]] <= i) { if(dp[i-num[match[j]]] == "" && i != num[match[j]]) continue; if(check(s,dp[i-num[match[j]]]+nchar[match[j]])) s = dp[i-num[match[j]]]+nchar[match[j]]; } } dp.push_back(s); } cout << dp[n] << endl; }
#include<bits/stdc++.h> #define fi first #define se second #define lc (x<<1) #define rc (x<<1|1) #define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++) #define mk make_pair #define pi pair<int,int> #define pb push_back #define IT iterator #define SZ(a) ((int)a.size()) #define all(a) a.begin(),a.end() using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; const int N=4e5+10,size=1<<20,mod=998244353; const ll inf=1e18; template<class o> void qr(o &x) { char c=gc; x=0; int f=1; while(!isdigit(c)){if(c=='-')f=-1; c=gc;} while(isdigit(c)) x=x*10+c-'0',c=gc; x*=f; } template<class o> void qw(o x) { if(x/10) qw(x/10); putchar(x%10+'0'); } template<class o> void pr1(o x) { if(x<0)x=-x,putchar('-'); qw(x); putchar(' '); } template<class o> void pr2(o x) { if(x<0)x=-x,putchar('-'); qw(x); puts(""); } int n,dic[150],f[N*2][2],g[N*2][2]; ll ans=inf; vector<pi> x[N],y[N]; int main() { qr(n); dic['U']=0; dic['D']=1; dic['R']=2; dic['L']=3; for(int i=1;i<=n;i++) { int a,b,c;qr(a); qr(b); char str[6]; scanf("%s",str); a++; b++; c=dic[str[0]]; x[a].pb(mk(b,c)); y[b].pb(mk(a,c)); } for(int i=1;i<N;i++) { sort(all(x[i])); sort(all(y[i])); ll a,b; a=b=inf; for(auto j:x[i]) { if(j.se==0) a=j.fi; else if(j.se==1) b=j.fi; if(a<b) ans=min(ans,(b-a)*5); } a=b=inf; for(auto j:y[i]) { if(j.se==2) a=j.fi; else if(j.se==3) b=j.fi; if(a<b) ans=min(ans,(b-a)*5); } } for(int i=1;i<N;i++) for(auto j:x[i]) { int t=j.fi; if(j.se==2) { f[j.fi-i+N][0]=i; f[j.fi+i][1]=i; } else if(j.se==3) { int k=g[j.fi+i][1]; if(k) ans=min(ans,(i-k)*10LL); k=g[j.fi-i+N][0]; if(k) ans=min(ans,(i-k)*10LL); } else if(j.se==1) { int k=f[j.fi-i+N][0]; if(k) ans=min(ans,(i-k)*10LL); g[j.fi+i][1]=i; } else if(j.se==0) { int k=f[j.fi+i][1]; if(k) ans=min(ans,(i-k)*10LL); g[j.fi-i+N][0]=i; } } if(ans>inf/2) puts("SAFE"); else pr2(ans); return 0; }
0
#include <bits/stdc++.h> #define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a) #define loop(i, s, n) loop2(i, s, n, 1) #define rep(i, n) loop(i, 0, n) #define pb push_back #define all(in) in.begin(),in.end() using ll = long long; using ull = unsigned long long; using namespace std; int main(){ int n; cin >> n; vector<int> data(n); rep(i,n) cin >> data[i]; vector<int> ans(1,-data[0]); for(int i = 1; i < n; i++){ int k = upper_bound(all(ans),-data[i]) - ans.begin(); if(k == ans.size()) ans.push_back(-data[i]); else ans[k] = -data[i]; } cout << ans.size() << endl; }
#include <iostream> #include <cmath> #include <cstdio> using namespace std; int main(void) { double x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; printf("%lf\n", sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2))); return 0; }
0
#include <iostream> #include <string> #include <algorithm> #include <vector> //#include <stack> //#include <queue> //#include <cstdio> #include <cmath> #include <iterator> #include <map> //#include <list> #include <iomanip> using namespace std; #define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define prec std::cout << std::fixed << std::setprecision(15); #define endl "\n" #define MOD 1000000007 #define Int int64_t #define PI 3.14159265358979 #define ssort(z) sort(z.begin(), z.end()) #define rsort(z) sort(z.rbegin(), z.rend()) #define eerase(z) z.erase(unique(z.begin(), z.end()), z.end()) #define ccnt(z, w) count(z.begin(), z.end(), w) #define rep(i,a,n) for(Int (i)=(a); (i)<(n); (i)++) #define repq(i,a,n) for(Int (i)=(a); (i)<=(n); (i)++) const int MAX_N = 1000000; const Int MAX_N_Int = 1000000000000; template <typename T> void printV(const std::vector<T>& v, const char * const separator = " ") { if(!v.empty()) { std::copy(v.begin(), --v.end(), std::ostream_iterator<T>(std::cout, separator)); std::cout << v.back() << "\n"; } } 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; } Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; } Int lcm(Int a, Int b) { return a / gcd(a, b) * b; //a*bは64bit integer overflow } int Max(int a, int b, int c) { int temp = max(a, b); return max(temp, c); } int Min(int a, int b, int c) { int temp = min(a, b); return min(temp, c); } bool integer(double num) { return floor(num) == num; } Int fact(int num) { if (num == 0) return 1; else return num * fact(num - 1); } Int yakusu(int n) { int cnt = 0; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { cnt++; if (i * i != n) cnt++; } } return cnt; } Int fact_mod(Int n, Int mod) { Int f = 1; repq(i,2,n) f = f * (i % MOD) % MOD; return f; } // 繰り返し二乗法 (modの世界での累乗) Int mod_pow(Int x, Int n, Int mod) { Int res = 1; while(n > 0) { if(n & 1) res = (res * x) % mod; x = (x * x) % mod; n >>= 1; } return res; } // 組み合わせ nCr を求める Int combination_mod(Int n, Int r, Int mod) { if(r > n-r) r = n-r; if(r == 0) return 1; Int a = 1; rep(i, 0, r) a = a * ((n-i) % mod) % mod; Int b = mod_pow(fact_mod(r, mod), mod-2, mod); return (a % mod) * (b % mod) % mod; } Int cntZero(string s){ int cnt=0; reverse(s.begin(),s.end()); for (int i = 0; i < s.length(); ++i) { if(s[i]=='0')cnt++; else break; } return cnt; } int main() { //COMinit(); IOS; prec; Int a,b,c,d,n,m,k,x,y=0,ans=0,ans1=0; string str,s="",t,u; Int h,w; cin>>h>>w>>n; Int cnt=0; rep(i,0,min(h,w)){ ans+=max(h,w); cnt++; if(ans>=n){ cout<<cnt<<endl; return 0; } } rep(i,0,max(h,w)){ ans+=min(h,w); cnt++; if(ans>=n){ cout<<cnt<<endl; return 0; } } cout<<endl; return 0; }
#include<stdio.h> int main() { int n, m, k; scanf("%d %d %d", &n, &m, &k); int sum1 = k/n; int sum2 = k/m; int ctr = 0; int temp; if(sum1 > sum2){ for(int i = 1; i <= 100; i++){ temp = m * i; ++ctr; if(temp >= k){ break; } } }else{ for(int i = 1; i <= 100; i++){ temp = n * i; ++ctr; if(temp >= k){ break; } } } printf("%d\n", ctr); }
1
#include <bits/stdc++.h> using namespace std; const int MaxM = 110; int N, M, A[ MaxM ], Sum, Num; int main() { scanf( "%d%d", &N, &M ); for( int i = 1; i <= M; ++i ) scanf( "%d", &A[ i ] ); for( int i = 1; i <= M; ++i ) Sum += A[ i ]; if( Sum != N ) { printf( "Impossible" ); return 0; } for( int i = 1; i <= M; ++i ) if( A[ i ] % 2 == 1 ) ++Num; if( Num > 2 ) { printf( "Impossible" ); return 0; } if( Num == 0 ) { for( int i = 1; i <= M; ++i ) printf( "%d ", A[ i ] ); printf( "\n" ); printf( "%d\n", M + 1 ); printf( "%d ", A[ 1 ] - 1 ); for( int i = 2; i <= M; ++i ) printf( "%d ", A[ i ] ); printf( "%d\n", 1 ); return 0; } if( Num == 2 ) { int a, b; for( int i = 1; i <= M; ++i ) if( A[ i ] % 2 == 1 ) { a = A[ i ]; break; } for( int i = M; i >= 1; --i ) if( A[ i ] % 2 == 1 ) { b = A[ i ]; break; } printf( "%d ", a ); for( int i = 1; i <= M; ++i ) if( A[ i ] % 2 == 0 ) printf( "%d ", A[ i ] ); printf( "%d\n", b ); if( a > 1 ) { printf( "%d\n", M ); printf( "%d ", a - 1 ); for( int i = 1; i <= M; ++i ) if( A[ i ] % 2 == 0 ) printf( "%d ", A[ i ] ); printf( "%d\n", b + 1 ); return 0; } printf( "%d\n", M - 1 ); for( int i = 1; i <= M; ++i ) if( A[ i ] % 2 == 0 ) printf( "%d ", A[ i ] ); printf( "%d\n", b + 1 ); return 0; } int t = 0; for( int i = 1; i <= M; ++i ) if( A[ i ] % 2 == 1 ) { t = A[ i ]; break; } printf( "%d ", t ); for( int i = 1; i <= M; ++i ) if( A[ i ] % 2 == 0 ) printf( "%d ", A[ i ] ); printf( "\n" ); if( t > 1 ) { printf( "%d\n", M + 1 ); printf( "%d ", t - 1 ); for( int i = 1; i <= M; ++i ) if( A[ i ] % 2 == 0 ) printf( "%d ", A[ i ] ); printf( "%d\n", 1 ); } else { printf( "%d\n", M ); for( int i = 1; i <= M; ++i ) if( A[ i ] % 2 == 0 ) printf( "%d ", A[ i ] ); printf( "%d\n", 1 ); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> P; typedef pair<ll,ll> l_l; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; typedef pair<l_l,ll> lll; typedef vector<string> vs; const ll dx[4]={1,-1,0,0}; const ll dy[4]={0,0,1,-1}; #define pb push_back #define sz(x) (int)(x).size() #define fi first #define se second #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=1001001000; const int mINF=-1001001000; const ll LINF=1010010010010010000; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } int main(){ ll n,k;cin>>n>>k; vl a(n); rep(i,n)cin>>a[i]; rep(t,k){ vl imos(n+1); rep(i,n){ imos[max(i-a[i],0ll)]++; imos[min(i+a[i]+1,n)]--; } rep(i,n)imos[i+1]+=imos[i]; imos.pop_back(); if(imos==a)break; a=imos; } rep(i,n)cout<<a[i]<<" ";cout<<endl; }
0
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <array> #include <queue> #include <deque> #include <map> #include <set> #include <sstream> #include <cstdio> #include <cstring> #include <cmath> #include <list> #include <numeric> #include <stack> #include <iomanip> #include <random> #include <complex> #include <functional> #include <tuple> #include <new> //#include "All.h" using namespace std; #define EPS (1e-9) #define INF (1e9) #define MOD (ll)(1e9 + 7) #define PI (acos(-1)) #define REP(i,a,n) for(int i=a;i<n;i++) #define rep(i, n) REP(i,0,n) #define allof(a) (a).begin(), (a).end() #define Yes(q) ((q) ? "Yes" : "No") #define YES(q) ((q) ? "YES" : "NO") #define Possible(q) ((q) ? "Possible" : "Impossible") #define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE") using ll = long long int; ll gcd(ll a, ll b) { if (a < b) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } ll beki(ll a, ll b) { ll tmp = 1; rep(i, b) tmp *= a; return tmp; } ll modPow(ll x, ll a) { if (a == 1) return x; if (a % 2) return (x * modPow(x, a - 1)) % MOD; ll t = modPow(x, a / 2); return ((t % MOD) * (t % MOD)) % MOD; } ll modInv(ll x) { return modPow(x, MOD - 2); } int main() { map<string, int> day_to_sun; string S; day_to_sun["SUN"] = 7; day_to_sun["MON"] = 6; day_to_sun["TUE"] = 5; day_to_sun["WED"] = 4; day_to_sun["THU"] = 3; day_to_sun["FRI"] = 2; day_to_sun["SAT"] = 1; cin >> S; cout << day_to_sun[S] << endl; }
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for(int i=0; i<n; i++) #define rep1(i, n) for(int i=1; i<=n; i++) #define repr(i, n) for(int i=n-1; i>=0; i--) #define repr1(i, n) for(int i=n; i>=1; i--) #define all(v) v.begin(),v.end() 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 INF = 1e9; const ll LLINF = 1e18; const ll MOD = 1e9+7; const double EPS = 1e-10; 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 a[2]; cin >> a[0] >> a[1]; int ans = 0; rep(i, 2) { if (a[i] <= 3) ans += (4 - a[i]) * 100000; } if (a[0] == 1 && a[1] == 1) ans += 400000; cout << ans << endl; }
0
#include<iostream> using namespace std; #include<string> #include<strstream> #include<sstream> #include<algorithm> #include<math.h> bool issqr(int n) { double d = sqrt(n); double x = floor(d); if (d - x == 0) return true; else return false; } int main() { int n; cin >> n; for (int i = n; i >= 0; --i) { if (issqr(i) == true) { cout << i; break; } } }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define inf 1000000000 #define IOS ios_base::sync_with_stdio(0);cin.tie(0) #define meM(y,a) memset(y,a,sizeof y) #define sC(a) scanf("%d",&a) #define alL(a) a.begin(),a.end() #define prinT(a,sz) cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl #define ranD srand(chrono::steady_clock::now().time_since_epoch().count()); typedef pair<int,int>pi; typedef pair<ll,ll>pll; //int fx[]={0,0,1,-1}; //int fy[]={1,-1,0,0}; //int gx[]={0,0,1,1,1,-1,-1,-1}; //int gy[]={1,-1,0,1,-1,0,1,-1}; const int N=100010; int main() { IOS; string s;cin>>s; int n=s.length(); int cnt=0; int i=0; int ss=0,t=0; while(i<n) { // cout<<"i = "<<i<<endl; while(s[i]=='S'){ ss++,i++; if(i==n)break; } while(s[i]=='T'){ i++,t++; if(i==n)break; } cnt+=min(ss,t); ss=max(ss-t,0); t=0; } cout<<n-cnt*2<<endl; } /* sttssttsst SSSSTTSSTTTS */
0
#include <bits/stdc++.h> #define INF 1e9 #define endl '\n' #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i) #define FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i) #define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i) #define ALL(x) (x).begin(), (x).end() #define SORT(c) sort((c).begin(), (c).end()) #define SORTR(c) sort((c).begin(), (c).end(), greater<int>()) using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; vector<int> L(N); for (int i = 0; i < N; i++) { cin >> L.at(i); } int ans = 0; FOR(i, 0, N - 2) { FOR(j, i + 1, N - 1) { FOR(k, j + 1, N) { int Li = L.at(i); int Lj = L.at(j); int Lk = L.at(k); if ((Li != Lj) & (Li != Lk) & (Lj != Lk) & (Li + Lj > Lk) & (Lj + Lk > Li) & (Lk + Li > Lj)) { ++ans; } } } } cout << ans << endl; }
#include <bits/stdc++.h> #define PI 3.14159265359 #define rep(i,a,n) for(int i=a;i<(int)n;++i) #define SZ(x) ((int)(x).size()) //size() unsigned -> int #define descSort(a) sort(a.begin(),a.end(),std::greater<int>()) using namespace std; typedef long long ll; const ll INF = 1e9 + 7; int main() { int n; cin>>n; vector<ll> l(n); rep(i,0,n)cin>>l[i]; sort(l.begin(),l.end()); int ans=0; rep(i,0,n){ rep(j,i+1,n){ rep(k,j+1,n){ if(l[i]+l[j]<=l[k])continue; if(l[i]<l[j]&&l[j]<l[k]){ans++;} } } } cout<<ans<<endl; return 0; }
1
/** * author: tourist * created: 06.07.2020 09:38:22 **/ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int x, y; cin >> x >> y; int ans = 0; if (x <= 3) { ans += (4 - x) * 100000; } if (y <= 3) { ans += (4 - y) * 100000; } if (x == 1 && y == 1) { ans += 400000; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> #define mset(a, b) memset(a, b, sizeof(a)) #define mcpy(a, b) memcpy(a, b, sizeof(a)) #define rg register using namespace std; typedef long long LL; const int MAXN = 200005; const LL INF = 0x3f3f3f3f3f3f3f3f; template <typename T> inline void read(T &AKNOI) { T x = 0, flag = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') flag = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } AKNOI = flag * x; } template <typename T> inline void cmin(T &x, T y) { if (x > y) x = y; } template <typename T> inline void cmax(T &x, T y) { if (x < y) x = y; } int n, q, A, B, p[MAXN]; LL csum[MAXN], dp[MAXN]; struct BIT { LL tr[MAXN]; BIT() { mset(tr, 0x3f); } inline int lowbit(int x) { return x & (-x); } inline void update(int x, LL val) { for (int i=x;i<=n;i+=lowbit(i)) { cmin(tr[i], val); } } inline LL query(int x) { LL ret = INF; for (int i=x;i;i-=lowbit(i)) { cmin(ret, tr[i]); } return ret; } }t1, t2; void init() { read(n); read(q); read(A); read(B); for (int i=1;i<=q;++i) { read(p[i]); } for (int i=2;i<=q;++i) { csum[i] = csum[i-1] + abs(p[i]-p[i-1]); } } void solve() { dp[0] = min(abs(A-p[1]), abs(B-p[1])); t1.update(A, abs(B-p[1]) - A); t2.update(n-A+1, abs(B-p[1]) + A); t1.update(B, abs(A-p[1]) - B); t2.update(n-B+1, abs(A-p[1]) + B); for (int i=1;i<q;++i) { dp[i] = min( t1.query(p[i+1]) + csum[i] + p[i+1], t2.query(n-p[i+1]+1) + csum[i] - p[i+1] ); t1.update(p[i], dp[i] - csum[i+1] - p[i]); t2.update(n-p[i]+1, dp[i] - csum[i+1] + p[i]); } LL ans = INF; for (int i=0;i<q;++i) { cmin(ans, dp[i] + csum[q] - csum[i+1]); } printf("%lld\n", ans); } int main() { init(); solve(); return 0; }
0
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define repr(i,n) for(int i = (int)(n); i >= 0; i--) #define all(v) v.begin(),v.end() typedef long long ll; int main(){ int N; cin >> N; vector<pair<int,int> > red(N); vector<pair<int,int> > blue(N); rep(i,N){ cin >> red[i].second >> red[i].first; } rep(i,N){ cin >> blue[i].first >> blue[i].second; } sort(all(red)); sort(all(blue)); int ans = 0; rep(i,N){ int len = red.size(); for (int j = len - 1; j >= 0; j--){ if (blue[i].first > red[j].second && blue[i].second > red[j].first){ ans++; red.erase(red.begin() + j); break; } } } cout << ans << endl; }
#include <iostream> #include <string> #include <cstring> #include <algorithm> #include <functional> #include <cmath> #include <set> #include <queue> #include <deque> #include <vector> #include <climits> #include <sstream> #include <iomanip> #include <map> #include <stack> using namespace std; typedef unsigned long long ull; typedef long long ll; struct EdgeMF { int to; ll capacity; int reverse; }; void addEdgeForFlow(vector<vector<EdgeMF>>& G, int from, int to, ll capacity, ll reverseCapacity) { G[from].push_back({ to, capacity, (int)G[to].size() }); G[to].push_back({ from, reverseCapacity, (int)G[from].size() - 1 }); } ll dfsForFlow(vector<vector<EdgeMF>>& G, vector<bool>& used, int u, int t, ll f) { if (u == t) { return f; } used[u] = true; for (auto& e : G[u]) { if (used[e.to] || e.capacity <= 0) { continue; } auto d = dfsForFlow(G, used, e.to, t, min(f, e.capacity)); if (d > 0) { e.capacity -= d; G[e.to][e.reverse].capacity += d; return d; } } return 0; } ll calcMaxFlow(vector<vector<EdgeMF>>& G, int s, int t) { auto f = 0ll; while (true) { vector<bool> used((int)G.size()); auto d = dfsForFlow(G, used, s, t, LLONG_MAX); if (d <= 0) { break; } f += d; } return f; } int main() { int N; cin >> N; vector<int> x(2 * N); vector<int> y(2 * N); for (auto i = 0; i < 2 * N; ++i) { cin >> x[i] >> y[i]; } vector<vector<EdgeMF>> G(2 * N + 2); for (auto i = 0; i < N; ++i) { for (auto j = N; j < 2 * N; ++j) { if (x[i] < x[j] && y[i] < y[j]) { addEdgeForFlow(G, i, j, 1, 0); } } } int s = 2 * N; int t = s + 1; for (auto i = 0; i < N; ++i) { addEdgeForFlow(G, s, i, 1, 0); addEdgeForFlow(G, i + N, t, 1, 0); } cout << calcMaxFlow(G, s, t) << endl; return 0; }
1
#include <iostream> #include <bitset> #include <vector> #include <string> #include <algorithm> #include <set> #include <map> #include <stack> #include <cmath> #include <regex> #include <iomanip> #include <climits> #include <utility> #include <queue> using namespace std; using ll = long long int; using dd = long double; const ll MOD = 1e9 + 7; const dd PI = 3.1415926435; class UnionFind { public: UnionFind(int N) : par(N) { for (ll i = 0; i < N; i++) { par[i] = i; } } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; par[rx] = ry; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } private: vector<int> par; }; ll gcd(ll a, ll b) { if (a % b == 0) { return b; } return gcd(b, a % b); } ll fact(ll n) { if (n == 0) { return 1; } if (n == 1) { return 1; } return n * fact(n - 1) % MOD; } ll pow_fast(ll n, ll k) { if (k == 0) { return 1; } if (k == 1) { return n; } if (k % 2 == 0) { ll tmp = pow_fast(n, k / 2LL); return tmp * tmp % MOD; } else { ll tmp = pow_fast(n, k / 2LL); tmp *= tmp; tmp %= MOD; return tmp * n % MOD; } } map<ll, ll> sosuu(ll n) { map<ll, ll> res; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { res[i] += 1; n /= i; } } if (n != 1) { res[n] += 1; } return res; } int main() { string S; cin >> S; regex re("A[a-z]+C[a-z]+"); if (regex_match(S, re)) { cout << "AC" << endl; } else { cout << "WA" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; string res = "AC"; int C_cnt = 0; if (s.at(0) == 'A') { for (int i = 1; i < s.size(); i++) { if (s.at(i) == 'C') { if (2 <= i && i <= (s.size()-2)) { C_cnt++; } else { res = "WA"; } } else { if (!('a' <= s.at(i) && s.at(i) <= 'z')) res = "WA"; } } if (C_cnt != 1) res = "WA"; } else { res = "WA"; } cout << res << endl; return 0; }
1
#include<bits/stdc++.h> #define watch(x) cout << (#x) << " is " << (x) << endl #define endl "\n" typedef long long ll; using namespace std; int static fast = [](){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }(); // freopen("input.txt", "r", stdin); int main() { int n; string s, t; cin >> n >> s >> t; int overlap = 0; for(int i = 1; i <= n; i++) { if (s.substr(n-i, i) == t.substr(0, i)) { overlap = i; } } cout << n*2 - overlap << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int N; string s,t; cin>>N>>s>>t; long long len1,len2,count=0; len1=s.length(); len2=t.length(); if(len1==len2&&len1==N&&N>=1&&N<=100){ if (N>=len1+len2){ count=N; } else { count=len1+len2; for(int i=0;i<=len1;i++){ for(int j=1;j<=len2;j++){ if(s.substr(i,len1)==t.substr(0,j)&&len1+len2-j>=N){ count=min(len1+len2-j,count); } } } } cout<<count; } return 0; }
1
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <map> #include <queue> #include <set> #include <stack> #include <iomanip> using ll = long long; using uint = unsigned int; using graph = std::vector<std::vector<ll>>; using wGraph = std::vector<std::vector<std::pair<ll,ll>>>; #define rep(i,n) for (int i=0; i < int(n); i++) using namespace std; ll MOD7 = 1000000007; ll MOD9 = 1000000009; vector<ll> InputVec(ll N){ vector<ll> A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } return A; } void OutputVec(vector<ll> A){ for (int i = 0; i < A.size(); ++i) { cout << A[i] << ","; } cout << endl; } vector<vector<ll>> InputVec2d(ll H,ll W){ vector<vector<ll>> A(H); for (int yi = 0; yi < H; ++yi) { A[yi] = vector<ll>(W); } for (int yi = 0; yi < H; ++yi) { for (int xi = 0; xi < W; ++xi) { cin >> A[yi][xi]; } } return A; } vector<vector<char>> InputVec2dStr(ll H,ll W){ vector<vector<char>> A(H); for (int yi = 0; yi < H; ++yi) { A[yi] = vector<char>(W); } for (int yi = 0; yi < H; ++yi) { string S; cin >> S; for (int xi = 0; xi < W; ++xi) { A[yi][xi] = S[xi]; } } return A; } void OutputVec2d(vector<vector<ll>> A){ for (int yi = 0; yi < A.size(); ++yi) { for (int xi = 0; xi < A[yi].size(); ++xi) { cout << A[yi][xi] << ","; } cout << endl; } } graph InputGraph(ll N,ll M){ graph G(N); for (int i = 0; i < M; ++i) { ll a,b; cin >> a >> b; a--;b--; G[a].push_back(b); G[b].push_back(a); } return G; } graph InputDGraph(ll N,ll M){ graph G(N); for (int i = 0; i < M; ++i) { ll a,b; cin >> a >> b; a--;b--; G[a].push_back(b); } return G; } void OutputGraph(graph G){ for (int i = 0; i < G.size(); ++i) { cout << i << ":"; for (int j = 0; j < G[i].size(); ++j) { cout << G[i][j]<< ","; } cout << endl; } } void OutputAnswerBool(bool b,bool isUpperCase = false){ if(b){ if(isUpperCase){ cout << "YES" << endl; }else{ cout << "Yes" << endl; } }else{ if(isUpperCase){ cout << "NO" << endl; }else{ cout << "No" << endl; } } } int main() { string S; cin >> S; ll w; cin >> w; for (int i = 0; i < S.size(); i += w) { cout << S[i]; } cout << endl; }
#include <iostream> using namespace std; void call(int n); void judge1(int a); void judge2(int b); void judge3(int c); int main() { int input; cin>>input; call(input); return 0; } void call(int n) { int i; for (i = 1; i <= n; i++) { judge1(i); } cout << endl; } void judge1(int a) { if (a % 3 == 0) cout << " " << a; else judge2(a); } void judge2(int b) { if (b % 10 == 3) cout << " " << b; else judge3(b); } void judge3(int c) { int temp = 0; while (1) { if (temp == 0) temp = c; temp /= 10; if (temp) { if (temp % 10 == 3) { cout << " " << c; break; } } else break; } }
0
#include<bits/stdc++.h> using namespace std; int main() { int n,m; int sum = 0; cin >> n; m = n; for(int i = 0; n > 0; ++i){ sum += n%10; n /= 10; } if(m%sum==0) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1000000009; const ll LINF = 1e18; int cal_digit(ll n) { int rtn = 0; while (n) { ++rtn; n /= 10; } return rtn; } int main() { ll n; cin >> n; int rtn = INF; for (ll a = 1; a * a <= n; ++a) { if (n % a == 0) { ll b = n / a; int t_dig = max(cal_digit(a), cal_digit(b)); rtn = min(rtn, t_dig); } } cout << rtn << endl; }
0
#include <iostream> #include <stdio.h> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <iomanip> #include <queue> #include <deque> #include <map> #include <unordered_map> #define rep(i,n) for(int i=0;i<n;i++) #define repn(i,n) for(int i=1;i<=n;i++) #define repr(e,x) for(auto& e:x) using namespace std; typedef long long ll; map<string,int> m; int memo[99999]; int N; string s; void bs(int start,int end){ //cout<<"aaa1"<<endl; int v1,v2,vc; int c=(start+end)/2; //cout<<"aaa2"<<endl; if(memo[start]==-1){ cout<<start<<'\n'<<flush; cin>>s; if(m[s]==2){ return; } v1=memo[start]=m[s]; }else{ v1=memo[start]; } //cout<<"aaa3"<<endl; if(memo[end]==-1){ cout<<end<<'\n'<<flush; cin>>s; if(m[s]==2){ return; } v2=memo[end]=m[s]; }else{ v2=memo[end]; } //cout<<"aaa5"<<endl; if(memo[c]==-1){ cout<<c<<'\n'<<flush; cin>>s; if(m[s]==2){ return; } vc=memo[c]=m[s]; }else{ vc=memo[c]; } //cout<<"aaa6"<<endl; if((c-start)%2==1 && v1==vc){ bs(start,c); }else if((c-start)%2==0 && v1!=vc){ bs(start,c); }else if((end-c)%2==1 && v2==vc){ bs(c,end); }else if((end-c)%2==0 && v2!=vc){ bs(c,end); } } int main(){ m["Male"]=0; m["Female"]=1; m["Vacant"]=2; fill(memo,memo+99999,-1); cin>>N; bs(0,N-1); }
#include<bits/stdc++.h> //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); //clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl; using namespace std; typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui; typedef pair<int,int> pii; typedef pair<pii,int> ppii; typedef pair<int,pii> pipi; typedef pair<ll,ll> pll; typedef pair<pll,ll> ppll; typedef pair<ll,pll> plpl; typedef tuple<ll,ll,ll> tl; typedef pair<double,double> pdd; typedef vector<vector<ll>> mat; ll mod=1000000007; ll mod2=998244353; ll mod3=1000003; ll mod4=998244853; ll mod5=1000000009; ll inf=1LL<<60; double pi=3.141592653589793238462643383279L; double eps=1e-14; #define rep(i,m,n) for(ll i=m;i<n;i++) #define rrep(i,n,m) for(ll i=n;i>=m;i--) #define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++) #define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++) #define Max(a,b) a=max(a,b) #define Min(a,b) a=min(a,b) int dh[4]={1,-1,0,0}; int dw[4]={0,0,1,-1}; int ddh[8]={-1,-1,-1,0,0,1,1,1}; int ddw[8]={-1,0,1,-1,1,-1,0,1}; ll gcd(ll a,ll b){ if(a<b)swap(a,b); if(b==0)return a; if(a%b==0)return b; return gcd(b,a%b); } ll Pow(ll n,ll k){ ll ret=1; ll now=n; while(k>0){ if(k&1)ret*=now; now*=now; k/=2; } return ret; } ll beki(ll n,ll k,ll md){ ll ret=1; ll now=n; while(k>0){ if(k%2==1){ ret*=now; ret%=md; } now*=now; now%=md; k/=2; } return ret; } ll gyaku(ll n,ll md){ return beki(n,md-2,md); } ll popcount(ll n){ ll ret=0; ll u=n; while(u>0){ ret+=u%2; u/=2; } return ret; } int main(){ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n;cin>>n; cout<<0<<endl; string s;cin>>s; if(s=="Vacant")return 0; int r=n,l=0; while(r-l>1){ int mid=(l+r)/2; cout<<mid<<endl; string t;cin>>t; if(t[0]=='V')return 0; if(t==s){ if(mid%2==0)l=mid; else r=mid; } else{ if(mid%2==0)r=mid; else l=mid; } } }
1
#include <iostream> #include <stdio.h> #include <math.h> #include <string.h> #include <time.h> #include <stdlib.h> #include <string> #include <bitset> #include <vector> #include <set> #include <map> #include <queue> #include <algorithm> #include <sstream> #include <stack> #include <iomanip> #include <assert.h> using namespace std; #define pb push_back #define mp make_pair typedef pair<int,int> pii; typedef long long ll; typedef double ld; typedef vector<int> vi; #define fi first #define se second #define fe first #define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);} #define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);} #define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);} #define es(x,e) (int e=fst[x];e;e=nxt[e]) #define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e]) #define SZ 666666 int n,MOD; ll fac[SZ],rfac[SZ]; ll qp(ll a,ll b) { ll x=1; a%=MOD; while(b) { if(b&1) x=x*a%MOD; a=a*a%MOD; b>>=1; } return x; } ll rw[4]; ll C(int a,int b) { return fac[a]*rfac[a-b]%MOD*rfac[b]%MOD; } ll f[6005][2005*6]; int main() { cin>>n>>MOD; fac[0]=1; for(int i=1;i<SZ;++i) fac[i]=fac[i-1]*i%MOD; rfac[SZ-1]=qp(fac[SZ-1],MOD-2); for(int i=SZ-1;i;--i) rfac[i-1]=rfac[i]*i%MOD; int N=n*3; f[0][N]=1; for(int i=0;i<N;++i) for(int j=0;j<=N*2;++j) if(f[i][j]) for(int s=1;s<=3&&i+s<=N;++s) (f[i+s][j+(s==1)-(s==2)]+=f[i][j]*fac[i+s-1]%MOD*rfac[i])%=MOD; ll aa=0; for(int j=N;j<=N*2;++j) (aa+=f[N][j])%=MOD; aa=(aa%MOD+MOD)%MOD; cout<<aa<<"\n"; }
#include<bits/stdc++.h> using namespace std; template<typename T>inline T read(){ T f=0,x=0;char c=getchar(); while(!isdigit(c)) f=c=='-',c=getchar(); while(isdigit(c)) x=x*10+c-48,c=getchar(); return f?-x:x; } namespace run{ const int N=6009;int mod; inline int add(int x,int y){return x+y>=mod?x-mod+y:x+y;} int f[N][(N<<1)+3],n; int main(){ n=read<int>()*3,mod=read<int>(); f[0][N]=1; for(int i=0;i<n;i++) for(int j=-i;j<=i;j++){ f[i+1][j+1+N]=add(f[i+1][j+1+N],f[i][j+N]); f[i+2][j-1+N]=add(f[i+2][j-1+N],1LL*f[i][j+N]*(i+1)%mod); f[i+3][j+N]=add(f[i+3][j+N],1LL*f[i][j+N]*(i+1)%mod*(i+2)%mod); } int ans=0; for(int j=0;j<=n;j++) ans=add(ans,f[n][j+N]); printf("%d\n",ans); return 0; } } int main(){ #ifdef my freopen(".in","r",stdin); freopen(".out","w",stdout); #endif return run::main(); }
1
#include <bits/stdc++.h> using namespace std; #define ALL(x) (x).begin(),(x).end() #define COUT(x) cout<<(x)<<"\n" #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define REP(i, n) for(int i=0;i<n;i++) #define YES(x) cout<<(x?"YES":"NO")<<"\n" #define Yes(x) cout<<(x?"Yes":"No")<<"\n" #define dump(x) cout<<#x<<" = "<<(x)<<"\n" #define endl "\n" using G = vector<vector<int>>; using M = map<int,int>; using P = pair<int,int>; using PQ = priority_queue<int>; using PQG = priority_queue<int,vector<int>,greater<int>>; using V = vector<int>; using ll = long long; using edge = struct { int to; int cost; }; 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 = 1e9; const int MOD = 1e9+7; const ll LINF = 1e18; string s; int k, ans = INF; vector<int> l; void dfs(string t = "") { if (s.size() <= t.size()) { if (stoi(s) <= stoi(t)) chmin(ans, stoi(t)); if (s.size() < t.size()) return; } for (int v: l) dfs(t + (char)('0' + v)); } int main() { IOS; cin >> s >> k; M m; REP(i,k) { int d; cin >> d; m[d]++; } REP(i,10) if (m[i] == 0) l.push_back(i); dfs(); COUT(ans); return 0; }
#include <stdio.h> int main(void) { char line[80]; int l[10], v[2]; while (true) { if (fgets(line, sizeof line, stdin) == NULL) { break; } if (sscanf(line, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &(l[0]), &(l[1]), &(l[2]), &(l[3]), &(l[4]), &(l[5]), &(l[6]), &(l[7]), &(l[8]), &(l[9]), &(v[0]), &(v[1])) != 12) { break; } int total = 0; for (int k : l) { total += k; } double h = (double)(v[0]) / (v[0] + v[1]); double p = total * h; for (int i = 0; i < 10; i++) { p -= l[i]; if (p <= 0) { printf("%d\n", i+1); break; } } } return 0; }
0
#include <bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0) #define AfterDecimal(n) cout << fixed << setprecision(n); #define ll long long int #define ld long double #define all(a) a.begin(), a.end() #define pii pair<int, int> #define pll pair<ll, ll> #define bits(x) __builtin_popcount(x) using namespace __gnu_pbds; using namespace std; // #pragma GCC optimize("Ofast") // #pragma GCC target("avx,avx2,fma") // #pragma GCC optimization ("unroll-loops") //template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #ifdef LOCAL #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__) template<typename Arg1> void __f(const char* name, Arg1&& arg1){ cout << "# "<< name << " = " << arg1 << '\n'; } template<typename Arg1, typename... Args> void __f(const char* names, Arg1 && arg1, Args &&... args){ const char* comma = strchr(names + 1 ,','); cout << "# "; cout.write(names, comma - names)<< " = " << arg1 << " | "; __f(comma + 1, args...); } #else #define debug(...) 36 #endif std::mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int ri(int a, int b) { return uniform_int_distribution<int>(a, b)(rng); } ll power(ll x, ll y, ll p){ ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } const ll INF = (ll)(8e18); const ll MOD = (ll)(1e9 + 7); const ll HMOD = (ll)4222234727; const ll Hashprime = (ll)31; const int maxn = 100100; 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--){ string s; cin >> s; string temp[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; for(int i = 0; i < 14; i++){ if(temp[i] == s){ for(int j = i + 1; j < 14; j++){ if(temp[j] == "SUN"){ cout << j - i << '\n'; return 0; } } } } } #ifdef LOCAL cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif } //g++ -DLOCAL -std=c++17 -Wshadow -Wall -o "c" "comp.cpp" -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; int main() { int R; cin >> R; string S; if (R < 1200) S = "ABC"; else if (R < 2800) S = "ARC"; else S = "AGC"; cout << S << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; // ----------- define -------------- #define int long long #define vi vector<int> #define vc vector<char> #define ii pair<int,int> #define fi first #define sc second #define all(x) (x).begin(),(x).end() #define get_bit(x, k) ((x >> k) & 1) // --------------------------------- void MAIN() { string s; cin >> s; int ans = s.size(), cnt = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'S') cnt++; else { if (cnt) { ans -= 2; cnt--; } } } cout << ans << '\n'; } signed main() { ios::sync_with_stdio(0); cin.tie(0); int T = 1; // cin >> T; while (T--) MAIN(); }
#ifdef __GNUC__ #pragma GCC target("avx2") #pragma GCC optimize ("O30") #pragma GCC optimize ("tree-vectorize") #pragma GCC optimize("unroll-loops") #define iss std::cin #endif #include "bits/stdc++.h" #define rep(i, times) for(ll i = 0; i < (times); ++i) #define p(x) (cout << (x) << "\n") using ll = long long; using ld = long double; using namespace std; class Festival { ll N{0}; vector<vector<ll>> A; void inp( ) { iss >> N; A.resize(3, vector<ll>(N)); for (auto &abc : A) { for (auto &a : abc) iss >> a; } sort(begin(A[0]), end(A[0])); sort(begin(A[2]), end(A[2])); } void biSearch( ) { ll cnt{0}; for (auto &b : A[1]) { cnt += (end(A[2]) - upper_bound(begin(A[2]), end(A[2]), b)) * (lower_bound(begin(A[0]), end(A[0]), b) - begin(A[0])); } p(cnt); } public: void procedures( ) { inp( ); biSearch( ); } }; int main( ) { cin.tie(0); ios::sync_with_stdio(0); class Festival a; a.procedures( ); }
0
#include <iostream> #include <algorithm> #include <vector> #include <cstring> #include <cstdio> #include <map> #include <set> #define LL long long #define pb push_back #define mp make_pair #define INF 0x3f3f3f3f #define Inf 1000000000000000000LL #define F first #define S second using namespace std; typedef pair<int,int>pii; int main(){ int n,m; cin>>n>>m; map<int,int>mm; multiset<int>ss; for(int i=0;i<m;i++)mm[i]=i; for(int i=0;i<m;i++)ss.insert(0); for(int i=1,add=1;i<=n;i++){ int a,b,c,d; cin>>a>>b; c=-1; for(auto j=mm.lower_bound(--a);j!=mm.end()&&j->F<=b;mm.erase(j++)){ d=j->F; c=max(c,mm[d]); ss.erase(ss.find(d-mm[d])); } if(c+1&&b<m)mm[b]=c,ss.insert(b-c); if(ss.size())cout<<*ss.begin()+add<<endl,add++; else puts("-1"); } }
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5+2; int pre1[MAXN],pre2[MAXN]; int finds(int x,int *pre) { return pre[x] == x? pre[x]:pre[x] = finds(pre[x],pre); } void join(int x,int y,int *pre) { int px = finds(x,pre); int py = finds(y,pre); if( px!=py) { pre[px] = py; } } int main() { int n,k,l; cin>>n>>k>>l; for(int i = 1;i<=n;i++) pre1[i] = i,pre2[i] = i; for(int i = 1;i<=k;i++) { int x,y; cin>>x>>y; join(x,y,pre1); } for(int i = 1;i<=l;i++) { int x,y; cin>>x>>y; join(x,y,pre2); } for(int i = 1;i<=n;i++) { finds(i,pre1); finds(i,pre2); } map<pair<int,int>,int> mp; for(int i = 1;i<=n;i++) { mp[make_pair(pre1[i],pre2[i])] ++; } for(int i = 1;i<=n;i++) { cout<<mp[make_pair(pre1[i],pre2[i])]<<" "; } cout<<endl; }
0
#include <iostream> #include <algorithm> #include <iomanip> #include <string> #include <vector> #include <math.h> #include <queue> #include <deque> #include <stack> #include <set> #include <map> const int MOD = 1e9+7; const int MOOD = 998244353; #define PI 3.14159265359 typedef long long ll; using namespace std; int dp[200000][11]; int main(){ int d, g; cin >> d >> g; vector<int> p(d+1), c(d+1); g /= 100; for (int i = 0; i < 200000; i++){ for (int j = 0; j <= 10; j++){ dp[i][j] = MOD; } } for (int i = 1; i <= d; i++){ cin >> p[i] >> c[i]; c[i] /= 100; } dp[0][0] = 0; for (int i = 0; i <= g; i++){ for (int j = 1; j <= d; j++){ if (dp[i][j-1] != MOD){ for (int k = 0; k < p[j]; k++){ dp[i+j*k][j] = min(dp[i][j-1] + k, dp[i+j*k][j]); } dp[i+j*p[j]+c[j]][j] = min(dp[i][j-1] + p[j], dp[i+j*p[j]+c[j]][j]); } } } int ans = MOD; for (int i = g; i <= g+20000; i++){ for (int j = 1; j <= d; j++){ ans = min(ans, dp[i][j]); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, e) for(int (i) = 0; (i) < (e); ++(i)) #define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i)) #define ALL(c) (c).begin(), (c).end() #define PRINT(x) cout << (x) << "\n" using namespace std; using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>; const long long MOD = 1000000007; ll D, G, p[20], c[20]; ll solve(ll st){ ll sum = 0, cnt = 0; REP(i, D){ if(st & (1 << i)){ sum += p[i] * 100 * (i + 1) + c[i]; cnt += p[i]; } } while(sum < G){ for(int i = D - 1; i >= 0; i--){ if(st & (1 << i)) continue; ll d = (G - sum + 100 * (i + 1) - 1) / (100 * (i + 1)); if(d <= p[i]){ cnt += d; return cnt; } cnt += p[i]; sum += p[i] * 100 * (i + 1); } } return cnt; } signed main(){ cin >> D >> G; REP(i, D) cin >> p[i] >> c[i]; ll ans = INT64_MAX; REP(i, 1 << D){ ans = min(ans, solve(i)); } PRINT(ans); return 0; }
1
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int mxn= 5e5+5; #define mod 1000000007 #define endl '\n' void rishabh(){ ios_base::sync_with_stdio(false); cin.tie(NULL); } vector<array<ll,2>> adj[mxn]; bool vis[mxn]; ll ans=0,w,check; ll dfs(int i, ll temp, int j){ vis[i]=true; ll sum=0; for(auto x : adj[i]){ if(!vis[x[0]]){ if(temp+x[0]>=check*j){ while(x[1]>=check){ ans++; x[1]=x[1]/2; } } ll k=dfs(x[0],temp+x[1],j+1); sum=sum+k-x[1]; if(k>=check*j){ while(x[1]>=check){ ans++; x[1]=x[1]/2; } } sum=sum+x[1]; } } return sum; } int main(){ int n,m,q,u,v; cin>>n>>m>>q; map<int,int> a,b; u=v=INT_MAX; for(int i=1;i<=n;i++){ int c; cin>>c; u=min(u,c); a[i]=c; } for(int i=1;i<=m;i++){ int c; cin>>c; b[i]=c; v=min(c,v); } int ans=INT_MAX; while(q--){ int x,y,z; cin>>x>>y>>z; int temp=a[x]+b[y]-z; ans=min(ans,temp); } cout<<min(v+u,ans); }
#include <bits/stdc++.h> using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; bitset<13000> dp[85][85]; int A[85][85]; int B[85][85]; int main(){ int H, W; cin >> H >> W; int ret = 0; rep(i,H){ rep(j,W){ cin >> A[i][j]; ret += A[i][j]; } } rep(i,H){ rep(j,W){ cin >> B[i][j]; } } dp[0][0][abs(A[0][0]-B[0][0])+6500] = true; dp[0][0][abs(B[0][0]-A[0][0])+6500] = true; rep(i,H){ rep(j,W){ if(i+1<H){ dp[i+1][j] |= (dp[i][j] << abs(A[i+1][j]-B[i+1][j])); dp[i+1][j] |= (dp[i][j] >> abs(A[i+1][j]-B[i+1][j])); } if(j+1<W){ dp[i][j+1] |= (dp[i][j] << abs(A[i][j+1]-B[i][j+1])); dp[i][j+1] |= (dp[i][j] >> abs(A[i][j+1]-B[i][j+1])); } } } rep(i,13000){ if(dp[H-1][W-1][i]){ ret = min(ret, abs(i-6500)); } } cout << ret << endl; return 0; }
0
#include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int h1,m1,h2,m2,k; cin>>h1>>m1>>h2>>m2>>k; cout<<(h2*60+m2)-(h1*60+m1)-k<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; using usize = ::std::size_t; using u64 = ::std::int_least64_t; static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2; u64 N; vector<u64> a, parent, visited; void findpath(u64 i){ if (parent[i] != -1) { findpath(parent[i]); } visited[i] = 1; cout << a[i] << endl; } bool cmp(u64 a, u64 b){ return a >= b; } int main(int argc, char *argv[]) { cin.tie(0); ios::sync_with_stdio(false); cin >> N; vector<u64> M, indexer; a.resize(N), parent.resize(N, -1), visited.resize(N, 0); for (u64 i = 0; i < N; i++) { cin >> a[i]; } M.push_back(a[0]); indexer.push_back(0); for (auto it = a.begin() + 1; it != a.end(); it++) { if (*it <= M.back()) { M.push_back(*it); parent[it - a.begin()] = indexer.back(); indexer.push_back(it - a.begin()); } else { auto location = lower_bound(M.begin(), M.end(), *it, cmp); *location = *it; if (location != M.begin()) { parent[it - a.begin()] = indexer[location - M.begin() - 1]; } indexer[location - M.begin()] = it - a.begin(); } } cout << M.size() << endl; //findpath(indexer.back()); return 0; }
0
#include <bits/stdc++.h> using namespace std; bool dfs(int i, int nowcolor, vector<vector<int>> &way, vector<int> &color) { color.at(i) = nowcolor; for(int j = 0; j < way.at(i).size(); j++) { if(color.at(way.at(i).at(j)) == nowcolor) { return false; } else if(color.at(way.at(i).at(j)) == -1) { color.at(way.at(i).at(j)) = 1 - nowcolor; if(!dfs(way.at(i).at(j), 1 - nowcolor, way, color)) { return false; } } } return true; } int main() { int64_t N, M; cin >> N >> M; vector<vector<int>> way(N); for(int64_t i = 0; i < M; i++) { int a, b; cin >> a >> b; way.at(a - 1).push_back(b - 1); way.at(b - 1).push_back(a - 1); } vector<int> color(N, -1); if(!dfs(0, 0, way, color)) { cout << N * (N - 1) / 2 - M << endl; } else { int count = 0; for(int i = 0; i < N; i++) { if(color.at(i) == 1) { count++; } } cout << count * (N - count) - M << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int N,M; cin >> N >> M; int ans = -1; vector<int> s(M); vector<char> c(M); for (int i=0;i<M;i++) cin >> s[i] >> c[i]; for (int i = (N==1) ? 0 : pow(10, N-1);i<pow(10,N);i++){ string x = to_string(i); bool can = true; for (int j=0;j<M;j++){ if (x[s[j]-1]!=c[j]) can = false; } if (can) { ans = i; break; } } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; #define ll long long #define PII pair<ll,ll> #define VI vector<ll> #define VB vector<bool> #define VC vector<char> #define VVI vector<vector<ll>> #define VVC vector<vector<char>> #define VS vector<string> #define VP vector<PII> #define lf(i,a,b) for(ll i=a;i<=b;i++) #define lr(i,a,b) for(ll i=a;i>=b;i--) #define lfl(i,v) for(ll i=0;i<v.size();i++) #define lrl(i,v) for(ll i=(ll)(v.size())-1;i>=0;i--) #define chk2(a,b) cout<<"check : "<<a<<" "<<b<<endl #define chk3(a,b,c) cout<<"check : "<<a<<" "<<b<<" "<<c<<endl #define chk4(a,b,c,d) cout<<"check : "<<a<<" "<<b<<" "<<c<<" "<<d<<endl #define chk5(a,b,c,d,e) cout<<"check : "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl #define l_b(v,k) lower_bound(v.begin(),v.end(),k)-v.begin() #define u_b(v,k) upper_bound(v.begin(),v.end(),k)-v.begin() #define mod 1000000007 #define sort(v) sort(v.begin(),v.end()) #define p_b push_back #define p_f push_front #define m_p make_pair #define fir first #define sec second #define sz size() #define maxn 1<<17 ll n; ll dp[maxn]; ll dpsmm[maxn]; ll valor[maxn]; VVI sub(maxn); VVI mat; void calcula(){ for(int bitmask = 1;bitmask < (1 << n);bitmask++){ for(int i = 0;i<n;i++){ if(!(bitmask & (1 << i))) continue; for(int j = i+1;j<n;j++){ if(!(bitmask & (1 << j))) continue; valor[bitmask] += mat[i][j]; } } } } void fill_sub(ll ind,ll bm,ll subm) { if(ind==n) { if(__builtin_popcount(subm) == 0) return; sub[bm].p_b(subm);return ; } fill_sub(ind+1,bm,subm); fill_sub(ind+1,bm^(1<<ind),subm^(1<<ind)); fill_sub(ind+1,bm^(1<<ind),subm); } ll smm(ll bm) { VI v1; if(dpsmm[bm]!=-1) return dpsmm[bm]; lf(i,0,n-1) { if(bm&(1<<i)) { v1.p_b(i); } } ll len=v1.size(); ll sum=0; lfl(i,v1) lf(j,i+1,len-1) sum+=mat[v1[i]][v1[j]]; return dpsmm[bm]=sum; } ll fun(ll bm) { if(bm==0) { return 0; } if(dp[bm]!=-1) return dp[bm]; //cout<<bm<<endl; ll maxi=0; lfl(i,sub[bm]) { maxi=max(maxi,valor[sub[bm][i]]+fun(bm^sub[bm][i])); } return dp[bm]=maxi; } int main() { cin>>n; mat=VVI(n,VI(n,0)); lf(i,0,n-1) lf(j,0,n-1) cin>>mat[i][j]; memset(dp,-1,sizeof(dp)); memset(dpsmm,-1,sizeof(dpsmm)); fill_sub(0,0,0); calcula(); cout<<fun((1<<n)-1); }
//thuanqvbn03 #include <bits/stdc++.h> using namespace std; int n; int a[16][16]; long long dp[1 << 16]; int GetBit(int num, int pos) { return (num >> pos) & 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } } int m = (1 << n) - 1; for (int i = 1; i <= m; i++) { dp[i] = 0; for (int j = 0; j < n; j++) { if (GetBit(i, j)) { for (int k = j + 1; k < n; k++) { if (GetBit(i, k)) { dp[i] += a[j][k]; } } } } int t = m / 2; for (int j = 1; j <= t; j = ((i & j) == j ? j + 1 : j + (j & -j))) { if ((i & j) == j) { dp[i] = max(dp[i], dp[j] + dp[i ^ j]); } } } cout << dp[m]; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int N,M; cin >> N >> M; if (M == 1){ cout << 1 << ' ' << 2 << endl; return 0; } if (N % 2 == 1){ for (int i = 0; i < M; i++) { cout << i+1 << ' ' << M*2 - i << endl; } } else { for (int i = 0; i < (M+1)/2; i++) { cout << i+1 << ' ' << N/2 - i << endl; } for (int i = 0; i < M/2; i++) { cout << N/2 + i + 2 << ' ' << N - i << endl; } } }
#include <bits/stdc++.h> typedef long long ll; using namespace std; ll MOD = 1000000007; #define vec vector<int> #define vecll vector<ll> #define vecd vector<double> #define vecst vector<string> #define vecb vector<bool> #define vec2(var, n, m) vector<vector<int>> var(n, vector<int>(m, 0)) #define vecb2(var, n, m) vector<vector<bool>> var(n, vector<bool>(m, false)) #define vecll2(var, n, m) vector<vector<ll>> var(n, vector<ll>(m, 0)) #define rep(i,n) for(ll i=(ll)0; i<(ll)n; i++) #define REP(i,m,n) for(ll i=(ll)m; i<(ll)n; i++) #define arr(var, n) vec var(n); rep(i,n){cin >> var[i];} #define arrll(var, n) vecll var(n); rep(i,n){cin >> var[i];} #define arrst(var, n) vecst var(n); rep(i,n){cin >> var[i];} #define all(var) (var).begin(), (var).end() #define sortall(var) sort(all(var)) #define uniqueall(v) v.erase(unique(v.begin(), v.end()), v.end()); #define f_sum(var) accumulate(all(var), 0) #define f_sumll(var) accumulate(all(var), 0LL) #define chmin(v1, v2) v1 = min(v1, v2) #define chmax(v1, v2) v1 = max(v1, v2) #define pb(var) push_back(var) #define prt(var) cout << (var) << "\n" #define prtd(n, var) cout << fixed << setprecision(n) << (var) << "\n" #define prtfill(n, var) cout << setw(n) << setfill('0') << (var); #define prt2(v1, v2) cout << (v1) << " " << (v2) << "\n" #define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n" #define prtall(v) rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");} void prtok(bool ok){prt(ok ? "Yes" : "No");} //---------------------------------------------------------------- vector<int> make_divisors(ll x){ vector<int> v; for(ll i=1; i*i<=x; i++){ if(x%i==0){ v.push_back(i); if(i!=x/i) v.push_back(x/i); } } sort(v.begin(), v.end()); return v; } int main(void) { int n, m; cin >> n >> m; vec v = make_divisors(m); rep(i,v.size()){ if(m/v[v.size()-1-i]>=n){ prt(v[v.size()-1-i]); return 0; } } }
0
#include <bits/stdc++.h> #include <iomanip> #include <math.h> #include <unistd.h> //#include <stdio.h> #define rep(i,x) for(ll i = 0;i<x;i++) #define all(a) (a).begin(),(a).end() using ll = long long; using ld = long double; using namespace std; using dou = double; const ll INF = 1LL << 60; const ll mod = 1000000007; typedef pair<ll,ll> P; using graph = vector<vector<ll>>; 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;} ll gcd(ll a,ll b){ if(a < b)swap(a,b); if(a % b == 0)return b; else return gcd(b,a%b); } //素数判定O(sqrt(N)) bool isp(ll n){ bool res = true; if(n == 1)return false; else{ for(ll i = 2;i * i <= n;i++){ if(n % i == 0){ res = false; break; } } return res; } } ll fac[510000], finv[510000], inv[510000]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < 510000; i++){ fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod%i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } // 二項係数計算 ll COM(ll n, ll k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } //nのm乗をMODで割ったあまりO(logN) ll modpow(ll n,ll m,ll MOD){ ll res = 1; while(m){ if(m & 1)res = (res * n) % MOD; m >>= 1; n *= n; n %= MOD; } return res; } //printf("%.10f\n", N); /* vector<ll> vec = {1,2,5,6,8,9,10}; cout << binary_search(all(vec),5) << endl; -> true*/ /* vector<ll> vec = {1,2,5,6,8,9,10}; auto n = upper_bound(all(vec),4); cout << *n << endl; -> 5*/ /* cout << fixed << setprecision(15); */ int main(){ ll N; cin >> N; vector<ll>num(N); rep(i,N)cin >> num[i]; map<ll,ll> odd,even; rep(i,N){ if(i % 2 == 0)odd[num[i]]++; else even[num[i]]++; } vector<P> od,ev; for(auto x : odd){ od.push_back(P(x.second,x.first)); } for(auto x : even){ ev.push_back(P(x.second,x.first)); } sort(all(od));sort(all(ev));reverse(all(od));reverse(all(ev)); ll os = od.size(),es = ev.size(); if(od[0].second != ev[0].second){ cout << N - ev[0].first - od[0].first << endl; } else{ if(os == 1 && es == 1){ cout << N - max(od[0].first,ev[0].first) << endl; } else if(es == 1){ cout << N - ev[0].first - od[1].first << endl; } else if(os == 1){ cout << N - ev[1].first - od[0].first << endl; } else{ cout << N - max(od[0].first + ev[1].first,od[1].first + ev[0].first) << endl; } } }
// #include<bits/stdc++.h> // using namespace std; // #define ll long long int // #define maxn 100005 // int main(){ // ios::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); // ll t=1; // //cin>>t; // while(t--){ // int n; // cin>>n; // double d; // ll x; // int num2,num5; // map<pair<int,int>,int> num; // for(int i=0;i<n;i++){ // cin>>d; // x=llround(d*1e9); // //cout<<x<<"\n"; // num2=0,num5=0; // while(x%2==0) num2++,x/=2; // //cout<<x<<"\n"; // while(x%5==0) num5++,x/=5; // num[{num2,num5}]++; // } // int ans=0; // for(auto p1:num){ // for(auto p2:num){ // if(p1.first.first+p2.first.first>=18 && p1.first.second+p2.first.second>=18){ // if(p1<p2) ans+= p1.second*p2.second; // if(p1==p2)ans+=(p1.second*(p2.second-1))/2; // } // } // } // cout<<ans<<"\n"; // } // } #include<bits/stdc++.h> using namespace std; #define ll long long int #define maxn 100005 int num[19][19]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll t=1; //cin>>t; while(t--){ ll n; cin>>n; double d; ll x,y=1000000000; int num2,num5; for(int i=0;i<=18;i++) for(int j=0;j<=18;j++) num[i][j]=0; vector<pair<int,int>> vec; for(int i=0;i<n;i++){ cin>>d; x=llround(d*1e9); //cout<<x<<"\n"; num2=0,num5=0; while(x%2==0) num2++,x/=2; //cout<<x<<"\n"; while(x%5==0) num5++,x/=5; if(num2>18) num2=18; if(num5>18) num5=18; vec.push_back({num2,num5}); //cout<<num2<<" "<<num5<<"\n"; for(int j=0;j<=18;j++){ for(int k=0;k<=18;k++){ if(18-num2<=j && 18-num5<=k) num[j][k]++; } } } ll ans=0; for(int i=0;i<n;i++){ num2=vec[i].first; num5=vec[i].second; for(int j=0;j<=18;j++){ for(int k=0;k<=18;k++){ if(18-num2<=j && 18-num5<=k) num[j][k]--; } } ans+=num[num2][num5]; } cout<<ans<<"\n"; } }
0
#include <bits/stdc++.h> using namespace std; int main() { long long i,j,k,a,b,c=0,n,t; cin>>n; long long A[n]; for(i=0;i<n;i++) cin>>A[i]; sort(A,A+n); for(i=0;i+2<n;i++) { for(j=i+1;j+1<n;j++) { for(k=j+1;k<n;k++) { if(A[i]!=A[j]&&A[j]!=A[k]&&A[k]!=A[i]&&A[i]+A[j]>A[k]) c++; } } } cout<<c<<endl; return 0; }
//#include"bits/stdc++.h" #include<iostream> #include<ostream> #include<vector> #include<string> #include<algorithm> #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++) #define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) RFOR(i,0,n) #define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME #define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__) #define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__) using namespace std; using ll = long long; void solve(); int main() { solve(); return 0; } void solve() { ll n; cin >> n; REP(i, n) { ll score=0; ll runner=0; ll out=0; string in; while (out < 3) { cin >> in; if (in == "OUT") { out++; } else if (in == "HIT") { runner++; if (runner == 4) { score++; runner = 3; } } else if (in == "HOMERUN") { score += (runner + 1); runner = 0; } } cout << score << endl; } }
0
#include <bits/stdc++.h> using namespace std; int main() { long N; cin>>N; vector<vector<long>> a(100005,vector<long>(2)); vector<vector<long>> b(100005,vector<long>(2)); long al=0,bl=0; for(int i=0;i<N;i++){ long v; cin>>v; if(i%2==0) a[v][0]++,al++; else b[v][0]++,bl++; } for(int i=0;i<100005;i++) a[i][1]=i,b[i][1]=i; sort(a.begin(),a.end()); sort(b.begin(),b.end()); reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); long ans1=1234567890; long x=a[0][0]; long y=b[0][0]; if(a[0][1]!=b[0][1]){ ans1=(al-x)+(bl-y); } long ans2=1234567890; x=a[1][0]; y=b[0][0]; if(a[1][1]!=b[0][1]){ ans2=(al-x)+(bl-y); } long ans3=1234567890; x=a[0][0]; y=b[1][0]; if(a[0][1]!=b[1][1]){ ans3=(al-x)+(bl-y); } cout<<min(min(ans1,ans2),ans3)<<endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long int main(){ ll n; cin >> n; vector<ll> a(n),ev(100001),od(100001); rep(i,n){ cin >> a.at(i); if(i%2==0){ od.at(a.at(i))++; }else{ ev.at(a.at(i))++; } } ll maxiev=0,maxiod=0,soeev,soeod; rep(i,100001){ if(maxiev<ev.at(i)){ maxiev=ev.at(i); soeev=i; } if(maxiod<od.at(i)){ maxiod=od.at(i); soeod=i; } } if(soeev!=soeod){ cout << n/2-maxiev+n/2-maxiod; }else{ if(maxiev<maxiod){ ll q=0; rep(i,100001){ if(soeev!=i && q<ev.at(i)){ q=ev.at(i); } } cout << n/2-maxiod+n/2-q; }else if(maxiev>maxiod){ ll q=0; rep(i,100001){ if(soeod!=i && q<od.at(i)){ q=od.at(i); } } cout << n/2-maxiev+n/2-q; }else{ ll p=0,q=0; rep(i,100001){ if(soeev!=i && q<ev.at(i)){ q=ev.at(i); } } rep(i,100001){ if(soeod!=i && p<od.at(i)){ p=od.at(i); } } ll ans=max(p,q); cout <<n/2-ans+n/2-maxiod; } } }
1
#include <iostream> #include <vector> using namespace std; int main() { int n; while (cin >> n, n){ long long e[5000] = {0}, p, q, t; bool out = false, f = false; vector<int> s; for (int i = 0; i < n; i++){ cin >> t >> p >> q; for (int j = 0; j < s.size(); j++){ if (s[j] == t){ f = true; break; } } if (f == false){ s.push_back(t); } e[t] += p * q; } for (int i = 0; i < s.size(); i++){ if (e[s[i]] >= 1000000){ cout << s[i] << endl; out = true; } } if (out == false) cout << "NA" << endl; } return (0); }
#include <iostream> #include <string> #define REP(i,k,n) for(int i=k;i<n;i++) #define rep(i,n) for(int i=0;i<n;i++) using namespace std; string s[12]; int dx[4] = {1,0,-1,0}; int dy[4] = {0,1,0,-1}; void dfs(int x,int y) { s[x][y] = '0'; rep(i,4) { int nx = x + dx[i]; int ny = y + dy[i]; if(0 <= nx && nx < 12 && 0 <= ny && ny < 12) { if(s[nx][ny] == '1') { dfs(nx,ny); } } } return; } int main() { while(cin >> s[0]) { REP(i,1,12) { cin >> s[i]; } int res = 0; rep(i,12) { rep(j,12) { if(s[i][j] == '1') { dfs(i,j); res++; } } } cout << res << endl; } return 0; }
0
#include <iostream> #include <stdio.h> #include <math.h> #include <string> using namespace std; int main() { double x1, y1, x2, y2, num, ans = 0, dou = 1, xx; cin >> x1 >> y1 >> x2 >> y2; num = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1); while (dou < num) { dou *= 10; } xx = dou; for (int i = 0; i < 100; i++) { for (int j = 0; j < i; j++) { dou *= 0.1; } if (dou < 0.000001)break; for (int j = 0; j < 10; j++) { ans += dou; //cout << ans << " " << j << " " << dou << endl; if (ans*ans > num) { ans -= dou; break; } } dou = xx; } printf("%f\n", ans); //cout << ans; return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; int main() { double x1, y1, x2, y2; scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2); printf("%lf", sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2))); }
1
#include <iostream> using namespace std; int f[102][102]; bool dfs(int ys,int xs,int yg,int xg,int c){ if(f[ys][xs]!=c)return 0; if(ys==yg && xs==xg)return 1;; f[ys][xs]=0; bool flag=0; flag += dfs(ys+1,xs,yg,xg,c); flag += dfs(ys-1,xs,yg,xg,c); flag += dfs(ys,xs+1,yg,xg,c); flag += dfs(ys,xs-1,yg,xg,c); return flag; } void set(int c,bool d,int x,int y){ if(d==0){ for(int i=0; i<4; i++){ f[y][x+i]=c; f[y+1][x+i]=c; } }else if(d==1){ for(int i=0; i<4; i++){ f[y+i][x]=c; f[y+i][x+1]=c; } } } ; int main(){ while(1){ int w,h; cin >> w >> h; if(w==0 && h==0)break; int xs,ys; cin >> xs >> ys; int xg,yg; cin >> xg >> yg; int n; cin >> n; for(int i=0; i<n; i++){ bool d; int c,x,y; cin >> c >> d >> x >> y; set(c,d,x,y); } if(dfs(ys,xs,yg,xg,f[ys][xs])){ cout << "OK\n"; }else{ cout << "NG\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, s, n) for(int i = s; i < (int)n; i++) #define per(i, n) for(int i = n; i >= 0; i--) #define ROF(i, s, n) for(int i = s; i >= (int)n; i--) #define FORIT(i, A) for (auto i : A) #define PRINT(x) cout << (x) << "\n" #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define MP make_pair #define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i) #define SZ(a) int((a).size()) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) #define CLR(a) memset((a), 0 ,sizeof(a)) #define NCLR(a) memset((a), -1 ,sizeof(a)) #define dump(x) cout << #x << " = " << (x) << "\n"; #define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n"; #define sq(n) (n) * (n) typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef unsigned int uint; typedef unsigned long long ull; typedef priority_queue<int> maxpq; typedef priority_queue< int, vector<int>, greater<int> > minpq; typedef complex<double> P; static const double EPS = 1e-10; static const double PI = acos( -1.0 ); static const int mod = 1000000007; static const int INF = 1 << 29; static const LL LL_INF = 1152921504606846976; static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 }; static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 }; int n, m; int cl[ 100 ][ 100 ]; int main() { queue<PII> q; set<PII> s; while ( ~scanf("%d %d", &n, &m) && n && m ) { CLR( cl ); bool can = false; int sx, sy, gx, gy; scanf( "%d %d", &sx, &sy ); --sx; --sy; scanf( "%d %d", &gx, &gy ); --gx; --gy; int k; scanf( "%d", &k ); for ( int i = 0; i < k; i++ ) { int c, d, x, y; scanf( "%d %d %d %d", &c, &d, &x, &y ); --x; --y; if ( d ) { for ( int i = 0; i < 4; i++ ) { for ( int j = 0; j < 2; j++ ) { cl[ y + i ][ x + j ] = c; } } } else { for ( int i = 0; i < 2; i++ ) { for ( int j = 0; j < 4; j++ ) { cl[ y + i ][ x + j ] = c; } } } } q.push( MP( sx, sy ) ); while ( q.size() ) { int x = q.front().first; int y = q.front().second; q.pop(); if ( s.count( MP( x, y ) ) ) { continue; } s.insert( MP( x, y ) ); if ( x == gx && y == gy ) { can = true; break; } for ( int i = 0; i < 4; i++ ) { if ( x + dx[ i ] < 0 || x + dx[ i ] == n || y + dy[ i ] < 0 || y + dy[ i ] == m || cl[ y ][ x ] != cl[ y + dy[ i ] ][ x + dx[ i ] ] ) { continue; } q.push( MP( x + dx[ i ], y + dy[ i ] ) ); } } printf( "%s\n", can ? "OK" : "NG" ); while ( q.size() ) { q.pop(); } s.clear(); } return 0; }
1
#include <bits/stdc++.h> using namespace std; /* typedef */ typedef long long ll; typedef pair<int, int> pii; /* constant */ const int INF = 1 << 30; const ll LINF = 1LL << 50; const int NIL = -1; const int MAX = 10000; const int mod = 1000000007; const double pi = 3.141592653589; /* global variables */ /* function */ /* main */ int main(){ int a, b, c; cin >> a >> b >> c; if (a > b) swap(a, b); if (a < c && c < b) cout << "Yes" << '\n'; else cout << "No" << '\n'; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define int long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i, n) for (int i = 0; i < n; ++i) #define REP(i, n) for (int i = 0; i < n; ++i) #define range(i,a,b) ((a)<=(i) && (i)<(b)) #define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl; #define fs first #define sc second #define pb push_back typedef long long ll; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> T; typedef priority_queue<ll> PQI; typedef priority_queue<P> PQP; typedef vector<vector<P>> pvec; typedef vector<vector<ll>> vvec; typedef vector<ll> vec; const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1}; const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1}; const int MOD = (1000000007); // const int MOD = (998244353); // const int INF = (1 << 30); const int INF = (1LL << 60); const double EPS = (1 >> 30); template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;} template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;} signed main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); //--------------------------------------------- int a,b,k; cin>>a>>b>>k; rep(i,k){ if(i%2==0){ if(a%2==1){ a--; } a/=2; b+=a; } else{ if(b%2==1){ b--; } b/=2; a+=b; } } cout<<a<<" "<<b<<endl; }
0
#include<cstdio> #include<algorithm> using namespace std; const int N=1001000; int ii,i,j,k,l,n,m,ch,Last,ans; char s[N],t[N],f[N]; struct cc { int x,l,r;} A[N]; int main() { scanf("%d",&n); scanf("%s",s+1); scanf("%s",t+1); for (i=1;i<=n;i++) if (s[i]!=t[i]) break; if (i>n) return puts("0"),0; Last=n; for (i=n;i;i--) { j=i; while (j && t[j-1]==t[i]) j--; k=min(j,Last); while (k && s[k]!=t[j]) k--; if (!k) return puts("-1"),0; A[k].x=k; A[k].l=j;A[k].r=i; Last=k-1; i=j; } for (i=1;i<=n;i++) if (A[i].x) A[++m]=A[i]; ans=1;f[m]=1;j=m+1; for (i=m-1;i;i--) { while (j>i && A[j-1].x-(j-1-i)>=A[i].r) j--; if (j-i>ans) ans=j-i; } printf("%d\n",ans); }
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<int> a(n); bool f_zero = false; int num_m = 0; long long s = 0; int m = 1e9; for(int i=0; i<n; i++){ cin >> a[i]; if(a[i]==0) f_zero = true; if(a[i]<0) num_m++; s += abs(a[i]); m = min(m,abs(a[i])); } if(f_zero || num_m%2==0) cout << s << endl; else cout << s-2*m << endl; }
0
#include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> using namespace std; struct Info{ int number; }; void strcpy(char* to,char* str){ for(int i=0;str[i] != '\0';i++){ to[i] = str[i]; to[i+1] = '\0'; } } //base??¨comp??????????????????????????¢??° bool strCmp(char* base, char* comp){ int length1 = 0,length2 = 0; for(int i=0;base[i] != '\0'; i++)length1++; for(int i=0;comp[i] != '\0'; i++)length2++; if(length1 != length2)return false; for(int i=0;base[i] != '\0'; i++){ if(base[i] != comp[i])return false; } return true; } void func(int n,int k){ Info info[5041]; int index = 0,cards[10],tmp; for(int i = 0; i < n; i++)scanf("%d",&cards[i]); //k????????????????????¶?????° if(k == 2){ for(int i = 0; i < n; i++){ for(int k = 0; k < n; k++){ if(i != k){ //???????????°?????????????????? if(cards[k] >= 10){ tmp = 100*cards[i] + cards[k]; }else{ tmp = 10*cards[i] + cards[k]; } if(index == 0){ info[0].number = tmp; index++; }else{ //??¢??????????????????????????°??¨????????????????????? bool Found = false; for(int p = 0; p < index; p++){ if(info[p].number == tmp){ Found = true; break; } } if(!Found){ //?????¨???????????´??????????????? info[index].number = tmp; index++; } } } } } printf("%d\n",index); }else if(k == 3){ for(int i = 0; i < n; i++){ for(int k = 0; k < n; k++){ for(int a = 0; a < n; a++){ if(i != k && i != a && k != a){ //???????????°?????????????????? if(cards[a] >= 10){ tmp = 100*cards[k] + cards[a]; }else{ tmp = 10*cards[k] + cards[a]; } if(tmp <= 99){ //2??? tmp += 100*cards[i]; }else if(tmp <= 999){ //3??? tmp += 1000*cards[i]; }else{ //4??? tmp += 10000*cards[i]; } if(index == 0){ info[0].number = tmp; index++; }else{ //??¢??????????????????????????°??¨????????????????????? bool Found = false; for(int p = 0; p < index; p++){ if(info[p].number == tmp){ Found = true; break; } } if(!Found){ //?????¨???????????´??????????????? info[index].number = tmp; index++; } } } } } } printf("%d\n",index); }else{ //k == 4 for(int i = 0; i < n; i++){ for(int k = 0; k < n; k++){ for(int a = 0; a < n; a++){ for(int b = 0; b < n; b++){ if(i != k && i != a && i != b && k != a && k != b && a != b){ //???????????°?????????????????? if(cards[b] >= 10){ tmp = 100*cards[a] + cards[b]; }else{ tmp = 10*cards[a] + cards[b]; } if(tmp <= 99){ //2??? tmp += 100*cards[k]; }else if(tmp <= 999){ //3??? tmp += 1000*cards[k]; }else{ //4??? tmp += 10000*cards[k]; } if(tmp <= 999){ //3??? tmp += 1000*cards[i]; }else if(tmp <= 9999){ //4??? tmp += 10000*cards[i]; }else if(tmp <= 99999){ //5??? tmp += 100000*cards[i]; }else{ //6??? tmp += 1000000*cards[i]; } if(index == 0){ info[0].number = tmp; index++; }else{ //??¢??????????????????????????°??¨????????????????????? bool Found = false; for(int p = 0; p < index; p++){ if(info[p].number == tmp){ Found = true; break; } } if(!Found){ //?????¨???????????´??????????????? info[index].number = tmp; index++; } } } } } } } printf("%d\n",index); } } int main(){ int n,k; while(true){ scanf("%d %d",&n,&k); if(n == 0 && k == 0)break; func(n,k); } return 0; }
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<cassert> #include<iostream> #include<sstream> #include<string> #include<vector> #include<queue> #include<set> #include<map> #include<utility> #include<numeric> #include<algorithm> #include<bitset> #include<complex> using namespace std; typedef long long Int; typedef vector<int> vint; typedef pair<int,int> pint; #define mp make_pair template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template<class T> void chmin(T &t, T f) { if (t > f) t = f; } template<class T> void chmax(T &t, T f) { if (t < f) t = f; } int in() { int x; scanf("%d", &x); return x; } int cards[10]; set<int> nums; int n; void f(int m,int k,int used){ if(k==0){ nums.insert(m); return; } int i; for(i=0;i<n;i++){ if(used&1<<i)continue; f(m*(cards[i]<10?10:100)+cards[i],k-1,used|1<<i); } } int main() { int k; while(n=in(),k=in()){ nums.clear(); int i; for(i=0;i<n;i++){ cards[i]=in(); } f(0,k,0); cout<<nums.size()<<endl; } return 0; }
1
#include<iostream> #include<vector> #include<string> #include<algorithm> using namespace std; class crop{ public: string name; int price,seeding,youngL,L,flower, fruit,numFruit,fruitPrice,times; int StoL,LtoFruit,totaltime; double sum; crop(); crop(string name,int price,int seeding,int youngL, int L,int flower,int fruit, int numFruit,int fruitPrice, int times):name(name),price(price), seeding(seeding),youngL(youngL),L(L), flower(flower),fruit(fruit),numFruit(numFruit), fruitPrice(fruitPrice),times(times){ this->StoL= seeding + youngL + L; this->LtoFruit = flower + fruit; this->totaltime=StoL + LtoFruit * times; this->sum = ((times * numFruit * fruitPrice) - price) / (double)totaltime; } ~crop(){} bool operator<(const crop &a)const{ if(this->sum != a.sum){ return this->sum > a.sum; }else{ return this->name < a.name; } } }; void printCrop(crop &a){ cout << "name:" << a.name << endl; cout << "price:" << a.price << " sum:" << a.sum << " totaltime:"<< a.totaltime<< endl; } int main(){ int n; while(cin>>n,n){ vector<crop> C; for(int i=0;i<n;i++){ string l; int p,a,b,c,d,e,f,s,m; cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m; C.push_back(crop(l,p,a,b,c,d,e,f,s,m)); } sort(C.begin(), C.end()); for(int i=0;i<n;i++){ //printCrop(C[i]); cout << C[i].name << endl; } cout << "#" << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n; cin >> n; int k[100]; char s[101]; while (n != 0) { for (int i = 0; i < n; i++) cin >> k[i]; cin >> s; int j = 0; for (int i = 0; s[i] != '\0'; i++) { if (s[i] >= 'a') s[i] -= 6; s[i] -= k[j]; if (s[i] < 'A') s[i] += 52; j++; if (j == n) j = 0; } for (int i = 0; s[i] != '\0'; i++) { if (s[i] > 'Z') s[i] += 6; } cout << s << endl; cin >> n; } return 0; }
0
#include <bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define input_output freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #define ll long long #define read1(x) cin>>x #define read2(x,y) cin>>x>>y #define print(x) cout<<x<<endl #define pii pair<int, int> #define pli pair<ll, int> #define pil pair<int, ll> #define pll pair<ll, ll> #define vi vector<int> #define vll vector<ll> #define vb vector<bool> #define vd vector<double> #define vs vector<string> #define ff first #define ss second #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define vpii vector<pii> #define umap unordered_map #define uset unordered_set #define clr(a,b) memset(a,b,sizeof a) #define all(ds) ds.begin(), ds.end() #define rev(ds) ds.rbegin(), ds.rend() #define asc(A) sort(A.begin(), A.end()) #define dsc(A) sort(A.begin(), A.end(), greater<int>()) #define gcd(x,y) __gcd(x,y) #define clr(a,b) memset(a,b,sizeof a) #define fr(i, n) for(int i=0; i<n;++i) #define fr1(i, n) for(int i=1; i<=n; ++i) #define rfr(i, n) for(int i=n-1; i>=0; --i) #define printVector(v) for(int i= 0;i<v.size();i++) {cout<<v[i]<<" ";} cout<<endl; #define precise(x) cout<<fixed<<setprecision(x) #define inf 10000000000000 ll lcm(ll a, ll b) {return (a*b)/__gcd(a, b); } ll power(ll x, ll y, ll m) { if(!y) return 1; ll p=power(x, y>>1, m)%m; p=p*p%m; return (y&1)?(x*p)%m:p;} ll modInverse(ll a, ll m){ return power(a, m-2, m); } bool isPrime(ll num){bool flag=true;for(ll i =2;i<=num/2;i++){if(num%i==0) {flag=false; break;} }return flag;} ll sumofdigits(ll n){ll c=0;while(n>0){c++;n/=10;}return c;} bool sortinrev(const pair<int,int>&a,const pair<int,int>&b) {return a.first > b.first; } bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) {return a.second < b.second; } //const double PI= 2*acos(0.0); const long long MOD= 1000000007; void solve(){ int n; cin>>n; vi v; fr(i, n){ int x; cin>>x; v.push_back(x); } sort(all(v)); if(v.size() <= 2){ print(0); return; } int count = 0; for(int i = 0; i < n-2; ++i){ for(int j = i+1; j < n-1; ++j){ if(v[i] == v[j])continue; for(int k = j+1; k < n; ++k){ if(v[i] == v[k] || v[j] == v[k])continue; if(v[i] + v[j] > v[k])count++; } } } cout<<count<<endl; } int main() { #ifndef ONLINE_JUDGE input_output #else fastio #endif int t =1 ; // cin>>t; while(t--){ solve(); } return 0; }
#include "bits/stdc++.h" using namespace std; #ifndef LOCAL #define endl '\n' #endif #define fr(i, a, b) for(int i = a; i <= b; i++) #define rf(i, a, b) for(int i = a; i >= b; i--) #define pf push_front #define pb push_back #define eb emplace_back #define fi first #define se second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)x.size() #define lb lower_bound #define ub upper_bound typedef long long ll; typedef long double f80; typedef pair<int,int> pii; typedef pair<ll,ll> pll; int pct(int x) { return __builtin_popcount(x); } int pct(ll x) { return __builtin_popcountll(x); } int bt(int x) { return 31 - __builtin_clz(x); } // floor(log2(x)) int bt(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x)) int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); } ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); } int nxt_C(int x) { int c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; } ll nxt_C(ll x) { ll c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; } vector<int> get_bits(int mask) { vector<int> bb; while(mask) { int b = bt(mask); bb.pb(b); mask ^= (1 << b); } reverse(all(bb)); return bb; } int get_mask(vector<int> v) { int mask = 0; for(int x : v) { mask ^= (1 << x); } return mask; } template<typename T> void uniq(vector<T> &v) { sort(all(v)); v.resize(unique(all(v)) - v.begin()); } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r){ uniform_int_distribution<ll> uid(l, r); return uid(rng); } void sc() {} template <typename Head, typename... Tail> void sc(Head &H, Tail &... T) { cin >> H; sc(T...); } #ifdef LOCAL #define debug(...) cerr << "[L:" << __LINE__ << "][" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif // #ifndef LOCAL // string to_string(__int128 x) { // string s = ""; // bool neg = 0; // if(x < 0) { s += "-"; neg = 1; x = -x; } // if(!x) s += '0'; // while(x) { // int rem = x % 10; // s += to_string(rem); // x /= 10; // } // reverse(s.begin() + neg, s.end()); // return s; // } // #endif const int mod = 1e9 + 7; // 998244353; int pwr(int a,ll b) { int ans = 1; while(b) { if(b & 1) ans = (ans * 1LL * a) % mod; a = (a * 1LL * a) % mod; b >>= 1; } return ans; } /* Lookout for overflows!! Check array sizes!! Clear before test cases!! Use the correct modulo!! Check for corner cases!! Are you forgetting something?! Read problem statement carefully!!! */ const int N = 1e5 + 5; int dsu[N], sz[N]; bool odd[N], par[N]; int root(int u) { while(u != dsu[u]) u = dsu[u]; return u; } int get_par(int u) { int p = 0; while(u != dsu[u]) { p ^= par[u]; u = dsu[u]; } return p; } void uni(int u,int v) { int uu = root(u), vv = root(v); if(uu == vv) { if(get_par(u) == get_par(v)) odd[uu] = 1; return; } if(sz[uu] > sz[vv]) { swap(uu, vv), swap(u, v); } dsu[uu] = vv; sz[vv] += sz[uu]; odd[vv] |= odd[uu]; par[uu] = get_par(u) ^ get_par(v) ^ 1; } void solve() { int n, m; sc(n, m); fr(i, 1, n) { sz[i] = 1; dsu[i] = i; odd[i] = 0; par[i] = 0; } fr(i, 1, m) { int u, v; sc(u, v); uni(u, v); } int c1 = 0, c2 = 0, c3 = 0; fr(i, 1, n) { if(i == dsu[i]) { if(sz[i] == 1) { c1++; } else if(odd[i]) { c2++; } else { c3++; } } } ll ans = 0; while(c1) { ans += 2 * n - 1; n--; c1--; } while(c2) { ans += 2 * (c2 + c3) - 1; c2--; } ans += (c3 * 1LL * (c3 - 1)) * 2 + 2LL * c3; cout << ans; } int main() { ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; for(int tt = 1; tt <= t; tt++) { solve(); } return 0; }
0
#include <bits/stdc++.h> #define ri register #define int long long #define E (n+1) using namespace std; const int N=200010; inline int read() { int s=0, w=1; ri char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); } while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar(); return s*w; } int n,a[N],b[N],c[N]; signed main() { n=read(); for(ri int i=1;i<=n;i++) a[i]=read(); for(ri int i=1;i<=n;i++) b[i]=read(); for(ri int i=1;i<=n;i++) c[i]=read(); sort(a+1,a+1+n), sort(b+1,b+1+n), sort(c+1,c+1+n); int res=0; for(ri int i=1;i<=n;i++) { int p=lower_bound(a+1,a+1+n,b[i])-a; int q=upper_bound(c+1,c+1+n,b[i])-c; res+=(n-q+1)*(p-1); } printf("%lld\n",res); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n), b(n), c(n); for (auto &x: a) cin >> x; for (auto &x: b) cin >> x; for (auto &x: c) cin >> x; sort(a.begin(), a.end()); sort(b.begin(), b.end()); sort(c.begin(), c.end()); vector<long long> l(n); int j = 0; for (int i = 0; i < n; i++) { while (j < n && c[j] <= b[i]) j++; l[i] = n - j; } for (int i = n - 1; i > 0; i--) l[i-1] += l[i]; long long ans = 0; j = 0; for (int i = 0; i < n; i++) { while (j < n && b[j] <= a[i]) j++; if (j == n) break; ans += l[j]; } cout << ans << endl; return 0; }
1
#include <stdio.h> #include <cstdio> #include <iostream> #include <iomanip> #include <queue> #include <set> #include <vector> #include <string> #include <cstring> #include <algorithm> #include <cmath> #include <complex> int main(){ // read problem long long int M, tmp1, tmp2; std::vector<long long int> d, c; scanf("%lld", &M); for(long long int i = 0; i < M; i++){ scanf("%lld%lld", &tmp1, &tmp2); d.push_back(tmp1); c.push_back(tmp2); } /*std::cerr << "M: " << M << std::endl; std::cerr << "d: " << std::endl; for(long long int i = 0; i < M; i++){ std::cerr << d[i] << " "; }std::cerr << std::endl; std::cerr << "c: " << std::endl; for(long long int i = 0; i < M; i++){ std::cerr << c[i] << " "; }std::cerr << std::endl;*/ // solve problem long long int carryover = 0; long long int topdigit, period, tmp_pos; long long int ans = 0; std::vector<long long int> tmp_digits(10); for(long long int i = 0; i < M; i++){ //std::cerr << "i: " << i << " carryover: " << carryover << std::endl; // calculate carryover topdigit = d[i]; while(carryover>0){ ans++; topdigit = topdigit+carryover; carryover = topdigit/10; topdigit = (topdigit+10)%10; } //std::cerr << "carryover is done" << std::endl; // calculate one period tmp_digits[0] = topdigit; for(long long int j = 1; j < 10; j++){ tmp_digits[j] = d[i]; } tmp_pos = 0; period = 0; for(long long int tmp_pos = 0; tmp_pos < 9; tmp_pos++){ while(tmp_digits[tmp_pos] > 0){ period++; tmp_digits[tmp_pos+1] = tmp_digits[tmp_pos] + tmp_digits[tmp_pos+1]; tmp_digits[tmp_pos] = tmp_digits[tmp_pos+1]/10; tmp_digits[tmp_pos+1] = (tmp_digits[tmp_pos+1]+10)%10; } /*for(long long int k = 0; k < 10; k++){ std::cerr << tmp_digits[k]; }std::cerr << std::endl;*/ } ans += period*((c[i]-1)/9); //std::cerr << "one period calculated" << std::endl; // calculate amari tmp_pos = 9 - ((c[i]+8)%9); if(tmp_pos == 0){ continue; } tmp_digits[tmp_pos] = topdigit; for(long long int j = tmp_pos+1; j < 10; j++){ tmp_digits[j] = d[i]; } for(long long int tmp_pos = 0; tmp_pos < 9; tmp_pos++){ while(tmp_digits[tmp_pos] > 0){ ans++; tmp_digits[tmp_pos+1] = tmp_digits[tmp_pos] + tmp_digits[tmp_pos+1]; tmp_digits[tmp_pos] = tmp_digits[tmp_pos+1]/10; tmp_digits[tmp_pos+1] = (tmp_digits[tmp_pos+1]+10)%10; } } //std::cerr << "amari calculated" << std::endl; carryover = tmp_digits[9]; } std::cerr << "Answer: " << std::endl; std::cout << ans << std::endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i) #define rreps(i, n) for (int i = ((int)(n)); i > 0; --i) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++) #define inf 2e9 #define linf 9000000000000000000ll #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; int m; ll d[200001], c[200001]; ll digitsum(ll n) { ll res = 0; while (n != 0) { res += n % 10; n /= 10; } return res; } int main() { cin >> m; rep(i, m) { cin >> d[i] >> c[i]; } ll sum = 0; ll dignum = 0; rep(i, m) { dignum += c[i]; sum += d[i] * c[i]; } cout << dignum - 1 + (sum - 1) / 9 << endl; return 0; }
1
#include<iostream> using namespace std; int main (void) { int r; cin>>r; r=r*2*3141592; cout<<r/1000000<<"."<<r%1000000; }
#include<bits/stdc++.h> using namespace std; #define pi acos(-1) int main(){ int r; cin >> r; cout << fixed << setprecision(20) << (2*r*pi) << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back typedef long long ll; typedef pair<int, int> pi; typedef vector<int> vi; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int) (x).size() const int maxn = 505; ll a[maxn][maxn]; int n; const int maxm = 1e4 + 5; bool vis[maxm]; map<int, int> zhu, fu; ll gcd(ll x, ll y){ return y == 0 ? x : gcd(y, x % y); } ll lcm(ll x, ll y){ return x / gcd(x, y) * y; } void solve(){ memset(vis, 0, sizeof(vis)); vector<int> prime; vis[1] = 1; for(int i = 2;i < maxm;i++){ if(!vis[i]){ prime.push_back(i); for(int j = 2 * i;j < maxm;j += i){ vis[j] = 1; } } } int front = 0, rear = n - 1; for(int i = 2;i <= 2 * n;i += 2){ int k = i / 2; if(k & 1){ zhu[i] = prime[front++]; }else{ zhu[i] = prime[rear--]; } } int k; if(n & 1) k = n; else k = n - 1; front = n, rear = n + k - 1; for(int i = 1 - k, odd = 1;i <= k - 1;i += 2, odd++){ if(odd & 1){ fu[i] = prime[front++]; }else{ fu[i] = prime[rear--]; } } for(int i = 1;i <= n;i++){ int st; if(i & 1){ st = 1; }else{ st = 2; } for(int j = st;j <= n;j += 2){ int id1 = zhu[i + j]; int id2 = fu[i - j]; a[i][j] = 1LL * id1 * id2; } } for(int i = 1;i <= n;i++){ int st; if(i & 1){ st = 2; }else{ st = 1; } for(int j = st;j <= n;j += 2){ a[i][j] = 1; if(j > 1){ a[i][j] = lcm(a[i][j], a[i][j - 1]); } if(j < n){ a[i][j] = lcm(a[i][j], a[i][j + 1]); } if(i > 1){ a[i][j] = lcm(a[i][j], a[i - 1][j]); } if(i < n){ a[i][j] = lcm(a[i][j], a[i + 1][j]); } a[i][j]++; } } for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++){ cout << a[i][j] << ((j == n) ? '\n' : ' '); } } } int main(){ ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; if(n == 2){ cout << 4 << " " << 7 << endl; cout << 23 << " " << 10 << endl; return 0; } solve(); return 0; }
#include<bits/stdc++.h> const int N=503; using namespace std; typedef long long ll; ll a[N][N]; int n,p[N*2],tot; bool np[N*30]; inline int F(int x){ return p[n+x/2]; } inline int G(int x){ return p[(x+n/2*2)/2]; } int main(){ scanf("%d",&n); for(int i=2;tot<2*n;i++){ if(!np[i])p[tot++]=i; for(int j=i*i;j<N*30;j+=i)np[j]=1; } for(int i=0;i<n;i++,puts("")) for(int j=0;j<n;j++) if(i+j&1){ printf("%lld ",1ll*F(i+j-1)*F(i+j+1) *G(i-j-1)*G(i-j+1)+1); }else printf("%d ",F(i+j)*G(i-j)); }
1
/*{{{*/ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<iostream> #include<sstream> #include<set> #include<map> #include<queue> #include<bitset> #include<vector> #include<limits.h> #include<assert.h> #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define FOR(I, A, B) for (int I = (A); I <= (B); ++I) #define FORS(I, S) for (int I = 0; S[I]; ++I) #define RS(X) scanf("%s", (X)) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++) #define MP make_pair #define PB push_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PII> VPII; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template<class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(LL &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const LL &x) { printf("%lld", x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);} template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } #ifdef HOME #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");} #else #define DEBUG(...) #endif int MOD = 1e9+7; void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;} /*}}}*/ const int SIZE = 1e6+10; int N,X; LL b[SIZE],l[SIZE],u[SIZE]; bool used[SIZE]; int main(){ R(N,X); LL need=0; priority_queue<PLL>h0,h1,h2; REP(i,N){ R(b[i],l[i],u[i]); need+=b[i]*l[i]; h0.push({l[i]*b[i]+u[i]*(X-b[i]),i}); } LL an=0; while(need>=h0.top().F){ an+=X; used[h0.top().S]=1; need-=h0.top().F; h0.pop(); } if(need<=0){ W(an); return 0; } int add_id=h0.top().S; LL add_v=l[add_id]*b[add_id]+u[add_id]*(X-b[add_id]); LL mi=1e18; REP(i,N){ if(used[i]){ LL need2=need-add_v+l[i]*b[i]+u[i]*(X-b[i]); if(l[i]*b[i]>=need2){ mi=min(mi,(need2+l[i]-1)/l[i]); } else{ mi=min(mi,(need2-l[i]*b[i]+u[i]-1)/u[i]+b[i]); } } else{ if(l[i]*b[i]+u[i]*(X-b[i])<need)continue; if(l[i]*b[i]>=need){ mi=min(mi,(need+l[i]-1)/l[i]); } else{ mi=min(mi,(need-l[i]*b[i]+u[i]-1)/u[i]+b[i]); } } } an+=mi; W(an); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=100005; struct sj{ int a,l,r;ll x; inline sj(){} inline sj(int a,int l,int r,ll x):a(a),l(l),r(r),x(x){} inline bool operator<(const sj &t)const{return x>t.x;} }d[N]; inline void cmax(ll &a,ll b){if(a<b)a=b;} inline ll Y(int i,ll k){ ll a=d[i].a; if(k<=a)return k*d[i].l; else return k*d[i].r+a*(d[i].l-d[i].r); } int main(){ int n,i,a,l,r,x; ll L=0ll,R,M,S,g=0ll,t1,t2; scanf("%d%d",&n,&x);R=(S=(t1=((ll)x))*n)-1ll; for(i=1;i<=n;++i){ scanf("%d%d%d",&a,&l,&r);t2=a; d[i]=sj(a,l,r,t1*r+t2*(l-r)); g+=l*t2; } sort(d+1,d+n+1); while(L<=R){ M=(L+R)>>1; l=M/x; r=M%x; // printf("M=%lld l=%d r=%d",M,l,r); // for(i=1;i<=n;++i)printf(" (%d,%d)",d[i].x,Y(i,r)); // printf("\n"); t1=-1000000000000ll;t2=0ll; for(i=1;i<=l;++i){ t2+=d[i].x; cmax(t1,Y(i,r)-d[i].x); } t1+=d[i].x; for( ;i<=n;++i)cmax(t1,Y(i,r)); if(t1+t2>=g)R=(S=M)-1ll;else L=M+1ll; } printf("%lld",S); return 0; }
1
#include<bits/stdc++.h> using namespace std; struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io; typedef long long ll; typedef long double db; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vi> vii; typedef pair<int, int> pi; typedef tuple<int, int, int> t3; typedef map<int, int> mi; #define fi first #define se second #define vt vector #define be begin() #define ed end() #define sz size() #define cl clear() #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define lb(v, x) lower_bound(v.begin(), v.end(), x) #define lbi(v, x) (lb(v, x) - v.begin()) #define tp(t, x, y) t x, y; tie(x, y) #define tp3(t, x, y, z) t x, y, z; tie(x, y, z) #define mp make_pair #define mt make_tuple #define co const #define fc(x) for(int x = 1, _end = ri(); x <= _end; x++) void uni(vi &v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } db rd() { db x; cin >> x; return x; } ll ri() { ll x; cin >> x; return x; } string rs() { string s; cin >> s; return s; } pi rpi() { pi x; cin >> x.fi >> x.se; return x; } vi rvi(int n, int f = 0) { vi v(n + f); for (int i = f; i < v.size(); i++) cin >> v[i]; return v; } vii rvii(int n, int m, int f = 0) { vii v(n + f, vi(n + f)); for (int i = f; i < v.size(); i++) for (int j = f; j < v[0].size(); j++) cin >> v[i][j]; return v; } void pr() {}; template <class T, class ...U> void pr(T x, U ...y) { cout << x << ' ', pr(y...); } void prl() { cout << '\n'; }; template <class T, class ...U> void prl(T x, U ...y) { cout << x << ' ', prl(y...); } void pr(const vi &v, int f = 0) { for (int i = f; i < v.size(); i++) cout << v[i] << ' '; } void prl(const vi &v, int f = 0) { pr(v, f); cout << '\n'; } void pr(const pi &x) { cout << x.fi << ' ' << x.se; }; void prl(const pi &x) { pr(x); cout << '\n'; } #define rep(i, l, r) for (int i = l; i < r; i++) #define per(i, l, r) for (int i = l; i >= r; i--) const int N = 2e5 + 5, M = 1e9 + 7; int fa[N]; int fi(int x) { return !fa[x] || fa[x] == x ? x : fa[x] = fi(fa[x]); } vi g[N]; map<int, vi> cnt; bool vis[N]; void dfs(int u) { vis[u] = 1; cnt[fi(u)].pb(u); for (auto &v : g[u]) { if (!vis[v]) dfs(v); } } int main() { int n = ri(), a = ri(), b = ri(); rep(i, 0, a) { int x = ri(), y = ri(); fa[fi(x)] = fi(y); } rep(i, 0, b) { int u = ri(), v = ri(); g[u].pb(v); g[v].pb(u); } vi ans(n + 1); rep(i, 1, n + 1) { if (!vis[i]) { cnt.clear(); dfs(i); for (auto &p : cnt) { for (auto &v : p.se) { ans[v] = p.se.sz; } } } } pr(ans, 1); }
#include <bits/stdc++.h> // statics using namespace std; using int64 = int_fast64_t; using PAIR = pair<int, int>; constexpr int INF = 1 << 30; constexpr int64 LINF = 1LL << 60; constexpr int MOD = 1e9 + 7; constexpr int MAX_N = 1e5 + 1; // init/input #define int int64 #define INIT ios::sync_with_stdio(false);cin.tie(0); #define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__); template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;} template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);} #define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i; // out #define OUT(dist) cout<<(dist); #define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist); #define SP cout<<" "; #define BR cout<<"\n"; #define debug(x) cerr<<#x<<":"<< (x);BR; // utility #define ALL(a) (a).begin(), (a).end() #define EACH(i, a) for(auto &&i:(a)) #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i) #define REP(i, n) for(int i=0;i<(n);++i) #define RREP(i, n) for(int i=(n)-1;i>=0;--i) struct UnionFind { vector< int > par; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n); for(int i = 0; i < n; i++) par[i] = -1; } int root(int n) { if (par[n] < 0) return n; return par[n] = root(par[n]); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } bool issame(int x, int y) { return root(x) == root(y); } }; signed main() { INIT; VAR(int, n, k, l); UnionFind road(n + 1); REP(i, k) { VAR(int, p, q); road.merge(--p, --q); } UnionFind train(n + 1); REP(i, l) { VAR(int, s, t); train.merge(--s, --t); } map< PAIR, int > mp; REP(i, n) { mp[make_pair(road.root(i), train.root(i))]++; } REP(i, n) { OUT(mp[make_pair(road.root(i), train.root(i))]); if (i < n - 1) SP else BR } return 0; }
1
#include <iostream> #include <iomanip> #include <utility> #include <cmath> #include <random> #include <vector> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <string> #include <algorithm> using namespace std; #define rep(i,n) for(int i = 0; i<n; ++i) #define REP(i,n) for(int i = 1; i<=n; ++i) #define all(x) begin(x),end(x) #define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;} #define line "----------" typedef long long ll; typedef pair<int,int> P; const int inf = 1001001000; const ll INF = 1LL<<60; const ll MOD = 1e9 + 7; int main(){ string s; cin>>s; ll ans = s.size()*(s.size()-1)/2+1; map<char,ll> cha; rep(i,s.size()){ cha[s[i]]++; } for(auto x: cha){ ll t = x.second; ans -= t*(t-1)/2; } cout<<ans<<endl; return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <numeric> #include <cmath> #include <iomanip> //cout << fixed << setprecision(15) << << endl; #include <cassert> //#include "atcoder/all" using namespace std; //using namespace atcoder; typedef long long ll; #define pb push_back #define rep(i, n) for(int i=0;i<(n);i++) #define REP(i, n) for(int i=1;i<=(n);i++) #define P pair<int,int> template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } int mx8[] = {0, 0, 1, -1, -1, 1, -1, 1}; int my8[] = {-1, 1, 0, 0, -1, -1, 1, 1}; int mx4[] = {1, -1, 0, 0}; int my4[] = {0, 0, -1, 1}; const int MOD = 1000000007; int main() { ios::sync_with_stdio(false); string s; cin >> s; int m=0; int n = s.size(); int a = 0; rep(i, n) { a += int(s[i])-48; m += pow(10,n-i-1) * (int(s[i])-48); } if(m % a == 0) cout << "Yes" << endl; else cout << "No" << endl; }
0
#include <bits/stdc++.h> #include <math.h> #define _GLIBCXX_DEBUG #define _LIBCPP_DEBUG 0 using namespace std; #define ll long long #define rep(i,n) for (int i = 0; i < n; i++) #define rrep(i,n) for (int i = n-1; i >= 0; i--) #define MOD (1000000007) #define vi vector<int> #define vl vector<ll> #define vb vector<bool> #define vvi vector<vi> #define vvl vector<vl> #define pii pair<int, int> #define pli pair<ll, int> #define pb push_back #define mp make_pair #define all(a) (a).begin(),(a).end() 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; } ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } ll keta(ll n){ string s = to_string(n); ll num = s.size(); return num; } const ll INF = 1LL << 60; const int dh[4] = {1,0,-1,0}; const int dw[4] = {0,1,0,-1}; struct Edge{ int to; int weight; Edge(int t, int w) : to(t), weight(w){} }; using Graph = vector<vector<Edge>>; using P = pair<ll, int>; class UnionFind{ public: vi Parent; UnionFind(int n){ Parent = vi(n,-1); } int root(int a){ if(Parent[a] < 0) return a; return Parent[a] = root(Parent[a]); } bool issame(int a, int b){ return root(a) == root(b); } int size(int a){ return -Parent[root(a)]; } bool merge(int a, int b){ a = root(a); b = root(b); if(a == b) return false; if(size(a) < size(b)) swap(a,b); Parent[a] += Parent[b]; Parent[b] = a; return true; } }; vi MP(string s){ vi A(s.size()+1); A[0] = -1; int j = -1; rep(i,s.size()) { while(j >= 0 && s[i] != s[j]) j = A[j]; j++; A[i+1] = j; } return A; } vi Manacher(string s){ vi R(s.size()); int i = 0, j = 0; while(i < s.size()){ while(i-j >= 0 && i+j < s.size() && s[i-j] == s[i+j]) ++j; R[i] = j; int k = 1; while(i-k >= 0 && i+k < s.size() && k+R[i-k] < j) R[i+k] = R[i-k], k++; i += k; j -= k; } return R; } vi Z_algorithm(string &s){ vi Z(s.size()); Z[0] = s.size(); int i = 1, j = 0; while(i < s.size()){ while(i+j < s.size() && s[j] == s[i+j]) j++; Z[i] = j; if(j == 0){++i; continue;} int k = 1; while(i+k < s.size() && k+Z[k] < j) Z[i+k] = Z[k], ++k; i += k; j -= k; } return Z; } const int MAX = 1e6+1; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(ll n, ll k){ if(n >= MAX){ ll tmp = 1; rep(i,k){ tmp *= (n-i); tmp %= MOD; } return tmp*finv[k]%MOD; } if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll POW(ll x, ll n){ ll ret = 1; if(n < 0){// n < 0 にも対応 n *= -1; x = inv[x]; } while(0 < n){ if(n%2 == 0){ x = x*x%MOD; n /= 2; } else{ ret = ret*x%MOD; n--; } } return ret; } int main(){ int A, B; cin >> A >> B; A--; B--; int H, W; H = W = 100; char a[H][W]; rep(h,H) rep(w,W) { if(h < H/2) a[h][w] = '#'; else a[h][w] = '.'; } for(int h = 0; h < H; h += 2) for(int w = 0; w < W; w += 2) { if(h < H/2 && A > 0){ a[h][w] = '.'; A--; } if(h > H/2 && B > 0){ a[h][w] = '#'; B--; } } printf("%d %d\n", H, W); rep(h,H) rep(w,W) { cout << a[h][w]; if(w == W-1) cout << endl; } }
#pragma region Macros #include <bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<int>>; using WGraph = vector<vector<pair<int, ll>>>; template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; } template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0}; constexpr int INF = 1e9; constexpr long long LINF = 1e18; constexpr long long MOD = 1e9 + 7; constexpr double EPS = 1e-10; constexpr double PI = M_PI; #pragma endregion void solve() { int a, b; cin >> a >> b; vector<string> res(100); for (int i=0; i<100; i++) { for (int j=0; j<100; j++) { if (i < 50) res.at(i).push_back('.'); else res.at(i).push_back('#'); } } int x = 0, y = 0; for (int i=0; i<b-1; i++) { res.at(x).at(y) = '#'; y += 2; if (y >= 100) { x += 2; y = 0; } } x = 51, y = 0; for (int i=0; i<a-1; i++) { res.at(x).at(y) = '.'; y += 2; if (y >= 100) { x += 2; y = 0; } } cout << 100 << ' ' << 100 << '\n'; for (string s : res) cout << s << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); solve(); return 0; }
1
#include <bits/stdc++.h> using namespace std; int main(){ vector<queue<char>> s(3); for(int ix=0;ix<3;ix++){ string tmp; cin >> tmp; for(int ixx=0;ixx<tmp.size();ixx++) s.at(ix).push(tmp.at(ixx)); } char card; int turnplayer = 0; while(!s.at(turnplayer).empty()){ card = s.at(turnplayer).front(); s.at(turnplayer).pop(); turnplayer = card - 'a'; } if(turnplayer == 0) cout << "A" << endl; if(turnplayer == 1) cout << "B" << endl; if(turnplayer == 2) cout << "C" << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ string sa,sb,sc; cin>>sa>>sb>>sc; reverse(sa.begin(),sa.end()); reverse(sb.begin(),sb.end()); reverse(sc.begin(),sc.end()); queue<char> card; card.push(sa[sa.size()-1]); sa.pop_back(); char ans; while(true){ char now=card.front(); card.pop(); if(now=='a'){ if(sa.empty()) {ans='A'; break;} card.push(sa[sa.size()-1]); sa.pop_back(); } if(now=='b'){ if(sb.empty()) {ans='B'; break;} card.push(sb[sb.size()-1]); sb.pop_back(); } if(now=='c'){ if(sc.empty()) {ans='C'; break;} card.push(sc[sc.size()-1]); sc.pop_back(); } } cout<<ans<<endl; }
1
#include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define endl "\n" using namespace std; using ll = long long; using P = pair<int, int>; const ll MOD = 1000000007LL; // = 10^9 + 7 const double PI = 3.14159265358979; void solve() { int n, v1, v2; cin >> n; map<int, int> hist1; map<int, int> hist2; for(int i = 0; i < n / 2; ++i) { cin >> v1 >> v2; hist1[v1]++; hist2[v2]++; } vector<P> h1{ P(0, -1) }; vector<P> h2{ P(0, -1) }; for(const auto& h : hist1) { h1.emplace_back(P(h.second, h.first)); } for(const auto& h : hist2) { h2.emplace_back(P(h.second, h.first)); } sort(h1.rbegin(), h1.rend()); sort(h2.rbegin(), h2.rend()); ll ans = 0; int i1 = 0, i2 = 0; if (h1[0].second == h2[0].second) { if (h1[0].first == h2[0].first) { h1[1] > h2[1] ? i1++ : i2++; } else { h1[0] < h2[0] ? i1++ : i2++; } } ans = n - h1[i1].first - h2[i2].first; cout << ans; } int main() { fastio; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main(int argc, const char *argv[]) { int n; cin >> n; int max_v = 100000; vector<int> va(n), cnt1(max_v + 1, 0), cnt2(max_v + 1, 0); for (int i = 0; i < n; ++i) { cin >> va[i]; if (i % 2 == 0) { cnt1[va[i]]++; } else { cnt2[va[i]]++; } } auto max2 = [](vector<int> &cnt) { array<int, 2> res{0, 0}; for (int i = 0; i < cnt.size(); i++) { if (cnt[res[0]] < cnt[i]) { res[1] = res[0]; res[0] = i; } else if (cnt[res[1]] < cnt[i]) { res[1] = i; } } return res; }; auto max2_even = max2(cnt1), max2_odd = max2(cnt2); int ans; if (max2_even[0] != max2_odd[0]) { ans = n - cnt1[max2_even[0]] - cnt2[max2_odd[0]]; } else { ans = n - max(cnt1[max2_even[0]] + cnt2[max2_odd[1]], cnt1[max2_even[1]] + cnt2[max2_odd[0]]); } cout << ans << '\n'; }
1
#include<bits/stdc++.h> using namespace std; #define int long long #define ii pair <int, int> #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define f first #define s second #define Time (double)clock()/CLOCKS_PER_SEC ii mer(int a, int b) { int op = 0; while (1) { ++op; if (a + b < 10) return mp(a+b,op); else tie(a,b) = mp((a+b)/10, (a+b)%10); } } ii mr[10][10]; ii mem[10][60]; signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); #endif for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) mr[i][j] = mer(i, j); for (int c = 0; c < 10; ++c) { mem[c][0] = mp(c, 0); for (int i = 1; i < 60; ++i) { auto t = mr[mem[c][i - 1].f][mem[c][i - 1].f]; mem[c][i] = mp(t.f, t.s + mem[c][i - 1].s * 2); } } int n; cin >> n; int ans = 0; vector <int> ar; for (int i = 0; i < n; ++i) { int d, k; cin >> d >> k; int c = d; --k; for (int j = 0; j < 60; ++j) { if ((k >> j) & 1) { ii add = mem[d][j]; auto t = mr[c][add.f]; ans += t.s; ans += add.s; c = t.f; } } ar.app(c); } int cur = ar[0]; for (int i = 1; i < ar.size(); ++i) { ii t = mr[cur][ar[i]]; cur = t.f; ans += t.s; } cout << ans << endl; }
/** * author: tourist * created: 29.12.2019 21:02:36 **/ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; for (int t = 0; t < 4; t++) { vector<int> a(n + 2); a[0] = t & 1; a[1] = (t & 2) >> 1; for (int i = 2; i < n + 2; i++) { char c = s[(i - 1) % n]; if (c == 'o') a[i] = a[i - 1] ^ a[i - 2]; else a[i] = a[i - 1] ^ a[i - 2] ^ 1; } if (a[0] == a[n] && a[1] == a[n + 1]) { for (int i = 0; i < n; i++) cout << (!a[i] ? 'S' : 'W'); cout << '\n'; return 0; } } cout << -1 << '\n'; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int ans = 0; for ( int n = a; n <= b; n++ ) { string num = to_string(n); if ( num[0] == num[4] && num[1] == num[3] ) { ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int A, B; cin >> A >> B; int x = 0; int C = A; for (int i = 0; i < B - A + 1; i++) { int y = C / 10000 + C / 1000 % 10 *10 + C / 100 % 10 * 100 + C / 10 % 10 * 1000 + C % 10 * 10000; if ( C == y ){ x += 1; } C += 1; } cout << x << endl; }
1
#include <iostream> int main(){ int n; std::cin>>n; std::cout<<(n-2)*180; }
#include<iostream> #include<stdio.h>//printf("%.*f\n",*********); #include<vector>//s.erase(n),vector #include<algorithm>//next_permutation #include<set> #include<string>//char('a'=32+'A') //to_string,string,substr #include<sstream> #include<complex> #include<time.h> #include<random> #include<cmath>//min,max #include<math.h> #include<queue> #include<time.h> #include<iomanip> #include<locale> #include<utility>//swap #define rt "\n" #define rep(i,n) for(int i=0;i<n;i++) #define rop(i,n) for(int i=1;i<=n;i++)//start==1 #define drep(i,n) for(int i=n-1;0<=i;i--) #define drop(i,n) for(int i=n;0<i;i--)//end==1 #define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt; #define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt; #define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt; #define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt; #define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt; #define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数) #define sort(s) sort(s.begin(),s.end())//昇順 #define reve(s) reverse(s.begin(),s.end())//反転 #define please return #define AC 0 #define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false) #define pi 3.1415926535897932384626//pi #define nine 1000000000//10^9 using namespace std; typedef vector<int> vint; typedef long double ldouble; typedef vector<string> vstr; typedef vector<char> vchar; typedef vector<double> vdou; typedef vector<double> vdouble; typedef long long int llint; typedef pair<int, int> pint; typedef pair<llint, llint> pllint; typedef vector<llint> vllint; typedef vector<pint> vpint; typedef vector<pair<llint, llint>> vpllint; typedef vector<vector<int>> vvint; typedef vector<vector<char>> vvchar; typedef vector<vector<double>> vvdouble; typedef vector<vector<llint>> vvllint; typedef vector<vector<string>> vvstr; typedef vector<vector<bool>> vvbool; typedef vector<vector<pint>> vvpint; typedef vector<bool> vbool; long long GCD(long long a, long long b) { if (b == 0) return a; else return GCD(b, a % b); } long long LCM(long long a, long long b) { return a * b / GCD(a, b); } unsigned GetDigit(unsigned num) { return std::to_string(num).length(); } int tow(int n) {//2のn乗 if (n == 0)return 1; int x = tow(n / 2); x *= x; if (n % 2 == 1)x *= 2; return x;//@domino } int KETA(int n) { //Sum of Each Digit int sum = 0; while (n > 0) { sum += n % 10; n /= 10; } return sum; } unsigned ND(unsigned num) {//Number of Digits return std::to_string(num).length();//outmax=10 } bool KIBN(string s) { rep(i, s.size() / 2) { if (s[i] != s[s.size() - 1 - i])return false; } return true; } /* (char)toupper(a[n])=文字列のn文字目を大文字で出力 pow(a,b)=aのb乗 */ int main(void) { rapid_pleaseAC_fast; int n; cin >> n; cout << (n - 2) * 180 << rt; please AC; } //参考:---
1
#include<algorithm>//sort,二分探索,など #include<bitset>//固定長bit集合 #include<cmath>//pow,logなど #include<complex>//複素数 #include<deque>//両端アクセスのキュー #include<functional>//sortのgreater #include<iomanip>//setprecision(浮動小数点の出力の誤差) #include<iostream>//入出力 #include<iterator>//集合演算(積集合,和集合,差集合など) #include<map>//map(辞書) #include<numeric>//iota(整数列の生成),gcdとlcm(c++17) #include<queue>//キュー #include<set>//集合 #include<stack>//スタック #include<string>//文字列 #include<unordered_map>//イテレータあるけど順序保持しないmap #include<unordered_set>//イテレータあるけど順序保持しないset #include<utility>//pair #include<vector>//可変長配列 #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using P = pair<int,int>; using ll = long long; const int INF = 100005; const int MAX_N = 100005; bool comp(P a, P b){ if(a.second != b.second){ return a.second < b.second; }else{ return a.first < b.first; } } int n; int main(){ cin >> n; vector<P> a,b; int x,y; rep(i,n){ cin >> x >> y; a.push_back(make_pair(x,y)); } rep(i,n){ cin >> x >> y; b.push_back(make_pair(x,y)); } sort(a.rbegin(),a.rend()); sort(b.begin(),b.end(),comp); int count =0; rep(i,n){ for(int j=0; j<b.size(); j++){ if(a[i].first < b[j].first && a[i].second < b[j].second ){ count ++; b.erase(b.begin()+j); break; } } } cout << count << endl; }
#include <iostream> #include <string> #include <cstring> #include <algorithm> #include <functional> #include <cmath> #include <set> #include <queue> #include <deque> #include <vector> #include <climits> #include <sstream> #include <iomanip> #include <map> #include <stack> using namespace std; typedef unsigned long long ull; typedef long long ll; struct EdgeMF { int to; ll capacity; int reverse; }; void addEdgeForFlow(vector<vector<EdgeMF>>& G, int from, int to, ll capacity, ll reverseCapacity) { G[from].push_back({ to, capacity, (int)G[to].size() }); G[to].push_back({ from, reverseCapacity, (int)G[from].size() - 1 }); } ll dfsForFlow(vector<vector<EdgeMF>>& G, vector<bool>& used, int u, int t, ll f) { if (u == t) { return f; } used[u] = true; for (auto& e : G[u]) { if (used[e.to] || e.capacity <= 0) { continue; } auto d = dfsForFlow(G, used, e.to, t, min(f, e.capacity)); if (d > 0) { e.capacity -= d; G[e.to][e.reverse].capacity += d; return d; } } return 0; } ll calcMaxFlow(vector<vector<EdgeMF>>& G, int s, int t) { auto f = 0ll; while (true) { vector<bool> used((int)G.size()); auto d = dfsForFlow(G, used, s, t, LLONG_MAX); if (d <= 0) { break; } f += d; } return f; } int main() { int N; cin >> N; vector<int> x(2 * N); vector<int> y(2 * N); for (auto i = 0; i < 2 * N; ++i) { cin >> x[i] >> y[i]; } vector<vector<EdgeMF>> G(2 * N + 2); for (auto i = 0; i < N; ++i) { for (auto j = N; j < 2 * N; ++j) { if (x[i] < x[j] && y[i] < y[j]) { addEdgeForFlow(G, i, j, 1, 0); } } } int s = 2 * N; int t = s + 1; for (auto i = 0; i < N; ++i) { addEdgeForFlow(G, s, i, 1, 0); addEdgeForFlow(G, i + N, t, 1, 0); } cout << calcMaxFlow(G, s, t) << endl; return 0; }
1
/* ID: anonymo14 TASK: wormhole LANG: C++ */ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<pair<int,int>> vpii; #define F first #define S second #define PU push #define PUF push_front #define PUB push_back #define PO pop #define POF pop_front #define POB pop_back #define REP(i,a,b) for(int i=a; i<=b; i++) #define MOD 1000000007 void solve(int test_case) {//239///F.Sugoroku int n,k;cin>>n>>k; if(n==k)cout<<2*n; else cout<<2*max(n,k)-1; } int main() { ////// FILE BASED IO//// //freopen("wormhole.in", "r", stdin); //freopen("wormhole.out", "w", stdout); /////////////// ios::sync_with_stdio(0); cin.tie(0); int t=1; //cin>>t; REP(i,1,t) { solve(i); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int A,B; cin >> A >> B; if(A>B){ cout << A+max(A-1,B) << endl; return 0; } cout << B+max(B-1,A) << endl; }
1
#include <iostream> #include <iomanip> #include<math.h> #include<list> #include <algorithm> #include<set> #include<vector> #include<math.h> #include<map> #include<string> #include <numeric> #include <queue> #include <sstream> #include <bitset> #include<stack> using namespace std; using ll = long long; using vll = vector<long long>; using sll = set<long long>; const long long ll_max = 9223372036854775807; const long long ll_min = -9223372036854775807; const int int_max = 2147483647; template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template<typename T> map<T, T> getPrimeFactor(T n) { map<T, T> res; for (T i = 2; i * i <= n; ++i) { while (n % i == 0) { res[i] ++; n /= i; } } if (n != 1) res[n] = 1; return res; } template<typename T> bool IsPrimeNumber(T num) { 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; } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // 繰り返し二乗法 ll pow2(ll n, ll p, ll mod) { if (p == 0 || n == 1) { return 1; } else { ll ret = pow2(n * n % mod, p / 2, mod); if (p % 2 == 1) { ret *= n; } return ret % mod; } } #define rep(i,s,e) for(ll i=s;i<e;i++) #define repeq(i,s,e) for(ll i=s;i<=e;i++) int main() { int N; cin >> N; vll num(4); ll d = 10; rep(i, 0, 4) { num[i] = N % d; N -= num[i]; num[i] *= 10; num[i] /= d; d *= 10; } rep(i, 0, (1LL << 3)) { ll tmp = num[3]; rep(j, 0, 3) { if (i & (1LL << j)) { tmp += num[j]; } else { tmp -= num[j]; } } if (tmp == 7) { cout << num[3]; for (ll j = 2; j >= 0; j--) { if (i & (1LL << j)) { cout << '+'; } else { cout << '-'; } cout << num[j]; } cout << "=7" << endl; return 0; } } return 0; }
#include<iostream> #include<cmath> using namespace std; int main() { int R; scanf("%d",&R); printf("%f",2*R*acos(-1.0)); return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ldouble = long double; const ll inf = 1ll << 60; const ll mod = (ll)1e9 + 7; #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define print(s) cout << s; #define println(s) cout << s << endl; #define printd(s) cout << fixed << setprecision(10) << s << endl; string res; int main() { ll a, b; cin >> a >> b; println(2*b - a); }
#include<stdio.h> int main(){ char word1[105]; char word2[105]; scanf ("%s %s", &word1, &word2); printf("%s%s\n",word2,word1); return 0; }
0
#include <iostream> #include <iomanip> #include <cstdio> #include <queue> #include <cstring> #include <vector> #include <map> #include <algorithm> #include <cctype> #include <cmath> #include <bitset> #include <set> #include <stack> using namespace std; #define REP(i,n) for(int i=0;i<(int)(n);i++) #define RREP(i,n) for(int i=n-1;i>=0;i--) #define FOR(i,k,n) for(int i=(k);i<(int)(n);i++) #define all(i,n) (i),(i+n) int dx4[4]={1,0,-1,0}; int dy4[4]={0,-1,0,1}; int dx8[8]={1,0,-1,1,-1,1,0,-1}; int dy8[8]={1,1,1,0,0,-1,-1,-1}; int dx9[9]={0,1,0,-1,1,-1,1,0,-1}; int dy9[9]={0,1,1,1,0,0,-1,-1,-1}; typedef pair<int, int> P; typedef pair<string, int> SP; typedef long long ll; typedef pair<ll, ll> PLL; const int INF = 1e9; const ll LLINF = 1e18; const int MAX_V = 1e6+1; const ll mod = 1000000007; // << fixed << setprecision // -------------------------------------- int n; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; ll ans = 1; int c[3]; REP(i, 3) c[i] = 0; REP(i, n) { int a; cin >> a; int t = 0, p = 0; REP(j, 3) if(c[j] == a) { t++; p = j; } ans = (ans * t) % mod; c[p]++; } cout << ans << endl; }
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #include <deque> #include <array> #define rep(i,n) for(int i=0;i<(int)n;i++) #define range(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define mp make_pair #define pb push_back #define fst first #define snd second #define all(x) x.begin(), x.end() #define PI 3.1415926536 using namespace std; const int MAX_N = 5000; array<int, MAX_N + 1> bit; int sets, n; int sum(int i){ int ret = 0; while(i > 0){ ret += bit[i]; i -= i & -i; } return ret; } void add(int i, int x){ while(i <= n){ bit[i] += x; i += i & -i; } } void solve(){ cin >> n; if(n == 0) exit(0); bit.fill(0); for (int i = 1; i <= n; ++i) { int t; cin >> t; add(i, t); } int ans = -1e9; for (int i = 0; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { ans = max(ans, sum(j) - sum(i)); } } cout << ans << endl; } int main(){ cin.tie(0); ios::sync_with_stdio(false); for(;;) solve(); return 0; }
0
#include<bits/stdc++.h> using namespace std; using ll = long long; #define REP(i,n) for(int i = 0;i < n;i++) /* * verified : http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4713284#1 * last revised : 29.July.2020 */ template<class T> class BIT { private: int n; vector<T> dat;//[1,n] public: BIT(int maxn, int _n) { dat.assign(maxn + 1, 0); n = _n; } T sum(int i) { T res = 0; while (i > 0) { res += dat[i]; i -= i & -i; } return res; } void add(int i, T x) { while (i <= n) { dat[i] += x; i += i & -i; } } }; #define maxn 500050 #define F first #define S second struct range{ int l,r,id; range(){} range(int l,int r,int id):l(l),r(r),id(id){} }; bool comp(range& a,range& b){ return a.r < b.r; } int main(){ cin.tie(0);ios::sync_with_stdio(false); int N,Q;cin >> N >> Q; vector<int> c(N+1); for(int i=1;i<=N;i++)cin>>c[i]; vector<range> a(Q); for(int i=0;i<Q;i++){ int l,r;cin >> l >> r; a[i] = range(l,r,i); } sort(a.begin(),a.end(),comp); BIT<int> bit(maxn,maxn); vector<int> good(maxn,0); vector<int> ans(Q,0); int i = 0,j = 1; for(;i < Q;i++){ for(;j <= a[i].r;j++){ if(good[c[j]] == 0){ bit.add(j,1); }else{ bit.add(good[c[j]],-1); bit.add(j,1); } good[c[j]] = j; } if(a[i].l == 1) ans[a[i].id] = bit.sum(a[i].r); else ans[a[i].id] = bit.sum(a[i].r) - bit.sum(a[i].l-1); } for(int i=0;i<Q;i++)cout << ans[i] << '\n'; }
#include<stdio.h> #include<math.h> #include<stdlib.h> #include<vector> #include<algorithm> #include<map> using namespace std; double pi = 3.1415926535897932384646433; typedef long long ll; typedef pair<ll, ll>pii; ll ccw(pii a, pii b, pii c) { return (b.first - a.first)*(c.second - b.second) - (b.second - a.second)*(c.first - b.first); } double dist(pii a, pii b) { return sqrt(double((b.first - a.first)*(b.first - a.first) + (b.second - a.second)*(b.second - a.second))); } double dot(pii a, pii b) { return double(a.first*b.first + a.second*b.second); } double ans[111]; int main() { fill(ans, ans + 111, 0); int num; scanf("%d", &num); vector<pii>v; map<pii, int>ma; for (int i = 0; i < num; i++) { ll a, b; scanf("%lld%lld", &a, &b); v.push_back(make_pair(a, b)); ma[make_pair(a, b)] = i; } sort(v.begin(), v.end()); vector<pii>v1, v2; for (int i = 0; i < num; i++) { for (;;) { if (v1.size() <= 1)break; pii a = v1[v1.size() - 2], b = v1[v1.size() - 1]; if (ccw(a, b, v[i])<0)v1.pop_back(); else break; } v1.push_back(v[i]); } for (int i = 0; i < num; i++) { for (;;) { if (v2.size() <= 1)break; pii a = v2[v2.size() - 2], b = v2[v2.size() - 1]; if (ccw(a, b, v[i])>0)v2.pop_back(); else break; } v2.push_back(v[i]); } for (int i = int(v2.size()) - 2; i >= 1; i--)v1.push_back(v2[i]); for (int i = 0; i < v1.size(); i++) { pii s = v1[(i + v1.size() - 1) % v1.size()]; pii t = v1[i]; pii u = v1[(i + 1) % v1.size()]; //printf("%lld %lld %lld %lld %lld %lld\n", s.first, s.second, t.first, t.second, u.first, u.second); double x = acos(dot(make_pair(u.first - t.first, u.second - t.second), make_pair(s.first - t.first, s.second - t.second)) / dist(s, t) / dist(t, u)); ans[ma[v1[i]]] = (pi - x) / (2 * pi); } for (int i = 0; i < num; i++)printf("%.6lf\n", ans[i]); }
0
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif int main() { long long int n, k; cin >> n >> k; long long ans = k; long long t; cin >> t; for (int i = 1; i < n; i++) { long long x; cin >> x; ans += min(k, (x - t)); t = x; } cout << ans; }
#include <bits/stdc++.h> using namespace std; int ts[200010]; int main(){ int n, t; scanf("%d%d", &n, &t); for(int i = 0; i < n; i++) scanf("%d", &ts[i]); long ans = t; for(int i = 0; i + 1 < n; i++) { int time = ts[i+1] - ts[i]; ans += (time > t) ? t : time; } printf("%ld\n", ans); }
1