code_file1
stringlengths
80
4k
code_file2
stringlengths
91
4k
similar_or_different
int64
0
1
#include <bits/stdc++.h> using namespace std; int root(vector<int> &r, int a) { if (r[a] == a) return a; else return r[a] = root(r, r[a]); } int main() { long long N, K, L; scanf("%lld%lld%lld", &N, &K, &L); vector<int> road, rail; for (int i = 0; i <= N; i++) { road.push_back(i); rail.push_back(i); } for (int i = 1; i <= K; i++) { int p, q; scanf("%d%d", &p, &q); road[root(road, p)] = root(road, q); } for (int i = 1; i <= L; i++) { int r, s; scanf("%d%d", &r, &s); rail[root(rail, r)] = root(rail, s); } map<pair<int, int>, int> mp; for (int i = 1; i <= N; i++) { mp[make_pair(root(road, i), root(rail, i))]++; } for (int i = 1; i <= N; i++) { printf("%d ", mp[make_pair(root(road, i), root(rail, i))]); } printf("\n"); }
#include <bits/stdc++.h> using namespace std; #define fr(i,n) _back #define pb push_back #define eb emplace_back #define mk make_pair #define fi first #define se second #define endl '\n' typedef long long ll; typedef pair<int,int> ii; typedef vector<ii> vii; const int INF = 0x3f3f3f3f; const double PI = acos(-1.0); const int T = 2e5 + 3; int pai[3][T]; int peso[3][T]; vii g[T]; int n,k,l; void init() { for(int i = 0; i < 3; i++) for(int j = 0; j <= n; j++) { pai[i][j] = j; peso[i][j] = 1; } } int find(int op, int x) { return (pai[op][x] == x? x : pai[op][x] = find(op,pai[op][x])); } void join(int op, int x, int y) { x = find(op,x); y = find(op,y); if(x == y) return; if(peso[op][x] < peso[op][y]) swap(x,y); pai[op][y] = x; peso[op][x] += peso[op][y]; } int main() { ios_base::sync_with_stdio(false); cin >> n >> k >> l; init(); while(k--) { int a,b; cin >> a >> b; if(find(0,a) != find(0,b)) join(0,a,b); } while(l--) { int a,b; cin >> a >> b; if(find(1,a) != find(1,b)) join(1,a,b); } for(int i = 1; i <= n; i++) g[find(0,i)].eb(find(1,i),i); for(int i = 1; i <= n; i++) { sort(g[i].begin(), g[i].end()); for(int j = 1; j < g[i].size(); j++) if(g[i][j].fi == g[i][j-1].fi) join(2,g[i][j].se,g[i][j-1].se); } for(int i = 1; i <= n; i++) cout << peso[2][find(2,i)] << " "; cout << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; #define ll long long const ll MOD = 1000000007; bool check(int a,int b,int c) { if((a+b)>c && (c+b)>a && (a+c)>b) return true; return false; } int main() { // freopen("input01.txt", "r", stdin); // freopen("output01.txt", "w", stdout); int n; cin>>n; map<ll int,int> mp; ll int a; int l,ct=0; for(l=0;l<n;l++) { cin>>a; mp[a]++; } if(mp.size()<3) { cout<<0; return 0; } for(auto i=mp.begin();next(next(i))!=mp.end();i++) { for(auto j=next(i);next(j)!=mp.end();j++) { for(auto k=next(j);k!=mp.end();k++) { if(check(i->first,j->first,k->first)) ct+=(i->second*j->second*k->second); } } } cout<<ct; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> L(N); for(int i = 0; i < N; i++) cin >> L.at(i); int total = 0; if(N < 3) cout << "0" << endl; else { for(int i = 0; i < N - 2; i++) { for(int j = i + 1; j < N - 1; j++) { for(int k = j + 1; k < N; k++) { if(L.at(i) == L.at(j) || L.at(j) == L.at(k) || L.at(k) == L.at(i)) { continue; } if(L.at(i) + L.at(j) > L.at(k) && L.at(i) + L.at(k) > L.at(j) && L.at(j) + L.at(k) > L.at(i)) { total++; } } } } cout << total << endl; } }
1
#include <functional> #include <algorithm> #include <iostream> #include <numeric> #include <iomanip> #include <utility> #include <cstdlib> #include <sstream> #include <bitset> #include <vector> #include <cstdio> #include <ctime> #include <queue> #include <deque> #include <cmath> #include <stack> #include <list> #include <map> #include <set> using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; typedef long long ll; #define dump(x) cerr << #x << " = " << (x) << endl #define rep(i,n) for(int i=0;i<(n);i++) #define all(a) (a).begin(),(a).end() #define pb push_back bool isLeep(int n){ if((n%4==0 && n%100!=0) || n%400==0){ return true; } else return false; } int main() { int a[5]={}; char ch; while(cin>>a[0]>>ch>>a[1]>>ch>>a[2]>>ch>>a[3]>>ch>>a[4]){ sort(a,a+5); if( (a[0]==a[1] && a[1]==a[2] && a[2]==a[3]) || (a[1]==a[2] && a[2]==a[3] && a[3]==a[4]) )cout<<"four card"<<endl; else if( (a[0]==a[1] && a[1]==a[2] && a[3]==a[4]) || (a[0]==a[1] && a[2]==a[3] && a[3]==a[4]) )cout<<"full house"<<endl; else if( (a[0]+1==a[1] && a[1]+1==a[2] && a[2]+1==a[3] && a[3]+1==a[4]) || (a[0]==1 && a[1]==10 && a[2]==11 && a[3]==12 && a[4]==13) )cout<<"straight"<<endl; else if( (a[0]==a[1] && a[1]==a[2]) || (a[1]==a[2] && a[2]==a[3]) || (a[2]==a[3] && a[3]==a[4]) )cout<<"three card"<<endl; else if( (a[0]==a[1] && (a[2]==a[3] || a[3]==a[4] )) || (a[1]==a[2] && a[3]==a[4]) )cout<<"two pair"<<endl; else if( a[0]==a[1] || a[1]==a[2] || a[2]==a[3] || a[3]==a[4] )cout<<"one pair"<<endl; else cout<<"null"<<endl; } return 0; }
#include <cstdio> #include <vector> using namespace std; int main() { int n,num; while (scanf("%d",&n)&&n!=0) { vector<int> ice(10,0); for (int i=0; i<n; i++) { scanf("%d",&num); ice[num]++; } for (int i=0; i<10; i++) { if (ice[i]==0) { printf("-"); } else { for (int j=0; j<ice[i]; j++) printf("*"); } printf("\n"); } } }
0
#include<iostream> #include<string> using namespace std; int main(void){ string str; while(getline(cin, str)){ for(int i=0; i<26; i++){ for(int j=0; j<str.size(); j++){ if(str[j]!=' ' && str[j]!='.'){ str[j]++; if(str[j]>'z') str[j]-=26; } } if(str.find("the")!=string::npos){ cout<<str<<endl; break; }else if(str.find("this")!=string::npos){ cout<<str<<endl; break; }else if(str.find("that")!=string::npos){ cout<<str<<endl; break; } } } }
#include<iostream> #include<iomanip> #include<memory> #include<array> #include<vector> #include<queue> #include<list> #include<stack> #include<algorithm> #include<cmath> using namespace std; int chipher( string& s ) { for ( auto& c : s ) { if ( c >= 'a' && c <= 'y' ) ++c; else if ( c == 'z' ) c = 'a'; } return 0; } int main() { string x; while( getline(cin, x) ) { for ( int i = 0; i < 26; ++i ) { if ( x.find( "the" ) != string::npos ) cout << x << endl; else if ( x.find( "this" ) != string::npos ) cout << x << endl; else if ( x.find( "that" ) != string::npos ) cout << x << endl; chipher( x ); } } return 0; }
1
#include <bits/stdc++.h> using namespace std; #define repex(i, a, b, c) for(int i = a; i < b; i += c) #define repx(i, a, b) repex(i, a, b, 1) #define rep(i, n) repx(i, 0, n) #define repr(i, a, b) for(int i = a; i >= b; i--) int main(){ // 1. 入力情報. char X[202020]; scanf("%s", X); int l = strlen(X); // 2. 'T' が 来たら, stack から 'S' を 取り除く. stack<char> st; rep(i, l){ char c = X[i]; if(st.empty()){ st.push(c); continue; } char t = st.top(); if(c == 'T' && t == 'S') st.pop(); else st.push(c); } // 3. 出力. printf("%d\n", st.size()); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define ve vector int main(){ string s; cin >> s; ll n = s.size(); reverse(s.begin(), s.end()); ve<int> b(n+1); rep(i,n) b[i] = s[i] - '0'; b[n] = 0; rep(i,n){ if(b[i] >= 6 || (b[i] == 5 && b[i+1] >= 5)){ b[i] = 10 - b[i]; b[i+1]++; } } ll ans = 0; rep(i,n+1) ans += b[i]; cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } using ll = long long; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { ll N,M; cin>>N>>M; vector<ll> mo(N); for(ll i = 0LL; i < N; i++) { ll x; cin>>x; if(i==0LL) mo[i]=x%M; else mo[i]=(mo[i-1]+x)%M; } sort(mo.begin(),mo.end()); ll ans = 0LL; ll k = 0LL; for(ll i = 0LL; i < N;i++){ k++; if(i==N-1LL||mo[i]!=mo[i+1LL]){ if(mo[i]==0LL)ans+=(k+k*(k-1LL)/2LL); else ans+=(k*(k-1LL)/2LL); k=0LL; } } cout<<ans<<endl; }
#include<iostream> #include<algorithm> #include<vector> #include<queue> #include<string> #include<iomanip> #include<sstream> #include<map> #include<cmath> using namespace std; #define rep(i,n) for(int i = 0;i < n;i++) #define req(i,n) for(int i = 1;i <=n;i++) #define rrep(i,n) for(int i = n -1;i >= 0;i--) #define ALL(a) a.begin(),a.end() typedef long long ll; typedef long double ld; const ll MOD = 1000000007; const ll INF = 1LL << 60; int n, m, x, y;ll z = 0, w, h, sum = 0, ans; template<typename A, size_t N, typename T> void Fill(A(&array)[N], const T & val) { std::fill((T*)array, (T*)(array + N), val); } int main(void) { cin >> n >> m; map<int, int> mp; mp[0]++; rep(i, n) { cin >> x; z += x; z %= m; sum += mp[z]; mp[z]++; }cout << sum << endl; }
1
#include <cstdio> #include <cstdlib> #include <iostream> #include <fstream> #include <sstream> #include <set> #include <map> #include <vector> #include <list> #include <algorithm> #include <cstring> #include <cmath> #include <string> #include <stack> #include <queue> #include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic #include <cassert> #include <iomanip> //do setprecision #include <ctime> #include <complex> using namespace std; #define FOR(i,b,e) for(int i=(b);i<(e);++i) #define FORQ(i,b,e) for(int i=(b);i<=(e);++i) #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i) #define REP(x, n) for(int x = 0; x < (n); ++x) #define ST first #define ND second #define PB push_back #define PF push_front #define MP make_pair #define LL long long #define ULL unsigned LL #define LD long double #define pii pair<int,int> #define pll pair<LL,LL> #define vi vector<int> #define vii vector<vi> const double pi = 3.14159265358979323846264; const int mod=1000000007; int main(){ //cin.tie(0); //ios::sync_with_stdio(false); //std::cout << std::fixed; //std::cout << std::setprecision(12); //std::cout << std::defaultfloat; int n,k; cin>>n>>k; vector<int> a(n); vector<int> in(n,0); vector<int> used(n,0); int d[101001]={}; int ans=0; FOR(i,0,n){ cin>>a[i]; a[i]--; if(i==0){ if(a[i]!=0){ ans++; a[i]=0; } continue; } //g[i].PB(a[i]); in[a[i]]++; } queue<int> q; used[0]=1; FOR(i,1,n){ if(in[i]==0)q.push(i); } while (q.size()) { int nw=q.front(); q.pop(); int nd=d[nw]; //cerr<<nw<<" "<<nd<<endl; if(used[nw])continue; used[nw]=1; if(nd>=k-1&&a[nw]!=0){ ans++; }else{ if(a[nw]!=0)d[a[nw]]=max(d[a[nw]],nd+1); } in[a[nw]]--; if(in[a[nw]]==0)q.push(a[nw]); } cout<<ans<<endl; return 0; }
#include <stdio.h> int main() { int n, row, col; scanf("%d", &row); scanf("%d", &col); scanf("%d", &n); int temp; int count = 0; if (row > col) { temp = row; } else { temp = col; } for (int i = 0; i < n; i = i + temp) { count++; } printf("%d\n", count); return 0; }
0
#include <iostream> #include <atcoder/all> using namespace std; using namespace atcoder; int main() { int N, Q; cin >> N >> Q; fenwick_tree<long long> t(N); for (int i = 0; i < N; ++i) { long long a; cin >> a; t.add(i, a); } for (int i = 0; i < Q; ++i) { long long q, arg0, arg1; cin >> q >> arg0 >> arg1; if (q == 0) { t.add(arg0, arg1); } else { cout << t.sum(arg0, arg1) << endl; } } return 0; }
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<queue> #include<vector> #include<ctime> #include<map> #include<bitset> #include<set> #include<assert.h> #include<chrono> #include<random> #define LL long long #define mp(x,y) make_pair(x,y) #define pll pair<long long,long long> #define pii pair<int,int> #define SZ(x) ((int)x.size()) using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); inline LL read() { LL f=1,x=0;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int stack[20]; template<typename T>inline void write(T x) { if(x<0){putchar('-');x=-x;} if(!x){putchar('0');return;} int top=0; while(x)stack[++top]=x%10,x/=10; while(top)putchar(stack[top--]+'0'); } template<typename T>inline void pr1(T x){write(x);putchar(' ');} template<typename T>inline void pr2(T x){write(x);putchar('\n');} template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;} template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;} const int MAXN=200005; int n,E1,E2; struct DSU { int rt[MAXN]; void init(){for(int i=1;i<=n;i++)rt[i]=i;} int findrt(int x){return rt[x]==x?rt[x]:rt[x]=findrt(rt[x]);} void merge(int x,int y){rt[findrt(x)]=findrt(y);} }A,B; map<int,int> mp[MAXN]; int main() { n=read();E1=read();E2=read(); A.init();B.init(); for(int i=1;i<=E1;i++) { int x=read(),y=read(); A.merge(x,y); } for(int i=1;i<=E2;i++) { int x=read(),y=read(); B.merge(x,y); } for(int i=1;i<=n;i++)mp[A.findrt(i)][B.findrt(i)]++; for(int i=1;i<=n;i++)pr1(mp[A.findrt(i)][B.findrt(i)]);puts(""); return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> P; typedef long long ll; #define int ll main(){ int a,b,c; cin >> a >> b >> c; if(a<c){ if(c<b) cout << "Yes" << endl; else cout << "No" << endl; }else{ if(c>b) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
#include <iostream> using namespace std; int main(void){ int a, b, c; cin >> a >> b >> c; cout << ((c-a)*(b-c)>0?"Yes":"No") << endl; return 0; }
1
#define _GIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(v) v.begin(), v.end() using namespace std; using ll = long long; using P = pair<int, int>; const double EPS = 1e-10; bool rec(int n, vector<int>& num, vector<bool>& isPlus) { // ベースケース if (n == (int) isPlus.size()) { int ans = num[0]; rep(i, (int) isPlus.size()) { if (isPlus[i]) { ans += num[i + 1]; } else { ans -= num[i + 1]; } } if (ans == 7) { cout << num[0]; rep(i, (int) isPlus.size()) { if (isPlus[i]) { cout << '+' << num[i + 1]; } else { cout << '-' << num[i + 1]; } } cout << "=7" << endl; return true; } return false; } // 再帰ステップ isPlus[n] = true; if (rec(n + 1, num, isPlus)) return true; isPlus[n] = false; if (rec(n + 1, num, isPlus)) return true; return false; } int main(void) { int ABCD; cin >> ABCD; vector<int> num(4); rep(i, 4) { num[i] = ABCD % 10; ABCD /= 10; } reverse(num.begin(), num.end()); vector<bool> isPlus(3, true); rec(0, num, isPlus); return 0; }
#include <iostream> #include <vector> #include <algorithm> class Baseball { private: int out; int runner; int score; public: //constructor Baseball() { out = 0; runner = 0; score = 0; } //getter int getOut() { return out; } int getRunner() { return runner; } int getScore() { return score; } //input OUT void execOut() { ++out; } //input HIT void execHit() { if(runner == 3)++score; else ++runner; } //input HOMERUN void execHomerun() { score += runner + 1; runner = 0; } }; int main(){ int dataSetNum; std::cin >> dataSetNum; std::vector< Baseball > baseball; baseball.resize(dataSetNum); for(int i = 0; i < dataSetNum; ++i){ while(baseball[i].getOut() != 3){ //input std::string tmp; std::cin >> tmp; if(tmp == "OUT")baseball[i].execOut(); else if(tmp == "HIT")baseball[i].execHit(); else if(tmp == "HOMERUN")baseball[i].execHomerun(); } } //output std::for_each(baseball.begin(), baseball.end(), [](Baseball x) { std::cout << x.getScore() << std::endl; } ); return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll #define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++) #define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++) #define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--) #define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--) #define MP(a, b) make_pair((a), (b)) #define PB(a) push_back((a)) #define all(v) (v).begin(), (v).end() #define PERM(v) next_permutation(all(v)) #define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end()) #define CIN(type, x) type x;cin >> x #define TRUE__ "Yes" #define FALSE__ "No" #define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;} #define RS resize #define CINV(v, N) do {\ v.RS(N);\ rep(i, N) cin >> v[i];\ } while (0); #define RCINV(v, N) do {\ v.RS(N);\ rrep(i, N) cin >> v[i];\ } while (0); #define MOD 998244353 template<class T> inline T GET() { T x; cin >> x; return x; } void init(); void solve(); signed main() { init(); solve(); } ll dp[2020][2020]; ll sum; int K, N; void init() { cin >> K >> N; rep(i, K) { dp[N-1][i] = 1; } rrep(i, N-1) { ll a = 0; rrep(j, K) { a += dp[i+1][j]; a %= MOD; dp[i][j] = a; } } rep(i, K) { sum += dp[0][i]; sum %= MOD; } } struct comb { #define MOD_COMB MOD vector<ll> fact; vector<ll> facti; comb(int n) { init(n); } void init(int n) { fact.resize(n); facti.resize(n); fact[0] = 1; for (int i = 1; i < n; i++) { fact[i] = fact[i-1] * i % MOD_COMB; } facti[n-1] = po(fact[n-1], MOD_COMB - 2); for (int i = n-2; i >= 0; i--) { facti[i] = facti[i+1] * (i + 1) % MOD_COMB; } } ll nCr(int a, int b) { return (fact[a] * facti[b] % MOD_COMB) * facti[a-b] % MOD_COMB; } private: ll po(ll next, int cnt) { ll res = 1; if (cnt == 0) return 1; if (cnt & 1) res = res * next % MOD_COMB; return res * po(next * next % MOD_COMB, cnt >> 1) % MOD_COMB; } }; void solve() { vector<ll> res; comb co(2020); if (K == 1) { cout << 0 << endl; return; } int i = 0; reps(cnt, 3, K+3) { ll hugo = 1; ll ans = 0; rep(j, i+1) { ans += hugo * co.nCr(i+1, j+1) * dp[j*2+1][0]; ans %= MOD; hugo *= -1; } res.PB(ans); res.PB(ans); cnt++; i++; } if (K%2) res.pop_back(); rep(i, res.size()) { cout << (sum - res[i] + MOD) % MOD << endl; } rrep(i, res.size()-1) { cout << (sum - res[i] + MOD) % MOD << endl; } }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define ll long long const int md=998244353; const int mx=4005; int n,k; ll exp(ll b, ll n){ ll res = 1; for(;n;n>>=1,(b*=b)%=md)if(n&1)(res*=b)%=md; return res; } ll fact[mx]={1},invf[mx]; inline void init(int n){ for(int i=1;i<=n;i++) fact[i]=(fact[i-1]*i)%md; invf[n]=exp(fact[n],md-2); for(int i=n;i>0;i--) invf[i-1]=(invf[i]*i)%md; } inline ll comb(int a,int b){return fact[a]*invf[a-b]%md *invf[b]%md;} inline ll nkcom(int n,int k){return comb(n+k-1,n);} inline ll calc(int n,int k,int t){ ll ret=0; rep(i,t+1) ret=(ret+nkcom(n-i,k-t*2+i)*comb(t,i)%md*exp(2,i))%md; return ret; } int main(){ scanf("%d%d",&k,&n); init(k+n); for(int i=1;i<2*k;i++){ int t=min(i,2*k-i); printf("%lld\n",t&1 ?(calc(n-1,k-1,t/2)+calc(n,k-1,t/2))%md:calc(n,k,t/2)); } }
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 pair<pii,pii> P; 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<<62; 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) #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}; struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; #define umh unordered_map<ll,ll,custom_hash> 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 lcm(ll a,ll b){ ll c=gcd(a,b); return a*b/c; } 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; now%=md; 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); int n;cin>>n; ll a[n]; rep(i,0,n)cin>>a[i]; if(a[0]>0){ cout<<-1<<endl; return 0; } ll ans=0; rep(i,1,n){ if(a[i]>a[i-1]+1){ cout<<-1<<endl; return 0; } else if(a[i]<a[i-1]+1){ ans+=a[i-1]; } } ans+=a[n-1]; cout<<ans<<endl; }
#include <iostream> #include <cstdio> using namespace std; int S[1000000], cnt = 0; int sor(int n, int g){ do{ g = (g - 1) / 3; for(int i = g;i < n;i++){ int j = i - g, v = S[i]; while(j >= 0 && v < S[j]){ //printf("*%d*", j); S[j + g] = S[j]; j -= g, cnt++; } S[j + g] = v; } }while(g != 1); return 0; } int main(){ int g = 1, n, num = 0; scanf("%d", &n); for(int i= 0;i < n;i++)scanf("%d", &S[i]); while(g <= n)g = g * 3 + 1, num++; printf("%d\n", num); for(int i= g;i != 1;){ if(i != g)printf(" "); i = (i - 1) / 3; printf("%d", i); } puts(""); sor(n, g); printf("%d\n", cnt); for(int i= 0;i < n;i++)printf("%d\n", S[i]); return 0; }
0
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define fi first #define se second #define rep(i,n) for(int i=0;i<(n);i++) int main(){ ll n,t,x; cin>>n>>t; ll px=-1,ans=0; for(ll i=0;i<n;i++){ cin>>x; ans+=t; if(px!=-1) ans-=max((ll)0,px-x+t); px=x; } cout<<ans; }
#include <bits/stdc++.h> // #undef DEBUG // Uncomment this line to forcefully disable debug print. #if DEBUG template <typename T> void debug(T value) { std::cerr << value; } template <typename T, typename... Ts> void debug(T value, Ts... args) { std::cerr << value << ", "; debug(args...); } #define dbg(...) \ do { \ cerr << #__VA_ARGS__ << ": "; \ debug(__VA_ARGS__); \ cerr << " (L" << __LINE__ << ")" << endl; \ } while (0) #else #define dbg(...) #endif void read_from_cin() {} template <typename T, typename... Ts> void read_from_cin(T& value, Ts&... args) { std::cin >> value; read_from_cin(args...); } #define in(type, ...) \ type __VA_ARGS__; \ read_from_cin(__VA_ARGS__); template <typename T> void write_to_cout(const T& value) { std::cout << value << std::endl; } template <typename T, typename... Ts> void write_to_cout(const T& value, const Ts&... args) { std::cout << value << ' '; write_to_cout(args...); } #define out(...) write_to_cout(__VA_ARGS__); #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using ll = long long; using namespace std; bool Less(const string& a, const string& b) { if (a.size() != b.size()) return a.size() < b.size(); return a < b; } int main() { const vector<int> cost = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6}; in(int, n, m); vector<int> a(m); rep(i, m) cin >> a[i]; vector<string> dp(n + 1); for (int i = 0; i <= n; ++i) { for (int j = 0; j < m; ++j) { int k = i - cost[a[j]]; if (k < 0 || dp[k] == "" && k != 0) continue; string d = char('0' + a[j]) + dp[k]; if (Less(dp[i], d)) dp[i] = d; } } out(dp[n]); }
0
#include<iostream> #include<algorithm> using namespace std; int main (void) { string s; cin>>s; if(s=="SUN")cout<<"7"<<endl; if(s=="MON")cout<<"6"<<endl; if(s=="TUE")cout<<"5"<<endl; if(s=="WED")cout<<"4"<<endl; if(s=="THU")cout<<"3"<<endl; if(s=="FRI")cout<<"2"<<endl; if(s=="SAT")cout<<"1"<<endl; }
#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; //#define int long long #define DBG 1 #define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;} #define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;} #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--) #define each(it,c) for(auto it=(c).begin();it!=(c).end();it++) #define all(c) c.begin(),c.end() const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)(1e9 + 7); const double EPS = 1e-10; signed main() { int n; cin >> n; cin.ignore(); while (n--) { string s; getline(cin, s); for (int i = 0; i + 6 < s.size(); i++) { if (s.substr(i, 7) == "Hoshino")s[i + 6] = 'a'; } cout << s << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { string x, y, z; bool s = false; bool t = false; cin >> x >> y >> z; if(x[x.size()-1] == y[0]){s = true;} if(y[y.size()-1] == z[0]){t = true;} if(s*t == 1){cout << "YES" << endl;} else{cout << "NO" << endl;} }
#if 1 #include <bits/stdc++.h> #else #include "../../bits/stdc++.h" #endif #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 REP(i,n) FOR(i,0,(n)) #define RREP(i,n) RFOR(i,0,(n)) using namespace std; typedef pair<int, int> P; #define pb push_back #define mp make_pair #define ft first #define sd second int m, nin, nax; int p[202]; bool input(){ cin>>m>>nin>>nax; REP(i, m)cin>>p[i]; return m; } void solve(){ int s=0, b=0; FOR(i, nin-1, nax) { if(p[i]-p[i+1]>=s){ b=i+1; s=p[i]-p[i+1]; } } cout<<b<<endl; } int main(){ cin.tie(0); while (input()){ solve(); } return 0; }
0
#include <bits/stdc++.h> #define exrep(i, a, b) for(long long i = a; i <= b; i++) #define rep(i,n)for(long long i=0;i<(long long)(n);i++) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; 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; } const ll MOD=1e9+7; const ll INF=1e18; const int MAX=510000; const double pi=acos(-1); int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; ll modpow(ll a, ll n){ if(n==0)return 1; if(n%2==0){ ll t=modpow(a,n/2); return t*t%MOD; } return a*modpow(a,n-1)%MOD; } ll modinv(ll a){ return modpow(a,MOD-2); } 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; } struct UnionFind { vector<int> par; // 親ノード vector<int> rank; // ランク UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n); rank.resize(n); for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; return true; } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); COMinit(); ll n; cin >> n; vector<ll>a(n); rep(i,n) cin >> a[i]; if(a[0]!=0){ cout<<-1<<endl; return 0; } rep(i,n-1){ if(a[i]+1<a[i+1]){ cout << -1 << endl; return 0; } } ll cnt=0; rep(i,n-1){ if(a[i+1]==a[i]+1)cnt++; else cnt+=a[i+1]; } cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; vector<int> a(n+2); a[0] = 0; a[n+1] = 0; int sum = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += abs(a[i] - a[i-1]); } sum += abs(a[n+1] - a[n]); for (int i = 1; i <= n; i++) { int diff = abs(a[i+1] - a[i]) + abs(a[i] - a[i-1]) - abs(a[i+1] - a[i-1]); cout << sum - diff << endl; } return 0; }
0
#include<bits/stdc++.h> using namespace std; // macro #define rep(i,n) for(int i=0;i<n;i++) #define ll long long #define all(v) v.begin(), v.end() // code starts #define MOD 1000000007 int main() { int h,w,k;cin>>h>>w>>k; vector<vector<ll>> dp(h+1,vector<ll>(w,0)); dp[0][0]=1; int i,j,l; for(i=1;i<=h;i++) { for(j=0;j<(1<<(w-1));j++) { bool warp=false; for(l=0;l<w-2;l++) { if((j&(1<<l))&&(j&(1<<(l+1))))warp=true; } if(warp)continue; for(l=0;l<w;l++) { bool con=false; if(l>0&&(j&(1<<(l-1)))) { dp[i][l]+=dp[i-1][l-1]; dp[i][l]%=MOD; con=true; } if(l<w-1&&(j&(1<<l))) { dp[i][l]+=dp[i-1][l+1]; dp[i][l]%=MOD; con=true; } if(!con) { dp[i][l]+=dp[i-1][l]; dp[i][l]%=MOD; } } } } cout<<dp[h][k-1]<<endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; const int MOD = 1e9 + 7; int H, W, K; vector<int> fib; ll ans; void input() { cin >> H >> W >> K; } int solve(int n) { if (n < 0) return 1; return fib[n]; } int main() { input(); fib = vector<int>(W); fib[0] = 1; fib[1] = 2; for (int i = 2; i < W; i++) fib[i] = fib[i-1] + fib[i-2]; vector<ll> w1, w2; w1 = vector<ll>(W, 0); w1[0] = 1; rep(i, H) { w2 = vector<ll>(W, 0); for (int j = 0; j < W; j++) { if (j > 0) w2[j-1] = (w2[j-1] + w1[j] * solve(j-2) * solve(W-j-2)) % MOD; w2[j] = (w2[j] + w1[j] * solve(j-1) * solve(W-j-2)) % MOD; if (j < W - 1) w2[j+1] = (w2[j+1] + w1[j] * solve(j-1) * solve(W-j-3)) % MOD; } w1 = w2; } cout << w1[K-1] << endl; }
1
#include<iostream> #include<map> #include<string> using namespace std; typedef pair<string, string> P; P next_word(string sentence) { if (sentence.empty()) return make_pair(string(""), string("")); if (sentence[0] == ' ' || sentence[0] == '.') { return make_pair("", sentence.substr(1)); } else { P recur = next_word(sentence.substr(1)); return make_pair(sentence[0] + recur.first, recur.second); } } bool acceptable(string sentence) { P p = next_word(sentence); while (! p.first.empty() ) { if (p.first == "this" || p.first == "the" || p.first == "that") return true; p = next_word(p.second); } return false; } char slip(char c) { if (c < 'a' || 'z' < c) return c; string alphabet = "abcdefghijklmnopqrstuvwxyza"; int index = (int)(c - 'a'); return alphabet[index + 1]; } char slip(char c, int n) { for (int i = 0; i < n; i++) c = slip(c); return c; } string slip(string code, int n) { string val; for (int i = 0, len = code.length(); i < len; i++) val += slip(code[i], n); return val; } string decode(string code) { for (int i = 1; i < 27; i++) { string sentence = slip(code, i); if (acceptable(sentence)) return sentence; } return ""; } int main() { string code; while ( getline(cin, code) ) cout << decode(code) << endl; }
#include <iostream> #include <string> using namespace std; int main() { string stro, str; while(getline(cin, stro)){ for(int i = 0; i < 26; i++){ str = stro; for(int j = 0; j < stro.length(); j++){ if(str[j] >= 'a' && str[j] <= 'z') if(str[j] + i > 'z') str[j] += i - 26; else str[j] += i; } if(str.find("the") != string::npos || str.find("this") != string::npos || str.find("that") != string::npos) cout << str << endl; } } }
1
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; typedef map<ll,ll>::iterator itll; typedef long double ld; typedef map<ll,ll> mapll; #define con continue #define pb push_back #define fi first #define se second #define fr front() #define INF 1000000000000000000 #define all(vl) vl.begin(),vl.end() #define m_p make_pair #define sz(a) sizeof(a) #define forn(mp,it) for(it = mp.begin();it!=mp.end();it++) #define FOR(i,a,n) for(int i=a;i<n;i++) #define FORE(i,a,n) FOR(i,a,n+1) #define Endl endl #define eNdl endl #define enDl endl #define endL endl int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll k; cin>>k; vector<ll> vl; string s = "~abcdefghijklmnopqrstuvwxyz"; if(k<=26) { cout<<s[k]<<endl; return 0; } while(k>=26) { ll yu = k%26; k/=26; if(yu == 0) { yu = 26; k--; } vl.pb(yu); } if(k>0) vl.pb(k); reverse(all(vl)); FOR(i,0,vl.size()) { if(vl[i]>0)cout<<s[vl[i]]; else cout<<"z"; } cout<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int, int> ii; typedef map<int, int> MPII; typedef set<int> SETI; const int mxN = 2e5; const ld pi = 4.0 * atanl(1.0); const int iinf = 1e9 + 10; const int inf = 1e18 + iinf + 10; const int mod = 1000000007; const ld prec = .000001; #define F first #define S second #define pb push_back #define mp make_pair #define all(c) c.begin(), c.end() #define rall(c) c.end(), c.begin() int n, m, t, a[mxN]; vi v; void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); } int main() { fast(); string s; cin >> s; int ans = mxN; for (int i = 0; i < s.length() - 2; i++) { int diff = abs( ((s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0')) - 753); ans = min(ans, diff); } cout << ans; return 0; }
0
#include<iostream> using namespace std; int main(){ int n, q, count = 0; cin >> n; long int S[n]; for(int i = 0; i < n; i++) cin >> S[i]; cin >> q; while(q--){ long int T; cin >> T; int i = n; while(i--){ if(S[i] == T){ count++; break; } } } cout << count << endl; }
#include<iostream> using namespace std; #include<stdio.h> class dice { private: int temp_t; int temp_e; int temp_s; int temp_b; int temp_w; int temp_n; public: int top; int east; int south; int bottom; int west; int north; dice(int _top, int _east, int _south, int _bottom, int _west, int _north); void roll(char dir); ~dice(); }; dice::dice(int _top, int _east, int _south, int _bottom, int _west, int _north){ top = _top; east = _east; south = _south; bottom = _bottom; west = _west; north = _north; } void dice::roll(char dir){ switch (dir){ case 'N': temp_n = north; temp_t = top; temp_s = south; temp_b = bottom; north = temp_t; bottom = temp_n; south = temp_b; top = temp_s; break; case 'S': temp_n = north; temp_t = top; temp_s = south; temp_b = bottom; north = temp_b; bottom = temp_s; south = temp_t; top = temp_n; break; case 'E': temp_e = east; temp_t = top; temp_w = west; temp_b = bottom; east = temp_t; bottom = temp_e; west = temp_b; top = temp_w; break; case 'W': temp_e = east; temp_t = top; temp_w = west; temp_b = bottom; east = temp_b; bottom = temp_w; west = temp_t; top = temp_e; break; default: cout << "Unknown Roll Command. Quit." << endl; break; } } dice::~dice(){} int main(){ char ch; int N, T, E, W, B, S; cin >> T >> S >> E >> W >> N >> B; scanf("%c", &ch); dice diceA(T, E, S, B, W, N); for(int i = 0; i < 100; i++) { scanf("%c", &ch); if(ch == '\n') break; diceA.roll(ch); } cout << diceA.top << endl; }
0
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <vector> #include <queue> using namespace std; int a[200005], b[200005]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); } for (int i = n; i >= 1; --i) { scanf("%d", &b[i]); } bool flag = true; for (int i = 1; i <= n; ++i) { if (a[i] == b[i]) { flag = false; for (int j = 1; j <= n; ++j) { if (b[j] != a[i] && b[i] != a[j]) { swap(b[j], b[i]); flag = true; break; } } if (!flag) { break; } } } if (flag) { printf("Yes\n"); for (int i = 1; i <= n; ++i) { printf("%d ", b[i]); } } else { printf("No\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) typedef long long Int; const Int INF = 1e18; int main() { Int N; cin >> N; vector<Int> A(N); rep(i,N) cin >> A[i]; vector<Int> dp0(N, -INF), dp1(N, -INF); dp0[0] = 0; dp1[0] = A[0]; dp0[1] = max(A[0], A[1]); for(int i = 2; i<N; i++) { if (i % 2 == 1) { dp0[i] = max(dp1[i-1], A[i]+dp0[i-2]); } else { dp0[i] = max(dp0[i-1], A[i] + dp0[i-2]); dp1[i] = A[i] + dp1[i-2]; } } cout << dp0[N-1] << endl; }
0
#include <bits/stdc++.h> using namespace std; class Fruit { public: string name; double efficiency; Fruit(string _name, double _efficiency): name(_name), efficiency(_efficiency) { } }; int main() { int N; while(cin >> N, N) { vector<Fruit> fruits; for(int n = 0; n < N; ++n) { string name; cin >> name; int seedCost; cin >> seedCost; int aTime = 0; int aFromLeafTime = 0; for(int i = 0; i < 5; ++i) { int t; cin >> t; aTime += t; if(i > 2) aFromLeafTime += t; } int nfruit; cin >> nfruit; int aFruitPrice; cin >> aFruitPrice; int ngrow; cin >> ngrow; int tTime; tTime = aTime + aFromLeafTime * (ngrow - 1); int price; price = aFruitPrice * nfruit * ngrow; int income; income = price - seedCost; double efficiency; efficiency = (double)income / (double)tTime; Fruit fruit(name, efficiency); fruits.push_back(fruit); } sort(fruits.begin(), fruits.end(), [](Fruit left, Fruit right) { if(left.efficiency == right.efficiency) return left.name < right.name; return left.efficiency > right.efficiency; }); for(int i = 0; i < N; ++i) cout << fruits[i].name << endl; //cout << fruits[i].name << " " << fruits[i].efficiency << endl; cout << '#' << endl; } return 0; }
#include<iostream> #include<algorithm> using namespace std; struct CROPS{ string name; double total; }; int main(){ int i,j,n; double p,a,b,c,d,e,f,s,m,efficient; CROPS crop[51]; while(1){ cin >> n; if(n==0)break; for(i = 0; i < n; i++){ cin >> crop[i].name >> p >> a >> b >> c >> d >> e >> f >> s >> m; efficient=(f*s*m-p)/(a+b+c+(d+e)*m); crop[i].total=efficient; } for(i = 0; i < n; i++){ for(j = 0; j < n-1; j++){ if(crop[j].total < crop[j+1].total){ swap(crop[j],crop[j+1]); } } } for(i = 0; i < n; i++){ for(j = 0; j < n-1; j++){ if(crop[j].total == crop[j+1].total && crop[j].name>crop[j+1].name){ swap(crop[j],crop[j+1]); } } } for(i = 0; i < n; i++){ cout << crop[i].name << endl; } cout << "#" << endl; } return 0; }
1
#include<stdio.h> main(){ int i,d,s; while(scanf("%d",&d)!=EOF){ s=0; for(i=0;i<600/d;i++){ s+=(d*((d*i)*(d*i))); } printf("%d\n",s); } return 0; }
#include<bits/stdc++.h> using namespace std; int main(void){ int n; while (cin >> n, n){ vector<int> dp(n + 5); dp[0] = 1; dp[1] = 1; dp[2] = 2; dp[3] = 4; for (int i = 4; i <= n; i++){ dp[i] = dp[i - 3] + dp[i - 2] + dp[i - 1]; } cout << (((dp[n] + 9) / 10) + 364) / 365 << endl; } return 0; }
0
//include //------------------------------------------ #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> using namespace std; //conversion //------------------------------------------ inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} //math //------------------------------------------- template<class T> inline T sqr(T x) {return x*x;} //typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<long, long> PLL; typedef long long LL; //container util //------------------------------------------ #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) //repetition //------------------------------------------ #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) //constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); //clear memory #define CLR(a) memset((a), 0 ,sizeof(a)) int mp[22][22]; int main(){ int N,M; int x[]={0,1,0,-1}; int y[]={1,0,-1,0}; while(cin>>N){ if(N==0)break; CLR(mp); REP(i,N){ int tx,ty; cin>>tx>>ty; mp[tx][ty]++; } cin>>M; int nx=10,ny=10; int res=0; REP(k,M){ char d;int l; cin>>d>>l; int rx,ry; if(d=='N'){ rx=x[0]*l; ry=y[0]*l; }else if(d=='E'){ rx=x[1]*l; ry=y[1]*l; }else if(d=='S'){ rx=x[2]*l; ry=y[2]*l; }else{ rx=x[3]*l; ry=y[3]*l; } if(rx<0||ry<0){ for(int i=0;i>=rx;i--)for(int j=0;j>=ry;j--){ if(mp[nx+i][ny+j]!=0){ mp[nx+i][ny+j]=0; //cout<<"!"<<nx+i<<" "<<ny+j<<endl; res++; } } }else{ for(int i=0;i<=rx;i++)for(int j=0;j<=ry;j++){ if(mp[nx+i][ny+j]!=0){ mp[nx+i][ny+j]=0; //cout<<"!"<<nx+i<<" "<<ny+j<<endl; res++; } } } nx+=rx;ny+=ry; } if(res==N)cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }
#include<stdio.h> int main(void) { for(;;){ int houkosu={0}; int comkosu={0}; int hou[21][21]={{0},{0}}; int zahyo[21][21]={{0},{0}}; int mypox={10}; int mypoy={10}; int x={0},y={0}; int i={0},j={0}; char dire={0}; int dis={0}; int hantei={0}; char dir[31]={0}; int di[31]={0}; scanf("%d",&houkosu); if(houkosu==0) break; for(i=0;i<houkosu;i++){ scanf("%d %d",&x,&y); hou[x][y]=1; } scanf("%d",&comkosu); hou[10][10]=0; for(i=0;i<2*comkosu;i++){ scanf("%c",&dire); dir[i/2]=dire; scanf("%d",&dis); di[(i-1)/2]=dis; } for(i=0;i<comkosu;i++){ if(dir[i]=='N'){ for(j=mypoy+1;j<=mypoy+di[i];j++){ if(hou[mypox][j]==1) hou[mypox][j]=0; } mypoy+=di[i]; }else if(dir[i]=='S'){ for(j=mypoy-1;j>=mypoy-di[i];j--){ if(hou[mypox][j]==1) hou[mypox][j]=0; } mypoy-=di[i]; }else if(dir[i]=='E'){ for(j=mypox+1;j<=mypox+di[i];j++){ if(hou[j][mypoy]==1) hou[j][mypoy]=0; } mypox+=di[i]; }else{ for(j=mypox-1;j>=mypox-di[i];j--){ if(hou[j][mypoy]==1) hou[j][mypoy]=0; } mypox-=di[i]; } } for(i=0;i<21;i++){ for(j=0;j<21;j++){ if(hou[i][j]!=0) hantei=1; } } if(hantei==0) puts("Yes"); else puts("No"); } return 0; }
1
#include <bits/stdc++.h> #define REP(i, n) for(long long i=0; i<n; i++) #define REPR(i, n) for(long long i=n-1; i>=0; i--) #define FOR(i, m, n) for(long long i=m; i<=n; i++) #define FORR(i, m, n) for(long long i=m; i>=n; i--) #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define VSORTR(v) sort(v.rbegin(), v.rend()); #define ALL(v) (v).begin(),(v).end() #define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); using namespace std; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<ll, ll>; const ll mod = 1e9+7; const ll inf = 1e15; int main(){FIN ll n; string s; cin>>n>>s; ll ans=mod; vll ws(1,0); vll es(1,0); ll cnt=0; FOR(i,1,n-1){ if(s[i-1]=='W') cnt++; ws.push_back(cnt); } cnt=0; FORR(i,n-2,0){ if(s[i+1]=='E') cnt++; es.push_back(cnt); } reverse(ALL(es)); // REP(i,n){ // cout<<ws[i]<<endl; // } REP(i,n){ ans = min(ans, es[i]+ws[i]); } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int a, b, ans; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> a >> b; for (int i = 0; i < 2; ++i) { if (a > b) { ans += a; --a; } else { ans += b; --b; } } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(int)(n); i++) using namespace std; using LL = long long; using P = pair<int,int>; int main(){ int H1, M1, H2, M2, K; cin >> H1 >> M1 >> H2 >> M2 >> K; int d=(H2-H1)*60+(M2-M1); cout << d-K << endl; return 0; }
#include <cstdio> #include <cctype> #include <cstring> #include <algorithm> #include <vector> #define debug(...) fprintf(stderr, __VA_ARGS__) #ifndef AT_HOME #define getchar() IO::myGetchar() #define putchar(x) IO::myPutchar(x) #endif namespace IO { static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23; inline char myGetchar() { static char buf[IN_BUF], *ps = buf, *pt = buf; if (ps == pt) { ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin); } return ps == pt ? EOF : *ps++; } template<typename T> inline bool read(T &x) { bool op = 0; char ch = getchar(); x = 0; for (; !isdigit(ch) && ch != EOF; ch = getchar()) { op ^= (ch == '-'); } if (ch == EOF) { return false; } for (; isdigit(ch); ch = getchar()) { x = x * 10 + (ch ^ '0'); } if (op) { x = -x; } return true; } inline int readStr(char *s) { int n = 0; char ch = getchar(); for (; isspace(ch) && ch != EOF; ch = getchar()) ; for (; !isspace(ch) && ch != EOF; ch = getchar()) { s[n++] = ch; } s[n] = '\0'; return n; } inline void myPutchar(char x) { static char pbuf[OUT_BUF], *pp = pbuf; struct _flusher { ~_flusher() { fwrite(pbuf, 1, pp - pbuf, stdout); } }; static _flusher outputFlusher; if (pp == pbuf + OUT_BUF) { fwrite(pbuf, 1, OUT_BUF, stdout); pp = pbuf; } *pp++ = x; } template<typename T> inline void print_(T x) { if (x == 0) { putchar('0'); return; } std::vector<int> num; if (x < 0) { putchar('-'); x = -x; } for (; x; x /= 10) { num.push_back(x % 10); } while (!num.empty()) { putchar(num.back() ^ '0'); num.pop_back(); } } template<typename T> inline void print(T x, char ch = '\n') { print_(x); putchar(ch); } inline void printStr_(const char *s, int n = -1) { if (n == -1) { n = strlen(s); } for (int i = 0; i < n; ++i) { putchar(s[i]); } } inline void printStr(const char *s, int n = -1, char ch = '\n') { printStr_(s, n); putchar(ch); } } using namespace IO; void solve() { int h1, m1, h2, m2, k; read(h1), read(m1), read(h2), read(m2), read(k); int t1 = h1 * 60 + m1, t2 = h2 * 60 + m2; print(std::max(t2 - t1 - k, 0)); } int main() { int T = 1; // read(T); while (T--) { solve(); } }
1
////////////////////////// Author ////////////////////////// Nasim Hossain Rabbi ////////////////////////// JU-CSE28 ////////////////////////// CF - imnasim3.1415 ////////////////////////// UVA - imnasim3.1415 ////////////////////////// Mail - imnasim3.1415@gmail.com #include<bits/stdc++.h> using namespace std; #define E end() #define B begin() #define sz size() #define EM empty() #define fi first #define se second #define cl clear() #define sqr(a) (a*a) #define mk make_pair #define po pop() #define pu push #define pb push_back #define pf push_front #define pob pop_back() #define pof pop_front() string en="\n"; string sp=" "; string t="hello"; string Y="YES\n"; string N="NO\n"; #define rep(i,n) for(i=0;i<n;i++) #define Rep(i,n) for(i=1;i<=n;i++) #define per(i,n) for(i=n-1;i>=0;i--) #define peR(i,n) for(i=n;i>0;i--) #define mem(a,b) memset(a,b,sizeof(a)) #define all(cont) cont.begin(),cont.end() #define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL) #define pi 3.1415926535897932384626433832795 #define vi vector<long long> #define vs vector<string> #define MX LLONG_MAX #define MN LLONG_MIN #define MOD 1000000007 #define vp(vi,x) cin>>x; vi.pb(x); #define bsearch(a,x) binary_search(all(a),x) #define LB(a,x) (lower_bound(all(a),x)-a.B) #define UB(a,x) (upper_bound(all(a),x)-a.B) typedef long long LL; typedef long double LD; typedef unsigned long long ULL; bool isprm(LL a){if(a==1)return false; for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;} bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;} bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;} int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;} LL ceil2(LL a,LL b){LL c=a/b; if(a%b)c++; return c; } LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;} LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;} LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;} template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);} template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));} int main() { // fast; LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0; bool f=0,ff=0;string st,s1,s2,s3; char ch; while(cin>>n>>m) { a=b=0; bool ar[n+5]; rep(i,n+5)ar[i]=0; map<LL,LL>mp; while(m--) { cin>>p>>st; if(ar[p])continue; if(st=="AC") a++,ar[p]=1; else mp[p]++; } for(auto it=mp.B;it!=mp.E;it++) { if(ar[it->fi])b+=it->se; } cout<<a<<sp<<b<<en; } return 0; }
#include<algorithm> using namespace std; #define MAXN 100000 int AC[MAXN] = {}; int WA[MAXN] = {}; int main() { int ACCount = 0; int WACount = 0; int n,m; scanf("%d %d",&n,&m); for(int i = 0; i < m; i++) { int curNum; char first, second; scanf("%d %c%c", &curNum, &first, &second); if(AC[curNum - 1] != 0) { continue; } if(first == 'A') { AC[curNum - 1] = 1; WACount += WA[curNum - 1]; ACCount += 1; } else { WA[curNum - 1] += 1; } } printf("%d %d",ACCount, WACount); }
1
#include<bits/stdc++.h> using namespace std; #define int long long typedef vector<int>vint; typedef pair<int,int>pint; typedef vector<pint>vpint; #define rep(i,n) for(int i=0;i<(n);i++) #define reps(i,f,n) for(int i=(f);i<(n);i++) #define all(v) (v).begin(),(v).end() #define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++) #define pb push_back #define fi first #define se second template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;} template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;} /* 転倒数を求める O(NlogN) */ int inversion_number(vector<int>dat){ //座標圧縮 vector<int>vs; for(int i=0;i<dat.size();i++)vs.push_back(dat[i]); sort(vs.begin(),vs.end()); vs.erase(unique(vs.begin(),vs.end()),vs.end()); for(int i=0;i<dat.size();i++) dat[i]=lower_bound(vs.begin(),vs.end(),dat[i])-vs.begin(); /* BIT 0-indexedで扱う 点kにxを加算するクエリ、区間[0,x]の和を求めるクエリがO(logN)でできる */ struct binary_indexed_tree{ vector<int>dat; void init(int n){dat=vector<int>(n+1);} binary_indexed_tree(int n):dat(n+1){} binary_indexed_tree(){} void add(int k,int x){ for(k++;k<dat.size();k+=k&-k)dat[k]+=x; } int sum(int k){ int ret=0; for(k++;k;k-=k&-k)ret+=dat[k]; return ret; } }bit(vs.size()); int ret=0; for(int i=0;i<dat.size();i++){ ret+=i-bit.sum(dat[i]); bit.add(dat[i],1); } return ret; } int N; int A[100000][3]; signed main(){ scanf("%lld",&N); rep(j,3)rep(i,N)scanf("%lld",&A[i][j]),A[i][j]--; vector<int>X[2]; int x[2]={}; rep(i,N){ if(A[i][0]%3)reverse(A[i],A[i]+3),x[i&1]++; if(A[i][0]+1!=A[i][1]||A[i][1]+1!=A[i][2]||((A[i][0]/3)&1)!=(i&1)){ puts("No"); return 0; } X[i&1].pb(A[i][0]/3); } rep(i,2)x[i^1]+=inversion_number(X[i]); puts((x[0]%2||x[1]%2)?"No":"Yes"); return 0; }
#include <bits/stdc++.h> #define NO puts("No"),exit(0) using namespace std; const int N=100010; int n,a[4][N],b[N],t[N],rev[2],swp[2]; void modify(int x){for (; x<=n; t[x]^=1,x+=x&-x);} int ask(int x){int s=0; for (; x; s^=t[x],x-=x&-x); return s;} void work() { scanf("%d",&n); for (int i=1; i<=3; i++) for (int j=1; j<=n; j++) scanf("%d",&a[i][j]); for (int i=1; i<=n; i++) { if (((a[1][i]-1)/3!=(a[2][i]-1)/3)||((a[1][i]-1)/3!=(a[3][i]-1)/3)) NO; if (a[2][i]%3!=2) NO; if (a[2][i]/3%2==i%2) NO; if (a[1][i]>a[3][i]) rev[i&1]^=1; b[i]=a[2][i]/3+1; } for (int i=n-1+(n&1); i>0; i-=2) swp[1]^=ask(b[i]),modify(b[i]); memset(t,0,sizeof(t)); for (int i=n-(n&1); i>0; i-=2) swp[0]^=ask(b[i]),modify(b[i]); if ((rev[0]!=swp[1])||(rev[1]!=swp[0])) NO; puts("Yes"); } int main() { work(); return 0; }
1
#include <algorithm> #include <iostream> #include <string> #include <cstring> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iomanip> #include <limits> #include <map> #include <queue> #include <stack> #include <vector> #define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i)) #define rep(i,n) FOR(i,0,n) #define pb push_back #define all(v) begin(v), end(v) #define debug(x) cerr << #x << ": " << x << endl #define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<i_i, int> p_i; typedef vector<int> vi; typedef vector<vector<int>> vvi; template<class T> using vv=vector<vector<T>>; typedef deque<int> di; typedef deque<deque<int>> ddi; int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, -1, 0, 1}; short d[22][22][11] ={}; int ans = 100; void dfs(i_i p, int t) { if(t > 10) return; rep(i,4){ i_i m = p; if(d[m.first+dx[i]][m.second+dy[i]][t] == 2) continue; while(1) { if(d[m.first+dx[i]][m.second+dy[i]][t] == 0) break; if(d[m.first+dx[i]][m.second+dy[i]][t] == 4) { ans = min(ans,t); break; } if(d[m.first+dx[i]][m.second+dy[i]][t] == 2) { rep(j,22) { rep(k,22) { d[j][k][t+1] = d[j][k][t]; } } d[m.first+dx[i]][m.second+dy[i]][t+1] = 1; dfs(make_pair(m.first,m.second),t+1); break; } else { m.first += dx[i], m.second += dy[i]; } } } } int main() { while(1) { int w,h; i_i s; ans = 100; memset(d,0,sizeof(d)); cin >> w >> h; if(w==0) break; FOR(j,1,h+1) { FOR(i,1,w+1) { cin >> d[i][j][1]; if(d[i][j][1] == 2){s = make_pair(i,j); d[i][j][1] = 0; } d[i][j][1] += 1; } } dfs(s,1); ans == 100? cout << -1 << endl:cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,s,n) for(ll i = (s); i < (n); i++) #define rep0(i,n) rep(i,0,n) #define rep1(i,n) rep(i,1,n+1) #define repR(i,s,n) for(ll i = (n-1); i >= (s); i--) #define repR0(i,n) repR(i,0,n) #define repR1(i,n) repR(i,1,n+1) #define BR "\n" #define SP " " #define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR; #define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR; #define fcout cout << fixed << setprecision(18) int main() { int A , B; cin >> A >> B; int MAX = max(A, B), MIN = min(A, B); if (MAX == 1) { cout << "1 2\n.#" << BR; return 0; } string S = ".#"; if (MAX == A) S = "#."; int H = 90, W = 80; vector<vector<ll>> cells(H, vector<ll>(W , 0)); int h = 1, w = 1; while(MAX > 1) { cells[h][w] = 1; if (w + 2 < W) { w += 2; } else { h += 3; w = 1; } MAX--; } if (MIN > 1) rep(i, h + 2, H) rep0(j, W) cells[i][j] = 1; else cells[H - 1][W - 1] = 1; h += 3; w = 1; MIN--; while(MIN > 0) { cells[h][w] = 0; if (w + 2 < W) { w += 2; } else { h += 3; w = 1; } MIN--; } cout << H << SP << W << BR; rep0(i, H) { rep0(j, W) { cout << S[cells[i][j]]; } cout << BR; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int r; int g; int x; cin >> r; cin >> g; x = 2*g - r; cout << x << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int R, G; cin >> R >> G; cout << G - R + G << endl; }
1
#include "bits/stdc++.h" #define REP(i,num) for(ll i=0;i<(num);++i) #define LOOP(i) while(i--) #define ALL(c) c.begin(),c.end() #define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl; #define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;} using namespace std; using ll = long long; constexpr ll atcoder_mod = 1e9+7; template<typename T=ll> T in(){T x; cin >> x; return (x);} template<typename T=ll,typename C=vector<T>> C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);} void vout(){cout << endl;} template<typename Head,typename... Tail> void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);} void out(){cout << endl;} template<typename Head,typename... Tail> void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);} int main(){ cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); string S=in<string>(); map<char,ll> M; for(auto& x:S) M[x]++; ll N=S.size(); ll A=N*(N-1LL)/2LL; for(auto& x:M){ A -= x.second*(x.second-1LL)/2LL; } out(A+1LL); return 0; }
#include <bits/stdc++.h> #include <string.h> using namespace std; int main() { int num,i,j,x,y,z; char a[20],b[20],c[20]; scanf("%s %s %s",a,b,c); x = strlen(a); y = strlen(b); z = strlen(c); if(a[x-1] == b[0] && b[y-1] == c[0]) cout << "YES"; else cout << "NO"; }
0
#define _USE_MATH_DEFINES #include<iostream> #include<vector> #include<algorithm> #include<string> #include<cmath> #include<list> #include<stack> #include<queue> #include<cctype> #include<iomanip> #include<functional> #include<numeric> #include<map> #include<set> #define EPS 1e-10 using namespace std; typedef long long llong; int rome(char g) { switch (g) { case 'I':return 1; case 'V':return 5; case 'X':return 10; case 'L':return 50; case 'C':return 100; case 'D':return 500; case 'M':return 1000; default:return -1; } } int main() { string s; while (cin >> s) { int sum = 0; int i; for (i = 0; i < s.length() -1; i++) { if (rome(s[i]) < rome(s[i + 1])) { sum += rome(s[i + 1]) - rome(s[i]); i++; //cout << "sum += " << rome(s[i + 1]) - rome(s[i]) << " "; } else { sum += rome(s[i]); //cout << "sum += " << rome(s[i]) << " "; } //cout << "sum is " << sum << endl; } if (i == s.length() - 1)sum += rome(s[i]); cout << sum << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using lint = long long; signed main(){ string s; cin >> s; int n = s.size(); for(int i = 0; i < n - 1; i++){ if(s[i] == s[i + 1]){ cout << i + 1 << " " << i + 2 << endl; return 0; } if(i < n - 2 && s[i] == s[i + 2]){ cout << i + 1 << " " << i + 3 << endl; return 0; } } cout << -1 << " " << -1 << endl; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; int main() { int a,b; cin>>a>>b; cout<<a-b+1<<endl; return 0; }
#include<iostream> #include<algorithm> #include<string> #include<vector> #include<cstring> #include<queue> #include<tuple> #include<utility> #include<map> #include<math.h> #include<iomanip> #include<stdio.h> #include<stdlib.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define FOR(i, a, b) for (int i=a; i<(b); i++) #define range(a) a.begin(), a.end() #define endl "\n" #define Yes() cout << "Yes" << endl #define No() cout << "No" << endl #define MP make_pair using Graph = vector<vector<int>>; const unsigned long long mod = 1e9 + 7; const long long INF = 1LL<<60; const int dx[4]={1,0,-1,0}; const int dy[4]={0,1,0,-1}; void chmin(long long &a, long long b) { if (a > b) a = b; } void chmax(long long &a, long long b) { if (a < b) a = b; } vector<long long> divisor(long long n) { vector<long long> ret; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); // 昇順に並べる return ret; } template<typename T> T gcd(T a, T b){ if (a%b == 0) return(b); else return(gcd(b, a%b)); } int main(void){ ios::sync_with_stdio(0); cin.tie(0); ll A, B; cin >> A >> B; ll upper = gcd<ll>(A, B); vector<ll> D = divisor(upper); vector<ll> J; FOR(i, 0, D.size() - 1) { if (binary_search(range(J), D.at(i))) continue; FOR(j, i + 1, D.size()) { if (binary_search(range(J), D.at(j))) continue; if (gcd<ll>(D.at(i), D.at(j)) != 1) { J.push_back(D.at(j)); sort(range(J)); } } } cout << D.size() - J.size() << endl; return 0; }
0
/////////////////////////////////////////////////////////////////////////// // /*Dis = size of the program || TLE. */ /* #ifndef LOCAL #pragma GCC optimize("O3") #endif */ // #pragma GCC target("avx,avx2,fma") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("unroll-loops") /* D = Too many loops */ #include <sys/time.h> // for CLOCKS_PER_SEC #include <ctime> // for clock #include <iostream> // for operator<<, ostream, istream, basic_ostream #include <unordered_set> using namespace std; #define endl '\n' typedef long long ll; ////////////////////////////////////////////////////////////////////////// /* Custom function starts here */ /* Custom function ends here: */ ////////////////////////////////////////////////////////////////////////////// int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(20); /* MAIN Code STARTS here: */ unordered_set<long long int> ss; unordered_set<long long int> dup; long n; cin >> n; for (long i = 0; i < n; i++) { ll num; cin >> num; if (ss.find(num) != ss.end()) { dup.insert(num); } else { ss.insert(num); } } if (dup.empty() == true) { cout << "YES" << endl; } else { cout << "NO" << endl; } /* MAIN Code ENDS here: */ cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; }
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; vector<int>arr(n); for(int i=0; i<n; i++) cin>>arr[i]; sort(arr.begin(),arr.end()); for(int i=1; i<arr.size(); i++){ if(arr[i-1]==arr[i]){ cout<<"NO"; return 0; } } cout<<"YES"; }
1
#include <iostream> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <map> #include <cmath> #include <string> #include <sstream> #include <iomanip> #include <complex> using namespace std; #define ll long long #define vvi vector< vector<int> > #define vi vector<int> #define All(X) X.begin(),X.end() #define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define REP(i,n) for(int i=0;i<(int)(n);i++) #define pb push_back #define pii pair<int,int> #define mp make_pair ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} int main(){ double i, j, k, l; cin >> i >> j >> k >> l; cout << fixed << setprecision(8); cout << (double)sqrt(pow(i - k, 2.0) + pow(j - l, 2.0)) << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define mp make_pair #define pb push_back #define endl "\n" #define rep(i,a,n) for(int i=a;i<n;i++) const int mod = 1e9 + 7; void solve() { int n, x, t; cin >> n >> x >> t; int s = 0, c = 0; while (s < n) { s += x; c++; } cout << c*t; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output1.txt", "w", stdout); #endif int t; t = 1; //cin >> t; while (t--) { solve(); } return 0; }
0
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define rep(i, n) for(ll i = 0; i < (n); ++i) #define FOR(i, m, n) for(ll i = m; i < (n); i++) #define all(x) (x).begin(),(x).end() using namespace std; typedef long long ll; using vi = vector<int>; using vii = vector<vi>; using pii = pair<int, int>; using vl = vector<ll>; using vll = vector<vl>; using pll = pair<ll, ll>; int main() { ll A, B, C; cin >> A >> B >> C; if(A <= B){ for(ll i = A; i <= B; i++){ if(i == C){ cout << "Yes"; return 0; } } }else{ for(ll i = A; i >= B; i--){ if(i == C){ cout << "Yes"; return 0; } } } cout << "No"; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);++i) using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { int a, b, c; cin >> a >> b >> c; if ((a < c && b > c) || (a > c && b < c)) puts("Yes"); else puts("No"); return 0; }
1
#include <iostream> #include <vector> #include <algorithm> #include <cstdio> using namespace std; int main(){ int n; while(cin >> n, n){ n++; vector<int> t(n), v(n); t[0] = 0; for(int i = 1;i < n;i++){ cin >> v[i]; t[i] = max(t[i-1]+v[i], v[i]); } cout << *max_element(t.begin()+1, t.end()) << endl; } return 0; }
#include <iostream> using namespace std; int n , now = 0; int saiki(int now){ if( now == n ) return 1; if( now > n ) return 0; int res = 0; res += saiki(now+1)+saiki(now+2)+saiki(now+3); return res; } int main(){ while(1){ int x=0; cin >> n; if( n==0 ) break; int count = saiki(0); int co = count / 10; if( count%10 > 0 ) co ++; x = co / 365 ; if(co%365>0) x ++; cout << x << endl; } }
0
#include <algorithm> #include <bitset> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define ll long long using namespace std; const int MOD = 1000000007; const long long INF = 1LL << 60; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vector<ll> a(n); bool flag = false; ll m = INF; ll cnt = 0; for (ll i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 0) { flag = true; } if (a[i] < 0) cnt++; m = min(m, abs(a[i])); } if (flag || cnt % 2 == 0) { ll num = 0; for (ll i = 0; i < n; i++) { num += abs(a[i]); } cout << num << endl; return 0; } else { ll num = 0; for (ll i = 0; i < n; i++) { num += abs(a[i]); } num -= 2 * m; cout << num << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll MOD = 1000000007; const ld PI = acos(-1); const ld EPS = 0.0000000001; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; #define rep(i, n) for(ll i=0; i<(ll)(n); i++) #define repd(i, n) for(ll i=n-1; 0<=i; i--) #define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++) #define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--) #define ALL(x) x.begin(), x.end() #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int main(){ ll n; cin >> n; vector<vector<ll>> dp(n+1, vector<ll>(2, 0)); vector<ll> a(n); rep(i, n) cin >> a[i]; rep(i, n+1) rep(j, 2) dp[i][j] = -LINF; dp[0][0] = 0; rep(i, n){ dp[i+1][0] = max(dp[i][0]+a[i], dp[i][1]-a[i]); dp[i+1][1] = max(dp[i][1]+a[i], dp[i][0]-a[i]); } cout << dp[n][0] << endl; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for (int i = 0; i < (n); ++i) #define INF (1LL<<50) #define MOD 1000000007 int main(){ ll N; cin >> N; if(N==0){ cout << 0 << endl; return 0; } string S = ""; while(N!=0){ if(N%2==0){ if(N<0){ N*=(-1); N/=2; }else{ N/=2; N*=(-1); } S+='0'; continue; } if(N<0){ N*=(-1); N+=1; N/=2; }else{ N/=2; N*=(-1); } S+='1'; } reverse(S.begin(),S.end()); cout << S << endl; return 0; }
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <vector> #include <cmath> #include <ctime> #include <queue> #include <map> #include <set> using namespace std; const int N=3e5+30,M=524288; const int MAX=2e9; const long long Mod=1e9+7; int trans[8][2]={{2,1},{4,3},{6,5},{3,3},{7,1},{2,1},{2,2},{4,4}}; long long dp[N][8]; char s[N]; int n; int main(){ //freopen("problem.in","r",stdin); //freopen("problem.out","w",stdout); scanf("%s",s+1); n=strlen(s+1); dp[0][0]=1; for(int i=0;i<n;i++){ for(int j=0;j<8;j++){ if(s[i+1]!='0'){ dp[i+1][trans[j][1]]+=dp[i][j]; dp[i+1][trans[j][1]]%=Mod; } if(s[i+1]!='1'){ dp[i+1][trans[j][0]]+=dp[i][j]; dp[i+1][trans[j][0]]%=Mod; } } } printf("%lld\n",(dp[n][1]+dp[n][3])%Mod); return 0; }
0
#include <bits/stdc++.h> using namespace std; char s[10000]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s; int n = strlen(s); for (int i = 0; i < n - 8; i++) cout << s[i]; return 0; }
#include <bits/stdc++.h> using namespace std; // types typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ld,ld> pdd; typedef vector<ll> vll; // macros #define ALL(a) a.begin(),a.end() #define SZ(a) ((int)a.size()) #define FI first #define SE second #define REP(i,n) for(int i=0;i<((int)n);i++) #define REP1(i,n) for(int i=1;i<((int)n);i++) #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define PB push_back #define EB emplace_back #define MP(a,b) make_pair(a,b) #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 Decimal fixed<<setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL // constants const int inf = 1e9; const ll linf = 1LL << 50; const double eps = 1e-10; const int MOD = 1e9 + 7; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; ll dp[2][102]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin>>s; ll n=s.size(); string ans = s.substr(0,n-8); cout<<ans<<endl; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n,i; cin >> n >> i; int ans = 1; if(n%i == 0) ans = 0; cout << ans << endl; }
/*16D8103008D 西村 悠輝 ALDS10C*/ #include<iostream> #include<string> #include<algorithm> using namespace std; string X, Y; int v[1001][1001]; int dp(string X, string Y) { int n = X.size(); int m = Y.size(); for (int i = 0; i <= n; i++) { v[i][0] = i; ///0のテーブル for (int j = 0; j <= m; j++) { v[0][j] = j; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (X[i-1] == Y[j-1]) { v[i][j]= v[i-1][j-1]; } else { int y = min(v[i][j - 1] + 1, v[i - 1][j] + 1); if (y > v[i - 1][j - 1] + 1) { v[i][j] = v[i - 1][j - 1] + 1; }else{ v[i][j] = y; } } } } return v[n][m]; } int main(void) { cin >> X >> Y; int ans = dp(X, Y); cout << ans << endl; } /* acac acm 2 */
0
/* 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) { string s; cin>>s; if(s=="SUN")cout<<7; else if(s=="MON")cout<<6; else if(s=="TUE")cout<<5; else if(s=="WED")cout<<4; else if(s=="THU")cout<<3; else if(s=="FRI")cout<<2; else if(s=="SAT")cout<<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; typedef long long ll; #define pi 2*acos(0.0) int main(void) { //ios_base::sync_with_stdio(false); //cin.tie(0); // cout.tie(0); set<ll>s; int n; cin>>n; bool flag = true; while(n--) { ll x; cin>>x; if(s.count(x)>0) { flag = false; } s.insert(x); } if(flag) { cout<<"YES"<<endl; } else { cout<<"NO"<<endl; } }
0
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) #define REPR(i, n) for(int i = n; i >= 0; i--) #define FOR(i, m, n) for(int i = m; i < n; i++) #define ALL(obj) (obj).begin(), (obj).end() #define INF 1e9 typedef long long ll; int main() { string S; cin >> S; vector<int> alpha(26,0); REP(i,S.size()){ alpha[S[i]-'a']++; } for (char a='a'; a<='z';a++){ if(alpha[a-'a']==0){ cout << a << endl; return 0; } } cout << "None" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<int>>; #define ll long long #define _GLIBCXX_DEBUG const ll MOD = 1000000007; const ll Mod = 998244353; const int MAX = 510000; const double PI = 3.14159265358979; const vector<int> dx = {1, 0}; const vector<int> dy = {0, 1}; int main() { string A; cin >> A; map<char, ll> z; for (int i=0; i<(int)A.size(); i++) { if (z.count(A[i])) z[A[i]]++; else z[A[i]] = 1; } ll num = 0; for (auto p: z) { auto value = p.second; num += value*(value-1)/2; } cout << (ll)A.size()*(A.size()-1)/2-num+1 << endl; return 0; }
0
#include<iostream> using namespace std; int main () { int n, a, p, k; cin >> n; a = n / 100; k = a * 100 + a * 10 + a; p = (a + 1) * 100 + (a + 1) * 10 + a + 1; if(n <= k) cout << k; else cout << p; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll ; typedef double db; const double pi = 3.141592654; #define pb push_back #define forab(i,a,b) for(int i=(a);i<=(b);i++) #define CIN ios_base::sync_with_stdio(0); cin.tie(0) #define pcase(z,x) printf("Case %ld: %lld\n",z,x) #define nw "\n" int main(void) { CIN; ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0; string s; ll a,b; cin>>a>>b; cin>>s; l=s.size(); if(s[a]=='-')x=1; for(ll i=0;i<l;i++){ if(i==a)continue; if(!(s[i]>='0'&&s[i]<='9'))return cout<<"No",0; } if(x==1)cout<<"Yes"; else cout<<"No"; }
0
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) #define sz(x) int(x.size()) typedef long long ll; const int inf = 100100100; //conbinatin (2002,2) = int main(){ ll n,y; cin >> n >> y; rep(i,n+1){ rep(j,n+1-i){ int k = n-i-j; if(10000*i+5000*j+1000*k == y) { cout << i << " " << j << " " << k << endl; return 0; } } } cout << "-1 -1 -1" << endl; }
#include <bits/stdc++.h> #include <iostream> #include <queue> #include <stack> #include <vector> #include <string> #include <set> #include <map> #include <random> #define rep(i,n) for (int i = 0; i < (n); ++i) #define repp(i,n,m) for (int i = m; i < (n); ++i) #define repl(i,n) for (long long i = 0; i < (n); ++i) #define reppl(i,n,m) for (long long i = m; i < (n); ++i) using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; using PL = pair<long long, long long>; using Pxy = pair<double, double>; using T = tuple<int, int, bool>; const int INF = 1001001007; const int mod = 1000000007; const int MOD = 998244353; const ll inf = 1e18; template <typename AT> void printvec(vector<AT> &ar){ rep(i,ar.size()-1) cout << ar[i] << " "; cout << ar[ar.size()-1] << endl; } template <typename Q> void printvvec(vector<vector<Q>> &ar){ rep(i,ar.size()){ rep(j,ar[0].size()-1) cout << ar[i][j] << " "; cout << ar[i][ar[0].size()-1] << endl; } } template <typename S> bool range(S a, S b, S x){ return (a <= x && x < b); } void yes(int n){ cout << "Yes" << endl; } void no (int n){ cout << "No" << endl; } ll cel (ll a, ll b){ if (a % b == 0) return a / b; else return a / b + 1; } int main() { ll n, a, b, c, d, e; cin >> n >> a >> b >> c >> d >> e; cout << cel(n,min({a,b,c,d,e})) + 4LL << endl; }
0
#include <iostream> #include <math.h> int main() { int x; std::cin >> x; std::cout << int(pow(x, 3)) << std::endl; return 0; }
#include <iostream> using namespace std; int main(){ int x; cin >> x; cout << x * x * x << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> P; #define all(v) v.begin(), v.end() const ll mod=1000000007; ll countBits(ll in){ int res=0; for(;in>0;in>>=1){ if((in&0x01)!=0){ res++; } } return res; } template<typename T> void show2dVector(vector<vector<T>>& v){ for(int i=0;i<v.size();i++){ int m=v[i].size(); cout<<i<<" : "; for(int j=0;i<m;i++){ cout<<v[i][j]<<" "; } cout<<endl; } } void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){ seen[v]=true; cout<<v<<" "; for(auto next: g[v]){ if(seen[next]){ continue; } bfs(g,next,seen); } } bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){ bool res=false; seen[start]=true; if(start==goal){ return true; } for(auto next: g[start]){ if(seen[next]){ continue; } res=dfs(g,next,goal,seen); if(res){ break; } } return res; } ll gcd(ll a,ll b) { return b? gcd(b,a%b): a; } ll lcm(ll a,ll b) { return a*b/gcd(a,b); } bool isLowerCase(char c){ return (c>='a'&&c<='z'); } char toLowerCase(char c){ if(isLowerCase(c)){ return c; }else{ return c+'a'-'A'; } } char toUpperCase(char c){ if(isLowerCase(c)){ return c-('a'-'A'); }else{ return c; } } ll powm(ll a,ll n, ll m){ ll ret=1; while(n>0){ if(n%2==1){ ret=(ret*a)%m; } n>>=1; a=(a*a)%m; } return ret; } const string yesno(bool ans){ return (ans?"Yes":"No"); } void func(vector<int>& l, int depth, int idx){ ; } int main() { ll a[2],k;cin>>a[0]>>a[1]>>k; for(int i=0;i<k;i++){ ll half=a[i%2]/2; if(a[i%2]%2!=0){ a[i%2]--; } a[i%2]-=half; a[(i+1)%2]+=half; } cout<<a[0]<<" "<<a[1]<<endl; return 0; }
#include<bits/stdc++.h> #define rep(i,N) for(ll (i)=0;(i)<(N);(i)++) #define chmax(x,y) x=max(x,y) #define chmin(x,y) x=min(x,y) using namespace std; typedef long long ll; typedef pair<int,int> P; const int mod = 1000000007; int main() { int a, b, k; cin >> a >> b >> k; rep(i, k) { if(i % 2 == 0) { a /= 2; b += a; } else { b /= 2; a += b; } } cout << a << " " << b << endl; }
1
#include <bits/stdc++.h> using namespace std; int main() { int N,M; cin >> N; vector<string> blue(N); int MAX = 0; for(int i = 0; i < N; i++){ cin >> blue.at(i); } cin >> M; vector<string> red(M); for(int i = 0; i < M; i++){ cin >> red.at(i); } int count; string S; for(int i = 0; i < N; i++){ count = 0; S = blue.at(i); for(int j = 0; j < N; j++){ if(S == blue.at(j)){ count++; } } for(int k = 0; k < M; k++){ if(S == red.at(k)){ count--; } } if(MAX < count){ MAX = count; } } if(MAX < 1){ cout << 0 << endl; }else{ cout << MAX << endl; } }
#define _USE_MATH_DEFINES #include <iostream> #include <sstream> #include <string> #include <list> #include <vector> #include <queue> #include <algorithm> #include <climits> #include <cstring> #include <cmath> #include <stack> #include <iomanip> #include <tuple> #include <functional> #include <cfloat> #include <map> #include <set> #include <array> #include <stdio.h> #include <string.h> #include <random> using ll = long long; using ull = unsigned long long; using namespace std; #define int long long #define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end()) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ARY_SORT(a, size) sort((a), (a)+(size)) #define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end())) #define REVERSE(v) (reverse((v).begin(), (v).end())) #define ARY_REVERSE(v,a) (reverse((v), (v)+(a))) #define REP(i, n) for (int (i)=0; (i) < (n); (i)++) #define CONTAINS_MAP(m, a) (m).find((a)) != m.end() #define CONTAINS_SET(m, a) (m).find((a)) != m.end() void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; } void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; } int N; int M; map<string, int> S; map<string, int> T; signed main() { cin >> N; REP(i, N) { string s; cin >> s; if (CONTAINS_MAP(S, s)) { S[s]++; } else { S[s] = 1; } } cin >> M; REP(i, M) { string s; cin >> s; if (CONTAINS_MAP(T, s)) { T[s]++; } else { T[s] = 1; } } int ma = 0; for (auto pair : S) { int n = pair.second; if (CONTAINS_MAP(T, pair.first)) { n -= T[pair.first]; } ma = max(ma, n); } cout << ma << endl; }
1
#include <iostream> #include <algorithm> using namespace std; const int INF = 1e9 + 7; int m; int g1[100][100]; //cost int g2[100][100]; //time void floyd() { for (int k = 0; k < m; k++) { for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { g1[i][j] = min(g1[i][j], g1[i][k] + g1[k][j]); g2[i][j] = min(g2[i][j], g2[i][k] + g2[k][j]); } } } } signed main() { int n, k; int a, b, c, t; while (cin >> n >> m, n || m) { for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { g1[i][j] = INF; g2[i][j] = INF; } } for (int i = 0; i < n; i++) { cin >> a >> b >> c >> t; a--; b--; g1[a][b] = c; g1[b][a] = c; g2[a][b] = t; g2[b][a] = t; } floyd(); cin >> k; for (int i = 0; i < k; i++) { int p, q, r; cin >> p >> q >> r; if (r == 0) { cout << g1[p - 1][q - 1] << endl; } else { cout << g2[p - 1][q - 1] << endl; } } } return (0); }
#include<bits/stdc++.h> using namespace std; typedef pair<int,int> P; struct Graph{ Graph(int n):E(n),d(n){} vector<vector<tuple<int,int,int>>>E; vector<int>d; void add_edge(int a,int b,int c,int d){ E[a].push_back(make_tuple(b,c,d)); } void dijkstra(int s,int f){ priority_queue<P,vector<P>,greater<P>>q; fill(d.begin(),d.end(),1e9); q.push({d[s]=0,s}); while(q.size()){ auto p=q.top();q.pop(); if(p.first>d[p.second])continue; for(auto& a:E[p.second]){ int x=get<0>(a),y=get<1>(a)+p.first; if(f)y=get<2>(a)+p.first; if(y<d[x])d[x]=y,q.push({y,x}); } } } }; main(){ int n,m,a,b,c,d,k; while(cin>>n>>m,n){ Graph E(m); for(int i=0;i++<n;E.add_edge(--a,--b,c,d),E.add_edge(b,a,c,d))cin>>a>>b>>c>>d; cin>>k; for(int i=0;i++<k;cout<<E.d[--b]<<endl){ cin>>a>>b>>c; E.dijkstra(--a,c); } } }
1
#include <iostream> #include <iomanip> #include <vector> #include <string> #include <stack> #include <set> #include <cmath> #include <algorithm> using namespace std; int day_of_week(int y,int m,int d){ static int t[]={0,3,2,5,0,3,5,1,4,6,2,4}; y-=m < 3; return ( y + y/4 - y/100 + y/400 + t[m-1] + d) % 7 ; } int main(){ int m , d , w=4 , fw; while (cin >> m >> d, m){ switch(day_of_week(2004,m,d)){ case 0: cout << "Sunday" << endl; break; case 1: cout << "Monday" << endl; break; case 2: cout << "Tuesday" << endl; break; case 3: cout << "Wednesday" << endl; break; case 4: cout << "Thursday" << endl; break; case 5: cout << "Friday" << endl; break; case 6: cout << "Saturday" << endl; } } return 0; }
#include <stdio.h> int main(void) { int day[13][32]; int i, j; int n = 4; int month; int da; for (i = 1; i <= 12; i++){ if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12){ for (j = 1; j <= 31; j++){ day[i][j] = n; n++; if (n == 8){ n = 1; } } } else if (i == 4 || i == 6 || i == 9 || i == 11){ for (j = 1; j <= 30; j++){ day[i][j] = n; n++; if (n == 8){ n = 1; } } } else if (i == 2){ for (j = 1; j <= 29; j++){ day[i][j] = n; n++; if (n == 8){ n = 1; } } } } while (1){ scanf("%d %d", &month, &da); if (month == 0){ return (0); } //printf("%d\n", day[month][da]); switch (day[month][da]){ case 1: printf("Monday\n"); break; case 2: printf("Tuesday\n"); break; case 3: printf("Wednesday\n"); break; case 4: printf("Thursday\n"); break; case 5: printf("Friday\n"); break; case 6: printf("Saturday\n"); break; case 7: printf("Sunday\n"); break; } } }
1
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<n; i++) #define rep2(i,a,n) for(int i=(a); i<(n); i++) #define all(vec) vec.begin(),vec.end() using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; int main() { ll N, Y ; cin >> N >> Y; rep(i,N+1){ rep(j,(N-i+1)){ if( Y == i*10000 + j*5000 + (N-i-j)*1000 ){ cout << i << " " << j << " " << N-i-j << endl; return 0; } } } cout << "-1 -1 -1" << endl; }
#include<cstdio> #include<algorithm> using namespace std; int main(void) { int n,y; int i,j,flg=0; scanf("%d %d",&n,&y); for(i=0;i<=n;i++){ for(j=0;j<=n;j++){ if(n-(i+j)<0) { break; } if(i+j+n-(i+j)==n&&y==i*10000+j*5000+(n-(i+j))*1000){ flg=1; break; } } if(flg==1) break; } if(flg==1){ printf("%d %d %d\n",i,j,n-(i+j)); } else if(flg==0||flg==2){ printf("-1 -1 -1\n"); } return 0; }
1
#include <bits/stdc++.h> using namespace std; typedef long lint; typedef long long llint; typedef pair<int, int> pint; typedef pair<long long, long long> pllint; // static const int MAX = 1e6; // static const int NIL = -1; // static const llint INF = 1<<21; // static const llint MOD = 1e9 + 7; bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; } template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } } template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } } int main(void) { int n, t; cin >> n >> t; int ans = 0, tnow, tpush, tbfr; cin >> tbfr; for(int in=1;in<n;in++) { cin >> tpush; if(tpush-tbfr<=t) ans += tpush-tbfr; else ans += t; tbfr = tpush; } ans += t; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ln "\n" #define SORT(X) sort(X.begin(), X.end()) #define SORTi(X) sort(X.begin(), X.end(), greater<ll>()) #define REP(x, a, b) for (auto x = a; x <= b; x++) #define REPi(x, b, a) for (auto x = b; x >= a; x--) #define REPit(x, A) for (auto x = A.begin(); x != A.end(); x++) #define REPr(x, A) for (auto x : A) #define ll long long #define ull unsigned long long #define PB push_back #define EB emplace_back #define UMP unordered_map #define UST unordered_set using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int N , T, sum = 0; cin >> N >> T; vector <int> A(N); REP(i, 0, N-1) { cin>>A[i]; } int tmp = 0; REP(i, 0, N-2) { tmp = (A[i+1] - A[i]); if(tmp < T) { sum = sum + tmp; } else if (tmp >= T) { sum = sum + T; } } sum = sum + T; cout<<sum<<ln; return 0; }
1
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = 1; i < (int)(n+1); i++) const long long INF = 1LL << 60; int main(){ int A,B,C; cin>>A>>B>>C; if(A<=C&&C<=B){ cout<<"Yes"<<endl; } else if(B<=C&&C<=A){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int a, b; scanf("%d%d", &a, &b); if(a <= 8 && b <= 8) printf("Yay!\n"); else printf(":(\n"); return 0; }
0
/*input 3 2 1 2 10 2 1 1 10 6 2 3 4 5 6 7 111000 */ #include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ld,ld> pdd; #define IOS ios_base::sync_with_stdio(0); cin.tie(0) #define ALL(a) a.begin(),a.end() #define SZ(a) ((int)a.size()) #define F first #define S second #define REP(i,n) for(int i=0;i<((int)n);i++) #define eb emplace_back #define pb push_back #define MP(a,b) make_pair(a,b) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (int)(lower_bound(c.begin(),c.end(),x)-c.begin()) #define EL cout<<'\n' #define BS(a,x) binary_search(ALL(a),x) template<typename T1,typename T2> ostream& operator<<(ostream& out,pair<T1,T2> P){ out<<'('<<P.F<<','<<P.S<<')'; return out; } template<typename T> ostream& operator<<(ostream& out,vector<T> V){ REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":""); return out; } //}}} const ll maxn=300005; const ll maxlg=20; const ll INF64=1e18; const int INF=0x3f3f3f3f; const ll MOD=ll(1e9+7); const ld PI=acos(-1); const ld eps=1e-9; //const ll p=880301; //const ll P=31; ll mypow(ll a,ll b){ ll res=1LL; while(b){ if(b&1) res=res*a%MOD; a=a*a%MOD; b>>=1; } return res; } int n; string s; ll a[maxn]; ll v[60]; bitset<60> vis; void solve(){ vis.reset(); cin>>n; REP(i,n) cin>>a[i]; cin>>s; bool flag = 0; for(int i=n-1;i>=0;i--){ if(s[i]=='1'){ for(int j=60;j>=0;j--) if(a[i]&(1LL<<j)){ if(!vis[j]) flag = 1; else{ a[i]^=v[j]; } } if(flag) break; } else{ for(int j=60;j>=0;j--) if(a[i]&(1LL<<j)){ if(!vis[j]){ vis[j] = 1; v[j]=a[i]; break; } else{ a[i]^=v[j]; } } } } cout<<flag<<'\n'; } int main(){ IOS; int T; cin>>T; while(T--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' const int N = 1e6 + 5; ll a[N]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("BONUS.INP", "r")){ freopen("BONUS.INP", "r", stdin); freopen("BONUS.OUT", "w", stdout); } ll t; cin >> t; while (t--){ ll n; cin >> n; for (int i = 0; i < n; i++){ cin >> a[i]; } string s; cin >> s; vector<ll> now; bool flag = true; for (int i = n - 1; i >= 0; i--){ for (auto j : now) a[i] = min(a[i], a[i] ^ j); now.push_back(a[i]); if (s[i] == '1' && a[i]){ flag = false; break; } } if (flag) cout << 0 << endl; else cout << 1 << endl; } }
1
#define NguyenDangQuan the_author #include <bits/stdc++.h> #define all(x) x.begin(),x.end() #define mset(x, i) memset(x,i,sizeof(x)) #define elif else if #define heap priority_queue #define fi first #define se second #define pb push_back #define ld long double #define ll long long #define ull unsigned long long #define task "codejam" using namespace std; int typetest; template<class T> void read(T &x){ register int c; T neg = 1; x = (T)0; while ((c = getchar()) <= 47 || c >= 58) if(c == '-') neg = -1; for (; (c > 47 && c < 58); c = getchar()){ x = (x << 3) + (x << 1) + (T)(c - 48); } x *= neg; } inline void fastIOfileinput(){ ios:: sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen(task".INP", "r", stdin); // freopen(task".OUT", "w", stdout); // freopen(task".in", "r", stdin); // freopen(task".out", "w", stdout); typetest = 0; } const int N = 2e5 + 2; int m, n, k; vector<int> ker[N], kel[N]; int ltr[N], ltl[N]; void Enter(){ read(n); read(m); read(k); while(m--){ int a, b; read(a); read(b); ker[a].pb(b); ker[b].pb(a); } while(k--){ int a, b; read(a); read(b); kel[a].pb(b); kel[b].pb(a); } } void BFS(int i, int lt[], vector<int> ke[]){ ++m; lt[i] = m; queue<int> open; open.push(i); while(open.size()){ int c = open.front(); open.pop(); for(auto i : ke[c]){ if((!lt[i])) open.push(i), lt[i] = m; } } } void solve(){ m = 0; for(int i = 1; i <= n; ++i) if(ltr[i] == 0) BFS(i, ltr, ker); m = 0; for(int i = 1; i <= n; ++i) if(ltl[i] == 0) BFS(i, ltl, kel); map<int, map<int, int> > s; for(int i = 1; i <= n; ++i){ ++s[ltr[i]][ltl[i]]; // cerr << ltr[i] << " " << ltl[i] << "\n"; } for(int i = 1; i <= n; ++i){ int& v = s[ltr[i]][ltl[i]]; cout << v << " "; } } signed main(){ fastIOfileinput(); if(typetest){ int t; cin >> t; int v = t; while(t--){ Enter(); cout << "Case #" << v - t << ": "; solve(); } } else{ Enter(); solve(); } }
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> const int MOD = 1e9 + 7; const int iINF = 1000000000; const long long int llINF = 1000000000000000000; using namespace std; using ll = long long int; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vvvl = vector<vector<vector<ll>>>; typedef pair<ll, ll> pll; bool paircomp(const pll &a, const pll &b) { if (a.first == b.first) return a.second < b.second; return a.first < b.first; } #define REP(i, n) for (ll i = 0; i < (n); i++) #define RREP(i, n) for (ll i = (n)-1; i >= 0; i--) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define AUTO(i, m) for (auto &i : m) #define ALL(a) (a).begin(), (a).end() #define MAX(vec) *std::max_element(vec.begin(), vec.end()) #define MIN(vec) *std::min_element(vec.begin(), vec.end()) #define ARGMAX(vec) \ std::distance(vec.begin(), std::max_element(vec.begin(), vec.end())) #define ARGMIN(vec) \ std::distance(vec.begin(), std::min_element(vec.begin(), vec.end())) #define REV(T) greater<T>() #define PQ(T) priority_queue<T, vector<T>, greater<T>> #define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c)) #define VVVL(a, b, c, d) \ vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d))) #define SP(a) setprecision(a) #define SQRT(a) sqrt((long double)(a)) #define DPOW(a, b) pow((long double)(a), (long double)(b)) ll POW(ll n, ll m) { if (m == 0) { return 1; } else if (m % 2 == 0) { ll tmp = POW(n, m / 2); return (tmp * tmp); } else { return (n * POW(n, m - 1)); } } struct UnionFind { vector<ll> data; UnionFind(ll sz) { data.assign(sz, -1); } bool unite(ll x, ll y) { x = root(x), y = root(y); if (x == y) return (false); if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return (true); } ll root(ll k) { if (data[k] < 0) return (k); return (data[k] = root(data[k])); } ll size(ll k) { return (-data[root(k)]); } ll same(ll a, ll b) { return root(a) == root(b); } }; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; struct PO { ll ar; ll br; ll i; }; bool pocomp(const PO &a, const PO &b) { if (a.ar == b.ar) return a.br < b.br; return a.ar < b.ar; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll N, K, L; cin >> N >> K >> L; auto uf1 = UnionFind(N); auto uf2 = UnionFind(N); vector<PO> P(N); REP(i, K) { ll p, q; cin >> p >> q; uf1.unite(p - 1, q - 1); } REP(i, L) { ll r, s; cin >> r >> s; uf2.unite(r - 1, s - 1); } REP(i, N) { P[i] = {uf1.root(i), uf2.root(i), i}; } sort(ALL(P), pocomp); vl ans(N); for (ll i = 0; i < N; i++) { ll j = i; while (j + 1 < N && P[j].ar == P[j + 1].ar && P[j].br == P[j + 1].br) { j++; } for (ll k = i; k <= j; k++) { ans[P[k].i] = j - i + 1; } i = j; } REP(i, N) { cout << ans[i] << " " << endl; } return 0; }
1
#include<bits/stdc++.h> //ios::sync_with_stdio(false); //cin.tie(0); using namespace std; typedef long long ll; typedef unsigned long long ull; 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; ll mod=1000000007; ll mod2=998244353; ll inf=1000000000000000000; double pi=2*acos(0); #define rep(i,m,n) for(ll i=m;i<n;i++) #define rrep(i,n,m) for(ll i=n;i>=m;i--) 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 lmax(ll a,ll b){ if(a<b)return b; else return a; } ll lmin(ll a,ll b){ if(a<b)return a; else return b; } ll gcd(ll a,ll b){ if(a<b)swap(a,b); 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 gya[200010]; ll kai[200010]; ll m; ll beki(ll n,ll k){ ll ret=1; ll now=n; while(k>0){ if(k%2==1){ ret*=now; ret%=m; } now*=now; now%=m; k/=2; } return ret; } ll gyaku(ll n){ return beki(n,mod-2); } void nckinit(ll n){ kai[0]=1; kai[1]=1; for(int i=2;i<=n;i++){ kai[i]=kai[i-1]*i; kai[i]%=mod; } gya[n]=gyaku(kai[n]); for(int i=n-1;i>=1;i--){ gya[i]=gya[i+1]*(i+1); gya[i]%=mod; } gya[0]=1; } ll nck(ll n,ll k){ if(k<0)return 0; if(k==0||n==k)return 1; ll ret=kai[n]; ret*=gya[n-k]; ret%=mod; ret*=gya[k]; ret%=mod; return ret; } ll npk(ll n,ll k){ if(k<0)return 0; if(k==0)return 1; ll ret=kai[n]; ret*=gya[n-k]; ret%=mod; return ret; } random_device rnd; mt19937 mt(rnd()); uniform_real_distribution<double> ra(1,6); int main(){ ios::sync_with_stdio(false); cin.tie(0); int n,m;cin>>n>>m; string s[n]; rep(i,0,n)cin>>s[i]; vector<int> v[m+1]; rep(i,0,n-1){ rep(j,0,m-1){ int cnt=0; if(s[i][j]=='#')cnt++; if(s[i+1][j]=='#')cnt++; if(s[i][j+1]=='#')cnt++; if(s[i+1][j+1]=='#')cnt++; if(cnt%2==1)v[j+1].push_back(i+1); } } rep(i,0,m+1){ v[i].push_back(n); sort(v[i].begin(),v[i].end()); } int now[m+1]; fill(now,now+m+1,0); int ans=0; rep(i,0,n){ rep(j,0,m+1){ if(v[j][now[j]]==i)now[j]++; //cout<<v[j][now[j]]<<" "; } deque<pii> dq; dq.push_back({0,0}); rep(j,1,m+1){ int f=v[j][now[j]]; f-=i; while(dq.back().first>=f){ int y=dq.size(); ans=max(ans,((int)j-dq[y-2].second)*dq[y-1].first); dq.pop_back(); } ans=max(ans,((int)j-dq.back().second)*f); dq.push_back({f,j}); } while(dq.size()>1){ int y=dq.size(); ans=max(ans,(m-dq[y-2].second)*dq[y-1].first); dq.pop_back(); } } cout<<ans<<endl; }
#pragma region header #include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--) #define rev1(i, n) for(int i = (int)(n); i > 0; i--) #define pb push_back #define all(v) (v).begin(), (v).end() #define resort(v) sort((v).rbegin(), (v).rend()) #define vi vector<int> #define vvi vector<vector<int>> #define vc vector<char> #define vvc vector<vector<char>> #define vb vector<bool> #define vvb vector<vector<bool>> using ll = long long; using P = pair<int, int>; /* ----------------よく使う数字や配列----------------- */ int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1}; constexpr ll mod = 1e9+7; constexpr ll inf = INT32_MAX/2; constexpr ll INF = LLONG_MAX/2; constexpr long double eps = DBL_EPSILON; constexpr long double pi = 3.141592653589793238462643383279; /* ----------------------end----------------------- */ /* --------------------テンプレート------------------ */ 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; } /* ----------------------end----------------------- */ /* --------------------ライブラリ-------------------- */ ll fact(int i) { //階乗 if (i == 0) return 1; return (fact(i - 1)) * i % mod; } ll gcd(ll a, ll b) { //最大公約数 if(b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { //最小公倍数 return a * b / gcd(a, b); } int keta(ll n) { //桁数を求める if(n == 0) return 1; int count = 0; while(n != 0) { n /= 10; count++; } return count; } ll ketasum(ll n) { //各桁の和 ll sum = 0; while(n != 0) { sum += n % 10; n /= 10; } return sum; } /* ----------------------end----------------------- */ #pragma endregion signed main() { int h,w;cin >> h >> w; vvb bo(h,vb(w)); vector<P> v; rep(i, h) { rep(j, w) { char c;cin >> c; if(c=='#') { bo[i][j]=true; v.pb({i,j}); } else bo[i][j]=false; } } bool ok = true; rep(i, v.size()) { rep(j, 4) { int x=v[i].first+dx[j],y=v[i].second+dy[j]; if(x<0||x>=h||y<0||y>=w||!bo[x][y]) { // cout << i << endl; if(j==3) { cout << "No" << endl; return 0; } continue; } break; } } cout << "Yes" << endl; return 0; }
0
#include<bits/stdc++.h> using namespace std; using ll = long long; int main() { vector<int> d(10),e(10); for(int i = 1;i<10;i++) { int now = i*2; int num = 2; int cnt = 1; while(now != i) { if(now>9) { now = now%10+now/10; cnt++; if(now==i)break; } now += i; num++; cnt++; if(now==i)break; if(now>9) { now = now%10+now/10; cnt++; } } //cout<<i << ' ' << num << ' ' << cnt<<endl; d[i]= num; e[i]= cnt; d[i]--; } d[0] = 1; e[0]=1; int n; cin >> n; ll ans = 0; int now = 0; map<ll,ll> mp; for(int i = 0;i<n;i++) { ll x,y; cin >> x >> y; mp[x] += y; } for(int i = 0;i<10;i++) { if(mp[i]>0) { mp[i]--; ans += mp[i]/d[i]*e[i]; //cout << mp[i]<<endl; //cout<< "ans" << ans << endl; //cout << d[i] <<';'<< e[i]<<endl;; mp[i]%=d[i]; mp[i]++; for(int j = 0;j<mp[i];j++) { now += i; ans++; if(now>9) { now = now/10+now%10; ans++; } } } } cout << ans -1<< endl; }
#include <iostream> using namespace std; int m[124][124] = {{}}; int p[124] = {}; int n; void chain(){ for(int i = 0 ;i < n;i++) m[i][i] = 0; for(int l = 2;l <= n;l++){ for(int i = 1 ;i <= n - l + 1;i++){ int j = i + l - 1; m[i][j] = (1 << 21); for(int k = i;k <= j;k++){ m[i][j] = min(m[i][j],m[i][k] + m[k + 1][j] + p[i - 1] *p[k] *p[j]); } } } cout << m[1][n] << endl; } int main(){ cin >> n; for(int i = 1;i <= n;i++){ cin >> p[i - 1] >> p[i]; } chain(); }
0
#include<bits/stdc++.h> using namespace std; #define int long long int #define mod 1000000007 #define b1(n) __builtin_popcount(n) vector<int>sie; inline int gEd(int a, int b, int *ax, int *ay) { int x,y; if (a==0) { *ax=0; *ay = 1; return b; } int g = gEd(b%a,a,&x,&y); *ax=y-(b/a)*x; *ay=x; return g; } inline int mli(int a,int m) //mli(a,m) { int ax,ay; gEd(a,m,&ax,&ay); int val1=(ax%m+m)%m; return val1; } inline int powerm(int a,int n) //powerm(a,n) { int ans=1; while(n>0) { int last_bit=(n&1); if(last_bit) ans=((ans%mod)*(a%mod))%mod; a=((a%mod)*(a%mod))%mod; n=n>>1; } return ans; } inline int power(int a,int n) //power(a,n) { int ans=1; while(n>0) { int last_bit=(n&1); if(last_bit) ans=ans*a; a=a*a; n=n>>1; } return ans; } inline int add(int a,int b) { int s=((a%mod)+(b%mod))%mod; return s; } inline int sub(int a,int b) { int s=((a%mod)-(b%mod))%mod; return s; } inline int mul(int a,int b) { int s=((a%mod)*(b%mod))%mod; return s; } inline int ncr(int n, int k) //ncr(a,b) { int res = 1; if (k > n - k) k = n - k; for (int i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } inline void sieve() //sieve vector->sie { const int n=10000000; bitset<10000000>b; b.set(); b[0]=b[1]=0; for(int i =2;i<=n;i++) { if(b[i]) { sie.push_back(i); for(int j=i*i;j<=n;j=j+i) b[j]=0; } } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin>>s; if(s=="SUN"){ cout<<"7"<<endl; } if(s=="MON"){ cout<<"6"<<endl; } if(s=="TUE"){cout<<"5"<<endl;} if(s=="WED"){cout<<"4"<<endl;} if(s=="THU"){cout<<"3"<<endl;} if(s=="FRI"){cout<<"2"<<endl;} if(s=="SAT"){cout<<"1"<<endl;} }
#include <bits/stdc++.h> #define rep(i,a,b) for(int i=int(a);i<int(b);++i) #define SIZE 200005 #define INF 1000000005LL #define MOD 1000000007 using namespace std; typedef long long int ll; typedef pair <string,string> P; int n; string s; map<P,ll> a,b; int main(){ cin >> n >> s; rep(U,0,1<<n){ string t,w; rep(i,0,n){ if(U>>i & 1) t.push_back(s[i]); else w.push_back(s[i]); } a[P(t,w)]++; } rep(U,0,1<<n){ string t,w; rep(i,0,n){ if(U>>i & 1) t.push_back(s[n*2-i-1]); else w.push_back(s[n*2-i-1]); } b[P(t,w)]++; } ll ans = 0; for(auto i : a){ ans += i.second * b[i.first]; } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int nb_min, nb_max, nb; int count = 0; string str, rev; cin >> nb_min >> nb_max; nb = nb_min; while (nb <= nb_max) { str = to_string(nb); rev = str; reverse(rev.begin(), rev.end()); if (str == rev) count++; nb++; } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n,k; cin>>n>>k; int a=n/100,b=k/100; int c=b-a-1; int aaf=(a/10)/10,aab=(a/10)%10; int bbf=(b/10)/10,bbb=(b/10)%10; int af=(n%100)/10,ab=(n%100)%10; int bf=(k%100)/10,bb=(k%100)%10; if(aab*10+aaf>=n%100){ c+=1; } if(bbb*10+bbf<=k%100){ c+=1; } cout<<c<<endl; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; template <typename T> void cmin(T &x, const T &y) { if(y < x) x = y; } template <typename T> void cmax(T &x, const T &y) { if(y > x) x = y; } template <typename T> void read(T &x) { x = 0; char c = getchar(); bool f = 0; while(!isdigit(c) && c!='-') c = getchar(); if(c == '-') f = 1, c = getchar(); while(isdigit(c)) x = x*10+c-'0', c = getchar(); if(f) x = -x; } ll pw10[19], D, ans; int bit[19]; void dfs(int l, int r, ll d, ll way) { if(l > r) { if(d == -D) ans += way; } else { if(l == r) dfs(l+1, r-1, d, way*10); else { for(int i=-9; i<=9; i++) { ll base = d+i*pw10[r]-i*pw10[l]; ll upb = base + pw10[r]; ll lob = base - pw10[r]; if(lob<=-D && -D<=upb) bit[l] = i, dfs(l+1, r-1, base, way*(10-abs(i)-(i<=0&&l==0))); } } } } int main() { read(D); pw10[0] = 1; for(int i=1; i<=18; i++) pw10[i] = pw10[i-1] * 10; for(int i=1; i<=18; i++) dfs(0, i, 0, 1); printf("%lld\n", ans); return 0; }
#include<bits/stdc++.h> using namespace std; int main() { string a; getline(cin,a); if(a.size()==2 && a[0]==a[1]){ cout<<"1 2"<<endl; return 0; } long long i,flag=0; for(i=0;i<a.size()-2;i++) { if(a[i]==a[i+1] || a[i]==a[i+2] || a[i+1]==a[i+2]){ cout<<i+1<<" "<<i+3<<endl; flag=1; break; } } if(!flag) cout<<"-1 -1"<<endl; }
0
#include<bits/stdc++.h> using namespace std; int main(){ int a,b;cin>>a>>b; int ans=0; if(a>=b){ ans+=a; a-=1; } else{ ans+=b; b-=1; } if(a>=b){ ans+=a; a-=1; } else{ ans+=b; b-=1; } cout<<ans<<endl; }
//This Code was made by Chinese_zjc_. #include <iostream> #include <fstream> #include <iomanip> #include <algorithm> #include <vector> #include <bitset> #include <cmath> #include <queue> #include <stack> #include <string> #include <cstring> #include <cstdio> #include <cstdlib> #include <map> #include <set> #include <ctime> // #include<windows.h> #define int long long #define double long double using namespace std; const double PI = acos(-1); const double eps = 0.0000000001; const int INF = 0x3fffffffffffffff; int n, k, dp[55][55]; signed main() { ios::sync_with_stdio(false); cin >> n >> k; cout << n - k + 1 << endl; return 0; }
0
#include <functional> #include <algorithm> #include <iostream> #include <numeric> #include <iomanip> #include <utility> #include <cstdlib> #include <sstream> #include <bitset> #include <vector> #include <cstdio> #include <ctime> #include <queue> #include <deque> #include <cmath> #include <stack> #include <list> #include <map> #include <set> using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; typedef long long ll; #define dump(x) cerr << #x << " = " << (x) << endl #define rep(i,n) for(int i=0;i<(n);i++) #define all(a) (a).begin(),(a).end() #define pb push_back #define sz size() const double EPS = 1e-10; const int INF = 100000000; int main(){ int n,q; while(cin>>n>>q){ if(n==0 && q==0)break; int date[200]; rep(i,200)date[i]=0; rep(i,n){ int m; cin>>m; rep(j,m){ int a; cin>>a; date[a]++; } } int maxi=-1; int day=-1; for(int i=1;i<100;i++){ if(maxi<date[i]){ day=i; maxi=date[i]; } } if(maxi>=q)cout<<day<<endl; else cout<<"0"<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { while (true) { int n, m; cin >> n >> m; if (n==0 && m==0) { break; } int p[n]; int s = 0; for (int i=0; i<n; i++) { cin >> p[i]; s += p[i]; } sort(p, p+n, greater<int>()); for (int i=1; i*m-1<n; i++) { s -= p[i*m-1]; } cout << s << endl; } }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll inf = 10000000; int main() { string s; cin >> s; for (int i = 1; i < s.size(); i++) { if (s[i-1] == s[i]) { cout << i << " " << i+1 << endl; return 0; } } for (int i = 0; i+2 < s.size(); i++) { if (s[i] == s[i+2]) { cout << i+1 << " " << i+3 << endl; return 0; } } cout << -1 << " " << -1 << endl; }
#include <bits/stdc++.h> using namespace std; string s; int main () { cin >> s; for (char c = 'a'; c <= 'z'; c++){ if (s.find(c) == -1){ cout << c; return 0; } } cout << "None"; }
0
#include<iostream> #include<cstdio> using namespace std; int main(){ int n,ground,ou,point; string s; scanf("%d",&n); for(int cas=0;cas<n;cas++){ ground = ou = point = 0; while(1){ cin >> s; if(s == "OUT"){ ou++; if(ou == 3) break; } else if(s == "HIT"){ ground<<=1; ground|=1; if(ground >= (1<<3)){ ground&=(~(1<<3)); point++; } } else{ for(int i=0;i<3;i++){ if(ground&(1<<i)) point++; } ground=0; point++; } } cout << point << endl; } return 0; }
#include<iostream> #include<string> using namespace std; int main(){ int n=0,ct=0, score=0, out=0,run=0; string x; cin >> n; while (1){ int score = 0, out = 0, run = 0; while (1){ cin >> x; if (x == "OUT"){ out++; } if (x == "HOMERUN"){ score+=run; score++; run = 0; } if (x == "HIT"){ run++; } if (run > 3){ run--; score++; } if (out == 3){ cout << score << endl; ct++; break; } } if (ct == n)break; } return 0; }
1
#include<bits/stdc++.h> using namespace std; #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (ll i = m; i < (n); i++) using ll = long long; using pii = pair<int, int>; using Vi = vector<int>; int main() { int N,y; cin >> N >> y; for(int i = 0; i<= N; i++){ for(int j = 0; i+j<= N; j++){ if(10000*i+5000*j+(N-i-j)*1000==y){ cout << i << " " << j << " " << N-i-j << endl; return 0; } } } cout << "-1 -1 -1" << endl; }
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <string> #include <map> #include <bitset> #include <vector> #include <queue> using namespace std; typedef long long ll; #define FOR(i,a,b) for(ll i = (a); i < (b); i++ ) #define REP(i, n) FOR(i,0,n) typedef pair< ll, ll > cp2; typedef pair< string, cp2 > cp3; #define fi first #define se second #define sec se.fi #define thr se.se const ll mod = 1000000007; // 123456789 /////////////////////////////////////////////// // // /////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////// int N; ll Y; bool ans = false; ll A, B, C; int main(){ cin>>N>>Y; REP( i, N+1 ){ REP( j, N+1-i ){ A = i; B = j; C = N-i-j; if( A*1000+B*5000+C*10000 == Y ){ ans = true; i = N; break; } } } if( ans ){ printf("%lld %lld %lld\n", C, B, A); } else{ puts("-1 -1 -1"); } return 0; }
1
#include <bits/stdc++.h> using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) #define all(c) (c).begin(), (c).end() #define zero(a) memset(a, 0, sizeof a) #define minus(a) memset(a, -1, sizeof a) #define watch(a) { std::cout << #a << " = " << a << "\n"; } template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); } template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); } template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; } template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; } template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; } typedef long long ll; int const inf = INT_MAX / 2; int main() { int N, K; cin >> N >> K; vector<int> A(N); cin >> A; rep(_, min(K, 50)) { vector<int> acc(N + 1); rep(i, N) { acc[max(0, i - A[i])]++; acc[min(N, i + A[i] + 1)]--; } REP(i, 1, N + 1) { acc[i] += acc[i - 1]; } rep(i, N) { A[i] = acc[i]; } } rep(i, N) { if (i) cout << " "; cout << A[i]; } cout << "\n"; }
#include<iostream> using namespace std; int main(){ int n; cin >> n; int a[n]; int min, max; long sum; cin >> a[0]; min = a[0]; max = a[0]; sum += a[0]; for(int i = 1; i < n; i++){ cin >> a[i]; if(min > a[i]){ min = a[i]; }else if(max < a[i]){ max = a[i]; } sum += a[i]; } cout << min << " " << max << " " << sum << endl; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define INF 1e12 #define PB push_back #define PF push_front #define fi first #define se second #define pii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vpi vector<pii> #define vll vector<ll> #define vpl vector<pll> #define vvi vector<vector<int>> #define vvl vector<vector<ll>> #define MX(x) *max_element(all(x)) #define MN(x) *min_element(all(x)) #define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define pr_d(x) cout << fixed << setprecision(15) << x << endl #define ud(c, x) distance(c.begin(), upper_bound(all(c), x)) #define ld(c, x) distance(c.begin(), lower_bound(all(c), x)) #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) #define rep3(i, n) for (int i = (n - 1); i >= 0; --i) #define rep4(i, a, b) for (int i = (a); i > (b); --i) #define pb push_back #define out(x) cout << x << "\n" bool odd(int i) { return i % 2; } #define all(v) v.begin(), v.end() #define size(x) int(x.size()) int gcd(int a, int b) { return __gcd(a, b); } int lcm(int a, int b) { return a * (b / gcd(a, b)); } void Yes_No(bool f) { if (f) printf("Yes\n"); else printf("No\n"); } void YES_NO(bool f) { if (f) printf("YES\n"); else printf("NO\n"); } template <typename T> void deb1(T x) { cout << x << "\n"; } template <typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; } //-------------------ここから回答する----------------------- void solve(void) { int n, k; cin >> n >> k; vi l(n); rep(i, n) cin >> l[i]; sort(all(l), greater<int>()); int ans = 0; rep(i, k) ans += l[i]; out(ans); } int main(void) { solve(); }
/* * a.cc: */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_N = 100; /* typedef */ struct Edge { int i, j, c; Edge() {} Edge(int _i, int _j, int _c): i(_i), j(_j), c(_c) {} bool operator<(const Edge &e) const { return c < e.c; } }; typedef vector<Edge> ve; struct UFT { int links[MAX_N], ranks[MAX_N], sizes[MAX_N]; void clear(int n) { for (int i = 0; i < n; i++) links[i] = i, ranks[i] = sizes[i] = 1; } UFT() {} UFT(int n) { clear(n); } int root(int i) { int i0 = i; while (links[i0] != i0) i0 = links[i0]; return (links[i] = i0); } int rank(int i) { return ranks[root(i)]; } int size(int i) { return sizes[root(i)]; } bool same(int i, int j) { return root(i) == root(j); } int merge(int i0, int i1) { int r0 = root(i0), r1 = root(i1), mr; if (r0 == r1) return r0; if (ranks[r0] == ranks[r1]) { links[r1] = r0; sizes[r0] += sizes[r1]; ranks[r0]++; mr = r0; } else if (ranks[r0] > ranks[r1]) { links[r1] = r0; sizes[r0] += sizes[r1]; mr = r0; } else { links[r0] = r1; sizes[r1] += sizes[r0]; mr = r1; } return mr; } }; /* global variables */ /* subroutines */ /* main */ int main() { int n; cin >> n; ve es; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { int ai; cin >> ai; if (ai >= 0) es.push_back(Edge(i, j, ai)); } sort(es.begin(), es.end()); UFT uft(n); int en = es.size(), sum = 0; for (int i = 0; i < en; i++) { Edge &ei = es[i]; if (! uft.same(ei.i, ei.j)) { uft.merge(ei.i, ei.j); sum += ei.c; } } printf("%d\n", sum); return 0; }
0
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) typedef long long ll; struct edge { ll s, t, x; }; typedef pair<ll, ll> P; typedef pair<double, P> event; const ll MAX = 510000; const ll MOD = 1000000007; #define INF (ll)10000000000000000 int main() { ll N,Q; cin>>N>>Q; priority_queue<event>pq; set<ll>st; //eventはP(P(a,b),c)で書き、 //aに時刻をもち,b=0→工事開始,1→終了,2→歩行者とする rep(i,N){ double s,t; ll x; cin>>s>>t>>x; s=(double)x-s+0.5; t=(double)x-t+0.5; pq.push(event(s,P(0ll,x))); pq.push(event(t,P(1ll,x))); } rep(i,Q){ double g; cin>>g; pq.push(event(-1*g,P(2ll,0ll))); } while(!pq.empty()){ auto t=pq.top(); pq.pop(); if(t.second.first==0){ st.insert(t.second.second); } if(t.second.first==1){ st.erase(t.second.second); } if(t.second.first==2){ if(st.empty()){cout<<-1<<endl;} else{ cout<<*begin(st)<<endl; } } } }
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> P; typedef long long ll; typedef long double ld; const int inf=1e9+7; const ll longinf=1LL<<60; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) #define F first #define S second #define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/ const int mx=100010; const ll mod=1e9+7; int main(){ int n,q; cin >> n >> q; vector<pair<ll,pair<int,ll>>> a; rep(i,n){ int s,t,x; cin >> s >> t >> x; a.push_back({s-x,{-1,x}}); a.push_back({t-x,{0,x}}); } rep(i,q){ int d; cin >> d; a.push_back({d,{1,i}}); } sort(a.begin(),a.end()); vector<ll> res(q,-1); multiset<int> st; for(auto it:a){ if(it.S.F == -1){ st.insert(it.S.S); } else if(it.S.F == 0){ // st.erase(it.S.S); //同じ数字を全部消してしまう st.erase(st.lower_bound(it.S.S)); //1つだけ消したい } else { if(!st.empty()) res[it.S.S] = *st.begin(); } } for(auto ans:res){ cout << ans << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; #define fs first #define sc second #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i, n) for (int i = 0; i < n; ++i) #define pb emplace_back using pii = pair<int, int>; using vi = vector<int>; using lint = long long; const int inf = 1001001001; const lint linf = 1001001001001001001ll; const int mod = 1e9 + 7; const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1}; template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; } template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; } template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; } template<typename T> inline void print(const vector<T> &v, string s = " ") { rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); } inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; } inline lint in() { lint x; std::cin>>x; return x; } int main() { int l[10], u, v; char c; while (cin >> l[0] >> c) { rep(i, 9) cin >> l[i + 1] >> c; cin >> u >> c >> v; for (int i = 1; i < 10; ++i) { l[i] += l[i - 1]; } double d = (double)l[9] / (u + v) * u; for (int i = 0; i < 10; ++i) { if (l[i] >= d) { cout << i + 1 << endl; break; } } //rep(i, 10) cout << l[i] << endl; //cout << u << endl; //cout << v << endl; } }
#include <iostream> using namespace std; using ll = long long; const ll MOD = 1000000007; const int MAXXYZ = 17; int n,x,y,z; inline bool hasXYZ(int a){ return (a >> (z - 1)) & (a >> (y + z - 1)) & (a >> (x + y + z - 1)) & 1; } signed main(){ ll dp[50][1 << MAXXYZ] = {}; cin >> n >> x >> y >> z; dp[0][0] = 1; for(int i = 0;i < n;i++){ for(int j = 0;j < (1 << MAXXYZ);j++){ for(int k = 1;k <= 10;k++){ int nxt = ((j << k) + (1 << (k - 1))) % (1 << MAXXYZ); if(!hasXYZ(nxt)) (dp[i + 1][nxt] += dp[i][j]) %= MOD; } } } ll ans = 1; for(int i = 0;i < n;i++) ans = ans * 10 % MOD; for(int i = 0;i < (1 << MAXXYZ);i++) ans = (ans - dp[n][i] + MOD) % MOD; cout << ans << endl; }
0
#include<iostream> #include<iomanip> #include<cstring> #include<cmath> #include<cstdio> #include<queue> #include<algorithm> using namespace std; int n,s; struct que { int x; long long p; }a[100005]; long long calc(int l,int r,int last) { if(a[l].x>=s) return a[r].x-s; if(a[r].x<=s) return s-a[l].x; if(a[l].p>=a[r].p){a[l].p+=a[r].p;return calc(l,r-1,l)+((last==r)?a[r].x-a[l].x:0);} else {a[r].p+=a[l].p;return calc(l+1,r,r)+((last==l)?a[r].x-a[l].x:0);} } int main() { scanf("%d%d",&n,&s); for(int i=1;i<=n;i++) scanf("%d%lld",&a[i].x,&a[i].p); printf("%lld\n",calc(1,n,a[1].p<a[n].p?1:n)); }
#include<iostream> #include<vector> #include<algorithm> using namespace std; struct UnionFind { vector<int> par; UnionFind(int n) :par(n) { for (int i = 0; i < n; i++) { par[i] = i; } } int root(int x) { return par[x] == x ? x : par[x] = root(par[x]); } bool same(int x, int y) { return root(x) == root(y); } void merge(int x, int y) { int rx = root(x), ry = root(y); if (rx == ry)return; par[rx] = ry; } }; int main() { int n; cin >> n; vector<long long>x(n), y(n); for (int i = 0; i < n; i++)cin >> x[i] >> y[i]; using P = pair<int, int>; using edge = pair<long long, P>; vector<edge>edges; vector<int>ids(n); for (int i = 0; i < n; i++)ids[i] = i; sort(ids.begin(), ids.end(), [&](int i, int j) {return x[i] < x[j]; }); for (int i = 0; i < n - 1; i++) { int u = ids[i], v = ids[i + 1]; edges.push_back(edge(x[v] - x[u], P(u, v))); } sort(ids.begin(), ids.end(), [&](int i, int j) {return y[i] < y[j]; }); for (int i = 0; i < n - 1; i++) { int u = ids[i], v = ids[i + 1]; edges.push_back(edge(y[v] - y[u], P(u, v))); } sort(edges.begin(), edges.end()); UnionFind uf(n); long long ans = 0; for (auto e : edges) { int u = e.second.first, v = e.second.second; long long cost = e.first; if (uf.same(u, v))continue; uf.merge(u, v); ans += cost; } cout << ans << endl; return 0; }
0
#include <iostream> using i64 = long long; i64 abs(i64 x) { return x < 0 ? -x : x; } const int N = 100000 + 7; int n, s; int x[N], p[N]; i64 dfs(int l, int r, i64 u, i64 v) { if (s < x[l]) return x[r] - s; if (s > x[r]) return x[l] - s; if (u + p[l] >= v + p[r]) { i64 t = dfs(l, r - 1, u + v + p[r], 0); return x[r] - (t > 0 ? x[r - 1] : x[l]) + abs(t); } if (u + p[l] < v + p[r]) { i64 t = dfs(l + 1, r, 0, u + v + p[l]); return x[l] - (t > 0 ? x[r] : x[l + 1]) - abs(t); } } int main() { // freopen("code.in", "r", stdin); // freopen("code.out", "w", stdout); scanf("%d%d", &n, &s); for (int i = 1; i <= n; ++i) scanf("%d%d", x + i, p + i); printf("%lld\n", abs(dfs(1, n, 0, 0))); return 0; }
#include <bits/stdc++.h> using namespace std; vector<bool> visited, exhausted; stack<int> cycle; int closing_point; void DFS(const vector<vector<int>> &graph, int v, int previous_v){ visited[v] = true; cycle.push(v); for(auto next_v : graph[v]){ if(next_v == previous_v) continue; if(exhausted[next_v] == false){ if(visited[next_v] == true) closing_point = next_v; if(visited[next_v] == false) DFS(graph, next_v, v); if(closing_point != -1) return; } } // if // 1. no next_v (dead-end) or // 2. all next_v lead to dead-end cycle.pop(); exhausted[v] = true; } int main(){ int V, E; cin >> V >> E; vector<vector<int>> graph(V); for(int i=0; i<E; i++){ int s, t; cin >> s >> t; s -= 1; t -= 1; graph[s].push_back(t); // graph[t].push_back(s); } for(int i=0; i<V; i++){ visited.assign(V, false); exhausted.assign(V, false); while(cycle.empty() == false){ cycle.pop(); } closing_point = -1; DFS(graph, i, -1); vector<int> prov_ans; while(cycle.empty() == false){ int t = cycle.top(); cycle.pop(); prov_ans.push_back(t); if(t == closing_point) break; } int nvc = prov_ans.size();// number of vertices in the cycle if(nvc != 0){ reverse(prov_ans.begin(),prov_ans.end()); map<int, int> vc; for(int j=0; j<nvc; j++){ vc[prov_ans[j]] = j; } bool flag = false; int start = 0, end = nvc-1; for(int j=1; j<nvc; j++){ for(auto adjacent_v : graph[prov_ans[j]]){ // since directed if(j < nvc - 1 && adjacent_v == prov_ans[j+1]) continue; if(j == nvc - 1 && adjacent_v == prov_ans[0]) continue; if(vc.count(adjacent_v)){ //cout << prov_ans[j] << " -- " << adjacent_v << endl; flag = true; end = j; start = max(start, vc[adjacent_v]); } } if(flag == true){ cout << end - start + 1 << endl; for(int k=start; k<=end; k++){ cout << prov_ans[k] + 1 << endl; } return 0; } } cout << end - start + 1 << endl; for(int k=start; k<=end; k++){ cout << prov_ans[k] + 1 << endl; } return 0; } } cout << -1 << endl; return 0; }
0
#include<bits/stdc++.h> #include<ctype.h> # define pb push_back #define fst first #define sec second #define For(i,a,b) for(int i=a;i<b;i++) #define ll long long int #define ull unsigned long long int #define mod 1000000007 #define fo(i,n) for(ll i=0;i<n;i++) #define endl "\n" #define rev(i,n) for(ll i=n-1;i>=0;i--) #define fo1(i,n) for(ll i=1;i<=n;i++) #define boolsize 1000001 #define pi pair<ll,ll> #define vi vector<ll> #define vii vector<pi> using namespace std; template<typename T> void showvector(vector <T> v) { for(T x:v) cout<<x<<" "; cout<<endl; } template<typename T> void showvector1(vector <T> v) { ll n=v.size(); fo1(i,n-1) cout<<v[i]<<endl; } template<typename T> void showset(set <T> s) { for(T x: s) cout<<x<<" "; cout<<endl; } template<class T> void showvectorpair(vector<T> v) { for(auto it=v.begin();it!=v.end();it++) cout<<it->first<<" "<<it->second<<endl; cout<<endl; } template<typename T,typename P> void showmap(map <T,P> m) { for(auto it=m.begin();it!=m.end();it++) cout<<it->first<<" "<<it->second<<endl; cout<<endl; } template<typename T> bool comp(T a,T b) { return (a>b); } template<class T> bool comppair(T a,T b) { if(a.first==b.first) return(a.second>b.second); return (a.first>b.first); } bool sameparity(ll a,ll b) { return (a%2==b%2); } bool difparity(ll a,ll b) { return !(a%2==b%2); } bool isprime(ll x) { if(x<=1) return false; for(ll i=2;i<=sqrt(x);i++) { if(x%i==0) return false; } return true; } bool iseven(ll x) { return !(x%2); } bool isodd(ll x) { return (x%2); } /// check for test case before submitting void vfun() { ll n,k; cin>>n; vector <ll> v(n); fo(i,n) cin>>v[i]; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); ///cant use scanf, printf cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive //cout << fixed << setprecision(11); /// no scientific output ll test=1; //cin>>test; while(test--) { ll n; cin>>n; ll ans=n/11; ans=2*ans; if(n%11>=7) ans+=2; else if(n%11>0) ans+=1; cout<<ans<<endl; // if(vfun()) // cout<<"YES\n"; // else // cout<<"NO\n"; } } ///before sub /// check for value of zero and single input in array ///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs /// check whether test cases are given or not
#include<bits/stdc++.h> using namespace std; #define ll long long #define fast ios::sync_with_stdio(0); cin.tie(0); #define endl '\n' int main() { fast; int n; cin>>n; int ans=0; vector<int> v; for(int i=0;i<2*n;i++) { int x; cin>>x; v.push_back(x); } sort(v.begin(),v.end()); for(auto i=v.begin();i!=v.end();i=i+2) { // cout<<*i<<endl; ans+=*i; } cout<<ans<<endl; }
0
#include<bits/stdc++.h> using namespace std; int main(void){ int k;string s;cin>>k>>s; if(s.size()>k) {for(int i=0; i<k; ++i) cout<<s[i]; cout<<"..."<<endl;} else cout<<s<<endl; return 0; }
#include <bits/stdc++.h> #define rep(i,m,n) for(int i=m; i<n; i++) #define co(n) cout << n << endl using namespace std; int main(){ string s; cin >> s; char a[s.size()]; int c=0, d=0; rep(i,0,s.size()-8) cout << s.at(i); cout << endl; return 0; }
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> primes; vector<int> is_prime(55556, -1); for (int i = 2; i <= 55555; i++) { if (is_prime[i] != -1) continue; primes.push_back(i); is_prime[i] = 1; for (int j = i+i; j <= 55555; j+=i) { is_prime[j] = 0; } } int k = 0; for (int x: primes) { if (k == n) break; if (x % 5 == 1) { cout << x << " "; k++; } } cout << endl; }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); i++) using namespace std; const int MAX = 55556; vector<bool> ok(MAX, true); signed main(void) { int n; vector<int> vec; cin >> n; ok[0] = ok [1] = false; rep(i, sqrt(MAX)) { if (ok[i]) { for (int j = 0; i * (j + 2) < MAX; j++) { ok[i * (j + 2)] = false; } } } for(int i = 6; i < MAX; i += 5) { if (ok[i]) vec.push_back(i); } sort(vec.begin(), vec.end()); rep(i, n) { printf("%d%c", vec[i], i == n - 1?'\n':' '); } return 0; }
1
#include <iostream> #include <string> #include <vector> #include <set> #include <stack> #include <queue> #include <map> #include <algorithm> #include <iomanip> #include <math.h> #include <string.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>; int ctoi(char c) { switch (c) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default: return 0; } } bool pairCompare(const pll firstElof, pll secondElof) { return firstElof.first > secondElof.first; } //**Snippetリスト**// //rep, vin, all, iteLoop// //gcdlcm, isPrime, eratos, divisor, modinv, bitSearch, bitList, dfs, bfs// //dijkstra, UnionFind, COM, digitDP// ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z; ll MOD = 1000000007; ll INF = 9999999999999; ll ans = INF; vl flag, color, D; vll path; //***********// int main() { cin >> H >> W >> K; if (W == 1) cout << 1; else { vll sub_dp(W + 1, vl(2, 0)); sub_dp[0][1] = 1; for (i = 0; i < W; i++) { sub_dp[i + 1][0] = sub_dp[i][0] + sub_dp[i][1]; sub_dp[i + 1][1] = sub_dp[i][0]; } vl sub(W + 1); for (i = 0; i < W + 1; i++) { sub[i] = (sub_dp[i][0] + sub_dp[i][1]) % MOD; //cout << sub[i] << endl; } vll dp(H + 1, vl(W, 0)); dp[0][0] = 1; for (i = 0; i < H; i++) { for (j = 0; j < W; j++) { if (j == 0) { dp[i + 1][j] = (dp[i][j + 1] * sub[W - 2] + dp[i][j] * sub[W - 1]) % MOD; } else if (j == W - 1) { dp[i + 1][j] = (dp[i][j - 1] * sub[W - 2] + dp[i][j] * sub[W - 1]) % MOD; } else { dp[i + 1][j] = (dp[i + 1][j] + dp[i][j - 1] * sub[j - 1] * sub[W - j - 1]) % MOD; dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * sub[j] * sub[W - j - 1]) % MOD; dp[i + 1][j] = (dp[i + 1][j] + dp[i][j + 1] * sub[j] * sub[W - j - 2]) % MOD; } } } cout << dp[H][K - 1]; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; const int N = 2e5 + 5, mod = 998244353; int fact[N], rev[N]; int mult(int a, int b) { return (1LL * a * b) % mod; } int pw(int a, int b) { if(!b) return 1; int ans = pw(a, b / 2); ans = mult(ans, ans); if(b & 1) ans = mult(ans, a); return ans; } void prep() { fact[0] = 1; for (int i = 1; i < N; i++) fact[i] = mult(fact[i - 1], i); rev[N - 1] = pw(fact[N - 1], mod - 2); for (int i = N - 2; ~i; i--) rev[i] = mult(rev[i + 1], i + 1); } int sum(int a, int b) { a += b; if(a >= mod) a -= mod; if(a < 0) a += mod; return a; } int c(int n, int k) { if(k > n) return 0; return mult(fact[n], mult(rev[k], rev[n - k])); } int n, m, k; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); prep(); cin >> n >> m >> k; int ans = 0; for (int i = 0; i <= k; i++) ans = sum(ans, mult(m, mult(pw(m - 1, n - 1 - i), c(n - 1, i)))); cout << ans << "\n"; }
0
#include<bits/stdc++.h> #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb emplace_back #define mp make_pair #define all(v) v.begin(),v.end() #define sz(x) (ll)x.size() #define F first #define S second #define FOR(i,a,b) for(ll i=a;i<=b;++i) #define ROF(i,a,b) for(ll i=a;i>=b;--i) typedef long long ll; using namespace std; const int N = 1000001; bool cmp(const pair<int,int>&a, const pair<int,int>&b){ return a.S > b.S; } int n; vector<pair<int,int>>v1, v2; int main(){ IOS int n; cin >> n; FOR(i,1,n){ string s; cin >> s; int m = s.length(); int open = 0, closed = 0; FOR(j,0,m-1){ if(s[j] == '(') open++; else{ if(open > 0) open--; else closed++; } } if(open > closed) v1.pb(mp(open, closed)); else v2.pb(mp(open, closed)); } int remmatch = 0; sort(all(v1), cmp); sort(all(v2)); for(auto p:v2){ if(p.F > remmatch){ cout << "No"; return 0; } remmatch -= p.F; remmatch += p.S; } for(auto p:v1){ if(p.F > remmatch){ cout << "No"; return 0; } remmatch -= p.F; remmatch += p.S; } if(remmatch != 0) cout << "No"; else cout << "Yes"; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define PII pair < int , int > const int seed = 233 , MOD = 20190816170251; int N; char str[43]; map < PII , int > cnt; signed main(){ scanf("%d %s" , &N , str + 1); for(int i = 0 ; i < 1 << N ; ++i){ int p = 0 , q = 0; for(int j = 1 ; j <= N ; ++j) if(i >> (j - 1) & 1) p = (p * seed + str[j]) % MOD; else q = (q * seed + str[j]) % MOD; ++cnt[PII(p , q)]; } reverse(str + 1 , str + 2 * N + 1); int ans = 0; for(int i = 0 ; i < 1 << N ; ++i){ int p = 0 , q = 0; for(int j = 1 ; j <= N ; ++j) if(i >> (j - 1) & 1) p = (p * seed + str[j]) % MOD; else q = (q * seed + str[j]) % MOD; ans += cnt[PII(p , q)]; } cout << ans; return 0; }
0
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") //#include<bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstring> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int cm = 1 << 17; char cn[cm], * ci = cn + cm, ct; inline char getcha() { if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; } return *ci++; } inline int getint() { int A = 0; if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0'; else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0'; return A; } const int dm = 1 << 21; char dn[dm], * di = dn; const int MAX = 1000; class unko { public: char C[MAX * 6 + 10]; int K[MAX + 10]; constexpr unko() : C(), K() { auto di = C + 1; C[0] = '0'; K[0] = 0; K[1] = 1; rep1(i, MAX) { int X = i; int keta = 0; char c[10] = {}; while (X) { *(c + keta) = '0' + X % 10; X /= 10; keta++; } for (int j = keta - 1; j >= 0; j--)* di++ = (*(c + j)); K[i + 1] = K[i] + keta; } } }; constexpr unko f; inline void putint(ll X) { int ue = X / 1000; if (ue) { for (int i = f.K[ue]; i < f.K[ue + 1]; i++)* di++ = f.C[i]; int sita = X - ue * 1000; rep(i, 3 - f.K[sita + 1] + f.K[sita])* di++ = '0'; for (int i = f.K[sita]; i < f.K[sita + 1]; i++)* di++ = f.C[i]; } else for (int i = f.K[X]; i < f.K[X + 1]; i++)* di++ = f.C[i]; *di++ = '\n'; } int main() { //cin.tie(0); //ios::sync_with_stdio(false); int N = getint(), K = getint(); int A[200001]; rep(i, N) A[i] = getint(); ll owa = ll(N) * N; rep(p, K) { int B[200001] = {}; rep(i, N) { B[max(0, i - A[i])]++; B[min(N, i + A[i] + 1)]--; } ll kei = B[0]; A[0] = B[0]; rep1(i, N - 1) { kei +=(A[i] = A[i - 1] + B[i]); } if (kei == owa) break; } rep(i, N) putint(A[i]); fwrite(dn, 1, di - dn, stdout); Would you please return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int A,B,K; cin>>A>>B>>K; int temp=1; for(int i=0;i<K;i++){ if(temp==1){ if(A%2 == 1){ A--; } B+=A/2; A=A/2; temp=temp*(-1); continue; } if(temp==(-1)){ if(B%2 == 1){ B--; } A+=B/2; B=B/2; temp=temp*(-1); } } cout<<A<<" "<<B<<endl; return 0; }
0
#include<bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; using p = pair<int, int>; typedef vector<int> vi; int main() { int N, x; cin >> N >> x; int a[N]; rep(i, N) cin >> a[i]; sort(a, a+N); int ans = 0; for (int i = 0; i < N; i++) { if (x >= a[i]) { ++ans; x -= a[i]; } } if (ans == N && x > 0) --ans; cout << ans << endl; return 0; }
#include <bits/stdc++.h> // #undef DEBUG // Uncomment this line to forcefully disable debug print. #if DEBUG template <typename T> void debug(T value) { std::cerr << value; } template <typename T, typename... Ts> void debug(T value, Ts... args) { std::cerr << value << ", "; debug(args...); } #define dbg(...) \ do { \ cerr << #__VA_ARGS__ << ": "; \ debug(__VA_ARGS__); \ cerr << " (L" << __LINE__ << ")" << endl; \ } while (0) #else #define dbg(...) #endif void read_from_cin() {} template <typename T, typename... Ts> void read_from_cin(T& value, Ts&... args) { std::cin >> value; read_from_cin(args...); } #define in(type, ...) \ type __VA_ARGS__; \ read_from_cin(__VA_ARGS__); template <typename T> void write_to_cout(const T& value) { std::cout << value << std::endl; } template <typename T, typename... Ts> void write_to_cout(const T& value, const Ts&... args) { std::cout << value << ' '; write_to_cout(args...); } #define out(...) write_to_cout(__VA_ARGS__); #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using ll = long long; using namespace std; int main() { in(int, p, q, r); out(p + q + r - max({p, q, r})); }
0
#include<cstdio> #include<iostream> #include<vector> #include<string> #include<map> #include<stack> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define reps(i,n) for(int i=1;i<=n;i++) vector<int> card[10]; map<stack<int> ,int> check; int visit[10]; stack<int> ub; int cont; void saiki(int dep,int k,int n){ if(dep==k){ if(check[ub]==0){ check[ub]=1; cont++; } return; } rep(i,n){ if(visit[i]==0){ visit[i]=1; rep(j,card[i].size()){ ub.push(card[i][j]); } saiki(dep+1,k,n); rep(j,card[i].size()){ ub.pop(); } visit[i]=0; } } } int main(){ while(1){ int n; int k; scanf("%d%d",&n,&k); if(n==0)break; rep(i,10){ card[i].clear(); visit[i]=0; } check.clear(); cont=0; rep(i,n){ int a; scanf("%d",&a); if(a<10){ card[i].push_back(a); }else{ card[i].push_back(a/10); card[i].push_back(a%10); } } saiki(0,k,n); printf("%d\n",cont); } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i) #define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i) #define all(n) begin(n), end(n) using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vl = vector<ll>; using vs = vector<string>; using vc = vector<char>; using vb = vector<bool>; using vd = vector<double>; vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1}; int main() { int n, m; cin >> n >> m; vi a(m); rep(i, m) cin >> a[i]; sort(all(a), greater<int>()); vi v = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; vi dp(n + 10, -1); dp[0] = 0; rep(i, n) rep(j, m) { if(dp[i] == -1) continue; dp[i + v[a[j]]] = max(dp[i + v[a[j]]], dp[i] + 1); } string ans; int i = n; while(i) { for(int j : a) { if(i - v[j] >= 0 && dp[i - v[j]] == dp[i] - 1) { i -= v[j]; ans += char('0' + j); break; } } } cout << ans << endl; }
0
//Space Coconut Grab #include<bits/stdc++.h> using namespace std; #define INF 10000000 typedef long long ll; //x^t ll mypow(ll x, ll t){ return (ll)pow((double)x, (double)t); } ll ans[1000001]; int main(){ for(ll i=0; i<=1000000; i++)ans[i]=INF; for(ll z=0; mypow(z, 3)<=1000000; z++){ ll tmp; for(ll y=0; (tmp=mypow(z,3)+mypow(y,2))<=1000000; y++) if(ans[tmp]>y+z) ans[tmp]=y+z; } while(true){ ll e; cin>>e; if(e==0)break; ll mn=INF; for(int i=0; i<=e; i++) if(mn>ans[i]+(e-i))mn=ans[i]+(e-i); cout<<mn<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> duo; #define TT template<typename T> TT T sq(T x){ return x*x; } TT int ubnd(vector<T>& v,T x){ return upper_bound(v.begin(), v.end(), x) - v.begin(); } TT int lbnd(vector<T>& v,T x){ return lower_bound(v.begin(), v.end(), x) - v.begin(); } TT void sort(T& v){ sort(v.begin(), v.end()); } TT void revs(T& v){ reverse(v.begin(), v.end()); } TT void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); } TT void show(T& v,char d=' ',char e='\n'){for(int i=0;i<v.size();++i)cout<<v[i]<<((i==v.size()-1)?e:d);} TT void inpt(vector<T>& v,int n){ v.reserve(n);for(int i=0;i<n;++i){T x; cin>>x; v.push_back(x);} } TT T In(){ T x; cin >> x; return x; } static inline void fast_io(){ ios::sync_with_stdio(0); cin.tie(0); } static inline int in(){ int x; scanf("%d", &x); return x; } static inline string instr(){ string x; cin >> x; return x; } static const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1}; static const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1}; int main() { while (int e = in()){ int m = 1e8; for (int z = 0; z <= 100; ++z){ for (int y = 0; y <= 1000; ++y){ int x = e - (sq(z) * z + sq(y)); if (x < 0) continue; m = min(m, z + y + x); } } printf("%d\n", m); } return (0); }
1
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define fi first #define se second #define em emplace #define eb emplace_back #define mp make_pair #define pi pair<int,int> #define vi vector<int> #define vpi vector<pair<int,int>> #define vll vector<ll> #define vpll vector<pair<ll,ll>> #define endl '\n' #define si(v) int(v.size()) #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep2(i, n, m) for (ll i = n; i <= (m); ++i) #define rep3(i, n, m) for (ll i = n; i >= (m); --i) template<class T, class U> bool chmax(T &a, U b) { if (a < b) a = b; return true; } template<class T, class U> bool chmin(T &a, U b) { if (b < a) a = b; return true; } using ll = long long; using ld = long double; using namespace std; constexpr ll MOD = 1000000007; signed main() { cout << fixed << setprecision(20); ios::sync_with_stdio(false); cin.tie(0); int a; cin >> a; cout << a + a*a + a*a*a << endl; return (0); }
#include<bits/stdc++.h> // Begin Header {{{ using namespace std; using ll = long long; using P = pair<ll, ll>; using Graph = vector<vector<ll>>; #define rep(i,n) for(ll i=0; i<n; i++) #define loop(i, j, n) for(ll i=j; i<n; i++) #define all(x) (x).begin(), (x).end() constexpr int INF = 0x3f3f3f40; const long long mod=2e9+7; const long double PI = acos(0); // }}} End Header int main() { ll x, ans=0; cin >> x; ans+=1000*(x/500); x%=500; ans+=5*(x/5); cout << ans << endl; return 0; }
0
#include <iostream> #include <algorithm> #include <vector> using namespace std; vector<int> articulation_points; vector<int> graph[100000]; int ord[100000],low[100000]; bool visited[100000]; int visit_time = 0; void dfs(int v,int p){ visited[v] = true; ord[v] = visit_time; low[v] = ord[v]; visit_time++; bool is_articulation = false; int cnt = 0; for(int i=0;i<graph[v].size();++i){ if(!visited[graph[v][i]]){ cnt++; dfs(graph[v][i],v); low[v] = min(low[v],low[graph[v][i]]); if(p!=-1&&ord[v]<=low[graph[v][i]]) is_articulation = true; }else if(graph[v][i]!=p){ low[v] = min(low[v],ord[graph[v][i]]); } } if(p==-1&&cnt > 1) is_articulation = true; if(is_articulation) articulation_points.emplace_back(v); } int main(){ int N , M ; cin >> N >> M; for(int i=0;i<M;++i){ int s,t; cin >> s >> t; graph[s].push_back(t); graph[t].push_back(s); } for(int i=0;i<N;++i){ if(!visited[i]) dfs(i,-1); } sort(articulation_points.begin(),articulation_points.end()); for(const auto &a:articulation_points){ cout << a << endl; } return 0; }
#include <iostream> #include <vector> #include <set> using namespace std; static const int NIL = -1; struct Vertex { vector<int> link; int parent = NIL; int ord; int lowlink; bool is_visit = false; }; class ArticulationPoint { private: int n; vector<Vertex> graph; int timer = 1; public: ArticulationPoint() {} ArticulationPoint(int n) { this->n = n; graph.resize(n); int edge; cin >> edge; int s, t; for (int e = 0; e < edge; e++) { cin >> s >> t; graph[s].link.push_back(t); graph[t].link.push_back(s); } } void dfs(int current) { graph[current].is_visit = true; graph[current].ord = graph[current].lowlink = timer; timer++; for(int next : graph[current].link) { if(!graph[next].is_visit) { graph[next].parent = current; dfs(next); graph[current].lowlink = min(graph[current].lowlink, graph[next].lowlink); // 3. } else if(next != graph[current].parent) { // 1回の移動で行くことのできる訪問済みの頂点は,Backedgeを除けば自分の親しかいない // つまりこのブロックにくるのはnextがBackedgeを通った訪問済みの頂点のとき graph[current].lowlink = min(graph[current].lowlink, graph[next].ord); } } } void articulation_point() { set<int> art_point; int root = 0; dfs(root); int root_child_num = 0; for(int u = 0; u < n; u++) { int p = graph[u].parent; if(p == NIL) continue; if(p == root) { root_child_num++; if(root_child_num >= 2) art_point.insert(root); } else if(graph[p].ord <= graph[u].lowlink) { art_point.insert(p); } } for(int x : art_point) cout << x << endl; } }; int main() { int n; cin >> n; ArticulationPoint articulationPoint(n); articulationPoint.articulation_point(); }
1
#include <iostream> #include <cstdio> #include <string> #include <cstring> //#include <algorithm> #include <queue> #include <map> #include <set> #include <cmath> #include <vector> #define INF 0x3f3f3f typedef long long ll; const int maxn = 1e3 + 5; const ll mod = 1e9 + 7; const double pi = acos(-1.0); int n, m; int dis[maxn][maxn]; std::vector<int> v[maxn]; void GetDistance(int u) { std::queue<int> q; q.push(u); dis[u][u] = 0; while (!q.empty()) { int cur = q.front(); q.pop(); for (int i=0; i < v[cur].size(); i++) { if (dis[u][cur] + 1 < dis[u][v[cur][i]]) { dis[u][v[cur][i]] = dis[u][cur] + 1; q.push(v[cur][i]); } } } } void FindPath(int s, int t, std::set<int> &S) { int pre[maxn]; memset(pre, 0, sizeof(pre)); S.insert(s); std::queue<int> q; q.push(s); pre[s] = s; while (!q.empty()) { int cur = q.front(); q.pop(); if (cur == t) { int u = cur; while (pre[u] != s) { u = pre[u]; S.insert(u); } return; } for (int i=0; i < v[cur].size(); i++) { if (!pre[v[cur][i]]) { pre[v[cur][i]] = cur; q.push(v[cur][i]); } } } } int main(int argc, char **argv){ std::cin >> n >> m; int x, y; for (int i=1; i <= m; i++) { std::cin >> x >> y; v[x].push_back(y); } memset(dis, INF, sizeof(dis)); for (int i=1; i <= n; i++) { GetDistance(i); } int ans = n+2; int s = -1, t = -1; for (int i=1; i <= n; i++) { for (int j=i+1; j <= n; j++) { if (dis[i][j] + dis[j][i] < ans) { ans = dis[i][j] + dis[j][i]; s = i; t = j; } } } // std::cout << s << " " << t << " " << ans << std::endl; if (s != -1 && t != -1) { std::cout << ans << std::endl; std::set<int> S; FindPath(s, t, S); FindPath(t, s, S); for (auto& it: S) { std::cout << it << std::endl; } } else { std::cout << "-1" << std::endl; } return 0; }
#include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <cfloat> #include <climits> #include <ctime> #include <cassert> #include <numeric> #include <fstream> #include <functional> #include <bitset> #define chmin(a, b) ((a)=min((a), (b))) #define chmax(a, b) ((a)=max((a), (b))) #define fs first #define sc second #define eb emplace_back using namespace std; typedef long long ll; typedef pair<int, int> P; typedef tuple<int, int, int> T; const ll MOD=1e9+7; const ll INF=1e18; const double pi=acos(-1); const double eps=1e-10; int dx[]={1, 0, -1, 0}; int dy[]={0, -1, 0, 1}; int main(){ int n, m; cin>>n>>m; vector<int> p(m), q(m), c(m); vector<P> v; for(int i=0; i<n; i++){ v.push_back(P(i, -1)); } for(int i=0; i<m; i++){ cin>>p[i]>>q[i]>>c[i]; p[i]--, q[i]--; v.push_back(P(p[i], c[i])); v.push_back(P(q[i], c[i])); } sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); int nn = v.size(); map<P, int> p2v; for(int i=0; i<nn; i++){ p2v[v[i]] = i; } vector<vector<P>> edge(nn); for(int i=0; i<nn; i++){ if(v[i].second == -1) continue; int station = v[i].first; int out = p2v[P(station, -1)]; edge[i].push_back(P(out, 0)); edge[out].push_back(P(i, 1)); } for(int i=0; i<m; i++){ int s = p2v[P(p[i], c[i])]; int t = p2v[P(q[i], c[i])]; edge[s].push_back(P(t, 0)); edge[t].push_back(P(s, 0)); } int s = p2v[P(0, -1)]; int g = p2v[P(n-1, -1)]; vector<int> dist(nn, 1e9); dist[s] = 0; priority_queue<P, vector<P>, greater<P>> que; que.push(P(0, 0)); while(que.size()){ int cdist, cv; tie(cdist, cv) = que.top(); que.pop(); if(dist[cv] < cdist) continue; for(auto i:edge[cv]){ int nv, ndist; tie(nv, ndist) = i; if(dist[cv] + ndist < dist[nv]){ dist[nv] = dist[cv] + ndist; que.push(P(dist[nv], nv)); } } } cout << (dist[g] == 1e9 ? -1 : dist[g]) << endl; }
0
#include <iostream> #include <string> #include <map> using namespace std; int main(void) { map<char,int> a = {{'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}}; string str; while(getline(cin, str)) { int b = 0, c = a[str[0]], d = a[str[0]]; for(int i = 1; i < str.length(); ++i) { int e = a[str[i]]; if (e == d) { c += e; } else if (d < e) { b -= (c); c = e; } else if (e < d) { b += (c); c = e; } d = e; } b += c; cout << b << endl;; } return 0; }
#include <iostream> using namespace std; int main() { int date[13][32]; for(int i = 1;i<=31;i++)date[1][i] = i; for(int i = 1;i<=28;i++)date[2][i] = i+3; for(int i = 1;i<=31;i++)date[3][i] = i+4; for(int i = 1;i<=31;i++)date[4][i] = i; for(int i = 1;i<=31;i++)date[5][i] = i+2; for(int i = 1;i<=31;i++)date[6][i] = i+5; for(int i = 1;i<=31;i++)date[7][i] = i; for(int i = 1;i<=31;i++)date[8][i] = i+3; for(int i = 1;i<=31;i++)date[9][i] = i+6; for(int i = 1;i<=31;i++)date[10][i] = i+1; for(int i = 1;i<=31;i++)date[11][i] = i+4; for(int i = 1;i<=31;i++)date[12][i] = i+6; int month,day; while(true) { cin >> month; cin >> day; if(month==0&&day==0)break; switch (date[month][day] % 7) { case 0: cout << "Wednesday" << endl; break; case 1: cout << "Thursday" << endl; break; case 2: cout << "Friday" << endl; break; case 3: cout << "Saturday" << endl; break; case 4: cout << "Sunday" << endl; break; case 5: cout << "Monday" << endl; break; case 6: cout << "Tuesday" << endl; break; } } return 0; }
0
#pragma GCC optimize ("Ofast") #pragma GCC target ("avx2") #include <cstdio> #include <cstdlib> #include <iostream> #include <fstream> using namespace std; #define NMAX 200001 int a[NMAX]; int imos[NMAX]; void reset(int n) { for(int i = 0; i < n; i++) imos[i] = 0; } int max(int a, int b) { if(a > b) return a; else return b; } int min(int a, int b) { if(a > b) return b; else return a; } int get_int() { int res = 0; char c = getchar(); while(c != EOF && c != ' ' && c != '\n') { res *= 10; res += c - '0'; c = getchar(); } return res; } void put_int(int n) { char c[30]; int sz = 0; c[sz++] = (n % 10) + '0'; n /= 10; while(n > 0) { c[sz++] = (n % 10) + '0'; n /= 10; } for(int i = sz-1; i >= 0; i--) { putchar(c[i]); } putchar('\n'); } int main(){ int n, k; n = get_int(); k = get_int(); for(int i = 0; i < n; i++) a[i] = get_int(); for(int itr = 0; itr < k; itr++) { int f = 0; reset(n+1); for(int i = 0; i < n; i++){ imos[max(0, i - a[i])]++; imos[min(n, i + a[i] + 1)]--; } int acc = 0; for(int i = 0; i < n; i++){ acc += imos[i]; a[i] = acc; } int sum = 0; for(int i = 0; i < n; i++) sum += a[i]; if(sum == n * n) break; } for(int i = 0; i < n; i++) put_int(a[i]); return 0; }
#include<iostream> #include<algorithm> using namespace std; int main() { int a[5001] = { 0 }; int n; while (1) { cin >> n; if (n == 0)break; // a[0] = 0; int maxv = -100000; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { a[i] = max(a[i], a[i] + a[i - 1]); maxv = max(maxv, a[i]); } cout << maxv << endl; } }
0
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair<int,int> ; using pll = pair<long long,long long>; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; int main(){ int n; ll x; cin >> n >> x; vector<ll> a(n); rep(i,n) cin >> a[i]; sort(a.begin(),a.end()); ll now = 0; int ans = n; rep(i,n){ now += a[i]; if(now > x){ ans = i; break; } } if(ans==n&&now!=x) cout << (n-1) << endl; else cout << ans << endl; return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; int main() { int N, x; cin >> N >> x; vector<int> v(N); for (int i = 0; i < N; i++) { cin >> v.at(i); } sort(v.begin(), v.end()); int cnt = 0; if (x < v.at(0)) { cout << 0; } else { for (int i = 0; i < N && x >= v.at(i); i++) { cnt++; x -= v.at(i); } if (cnt == N && x > 0) cnt--; cout << cnt; } }
1
#include<bits/stdc++.h> #define N 110 using namespace std; char s[N][N]; int sum[N][N],h,w,eh,ew; int dp[N*N/4][N*N/4]; inline int rg(int l,int r,int d,int u){ if(l>r||d>u) return 0; return sum[r][u]-sum[l-1][u]-sum[r][d-1]+sum[l-1][d-1]; } int solve(int ch,int cw){ if(!ch&&!cw) return 0; if(dp[ch][cw]>=0) return dp[ch][cw]; int l=ch%eh,r=ch/eh,d=cw%ew,u=cw/ew; if(l){ dp[ch][cw]=max(dp[ch][cw],solve(ch-1,cw)+ (eh-l>r?rg(eh-l,eh-l,max(1+u,ew-d),min(w-d,ew+u)):0) ); } if(r){ dp[ch][cw]=max(dp[ch][cw],solve(ch-eh,cw)+ (eh+r<=h-l?rg(eh+r,eh+r,max(1+u,ew-d),min(w-d,ew+u)):0) ); } if(d){ dp[ch][cw]=max(dp[ch][cw],solve(ch,cw-1)+ (ew-d>u?rg(max(1+r,eh-l),min(h-l,eh+r),ew-d,ew-d):0) ); } if(u){ dp[ch][cw]=max(dp[ch][cw],solve(ch,cw-ew)+ (ew+u<=w-d?rg(max(1+r,eh-l),min(h-l,eh+r),ew+u,ew+u):0) ); } return dp[ch][cw]; } int main(){ scanf("%d%d",&h,&w); for(int i=1;i<=h;i++){ scanf("%s",s[i]+1); for(int j=1;j<=w;j++){ sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]; if(s[i][j]=='o') sum[i][j]++; else if(s[i][j]=='E') eh=i,ew=j; } } memset(dp,-1,sizeof(dp)); printf("%d\n",solve(eh*(h-eh)+eh-1,ew*(w-ew)+ew-1)); return 0; }
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int n,m,Ex,Ey,Ans,f[2][110][110][110]; int g[110][110],row[110][110],line[110][110]; inline int Row(int id,int L,int R) {return row[id][R]-row[id][L-1];} inline int Line(int U,int D,int id) {return line[D][id]-line[U-1][id];} int main() { //#ifdef h10 // freopen("robots.in","r",stdin); // freopen("robots.out","w",stdout); //#endif int i,j,U,D,L,R; char c; scanf("%d%d",&n,&m); for (i=1;i<=n;i++) for (j=1;j<=m;j++) { c=getchar(); while (c!='.'&&c!='o'&&c!='E') c=getchar(); if (c=='o') g[i][j]=1; if (c=='E') Ex=i,Ey=j; row[i][j]=row[i][j-1]+g[i][j]; line[i][j]=line[i-1][j]+g[i][j]; } for (U=0;U<Ex;U++) for (D=0;D<=n-Ex;D++) for (L=0;L<Ey;L++) for (R=0;R<=m-Ey;R++) { int X=U&1,Y=X^1,&val=f[X][D][L][R]; int u=max(D+1,Ex-U),d=min(Ex+D,n-U); int l=max(R+1,Ey-L),r=min(Ey+R,m-L); if (U&&Ex-U-D>0) val=max(val,f[Y][D][L][R]+Row(Ex-U,l,r)); if (D&&Ex+D+U<=n) val=max(val,f[X][D-1][L][R]+Row(Ex+D,l,r)); if (L&&Ey-L-R>0) val=max(val,f[X][D][L-1][R]+Line(u,d,Ey-L)); if (R&&Ey+R+L<=m) val=max(val,f[X][D][L][R-1]+Line(u,d,Ey+R)); Ans=max(Ans,val); } printf("%d\n",Ans); }
1
#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(){ int sx,sy,tx,ty; cin >> sx >> sy >> tx >> ty; string ans; int zyoge=abs(ty-sy); int sayu=abs(tx-sx); char rl,ud; //1 if(tx-sx>=0){ rl='R'; }else{ rl='L'; } if(ty-sy>=0){ ud='U'; }else{ ud='D'; } int i,j; for(i=0;i<zyoge;i++){ ans=ans+ud; } for(j=0;j<sayu;j++){ ans+=rl; } //2 if(tx-sx>=0){ rl='L'; }else{ rl='R'; } if(ty-sy>=0){ ud='D'; }else{ ud='U'; } for(i=0;i<zyoge;i++){ ans=ans+ud; } for(j=0;j<sayu;j++){ ans+=rl; } //3 if(tx-sx>=0){ rl='R'; ans+='D'; }else{ rl='L'; ans+='D'; } if(ty-sy>=0){ ud='U'; }else{ ud='D'; } for(j=0;j<sayu+1;j++){ ans+=rl; } for(i=0;i<zyoge+1;i++){ ans=ans+ud; } //4 if(tx-sx>=0){ ans+='L'; rl='L'; ans+='U'; }else{ ans+='R'; rl='R'; ans+='U'; } if(ty-sy>=0){ ud='D'; }else{ ud='U'; } for(j=0;j<sayu+1;j++){ ans+=rl; } for(i=0;i<zyoge+1;i++){ ans=ans+ud; } if(tx-sx>=0){ ans+='R'; }else{ ans+='L'; } cout << ans; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define all(x) (x).begin(),(x).end() using ll = long long; string char_to_string(char val) { return string(1, val); } int char_to_int(char val) { return val - '0'; } 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 vector_finder(std::vector<ll> vec, int number) { auto itr = std::find(vec.begin(), vec.end(), number); size_t index = std::distance( vec.begin(), itr ); if (index != vec.size()) { // 発見できたとき return 1; } else { // 発見できなかったとき return 0; } } int main() { int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty; int x = tx - sx; int y = ty - sy; vector<string> ans; REP(i, y) ans.push_back("U"); REP(i, x) ans.push_back("R"); REP(i, y) ans.push_back("D"); REP(i, x) ans.push_back("L"); ans.push_back("L"); REP(i, y + 1) ans.push_back("U"); REP(i, x + 1) ans.push_back("R"); ans.push_back("D"); ans.push_back("R"); REP(i, y + 1) ans.push_back("D"); REP(i, x + 1) ans.push_back("L"); ans.push_back("U"); REP(i, ans.size()) cout << ans[i]; cout << endl; }
1
#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++) int main() { int N, K; cin >> N >> K; vector<int> v(N); rep(i, N) { cin >> v.at(i); } int a=0, b=0, c=0, x, y, z; rep(i, min(K,50)) { vector<int> vv(N+1); rep(j, N) { x = v.at(j); vv.at(max(j-x, 0)) += 1; vv.at(min(j+x+1,N)) -= 1; } v.at(0) = vv.at(0); rep1(j, N) { v.at(j) = v.at(j-1) + vv.at(j); } } rep(i, N) { cout << v.at(i) << " "; } }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define debug(var) cerr << (#var) << " = " << (var) << endl; #else #define debug(var) #endif void init() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void solve() { int n, k; scanf("%d%d", &n, &k); int g = -1, m = 0; for (int a, i = 0; i < n; ++i) { scanf("%d", &a); m = max(m, a); if (g == -1) g = a; else g = __gcd(g, a); } if (k > m || k % g) puts("IMPOSSIBLE"); else puts("POSSIBLE"); } int main() { init(); int t = 1; //scanf("%d", &t); while (t--) { solve(); } return 0; }
0
#include<bits/stdc++.h> #define N 1000006 using namespace std; int f[N][2],n; char s[N]; int main() { f[0][1]=1; scanf("%s",s+1); n=strlen(s+1); for (int i=1;i<=n;i++) f[i][0]=min(f[i-1][0]+(s[i]^48),f[i-1][1]+10-(s[i]^48)), f[i][1]=min(f[i-1][0]+(s[i]^48)+1,f[i-1][1]+9-(s[i]^48)); printf("%d\n",min(f[n][0],f[n][1]+1)); }
#include<bits/stdc++.h> #define ll long long int #define mod 998244353 #define ld long double #define pb push_back #define inf INT_MAX #define N 1000000 using namespace std; int n,m,k; ll ans=0; ll inv[N+3]; ll fact_inv[N+3]; ll fact[N+3]; //modulo inverse void inverse(){ inv[1]=1;//MMI int i; for(i=2;i<=N;i++){ inv[i]=mod-(mod/i)*inv[mod%i]%mod; } } void factinv(){ int i; fact_inv[0]=1; for(i=1;i<=N;i++){ fact_inv[i]=fact_inv[i-1]*inv[i]%mod; } } void facto(){ int i; fact[0]=1; for(i=1;i<=N;i++){ fact[i]=(fact[i-1]*i)%mod; } } ll power(int a,int b){ if(b==0) return 1; else if(b==1) return a; else{ if(b&1) return ((a%mod)*(power(a,b-1)%mod))%mod; else return ((power(a,b/2)%mod)*(power(a,b/2)%mod))%mod; } } void solve(int p){ ll a=((fact_inv[n-p-1]%mod)*(fact_inv[p]%mod))%mod; ll b=(m*power(m-1,n-p-1)%mod)%mod; ll c=(a*b)%mod; ans+=(fact[n-1]*c)%mod; ans%=mod; } int main(void){ ios_base::sync_with_stdio(false); cin.tie(NULL); int i; cin>>n>>m>>k; facto(); inverse(); factinv(); //cout<<inv[123]<<endl; for(i=0;i<=k;i++) solve(i); cout<<ans<<endl; }
0
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<tuple> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define Per(i,sta,n) for(int i=n-1;i>=sta;i--) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef long double ld; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; int dx[4]={1,-1,0,0}; int dy[4]={0,0,1,-1}; int n,m=250; int S[300][300]; vector<P> v; void plot(ll x,ll y){ int cnt2=0,cnt5=0; while(x%2==0){ x/=2; cnt2+=1; } while(y%2==0){ y/=2; cnt2-=1; } while(x%5==0){ x/=5; cnt5+=1; } while(y%5==0){ y/=5; cnt5-=1; } S[cnt2+100][cnt5+100]+=1; v.push_back(P(cnt2,cnt5)); } void solve(){ cin >> n; rep(i,n){ ll a=0,b=1;string s; cin >> s; bool flag=false; rep(i,s.length()){ if(s[i]=='.') flag=true; else{ if(flag) b*=10; a*=10; a+=s[i]-'0'; } } plot(a,b); } rep(i,m) rep(j,m) { S[i][j+1]=S[i][j]+S[i][j+1]; } rep(j,m+1) rep(i,m) { S[i+1][j]=S[i][j]+S[i+1][j]; } ll ans=0; rep(i,n){ int x=v[i].first,y=v[i].second; ans+=S[m][m]-S[-x+99][m]-S[m][-y+99]+S[-x+99][-y+99]; if(x>=0 && y>=0) ans-=1; } cout << ans/2 << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); solve(); }
#include <bits/stdc++.h> #define ll long long using namespace std; void solve() { int n; cin >> n; map<pair<int, int>, int> cnt; for (int i = 1; i <= n; ++i) { long double ai; cin >> ai; ll val = (ll) (ai * 1000000000.0 + 0.5); ll cnt2 = 0; ll cnt5 = 0; while (val % 2 == 0) { cnt2++; val /= 2; } while (val % 5 == 0) { cnt5++; val /= 5; } cnt[make_pair(cnt2, cnt5)]++; } ll ans = 0; for (const auto &pi: cnt) { for (const auto &pj: cnt) { if (pi.first.first + pj.first.first >= 18 && pi.first.second + pj.first.second >= 18) { if (pi == pj) { ans += pi.second * (pi.second - 1ll); } else { ans += pi.second * 1ll * pj.second; } } } } cout << ans / 2 << endl; } int main(){ solve(); }
1
// //AtCoder Beginner Contest 125 //D //https://atcoder.jp/contests/abc125/tasks/abc125_d // #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; cin >> n; vector<int> a(n); int mCnt=0; int mMax=1e9*-1; int pMin=1e9; REP(i, n) { cin >> a[i]; if (a[i]<0) { mCnt++; mMax = max(mMax, a[i]); }else{ pMin = min(pMin, a[i]); } } ll ans=0; REP(i,n) ans+=abs(a[i]); if (mCnt%2==1){ ans -= 2*min(pMin, abs(mMax)); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define irep(i, n) for (int i = (n); i >= 0; i--) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1 << 25; const int MOD = 1e9+7; int a[int(1e5+10)]; ll dp[100010][2]; int main() { int n; cin >> n; rep(i,n) cin >> a[i]; dp[0][0] = 0; dp[0][1] = -(1LL<<60); rep(i,n) { dp[i+1][0]=max(dp[i][0]+a[i],dp[i][1]-a[i]); dp[i+1][1]=max(dp[i][0]-a[i],dp[i][1]+a[i]); } cout << dp[n][0] << endl; return 0; }
1
#include <iostream> #include <string> #include <vector> enum face { TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM }; class dice { public: dice(); void setDice(int spot, int eye); int getSpot(int top); void rollNorth(); void rollSouth(); void rollEast(); void rollWest(); void rollRight(); void rollLeft(); std::vector<dice> all_rolls(); int& operator[] (face f) {return id[f];} const int& operator[] (face f) const {return id[f];} bool operator==(const dice &b) const { const dice &a = *this; return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] && a[FRONT] == b[FRONT] && a[BACK] == b[BACK] && a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT]; } bool equivalent_to(const dice &di); private: void roll(face a, face b, face c, face d); std::vector<int> id; }; dice::dice() { id.resize(6); } void dice::setDice(int spot, int eye) { switch(eye) { case TOP: id[TOP] = spot; break; case BOTTOM: id[BOTTOM] = spot; break; case FRONT: id[FRONT] = spot; break; case BACK: id[BACK] = spot; break; case LEFT: id[LEFT] = spot; break; case RIGHT: id[RIGHT] = spot; break; } } int dice::getSpot(int top) { return id[top]; } void dice::rollNorth() { roll(TOP, FRONT, BOTTOM, BACK); } void dice::rollSouth() { roll(TOP, BACK, BOTTOM, FRONT); } void dice::rollEast() { roll(TOP, LEFT, BOTTOM, RIGHT); } void dice::rollWest() { roll(TOP, RIGHT, BOTTOM, LEFT); } void dice::rollRight() { roll(FRONT, LEFT, BACK, RIGHT); } void dice::rollLeft() { roll(FRONT, RIGHT, BACK, LEFT); } std::vector<dice> dice::all_rolls() { std::vector<dice> ret; for(int k = 0; k < 6; (k&1 ? rollEast(): rollNorth()), ++k) { for(int i = 0; i < 4; rollRight(), ++i) { ret.push_back(*this); } } return ret; } bool dice::equivalent_to(const dice &di) { for(int k = 0; k < 6; (k & 1 ? rollEast(): rollNorth()), ++k) { for(int i = 0; i < 4; rollRight(), ++i) { if(*this == di) { return true; } } } return false; } void dice::roll(face a, face b, face c, face d) { int tmp = id[a]; id[a] = id[b]; id[b] = id[c]; id[c] = id[d]; id[d] = tmp; } int main() { int d, n; std::cin >> n; std::vector<dice> dices(n); for(int i = 0; i < n; ++i) { dice di; for(int j = 0; j < 6; ++j) { std::cin >> d; di.setDice(d, j); } dices[i] = di; } for(int i = 0; i < n; ++i) { for(int j = i + 1; j < n; ++j) { if(dices[i].equivalent_to(dices[j])) { std::cout << "No" << std::endl; return 0; } } } std::cout << "Yes" << std::endl; return 0; }
#include <iostream> #include <vector> using namespace std; int main(){ int N, Q; while(cin >> N >> Q, N){ vector<int> cnt(101, 0); for(int i=0;i<N;i++){ int M; cin >> M; for(int j=0;j<M;j++){ int d; cin >> d; cnt[d]++; } } int res = 0; for(int i=0;i<=100;i++){ if(cnt[res] < cnt[i]) res = i; } cout << (cnt[res] >= Q ? res : 0) << endl; } }
0
#include<iostream> #include<stdio.h> #include<string.h> #include<math.h> using namespace std; #define MAX 256 #define S(x) (x*x) int f(int z){ if (z < 10)return 1; return 1 + f(z / 10); } int main(void){ int ans[MAX]; for (int i = 0; i < MAX; i++){ ans[i] = 0; } int d; int i = 0; while (scanf("%d", &d) != EOF){ for (int j = d; j <= 600 - d; j += d){ ans[i] += S(j)*d; } i++; } for (int j = 0; j < i; j++){ printf("%d\n", ans[j]); } return 0; }
#include <iostream> #include <iomanip> #include <cmath> using namespace std; int f(int x) { return pow(x, 2); } int main() { int n; while (cin >> n) { long long int sum = 0; for (int i = n; i <= 600 - n; i += n) sum += f(i)*n; cout << sum << endl; } return 0; }
1
#include<iostream> #include<cstdio> #include<cstring> using namespace std; inline int read(){ int x=0,f=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-')f=-1; c=getchar(); } while(c>='0'&&c<='9'){ x=(x<<1)+(x<<3)+c-'0'; c=getchar(); } return x*f; } int A,B; const int c[5]={0,300000,200000,100000,0}; int main(){ A=read(),B=read(); if(A==1&&B==1){ return !printf("1000000\n"); } A=min(A,4),B=min(B,4); printf("%d\n",c[A]+c[B]); return 0; }
#include <bits/stdc++.h> #include <string> #include <algorithm> #include <string.h> #include <ctype.h> #include <math.h> #include <float.h> #include <iomanip> #include <iostream> using namespace std; int main(){ int A,B,ans=0; cin>>A>>B; for(int i=1;i<=3;i++){ if(A==i)ans+=(4-i)*100000; if(B==i)ans+=(4-i)*100000; } if(A==1&&B==1)ans+=400000; cout <<ans<<endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); int i; int n; cin>>n; int a[n],b[n]; for (i = 0 ; i < n ; i++) cin>>a[i]; for (i = 0 ; i < n ; i++) cin>>b[i]; int s[3*n+2]; s[0] = -2; for (i = 1; i < n+1 ; i++) s[i] = b[i-1]^b[i%n]; s[n+1] = -1; for (i = n+2; i < 2*n+2 ; i++) s[i] = a[i-n-2]^a[(i-n-1)%n]; for (i = 2*n+2; i < 3*n+2 ; i++) s[i] = s[i-n]; //for (i = 0; i < 3*n+2; i++) cout<<s[i]<<" "; int P[3*n+2]; P[1] = 0; for (i = 2; i < 3*n+1; i++){ int ps = P[i-1]; while (s[i] != s[ps+1] && ps) ps = P[ps]; if (s[i] == s[ps+1]) P[i] = ps+1; else P[i] = 0; if (P[i] == n) cout<<i-2*n-1<<" "<<(b[0]^a[i-2*n-1])<<"\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int>D(N); for(size_t i = 0; i < N; i++) { cin >> D[i]; } for(size_t i = 0; i < N; i++) { cout << D[N - i - 1] << ( i == N - 1 ? "\n" : " " ); } }
0
#include<iostream> #include<algorithm> using namespace std; int w,h; int ans; int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; bool canmove(int x,int y){ return (0 <= x && x < w && 0 <= y && y < h); } struct Map{ int map[20][20]; int s,g; int cnt; int cur; Map(int m[20][20]){ for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ map[i][j]=m[i][j]; if(m[i][j]==2) s=i*32+j; if(m[i][j]==3) g=i*32+j; } } cnt=0; cur=s; } Map(int m[20][20],int curling,int _cnt){ for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ map[i][j]=m[i][j]; if(m[i][j]==2) s=i*32+j; if(m[i][j]==3) g=i*32+j; } } cnt=_cnt; cur=curling; } Map move(int direc){ Map m(map,cur,cnt+1); int y=cur/32,x=cur%32; if(canmove(x+dx[direc],y+dy[direc]) && map[y+dy[direc]][x+dx[direc]]==1){ m.cnt=100; return m; } int k=1; while(true){ bool b=canmove(x+k*dx[direc],y+k*dy[direc]); int num=map[y+k*dy[direc]][x+k*dx[direc]]; if(b && num==3){ m.cur=g; break; } else if(b && num!=1) k++; else if(b && num==1){ m.map[y+k*dy[direc]][x+k*dx[direc]]=0; k--; m.cur=(y+k*dy[direc])*32+x+k*dx[direc]; break; }else{ m.cnt=100; break; } } // cout<<m.cnt<<endl; return m; } }; void dfs(Map m){ if(m.cnt > 10) return; if(m.cnt >= ans) return; if(m.cur == m.g){ ans = min(m.cnt,ans); return; } for(int i=0;i<4;i++){ dfs(m.move(i)); } } int main(){ while(cin>>w>>h,w+h){ int map[20][20]; ans=1000; for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin>>map[i][j]; Map m(map); dfs(m); if(ans == 1000) cout<<-1<<endl; else cout<<ans<<endl; } return 0; }
#include <map> #include <cmath> #include <cstdio> #include <vector> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef long long LL; const int maxn = 105; const int mod = 1e9 + 7; short dp[maxn][maxn][maxn][maxn]; short row[maxn][maxn], col[maxn][maxn]; char mp[maxn][maxn]; short max(short a, short b) { return a>b? a : b; } int main() { int n, m, ex, ey; scanf("%d%d", &n, &m); for (int i=1; i<=n; i++) scanf("%s", mp[i]+1); for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) { if (mp[i][j] == 'E'){ ex = i, ey = j; break; } } for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) { row[i][j] = row[i][j-1] + (mp[i][j] == 'o'); col[i][j] = col[i-1][j] + (mp[i][j] == 'o'); } int L = ey - 1, R = m - ey, U = ex - 1, D = n - ex; memset(dp, -1, sizeof dp); dp[0][0][0][0] = 0; short ans = 0; for (int l=0; l<=L; l++){ for (int u=0; u<=U; u++){ for (int r=0; r<=R; r++){ for (int d=0; d<=D; d++) if(dp[l][u][r][d] != -1){ int up = max(ex - u, d + 1), down = min(ex + d, n - u); int left = max(ey - l, r + 1), right = min(ey + r, m - l); if (up > down || left > right) continue; ans = max(ans, dp[l][u][r][d]); short add; //printf("\n=========%d %d %d %d -> %d %d %d %d=========\n",l,u,r,d,left,up,right,down); if (l+r < L){ add = col[down][ey-l-1] - col[up-1][ey-l-1]; //printf("l: %d ",add); dp[l+1][u][r][d] = max(dp[l+1][u][r][d], dp[l][u][r][d] + add); } if(u+d < U){ add = row[ex-u-1][right] - row[ex-u-1][left-1]; //printf("u: %d ",add); dp[l][u+1][r][d] = max(dp[l][u+1][r][d], dp[l][u][r][d] + add); } if(l+r < R){ add = col[down][ey+r+1] - col[up-1][ey+r+1]; //printf("r: %d ",add); dp[l][u][r+1][d] = max(dp[l][u][r+1][d], dp[l][u][r][d] + add); } if(u+d < D){ add = row[ex+d+1][right] - row[ex+d+1][left-1]; //printf("d: %d ",add); dp[l][u][r][d+1] = max(dp[l][u][r][d + 1], dp[l][u][r][d] + add); } } } } } printf("%d\n", ans); return 0; }
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 <cmath> #include <iomanip> #include <ctype.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi >; using vl = vector<ll>; using vvl = vector<vl >; using pairi = pair<int, int>; using pairl = pair<ll, ll>; #define TR "," #define TS " " #define rep(i,N) for(ll i=0;i<(ll)N;++i) #define rpt(i,a,b) for(ll i=a;i<(ll)b;++i) #define all(v) v.begin(), v.end() #define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) ll gcd(ll a, ll b) { if (a < b) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } void printVector(const vector<ll>& vec) { for (ll value : vec) { cout << value << " "; } cout << endl; } vector<int> IntegerToVector(int bit, int N) { vector<int> S; for (int i = 0; i < N; ++i) { if (bit & (1 << i)) { S.push_back(i); } } return S; } int main() { IO; ll N; cin >> N; string str; cin >> str; vl wkosuu(N), ekosuu(N); ll x = 0, y = 0, z=0; rep(i, N) { if (str[i] == 'E') { ++y; } else if (str[i] == 'W') { ++z; } } wkosuu[0] = 0; wkosuu[N - 1] = z; ekosuu[0] = y; ekosuu[N - 1] = 0; for (ll i = 1; i < N-1; ++i) { if (str[i-1] == 'E') { wkosuu[i] = wkosuu[i - 1]; } else if (str[i-1] == 'W') { ++x; wkosuu[i] = x; } } for (ll i = 0; i < N-1; ++i) { if (str[i] == 'W') { if (i > 0) { ekosuu[i] = ekosuu[i - 1]; } } else if (str[i] == 'E') { --y; ekosuu[i] = y; } } ll ans = N; rep(i, N) { ans = min(ans, wkosuu[i] + ekosuu[i]); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin>>N; string S; cin>>S; vector<int>E(N); vector<int>W(N); for(int i=0;i<N;i++){ if(S.at(i)=='E')E[i]++; else W[i]++; if(i!=0){E[i]+=E[i-1];W[i]+=W[i-1];} } vector<int>ans(N); for(int i=0;i<N;i++){ if(i!=0)ans[i]+=W[i-1]; ans[i]+=E[N-1]-E[i]; } sort(ans.begin(),ans.end()); cout<<ans[0]<<endl; }
1
#include<bits/stdc++.h> using namespace std; int gcd(int a,int b){return b%a ? gcd(b%a,a) : a;} int main(){ int N; cin>>N; int a,b,c; cin>>a>>b; if(N==3) cin>>c; int tmp=gcd(a,b); if(N==3) tmp=gcd(tmp,c); for(int i=1;i<=tmp;i++){ if(tmp%i==0) cout<<i<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(int i = 0; i < (n); i++) #define all(v) v.begin(), v.end() #define MOD 1000000007 const int INF = 1LL<<30; int main(){ ll l,r; cin>>l>>r; ll ans=3000; for(int i=l;i<=min(r,l+3000);i++){ for(int j=i+1;j<=min(r,l+3000);j++){ ll tmp=((i%2019)*(j%2019))%2019; ans=min(ans,tmp); } } cout<<ans<<endl; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll INF = 100000000; #define rep1(i, n) for (ll i=0; i<(n); i++) #define rep2(i, k, n) for (ll i=k; i<(n); i++) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { ll n, m; cin >> n >> m; vector<ll> a(n, -1), s(n), c(n); rep1(i, m) cin >> s[i] >> c[i]; rep1(i, m){ if (a[s[i]-1]!=-1 && a[s[i]-1]!=c[i]){ cout << -1 << endl; return 0; } a[s[i]-1] = c[i]; } if (a[0]==0 && n>1){ cout << -1 << endl; return 0; } rep1(i, n){ if (i==0 && n>1){ if (a[i]==-1) cout << 1; else cout << a[i]; }else{ if (a[i]==-1) cout << 0; else cout << a[i]; } } }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main(int argc, char **argv) { string n; ll k; cin>>n; cin>>k; set <ll> arr; for(ll i=0;i<k;i++){ ll x; cin>>x; arr.insert(x); } // checking for the case when the n is fine ll flag=1; for(ll i=0;i<n.size();i++){ ll temp=n[i]-'0'; if (arr.find(temp)!=arr.end()){ flag=0; break; } } if (flag) { cout<<n<<"\n"; return 0; } ll num=stoi(n); //cout<<"pika"<<"\n"; while(num){ ll ok=1; ll temp=num; while(temp!=0){ ll digit=temp%10; temp=temp/10; //cout<<digit<<" "<<temp<<"\n"; if (arr.find(digit)!=arr.end()){ ok=0; break; } } if (ok){ cout<<num<<"\n"; return 0; } num++; } return 0; }
0