code_file1
stringlengths
80
4k
code_file2
stringlengths
91
4k
similar_or_different
int64
0
1
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define all(x) x.begin(), x.end() typedef pair<int,int> pii; typedef pair <long long,long long> pll; typedef long long ll; typedef long double ld; const ll mod = 1e9+7; ll dp[10001][101][2]; ll solve( string & k, int& D, int pos , int d , bool tight) { if(dp[pos][d][tight] != -1) return dp[pos][d][tight]; int ub = (tight) ? (k[pos]-'0') : 9 ; if(pos == k.length() - 1){ ll ans = 0; for(int x = 0; x <= ub ; x++) if(x%D == d) ans++; return ans; } else{ ll ans = 0; for(int x = 0; x <= ub; x++) ans = (ans + solve( k , D, pos+1, (D + d - x%D)%D , tight&&(x == ub)))%mod; return dp[pos][d][tight] = ans; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int d; string k; cin >> k >> d; memset(dp, -1, sizeof(dp)); cout << (mod+solve(k, d, 0, 0, 1)-1)%mod; return 0; }
#include <iostream> #include <cstdio> #include <algorithm> #define mod 998244353 #define ll long long #define N 1000005 #define inv 499122177 using namespace std; int n, m; ll fac[N], ifac[N]; ll ans; void init(); ll quick_pow(ll ,int); ll C(int ,int); int main(){ cin >> n >> m;init(); if(n < m) swap(n, m); for(int i = 1; i <= m; ++i){ int x = n - i, y = m - i; (ans += C(i, 2 * i) * C(x, x + y) % mod) %= mod; } (ans *= quick_pow(C(n, n + m), mod - 2) * inv % mod) %= mod; (ans += n) %= mod; cout << ans << endl; } void init(){ fac[0] = 1;ifac[0] = 1; for(int i = 1; i <= 1e6; ++i) fac[i] = fac[i - 1] * i % mod, ifac[i] = quick_pow(fac[i], mod - 2); return ; } ll C(int x,int y){ return fac[y] * ifac[y - x] % mod * ifac[x] % mod; } ll quick_pow(ll x,int y){ ll sum = 1, a = x; while(y){ if(y & 1) (sum *= a) %= mod; (a *= a) %= mod; y >>= 1; } return sum; }
0
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <unordered_map> #include <iomanip> #include <cmath> #include <tuple> using namespace std; using ll = long long; #define rep(i, j, n) for(int i = j; i < (int)n; ++i) #define rrep(i, j, n) for(int i = (int)n - 1; j <= i; --i) constexpr ll MOD = 0x3b9aca07; constexpr int INF = 0x3f3f3f3f; constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL; vector<int> par; int root(int x) { if (par[x] < 0) return x; return par[x] = root(par[x]); } int size(int x) { return -par[root(x)]; } void merge(int x, int y) { if (size(x) < size(y)) swap(x, y); int rx = root(x); int ry = root(y); if (rx == ry) return; par[rx] += par[ry]; par[ry] = rx; } int main() { cin.tie(0); ios_base::sync_with_stdio(0); ll n, m; cin >> n >> m; par.assign(n * 2, -1); rep(i, 0, m) { int a, b; cin >> a >> b; --a, --b; merge(a, b + n); merge(b, a + n); } if (root(0) != root(n)) { // 二部グラフの左側*右側 ll cnt = 0; rep(i, 0, n) if (root(0) == root(i)) ++cnt; cout << cnt * (n - cnt) - m << endl; } else { cout << n * (n - 1) / 2 - m << endl; } return 0; }
#include<bits/stdc++.h> typedef long long ll; #define pb push_back #define mod 1000000007ll const ll maxn = 9e18; using namespace std; const ll maxsize = 100000009; vector<bool> mark(100005, 0); int wa[100005]; void solve() { int n, k; cin >> n >> k; map<string,ll> m; m["AC"] = 0; int ac_cnt = 0, wa_cnt = 0; m["WA"] = 0; int t = 0; for(int i = 0; i < k; ++i) { int x; string s; cin >> x >> s; if(mark[x]) continue; if(s == "AC") { mark[x] = 1; ac_cnt++; wa_cnt += wa[x]; } else wa[x]++; } cout << ac_cnt <<" "<< wa_cnt << endl; cout << endl; } int main() { ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(35); solve(); return 0; }
0
#include <bits/stdc++.h> #define fi first #define se second #define rep(i,n) for(int i = 0; i < (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define rng(a) a.begin(),a.end() #define maxs(x,y) (x = max(x,y)) #define mins(x,y) (x = min(x,y)) #define limit(x,l,r) max(l,min(x,r)) #define lims(x,l,r) (x = max(l,min(x,r))) #define isin(x,l,r) ((l) <= (x) && (x) < (r)) #define pb push_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)),x.end()) #define show(x) cout<<#x<<" = "<<x<<endl; #define PQ(T) priority_queue<T,v(T),greater<T> > #define bn(x) ((1<<x)-1) #define dup(x,y) (((x)+(y)-1)/(y)) #define newline puts("") #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef set<int> S; typedef queue<int> Q; typedef queue<P> QP; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; inline int in() { int x; scanf("%d",&x); return x;} const ll LINF = 1001002003004005006ll; const int INF = 1001001001; const int MOD = 1000000007; #define dame { puts("-1"); return 0;} #define yn {puts("YES");}else{puts("NO");} int main() { int N; cin >> N; int H,W; cin >> H >> W; cout << (N-H+1) * (N-W+1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする //cmdで g++ test.cpp とするとコンパイルできる //制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい // https://github.com/atcoder/live_library // cppdbg: test.exeのterminalに標準入力を打てる #define ALL(x) x.begin(),x.end() #define get_tp(t,i) get<i>(t) #define len(x) (ll)(x.size()) #define ub(a,x) (upper_bound(ALL(a),x)-a.begin()) #define lb(a,x) (lower_bound(ALL(a),x)-a.begin()) typedef long long ll; //long long typedef pair<int,int> pii; //pair<int,int> typedef pair<long long,long long> pllll; //pair<ll,ll> typedef vector<int> vi; //vector<int> typedef vector<vector<int>> vvi; //vector<vector<int>> typedef vector<ll> vll; //vector<long long> typedef vector<vector<ll>> vvll; //vector<vector<long long>> typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue typedef priority_queue<ll> pq; //const int MOD=998244353; const int MOD=1000000007; //10^9+7 const long double PI=3.1415926535897932; int main(){ string S;cin>>S; S[3]='8'; cout<<S<<endl; }
0
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author champon */ #include <iostream> #include <fstream> #include <bits/stdc++.h> #define se cout << "test ok" << endl; #define sp << " " << using namespace std; using ll = long long; using ld = long double; ll mod = ll(1e9)+7; ll inf = ll(5e18); template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; } void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; } void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; } template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; } template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; } template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); } int dx[] = {1, 0, -1, 0, 1, -1, 1, -1}; int dy[] = {0, 1, 0, -1, 1, -1, -1, 1}; #ifndef INCLUDE_DEBUG_HPP #define INCLUDE_DEBUG_HPP #include <iostream> #include <vector> #include <map> using namespace std; namespace dbg { using ll = long long; class Debug { public: Debug(){} template<typename T> void vd(vector<T> vec); template<typename T> void vd2(vector<vector<T>> vec); template<typename T> void ad(T *arr, ll n); template<typename T, size_t N> void ad2(T (&arr)[N], ll n); template<typename T> void md(T mp); }; template<typename T> void Debug::vd(vector<T> vec) { for (auto vv : vec) cout << vv << " "; cout << endl; } template<typename T> void Debug::vd2(vector<vector<T>> vec) { for (auto vv : vec) for (auto vvv : vv) cout << vvv << " "; cout << endl; } template<typename T> void Debug::ad(T *arr, ll n) { for (int i = 0; i <= n; i++) cout << arr[i] << " "; cout << endl; } template<typename T, size_t N> void Debug::ad2(T (&arr)[N], ll n) { for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " "; cout << endl; } template<typename T> void Debug::md(T mp) { cout << "key : value" << endl; for (auto const &m : mp) cout << m.first << " : " << m.second << endl; cout << endl; } } #endif //INCLUDE_DEBUG_HPP using dbg::Debug; Debug debug; class DGridComponents { public: void solve(std::istream& in, std::ostream& out) { int a, b; in >> a >> b; vector<vector<char>> g(100, vector<char>(100, '#')); for(int i=0; i<100; i++){ if(i >= 50) break; for(int j=0; j<100; j++){ g[i][j] = '.'; } } int cnt = 0; for(int i=0; i<50; i++){ if(i%2 == 1) continue; for(int j=0; j<100; j++){ if(cnt == b-1) break; if(i%2 == j%2) { g[i][j] = '#'; cnt++; } } } cnt = 0; for(int i=99; i>=50; i--){ if(i%2 == 0) continue; for(int j=0; j<100; j++){ if(cnt == a-1) break; if(i%2 == j%2){ g[i][j] = '.'; cnt++; } } } out << 100 sp 100 << endl; for(int i=0; i<100; i++){ for(int j=0; j<100; j++){ out << g[i][j]; } out << endl; } } }; int main() { DGridComponents solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define mp make_pair #define PI pair<int,int> #define lowbit(i) i&-i #define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++) #define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--) #define pb push_back #define fi first #define se second inline char gc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++; } #define gc getchar inline ll read(){ ll x = 0; char ch = gc(); bool positive = 1; for (; !isdigit(ch); ch = gc()) if (ch == '-') positive = 0; for (; isdigit(ch); ch = gc()) x = x * 10 + ch - '0'; return positive ? x : -x; } inline void write(ll a){ if(a<0){ a=-a; putchar('-'); } if(a>=10)write(a/10); putchar('0'+a%10); } inline void writeln(ll a){write(a); puts("");} inline void wri(ll a){write(a); putchar(' ');} inline ull rnd(){ ull ans=0; For(i,0,5)ans=ans<<15^rand(); return ans; } ll ycl[20],f[10],ans,d,L; ll xqz(ll x,ll y){ if(x>=0)return x/y; x=-x; x--; return -x/y-1; } void dfs(int p,ll xs,ll d){ if(p==L/2){ if(d==0)ans+=xs*((L&1)?10:1); return; } ll cz=ycl[L-1-p]-ycl[p],t=xqz(d,cz); //cout<<d<<" "<<cz<<" "<<t<<" "<<L/2<<endl; if(abs(t)<=9){ dfs(p+1,xs*(f[abs(t)]-(p==0&&t>=0)),d-t*cz); } t++; if(abs(t)<=9){ dfs(p+1,xs*(f[abs(t)]-(p==0&&t>=0)),d-t*cz); } } void get(int len,ll d){ L=len; dfs(0,1,d); } int main(){ For(i,0,9)For(j,0,i)f[i-j]++; d=read(); int ws=1; For(i,ycl[0]=1,18){ycl[i]=ycl[i-1]*10; if(d>=ycl[i])ws++;} //get(2,d); cerr<<ans<<endl; return 0; For(i,max(2,ws),2*ws){ get(i,d); } cout<<ans<<endl; }
0
#include<bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) #define rrep(i,n) for(int i = (n)-1; i >= 0; i--) #define rep1(i,n) for(int i = 1; i <= (n); i++) #define rrep1(i,n) for(int i = (n); i > 0; i--) #define ll long long #define pi pair<int, int> #define pll pair<ll, ll> #define MOD 1000000007 #define INF 1000000000000000LL using namespace std; #define MAXN 10000 #define MAXD 100 ll dp[MAXN+1][MAXD][2]; int main(){ string s;cin>>s; int n = s.size(); int d;cin>>d; dp[0][0][1]=1; rep(i, n)rep(j, d)rep(k, 10){ int cd = s[i]-'0'; int nj = (j+k)%d; if(k>cd){ dp[i+1][nj][0] += dp[i][j][0]; }else if(k==cd){ dp[i+1][nj][1] += dp[i][j][1]; dp[i+1][nj][0] += dp[i][j][0]; }else{ dp[i+1][nj][0] += dp[i][j][1]; dp[i+1][nj][0] += dp[i][j][0]; } dp[i+1][nj][0] %= MOD; dp[i+1][nj][0] %= MOD; } cout<<(dp[n][0][0]+dp[n][0][1]-1+MOD)%MOD<<endl; return 0; }
#include <bits/stdc++.h> #define mod 998244353 #define int long long using namespace std; const int N=3*1e6+100; int n,m,fac[N],inv[N],a,b; inline int m_pow(int a,int b) { int ans=1; while (b) { if (b&1) ans=(ans*a)%mod; b>>=1; a=(a*a)%mod; } return ans; } inline int c(int n,int m) { if (m>n) return 0; return (fac[n]*(inv[m]*inv[n-m]%mod)%mod)%mod; } signed main() { scanf("%lld%lld",&n,&m); fac[0]=1; for (int i=1;i<=n+3*m;i++) fac[i]=(fac[i-1]*i)%mod; inv[n+3*m]=m_pow(fac[n+3*m],mod-2); for (int i=n+3*m-1;i>=0;i--) inv[i]=(inv[i+1]*(i+1))%mod; for (int i=0;i<=m;i++) { if ((3*m-i)%2!=0) continue; a=(a+(c(n,i)*c(n+(3*m-i)/2-1,n-1))%mod)%mod; } for (int i=2*m+1;i<=3*m;i++) b=(b+c(n+3*m-i-2,n-2))%mod; b=(b*n)%mod; printf("%lld\n",(a-b+mod)%mod); }
0
#include<iostream> using namespace std; int main(){ int a[10][10]; int d, i, j, k, temp,sum=0; while (1){ cin >> d; if (d == 0){ return 0; } for (i = 0, j = 0; i < d; i++){ for (j = 0; j < d; j++){ cin >> a[i][j]; } } for (i = 0, j = 0; i < d; i++){ for (j = 0; j < d; j++){ cout.width(5); cout << a[i][j]; } temp = 0; for (k = 0; k < d; k++){ temp += a[i][k]; } cout.width(5); cout << temp << endl; sum += temp; } for (j = 0; j < d; j++){ temp = 0; for (k = 0; k < d; k++){ temp += a[k][j]; } cout.width(5); cout << temp; sum += temp; } cout.width(5); cout << sum/2 << endl; sum = 0; } }
#include <bits/stdc++.h> #define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v) using namespace std; typedef long long int lint; static inline int in(){ int x; scanf("%d", &x); return (x); } static inline lint inl(){ lint x; scanf("%lld", &x); return (x); } int matrix[11][11]; int main() { int n; while( (n = in()) != 0 ) { loop(i, 0, 11) { loop(j, 0, 11) { matrix[i][j] = 0; } } loop(i, 0, n) { loop(j, 0, n) { matrix[i][j] = in(); } } loop(i, 0, n) { loop(j, 0, n) { matrix[i][n] += matrix[i][j]; matrix[n][i] += matrix[j][i]; } matrix[n][n] += matrix[i][n]; } loop(i, 0, n + 1) { loop(j, 0, n + 1) { printf("%5d", matrix[i][j]); } printf("\n"); } } return (0); }
1
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int x[n],y[n]; for(int i=0;i<n;i++){ cin>>x[i]>>y[i]; } int p[10]={0,1,2,3,4,5,6,7,8,9}; double sum=0; int divide=0; do{ for(int i=0;i<n-1;i++) sum+=sqrt(pow(x[p[i+1]]-x[p[i]],2)+pow(y[p[i+1]]-y[p[i]],2)); divide++; }while(next_permutation(p,p+n)); cout<<fixed<<setprecision(7)<<sum/divide<<endl; }
#include"bits/stdc++.h" using namespace std; #define ll long long #define mod 1000000007 #define prec(n) fixed<<setprecision(n) int N; int x[10], y[10]; double dist(int i, int j) { double dx = x[i] - x[j]; double dy = y[i] - y[j]; return pow(dx * dx + dy * dy, 0.5); } void solve() { cin >> N; for(int i = 1; i <= N; i++) cin >> x[i] >> y[i]; double dsum = 0.0; for (int i = 1 ;i<=N; ++i) { for (int j = i+1; j<=N;++j) { dsum += dist(i, j) * 2 / N; } } cout << prec(10) << dsum << "\n"; return; } int main() { solve(); return 0; }
1
# include <iostream> # include <algorithm> # include <vector> # include <string> # include <set> # include <map> # include <cmath> # include <iomanip> # include <functional> # include <utility> # include <stack> # include <queue> # include <list> constexpr int MOD = 1000000000 + 7; constexpr int INF = 2000000000; using namespace std; int main() { int n; while (cin >> n&&n) { long long member[4001] = {}; bool flag[4001] = {}; for (int i = 1; i <= 4000; i++) { member[i] = 0; flag[i] = false; } long long a, b, c; int count = 0; for (int i = 0; i < n; i++) { cin >> a >> b >> c; member[a] += b*c; if (member[a] >= 1000000&&!flag[a]) { count++; flag[a] = true; cout << a << endl; } } if (count == 0)cout << "NA" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; while (cin >> a >> b >> c, a | b | c) { int N; cin >> N; vector<int> res(a + b + c, 2); vector<vector<int>> no; for (int i = 0; i < N; i++) { int x, y, z, t; cin >> x >> y >> z >> t; x--, y--, z--; if (t) { res[x] = res[y] = res[z] = 1; } else { no.push_back(vector<int>({ x, y, z })); } } for (auto t : no) { int x = t[0], y = t[1], z = t[2]; if (res[x] == 1 && res[y] == 1) { res[z] = 0; } else if (res[y] == 1 && res[z] == 1) { res[x] = 0; } else if (res[z] == 1 && res[x] == 1) { res[y] = 0; } } for (int i = 0; i < a + b + c; i++) { cout << res[i] << endl; } } return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; //マクロ //forループ関係 //引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか //Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる #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--) //xにはvectorなどのコンテナ #define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい #define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく //定数 #define INF 1000000000000 //10^12:極めて大きい値,∞ #define MOD 1000000007 //10^9+7:合同式の法 #define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用) //略記 #define PB emplace_back //vectorヘの挿入 #define MP make_pair //pairのコンストラクタ #define F first //pairの一つ目の要素 #define S second //pairの二つ目の要素 #define Umap unordered_map #define Uset unordered_set int main(){ ll a, b; cin >> a >> b; cout << max(a+b, max(a, b)*2-1); return 0; }
#include <iostream> #include <algorithm> #include <iomanip> #include <math.h> #include <vector> using namespace std; int main(){ cin.tie(NULL); ios::sync_with_stdio(false); int a[5]; int ans; for(int i=0;i<2;i++){ cin>>a[i]; } sort(a,a+2); ans=a[1]; a[1]--; sort(a,a+2); ans+=a[1]; cout<<ans<<"\n"; return 0; }
1
#include <bits/stdc++.h> #include <set> using namespace std; using pii = pair<int,int>; using pll = pair<long long, long long>; const long long INF = 1<<29; const int MOD = 998244353; long long ruizyou(long long m,long long n){ if(m == 0)return 0; if(m == 1)return 1; long long ans = 1; long long tmp = m; for(int i=0;i<=30;i++){ if(n & (1<<i)){ ans *= tmp; ans %= MOD; } tmp *= tmp; tmp %= MOD; } return ans; } long long kaizyou(long long x){ if(x == 0)return 1; return x * kaizyou(x-1) % MOD; } long long comb(long long x,long long y){ long long bunsi = kaizyou(x); long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD; return bunsi * ruizyou(bunbo,MOD-2) % MOD; } struct unionfind{ vector<int> par; vector<vector<int>> children; vector<int> hukasa; vector<int> kazu; unionfind(int n){ par = vector<int>(n); hukasa = vector<int>(n,0); kazu = vector<int>(n,1); for(int i=0;i<n;i++){ par.at(i) = i; } } int root(int x){ if(par.at(x) == x)return x; return root(par.at(x)); } void unite(int x,int y){ int rx = root(x); int ry = root(y); if(rx == ry)return; if(hukasa.at(rx) >= hukasa.at(ry)){ par.at(ry) = rx; hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx)); kazu.at(rx) += kazu.at(ry); } else{ par.at(rx) = ry; kazu.at(ry) += kazu.at(rx); } } void newkazu(){ int n = kazu.size(); for(int i=0;i<n;i++){ kazu.at(i) = kazu.at(root(i)); } } bool same(int x,int y){ return root(x) == root(y); } }; int ctoi(char a){ return a - '0'; } long long gcd(long long a,long long b){ long long c = max(a,b); long long d = min(a,b); if(d % c == 0)return c; return gcd(c,d%c); } long long lcm(long long a,long long b){ return a * b / gcd(a,b); } int main(){ int h,w; cin >> h >> w; vector<vector<char>> s(h,vector<char>(w)); for(int i=0;i<h;i++){ for(int j=0;j<w;j++)cin >> s.at(i).at(j); } vector<vector<int>> table(h,vector<int>(w,-1)); queue<pii> q; q.push(pii(0,0)); table.at(0).at(0) = 1; bool flag = false; int count; while(!q.empty()){ pii tmppair = q.front(); q.pop(); int x,y; tie(x,y) = tmppair; set<pii> se; if(x-1 >= 0)se.insert(pii(x-1,y)); if(x+1 < h)se.insert(pii(x+1,y)); if(y-1 >= 0)se.insert(pii(x,y-1)); if(y+1 < w)se.insert(pii(x,y+1)); for(auto t:se){ int tx,ty; tie(tx,ty) = t; if(s.at(tx).at(ty) == '.' && table.at(tx).at(ty) == -1){ table.at(tx).at(ty) = table.at(x).at(y) + 1; q.push(t); } if(t == pii(h-1,w-1)){ count = table.at(tx).at(ty); flag = true; break; } } if(flag) break; } if(!flag) cout << -1 << endl; else{ int count2 = 0; for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ if(s.at(i).at(j) == '#')count2++; } } cout << h * w - count - count2 << endl; } }
#include <bits/stdc++.h> using namespace std; const int N = 200; const int S = 100005; const int mo = 1e9 + 7; int n, x; int a[N + 5]; int f[N + 5][S + 5]; int main() { #ifdef Wearry freopen("in", "r", stdin); freopen("out", "w", stdout); #endif cin >> n >> x; for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a, a + n, greater<int>()); f[0][x] = 1; for (int i = 0; i < n; ++i) for (int j = 0; j <= x; ++j) if (f[i][j]) { f[i + 1][j % a[i]] = (f[i + 1][j % a[i]] + f[i][j]) % mo; f[i + 1][j] = (f[i + 1][j] + 1ll * f[i][j] * (n - 1 - i)) % mo; } int ans = 0; for (int i = 0; i <= x; ++i) { ans = (ans + 1ll * f[n][i] * i) % mo; } cout << ans << endl; return 0; }
0
#include <algorithm> #include <iostream> #include <set> using namespace std; typedef pair<int, int> P; int main() { int n, q; cin >> n >> q; int s[200005], t[200005], x[200005]; P p[400005]; for(int i = 0; i < n; i++){ cin >> s[i] >> t[i] >> x[i]; p[i * 2] = P(s[i] - x[i], x[i]); p[i * 2 + 1] = P(t[i] - x[i], -x[i]); } sort(p, p + n * 2); set<int> st; int i = 0; while(q--){ int d; cin >> d; while(i < n * 2 && p[i].first <= d){ if(p[i].second > 0) st.insert(p[i].second); else st.erase(-p[i].second); i++; } if(st.empty()) cout << -1 << endl; else cout << *st.begin() << endl; } }
#include <bits/stdc++.h> using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = mod * mod; const int INF_N = 1e+9; typedef pair<int, int> P; // #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define all(v) (v).begin(),(v).end() typedef pair<ll, ll> LP; typedef long double ld; typedef pair<ld, ld> LDP; const ld eps = 1e-12; const ld pi = acos(-1.0); //typedef vector<vector<ll>> mat; typedef vector<int> vec; //繰り返し二乗法 ll mod_pow(ll a, ll n, ll m) { ll res = 1; while (n) { if (n & 1)res = res * a%m; a = a * a%m; n >>= 1; } return res; } struct modint { ll n; modint() :n(0) { ; } modint(ll m) :n(m) { if (n >= mod)n %= mod; else if (n < 0)n = (n%mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; } modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; } modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, int n) { if (n == 0)return modint(1); modint res = (a*a) ^ (n / 2); if (n % 2)res = res * a; return res; } //逆元(Eucledean algorithm) ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } const int max_n = 1 << 18; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b)return 0; return fact[a] * factinv[b] * factinv[a - b]; } using mP = pair<modint, modint>; int dx[4] = { 0,1,0,-1 }; int dy[4] = { 1,0,-1,0 }; void solve() { int N, Q; cin >> N >> Q; vector<tuple<ll, ll, ll>> v(N); rep(i, N){ ll s, t, x; cin >> s >> t >> x; v[i] = {x, s, t}; } // map<ll, ll> d; set<ll> d; map<ll, ll> m; rep(i, Q){ ll tmp; cin >> tmp; // d[tmp] = 1; d.insert(tmp); m[tmp] = -1; } sort(all(v)); rep(i, N){ // auto it1 = lower_bound(all(d), get<1>(v[i])-get<0>(v[i])); // auto it2 = lower_bound(all(d), get<2>(v[i])-get<0>(v[i])); auto it1 = d.lower_bound(get<1>(v[i])-get<0>(v[i])); auto it2 = d.lower_bound(get<2>(v[i])-get<0>(v[i])); // while(it1 != it2) { // m[*it1] = x[i]; // d.erase(it1); // } while(it1 != it2){ // m[it1->first] = get<0>(v[i]); m[*it1] = get<0>(v[i]); d.erase(it1++); } } for(auto p: m){ cout << p.second << endl; } } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(10); //init_f(); //init(); //int t; cin >> t; rep(i, t)solve(); solve(); // stop return 0; }
1
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iomanip> // fixed, setprecision #include <iostream> // cout, endl, cin #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pair #include <vector> // vector using namespace std; int main() { int64_t N, M, p, acc = 0, wac = 0; string s; cin >> N >> M; map<int, int> wa{}; vector<bool> ac(N, false); for (int i = 0; i < M; i++) { cin >> p >> s; p--; if (s == "AC" && !ac[p]) ac[p] = true; if (s == "WA" && !ac[p]) wa[p]++; } for (int i = 0; i < N; i++) { if (ac[i]) { acc++; wac += wa[i]; } } cout << acc << " " << wac << endl; }
#pragma region Macros #include <bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<int>>; using WGraph = vector<vector<pair<int, ll>>>; template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; } template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0}; constexpr int INF = 1e9; constexpr long long LINF = 1e18; constexpr long long MOD = 1e9 + 7; constexpr double EPS = 1e-10; constexpr double PI = M_PI; #pragma endregion std::vector<int> topologicalSort(const Graph &G) { int n = (int)G.size(); std::vector<int> cntIn(n); for (auto vec : G) { for (int x : vec) { cntIn.at(x)++; } } std::vector<int> res; std::stack<int> st; for (int i=0; i<n; i++) { if (cntIn.at(i) == 0) { st.push(i); } } while (!st.empty()) { int cur = st.top(); st.pop(); res.push_back(cur); for (int x : G.at(cur)) { cntIn.at(x)--; if (cntIn.at(x) == 0) { st.push(x); } } } return res; } void solve() { int n, m; cin >> n >> m; Graph G(n); for (int i=0; i<n+m-1; i++) { int a, b; cin >> a >> b; G.at(a-1).push_back(b-1); } auto sorted = topologicalSort(G); vector<int> res(n, 0); for (int x : sorted) { for (int nx : G.at(x)) { res.at(nx) = x + 1; } } for (int x : res) { cout << x << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); solve(); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main(void){ long long int a,b,n,x,y,z,i=0,ans=0,c=0; string s; cin >> x >> y >> z; cout << z << " "<< x << " "<< y << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) using ll = long long; using ld = long double; #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) #define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++) #define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++) #define repr(i,n) for (ll i = (n-1); i>=0;i--) #define repr3(i,n) for(ll i = (n);i>0;i--) #define stlen(s) ll s.size()-1 #define all(v) v.begin(), v.end() #define cout(n) cout<<std::fixed<<std::setprecision(n) using Graph = vector<vector<int>>; #define INF1 INT_MAX; #define INF2 LLONG_MAX; #define PI 3.14159265358979323846; int main() { int H,W,A,B; cin>>H>>W>>A>>B; int M[H+1][W+1]; rep3(i,H){ rep3(j,W){ if(((i<=B)&&(j<=A))||((i>B)&&(j>A))){ M[i][j]=1; } else{ M[i][j]=0; } } } rep3(i,H){ rep3(j,W){ if(j!=W){ cout<<M[i][j]; } else{ cout<<M[i][j]<<endl; } } } return 0; }
0
// Aaradhya Beri #pragma GCC optimze("Ofast") #include <bits/stdc++.h> using namespace std; #define endl '\n' #define pb push_back #define fi first #define se second typedef long long ll; typedef long double f80; #define double long double #define pii pair<int,int> #define pll pair<ll,ll> #define sz(x) ((long long)x.size()) #define fr(a,b,c) for(int a=b; a<=c; a++) #define rep(a,b,c) for(int a=b; a<c; a++) #define trav(a,x) for(auto &a:x) #define all(con) con.begin(),con.end() #define w(x) int x; cin>>x; while(x--) const ll infl=0x3f3f3f3f3f3f3f3fLL; const int infi=0x3f3f3f3f; //const int mod=998244353; const int mod=1000000007; typedef vector<int> vi; typedef vector<ll> vl; int powm(int a, int b) { int res=1; while(b) { if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res; } signed main() { ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); cout<<fixed<<setprecision(8); ll x;cin>>x; ll res=(x%11<=6)? ((x%11==0)? (x/11)*2:(x/11)*2+1):(x/11)*2+2; cout<<res<<endl; return 0; }
#include<iostream> #include<string> using namespace std; int main(){ string s; cin>>s; if(s[0]=='7') cout<<"Yes"<<endl; else if(s[1]=='7') cout<<"Yes"<<endl; else if(s[2]=='7') cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; }
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using vll = vector<ll> ; #define all(v) v.begin(),v.end() const ll mod = 1e9+7; int main(){ ll N;cin>>N; vector<int> A(N);rep(i,N)cin>>A[i]; map<int,int> m; ll ans = 1; rep(i,N){ m[A[i]]++; if(A[i]==0){ ans *= 4 - m[0]; } else{ ans *= (m[A[i]-1] - m[A[i]] + 1); } ans %= mod; } cout << ans << endl; }
#include <bits/stdc++.h> #define int long long typedef long long ll; using namespace std; const ll MAXN = 200000; const ll INF = 1001001001; ll N, ans=0, tmp=0; vector<ll> A; signed main(){ cin >> N; for(int i=0;i<N;i++) { ll a; cin >> a; if(i==0&&a!=0) { cout << -1 << endl; return 0; } if(tmp+1<a) { cout << -1 << endl; return 0; } else { if(tmp+1>a) { ans += a; } else { ans += a-tmp; } } tmp = a; } cout << ans << endl; return 0; }
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++) using P = pair<int,int>; using pq = priority_queue<int>; typedef long long ll; int main() { int n; cin >> n; vector <long> a(n); rep(i, n) cin >> a[i]; vector <long> b(n, 0); ll sum = 0; long max = a[0]; int i = 0; while (i < n) { if (max < a[i]) max = a[i]; else if (a[i] < max) sum += max - a[i]; i++; } cout << sum << endl; return (0); }
#include <iostream> #include <unordered_map> #include <string> #include <algorithm> using namespace std; int main(void){ long long N; cin >> N; long long A[N]; long long count = 0; long long sum=0; long long ans ; for(int i=0;i<N;i++){ cin >> A[i]; if(A[i] < 0)count++; sum += abs(A[i]); } if(count % 2 == 0){ ans = sum; } else{ ans = 0; for(int i=0;i<N;i++){ ans = max(ans,sum-abs(A[i])*2); } } cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; #define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); #define MAXX 10005 #define PI 3.14159265358979323846264338327950 #define F first #define S second #define ll long long int #define mod 1000000007 int main() { FAST; ll n; ll a, b; cin >> a >> b; if(a <= 8 && b <= 8){ cout << "Yay!"; return 0; } cout << ":("; return 0; }
#include<bits/stdc++.h> #define ll long long #define rep(i,a,b) for(i=a;i<b;i++) #define pb push_back #define all(v) v.begin(),v.end() #define F first #define S second #define hell 1000000007 using namespace std; const int N=500; void solve() { ll i,j,k,n,m,c=0,ans=0; string s; cin>>n>>m; if(abs(n-m)<=16-n-m) cout<<"Yay!"; else cout<<":("; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t=1; //cin>>t; while(t--) solve(); }
1
#include<bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) (v).begin(),(v).end() #define pb push_back typedef long long ll; typedef pair<int,int> P; //----------------------------------------------------------------------- vector<pair<int,P> > p; int main() { cin.tie(0); ios::sync_with_stdio(false); for(int i=1;i<=150;i++){ for(int j=i+1;j<=150;j++){ p.pb(make_pair(i*i+j*j,P(i,j))); } } sort(p.begin(),p.end()); int h,w; while(cin>>h>>w,h+w){ pair<int,P> q=make_pair(h*h+w*w,P(h,w)); pair<int,P> r=*upper_bound(p.begin(),p.end(),q); cout<<r.second.first<<" "<<r.second.second<<endl; } }
#include <iostream> #include <algorithm> #include <cctype> #include <cstdio> #include <math.h> #include <map> #include <queue> #include <string> using namespace std; char ch; string text; int main() { while(getline(cin,text)){ for(int i=0;i<26;i++){ for(int j=0;j<text.size();j++){ if(text[j]>='a'&&text[j]<='y')text[j]+=1; else if(text[j]=='z')text[j]='a'; } int p=text.find("the"),q=text.find("this"),r=text.find("that"); if(p!=string::npos||q!=string::npos||r!=string::npos){ cout<<text<<endl; break; } } } }
0
#include <iostream> #include <string> #define llint long long #define mod 1000000007 using namespace std; string s; llint dp[300005][2][2][2][3]; int main(void) { cin >> s; s += "1"; int n = s.size(); s = "#" + s; dp[0][0][0][0][0] = 1; for(int i = 0; i < n; i++){ for(int j = 0; j < 2; j++){ for(int k = 0; k < 2; k++){ for(int l = 0; l < 2; l++){ for(int m = 0; m < 3; m++){ if(s[i+1] != '1'){ (dp[i+1][(j+1)%2][1][l][m] += dp[i][j][k][l][m]) %= mod; } if(s[i+1] != '0'){ if(j % 2){ (dp[i+1][0][0][l][m] += dp[i][j][k][l][m]) %= mod; continue; } int nm = m; if(k == 0){ if(m == 0 && l % 2 == 0) nm = 1; else if(m == 1 && l % 2) nm = 2; } (dp[i+1][0][0][(l+1)%2][nm] += dp[i][j][k][l][m]) %= mod; } } } } } } llint ans = 0; for(int l = 0; l < 2; l++) ans += dp[n][0][0][l][2], ans %= mod; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define fi first #define se second const int N = 2020; const int Q = N * N; const int mod = 1e9 + 7; using namespace std; int pw(int x, int n) { int res = 1; for(; n > 0; n >>= 1){ if(n & 1){ res = 1ll * res * x % mod; } x = 1ll * x * x % mod; } return res; } int fac[Q], inv[Q]; void make() { fac[0] = 1; for(int i = 1; i < Q; i++) fac[i] = fac[i - 1] * 1ll * i % mod; inv[Q - 1] = pw(fac[Q - 1], mod - 2); for(int i = Q - 2; i >= 0; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod; } int C(int n, int k) { if(k < 0 || k > n) return 0; return 1ll * fac[n] * inv[k] % mod * inv[n - k] % mod; } void add(int &x, int y) { x += y; if(x >= mod){ x -= mod; } } int n, k; int d[N][N]; int main() { ios_base::sync_with_stdio(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); make(); cin >> n >> k; if(k == 1){ cout << 1 << "\n"; return 0; } d[0][0] = 1; for(int i = 0; i <= n; i++){ for(int j = i; j <= n; j++){ if(i > 0)add(d[i][j], d[i - 1][j]); if(j > 0)add(d[i][j], d[i][j - 1] * 1ll * C(j * (k - 1) + i - 1, k - 2) % mod); } } cout << d[n][n] * 1ll * fac[n] % mod << "\n"; }
0
#include <iostream> #include <fstream> #include <set> #include <map> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <functional> #include <algorithm> #include <climits> #include <cmath> #include <iomanip> using namespace std; #define ll long long int #define rep(i,n) for( int i = 0; i < n; i++ ) #define rrep(i,n) for( int i = n; i >= 0; i-- ) #define REP(i,s,t) for( int i = s; i <= t; i++ ) #define RREP(i,s,t) for( int i = s; i >= t; i-- ) #define dump(x) cerr << #x << " = " << (x) << endl; #define INF 2000000000 #define mod 1000000007 #define INF2 1000000000000000000 int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; int l1 = 1, r1 = 2 + ((m - 1)/2) * 2; int l2 = r1 + 1, r2 = l2 + 2 + ((m - 2)/2) * 2; //cout << l1 << " " << r1 << " " << l2 << " " << r2 << endl; while(l1 < r1 && m > 0) { cout << l1 << " " << r1 << endl; l1++; r1--; m--; } while(l2 < r2 && m > 0) { cout << l2 << " " << r2 << endl; l2++; r2--; m--; } return 0; } // 1 2 3 4 5 // . . // . . // 1 2 3 4 5 6 7 8 // . . . . // . .
#include <bits/stdc++.h> #define ALL(A) (A).begin(), (A).end() #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 }; // i<4:4way i<8:8way int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 }; const ll mod = 1e9 + 7; const ll INF = -1 * ((1LL << 63) + 1); const int inf = -1 * ((1 << 31) + 1); int main(void){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int n,m; cin >> n >> m; if(m==1){ cout << "1 2" << endl; return 0; } int i1 = 1; int i2 = m + 2; for(int diff = m;diff >= 1;diff--){ cout << i1 << " " << i1 + diff << endl; i1++; swap(i1,i2); } }
1
#include <stdio.h> typedef struct _Gem{ int x; int y; bool hit; } Gem; static void pick_gem(Gem* g, int n, int x, int y) { for (int i = 0; i < n; i++) { if (!g[i].hit && g[i].x == x && g[i].y == y) { g[i].hit = true; return; } } } static bool check_gem(Gem* g, int n) { for (int i = 0; i < n; i++) { if (g[i].hit == false) { return false; } } return true; } int main(void) { char line[80]; int n; int m; Gem g[20]; char d[30]; int l[30]; while (true) { if (fgets(line, sizeof line, stdin) == NULL) { return 1; } if (sscanf(line, "%d", &n) != 1) { return 1; } if (n == 0) { break; } for (int i = 0; i < n; i++) { if (fgets(line, sizeof line, stdin) == NULL) { return 1; } if (sscanf(line, "%d %d", &(g[i].x), &(g[i].y)) != 2) { return 1; } g[i].hit = false; } if (fgets(line, sizeof line, stdin) == NULL) { return 1; } if (sscanf(line, "%d", &m) != 1) { return 1; } for (int i = 0; i < m; i++) { if (fgets(line, sizeof line, stdin) == NULL) { return 1; } if (sscanf(line, "%c %d", &(d[i]), &(l[i])) != 2) { return 1; } } int x = 10; int y = 10; for (int i = 0; i < m; i++) { if (d[i] == 'N') { for (int k = 1; k <= l[i]; k++) { pick_gem(g, n, x, ++y); } } else if (d[i] == 'S') { for (int k = 1; k <= l[i]; k++) { pick_gem(g, n, x, --y); } } else if (d[i] == 'E') { for (int k = 1; k <= l[i]; k++) { pick_gem(g, n, ++x, y); } } else { for (int k = 1; k <= l[i]; k++) { pick_gem(g, n, --x, y); } } } printf("%s\n", (check_gem(g, n) ? "Yes" : "No")); } return 0; }
#include <iostream> #include <algorithm> using namespace std; #define REP(i, n) for(int (i) = 0; (i) < (n); (i)++) int main() { while(1){ int N; cin >> N; if(N == 0){ break; }else{ int x, y; int planet[21][21]; fill(&planet[0][0], &planet[21][0], 0); REP(i, N){ cin >> x >> y; planet[x][y] = 1; } int M; char d; int l; int px, py; px = py = 10; cin >> M; REP(i, M){ cin >> d >> l; if(d == 'N'){ REP(j, l + 1) planet[px][py + j] = 0; py += l; }else if(d == 'E'){ REP(j, l + 1) planet[px + j][py] = 0; px += l; } else if(d == 'S'){ REP(j, l + 1) planet[px][py - j] = 0; py -= l; }else{ REP(j, l + 1) planet[px - j][py] = 0; px -= l; } } int c = 0; REP(i, 21) REP(j, 21) if(planet[i][j]) c++; if(c) cout << "No" << endl; else cout << "Yes" << endl; } } }
1
#include <iostream> using namespace std; int main() { int R, G, T; cin >> R; cin >> G; T = (2 * G) - R; cout << T << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long const int MAX = 2000000; const int MOD = 998244353; // int 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; } } // 二項係数計算 int 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; } signed main() { int n,m; cin>>n>>m; COMinit(); int ans=n*COM(m+n-2,m)%MOD; for(int i=m;3*m-2*i>=0;i++){ ans=(ans + (COM(i+n-1,i) +(MOD - n*COM(i-m+n-1,i-m)%MOD))*COM(n,3*m-2*i)%MOD)%MOD; } cout<<ans; }
0
#include <bits/stdc++.h> #define fi first #define se second #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define isin(x,l,r) ((l) <= (x) && (x) < (r)) #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)),x.end()) #define snuke srand((unsigned)clock()+(unsigned)time(NULL)); #define show(x) cerr<<#x<<" = "<<x<<endl; #define PQ(T) priority_queue<T,v(T),greater<T> > #define bn(x) ((1<<x)-1) #define dup(x,y) (((x)+(y)-1)/(y)) #define newline puts("") #define v(T) vector<T> #define vv(T) v(v(T)) #define put(x) std::cout << x << endl; using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef tuple<int,int,int> T; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<T> vt; int getInt(){int x;scanf("%d",&x);return x;} template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;} template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);} template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;} template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;} template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;} template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;} template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;} template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;} const double eps = 1e-10; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; #define dame { puts("-1"); return 0;} #define yn {puts("Yes");}else{puts("No");} const int MX = 200005; // Segment tree struct F { // min func typedef int TT; TT d; F(TT d=INF):d(d) {} F& operator+=(const F& f) { mins(d, f.d); return *this; } F operator+(const F& f) const { return F(*this) += f;} }; struct seg { vector<F> d; int n; seg(){} seg(int mx) { n = 1; while (n < mx) n <<= 1; d = vector<F>(n<<1); } void upd(int i) { d[i] = d[i<<1]+d[i<<1|1];} F& operator[](int i) { return d[n+i];} void init() { for(int i=n-1;i;--i) upd(i);} void add(int i, F f) { for (i+=n,d[i]+=f,i>>=1;i;i>>=1) upd(i);} void set(int i, F f) { for (i+=n,d[i]=f,i>>=1;i;i>>=1) upd(i);} F get(int l, int r) { l += n; r += n; F lf, rf; while (l < r) { if (l&1) lf += d[l++]; if (r&1) rf = d[--r] + rf; l >>= 1; r >>= 1; } return lf += rf; } }; void Main() { ll H, W; cin >> H >> W; vector<ll> A(H), B(H); rep(i, H) cin >> A[i] >> B[i]; map<int, int> a; rep(i, W) a[i] = i; seg t(W+5); rep(i, W) t.add(i, F(0)); rep(i, H) { ll l = A[i]-1; ll r = B[i]; ll maxX = -1; for (auto it = a.lower_bound(l); it != a.end() && it->first < r; a.erase(it++)) { maxX = std::max(maxX, (ll)it->second); t.set(it->first, F(INF)); // invalid } if (r < W && maxX >= 0) { if (0 == a.count(r)) a[r] = -1; a[r] = max(a[r], (int)maxX); t.set(r, F(r - a[r])); } ll res = 1 + i + t.get(0, W).d; // get minimum if (res > INF) { put(-1); } else { put(res); } } } signed main(){ Main();return 0;}
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define _GLIBCXX_DEBUG using namespace std; using ll = long long; using vi = vector<int>; using vs = vector<string>; using vvi = vector<vector<int>>; using P = pair<int,int>; int main() { int h, w; cin >> h >> w; map<int,int> s; multiset<int> vals; rep(i,w) s[i] = i; rep(i,w) vals.insert(0); rep(i,h) { int l, r; cin >> l >> r; --l; auto it = s.lower_bound(l); int mr = -1; while (it != s.end() && it->first <= r) { mr = max(mr, it->second); int x = it->first - it->second; vals.erase(vals.find(x)); s.erase(it++); } if (mr != -1 && r < w) { vals.insert(r - mr); s[r] = mr; } int ans = -1; if (vals.size() > 0) { ans = *vals.begin() + (i+1); } cout << ans << endl; } return 0; }
1
#include <cstdio> //#include <iostream> //#include <string> using namespace std; // cl /EHsc xxx.cpp int main(int argc, char *argv[]) { int n; scanf("%d", &n); int *ary = new int[n]; int v; int t = n; while (t) { scanf("%d", &v); ary[--t] = v; } for (int j = 0; j < n; j++) { printf((j == n-1) ? "%d\n" : "%d ", ary[j]); } delete[] ary; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<int> a(n); for(int i = 0; i < n; i++){ cin >> a[i]; } for(int i = 0; i < n; i++){ cout << a[n - 1 - i]; if(i == n - 1) break; cout << ' '; } cout << endl; }
1
#include <stdio.h> int main(){ int date[11]; for(int i = 0; i < 10; i++){ scanf("%c", &date[i]); } for(int i = 0; i < 10; i++){ date[3] = '8'; printf("%c", date[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; int main(void){ //* string a; cin >> a ; //*/ a.at(3) = '8'; /* vector<int> vec(4); cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ; sort(vec.begin(), vec.end()); */ /* if(a == 0){ cout << "" << endl; } else if(a > 0){ cout << "" << endl; } else { cout << "" << endl; } */ cout << a << endl; return 0; }
1
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> #include <string> #include <vector> #include <map> #include <unordered_map> #include <queue> #include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <limits> using namespace std; typedef long long LL; using Graph = vector<vector<int>>; static long long INF = (1LL<<62); LL N, M; int main(int argc, char* argv[]){ cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M; if(N == 1){ printf("%lld\n", M); return 0; } vector<LL> D; for(LL d = 2; d * d <= M; d++){ if((M % d) == 0){ D.push_back(d); D.push_back(M/d); } } sort(D.begin(), D.end()); long long ans = 1; for(int i=D.size()-1; i>=0; i--){ if( (M / D[i]) >= N && D[i] > ans){ ans = D[i]; } } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define pb push_back #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) #define ll long long using namespace std; const ll P = 1000000007; int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } int main() { cout << fixed << setprecision(10); int N,M; cin >> N >> M; int n = M/N; for(int i=n;i>0;i--) { if((M-(N-1)*i)%i==0) { cout << i << endl; return 0; } } return 0; }
1
#include<iostream> #include<cstdio> using namespace std; class Dice_c{ private: int me[4]; int topbot[2]; // top,bottom public: void Input(); void Roll(char c); void Output(); }; int main(){ Dice_c dice; char com; dice.Input(); while(1){ scanf("%c",&com); if(com=='\n') break; dice.Roll(com); } dice.Output(); return 0; } /////////////////////////////////////// void Dice_c::Input(){ cin >> me[1] >> topbot[1] >> me[2] >> me[0] >> topbot[0] >> me[3]; getchar(); } void Dice_c::Roll(char c){ int tmp; if(c == 'W'){ tmp = me[0]; me[0]=me[1] , me[1]=me[2] , me[2]=me[3] , me[3]=tmp; } else if(c == 'E'){ tmp = me[3]; me[3]=me[2] , me[2]=me[1] , me[1]=me[0] , me[0]=tmp; } else if(c == 'N'){ tmp = topbot[1]; topbot[1]=me[3] , me[3]=topbot[0] , topbot[0]=me[1] , me[1]=tmp; } else{ tmp = topbot[0]; topbot[0]=me[3] , me[3]=topbot[1] , topbot[1]=me[1] , me[1]=tmp; } /* cout << " " << topbot[0] << endl; for(int i=0; i<4; i++) cout << me[i] << ' '; cout << endl << " " << topbot[1] << endl; */ } void Dice_c::Output(){ cout << me[1] << endl; }
#include <iostream> #include <string> using namespace std; class Dice{ int top, n, s, e, w; public: Dice(); void roll(char dir); int getTop(); }; Dice::Dice(){ top = 1; n = 5; s = 2; e = 3; w = 4; } void Dice::roll(char dir){ switch (dir){ case 'N': n = top; top = s; s = 7 - n; break; case 'S': s = top; top = n; n = 7 - s; break; case 'E': e = top; top = w; w = 7 - e; break; case 'W': w = top; top = e; e = 7 - w; break; } } int Dice::getTop(){ return top; } int main(void){ int num[6]; string str; Dice dice; for (int i = 0; i < 6; i++){ cin >> num[i]; } cin >> str; for (int i = 0; i < str.size(); i++){ dice.roll(str[i]); } cout << num[dice.getTop()-1] << "\n"; return 0; }
1
#include<bits/stdc++.h> #define For(i,x,y) for (register int i=(x);i<=(y);i++) #define FOR(i,x,y) for (register int i=(x);i<(y);i++) #define Dow(i,x,y) for (register int i=(x);i>=(y);i--) #define Debug(v) for (auto i:v) printf("%lld ",i);puts("") #define mp make_pair #define fi first #define se second #define pb push_back #define ep emplace_back #define siz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() #define fil(a,b) memset((a),(b),sizeof(a)) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pa; typedef pair<ll,ll> PA; typedef vector<int> poly; inline ll read(){ ll x=0,f=1;char c=getchar(); while ((c<'0'||c>'9')&&(c!='-')) c=getchar(); if (c=='-') f=-1,c=getchar(); while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar(); return x*f; } const int N = 2e5+10; int n; inline PA Get(int d,ll c){ if (c==1) return {d,0}; PA tmp=Get(d,c/2); tmp.se=(tmp.se*2+1+(tmp.fi*2>=10)); if (tmp.fi*2>=10) tmp.fi=(tmp.fi*2)/10+(tmp.fi*2)%10; else tmp.fi*=2; if (c&1){ tmp.se=tmp.se+1+(tmp.fi+d>=10); tmp.fi=(tmp.fi+d)/10+(tmp.fi+d)%10; } return tmp; } int main(){ n=read(); ll x=0,ans=0; For(i,1,n){ ll d=read(),c=read(); PA tmp=Get(d,c); ans+=tmp.se; if (i!=1) ans++; ans+=(x+tmp.fi>=10); x=(x+tmp.fi)/10+(x+tmp.fi)%10; //printf(" %lld %lld\n",x,ans); } printf("%lld\n",ans); }
#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; ll c[200100], d[200100]; int main() { int m; cin >> m; rep(i,m) cin >> d[i] >> c[i]; ll s = 0, len = 0; rep(i,m) { s += c[i] * d[i]; len += c[i]; } ll ans = (len-1) + ((s-1)/9); cout << ans << endl; return 0; }
1
#include <iostream> #include <algorithm> using namespace std; const int inf = 1012345678; int N, M, a[114], b[114], c[114], g[19][19], sum[32777], val[32777], dp[19][32777], dp2[32777]; int main() { cin >> N >> M; int all_cost = 0; for (int i = 0; i < M; i++) { cin >> a[i] >> b[i] >> c[i]; a[i]--, b[i]--; sum[(1 << a[i]) + (1 << b[i])] += c[i]; g[a[i]][b[i]] = g[b[i]][a[i]] = c[i]; all_cost += c[i]; } for (int i = 0; i < M; i++) { for (int j = i + 1; j < M; j++) { if (c[i] < c[j]) { swap(a[i], a[j]); swap(b[i], b[j]); swap(c[i], c[j]); } } } for (int i = 0; i < N; i++) { for (int j = 0; j < 1 << N; j++) { dp[i][j] = -inf; } } dp[0][1] = 0; for (int i = 3; i < 1 << N; i += 2) { for (int j = 0; j < N; j++) { if (i & (1 << j)) { int sb = i - (1 << j); for (int k = 0; k < N; k++) { if ((sb & (1 << k)) && g[j][k] != 0) { dp[j][i] = max(dp[j][i], dp[k][sb] + g[j][k]); } } } } } for (int i = 0; i < N; i++) { for (int j = 0; j < 1 << N; j++) { if (!(j & (1 << i))) { sum[j + (1 << i)] += sum[j]; } } } int ret = 0; for (int i = 0; i < 1 << N; i++) { if ((i & 1) && (i & (1 << (N - 1)))) { int sb = (1 << N) - i - 1; for (int j = sb; j >= 0; j--) { j &= sb; val[j] = 0; for (int k = 0; k < N; k++) { if (i & (1 << k)) { val[j] = max(val[j], sum[j + (1 << k)]); } } } dp2[0] = 0; for (int j = sb; j >= 0; j--) { j &= sb; if (j == sb) continue; int rj = sb - j; dp2[rj] = 0; for (int k = rj; k > 0; k = (k - 1) & rj) { dp2[rj] = max(dp2[rj], dp2[rj - k] + val[k]); } } ret = max(ret, dp2[sb] + dp[N - 1][i]); } } cout << all_cost - ret << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define D isdigit(c=getchar()) inline int getint(){ int c,l=0,x; for (;!D;l=c)if(c==EOF)return 1<<31; for (x=c-'0';D;x=x*10+c-'0')if(c==EOF) break; return l=='-'?-x:x; } int dist[16][16],f[1<<16],dp[16][1<<16],g[1<<16][16],n,m; int main(){ n=getint();m=getint(); for(int i=1;i<=m;i++){ int x=getint(),y=getint(); dist[x][y]=dist[y][x]=getint(); } for(int i=0;i<(1<<n);i++) for(int j=1;j<=n;j++) for(int k=1;k<=n;k++) if((i&(1<<j-1))&&(!(i&(1<<k-1))))f[i]+=dist[j][k]; memset(dp,0x3f,sizeof(dp)); for(int i=0;i<(1<<n);i++) if(i&1){ dp[1][i]=f[i]; for(int j=1;j<=n;j++)if(dist[1][j])g[i][j]=1; } for(int i=1;i<(1<<n);i++)if(i&1){ for(int k=2;k<=n;k++)if(i&(1<<k-1)){ for(int j=i-(1<<k-1);j;j=j-1&i-(1<<k-1))if(j&1){ int l=g[j][k];if(!l)continue; dp[k][i]=min(dp[k][i],dp[l][j]-2*dist[l][k]+f[i-j]); } // printf("dp[%d][%d]=%d\n",k,i,dp[k][i]); } for(int k=1;k<=n;k++){ int mx=0x3f3f3f3f;g[i][k]=0; for(int l=1;l<=n;l++)if(i&(1<<l-1)&&dist[l][k]&&dp[l][i]-2*dist[l][k]<mx){ mx=dp[l][i]-2*dist[l][k];g[i][k]=l; } } } printf("%d\n",dp[n][(1<<n)-1]/2); return 0; } //MainFunction
1
#include <iostream> using namespace std; int main(){ long long int n,i=1,a=0; cin >> n; while (i <= n) { if (i % 3 != 0 && i % 5 != 0) a += i; i++; } cout << a; }
///f. fizzbuzz sequence #include <stdio.h> #include <math.h> int main() { long long int n; scanf("%lld",&n); long long int d3,d5,d15; d3=n/3; d5=n/5; d15=n/15; long long sum = (n*(n+1)-3*d3*(d3+1)-5*d5*(d5+1)+15*d15*(d15+1))/2; printf("%lld",sum); return 0; }
1
#include<iostream> #include<map> using namespace std; int main(){ map<string, int> weekday; weekday["SUN"] = 0; weekday["MON"] = 1; weekday["TUE"] = 2; weekday["WED"] = 3; weekday["THU"] = 4; weekday["FRI"] = 5; weekday["SAT"] = 6; string day; std::cin >> day; std::cout << 7 - weekday[day]; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> P; typedef vector<ll> VI; typedef vector<VI> VVI; const ll MOD = 1000000007; const ll INF = 1e18; #define REP(i, n) for(int i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() int main(){ ll n; cin >> n; int ans=log10(n)+1; for(int i=1;i<=sqrt(n);i++){ if(n%i==0){ ans=max(log10(i)+1,log10(n/i)+1); } } cout << ans << endl; return 0; }
0
//Partition #include<bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define rep(i,x,y) for(ll i=x;i<y;i++) #define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i] #define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i] #define lcm(a,b) (a/__gcd(a, b)*b) #define range(a) (a).begin(),(a).end() #define pb push_back #define mp make_pair #define nnn "\n" #define spa " " using p = pair<ll,ll>; using graph = vector<vector<ll>>; const int inf = 2147483647;//2*10^9 const ll INF = 9223372036854775807;//9*10^18 bool IsPrime(int num){ if(num<2)return false; else if(num==2)return true; else if(num%2==0)return false; double sqrtNum=sqrt(num); for (int i=3;i<=sqrtNum;i+=2)if(num%i==0)return false; return true; } signed main (){ int n,m,ans=1;cin>>n>>m; if(n==1){cout<<m<<nnn;return 0;} if(IsPrime(m)){cout<<1<<nnn;return 0;} for(int i=2;i*i<1000001000;i++){ if(m%i==0&&m/i>=n){ ans=max(ans,i); if(i>=n){ ans=max(ans,m/i); } } } cout<<ans<<nnn; return 0; }
#include<bits/stdc++.h> #define ll long long #define rep(i,a,b) for(i=a;i<b;i++) #define pb push_back #define all(v) v.begin(),v.end() #define F first #define S second #define hell 1000000007 using namespace std; const int N=500; void solve() { ll i,j,k,n,m,c=0,ans=0; string s; cin>>n>>m; if(abs(n-m)<=16-n-m) cout<<"Yay!"; else cout<<":("; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t=1; //cin>>t; while(t--) solve(); }
0
#include <bits/stdc++.h> using namespace std; int main() { int N,k; cin >> N >>k; int sum; if(k==1){ sum = N+1; } else if(k==2||k==3||k==4){ if (N==1){ sum = 2; } else{ sum = 4 + k*(N-2); } } else if(k==5||k==6||k==7){ if (N==1){ sum = 2; } else if(N==2){ sum = 4; } else{ sum = 8 + k*(N-3); } } else{ if (N==1){ sum = 2; } else if (N==2){ sum = 4; } else if (N==3){ sum = 8; } else{ sum = 16 + k*(N-4); } } cout<<sum<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; int x = 1; for (int i = 0; i < N; i++) { // iのスコープはforの終わりまで if( x * 2 <= x + K ){ x *= 2; } else { x += K; } } cout << x <<endl; }
1
#include<bits/stdc++.h> using namespace std; #define ll long long int int main(){ char s[3]; cin>>s[0]>>s[1]>>s[2]; int max=0, locmax=0; for(int i=0;i<3;i++){ if(s[i] == 'R'){ locmax++; } else{ locmax=0; } if(locmax>max){ max=locmax; } } cout<<max; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; int main() { int n, l; cin >> n >> l; vector<int> d(n); for (int i = 1; i <= n; i++) { d[i-1] = l+i-1; } int all = 0; rep(i,n) all += d[i]; int ans = 0; int mn = 10000; rep(i,n) { int dall = all-d[i]; if (abs(all-dall) < mn) { mn = abs(all-dall); ans = dall; } } cout << ans << endl; return 0; }
0
#include<cstdio> int main(){ int n,x; scanf("%d", &n); int dice[n][6]; int tmp[6]; for(int i = 0; i < n; i++){ for(int j = 0; j < 6; j++){ scanf("%d", &dice[i][j]); } } int pt[5][6] = { {5,1,3,4,6,2}, {0,0,0,0,0,0}, {4,2,1,6,5,3}, {2,6,3,4,1,5}, {3,2,6,1,5,4}}; int t[24] = {0,0,0,2,0,0,0,2,0,0,0,4,0,0,0,4,0,0,0,2,0,0,0,0}; for(int a = 0; a < n; a++){ for(int b = a + 1; b < n; b++){ for(int i = 0; i < 24 ; i++){ int c = 0; while(!(dice[a][c] - dice[b][c])){ c++; if(c == 6){ printf("No\n"); return 0; } } for(int j = 0; j < 6; j++){ tmp[j] = dice[a][j]; } for(int j = 0; j < 6; j++){ x = pt[t[i]][j]; dice[a][j] = tmp[x - 1]; } } } } printf("Yes\n"); return 0; }
#include<iostream> #include<string> #include<vector> using namespace std; enum Diceface { DICETOP, DICEFRONT, DICERIGHT, DICELEFT, DICEBACK, DICEBOTTOM, DICENUM }; class Dice { private: int *face; public: Dice( ) { face = new int[DICENUM]; } Dice( int top, int front, int right, int left, int back, int bottom ) { face = new int[DICENUM]; face[DICETOP] = top; face[DICEFRONT] = front; face[DICERIGHT] = right; face[DICELEFT] = left; face[DICEBACK] = back; face[DICEBOTTOM] = bottom; } ~Dice( ) { delete [ ] face; } void setFace( int top, int front, int right, int left, int back, int bottom ) { face[DICETOP] = top; face[DICEFRONT] = front; face[DICERIGHT] = right; face[DICELEFT] = left; face[DICEBACK] = back; face[DICEBOTTOM] = bottom; return; } void roll( char cmd ) { int t; if( 'E' == cmd ) { t = face[DICETOP]; face[DICETOP] = face[DICELEFT]; face[DICELEFT] = face[DICEBOTTOM]; face[DICEBOTTOM] = face[DICERIGHT]; face[DICERIGHT] = t; } else if( 'N' == cmd ) { t = face[DICETOP]; face[DICETOP] = face[DICEFRONT]; face[DICEFRONT] = face[DICEBOTTOM]; face[DICEBOTTOM] = face[DICEBACK]; face[DICEBACK] = t; } else if( 'S' == cmd ) { t = face[DICETOP]; face[DICETOP] = face[DICEBACK]; face[DICEBACK] = face[DICEBOTTOM]; face[DICEBOTTOM] = face[DICEFRONT]; face[DICEFRONT] = t; } else if( 'W' == cmd ) { t = face[DICETOP]; face[DICETOP] = face[DICERIGHT]; face[DICERIGHT] = face[DICEBOTTOM]; face[DICEBOTTOM] = face[DICELEFT]; face[DICELEFT] = t; } else if( 'M' == cmd ) { t = face[DICEBACK]; face[DICEBACK] = face[DICERIGHT]; face[DICERIGHT] = face[DICEFRONT]; face[DICEFRONT] = face[DICELEFT]; face[DICELEFT] = t; } return; } int getFace( int diceface ) { return face[ diceface ]; } bool isDiff( Dice &dice ) { int cnt; string cmd = "MMMMNMMMMWMMMMWMMMMWMMMMNMMMM"; for( int i=0; i<cmd.length(); i++ ) { if( dice.getFace( DICETOP ) == face[ DICETOP ] ) { for( cnt=0; cnt<DICENUM; cnt++ ) { if( dice.getFace( cnt ) != face[ cnt ] ) { break; } } if( DICENUM == cnt ) { break; } } dice.roll( cmd[i] ); } if( DICENUM == cnt ) { return false; } else { return true; } } }; int main( ) { int t, f, r, l, ba, bo; int n; cin>>n; Dice *dice = new Dice[n]; if( NULL == dice ) { return 0; } int cnt = 0; while( cnt < n ) { cin>>t>>f>>r>>l>>ba>>bo; dice[ cnt++ ].setFace( t, f, r, l, ba, bo ); } bool isDiff = false; for( int i=0; i<n-1; i++ ) { for( int j=i+1; j<n; j++ ) { if( !( isDiff = dice[i].isDiff( dice[j] ) ) ) { break; } } if( !isDiff ) { break; } } if( isDiff ) { cout<<"Yes"<<endl; } else { cout<<"No"<<endl; } delete [ ] dice; return 0; }
1
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<set> #include<iomanip> #define rep(i, a, n) for(int i = a; i < n; i++) using namespace std; int main(){ int a, b; cin >> a >> b; if(a % b == 0){ cout << "0\n"; return 0; } cout << "1\n"; }
#include <cstdio> #include <cmath> #include <limits> #include <fstream> #include <iostream> #include <algorithm> #include <vector> #include <utility> #include <cstring> #include <set> #include <map> #include <queue> #include <stack> #include <cstdint> #include <functional> #define rep(i, s, g) for (i = s; i < g; i++) using namespace std; using ll = long long; const ll mod = 1000000000 + 7; //10^9 int main() { int N, L; cin >> N >> L; vector<int> abs_taste(N); int eat = 300; int c; for (int i = 0; i < N; i++) { abs_taste[i] = abs(L + i); if(abs_taste[i] < eat){ eat = abs_taste[i]; c = i; } } int sum = N * (L - 1) + (1 + N) * N / 2; int ans = sum - (L + c ); cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for(int i = n-1; i >= 0; i--) #define all(x) (x).begin(),(x).end() // 昇順ソート #define rall(v) (v).rbegin(), (v).rend() // 降順ソート #define FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) typedef long long ll; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<vector<int>>; using VL = vector<ll>; using VVL = vector<vector<ll>>; using VP = vector<P>; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; } const ll INF = 1LL<<60; int main(){ int d; ll g; cin >> d >> g; VP q(d); rep(i,d) cin >> q[i].first >> q[i].second; VI p(d); rep(i,d) p[i] = i; ll ans = INF; do{ VI pp(d); rep(i,d) pp[p[i]] = i; ll gg = g; ll cnt = 0; rep(i,d){ int j = pp[i]; ll pc = (j + 1) * 100; ll num = min((ll)q[j].first, ((gg + (pc-1)) / pc)); cnt += num; gg -= pc * num; gg -= q[j].second; if (gg <= 0) break; } ans = min(ans, cnt); } while(next_permutation(all(p))); cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int d, g; cin >> d >> g; int p[d], c[d]; int sum = 0, num_mn = 1001; bool ach; for (int i = 0; i < d; i++) cin >> p[i] >> c[i]; for (int bit = 0; bit < (1 << d); bit++) { int num_tmp = 0; sum = 0; ach = false; for (int i = 0; i < d; i++) { if (bit & (1 << i)) { num_tmp += p[i]; sum += ((i + 1) * 100 * p[i] + c[i]); } } // cout << "1st sum:" << sum << " num_tmp:" << num_tmp << endl; if (sum < g) { for (int i = d - 1; i >= 0; i--) { if (!(bit & (1 << i))) { if (g - sum <= (i + 1) * 100 * (p[i] - 1)) { ach = true; num_tmp += ((g - sum) / ((i + 1) * 100)); if ((g - sum) % ((i + 1) * 100) != 0) num_tmp++; break; } else { sum += (i + 1) * 100 * (p[i] - 1); num_tmp += (p[i] - 1); } } } } else ach = true; if (!ach) num_tmp = 1001; num_mn = min(num_mn, num_tmp); } cout << num_mn << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int N,M; cin>>N>>M; vector<bool> isAC(N, false); vector<int> check(N,0); int wans=0, cans=0; int p; string s; for(int i=0; i<M; i++){ cin>>p>>s; if(isAC.at(p-1)) continue; else{ if(s=="AC"){ isAC.at(p-1) = true; cans++; wans+=check.at(p-1); } else{ check.at(p-1)++; } } } cout<<cans<<" "<<wans<<"\n"; }
#include <iostream> #include <algorithm> using namespace std; #include <cmath> //floor ceil #include <cstdlib> //abs #include <cstdio> #include <climits> //INT_MAX #include <cstring> #define endl "\n" #define debug(x) cerr<<#x<<'='<<(x)<<endl; #define lli long long int #define MOD 1000000007 #include <map> #define mp make_pair #define mii map<int,int> /*---------------------------------------------------CODE STARTS FROM HERE---------------------------------------------------*/ int main () { int n,m,ac=0,p=0; cin>>n>>m; int a[n],wa[n]; for (int i=0;i<n;i++) a[i]=0,wa[i]=0; while(m--) { int x; string s; cin>>x>>s; if(a[x-1]==0 && s=="AC") { a[x-1]=1; ac++; p += wa[x-1];} else if(a[x-1]==0 && s=="WA") wa[x-1]++; //debug(wa[x-1]); } printf("%d",ac); printf(" "); printf("%d",p); return 0; }
1
#include <bits/stdc++.h> using namespace std; #define PI 3.14159265358979323846264338327950L int main() { int N; cin >> N; long long sum = 0; for (int ii = 1; ii <= N; ii++) { if (ii % 3 == 0 && ii % 5 == 0) { continue; } if (ii % 3 == 0 || ii % 5 == 0) { continue; } sum += ii; } cout << sum << endl; }
#include<iostream> #include<math.h> #include<algorithm> #include<stdint.h> #include<vector> #include<deque> #include<stack> #include<string> #include<cstring> #include<time.h> #include<array> #include<iomanip> #include<list> #include<set> #include<unordered_map> #include<unordered_set> #include<random> #include<bitset> #include <queue> #include <map> using namespace std; using ll = long long; using ull = unsigned long long; using uint = unsigned int; using ldouble = long double; //BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun #define PRI(s) cout << s << endl #define PRIY PRI("Yes") #define PRIN PRI("No") int main() { string d[7] = { "SUN","MON","TUE","WED","THU","FRI","SAT" }; string x; cin >> x; for (int i = 0; i < 7; ++i) { if (d[i] == x) { PRI(7 - i); return 0; } } return 0; }
0
#include<bits/stdc++.h> using namespace std; #define intt long long int #define intu unsigned long long int #define vi vector<intt> #define ii pair<int,int> #define pb push_back //#define mp make_pair #define ff first #define ss second #define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL); # define PI 3.14159265358979323846 #define all(a) a.begin(),a.end() #define for0(i, n) for (int i = 0; i < n; i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define loop(i,a,b) for (int i = a; i < b; i++) #define bloop(i,a,b) for (int i = a ; i>=b;i--) #define tc(t) int t; cin >> t; while (t--) int mod = 1000000007; intt gcd(intt a, intt b) {return b ? gcd(b, a % b) : a;} int lcm(int a, int b) {return a * b / gcd(a, b); } intt bpow(intt a,intt b) { intt res = 1; while (b > 0) { if (b & 1)res = res * a; a = a * a; b >>= 1; } return res; } intt fact(intt n) { if ((n==0)||(n==1)) return 1; else return (n*fact(n-1))%mod; } void go() { #ifndef ONLINE_JUDGE freopen("IN.txt","r",stdin); freopen("OUT.txt","w",stdout); #endif } int main(){ go(); fast_io int n;cin>>n; vi a(n),b(n); for0(i,n){ cin>>a[i]; } for0(i,n){ cin>>b[i]; } reverse(all(b)); int l=0,r=0; while(b[r]!=a[r] && r<n){ r++;l++; } if(r==n){ cout << "Yes" <<"\n"; for(auto it: b) cout << it <<" "; cout << "\n"; } else{ while(r<n && a[r]==b[r]) r++; int need=r-l; int j=0,left=l,right=r; while(j<left && l<r && need){ if(b[j]!=b[l] && a[j]!=b[l]){ swap(b[j],b[l]); need--; l++; j++; } else break; } j=n-1; while(j>=right && l<right && need){ if(b[j]!=b[l] && a[j]!=b[l]){ swap(b[j],b[l]); need--; l++; j--; } else break; } if(need) cout << "No" <<"\n"; else{ cout << "Yes" <<"\n"; for(auto it: b) cout << it <<" "; cout << "\n"; } } } /* */ //9c(n-2)*2
#include <bits/stdc++.h> #define _USE_MATH_DEFINES #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) FOR(i, 0, n) using namespace std; class Dice { public: int label[6], tmp; void in() { rep(i, 6) scanf("%d", &label[i]); } void rollS() { tmp = label[0]; label[0] = label[4]; label[4] = label[5]; label[5] = label[1]; label[1] = tmp; } void rollN() { tmp = label[0]; label[0] = label[1]; label[1] = label[5]; label[5] = label[4]; label[4] = tmp; } void rollE() { tmp = label[0]; label[0] = label[3]; label[3] = label[5]; label[5] = label[2]; label[2] = tmp; } void rollW() { tmp = label[0]; label[0] = label[2]; label[2] = label[5]; label[5] = label[3]; label[3] = tmp; } void sideturn() { tmp = label[1]; label[1] = label[2]; label[2] = label[4]; label[4] = label[3]; label[3] = tmp; } }; bool check2(Dice d1, Dice d2) { bool c = true; FOR(i, 1, 5) { c = c && d1.label[i] == d2.label[i]; } return c; } bool check1(Dice d1, Dice d2) { bool b = false; if (d1.label[0] == d2.label[0] && d1.label[5] == d2.label[5]) { rep(i, 4) { b = b || check2(d1, d2); d2.sideturn(); } } return b; } bool isSame(Dice d1, Dice d2) { bool a = false; a = a || check1(d1, d2); d2.rollN(); a = a || check1(d1, d2); d2.rollE(); a = a || check1(d1, d2); d2.rollE(); a = a || check1(d1, d2); d2.rollE(); a = a || check1(d1, d2); d2.rollN(); a = a || check1(d1, d2); return a; } int main() { int n; bool ans = false; scanf("%d", &n); Dice dice[n]; rep(i, n) dice[i].in(); rep(i, n) { FOR(j, i + 1, n) { ans = ans || isSame(dice[i], dice[j]); } } if (ans) printf("No\n"); else printf("Yes\n"); }
0
////////////////////////// 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) { c=0,a=MX; rep(i,n) { cin>>x; if(x<a)c++,a=x; } cout<<c<<en; } return 0; }
// Problem : C - Low Elements // Contest : AtCoder - AtCoder Beginner Contest 152 // URL : https://atcoder.jp/contests/abc152/tasks/abc152_c // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include<bits/stdc++.h> #include<set> #define lli long long int #define pb push_back #define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define rep(i,a,n) for(i=a;i<n;i++) #define all(v) (v.begin(),v.end()) #define ppb pop_back #define vsz v.size() #define pi 3.141592653589793238 using namespace std; int main() { lli t,n,i,k=1e6; cin>>n; vector<lli>v; for(i=0;i<n;i++){ cin>>t; v.pb(t); } t=0; for(i=0;i<n;i++){ if(v[i]<k) t++; k=min(k,v[i]); } cout<<t; return 0; }
1
#include<bits/stdc++.h> using namespace std; void read(int &x) { x=0;int f=1;char ch=getchar(); for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f; for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f; } void print(int x) { if(x<0) putchar('-'),x=-x; if(!x) return ;print(x/10),putchar(x%10+48); } void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');} #define lf double #define ll long long #define pii pair<int,int > #define vec vector<int > #define pb push_back #define mp make_pair #define fr first #define sc second #define data asd09123jdf02i3h #define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++) const int maxn = 1e6+10; const int inf = 1e9; const lf eps = 1e-8; const int mod = 1e9+7; int n;ll ans; char s[maxn]; map<pair<string,string > ,int > t; void dfs1(int x,string a,string b) { if(x==n+1) {t[mp(a,b)]++;return ;} dfs1(x+1,a+s[x],b),dfs1(x+1,a,s[x]+b); } void dfs2(int x,string a,string b) { if(x==n) {ans+=t[mp(a,b)];return ;} dfs2(x-1,a+s[x],b),dfs2(x-1,a,s[x]+b); } int main() { read(n);scanf("%s",s+1); dfs1(1,"",""); dfs2(2*n,"",""); printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for(int i=0; i<(n); i++) #define int long long #define double long double #define all(a) a.begin(),a.end() template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; signed main(void){ cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int n; string s; cin>>n>>s; map<pair<string,string>,int> mp; rep(i,1<<n){ string t="",u=""; rep(j,n){ if((1<<j)&i)t=s[j+n]+t; else u=s[j+n]+u; } mp[pair<string,string>(t,u)]++; } int ans=0; rep(i,1<<n){ string t="",u=""; rep(j,n){ if((1<<j)&i)t+=s[j]; else u+=s[j]; } ans+=mp[pair<string,string>(t,u)]; } cout<<ans<<endl; }
1
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <unordered_set> using namespace std; using ll = long long int; int main() { int x, y; cin >> x >> y; int prize = 0; if (x <= 3) { prize += (4-x) * 100000; } if (y <= 3) { prize += (4-y) * 100000; } if (x == 1 && y == 1) { prize += 400000; } cout << prize << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int x,y; cin >> x>>y; vector<int> a(206); a.at(1)=300000; a.at(2)=200000; a.at(3)=100000; if((x==1)&&(y==1)){ cout << 1000000 <<endl; } else{ cout << a.at(x) + a.at(y) << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int K, T; cin >> K >> T; priority_queue<pair<int, int>> q; int ai; for (int i = 0; i < T; i++) { cin >> ai; q.push(make_pair(ai, i + 1)); } int res = 0; int prev = 0; for (int i = 0; i < K; i++) { pair<int, int> p0 = q.top(); q.pop(); if (p0.second == prev) { if (q.empty()) { res += p0.first; break; } else { pair<int, int> p1 = q.top(); q.pop(); p1.first--; prev = p1.second; if (p1.first > 0) { q.push(p1); } } } else { p0.first--; prev = p0.second; } if (p0.first > 0) { q.push(p0); } } cout << res << endl; }
#include <algorithm> #include <iostream> using namespace std; int main() { int K, a, M{}; cin >> K >> a; while (cin >> a) M = max(M, a); cout << max(0, 2 * M - K - 1) << endl; }
1
#include<bits/stdc++.h> using namespace std; const int MAXN=10005; int P=1e9+7,d,len; char k[MAXN]; long long a[MAXN],dp[10005][105]; long long dfs(int pos,int tot,bool lim) { // cout<<pos<<' '<<tot<<' '<<lim<<endl; if(pos==len+1) { if(tot==0) return 1; return 0; } if(!lim&&dp[pos][tot]!=-1) return dp[pos][tot]; long long ret=0 , up=lim?a[pos]:9 ; for(int i=0;i<= up ;++i) { ret=(ret+dfs(pos+1,(tot+i)%d, lim&&i==a[pos] ))%P; //(ret+=dfs(pos+1,(tot+i)%d, lim&&i==a[pos] ) )%=P; } if(!lim) dp[pos][tot]=ret; return ret; } int main() { memset(dp,-1,sizeof(dp)); scanf("%s",k+1); scanf("%d",&d); len=strlen(k+1); for(int i=1;i<=len;++i) { a[i]=k[i]-'0'; } long long ans=(dfs(1,0,1)-1+P)%P; printf("%lld\n",ans); return 0; }
#include<iostream> #include<string> using namespace std; long long MOD = 1000000007; int main(){ //input long long D; string S; cin >> S; cin >> D; long long keta=S.length(); long long N[keta]; long long i,k, digit; long long j; for(i=0; i<keta; i++){ N[i]=(long long)(S[i]-'0'); } //calc long long dp[keta][2][D]; for(i=0; i<keta; i++){ for(j=0; j<=1; j++){ for(k=0; k<D; k++){ dp[i][j][k]=0; } } } for(digit=0; digit<10; digit++){ if(digit<N[0]){ dp[0][1][digit%D]++; }else if(digit==N[0]){ dp[0][0][digit%D]++; } } for(i=0; i<keta-1; i++){ for(j=0; j<=1; j++){ for(k=0; k<D; k++){ for(digit=0; digit<(j?10:N[i+1]+1); digit++){ dp[i+1][j||(digit<N[i+1])][(k+digit)%D]+=dp[i][j][k]; dp[i+1][j||(digit<N[i+1])][(k+digit)%D]%=MOD; } } } } cout << (dp[keta-1][0][0]+dp[keta-1][1][0]-1+MOD)%MOD << endl; system("pause"); return 0; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define mod 1000000007 struct mint { ll x; mint(ll x=0):x(x%mod){} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res+=a; } mint operator-(const mint a) const { mint res(*this); return res-=a; } mint operator*(const mint a) const { mint res(*this); return res*=a; } }; mint mod_pow(int i,int j) { mint x=i; mint y=(j%2)? x:1; j/=2; while(j!=0) { x=x*x; if(j%2) { y=(y.x==1)? x:x*y; } j/=2; } return y; } int main() { int n; cin>>n; vector<long long>a(n); for(int i=0;i<n;i++)cin>>a[i]; mint ans=0; for(int i=0;i<64;i++) { int z=0; int o=0; for(int j=0;j<n;j++) { ll t=1L<<i; if(t&a[j])o+=1; else z+=1; } //cout<<i<<" "<<o<<" "<<z<<endl; ans+=(mod_pow(2,i)*z*o); } cout<<ans.x<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(int i=0; i<(n); i++) #define REP2(i,x,n) for(int i=x; i<(n); i++) #define PRINT(x) cout<<(x)<<endl #define INF 1000000000000 // 10^12 #define MOD 1000000007 // 10^9+7 #define PB push_back #define MP make_pair const int MAX_N = 100009; int N, A[MAX_N]; int same_hat[MAX_N]; // same_hat[i]: 同色の帽子をi人が被っているような色の種類数 int main() { cin >> N; REP(i, N) cin >> A[i]; REP(i, N) same_hat[i] = 0; same_hat[0] = 3; ll num_comb = 1; REP(i, N) { num_comb = num_comb * same_hat[A[i]] % MOD; same_hat[A[i]]--; same_hat[A[i] + 1]++; } PRINT(num_comb); return 0; }
0
#include <bits/stdc++.h> #define rep(i, e, n) for (int i = e; i < (n); ++i) using namespace std; typedef long long ll; using P = pair<int,int>; const ll inf=1000000000007; int main() { int n,q; cin >> n >> q; string s; cin >> s; vector<int> a(n); a[0]=0; rep(i,1,n){ if(s[i-1]=='A' && s[i]=='C') { a[i]= a[i-1]+1; } else a[i]=a[i-1]; } // rep(i,0,n) cout << a[i] << ' '; rep(i,0,q){ int l,r; cin >> l >> r; l--; r--; cout << a[r] - a[l] << endl; } return 0; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; using ll = long long; using vec = vector<ll>; using vect = vector<double>; using Graph = vector<vector<ll>>; #define loop(i, n) for (ll i = 0; i < n; i++) #define Loop(i, m, n) for (ll i = m; i < n; i++) #define pool(i, n) for (ll i = n; i >= 0; i--) #define Pool(i, m, n) for (ll i = n; i >= m; i--) #define mod 1000000007ll //#define mod 998244353ll #define flagcount __builtin_popcount #define flag(x) (1 << x) #define flagadd(bit, x) bit |= flag(x) #define flagpop(bit, x) bit &= ~flag(x) #define flagon(bit, i) bit &flag(i) #define flagoff(bit, i) !(bit & (1 << i)) #define all(v) v.begin(), v.end() #define low2way(v, x) lower_bound(all(v), x) #define high2way(v, x) upper_bound(all(v), x) #define idx_lower(v, x) (distance(v.begin(), low2way(v, x))) //配列vでx未満の要素数を返す #define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す #define idx_lower2(v, x) (v.size() - idx_lower(v, x)) //配列vでx以上の要素数を返す #define idx_upper2(v, x) (v.size() - idx_upper(v, x)) //配列vでxより大きい要素の数を返す #define putout(a) cout << a << endl #define Gput(a, b) G[a].push_back(b) #define Sum(v) accumulate(all(v), 0ll) #define gcd(x, y) __gcd(x, y) ll ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; } template <typename T> T lcm(T x, T y) { T z = gcd(x, y); return x * y / z; } template <typename T> bool primejudge(T n) { if (n < 2) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; double sqrtn = sqrt(n); for (T i = 3; i < sqrtn + 1; i++) { if (n % i == 0) { return false; } i++; } return true; } //場合によって使い分ける //const ll dx[4]={1,0,-1,0}; //const ll dy[4]={0,1,0,-1}; const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; //2次元配列の宣言 //vector<vector<ll>> field(h, vector<ll>(w)); int main() { cout << fixed << setprecision(30); ll D, G; cin >> D >> G; vec p(D), c(D); loop(i, D) cin >> p[i] >> c[i]; ll ans = 1e9; loop(bit, 1 << D) { ll ac = 0; ll score = 0; bool check = false; loop(i, D) if (flagon(bit, i)) { ac += p[i]; score += p[i] * (i + 1) * 100; score += c[i]; if (score >= G) { check = true; break; } } if (check) { ans = min(ans, ac); continue; } //もしも基準点に達していなければ、いままで選択していないなかでもっとも配点の高いシリーズから解いていく //もしも基準を満たせなかったら諦める bool check2 = false; for (ll i = D - 1; i >= 0; i--) { if (flagoff(bit, i)) { loop(j, p[i]) { score += 100 * (i + 1); ac++; if (j == p[i] - 1) score += c[i]; if (score >= G) { check2 = true; break; } } break; } } if (check2) ans = min(ans, ac); } putout(ans); return 0; }
0
#include <stdlib.h> #include <cmath> #include <cstdio> #include <cstdint> #include <string> #include <iostream> #include <vector> #include <utility> #include <algorithm> #include <map> using namespace std; using ll = long long; int main(){ int N,M; cin >> N; map<string,int> blue; string s; for(int i=0;i<N;++i){ cin >> s; if(blue.count(s)) blue.at(s)++; else blue[s]=1; } cin >> M; map<string,int> red; for(int i=0;i<M;++i){ cin >> s; if(red.count(s)) red.at(s)++; else red[s]=1; } int ans=-200; for(auto p: blue){ auto word=p.first; auto value=p.second; if(red.count(word)){ ans=max(ans,value-red.at(word)); } else ans=max(ans,value); } if(ans<0) cout << 0 << endl; else cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; /* エイリアス */ #define ll long long #define ld long double #define vi vector<int> #define vll vector<ll> #define pii pair<int,int> #define pll pair<ll,ll> #define vpi vector<pii> #define vpll vector<pll> #define endl '\n' #define fi first #define se second #define pb push_back #define eb emplace_back #define em emplace #define mp make_pair /* 関数マクロ */ #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) #define all(v) v.begin(), v.end() #define si(v) int(v.size()) #define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end()) /* 定数 */ const ll mod = 1e9 + 7; const ll infll = (1LL << 62) - 1; const ll inf = (1LL << 30) - 1; /* その他 */ template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class T> using pq = priority_queue<T>; template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>; signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); int n; cin >> n; map<string,int> red, blue; rep(i, n) { string s; cin >> s; ++red[s]; } int m; cin >> m; rep(i, m) { string s; cin >> s; ++blue[s]; } int ans = 0; for (auto e : red) { int score = e.se; score -= blue[e.fi]; chmax(ans, score); } cout << ans << endl; }
1
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; vector<int> r,g,b; for(int i = 0; i < n; i++) { char x; cin >> x; if(x=='R') r.push_back(i+1); if(x=='G') g.push_back(i+1); if(x=='B') b.push_back(i+1); } ll ans = r.size()*g.size()*b.size(); if(ans==0){ cout << 0 << endl; return 0; } for(int i = 0; i < r.size(); i++) { for(int j = 0; j < g.size(); j++) { int y=lower_bound(b.begin(),b.end(),g[j]+g[j]-r[i])-b.begin(); if(y!=b.size()){ if(b[y]==g[j]+g[j]-r[i]) ans--; } y=lower_bound(b.begin(),b.end(),r[i]+r[i]-g[j])-b.begin(); if(y!=b.size()){ if(b[y]==r[i]+r[i]-g[j]) ans--; } if((r[i]+g[j])%2==0){ y=lower_bound(b.begin(),b.end(),(r[i]+g[j])/2)-b.begin(); if(y!=b.size()){ if(b[y]==(r[i]+g[j])/2) ans--; } } } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 100005; int r[N],g[N],b[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; string s; cin>>s; ll ans = 0; if(s[0] == 'R')r[0]++; if(s[0] == 'G')g[0]++; if(s[0] == 'B')b[0]++; for(int i=1;i<n;i++){ r[i] = r[i-1]; g[i] = g[i-1]; b[i] = b[i-1]; if(s[i] == 'R')r[i]++; if(s[i] == 'G')g[i]++; if(s[i] == 'B')b[i]++; } for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ if(s[i] != s[j]){ if(s[i] != 'G' && s[j] != 'G'){ ans += g[n-1]-g[j]; if(j + (j-i) <= n-1 && s[j+j-i] == 'G')ans--; } if(s[i] != 'R' && s[j] != 'R'){ ans += r[n-1]-r[j]; if(j + (j-i) <= n-1 && s[j+j-i] == 'R')ans--; } if(s[i] != 'B' && s[j] != 'B'){ ans += b[n-1]-b[j]; if(j + (j-i) <= n-1 && s[j+j-i] == 'B')ans--; } } } } cout<<ans; return 0; }
1
#include <cstdio> #include <iostream> #include <string> using namespace std; int main() { int n; scanf("%d",&n); for (int ix=0; ix<n; ix++) { int out=0,score=0; int hit[] = {0,0,0}; string event; while (out<3) { cin>>event; if (event=="HIT") { if (hit[2]==1) score++; if (hit[1]==1) hit[2]=1; if (hit[0]==1) hit[1]=1; hit[0]=1; } else if (event=="HOMERUN") { for (int i=0; i<3; i++) { score+=hit[i]; hit[i]=0; } score++; } else if (event=="OUT") { out++; } } printf("%d\n",score); } }
#include<stdio.h> int main(){ int n,a[101],t,i,j; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d",&a[i]); } for(j=i-1;j>=0;j--){ if(j==0){printf("%d",a[j]); printf("\n");} else printf("%d ",a[j]); } return 0; }
0
#define REP(i, s, e) for (int i = s; i <= e; i++) #define DREP(i, s, e) for (int i = s; i >= e; i--) #define DEBUG fprintf(stderr, "Passing [%s] in Line %d\n", __FUNCTION__, __LINE__) #define chkmax(a, b) a = max(a, b) #define chkmin(a, b) a = min(a, b) #include <iostream> #include <cstdio> using namespace std; const int maxn = 4000 + 10, MOD = 998244353; int n, k, tot[maxn]; long long fac[maxn], Inv[maxn]; inline int C(int n, int m) {return fac[n] * Inv[m] % MOD * Inv[n-m] % MOD;} int power_pow(long long base, int b) { long long ans(1); while (b) { if (b & 1) (ans *= base) %= MOD; (base *= base) %= MOD; b >>= 1; } return ans; } #define inv(x) power_pow(x, MOD - 2) inline void init() { fac[0] = 1; REP(i, 1, 4000) fac[i] = fac[i-1] * i % MOD; Inv[4000] = inv(fac[4000]); DREP(i, 3999, 0) Inv[i] = Inv[i+1] * (i+1) % MOD; } int main() { #ifdef CraZYali freopen("C.in", "r", stdin); freopen("C.out", "w", stdout); #endif init(); cin >> k >> n; REP(i, 1, k) tot[i+1]++, tot[i+k+1]--; REP(i, 1, k + k) tot[i] += tot[i-1]; REP(i, 2, k + k) { int cnt = tot[i] + 1 >> 1, ans(0); const int lim = min(cnt, n >> 1); REP(j, 0, lim) (ans += (j & 1 ? -1ll : 1ll) * C(cnt, j) * C(n-j-j+k-1, k-1) % MOD) %= MOD; printf("%d\n", (ans + MOD) % MOD); } return 0; }
#include<iostream> #include<algorithm> #include<vector> #include<queue> #include<unordered_map> #include<unordered_set> using namespace std; typedef long long ll; #define chmin(a,b) a=min(a,b) #define chmax(a,b) a=max(a,b) #define mod 998244353 #define mad(a,b) a=(a+b)%mod; #define mul(a,b) a=a*b%mod; #define N 100010 ll fac[N],inv[N],ivf[N]; ll C(ll n,ll k){ if(n<k)return 0; if(n<0||k<0)return 0; return fac[n]*ivf[n-k]%mod*ivf[k]%mod; } ll H(ll n,ll k){ //if(k==0)return 1; return C(n+k-1,k); } ll P(ll n,ll k){ return fac[n]*ivf[n-k]%mod; } ll po(ll x,ll y){ ll res=1; for(;y;y>>=1){ if(y&1)res=res*x%mod; x=x*x%mod; } return res; } ll solve(ll a,ll b,ll n){ ll res=0; for(ll p=0;p<=b;p++){ ll cur=C(b,p)*po(2,p)%mod; mul(cur,H(a+p,n-p)); mad(res,cur); } //cout<<"#"<<a<<" "<<b<<" "<<n<<" "<<res<<endl; return res; } int main(){ fac[0]=ivf[0]=inv[1]=1; for(int i=1;i<N;i++){ if(i>1)inv[i]=(mod-mod/i*inv[mod%i]%mod)%mod; fac[i]=fac[i-1]*i%mod; ivf[i]=ivf[i-1]*inv[i]%mod; } ll k,n; cin>>k>>n; for(ll i=2;i<=2*k;i++){ ll a,b; a=abs(k-i+1); b=(k-a)/2; ll ans=solve(a,b,n); if(i%2==0){ mad(ans,solve(a,b,n-1)); } if(ans<0)ans+=mod; cout<<ans<<endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define rep(i,n) for (int i = 0; i < (n); i++) const ll mod = 1000000007; int main() { int n; cin >> n; int a[n+1]; rep(i,n) cin >> a[i+1]; int ans[n+1]; rep(i,n) ans[i+1] = 0; //rep(i,n) cout << a[i] << endl; for(int i = n; i >= 1; --i) { //printf("OK\n"); for(int j = i; j <= n; j += i) { ans[i] = (ans[i]+ans[j])%2; } ans[i] = (ans[i]+a[i])%2; //printf("OK2\n"); } //rep(i,n) cout << ans[i+1] << endl; int cnt = 0; rep(i,n) { if(ans[i+1]) cnt++; } if (cnt) { cout << cnt << endl; rep(i,n) { if (ans[i+1]) { printf("%d\n", i+1); } } } else cout << 0 << endl; return 0; }
#pragma GCC optimize ("O3") #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <prettyprint.hpp> #define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__); #else #define debug(...) 83; #endif void d_err() { cerr << endl; } template <typename H, typename... T> void d_err(H h, T... t) { cerr << h << " "; d_err(t...); } template <typename T> void print(T x) { cout << x << endl; } #define ALL(x) (x).begin(), (x).end() #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i) #define REP(i, n) FOR(i, 0, n) #define REVREP(i, n) REVFOR(i, 0, n) #define fi first #define se second #define pb push_back #define mp make_pair #define eb emplace_back #define bcnt __builtin_popcountll typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<ll,ll> Pll; typedef pair<int,int> Pin; ll INF = 1e16; int inf = 1e9; ll MOD = 1e9+7; int main(){ cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); int N; cin >> N; vi a(N + 1, 0); FOR(i, 1, N + 1) cin >> a[i]; vi b(N+1, 0); REVFOR(i, N / 2 + 1, N + 1) { b[i] = a[i]; } REVFOR(i, 1, N / 2 + 1) { int cnt = 0; for(int j = i; j <= N; j += i) { cnt += b[j]; } if ((cnt & 1) != a[i]) b[i] = 1; } int m = accumulate(ALL(b), 0); print(m); if (m == 0) return 0; FOR(i, 1, N+1) if(b[i]) cout << i << " "; cout << endl; }
1
#include<iostream> using namespace std; int main() { int a,b,c; int m,n,o; cin>>a>>b>>c; m=a; n=b; o=c; b=m; a=o; c=n; cout<<a<<" "<<b<<" "<<c; return 0; }
#include <iostream> #include <iomanip> typedef long long ll; using namespace std; const ll INF = 1e9; const ll MOD = 1e9 + 7; #define repi(i, n, init) for (ll i = init; i < (n); i++) int main() { int a, b, c; cin >> a >> b >> c; cout << (a <= c && c <= b || b <= c && c <= a ? "Yes" : "No") << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long int N, i, div, result; cin >> N; vector<long long int> A_sum(N); vector<long long int> A(N); div = 1; for (i = 0; i < 9; i++) { div *= 10; } div += 7; for (i = 0; i < N; i++) { cin >> A[i]; A[i] = A[i] % div; } A_sum[N - 1] = A[N - 1]; for (i = N - 2; i > 0; i--) { A_sum[i] = A_sum[i + 1] + A[i]; A_sum[i] = A_sum[i] % div; } result = 0; for (i = 0; i < N - 1; i++) { result += A[i] * A_sum[i + 1]; result = result % div; } cout << result << endl; return 0; }
#include <bits/stdc++.h> #define int long long #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() #define pb push_back #define F first #define S second using namespace std; using P = pair<int,int>; using ivec = vector<int>; using Graph = vector<vector<int>>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } const int MOD=1000000007; int INF=100100100100100; int a[200010]; int ans[200010]; signed main(){ int n;cin>>n; int cnt=0; for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=n;i>=1;i--){ int sum=0; for(int j=2*i;j<=n;j+=i){ sum+=ans[j]; } ans[i]=(sum+a[i])%2; if(ans[i])cnt++; } cout<<cnt<<endl; for(int i=1;i<=n;i++){ if(ans[i])cout<<i<<endl; } return 0; }
0
#pragma GCC optimize ("Ofast") #include"bits/stdc++.h" using namespace std; //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); } } ___; #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " "; __f(comma + 1, args...); } #define ll long long #define pii pair<int,int> #define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define ff first #define ss second #define endll '\n' #define rep(i,n) for(int i=0;i++<n;) #define scl(i) scanf("%lld",&i) #define int long long int #define all(n) n.begin(),n.end() #define mem(n,i) memset(n,i,sizeof n) #define em(a) emplace_back(a) #define pb(a) push_back(a) #define srep(it,vv) for(auto &it : vv) #define prep(it,vv) for(auto it : vv) //vector<vector<int>>arr(n + 5, vector<int>(m + 5,0)); typedef vector<int> vii; typedef vector<string> vss; /* */ signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif set<int>ss; int n = 3; rep(i, n) { int a; cin >> a; ss.insert(a); } if (ss.size() == 2) cout << "Yes" << endll; else cout << "No" << endll; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MOD = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(0); int a, b, c; cin >> a >> b >> c; if (a == b && a != c) { cout << "Yes" << "\n"; } else if (c == b && b != a) { cout << "Yes" << "\n"; } else if (c == a && b != a) { cout << "Yes" << "\n"; } else { cout << "No" << "\n"; } }
1
#include<iostream> #include<algorithm> #include<numeric> #include<map> #include<set> int const MAXN = 2e5; int a[MAXN], b[MAXN], N, k; int c[MAXN-1], d[MAXN+MAXN-2]; int rank[MAXN+MAXN-1]; int tmp[MAXN+MAXN-1]; int sa[MAXN+MAXN-1]; bool comp_sa(int i, int j) { if(rank[i]!=rank[j]) return rank[i] < rank[j]; int ri = i+k <= N+N-2? rank[i+k]: -1; int rj = j+k <= N+N-2? rank[j+k]: -1; return ri < rj; } int main() { std::cin >> N; for(int i = 0; i < N; ++i) std::cin >> a[i]; for(int i = 0; i < N; ++i) std::cin >> b[i]; for(int i = 0; i < N-1; ++i) c[i] = a[i]^a[i+1]; for(int i = 0; i < 2*N-2; ++i) d[i] = b[i%N]^b[(i+1)%N]; std::set<int> ans; // SA std::copy_n(d, 2*N-2, rank); rank[2*N-2] = -1; std::iota(sa, sa+2*N-1, 0); for(k = 1; k <= 2*N-2; k += k) { std::sort(sa, sa+2*N-1, comp_sa); tmp[sa[0]] = 0; for(int i = 1; i <= 2*N-2; ++i) { tmp[sa[i]] = tmp[sa[i-1]] + (comp_sa(sa[i-1], sa[i])? 1: 0); } std::copy_n(tmp, 2*N-1, rank); } int lb = std::partition_point(sa, sa+2*N-1, [&](int i) { // d[i, 2*N-2) < c[0, N-1) for(int j = 0; j+i < 2*N-2 && j < N-1; ++j) { if(d[j+i] != c[j]) return d[j+i] < c[j]; } return 2*N-2-i < N-1; }) - sa; int ub = std::partition_point(sa, sa+2*N-1, [&](int i) { // d[i, 2*N-2) < c[0, N-1) or d[i, i+N-1) == c[0, N-1) for(int j = 0; j+i < 2*N-2 && j < N-1; ++j) { if(d[j+i] != c[j]) return d[j+i] < c[j]; } return true; }) - sa; for(int i = lb; i < ub; ++i) { ans.insert((N-sa[i])%N); } // ans for(auto k: ans) { int x = a[0]^b[(N-k)%N]; std::cout << k << " " << x << std::endl; } return 0; }
#include <bits/stdc++.h> using namespace std; inline char Get(){ static char ch; ch = getchar(); while (ch != '\n' && ch != '0' && ch != '1' && ch != '?') ch = getchar(); if (ch == '\n') return '*'; return ch; } const int P = 1e9 + 7; inline void upd(int &x,int v){ x = (x+v>=P)?(x+v-P):(x+v); } int f[9],g[9],nxt[9][2]; inline int getnxt(int s,int v){ int cnt1 = s / 3,cnt0 = s % 3; if (v == 1){ if (!cnt0) cnt1 = min(2,cnt1+1); else --cnt0; } else{ if (cnt0 == 2) cnt0 = 0; ++cnt0; } return cnt1 * 3 + cnt0; } inline void DP(char c){ int i; for (i = 0; i < 9; ++i) g[i] = f[i],f[i] = 0; for (i = 0; i < 9; ++i) if (g[i]){ if (c != '1') upd(f[nxt[i][0]],g[i]); if (c != '0') upd(f[nxt[i][1]],g[i]); } } int main(){ int i,j; for (i = 0; i < 9; ++i) for (j = 0; j < 2; ++j) nxt[i][j] = getnxt(i,j); f[0] = 1; char c; while ((c=Get())!='*') DP(c); int ans = 0; for (i = 0; i < 9; ++i) if (i / 3 >= i % 3) upd(ans,f[i]); cout << ans << '\n'; return 0; }
0
#include <iostream> #include <math.h> #include <string> using namespace std; int main() { long long n; cin >> n; int l; long stocks = 1000; for (long long i = 1; i*i <= n; i++) { if (n % i != 0) continue; l = log10(n/i) + 1; if (l < stocks) stocks = l; } cout << stocks << endl; }
#include <algorithm> #include <cstdlib> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long LL; int main() { int R; cin >> R; if (R < 1200) cout << "ABC" << endl; else if (R < 2800) cout << "ARC" << endl; else cout << "AGC" << endl; }
0
#include <set> #include <cstdio> using namespace std; char s[1000000 + 10]; int cnt[3]; char m[128]; int main(){ scanf("%s", s); m['J'] = 0; m['O'] = 1; m['I'] = 2; int k = 0; for(char *c = s; *c; c++){ int i = m[*c]; if(i == 0 && cnt[1] + cnt[2]) cnt[0] = cnt[1] = cnt[2] = 0; if(i == 1 && cnt[2]) cnt[0] = cnt[1] = cnt[2] = 0; cnt[i]++; if(i == 2 && cnt[0] >= cnt[1] && cnt[2] >= cnt[1]) k = max(k, cnt[1]); } printf("%d\n", k); return 0; }
#include<iostream> #include<string> using namespace std; int conv(char r) { if(r=='I') return 1; if(r=='V') return 5; if(r=='X') return 10; if(r=='L') return 50; if(r=='C') return 100; if(r=='D') return 500; if(r=='M') return 1000; else return 0; } int main() { string in; while(cin>>in) { int ans=0; for(int i = 1; i < in.size(); ++i) { int right=conv(in[i]); int left=conv(in[i-1]); if(!right||!left) continue; if(left<right) { ans+=right-left; in[i]=in[i-1]='0'; } } for(int i = 0; i < in.size(); ++i) { ans+=conv(in[i]); } cout<<ans<<endl; } return 0; }
0
#include<bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second typedef pair<int, int> ii; typedef pair<long long, int> li; typedef pair<long long, pair<int, int> > lii; const int N = 2e5 + 5; const long long inf = 1e18 + 123; int n, a[N], d; long long ans; vector<ii> vec; vector<lii> edge; struct Bit1 { vector<li> node; Bit1 (int sz = 0) { node.assign(sz + 5, li(inf, 0) ); } void update (int pos, li val) { for (; pos < (int)node.size(); pos += pos & -pos) node[pos] = min(node[pos], val); } li get (int pos) { li ret = li(inf, 0); for (; pos > 0; pos -= pos & -pos) ret = min(ret, node[pos]); return ret; } }; struct Bit2 { vector<li> node; Bit2 (int sz = 0) { node.assign(sz + 5, li(inf, 0) ); } void update (int pos, li val) { pos = (int)node.size() - pos; for (; pos < (int)node.size(); pos += pos & -pos) node[pos] = min(node[pos], val); } li get (int pos) { pos = (int)node.size() - pos; li ret = li(inf, 0); for (; pos > 0; pos -= pos & -pos) ret = min(ret, node[pos]); return ret; } }; struct Dsu { vector<int> pSet, szSet; Dsu (int _n = 0) { pSet.assign(_n + 5, 0); for (int i = 0; i < (int)pSet.size(); ++i) pSet[i] = i; szSet.assign(_n + 5, 1); } int findSet (int i) { return i == pSet[i] ? i : pSet[i] = findSet(pSet[i]); } bool unionSet (int i, int j) { i = findSet(i); j = findSet(j); if (i == j) return false; if (szSet[i] > szSet[j]) swap(i, j); szSet[j] += szSet[i]; pSet[i] = j; return true; } }; long long cost (int i, int j) { return 1LL * abs(i - j) * d + a[i] + a[j]; } int main () { scanf("%d %d", &n, &d); for (int i = 1; i <= n; ++i) { scanf("%d", a + i); vec.pb(ii(a[i], i) ); } sort(vec.begin(), vec.end() ); Bit1 bit1(n); Bit2 bit2(n); for (auto _ : vec) { int i = _.se; li tmp1 = bit1.get(i), tmp2 = bit2.get(i); if (tmp1.se) edge.pb(lii(cost(tmp1.se, i), ii(tmp1.se, i) ) ); if (tmp2.se) edge.pb(lii(cost(tmp2.se, i), ii(tmp2.se, i) ) ); bit1.update(i, li(a[i] - 1LL * i * d, i) ); bit2.update(i, li(a[i] + 1LL * i * d, i) ); } sort(edge.begin(), edge.end() ); Dsu dsu(n); for (auto _ : edge) { if (dsu.unionSet(_.se.fi, _.se.se) ) ans += _.fi; } cout << ans; return 0; }
#include<bits/stdc++.h> 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 Would #define you #define please //世界の皆は頭ええな int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, D; cin >> N >> D; ll kotae = (N - 1) * D; ll A[200001], C[200001]; C[0] = 1e18; rep1(i, N) { cin >> A[i]; kotae += A[i]; C[i] = min(C[i - 1] + D, A[i]); } ll mae = 1e18; for (int i = N - 1; i > 1; i--) { mae = min(mae + D, A[i + 1]); ll kari = min(mae, C[i - 1]) + D; kotae += min(A[i], kari); } co(kotae); Would you please return 0; }
1
#include <bits/stdc++.h> #include <vector> #include <iostream> #include<algorithm> #include<string> #include <map> #include <queue> #include <stack> #include<set> #include<tuple> #define DIV 1000000007 using namespace std; using ll = long long; using ldb = long double; int main() { ll N; cin >> N; vector<pair<ll,ll>> ran(N); vector<ll> u(2), v(2,1e10); for (int i = 0; i < N; i++) { cin >> ran[i].first >> ran[i].second; if (u[0] < ran[i].first) { swap(u[0], u[1]); u[0] = ran[i].first; } else if (u[1] < ran[i].first)u[1] = ran[i].first; if (v[0] > ran[i].second) { swap(v[0], v[1]); v[0] = ran[i].second; } else if (v[1] > ran[i].second)v[1] = ran[i].second; } sort(ran.begin(), ran.end()); vector<pair<ll, ll>> left(N); left[0] = ran[0]; for (int i = 1; i < N; i++) { left[i].first = ran[i].first; left[i].second = min(left[i - 1].second, ran[i].second); } vector<pair<ll, ll>> right(N); right[N - 1] = ran[N - 1]; for (int i = N - 2; i >= 0; i--) { right[i].first = right[i + 1].first; right[i].second = min(right[i + 1].second, ran[i].second); } ll ans = 0; for (int i = 0; i < N - 1; i++) { ll temp = max((ll)0, left[i].second - left[i].first + 1); temp += max((ll)0, right[i + 1].second - right[i + 1].first + 1); ans = max(ans, temp); //cout << "i=" << i << " temp=" << temp << endl; } if (u[0] < u[1])swap(u[0], u[1]); //cout << "u[0]=" << u[0] << " u[1]=" << u[1] << endl; if (v[0] > v[1])swap(v[0], v[1]); //cout << "v[0]=" << v[0] << " v[1]=" << v[1] << endl; for (int i = 0; i < N; i++) { ll p = (ran[i].first != u[0] ? u[0] : u[1]), q = (ran[i].second != v[0] ? v[0] : v[1]); ans = max(ans, max((ll)0, q - p + 1) + ran[i].second - ran[i].first + 1); //cout << "i=" << i << " ans=" << ans ; //cout << " p=" << p << " q=" << q << endl; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define ok() puts(ok?"Yes":"No"); #define chmax(x,y) x = max(x,y) #define chmin(x,y) x = min(x,y) using namespace std; using ll = long long; using vi = vector<int>; using ii = pair<int, int>; using vvi = vector<vi>; using vii = vector<ii>; using gt = greater<int>; using minq = priority_queue<int, vector<int>, gt>; using P = pair<ll,ll>; const ll LINF = 1e18L + 1; const int INF = 1e9 + 1; //clang++ -std=c++11 -stdlib=libc++ vi to[100005]; // abc148 f vi dist; int n; void dfs(int v, int d=0, int p=-1) { dist[v] = d; for (int u: to[v]) { if (u == p) continue; dfs(u,d+1,v); } } vi getDist(int v) { dist = vi(n); dfs(v); return dist; } int main() { int t, a; cin >> n >> t >> a; t--; a--; rep(i,n-1) { int a,b; cin >> a >> b; a--; b--; to[a].push_back(b); to[b].push_back(a); } vi distA = getDist(a); vi distT = getDist(t); int ans=0; rep(i,n) { if (distA[i] > distT[i]) { chmax(ans, distA[i]); } } ans--; cout << ans << endl; return 0; }
0
#include<bits/stdc++.h> using namespace std; int psum[505][505]; int main(){ int n,m,q; cin>>n>>m>>q; while(m--){ int l,r; cin>>l>>r; psum[r][l]++; } for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++) psum[i][j]+=psum[i][j-1]; } for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++) psum[i][j]+=psum[i-1][j]; } while(q--){ int l,r; cin>>l>>r; cout<<psum[r][n]-psum[r][l-1]<<'\n'; } }
#include <iostream> #include <algorithm> #include <cassert> #include <cctype> #include <cstdio> #include <math.h> #include <map> #include <queue> #include <string> using namespace std; typedef long long ll; int n,N; ll s[4000][2],a,b; string d; int main(){ while(cin>>N){ if(N==0)return 0; for(int i=0;i<4000;i++){ for(int j=0;j<2;j++){ s[i][j]=0; } } int m=0; for(int i=0;i<N;i++){ cin>>n>>a>>b; int flag=0; for(int j=0;j<m;j++)if(s[j][0]==n){s[j][1]+=a*b;flag=1;} if(flag==0){s[m][0]=n;s[m][1]=a*b;m++;} } int flag2=0; for(int i=0;i<m;i++)if(s[i][1]>999999){cout<<s[i][0]<<endl;flag2=1;} if(flag2==0)cout<<"NA"<<endl; } }
0
#include <bits/stdc++.h> using namespace std; int main() { int N,A,B; cin>>N>>A>>B; if(N==1) cout<<"Hello World"<<endl; else cout<<A+B<<endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) #define COUT(x) cout<<(x)<<endl #define dump(x) cout<<#x<<" = "<<(x)<<endl; #define Yes(x) cout<<(x?"Yes":"No")<<endl; using ll = long long; using P = pair<int,int>; using Graph = vector<vector<int>>; using M = map<int,int>; using PQ = priority_queue<int>; using PQG = priority_queue<int, vector<int>, greater<int>>; const int INF = 1e9; const int MOD = 1e9+7; const ll LINF = 1e18; int main() { int n,a,b; cin >> n; if (n == 2) { int a,b; cin>>a>>b; COUT(a+b); } else COUT("Hello World"); return 0; }
1
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <cassert> #include <iostream> #include <cctype> #include <sstream> #include <string> #include <list> #include <vector> #include <queue> #include <set> #include <stack> #include <map> #include <utility> #include <numeric> #include <algorithm> #include <iterator> #include <bitset> #include <complex> #include <fstream> using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<int> vint; typedef pair<int, int> pint; #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define MSG(a) cout << #a << " " << a << endl; #define REP(i, x, n) for(int i = x; i < n; i++) template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); } template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; } template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; } template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); } bool f(int a, int b, int c) { if(a == 2 && b == 1 && c == 1) return true; if(a == 1 && b == 2 && c == 1) return true; if(a == 1 && b == 1 && c == 2) return true; return false; } int main() { for(int a, b, c; cin >> a >> b >> c && (a || b || c); ) { vint S(a+b+c, 2); int N; cin >> N; vector<pair<pint, pint> > tests(N); rep(i, N) { cin >> tests[i].first.first >> tests[i].first.second; cin >> tests[i].second.first >> tests[i].second.second; if(tests[i].second.second == 1) { S[tests[i].first.first-1] = 1; S[tests[i].first.second-1] = 1; S[tests[i].second.first-1] = 1; } } rep(i, N) { if(f(S[tests[i].first.first-1], S[tests[i].first.second-1], S[tests[i].second.first-1])) { if(S[tests[i].first.first-1] == 2) S[tests[i].first.first-1] = 0; if(S[tests[i].first.second-1] == 2) S[tests[i].first.second-1] = 0; if(S[tests[i].second.first-1] == 2) S[tests[i].second.first-1] = 0; } } rep(i, a+b+c) cout << S[i] << endl; } }
#include<iostream> #include<cstdio> using namespace std; int main(){ int a,b,c; while(cin>>a>>b>>c,a||b||c){ int n,parts[500],input[10000][4],bd; for(int i=0;i<500;i++) parts[i]=2; cin>>n; for(int _i=0;_i<n;_i++){ for(int _j=0;_j<4;_j++){ cin>>input[_i][_j]; } if(input[_i][3]==1){ for(int i=0;i<3;i++){ parts[input[_i][i]]=1; } } for(int i=0;i<=_i;i++){ if(input[i][3]==1) continue; bd=-1; for(int j=0;j<3;j++){ if(parts[input[i][j]]==2 && bd==-1) bd=input[i][j]; else if(parts[input[i][j]]!=1){ bd=-1; break; } } if(bd!=-1) parts[bd]=0; } } for(int i=1;i<=a+b+c;i++){ printf("%d\n",parts[i]); } } return 0; }
1
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) using ll = long long; using ld = long double; ll INF = LLONG_MAX; using vi = vector<int>; using vll = vector<ll>; using pii = pair<int, int>; namespace output { void pr(int x) { cout << x; } void pr(long x) { cout << x; } void pr(ll x) { cout << x; } void pr(unsigned x) { cout << x; } void pr(unsigned long x) { cout << x; } void pr(unsigned long long x) { cout << x; } void pr(float x) { cout << x; } void pr(double x) { cout << x; } void pr(ld x) { cout << x; } void pr(char x) { cout << x; } void pr(const char* x) { cout << x; } void pr(const string& x) { cout << x; } void pr(bool x) { pr(x ? "true" : "false"); } template<class T> void pr(const complex<T>& x) { cout << x; } template<class T1, class T2> void pr(const pair<T1,T2>& x); template<class T> void pr(const T& x); template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { pr(t); pr(ts...); } template<class T1, class T2> void pr(const pair<T1,T2>& x) { pr("{",x.f,", ",x.s,"}"); } template<class T> void pr(const T& x) { pr("{"); // const iterator needed for vector<bool> bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; pr("}"); } void print() { pr("\n"); } // print w/ spaces template<class T, class... Ts> void print(const T& t, const Ts&... ts) { pr(t); if (sizeof...(ts)) pr(" "); print(ts...); } } using namespace output; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int N, M; cin >> N >> M; if (N&1) { FOR(i, 1, M+1) print(i, N-i+1); } else { int even_pos = 1; int odd_pos = N/2+1; for (int s = M; s >= 1; --s) { if (s&1) { print(odd_pos, odd_pos + s); ++odd_pos; } else { print(even_pos, even_pos + s); ++even_pos; } } } }
#include <iostream> #include <stdio.h> #include <cstring> #include <cstdio> #include <math.h> #include <algorithm> #include <vector> #include <string> #include <stdlib.h> #include <queue> #include <stack> #include <utility> #include <fstream> #include <random> #include <map> #include <unordered_map> #include <cstdlib> #include <functional> #include <random> #include <time.h> #include <chrono> #include <sstream> #include <iomanip> #include <numeric> #include <iostream> #include <limits> #include <numeric> #include <type_traits> #define rep(i,n) for(int i=0;i<n;i++) #define rrep(i,n) for(int i=n-1;i>=0;i--) #define FOR(i,a,b) for(int i=a;i<b;i++) #define ll long long #define INF 1000000001 #define MOD 1000000007 #define SORT(s) sort(s.begin(), s.end()); #define REVERSE(s) reverse(s.begin(), s.end()); #define SUM(s) accumulate(s.begin(), s.end(), 0LL); #define P pair<int,int> #define mp make_pair #define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w) //#define int ll int dx[4] = { 0,1,0,-1 }; int dy[4] = { 1,0,-1,0 }; int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 }; int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 }; using namespace std; int POW(int x, int y) { return int(pow(double(x), double(y))); } double log(double a, double b) { return log(b) / log(a); } int main() { int n, m; cin >> n >> m; vector<int> v(n+1); int u1 = 1+m; int d1 = 1; int u2= n; int d2 = n - m + 1; int c = 0; while (u1 > d1 && c < m) { cout << d1 << " " << u1 << endl; d1++; u1--; c++; } while (u2 > d2 && c < m) { cout << d2 << " " << u2 << endl; d2++; u2--; c++; } }
1
#include<bits/stdc++.h> using namespace std; int main(){ long long a,b,k; cin>>a>>b>>k; while(k){ if(a%2==1)a--; a/=2; b+=a; k--; if(k==0)break; if(b%2==1)b--; b/=2; a+=b; k--; if(k==0)break; } cout<<a<<" "<<b<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll MOD = 1000000007; ll INF = 100000000; double PI = 3.1415926535; template<typename T> void remove(std::vector<T>& vector, unsigned int index) { vector.erase(vector.begin() + index); } using Graph = vector<vector<pair<ll,ll>>>; int main(){ int N,H,W; cin >> N >> H >> W; cout << max(0,(N-H+1)*(N-W+1)) << endl; }
0
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> #include <set> #include <map> #include <vector> #include <queue> #define LL long long #define N 55555 #define maxn 10005 #define INF 0x3f3f3f3f #define mase(a,b) memset(a,b,sizeof(a)) #define MIN(a,b) (a<b?a:b) #define MAX(a,b) (a>b?a:b) #define DS DisputeSegement using namespace std; bool isPrime(int fig) { int limit=(int)sqrt(fig)+1; for(int i=2;i<limit;i++) { if(fig%i==0) { return false; } } return true; } int main() { int n; scanf("%d",&n); for(int i=11;i<=N;i+=10) { if(isPrime(i)) { printf("%d",i); n--; printf("%c",n?' ':'\n'); if(!n) { break; } } } return 0; } //Five,Five Everywhere,原创者CSDN@
#define scanf_s scanf #include <stdio.h> #include <string> #include <iostream> using namespace std; #define MAX 20 int main(void) { int i; char str[MAX + 1]; scanf_s("%s", str, MAX); for (i = 0; str[i + 1] != '\0'; ++i); for (; i >= 0;--i){ printf("%c", str[i]); } printf("\n"); }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll INF = 1e16; const ll mod = 1000000007; #define rep(i, n) for (int i = 0; i < (ll)(n); i++) int main() { ll n; cin >> n; if (n-1) { ll a, b; cin >> a >> b; cout << a + b << endl; } else { cout << "Hello World" << endl; } }
#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++) int main() { string S; cin>>S; int w; cin>>w; int a=S.size(); if(w!=1){ for(int i=1; i<a+1; i++){ if(i%w==1){ cout<<S[i-1]; } } } else{ rep(i,S.size()){ cout<<S[i]; } } cout<<""<<endl; }
0
#include <iostream> #include <iomanip> #include <algorithm> #include <complex> #include <utility> #include <vector> #include <string> #include <stack> #include <queue> #include <tuple> #include <cmath> #include <bitset> #include <cctype> #include <set> #include <map> #include <unordered_map> #include <numeric> #include <functional> #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define all(x) (x).begin(),(x).end() #define PRINT(V) cout << V << "\n" #define SORT(V) sort((V).begin(),(V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) using namespace std; using ll = long long; 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; } inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); } template<class itr> void cins(itr first,itr last){ for (auto i = first;i != last;i++){ cin >> (*i); } } template<class itr> void array_output(itr start,itr goal){ string ans = "",k = " "; for (auto i = start;i != goal;i++) ans += to_string(*i)+k; if (!ans.empty()) ans.pop_back(); PRINT(ans); } ll gcd(ll a, ll b) { return a ? gcd(b%a,a) : b; } const ll INF = 1e9; const ll MOD = 1000000007; const ll MOD2 = 998244353; typedef pair<ll,ll> P; typedef pair<double,double> point; const ll MAX = 200005; constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1}; constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1}; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n,m; cin >> n >> m; if (n%2){ ll l = 1,r = n; rep(i,m){ printf("%lld %lld\n",l,r); l++; r--; } } else{ ll k = n/2; ll l = 1,r = n; rep(i,min(k/2,m)){ printf("%lld %lld\n",l,r); l++; r--; } r--; rep(i,m-k/2){ printf("%lld %lld\n",l,r); l++; r--; } } }
#include<cstdio> #include<algorithm> using namespace std; int main(){ int n,rank[100]; pair<int,int> point[100]; scanf("%d",&n); for(int i=0;i<n;i++){ point[i].first = 0; point[i].second = i; } for(int i=0;i<n*(n-1)/2;i++){ int a,b,c,d; scanf("%d %d %d %d",&a,&b,&c,&d); if(c<d){ point[b-1].first += 3; }else if(c>d){ point[a-1].first += 3; }else{ point[a-1].first += 1; point[b-1].first += 1; } } sort(point,point+n); reverse(point,point+n); int r; for(int i=0;i<n;i++){ int team = point[i].second; if(i>0&&point[i].first==point[i-1].first){ rank[team] = r; }else{ r = i+1; rank[team] = r; } } for(int i=0;i<n;i++) printf("%d\n",rank[i]); return 0; }
0
#include<bits/stdc++.h> //#include<atcoder/all> using namespace std; using ll = long long; string s; void dfs(string op,int now,int i) { if(i==4) { if(now==7) { for(int i =0 ;i<3;i++)cout<<s[i]<<op[i+1]; cout<<s.back(); cout<<"=7"<<endl; exit(0); } return; } dfs(op+'+',now+s[i]-'0',i+1); if(i)dfs(op+'-',now-s[i]+'0',i+1); } int main() { cin >> s; dfs("",0,0); }
#include<bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; int a[4], ans, k; for (int i = 3; i >= 0; i--) { a[i] = n % 10; n = n / 10; } string op; for (int i = 0; i < 8; i++) { ans = a[0]; k = 1; for (int j = 2; j >= 0; j--) { if (i & (1 << j)) { op += "-"; ans -= a[k++]; } else { op += "+"; ans += a[k++]; } } if (ans == 7) { break; } else { op = ""; } } string r = to_string(a[0]); k = 1; for (int i = 0; i < 3; i++) r += op[i] + to_string(a[k++]); r += "=7"; cout << r << endl; }
1
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); i++) using namespace std; int main() { cin.tie(0)->sync_with_stdio(false); int n; cin >> n; string s, t; cin >> s >> t; int index = -1; REP(i, n) { if (s.substr(i, n - i) == t.substr(0, n - i)) { index = i; break ; } } if (index == -1) cout << s.size() + t.size() << '\n'; else cout << n + index << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<int>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define pii pair<int,int> const long long MOD=1000000007; int main(){ int n,m,x,y; cin>>n>>m>>x>>y; int xmax=x,ymin=y; rep(i,n){ int x0; cin>>x0; xmax=max(xmax,x0); } rep(i,m){ int y0; cin>>y0; ymin=min(ymin,y0); } if(xmax<ymin) cout<<"No War"<<endl; else cout<<"War"<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define all(x) (x).begin(),(x).end() #define YES() printf("YES\n") #define NO() printf("NO\n") #define Yes() printf("Yes\n") #define No() printf("No\n") #define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w #define int long long //using ll = long long; using P = pair<int,int>; template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } const int INF=1e+9; const double EPS=1e-9; const int MOD=1000000007; const int dx[]={1,0,-1,0},dy[]={0,-1,0,1}; signed main(){ int n,q; string s; cin >> n >> s >> q; for(int i = 0;i < q;i++){ int k,ans = 0,d = 0,m = 0,c = 0,dm = 0,mc = 0; cin >> k; for(int j = 0;j < n;j++){ if(j >= k){ if(s[j - k] == 'D'){ d--; dm -= m; } else if(s[j - k] == 'M'){ m--; mc -= c; } else if(s[j - k] == 'C'){ c--; } } if(s[j] == 'D'){ d++; } else if(s[j] == 'M'){ m++; dm += d; } else if(s[j] == 'C'){ c++; mc += m; ans += dm; } } cout << ans << endl; } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pb push_back #define fi first #define se second const ll mod = 1e9+7; const int N = 2e5+6; int bit[55][55]; void add(int x, int y){ for(int i=x;i>0;i-=(i&-i)){ for(int j=y;j>0;j-=(j&-j)){ bit[i][j]++; } } } ll get(int x, int y){ ll ret =0; for(int i=x;i<55;i+=(i&-i)){ for(int j=y;j<55;j+=(j&-j)){ ret+=bit[i][j]; } } return ret; } ll get2(ll x){ ll ret = 1; while(x%2==0){ ret++; x/=2; } return ret; } ll get5(ll x){ ll ret = 1; while(x%5==0){ ret++; x/=5; } return ret; } void solve(){ int n; cin>>n; ll ans = 0; for(int i=1;i<=n;i++){ ld inp; cin>>inp; ll trt = llround(inp*1e9); ll x = get2(trt); ll y = get5(trt); ll xp = max(1ll,20-x); ll yp = max(1ll,20-y); ans+=get(xp,yp); add(x,y); } cout<<ans<<endl; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); } return 0; }
0
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG_MODE #define DBG(n) n; #else #define DBG(n) ; #endif #define REP(i,n) for(ll (i) = (0);(i) < (n);++i) #define PB push_back #define MP make_pair #define FI first #define SE second #define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;} #define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;} #define ALL(v) v.begin(),v.end() #define Decimal fixed<<setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL #define MOD 1000000007 typedef long long ll; typedef pair<ll,ll> P; ll mp[555][555]; int dx[] = {1,0,-1,0}; int dy[] = {0,-1,0,1}; vector<ll> v; ll gcd(ll a,ll b){ if(a < b)swap(a,b); return b == 0 ? a : gcd(b,a%b); } void prime(){ vector<bool> pri(100000); vector<ll> tmp; int cou = 0; for(int i = 2;;i++){ if(!pri[i]){ tmp.PB(i); for(int j = i;j < 100000;j+=i)pri[j] = true; cou++; } if(cou == 1010)break; } for(int i = 0,j = tmp.size() - 1;i < j;i++,j--){ v.PB(tmp[i]); v.PB(tmp[j]); } } void seica(){ REP(i,555)REP(j,555)mp[i][j] = 1; REP(i,500){ REP(j,500){ if((i+j) % 2 == 0){ mp[i][j] *= v[(i+j)/2]; } if((i+499-j) % 2 == 1){ mp[i][j] *= v[501+(i+499-j)/2]; } } } REP(i,500){ REP(j,500){ if((i + j) % 2){ ll now = 1; REP(k,4){ if(i+dy[k] >= 0 && i+dy[k] < 500 && j+dx[k] >= 0 && j+dx[k] < 500){ ll hoge = gcd(now, mp[i+dy[k]][j+dx[k]]); now *= mp[i+dy[k]][j+dx[k]] / hoge; } } mp[i][j] = now + 1; } } } } int main(){ int n;cin >> n; prime(); //cout << v.size() << endl; seica(); REP(i,n){ REP(j,n){ cout << mp[i][j] << " "; } cout << endl; } return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <queue> #include <bitset> #include <stack> #include <functional> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif #define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i) #define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i) #define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i) #define all(x) (x).begin(), (x).end() template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair <ll,ll> P; typedef long double ld; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; if (n <= 2) { cout << "-1\n"; } else if (n % 3 == 0) { rep (i, n) { rep (j, n) { if (i / 3 == j / 3 && ((i % 3 == 0) ^ (j % 3 == 0))) cout << 'a'; else cout << '.'; } cout << "\n"; } } else if (n == 7) { cout << "abb...a\n" << "a.a...a\n" << "bba...c\n" << "...abbc\n" << "...a.ab\n" << "...bbab\n" << "bbaacc.\n"; } else if (n == 11) { cout << "bccaabbccaa\n" << "babb...abbc\n" << "ca.a...a.ac\n" << "cbba...bbab\n" << "baccbcc...b\n" << "ba.ab.b...a\n" << "accaccb...a\n" << "a...baacaab\n" << "b...b.bc.cb\n" << "b...aabaaca\n" << "ccaabbccbba\n"; } else { int a, b; for (int i = n / 5; i >= 0; i--) { if ((n - 5 * i) % 4 == 0) { a = i; b = (n - 5 * i) / 4; break; } } // eprintf("a=%d, b=%d\n", a, b); vector<string> s4 = {"aaca", "bbca", "acbb", "acaa"}, s5 = {"aacca", "c.bba", "cb..c", "ab..c", "accaa"}; rep (i, n) { rep (j, n) { if (i / 5 == j / 5 && i / 5 < a) { // cout << 1; cout << s5[i % 5][j % 5]; } else if ((i - 5 * a) / 4 == (j - 5 * a) / 4 && i - 5 * a >= 0 && j - 5 * a >= 0) { // cout << 2; cout << s4[(i - 5 * a) % 4][(j - 5 * a) % 4]; } else { // cout << 3; cout << '.'; } } cout << "\n"; } } return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; #define MOD 1000000007LL #define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++) #define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++) #define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++) #define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++) #define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--) #define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--) #define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--) #define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--) #define iter(i, it) for(auto &(i): (it)) template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) { cout << "(" << m.first << ", " << m.second << ")"; return s; } template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) { ll c = 0; cout << "{ "; iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", "); cout << "}"; return s; } template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) { cout << "{ "; rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", "); cout << "}"; return s; } template<typename T> ostream& operator<<(ostream &s, const list<T> &v) { ll c = 0; cout << "{ "; iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", "); cout << "}"; return s; } int main(void) { vector<ll> A(3); cin >> A[0] >> A[1] >> A[2]; sort(A.begin(), A.end()); ll K; cin >> K; rep(i, K) A.back() *= 2; cout << accumulate(A.begin(), A.end(), 0LL) << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++) #define repr(i, n) for (ll i = n; i >= 0; i--) #define pb push_back #define COUT(x) cout << (x) << endl #define COUTF(x) cout << setprecision(15) << (x) << endl #define ENDL cout << endl #define DF(x) x.erase(x.begin()) // 先頭文字削除 #define ALL(x) x.begin(), x.end() #define SORT(x) sort(ALL(x)) #define REVERSE(x) reverse(ALL(x)) #define init() \ cin.tie(0); \ ios::sync_with_stdio(false) #define debug(x) cerr << "[debug] " << #x << ": " << x << endl; #define debugV(v) \ cerr << "[debugV] " << #v << ":"; \ rep(i, v.size()) cerr << " " << v[i]; \ cerr << endl; using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using P = pair<ll, ll>; constexpr ll INF = 0x3f3f3f3f3f3f3f3f; constexpr ld PI = 3.141592653589793238462643383279; ll get_digit(ll x) { return to_string(x).size(); } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } vector<P> factorize(ll n) { vector<P> result; for (ll i = 2; i * i <= n; ++i) { if (n % i == 0) { result.pb({i, 0}); while (n % i == 0) { n /= i; result.back().second++; } } } if (n != 1) { result.pb({n, 1}); } return result; } vll divisor(ll n) { vll ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } SORT(ret); return (ret); } 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; } signed main() { init(); ll A, B, C; cin >> A >> B >> C; ll K; cin >> K; ll m1 = max(max(A, B), C); ll m2 = max(max(A, B), C); rep(i, K) { m1 *= 2; } ll ans = A + B + C - m2 + m1; COUT(ans); return 0; }
1
#include <bits/stdc++.h> using namespace std; using ll=long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; #define all(x) x.begin(),x.end() #define rep(i,j,n) for (long long i = j; i < (long long)(n); i++) #define _GLIBCXX_DEBUG #define MOD 1000000007 template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } //name[i][j]-> vvl name(i,vl(j)) //map<int,int>mp //余りを切り上げる => (a + b - 1) / b signed main(){ vi v(3); rep(i,0,3)cin>>v[i]; sort(all(v)); cout<<(v[0]+v[1])<<endl; return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } int ans = 0; for (int i = 1; i < N; i++) { int d = A[i - 1] - A[i]; if (d > 0) { ans += d; A[i] = A[i - 1]; } } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; int r; int x; cin >> n; cin >> r; x = 100*(10-n)+r; if (n >= 10) { cout << r; } else { cout << x; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define show(x) {for(auto i: x){cout << i << " ";} cout << endl;} using namespace std; using ll = long long; using P = pair<int, int>; int main() { int N, R; cin >> N >> R; if (N < 10) { R += 100 * (10 - N); } cout << R << '\n'; return 0; }
1
#include <stdio.h> #include <algorithm> #include <iostream> #include <vector> #include <assert.h> #include <map> #include <set> #include <unordered_set> #include <unordered_map> #include <math.h> #include <string> #include <string.h> #include <queue> #include <complex> #include <iomanip> #include <stack> using namespace std; typedef long long int ll; typedef unsigned long long int ull; ll mod=1e9+7; double eps=1e-7; ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;} ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;} ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);} ll lcm(ll x,ll y){return x*(y/gcd(x,y));} ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;} ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;} ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;} ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;} ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;} ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;} ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;} ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;} ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;} ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;} ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;} bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;} ll n, k, T, x, y, cnt; ll vv[55]; int main(void) { cin>>k; n=50; T=k/n; ll i; x=T+2*n-k%n; y=x-n-1; for(i=1 ; i<=k%n ; i++) vv[i]=x; for(i=k%n+1 ; i<=n ; i++) vv[i]=y; cout<<n<<"\n"; for(i=1 ; i<=n ; i++) cout<<vv[i]<<" "; return 0; } // 제출하기 전에 생각햇나요? // it may be easier/harder than you think // ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#include <bits/stdc++.h> using namespace std; int main() { string S, target = "FESTIVAL"; cin >> S; S.replace(S.length()-target.length(),S.length(),""); cout << S << endl; return 0; }
0
#include <iostream> using namespace std; int main() { int month, day; cin >> month >> day; while (month != 0 && day != 0) { if (month >= 1) day = day; if (month >= 2) day = day + 31; if (month >= 3) day = day + 29; if (month >= 4) day = day + 31; if (month >= 5) day = day + 30; if (month >= 6) day = day + 31; if (month >= 7) day = day + 30; if (month >= 8) day = day + 31; if (month >= 9) day = day + 31; if (month >= 10) day = day + 30; if (month >= 11) day = day + 31; if (month >= 12) day = day + 30; if (day % 7 == 0) cout << "Wednesday" << endl; if (day % 7 == 1) cout << "Thursday" << endl; if (day % 7 == 2) cout << "Friday" << endl; if (day % 7 == 3) cout << "Saturday" << endl; if (day % 7 == 4) cout << "Sunday" << endl; if (day % 7 == 5) cout << "Monday" << endl; if (day % 7 == 6) cout << "Tuesday" << endl; cin >> month >> day; } return 0; }
#include<bits/stdc++.h> using namespace std; #define debug(x) cout << (#x) << " is " << x << endl; #define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++) typedef long long int lli; typedef pair<int, int> pi; int main() { int has = 1, a, b, ans=0; cin >> a >> b; while(has < b){ has--; has += a; ans++; } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; const i64 MOD = 1e9 + 7; struct LowLink{ vector<vector<int>>& edges; // 関節点 vector<int> art; vector<pair<int,int>> bridge; vector<int> used, ord, low; int k; void dfs(int idx, int par){ ord[idx] = k++; low[idx] = ord[idx]; bool is_art = false; int cnt = 0; for(auto& to : edges[idx]){ if(ord[to] == -1){ ++cnt; dfs(to, idx); low[idx] = min(low[idx], low[to]); is_art |= par != -1 && low[to] >= ord[idx]; if(ord[idx] < low[to]) bridge.emplace_back(idx, to); }else if(to != par) low[idx] = min(low[idx], ord[to]); } is_art |= (par == -1 && cnt > 1); if(is_art) art.emplace_back(idx); } LowLink(vector<vector<int>>& edges) : edges(edges), ord(edges.size(), -1), low(edges.size(), 0), k(0) { for(int i = 0; i < edges.size(); ++i) if(ord[i] == -1) dfs(i, -1); for(auto& b : bridge) b = make_pair(min(b.first, b.second), max(b.first, b.second)); sort(art.begin(), art.end()); sort(bridge.begin(), bridge.end()); } }; signed main(){ int n, m; cin >> n >> m; vector<pair<int,int>> v(m); vector<vector<int>> edges(n); for(int i = 0; i < m; ++i){ vector<int> l(2); for(auto& x : l) cin >> x; sort(l.begin(), l.end()); v[i] = make_pair(l.front(), l.back()); edges[l[0]].emplace_back(l[1]); edges[l[1]].emplace_back(l[0]); } LowLink ll(edges); for(auto& x : ll.art) cout << x << endl; }
#include <vector> #include <iostream> #include <algorithm> #include <set> using namespace std; #define MAX 10000 vector<int> G[MAX]; int n; bool visited[MAX]; int treeIdx[MAX], parent[MAX], lowest[MAX], treeNodeCounter; void dfs(int curIdx, int prev) { treeIdx[curIdx] = lowest[curIdx] = treeNodeCounter; treeNodeCounter++; visited[curIdx] = true; int next; for (int i = 0; i < G[curIdx].size(); ++i) { next = G[curIdx][i]; if (!visited[next]) { parent[next] = curIdx; dfs(next, curIdx); lowest[curIdx] = min(lowest[curIdx], lowest[next]); } else if (next != prev) { lowest[curIdx] = min(lowest[curIdx], treeIdx[next]); } } } void criticalPoints() { for (int i = 0; i < n; ++i) visited[i] = false; treeNodeCounter = 1; dfs(0, -1); set<int> s; int np = 0; for (int i = 1; i < n; ++i) { int p = parent[i]; if (0 == p) np++; else if (treeIdx[p] <= lowest[i]) s.insert(p); } if (np > 1) cout << 0 << endl; for (auto v : s) cout << v << endl; } int main() { int m; cin >> n >> m; for (int i = 0; i < m; ++i) { int s, t; cin >> s >> t; G[s].push_back(t); G[t].push_back(s); } criticalPoints(); return 0; }
1
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define MOD 1000000007 using namespace std; int main() { string s; cin >> s; if(s.size() == 2) { cout << s << "\n"; } else { for(int i = s.size() - 1;i >= 0;i--) { cout << s[i]; } cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; if(s.length()==3) { reverse(s.begin(),s.end()); } cout << s << '\n'; return 0; }
1
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll Mod = 1000000007; bool exists(vector<ll>& vec,ll x) { auto pos = lower_bound(vec.begin(),vec.end(),x); if(pos == vec.end())return false; return *pos == x; } void solve(ll N, ll M, vector<ll> A, vector<ll> B) { ll ans = 1; sort(A.begin(),A.end()); sort(B.begin(),B.end()); ll empty = 0; ll numrow=0,numcol=0; for(ll x = M*N;x>=1;--x) { if(exists(A,x)) { if(exists(B,x)) { empty += numcol + numrow; numcol++; numrow++; }else { empty += numcol - 1; ans *= numcol; ans %= Mod; numrow++; } }else { if(exists(B,x)) { empty += numrow - 1; ans *= numrow; ans %= Mod; numcol++; }else { if(empty <= 0) { cout<<0<<endl; return; } ans *= empty; empty--; ans %= Mod; } } } cout<<ans<<endl; } int main() { ll N; cin >> N; ll M; cin >> M; vector<ll> A(N); for(int i = 0 ; i < N ; i++) { cin >> A[i]; } vector<ll> B(M); for(int i = 0 ; i < M ; i++) { cin >> B[i]; } solve(N, M, move(A), move(B)); return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> #define inf 0x3f3f3f3f #define MOD 1000000007 using namespace std; typedef long long ll; template <typename Tp> inline void getint(Tp &num){ register int ch, neg = 0; while(!isdigit(ch = getchar())) if(ch == '-') neg = 1; num = ch & 15; while(isdigit(ch = getchar())) num = num * 10 + (ch & 15); if(neg) num = -num; } int N, M, A[1005], B[1005]; ll ans = 1; int main(){ getint(N), getint(M); for(register int i = 1; i <= N; i++) getint(A[i]); for(register int i = 1; i <= M; i++) getint(B[i]); sort(A + 1, A + N + 1), sort(B + 1, B + M + 1), A[N + 1] = B[M + 1] = inf; for(register int i = 1; i < N; i++) if(A[i] == A[i + 1]) return puts("0"), 0; for(register int i = 1; i < M; i++) if(B[i] == B[i + 1]) return puts("0"), 0; for(register int i = 1, j = 1, k = 1; i <= N * M; i++){ while(j <= N && A[j] < i) j++; while(k <= M && B[k] < i) k++; if(A[j] == i && B[k] != i) ans = ans * (M - k + 1) % MOD; else if(A[j] != i && B[k] == i) ans = ans * (N - j + 1) % MOD; else if(A[j] != i && B[k] != i) ans = ans * ((M - k + 1) * (N - j + 1) - (N * M - i)) % MOD; } return printf("%lld\n", ans), 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int A; int B; cin>>A>>B; int i=0; int j=B-A; int sum=0; int C=A; while(i<=j){ A=C; int a=A%10;//A=12345の時5 A/=10;//A=1234 int b=A%10; A/=10;//A=123 A/=10;//A=12 int d=A%10; A/=10;//A=1 int e=A; if(a==e&&b==d){ sum+=1; } C++; i++; } cout<<sum<<endl; }
#include<iostream> using namespace std; int main() { string sa, sb, sc; cin >> sa >> sb >> sc; int na = sa.length() + 1; int nb = sb.length() + 1; int nc = sc.length() + 1; int a = 0, b = 0, c = 0; char next = 'a', ans = 'A'; while(a < na && b < nb && c < nc) { if (next == 'a') { next = sa[a]; a++; ans = 'A'; } else if (next == 'b') { next = sb[b]; b++; ans = 'B'; } else { next = sc[c]; c++; ans = 'C'; } } cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int a; int ma = 0, mi = 999; for (int i=0; i<5; i++) { cin >> a; ma = max(ma, a); mi = min(mi, a); } int dist = ma - mi; int k; cin >> k; if (dist <= k) cout << "Yay!" << endl; else cout << ":(" << endl; }
#include <iostream> using namespace std; void call(int n){ bool end_check_num=false; int i=1,x; while(1){//check_num while(1){//end_check_num x=i; if(x%3==0){ cout<<" "<<i; break;//goto end_check_num } while(1){//include3 if(x%10==3){ cout<<" "<<i; end_check_num=true; break;//goto end_check_num } if(end_check_num) break; x/=10; if(x==0) break;//goto include3 } break; } //end_check_num end_check_num=false; if(++i>n) break; } cout<<endl; } int main(){ int n=0; cin>>n; call(n); return 0; }
0
#include<bits/stdc++.h> using namespace std; int main(){ int N,K; cin>>N>>K; if(N<K){ cout<<1<<endl; } else if(N%K==0){ cout<<0<<endl; } else{ cout<<1<<endl; } }
#include <iostream> #include <climits> // to use INT_MIN and INT_MAX using namespace std; typedef long long ll; ll arr[100005]; ll gcd(ll a, ll b) { // Euclidean algorithm if (b == 0) return a; return gcd(b, (a%b)); // doing a%b will also help swap both numbers in the case b>a } bool multiples(ll N, ll K, ll min, ll max) { ll gcdRes = 0; // (1) CHECK FOR GCD IN ARRAY for(ll i=0; i<N; i++) { gcdRes = gcd(gcdRes, arr[i]); } // (2) CHECK IF TARGET K IS DIVISIBLE BY GCD bool flag = false; if(K % gcdRes != 0) { flag = true; } return flag; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll N, K, min = INT_MAX, max = INT_MIN; cin >> N >> K; for(int i=0; i<N; i++) { cin >> arr[i]; if(arr[i] == K) { // box already contains target K cout << "POSSIBLE" << endl; exit(0); } if(arr[i] < min) min = arr[i]; if(arr[i] > max) max = arr[i]; } // If max (eg. 5) is less than target (eg. 10), // Even if min=1 (smallest possible from constraints), abs diff will never reach target: if(max < K) { cout << "IMPOSSIBLE" << endl; exit(0); } if(multiples(N , K, min, max) == true){ cout << "IMPOSSIBLE" << endl; } else cout << "POSSIBLE" << endl; }
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 = 1400000; char dn[dm], * di = dn; const int MAX = 20000; class unko { public: char C[MAX * 7 + 10], *K[MAX + 10]; constexpr unko() : C(), K() { auto di = C + 3; C[0] = '0'; C[0] = ' '; C[0] = '\n'; K[0] = C; K[1] = di; 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)); *di++ = ' '; *di++ = '\n'; K[i + 1] = di; } } }; constexpr unko f; inline void putint(int X) { if (X > 20000) { int ue = X / 10; for (auto i = f.K[ue]; *i != ' '; i++) *di++ = *i; *di++ = '0' + X % 10; *di++ = ' '; } else for (auto i = f.K[X]; *i != '\n'; i++)* di++ = *i; } 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 n; cin>>n; long long ret = 0; int neg = 0; vector<long long>arr(n); for(int i=0; i<n; i++){ cin>>arr[i]; if(arr[i]<0) neg++; ret+=abs(arr[i]); arr[i] = abs(arr[i]); } if(neg%2) ret-=2*(*min_element(arr.begin(),arr.end())); cout<<ret; }
0
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; set <int> s; for(int i = 0;i < n;++i){ int num; cin >> num; auto itr = s.find(num); if(itr == s.end()) s.insert(num); else s.erase(num); } cout << (int)s.size() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long a,b,i,c=0,d=0,n,m,t,j; cin>>n; long long A[n]; for(i=0;i<n;i++) cin>>A[i]; sort(A,A+n); for(i=0;i<n-1;i++) { if(A[i]==A[i+1]) { c+=2; i++; } } std::cout <<n-c<< '\n'; return 0; }
1
#include <cstdio> #include <utility> #include <cmath> #include <algorithm> using namespace std; #define gcu getchar_unlocked int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu(); do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} int in() {return in(gcu());} bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);} bool scan(char &c){c=gcu();gcu();return c!=EOF;} //bool scan(string &s){int c;s=""; // for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}} #define pcu putchar_unlocked #define vo inline void out template <typename T> vo(T n){static char buf[20];char *p=buf; if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10; while (p!=buf)pcu(*--p);} vo(const char *s){while(*s)pcu(*s++);} vo(char c){pcu(c);} //vo(string &s){for (char c: s) pcu(c);} template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);} //template <typename T> vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');} #undef vo int main() { for (int e, m; (e = m = in());) { for (int z = cbrt(e) + 0.00001; z >= 0; z--) { int te = e - z * z * z; int y = (int)sqrt(te); int tm = z + y + te - y * y; if (y > m) break; m = min(m, tm); } out(m, '\n'); } }
#include <stdio.h> #include <iostream> #include <queue> #include <map> #include <string> #include <vector> #include <algorithm> #include <math.h> #define PB push_back #define in scanf #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 (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) using namespace std; void solve(){ int e; while(cin >> e ,e!=0) { int m =1000000000; int x; for(int z=0;z*z*z<=e;z++){ for(int y=0;y*y+z*z*z<=e;y++){ x = e-y*y-z*z*z; m = min(x + y + z,m); } } cout << m << endl; } } int main(){ solve(); }
1
#include<iostream> #include<math.h> using namespace std; int main(){ long long a,b,c,d=0,e=0; cin>>a>>b>>c; if(a==b && b==c || a!=b && b!=c && a!=c){cout<<"No";return 0;} else{cout<<"Yes";} return 0; }
//============================================================================ // Name : JOI.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <algorithm> using namespace std; typedef struct pair<int,int> P; int A,B,C,D,E,F; int main() { cin>>A>>B>>C>>D>>E>>F; int M=A; if(B<M)M=B; if(C<M)M=C; if(D<M)M=D; int R=A+B+C+D-M; int L=0; if(E<F){ L=F; }else{ L=E; } cout<<R+L<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int n = int(s.size()); if(n == 2 && s[0] == s[1]) return cout << 1 << ' ' << 2 << '\n', 0; for(int i = 0; i < n - 2; ++i){ string ac = s.substr(i, 3); if(ac[0] == ac[1] || ac[0] == ac[2] || ac[1] == ac[2]){ return cout << i + 1 << ' ' << i + 3 << '\n', 0; } } cout << -1 << ' ' << -1 << '\n'; return 0; }
#include <bits/stdc++.h> #define s second #define f first #define pb push_back #define endl '\n' using namespace std; typedef long long ll; typedef pair<int,int> pii; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); string S; cin >> S; vector<vector<int>> Oc(27); for(int i = 0; i < S.size(); i++){ Oc[S[i] - 'a'].pb(i); } bool can = 0; for(int i = 0; i < 27; i++){ for(int l = 0; l < Oc[i].size(); l++){ for(int r = l + 1; r < Oc[i].size(); r++){ if(r - l + 1 > (Oc[i][r] - Oc[i][l] + 1)/2){ can = 1; cout << Oc[i][l] + 1 << " " << Oc[i][r] + 1 << endl; } if(can) break; } if(can) break; } if(can) break; } if(!can){ cout << -1 << " " << -1 << endl; } return 0; }
1
#include <iostream> using namespace std; int bubbleSort(int A[], int N) { int s = 0; for(int i = 0; i < N - 1; i++) for(int j = N - 1; j > i; j--) if(A[j] < A[j - 1]){ int tmp = A[j - 1]; A[j - 1] = A[j]; A[j] = tmp; s++; } return s; } int main() { int N; cin >> N; int A[N]; for(int i = 0; i < N; i++) cin >> A[i]; int n = bubbleSort(A, N); for(int i = 0; i < N; i++) if(i) cout << " " << A[i]; else cout << A[i]; cout << endl << n << endl; }
#include <iostream> #include <cmath> #include <vector> #include <climits> using namespace std; int main() { int n; cin >> n; vector<int> v; for(int i = 0;i < n;i++) { int t; cin >> t; v.push_back(t); } bool f = true; int c = 0; while(f) { f = false; for(int i = 1;i < v.size();i++) { if(v.at(i) < v.at(i - 1)) { int t = v.at(i - 1); v.at(i -1) = v.at(i); v.at(i) = t; f = true; c++; } } } for(int i = 0;i < v.size();i++) { cout << v.at(i); if(i + 1 != v.size()) { cout << " "; } else { cout << endl; } } cout << c << endl; }
1
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif #define rep(i,n) for(int i=0;i<(int)(n);i++) #define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define all(x) (x).begin(),(x).end() #define foreach(u,v) for(auto (u) : (v)) #define pb push_back #define mp make_pair #define mt make_tuple typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<ll, ll> pll; typedef vector<ll> vl; const int inf = 1e9; const ll linf = 1LL<<60; const ll mod = 1e9 + 7; const double eps = 1e-9; /* */ typedef tuple<int, int, int> triple; int n, m; map<pii, vector<triple>> g; map<pii, ll> dist; int main() { cin >> n >> m; rep(i, m){ int p, q, c; cin >> p >> q >> c; p--; q--; g[mp(p, c)].pb(mt(q, c, 0)); g[mp(q, c)].pb(mt(p, c, 0)); g[mp(p, c)].pb(mt(q, -1, 0)); g[mp(q, c)].pb(mt(p, -1, 0)); g[mp(p, -1)].pb(mt(q, c, 1)); g[mp(q, -1)].pb(mt(p, c, 1)); dist[mp(p, c)] = linf; dist[mp(q, c)] = linf; dist[mp(p, -1)] = linf; dist[mp(q, -1)] = linf; } rep(i, n) dist[mp(i, -1)] = linf; priority_queue<triple, vector<triple>, greater<triple>> que; que.push(mt(0, 0, -1)); dist[mp(0, -1)] = 0; while(!que.empty()){ int d, v, c; tie(d, v, c) = que.top(); que.pop(); if(dist[mp(v, c)] < d) continue; for(auto e : g[mp(v, c)]){ int to, cc, dd; tie(to, cc, dd) = e; if(dist[mp(to, cc)] > dist[mp(v, c)] + dd){ dist[mp(to, cc)] = dist[mp(v, c)] + dd; que.push(mt(dist[mp(to, cc)], to, cc)); } } } ll ans = dist[mp(n-1, -1)]; if(ans == linf) cout << -1 << endl; else cout << ans << endl; return 0; }
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <queue> #define MN 301000 #define MM 1601000 typedef std::pair<int, int> P; int h[MN], nxt[MM], to[MM], cost[MM], K = 0; std::vector<P> v[101000]; int d[MN], n, m; std::deque<int> q; void ins(int u, int v, int c) {nxt[++K] = h[u]; h[u] = K; to[K] = v; cost[K] = c;} int bfs() { q.push_back(1); memset(d, 0x3f, sizeof(d)); d[1] = 0; while(!q.empty()) { int u = q.front(); q.pop_front(); for(int i = h[u]; i; i = nxt[i]) { if(d[to[i]] > d[u] + cost[i]) { d[to[i]] = d[u] + cost[i]; if(cost[i]) q.push_back(to[i]); else q.push_front(to[i]); } } } if(d[n] > 1e9) return -1; return d[n]; } int main() { scanf("%d%d", &n, &m); for(int i = 1; i <= m; i++) { int p, q, c; scanf("%d%d%d", &p, &q, &c); v[p].push_back(P(c, i)); v[q].push_back(P(c, i)); ins(p, n + i, 1); ins(n + i, p, 0); ins(q, n + i, 1); ins(n + i, q, 0); } for(int i = 1; i <= n; i++) { std::sort(v[i].begin(), v[i].end()); int S = v[i].size(); for(int j = 1; j < S; j++) { if(v[i][j].first == v[i][j - 1].first) { ins(v[i][j].second + n, v[i][j - 1].second + n, 0); ins(v[i][j - 1].second + n, v[i][j].second + n, 0); } } } printf("%d\n", bfs()); }
1
#include <iostream> #include <string> #include <unordered_map> #include <unordered_set> #include <cstring> #include <chrono> #include <vector> #include <map> #include <random> #include <set> #include <algorithm> #include <math.h> #include <cstdio> #include <stdio.h> #include <queue> #include <bitset> #include <cstdlib> #include <deque> #include <cassert> #include <stack> using namespace std; #define mp make_pair #define f first #define se second #define pb push_back #define ppb pop_back #define emb emplace_back #define ll long long #define ull unsigned long long #define cntbit(x) __builtin_popcount(x) #define endl '\n' #define uset unordered_set #define umap unordered_map #define pii pair<int, int> #define ld long double #define pll pair<long long, long long> mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> inline T range(T l, T r) { return uniform_int_distribution<T>(l, r)(rng); } inline void setin(string s) { freopen(s.c_str(), "r", stdin); } inline void setout(string s) { freopen(s.c_str(), "w", stdout); } template <typename T> void Min(T &a, T b) { a = min(a, b); } template <typename T> void Max(T &a, T b) { a = max(a, b); } const int inf = 0x3f3f3f3f; const int mod = 998244353; const int N = 3e2 + 15; int n, k; string s; int dp[2][N][N]; // dp[i][operation_applied][free_ones] int a[N]; inline int add(int a, int b) { a += b; if(a >= mod) a -= mod; return a; } inline void add_t(int &a, int b) { a = add(a, b); } inline int mt(int a, int b) { return 1ll * a * b % mod; } inline void construct() { int sz = 1; for(int i = 1; i <= n && s[i] == '1'; ++i) a[1] = i; for(int i = a[1] + 1; i <= n; ++i) { if(s[i] == '0') { if(i + 1 <= n && s[i + 1] == '0') a[++sz] = 0; } else { int j = i; while(j + 1 <= n && s[j + 1] == '1') ++j; a[++sz] = j - i + 1; i = j; } } n = sz; } inline void solve() { // dp[i][operation_applied][free_ones] dp[(n + 1) & 1][0][0] = 1; int sum = 0; for(int i = n; i >= 1; --i) { int bit = i & 1; memset(dp[bit], 0, sizeof(dp[bit])); for(int k = 0; k <= sum; ++k) { int val = 0; for(int t = sum; t >= 0; --t) { add_t(dp[bit][k][t], val); for(int j = 0; j <= a[i] && k + j < N; ++j) add_t(dp[bit][k + j][t + j], dp[bit ^ 1][k][t]); add_t(val, dp[bit ^ 1][k][t]); } } sum += a[i]; } } inline void output() { int ans = 0; for(int i = 0; i < min(N, k + 1); ++i) add_t(ans, dp[1][i][0]); cout << ans << endl; } main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // setin("input.txt"); cin >> s >> k; n = s.size(); s = '#' + s; construct(); solve(); output(); return 0; }
// IOI 2021 #include <bits/stdc++.h> using namespace std; #define endl '\n' #define ends ' ' #define die(x) return cout << x << endl, 0 #define all(v) v.begin(), v.end() #define sz(x) (int)(x.size()) void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); } #define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__) typedef long long ll; typedef pair<int, int> pii; const int INF = 1e9; const ll MOD = 998244353; //////////////////////////////////////////////////////////////////// const int N = 3e2 + 5; int A[N], DP[N][N][N]; void Add(int &x, int y) { x += y; if (x >= MOD) x -= MOD; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); mt19937 Rnd(time(0)); string S; cin >> S; int m = 1, o = 0; for (char c : S) if (c == '0') m++; else A[m - 1]++, o++; reverse(A, A + m); DP[0][0][0] = 1; for (int i = 0; i < m; i++) for (int j = 0; j <= o; j++) for (int k = 0; k <= o; k++) { if (!DP[i][j][k]) continue; for (int l = 0; l <= A[i] + k; l++) Add(DP[i + 1][j + max(A[i] - l, 0)][k + A[i] - l], DP[i][j][k]); } int k; cin >> k; k = min(k, o); int ans = 0; for (int i = 0; i <= k; i++) Add(ans, DP[m][i][0]); cout << ans << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; using int64 = long long; constexpr int DEBUG = 0; // For modular arithmetic when a modular is specified per input case. // Verified: ABC129F struct ModInt { private: static int64 M; int64 x; public: static void SetMod(int64 mod) { M = mod; } ModInt(int64 input_x) : x(input_x % M) {} ModInt() : x(0) {} int64 Value() { return x; } inline ModInt operator+(ModInt o) { ModInt r(*this); r += o; return r; } inline ModInt operator-(ModInt o) { ModInt r(*this); r -= o; return r; } inline ModInt operator* (ModInt o) { ModInt r(*this); r *= o; return r; } inline void operator+= (ModInt o) { x = (x + o.x) % M; } inline void operator-= (ModInt o) { x = (x + M - o.x) % M; } inline void operator*= (ModInt o) { x = (x * o.x) % M; } }; int64 ModInt::M = 1; // Do not forget to add this line. template<typename T> vector<vector<T>> MakeVector2D(int d1, int d2, T default_value) { return vector<vector<T>>(d1, vector<T>(d2, default_value)); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int m; cin >> m; ModInt::SetMod(m); const int BASE = n; auto dp = MakeVector2D<ModInt>(3 * n + 1, 2 * n + 1, ModInt(0)); dp[0][BASE] = 1; for (int i = 0; i < 3 * n; i++) { for (int k = 0; k <= 2 * n; k++) { if (dp[i][k].Value() == 0) continue; // Size 1 dp[i + 1][min(k + 1, 2 * n)] += dp[i][k]; // Size 2 if (k > 0 && i + 2 <= 3 * n) { dp[i + 2][k - 1] += dp[i][k] * (i + 1); } // Size 3 if (i + 3 <= 3 * n) { dp[i + 3][k] += dp[i][k] * (i + 1) * (i + 2); } } } ModInt ans = 0; for (int k = BASE; k <= 2 * n; k++) { // cout << dp[3 * n][k].Value() << endl; ans += dp[3 * n][k]; } cout << ans.Value() << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define f first #define s second int n , g , p[11] , c[11] , mn=1e9; bool vis[11]; void solve(int i , int sum , int cnt) { if (i > n) { int rem = g-sum; if (rem <= 0) mn = min(mn , cnt); else { for(int j=n; j>0; j--) { if (vis[j]) continue; for(int k=1; k<=p[j]; k++) { rem -= j*100 , cnt++; if (rem <= 0) { mn = min(mn , cnt); return; } } } } return; } vis[i] = 1; solve(i+1 , sum+p[i]*i*100+c[i] , cnt+p[i]); vis[i] = 0; solve(i+1 , sum , cnt); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> g; for(int i=1; i<=n; i++) { cin >> p[i] >> c[i]; } solve(1,0,0); cout << mn << '\n'; return 0; }
0
#include<iostream> #include<string> using namespace std; int main(void) { string str, cmd, rep; int q, s, e; cin >> str >> q; for (int i = 0; i < q; i++) { cin >> cmd >> s >> e; int interval = e - s + 1; if (cmd == "print") { cout << str.substr(s, interval) << endl; } else if (cmd == "reverse") { string original = str.substr(s, interval); int size = original.size(); for (int i = 0; i < size; i++) { str[s + i] = original[size - i - 1]; } } else if (cmd == "replace") { cin >> rep; str.replace(s, interval , rep); } } return 0; }
#include <algorithm> #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define ll long long #define INF 1000000000000000000 typedef pair<ll, ll> pll; typedef pair<int, int> pint; int main() { int H, W; cin >> H >> W; int cnt = 0; vector<vector<char>> G(H, vector<char>(W)); vector<pint> flip; rep(i, H) { rep(j, W) { cin >> G[i][j]; if (G[i][j] == '.') cnt++; else flip.push_back({i, j}); } } ll ans = 0; int dx[4] = {1, 0, 0, -1}; int dy[4] = {0, 1, -1, 0}; while (cnt != 0) { vector<pint> A; rep(i, flip.size()) { for (int j = 0; j < 4; j++) { pint p = flip[i]; int ny = p.first + dy[j]; int nx = p.second + dx[j]; if (ny < 0 || nx < 0 || ny >= H || nx >= W) continue; if (G[ny][nx] == '#') continue; G[ny][nx] = '#', cnt--, A.push_back({ny, nx}); } } ans++; flip = A; } cout << ans << endl; return 0; }
0
#include "bits/stdc++.h" using namespace std; // Inserted snippets: io, root #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; } template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; } template<typename H> void read(H& head) { cin >> head; } template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); } template<typename H> void write(H head) { cout << head << '\n'; } template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); } template<typename ...T> void die(T ...tok) { write(tok...); exit(0); } // End snippets int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); int sx, sy, tx, ty; read(sx, sy, tx, ty); int dx = tx - sx, dy = ty - sy; write( "L" + string(dy + 1, 'U') + string(dx + 1, 'R') + "D" + "R" + string(dy + 1, 'D') + string(dx + 1, 'L') + "U" + string(dy, 'U') + string(dx, 'R') + string(dy, 'D') + string(dx, 'L') ); }
#define _GLIBCXX_DEBUG #include<bits/stdc++.h> #include<algorithm>//next_permutation #define rep(i,n) for (int i = 0;i < (n);i++) #define all(v) v.begin(),v.end() #define dec(n) cout << fixed << setprecision(n); #define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #define small "abcdefghijklmnopqrstuvwxyz" using namespace std; using ll = long long; using P = pair<ll,ll>; using vl = vector<ll>; using vvl = vector<vl>; ll gcd(ll a,ll b){ if(b == 0) return a; return gcd(b , a % b); } const ll MOD = 1000000007; const ll MAX = 2000001; ll mod(ll a){ return a % MOD; } ll lcm(ll a,ll b){ return (a*b)/gcd(a,b); } ll fac[MAX], finv[MAX], inv[MAX]; void nCrprep() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll 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; } } ll nCr(ll n, ll r){ if (n < r) return 0; if (n < 0 || r < 0) return 0; return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD; } ll nCrcheep(ll n,ll r){ if(r == 0) return 1; else if(r == 1) return n; else return nCrcheep(n-1,r-1)*n/r; } vector<pair<ll,ll>> prime_factorize(ll n){ vector<pair<ll,ll>> res; for(ll i=2; i*i <= n; i++){ if(n % i != 0) continue; ll ex = 0; while(n % i == 0){ ex++; n /= i; } res.push_back({i,ex}); } if(n != 1) res.push_back({n,1}); return res; } int main(){ ll sx,sy,tx,ty; cin >> sx >> sy >> tx >> ty; ll dx = tx - sx; ll dy = ty - sy; cout << string(dx,'R') << string(dy,'U') << string(dx,'L') << string(dy,'D') << 'D' << string(dx+1,'R') << string(dy+1,'U') << 'L' << 'U' << string(dx+1,'L') << string(dy+1,'D') << 'R' << endl; }
1
// luogu-judger-enable-o2 #include <cstdio> #include <cstring> #include <algorithm> #include <cctype> typedef long long int64; using namespace std; inline int64 read(int f = 1, int64 x = 0, char ch = ' ') { while(!isdigit(ch = getchar())) if(ch == '-') f = -1; while(isdigit(ch)) x = x*10+ch-'0', ch = getchar(); return f*x; } const int N = 1e5+5; int n, m, a[N], f[N], s[N], top, vis[N]; int64 ans[N], k; int main() { n = read(); for(int i = 1; i <= n; ++i) a[i] = read(); for(int i = n; i; --i) a[i] -= a[i-1], f[i] = i; m = read(), k = read(); for(int i = 1, p; i <= m; ++i) p = read(), swap(f[p], f[p+1]); for(int i = 1; i <= n; ++i, top = 0) if(!vis[i]) { for(int j = i; !vis[j]; j = f[j]) vis[j] = 1, s[++top] = j; for(int j = 1; j <= top; ++j) ans[s[j]] = a[s[(j+k-1)%top+1]]; } for(int i = 1; i <= n; ++i) printf("%lld\n", ans[i] += ans[i-1]); return 0; }
//Optional FAST //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native") //Required Libraries #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> //Required namespaces using namespace std; using namespace __gnu_pbds; //Required defines #define endl '\n' #define READ(X) cin>>X; #define READV(X) long long X; cin>>X; #define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];} #define rz(A,N) A.resize(N); #define sz(X) (long long)(X.size()) #define pb push_back #define pf push_front #define fi first #define se second #define FORI(a,b,c) for(long long a=b;a<c;a++) #define FORD(a,b,c) for(long long a=b;a>c;a--) //Required typedefs typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<long long,long long> pll; //Required Constants const long long inf=(long long)1e18; const long long MOD=(long long)(1e9+7); const long long INIT=(long long)(1e6+1); const long double PI=3.14159265358979; // Required random number generators // mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count()); // mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count()); //Required Functions ll power(ll x,ll y) { if (y == 0) return 1; ll p = power(x, y/2) % MOD; p = (p * p) % MOD; return (y%2 == 0)? p : (x * p) % MOD; } ll modInverse(ll a) { return power(a,MOD-2); } //Work int main() { #ifndef ONLINE_JUDGE if (fopen("INPUT.txt", "r")) { freopen ("INPUT.txt" , "r" , stdin); //freopen ("OUTPUT.txt" , "w" , stdout); } #endif ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); clock_t clk; clk = clock(); //-----------------------------------------------------------------------------------------------------------// READV(N); READAR(A,N); ll P[N]={0}; ll ans[N]; FORI(i,0,N) { P[i]=i; ans[i]=i; } READV(M); READV(K); FORI(i,0,M) { READV(x); swap(P[x-1],P[x]); } while (K>0) { ll V[N]={0}; if(K%2==1) { FORI(i,1,N) { ans[i]=P[ans[i]]; } } FORI(i,1,N) { V[i]=P[P[i]]; } FORI(i,1,N) { P[i]=V[i]; } K=K/2; } ll diff[N]={0}; FORI(i,1,N) { diff[i]=A[i]-A[i-1]; } FORI(i,1,N) { ans[i]=diff[ans[i]]; } cout<<A[0]<<endl; ll prev=A[0]; FORI(i,1,N) { cout<<prev+ans[i]<<endl; prev=prev+ans[i]; } cout<<endl; //-----------------------------------------------------------------------------------------------------------// clk = clock() - clk; cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl; return 0; }
1
#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> #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; 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=100005; int X[MAXN],n,S;LL P[MAXN]; int main() { n=read();S=read(); for(int i=1;i<=n;i++)X[i]=read(),P[i]=read();LL ans=0; int l=1,r=n,preo=-1; while(l<=r&&X[l]<S&&X[r]>S) { if(P[l]>=P[r]) { P[l]+=P[r]; if(preo!=2)preo=2,ans+=X[r]-X[l]; --r; } else { P[r]+=P[l]; if(preo!=1)preo=1,ans+=X[r]-X[l]; ++l; } } if(l<=r) { if(X[l]>=S)ans+=X[r]-S; else ans+=S-X[l]; }pr2(ans); return 0; }
/* * Since g++10 is released, some characters is not valid inside #if 0 :( * So, why not using clang++? :D * Date: echo -n ' ' && date +%Y.%m.%d # Just Run this (Type !!sh in Vim). * Solution: * 考虑边界,推导结论,子问题递归求解 如果 S <= p[1] 或者 S >= p[n] ,显然所有人投票都是一个方向,不妨假设 p[1] < S < p[n] 。 考虑处在最边上的 1 号点和 n 号点,如果 a[1] >= a[n] ,那么一定先到 1 ,否则先到 n 。归 纳证明,如果 n = 2 显然成立,对于 n >= 3 ,若 S >= a[n - 1] 显然成立,否则 S < a[n - 1] , 此时考虑 1 和 n - 1 ,如果先到 n - 1 就会回到 S >= a[n - 1] 的情况。 不妨假设 a[1] >= a[n] ,那么到 n 的时间就一定是到 1 的时间加上 1 到 n 的距离,那么 n 想 要最小化到达 n 的时间其实就是等价于最小化到达 1 的时间,可以赋值 a[1] = a[1] + a[n] 并赋 值 n = n - 1 转换为子问题,递归求解,可以求出每个点的到达时间。 * Digression: * CopyRight: ▁▃▄▄▄▃▃▃▃▄▶ ▗▇▀▔ ▔▔▔▔ ▄▛ ▃▅━━■▄▂ ▟▊ ▐▘ ▀▙ ▟▜▌ ▐▖ ▋ ▐▍ ▟▘ ▜ ▝▀▇▆●▘ ▐▌ ▗▟▘ ▜▃ ▁▅▛ ▔▀▼▅▄▃▃██▅▄▄▄▅■▀▔ ▔▔▔▔▔▔ */ #include <cstdio> #include <algorithm> #define debug(...) fprintf(stderr, __VA_ARGS__) typedef long long ll; struct { inline operator int () { int x; return scanf("%d", &x), x; } inline operator ll () { ll x; return scanf("%lld", &x), x; } template<class T> inline void operator () (T &x) { x = *this; } template<class T, class ...A> inline void operator () (T &x, A &...a) { x = *this; this -> operator () (a...); } } read; const int maxn = 1000005; int p[maxn]; ll a[maxn]; ll t[maxn]; void solve (int l, int r, int S) { if (S <= p[l]) { for (int i = l; i <= r; i ++) t[i] = p[i] - S; return; } if (S >= p[r]) { for (int i = l; i <= r; i ++) t[i] = S - p[i]; return; } if (a[l] >= a[r]) { a[l] += a[r]; solve(l, r - 1, S); t[r] = t[l] + p[r] - p[l]; } else { a[r] += a[l]; solve(l + 1, r, S); t[l] = t[r] + p[r] - p[l]; } } int main () { int n = read, S = read; for (int i = 1; i <= n; i ++) read(p[i], a[i]); solve(1, n, S); ll ans = 0; for (int i = 1; i <= n; i ++) ans = std::max(ans, t[i]); printf("%lld\n", ans); }
1
#include<iostream> #include<string> #include<vector> #include<queue> #include<algorithm> #include<map> #include<set> #include<cmath> #include<iomanip> typedef long long ll; #define rep(i,n) for(int i=0;i<(n);i++) #define pb push_back #define sz(a) (int)a.size() using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long double n, m, d; cin >> n >> m >> d; if (d == 0) { cout << fixed<<setprecision(12)<<(m-1)*(1/n) << endl; } else { cout << fixed<<setprecision(12)<<(m-1)*(2*(n-d)/(n*n)) << endl; } }
#include <iostream> using namespace std; int main() { int D,T,S; cin>>D>>T>>S; double t=(double)D/S; if(t<=T){ cout<<"Yes"<<endl; } else { cout<<"No"<<endl; } return 0; }
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll read(){ ll a=0,b=getchar(),c=1; while(!isdigit(b))c=b=='-'?-1:1,b=getchar(); while(isdigit(b))a=a*10+b-'0',b=getchar(); return a*c; } string s; int main(){ cin >> s; if(s.size()<26){ for(char c='a';c<='z';c++) if(s.find(c)==string::npos){ cout << s << c; return 0; } } for(int i=s.size()-2;i>=0;i--){ if(s[i]<s[i+1]){ char t=s[i+1]; for(int j=i+1;j<s.size();j++) if(s[j]>s[i])t=min(t,s[j]); s[i]=t; s=s.substr(0,i+1); cout << s; return 0; } } puts("-1"); return 0; }
#include <iostream> #include <vector> #include <string> #include <cstring> #include <cmath> #include <algorithm> #include <iomanip> #include <assert.h> #include <numeric> #include <time.h> #include <map> #include <unordered_map> #include <stack> #include <queue> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < n; i++) #define all(c) (c).begin(), (c).end() #define P pair<int, int> #define chmin(x, y) x = min(x, y) int main() { string s; cin >> s; reverse(all(s)); s += '0'; int n = s.size(); const int INF = 100100100; vector<vector<int>> dp(n + 1, vector<int>(2, INF)); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) { int x = s[i] - '0'; x += j; if (x < 10) chmin(dp[i + 1][0], dp[i][j] + x); if (x > 0) chmin(dp[i + 1][1], dp[i][j] + (10 - x)); } } cout << dp[n][0] << endl; }
0
#pragma GCC optimize ("O3") #include <bits/stdc++.h> #define DEBUG true #ifdef ONLINE_JUDGE #undef DEBUG #define DEBUG false #endif using namespace std; #define TRACE(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << endl;} void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << "[" << *it << " = " << a << "]"; err(++it, args...); } #define MAXN ((ll)2e5+5) #define MOD ((ll)998244353) #define INF ((ll)1e9 + 9) #define ll long long #define _ << " " << #define CLEAR(a, b) memset(a, b, sizeof(a)) #define LOG(x) if(DEBUG) cerr << x << endl; #define pb push_back #define all(x) x.begin(), x.end() #define endl "\n" #define pii pair<int,int> #define mid ((l+r)/2) ll n, m, k; ll A = 0; ll ans; void mulself(ll& a, ll b) { a *= b; a %= MOD; } ll fast(ll a,ll b) { ll res=1; while(b) { if(b&1LL) { res*=a; res%=MOD; } b>>=1LL; a*=a; a%=MOD; } return res; } ll inv(ll x) { return fast(x, MOD-2); } ll C(ll a, ll b) { ll ret = 1; for (int i = 0; i < b; ++i) mulself(ret, a-i); for (int i = 2; i <= b; ++i) mulself(ret, inv(i)); return ret; } signed main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin >> n >> m >> k; A = m * fast(m-1, n-k-1); A %= MOD; mulself(A, C(n-1, k)); ans = (ans + A) % MOD; ll B = A; for (int i = k-1; i >= 0; --i) { mulself(B, m-1); mulself(B, i+1); mulself(B, inv(n-(i+1))); ans = (ans + B) % MOD; } cout << ans << endl; } /* stuff you should look for * ll overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN */
#include<bits/stdc++.h> #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define int long long int #define mod 998244353 using namespace std; int fact[200005]; int power(int a, int b) { if(b==0) return 1; int t = power(a,b/2); t*=t; t%=mod; if(b&1) t*=a; return t%mod; } int ncr(int n, int r) { if(r==0) return 1; int ans=1; ans*=fact[n]; ans%=mod; ans*=power(fact[r],mod-2); ans%=mod; ans*=power(fact[n-r],mod-2); ans%=mod; return ans; } void solve() { fact[1]=1; fact[0]=1; for(int i=2;i<200005;i++) fact[i]=fact[i-1]*i%mod; int n,m,k; cin>>n>>m>>k; if(m==1) { if(k==n-1) cout<<1<<endl; else cout<<0<<endl; return; } int ans=0; for(int i=0;i<=k;i++) { int g = ncr(n-1,i); // cout<<g<<endl; int t = (g*m%mod)*power(m-1,n-1-i)%mod; ans+=t; ans%=mod; } cout<<ans<<endl; } signed main() { FAST_IO; int t = 1; // cin>>t; while(t--) { solve(); } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int N,L;cin>>N>>L; int left=L; int right=L+N-1; int all=0; for(int i=1;i<=N;i++) all+=L+i-1; if(left>=0) cout<<all-L<<endl; else if(right<=0) cout<<all-L-N+1<<endl; else cout<<all<<endl; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);++i) using namespace std; using ll=long long; using Graph=vector<vector<ll>>; int main(){ ll n,t;cin>>n>>t; vector<ll> ti(n); rep(i,n)cin>>ti[i]; ll c=t; for(int i=n-1;i>0;--i){ c+=min(t,ti[i]-ti[i-1]); } cout<<c; }
0