code_file1
stringlengths
80
4k
code_file2
stringlengths
91
4k
similar_or_different
int64
0
1
#include <iostream> #include <vector> #include <cmath> #include <limits.h> #include <utility> #include <map> #include <algorithm> #include <set> using namespace std; using P = pair<int,int>; using ll = long long; const int MOD=1e9+7; void modplus(int &a,int b){ a+=b; a%=MOD; } ll eline(int a){ if(a<=0)return 1ll; vector<vector<int>> dp(a,vector<int>(2,0)); dp[0][0]=1; dp[0][1]=1; for(int i=1;i<a;i++){ dp[i][0]=dp[i-1][0]+dp[i-1][1]; dp[i][1]=dp[i-1][0]; } return dp[a-1][0]+dp[a-1][1]; } int main(){ int h,w,g; cin>>h>>w>>g; g--; vector<vector<int>> dp(h+1,vector<int>(w,0)); dp[0][0]=1; for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ for(int l=-1;l<=1;l++){ int from=j,to=j+l; if(from>to)swap(from,to); if(l==0){ modplus(dp[i+1][j],dp[i][j]*(eline(from-1)*eline(w-to-2)%MOD)%MOD); }else if(0<=j+l&&j+l<w){ modplus(dp[i+1][j+l],dp[i][j]*(eline(from-1)*eline(w-to-2)%MOD)%MOD); } } } } cout<<dp[h][g]<<endl; }
#include<bits/stdc++.h> using namespace std; #define p 1000000007 #define maxn 100005 #define int long long int h,w,a,b,fac[maxn*2+5],inv[maxn*2+5]; inline int qpow(int x,int a) { int ans=1; while(a) { if(a&1) ans=1ll*ans*x%p; x=1ll*x*x%p; a>>=1; } return ans; } inline void pre(int x=maxn*2) { fac[0]=inv[0]=1; for(int i=1;i<=x;++i) fac[i]=1ll*fac[i-1]*i%p; inv[x]=qpow(fac[x],p-2); for(int i=x-1;i;--i) inv[i]=1ll*inv[i+1]*(i+1)%p; } inline int c(int x,int y) { if(x<y) return 0; return 1ll*fac[x]*inv[y]%p*inv[x-y]%p; } signed main() { scanf("%lld%lld%lld%lld",&h,&w,&a,&b); pre(); int ans=c(h+w-2,h-1); for(int i=1;i<=b;++i) ans-=1ll*c(h-a+i-2,i-1)*c(w-i+a-1,a-1),ans%=p; ans=(ans%p+p)%p; printf("%lld\n",ans); return 0; }
0
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <vector> const int MOD = 1e9 + 7; const int iINF = 2147483647 / 2; const long long int llINF = 9223372036854775807 / 2; using namespace std; using ll = long long int; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vvvl = vector<vector<vector<ll>>>; typedef pair<ll, ll> pll; bool paircomp(const pll &a, const pll &b) { if (a.first == b.first) return a.second < b.second; return a.first < b.first; } #define REP(i, n) for (ll i = 0; i < (n); i++) #define RREP(i, n) for (ll i = (n)-1; i >= 0; i--) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define AUTO(i, m) for (auto &i : m) #define ALL(a) (a).begin(), (a).end() #define MAX(vec) *std::max_element(vec.begin(), vec.end()) #define MIN(vec) *std::min_element(vec.begin(), vec.end()) #define ARGMAX(vec) \ std::distance(vec.begin(), std::max_element(vec.begin(), vec.end())) #define ARGMIN(vec) \ std::distance(vec.begin(), std::min_element(vec.begin(), vec.end())) #define REV(T) greater<T>() #define PQ(T) priority_queue<T, vector<T>, greater<T>> #define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c)) #define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c)) #define VVVL(a, b, c, d) \ vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d))) #define VVV(T, a, b, c, d) \ vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d))) #define SP(a) setprecision(a) #define SQRT(a) sqrt((long double)(a)) #define DPOW(a, b) pow((long double)(a), (long double)(b)) #define UNIQUE(vec) \ do { \ sort(ALL((vec))); \ (vec).erase(std::unique(ALL((vec))), (vec).end()); \ } while (0) ll POW(ll n, ll m) { if (m == 0) { return 1; } else if (m % 2 == 0) { ll tmp = POW(n, m / 2); return (tmp * tmp); } else { return (n * POW(n, m - 1)); } } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll T; cin >> T; vl ANS(T, 0); REP(t, T) { ll N; string S; cin >> N; vl A(N); REP(i, N) cin >> A[i]; cin >> S; vl base; RREP(i, N) { ll x = A[i]; sort(ALL(base), REV(ll)); AUTO(b, base) x = min(x, x ^ b); if (x != 0) { if (S[i] == '0') base.push_back(x); else { ANS[t] = 1; break; } } } } REP(t, T) cout << ANS[t] << endl; return 0; }
#include <iostream> using namespace std; int main(){ int n,a; cin >> n; int max = -1000001; int min = 1000001; long sum = 0; for(int i=0;i<n;i++){ cin >> a; sum = sum + a; if(max<a) max = a; if(min>a) min = a; } cout << min << " " << max << " " << sum << endl; }
0
#define _GLIBCXX_DEBUG #include <iostream> #include <string> using namespace std; int main(void){ string s; cin >> s; for(int bit=0; bit<(1<<3); bit++){ int svn = s[0]-'0'; for(int i=0; i<3; i++){ if(bit & (1<<i)) svn += s[i+1]-'0'; else svn -= s[i+1]-'0'; } if(svn == 7){ for(int i=0; i<3; i++){ if(bit & (1<<i)) s.insert(2*i+1, "+"); else s.insert(2*i+1, "-"); } s += "=7"; goto SKIP; } } SKIP: cout << s << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long void solve() { string s; cin >> s; int a = s[0] - '0'; int b = s[1] - '0'; int c = s[2] - '0'; int d = s[3] - '0'; if (a+b+c+d == 7) cout << a << "+" << b << "+" << c << "+" << d << "=7"; else if (a+b+c-d == 7) cout << a << "+" << b << "+" << c << "-" << d << "=7"; else if (a+b-c-d == 7) cout << a << "+" << b << "-" << c << "-" << d << "=7"; else if (a-b-c-d == 7) cout << a << "-" << b << "-" << c << "-" << d << "=7"; else if (a+b-c+d == 7) cout << a << "+" << b << "-" << c << "+" << d << "=7"; else if (a-b-c+d == 7) cout << a << "-" << b << "-" << c << "+" << d << "=7"; else if (a-b+c+d == 7) cout << a << "-" << b << "+" << c << "+" << d << "=7"; else if (a-b+c-d == 7) cout << a << "-" << b << "+" << c << "-" << d << "=7"; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1, i = 1; //cin >> t; while(t--) { //cout << "Case #" << i << ": "; solve(); //i++; } return 0; }
1
#include <iostream> #include <cstring> #include<vector> #include <algorithm> #include<cstdlib> #include<set> #include<math.h> using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(ll i=0;i<n;i++) int main() { int a, b; cin >> a >> b; int ans; ans = (b - 1) /(a - 1); if((b-1)%(a-1)!=0) ans++; cout << ans << "\n"; return 0; }
// include // ------------------------------------------------ #include <bits/stdc++.h> #include <math.h> using namespace std; // func // ------------------------------------------------ int CalcSumOfDigit(int n); // 各桁の和を計算する。 int getDigit(int n); // 数字の桁数を取得する。 string upper(string str); // 英字を大文字に変換する。 string lower(string str); // 英字を小文字に変換する。 vector<pair<long long,long long>> prime_factorize(long long p); // 素因数分解 // class // ------------------------------------------------ class Combi { public: Combi(); long long Combination(long long n, long long k); long long nPk_modp(long long n, long long k, long long p); private: vector<vector<long long>> memo; long long n_num; long long k_num; void Resize(long long n, long long k); }; // define // ------------------------------------------------ #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define sz(a) int((a).size()) #define rep(i,n) for(int(i)=0;(i)<(n);(i)++) #define repe(i,n) for(int(i)=0;(i)<=(n);(i)++) #define vsort(v) sort((v).begin(),(v).end()) #define rvsort(v) sort(rall((v))) #define vi vector<int> #define GCD(a,b) __gcd((a),(b)) #define LCM(a,b) (a)/GCD((a),(b))*(b) #define kiriage(a,b) ((a)+(b)-1)/(b) const int INF = 1e9; typedef long long ll; typedef unsigned long long ull; typedef vector<long> vll; // code // ------------------------------------------------ int main() { ll k,t; cin >> k >> t; vll a(t); rep(i,t) cin >> a[i]; rvsort(a); ll ans = max((a[0] - 1 - (k - a[0])),0LL); cout << ans << endl; return 0; } // funcの実体 // ------------------------------------------------ int getDigit(int n) { int i = 1; while(1) { n = n / 10; if(n == 1) break; i++; } return i; } int CalcSumOfDigit(int n) { int s = 0; while(n) { s += n % 10; n = n / 10; } return s; } string upper(string str) { for(auto itr = str.begin();itr != str.end() ; itr++) { if(97 <= *itr && *itr <= 122) { *itr = *itr - 32; } } return str; } string lower(string str) { for(auto itr = str.begin();itr != str.end() ; itr++) { if(65 <= *itr && *itr <= 90) { *itr = *itr + 32; } } return str; } Combi::Combi() { n_num = -1; k_num = -1; }; ll Combi::Combination(ll n, ll k) { Resize(n,k); ll ret; if(memo[n][k] != 0) { ret = memo[n][k]; } else if(n == k || k == 0) { memo[n][k] = 1; ret = 1; } else { ret = Combination(n - 1, k - 1) + Combination(n - 1, k); memo[n][k] = ret; } return ret; } void Combi::Resize(ll n, ll k) { if(n_num <= n || k_num <= k) { n_num = (n + 1) * 2; k_num = (k + 1) * 2; memo.resize(n_num); for(auto itr = memo.begin(); itr != memo.end(); ++itr) { itr->resize(k_num); } } } long long Combi::nPk_modp(long long n, long long k, long long p) { ll ans = 1; for(long long i = k; i <= n; i++) { ans = (ans * i) % p; } return ans; }; vector<pair<long long,long long>> prime_factorize(long long p) { vector<pair<long long,long long>> ret; for(long long x = 2; x * x <= p; ++x) { if(p % x != 0) continue; long long num = 0; while(p % x == 0) { num++; p /= x; } ret.push_back(make_pair(x,num)); } if(p != 1) ret.push_back(make_pair(p, 1)); return ret; }
0
#include <iostream> #include <iomanip> #include <vector> #include <string> #include <cmath> #include <map> #include <climits> #include <cassert> #include <algorithm> #include <utility> using namespace std; using Int = long long int; using UInt = unsigned long long int; using VI = vector<long long int>; using VVI = vector<vector<long long int> >; // ビット演算 namespace Bits { // 整数 x を左に i ビットシフトした値を返す static Int LeftBitShift(Int x, Int i); // 整数 x を右に i ビットシフトした値を返す static Int RightBitShift(Int x, Int i); // 整数x の 下から i 桁目が1かどうかを返す static bool IsFlagUp(Int x, Int i); // 整数x の 下から i 桁目が0かどうかを返す static bool IsFlagDown(Int x, Int i); // 整数 x を左に i ビットシフトした値を返す Int LeftBitShift(Int x, Int i) { return (x << i); } // 整数 x を右に i ビットシフトした値を返す Int RightBitShift(Int x, Int i) { return (x >> i); } // 整数x の 下から i 桁目が1かどうかを返す bool IsFlagUp(Int x, Int i) { return ((x & (1 << i)) != 0); } // 整数x の 下から i 桁目が0かどうかを返す bool IsFlagDown(Int x, Int i) { return ((x & (1 << i)) == 0); } } using namespace Bits; // 二つの値の最大値を求める関数 Int Max(const Int a, const Int b) { if (a >= b) { return a; } else { return b; } } int main(void) { Int n; cin >> n; VI a(n); VVI table(n, VI(n, -1)); // -1 不明, 0 不親切, 1 正直者 Int x, y; for (Int i = 0; i < n; ++i) { cin >> a[i]; for (Int j = 0; j < a[i]; ++j) { cin >> x >> y; --x; table[i][x] = y; } } Int result = 0; for (Int i = 0; i < pow(2, n); ++i) { // cout << "I = " << i << endl; bool correct = true; Int rank = 0; // ビット列が1の人のみの証言に矛盾がないかを調べる for (Int j = 0; j < n; ++j) { if (IsFlagUp(i, j)) { rank++; for (Int k = 0; k < n; ++k) { if (table[j][k] == 0 && IsFlagUp(i, k)) { correct = false; } else if (table[j][k] == 1 && IsFlagDown(i, k)) { correct = false; } } } } if (correct) { // cout << "CORRECT" << endl; result = Max(result, rank); } else { // cout << "INCORRECT" << endl; } } cout << result << endl; /* for (Int i = 0; i < n; ++i) { for (Int j = 0; j < n; ++j) { cout << table[i][j] << " "; } cout << endl; } */ return 0; }
/* * @Author: hesorchen * @Date: 2020-07-03 17:05:01 * @LastEditTime: 2020-09-04 20:28:08 * @Description: https://hesorchen.github.io/ */ #include <map> #include <set> #include <list> #include <queue> #include <deque> #include <cmath> #include <stack> #include <vector> #include <bitset> #include <cstdio> #include <string> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define endl '\n' #define PI acos(-1) #define PB push_back #define ll long long #define INF 0x3f3f3f3f #define mod 1000000007 #define pll pair<ll, ll> #define lowbit(abcd) (abcd & (-abcd)) #define max(a, b) ((a > b) ? (a) : (b)) #define min(a, b) ((a < b) ? (a) : (b)) #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define FRE \ { \ freopen("in.txt", "r", stdin); \ freopen("out.txt", "w", stdout); \ } inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } return x * f; } //head============================================================================== struct node { int p, y; }; vector<node> vec[20]; int a[20]; int all[35000][20]; int vis[20]; int main() { int n; scanf("%d", &n); for (int i = 0; i < (1 << n); i++) { for (int j = 0; j < n; j++) { if (i & (1 << j)) all[i][j + 1] = 1; } } for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); for (int j = 1; j <= a[i]; j++) { int temp1, temp2; scanf("%d %d", &temp1, &temp2); vec[i].push_back(node{temp1, temp2}); } } int ans = 0; for (int i = 0; i < (1 << n); i++) { int flag = 1; fill(vis, vis + 18, -1); for (int j = 1; j <= n; j++) { if (!all[i][j]) continue; else { for (int k = 0; k < a[j]; k++) { if (vec[j][k].y != vis[vec[j][k].p] && vis[vec[j][k].p] != -1) { flag = 0; break; } if (vec[j][k].y && !all[i][vec[j][k].p]) { flag = 0; break; } if (!vec[j][k].y && all[i][vec[j][k].p]) { flag = 0; break; } if (vec[j][k].y) vis[vec[j][k].p] = 1; else vis[vec[j][k].p] = 0; } } if (!flag) break; } if (flag) { int s = 0; for (int j = 1; j <= n; j++) s += all[i][j]; ans = max(ans, s); } } printf("%d\n", ans); return 0; }
1
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pair<int, int> > vii; #define rrep(i, m, n) for(int (i)=(m); (i)<(n); (i)++) #define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++) #define rep(i, n) for(int (i)=0; (i)<(n); (i)++) #define rev(i, n) for(int (i)=(n)-1; (i)>=0; (i)--) #define vrep(i, c) for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++) #define ALL(v) (v).begin(), (v).end() #define mp make_pair #define pb push_back template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); } template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); } #define INF 1000000000 #define MOD 1000000007 #define EPS 1E-12 const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; const int MAX_H = 12; const int MAX_W = 12; char m[MAX_H+1][MAX_W+1]; inline bool check(int x, int y){ return 0<=x&&x<MAX_H && 0<=y&&y<MAX_W; } void dfs(int hx, int hy) { rep(i, 4){ int nx = hx + dx[i]; int ny = hy + dy[i]; if(!check(nx, ny)) continue; if(m[nx][ny] == '1'){ m[nx][ny] = '0'; dfs(nx, ny); } } } int main() { while(true){ rep(i, MAX_H) rep(j, MAX_W) if(!(cin >> m[i][j])) return 0; int res = 0; rep(i, MAX_H) rep(j, MAX_W) if(m[i][j] == '1'){ res += 1; dfs(i, j); } cout << res << endl; } return 0; }
#include<bits/stdc++.h> #pragma GCC optimization ("Ofast") #pragma GCC optimization ("unroll-loops") using namespace std; #define int long long #define rep(i,n) for(int i=0;i<n;i++) #define REP(i,n) for(int i=1;i<n;i++) #define rev(i,n) for(int i=n-1;i>=0;i--) #define all(v) v.begin(),v.end() #define P pair<int,int> #define len(s) (int)s.size() 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; } constexpr int mod = 1e9+7; constexpr long long inf = 3e18; class BIT{ int N; vector<int>bit; void add_(int x,int y){ while(x<=N){ bit[x]+=y;x+=x&-x; } } int sum_(int x){ int res=0; while(x>0){ res+=bit[x];x-=x&-x; } return res; } public: int lower_bound(int w){ if(w<=0)return -1; int x=0; int k=1;while(k*2<=N)k*=2; for(;k>0;k/=2){ if(x+k<=N&&bit[x+k]<w){ w-=bit[x+k]; x+=k; } } return x; } void add(int x,int y){add_(x+1,y);} int sum(int l,int r){return sum_(r)-sum_(l);} BIT(int x):N(x),bit(x+1){} }; signed main(){ cin.tie(0);ios::sync_with_stdio(false); int N,Q;cin>>N>>Q; BIT bit(N); rep(i,N){int a;cin>>a;bit.add(i,a);} while(Q--){ int t;cin>>t; if(!t){ int p,x;cin>>p>>x;bit.add(p,x); }else { int l,r;cin>>l>>r;cout<<bit.sum(l,r)<<"\n"; } } }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int cnt=0; string s; cin>>s; int m =0; for(int i =0 ;i<3;i++) { if(s[i]=='R')m++; else { cnt = max(m,cnt); m =0; } } cnt = max(m,cnt); cout<<cnt; return 0; }
#include <bits/stdc++.h> using namespace std; int n; char x[5]; int main() { scanf("%s", x); int ans = 0, cur = 0; for (int i = 0; x[i]; i++) if (x[i] == 'R') ans = max(ans, ++cur); else cur = 0; printf("%d\n", ans); }
1
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> #define pb push_back #define mp make_pair #define taskname "A" using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; const int maxn = 1e5 + 5; const int mod = 1e9 + 7; int d; ll ans = 0; ll p[20]; ll Cal(int i , ll d , int len){ if(i == len / 2)return (d == 0 ? ((len & 1) ? 10 : 1) : 0); ll tmp = p[len - i - 1] - p[i]; ll tmp1 = d / tmp; ll ans = 0; if(tmp1 >= -9 && tmp1 <= 9)ans += Cal(i+1,d-tmp*tmp1,len) * (10 - abs(tmp1) - (i == 0)); tmp1 += (d >= 0 ? 1 : -1); if(tmp1 >= -9 && tmp1 <= 9)ans += Cal(i+1,d-tmp*tmp1,len) * (10 - abs(tmp1) - (i == 0)); return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(taskname".INP","r")){ freopen(taskname".INP", "r",stdin); freopen(taskname".OUT", "w ",stdout); } p[0] = 1; for(int i = 1 ; i <= 19 ; ++i)p[i] = p[i - 1] * 10; int d;cin >> d; for(int i = 1 ; i <= 18 ; ++i)ans += Cal(0,d,i); cout << ans; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; template <typename T> void cmin(T &x, const T &y) { if(y < x) x = y; } template <typename T> void cmax(T &x, const T &y) { if(y > x) x = y; } template <typename T> void read(T &x) { x = 0; char c = getchar(); bool f = 0; while(!isdigit(c) && c!='-') c = getchar(); if(c == '-') f = 1, c = getchar(); while(isdigit(c)) x = x*10+c-'0', c = getchar(); if(f) x = -x; } ll pw10[19], D, ans; int bit[19]; void dfs(int l, int r, ll d, ll way) { if(l > r) { if(d == -D) ans += way; } else { if(l == r) dfs(l+1, r-1, d, way*10); else { for(int i=-9; i<=9; i++) { ll base = d+i*pw10[r]-i*pw10[l]; ll upb = base + pw10[r]; ll lob = base - pw10[r]; if(lob<=-D && -D<=upb) bit[l] = i, dfs(l+1, r-1, base, way*(10-abs(i)-(i<=0&&l==0))); } } } } int main() { read(D); pw10[0] = 1; for(int i=1; i<=18; i++) pw10[i] = pw10[i-1] * 10; for(int i=1; i<=18; i++) dfs(0, i, 0, 1); printf("%lld\n", ans); return 0; }
1
#include <bits/stdc++.h> #define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false)) #define rep(i, n) for (int i = 0; i < (n); ++i) #define precise(i) fixed << setprecision(i) using lint = long; using llint = long long; using namespace std; int main() { fastIO; int h, w, n; cin >> h >> w >> n; int longer = max(h, w); if (n % longer == 0) cout << (n / longer) << endl; else cout << (n / longer + 1) << endl; }
const int LG = 21; const int FN = 400005; const long long MOD = 998244353; const long long INF = 1e9; const long long INFLL = 1e18; #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; #define forn(i, n) for (int (i) = 0; (i) != (n); (i)++) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define popcount(x) __builtin_popcount(x) #define popcountll(x) __builtin_popcountll(x) #define fi first #define se second #define re return #define pb push_back #define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin()) #ifdef LOCAL #define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl #define ln cerr << __LINE__ << endl #else #define dbg(x) void(0) #define ln void(0) #endif // LOCAL int cx[4] = {-1, 0, 1, 0}; int cy[4] = {0, -1, 0, 1}; ll inq(ll x, ll y) { if (!y) re 1 % MOD; ll l = inq(x, y / 2); if (y % 2) re l * l % MOD * x % MOD; re l * l % MOD; } ll rev(ll x) { return inq(x, MOD - 2); } bool __precomputed_combinatorics = 0; vector<ll> __fact, __ufact, __rev; void __precompute_combinatorics() { __precomputed_combinatorics = 1; __fact.resize(FN); __ufact.resize(FN); __rev.resize(FN); __rev[1] = 1; for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD; __fact[0] = 1, __ufact[0] = 1; for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD; } ll fact(int x) { if (!__precomputed_combinatorics) __precompute_combinatorics(); return __fact[x]; } ll cnk(int n, int k) { if (k < 0 || k > n) return 0; if (!__precomputed_combinatorics) __precompute_combinatorics(); return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD; } int Root(int x, vector<int> &root) { if (x == root[x]) return x; return root[x] = Root(root[x], root); } void Merge(int v, int u, vector<int> &root, vector<int> &sz) { v = Root(v, root), u = Root(u, root); if (v == u) return; if (sz[v] < sz[u]) { sz[u] += sz[v]; root[v] = u; } else { sz[v] += sz[u]; root[u] = v; } } int ok(int x, int n) { return 0 <= x && x < n; } const int N = 1100000; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, m, k; cin >> n >> m >> k; ll ans = 0; for (int i = 0; i <= k; i++) { ll g = cnk(n - 1, i); ll fi = m * inq(m - 1, n - i - 1) % MOD; ans = (ans + g * fi) % MOD; } cout << ans; } /* Note: Check constants at the beginning of the code. N is set to 4e5 but be careful in problems with large constant factor. Setting N in every problem is more effective. Check corner cases. N = 1 No def int long long for now. Add something here. */
0
#include <iostream> #include <atcoder/fenwicktree> using namespace std; using namespace atcoder; int main() { int N,Q; cin >> N >> Q; fenwick_tree<long long int> fw(N); for(int i=0;i<N;i++) { int a; cin >> a; fw.add(i, a); } for(int i=0;i<Q;i++) { int t,c,d; cin >> t >> c >> d; if(t==0){ fw.add(c, d); }else{ cout << fw.sum(c, d) << endl; } } }
#include <iostream> #include <queue> #include <set> #include <map> #include <vector> #define FOR(i,n) for(unsigned i=0; i<n; i++) using namespace std; typedef unsigned us; typedef pair<us, us> point; int main () { us V, E; cin >> V >> E; set<us> seen; seen.insert(0); map<us, vector<point> > graph; priority_queue<point, vector<point>, greater<point> > q; us distance = 0; FOR(_, E) { us s, t, d; cin >> s >> t >> d; graph[s].push_back(make_pair(d, t)); graph[t].push_back(make_pair(d, s)); if (s == 0) q.push(make_pair(d, t)); if (t == 0) q.push(make_pair(d, s)); } while (!q.empty() && seen.size() != V) { point p = q.top(); us v = p.second; us w = p.first; q.pop(); if (seen.find(v) == seen.end()) { seen.insert(v); vector<point> neighbours = graph[v]; FOR(i, neighbours.size()) q.push(neighbours[i]); distance += w; } } cout << distance << endl; }
0
#include <iostream> #define SIZE 8 void threaten(int board[][SIZE], int x, int y) { for (int i=0; i<SIZE; i++) { board[i][y]++; board[x][i]++; } for (int i=-x; i<SIZE-x; i++) { if (0 <= y+i && y+i < SIZE) board[x+i][y+i]++; if (0 <= y-i && y-i < SIZE) board[x+i][y-i]++; } board[x][y]+=100; } void unthreaten(int board[][SIZE], int x, int y) { for (int i=0; i<SIZE; i++) { board[i][y]--; board[x][i]--; } for (int i=-x; i<SIZE-x; i++) { if (0 <= y+i && y+i < SIZE) board[x+i][y+i]--; if (0 <= y-i && y-i < SIZE) board[x+i][y-i]--; } board[x][y]-=100; } bool solve(int board[][SIZE], int rest) { if (rest==0) return true; for (int i=0; i<SIZE; i++) { for (int j=0; j<SIZE; j++) { if (board[i][j]>0) continue; threaten(board, i, j); if (solve(board, rest-1)) return true; unthreaten(board, i, j); } } return false; } int main() { int board[SIZE][SIZE]; for (int i=0; i<SIZE; i++) { for (int j=0; j<SIZE; j++) board[i][j] = 0; } int k; std::cin >> k; for (int i=0; i<k; i++) { int x, y; std::cin >> x >> y; threaten(board, x, y); } solve(board, SIZE-k); for (int i=0; i<SIZE; i++) { for (int j=0; j<SIZE; j++) { if (board[i][j] < 100) std::cout << "."; else std::cout << "Q"; } std::cout << std::endl; } return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int,int>; using Pl = pair<ll,ll>; #define rep(i,n) for(ll i = 0;i < (ll)n;i++) #define ALL(x) (x).begin(),(x).end() #define MOD 1000000007 int main(){ int n; cin >> n; ll taka = 0,ao = 0; priority_queue<Pl> que; vector<Pl> v(n); rep(i,n){ ll a,b;cin >> a >> b; que.push(make_pair(a+b,i)); v[i] = make_pair(a,b); } rep(i,n){ Pl k = que.top();que.pop(); if(!(i & 1))taka += v[k.second].first; else ao += v[k.second].second; } cout << taka-ao << endl; return 0; }
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; typedef map<ll,ll>::iterator itll; typedef long double ld; typedef map<ll,ll> mapll; #define con continue #define pb push_back #define fi first #define se second #define fr front() #define INF 1000000000000000000 #define all(vl) vl.begin(),vl.end() #define m_p make_pair #define sz(a) sizeof(a) #define forn(mp,it) for(it = mp.begin();it!=mp.end();it++) #define FOR(i,a,n) for(int i=a;i<n;i++) #define FORE(i,a,n) FOR(i,a,n+1) #define Endl endl #define eNdl endl #define enDl endl #define endL endl int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll k; cin>>k; vector<ll> vl; string s = "~abcdefghijklmnopqrstuvwxyz"; if(k<=26) { cout<<s[k]<<endl; return 0; } while(k>=26) { ll yu = k%26; k/=26; if(yu == 0) { yu = 26; k--; } vl.pb(yu); } if(k>0) vl.pb(k); reverse(all(vl)); FOR(i,0,vl.size()) { if(vl[i]>0)cout<<s[vl[i]]; else cout<<"z"; } cout<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> pi; typedef vector<pi> vpi; typedef vector<string> vsi; typedef map<ll, ll> mape; #define rep(i, a, b) for(ll i=(ll)a;i<=(ll)b;i++) #define per(i, a, b) for(ll i=(ll)a;i>=(ll)b;i--) #define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);} #define N 2100 #define MAX 1234567890 #define f first #define s second #define pb push_back #define mkp make_pair #define MOD 1000000007 int main() { fastio; ll n; cin >> n; string s = ""; while(n > 26){ ll rem = n % 26; if(rem == 0) { s += 'z'; rem = 26; } else s += ('a' + rem - 1); n = (n - rem) / 26; } s += ('a' + n - 1); reverse(s.begin(), s.end()); cout << s << endl; return 0; }
1
#include<iostream> #include<map> #include<set> #include<algorithm> using namespace std; map< int, set<int> > Init(int); set<int> FindFriends(map< int, set<int> >); int main(){ int i, n, m, a, b; set<int> friends; map< int, set<int> > data; while(1){ cin >> n >> m; if(n == 0 && m == 0) break; data = Init(n); for(i=0; i<m; ++i){ cin >> a >> b; data[a].insert(b); data[b].insert(a); } friends = FindFriends(data); cout << friends.size() << endl; } return 0; } map< int, set<int> > Init(int n){ int i; set<int> _data; map< int, set<int> > data; for(i=1; i<=n; ++i) data.insert(make_pair(i, _data)); return data; } set<int> FindFriends(map< int, set<int> > data){ set<int> _data, friends; set<int>::iterator i, j; map< int, set<int> >::iterator k; _data = data[1]; for(i=_data.begin(); i!=_data.end(); ++i){ if(friends.find(*i) == friends.end()) friends.insert(*i); k = data.find(*i); for(j=k->second.begin(); j!=k->second.end(); ++j){ if(*j != 1 && friends.find(*j) == friends.end()) friends.insert(*j); } } return friends; }
#include <iostream> #include <stdlib.h> using namespace std; int main(int argc, char **argv) { int n, m, **a, s, t, c, *b; while(1){ cin >> n; cin >> m; if(n == 0 && m == 0){ break; } c = 0; a = (int **)calloc(n+1, sizeof(int)); b = (int *)calloc(n+1, sizeof(int)); for(int i = 0; i <= n; i++){ a[i] = (int *)calloc(n+1, sizeof(int)); } for(int i = 0; i < m; i++){ cin >> s >> t; if(s == 1 || t == 1){ a[s][t] = a[t][s] = 1; b[t] = b[s] = 1; } else { a[s][t] = a[t][s] = 2; } } for(int i = 2; i <= n; i++){ if(a[1][i] == 1){ for(int j = 2; j <= n; j++){ if(a[i][j] == 2 && b[j] == 0){ b[j] = 1; } } } } b[1] = 0; for(int i = 0; i <= n; i++){ free(a[i]); c += b[i]; } free(a); free(b); cout << c << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) using ll = long long; using P = pair<int, int>; int main() { int n,m,x,y,flg = 0; cin >> n >> m >> x >> y; vector<int> X(n), Y(m); rep(i,n) cin >> X[i]; rep(i,m) cin >> Y[i]; sort(X.begin(), X.end()); sort(Y.begin(), Y.end()); for (int i = x+1; i <= y; i++) { if (X[n-1] < i && i <= Y[0]) { flg = 1; break; } } if (flg) cout << "No War" << endl; else cout << "War" << endl; return 0; }
#include <iostream> #include<string> using namespace std; class Dice{ public: int num[6],t;//t=top /* dice.num[0] = ??? dice.num[1] = ??? dice.num[2] = ??? dice.num[3] = ??? dice.num[4] = ??? dice.num[5] = ???*/ void North(){ t = num[0]; num[0] = num[1];//??????1?????¨??? num[1] = num[5];//??????2?????¨??? num[5] = num[4];//??????6?????¨??? num[4] = t;//??????5?????¨??? } void East(){ t = num[0]; num[0] = num[3];//??????1?????¨??? num[3] = num[5];//??????4?????¨??? num[5] = num[2];//??????6?????¨??? num[2] = t;//??????3?????¨??? } void West(){ t = num[0]; num[0] = num[2];//??????1?????¨??? num[2] = num[5];//??????5?????¨??? num[5] = num[3];//??????6?????¨??? num[3] = t;//??????2?????¨??? } void South(){ t = num[0]; num[0] = num[4];//??????1?????¨??? num[4] = num[5];//??????3?????¨??? num[5] = num[1];//??????6?????¨??? num[1] = t;//??????3?????¨??? } void Rotation(){//?????¢??????????????§?????¢???????????¨??? t = num[1]; num[1] = num[2];//?????¢???2?????¨??? num[2] = num[4];//?????¢???3?????¨??? num[4] = num[3];//?????¢???5?????¨??? num[3] = t;//?????¢???4?????¨??? } }; int main() { Dice d[100]; int n; cin >> n; for(int i=0; i<n; i++){ cin >> d[i].num[0] >> d[i].num[1] >> d[i].num[2] >> d[i].num[3] >> d[i].num[4] >> d[i].num[5]; } for(int i=0; i<n; i++){ for(int j=i+1; j<n; j++){ //?????¢?????????????????? if(( d[i].num[2] == d[j].num[0] || d[i].num[3] == d[j].num[0]) && d[i].num[0] != d[j].num[5]){ d[i].East(); } //?????¢??????????¨??????? for(int k = 0; k<4; k++){ if(d[i].num[0] == d[j].num[0])break; d[i].North(); } ////?????¢????????????????????? for(int k = 0; k<4; k++){ if(d[i].num[1] == d[j].num[1])break; d[i].Rotation(); } for(int k = 0; k<4; k++){ if(d[i].num[2] == d[j].num[2])break; d[i].Rotation(); } for(int k = 0; k<4; k++){ if(d[i].num[3] == d[j].num[3])break; d[i].Rotation(); } for(int k = 0; k<4; k++){ if(d[i].num[4] == d[j].num[4])break; d[i].Rotation(); } for(int k = 0; k<4; k++){ if(d[i].num[5] == d[j].num[3])break; d[i].Rotation(); } if( d[i].num[0] == d[j].num[0] && d[i].num[1] == d[j].num[1] && d[i].num[2] == d[j].num[2] && d[i].num[3] == d[j].num[3] && d[i].num[4] == d[j].num[4] && d[i].num[5] == d[j].num[5] ){ cout << "No" << endl; return 0; } } } cout << "Yes" << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) typedef long long ll; int main(){ int n; cin>>n; for(int i=n; i>0; i--){ double r=sqrt(i); if(r==(int)r) {cout<<i<<endl; return 0;} } }
#include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include<cmath> #include<limits> #define ll long long #define ALL(x) (x).begin(),(x).end() #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define int_INF 2147483647 #define pint_INF 2000000000 #define ll_INF 9223372036854775807 #define MOD 1000000007 #define vi vector<int> #define vvi vector<vector<int>> #define vll vector<long long> #define pii pair<int,int> #define vpii vector<pair<int,int>> #define sysp system("PAUSE") using namespace std; int Getinput(){ string s; cin >> s; if(s == "Vacant") return 0; else if(s == "Male") return 1; else if(s == "Female") return 2; } int main(){ int N; cin >> N; cout << N - 1 << endl; if(Getinput() == 0){ return 0; } cout << 0 << endl; int x = Getinput(); if(x == 0){ return 0; } int low = 0,high = N - 1; int stnd = x; while(high - low > 2){ int mid = (high + low) / 2; if(mid % 2 == 1) mid--; cout << mid << endl; int y = Getinput(); if(y == 0){ return 0; }else if(stnd == y){ low = mid; }else{ high = mid; } } cout << low + 1 << endl; int z = Getinput(); return 0; }
0
#include <string> #include <iostream> #include <algorithm> using namespace std; string s, t, u; int n, a, b; int main() { cin >> s >> n; for(int i = 0; i < n; i++) { cin >> t; if(t == "print") cin >> a >> b, cout << s.substr(a, b - a + 1) << endl; if(t == "reverse") cin >> a >> b, reverse(s.begin() + a, s.begin() + b + 1); if(t == "replace") cin >> a >> b >> u, s.replace(a, b - a + 1, u); } return 0; }
#include <bits/stdc++.h> #include<string> typedef long long int ll; typedef unsigned long long ull; typedef long double ld; #define F first #define S second #define pb push_back #define pll pair<ll,ll> #define pii pair<int,int> #define len(s) s.length() #define all(v) v.begin(),v.end() const ll INF = LONG_MAX; const int N = 2e5 + 5; const ll mod = 1000000007 ; using namespace std; ld dp[15][15]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); ll tc = 1; // cin >> tc; while (tc--) { ll m; ll i, j; ll n; ll k; ll h1, m1, h2, m2; cin >> h1 >> m1 >> h2 >> m2 >> k; ll ans = (h2 * 60 + m2 - (h1 * 60 + m1) - k); cout << ans << endl; } }
0
#include<cstdio> #include<string> #include<map> #include<algorithm> using namespace std; int main() { int n,i,p,a,b,c,d,e,f,m,s; char l[32]; pair<double,string>A[50]; while(scanf("%d",&n),n) { for(i=0;i<n;++i) { scanf("%s%d%d%d%d%d%d%d%d%d",l,&p,&a,&b,&c,&d,&e,&f,&s,&m); A[i].second=l; A[i].first=-(f*s*m-p)/double(a+b+c+m*(d+e)); } sort(A,A+n); for(i=0;i<n;++i)puts(A[i].second.c_str()); puts("#"); } return 0; }
#include<algorithm> #include<iostream> #include<string> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> using namespace std; int main(){ /* cout<< ("onion">"potato") <<endl; return 0; */ int h,i,j; int y[50],z[50],n,p,a,b,c,d,e,f,s,m; string l[50]; while(cin>>n&&n){ for(i=0;i<n;i++){ cin>>l[i]>>p>>a>>b>>c>>d>>e>>f>>s>>m; y[i]=f*s*m-p; z[i]=a+b+c+(d+e)*m; } h=1; for(i=0;h;i++){ h=0; for(j=1;j<n-i;j++){ if(y[j-1]*z[j]<y[j]*z[j-1]){ swap(y[j-1],y[j]); swap(z[j-1],z[j]); swap(l[j-1],l[j]); h=1; }else if(y[j-1]*z[j]==y[j]*z[j-1]){ if(l[j-1]>l[j]){ swap(y[j-1],y[j]); swap(z[j-1],z[j]); swap(l[j-1],l[j]); h=1; } } } } for(i=0;i<n;i++) cout<<l[i]<<endl; cout<<"#"<<endl; } return 0; }
1
#include <iostream> using namespace std; long long sum(int size,int ary[]); int min(int size,int ary[]); int max(int size,int ary[]); int main(){ int size=0; cin >>size; int nums[size]; for(int i=0;i<size;i++){ cin >> nums[i]; } int a=0,b=0; long long c=0; a=min(size,nums); b=max(size,nums); c=sum(size,nums); cout <<a<<" "<<b<<" "<<c<<endl; return 0; } long long sum(int size,int ary[]){ long long ret=0; for(int i=0;i<size;i++){ ret +=ary[i]; } return ret; } int min(int size,int ary[]){ int ret=ary[0]; for(int i=1;i<size;i++){ if(ary[i]<ret) ret = ary[i]; } return ret; } int max(int size,int ary[]){ int ret=ary[0]; for(int i=1;i<size;i++){ if(ary[i]>ret) ret = ary[i]; } return ret; }
#include <bits/stdc++.h> #define TOP 0 #define FRONT 1 #define LEFT 2 #define RIGHT 3 #define BACK 4 #define BOTTOM 5 using namespace std; //TOP,FRONT,LEFT,RIGHT,BACK,BOTTOM int dice[6]={1,2,4,3,5,6}; //?\\?????¢?????? void rotN(){ swap(dice[TOP],dice[FRONT]); swap(dice[FRONT],dice[BOTTOM]); swap(dice[BOTTOM],dice[BACK]); } //???????????¢?????? void rotS(){ //rotN(),rotN(),rotN(); swap(dice[TOP],dice[BACK]); swap(dice[BACK],dice[BOTTOM]); swap(dice[BOTTOM],dice[FRONT]); } //????????¢?????? void rotE(){ swap(dice[TOP],dice[LEFT]); swap(dice[LEFT],dice[BOTTOM]); swap(dice[BOTTOM],dice[RIGHT]); } //????????¢?????? void rotW(){ //rotE(),rotE(),rotE(); swap(dice[TOP],dice[RIGHT]); swap(dice[RIGHT],dice[BOTTOM]); swap(dice[BOTTOM],dice[LEFT]); } //???????????????????¨???????????????? void rotCW(){ swap(dice[FRONT],dice[RIGHT]); swap(dice[RIGHT],dice[BACK]); swap(dice[BACK],dice[LEFT]); } //??????????????????????¨??????????????????? void rotCCW(){rotCW(),rotCW(),rotCW();} int main(){ cin>>dice[TOP]>>dice[FRONT]>>dice[RIGHT]; cin>>dice[LEFT]>>dice[BACK]>>dice[BOTTOM]; string str; cin>>str; for(int i=0;i<str.size();i++){ if(str[i]=='N') rotN(); if(str[i]=='S') rotS(); if(str[i]=='E') rotE(); if(str[i]=='W') rotW(); } cout << dice[TOP]<<endl; }
0
#include <iostream> #include <vector> #include <climits> #include <algorithm> #include <cmath> #include <map> #include <set> #include <string> #include <bitset> #include <utility> #include <numeric> #include <queue> #include <stack> using ll = long long; using namespace std; constexpr int MOD = 1e9 + 7; constexpr ll MOD_LL = ll(1e9) + 7; int main(void) { int n, k; cin >> n >> k; if( n % k == 0 ) cout << 0 << endl; else cout << 1 << endl; return 0; }
#include <iostream> #include <string> #include <cstring> #include <algorithm> #include <iomanip> #include <vector> #include <cmath> #define endl "\n" using namespace std; void solve() { int x,y; cin >> x >> y; cout << x*y; } int main() { ios::sync_with_stdio(0); cin.tie(0); solve(); }
0
#include <bits/stdc++.h> using namespace std; using int64 = long long; constexpr int DEBUG = 0; template<typename T> vector<vector<T>> Make2DVector(int d1, int d2, T default_value) { return vector<vector<T>>(d1, vector<T>(d2, default_value)); } // Vector template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) { int len = v.size(); s << "["; for (int i = 0; i < len; i++) { if (i > 0) s << ", "; s << v[i]; } s << "]"; return s; } template<class T> inline bool UpdateMin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class T> inline bool UpdateMax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } int SolveMaxRectangle(const vector<int>& input_xs, int w) { vector<int> xs(input_xs.begin(), input_xs.end()); xs.push_back(0); int max = w; stack<pair<int, int>> stack; for (int i = 0; i < xs.size(); i++) { if (stack.empty()) { stack.push(make_pair(xs[i], i)); } else { if (xs[i] >= stack.top().first) { stack.push(make_pair(xs[i], i)); } else { int push_index = i; while (!stack.empty() && xs[i] < stack.top().first) { int r_width = i - stack.top().second + 1; int r_area = r_width * stack.top().first; UpdateMax(max, r_area); push_index = stack.top().second; // if (DEBUG) { // cout << "i: " << i << endl; // cout << "stack.top().second: " << stack.top().second << endl; // cout << "v: " << stack.top().first << endl; // cout << "r_area: " << r_area << endl; // } stack.pop(); } stack.push(make_pair(xs[i], push_index)); } } } return max; } int main() { ios::sync_with_stdio(false); cin.tie(0); int h, w; cin >> h >> w; vector<string> board(h); for (int r = 0; r < h; r++) { cin >> board[r]; } vector<vector<int>> dp1 = Make2DVector(h - 1, w, -1); for (int r = 0; r < h - 1; r++) { int current = -1; for (int c = w - 1; c >= 0; c--) { if (c == w - 1) { current = board[r][c] == board[r + 1][c]; dp1[r][c] = 1; } else { if ((board[r][c] == board[r + 1][c]) == current) { dp1[r][c] = dp1[r][c + 1] + 1; } else { current = board[r][c] == board[r + 1][c]; dp1[r][c] = 1; } } } } if (DEBUG) { for (int r = 0; r < h - 1; r++) { cout << "dp1[" << r << "]: " << dp1[r] << endl; } } int ans = 0; for (int c = 0; c < w; c++) { vector<int> xs(h - 1); for (int r = 0; r < h - 1; r++) { xs[r] = dp1[r][c]; } if (DEBUG) { cout << "SolveMaxRectangle(" << c << ")" << endl; cout << "xs: " << xs << endl; } int max_rectanle = SolveMaxRectangle(xs, w - c); if (DEBUG) cout << "c: " << c << " max_rectangle: " << max_rectanle << endl; UpdateMax(ans, max_rectanle); } cout << ans << endl; }
/* Writer: SPD_9X2 https://atcoder.jp/contests/arc081/tasks/arc081_d 長方形にできる必要十分条件は、 内側にある四つ角の周り全てに関して、周りにある黒が偶数個 →そのような条件を満たす四つ角グリッドを考えると最大長方形になる 幅1の長方形に関しては全て作れるので、ans初期値はmax(H,W) */ #include <bits/stdc++.h> using namespace std; #define rep(i,n,m) for(int (i)=(n);(i)<(m);(i)++) #define rrep(i,n,m) for(int (i)=(n);(i)>(m);(i)--) using ll = long long; const ll mod = 1000000007; const ll half = 500000004; int LRIH(vector<int>& lis){ vector<vector<int>> stk(0); int ans = 0; int N = lis.size(); rep(i,0,N){ if (stk.size() == 0){ stk.push_back({lis[i],i}); }else if (stk[stk.size()-1][0] < lis[i]){ stk.push_back({lis[i],i}); }else if (stk[stk.size()-1][0] > lis[i]){ int lastpos = -1; while ( (stk.size()>0) && (stk[stk.size()-1][0] > lis[i])){ int nh = stk[stk.size()-1][0]; int np = stk[stk.size()-1][1]; lastpos = np; stk.pop_back(); ans = max(ans , (nh+1)*(i-np+1)); } stk.push_back({lis[i] , lastpos}); } } return ans; } int main(){ int H,W; cin >> H >> W; vector<vector<char>> S(H,vector<char> (W)); rep(i,0,H){ rep(j,0,W){ cin >> S[i][j]; } } vector<vector<int>> lis(H-1,vector<int> (W-1,0)); rep(i,0,H-1){ rep(j,0,W-1){ if (S[i][j] == '#') lis[i][j] += 1; if (S[i+1][j] == '#') lis[i][j] += 1; if (S[i][j+1] == '#') lis[i][j] += 1; if (S[i+1][j+1] == '#') lis[i][j] += 1; lis[i][j] %= 2; } } vector<vector<int>> hist(H-1,vector<int> (W,0)); rep(i,0,H-1){ rep(j,0,W-1){ if (lis[i][j] == 0){ if (i==0){ hist[i][j] = 1; }else{ hist[i][j] = hist[i-1][j] + 1; } } } } int ans = max(H,W); rep(i,0,H-1){ ans = max(ans , LRIH(hist[i])); } cout << ans << endl; }
1
#include <cstdio> #include <cstring> #include <algorithm> inline int read() { int data = 0, w = 1; char ch = getchar(); while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar(); if (ch == '-') w = -1, ch = getchar(); while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar(); return data * w; } const int N(100010); int a[N], cnt[2], n; void trans() { for (int i = 1; i <= n; i++) if (a[i] & 1) --a[i]; int g = a[1]; for (int i = 2; i <= n; i++) g = std::__gcd(g, a[i]); for (int i = 1; i <= n; i++) a[i] /= g; } int check() { cnt[0] = cnt[1] = 0; for (int i = 1; i <= n; i++) ++cnt[a[i] & 1]; if (cnt[0] & 1) return 1; else if (cnt[1] > 1) return 0; else { for (int i = 1; i <= n; i++) if (a[i] == 1) return cnt[0] & 1; return trans(), check() ^ 1; } } int main() { n = read(); for (int i = 1; i <= n; i++) a[i] = read(); puts(check() ? "First" : "Second"); return 0; }
#include <iostream> #include <string> using namespace std; string line; int str_len; bool is_finish() { for(int i=0; i<str_len-3; i++) { if(line[i] == 't') { if(line[i+1] == 'h') { if(line[i+2] == 'e') { return true; } else if(line[i+2] == 'i' && line[i+3] == 's') { return true; } else if(line[i+2] == 'a' && line[i+3] == 't') { return true; } } } } return false; }; int main() { while(getline(cin, line)) { str_len = line.length(); for(int j=0; j<26; j++) { if(is_finish()) { cout << line << endl; break; } for(int j=0; j<str_len; j++) { if('a' <= line[j] && line[j] < 'z') { line[j] += 1; } else if(line[j] == 'z') { line[j] = 'a'; } } } } return 0; }
0
#include<iostream> using namespace std; int main(){ int n; cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i]; for(int i=n-1;i>=0;i--) { if(i==0)cout<<a[i]; else cout<<a[i]<<' '; } cout<<endl; }
#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++) { if (j == n-1) { printf("%d", ary[j]); } else { printf("%d ", ary[j]); } } printf("\n"); delete[] ary; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { long long v, a, b, c, d, e; cin >> v >> a >> b >> c >> d >> e; long long slow = min({a, b, c, d, e}); cout << (v + slow-1)/ slow + 4; return 0; }
#include<iostream> #include<stdio.h> //#include <bits/stdc++.h> #include<vector> #include<float.h> #include<iomanip> #include<algorithm> #include<string> #include<cstring> #include<math.h> #include<cmath> #include<sstream> #include<set> #include<map> #include<queue> #include<cassert> #include<cmath> #include<cstdint> #define INF 1e9 #define LINF 1e19 #define rep(i,n)for(int i=0;(i)<(int)(n);i++) #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++) #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i; #define vec(type,n) vector<type>(n) #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n)) #define ALL(a) (a).begin(),(a).end() #define chmin(a, b) a = min(a, b) #define chmax(a, b) a = max(a, b) using namespace std; using ll = long long; using Graph = vector<vector<int>>; using P = pair<ll, ll>; const ll MOD = 1e9 + 7; //最大公約数 ll gcd(ll a, ll b){ if(b == 0)return a; else return gcd(b, a % b); } int main(){ ll n; cin >> n; vector<ll> a(5); ll m = INF * INF; rep(i, 5){ cin >> a[i]; chmin(m, a[i]); } ll res = (n + m - 1) / m + 4; cout << res << endl; }
1
// C++ 14 #include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) os << ", "; } os << "]"; return os; } template <typename T> void print(T v, string s = "\n") { cout << v << s; } template <typename T> void in(T &v) { cin >> v; } #define ll long long #define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++) int G[500][500]; int ACC[501][501]; int main() { int n, m, q; in(n),in(m),in(q); loop(i,0,m) { int l, r; in(l),in(r); l--;r--; G[l][r]++; } loop(y,0,n) { loop(x,0,n) { ACC[y+1][x+1] = ACC[y+1][x] + ACC[y][x+1] - ACC[y][x] + G[y][x]; } } // loop(y,0,n+1) { // loop(x,0,n+1) { // print(ACC[y][x], " "); // } // print(""); // } loop(i,0,q) { int l,r; in(l),in(r); int cnt = ACC[r][r]; cnt += ACC[l-1][l-1]; cnt -= ACC[l-1][r]; cnt -= ACC[r][l-1]; // print(ACC[r][r]); // print(ACC[l-1][l-1]); // print(ACC[l-1][r]); // print(ACC[r][l-1]); print(cnt); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const static ll INF = LLONG_MAX; #define rep(i, n) for (int i = 0; i < (int)(n); i++) // __uint128_t const ll MOD = 1e9+7; int main(){ ll N, K; cin >> N >> K; vector<ll> A(N+1); for(int i = 0; i < N; i++) cin >> A[i]; while(K--){ vector<ll> A_(N+1); for(int i = 0; i < N; i++){ ll l = i-A[i], r = i + A[i]; l = max(l, 0LL), r = min(r, N-1); A_[l]++; A_[r+1]--; } ll t = 0; bool flag = true; for(int i = 0; i < N; i++) { t += A_[i]; A[i] = t; if(flag && A[i] != N) flag = false; } if(flag) break; } for(int i = 0; i < N; i++) cout << A[i] << " "; cout << endl; }
0
#include <bits/stdc++.h> #include <math.h> #define _GLIBCXX_DEBUG #define _LIBCPP_DEBUG 0 using namespace std; #define ll long long #define rep(i,n) for (int i = 0; i < n; i++) #define rrep(i,n) for (int i = n-1; i >= 0; i--) #define MOD (1000000007) #define vi vector<int> #define vl vector<ll> #define vb vector<bool> #define vvi vector<vi> #define vvl vector<vl> #define pii pair<int, int> #define pli pair<ll, int> #define pb push_back #define mp make_pair #define all(a) (a).begin(),(a).end() template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } ll keta(ll n){ string s = to_string(n); ll num = s.size(); return num; } const ll INF = 1LL << 60; const int dh[4] = {1,0,-1,0}; const int dw[4] = {0,1,0,-1}; struct Edge{ int to; int weight; Edge(int t, int w) : to(t), weight(w){} }; using Graph = vector<vector<Edge>>; using P = pair<ll, int>; class UnionFind{ public: vi Parent; UnionFind(int n){ Parent = vi(n,-1); } int root(int a){ if(Parent[a] < 0) return a; return Parent[a] = root(Parent[a]); } bool issame(int a, int b){ return root(a) == root(b); } int size(int a){ return -Parent[root(a)]; } bool merge(int a, int b){ a = root(a); b = root(b); if(a == b) return false; if(size(a) < size(b)) swap(a,b); Parent[a] += Parent[b]; Parent[b] = a; return true; } }; vi MP(string s){ vi A(s.size()+1); A[0] = -1; int j = -1; rep(i,s.size()) { while(j >= 0 && s[i] != s[j]) j = A[j]; j++; A[i+1] = j; } return A; } vi Manacher(string s){ vi R(s.size()); int i = 0, j = 0; while(i < s.size()){ while(i-j >= 0 && i+j < s.size() && s[i-j] == s[i+j]) ++j; R[i] = j; int k = 1; while(i-k >= 0 && i+k < s.size() && k+R[i-k] < j) R[i+k] = R[i-k], k++; i += k; j -= k; } return R; } vi Z_algorithm(string &s){ vi Z(s.size()); Z[0] = s.size(); int i = 1, j = 0; while(i < s.size()){ while(i+j < s.size() && s[j] == s[i+j]) j++; Z[i] = j; if(j == 0){++i; continue;} int k = 1; while(i+k < s.size() && k+Z[k] < j) Z[i+k] = Z[k], ++k; i += k; j -= k; } return Z; } const int MAX = 1e6+1; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(ll n, ll k){ if(n >= MAX){ ll tmp = 1; rep(i,k){ tmp *= (n-i); tmp %= MOD; } return tmp*finv[k]%MOD; } if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll POW(ll x, ll n){ ll ret = 1; if(n < 0){// n < 0 にも対応 n *= -1; x = inv[x]; } while(0 < n){ if(n%2 == 0){ x = x*x%MOD; n /= 2; } else{ ret = ret*x%MOD; n--; } } return ret; } int main(){ int A, B; cin >> A >> B; A--; B--; int H, W; H = W = 100; char a[H][W]; rep(h,H) rep(w,W) { if(h < H/2) a[h][w] = '#'; else a[h][w] = '.'; } for(int h = 0; h < H; h += 2) for(int w = 0; w < W; w += 2) { if(h < H/2 && A > 0){ a[h][w] = '.'; A--; } if(h > H/2 && B > 0){ a[h][w] = '#'; B--; } } printf("%d %d\n", H, W); rep(h,H) rep(w,W) { cout << a[h][w]; if(w == W-1) cout << endl; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define zero_pad(num) setfill('0') << std::right << setw(num) using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; int main() { int a, b; cin >> a >> b; vector<string> ans(100, ""); for(int i = 0; i < 50; i++) { rep(j, 100) ans[i] += "#"; } for(int i = 50; i < 100; i++) { rep(j, 100) ans[i] += '.'; } a--; b--; for(int i = 1; i < 50; i += 2){ if(a == 0) break; for(int j = 1; j < 100; j += 2){ if(a == 0) break; ans[i][j] = '.'; a--; } } for(int i = 51; i < 100; i += 2){ if(b == 0) break; for(int j = 1; j < 100; j += 2){ if(b == 0) break; ans[i][j] = '#'; b--; } } cout << "100 100" << endl; rep(i, 100) cout << ans[i] << endl; }
1
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; int x = 1; for (int i = 0;N > i;i++){ cin >> x; if (x < K){ x *= 2; } else{ x += K; } } cout << x << endl; }
#include <bits/stdc++.h> using namespace std; int main () { int N,K,A; cin >> N >> K; A = 1; for (int i=0;i<N;i++) { if ( A*2 < A + K ) A = A*2; else A = A + K; } cout << A << endl; }
1
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define mp make_pair #define pb push_back #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair<ll,ll> ii; typedef vector<int> vi; typedef long double ld; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; const long long mod = 1000000007; const long long inf = 1e18; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll n; cin>>n; for(ll i=n;i>=0;i--){ int k=sqrt(i); if(k*k==i){ cout<<i<<endl; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define SELECTER(_1, _2, _3, SELECT, ...) SELECT #define REP1(i, n) for(int (i)=0; (i)<(n); (i)++) #define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++) #define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__) #define MOD 1000000007 template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; } template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; } int dp[1111111][2]; int main(){ string S; cin >> S; int N = S.size(); S += '0'; for(int i=0; i<1111111; i++) dp[i][0] = dp[i][1] = 1<<30; dp[0][0] = 0; for(int i=0; i<N; i++){ int d = S[N-1-i] - '0'; dp[i+1][0] = min(dp[i+1][0], dp[i][0] + d); dp[i+1][1] = min(dp[i+1][1], dp[i][0] + (10 - d)); dp[i+1][0] = min(dp[i+1][0], dp[i][1] + (d + 1)); dp[i+1][1] = min(dp[i+1][1], dp[i][1] + (10 - (d + 1))); } int ans = min(dp[N][0], dp[N][1] + 1); cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> #define rep(i,n)for(long long i=0;i<(long long)(n);++i) #define all(a) a.begin(), a.end() using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } const int MOD=1e9+7; const ll INF=1e18; const int MAX=510000; const double pi=acos(-1); int dx[8] = {1,0,-1,0,1,1,-1,-1}; int dy[8] = {0,1,0,-1,-1,1,1,-1}; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n,q; cin >> n >> q; vector<tuple<int,int,int>> stx(n); rep(i,n){ cin >> get<1>(stx[i]) >> get<2>(stx[i]) >> get<0>(stx[i]); } sort(stx.begin(),stx.end()); set<P> st; rep(i,q){ int x; cin >> x; st.emplace(x,i); } vector<int> ans(q,-1); rep(i,n){ int s = get<1>(stx[i]); int t = get<2>(stx[i]); int x = get<0>(stx[i]); //xの昇順で考えてぶつかったら,その人をerase auto first = st.lower_bound(P(s-x,0));//引っかかる人 auto end = st.upper_bound(P(t-x-1,q));//引っかからない人 for(auto it = first; it !=end; ++it) ans[it->second] = x; st.erase(first,end); } rep(i,q) cout << ans[i] << endl; return 0; }
#include <bits/stdc++.h> #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 all(x) (x).begin(),(x).end() #define SZ(x) ((int)(x).size()) #define bit(n) (1<<(n)) using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<bool> vb; typedef pair<int, int> pii; typedef pair<ll, ll> pll; 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 const INF = 1001001001; int main() { cin.tie(0); ios::sync_with_stdio(false); int N,Q; cin >> N >> Q; map<int,vi> add; map<int,vi> era; map<int,int> mp; rep(i,N) { int s,t,x; cin >> s >> t >> x; add[max(0,s-x)].push_back(x); era[max(1,t-x)].push_back(x); mp[max(0,s-x)] = 0; mp[max(1,t-x)] = 0; } rep(i,Q) { int d; cin >> d; mp[d] = 1; } set<int> st; for(auto x : mp) { for(auto erx : era[x.first]) { st.erase(erx); } for(auto adx : add[x.first]) { st.insert(adx); } if(x.second == 1) { if(!st.empty()) { cout << *st.begin() << endl; } else { cout << -1 << endl; } } } return 0; }
1
#include <bits/stdc++.h> using namespace std; template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; for(auto v:V)os << v << " "; return os << "]"; } template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}"; } template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) { return os<<"("<<P.first<<","<< P.second << ")"; } template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) { os<<"{ ";for(auto m:M)os<<"("<<m.F<<":"<<m.S<<")"; return os<<"}"; } #define cerr cout #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << std::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...); } #else #define trace(...) 1 #endif #define ll long long #define ld long double #define vll vector<ll> #define pll pair<ll,ll> #define vpll vector<pll> #define I insert #define pb push_back #define F first #define S second #define endl "\n" #define mp make_pair #define all(v) (v).begin(),(v).end() #define For(i,n) for(int i=0;i<(int)n;++i) #define Rev(i,n) for(int i=(int)n-1;i>=0;--i) #define Rep(i,n) for(int i=1;i<=(int)n;++i) typedef vector<int> vi; typedef pair<int,int> pii; typedef pair<pii,int> ppi; typedef vector<pii> vpii; #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) const int N = 1e6 + 100; const int INF = 1e9; int U[N] , V[N] , C[N]; int n , m; vpii G[N]; int dis[N]; int main(){ fio; cout<<fixed<<setprecision(25); cin >> n >> m; map<pii , int> exist; int idx = n+1 , u , v , c; for(int i = 1;i <= m;++i){ cin >> u >> v >> c; if(exist.find(mp(u , c)) == exist.end()){ exist[mp(u , c)] = idx++; } if(exist.find(mp(v , c)) == exist.end()){ exist[mp(v , c)] = idx++; } G[u].pb(mp(exist[mp(u , c)] , 1)); G[exist[mp(u , c)]].pb(mp(u , 0)); G[v].pb(mp(exist[mp(v , c)] , 1)); G[exist[mp(v , c)]].pb(mp(v , 0)); G[exist[mp(u , c)]].pb(mp(exist[mp(v , c)] , 0)); G[exist[mp(v , c)]].pb(mp(exist[mp(u , c)] , 0)); } for(int i =1 ;i < idx ; ++i){ dis[i] = INF; } deque<pii> Q; // priority_queue<pair<pii, int> , vector<pair<pii,int> > , greater<pair<pii,int> > >Q; // Q.push(mp(mp(0 , -1) , 1)); Q.pb(mp(0 , 1)); dis[1] = 0; //it.F is distance //it.S is vertex while(Q.size() > 0){ auto it = Q.front(); // trace(it); if(it.S == n){ cout << it.F << endl; return 0; } Q.pop_front(); for(auto e : G[it.S]){ int w = e.S + it.F; if(dis[e.F] > w){ dis[e.F] = w; if(e.S == 1){ Q.pb(mp(dis[e.F] , e.F)); } else{ Q.push_front(mp(dis[e.F] , e.F)); } } } } cout << -1 << endl; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 #define MAXN 400005 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 +c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } struct node { int to,next,val; }E[MAXN * 10]; int head[MAXN],sumE; int N,M,Ncnt; int c[MAXN],dis[MAXN]; vector<int> to[MAXN]; bool vis[MAXN]; priority_queue<pii > Q; void add(int u,int v,int c) { E[++sumE].to = v; E[sumE].next = head[u]; E[sumE].val = c; head[u] = sumE; } void Solve() { read(N);read(M); int q,p; Ncnt = M; for(int i = 1 ; i <= M ; ++i) { read(q);read(p);read(c[i]); to[q].pb(i);to[p].pb(i); } for(int i = 1 ; i <= N ; ++i) { sort(to[i].begin(),to[i].end(),[](int a,int b) {return c[a] < c[b];}); int nw = ++Ncnt; for(int j = 0 ; j < to[i].size() ; ++j) { int p = j; while(p < to[i].size() - 1 && c[to[i][p + 1]] == c[to[i][j]]) ++p; for(int h = j + 1 ; h <= p ; ++h) { add(to[i][j],to[i][h],0); add(to[i][h],to[i][j],0); } add(to[i][j],nw,0); add(nw,to[i][j],1); j = p; } } for(int i = 1 ; i <= Ncnt ; ++i) dis[i] = 1e9; for(auto t : to[1]) {dis[t] = 1;Q.push(mp(-1,t));} while(!Q.empty()) { pii now = Q.top();Q.pop(); if(vis[now.se]) continue; int u = now.se;vis[u] = 1; for(int i = head[u] ; i ; i = E[i].next) { int v = E[i].to; if(dis[v] > dis[u] + E[i].val) { dis[v] = dis[u] + E[i].val; Q.push(mp(-dis[v],v)); } } } int ans = 1e9; for(auto t : to[N]) ans = min(ans,dis[t]); if(ans >= 1e9) { puts("-1");return; } else {out(ans);enter;} } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; }
1
#include <bits/stdc++.h> using namespace std; #define REP(i, N) for (int i = 0; i < (int)N; i++) #define FOR(i, a, b) for (int i = a; i < (int)b; i++) #define ALL(x) (x).begin(), (x).end() #define INF (1 << 30) #define LLINF (1LL << 62) #define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__) constexpr int MOD = 1000000007; using ll = long long; using Pii = pair<int, int>; using Pll = pair<ll, ll>; template <class T> string to_string(T s); template <class S, class T> string to_string(pair<S, T> p); string to_string(string s) { return s; } string to_string(const char s[]) { return to_string(string(s)); } template <class T> string to_string(T v) { if (v.empty()) return "{}"; string ret = "{"; for (auto x : v) ret += to_string(x) + ","; ret.back() = '}'; return ret; } template <class S, class T> string to_string(pair<S, T> p) { return "{" + to_string(p.first) + "," + to_string(p.second) + "}"; } void debug() { cerr << endl; } template <class Head, class... Tail> void debug(Head head, Tail... tail) { cerr << to_string(head) << " "; debug(tail...); } struct IO { #ifdef _WIN32 inline char getchar_unlocked() { return getchar(); } inline void putchar_unlocked(char c) { putchar(c); } #endif string separator = " "; template <class T> inline void read(T& x) { char c; do { c = getchar_unlocked(); } while (c != '-' && (c < '0' || '9' < c)); bool minus = 0; if (c == '-') { minus = 1; c = getchar_unlocked(); } x = 0; while ('0' <= c && c <= '9') { x *= 10; x += c - '0'; c = getchar_unlocked(); } if (minus) x = -x; } inline void read(string& x) { char c; do { c = getchar_unlocked(); } while (c == ' ' || c == '\n'); x.clear(); do { x += c; c = getchar_unlocked(); } while (c != ' ' && c != '\n' && c != EOF); } template <class T> inline void read(vector<T>& v) { for (auto& x : v) read(x); } template <class Head, class... Tail> inline void read(Head& head, Tail&... tail) { read(head); read(tail...); } template <class T> inline void write(T x) { char buf[32]; int p = 0; if (x < 0) { x = -x; putchar_unlocked('-'); } if (x == 0) putchar_unlocked('0'); while (x > 0) { buf[p++] = (x % 10) + '0'; x /= 10; } while (p) { putchar_unlocked(buf[--p]); } } inline void write(string x) { for (char c : x) putchar_unlocked(c); } inline void write(const char s[]) { for (int i = 0; s[i] != 0; ++i) putchar_unlocked(s[i]); } template <class T> inline void write(vector<T> v) { for (auto itr = v.begin(); itr + 1 != v.end(); ++itr) { write(*itr); write(separator); } write(v.back()); } template <class Head, class... Tail> inline void write(Head head, Tail... tail) { write(head); write(separator); write(tail...); } template <class Head, class... Tail> inline void writeln(Head head, Tail... tail) { write(head, tail...); write("\n"); } void set_separator(string s) { separator = s; } } io; int main() { int N; string S; io.read(N, S); using Pss = pair<string, string>; map<Pss, ll> left, right; ll ans = 0; REP(b, 1 << N) { string l_r, l_b, r_r, r_b; REP(i, N) if ((b >> i) & 1) { l_r += S[i]; r_r += S[2 * N - 1 - i]; } else { l_b += S[i]; r_b += S[2 * N - 1 - i]; } left[Pss(l_r, l_b)]++; right[Pss(r_r, r_b)]++; } for (auto l : left) ans += l.second * right[Pss(l.first.second, l.first.first)]; io.writeln(ans); return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <cassert> #include <string> #include <cstring> #include <vector> #include <list> #include <map> #include <set> #include <stack> #include <queue> #include <algorithm> using namespace std; // --------------------- // repetition #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; // --------------------- #define INF 922337203685477580 typedef long long ll; int main() { int n; cin >> n; int G[n][n]; int visited[n]; int d[n]; int p[n]; REP(y, n) { REP(x, n) { int cost; cin >> cost; if (cost == -1) { G[y][x] = 1 << 15; } else { G[y][x] = cost; } } visited[y] = 0; d[y] = 1 << 15; p[y] = -1; } d[0] = 0; REP(_, n) { int mincost = 1 << 15; int minv = -1; REP(v, n) { if (!visited[v] && d[v] < mincost) { minv = v; mincost = d[v]; } } visited[minv] = 1; REP(to, n) { if (!visited[to] && G[minv][to] < (1 << 15) && G[minv][to] < d[to]) { d[to] = G[minv][to]; p[to] = minv; } } } ll sum = 0; REP(i, n) { if (p[i] != -1) { sum += G[i][p[i]]; } } cout << sum << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<n; i++) #define all(vec) vec.begin(),vec.end() using vi = vector<int>; using vvi = vector<vi>; using ll = long long; int jd(vi D, int N){ while(N > 0){ for(int x : D){ if (N%10 == x ){ return 0; } } N /= 10; } return 1; } int main() { int N, K; cin >> N >> K; vi D(K); rep(i,K) cin >> D[i]; int ans=0; while(ans <= 0){ ans = jd(D, N); if(ans==0) N++; } cout << N << endl; }
#include<algorithm> #include<iostream> #include<vector> #include<string> #include<queue> #include<stack> #include<cmath> #include<list> #include<set> #include<map> using namespace std; long long MOD = 1000000007LL; const double PI = 3.14159265358979323846; #undef INT_MIN #undef INT_MAX #define INT_MIN -2147483648 #define INT_MAX 2147483647 #define endl "\n" int main() { int N; cin >> N; int K; cin >> K; map<char, bool> mp; for (int i = 0; i < K; ++i) { char a; cin >> a; mp[a] = true; } for (int i = N; i < N * 100; ++i) { string s = to_string(i); bool flags = 0; for (int j = 0; j < s.length(); ++j) { if (mp[s[s.length() - j - 1]] == 1) { flags = 1; break; } } if (!flags) { cout << i << endl; return 0; } } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int a, b, k; cin >> a >> b >> k; for (int i = 0; i < k; i++) { if (i%2 == 0) { if (a%2==1) a--; b += a/2; a /= 2; } else { if (b%2==1) b--; a += b/2; b /= 2; } } printf ("%d %d",a,b); }
// ref: https://img.atcoder.jp/abc113/editorial.pdf // ref: https://atcoder.jp/contests/abc113/submissions/3540482 //#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; typedef int64_t int64; typedef uint32_t uint; typedef uint64_t uint64; //--- template <typename T> inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; } template <typename T> inline void print(const std::vector<T>& rhs){ std::cout<<" = [ "; for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; } std::cout<<"]"<<std::endl; } template <typename T> inline void print(const std::vector<std::vector<T>>& rhs){ std::cout<<" = "<<std::endl; std::cout<<"[[ "; for(uint p=0; p<rhs.size(); ++p){ if(p!=0){ std::cout<<" [ "; } for(uint q=0; q<rhs[p].size(); ++q){ std::cout<<rhs[p][q]<<' '; } if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; } } std::cout<<"]]"<<std::endl; } template <typename TL, typename TR> inline void print(const std::vector<std::pair<TR,TL>>& rhs){ std::cout<<" = ["; uint i=0; for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; } std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl; } #define printn(var) {printf("%s", #var);print(var);} #define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);} //--- int main(){ // ios_base::sync_with_stdio(false); // cin.tie(NULL); const int mod = 1000000007; int H, W, K; cin >> H >> W >> K; vector<vector<int>> dp(H+1, vector<int>(W, 0)); dp[0][0] = 1; for(int hi=0; hi<H; ++hi){ for(int wi=0; wi<W; ++wi){ for(int ls=0; ls< 1<<(W-1); ++ls){ // lines: ls bool isConnected=false; // check if the two horizontal lines are connected. for(int i=0; i<W-2; ++i){ if( (ls>>i)&1 && (ls>>(i+1))&1 ){ isConnected=true; break; } } if(isConnected){ continue; } if( wi>=1 && (ls>>(wi-1))&1 ){ dp[hi+1][wi-1] += dp[hi][wi]; dp[hi+1][wi-1] %= mod; }else if( wi<=W-2 && (ls>>wi)&1 ){ dp[hi+1][wi+1] += dp[hi][wi]; dp[hi+1][wi+1] %= mod; }else{ dp[hi+1][wi+0] += dp[hi][wi]; dp[hi+1][wi+0] %= mod; } } } } cout << dp[H][K-1] << endl; return 0; }
0
#include <stdio.h> int main() { int a; scanf("%d",&a); a=a*a*a; printf("%d\n",a); 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 irep(i, n) for(int i = n-1; i >= (int)0; i--) #define reprep(i,j,h,w) rep(i,h)rep(j,w) #define rrep(i,m,n) for(int i = m; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() #define aall(x,n) (x).begin(),(x).begin()+(n) #define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i]; #define pb push_back #define pf push_front #define lb lower_bound #define ub upper_bound #define fi first #define se second #define mp make_pair #define sum accumulate #define keta fixed<<setprecision #define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a)) #define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a))); #define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) )); typedef long long ll; const int INF = 2000000000; const ll INF64 = 1000000000000000ll; const ll MOD = 1000000007LL; int main(){ string s; std::cin >> s; std::cout << s.substr(0,s.size()-8) << std::endl; }
0
#include<bits/stdc++.h> template< typename G > struct StronglyConnectedComponents { using UnWeightedGraph=std::vector<std::vector<int>>; const G &g; UnWeightedGraph gg, rg; std::vector< int > comp, order, used; StronglyConnectedComponents(G &g) : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) { for(int i = 0; i < g.size(); i++) { for(auto e : g[i]) { gg[i].emplace_back((int) e); rg[(int) e].emplace_back(i); } } } int operator[](int k) { return comp[k]; } void dfs(int idx) { if(used[idx]) return; used[idx] = true; for(int to : gg[idx]) dfs(to); order.push_back(idx); } void rdfs(int idx, int cnt) { if(comp[idx] != -1) return; comp[idx] = cnt; for(int to : rg[idx]) rdfs(to, cnt); } void build(UnWeightedGraph &t) { for(int i = 0; i < gg.size(); i++) dfs(i); reverse(begin(order), end(order)); int ptr = 0; for(int i : order) if(comp[i] == -1) rdfs(i, ptr), ptr++; t.resize(ptr); for(int i = 0; i < g.size(); i++) { for(auto &to : g[i]) { int x = comp[i], y = comp[to]; if(x == y) continue; t[x].push_back(y); } } } }; int main(){ int N,M; std::cin>>N>>M; std::vector<std::vector<bool>> to(N,std::vector<bool>(N,false)); std::vector<std::vector<int>> graph(N),t; std::vector<int> ans; for(int _=0;_<M;++_){ int u,v; std::cin>>u>>v; u--;v--; if(ans.empty()){ graph[u].push_back(v); StronglyConnectedComponents<std::vector<std::vector<int>>> scc(graph); scc.build(t); std::vector<std::vector<int>> tmp(N); for(int i=0;i<N;++i) tmp[scc[i]].push_back(i); int ok=-1; for(int i=0;i<N;++i) if(tmp[i].size()>1) ok=i; if(ok!=-1){ int now=v; while(now!=u){ ans.push_back(now); for(auto e:graph[now]) if(scc[e]==ok){ now=e; break; } } ans.push_back(u); } for(int i=0;i<N;++i) if(to[v][i]) to[u][i]=true; } else if(std::find(ans.begin(),ans.end(),u)!=ans.end()&& std::find(ans.begin(),ans.end(),v)!=ans.end()){ int ch=std::find(ans.begin(),ans.end(),v)-ans.begin(); int sz=ans.size(); std::vector<int> tmp; while(ans[ch]!=u){ tmp.push_back(ans[ch]); ch=(ch+1)%sz; } tmp.push_back(u); ans=tmp; } } if(ans.empty()){ std::cout<<-1<<std::endl; return 0; } std::cout<<ans.size()<<std::endl; for(auto a:ans) std::cout<<a+1<<std::endl; }
#include<iostream> #include<algorithm> #include<vector> #include<cstdint> #include<cstdlib> template<typename T> void fin(T const& t){ std::cout << t << std::endl; exit(0); } uint64_t getZ() { uint64_t v = 0; int c; while((c = getchar_unlocked()) >= '0') v=v*10+c-'0'; return v; } template<int BUFSIZE> struct ans_buf { char buf[BUFSIZE]; int i; ans_buf(): i(0) {} void putZ(uint64_t v, char delim='\n') { uint64_t k = 1; while(k <= v/10) k*=10; for(; k>0; v%=k, k/=10) buf[i++] = (v/k)+'0'; buf[i++] = delim; } void out() { std::fwrite(buf, 1, i, stdout); } }; int const MAXN = 1000; int N, M; std::vector<int> G[MAXN]; bool used[MAXN]; int nv[MAXN], n; bool dfs(int v) { used[v] = true; for(auto c: G[v]) { nv[v] = c; if(c == n) return true; if(!used[c] && dfs(c)) return true; } return false; } int main() { N = getZ(); M = getZ(); for(int i = 0; i < M; ++i) G[getZ()-1].push_back(getZ()-1); for(int i = 0; i < N; ++i) { std::fill_n(used, N, false); if(dfs(n = i)) break; n = -1; } if(n < 0) fin(n); for(;;) { std::fill_n(used, N, false); used[n] = true; for(int k = nv[n]; k!=n; k=nv[k]) used[k] = true; bool ok = true; for(int i = 0; i < N; ++i) if(used[i]) { for(auto c: G[i]) if(used[c] && c != nv[i]) { nv[i] = n = c; ok = false; break; } if(!ok) break; } if(ok) break; } int ans = 0; for(int i = 0; i < N; ++i) if(used[i]) ++ans; ans_buf<4000> buf; buf.putZ(ans); for(int i = 0; i < N; ++i) if(used[i]) buf.putZ(i+1); buf.out(); return 0; }
1
# include<bits/stdc++.h> # include<ext/pb_ds/assoc_container.hpp> # include<ext/pb_ds/tree_policy.hpp> # pragma GCC optimize ("Ofast") # pragma GCC optimize ("unroll-loops") # pragma GCC optimize ("Ofast") using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; # define int long long typedef long long ll; typedef pair<int, int> pii; # define S second # define F first # define kill(x) return(cout << x << '\n', 0LL) # define debug(x) cerr<< #x << " = " << (x) << endl # define ddebug(x, y) cerr<< #x << " = " << (x) << ", " << #y << " = " << (y) << endl # define tdebug(x, y, z) cerr<< #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl # define bin(x) cerr<< #x << " : " << bitset<4>(x) << endl # define sz(s) (int)s.size() # define sq(x) (x) * (x) # define PB(x) push_back(x) # define smax(x, y) (x) = max((x), (y)) # define smin(x, y) (x) = min((x), (y)) # define all(x) x.begin(), x.end() # define SP fixed << setprecision(10) # define uop(x, y) pii(min(x, y), max(x, y)) const int MAXN = 2000 + 10; int MOD, fact[3 * MAXN], inv[3 * MAXN], r2[3 * MAXN], r3[3 * MAXN]; int _pow(int a, int p) { if (!p) return 1; return _pow(sq(a) % MOD, p >> 1) * (p & 1 ? a : 1) % MOD; } int rev(int a) { return _pow(a, MOD - 2); } int ch(int n, int k) { return fact[n] * inv[k] % MOD * inv[n - k] % MOD; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n >> MOD; fact[0] = 1; for (int i = 1; i <= n * 3 + 10; i ++) fact[i] = fact[i - 1] * i % MOD; for (int i = 0; i <= n * 3 + 10; i ++) { r2[i] = rev(_pow(2, i)); r3[i] = rev(_pow(3, i)); inv[i] = rev(fact[i]); } int ans = 0; for (int i = 0; i <= n; i ++) for (int j = i; i + (j - i) / 3 <= n; j += 3) { int k = n - i - (j - i) / 3; int x = ch(3 * n, j) * ch(3 * n - j, 2 * i) % MOD * fact[2 * i] % MOD * r2[i] % MOD * inv[i] % MOD * fact[3 * k] % MOD * r3[k] % MOD * inv[k] % MOD; ans = (ans + x) % MOD; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std::literals::string_literals; using i64 = std::int_fast64_t; using std::cout; using std::cerr; using std::endl; using std::cin; template<typename T> std::vector<T> make_v(size_t a){return std::vector<T>(a);} template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){ return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); } i64 pow(i64 x, i64 n, i64 m) { i64 ret = 1; while(n) { if(n & 1) (ret *= x) %= m; (x *= x) %= m; n >>= 1; } return ret; } i64 inv(i64 n, i64 m) { return pow(n, m - 2, m); } int main() { i64 n, m; scanf("%lld%lld", &n, &m); i64 N = 1; for(i64 i = 1; i <= 3 * n; i++) N = N * i % m; std::vector<int> tan(3 * n + 1); for(i64 i = 0; i < tan.size(); i++) tan[i] = inv(i, m); int offset = 3 * n; auto dp = make_v<int>(3 * n + 1, 6 * n + 1); dp[0][offset] = N; for(int i = 0; i < 3 * n; i++) { for(int j = 0; j < 6 * n; j++) { i64 from = dp[i][j]; if(!from) continue; if(i + 1 <= 3 * n) (dp[i + 1][j + 1] += from * tan[i + 1] % m) %= m; if(i + 2 <= 3 * n)(dp[i + 2][j - 1] += from * tan[i + 2] % m) %= m; if(i + 3 <= 3 * n)(dp[i + 3][ j ] += from * tan[i + 3] % m) %= m; } } i64 ans = 0; for(int i = offset; i < 6 * n + 1; i++) (ans += dp[3 * n][i]) %= m; printf("%lld\n", ans); return 0; }
1
#include <bits/stdc++.h> using namespace std; const int maxN = 200010; typedef long long ll; int vis[2][maxN]; vector<int> G[2][maxN]; queue<int> Q; void bfs(int u, int d, int c){ while(!Q.empty()) Q.pop(); vis[d][u] = c; Q.push(u); while(!Q.empty()){ u = Q.front(); Q.pop(); for(int i = 0; i < G[d][u].size(); ++i){ int v = G[d][u][i]; if(!vis[d][v]) vis[d][v] = c, Q.push(v); } } } map<ll, int> mp; int main (){ int n, k, l, u, v, i, c0 = 0, c1 = 0; scanf("%d%d%d", &n, &k, &l); while(k--){ scanf("%d%d", &u, &v); G[0][u].push_back(v); G[0][v].push_back(u); } while(l--){ scanf("%d%d", &u, &v); G[1][u].push_back(v); G[1][v].push_back(u); } for(i = 1; i <= n; ++i) if(!vis[0][i]) bfs(i, 0, ++c0); for(i = 1; i <= n; ++i) if(!vis[1][i]) bfs(i, 1, ++c1); for(i = 1; i <= n; ++i) ++mp[vis[0][i] * 1ll * maxN + vis[1][i]]; for(i = 1; i <= n; ++i){ printf("%d", mp[vis[0][i] * 1ll * maxN + vis[1][i]]); if(i < n) printf(" "); } return 0; }
#include "bits/stdc++.h" using namespace std; #define INF 1e9+7 int main(){ int n,m; while(1){ cin>>n>>m; if(n==0&&m==0)break; vector<vector<int> > cost(m,vector<int>(m,INF)); vector<vector<int> > timea(m,vector<int>(m,INF)); for(int i=0;i<n;i++){ int a,b; cin>>a>>b; a--; b--; cin>>cost[a][b]>>timea[a][b]; cost[b][a]=cost[a][b]; timea[b][a]=timea[a][b]; } for(int i=0;i<m;i++){ cost[i][i]=0; timea[i][i]=0; } for(int k=0;k<m;k++){ for(int i=0;i<m;i++){ for(int j=0;j<m;j++){ cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]); timea[i][j]=min(timea[i][j],timea[i][k]+timea[k][j]); } } } int k; cin>>k; for(int i=0;i<k;i++){ int p,q,r; cin>>p>>q>>r; p--; q--; if(r==0)cout<<cost[p][q]<<endl; if(r==1)cout<<timea[p][q]<<endl; } } return 0; }
0
#include <iomanip> #include <iostream> #include <algorithm> #include <cmath> #include <vector> using namespace std; using ld = long double; const ld PI = acos(-1); struct point { ld x, y; }; int main() { int N; cin >> N; vector<point> coo(N); for (auto& p : coo) cin >> p.x >> p.y; for (int i = 0; i < N; ++i) { vector<ld> degs; for (int j = 0; j < N; ++j) { if (i == j) continue; degs.push_back(atan2(coo[i].y - coo[j].y, coo[i].x - coo[j].x)); } sort(degs.begin(), degs.end()); degs.push_back(degs.front() + PI * 2); ld ans = 0; for (int j = 0; j < N; ++j) { ans = max(ans, degs[j + 1] - degs[j] - PI); } cout << fixed << setprecision(10) << ans / (PI * 2) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define elif else if typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pdd; const ll MOD = 1e9+7; const ll MOD2 = 998244353; const ll INF = LLONG_MAX; const string alpha = "abcdefghijklmnopqrstuvwxyz"; //点a,bの距離の2乗 ld dist2(pdd a, pdd b){ ld x = b.first - a.first; ld y = b.second - a.second; return x*x + y*y; } //点a,bの距離 ld dist(pdd a, pdd b){ return sqrt(dist2(a, b)); } //内積a・b ld dot(pdd a, pdd b){ ld x = a.first * b.first; ld y = a.second * b.second; return x+y; } //a,bを横に並べた行列の行列式 ld det(pdd a, pdd b){ ld x = a.first * b.second; ld y = a.second * b.first; return x-y; } //b-a pdd dif(pdd a, pdd b){ pdd p; p.first = b.first - a.first; p.second = b.second - a.second; return p; } //点a,bの中点 pdd mid(pdd a, pdd b){ pdd p; p.first = (a.first + b.first)/2; p.second = (a.second + b.second)/2; return p; } int main(){ int N; cin >> N; pdd p[N]; map<pdd, int> mp; rep(i, N){ cin >> p[i].first >> p[i].second; mp[p[i]] = i; } sort(p, p+N); pdd q[N+1]; int k = 1; q[0] = p[0]; rep2(i, 1, N-1){ if(i < N-1 && p[i-1].first == p[i].first) continue; while(k > 1 && det(dif(q[k-1], p[i]), dif(q[k-1], q[k-2])) <= 0) k--; q[k] = p[i], k++; } int t = k; rep3(i, N-2, 0){ if(i > 0 && p[i+1].first == p[i].first) continue; while(k > t && det(dif(q[k-1], p[i]), dif(q[k-1], q[k-2])) <= 0) k--; q[k] = p[i], k++; } k--; ld ans[N]; fill_n(ans, N, 0); ld pi = 3.141592653589793238; rep(i, k){ int j = (k+i-1)%k, l = (i+1)%k; pdd x[2]; x[0] = mid(q[i], q[j]); x[1] = mid(q[i], q[l]); ld r[3], R[3]; rep(a, 2){ r[a] = dist(q[i], x[a]); R[a] = dist2(q[i], x[a]); } r[2] = dist(x[0], x[1]); R[2] = dist2(x[0], x[1]); ld cos = -(R[0]+R[1]-R[2])/(2*r[0]*r[1]); if(cos > 1) cos = 1; elif(cos < -1) cos = -1; ld the = acos(cos); int n = mp[q[i]]; ans[n] = the/(2*pi); } rep(i, N) cout << setprecision(15) << ans[i] << endl; }
1
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--) #define rrep(i,n) RREP(i,(n)-1,0) #define all(v) v.begin(), v.end() #define endk '\n' const int inf = 1e9+7; const ll longinf = 1LL<<60; const ll mod = 1e9+7; const ld eps = 1e-10; template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;} template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;} int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<ll> v(n); rep(i, n) cin >> v[i]; ll ans = 0; for(int i=0; i<=k; i++) { // push int j = k-i; // pop if(j >= n) { priority_queue<ll, vector<ll>, greater<ll>> q; rep(l, n) q.push(v[l]); rep(l, i) { if(q.empty()) break; if(q.top() >= 0) break; q.pop(); } ll tmp = 0; while(!q.empty()) { tmp += q.top(); q.pop(); } chmax(ans, tmp); } else { for(int l=0; l<=j; l++) { priority_queue<ll, vector<ll>, greater<ll>> q; rep(m, l) q.push(v[m]); rep(m, j-l) q.push(v[n-1-m]); rep(m, i) { if(q.empty()) break; if(q.top() >= 0) break; q.pop(); } ll tmp = 0; while(!q.empty()) { tmp += q.top(); q.pop(); } chmax(ans, tmp); } } } cout << ans << endk; return 0; }
#include <cstdio> using namespace std; int n; int m; int maxcnt; int maxidx; int a[1000]; int cnt[1000]; int main() { scanf("%d %d", &n, &m); for (int i=0; i<n; i++) { scanf("%d", &a[i]); } for (int i=0; i<m; i++) { int b; scanf("%d", &b); for (int i=0; i<n; i++) { if (a[i] <= b) { cnt[i]++; if (maxcnt < cnt[i]) { maxcnt = cnt[i]; maxidx = i; } break; } } } printf("%d\n", maxidx+1); }
0
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { ll x; cin >> x; ll nokori = x % 11; ll ans = (x-nokori) / 11; ans *= 2; if(nokori > 6){ ans += 2; } else if(nokori > 0) { ans++; } cout << ans << endl; return 0; }
#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; 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); string s; cin >> s; rep(i,s.size()-8){ cout << s[i]; } }
0
#include<iostream> #include<string> using namespace std; int main(){ int i,n; string a; cin>>a; n=a.size(); for(i=n-1;i>=0;i--){ cout<<a[i]; } cout<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string ans = ""; while(n != 0){ int t = n%(-2); if(t == -1) t = 1; ans.push_back('0'+t); n = (n-t)/(-2); } if(ans.size() == 0) ans = "0"; reverse(ans.begin(),ans.end()); cout << ans << endl; }
0
#include<bits/stdc++.h> #define fo(i,a,b) for(int i=(a);i<=(b);++i) #define rv(i,a,b) for(int i=(a);i>=(b);--i) using namespace std; const int M = 120000; typedef long long ll; int n,m,k; char grid[8][10][10]={{"aa.","..a","..a"}, {"aabc","ddbc","bcaa","bcdd"}, {"aabba","bcc.a","b..cb","a..cb","abbaa"}, { "aabc..", "ddbc..", "..aabc", "..ddbc", "bc..aa", "bc..dd" }, { "aabbcc.", "dd.dd.a", "..d..da", "..d..db", "dd.dd.b", "..d..dc", "..d..dc" }}; char ans[1001][1001]; void out(int x){ fo(i,0,x-1) { ans[i][x]='\0'; printf("%s\n",ans[i]); } } void ass(int x,int y,int num){ fo(i,0,num+2) fo(j,0,num+2) ans[i+x][j+y]=grid[num][i][j]; } int main(){ while(cin>>n){ if(2==n) puts("-1"); else { fo(i,0,n-1) fo(j,0,n-1) ans[i][j]='.'; int i; for(i=0;n-i*4>7;++i) { ass(i*4,i*4,1); } ass(i*4,i*4,n-i*4-3); out(n); } } return 0; }
// luogu-judger-enable-o2 #include<bits/stdc++.h> using namespace std; #define ll long long #define db double #define in inline namespace fast_io { char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0; in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;} in ll read() { ll x=0,y=1;while(nc=gc(),(nc<48||nc>57)&&nc!=-1)if(nc==45)y=-1;Bi=1; x=nc-48;while(nc=gc(),47<nc&&nc<58)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*y; } in db gf() {int a=read(),b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi):a);} in int gs(char *s) {char c,*t=s;while(c=gc(),c<32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;} in void ot() {fwrite(sr,1,C+1,stdout);C=-1;} in void flush() {if(C>1<<22) ot();} template <typename T> in void write(T x,char t) { int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10); if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush(); } in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();} } using namespace fast_io; const int N=1e3+5; int n; char ans[1005][1005]; string s3[3]={ "aab", "b.b", "baa", }; string s4[4]={ "bacc", "babb", "ccda", "aada", }; string s5[5]={ "accbb", "ad..a", "bd..a", "b.ddc", "aabbc", }; string s6[6]={ "oorrzz", ".a.b.c", ".a.b.c", "d.e.f.", "d.e.f.", "oorrzz" }; string s7[7]={ "..bbcca", "ccdd..a", ".a..d.b", ".a..d.b", "b....dc", "b....dc", "ccbbaa.", }; int main() { n=read();if(n<3) return puts("-1"),0; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) ans[i][j]=0; if(n==3) {for(int i=1;i<=n;i++){for(int j=1;j<=n;j++) sr[++C]=s3[i-1][j-1];sr[++C]='\n';}return ot(),0;} if(n==4) {for(int i=1;i<=n;i++){for(int j=1;j<=n;j++) sr[++C]=s4[i-1][j-1];sr[++C]='\n';}return ot(),0;} if(n==5) {for(int i=1;i<=n;i++){for(int j=1;j<=n;j++) sr[++C]=s5[i-1][j-1];sr[++C]='\n';}return ot(),0;} if(n==6) {for(int i=1;i<=n;i++){for(int j=1;j<=n;j++) sr[++C]=s6[i-1][j-1];sr[++C]='\n';}return ot(),0;} if(n==7) {for(int i=1;i<=n;i++){for(int j=1;j<=n;j++) sr[++C]=s7[i-1][j-1];sr[++C]='\n';}return ot(),0;} if(n%4==0) for(int i=1;i<=n;i+=4) for(int j=i;j<=i+3;j++) for(int k=i;k<=i+3;k++) ans[j][k]=s4[(j-1)%4][(k-1)%4]; if(n%4==1) { for(int i=1;i<=n-5;i+=4) for(int j=i;j<=i+3;j++) for(int k=i;k<=i+3;k++) ans[j][k]=s4[(j-1)%4][(k-1)%4]; for(int i=n-4;i<=n;i++) for(int j=n-4;j<=n;j++) ans[i][j]=s5[i-n+4][j-n+4]; } if(n%4==2) { for(int i=1;i<=n-6;i+=4) for(int j=i;j<=i+3;j++) for(int k=i;k<=i+3;k++) ans[j][k]=s4[(j-1)%4][(k-1)%4]; for(int i=n-5;i<=n;i++) for(int j=n-5;j<=n;j++) ans[i][j]=s6[i-n+5][j-n+5]; } if(n%4==3) { for(int i=1;i<=n-7;i+=4) for(int j=i;j<=i+3;j++) for(int k=i;k<=i+3;k++) ans[j][k]=s4[(j-1)%4][(k-1)%4]; for(int i=n-6;i<=n;i++) for(int j=n-6;j<=n;j++) ans[i][j]=s7[i-n+6][j-n+6]; } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) sr[++C]=(ans[i][j]?ans[i][j]:'.'); sr[++C]='\n';ot(); } return 0; } //Author: disangan233 //In my dream's scene,I can see the everything that in Cyaegha. /* ---------- aab b.b baa ---------- bacc babb ccda aada ---------- accbb ad..a bd..a b.ddc aabbc ---------- aabb.. b..aa. ba.... .a..aa ..a..b ..a..b ---------- ..bbcca ccdd..a .a..d.b .a..d.b b....dc b....dc ccbbaa. ---------- */
1
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) typedef long long ll; template<typename T> bool chmax(T &a, T b) {if(a <= b){a = b; return true;}return false;} template<typename T> bool chmin(T &a, T b) {if(a >= b){a = b; return true;}return false;} #define ABC 001 #define ARC 010 #define AGC 100 int main(void){ int r; cin >> r; int frag = AGC; if(r < 1200){ frag |= ABC; frag |= ARC; }else if( r < 2800){ frag |= ARC; } if(frag & ABC)cout << "ABC" << endl; else if(frag & ARC)cout << "ARC" << endl; else cout << "AGC" << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--) #define rrep(i,n) RREP(i,n-1,0) #define all(v) v.begin(), v.end() const int inf = 1e9+7; const ll longinf = 1LL<<60; const ll mod = 1e9+7; int main() { cin.tie(0); ios::sync_with_stdio(false); int r; cin >> r; if(r < 1200) cout << "ABC" << "\n"; else if(r < 2800) cout << "ARC" << "\n"; else cout << "AGC" << "\n"; return 0; }
1
#include <algorithm> #include <iostream> using namespace std; using ll = long long; void solve(ll A, ll B) { cout << max({A + B, A - B, A * B}) << endl; } int main() { ll A; cin >> A; ll B; cin >> B; solve(A, B); return 0; }
#include <iostream> #include <string> #include <cmath> using namespace std; int main() { int x; cin >> x; cout << int(pow(x, 3)) << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; #define LL long long #define DD long double #define M 1000000007 #define INF 1e18 void setIO(string s = "") { cin.sync_with_stdio(0); cin.tie(0); if (s.size()) s += ".in", freopen(s.c_str(), "r", stdin); } int tt = 1; void solve() { set<int> nums; int a; while (cin >> a) nums.insert(a); cout << ((nums.size() == 2) ? "Yes" : "No") << endl; } int main() { setIO(); while (tt--) { solve(); } return 0; }
#include<bits/stdc++.h> #include <stdio.h> #include <math.h> using namespace std; #define debug(x) cout << '[' << #x << " is: " << x << "] " << endl; #define imod(a , n) (a % n + n ) % n #define fastio ios_base::sync_with_stdio(false);cin.tie(0); #define inF freopen("gymnastics.in","r",stdin ); #define outF freopen("gymnastics.out" , "w" , stdout ) ; #define sum(a)a * (a + 1 ) / 2 #define ll long long const double eps = 1e-9 , PI = acos(-1) ; const int N = 1e6, oo = 1e7 , M = 4 * N, mod = 1<<30 , K = 12; int n ; int32_t main(){ //inF; // Dont Forget memset //calculate constraints please!!! fastio; map<int , int >mp; for(int i = 0 ; i < 3 ; i++){ int a ; cin >> a; mp[a]++; } cout << (mp.size() == 2 ? "Yes" : "No"); return 0 ; }
1
#include <cstdio> #include <cstdlib> #include <cassert> #include <algorithm> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define repi(i,a,b) for(ll i=(a);i<(b);++i) #define rep(i,a) repi(i,0,a) #define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i) #define repd(i,a) repdi(i,a,0) #define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it ) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() using ll = long long; using P = std::pair<std::string, std::string>; constexpr ll INF = 1ll<<60; 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; } template<class S, class T> std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a ) { std::cout << '(' << a.first << ", " << a.second << ')'; return out; } template<class T> std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a ) { std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; } ll N; std::string S; std::map<P, ll> mp; ll ans; int main() { std::cin >> N >> S; std::reverse( S.begin()+N, S.end() ); rep( i, 1<<N ) { std::string t[2]; rep( j, N ) t[i>>j&1] += S[j]; ++mp[P( t[0], t[1] )]; } rep( i, 1<<N ) { std::string t[2]; rep( j, N ) t[i>>j&1] += S[N+j]; ans += mp[P( t[0], t[1] )]; } std::cout << ans << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i < n; i++) #define elif else if typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 1e9+7; const ll MOD2 = 998244353; const ll INF = 1e15; vector<int> tovec(ll x, int N){ vector<int> vec; rep(i, N){ if(x % 2 == 0) vec.push_back(0); else vec.push_back(1); x /= 2; } return vec; } int main(){ int N; cin >> N; string S; cin >> S; string L, R; rep(i, N){ L += S[i]; R += S[2*N-1-i]; } ll e[N+1]; e[0] = 1; rep(i, N) e[i+1] = e[i]*2; map<pair<string, string>, ll> lmp, rmp; rep(i, e[N]){ vector<int> vec = tovec(i, N); string l1, l2, r1, r2; rep(i, N){ if(vec[i] == 0){ l1 += L[i]; r1 += R[i]; } else{ l2 += L[i]; r2 += R[i]; } } pair<string, string> p1 = make_pair(l1, l2), p2 = make_pair(r1, r2); if(lmp.count(p1)) lmp[p1]++; else lmp[p1] = 1; if(rmp.count(p2)) rmp[p2]++; else rmp[p2] = 1; } ll ans = 0; map<pair<string, string>, ll>::iterator ite;; ite = lmp.begin(); while(ite != lmp.end()){ if(rmp.count(ite->first)){ ans += ite->second * rmp[ite->first]; } ite++; } cout << ans << endl; }
1
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio> #include <cstring> #include <ctime> #include <string> #include <vector> #include <algorithm> #include <cmath> #include <sstream> #include <utility> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pii; #define all(c) (c).begin(), (c).end() #define loop(i,a,b) for(ll i=a; i<ll(b); i++) #define rep(i,b) loop(i,0,b) #define each(e,c) for(auto&e:c) #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define lb lower_bound #define ub upper_bound #ifdef DEBUG #define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl) struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}}; #else #define dump(...) #endif template<class T> ostream& operator<<(ostream& os, vector<T> const& v){ rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" "); return os; } int main(){ string s; while(cin>>s){ int n = s.size(); vi l(n); l[0] = 1; rep(i,n-1){ if(s[i+1]==s[i]) l[i+1]=l[i]+1; else l[i+1] = 1; } int ans = 0; dump(s); dump(l); loop(i,1,n-1){ if(s[i]=='O' && s[i+1]!='O' && i+l[i]<n && i-l[i] >= 0 && l[i+l[i]]>=l[i] && l[i-l[i]]>=l[i] && s[i+l[i]]=='I' && s[i-l[i]]=='J'){ ans = max(ans,l[i]); } } cout << ans << endl; } }
#include<iostream> using namespace std; int main(){ string in; // while(cin >> in){ cin >> in; int num[3] = {0,0,0}; int lev = 0; int status = 3; for(int i = 0; i < in.length(); i++){ if(in[i] == 'J'){ //cout << num[0] << " " << num[1] << " " << num[2] << endl; if(status != 0) num[0] = num[1] = num[2] = 0; num[0]++; status = 0; continue; } if(in[i] == 'O' && (status == 0 || status == 1)){ num[1]++; status = 1; continue; } if(in[i] == 'I' && (status == 1 || status == 2)){ num[2]++; status = 2; if(num[1] <= num[0] && num[1] <= num[2]) lev = max(lev,num[1]); continue; } status = 3; } cout << lev << endl; // } return 0; }
1
#include <bits/stdc++.h> using namespace std; using ll=long long; #define rep(i,n) for(int i=0;i<n;i++) int main() { int n,x,t; cin>>n>>x>>t; int times=(n+x-1)/x; int ans=times*t; cout<<ans<<endl; }
#include<iostream> using namespace std; char getAns(int m,int e,int j){ if(m==100||e==100||j==100)return 'A'; if((m+e)/2>=90)return 'A'; if((m+e+j)/3>=80)return 'A'; if((m+e+j)/3>=70)return 'B'; if((m+e+j)/3>=50&& (m>=80||e>=80))return 'B'; return 'C'; } int main(){ int d; while(cin>>d){ int pm,pe,pj; for(;d>0;d--){ cin>>pm>>pe>>pj; cout<<getAns(pm,pe,pj)<<endl; } } }
0
// J'aime // Chemise Blanche #include <bits/stdc++.h> using namespace std; #define int long long #define ii pair<int,int> #define fi first #define sc second #define all(x) (x).begin(),(x).end() #define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl int f(int n) { int ret = 0; while (n) { ret += n % 10; n /= 10; } return ret; } void MAIN() { int n; cin >> n; if (n % f(n) == 0) cout << "Yes" << '\n'; else cout << "No" << '\n'; } signed main() { #ifdef _DEBUG // freopen("in" , "r", stdin ); // freopen("out", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); int T = 1; // cin >> T; while (T--) MAIN(); }
#include <iostream> #include <sstream> #include <vector> #include <map> #include <set> #include <queue> #include <stack> #include <algorithm> #include <cstdio> #include <cmath> using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; #define ALL(a) (a).begin(),(a).end() #define REP(i,n) for(int i=0;i<(n);++i) const double EPS = 1e-10; const double PI = acos(-1.0); #define dump(x) cerr << " (L" << __LINE__ << ") " << #x << " = " << (x) << endl; #define dumpv(x) cerr << " (L" << __LINE__ << ") " << #x << " = "; REP(q,(x).size()) cerr << (x)[q] << " "; cerr << endl; template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& d) {return s << "(" << d.first << "," << d.second << ")";} int main() { string s; while (getline(cin, s)) { string orig; for (int i = 0; i <= 'z'-'a'; i++) { orig = s; for (int j = 0; j < orig.size(); j++) { if (orig[j] >= 'a' && orig[j] <= 'z') { orig[j] = 'a' + ((orig[j]-'a') + i) % ('z'-'a'+1); } } if (orig.find("the") != string::npos || orig.find("this") != string::npos || orig.find("that") != string::npos) { break; } } cout << orig << endl; } }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll INF = 100000000; #define rep1(i, n) for (ll i=0; i<(n); i++) #define rep2(i, k, n) for (ll i=k; i<(n); i++) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { ll n; cin >> n; vector<ll> a(n, 0), b(n, 0); ll sum = 0, count = 0; bool zero = false; rep1(i, n){ cin >> a[i]; sum += abs(a[i]); b[i] = abs(a[i]); if (a[i]<0) count++; if (a[i]==0) zero = true; } ll ans; sort(b.begin(), b.end()); if (count%2==0 || zero) ans = sum; else ans = sum - 2*b[0]; cout << ans << endl; //printf("%.12f", ans); }
#include <bits/stdc++.h> #define res register int #define ll long long #define pb push_back #define mp make_pair #define fr first #define sc second #define INF 1000000007 #define gc getchar() #define MAXN 200005 #define lc pos<<1 #define rc pos<<1|1 using namespace std; inline int read() { int ch=gc,f=0; int x=0; while(ch<'0'||ch>'9') { f|=ch=='-'; ch=gc; } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=gc; } return f?-x:x; } struct row { int c,flag; }r[MAXN]; int n,m; int a[4][MAXN],t[2],c[MAXN]; inline void hult() { printf("No\n"); exit(0); } inline void op(int i) { if(i<1) hult(); swap(r[i],r[i+2]); r[i].flag^=1; r[i+1].flag^=1; r[i+2].flag^=1; } int main() { n=read(); for(int i=1;i<=n;i++) a[1][i]=read(); for(int i=1;i<=n;i++) a[2][i]=read(); for(int i=1;i<=n;i++) a[3][i]=read(); for(int i=1;i<=n;i++) { int b[3]={a[1][i],a[2][i],a[3][i]}; sort(b,b+3); if(b[2]%3||b[1]!=b[2]-1||b[0]!=b[1]-1) hult(); if(a[2][i]!=b[1]) hult(); r[i].c=b[2]/3; r[i].flag=b[2]==a[3][i]; c[i]=r[i].c; if(abs(r[i].c-i)&1) hult(); t[i&1]^=b[2]==a[1][i]; } for(res i=1;i<=n;i++) { while(c[i]!=i) { t[i&1^1]^=1; swap(c[i],c[c[i]]); } } puts(t[0]||t[1]?"No":"Yes"); return 0; }
0
#include<cstdio> #include<iostream> using namespace std; int main() { float l[11]; float v1,v2; char s; while(1) { for(int i=1;i<=10;i++){ cin >> l[i] >> s; } cin >> v1 >> s >> v2; if(cin.eof()) break; float t,la; float lsum=0; for(int i=1;i<=10;++i){ lsum+= l[i]; } t = lsum/(v1+v2); la = v1*t; lsum = 0; for(int i=1;i<10;i++) { lsum += l[i]; if(lsum >= la){ cout << i << endl; break;} } if(lsum < la)cout << 10 << endl; } return 0; }
#include<iostream> #include<cstdio> using namespace std; int main(){ double row[10],v[2]; for(;;){ if (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&row[0],&row[1],&row[2],&row[3],&row[4],&row[5],&row[6],&row[7],&row[8],&row[9],&v[0],&v[1]) == EOF){break;} int i; double t,dis = 0,d = 0; for(int i=0; i<10; i++){ dis+=row[i]; } for(i=0; i<10; i++){ d+=row[i]; t = d/v[0]; if(dis <= t*(v[0]+v[1])){break;} } cout<<i+1<<endl; } return 0; }
1
#include <iostream> #include <vector> #include <string> using namespace std; int main(){ int n, m, x, y; cin >> n >> m >> x >> y; vector<int> x1(n+1); vector<int> y1(m+1); for(int i = 0; i < n; i++) cin >> x1[i]; for(int i = 0; i < m; i++) cin >> y1[i]; string ans = "War"; for(int z = x+1; z <= y; z++){ bool isok = true; for(int i = 0; i < n; i++){ if(x1[i] >= z) isok = false; } for(int i = 0; i < m; i++){ if(y1[i] < z) isok = false; } if(isok) ans = "No War"; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i,N) for(int i = 0; i < (N); i++) #define erep(i,N) for(int i = N; i >= 0; i--) const ll INF = 1000000000000000000; //input ll N,A,B,C,D,E; //processing ll hoge; //dpTable //int dp[100050]; int main(){ cin >> N >> A >> B >> C >> D >> E; hoge = min(A,min(B,min(C,min(D,E)))); ll ans = (N + hoge - 1) / hoge; cout << ans + 4 << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define elif else if #define sp(x) fixed << setprecision(x) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() using ll = long long; using ld = long double; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const ll MOD = 1e9+7; //const ll MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; const ld EPS = 1e-10; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; void print(ll x){ cout << x << ".00000000000000" << endl; } int main(){ int N; cin >> N; ll x[N]; rep(i, N) cin >> x[i]; ll d[N-1]; rep(i, N-1) d[i] = x[i+1]-x[i]; int M; ll K; cin >> M >> K; int dp[60][N-1]; rep(i, N-1) dp[0][i] = i; rep(i, M){ int a; cin >> a; swap(dp[0][a-2], dp[0][a-1]); } rep2(i, 1, 59){ rep(j, N-1) dp[i][j] = dp[i-1][dp[i-1][j]]; } ll ans = x[0]; print(ans); rep(i, N-1){ int now = i; rep(j, 60){ if(K&(1LL<<j)) now = dp[j][now]; } print(ans += d[now]); } }
#include <iostream> #include <algorithm> #include <vector> typedef long long ll; using namespace std; ll x[100010]; int a[100010], nsw[100010], now[100010], vid[100010], vnum[100010], repl[100010]; bool looked[100010]={}; vector<vector<int>> v; int main() { int N; cin >> N; for(int i=0; i<N; ++i) cin >> x[i]; int M; ll K; cin >> M >> K; for(int i=0; i<M; ++i) cin >> a[i]; for(int i=1; i<N; ++i) nsw[i]=i; for(int i=0; i<M; ++i) swap(nsw[a[i]-1], nsw[a[i]]); for(int i=1; i<N; ++i) now[nsw[i]]=i; int cnt=0; for(int i=1; i<N; ++i){ if(!looked[i]){ int b=i; v.emplace_back(); do{ vnum[b]=v[cnt].size(); v[cnt].emplace_back(b); vid[b]=cnt; looked[b]=1; b=now[b]; }while(b!=i); ++cnt; } } for(int i=1; i<N; ++i){ ll sz=v[vid[i]].size(); ll r=(K%sz+vnum[i])%sz; repl[v[vid[i]][r]]=i; } cout << x[0] << endl; ll ans=x[0]; for(int i=1; i<N; ++i){ ans += x[repl[i]]-x[repl[i]-1]; cout << ans << endl; } return 0; }
1
#include <iostream> #include <cmath> #include <iomanip> #include <utility> #include <vector> #include <map> #include <queue> #include <algorithm> #define ll long long using namespace std; long long gcd(int x, int y){ if ( x == 0 ) return y; return gcd(y%x, x); } long long lcm(int x, int y){ if ( y == 0 ){ return x; } return x*y/gcd(x, y); } int min(int a, int b){ return a > b ? b : a; } int max(int a, int b){ return a > b ? a : b; } int main() { cin.sync_with_stdio( false ); int n; cin>>n; int a[n]; map <int, int> m; for (int i=0;i<n;i++){ cin>>a[i]; m[a[i]]++; } for (int i=0;i<n;i++){ if ( m[a[i]] >= 2 ){ cout<<"NO"<<endl; return 0; } } cout<<"YES"<<endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) ((a)*(b))/gcd((a),(b)) const int maxn = 1e9 + 5; #define INF 1000000000 const int MOD = 1e9+7; const double PI = 3.14159265358979323846264338; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio int n; cin >> n; ll a[n]; set<ll> s; for(int i=0; i<n; i++){ cin >> a[i]; s.insert(a[i]); } if(s.size() == n){ cout << "YES\n"; }else{ cout << "NO\n"; } return 0; }
1
#include<bits/stdc++.h> using namespace std; int n,mod,jc[11111],injc[11111],ans,ipw1[11111],ipw2[11111],ipw3[11111],i2,i3,ct,pw[11111]; int binpow(int a,int t) { int res=1,p=a; for (int i=t;i;i>>=1) { if (i&1) res=1ll*res*p%mod; p=1ll*p*p%mod; } return res; } int main() { scanf("%d%d",&n,&mod); jc[0]=1; for (int i=1;i<=3*n;i++) { jc[i]=1ll*jc[i-1]*i%mod; } injc[3*n]=binpow(jc[3*n],mod-2); for (int i=3*n-1;i>=0;i--) { injc[i]=1ll*injc[i+1]*(i+1)%mod; } ipw1[0]=ipw2[0]=ipw3[0]=1;i2=binpow(2,mod-2);i3=binpow(6,mod-2); for (int i=1;i<=3*n;i++) { ipw1[i]=1;ipw2[i]=1ll*ipw2[i-1]*i2%mod; ipw3[i]=1ll*ipw3[i-1]*i3%mod; } pw[0]=1; for (int i=1;i<=3*n;i++) pw[i]=2ll*pw[i-1]%mod; for (int i=0;i<=3*n;i++) { for (int j=0;j<=i;j++) { if (i+2*j>3*n || (i+2*j)%3) continue; ans=(1ll*jc[3*n]*ipw2[j]%mod*ipw3[(3*n-i-2*j)/3]%mod*injc[i]%mod*injc[j]%mod*injc[(3*n-i-2*j)/3]%mod*pw[(3*n-i-2*j)/3]+ans)%mod; } } printf("%d\n",ans); return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <set> #include <map> #include <numeric> #include <queue> #include <deque> #include <list> #include <stack> #include <deque> #include <cmath> #include <complex> #include <cassert> #include <cstring> #include <functional> #include <bitset> #include <climits> using namespace std; typedef long long ll; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<VI> VVI; #define MP make_pair #define PB push_back #define inf 1000000007 #define rep(i,n) for(int i=0;i<(int)(n);++i) #define cmn(x,y) x=min(x,y) template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } template<typename T> class segtree { private: int n,sz; vector<pair<T, int> > node; public: segtree(vector<T>& v) : sz((int)v.size()){ n = 1; while(n < sz){ n *= 2; } node.resize(2*n, make_pair(numeric_limits<T>::max(), sz)); for(int i = 0; i < sz; i++){ node[i+n] = make_pair(v[i], i); } for(int i=n-1; i>=1; i--){ node[i] = min(node[2*i], node[2*i+1]); } } void update(int k, T a) { node[k+n] = make_pair(a, k); k += n; while(k>>=1){ node[k] = min(node[2*k], node[2*k+1]); } } pair<T, int> query(int a,int b,int k=0,int l=0,int r=-1) { pair<T, int> res1 = make_pair(numeric_limits<T>::max(), sz); pair<T, int> res2 = make_pair(numeric_limits<T>::max(), sz); a += n, b += n; while(a != b){ if(a % 2) cmn(res1, node[a++]); if(b % 2) cmn(res2, node[--b]); a >>= 1, b>>= 1; } return min(res1, res2); } void print() { for(int i = 0; i < sz; i++){ pair<T, int> p; p = query(i,i+1); cout << "st[" << i << "]: " << p.first << " " << p.second << endl; } } }; int n; ll d; ll saiki(segtree<ll>& sg, int a,int b){ //cerr << a << " " << b << endl; if(b==a+1)return 0; auto p = sg.query(a,b); ll s = p.first; ll ans = 0; int ind = p.second; if(ind-1>=a){ ll xx = sg.query(ind-1,ind).first; ans += s+d+xx; sg.update(ind-1,min(xx,s+d)); ans += saiki(sg,a,ind); } if(ind+1<b){ ll xx = sg.query(ind+1,ind+2).first; ans += s+d+xx; sg.update(ind+1,min(xx,s+d)); ans += saiki(sg,ind+1,b); } return ans; } int main(){ cin >> n >> d; vector<ll>v(n+1); rep(i,n)cin >> v[i]; segtree<ll> sg(v); ll ans = saiki(sg,0,n); cout << ans << endl; return 0; }
0
#include<stdio.h> #include<string.h> #include<iostream> #include<vector> #include<set> #include<map> #include<queue> #include<ctype.h> #include<stack> #include<math.h> #include <string> #include<algorithm> #include<iomanip> #define _for(i,a,b) for(int i = (a);i < (b);i++) #define mset(x) memset(x,0,sizeof(x)); using namespace std; int main() { long long int n,ans; cin>>n; ans = n * n *n; cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> P; typedef pair<ll, ll> Pll; #define rep(i,n) for(int (i) = 0; (i) < (int)(n); (i)++) #define debug(var) do{std::cout << #var << " : ";view(var);}while(0) template<typename T> void view(T e){std::cout << e << std::endl;} template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;} template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } } 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; } void Yes(){cout << "Yes" << endl;} void No(){cout << "No" << endl;} void YES(){cout << "YES" << endl;} void NO(){cout << "NO" << endl;} void err() {cout << -1 << endl;} #define all(x) (x.begin(), x.end()) const int MOD = 1000000007; const int INF = 1e9; #define PI acos(-1); int dx[4] = {1,-1,0,0}; int dy[4] = {0,0,1,-1}; int ddx[8] = {1,1,1,-1,-1,-1,0,0}; int ddy[8] = {0,1,-1,0,1,-1,1,-1}; int main(){ int n; cin >> n; if(n < 1200) cout << "ABC" << endl; else if(n < 2800) cout << "ARC" << endl; else cout << "AGC" << endl; }
0
#include <bits/stdc++.h> using namespace std; int main(void){ vector<int>X(26,0); string S;cin>>S; for(long long i=0;i<S.size();i++){ X[(int)S[i]-97]++; } for(long long i=0;i<26;i++){ if(X[i]==0){ int ans=i+97; cout<<(char)ans<<endl; return 0; } } cout<<"None"<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(int)n;i++) using Graph = vector<vector<int> >; using GraphC = vector<vector<char> >; const int INF = 100000000; typedef pair<char, int> P; int main() { string S; cin >> S; string alpha = "abcdefghijklmnopqrstuvwxyz"; vector<P> vec(26); rep(i,26) { vec.at(i).first = alpha.at(i); vec.at(i).second = 1; } rep(i, S.size()) { rep(j, 26) { if (S.at(i)==vec.at(j).first) { vec.at(j).second = 0; break; } } } rep(i, 26) { if (vec.at(i).second) { cout << vec.at(i).first << endl; return 0; } } cout << "None" << endl; }
1
#include <iostream> #include <map> #include <string> #include <vector> using namespace std; typedef vector <int> vi; int main(void){ map <char, int> m; vi x; int num[] = {1,5,10,50,100,500,1000}; for (int i=0; i<7; i++) m["IVXLCDM"[i]] = num[i]; while (true){ string roman; cin>>roman; if (cin.eof()) break; int tmp, tmp2= m[roman[0]]; for (int i=0; i<(int)roman.size(); i++){ tmp = m[roman[i]]; if (i!=0 && tmp2<tmp) x[i-1] = -tmp2; x.push_back(tmp); tmp2 = tmp; } int s=0; for (int i=0; i<(int)x.size(); i++) s += x[i]; cout<<s<<endl; x.clear(); } }
#include <iostream> #include <cstdio> #include <string> using namespace std; const string ara = "IVXLCDM\0"; const int integer[8] = {1,5,10,50,100,500,1000}; int Input(int num[],string in); void Output(int p,int num[]); int main(void){ string in; int num[1000]; while( cin >> in ){ for(int i = 0 ; i < 1000; i++)num[i] = 0; int p = Input(num,in); Output(p,num); } return 0; } int Input(int num[],string in){ int p = 0; for(int i = 0 ; i < (int)in.size(); i++){ for(int j = 0 ; ara[j] != '\0' ; j++ ){ if(in[i] == ara[j]){ num[p++] = integer[j]; break; } } } return p; } void Output(int p,int num[]){ int ans = 0; for(int i = 0 ;i < p ; i++){ if(num[i] < num[i+1]){ ans += (num[i+1] - num[i]); i++; } else ans+=num[i]; } cout << ans << endl; }
1
#include<bits/stdc++.h> //ios::sync_with_stdio(false); //cin.tie(0); using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<pii,int> ppii; typedef pair<int,pii> pipi; typedef pair<ll,ll> pll; typedef pair<pll,ll> ppll; typedef pair<ll,pll> plpl; typedef tuple<ll,ll,ll> tl; ll mod=1000000007; ll mod2=998244353; ll inf=1000000000000000000; double pi=2*acos(0); #define rep(i,m,n) for(int i=m;i<n;i++) #define rrep(i,n,m) for(int i=n;i>=m;i--) int dh[4]={1,-1,0,0}; int dw[4]={0,0,1,-1}; int ddh[8]={-1,-1,-1,0,0,1,1,1}; int ddw[8]={-1,0,1,-1,1,-1,0,1}; ll lmax(ll a,ll b){ if(a<b)return b; else return a; } ll lmin(ll a,ll b){ if(a<b)return a; else return b; } ll gcd(ll a,ll b){ if(a<b)swap(a,b); if(a%b==0)return b; return gcd(b,a%b); } ll beki(ll n,ll k){ ll ret=1; ll now=n; while(k>0){ if(k%2==1){ ret*=now; ret%=mod; } now*=now; now%=mod; k/=2; } return ret; } ll gyaku(ll n){ return beki(n,mod-2); } int main(){ ios::sync_with_stdio(false); cin.tie(0); ll n;cin>>n; ll a,b,c,d;cin>>a>>b>>c>>d; ll dp[n+1][n+1]; rep(i,0,n+1)rep(j,0,n+1)dp[i][j]=0; dp[a-1][0]=1; ll nck[1001][1001]; rep(i,0,1001)nck[i][0]=1; rep(i,0,1001)nck[i][i]=1; ll gya[1001]; rep(i,1,1001)gya[i]=gyaku(i); rep(i,1,1001){ rep(j,1,i){ nck[i][j]=nck[i-1][j-1]+nck[i-1][j]; nck[i][j]%=mod; } } rep(i,a-1,b){ int t=0; rep(j,0,n+1){ dp[i+1][j]+=dp[i][j]; dp[i+1][j]%=mod; if(t==1)continue; ll sum=1; ll now=n-j; rep(k,0,c){ if(now<0){ sum=-1; break; } sum*=nck[now][i+1]; sum%=mod; sum*=gya[k+1]; sum%=mod; now-=i+1; } if(sum==-1){ t=1; continue; } rep(k,c,d+1){ if(j+(i+1)*k>n)break; dp[i+1][j+(i+1)*k]+=dp[i][j]*sum; dp[i+1][j+(i+1)*k]%=mod; sum*=nck[n-(j+(i+1)*k)][i+1]; sum%=mod; sum*=gya[k+1]; sum%=mod; } } } cout<<dp[b][n]<<endl; }
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" #define int long long const int N=1e3+5; const int MOD=1e9+7; int n, a, b, c, d; int cache[N][N], cache2[N][N]; int fact[N], invfact[N]; int pow(int a, int b, int m) { int ans=1; while(b) { if(b&1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans; } int modinv(int k) { return pow(k, MOD-2, MOD); } void precompute() { fact[0]=fact[1]=1; for(int i=2;i<N;i++) { fact[i]=fact[i-1]*i; fact[i]%=MOD; } invfact[N-1]=modinv(fact[N-1]); for(int i=N-2;i>=0;i--) { invfact[i]=invfact[i+1]*(i+1); invfact[i]%=MOD; } } int nCr(int x, int y) { if(y>x) return 0; int num=fact[x]; num*=invfact[y]; num%=MOD; num*=invfact[x-y]; num%=MOD; return num; } int num(int r, int take) { int &ans=cache2[r][take]; if(ans!=-1) return ans; return modinv(pow(fact[r], take, MOD)); } int dp2(int n, int r, int take) { int ans=fact[n] * invfact[n-r*take]; ans%=MOD; int den=num(r, take); ans*=den; ans%=MOD; return ans; } int dp(int remaining, int freq) { if(remaining==0) return 1; if(freq==b+1) return 0; int &ans=cache[remaining][freq]; if(ans!=-1) return ans; ans=dp(remaining, freq+1); for(int i=c;i<=d;i++) { int take=i*freq; if(take>remaining) break; int ways=dp2(remaining, freq, i); ways*=dp(remaining-take, freq+1); ways%=MOD; ways*=invfact[i]; ways%=MOD; ans+=ways; } ans%=MOD; return ans; } int32_t main() { IOS; precompute(); memset(cache, -1, sizeof(cache)); memset(cache2, -1, sizeof(cache2)); cin>>n>>a>>b>>c>>d; int ans=dp(n, a); cout<<ans; cerr<<(double)clock()/CLOCKS_PER_SEC; return 0; }
1
#include "bits/stdc++.h" #define ll long long #define mp(a, b) make_pair(a, b) using namespace std; typedef pair<ll, ll> pairs; typedef pair<ll, pairs> tpl; ll c[4]; double dp[301][301][301]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll n, a; cin >> n; for (ll i = 0; i < n; i++) cin >> a, c[a]++; dp[0][0][0] = 0; for (ll i = 0; i <= n; i++) { for (ll j = 0; j <= n; j++) { for (ll k = 0; k <= n; k++) { double z = n - (i + j + k), val = 1; if (z == n) continue; if (i + j + k > n) continue; if (i > 0) val += (1.0 * i / n) * dp[i - 1][j + 1][k]; if (j > 0) val += (1.0 * j / n) * dp[i][j - 1][k + 1]; if (k > 0) val += (1.0 * k / n) * dp[i][j][k - 1]; if (z > 0) val /= (1.0 - 1.0 * z / n); dp[i][j][k] = val; } } } cout << setprecision(9) << fixed << dp[c[3]][c[2]][c[1]]; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0;i < (int)(n);i++) using ll = long long; const ll MOD=1000000007; const long long INF = 1LL << 60; const double pi=acos(-1.0); template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } ll N; //dp vector<vector<vector<double>>> table; double dp(ll i,ll j,ll k){ //cout<<i<<" "<<j<<" "<<k<<endl; if(i==0&&j==0&&k==0) return 0; if(table.at(i).at(j).at(k)>-1) return table.at(i).at(j).at(k); table.at(i).at(j).at(k)=0; if(i>0) table.at(i).at(j).at(k)+=dp(i-1,j,k)*i/N; if(j>0) table.at(i).at(j).at(k)+=dp(i+1,j-1,k)*j/N; if(k>0) table.at(i).at(j).at(k)+=dp(i,j+1,k-1)*k/N; table.at(i).at(j).at(k)+=1; return table.at(i).at(j).at(k)/=(double)(i+j+k)/N; } int main() { cin>>N; vector<ll> vec(4,0); rep(i,N) {ll a; cin>>a; vec.at(a)++;} //dp table=vector<vector<vector<double>>>(N+1,vector<vector<double>>(N+1,vector<double>(N+1,-1))); cout<<fixed<<setprecision(15)<<dp(vec.at(1),vec.at(2),vec.at(3))<<endl; /* rep(i,2) { if(i!=0) cout<<" "; cout<<table.at(0).at(0).at(i); } cout<<fixed<<setprecision(15)<<endl; */ return 0; }
1
#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; cin>>n; deque<int>q; rep(i,n){ int a; cin>>a; int x=lower_bound(q.begin(),q.end(), a)-q.begin(); if(x==0)q.push_front(a); else q[x-1]=a; } cout<<q.size()<<endl; }
// practice with Dukkha #include <algorithm> #include <iostream> using namespace std; const int N = 100000; int aa[N], ii[N], ft[N]; void update(int i, int n, int x) { while (i < n) { ft[i] = max(ft[i], x); i |= i + 1; } } int query(int i) { int x = 0; while (i >= 0) { x = max(x, ft[i]); i &= i + 1, i--; } return x; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> aa[i]; ii[i] = i; } sort(ii, ii + n, [] (int i, int j) { return aa[i] > aa[j] || aa[i] == aa[j] && i < j; }); int ans = 0; for (int h = 0; h < n; h++) { int i = ii[h]; int k = query(i) + 1; ans = max(ans, k); update(i, n, k); } cout << ans << '\n'; return 0; }
1
#include<bits/stdc++.h> using namespace std; #define int long long typedef vector<int>vint; typedef pair<int,int>pint; typedef vector<pint>vpint; #define rep(i,n) for(int i=0;i<(n);i++) #define reps(i,f,n) for(int i=(f);i<(n);i++) #define all(v) (v).begin(),(v).end() #define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++) #define pb push_back #define mp make_pair #define fi first #define se second template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;} template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;} int dp[111]; signed main(){ int N; while(cin>>N,N){ dp[0]=1; for(int i=1;i<=N;i++){ dp[i]=0; for(int j=1;j<=3;j++)if(i-j>=0)dp[i]+=dp[i-j]; } cout<<((dp[N]+9)/10+364)/365<<endl; } return 0; }
#include<iostream> #include<string> using namespace std; int main(){ int n,cou=0; string str; cin >> n; while(n>cou){ int cou_out=0,ans=0,ining=0; while(cou_out < 3){ cin >> str; if(str == "HIT"){ ining++; if(ining == 4){ ans++; ining--; } } else if(str == "OUT"){ cou_out++; } else if(str == "HOMERUN"){ ans += ining+1; ining = 0; } } cou++; cout << ans << endl; } }
0
#include <iostream> #include <vector> #include <queue> using namespace std; #define rep(i,n) for (int i=0;i<(n);i++) #define Graph vector<vector<int>> int main() { int H,W; scanf("%d%d",&H,&W); Graph A( H , vector<int> (W,0) ); Graph count( H , vector<int> (W,0) ); queue< pair<int,int> > que; rep(y,H){ rep(x,W){ char a; cin >> a; if( a == '#' ){ A[y][x]=1; que.push( make_pair(x,y) ); } } } vector<int> dx = { 0, 1, 0, -1 }; vector<int> dy = { 1, 0, -1, 0 }; int res = 0; while( !que.empty() ){ pair<int,int> v = que.front(); que.pop(); int x = v.first; int y = v.second; rep(i,4) { int nv_x = x + dx[i]; int nv_y = y + dy[i]; //通れるか? if ( nv_x < 0 || nv_x >= W ) continue; if ( nv_y < 0 || nv_y >= H ) continue; if ( A[nv_y][nv_x] == 1 ) continue; A[nv_y][nv_x] = 1; count[nv_y][nv_x] = count[y][x] +1; res = count[nv_y][nv_x]; que.push( make_pair(nv_x,nv_y) ); } } printf("%d\n", res ); return 0; }
#include <iostream> #include <string> #include <vector> using namespace std; int min(int a, int b) { return(a < b) ? a : b; } class Solution { public: int minDistance(const string &word1, const string &word2) { const size_t m = word1.size() + 1; const size_t n = word2.size() + 1; vector<vector<int> > k(m, vector<int>(n)); for (size_t i = 0; i < m; ++i) k[i][0] = i; for (size_t j = 0; j < n; ++j) k[0][j] = j; for (size_t i = 1; i < m; ++i) { for (size_t j = 1; j < n; ++j) { if (word1[i - 1] == word2[j - 1]) k[i][j] = k[i - 1][j - 1]; else k[i][j] = min(k[i - 1][j - 1], min(k[i - 1][j], k[i][j - 1])) + 1; } } return k[m - 1][n - 1]; } }; int main() { string a, b; cin >> a >> b; Solution A; cout << A.minDistance(a, b) << endl; }
0
#include <iostream> using namespace std; int main( void ) { int a, b, c, d, e, k; cin >> a >> b >> c >> d >> e >> k; if ( ( ( e - a ) <= ( 4 * k ) ) && ( ( d + e - a - b ) <= ( 3 * k ) ) && ( ( d + e - a - b ) <= ( 2 * k ) ) && ( ( e - a ) <= ( k ) ) ) { cout << "Yay!" << endl; } else { cout << ":(" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { vector<int> a(5); rep(i, 5) cin >> a[i]; int k; cin >> k; for (int i = 0; i < 5;i ++){ for (int j = i+1; j < 5; j++){ if(abs(a.at(i)-a.at(j)) >k){ cout << ":("; return 0; } } } cout << "Yay!"; }
1
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<functional> #include<vector> #include<queue> #include<stack> #include<set> #include<map> using namespace std; #define MOD 1000000007 #define f(i,n) for(int i=0;i<int(n);i++) #define N 200000 int main(){ vector<int>a; int n, k; int x, y, z; int s, ans; bool v = true; ans = 0; scanf("%d %d",&x,&n); if(n==1){ scanf("%d", &k); printf("%d\n",k); if(k==1){ printf("1\n1\n"); } else{ printf("2\n1 %d\n",k-1); } return 0; } x=0; y=0; z=0; f(i, n){ scanf("%d", &k); if(k%2==1){ x++; if(y>0)z=k; else y=k; } else a.push_back(k); } if(x>2){ printf("Impossible\n"); return 0; } else if(x>1){ printf("%d",y); f(i,a.size())printf(" %d",a[i]); printf(" %d\n",z); if(z==1){ printf("%d\n",a.size()+1); printf("%d",y+1); f(i,a.size())printf(" %d",a[i]); printf("\n"); } else{ printf("%d\n",a.size()+2); printf("%d",y+1); f(i,a.size())printf(" %d",a[i]); printf(" %d",z-1); printf("\n"); } } else if(x>0){ printf("%d",y); f(i,a.size())printf(" %d",a[i]); printf("\n"); printf("%d\n",a.size()+1); printf("%d",y+1); f(i,a.size()-1)printf(" %d",a[i]); printf(" %d\n",a[a.size()-1]-1); } else{ printf("%d",a[0]); f(i,a.size()-1)printf(" %d",a[i+1]); printf("\n"); printf("%d\n",a.size()); printf("%d",a[0]+1); f(i,a.size()-2)printf(" %d",a[i+1]); printf(" %d\n",a[a.size()-1]-1); } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; int a[3][MAXN]; int f[2][MAXN]; void add(int p, int index) { for (;p < MAXN; p += p&-p) ++f[index][p]; } int find(int p, int index) { int res = 0; for (;p; p -= p&-p) res += f[index][p]; return res; } int32_t main () { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n; cin >> n; for (int i = 0; i < 3; ++i) for (int j = 0; j < n; ++j) cin >> a[i][j]; vector <int> vctr; bool b[2] = {0, 0}; for (int i = 0; i < n; ++i) { int mx = max(a[0][i], max(a[1][i], a[2][i])); int mn = min(a[0][i], min(a[1][i], a[2][i])); if (mx - mn > 2) return cout << "No", 0; if (mx % 3) return cout << "No", 0; if (2 * a[1][i] != a[0][i] + a[2][i]) return cout << "No", 0; if ((mx - i) % 2 == 0) return cout << "No", 0; vctr.push_back(mx / 3); if (a[0][i] == mx) b[i & 1] = 1 - b[i & 1]; // cout << (a[0][i] == mx) << ' '; } // cout << b[0] << ' ' << b[1]; for (int i = n - 1; i >= 0; --i) { if (find(vctr[i], i & 1) & 1) b[(i + 1) & 1] = 1 - b[(i + 1) & 1]; add(vctr[i], i & 1); // cout << vctr[i] << ' '; } if (b[0] || b[1]) return cout << "No", 0; cout << "Yes"; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main () { int R; int G; cin >> R >> G ; cout << (G - R) + G << endl; }
#include <bits/stdc++.h> using namespace std; int main() { double R = 0; cin >> R;//現在のレーティング double G = 0; cin >> G;//したいレーティング //(R + ans) / 2 = G //R + ans = 2*G double ans = 0; ans = 2*G - R; cout << ans << endl; }
1
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <functional> #include <ctime> #include <cmath> #include <limits> #include <numeric> #include <type_traits> #include <iomanip> #include <float.h> #include <math.h> using namespace std; using ll = long long; unsigned euclidean_gcd(unsigned a, unsigned b) { if (a < b) return euclidean_gcd(b, a); unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } class UnionFind { public: vector <ll> par; vector <ll> siz; UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } ll root(ll x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } int main() { ll a, b; cin >> a >> b; cout << max(a * b, max(a + b, a - b)) << endl; }
#include <bits/stdc++.h> using namespace std; int main () { int A, B; cin >> A >> B; int tasu = A + B; int hiku = A - B; int kake = A * B; if (tasu >= hiku && tasu >= kake) { cout << tasu << endl; } else if (hiku >= kake && hiku >= tasu) { cout << hiku << endl; } else { cout << kake << endl; } }
1
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<vector<vector<ll>>> vvvll; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<vector<vector<bool>>> vvvb; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<vpll> vvpll; typedef vector<double> vd; typedef vector<vd> vdd; typedef pair<double, double> pd; typedef vector<pd> vpd; #define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i) #define REP(i,y) FOR(i, 0, y) #define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i) #define RREP(i,x) RFOR(i, x, 0) #define ALL(a) a.begin(), a.end() #define pb push_back #define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x); template <typename First> void debug_print_in(First first){ cerr << first << endl; return; } template <typename First, typename... Rest> void debug_print_in(First first, Rest... rest){ cerr << first << " "; debug_print_in(rest...); return; } void IN(void){ return; } template <typename First, typename... Rest> void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return; } template <typename First> void OUT(First first){ cout << first << endl; return; } template <typename First, typename... Rest> void OUT(First first, Rest... rest){ cout << first << " "; OUT(rest...); return; } template<class t, class u> t chmax(t&a,u b){if(a<b)a=b; return a;}; template<class t, class u> t chmin(t&a,u b){if(a>b)a=b; return a;}; int popcount(int t){return __builtin_popcount(t);} //GCC int popcount(ll t){return __builtin_popcountll(t);} //GCC template <typename T> void vec_print(vector<T> VEC){ REP(i, VEC.size()){ cerr << VEC[i] << " "; } cerr << endl; }; template <typename T> void mat_print(vector<vector<T> > MAT){ REP(i,MAT.size()){ REP(j,MAT[i].size()){ cerr << MAT[i][j] << " "; } cerr << endl; } }; constexpr int INF = (1<<30); constexpr ll INFLL = 1LL<<62; constexpr long double EPS = 1e-12; constexpr ll MOD = (ll)((1E+9)+7); ll N; string S; vll Ms; vvll dp; ll search(ll k){ dp[0][0] = 0; dp[0][1] = 0; dp[0][2] = 0; REP(i,N){ if(i-k>=0){ if(S[i-k]=='D'){ dp[i][0]--; dp[i][1] -= (Ms[i-1]-Ms[i-k]); } } switch(S[i]){ case 'D': dp[i+1][0] = dp[i][0] + 1; dp[i+1][1] = dp[i][1]; dp[i+1][2] = dp[i][2]; break; case 'M': dp[i+1][0] = dp[i][0]; dp[i+1][1] = dp[i][1] + dp[i][0]; dp[i+1][2] = dp[i][2]; break; case 'C': dp[i+1][0] = dp[i][0]; dp[i+1][1] = dp[i][1]; dp[i+1][2] = dp[i][2] + dp[i][1]; break; default: dp[i+1][0] = dp[i][0]; dp[i+1][1] = dp[i][1]; dp[i+1][2] = dp[i][2]; break; } } //mat_print(dp); return dp[N][2]; } int main(){ cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin) ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";) IN(N); IN(S); Ms.resize(N, 0); if(S[0]=='M') Ms[0]++; dp.resize(N+1, vll(3, 0)); FOR(i,1,N){ Ms[i]=Ms[i-1]; if(S[i]=='M') Ms[i]++; } ll Q; IN(Q); REP(q,Q){ ll k; IN(k); OUT(search(k)); } return 0; }
#define _CRT_SECURE_NO_WARNINGS #pragma GCC target("avx") #pragma GCC optimize("O3") #include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <string.h> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define rep(i,n) for(int i=0;i<(lint)(n);i++) #define REP(i,n) for(int i=1;i<=(lint)(n);i++) #define all(V) V.begin(),V.end() #define stackReplaceBegin(size)\ void* p=malloc(size);\ esp_new=(lint)p+size-1;\ void * stack_extend_memory_ = malloc(size);\ void * stack_extend_origin_memory_;\ char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\ *stack_extend_dummy_memory_ = 0;\ asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024)); typedef long long lint; typedef unsigned long long ulint; typedef std::pair<int, int> P; constexpr int INF = INT_MAX/2; constexpr lint LINF = LLONG_MAX/2; constexpr double eps = DBL_EPSILON; constexpr double PI = 3.141592653589793238462643383279; lint esp_new; template<class T> class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {}; template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } inline lint gcd(lint a, lint b) { while (b) { lint c = a; a = b; b = c % b; } return a; } inline lint lcm(lint a, lint b) { return a / gcd(a, b) * b; } bool isprime(lint n) { if (n == 1)return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0)return false; } return true; } template<typename T> T mypow(T a, unsigned int b) { T res(1),now(a); while(b){ if(b&1)res*=now; b>>=1; now*=now; } return res; } template<typename T> void printArray(std::vector<T>& vec) { rep(i, (int)vec.size() - 1)std::cout << vec[i] << " "; if(!vec.empty())std::cout << vec.back() << std::endl; } template<typename T> void printArray(T l, T r) { T rprev = r; rprev--; for (T i = l; i != rprev; i++) { std::cout << *i << " "; } std::cout << *rprev << std::endl; } int h,w,a[510][510]; std::vector<std::pair<P,P>> vec; int main(){ std::cin>>h>>w; rep(i,h){ rep(j,w)std::cin>>a[i][j]; } rep(i,h){ if(i%2==0){ rep(j,w-1){ if(a[i][j]%2){ vec.push_back({{i,j},{i,j+1}}); a[i][j]--; a[i][j+1]++; } } if(a[i][w-1]%2&&i!=h-1){ vec.push_back({{i,w-1},{i+1,w-1}}); a[i][w-1]--; a[i+1][w-1]++; } } else{ for(int j=w-1;j>0;j--){ if(a[i][j]%2){ vec.push_back({{i,j},{i,j-1}}); a[i][j]--; a[i][j-1]++; } } if(a[i][0]%2&&i!=h-1){ vec.push_back({{i,0},{i+1,0}}); a[i][0]--; a[i+1][0]++; } } } std::cout<<vec.size()<<std::endl; for(auto i:vec)std::cout<<i.first.first+1<<" "<<i.first.second+1<<" "<<i.second.first+1<<" "<<i.second.second+1<<std::endl; return 0; }
0
#pragma GCC optimize "-O3" #pragma GCC optimize("Ofast") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define NumberOfOnes __builtin_popcount #define LSOne(S) (S & (-S)) #define ll long long #define two pair<int,int> #define twoll pair<ll,ll> #define four pair<two,two> #define pb push_back #define eb emplace_back #define mk make_pair #define y1 y1922 #define INF 1000000000000000000 #define P 1000000007 #define lmax 1000000000 #define nn 1000003 #define ff first.first #define fs first.second #define sf second.first #define ss second.second #define f first #define s second #define vi vector<int> #define vll vector<ll> #define vtwo vector<two> #define ALL(container) (container).begin(), (container).end() #define sz(container) (int)(container.size()) #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) #define mid(a,b) (a+b>>1) #define minN 0 #define maxN 10000000 #define na(x) ((x)<P?(x):(x)-P) #define ab(a) (-(a)<(a)?(a):-(a)) #define FAST std::ios::sync_with_stdio(false) #define xRand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define rnd rng #define IT iterator typedef tree< int,// aq pair<int,int> shegidzlia null_type, less/*_equal*/<int>,// aqac rb_tree_tag, tree_order_statistics_node_update> ordered_set; // '_equal' mashin ginda roca multiset gchirdeba template<class key, class value,class cmp = std::less<key>> using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>; ordered_map<int, int> my_map; inline int rin(){ int x=0,w=1;char ch=getchar(); while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar(); if (ch=='-') w=0,ch=getchar(); while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar(); return w?x:-x; } inline int bin(){ int x=0;char ch=getchar(); while (ch<'0'||ch>'9') ch=getchar(); while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar(); return x; } int k,n,f[308][308][308]; string s; int main(){FAST;xRand; cin>>s; cin>>k; n=sz(s); for(int i=n-1;i>=0;i--){ for(int j=i;j<n;j++){ for(int p=0;p<=k;p++){ if(i==j){ f[i][j][p]=1; continue; } if(i+1==j){ f[i][j][p]=(s[i]==s[j]||p>0)?2:1; continue; } f[i][j][p]=max(f[i+1][j][p],f[i][j-1][p]); if(s[i]==s[j]){ f[i][j][p]=max(f[i][j][p],f[i+1][j-1][p]+2); } if(p>0){ f[i][j][p]=max(f[i][j][p],f[i+1][j-1][p-1]+2); } } } } cout<<f[0][n-1][k]<<endl; } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <iostream> #include <algorithm> #include <vector> #include <cmath> using namespace std; int N,K; vector<int> pl,mi; void input() { cin >> N >> K; for(int i=0; i<N; ++i){ int x; cin >> x; if(x > 0) pl.emplace_back(x); else if(x < 0) mi.emplace_back(-x); } reverse(mi.begin(),mi.end()); } void solve() { if(N != pl.size() + mi.size()) --K; int ans, left, right; if(pl.empty() && mi.empty()) ans = 0; else if(pl.empty()) ans = mi[K-1]; else if(mi.empty()) ans = pl[K-1]; else { int mi_size = mi.size(); int pl_size = pl.size(); if(pl_size >= K) { left = -1; right = K-1; ans = pl[right]; } else { left = K - pl_size - 1; right = pl_size - 1; if(pl[right] > mi[left]) ans = pl[right] + 2 * mi[left]; else ans = 2 * pl[right] + mi[left]; // cout << mi[left] << " " << pl[right] << endl; } while(1){ ++left; --right; if(left < mi_size){ if(right >= 0){ if(pl[right] > mi[left]) ans = min(ans, pl[right] + 2 * mi[left]); else ans = min(ans, 2 * pl[right] + mi[left]); // cout << mi[left] << " " << pl[right] << endl; } else if(right == -1) ans = min(ans, mi[left]); } else break; } } cout << ans << endl; } int main() { cin.tie(); ios::sync_with_stdio(false); input(); solve(); return 0; }
0
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for(int (i) = 0; (i) < (n); (i)++) #define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++) #define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++) #define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--) #define all(x) (x).begin(), (x).end() #define lint long long #define ulint unsigned long long #define ldou long double #define fi first #define se second #define setpre(x) std::cout << fixed << setprecision(x) #define ii(x) int x; cin >> (x) #define ii2(x, y) int x, y; cin >> (x) >> (y) #define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z) #define out(x) cout << (x) << endl #define outs(x) cout << (x) << " " #define yn(x) cout << ((x)?("Yes"):("No")) << endl #define YN(x) cout << ((x)?("YES"):("NO")) << endl #define bit_c(x) __builtin_popcountll(x) inline void logger(){ std::cout << " [LOGGER] " << endl; } template<typename A, typename... B> void logger(const A& a, const B&... b){ cout << a << " , "; logger(b...); } typedef pair<lint, lint> P; const lint MOD = 1000000007; const lint MOD9 = 998244353; const lint INF = MOD * MOD; const int MAX = 200005; /* ...o(^-^)o... */ int main(){ int a, b, ans; cin >> a >> b; ans = 0; repp(i, a, b+1){ string s = to_string(i); int l = s.length(); bool f = true; rep(j, l){ if(s[j] != s[l-1-j]) f = false; } if(f) ans++; } out(ans); }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> using namespace __gnu_pbds; using namespace std; typedef tree< pair<int, int>, null_type, less_equal<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define int long long #define double long double #define all(a) (a).begin(), (a).end() #define x first #define y second #define lb(v, z) lower_bound(all(v), z) #define ub(v, z) upper_bound(all(v), z) #define rep(i, a, b) for (int i = (a); i <= (b); i++) #define rdp(i, a, b) for (int i = (a); i >= (b); i--) #define rlt(i, a, b) for (int i = (a); i < (b); i++) #define cns(z) cout << (z) << ' ' #define cnl(z) cout << (z) << '\n' #define M1 1000000007 #define M2 998244353 #define MAXN 300005 #define INF (1ll << 60) #define endl "\n" #define garr(ip) \ for (auto &x : ip) \ cin >> x; #define parr(ip) \ for (auto &x : ip) \ cout << x << " "; \ cout << endl; #define nl cout << endl typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int>> vp; void solve(int testCaseNumber = 1) { int n; cin >> n; string ans; while (n > 0) { n--; ans += 'a' + n % 26; n /= 26; } reverse(all(ans)); cnl(ans); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); solve(); }
0
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) inline void reset(int cnt[], int& state) { REP(i, 3) cnt[i] = 0; state = 0; } int main() { int ans = 0, cnt[3], state; char JOI[] = {'J', 'O', 'I'}; reset(cnt, state); while (1) { int c = getchar(); if (c == JOI[state]) { cnt[state]++; } else { if (state == 2) { if (cnt[1] <= min(cnt[0], cnt[2])) ans = max(ans, cnt[1]); reset(cnt, state); } else if (c == JOI[state + 1]) { state++; } else reset(cnt, state); if (c == JOI[state]) cnt[state]++; } if (c == '\n') break; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; #define ll long long const int inf = 1000000000; int main(){ string s; cin >> s; int n=s.size()-2; int ans = inf; rep(i,n){ int x=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0'); ans = min(ans,abs(x-753)); } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; while (cin >> n) { long long stool = 0; int prev = 0; for (int i = 0; i < n; ++i) { int aux; cin >> aux; if (aux <= prev) { stool += (prev - aux); } else { prev = aux; } } cout << stool << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; long long a[200000],l[200000]; signed main() { ios::sync_with_stdio(0); long long n,i; long long ans=0; cin >> n; for(i=1; i<=n; i++) cin >> a[i]; for(i=1; i<=n; i++) l[i]=max(a[i],l[i-1]); for(i=1; i<=n; i++) ans+=l[i]-a[i]; cout << ans << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; bool c=true; for(int i=97;i<=122;i++){ c=true; for(int j=0;s[j]!='\0';j++){ if(char(i)==s[j]){ c=false; continue; } } if(c==true){ cout<<char(i); break; } } if(c==false) cout<<"None"; return 0; }
#include<stdio.h> #include<string.h> int main() { char a[20], b[20], c[20]; scanf("%s %s %s", &a, &b, &c); int al, bl; al = strlen(a)-1; bl = strlen(b)-1; if(a[al]==b[0] && b[bl]==c[0]) printf("YES"); else printf("NO"); }
0
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <set> #include <cmath> #include <stdio.h> #include <list> #include <numeric> #include <stack> #include <queue> #include <tuple> #include <bitset> #include <map> #include <math.h> //ceil(a/b) (a + (b - 1))/ b using namespace std; #define rep(i,n) for(int i = 0; i < (n); i++) typedef long long ll; typedef pair<int,int> P; const int inf=1000000007; const ll mod=1000000007; const double PI=3.14159265358979323846; int dx[] = {1,-1,0,0}; int dy[] = {0,0,1,-1}; ll gcd(ll a, ll b){ if (b==0) return a; else return gcd(b,a%b); } int cans(bool f){ if(f) cout << "Yes" << endl; else cout << "No" << endl; return 0; } int main(){ ll N; cin >> N; char a[28]; string s = ""; for(char i='a'; i<='z';i++){ a[int(i) - int('a')] = i; } while(N){ N--; s += a[N%26]; N /= 26; } reverse(s.begin(), s.end()); cout << s << endl; return 0; }
#include <iostream> #include <string> typedef long long ll; std::string alphabet = "abcdefghijklmnopqrstuvwxyz"; ll N; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); std::cin >> N; std::string ans = ""; while (N) { N--; ans = alphabet[N % 26] + ans; N /= 26; } std::cout << ans << "\n"; return 0; }
1
#include <string> #include <iostream> using namespace std; int main(){ string angou; while (getline(cin, angou)){ int a = angou.size(); for (int i = 0; i < 26; i++) { for (int q = 0; q < a; q++){ if (angou[q] == ' ' || angou[q] == '.') continue; if (angou[q] == 'z') angou[q] = 'a'; else angou[q]++; } bool theExists = angou.find("the") != string::npos; bool thisExists = angou.find("this") != string::npos; bool thatExists = angou.find("that") != string::npos; if (theExists || thisExists || thatExists) { cout << angou << endl; continue; } } } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ string s; cin>>s; int l=s.length(),j,k; vector<int> v(26,-1); for(j=0;j<l;j++){ k=s[j]-'a'; if(v[k]==-1||j-v[k]>2) v[k]=j; else{ cout<<v[k]+1<<' '<<j+1<<endl; return 0; } } cout<<"-1 -1"<<endl; }
0
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define ar array #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define vt vector #define pb push_back #define all(c) (c).begin(), (c).end() #define sz(x) (int)(x).size() #define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s)) #define F_OR1(e) F_OR(i, 0, e, 1) #define F_OR2(i, e) F_OR(i, 0, e, 1) #define F_OR3(i, b, e) F_OR(i, b, e, 1) #define F_OR4(i, b, e, s) F_OR(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define EACH(x, a) for (auto& x: a) template<class A> void read(vt<A>& v); template<class A, size_t S> void read(ar<A, S>& a); template<class T> void read(T& x) { cin >> x; } void read(double& d) { string t; read(t); d=stod(t); } void read(long double& d) { string t; read(t); d=stold(t); } template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); } template<class A> void read(vt<A>& x) { EACH(a, x) read(a); } template<class A, size_t S> void read(array<A, S>& x) { EACH(a, x) read(a); } string to_string(char c) { return string(1, c); } string to_string(bool b) { return b?"true":"false"; } string to_string(const char* s) { return string(s); } string to_string(string s) { return s; } string to_string(vt<bool> v) { string res; FOR(sz(v)) res+=char('0'+v[i]); return res; } template<size_t S> string to_string(bitset<S> b) { string res; FOR(S) res+=char('0'+b[i]); return res; } template<class T> string to_string(T v) { bool f=1; string res; EACH(x, v) { if(!f) res+=' '; f=0; res+=to_string(x); } return res; } template<class A> void write(A x) { cout << to_string(x); } template<class H, class... T> void write(const H& h, const T&... t) { write(h); write(t...); } void print() { write("\n"); } template<class H, class... T> void print(const H& h, const T&... t) { write(h); if(sizeof...(t)) write(' '); print(t...); } void DBG() { cerr << "]" << endl; } template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef _DEBUG #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) #else #define dbg(...) 0 #endif template<class T> void offset(ll o, T& x) { x+=o; } template<class T> void offset(ll o, vt<T>& x) { EACH(a, x) offset(o, a); } template<class T, size_t S> void offset(ll o, ar<T, S>& x) { EACH(a, x) offset(o, a); } mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count()); ll randint(ll a, ll b) { return uniform_int_distribution<ll>(a, b)(mt_rng); } const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1}; const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1}; ll mod=1e9+7; const int N=1e6+5; const ld PI=2*acos(0.0); ll modpow(ll a, ll b){ ll res=1; a%=mod; while(b){ if(b&1){ res=(res*a)%mod;} a=(a*a)%mod; b>>=1; } return res; } #define lcm(a,b) ((a)*(b))/(__gcd(a,b)) bool compare(array<int,2> a,array<int,2> b){ return a[0]<b[0]; } void solve() { int n,t; read(n,t); vt<array<int,2> > td(n+1); FOR(i,1,n+1) read(td[i][0],td[i][1]); sort(++td.begin(),td.end(),compare); int siz=(*--td.end())[0]+t+5; vt<int> dp(siz,0); vt<int> pre(siz,0); FOR(i,1,n+1){ FOR(j,1,siz){ if(j-td[i][0]<0||j-td[i][0]>=t) { dp[j]=pre[j];} else{ dp[j]=max(pre[j],pre[j-td[i][0]]+td[i][1]);} } FOR(j,1,siz){ pre[j]=dp[j]; dp[j]=0; } //dbg(i,pre); } print(*max_element(all(pre))); } int main() { ios::sync_with_stdio(0); cin.tie(0); solve(); }
#include <bits/stdc++.h> using namespace std; using ll =long long; typedef pair<int,int> P; #define SORT(a) sort((a).begin(),(a).end()) #define rSORT(a) reverse((a).begin(),(a).end()) #define For(i, a, b) for(int i = (a) ; i < (b) ; ++i) #define rep(i, n) For(i, 0, n) #define debug(x) cerr << #x << " = " << (x) << endl; 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; } //Write From this Line int dp[3010][10000]; int main() { int n, t; cin >> n >> t; vector<P> p(n); rep(i,n) cin >> p[i].first >> p[i].second; // 時間、美味しさ。 SORT(p); int ans = 0; rep(i,n){ rep(j,t){ chmax(dp[i+1][j], dp[i][j]); int nj = j + p[i].first; if(nj < t) chmax(dp[i+1][nj], dp[i][j] + p[i].second); } int now = dp[i][t-1]+p[i].second; // chmax(ans,now); } cout << ans << endl; }
1
#include <iostream> #include <stdio.h> using namespace std; int main(void){ int l, i=0, a[10]; while(2 > i){ cin >> a[i]; i++; } if (a[0] > 8 || a[1] > 8) { cout << ":(" << "\n"; } else { cout << "Yay!" << "\n"; } }
#include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ int a, b; cin >> a >> b; cout << (((a <= 8) && (b <= 8)) ? "Yay!" : ":(") << endl; return 0; }
1
#include<bits/stdc++.h> using namespace std; struct Node{ int key; Node *right,*left,*parent; }; Node *root,*NIL; Node * tmin(Node *x){ while(x->left!=NIL)x=x->left; return x; } Node * treeSuccessor(Node *x){ if(x->right!=NIL)return tmin(x->right); Node *y=x->parent; while(y!=NIL&&x==y->right){ x=y; y=y->parent; } return y; } void tdel(Node *z){ Node *y; Node *x; if(z->left==NIL||z->right==NIL)y=z; else y=treeSuccessor(z); if(y->left!=NIL){ x=y->left; } else{ x=y->right; } if(x!=NIL){ x->parent = y->parent; } if(y->parent==NIL){ root=x; } else{ if(y==y->parent->left){ y->parent->left=x; } else{ y->parent->right=x; } } if(y!=z){ z->key = y->key; } free(y); } Node * find(Node *u,int k){ while(u != NIL && k!=u->key){ if(k<u->key)u=u->left; else u = u -> right; } return u; } void insert(int k){ Node *y = NIL; Node *x = root; Node *z; z=(Node *)malloc(sizeof(Node)); z->key = k; z->left = NIL; z->right = NIL; while(x!=NIL){ y=x; if(z->key < x->key){ x=x->left; }else{ x=x->right; } } z->parent = y; if(y==NIL){ root = z; }else{ if(z->key < y->key){ y->left = z; }else{ y->right = z; } } } void inorder(Node *u){ if(u==NIL)return; inorder(u->left); cout << " " << u->key; inorder(u->right); } void preorder(Node *u){ if(u==NIL)return; cout << " " << u->key; preorder(u->left); preorder(u->right); } int main(){ int n,m; string func; cin >> n; for(int i=0;i<n;i++){ cin >> func; if(func=="find"){ cin >> m; Node *t=find(root,m); if(t!=NIL)cout << "yes" << endl; else cout << "no" << endl; } else if(func=="insert"){ cin >> m; insert(m); } else if(func=="print"){ inorder(root); cout << endl; preorder(root); cout << endl; } else if(func=="delete"){ cin >> m; tdel(find(root,m)); } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define mp make_pair #define ff first #define ss second #define pb push_back #define pf push_front #define popb pop_back #define popf pop_front #define all(v) v.begin(),v.end() const int maxn = 1e5 + 100; const ll inf = 2e18, mod = 1e9 + 7; int n, a[maxn]; bool bad() { for (int i = 0; i < n; i++) if (a[i] != 1) return false; return true; } void solve(int turn = 0) { if (bad()) { cout << ((1 - turn) ? "Second" : "First") << endl; return; } int parity = 0; bool check = false; for (int i = 0; i < n; i++) parity ^= (a[i] & 1), check |= (a[i] == 1); if (check) { if (parity ^ (n & 1)) cout << (turn ? "Second" : "First") << endl; else cout << ((1 - turn) ? "Second" : "First") << endl; return; } if (n & 1) { if (!parity) { cout << (turn ? "Second" : "First") << endl; return; } else { int cnt = 0; for (int i = 0; i < n; i++) cnt += (a[i] & 1); if (cnt > 1) { cout << ((1 - turn) ? "Second" : "First") << endl; return; } else { for (int i = 0; i < n; i++) if (a[i] & 1) a[i]--; int GCD = a[0]; for (int i = 1; i < n; i++) GCD = __gcd(a[i], GCD); for (int i = 0; i < n; i++) a[i] /= GCD; solve(1 - turn); } } } else { if (!parity) cout << ((1 - turn) ? "Second" : "First") << endl; else cout << (turn ? "Second" : "First") << endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; solve(); }
0
#include<stdio.h> int main(){ int n, r, t; scanf("%d %d", &n, &r); t = 100 * (10 - n); if(n<10){ printf("%d\n", r+t); } else{ printf("%d\n", r); } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; #define chmax(x,y) x = max(x,y); #define chmin(x,y) x = min(x,y); const int di[] = {-1, 0, 1, 0}; const int dj[] = {0, -1, 0, 1}; const int INF = 1001001001; int main() { int n, k; cin >> n >> k; if (n%k != 0) cout << 1 << endl; else cout << 0 << endl; return 0; }
0
#include <iostream> #include <algorithm> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #include <queue> #include <cmath> #include <bitset> #include <complex> #include <functional> // output #define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' '); #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl // utility #define ALL(i) (i).begin(), (i).end() #define FOR(i, a, n) for(int i=(a);i<(n);++i) #define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i) #define REP(i, n) for(int i=0;i<int(n);++i) #define RREP(i, n) for(int i=int(n)-1;i>=0;--i) #define IN(a, x, b) (a<=x && x<b) #define OUT(a, x, b) (x<a || b<=x) template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; } template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; } // type/const #define int ll using ll = long long; using ull = unsigned long long; using ld = long double; const int MOD = 1000000007; /* const int MOD = 1000000007; */ const int INF = 1e18; const double PI = acos(-1); using namespace std; signed main() { int H, W, K; cin >> H >> W >> K; vector<vector<int>> dp(H+1, vector<int>(W, 0)); dp[0][0] = 1; REP(i, H) REP(j, W) REP(k, (1<<(W-1))){ bool ok = true; REP(l, W-2){ if(((k >> l)&1) && ((k >> (l+1))&1)) ok = false; } if(ok){ if(j >= 1 && ((k >> (j-1))&1)){ dp[i+1][j-1] += dp[i][j]; dp[i+1][j-1] %= MOD; }else if(j <= W-2 && ((k >> j)&1)){ dp[i+1][j+1] += dp[i][j]; dp[i+1][j+1] %= MOD; }else{ dp[i+1][j] += dp[i][j]; dp[i+1][j] %= MOD; } } } cout << dp[H][K-1] << endl; return 0; }
#include<bits/stdc++.h> typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef double lf; typedef long double llf; typedef std::pair<int,int> pii; #define xx first #define yy second template<typename T> inline T max(T a,T b){return a>b?a:b;} template<typename T> inline T min(T a,T b){return a<b?a:b;} template<typename T> inline T abs(T a){return a>0?a:-a;} template<typename T> inline bool repr(T &a,T b){return a<b?a=b,1:0;} template<typename T> inline bool repl(T &a,T b){return a>b?a=b,1:0;} template<typename T> inline T gcd(T a,T b){T t;if(a<b){while(a){t=a;a=b%a;b=t;}return b;}else{while(b){t=b;b=a%b;a=t;}return a;}} template<typename T> inline T sqr(T x){return x*x;} #define mp(a,b) std::make_pair(a,b) #define pb push_back #define I inline #define mset(a,b) memset(a,b,sizeof(a)) #define mcpy(a,b) memcpy(a,b,sizeof(a)) #define fo0(i,n) for(int i=0,i##end=n;i<i##end;i++) #define fo1(i,n) for(int i=1,i##end=n;i<=i##end;i++) #define fo(i,a,b) for(int i=a,i##end=b;i<=i##end;i++) #define fd0(i,n) for(int i=(n)-1;~i;i--) #define fd1(i,n) for(int i=n;i;i--) #define fd(i,a,b) for(int i=a,i##end=b;i>=i##end;i--) #define foe(i,x)for(__typeof((x).end())i=(x).begin();i!=(x).end();++i) struct Cg{I char operator()(){return getchar();}}; struct Cp{I void operator()(char x){putchar(x);}}; #define OP operator #define RT return *this; #define RX x=0;char t=P();while((t<'0'||t>'9')&&t!='-')t=P();bool f=0;\ if(t=='-')t=P(),f=1;x=t-'0';for(t=P();t>='0'&&t<='9';t=P())x=x*10+t-'0' #define RL if(t=='.'){lf u=0.1;for(t=P();t>='0'&&t<='9';t=P(),u*=0.1)x+=u*(t-'0');}if(f)x=-x #define RU x=0;char t=P();while(t<'0'||t>'9')t=P();x=t-'0';for(t=P();t>='0'&&t<='9';t=P())x=x*10+t-'0' #define TR *this,x;return x; I bool IS(char x){return x==10||x==13||x==' ';}template<typename T>struct Fr{T P;I Fr&OP,(int&x) {RX;if(f)x=-x;RT}I OP int(){int x;TR}I Fr&OP,(ll &x){RX;if(f)x=-x;RT}I OP ll(){ll x;TR}I Fr&OP,(char&x) {for(x=P();IS(x);x=P());RT}I OP char(){char x;TR}I Fr&OP,(char*x){char t=P();for(;IS(t);t=P());if(~t){for(;!IS (t)&&~t;t=P())*x++=t;}*x++=0;RT}I Fr&OP,(lf&x){RX;RL;RT}I OP lf(){lf x;TR}I Fr&OP,(llf&x){RX;RL;RT}I OP llf() {llf x;TR}I Fr&OP,(uint&x){RU;RT}I OP uint(){uint x;TR}I Fr&OP,(ull&x){RU;RT}I OP ull(){ull x;TR}};Fr<Cg>in; #define WI(S) if(x){if(x<0)P('-'),x=-x;char s[S],c=0;while(x)s[c++]=x%10+'0',x/=10;while(c--)P(s[c]);}else P('0') #define WL if(y){lf t=0.5;for(int i=y;i--;)t*=0.1;if(x>=0)x+=t;else x-=t,P('-');*this,(ll)(abs(x));P('.');if(x<0)\ x=-x;while(y--){x*=10;x-=floor(x*0.1)*10;P(((int)x)%10+'0');}}else if(x>=0)*this,(ll)(x+0.5);else *this,(ll)(x-0.5); #define WU(S) if(x){char s[S],c=0;while(x)s[c++]=x%10+'0',x/=10;while(c--)P(s[c]);}else P('0') template<typename T>struct Fw{T P;I Fw&OP,(int x){WI(10);RT}I Fw&OP()(int x){WI(10);RT}I Fw&OP,(uint x){WU(10);RT} I Fw&OP()(uint x){WU(10);RT}I Fw&OP,(ll x){WI(19);RT}I Fw&OP()(ll x){WI(19);RT}I Fw&OP,(ull x){WU(20);RT}I Fw&OP() (ull x){WU(20);RT}I Fw&OP,(char x){P(x);RT}I Fw&OP()(char x){P(x);RT}I Fw&OP,(const char*x){while(*x)P(*x++);RT} I Fw&OP()(const char*x){while(*x)P(*x++);RT}I Fw&OP()(lf x,int y){WL;RT}I Fw&OP()(llf x,int y){WL;RT}};Fw<Cp>out; const int N=100007; int n,t[N][3],s[N]; int main() { in,n; fo0(l,3)fo1(i,n)in,t[i][l]; fo1(i,n) { int p=(t[i][0]-1)/3; //out,p,'\n'; bool f1=1,f2=1; fo0(j,3)f1&=t[i][j]==p*3+j+1; fo0(j,3)f2&=t[i][j]==p*3+3-j; if((!f1&&!f2)||(~(i^p)&1))return puts("No"),0; s[i]=f1?p+1:-p-1; } //fo1(i,n)out,s[i],' ';out,'\n'; int a[2]={0,0},b[2]={0,0}; fo1(i,n)a[i&1]^=s[i]<0; fo1(i,n)while(abs(s[i])!=i)std::swap(s[i],s[abs(s[i])]),b[i&1]^=1; out,a[0]==b[1]&&a[1]==b[0]?"Yes":"No",'\n'; }
0
#include <stdio.h> int n,k,i,j,p,num[5040],c[4],card[10],ans; void set(int x){ int i,j; if (x==k) { for (i=0; i<k; i++) { num[p]=num[p]*10; if (card[c[i]]>=10) { num[p]=num[p]*10; } num[p]+=card[c[i]]; } p++; return; } for (i=0; i<n; i++) { int flag=1; for (j=0; j<x; j++) { if (c[j]==i) { flag=0; break; } } if (flag) { c[x]=i; set(x+1); } } return; } int main(){ while (1) { scanf("%d%d",&n,&k); if (n==0&&k==0) { return 0; } for (i=0; i<n; i++) { scanf("%d",&card[i]); } for (i=0; i<5040; i++) { num[i]=0; } p=0; set(0); ans=0; k=p; while (k>0) { for (i=0; i<p; i++) { if (num[i]!=-1) { ans++; k--; for (j=i+1; j<p; j++) { if (num[i]==num[j]) { k--; num[j]=-1; } } } } } printf("%d\n",ans); } }
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <climits> #include <vector> #include <string> #include <queue> #include <deque> #include <list> #include <stack> #include <set> #include <map> #include <algorithm> #define int long long #define MOD7 1000000007 #define MOD9 1000000009 #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, a, n) for (int i = (a); i <= (n); i++) #define all(a) (a).begin(), (a).end() using namespace std; int dx[4] = { 1, 0, -1, 0 }; int dy[4] = { 0, -1, 0, 1 }; int nextInt() {int a; cin >> a; return a;} char nextChar() {char a; cin >> a; return a;} double nextDouble() {double a; cin >> a; return a;} string nextString() {string a; cin >> a; return a;} void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}} void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}} void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}} class Fruit { public: int time; int gain; string name; Fruit(string name) { time = 0; gain = 0; this->name = name; } bool operator< (const Fruit &a) const { if (gain * a.time == a.gain * time) return name < a.name; return gain * a.time > a.gain * time; } }; signed main() { int N; while (cin >> N) { if (!N) break; vector<Fruit> fruits; rep(i, N) { string L; int P, A, B, C, D, E, F, S, M; cin >> L >> P >> A >> B >> C >> D >> E >> F >> S >> M; Fruit fruit = Fruit(L); fruit.time = A + B + C; fruit.time += (D + E) * M; fruit.gain = S * F * M - P; fruits.push_back(fruit); } sort(all(fruits)); rep(i, N) { cout << fruits[i].name << endl; } cout << "#" << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ string s; cin>>s; if(s.size()!=26){ map<char,int> mp; rep(i,s.size()){ mp[s[i]]=1; } rep(i,26){ if(mp['a'+i]!=1){ s+=('a'+i); break; } } cout<<s<<endl; }else{ if(s=="zyxwvutsrqponmlkjihgfedcba"){ cout<<-1<<endl; return 0; } vector<char> tmp; tmp.push_back(s[25]); for(int i=24; i>=0; i--){ char ch='{'; for(auto x : tmp){ if(x > s[i]){ ch=min(ch,x); } } if(ch!='{'){ s = s.substr(0,i); s+=ch; break; } tmp.push_back(s[i]); } cout<<s<<endl; } }
#include <vector> #include <map> #include <set> #include <stack> #include <queue> #include <algorithm> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <string> #include <cstring> #include <complex> #include <ctime> #include <cstdlib> using namespace std; inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;} template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();} typedef long long ll; const int N_prime = 15000; class prime { public: prime(); vector<int> primeList; bool used[N_prime]; }; prime::prime() { memset(used, true, sizeof(used)); //一千万までの素数 for(int i = 2; i < sqrt( N_prime ); i++) { if(used[i] == false) { continue; } for(int j = i*2; j < N_prime; j += i) { used[j] = false; } } for(int i = 2; i < N_prime; i++) { if(used[i] == true) { primeList.push_back(i); } } } int main() { prime twin; int limit; while(cin >> limit, limit) { for(int i = 0; i < 10001; i++) { if(twin.primeList[i] > limit) { limit = i-1; break; } else if(twin.primeList[i] == limit) { limit = i; break; } } for(int i = limit; i > 0; i--) { if(twin.primeList[i-1] == twin.primeList[i]-2) { printf("%d %d\n",twin.primeList[i-1] ,twin.primeList[i]); break; } } } }
0
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; int x = 100; int f = n/x; int q = n%10; n /= 10; int y = n%10; if(y > f)cout << f + 1 << f + 1 << f + 1 << '\n'; else if(y == f && q > f) cout << f + 1 << f + 1 << f + 1 << '\n'; else cout << f << f << f << '\n'; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (3 == (int)s.size()) { reverse(s.begin(), s.end()); cout << s << endl; } else { cout << s << endl; } }
0
#include <bits/stdc++.h> using namespace std; int main(){ int h, w, a, b; cin >> h >> w >> a >> b; for (int i=0; i<h; i++){ for (int j=0; j<w; j++){ if ((i<b && j<a) || (i>=b && j>=a)) cout << "1"; else cout << "0"; } cout << "\n"; } }
#include <bits/stdc++.h> #define ll long long #define MODV 1000000007 #define INFLL LLONG_MAX // 9223372036854775807 #define EPS 1e-9 #define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++) #define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++) #define all(v) v.begin(), v.end() #define endl "\n" #define vi vector<ll> #define vvi vector<vector<ll>> #define Yes() cout << "Yes" << endl #define YES() cout << "YES" << endl #define No() cout << "No" << endl #define NO() cout << "NO" << endl #define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15); template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; } using namespace std; int main(){ Init(); ll h, w, a, b; cin >> h >> w >> a >> b; string zo = string(a, '0') + string(w-a, '1'); string oz = string(a, '1') + string(w-a, '0'); rep(i, h) cout << (i<b ? zo : oz) << endl; }
1
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1000000007; int main(){ int n; string s; cin >> n >> s; for(int i=0; i<2*n; i++){ if((i + (s[i] == 'W')) % 2 == 0){ s[i] = 'L'; } else{ s[i] = 'R'; } } if(count(s.begin(), s.end(), 'L') != n) cout << 0 << endl; else{ ll ans = 1; int left = 0; for(int i=0; i<2*n; i++){ if(s[i] == 'L') left++; else{ ans *= left; left--; ans %= MOD; } } for(int i=1; i<n+1; i++){ ans *= i; ans %= MOD; } cout << ans << endl; } }
#include <cstdio> using namespace std; #define MOD 1000000007 char s[200007]; int main(){ register int n, n2, i, ans, cnt, pre, now; scanf("%d", &n); n2 = n * 2; scanf("%s", s + 1); if (s[1] == 'W' || s[n2] == 'W') { puts("0"); return 0; } ans = cnt = 1, pre = 0; for (i = 2; i < n2; ++i) { if (s[i - 1] != s[i]) now = pre; else now = pre ^ 1; //now: 0 = [, 1 = ] if (now) { ans = 1ll * ans * cnt % MOD; --cnt; } else ++cnt; pre = now; } if (cnt > 1) { puts("0"); return 0; } for (i = 2; i <= n; ++i) ans = 1ll * ans * i % MOD; printf("%d\n", cnt == 1 ? ans : 0); return 0; }
1
// D - Factorization #include <bits/stdc++.h> using namespace std; typedef long long ll; // const int INF = 2147483647; // const ll INF = 9223372036854775807; const int MOD = 1000000007; vector<pair<ll, ll>> prime_factorize(ll n) { vector<pair<ll, ll> > result; for (ll p=2; p*p<=n; p++) { if (n % p != 0) continue; ll num = 0; while (n % p == 0) { num++; n /= p; } result.push_back(make_pair(p, num)); } if (n != 1) { result.push_back(make_pair(n, 1)); } return result; } vector<ll> prime_factorize_straight(ll n) { vector<ll> result; vector<pair<ll, ll>> pair_result = prime_factorize(n); for (auto pair : pair_result) { for (ll i=0; i<pair.second; i++) { result.push_back(pair.first); } } return result; } // mod p (pは素数)の下でのべき乗を求める ll mod_pow(ll a, ll n, ll p) { ll result = 1; while (n > 0) { if (n & 1) result = result * a % p; a = a * a % p; n >>= 1; } return result; }; // mod p(pは素数)の下での逆元を求める(フェルマーの小定理を利用) ll mod_inverse(ll a, ll p) { return mod_pow(a, p-2, p); } // mod p (pは素数)の下での除算 (a / b) ll mod_devide(ll a, ll b, ll p) { return a * mod_inverse(b, p) % p; } ll mod_comb(ll n, ll k, ll p) { ll numerator = 1; for (int i=n; i>n-k; i--) { numerator *= i; numerator %= p; } ll denominator = 1; for (int i=k; i>0; i--) { denominator *= i; denominator %= p; } return mod_devide(numerator, denominator, p); } int main() { int N, M; cin >> N >> M; vector<pair<ll, ll>> pf = prime_factorize(M); ll ans = 1; for (auto p : pf) { int k = p.second; ans = (ans * mod_comb(k+N-1, N-1, MOD)) % MOD; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, int> Pli; ll N, M; const int MAX = 5.0e5 + 100; const int MOD = 1.0e9 + 7; ll fac[MAX], finv[MAX], inv[MAX]; vector<ll> primeFactorization(ll n) { vector<ll> ret; ll a = 2; while (n >= a * a) { if (n % a == 0) { ret.push_back(a); n /= a; } else a++; } ret.push_back(n); return ret; } 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; } } ll 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; } int main() { COMinit(); cin >> N >> M; if (M == 1) { cout << 1 << endl; } else { vector<ll> pf = primeFactorization(M); map<ll, ll> mp; for (int i = 0; i < pf.size(); i++) { mp[pf[i]]++; } ll ans = 1; for (auto itr = mp.begin(); itr != mp.end(); itr++) { ll val = itr->second; ans = (ans * COM(N+val-1, val)) % MOD; } cout << ans << endl; } return 0; }
1
#include<iostream> #include<algorithm> #include<vector> #include<queue> #define lol(i,n) for(int i=0;i<n;i++) #define mod 1000000007 #define maz(a,b) a=max(a,b); typedef long long ll; using namespace std; #define N 310 ll d[N][N][N],n,x; string s; int main(){ cin>>s>>x; n=s.size(); lol(k,x+1)lol(i,n)d[0][i][k]=0,d[1][i][k]=1; for(ll t=2;t<=n;t++){ for(ll i=0;i+t-1<n;i++)lol(k,x+1){ ll l=i,r=i+t-1; ll res=max(d[t-1][i][k],d[t-1][i+1][k]); if(s[l]==s[r]){ maz(res,d[t-2][i+1][k]+2); } else if(k){ maz(res,d[t-2][i+1][k-1]+2); } d[t][i][k]=res; } } cout<<d[n][0][x]<<endl; return 0; }
#include <algorithm> #include <assert.h> #include <bitset> #include <cfloat> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <string.h> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> #define rep(i,n) for(int i=0;i<n;i++) #define REP(i,n) for(int i=1;i<=n;i++) #define int long long #define ll long long #define eps LDBL_EPSILON #define mod (ll)1000000007 #define INF LLONG_MAX/10 #define P pair<int,int> #define prique priority_queue using namespace std; int n; string s; bool b[200010]; signed main() { cin >> n >> s; if (s[0] == 'W' || s.back() == 'W') { cout << 0 << endl; return 0; } REP(i, 2 * n - 1) { if (s[i - 1] == s[i] && !b[i - 1])b[i] = true; if (s[i - 1] != s[i] && b[i - 1])b[i] = true; } if (!b[2 * n - 1]) { cout << 0 << endl; return 0; } int ans = 1, cnt = 0; rep(i, 2 * n) { if (b[i]) { ans *= cnt; ans %= mod; cnt--; } else cnt++; } if (cnt) { cout << 0 << endl; return 0; } REP(i, n) { ans *= i; ans %= mod; } cout << ans << endl; }
0
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native") // //#include <immintrin.h> //#include <emmintrin.h> #include <bits/stdc++.h> //#pragma GCC optimize("O2") #define vi vector<int> #define pii pair<int, int > #define mp make_pair #define fi first #define se second #define pb push_back #define LL long long #define rep(i,a,n) for (int i=a;i<=n;i++) #define per(i,a,n) for (int i=n;i>=a;i--) #define all(x) (x).begin(), (x).end() #define all2(x,n) (x+1), (x+1+n) #define sz(x) ((int)(x).size()) #define mod(x) ((x)%MOD) #define debug(x) cerr<<#x<<" : "<<x<<endl #define mt make_tuple #define eb emplace_back #define o(X) (1<<(X)) #define oL(X) (1LL<<(X)) #define contain(S,X) (((S)&o(X))!=0) #define containL(S,X) (((S)&oL(X))!=0) using namespace std; const int INF=0x3f3f3f3f,N=1e6+5,MOD=998244353; const LL INF_LL=0x3f3f3f3f3f3f3f3fLL; inline int getplc(int x,int y) { return (x>>y)&1; } template<typename T> T square(T x) {return x*x;} LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){ LL res=1; for(;b;b>>=1,a=a*a%_MOD){ if(b&1)res=res*a%_MOD; } return res; } // Smax //int Smax() { return -INF; } template <typename T> T Smax(T x) { return x; } template<typename T, typename... Args> T Smax(T a, Args... args) { return max(a, Smax(args...)); } // Smin template <typename T> T Smin(T x) { return x; } template<typename T, typename... Args> T Smin(T a, Args... args) { return min(a, Smin(args...)); } template <typename T> // erro #define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); errl(_it, args); } void errl(istream_iterator<string> it) {} template<typename T, typename... Args> void errl(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; errl(++it, args...); } #define error(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...); } void Solve(); int main() { #ifndef ONLINE_JUDGE // freopen("in.txt","r",stdin); // freopen("o1.txt","w",stdout); #endif ios::sync_with_stdio(false);cin.tie(0),cout.tie(0); Solve(); return 0; } ////////////////////////////////////////////////////////////////// int l[N],r[N],id[N]; int n; int a[N],s[N],pre[N],ans[N]; void add(int x,int y){ for(;x<=n;x+=x&-x)s[x]+=y; } int ask(int x){ int res=0; for(;x;x-=x&-x)res+=s[x]; return res; } void Solve(){ int q; cin>>n>>q; rep(i,1,n){ cin>>a[i]; } rep(i,1,q){ cin>>l[i]>>r[i]; id[i]=i; } sort(id+1,id+1+q,[&](int a,int b){ return r[a]<r[b]; }); int r=1; rep(i,1,n){ if(pre[a[i]])add(pre[a[i]],-1); add(i,1); pre[a[i]]=i; // error(i); // rep(j,1,n)error(j,ask(j)); while(r<=q&&::r[id[r]]<=i){ // error(i,l[id[r]],::r[id[r]]); ans[id[r]]=ask(i)-ask(l[id[r]]-1); r++; } } rep(i,1,q){ cout<<ans[i]<<'\n'; } }
#include <bits/stdc++.h> using namespace std; #define int long long #define itn int #define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++) #define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--) #define rep(i, n) For(i, 0, n - 1) #define repall(i, arr) for (auto& i : (arr)) #define all(x) (x).begin(), (x).end() #define pb push_back #define dump(x) cerr << #x << " = " << (x) << '\n' #define dump2(x, y) \ cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n' #define SZ(x) ((int)(x).size()) #define bit(n) (1LL << (n)) constexpr int MOD = 1e9 + 7; template <typename T> using pq = priority_queue<T>; template <typename T> using pqr = priority_queue<T, vector<T>, greater<T>>; const int INF = LLONG_MAX / 2; using P = pair<int, int>; using vec = vector<int>; template <typename T> using mat = vector<vector<T>>; // clang-format off template <typename T1, typename T2> ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; } template <typename T> void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; } template <typename Arg> void print(const Arg arg) { cout << arg << '\n'; } template <typename Head, typename... Args> void print(const Head head, const Args... args) { cout << head << " "; print(args...); } template <typename T, typename U> void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; } template <typename T> void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; } template <typename T> T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); } template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; } template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; } template <typename T> int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); } template <typename T = int> mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); } template <typename T = int> vector<T> ivec(int n) { vector<T> v(n); init(v); return v; } // clang-format on void yn(bool tf) { print(tf ? "Yes" : "No"); } void YN(bool tf) { print(tf ? "YES" : "NO"); } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } // ------------------------------------------------------------------- // sort 1 2 3 4 // pqr 1 2 3 must impl > signed main() { cin.tie(0), cout.tie(0), ios::sync_with_stdio(false); int a, b; cin >> a >> b; a--, b--; mat<char> grid = mmat<char>(100, 100); rep (i, 50) rep (j, 100) grid[i][j] = '.'; rep (i, 50) rep (j, 100) grid[i + 50][j] = '#'; rep (i, a) { int row = i / 50 * 2 + 51; int col = (i % 50) * 2; grid[row][col] = '.'; } rep (i, b) { int row = i / 50 * 2; int col = (i % 50) * 2; grid[row][col] = '#'; } print(100, 100); rep (i, 100) { rep (j, 100) cout << grid[i][j]; cout << endl; } return 0; }
0
//int a = s - '0'; 文字から数字 //小文字から大文字 //transform(a.begin(), a.end(), a.begin(), ::toupper); //map 全探索 //auto begin = p.begin(), end = p.end(); //for (auto it = begin; it != end; it++) {} //mapのキー:it->first mapのバリュー:it->second //大文字判定 isupper(文字) 小文字判定 islower(文字) //do{}while(next_permutation(ALL(配列))) //小文字に対応する文字コード:S[i] - 'a' //文字コード→小文字:(char)(数字+'a') //グラフの距離:隣接行列で扱う //bool型 初期値はTrue //島渡りの問題:中間ノードに着目 //数が大きい時の比較はstring型で行う //全て0になったか調べたい->0になるたびにcntする //例外処理は最初にする //x = p^m + q^n...の約数の個数:(n+1)*(m+1).... //N!のどの素因数で何回割れるか //⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和 //パズルの問題->一般化して全探索 //stack<ll> s; //s.push(要素);s.top();s.pop(); //queue<ll> q; //q.push(要素);q.front();q.pop(); //同じ作業繰り返す系の問題:収束先を見つける //過半数:N/2.0で判定 //優先度付きキュー //priority_queue< //ll, //vector<ll> //> q; #include <bits/stdc++.h> #define rep(i,N) for(int i = 0; i < N;i++) #define ALL(a) (a).begin(),(a).end() #define ll long long int #define PI 3.14159265358979323846264338327950L using namespace std; //割るやつ const ll MOD = (pow(10, 9) + 7); // K進数でのNの桁数 ll dig(ll N, ll K) { ll dig = 0; while (N) { dig++; N /= K; } return dig; } // a,bの最大公約数 ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a%b); } //a,bの最小公倍数 ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } //階乗計算 ll f(ll n) { if (n == 0 || n == 1) return 1; else return (n * f(n - 1)); } //Nのd桁目の数 ll dignum(ll N, ll d) { ll x = pow(10, d); N %= x; ll y = pow(10, d - 1); N /= y; return N; } //Nをdで何回割れるか ll divcnt(ll N, ll d) { ll ans = 0; while (1) { if (N%d == 0) { ans++; N /= d; } else break; } return ans; } //素数判定 bool prime(ll num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } //フィボナッチ数列 vector<ll> memo(pow(10, 6) + 1); ll fibo(ll n) { if (n == 1) return 1; else if (n == 2) return 1; else if (memo[n] != 0) return memo[n]; else return memo[n] = fibo(n - 1) + f(n - 2); } ll RS(ll N, ll P, ll M) { if (P == 0) return 1; if (P % 2 == 0) { ll t = RS(N, P / 2, M); return t * t % M; } return N * RS(N, P - 1, M); } vector<int> IntegerToVector(int bit, int N) { vector<int> S; for (int i = 0; i < N; ++i) { if (bit & (1 << i)) { S.push_back(i); } } return S; } int main() { ll N, M;cin >> N >> M; vector<ll> L(M), R(M); rep(i,M) cin >> L[i] >> R[i]; sort(ALL(L)); sort(ALL(R)); if(R[0] - L[M-1] + 1 < 0) cout << 0 << endl; else cout << R[0] - L[M-1] + 1 << endl; }
#include <iostream> #define SIZE 100000 using namespace std; void copy(int *res, int *ori, int n){ for(int i=0;i<n;i++){ *(res+i) = *(ori+i); } } void mult(int *res, int *a, int n){ for(int i=0;i<n;i++){ *(res+i) = *(a + *(res+i)); } } void pow(int *res, int *a, long long b, int n){ int base[SIZE], tmp[SIZE]; for(int i=0;i<n;i++){ *(base+i) = *(a+i); *(res+i) = i; } while(b > 0){ if(b%2 == 0){ copy(tmp, base, n); mult(tmp, base, n); copy(base, tmp, n); b /= 2; }else{ mult(res, base, n); b--; } } } int main(void){ int n, m, p[SIZE], q[SIZE]; long long k; long long x[SIZE], y[SIZE]; cin >> n; for(int i=0;i<n;i++){ cin >> x[i]; p[i] = i; if(i>0){ y[i-1] = x[i] - x[i-1]; } } cin >> m >> k; for(int i=0;i<m;i++){ int a, t; cin >> a; a--; t = p[a]; p[a] = p[a-1]; p[a-1] = t; } pow(q, p, k, n-1); for(int i=0;i<n;i++){ if(i > 0){ x[i] = x[i-1] + y[q[i-1]]; } cout << x[i] << endl; }/* for(int i=0;i<n;i++){ cout << i << " : " << q[i] << endl; cout << i << "y : " << y[i] << endl; }*/ }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; #define all(x) (x).begin(), (x).end() #define fsp(x) fixed << setprecision(x) const ll inf = LLONG_MAX; const long double pi = acos(-1); void Yes() {cout << "Yes" << endl;} void No() {cout << "No" << endl;} void YES() {cout << "YES" << endl;} void NO() {cout << "NO" << endl;} //素数判定 //#include <cmath> bool is_prime(long long n) { if (n == 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; for (long long i = 3; i <= sqrt(n); i += 2) { if (n % i == 0) return false; } return true; } //二項係数 mod p //#include <vector> long long modinv(long long n, long long p) { long long a = p, u = 1, v = 0; while (a) { long long t = n / a; n -= t * a; std::swap(n, a); u -= t * v; std::swap(u, v); } u %= p; if (u < 0) u += p; return u; } std::vector<long long> factorial; std::vector<long long> factorial_inv; void make_table(long long n, long long p) { factorial.resize(n, 1); factorial_inv.resize(n, 1); for (long long i = 2; i <= n; i++) { factorial[i] = factorial[i - 1] * i % p; } factorial_inv[n] = modinv(factorial[n], p); for (long long i = n - 1; i >= 2; i--) { factorial_inv[i] = factorial_inv[i + 1] * (i + 1) % p; } } long long combination(long long n, long long r, long long p) { r = std::min(r, n - r); long long ret = factorial[n] * factorial_inv[r] % p; ret *= factorial_inv[n - r]; ret %= p; return ret; } int main() { //ios::sync_with_stdio(false); //cin.tie(nullptr); const ll p = 1e9 + 7; //const ll p = 998244353; ll n, m; cin >> n >> m; map<ll, ll> mp; ll x = m; for (ll i = 2; i <= x; i++) { if (is_prime(x)) { mp[x]++; break; } if (!is_prime(i)) continue; ll cnt = 0; while (x % i == 0) { x /= i; cnt++; } mp[i] += cnt; } make_table(1e7, p); ll ans = 1; for (auto i = mp.begin(); i != mp.end(); i++) { ll a = (i -> first), b = (i -> second); ans *= combination(b + n - 1, n - 1, p); ans %= p; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; using Weight = long long; using Vertex = int; struct Edge {Vertex from, to; Weight weight;}; using Graph = std::vector<std::vector<Edge>>; std::vector<std::vector<Vertex>> connected_component(const Graph& G) { std::vector<std::vector<Vertex>> cc; std::vector<bool> used(G.size()); std::function<void(int)> dfs = [&](int v) { cc.back().push_back(v); used[v] = true; for(const auto& e: G[v]) if(!used[e.to]) dfs(e.to); }; for(Vertex v = 0; v < G.size(); ++v) if(!used[v]) { cc.push_back(std::vector<Vertex>()); dfs(v); } return cc; } using I = long long; I com2(I n) {return n * (n - 1) / 2;} bool check(const auto& G, auto s) { vector<int> color(G.size(), -1); function<bool(Vertex, int)> dfs = [&](auto v, auto c) { if(color[v] != -1) return color[v] == c; color[v] = c; c ^= 1; for(const auto& e: G[v]) if(!dfs(e.to, c)) return false; return true; }; return dfs(s, 0); } int main() { I N, M; cin >> N >> M; Graph G(N); for(auto i=0; i<M; ++i) { int u, v; cin >> u >> v; --u; --v; G[u].push_back({u, v}); G[v].push_back({v, u}); } auto cc = connected_component(G); auto V = N - count_if(begin(cc), end(cc), [](const auto& v) {return v.size() == 1;}); auto ans = N * N - V * V; I twocol = 0, obscure = 0; for(auto c: cc) if(c.size() != 1) { if(check(G, *begin(c))) ++twocol; else ++obscure; } ans += 2 * twocol + obscure; ans += 4 * com2(twocol) + 2 * com2(obscure); ans += 2 * twocol * obscure; cout << ans << endl; }
0
#include<bits/stdc++.h> using namespace std; const int maxn=2005; int n,m,q,ans; int a[maxn][maxn],s[maxn][maxn],up[maxn][maxn],lf[maxn][maxn]; inline int read() { int ret=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=-f;ch=getchar();} while(ch>=48&&ch<=57){ret=ret*10+ch-48;ch=getchar();} return ret*f; } char fstchar() { char ch=getchar(); while(ch!='0'&&ch!='1') ch=getchar(); return ch; } int main() { n=read();m=read();q=read(); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]=fstchar()-'0',s[i][j]=a[i][j]+s[i-1][j]+s[i][j-1]-s[i-1][j-1]; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { up[i][j]=up[i][j-1]+up[i-1][j]-up[i-1][j-1]; lf[i][j]=lf[i-1][j]+lf[i][j-1]-lf[i-1][j-1]; if(a[i][j]&&a[i-1][j]) up[i][j]++; if(a[i][j]&&a[i][j-1]) lf[i][j]++; } while(q--) { int x=read(),y=read(),xx=read(),yy=read(); ans=s[xx][yy]-s[x-1][yy]-s[xx][y-1]+s[x-1][y-1]; ans-=up[xx][yy]-up[x][yy]-up[xx][y-1]+up[x][y-1]; ans-=lf[xx][yy]-lf[xx][y]-lf[x-1][yy]+lf[x-1][y]; printf("%d\n",ans); } return 0; }
#include <bits/stdc++.h> using namespace std; int dp[1001][1001]; int main(){ string s1,s2; cin>>s1>>s2; for(int i=0;i<1001;i++){ for(int j=0;j<1001;j++) dp[i][j]=INT_MAX; } dp[0][0]=0; for(int i=1;i<=(int)s1.size();i++) dp[i][0]=i; for(int i=1;i<=(int)s2.size();i++) dp[0][i]=i; for(int i=1;i<=(int)s1.size();i++){ for(int j=1;j<=(int)s2.size();j++){ dp[i][j]=min(dp[i-1][j],dp[i][j-1])+1;//挿入(=削除) int cost=(s1[i-1]==s2[j-1])?0:1; dp[i][j]=min(dp[i][j],dp[i-1][j-1]+cost);//置き換え } } cout<<dp[s1.size()][s2.size()]<<endl; return 0; }
0
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #define LL long long #define mod 998244353 #define inv2 499122177 #define M 1000020 using namespace std; namespace IO{ int Top=0; char SS[20]; void write(int x){ if(!x){putchar('0');return;} if(x<0) x=-x,putchar('-'); while(x) SS[++Top]=x%10,x/=10; while(Top) putchar(SS[Top]+'0'),--Top; } int read(){ int nm=0,fh=1; char cw=getchar(); for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh; for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0'); return nm*fh; } }using namespace IO; int mul(int x,int y){return (LL)x*(LL)y%mod;} int add(int x,int y){return (x+y>=mod)?x+y-mod:x+y;} int mus(int x,int y){return (x-y<0)?x-y+mod:x-y;} int qpow(int x,int sq){ int res=1; for(;sq;sq>>=1,x=mul(x,x)) if(sq&1) res=mul(res,x); return res; } int n,m,fac[M],ifac[M],ans; int C(int tot,int tk){return mul(fac[tot],mul(ifac[tot-tk],ifac[tk]));} int main(){ n=read(),m=read(),fac[0]=1; if(n>m) swap(n,m); for(int i=1;i<=n+m;i++) fac[i]=mul(fac[i-1],i); ifac[n+m]=qpow(fac[n+m],mod-2); for(int i=n+m;i;i--) ifac[i-1]=mul(ifac[i],i); for(int i=1;i<=n;i++) ans=add(ans,mul(C(i<<1,i),C(n+m-(i<<1),n-i))); write(add(mul(ans,mul(inv2,qpow(C(n+m,m),mod-2))),m)),putchar('\n'); return 0; }
#include<bits/stdc++.h> #define LL long long #define uLL unsigned long long #define db double using namespace std; const int N=5e5+10,mod=998244353; int rd() { int x=0,w=1;char ch=0; while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();} return x*w; }; void ad(int &x,int y){x+=y,x-=x>=mod?mod:0;} int fpow(int a,int b){int an=1;while(b){if(b&1) an=1ll*an*a%mod;a=1ll*a*a%mod,b>>=1;} return an;} int ginv(int a){return fpow(a,mod-2);} int n,m,fac[N<<1],iac[N<<1]; int C(int a,int b){return b<0||a<b?0:1ll*fac[a]*iac[b]%mod*iac[a-b]%mod;} int main() { fac[0]=1; for(int i=1;i<=1000000;++i) fac[i]=1ll*fac[i-1]*i%mod; iac[1000000]=ginv(fac[1000000]); for(int i=1000000;i;--i) iac[i-1]=1ll*iac[i]*i%mod; n=rd(),m=rd(); if(n<m) swap(n,m); int ans=0; for(int i=1;i<=n;++i) ad(ans,1ll*C(i+i,i)*C(n+m-i-i,n-i)%mod); ans=1ll*ans*ginv(C(n+m,n))%mod*ginv(2)%mod; ad(ans,n); printf("%d\n",ans); return 0; }
1
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <numeric> #include <string> #include <cstdio> #include <cstring> #include <queue> #include <stack> #include <set> #include <cmath> #include <bitset> #include <iomanip> using ll = long long; using ull = unsigned long long; using namespace std; #define FALSE printf("false\n"); #define TRUE printf("true\n"); #define all(x) (x).begin(),(x).end() #define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i)) #define pb push_back #define mp make_pair #define fi first #define se second #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) #define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl const int INF = 1e9+7; const ll INFL = 9*1e18; // const int dx[4] = { 1, 0, -1, 0 }; // const int dy[4] = { 0, 1, 0, -1 }; const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1}; const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1}; ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数 template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和 template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数 template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数 template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗 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; } template<typename T>inline void print(T&& x){cout<<setprecision(32)<<x<<endl;}// 改行付き出力 double dp[330][330][330]; bool flag[330][330][330]; int n; double recurse(int i, int j, int k) { if (abs(dp[i][j][k] + 1) > 1e-9) return dp[i][j][k]; double ret = 0; ret += (double)n / (double)(i + j + k); if (i > 0) ret += (double)i / (double)(i + j + k) * recurse(i - 1, j, k); if (j > 0) ret += (double)j / (double)(i + j + k) * recurse(i + 1, j - 1, k); if (k > 0) ret += (double)k / (double)(i + j + k) * recurse(i, j + 1, k - 1); dp[i][j][k] = ret; return ret; } // TODO: write int main() { cin>>n; int c[4] = {0}; rep(i,n){ int a;cin>>a; c[a]++; } memset(dp, -1, sizeof(dp)); dp[0][0][0] = 0; print(recurse(c[1],c[2],c[3])); return 0; }
#include <iostream> #include <vector> #include <string> #include<algorithm> #include<stdio.h> #include<string> #include<math.h> #include<set> using namespace std; void itsvgg() { ios::sync_with_stdio(0);cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt", "w", stdout); #endif } double rolls[301][301][301]; void initialization() { for(int i=0;i<=300;i++) for(int j=0;j<=300;j++) for(int k=0;k<=300;k++) rolls[i][j][k]=0.0; } double prob(int n, int x,int y, int z) { double p1=double(x)/double(n),p2=double(y)/double(n),p3=double(z)/double(n); double p0=1-p1-p2-p3; double k=1; if(x>0) { if(rolls[x-1][y][z]==0) k+=p1*prob(n,x-1,y,z); else k+=p1*rolls[x-1][y][z]; } if(y>0) { if(rolls[x+1][y-1][z]==0) k+=p2*prob(n,x+1,y-1,z); else k+=p2*rolls[x+1][y-1][z]; } if(z>0) { if(rolls[x][y+1][z-1]==0) k+=p3*prob(n,x,y+1,z-1); else k+=p3*rolls[x][y+1][z-1]; } //cout<<x<<" "<<1-p0<<endl; if(x!=0 || y!=0 || z!=0) rolls[x][y][z]=k/(1-p0); else rolls[x][y][z]=0; return rolls[x][y][z]; } int main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); itsvgg(); initialization(); int n; cin>>n; int ones=0,twos=0,threes=0; for(int i=0;i<n;i++) { int x; cin>>x; if(x==1) { ones++; } else if (x==2) twos++; else threes++; } //cout<<ones<<twos<<threes<<endl; //cout<<expected[0][0][0]; //cout<<ones<<twos<<threes<<endl; cout.precision(10); cout<<prob(n,ones,twos,threes); }
1
// 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 = 1e9 + 7; //////////////////////////////////////////////////////////////////// const int N = 2e5 + 5; int A[N]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); mt19937 Rnd(time(0)); int n; cin >> n; for (int i = 0; i < n; i++) cin >> A[i]; if (A[0] != 0) die(-1); for (int i = 1; i < n; i++) if (A[i] - A[i - 1] > 1) die(-1); ll res = 0; for (int i = 1; i < n; i++) if (A[i] == A[i - 1] + 1) res++; else res += A[i]; cout << res << 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 <bitset> #include<iomanip> #include<functional> using namespace std; typedef long long ll; // a と b の最大公約数を返す関数 long long GCD(long long a, long long b) { if (b == 0) return a; else return GCD(b, a % b); } int main() { int N; cin >> N; map<int, int> A; for (int i = 0; i < N; i++) { int a; cin >> a; A[a]++; } int ans = 0; for (auto x : A) { if (x.second % 2 != 0) ans++; } cout << ans << endl; }
0
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define gc getchar_unlocked #define fo(i,n) for(int i=0;i<n;i++) #define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define ll long long int #define s(x) cin>>x #define p(x) cout<<x<<"\n" #define goog(x, y) cout<<"Case #"<<x<<": "<<y<<"\n" #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 #define INF 100000000000 #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef long double ld; mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); int rng(int lim) { uniform_int_distribution<int> uid(0,lim-1); return uid(rang); } int mpow(int base, int exp); void ipgraph(int n, int m); void dfs(int u, int par); int gcd(int a, int b) ; const int mod = 1'000'000'007; const int N = 3e5, M = N; //======================= vi g[N]; int a[N]; void solve() { int d,t,s;cin>>d>>t>>s; int k=d/s; if(k<t) p("Yes"); else if(k==t) { if(d%s==0) p("Yes"); else p("No"); } else p("No"); } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); int t = 1; //cin >> t; while(t--) { solve(); } return 0; } int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = ((ll)result * base) % mod; base = ((ll)base * base) % mod; exp >>= 1; } return result; } void ipgraph(int n, int m){ int i, u, v; while(m--){ cin>>u>>v; //u--, v--; g[u].pb(v); g[v].pb(u); } } void dfs(int u, int par){ for(int v:g[u]){ if (v == par) continue; dfs(v, u); } } int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); }
#include<bits/stdc++.h> using namespace std; #define rg register #define rep(i,a,b) for (rg int i=(a);i<=(b);i++) #define per(i,a,b) for (rg int i=(b);i>=(a);i--) #define pb push_back #define lowbit(x) (x&(-x)) #define replow(i,a,b) for(rg int i = (a);i<=(b);i+=lowbit(i)) #define perlow(i,a,b) for(rg int i = (b);i>=(a);i-=lowbit(i)) #define mk make_pair #define VI vector<int> #define pii pair<int,int> #define pLL pair<long long,long long> #define fi first #define se second #define il inline #define ll long long #define ull unsigned long long #define db double #define ld long double #define inf 0x3f3f3f3f #define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<15,stdin),p1==p2)?EOF:*p1++) char buf[1<<15],*p1 = buf,*p2 = buf; inline ll read(){ #define num ch-'0' char ch;bool flag=0;ll res; while(!isdigit(ch=getc())) (ch=='-')&&(flag=true); for(res=num;isdigit(ch=getc());res=res*10ll+num); (flag)&&(res=-res); #undef num return res; } inline void write(ll x){ if (x < 0) x = ~x + 1ll, putchar('-'); if (x > 9) write(x / 10ll); putchar(x % 10ll + '0'); } #define mid ((l + r)>>1) #define ls (x<<1) #define rs ((x<<1)|1) #undef mid #undef ls #undef rs multiset<int> s; void solve() { int n = read(); int mn = 1e9 + 10; int cnt = 0; rep(i,1,n) { int x = read(); if(s.empty()) { s.insert(x); } else { auto it = s.lower_bound(x); if(it == s.begin()) { s.insert(x); } else { it--; s.erase(it); s.insert(x); } } } printf("%d",s.size()); } int main() { #ifndef ONLINE_JUDGE freopen("data.txt","r",stdin); #endif // int T = read(); // while(T--) solve(); }
0
#include <iostream> #include <map> #include <cctype> using namespace std; char getResult(map<char, string> &s){ char turn, next; for(turn = 'a'; s[turn].size() > 0; turn = next){ next = s[turn][0]; s[turn] = s[turn].erase(0,1); } return toupper(turn); } int main(){ map<char, string> s; for(char c = 'a'; c <= 'c'; c++){ cin >> s[c]; } char result = getResult(s); cout << result << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<int>>; const ll LINF = 1e18; const int INF = 1e9; const ll MOD = 1000000007; int main(){ string a, b, c; cin >> a >> b >> c; if(a.back() == b.front()){ if(b.back() == c.front()) cout << "YES" << endl; else cout << "NO" << endl; } else{ cout << "NO" << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<vector<int>> c(20, vector<int>(20)); vector<pair<int, int>> a; for (int i = 0; i < n; i++) { string s; cin >> s; ll x = 0; bool found = false; for (int i = 0; i < (int)s.size(); i++) { if (s[i] != '.') (x *= 10) += s[i] - '0'; else found = true; } if (!found) x *= (ll)1e9; else { int cur = 0; while (s.back() != '.') ++cur,s.pop_back(); for (int it = 0; it < 9 - cur; it++) x *= 10; } int c2=0,c5=0; ll y = x; while (y % 2 == 0) ++c2,y /= 2; y = x; while (y % 5 == 0) ++c5,y /= 5; ++c[min(18, c2)][min(18, c5)]; a.emplace_back(min(18, c2), min(18, c5)); } for (int i = 18; i >= 0; i--) for (int j = 18; j >= 0; j--) c[i][j] += c[i + 1][j] + c[i][j + 1] - c[i + 1][j + 1]; ll w = 0; for (auto x : a) w += c[18 - x.first][18 - x.second] - (x.first >= 9 && x.second >= 9); w /= 2; cout << w; return 0; }
#include <bits/stdc++.h> using namespace std; using P=pair<int,int>; int main(){ int N; cin>>N; vector<P> Bracketfirst(0); vector<P> Bracketsecond(0); //A ( //B ) for(int i=0;i<N;i++){ int A=0,B=0; string S; cin>>S; for(int j=0;j<(int)S.size();j++){ if(S.at(j)=='('){ A++; } else{ if(A>0){ A--; } else{ B++; } } } if(A>=B){ Bracketfirst.push_back(make_pair(B,A)); } else{ Bracketsecond.push_back(make_pair(A,B)); } } sort(Bracketfirst.begin(),Bracketfirst.end()); sort(Bracketsecond.begin(),Bracketsecond.end()); reverse(Bracketsecond.begin(),Bracketsecond.end()); string answer=""; for(int i=0;i<(int)Bracketfirst.size();i++){ //cout<<Bracket.at(i).first<<" "<<Bracket.at(i).second<<endl; for(int j=0;j<Bracketfirst.at(i).first;j++){ answer+=")"; } for(int j=0;j<Bracketfirst.at(i).second;j++){ answer+="("; } } for(int i=0;i<(int)Bracketsecond.size();i++){ //cout<<Bracket.at(i).first<<" "<<Bracket.at(i).second<<endl; for(int j=0;j<Bracketsecond.at(i).second;j++){ answer+=")"; } for(int j=0;j<Bracketsecond.at(i).first;j++){ answer+="("; } } //cout<<answer<<endl; int a=0,b=0; for(int i=0;i<(int)answer.size();i++){ if(answer.at(i)=='('){ a++; } if(answer.at(i)==')'){ b++; } if(a<b){ cout<<"No"<<endl; return 0; } } if(a==b){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } }
0
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<climits> #include<iostream> #include<sstream> #include<utility> #include<map> #include<vector> #include<queue> #include<algorithm> #include<set> #include<stack> using namespace std; typedef long long ll; typedef pair<int,int>P; map<int,int>t; int N,B[200005],bit[200005]; int sum(int i) { int s=0; while(i>0) { s+=bit[i]; i-=i&-i; } return s; } void add(int i,int x) { while(i<=N) { bit[i]+=x; i+=i&-i; } } int main() { long long ans=0; scanf("%d",&N); for(int i=0;i<N;i++) { scanf("%d",B+i); t[B[i]]=1; } int i=1; for(map<int,int>::iterator it=t.begin();it!=t.end();it++,i++) it->second=i; for(int i=0;i<N;i++) B[i]=t[B[i]]; for(int j=0;j<N;j++) { ans+=j-sum(B[j]); add(B[j],1); } printf("%lld\n",ans); }
#include <stdio.h> #define MAX 200000 #define INFTY 2000000000 double cnt=0; void bubble(int *,int,int,int); void bubbleSort(int *,int,int); void bubble(int *A,int left,int mid,int right){ int i,j,k; int x1,x2; int L[MAX],R[MAX]; x1=mid-left; x2=right-mid; for(i=0;i<x1;i++){ L[i]=A[left+i]; } for(i=0;i<x2;i++){ R[i]=A[mid+i]; } L[x1]=INFTY; R[x2]=INFTY; i=0; j=0; for(k=left;k<right;k++){ if(L[i]<R[j]){ A[k]=L[i]; i++; }else{ A[k]=R[j]; cnt=cnt+(x1-i); j++; } } } void bubbleSort(int *A,int left,int right){ int middle; if(left+1<right){ middle=(left+right+1)/2; bubbleSort(A,left,middle); bubbleSort(A,middle,right); bubble(A,left,middle,right); } } int main() { int i,n,A[MAX]; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d",&A[i]); } bubbleSort(A,0,n); printf("%.0f\n",cnt); return 0; }
1
#include <iostream> #include <string> #include <algorithm> #include <cmath> #include <deque> #include <queue> #include <stack> #include <vector> #include <utility> #include <iomanip> #include <bitset> #include <set> #include <map> #include <stdio.h> #include <numeric> #include <cstring> #define rep(i,n) for (int i = 0; i < (n); i++) #define rep1(i,n) for (int i = 1; i < (n); i++) #define FOR(i,a,b) for (int i=(a); i < (b); i++) #define MOD 1000000007 //10^9+7 #define ALL(a) (a).begin(),(a).end() using namespace std; using ll = long long; using PII = pair<int, int>; using PLL = pair<long long, long long>; const int INF = numeric_limits<int>::max(); const ll INFL = numeric_limits<ll>::max(); constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); } const double PI = acos(-1); // 負の数にも対応した % 演算 long long mod(long long val, long long m) { long long res = val % m; if (res < 0) res += m; return res; } //greatest common divisor long long gcd(ll a, ll b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } //least common multiple long long lcm(ll a, ll b) { return a / gcd(a, b) * b ; } ll factorial(ll n) { ll res = 1; for (ll i = 1; i <= n; i++) { res *= i; } return res; } bool fn_is_prime(ll n) { for (ll i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return n != 1; } bool isOK(int index, int key, vector<ll>& a) { if (a[index] >= key) return true; else return false; } int binary_search(int key, vector<ll>& a) { int ng = -1; int ok = a.size(); while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(mid, key, a)) ok = mid; else ng = mid; } return ok; } struct UnionFind { vector<int> r; UnionFind(int N) { r = vector<int>(N, -1); } int root(int x) { if (r[x] < 0) return x; return r[x] = root(r[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (r[x] > r[y]) swap(x, y); r[x] += r[y]; r[y] = x; return true; } int size(int x) { return -r[root(x)]; } bool same(int x, int y) { return root(x) == root(y); } }; //素因数分解 vector<pair<long long, long long> > prime_factorize(long long N) { vector<pair<long long, long long> > res; for (long long a = 2; a * a <= N; ++a) { if (N % a != 0) continue; long long ex = 0; while (N % a == 0) { ++ex; N /= a; } res.push_back({a, ex}); } if (N != 1) res.push_back({N, 1}); return res; } //const auto &pf = prime_factorize(i); //for (auto p : pf) cout << p.first << " " << p.second; long long pow(long long x, long long n) { long long ret = 1; while (n > 0) { if (n & 1) ret = ret * x % MOD; // n の最下位bitが 1 ならば x^(2^i) をかける x = x * x % MOD; n >>= 1; // n を1bit 左にずらす } return ret; } int main() { int n, m; cin >> n >> m; vector<int> x(n+1), y(m+1); cin >> x[0] >> y[0]; for (int i = 1; i<= n; i++) cin >> x[i]; for (int i = 1; i<= m; i++) cin >> y[i]; sort(ALL(x)); sort(ALL(y)); if (x[n] < y[0]) cout << "No War" << endl; else cout <<"War" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int N, M, X, Y; cin >> N >> M >> X >> Y; int max_x; cin >> max_x; rep(i, N - 1){ int x; cin >> x; max_x = max(max_x, x); } int min_y; cin >> min_y; rep(i, N - 1){ int y; cin >> y; min_y = min(min_y, y); } for (int i = X + 1; i <= Y; i++){ if (max_x < i && i <= min_y){ cout << "No War" << endl; return 0; } } cout << "War" << endl; }
1
/*#include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/multiprecision/cpp_int.hpp> #include <boost/rational.hpp> */ #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 repr4(i,s,n) for(ll i = (n);i>=(s);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>>; using Graphw = vector<vector<pair<ll,ll>>>; #define INF1 INT_MAX; #define INF2 LLONG_MAX; #define PI 3.14159265358979323846; #define MOD 1000000007; /* namespace mp = boost::multiprecision; // 任意長整数型 using Bint = mp::cpp_int; // 仮数部長が32の浮動小数点数型 using Real32 = mp::number<mp::cpp_dec_float<32>>; // 仮数部長が1024の浮動小数点数型 using Real1024 = mp::number<mp::cpp_dec_float<1024>>; // 有理数型 using Rat = boost::rational<Bint>; */ const int mod = 1000000007; int main() { int sx,sy,tx,ty; cin>>sx>>sy>>tx>>ty; string S=""; rep(i,ty-sy){ S+='U'; } rep(i,tx-sx){ S+='R'; } rep(i,ty-sy){ S+='D'; } rep(i,tx-sx){ S+='L'; } S+='L'; rep(i,ty-sy+1){ S+='U'; } rep(i,tx-sx+1){ S+='R'; } S+='D'; S+='R'; rep(i,ty-sy+1){ S+='D'; } rep(i,tx-sx+1){ S+='L'; } S+='U'; cout<<S<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define all(n) begin(n),end(n) using ll = long long; using P = pair<int,int>; int main() { int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty; int x = tx-sx, y = ty-sy; rep(i,x) cout << 'R'; rep(i,y) cout << 'U'; rep(i,x) cout << 'L'; rep(i,y) cout << 'D'; cout << 'D'; rep(i,x+1) cout << 'R'; rep(i,y+1) cout << 'U'; cout << 'L'; cout << 'U'; rep(i,x+1) cout << 'L'; rep(i,y+1) cout << 'D'; cout << 'R'; return 0; }
1
#include<iostream> #include<cstdio> using namespace std; char map[13][13]; int d[13][13]; int dy[4]={-1,0,1,0}; int dx[4]={0,-1,0,1}; void bfs(int y,int x); int main(){ char a[12]; string str; while(1){ int co=0; for(int i=0;i<12;i++){ cin>>map[i]; } if(cin.eof())break; for(int i=0;i<12;i++){ for(int j=0;j<12;j++){ d[i][j]=0; } } for(int i=0;i<12;i++){ for(int j=0;j<12;j++){ if(map[i][j]=='1' && d[i][j]==0){ co++; bfs(i,j); } } } cout<<co<<endl; } } void bfs(int y,int x){ d[y][x]=1; for(int p=0;p<4;p++){ int ny=y+dy[p]; int nx=x+dx[p]; if(ny>=0 && ny<12 && nx>=0 && nx<12 && d[ny][nx]==0 && map[ny][nx]=='1' ){ bfs(ny,nx); } } return; }
#include <bits/stdc++.h> #define SIZE 300005 #define MOD 1000000007LL #define INF 1 << 30 #define LLINF 1LL << 60 #define REP(i,n) for(int i=0;i<n;i++) #define FOR(i,a,b) for(int i=a;i<=b;i++) #define DOWN(i,b,a) for(int i=b;i>=a;i--) #define SET(a,c) memset(a,c,sizeof a) #define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) #define FOREACH(i,c) for(auto (i) : (c)) #define BIT(i,j) ((i)>>(j))&1 #define ALL(o) (o).begin(), (o).end() #define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end()) #define SQ(x) ((x)*(x)) using namespace std; typedef long long ll; typedef valarray<int> Array; typedef pair<ll,ll> Pll; typedef pair<int, int> Pii; typedef pair<double, double> Pdd; template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i]<<((i==a.size()-1)?"\n":" ");}} ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);} ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);} int a[144]; void flip(int x, int y) { if(x>11||y>11||x<0||y<0) return; if(a[x+y*12]) { a[x+y*12] = 0; flip(x+1,y); flip(x-1,y); flip(x,y+1); flip(x,y-1); } } void solve() { int cnt = 0; REP(i,144) if(a[i]) { cnt++; flip(i%12,i/12); } cout << cnt << endl; } int main() { string s; int i = 0; while(cin >> s) { REP(j,12) a[i*12+j] = s[j]-'0'; i=(++i)%12; if(i==0) solve(); } return 0; }
1