code_file1
stringlengths
80
4k
code_file2
stringlengths
91
4k
similar_or_different
int64
0
1
#include <iostream> using namespace std; int main() { int A, B, C, D, E, F; cin >> A >> B >> C >> D >> E >> F; int sum = 0; if (A <= B && A <= C && A <= D) sum += B + C + D; else if (B <= A && B <= C && B <= D) sum += A + C + D; else if (C <= A && C <= B && C <= D) sum += A + B + D; else sum += A + B + C; if (E <= F) sum += F; else sum += E; cout << sum << endl; return 0; }
// // main.cpp // testing // // Created by 伊藤大騎 on 2019/01/07. // Copyright © 2019 HamamatsuJOHOKU. All rights reserved. // /* 科目選択 (Selecting Subjects) JOI 君は物理,化学,生物,地学,歴史,地理の 6 科目のテストを受けた. それぞれのテストは 100 点満点で採点された. JOI 君は物理,化学,生物,地学の 4 科目から 3 科目を選択し,歴史,地理の 2 科目から 1 科目を選択する. テストの合計点が最も高くなるように科目を選ぶとき, JOI 君の選んだ科目のテストの合計点を求めよ. 入力は 6 行からなり,1 行に 1 つずつ整数が書かれている. 1 行目には JOI 君の物理のテストの点数 A が書かれている. 2 行目には JOI 君の化学のテストの点数 B が書かれている. 3 行目には JOI 君の生物のテストの点数 C が書かれている. 4 行目には JOI 君の地学のテストの点数 D が書かれている. 5 行目には JOI 君の歴史のテストの点数 E が書かれている. 6 行目には JOI 君の地理のテストの点数 F が書かれている. 書かれている整数 A, B, C, D, E, F はすべて 0 以上 100 以下である. 出力 JOI 君が選んだ科目のテストの合計点を 1 行で出力せよ. 入出力例 入力例 1 入力例 2 100 15 34 21 76 15 42 42 10 15 0 62 出力例 1 出力例 2 228 140 入出力例 1 では,JOI 君が物理,生物,地学,歴史の 4 科目を選ぶとき,テストの合計点が最高になる. 物理,生物,地学,歴史の点数はそれぞれ 100, 76, 42, 10 なので,選んだ科目のテストの合計点は 228 である. 入出力例 2 では,JOI 君が化学,生物,地学,地理の 4 科目を選ぶとき,テストの合計点が最高になる. 化学,生物,地学,地理の点数はそれぞれ 21, 15, 42, 62 なので,選んだ科目のテストの合計点は 140 である. 入出力例 2 では,JOI 君が物理,化学,地学,地理の 4 科目を選ぶ場合でも,選んだテストの合計点は 140 である. */ #include <iostream> #include <algorithm> using namespace std; int main (){ int hairetsu[6]={0},ans=0,maxim=0; for (int i=0;i<6;i++){ cin>>hairetsu[i]; } for (int i=0;i<3;i++){ for (int j=0;j<4;j++){ if (maxim<hairetsu[j]){ maxim=hairetsu[j]; } } ans+=maxim; for (int j=0;j<4;j++){ if (hairetsu[j]==maxim){ hairetsu[j]=0; maxim=0; } } } ans+=max(hairetsu[4],hairetsu[5]); cout<<ans<<endl; return 0; }
1
// 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 void MAIN() { int n, k; cin >> n >> k; vector<int> a(n); for (auto &i : a) cin >> i; sort(all(a), greater<int>()); int ans = 0; for (int i = 0; i < k; i++) { ans += a[i]; } cout << ans << '\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 <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { int K, X; cin >> K >> X; int now = X-K+1; while(now <= X+K-1){ cout << now << endl; now++; } return 0; }
0
#include <bits/stdc++.h> #define ADD(a, b) a = (a + ll(b)) % mod #define MUL(a, b) a = (a * ll(b)) % mod #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define rep(i, a, b) for(int i = int(a); i < int(b); i++) #define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--) #define all(a) (a).begin(), (a).end() #define sz(v) (int)(v).size() #define pb push_back #define sec second #define fst first #define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<int, pi> ppi; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> mat; typedef complex<double> comp; void Debug() {cout << '\n'; } template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){ cout<<arg<<" ";Debug(rest...);} template<class T>ostream& operator<<(ostream& out,const vector<T>& v) { out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;} template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){ out<<"("<<v.first<<", "<<v.second<<")";return out;} const int MAX_N = 200010; const int MAX_V = 100010; const double eps = 1e-6; const ll mod = 1000000007; const int inf = 1 << 29; const ll linf = 1LL << 60; const double PI = 3.14159265358979323846; /////////////////////////////////////////////////////////////////////////////////////////////////// struct P { double x, y; int num; P() {} P(double x, double y, int num) : x(x), y(y), num(num) { } P operator+(P p) { return P(x + p.x, y + p.y, 0); } P operator-(P p) { return P(x - p.x, y - p.y, 0); } double det(const P& p) { return x * p.y - y * p.x; } double norm() { return sqrt(x * x + y * y); } bool operator<(const P& p) { return y != p.y ? y < p.y : x < p.x; } friend ostream& operator<<(ostream& out, const P& p) { out << "(" << p.x << ", " << p.y << ")"; return out; } }; vector<P> convex_hull(vector<P>& ps) { int n = sz(ps); sort(all(ps)); int k = 0; vector<P> qs(n * 2); rep(i, 0, n) { while(k > 1 && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= -eps) k--; qs[k++] = ps[i]; } for(int i = n - 2, t = k; i >= 0; i--) { while(k > t && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= -eps) k--; qs[k++] = ps[i]; } qs.resize(k - 1); return qs; } int N; double ans[110]; void solve() { cin >> N; vector<P> ps; rep(i, 0, N) { int a, b; cin >> a >> b; ps.pb(P{double(a), double(b), i}); } if(N == 2) { cout << "0.5\n0.5\n"; return; } auto qs = convex_hull(ps); int n = sz(qs); rep(i, 0, n) { P p = qs[i]; double angle = 1.0; rep(j, 0, n) { rep(k, 0, n) { if(i == j || j == k || k == i) continue; P p1 = qs[j]; P p2 = qs[k]; p1 = p1 - p; p2 = p2 - p; double tmp = (p1.x * p2.x + p1.y * p2.y) / (p1.norm() * p2.norm()); // debug(i, j, k, tmp, acos(tmp)); MIN(angle, (PI - acos(tmp)) / (2 * PI)); } } ans[qs[i].num] = angle; } rep(i, 0, N) { cout << ans[i] << "\n"; } } int main() { #ifndef LOCAL ios::sync_with_stdio(false); cin.tie(0); #endif cout << fixed; cout.precision(20); srand((unsigned int)time(NULL)); #ifdef LOCAL //freopen("in.txt", "wt", stdout); //for tester freopen("in.txt", "rt", stdin); #endif solve(); #ifdef LOCAL cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll solve() { ll N; cin >> N; vector<double> X(N), Y(N); for ( int i = 0; i < N; i++ ) { cin >> X[i] >> Y[i]; } vector<int> c(N); int M = 3e5; double pi = acos(0) * 2; for ( int k = 0; k < M; k++ ) { double t = 2 * pi * k / M; int mi; double mx = -2e6; for ( int i = 0; i < N; i++ ) { double x = X[i]*cos(t) - Y[i]*sin(t); if ( mx < x ) { mx = x; mi = i; } } c[mi]++; } for ( int i = 0; i < N; i++ ) { cout << c[i] / (double)M << "\n"; } return 0; } int main() { solve(); return 0; }
1
#include <algorithm> #include <iostream> using namespace std; using ll = long long; using ld = long double; #define ALL(x) begin(x), end(x) #define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i) void solve(ll A, ll B, ll C, ll D) { cout << min(A,B) + min(C,D) << endl; } int main() { ll A; cin >> A; ll B; cin >> B; ll C; cin >> C; ll D; cin >> D; solve(A, B, C, D); return 0; }
#define _USE_MATH_DEFINES #define INF 0x3f3f3f3f #include <cstdio> #include <iostream> #include <sstream> #include <cmath> #include <cstdlib> #include <algorithm> #include <queue> #include <stack> #include <limits> #include <map> #include <string> #include <cstring> #include <set> #include <deque> #include <bitset> #include <list> #include <cctype> #include <utility> using namespace std; typedef long long ll; typedef pair <int,int> P; typedef pair <int,P > PP; int tx[] = {0,1,0,-1}; int ty[] = {-1,0,1,0}; static const double EPS = 1e-8; struct Jinfo{ int start; int len; }; int main(){ string str; while(cin >> str){ int res = 0; deque<char> jdeq; deque<char> odeq; deque<char> ideq; int onum=0; for(int i=0;i<str.size();i++){ if(str[i]=='J'){ if(odeq.size() > 0 || ideq.size() > 0){ odeq.clear(); ideq.clear(); jdeq.clear(); } jdeq.push_back(str[i]); } else if(str[i]=='O'){ if(ideq.size() > 0){ jdeq.clear(); odeq.clear(); ideq.clear(); } odeq.push_back(str[i]); } else if(str[i]=='I'){ ideq.push_back(str[i]); } if(ideq.size() > 0 && odeq.size() > 0 && jdeq.size() > 0 && jdeq.size() >= odeq.size() && ideq.size() >= odeq.size()){ res = max(res,(int)odeq.size()); jdeq.clear(); ideq.clear(); odeq.clear(); } } printf("%d\n",res); } }
0
#include <bits/stdc++.h> #include <iostream> //#include <algorithm> // #include <iomanip> #define ll long long #define map unordered_map #define set unordered_set #define pll pair<ll, ll> #define vll vector<ll> #define mll map<ll, ll> using namespace std; const ll MOD = 1000000007LL; const ll INF = (1LL << 60LL); ll m[100][100]; void show_table(ll I, ll J) { for (ll i = 0; i <= I; i++) { for (ll j = 0; j <= J; j++) { cout << m[i][j] << " "; } cout << "" << endl; } cout << "" << endl; } int main() { // std::cout << std::fixed << std::setprecision(10); ll H, W; scanf("%lld %lld", &H, &W); for (ll y = 0; y < H; y++) { for (ll x = 0; x < W; x++) { m[y][x] = -1; } } ll spaces = 0; for (ll y = 0; y < H; y++) { string s; cin >> s; for (ll x = 0; x < W; x++) { if (s[x] == '.') { m[y][x] = INF; spaces++; } } } queue<pll> q; q.push(make_pair(0, 0)); m[0][0] = 0; for (;;) { if (q.empty()) { break; } auto pos = q.front(); ll y = pos.first; ll x = pos.second; ll c = m[y][x]; if (y >= 1 && m[y - 1][x] > c + 1) { m[y - 1][x] = c + 1; q.push(make_pair(y - 1, x)); } if (y < H - 1 && m[y + 1][x] > c + 1) { m[y + 1][x] = c + 1; q.push(make_pair(y + 1, x)); } if (x >= 1 && m[y][x - 1] > c + 1) { m[y][x - 1] = c + 1; q.push(make_pair(y, x - 1)); } if (x < W - 1 && m[y][x + 1] > c + 1) { m[y][x + 1] = c + 1; q.push(make_pair(y, x + 1)); } q.pop(); } // show_table(3, 3); ll a = m[H - 1][W - 1]; if (a == INF) { cout << -1 << endl; return 0; } // cout << "a:" << a << endl; ll ans = spaces - a - 1; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n); ++i) #define rep2(i,s,n) for(int i = (s); i < (n); ++i) #define ll long long #define ld long double #define P pair<ll,ll> #define all(v) v.begin(),v.end() const ll mod = 1e9+7; const ll INF = 1e18; const double pi = acos(-1.0); int main(void) { ll h,w; cin>>h>>w; char s[h][w]; rep(i,h)rep(j,w) cin>>s[i][j]; ll di[]={1,0,-1,0},dj[]={0,1,0,-1}; bool ok=true; rep(i,h){ rep(j,w){ if(s[i][j]=='.') continue; bool ok2=false; rep(k,4){ ll ni=i+di[k],nj=j+dj[k]; if(ni<0||h<=ni||nj<0||w<=nj) continue; if(s[i][j]=='#' && s[ni][nj]=='#') ok2=true; } if(!ok2){ ok=false; break; } } } if(ok) cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; }
0
#include<iostream> #include<algorithm> #include<string> using namespace std; int main() { string a,b; cin>>a>>b; int dp[1001][1001]={}; for(int i=0;i<=a.length();i++)dp[i][0]=i; for(int j=0;j<=b.length();j++)dp[0][j]=j; for(int i=0;i<a.length();i++) { for(int j=0;j<b.length();j++) { dp[i+1][j+1]=min(dp[i][j]+(a[i]!=b[j]),min(dp[i+1][j]+1,dp[i][j+1]+1)); } } cout<<dp[a.length()][b.length()]<<endl; return 0; }
#include <bits/stdc++.h> #include <limits> #include <math.h> #include <cmath> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int> ; using vi = vector<int> ; using vvi = vector<vector<int>> ; using vll = vector<long long>; using vvll = vector<vector<long long >>; #define PI 3.141592653 #define rep(i, n) for(int i = 0; i < n; i++) int main(){ int n; cin >> n; string s; cin >> s; bool fin; if(s[0] == 'o'){fin = true;} else{fin = false;} bool ans = true; vector<char> s1(n+1); s1[0] = 'W'; s1[1] = 'S'; vector<char> s2(n+1); s2[0] = 'W'; s2[1] = 'W'; vector<char> s3(n+1); s3[0] = 'S'; s3[1] = 'S'; vector<char> s4(n+1); s4[0] = 'S'; s4[1] = 'W'; while(true){ bool f; for(int i = 2; i <= n; i++){ f = true; if(s1[i-2] == 'W'){f = !f;} if(s1[i-1] == 'W'){f = !f;} if(s[i-1] == 'x'){f = !f;} if(f){s1[i] = 'S';} else{s1[i] = 'W';} } if(fin){if(s1[n-1] == 'W' && s1[0] == s1[n]) {rep(i, n){cout << s1[i];}ans = false; break;}} else{if(s1[n-1] == 'S' && s1[0] == s1[n]) {rep(i, n){cout << s1[i];}ans = false; break;}} for(int i = 2; i <= n; i++){ f = true; if(s2[i-2] == 'W'){f = !f;} if(s2[i-1] == 'W'){f = !f;} if(s[i-1] == 'x'){f = !f;} if(f){s2[i] = 'S';} else{s2[i] = 'W';} } if(fin){if(s2[n-1] == 'S' && s2[0] == s2[n] ) {rep(i, n){cout << s2[i];}ans = false; break;}} else{if(s2[n-1] == 'W' && s2[0] == s2[n]) {rep(i, n){cout << s2[i];}ans = false; break;}} for(int i = 2; i <= n; i++){ f = true; if(s3[i-2] == 'W'){f = !f;} if(s3[i-1] == 'W'){f = !f;} if(s[i-1] == 'x'){f = !f;} if(f){s3[i] = 'S';} else{s3[i] = 'W';} } if(fin){if(s3[n-1] == 'S' && s3[0] == s3[n]) {rep(i, n){cout << s3[i];} ans = false; break;}} else{if(s3[n-1] == 'W' && s3[0] == s3[n]) {rep(i, n){cout << s3[i];}ans = false; break;}} for(int i = 2; i <= n; i++){ f = true; if(s4[i-2] == 'W'){f = !f;} if(s4[i-1] == 'W'){f = !f;} if(s[i-1] == 'x'){f = !f;} if(f){s4[i] = 'S';} else{s4[i] = 'W';} } if(fin){if(s4[n-1] == 'W' && s4[0] == s4[n]) {rep(i, n){cout << s4[i];} ans = false;break;}} else{if(s4[n-1] == 'S' && s4[0] == s4[n]) { rep(i, n){cout << s4[i];}ans = false; break;}} cout << -1; break; } cout << endl; }
0
#include<bits/stdc++.h> using namespace std; #define F first #define S second #define PB push_back #define MP make_pair #define REP(i,a,b) for(inti=a;i<=b;i++) #define MOD 1000000007 typedef long long int ll; typedef vector<int>vi; typedef pair<int,int>pi; int main() { int n;cin>>n; int ans =0; int i = 0; while(i*i<=n) { i++; } cout<<(i-1)*(i-1)<<endl; return 0; }
#include <bits/stdc++.h> #define rep(i, start, end) for (long long i = start; i < end; ++i) #define repreverse(i, start, end) for (long long i = start; i >= end; --i) #define all(x) (x).begin(), (x).end() #define len(x) ((long long)(x).size()) #define g(a, b) __gcd((a), (b)) #define l(a, b) ((a) / __gcd((a), (b)) * (b)) using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using vllvll = vector<vll>; using pll = pair<ll, ll>; template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';} template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);} template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); } template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); } template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); } template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; } template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; } const long double pi = M_PI; const long long big = 1LL << 50; const long long inf = 1LL << 60; const long long mod = 1e9 + 7; int main() { ll N; cin >> N; ll ans = 1; rep(i, 1, N+1) { if (i * i > N) break; ans = i; } cout << ans*ans << endl; }
1
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c,x; cin>>a>>b; c=max(a+b,a-b); x=max(c,a*b); cout<<x<<endl; return 0; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <cmath> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define Rep(i, n) for (int i = 1; i <= (int)(n); i++) #define fore(i, a) for (auto &i:a) #define ll long long #define pll vector<pair<ll, ll>> #define mod 1000000007 #define all(x) (x).begin(), (x).end() #define pb push_back #define popcount(x) __builtin_popcountll(x) using namespace std; const long double PI = acos(-1); ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;} ll lcm(ll a,ll b){return a / gcd(a,b) * b;} ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);} bool isInteger(double x){return floor(x) == x;} int main(){ cin.tie(0); ios::sync_with_stdio(false); int a,b,c,d;cin >> a >> b >> c >> d; cout << min(a,b)+min(c,d) << endl; }
0
#include "bits/stdc++.h" using namespace std; const int MAX = 700000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } /*第二引数で第一引数を割ったときの切り上げの計算*/ long long int maxtime(long long int x, long long int y) { return(x + y - 1) / y; } /*最大公約数*/ long long int lcm(long long int number1, long long int number2) { long long int m = number1; long long int n = number2; if (number2 > number1) { m = number2; n = number1; } long long int s = -1; while (s != 0) { s = m % n; m = n; n = s; } return m; } /*最大公倍数*/ long long int gcd(long long int number1, long long int number2) { long long int m = number1; long long int n = number2; return m / lcm(m, n) * n; } /*逆元計算*/ long long int modinv(long long a, long long m) { long long int b = m, u = 1, v = 0; while (b) { long long int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // index が条件を満たすかどうか vector<long long int >meguru; bool isOK(int index, int key) { if (meguru[index] >= key) return true; else return false; } // 汎用的な二分探索のテンプレ int binary_search(int key) { int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1 int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size() /* どんな二分探索でもここの書き方を変えずにできる! */ while (right - left > 1) { int mid = left + (right - left) / 2; if (isOK(mid, key)) right = mid; else left = mid; } /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */ return right; } 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; } int main() { int n; cin >> n; vector<long long int> v; for (int i = 0; i < n; i++) { long long int a; cin >> a; v.push_back(a); } int max = 0; long long int ans = 0; for (int i = 0; i < v.size(); i++) { if (v[i] < max) { ans = ans + max - v[i]; } else if (v[i] > max) { max = v[i]; } } cout << ans; }
#include<bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; #define FOR(i,a,b) for (int i = a; i < b; ++i) #define FORR(i,a,b) for (int i = b - 1; i >= a; --i) #define REP(i,n) FOR(i,0,n) #define REPR(i,n) FORR(i,0,n) int main() { ll N; cin >> N; ll A, high = 0, ans = 0; REP (i, N) { cin >> A; high = max(A, high); ans += high - A; } cout << ans << endl; return 0; }
1
#include<bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> #include<chrono> using namespace std; using namespace std::chrono; using namespace __gnu_pbds; #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define fi first #define se second #define int long long #define pb push_back #define emp emplace_back #define vv(x) vector<x> #define mp(x,y) map<x,y> #define dq(x) deque<x> #define pql(x) priority_queue<x> #define pqs(x) priority_queue<x,vv(x),greater<x> > #define M 998244353 #define forf(i,a,b) for(int i=a;i<b;i++) #define it(x) x::iterator #define ll long long #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC)) #define vii vector<int> #define big 3e18 #define sm -1e9 #define mkr make_pair #define vpi vector<pair<int,int> > #define pii pair<int,int> #define rng 500005 #define sz(x) (int)x.size() #define rv(x) reverse(x.begin(),x.end()) #define out(x) cout<<x.fi<<" "<<x.se<<endl; typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> odst; void pr_init() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } pair<int,pii> proc (string s) { int an = 0 , lef = 0 , rg = 0;; for(int i=0;i<sz(s);i++) { if(s[i]=='(') an--; else an++; lef = max(lef,an); } an = 0; for(int i=sz(s)-1;i>=0;i--) { if(s[i]=='(')an++; else an--; rg = max(rg,an); } return {lef,{rg,an}}; } int arr[1000001],vis[1000001]; void solve() { int n; cin >> n; vector<pair<int,pii> > sq; vpi lef,rg; for(int i=0;i<n;i++) { string s; cin >> s; pair<int,pii> rm = proc(s); //cout<<rm.fi<<" "<<rm.se.fi<<" "<<rm.se.se<<endl; lef.pb({rm.fi,i}); rg.pb({rm.se.fi,i}); arr[i] = rm.se.se; } sort(lef.begin(),lef.end()); sort(rg.begin(),rg.end()); int i = 0,j=0,fw=0,bk=0,fl=0; while(i<sz(lef) && j<sz(rg)) { if(vis[lef[i].se]) i++; else if(vis[rg[j].se]) j++; else { if(fw - lef[i].fi < 0 || bk + rg[j].fi > 0) fl=1; fw += arr[lef[i].se]; vis[lef[i].se] =1; i++; if(!vis[rg[j].se]) bk += arr[rg[j].se] , vis[rg[j].se]=1; j++; } } if(fl || (fw+bk)!=0) { cout<<"No\n"; } else cout<<"Yes\n"; } int32_t main() { pr_init(); fastio; auto start = high_resolution_clock::now(); solve(); auto stop = high_resolution_clock::now(); auto duration = duration_cast<microseconds>(stop - start); // cout << "Time taken by function: " // << duration.count() << " microseconds" << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define all(t) t.begin(), t.end() #define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b)))) typedef vector<ll> vi; #define fi first #define se second #define show(x) cout << #x << " is " << x << "\n"; const ll inf = 9e18; const ll mod = 1e9 + 7; const ld pi = 3.141592653589793238462643383279502884; void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";} ll power(ll x, ll y, ll M = inf){ if(y<=0) return 1; ll ans = 1; x %= M; while(y){ if(y&1) ans = (x * ans) % M; x = (x * x) % M; y >>= 1; } return ans; } ll modInverse(ll n) {return power(n, mod-2, mod);} inline ll mul(ll a, ll b){ return (a * b) % mod; } inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; } inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; } inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); } //------------------------------------------------------------------------------------------ //const ll N = 1e5 + 1; //vector<ll> adj[N]; //bool visited[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout<<fixed<<setprecision(10); int n; cin >> n; vector<pair<int, int> > s1, s2; for(int i=0;i<n;i++){ string s; cin >> s; for(auto it = s.find("()"); it != string::npos; it = s.find("()")) { s.erase(it, 2); } int l = count(all(s), ')'); int r = count(all(s), '('); if (r - l >= 0) { s1.push_back(make_pair(l, r)); } else { s2.push_back(make_pair(l, r)); } } sort(all(s1), [](const auto& l, const auto& r){ return l.fi < r.fi; }); sort(all(s2), [](const auto& l, const auto& r){ return l.se > r.se; }); int l = 0, r = 0; for (auto s: s1) { l = l + s.fi - min(s.fi, r); r = r - min(s.fi, r) + s.se; } for (auto s: s2) { l = l + s.fi - min(s.fi, r); r = r - min(s.fi, r) + s.se; } if (l == 0 && r == 0) { cout << "Yes"; } else { cout << "No"; } return 0; }
1
#include<bits/stdc++.h> #define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i) using std::cin; using std::cout; const int maxn = 2020; typedef long long ll; const int mod = 998244353; inline ll pow(ll a,int b,int ans = 1) { for(;b;b >>= 1,a = a * a % mod) if(b & 1) ans = ans * a % mod; return ans; } inline ll inverse(int x){ return pow(x, mod - 2); } int h, w; char ch[maxn][maxn]; int right[maxn][maxn]; int down[maxn][maxn]; int can[maxn][maxn]; inline int calc(int * a) { auto min = [&](int x,int y){ return a[x] < a[y] ? x : y; }; static int st[20][maxn]; int ret = 0; for(int i = 1;i < h;++i) st[0][i] = i; for(int i = 1;i < 13;++i) for(int j = 1;j + (1 << i) - 1 < h;++j) { st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << i - 1)]); } std::function<void(int, int)> solve = [&](int l,int r) { if(l > r) return ; const int lg = std::__lg(r - l + 1); int mn = min(st[lg][l], st[lg][r - (1 << lg) + 1]); ret = std::max(ret, (a[mn] + 1) * (r - l + 2)); solve(l, mn - 1), solve(mn + 1, r); }; solve(1, h - 1); return ret; } int main() { std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> h >> w; rep(i, 1, h) cin >> ch[i] + 1; for(int i = h - 1;i >= 1;--i) { for(int j = w - 1;j >= 1;--j) { can[i][j] = !(ch[i][j] + ch[i + 1][j] + ch[i][j + 1] + ch[i + 1][j + 1] & 1); right[j][i] = can[i][j] ? right[j + 1][i] + 1 : 0; } } int ans = w; rep(i, 1, w - 1) ans = std::max(ans, calc(right[i])); cout << ans << '\n'; }
#include <iostream> #include <string> #include <cstdlib> #include <cmath> #include <vector> #include <unordered_map> #include <map> #include <set> #include <algorithm> #include <queue> #include <stack> #include <functional> #include <bitset> #include <assert.h> #include <unordered_map> #include <fstream> #include <ctime> #include <complex> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<double> vd; typedef pair<ll,ll> P; typedef pair<int,int> pii; typedef vector<P> vpl; typedef tuple<ll,ll,ll> tapu; #define rep(i,n) for(int i=0; i<(n); i++) #define REP(i,a,b) for(int i=(a); i<(b); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const int inf = 1<<30; const ll linf = 1LL<<62; const int MAX = 510000; ll dy[8] = {1,-1,0,0,1,-1,1,-1}; ll dx[8] = {0,0,1,-1,1,-1,-1,1}; const double pi = acos(-1); const double eps = 1e-7; template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){ if(a>b){ a = b; return true; } else return false; } template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){ if(a<b){ a = b; return true; } else return false; } template<typename T> inline void print(T &a){ rep(i,a.size()) cout << a[i] << " "; cout << "\n"; } template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";} template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){ cout << a << " " << b << " " << c << "\n"; } ll pcount(ll x) {return __builtin_popcountll(x);} //const int mod = 1e9 + 7; const int mod = 998244353; int main(){ int h,w; cin >> h >> w; vs s(h); rep(i,h) cin >> s[i]; vl dist(h+1,-1); int ans = w; rep(j,w){ vector<pii> st; st.emplace_back(0,0); REP(i,1,h+1){ if(i < h){ if(j==0 || dist[i] == 1){ int d = 0; bool rev = s[i][j] != s[i-1][j]; REP(k,j,w){ if(rev == (s[i][k] != s[i-1][k])) d++; else break; } dist[i] = d; }else{ dist[i]--; } }else{ dist[i] = 0; } if(st.empty() || st.back().first < dist[i]){ st.emplace_back(dist[i],i); }else{ int pos = i; while(!st.empty()){ if(st.back().first >= dist[i]){ pii p = st.back(); chmax(ans, p.first*(i-p.second)+p.first); pos = p.second; st.pop_back(); }else{ st.emplace_back(dist[i], pos); break; } } } } } cout << ans << "\n"; }
1
#include <bits/stdc++.h> #include <set> using namespace std; using pii = pair<int,int>; using pll = pair<long long, long long>; const long long INF = 1<<29; const int MOD = 998244353; long long ruizyou(long long m,long long n){ if(m == 0)return 0; if(m == 1)return 1; long long ans = 1; long long tmp = m; for(int i=0;i<=30;i++){ if(n & (1<<i)){ ans *= tmp; ans %= MOD; } tmp *= tmp; tmp %= MOD; } return ans; } long long kaizyou(long long x){ if(x == 0)return 1; return x * kaizyou(x-1) % MOD; } long long comb(long long x,long long y){ long long bunsi = kaizyou(x); long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD; return bunsi * ruizyou(bunbo,MOD-2) % MOD; } struct unionfind{ vector<int> par; vector<vector<int>> children; vector<int> hukasa; vector<int> kazu; unionfind(int n){ par = vector<int>(n); hukasa = vector<int>(n,0); kazu = vector<int>(n,1); for(int i=0;i<n;i++){ par.at(i) = i; } } int root(int x){ if(par.at(x) == x)return x; return root(par.at(x)); } void unite(int x,int y){ int rx = root(x); int ry = root(y); if(rx == ry)return; if(hukasa.at(rx) >= hukasa.at(ry)){ par.at(ry) = rx; hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx)); kazu.at(rx) += kazu.at(ry); } else{ par.at(rx) = ry; kazu.at(ry) += kazu.at(rx); } } void newkazu(){ int n = kazu.size(); for(int i=0;i<n;i++){ kazu.at(i) = kazu.at(root(i)); } } bool same(int x,int y){ return root(x) == root(y); } }; int ctoi(char a){ return a - '0'; } long long gcd(long long a,long long b){ long long c = max(a,b); long long d = min(a,b); if(d % c == 0)return c; return gcd(c,d%c); } long long lcm(long long a,long long b){ return a * b / gcd(a,b); } int main(){ int h,w; cin >> h >> w; vector<vector<char>> s(h,vector<char>(w)); for(int i=0;i<h;i++){ for(int j=0;j<w;j++)cin >> s.at(i).at(j); } vector<vector<int>> table(h,vector<int>(w,-1)); queue<pii> q; q.push(pii(0,0)); table.at(0).at(0) = 1; bool flag = false; int count; while(!q.empty()){ pii tmppair = q.front(); q.pop(); int x,y; tie(x,y) = tmppair; set<pii> se; if(x-1 >= 0)se.insert(pii(x-1,y)); if(x+1 < h)se.insert(pii(x+1,y)); if(y-1 >= 0)se.insert(pii(x,y-1)); if(y+1 < w)se.insert(pii(x,y+1)); for(auto t:se){ int tx,ty; tie(tx,ty) = t; if(s.at(tx).at(ty) == '.' && table.at(tx).at(ty) == -1){ table.at(tx).at(ty) = table.at(x).at(y) + 1; q.push(t); } if(t == pii(h-1,w-1)){ count = table.at(tx).at(ty); flag = true; break; } } if(flag) break; } if(!flag) cout << -1 << endl; else{ int count2 = 0; for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ if(s.at(i).at(j) == '#')count2++; } } cout << h * w - count - count2 << endl; } }
#include <bits/stdc++.h> using namespace std; /////////////////////////////////////////// const long long int INF = 1LL<<60; const long long int Mod = 1000000007; using ll = long long int; using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using P = pair<int, int>; using PLL = pair<ll, ll>; using matrix = vector<vector<ll>>; #define pb(x) push_back(x) #define mp(x,y) make_pair(x,y) #define all(x) (x).begin(),(x).end() #define rp(i,N) for(ll i = 0; i < (ll)N; i++) #define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i) template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; } template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; } template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根; #define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート #define p_queue(v) priority_queue<v, vector<v>, greater<v> > template<class T> inline void princ(T x){cout<<x<<" ";}; template<class T> inline void print(T x){cout<<x<<"\n";}; template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } /////////////////////////////////////////////////////////////////////////////////// void solve(){ matrix dxdy={{1,0},{-1,0},{0,1},{0,-1}}; ll h,w; cin >> h >> w; vector<vector<char>> s(h,vector<char>(w)); ll ctr=0; rp(i,h){ rp(j,w){ cin >> s[i][j]; if(s[i][j]=='#') ctr++; } } queue<pair<P,ll>> que; que.push(mp(mp(0,0),0)); matrix seen(h,Vi(w,0)); ll shortest=-1; while(!que.empty()){ P loc=que.front().first; ll dist=que.front().second; que.pop(); if(seen[loc.first][loc.second]==1) continue; if(loc.first==h-1&&loc.second==w-1) { shortest=dist; break; } seen[loc.first][loc.second]=1; for(auto vec:dxdy){ if(loc.first+vec[0]<0||loc.first+vec[0]>=h||loc.second+vec[1]<0||loc.second+vec[1]>=w) continue; if(s[loc.first+vec[0]][loc.second+vec[1]]=='.'){ que.push(mp(mp(loc.first+vec[0],loc.second+vec[1]),dist+1)); } } } if(shortest==-1){ print(-1); }else{ print(h*w-ctr-shortest-1); } return; } int main(){ cin.tie(0);ios::sync_with_stdio(false); std::cout<<std::fixed<<std::setprecision(30); solve(); return 0; }
1
#include <iostream> #include <algorithm> #include <queue> using namespace std; int main() { int N; cin >> N; N *= 2; int L[N]; for (int i = 0; i < N; i++) cin >> L[i]; int count = 0; priority_queue<int> Que; for (int i = 0; i < N; i++){ Que.push(L[i]); } while(!Que.empty()){ Que.pop(); if (Que.empty()) break; count += Que.top(); Que.pop(); } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) int main(){ int n; cin >> n; vector<int> l(2*n); int sum =0; rep(i,2*n){ cin >> l[i]; } rep(i,2*n){ rep(j,2*n-i-1){ int temp; if(l[j]>l[j+1]){ temp =l[j]; l[j] = l[j+1]; l[j+1]=temp; } } } rep(i,n){ sum +=l[2*i]; } cout << sum << endl; return 0; }
1
#include<bits/stdc++.h> using namespace std; #define MAX 100001 #define MOD 1000000007 #define ll long long #define ld long double #define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" int main() { fast; ll n; cin >> n; vector<ll> v(n); ll sum = 0; for(ll i=0;i<n;i++) { cin >> v[i]; sum += v[i]; } sum -= v[0]; ll ans = 0; for(ll i=0;i<n-1;i++) { ans = (ans + ((sum % MOD) * (v[i] % MOD)) % MOD) % MOD; sum -= v[i + 1]; } cout << ans << endl; }
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <algorithm> #include <utility> #include <functional> #include <cstring> #include <queue> #include <stack> #include <math.h> #include <iterator> #include <vector> #include <string> #include <set> #include <math.h> #include <iostream> #include <random> #include<map> #include <iomanip> #include <time.h> #include <stdlib.h> #include <list> #include <typeinfo> #include <list> #include <set> #include <cassert> #include<fstream> #include <unordered_map> #include <cstdlib> #include <complex> #include <cctype> #include <bitset> using namespace std; typedef string::const_iterator State; #define Ma_PI 3.141592653589793 #define eps 1e-5 #define LONG_INF 1e18 #define GOLD 1.61803398874989484820458 #define MAX_MOD 1000000007LL #define MOD 998244353LL #define seg_size 262144*4 #define REP(a,b) for(long long a = 0;a < b;++a) long long grid[600000] = {}; vector<long long> finding_X[2000000]; long long zero[600000] = {}; long long cnt_zero(long long l, long long r) { long long ans = zero[r]; if (l != 0) { ans -= zero[l - 1]; } return ans; } pair<long long,long long> calc(long long X) { pair<long long, long long> ans = make_pair(1, 0); if (finding_X[X].size() != 0) { ans.second = 1; } for (int i = 1; i < finding_X[X].size(); ++i) { long long zero_move = cnt_zero(finding_X[X][i - 1], finding_X[X][i]); ans.first += zero_move * ans.second; ans.first %= MAX_MOD; ans.second += ans.first; ans.second %= MAX_MOD; } return ans; } int main() { iostream::sync_with_stdio(false); cin.tie(0); int n; cin >> n; REP(i, n) { cin >> grid[i + 1]; grid[i + 1] ^= grid[i]; } for (int i = 1; i <= n; ++i) { zero[i] = zero[i - 1]; if (grid[i] == 0) { zero[i]++; } else { finding_X[grid[i]].push_back(i); } } if (grid[n] != 0) { cout << calc(grid[n]).first << endl; return 0; } long long ans = 1; for (int i = 0; i < zero[n]-1; ++i) { ans *= 2; ans %= MAX_MOD; } for (int i = 1; i < (1 << 20); ++i) { ans += calc(i).second; ans %= MAX_MOD; } cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; // 1個置くと3増えて全体でN*Q // クオリティQは3の倍数になる必要がある(N != 0 mod 3) using block = vector<string>; // Quality 1 block b3 = { "a..", "a..", ".aa" }; // Quality 3 block b4 = { "aacd", "bbcd", "cdaa", "cdbb" }; // Quality 3 block b5 = { "aabbc", "bc..c", "bc..d", "c.ccd", "cddee" }; // Quality 3 block b7 = { "ac..c..", "ac..c..", "b.cc.cc", "bc..c..", "ac..c..", "a.cc.cc", ".aabbaa" }; void horizontal_add(block &a, block b){ for (int i = 0; i < a.size(); ++i) a[i] += b[i]; } void vertical_add(block &a, block b){ a.insert(a.end(), b.begin(), b.end()); } block solve_k(int n, block b){ block res = b; for (int i = 0; i < n - 1; ++i) { horizontal_add(res, b); } block unit = res; for (int i = 0; i < n - 1; ++i) { vertical_add(res, unit); } return res; } block solve(int n){ block res; if (n % 3 == 0) return solve_k(n/3, b3); if (n % 4 == 0) return solve_k(n/4, b4); int t = __builtin_ctz(n); int m = n >> t; // m >= 5 が保証される if ((m - 1) % 4) res = b7; else res = b5; for (int i = 0; i < (m - 5) / 4; ++i) { horizontal_add(res, block(res.size(), "....")); string s(res.size(), '.'); block below(4, s); horizontal_add(below, b4); vertical_add(res, below); } return solve_k(n/m, res); } int main() { int N; cin >> N; if (N == 2) { cout << -1 << "\n"; } else { auto ans = solve(N); for (int i = 0; i < N; ++i) { cout << ans[i] << "\n"; } } return 0; }
#include <cstdio> const char pat3[3][4]={"a..", "a..", ".aa"}; const char pat4[4][5]={"aacd", "bbcd", "cdaa", "cdbb"}; const char pat5[5][6]={"..def", "..def", "aaggh", "bbj.h", "ccjii"}; const char pat6[6][7]={"aacd..", "bbcd..", "..aacd", "..bbcd", "cd..aa", "cd..bb"}; const char pat7[7][8]={"abc....", "abc....", "def....", "def....", "m..gghh", "m..iijj", ".nnkkll"}; char grid[1005][1005]; int main(){ int N; scanf("%d",&N); for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ grid[i][j]='.'; } } if(N==2){ printf("-1\n"); }else if(N==3){ for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ printf("%c",pat3[i][j]); } printf("\n"); } }else{ int index=0; while(N-index>7){ for(int i=0;i<4;i++){ for(int j=0;j<4;j++){ grid[index+i][index+j]=pat4[i][j]; } } index+=4; } if(N-index==4){ for(int i=0;i<4;i++){ for(int j=0;j<4;j++){ grid[index+i][index+j]=pat4[i][j]; } } }else if(N-index==5){ for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ grid[index+i][index+j]=pat5[i][j]; } } }else if(N-index==6){ for(int i=0;i<6;i++){ for(int j=0;j<6;j++){ grid[index+i][index+j]=pat6[i][j]; } } }else if(N-index==7){ for(int i=0;i<7;i++){ for(int j=0;j<7;j++){ grid[index+i][index+j]=pat7[i][j]; } } } for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ putchar(grid[i][j]); } printf("\n"); } } }
1
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { string a; cin >> a; reverse(a.begin(),a.end()); cout << a << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; using Graph = vector<vector<int>>; using P = pair<int, int>; int main() { string s; cin >> s; bool ok = false; rep(i, s.size() - 1) { if(s[i] == 'A' && s[i + 1] == 'C') ok = true; } if(ok) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
0
#include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; #define rep(i,n) for(int i = 0; i < n; i++) #define REP(i,j,n) for(int i = j; i < n; i++) int main(){ while(1){ vector< vector<int> > map (21, vector<int>(21,0)); vector< vector<int> > map2 (21, vector<int>(21,0)); int px = 10, py = 10; int N; cin >> N; if(N == 0){ break; } vector<int> tx(N); vector<int> ty(N); rep(i,N){ cin >> tx[i]; cin >> ty[i]; map2[ty[i]][tx[i]] = 1; } int M; cin >> M; string str; int v; rep(i,M){ cin >> str >> v; if(str == "N"){ for(int i = py; i <= py + v; i++){ map[i][px] = 1; } py += v; } else if(str == "E"){ for(int i = px; i <= px + v; i++){ map[py][i] = 1; } px += v; } else if(str == "S"){ for(int i = py; i >= py - v; i--){ map[i][px] = 1; } py -= v; } else if(str == "W"){ for(int i = px; i >= px - v; i--){ map[py][i] = 1; } px -= v; } // rep(i,21){ // rep(j,21){ // cout << map[i][j] << " "; // } // cout << endl; // } // cout << endl; } int sum = 0; rep(i,21){ rep(j,21){ if(map[i][j] == 0 && map2[i][j] == 1){ sum++; } } } if(sum == 0){ cout << "Yes" << endl; } else{ cout << "No" <<endl; } } return 0; }
#include <stdio.h> typedef struct _Gem{ int x; int y; bool hit; } Gem; static void pick_gem(Gem* g, int n, int x, int y) { for (int i = 0; i < n; i++) { if (!g[i].hit && g[i].x == x && g[i].y == y) { g[i].hit = true; return; } } } static bool check_gem(Gem* g, int n) { for (int i = 0; i < n; i++) { if (g[i].hit == false) { return false; } } return true; } int main(void) { char line[80]; int n; int m; Gem g[20]; char d[30]; int l[30]; while (true) { if (fgets(line, sizeof line, stdin) == NULL) { return 1; } if (sscanf(line, "%d", &n) != 1) { return 1; } if (n == 0) { break; } for (int i = 0; i < n; i++) { if (fgets(line, sizeof line, stdin) == NULL) { return 1; } if (sscanf(line, "%d %d", &(g[i].x), &(g[i].y)) != 2) { return 1; } g[i].hit = false; } if (fgets(line, sizeof line, stdin) == NULL) { return 1; } if (sscanf(line, "%d", &m) != 1) { return 1; } for (int i = 0; i < m; i++) { if (fgets(line, sizeof line, stdin) == NULL) { return 1; } if (sscanf(line, "%c %d", &(d[i]), &(l[i])) != 2) { return 1; } } int x = 10; int y = 10; for (int i = 0; i < m; i++) { if (d[i] == 'N') { for (int k = 1; k <= l[i]; k++) { pick_gem(g, n, x, ++y); } } else if (d[i] == 'S') { for (int k = 1; k <= l[i]; k++) { pick_gem(g, n, x, --y); } } else if (d[i] == 'E') { for (int k = 1; k <= l[i]; k++) { pick_gem(g, n, ++x, y); } } else { for (int k = 1; k <= l[i]; k++) { pick_gem(g, n, --x, y); } } } printf("%s\n", (check_gem(g, n) ? "Yes" : "No")); } return 0; }
1
#include <bits/stdc++.h> using namespace std; map<long long int,long long int>m; map<long long int,long long int>::iterator it,it1; main() { long long int n,i,j,k,cnt=0,ans=1; cin>>n; int a[n]; for(i=0;i<n;i++) { cin>>a[i]; } sort(a,a+n); for(i=n-1;i>0;i--) { if(a[i]==a[i-1]) { cnt++; ans*=a[i]; i--; } if(cnt==2) { break; } } if(cnt==2) { cout<<ans<<endl; } else{ cout<<0<<endl; } }
#include<bits/stdc++.h> #include<ctype.h> # define pb push_back #define fst first #define sec second #define For(i,a,b) for(int i=a;i<b;i++) #define ll long long int #define ull unsigned long long int #define mod 1000000007 #define fo(i,n) for(ll i=0;i<n;i++) #define endl "\n" #define rev(i,n) for(ll i=n-1;i>=0;i--) #define fo1(i,n) for(ll i=1;i<=n;i++) #define boolsize 1000001 #define pi pair<ll,ll> #define vi vector<ll> #define vii vector<pi> using namespace std; template<typename T> void showvector(vector <T> v) { for(T x:v) cout<<x<<" "; cout<<endl; } template<typename T> void showvector1(vector <T> v) { ll n=v.size(); fo1(i,n-1) cout<<v[i]<<endl; } template<typename T> void showset(set <T> s) { for(T x: s) cout<<x<<" "; cout<<endl; } template<class T> void showvectorpair(vector<T> v) { for(auto it=v.begin();it!=v.end();it++) cout<<it->first<<" "<<it->second<<endl; cout<<endl; } template<typename T,typename P> void showmap(map <T,P> m) { for(auto it=m.begin();it!=m.end();it++) cout<<it->first<<" "<<it->second<<endl; cout<<endl; } template<typename T> bool comp(T a,T b) { return (a>b); } template<class T> bool comppair(T a,T b) { if(a.first==b.first) return(a.second>b.second); return (a.first>b.first); } bool sameparity(ll a,ll b) { return (a%2==b%2); } bool difparity(ll a,ll b) { return !(a%2==b%2); } bool isprime(ll x) { if(x<=1) return false; for(ll i=2;i<=sqrt(x);i++) { if(x%i==0) return false; } return true; } bool iseven(ll x) { return !(x%2); } bool isodd(ll x) { return (x%2); } /// check for test case before submitting void vfun() { ll n,k; cin>>n; vector <ll> v(n); fo(i,n) cin>>v[i]; } int main() { #ifndef ONLINE_JUDGE freopen("inputh.txt", "r", stdin); freopen("outputh.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); ///cant use scanf, printf cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive //cout << fixed << setprecision(11); /// no scientific output ll test=1; //cin>>test; while(test--) { set <ll> s; vector <ll> v; ll x; ll n; cin>>n; fo(i,n) { cin>>x; if(s.count(x)) {v.pb(x);s.erase(x);} else s.insert(x); } ll ans=0; sort(v.begin(),v.end()); if(v.size()>=2) { ll n=v.size(); ans=v[n-1]*v[n-2]; } cout<<ans; // if(vfun()) // cout<<"YES\n"; // else // cout<<"NO\n"; } } ///before sub /// check for value of zero and single input in array ///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs /// check whether test cases are given or not
1
#include<iostream> #include<cstdio> #include<queue> #include<cstring> #include<cmath> #include<stack> #include<algorithm> #define rg register #define ll long long #define LDB long double #define ull unsigned long long #define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt) #define go(i,x,a) for(rg int i=a;i<x;i++) #define inf 0x3f3f3f3f #define INF 0x7fffffff using namespace std; const int maxn=105; int n,a[maxn],m,b[maxn]; inline int rd(){ int ret=0,af=1; char gc=getchar(); while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); } while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar(); return ret*af; } inline bool cmp(int a,int b){ return a%2 > b%2; } int main(){ n=rd(); m=rd(); go(i,m+1,1) a[i]=rd(); sort(a+1,a+m+1,cmp); int t=0; while(a[t+1]%2 == 1) t++; if(t > 2){ printf("Impossible"); return 0; } if(t == 2) swap(a[m],a[2]); go(i,m+1,1) printf("%d ",a[i]); puts(""); go(i,m+1,1) b[i]=a[i]; if(m == 1) m++; b[1]--; b[m]++; if(b[1] == 0){ printf("%d\n",m-1); go(i,m+1,2) printf("%d ",b[i]); }else{ printf("%d\n",m); go(i,m+1,1) printf("%d ",b[i]); } return 0; }//Faze
#include <bits/stdc++.h> using namespace std; int n, m, a[333]; int main(void) { scanf("%d%d", &n, &m); if(m == 1) { if(n == 1) { printf("1\n1\n1\n"); } else { printf("%d\n2\n1 %d\n", n, n - 1); } return 0; } int cnt = 0; for(int i = 1; i <= m; i++) { scanf("%d", &a[i]); cnt += a[i] & 1; } if(cnt > 2) { return puts("Impossible"), 0; } for(int i = 2; i <= m; i++) { if(a[i] & 1) { if(~a[1] & 1) { swap(a[1], a[i]); } else { swap(a[m], a[i]); } } } for(int i = 1; i <= m; i++) { printf("%d%c", a[i], i == m ? '\n' : ' '); } int i = 1; if(a[1] == 1) { i++; } printf("%d\n", m - i + 1); for(; i < m; i++) { printf("%d ", i == 1 ? a[i] - 1 : a[i]); } printf("%d\n", a[m] + 1); return 0; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<ll> v1; typedef vector<v1> v2; typedef vector<v2> v3; typedef unordered_map<ll, unordered_map<ll, ll>> graph; const ll INF = 1ll << 50; const ll mod = 1000000007; ll n; int main(){ cin >> n; cout << n / 3 << endl; }
#include<bits/stdc++.h> #define ll long long int #define vec vector<ll> #define mat vector<vector<ll>> using namespace std; const ll mod=1000000007; const ll inf=LONG_LONG_MAX; ll dx4[4]={1,0,-1,0}; ll dy4[4]={0,-1,0,1}; ll dx8[8]={1,0,-1,1,-1,1,0,-1}; ll dy8[8]={1,1,1,0,0,-1,-1,-1}; int main(){ ll n; cin >> n; ll a=0; while(3*a<=n){ a++; } cout << a-1 << endl; }
1
#include <bits/stdc++.h> using namespace std; int main() { int H, W; cin >> H >> W; vector<vector<char>> s(H, vector<char>(W)); int memo = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> s.at(i).at(j); if (s.at(i).at(j) == '.') { memo++; } } } vector<vector<int>> M(H, vector<int>(W, 0)); queue<int> X; queue<int> Y; X.push(0); Y.push(0); vector<int> vx = {1, -1, 0, 0}, vy = {0, 0, 1, -1}; s.at(0).at(0) = '#'; while (X.size() > 0) { for (int i = 0; i < 4; i++) { if ((X.front() + vx.at(i)) >= 0 && (Y.front() + vy.at(i)) >= 0 && (X.front() + vx.at(i)) < H && (Y.front() + vy.at(i)) < W && s.at(X.front() + vx.at(i)).at(Y.front() + vy.at(i)) == '.' && M.at(X.front() + vx.at(i)).at(Y.front() + vy.at(i)) == 0) { X.push(X.front() + vx.at(i)); Y.push(Y.front() + vy.at(i)); M.at(X.front() + vx.at(i)).at(Y.front() + vy.at(i)) = M.at(X.front()).at(Y.front()) + 1; } } X.pop(); Y.pop(); } if (M.at(H - 1).at(W - 1) != 0) { cout << memo - (M.at(H - 1).at(W - 1) + 1) << endl; } else { cout << -1 << endl; } }
#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>; const int INF=1001001001; int dy[4]={-1,0,1,0}; int dx[4]={0,-1,0,1}; int main(){ int h,w; cin>>h>>w; int ans=0; vector<string>s(h); rep(i,h)cin>>s[i]; rep(i,h)rep(j,w)if(s[i][j]=='.')ans++; vector<vector<int>>dist(h,vector<int>(w,INF)); queue<P>q; q.push(P(0,0)); dist[0][0]=1; while(!q.empty()){ int y=q.front().first; int x=q.front().second; q.pop(); rep(dir,4){ int vy=y+dy[dir]; int vx=x+dx[dir]; if(vy<0||vy>=h||vx<0||vx>=w)continue; if(s[vy][vx]=='#'||dist[vy][vx]!=INF)continue; dist[vy][vx]=dist[y][x]+1; q.push(P(vy,vx)); } } ans-=dist[h-1][w-1]; if(dist[h-1][w-1]!=INF)cout<<ans<<endl; else cout<<-1<<endl; }
1
#include<bits/stdc++.h> #define vi vector<int> #define vvi vector<vector<int> > #define vl vector<ll> #define vvl vector<vector<ll>> #define vb vector<bool> #define vc vector<char> #define vs vector<string> using ll = long long; using ld =long double; //#define int ll #define INF 1e9 #define EPS 0.0000000001 #define rep(i,n) for(int i=0;i<n;i++) #define loop(i,s,n) for(int i=s;i<n;i++) #define all(in) in.begin(), in.end() template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; } template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; } using namespace std; typedef pair<int, int> pii; typedef pair<int,pii> piii; #define mp make_pair #define MAX 100000 vector<vector<int>>edge(MAX); bool visited[MAX]; int prenum[MAX],parent[MAX],lowest[MAX],timer; int N; void dfs(int current,int prev){ prenum[current]=lowest[current]=timer; timer++; visited[current]=true; int next; for(int i=0;i<edge[current].size();i++){ next=edge[current][i]; if(!visited[next]){ parent[next]=current; dfs(next,current); lowest[current]=min(lowest[current],lowest[next]); }else if(next != prev){ lowest[current] = min(lowest[current],prenum[next]); } } } void art_point(){ timer=1; dfs(0,-1); map<int,int>Mp; int np=0; for(int i=1;i<N;i++){ int p=parent[i]; if(p==0)np++; else if(prenum[p]<=lowest[i])Mp[p]++; if(np>1)Mp[0]++; } for(auto itr:Mp) cout<<itr.first<<endl; } signed main(){ int m; cin>>N>>m; edge.resize(N); rep(i,N)visited[i]=false; for(int i=0;i<m;i++){ int s,t; cin>>s>>t; edge[s].push_back(t); edge[t].push_back(s); } art_point(); }
#include <bits/stdc++.h> using namespace std; using ll=long long; using vin=vector<int>; using vll=vector<long long>; using vvin=vector<vector<int>>; using vvll=vector<vector<long long>>; using vstr=vector<string>; using vvstr=vector<vector<string>>; using vch=vector<char>; using vvch=vector<vector<char>>; using vbo=vector<bool>; using vvbo=vector<vector<bool>>; using vpii=vector<pair<int,int>>; using pqsin=priority_queue<int,vector<int>,greater<int>>; #define mp make_pair #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep2(i,s,n) for(int i=(s);i<(int)(n);i++) #define all(v) v.begin(),v.end() #define decp(n) cout<<fixed<<setprecision((int)n) #define _GLIBCXX_DEBUG int main(){ int n; cin>>n; vpii red(n),blue(n); rep(i,n){ int a,b; cin>>a>>b; red[i]=mp(a,b); } rep(i,n){ int c,d; cin>>c>>d; blue[i]=mp(d,c); } sort(all(red)); reverse(all(red)); sort(all(blue)); rep(i,n){ int c,d; tie(d,c)=blue[i]; blue[i]=mp(c,d); } vbo tmp(n,true); int ans=0; rep(i,n){ rep(j,n){ if(red[i].first<blue[j].first&&red[i].second<blue[j].second&&tmp[j]){ ans++; tmp[j]=false; break; } } } cout<<ans<<endl; }
0
#include <bits/stdc++.h> using namespace std; class tsort { public: int V; vector<vector<int>> G; vector<int> deg, res; tsort(int node_size) : V(node_size), G(V), deg(V, 0) {} void add(int from, int to) { G.at(from).push_back(to); deg.at(to)++; } bool solve() { queue<int> que; for(int i = 0; i < V; i++) { if(deg.at(i) == 0) { que.push(i); } } while(!que.empty()) { int p = que.front(); que.pop(); res.push_back(p); for(int v : G.at(p)) { if(--deg.at(v) == 0) { que.push(v); } } } return (*max_element(deg.begin(),deg.end()) == 0); } }; int main() { int N, M; cin >> N >> M; vector<vector<int>> G(N); tsort T(N); for (int i = 0; i < N - 1 + M; i++) { int a, b; cin >> a >> b; G.at(--b).push_back(--a); T.add(a, b); } T.solve(); vector<int> V(N); int cnt = 0; for (auto r : T.res) V.at(r) = cnt++; for (int i = 0; i < N; i++) { int sz = G.at(i).size(); if (!sz) cout << 0 << "\n"; else if (sz == 1) cout << G.at(i).at(0) + 1 << "\n"; else { int mx = 0; for (auto g : G.at(i)) mx = max(mx, V.at(g)); for (auto g : G.at(i)) { if (V.at(g) == mx) { cout << g + 1 << "\n"; break; } } } } }
//ヘッダー #include<bits/stdc++.h> using namespace std; //型定義 typedef long long ll; //定数 const int INF=1e+9; const int MOD=1e+9+7; //REPマクロ #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++) #define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--) // 多次元 vector 生成 template<class T> vector<T> make_vec(size_t a){ return vector<T>(a); } template<class T, class... Ts> auto make_vec(size_t a, Ts... ts){ return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } //vectorの扱い #define ALL(x) (x).begin(),(x).end() //sortなどの引数省略 #define SIZE(x) ((ll)(x).size()) //size #define MAX(x) *max_element(ALL(x)) //最大値 #define MIN(x) *min_element(ALL(x)) //最小値 using Graph=vector<vector<int>>; // グラフ、頂点の入次数、頂点数を受け取り、そのトポロジカルソートを記録した配列を返す関数 vector<int> topological_sort(Graph &G, vector<int> &indegree, int V) { // トポロジカルソートを記録する配列 vector<int> sorted_vertices; // 入次数が0の頂点を発見したら、処理待ち頂点としてキューに追加する queue<int> que; for (int i = 0; i < V; i++) { if (indegree[i] == 0) { que.push(i); } } // キューが空になるまで、操作1~3を繰り返す while (que.empty() == false) { // キューの先頭の頂点を取り出す int v = que.front(); que.pop(); // その頂点と隣接している頂点の入次数を減らし、0になればキューに追加 for (int i = 0; i < G[v].size(); i++) { int u = G[v][i]; indegree[u] -= 1; if (indegree[u] == 0) que.push(u); } // 頂点vを配列の末尾に追加する sorted_vertices.push_back(v); } // トポロジカルソートを返す return sorted_vertices; } int main(){ int N,M; cin>>N>>M; Graph G(N),oya(N); vector<int> indegree(N,0); REP(i,N-1+M){ int a,b; cin>>a>>b; a--; b--; G[a].push_back(b); oya[b].push_back(a); indegree[b]++; } vector<int> topo=topological_sort(G,indegree,N); vector<int> ans(N); vector<int> rev(N+1); REP(i,N) rev[topo[i]]=i; rev[N]=-1; REP(i,N){ if(oya[i].size()==0) ans[i]=0; else{ int idx=N; REP(j,oya[i].size()){ int v=oya[i][j]; if(rev[v]>rev[idx]&&rev[v]<rev[i]){ idx=v; } } ans[i]=idx+1; } } REP(i,N) cout<<ans[i]<<endl; }
1
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <string> #include <map> #include <set> #include <queue> #include <stack> #include <algorithm> using namespace std; #define rep(i,j) REP((i), 0, (j)) #define REP(i,j,k) for(i=(j);(i)<(k);++i) #define BW(a,x,b) ((a)<=(x)&&(x)<=(b)) #define ALL(v) (v).begin(), (v).end() #define LENGTHOF(x) (sizeof(x) / sizeof(*(x))) #define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b) #define MP make_pair #define PB push_back #define F first #define S second #define INF 1 << 30 #define EPS 1e-10 typedef pair<int, int> pi; typedef pair<int, pi> pii; typedef vector<int> vi; typedef queue<int> qi; typedef long long ll; char s[1000001]; int main(){ fgets(s, sizeof(s), stdin); int res = 0, oc, ic, jc; int i, j, k, l; int slen = strlen(s); jc = oc = ic = 0; rep(i, slen){ if(ic == 0 && oc == 0 && s[i] == 'J') jc++; else if(jc && ic == 0 && s[i] == 'O') oc++; else if(jc && oc && s[i] == 'I') ic++; else{ if(jc >= oc && ic >= oc) res = max(res, oc); jc = oc = ic = 0; if(s[i] == 'J') jc++; } } if(jc >= oc && ic >= oc) res = max(res, oc); printf("%d\n", res); return 0; }
#include <iostream> #include <cstdio> #include <vector> #include <list> #include <algorithm> #include <cmath> #include <stack> #include <map> using namespace std; #define REP(i,n) for(int (i)=0; (i)<(n); (i)++) #define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++) #define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);} #define ALL(v) v.begin(), v.end() map<int, bool> mp; int cnt4; int main() { int n; cin >> n; REP(i,n) { int j; cin >> j; mp[j] = true; } int m; cin >> m; REP(i,m) { int j; cin >> j; if (mp[j]) cnt4++; } cout << cnt4 << endl; return 0; }
0
#include<bits/stdc++.h> using namespace std; using lli = long long; #define rep(i,n) for(int i=0;i<n;i++) lli n; string s, t; int main(void){ cin >> n >> s >> t; lli ans = 2*n; rep(i, n){ if(s.substr(i, n-i) == t.substr(0, n-i)){ ans = min(ans, n+i); } } cout << ans << endl; return 0; }
#include<iostream> using namespace std; int main() { int D, T, S; cin >> D >> T >> S; int A = S * T; if (A >= D) { cout << "Yes\n"; } else { cout << "No\n"; } return 0; }
0
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <functional> #include <cmath> #include <map> #include <iomanip> #define intt long long int main() { intt N; std::cin >> N; std::map<std::string, int> MAP; std::vector<std::string> s(N); for (auto& r : s) { std::cin >> r; ++MAP[r]; } intt M; std::cin >> M; std::vector<std::string> t(M); for (auto& r : t) { std::cin >> r; --MAP[r]; } int max = -201; for (auto& r : MAP) max = std::max(max, r.second); std::cout << std::max(max, 0) << std::endl; }
#include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define endl "\n" #define ALL(a) (a).begin(),(a).end() using namespace std; using ll = long long; const double PI = 3.14159265358979; void solve() { ll n; cin >> n; string s; map<string, int> mps; for(int i = 0; i < n; ++i) { cin >> s; mps[s]++; } ll m; cin >> m; string t; map<string, int> mpt; for(int i = 0; i < m; ++i) { cin >> t; mpt[t]++; } int ans = 0; for(const auto& m : mps) { ans = max(ans, mps[m.first] - mpt[m.first]); } cout << ans; } int main() { fastio; solve(); return 0; }
1
#include <iostream> #include <fstream> #include <vector> #include <algorithm> #include <cmath> #include <limits> #include <queue> #include <iomanip> #include <set> //#include <bits/stdc++.h> 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; } using namespace std; #define ALL(X) X.begin(),X.end() using ll = long long int; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<vvll> vvvll; const int MOD=1000000007; //const int MOD=998244353; const int INTMAX=2147483647; const ll LLMAX=9223372036854775807; ll modadd(ll a,ll b,ll mod=MOD){ return (a%mod+b%mod)%mod; } ll modsub(ll a,ll b,ll mod=MOD){ a%=mod; b%=mod; if(a>=b) return a-b; else return mod-b+a; } ll modmul(ll a,ll b,ll mod=MOD){ return ((a%mod)*(b%mod))%mod; } ll modpow(ll a, ll n,ll mod=MOD) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ll moddiv(ll a,ll b,ll mod=MOD) { return modmul(a, modpow(b, mod-2)); } int main(){ ios::sync_with_stdio(false); cin.tie(0); ll n,m; cin>>n>>m; vll x(n),y(m); for(ll i=0;i<n;i++)cin>>x[i]; for(ll j=0;j<m;j++)cin>>y[j]; sort(ALL(x));sort(ALL(y)); ll a=0; for(ll i=0;i<n;i++){ a=modadd(a,modmul(x[i],i-(n-1-i))); } ll b=0; for(ll i=0;i<m;i++){ b=modadd(b,modmul(y[i],i-(m-1-i))); } cout<<modmul(a,b)<<endl; return 0; }
#pragma GCC optimize ("O3") #include <bits/stdc++.h> #define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef long long ll; using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; int n , m , a , b , pref1 , pref2; int main() { abdelrahman010 cin >> n >> m; for(int i = 0;i < n;i++) { int x; cin >> x; if(i) a = (a + ((1ll * x * i) % mod - pref1 + mod) % mod) % mod; pref1 = (pref1 + x) % mod; } int ans = 0; for(int i = 0;i < m;i++) { int x; cin >> x; b = ((1ll * x * i) % mod - pref2 + mod) % mod; ans = (ans + (1ll * a * b) % mod) % mod; pref2 = (pref2 + x) % mod; } cout << ans; return 0; }
1
////////////////////////// Author ////////////////////////// Nasim Hossain Rabbi ////////////////////////// JU-CSE28 ////////////////////////// CF - imnasim3.1415 ////////////////////////// UVA - imnasim3.1415 ////////////////////////// Mail - [email protected] #include<bits/stdc++.h> using namespace std; #define E end() #define B begin() #define sz size() #define EM empty() #define fi first #define se second #define cl clear() #define sqr(a) (a*a) #define mk make_pair #define po pop() #define pu push #define pb push_back #define pf push_front #define pob pop_back() #define pof pop_front() string en="\n"; string sp=" "; string t="hello"; string Y="YES\n"; string N="NO\n"; #define rep(i,n) for(i=0;i<n;i++) #define Rep(i,n) for(i=1;i<=n;i++) #define per(i,n) for(i=n-1;i>=0;i--) #define peR(i,n) for(i=n;i>0;i--) #define mem(a,b) memset(a,b,sizeof(a)) #define all(cont) cont.begin(),cont.end() #define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL) #define pi 3.1415926535897932384626433832795 #define vi vector<long long> #define vs vector<string> #define MX LLONG_MAX #define MN LLONG_MIN #define MOD 1000000007 #define vp(vi,x) cin>>x; vi.pb(x); #define bsearch(a,x) binary_search(all(a),x) #define LB(a,x) (lower_bound(all(a),x)-a.B) #define UB(a,x) (upper_bound(all(a),x)-a.B) typedef long long LL; typedef long double LD; typedef unsigned long long ULL; bool isprm(LL a){if(a==1)return false; for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;} bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;} bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;} int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;} LL ceil2(LL a,LL b){LL c=a/b; if(a%b)c++; return c; } LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;} LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;} LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;} template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);} template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));} int main() { // fast; LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0; bool f=0,ff=0;string st,s1,s2,s3; char ch; while(cin>>n) { c=0,a=MX; rep(i,n) { cin>>x; if(x<a)c++,a=x; } cout<<c<<en; } return 0; }
#include <iostream> #include <iomanip> #include <sstream> #include <stdio.h> #include <list> #include <vector> #include <stack> #include <queue> #include <map> #include <set> #include <algorithm> #include <math.h> #include <utility> #include <string> #include <ctype.h> #include <cstring> #include <cstdio> #include <sstream> #include <functional> using namespace std; #define FOR(i,k,n) for(int i = (k); i < (n); i++) #define REP(i,n) FOR(i,0,n) #define INF 114514810 #define ll long long #define ALL(a) (a).begin(),(a).end() #define SORT(v) sort(ALL(v)) //#define scanf scanf_s int main() { int n, p; while (cin >> n >> p, n) { int m[55] = {}; int wan = p; int i, j; j = 0; for (i = 1; i < 1000005; i++) { if (wan>0) { wan--; m[j]++; if (m[j] == p) { cout << j << endl; break; } } else { wan += m[j]; m[j] = 0; } j++; if (j >= n) j = 0; } } return 0; }
0
#include <iostream> using namespace std; int main(){ int t; while(cin>>t && t > 0){ int p1 = 0, p2 = 0; while(t > 0){ int a = 0, b = 0; cin >> a >> b; if(a < 0 || a > 9 || a < 0 || a > 9){ continue; } if(a > b){ p1 += a + b; } else if(a < b){ p2 += a + b; } else{ p1 += a; p2 += b; } t--; } cout << p1 << " " << p2 << endl; } return 0; }
#include<cstdio> #include<queue> using namespace std; int main() { int ap, bp, turnnum, acard, bcard; ap = bp = 0; queue<int>adeck, bdeck; while (1) { scanf("%d", &turnnum); if (turnnum == 0)break; for (int i = 0; i < turnnum; i++) { scanf("%d %d", &acard, &bcard); adeck.push(acard); bdeck.push(bcard); } while (adeck.empty() == false) { if (adeck.front()>bdeck.front()) { ap += adeck.front() + bdeck.front(); adeck.pop(); bdeck.pop(); } else if(adeck.front() < bdeck.front()) { bp += adeck.front() + bdeck.front(); adeck.pop(); bdeck.pop(); } else { ap += adeck.front(); bp += bdeck.front(); adeck.pop(); bdeck.pop(); } } printf("%d %d\n", ap, bp); ap=0;bp=0; } }
1
#include <algorithm> #include <iostream> #include <iomanip> #include <numeric> #include <cassert> #include <vector> #include <cmath> #include <queue> #include <set> #include <map> #define syosu(x) fixed<<setprecision(x) using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int,P> pip; typedef vector<pip> vip; const int inf=1<<30; const ll INF=1ll<<60; const double pi=acos(-1); const double eps=1e-8; const ll mod=998244353; const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1}; int q,n; vl a; string s; int main(){ cin>>q; while(q){ cin>>n; a=vl(n); for(auto &i:a) cin>>i; cin>>s; reverse(a.begin(),a.end()); reverse(s.begin(),s.end()); vl b; bool B=0; for(int i=0;i<n;i++){ ll x=a[i]; for(auto j:b) x=min(x,x^j); if(s[i]=='0') b.push_back(x); else if(x) B=1; } cout<<B<<endl; q--; } }
#include <bits/stdc++.h> using namespace std; int solve () { int n; cin >> n; vector<long long> a(n); for (auto &e : a) cin >> e; string s; cin >> s; vector<long long> b; for (int i = n; i--> 0;) { long long e = a[i]; for (const auto &c : b) e = min(e, e^c); if (e > 0) { if (s[i] == '1') return 1; b.push_back(e); } } return 0; } int main() { int t; cin >> t; while (t--) cout << solve() << '\n'; return 0; }
1
#include <bits/stdc++.h> using namespace std; using ll = long long; #define double long double #define rep(i, n) for (long long i = 0; i < (n); ++i) #define repr(i, a, b) for (auto i = (a); i < (b); ++i) #define itr(x, c) for (auto&& x : (c)) #define updatemax(t, v) ((t) = std::max((t), (v))) #define updatemin(t, v) ((t) = std::min((t), (v))) #define endl _endl const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n'); int main() { ll n, m; cin >> n >> m; vector<ll> l(m), r(m); rep(i, m) cin >> l[i] >> r[i]; ll a = LLONG_MIN, b = LLONG_MAX; rep(i, m) updatemax(a, l[i]); rep(i, m) updatemin(b, r[i]); cout << max(0ll, b - a + 1) << endl; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; #define rep(i,n) for (int i=0; i < int(n); i++) // 素集合データ構造 struct UnionFind { // par[i]:データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである vector<int> par; // sizes[i]:根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる vector<int> sizes; UnionFind(int n) : par(n), sizes(n, 1) { // 最初は全てのデータiがグループiに存在するものとして初期化 rep(i,n) par[i] = i; } // データxが属する木の根を得る int find(int x) { if (x == par[x]) return x; return par[x] = find(par[x]); // 根を張り替えながら再帰的に根ノードを探す } // 2つのデータx, yが属する木をマージする void unite(int x, int y) { // データの根ノードを得る x = find(x); y = find(y); // xの木がyの木より大きくなるようにする if (sizes[x] < sizes[y]) swap(x, y); // xがyの親になるように連結する par[y] = x; sizes[x] += sizes[y]; // sizes[y] = -1; // sizes[y]は無意味な値となるので-1を入れておいてもよい } // 2つのデータx, yが属する木が同じならtrueを返す bool same(int x, int y) { return find(x) == find(y); } // データxが含まれる木の大きさを返す int size(int x) { return sizes[find(x)]; } }; // 頂点a, bをつなぐコストcostの(無向)辺 struct Edge { int a, b, cost; // コストの大小で順序定義 bool operator<(const Edge& o) const { return cost < o.cost; } }; // 頂点数と辺集合の組として定義したグラフ struct Graph { int n; // 頂点数 vector<Edge> es; // 辺集合 // クラスカル法で無向最小全域木のコストの和を計算する // グラフが非連結のときは最小全域森のコストの和となる int kruskal() { // コストが小さい順にソート sort(es.begin(), es.end()); UnionFind uf(n); int min_cost = 0; rep(ei, es.size()) { Edge& e = es[ei]; if (!uf.same(e.a, e.b)) { // 辺を追加しても閉路ができないなら、その辺を採用する min_cost += e.cost; uf.unite(e.a, e.b); } } return min_cost; } }; // 標準入力からグラフを読み込む Graph input_graph() { Graph g; int m; cin >> g.n >> m; rep(i, m) { Edge e; cin >> e.a >> e.b >> e.cost; g.es.push_back(e); } return g; } int main() { Graph g = input_graph(); cout << g.kruskal() << endl; return 0; }
0
#include<iostream> using namespace std; int main(){ int A,B,C,D; cin>>A>>B>>C>>D; cout << ((A<B ? A : B) + (C<D ? C : D)) << endl; return 0; }
#include <iostream> #include <algorithm> #include <iomanip> #include <math.h> #include <vector> using namespace std; int main(){ cin.tie(NULL); ios::sync_with_stdio(false); int a[5],b[5]; int ans=0; cin>>a[0]>>a[1]>>b[0]>>b[1]; sort(a,a+2); sort(b,b+2); ans=a[0]+b[0]; cout<<ans<<"\n"; return 0; }
1
#include <bits/stdc++.h> #define MOD 1000000007 #define INF 1000000000 #define LINF 1000000000000000000 #define rep(i,n) for (int i = 0; i < (n); ++i) #define bit(n) (1LL<<(n)) using namespace std; typedef pair<int, int> P; typedef pair<long long, long long> LLP; int main() { int X, Y; cin >> X >> Y; int ans = 0; switch(X) { case 1: ans += 300000; break; case 2: ans += 200000; break; case 3: ans += 100000; break; } switch(Y) { case 1: ans += 300000; break; case 2: ans += 200000; break; case 3: ans += 100000; break; } if (X == 1 && Y == 1) ans += 400000; cout << ans << endl; return 0; }
#include <iostream> using namespace std; int main() { string S,T; cin>>S>>T; string r=T+S; cout<<r; return 0; }
0
#include<iostream> #include<cstdio> using namespace std; const int N=1005; int h,w,A,B; int a[N][N]; int main() { scanf("%d%d%d%d",&h,&w,&A,&B); for(int i=1;i<=B;i++) for(int j=1;j<=A;j++) a[i][j]=1; for(int i=B+1;i<=h;i++) for(int j=A+1;j<=w;j++) a[i][j]=1; for(int i=1;i<=h;i++) { for(int j=1;j<=w;j++) printf("%d",a[i][j]); printf("\n"); } return 0; }
#include <iostream> #include <vector> #include <queue> #include <algorithm> #include <utility> using namespace std; const int Inf = 10000 * 100000 + 100; int main(){ int V,E,R; cin >> V >> E >> R; vector<int> s(E),t(E),d(E); vector<vector<int> > edge(V); for(int i = 0; i < E; i++){ cin >> s[i] >> t[i] >> d[i]; edge[s[i]].push_back(i); } vector<int> cost(V, Inf); cost[R] = 0; // < ?§??????????????????¢, ?????????id > priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q; q.push({0, R}); // ???????????????????????? vector<bool> fin(V, false); // vector<vector<int> > edge(V); // for(int i = 0; i < V; i++){ // edge[i] = {}; // // ?????? i ????????????????????????????????? // for(int j = 0; j < E; j++){ // if(s[j] == i) edge[i].push_back(j); // } // } while(!q.empty()){ // ?¢?????????????????????? u ??¨?????? auto npair = q.top(); int nd = npair.first, nu = npair.second; // cout << nd << " : " << nu << endl; q.pop(); if(fin[nu]) continue; // ?¢?????????????????????? fin[nu] = true; cost[nu] = nd; for(auto i : edge[nu]){ // u ????§??????§?¢????????????§??????????????????????????????????????? if(!fin[t[i]]){ // ????????? v ??¨??????. int nv = t[i]; // ????????§????????????????????? if(cost[nu] + d[i] < cost[nv]){ cost[nv] = cost[nu] + d[i]; q.push({cost[nv], nv}); } } } } for(int i = 0; i < V; i++){ if(cost[i] == Inf) cout << "INF"; else cout << cost[i]; cout << endl; } }
0
#include<bits/stdc++.h> #define ll long long using namespace std; double dp[301][301][301]; double sushi(int n, int x, int y, int z){ if(x==0 && y==0 && z==0){ return 0; } if(x<0 || y<0 || z<0){ return 0; } if(dp[x][y][z] > -0.9){ return dp[x][y][z]; } double res = n + x*sushi(n, x-1, y, z) + y*sushi(n, x+1, y-1, z) + z*sushi(n, x, y+1, z-1); return dp[x][y][z] = res/(x+y+z); } int main(){ memset(dp, -1, sizeof(dp)); int n; cin >> n; int a[n]; int ones=0, twos=0, threes=0; for(int i=0;i<n;i++){ cin >> a[i]; switch(a[i]){ case 1: ones++; break; case 2: twos++; break; case 3: threes++; break; } } cout << setprecision(10) << sushi(n, ones, twos, threes); return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int #define endl "\n" #define F first #define S second #define mod 1000000007 #define pb push_back #define FOR(i,a,n) for(int i=a;i<n;i++) #define REV(i,a,n) for(int i=a;i>=n;i--) #define all(a) a.begin(),a.end() #define UB upper_bound #define LB lower_bound const int NUM = 2e5 + 5; const int N = 301; double dp[N][N][N]; // dp[x][y][z] = x 3s, y 2s, z 1s and (n - x - y - z) zeros int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int num_tests=1; //cin >> num_tests; while(num_tests-->0){ int n; cin >> n; int cnt[4] = {0}; FOR(i,0,n){ int x; cin >> x; cnt[x]++; } dp[0][0][0] = 0.0; FOR(x,0,n+1){ FOR(y,0,n+1){ FOR(z,0,n+1){ int zeros = n - (x+y+z); if(zeros == n) continue; if(zeros < 0) continue; double res = 1.0; // if I pick 3 if(x > 0) res += (1.0 * x/n) * dp[x-1][y+1][z]; // if I pick 2 if(y > 0) res += (1.0 * y/n) * dp[x][y-1][z+1]; // if I pick 1 if(z > 0) res += (1.0 * z/n) * dp[x][y][z-1]; res = res/(1 - 1.0*zeros/n); dp[x][y][z] = res; } } } cout << fixed << setprecision(10); cout << dp[cnt[3]][cnt[2]][cnt[1]]; } }
1
# include <iostream> using namespace std; int N; int K; int A[100005]; int maximum=0; int factor; int gcd (int a, int b) { if (b==0) { return a; } else { return gcd(b, a%b); } } int main() { cin>>N; cin>>K; for (int i=1; i<=N; i++) { cin>>A[i]; maximum=max(maximum, A[i]); if (i==1) { factor=A[i]; } else { factor=gcd(factor, A[i]); } } if (K>maximum) { cout<<"IMPOSSIBLE"<<endl; return 0; } if (K%factor!=0) { cout<<"IMPOSSIBLE"<<endl; return 0; } cout<<"POSSIBLE"<<endl; }
#include <iostream> #include <map> #include <cmath> using namespace std; #define L 998244353 int main(int argc, char* argv[]) { long long N; cin >> N; long long d[N]; for (int i = 0; i < N; ++i) cin >> d[i]; if (d[0] != 0) { cout << "0" << endl; return 0; } map<long long, long long> m; long long max_v = 0; for (int i = 0; i < N; ++i) { if (m.find(d[i]) == m.end()) m[d[i]] = 0; ++m[d[i]]; max_v = max(d[i], max_v); } if (m[0] > 1) { cout << 0 << endl; return 0; } long long ret = 1; for (long long i = 1; i <= max_v; ++i) { if (m.find(i) == m.end()) { cout << 0 << endl; return 0; } for (int j = 0; j < m[i]; ++j) { ret *= m[i - 1]; ret %= 998244353; } } cout << ret << endl; return 0; }
0
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <complex> #include <cstring> #include <cstdlib> using namespace std; #define REP(i,n) for(int i=0;i<(int)n;++i) #define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) #define ALL(c) (c).begin(), (c).end() int main() { int n; cin >> n; while(n--) { string s; int out = 0; vector<int> rui(3); int ten = 0; while(out < 3) { // FOR(it,rui) // cout << *it << " "; // cout << endl; cin >> s; if (s == "HIT") { if (rui[2]) ten++; rui[2] = rui[1]; rui[1] = rui[0]; rui[0] = 1; } else if (s == "HOMERUN") { REP(i,3) { ten += rui[i]; } ten++; rui = vector<int>(3); } else out++; } cout << ten << endl; } }
// #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio> #include <algorithm> #include <string> #include <vector> #include <map> #include <set> #include <stack> #include <cmath> #include <cstdlib> #include <functional> #include <locale> #include <cctype> #include <sstream> using namespace std; typedef long long LL; typedef vector<int> VI; typedef vector<VI> VVI; typedef map<int, int> MAPII; typedef vector<pair<int, int> > VPII; typedef multimap<int, string, greater<int> > MuMIS; #define MP make_pair #define fastIO cin.tie(0); ios::sync_with_stdio(false); #define FOR(i,a,b) for(int i=(a);i<(b);i++) //for gcc (未test) // #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it) //for Visual Studio #define foreach_it(type,it,c) for(type::iterator it=c.begin(), c_end=c.end(); it!=c_end; ++it) // ------------------- include, typedef, define END. ------------------- int Hit(int *rui){ rui[0]++; // 塁を進める FOR(i, 1, 4){ if (rui[i - 1]==2){ rui[i]++; rui[i - 1] = 1; } } if (rui[3]!=0){ rui[3] = 0; return 1; } return 0; } int Homerun(int *rui){ int ret = 1; FOR(i, 0, 4) if (rui[i]) ret++; return ret; } int main(){ fastIO; int n, outCount = 0, tokuten = 0; string in; // rui[0]〜rui[2] = 1塁〜3塁, rui[3] = 本塁 // 各値はその塁にいる人数(0〜2) int rui[4] = {}; cin >> n; while (cin >> in){ if (in == "OUT") outCount++; if (outCount < 3){ if (in == "HIT"){ tokuten += Hit(rui); } else if (in == "HOMERUN"){ tokuten += Homerun(rui); FOR(i, 0, 4) rui[i] = 0; } } else{ cout << tokuten << endl; FOR(i, 0, 4) rui[i] = 0; tokuten = 0; outCount = 0; } } return 0; }
1
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef vector<vll> vvll; #define all(x) x.begin(), x.end() #define rep(i,a,b) for(int i = a; i < b; i++) int V, E; vvi conn(100002); vi vis(100002); vb trail(100002); vb cut(100002); int dfs_min(int v, int depth, int parent) { if(vis[v] > 0) return vis[v]; vis[v] = depth; trail[v] = true; int minHit = depth; rep(i,0,(int)conn[v].size()) { if(conn[v][i] != parent && (vis[conn[v][i]] == 0 || trail[conn[v][i]])) { int hit = dfs_min(conn[v][i], depth+1, v); minHit = min(minHit, hit); if(hit >= depth && conn[v].size() > 1) cut[v] = true; } } trail[v] = false; return minHit; } int main() { cin >> V; cin >> E; rep(e,0,E) { int s, t; cin >> s; cin >> t; conn[s].push_back(t); conn[t].push_back(s); } dfs_min(0, 1, -1); if(V > 1) { cut[0] = false; bool remember = cut[1]; fill(all(vis), 0); dfs_min(1, 1, -1); cut[1] = remember; } rep(v,0,V) if(cut[v]) cout << v << '\n'; }
#include <bits/stdc++.h> #define debug(...) fprintf(stderr, __VA_ARGS__) #ifndef AT_HOME #define getchar() IO::myGetchar() #define putchar(x) IO::myPutchar(x) #endif namespace IO { static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23; inline char myGetchar() { static char buf[IN_BUF], *ps = buf, *pt = buf; if (ps == pt) { ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin); } return ps == pt ? EOF : *ps++; } template<typename T> inline bool read(T &x) { bool op = 0; char ch = getchar(); x = 0; for (; !isdigit(ch) && ch != EOF; ch = getchar()) { op ^= (ch == '-'); } if (ch == EOF) { return false; } for (; isdigit(ch); ch = getchar()) { x = x * 10 + (ch ^ '0'); } if (op) { x = -x; } return true; } inline int readStr(char *s) { int n = 0; char ch = getchar(); for (; isspace(ch) && ch != EOF; ch = getchar()) ; for (; !isspace(ch) && ch != EOF; ch = getchar()) { s[n++] = ch; } s[n] = '\0'; return n; } inline void myPutchar(char x) { static char pbuf[OUT_BUF], *pp = pbuf; struct _flusher { ~_flusher() { fwrite(pbuf, 1, pp - pbuf, stdout); } }; static _flusher outputFlusher; if (pp == pbuf + OUT_BUF) { fwrite(pbuf, 1, OUT_BUF, stdout); pp = pbuf; } *pp++ = x; } template<typename T> inline void print_(T x) { if (x == 0) { putchar('0'); return; } static int num[40]; if (x < 0) { putchar('-'); x = -x; } for (*num = 0; x; x /= 10) { num[++*num] = x % 10; } while (*num){ putchar(num[*num] ^ '0'); --*num; } } template<typename T> inline void print(T x, char ch = '\n') { print_(x); putchar(ch); } inline void printStr_(const char *s, int n = -1) { if (n == -1) { n = strlen(s); } for (int i = 0; i < n; ++i) { putchar(s[i]); } } inline void printStr(const char *s, int n = -1, char ch = '\n') { printStr_(s, n); putchar(ch); } } using namespace IO; int n; int main() { read(n); print(180 * (n - 2)); }
0
#include <stdio.h> #include <iostream> #include <algorithm> using namespace std; #define N 100 void searchIndex(int mat[][N], int n, int obj, int *row, int *col); void changeGroup(int group[], int n, int g_old, int g_new); int main(void) { int n; cin >> n; int group[N]; for (int i = 0; i < n; i++) group[i] = i; int a[N][N]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int aij; cin >> aij; a[i][j] = aij; } } int e[N * N]; int k = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { e[k++] = a[i][j]; } } sort(e, e + k); int p = 0; while (e[p] == -1) p++; int cnt = 0; for (int q = p; q < k; q++) { int i, j; searchIndex(a, n, e[q], &i, &j); if (group[i] == group[j]) continue; cnt += e[q]; if (group[i] > group[j]) changeGroup(group, n, group[i], group[j]); else changeGroup(group, n, group[j], group[i]); } cout << cnt << endl; return 0; } void searchIndex(int mat[][N], int n, int obj, int *row, int *col) { for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (mat[i][j] == obj) { mat[i][j] = -1; *row = i; *col = j; return; } } } } void changeGroup(int group[], int n, int g_old, int g_new) { for (int i = 0; i < n; i++) { if (group[i] == g_old) group[i] = g_new; } }
#include <iostream> #include <set> #include <vector> #include <queue> #include <stack> #include <utility> #include <algorithm> using namespace std; typedef long long signed int ll; constexpr ll NIL = -20000000000; int n,z[100][100]; set <int> t; int main() { cin >> n; for(int i = 0;i < n;i++) { for(int j = 0;j < n;j++) { cin >> z[i][j]; if(z[i][j] == -1) z[i][j] = 100000; } } int res = 0; t.insert(0); while(t.size() != n) { int me = 100000;int mi = -1; for(auto e:t) { for(int i = 0;i < n;i++) { if(me > z[e][i] && t.find(i) == t.end()) { me = z[e][i]; mi = i; } } } res += me; t.insert(mi); } cout << res << endl; }
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(){ string s; cin >> s; if(s == "SUN") cout << 7 << endl; if(s == "MON") cout << 6 << endl; if(s == "TUE") cout << 5 << endl; if(s == "WED") cout << 4 << endl; if(s == "THU") cout << 3 << endl; if(s == "FRI") cout << 2 << endl; if(s == "SAT") cout << 1 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int R; cin >> R; double c = 2*R*3.14159; cout << c; }
0
#include<bits/stdc++.h> #define st first #define nd second #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define umax(x,y) x=max(x,y) #define umin(x,y) x=min(x,y) #define ll long long #define ii pair<int,int> #define iii pair<int,ii> #define iiii pair<ii,ii> #define sz(x) ((int) x.size()) #define orta ((bas+son)/2) #define all(x) x.begin(),x.end() #define pw(x) (1<<(x)) #define inf 1000000005 #define MOD 1000000007 #define N 100005 #define M 1000003 #define LOG 19 #define KOK 250 #define EPS 0.0000001 using namespace std; int n,x; int s[N],dp[N],pt[N]; int res[205][205]; int mul(int x,int y) { return (ll)x*y%MOD; } int add(int x,int y) { x+=y; if(x>=MOD) x-=MOD; if(x<0) x+=MOD; return x; } int main() { scanf("%d %d",&n,&x); for(int i=1;i<=n;i++) scanf("%d",&s[i]); sort(s+1,s+1+n); for(int i=0;i<=n+1;i++) { res[i][0]=1; for(int j=1;j<=n+1;j++) { res[i][j]=mul(res[i][j-1],i+j-1); } } int ptr=0; for(int i=0;i<=x;i++) { while(s[ptr+1]<=i && ptr+1<=n) ++ptr; pt[i]=ptr; if(ptr==0) dp[i]=i; for(int j=ptr;j>=1;j--) { int nm=i%s[j]; dp[i]=add(dp[i],mul(dp[nm],res[pt[nm]+1][ptr-pt[nm]-1])); } } dp[x]=mul(dp[x],res[ptr+1][n-ptr]); printf("%d",dp[x]); }
#include <bits/stdc++.h> template <typename InputIterator> typename InputIterator::value_type summation(InputIterator first, InputIterator last) { using T = typename InputIterator::value_type; T *p = new T(); const auto sum = std::accumulate(first, last, *p); delete p; return sum; } template <typename T> std::istream &operator>>(std::istream &stream, std::vector<T> &v); template <typename T1, typename T2> std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p); template <typename T> std::istream &operator>>(std::istream &stream, std::vector<T> &v) { for (auto &i : v) { stream >> i; } return stream; } template <typename T1, typename T2> std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) { stream >> p.first >> p.second; return stream; } int main() { int64_t n, x; std::cin >> n >> x; std::vector<int64_t> s(n); std::cin >> s; std::sort(s.begin(), s.end(), std::greater<int64_t>()); constexpr int64_t mod = 1000000007; std::vector<int64_t> t1(100001, 0), t2(100001, 0); t1[x] = 1; for (int64_t i = 0; i < n; i++) { std::fill(t2.begin(), t2.end(), 0); for (int64_t j = 0; j < 100001; j++) { t2[j % s[i]] += t1[j] % mod; t2[j % s[i]] %= mod; t2[j] += t1[j] * (n - i - 1); t2[j] %= mod; } std::swap(t1, t2); } int64_t ans = 0; for (int64_t j = 0; j < 100001; j++) { ans += j * t1[j] % mod; ans %= mod; } std::cout << ans << std::endl; return 0; }
1
// Author : Mohamed Sameh #include <bits/stdc++.h> typedef long long ll ; #define pb push_back #define f first #define s second #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define SZ(a) (int)a.size() #define Flush fflush(stdout); using namespace std ; const int N = 16; const ll MN = -1e9*N; int n; int a[N][N]; ll dp[(1<<N)]; ll value[(1<<N)]; int arr[N]; ll solve(int msk = (1<<n)-1) { if (!msk)return 0; ll &ret = dp[msk]; if (~ret)return ret; ret = MN; for (int cur_msk = msk; cur_msk; cur_msk=(cur_msk-1)&msk) { ret = max(ret, value[cur_msk] + solve(msk^cur_msk)); } return ret; } ll get_cost(int sz) { ll ret = 0; for (int i = 0; i < sz; i++) for (int j = i+1; j < sz; j++) ret += a[arr[i]][arr[j]]; return ret; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf("%d", a[i]+ j); memset(dp, -1, sizeof dp); for (int i = 0; i < (1<<n); i++) { int idx = 0; for (int j = 0; j < n; j++) { if (i & (1<<j))arr[idx++] = j; } value[i] = get_cost(idx); } printf("%lld\n", solve()); }
#include<iostream> #include<vector> #include<cmath> #include<cassert> #include<bitset> using namespace::std; #define int long long int int dp[1<<16],ar[20][20]; main(){ ios_base::sync_with_stdio(0); int n; cin>>n; for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>ar[i][j]; for(int j=1;j<(1<<n);j++){ int t=j; vector<int> v; for(;t;t-=t&(-t)) v.push_back((int)log2(t&(-t))); // cout<<(bitset<20>)j<<'\n'; t=j; for(int i=0;i<v.size();i++) for(int j=i+1;j<v.size();j++) dp[t]+=ar[v[i]][v[j]];//,cout<<v[i]<<' '<<v[j]<<' '<<ar[v[i]][v[j]]<<' '<<dp[t]<<'\n'; // for(auto a:v) // cout<<a<<' '; // cout<<dp[j]<<'\n'; } for(int i=1;i<=n;i++) for(int j=1;j<(1<<n);j++) if(__builtin_popcount(j)==i) for(int k=((1<<n)-1)^(((1<<n)-1)&j);k;k--,k^=k&j){ dp[j|k]=max(dp[j|k],dp[j]+dp[k]); } cout<<dp[(1<<n)-1]<<'\n'; // for(int j=1;j<(1<<n);j++) // cout<<dp[j]<<'\n'; }
1
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(long long i=0;i<(long long)(n);i++) #define REP(i,k,n) for(long long i=k;i<(long long)(n);i++) #define all(a) a.begin(),a.end() #define pb push_back #define eb emplace_back #define lb(v,k) (lower_bound(all(v),k)-v.begin()) #define ub(v,k) (upper_bound(all(v),k)-v.begin()) #define fi first #define se second #define pi M_PI #define PQ(T) priority_queue<T> #define SPQ(T) priority_queue<T,vector<T>,greater<T>> #define dame(a) {out(a);return 0;} #define decimal cout<<fixed<<setprecision(15); typedef long long ll; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> PP; typedef tuple<ll,ll,ll,ll> PPP; typedef multiset<ll> S; using vi=vector<ll>; using vvi=vector<vi>; using vvvi=vector<vvi>; using vp=vector<P>; using vvp=vector<vp>; using vb=vector<bool>; using vvb=vector<vb>; const ll inf=1001001001001001001; const int INF=1001001001; const int mod=998244353; const double eps=1e-10; template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;} template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;} template<class T> void out(T a){cout<<a<<'\n';} template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';} template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';} template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);} template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';} template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);} template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);} template<class T> void yesno(T b){if(b)out("yes");else out("no");} template<class T> void YesNo(T b){if(b)out("Yes");else out("No");} template<class T> void YESNO(T b){if(b)out("YES");else out("NO");} template<class T> void noyes(T b){if(b)out("no");else out("yes");} template<class T> void NoYes(T b){if(b)out("No");else out("Yes");} template<class T> void NOYES(T b){if(b)out("NO");else out("YES");} void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);} ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);} ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;} vi fac,finv,inv; void init(ll n) { fac=vi(n+5);finv=vi(n+5);inv=vi(n+5); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; REP(i,2,n+5){ 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 modcom(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(){ ll k,n;cin>>k>>n; init(n+k); REP(j,2,2*k+1){ ll ans=0; ll a=min((j-1)/2,(k*2-j+1)/2),b=(j+1)%2; rep(i,a+1)ans=(ans+modcom(a,i)*modpow(2,i)%mod*(modcom(n+k-a*2-b-1,k-a*2-b+i-1)+modcom(n+k-a*2-b-2,k-a*2-b+i-1)*b))%mod; out(ans); } }
#include <bits/stdc++.h> #define _USE_MATH_DEFINES using namespace std; // 型シノニム typedef long long ll; typedef long double ld; typedef pair<ll, ll> P; // 定数 constexpr ll INF = 1e16; constexpr ll INM = 114514; constexpr ll MOD = 1e9 + 7; constexpr ld EPS = 1e-12; constexpr ll dx[4] = {1, 0, -1, 0}; constexpr ll dy[4] = {0, 1, 0, -1}; // 便利関数 void IOS() { ios::sync_with_stdio(false), cin.tie(0); } template <typename T> void dump(T x) { cout << x << endl; } void dumpf(ld x, ll t) { cout << setprecision(t) << fixed << x << endl; } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill((T *)array, (T *)(array + N), val); } inline ll mod(ll a, ll mod) { if (a > 0) return a % mod; if (a % mod == 0) return 0; ll x = -a / mod + 1; a += x * mod; return a % mod; } ll powm(ll a, ll b, ll m) { if (b == 0) { return 1; } else if (b % 2 == 0) { ll d = powm(a, b / 2, m); return (d * d) % m; } else { return (powm(a, b - 1, m) * a) % m; } } // 本体 int main() { IOS(); ll n, m; cin >> n >> m; ll dif = (n - 1) / 2; ll lb = 1, ub = dif + 1; ll cnt = 0; while (lb < ub && cnt < m) { cout << lb << " " << ub << endl; lb++; ub--; cnt++; } lb = dif + 2; ub = 2 * dif + 1; while (lb < ub && cnt < m) { cout << lb << " " << ub << endl; lb++; ub--; cnt++; } }
0
#include <bits/stdc++.h> using namespace std; template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } #ifdef __LOCAL #define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n' #define debugArray(x, n) \ cerr << __LINE__ << ": " << #x << " = {"; \ for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \ cerr << ((hoge) ? "," : "") << x[hoge]; \ cerr << "}" << '\n' #define debugMatrix(x, h, w) \ cerr << __LINE__ << ": " << #x << " =\n"; \ for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) { \ cerr << ((hoge ? " {" : "{{")); \ for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga)) \ cerr << ((fuga ? ", " : "")) << x[hoge][fuga]; \ cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \ } #else #define debug(x) (void(0)) #define debugArray(x, n) (void(0)) #define debugMatrix(x, h, w) (void(0)) #endif signed main() { cin.tie(0); ios::sync_with_stdio(0); int T; cin >> T; while (T--) { int N; cin >> N; long long A[N]; for (int i = 0; i < N; i++) cin >> A[i]; string S; cin >> S; int ans = 0; vector<long long> bases; for (int i = N - 1; i >= 0; i--) { for (auto b : bases) A[i] = min(A[i], A[i] ^ b); if (A[i]) { if (S[i] == '1') { ans = 1; break; } bases.push_back(A[i]); } } cout << ans << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int po[63]; int f(int x) { for(int i=62;i>=0;i--) { if(po[i] & x) { return i; } } return -1; } vector <int> basis(vector <int> v) { if(v.size()==1) return v; sort(v.begin(),v.end()); reverse(v.begin(),v.end()); if(v[0]==0) { vector <int> ans; return ans; } int n=v.size(); vector <int> g; for(int i=1;i<n;++i) { if(f(v[i])==f(v[0])) { v[i]=v[i]^v[0]; } g.push_back(v[i]); } vector <int> ans=basis(g); ans.insert(ans.begin(),v[0]); return ans; } bool can(vector <int> v,int x) { int n=v.size(); for(int i=0;i<n;++i) { if(x==0) { return true; } if(f(x)==f(v[i])) { x^=v[i]; } } return (x==0); } int32_t main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int u=1; for(int i=0;i<63;++i) { po[i]=u; u*=2; } int t; cin>>t; while(t--) { int n; cin>>n; int a[n]; for(int i=0;i<n;++i) { cin>>a[i]; } string s; cin>>s; vector <int> v; bool h=true; for(int i=(n-1);i>=0;i--) { if(s[i]=='0') { v.push_back(a[i]); v=basis(v); } else { if(!can(v,a[i])) { h=false; break; } } } if(h) { cout<<0<<endl; } else { cout<<1<<endl; } } return 0; }
1
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) REP(i, 0, n) #define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--) #define sz(x) int(x.size()) #define bitsz(x) int(__builtin_popcount(x)) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb(x) push_back(x) #define INF 1e9 #define LINF 1e18 #define mod 1000000007 template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }; typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> LP; const int di[4] = {1,0,-1,0}; const int dj[4] = {0,1,0,-1}; int main() { int n; cin >> n; vector<ll> l(n); rep(i,n) cin >> l[i]; int ans = 0; rep(i,n) { for (int j=i+1; j<n; j++) { for (int k=j+1; k<n; k++) { if (l[i]==l[j] || l[j]==l[k] || l[k]==l[i]) continue; if (l[i]+l[j]>l[k] && l[j]+l[k]>l[i] && l[k]+l[i]>l[j]) ans++; } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long const ll MOD = 1000000007; bool check(int a,int b,int c) { if((a+b)>c && (c+b)>a && (a+c)>b) return true; return false; } int main() { // freopen("input01.txt", "r", stdin); // freopen("output01.txt", "w", stdout); int n; cin>>n; map<ll int,int> mp; ll int a; int l,ct=0; for(l=0;l<n;l++) { cin>>a; mp[a]++; } if(mp.size()<3) { cout<<0; return 0; } for(auto i=mp.begin();next(next(i))!=mp.end();i++) { for(auto j=next(i);next(j)!=mp.end();j++) { for(auto k=next(j);k!=mp.end();k++) { if(check(i->first,j->first,k->first)) ct+=(i->second*j->second*k->second); } } } cout<<ct; return 0; }
1
///Bismillahir Rahmanir Rahim #include "bits/stdc++.h" #define ll long long #define int ll #define fi first #define si second #define mp make_pair #define pb push_back #define pi pair<ll,ll> #define clr(x) memset(x,0,sizeof(x)); #define f(i,l,r) for(int i=l;i<=r;i++) #define rf(i,r,l) for(int i=r;i>=l;i--) #define done(i) cout<<"done = "<<i<<endl; #define show(x,y) cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl; #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; const ll inf=1e18; const int mod=1e9+7; const int M=100005; int h,w; int a[505][505]; vector<pi>vec; vector<pair<pi,pi> >ses; vector<pi>yo; int flag=0; void dfs(int x,int y,int ex,int ey,int turn) { if(flag)return ; if(x==ex && y==ey) { flag=1; return ; } if(y>w) { y=w; x++; turn=1-turn; dfs(x,y,ex,ey,turn); return ; } if(y<1) { y=1; x++; turn=1-turn; dfs(x,y,ex,ey,turn); return ; } yo.pb(mp(x,y)); if(turn==0) { dfs(x,y+1,ex,ey,turn); } else if(turn==1) { dfs(x,y-1,ex,ey,turn); } } void work(pi u,pi v) { int x1=u.fi; int y1=u.si; int x2=v.fi; int y2=v.si; int turn=0; if(x1%2==0)turn=1; flag=0; yo.clear(); dfs(x1,y1,x2,y2,turn); yo.pb(mp(x2,y2)); int sz=yo.size(); // for(auto x:yo) // { // cout<<x.fi<<" "<<x.si<<endl; // } // cout<<"......"<<endl; for(int i=0;i<sz-1;i++) { ses.pb(mp(yo[i],yo[i+1])); } } main() { fast cin>>h>>w; f(i,1,h) { vector<pi>nw; f(j,1,w) { cin>>a[i][j]; if(a[i][j]%2==1)nw.pb(mp(i,j)); } if(i%2==0)reverse(nw.begin(),nw.end()); for(auto x:nw)vec.pb(x); } if(vec.size()==0) { cout<<"0"<<endl; return 0; } if(vec.size()%2==1)vec.pop_back(); int sz=vec.size(); if(sz==0) { cout<<"0"<<endl;return 0; } for(int i=0;i<sz;i=i+2) { pi x=vec[i]; pi y=vec[i+1]; //cout<<x.fi<<" "<<x.si<<" "<<y.fi<<" "<<y.si<<endl; work(x,y); } cout<<ses.size()<<"\n"; for(auto x:ses) { pi u=x.fi; pi v=x.si; cout<<u.fi<<" "<<u.si<<" "<<v.fi<<" "<<v.si<<"\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; 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; } using ll = long long; using P = pair<int, int>; ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; } ll LCM(ll a, ll b) { return a/GCD(a, b)*b; } int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, -1, 0, 1}; int h, w; struct xydata { int px; int py; int nex; int ney; }; int main() { cin >> h >> w; vector< vector<int> > amap(h, vector<int>(w, 0)); for(int i = 0; i < h; ++i) { for(int j = 0; j < w; ++j) { cin >> amap.at(i).at(j); } } int n = 0; vector<xydata> xyvec; for(int i = 0; i < h; ++i) { for(int j = 0; j < w; ++j) { if(amap.at(i).at(j)%2 != 0) { // そのマスが奇数ならまずは周囲を確認する bool flg = false; for(int k = 0; k < 4; ++k) { int nx = j+dx[k]; int ny = i+dy[k]; if(nx >= 0 && nx < w && ny >= 0 && ny < h) { if(amap.at(ny).at(nx)%2 != 0) { flg = true; n++; xydata indata; indata.px = j; indata.py = i; indata.nex = nx; indata.ney = ny; xyvec.emplace_back(indata); amap.at(i).at(j)--; amap.at(ny).at(nx)++; break; } } } if(!flg) { for(int k = 2; k < 4; ++k) { int nx = j+dx[k]; int ny = i+dy[k]; if(nx >= 0 && nx < w && ny >= 0 && ny < h) { n++; xydata ndata; ndata.px = j; ndata.py = i; ndata.nex = nx; ndata.ney = ny; xyvec.emplace_back(ndata); amap.at(i).at(j)--; amap.at(ny).at(nx)++; break; } } } } } } cout << n << endl; for(int i = 0; i < n; ++i) { xydata ans = xyvec.at(i); cout << ans.py+1 << " " << ans.px+1 << " " << ans.ney+1 << " " << ans.nex+1 << endl; } }
1
#include<bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int,int>; ll dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; ll counterb=0,counterw=0; void dfs(ll x,ll y,ll H, ll W,vector<vector<bool>> &field,vector<vector<bool>> &check){ check[x][y]=1; if(field[x][y]==1){counterb++;} if(field[x][y]==0){counterw++;} bool meter=(x+y+field[x][y])%2; for(int i=0;i<4;i++){if(x+dx[i]>=0&&x+dx[i]<H&&y+dy[i]>=0&&y+dy[i]<W){ if(check[x+dx[i]][y+dy[i]]==0&&(x+y+dx[i]+dy[i]+field[x+dx[i]][y+dy[i]])%2==meter){ dfs(x+dx[i],y+dy[i],H,W,field,check); };} ;} } int main(){ ll H; cin >> H; ll W; cin >> W; vector<vector<bool>> field(H, vector<bool>(W, 0)); vector<vector<bool>> check(H, vector<bool>(W, 0)); for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ char k; cin>>k; if(k=='#'){field[i][j]=1;} ;} ;} ll ans=0; for(ll i=0;i<H;i++){ for(ll j=0;j<W;j++){ if(check[i][j]==0){ dfs(i,j,H,W,field,check);ans+=counterb*counterw; counterb=0;counterw=0; } ;} ;} cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int dy[4] = {-1,0,1,0}; int dx[4] = {0,1,0,-1}; char board[401][401]; int h,w; int visited[401][401]; long long int arr[160005][2]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); cin >> h >> w; for(int i=0;i<h;i++) { for(int j=0;j<w;j++) { cin >> board[i][j]; } } memset(visited,-1,sizeof(visited)); int cnt = 0; for(int i=0;i<h;i++) { for(int j=0;j<w;j++) { if(visited[i][j]==-1 && board[i][j]=='#') { queue <pair<int,int>> que; que.push(make_pair(i,j)); visited[i][j] = cnt; while(!que.empty()) { int y = que.front().first; int x = que.front().second; que.pop(); for(int k=0;k<4;k++) { int ny = y + dy[k]; int nx = x + dx[k]; if(ny < 0 || ny >= h || nx < 0 || nx >= w) { continue; } if(visited[ny][nx]==-1 && board[ny][nx]!=board[y][x]) { visited[ny][nx] = cnt; que.push(make_pair(ny,nx)); } } } cnt++; } } } long long int res = 0; for(int i=0;i<h;i++) { for(int j=0;j<w;j++) { if(visited[i][j]==-1) { continue; } if(board[i][j]=='#') { arr[visited[i][j]][0]++; } else { arr[visited[i][j]][1]++; } } } for(int i=0;i<cnt;i++) { res += (arr[i][0]*arr[i][1]); } cout << res << '\n'; return 0; }
1
#include <iostream> #include <algorithm> typedef long long ll; using namespace std; ll mod=998244353; const int SIZE=2010000; ll fac[SIZE], finv[SIZE], inv[SIZE], sum[260000]; void COMinit(ll m){ fac[0]=fac[1]=1; finv[0]=finv[1]=1; inv[1]=1; for(int i=2; i<SIZE; ++i){ fac[i]=(fac[i-1]*i)%m; inv[i]=m-(inv[m%i]*(m/i))%m; finv[i]=(finv[i-1]*inv[i])%m; } } ll COM(int n, int k, ll m){ if(n<k) return 0; if(n<0 || k<0) return 0; return (fac[n]*((finv[k]*finv[n-k])%m))%m; } int main(void){ int N, M; cin >> N >> M; COMinit(mod); ll ans=0; sum[0]=0; for(int i=0; i*2<=M; ++i){ sum[i+1]=(sum[i]+COM(N-2+i, i, mod))%mod; } for(int i=M%2; i<=min(N, M); i += 2){ ll num=COM((3*M-i)/2+N-1, N-1, mod); (num += mod-(sum[max((3*M-i)/2-M, 0)]*(N-i))%mod) %= mod; (num += mod-(sum[max((3*M-i)/2-M+1, 0)]*i)%mod) %= mod; (num *= COM(N, i, mod)) %= mod; (ans += num) %= mod; } cout << ans << endl; return 0; }
#include <cstdio> #include <algorithm> #define mod 998244353 #define maxn 200010 #define LL long long using namespace std; LL fact[maxn],inv[maxn],ans,t[maxn],p; int n,m,k,nm; LL quick_pow(LL a,LL b){//a^b LL ans=1; while(b){ if(b&1)ans=ans*a%mod; a=a*a%mod; b>>=1; } return ans%mod; } void init(){ int i; scanf("%d%d%d",&n,&m,&k); nm=n,nm=max(nm,m),fact[0]=1; for(i=1;i<=nm;i++)fact[i]=fact[i-1]*i%mod;//fact[i]代表i! inv[nm]=quick_pow(fact[nm],mod-2); for(i=nm-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;//inv[i]代表i!的乘法逆元 } LL C(LL a,LL b){//组合数计算 return fact[a]*inv[a-b]%mod*inv[b]%mod; } int main(){ int i; init(); ans=0,p=quick_pow(m-1,n-k-1); for(i=n-k;i<=n;i++){ ans=(ans+m*p%mod*C(n-1,i-1)%mod)%mod;//C(n-1,i-1)隔板法 p=p*(m-1)%mod; } printf("%lld\n",ans); return 0; }
0
#include <cstdio> #include <algorithm> #include <set> using namespace std; int n,m; int map[501][501]; main(){ fill((int*)map, (int*)(map+sizeof(map)/sizeof(*map)), 0); scanf("%d%d", &n, &m); if(n==0 && m == 0) return 0; int a,b; while(m--){ scanf("%d%d", &a, &b); map[a][b] = 1; map[b][a] = 1; } set<int> s; for(int i=0;i<501;i++){ if(map[1][i]){ s.insert(i); for(int j=0;j<501;j++){ if(map[i][j]){ s.insert(j); } } } } if(s.size()) printf("%d\n", (int)s.size()-1); else puts("0"); main(); }
#include<iostream> #include<queue> using namespace std; #define MAX 500 #define rep(i, n) for ( int i = 0; i < n; i++) bool G[MAX][MAX]; int n, m; int bfs(){ queue<int> q; int d[MAX]; rep(i, n) d[i] = (1<<21); q.push(0); d[0] = 0; int u; while(!q.empty()){ u = q.front(); q.pop(); rep(v, n){ if ( d[v] == (1<<21) && G[u][v] ){ d[v] = d[u] + 1; q.push(v); } } } int cnt = 0; rep(i, n) if ( d[i] == 1 || d[i] == 2 ) cnt++; return cnt; } main(){ int s, t; while(1){ cin >> n >> m; if ( n == 0 && m == 0 ) break; rep(i, n) rep(j, n) G[i][j] = false; rep(i, m){ cin >> s >> t; s--; t--; G[s][t] = G[t][s] = true; } cout << bfs() << endl; } }
1
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long #define rep(i,n) for(ll i=0;i<(n);i++) #define pll pair<ll,ll> #define pii pair<int,int> #define pq priority_queue #define pb push_back #define eb emplace_back #define fi first #define se second #define endl '\n' #define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define lb(c,x) distance(c.begin(),lower_bound(all(c),x)) #define ub(c,x) distance(c.begin(),upper_bound(all(c),x)) using namespace std; inline int topbit(unsigned long long x){ return x?63-__builtin_clzll(x):-1; } inline int popcount(unsigned long long x){ return __builtin_popcountll(x); } inline int parity(unsigned long long x){//popcount%2 return __builtin_parity(x); } template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;} template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} const ll INF=1e15; const ll mod=1e9+7; int main(){ ll n; cin >> n; vector<vector<ll>> a(n,vector<ll>(n-1)); rep(i,n)rep(j,n-1){ cin >> a[i][j]; a[i][j]--; } rep(i,n){ reverse(a[i].begin(),a[i].end()); } vector<pii> q; auto check=[&](ll i){ if(a[i].size()==0){ return ; } ll j=a[i].back(); if(a[j].back()!=i){ return ; } if(i>j) swap(i,j); pii P=make_pair(i,j); q.push_back(P); }; rep(i,n){ check(i); } ll day=0; while(q.size()){ day++; sort(q.begin(),q.end()); q.erase(unique(q.begin(),q.end()),q.end()); vector<pii> preQ; swap(preQ,q); for(pii x:preQ){ ll i=x.first; ll j=x.second; a[i].pop_back(); a[j].pop_back(); } for(pii x:preQ){ ll i=x.first; ll j=x.second; check(i); check(j); } } rep(i,n){ if(a[i].size()){ cout << -1 << endl; return 0; } } cout << day << endl; return 0; }
//Bismillahir Rahmanir Rahim #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pi; typedef vector<int> vi; typedef vector<pair<int, int>> vpi; #define pb push_back #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define ff first #define ss second #define mp make_pair #define lb lower_bound #define ub upper_bound #define tcase() int t; cin >> t; while(t--) const int MOD = 1e9 + 7; // 998244353; const int MX = 2e5 + 5; const ll INF = 1e18; const ld PI = acos((ld) -1); void setIO(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(sz(name)){ freopen((name+".in").c_str(), "r", stdin); freopen((name+".out").c_str(), "w", stdout); } } int main(){ setIO(); int n, m; cin >> n >> m; bool ok = true; int mpp[n + 1] = {0}; for(int i = 0; i < m; i++){ int x, y; cin >> x >> y; if(x > n){ ok = false; } if(mpp[x] != 0 && mpp[x] != y){ ok = false; } if(x == 1 && y == 0) ok = false; else mpp[x] = y; } if(n == 1 && mpp[1] == 0){ cout << 0; return 0; } if(m == 0 && n == 1){ cout << 0; return 0; } if(m == 0 && n > 1){ if(n == 2) cout << "10"; else cout << "100"; return 0; } if(!ok){ cout << -1; return 0; } if(mpp[1] == 0){ mpp[1] = 1; } for(int i = 1; i <= n; i++) cout << mpp[i]; }
0
#include <stdio.h> #include <vector> #include <queue> using namespace std; struct side{ int n; int m; int l; }; side sides[100000]; void mergesort(int l,int r){ if(l==r)return; side temp; if(l==r-1){ if(sides[l].l>sides[r].l){ temp=sides[l]; sides[l]=sides[r]; sides[r]=temp; } return; } int mid=(l+r)/2,now=0; side b[r-l+1]; mergesort(l,mid-1); mergesort(mid,r); for(int i=0;i<=r-l;i++){ if(sides[i+l-now].l<sides[mid+now].l){ b[i]=sides[i+l-now]; if(i+l-now==mid-1){ for(i++;i<=r-l;i++){ b[i]=sides[mid+now]; now++; } } } else{ b[i]=sides[mid+now]; now++; if(mid+now>r){ for(i++;i<=r-l;i++) b[i]=sides[i+l-now]; } } } for(int i=0;i<=r-l;i++) sides[i+l]=b[i]; } int main(){ int n,m,a,ans=0,c=1; bool tree[10000]; scanf("%d%d",&n,&m); if(m==0){ printf("0\n"); return 0; } tree[0]=true; for(int i=1;i<n;i++){ tree[i]=false; } for(int i=0;i<m;i++){ scanf("%d%d%d",&sides[i].n,&sides[i].m,&sides[i].l); } mergesort(0,m-1); while(c<n){ a=0; while(tree[sides[a].n]==tree[sides[a].m])a++; ans+=sides[a].l; tree[sides[a].n]=tree[sides[a].m]=true; c++; } printf("%d\n",ans); }
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <climits> #include <ctime> using namespace std; #define rep(i,a,n) for(int i=a; i<n; i++) #define repr(i,a,n) for(int i=a; i>=n; i--) #define pb(a) push_back(a) #define fr first #define sc second #define INF INT_MAX #define X real() #define Y imag() #define EPS (1e-10) #define EQ(a,b) (abs((a) - (b)) < EPS) #define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) ) #define LE(n, m) ((n) < (m) + EPS) #define GE(n, m) ((n) + EPS > (m)) typedef vector<int> VI; typedef vector<VI> MAT; typedef pair<int, int> pii; typedef long long int ll; typedef complex<double> P; typedef pair<P, P> L; typedef pair<P, double> C; int dy[]={0, 0, 1, -1}; int dx[]={1, -1, 0, 0}; int const MOD = 1000000007; // ????????¨???????????????????¨???????????§??????? struct Edge { int from, to, cost; Edge(int f, int s, int d) : from(f), to(s), cost(d) {} }; // 1??????????????????????????????????????±????????????????????????????????? vector // Edges????????????????????????????????????????????°?????????????????? typedef vector<Edge> Edges; // ???????????±??????????????? vector // Graph??????????????????????????°?????????????????§??? V ??§????????? typedef vector<Edges> Graph; // union-find??¨ int uf[100010]; int rank[100010]; // ????????? void init(int n) { rep(i,0,n) { uf[i] = i; rank[i] = 0; } } // find (??¨??????????±???????) int find(int x) { if(uf[x] == x) return x; else return uf[x] = find(uf[x]); } // x ??¨ y ????±?????????????????????? void unite(int x, int y) { x = find(x); y = find(y); if(x == y) return; if(rank[x] < rank[y]) uf[x] = y; else { uf[y] = x; if(rank[x] == rank[y]) rank[x]++; } } // x ??¨ y ???????????????????±??????????????????? bool same(int x, int y) { return find(x) == find(y); } bool comp(const Edge &e1, const Edge &e2) { return e1.cost < e2.cost; } int kruskal(Graph &G) { int V = G.size(); vector<Edge> es; rep(i,0,V) rep(j,0,G[i].size()) es.push_back(G[i][j]); int E = es.size(); sort(es.begin(), es.end(), comp); init(V); int res = 0; for(int i=0; i<E; i++) { Edge e = es[i]; if(!same(e.from, e.to)) { unite(e.from, e.to); res += e.cost; } } return res; } namespace std { bool operator<(const P a, const P b) { return a.X != b.X ? a.X < b.X : a.Y < b.Y; } } int main() { int V, E; cin >> V >> E; Graph G(V); int s, t, d; rep(i,0,E) { cin >> s >> t >> d; G[s].push_back(Edge(s,t,d)); G[t].push_back(Edge(t,s,d)); // ????????°??????????????§ } int ans = kruskal(G); cout << ans << endl; return 0; }
1
#include <cstdio> #include <cstring> #include <cctype> #include <algorithm> using namespace std; int getint() { char ch=getchar(); int f=1,x=0; while(!isdigit(ch)){if(ch=='-') f=-1; ch=getchar();} while(isdigit(ch)){x=x*10+ch-'0'; ch=getchar();} return f*x; } const int N=16; int n,m; int map[N][N]; int f[1<<15][N]; int slf[1<<15],ot[1<<15][N]; int tot; void init() { n=getint(),m=getint(); for(int i=1; i<=m; i++){ int u=getint(),v=getint(),w=getint(); map[u][v]=map[v][u]=w; tot+=w; } for(int s=1; s<(1<<n); s++){ for(int j=1; j<=n; j++){ if(s&(1<<(j-1))){ for(int k=j+1; k<=n; k++){ if(!(s&(1<<(k-1)))) continue; slf[s]+=map[j][k]; } }else{ for(int k=1; k<=n; k++){ if(!(s&(1<<(k-1)))) continue; ot[s][j]+=map[j][k]; } } } } } int main() { init(); memset(f,128,sizeof(f)); f[1][1]=0; for(int s=1; s<(1<<n); s+=2){ for(int i=1; i<=n; i++){ if(!(s&(1<<(i-1)))) continue; for(int t=s&(s-1); t; t=s&(t-1)){ if(!(t&1)) continue; f[s][i]=max(f[s][i],f[t][i]+slf[s^t]+ot[s^t][i]); } for(int j=1; j<=n; j++){ if(i==j || !(s&(1<<(j-1)))) continue; if(map[i][j]==0) continue; f[s][i]=max(f[s][i],f[s^(1<<(i-1))][j]+map[i][j]); } } } printf("%d\n",tot-f[(1<<n)-1][n]); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define REP(i,n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define debug(var) do{cout << #var << " : "; view(var);}while(0) template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;} template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;} using namespace std; template<class T> void view(T e) {cout << e << endl;} template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;} template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}} using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int,int>; const int inf = 1e9; const ll inf_l = 1e18; const int MAX = 1e5; const double eps = 1e-1; int main() { int n; cin >> n; vll x; rep(i,n) { double f; cin >> f; f *= inf; ll l = ll(f+eps); x.push_back(l); } vvint data(50,vint(50,0)); vector<P> ct; rep(i,n) { int ct_2 = 0, ct_5 = 0; while (x[i] % 2 == 0) { ct_2++; x[i] /= 2; } while (x[i] % 5 == 0) { ct_5++; x[i] /= 5; } data[ct_2][ct_5]++; ct.push_back(P(ct_2,ct_5)); } rep(i,50)rep(j,50) { if (i != 0) data[i][j] += data[i-1][j]; if (j != 0) data[i][j] += data[i][j-1]; if (i != 0 && j != 0) data[i][j] -= data[i-1][j-1]; } ll ans = 0; rep(i,n) { int ct_2 = max(0,18 - ct[i].first); int ct_5 = max(0,18 - ct[i].second); int tmp = data[49][49]; if (ct_5 != 0) tmp -= data[49][ct_5-1]; if (ct_2 != 0) tmp -= data[ct_2-1][49]; if (ct_5 != 0 && ct_2 != 0) tmp += data[ct_2-1][ct_5-1]; if (ct_2 <= ct[i].first && ct_5 <= ct[i].second) tmp--; ans += tmp; } ans /= 2; cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("unroll-loops") #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define int long long #define fr(i,a,b) for(int i = a ; i <= b ; ++i) #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) begin(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() #define pb push_back #define fst first #define snd second using namespace __gnu_pbds; using ordered_set = tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>; //find_by_order(k):returns iterator to kth element starting from 0 //order_of_key(k):returns count of elements strictly smaller than k typedef long long ll;typedef pair<int, int> pii; typedef vector<int> vi;typedef long double ld; template<class T> using min_heap = priority_queue<T,vector<T>,greater<T>>; template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);} template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));} template<class T> void re(T& x) { cin >> x; } template<typename T> void remdup(vector<T>& v) { sort(all(v)); v.erase(unique(all(v)), v.end()); } template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;} template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); } void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); } #ifdef np #include "/home/o_o/MyCodes/pr.h" #else #define trace(...) #endif #define MOD 1000000007 void solve(){ int cnt = 1 ; int n , x , t ; re(n,x,t); while(cnt*x<n) cnt++; cout << cnt * t << endl; } signed main() { unsyncIO(); int tt =1 ; // cin >> tt; rep(i,0,tt) solve(); #ifdef np cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
#include<bits/stdc++.h> // #include <ext/pb_ds/tree_policy.hpp> // #include <ext/pb_ds/assoc_container.hpp> #include<chrono> using namespace std; using namespace std::chrono; // using namespace __gnu_pbds; #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define fi first #define se second #define int long long #define pb push_back #define emp emplace_back #define vv(x) vector<x> #define mp(x,y) map<x,y> #define dq(x) deque<x> #define pql(x) priority_queue<x> #define pqs(x) priority_queue<x,vv(x),greater<x> > //#define M 1000000007 #define forf(i,a,b) for(int i=a;i<b;i++) #define it(x) x::iterator #define ll long long #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC)) #define vii vector<int> #define big 1e12 #define sm -2e18 #define mkr make_pair #define vpi vector<pair<int,int> > #define pii pair<int,int> #define rng 500005 #define sz(x) (int)x.size() #define rv(x) reverse(x.begin(),x.end()) #define out(x) cout<<x.fi<<" "<<x.se<<endl; #define MEM(x,val) memset(x,val,sizeof(x)) // typedef tree<pii, null_type, less<pii>, rb_tree_tag, // tree_order_statistics_node_update> odst; void pr_init() { #ifndef ONLINE_JUDGE freopen("gin.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif } void solve() { int n,x,t; cin >> n >> x >> t; int an = ceil((double)n/(double)x)*t ; cout<<an; } int32_t main() { pr_init(); fastio; auto start = high_resolution_clock::now(); solve(); auto stop = high_resolution_clock::now(); auto duration = duration_cast<microseconds>(stop - start); // cout << "Time taken by function: " // << duration.count() << " microseconds" << endl; return 0; }
1
/*{{{*/ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<iostream> #include<sstream> #include<set> #include<map> #include<queue> #include<bitset> #include<vector> #include<limits.h> #include<assert.h> #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define FOR(I, A, B) for (int I = (A); I <= (B); ++I) #define FORS(I, S) for (int I = 0; S[I]; ++I) #define RS(X) scanf("%s", (X)) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++) #define MP make_pair #define PB push_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PII> VPII; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template<class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(LL &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const LL &x) { printf("%lld", x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);} template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } #ifdef HOME #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");} #else #define DEBUG(...) #endif int MOD = 1e9+7; void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;} /*}}}*/ const int SIZE = 1e6+10; int N,X; LL b[SIZE],l[SIZE],u[SIZE]; bool used[SIZE]; int main(){ R(N,X); LL need=0; priority_queue<PLL>h0,h1,h2; REP(i,N){ R(b[i],l[i],u[i]); need+=b[i]*l[i]; h0.push({l[i]*b[i]+u[i]*(X-b[i]),i}); } LL an=0; while(need>=h0.top().F){ an+=X; used[h0.top().S]=1; need-=h0.top().F; h0.pop(); } if(need<=0){ W(an); return 0; } int add_id=h0.top().S; LL add_v=l[add_id]*b[add_id]+u[add_id]*(X-b[add_id]); LL mi=1e18; REP(i,N){ if(used[i]){ LL need2=need-add_v+l[i]*b[i]+u[i]*(X-b[i]); if(l[i]*b[i]>=need2){ mi=min(mi,(need2+l[i]-1)/l[i]); } else{ mi=min(mi,(need2-l[i]*b[i]+u[i]-1)/u[i]+b[i]); } } else{ if(l[i]*b[i]+u[i]*(X-b[i])<need)continue; if(l[i]*b[i]>=need){ mi=min(mi,(need+l[i]-1)/l[i]); } else{ mi=min(mi,(need-l[i]*b[i]+u[i]-1)/u[i]+b[i]); } } } an+=mi; W(an); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=100005; struct sj{ int a,l,r;ll x; inline sj(){} inline sj(int a,int l,int r,ll x):a(a),l(l),r(r),x(x){} inline bool operator<(const sj &t)const{return x>t.x;} }d[N]; inline void cmax(ll &a,ll b){if(a<b)a=b;} inline ll Y(int i,ll k){ ll a=d[i].a; if(k<=a)return k*d[i].l; else return k*d[i].r+a*(d[i].l-d[i].r); } int main(){ int n,i,a,l,r,x; ll L=0ll,R,M,S,g=0ll,t1,t2; scanf("%d%d",&n,&x);R=(S=(t1=((ll)x))*n)-1ll; for(i=1;i<=n;++i){ scanf("%d%d%d",&a,&l,&r);t2=a; d[i]=sj(a,l,r,t1*r+t2*(l-r)); g+=l*t2; } sort(d+1,d+n+1); while(L<=R){ M=(L+R)>>1; l=M/x; r=M%x; // printf("M=%lld l=%d r=%d",M,l,r); // for(i=1;i<=n;++i)printf(" (%d,%d)",d[i].x,Y(i,r)); // printf("\n"); t1=-1000000000000ll;t2=0ll; for(i=1;i<=l;++i){ t2+=d[i].x; cmax(t1,Y(i,r)-d[i].x); } t1+=d[i].x; for( ;i<=n;++i)cmax(t1,Y(i,r)); if(t1+t2>=g)R=(S=M)-1ll;else L=M+1ll; } printf("%lld",S); return 0; }
1
#include <iostream> #include <stack> using namespace std; long long N; void input() { cin >> N; } void solve() { long long num = 0; long long t26[13]; long long n26 = 1; for (int i = 0; i < 13; ++i) { t26[i] = n26; n26 *= 26; } long long tborder[13]; tborder[0] = 0; for (int i = 1; i < 13; ++i) tborder[i] = tborder[i-1] + t26[i]; for (int i = 0; i < 13; ++i){ // cout << tborder[i] << " "; if (tborder[i] < N) continue; N -= tborder[i-1] + 1; stack<char> stk; while (i != 0){ stk.push('a' + N % 26); N /= 26; --i; } while (!stk.empty()){ cout << stk.top(); stk.pop(); } cout << endl; break; } } int main() { cin.tie(); ios::sync_with_stdio(false); // int ti = clock(); input(); solve(); // printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) int main(){ long long N,a; int Z=26; //26^nで次のアルファベットの桁に移る string ans =""; cin >> N ; while(N>0){ N--; a=N%Z; N/=Z; ans+='a'+a; //aから割ったあまりの分文字コードを移動する } reverse(ans.begin(),ans.end()); cout << ans << endl; }
1
#include <bits/stdc++.h> using namespace std; int main(){ int n, l; cin >> n >> l; int ans = 0; for(int i=l; i<l+n; ++i){ if(l+n-1 < 0 && i == l+n-1) continue; if(l > 0 && i == l) continue; ans += i; } cout << ans << endl; }
// Author : Harshdeep Sharma , IIT Indore #pragma GCC optimize("O2") #include <bits/stdc++.h> using namespace std; // #define MOD 998244353 #define ll long long const double PI = atan(1.0) * 4; // const ll INF = (int)1e9 ; const int di[4] = { -1, 0, 1, 0} ; const int dj[4] = {0, -1, 0, 1} ; const ll INF = (ll)2e18 + 50; const int maximum = numeric_limits<int>::min(); const int minimum = numeric_limits<int>::max(); // function to calculate any numbered power of some number without modulo ll power(ll a , ll e) { ll res = 1LL ; while (e > 0) { if (e % 2 == 1) res = res * a; a = a * a ; e /= 2 ; } return res ; } // function to check whether a bracketed sequence is balanced or not bool isBalanced(const string &exp) { // Initialising Variables bool flag = true; int count = 0; // Traversing the Expression for (int i = 0; i < exp.length(); i++) { if (exp[i] == '(') { count++; } else { count--; } if (count < 0) { flag = false; break; } } if (count != 0) { flag = false; } return flag; } // function to sort by second in a set of pairs bool sortbysec(const pair<pair<int, int>, int> &a, const pair<pair<int, int>, int> &b) { return (a.second < b.second); } void uniformly_distribute_k_numbers_in_a_square_grid(int n , int k ) { int p = 0 , q = 0 ; vector<vector<int>> a(n, vector<int>(n)) ; for (int i = 1 ; i <= k ; ++i ) { a[p][q] = 1 ; p = p + 1 ; q = (q + 1) % n ; if (p == n) { p = 0 ; q = (q + 1) % n ; } } } ll f(ll n) { ll res ; if (n % 2 != 0) { ll pairs = (n + 1) / 2 ; if (pairs % 2 == 0) { res = 0 ; } else { res = 1 ; } } else { // cout << "i\n"; ll pairs = n / 2 ; if (pairs % 2 == 0) { res = 0 ; } else { res = 1 ; } res ^= n ; } return res ; } // main funtion int main() { ios::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // int t ; // cin >> t ; // while (t--) { int n , l ; cin >> n >> l ; int total = 0 ; int mn = 500 ; for (int i = 0 ; i < n ; i++) { total += (l + i) ; mn = min(mn , abs(l + i)) ; } // cout << total << " " << mn << "\n"; if (total > 0) cout << total - mn << "\n"; else cout << total + mn << "\n"; // } return 0 ; }
1
#include <bits/stdc++.h> #include <vector> #include <iostream> #include<algorithm> #include<string> #include <map> #include <queue> #include <stack> #include<set> #define DIV 1000000007 #define TE 2e5 using namespace std; using ll = long long; using ldb = long double; int main() { int N, M; cin >> N >> M; vector<vector<int>> A(N, vector<int>(M)); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { cin >> A[i][j]; A[i][j]--; } } vector<bool> sp(M, true); int ans = 1e8; for (int k = 0; k < M - 1; k++) { vector<int> num(M); int temp = 0, id = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { int a = A[i][j]; if (sp[a]) { num[a]++; if (temp < num[a]) temp = num[a], id = a; break; } } } //cout << "temp=" << temp << endl; sp[id] = false; if (temp == 0)continue; ans = min(ans, temp); } cout << (M == 1 ? N : ans) << endl; }
#include<stdio.h> #include<math.h> #include<algorithm> #include<cctype> #include<string.h> #include <stdlib.h> #define PI 3.1415926 void swap(int* x, int* y) { int a = *x; int b = *y; *x = b; *y = a; } int factorial(int n); int sum(int n, int*); int ave(int n, int*); int min(int n, int*), min(int n, int m); int max(int n, int*), max(int n, int m); int main() { int N, M, A[2000], B[2000]; int V[2000] = { 0 }; int max = 0; int ans; scanf("%d %d", &N, &M); for (int i = 1; i <= N; i++) { scanf("%d", &A[i]); } for (int i = 1; i <= M; i++) { scanf("%d", &B[i]); } for (int i = 1; i <= M; i++) { for (int j = 1; i <= N; j++) { if (A[j] <= B[i]) { V[j]++; break; } } } for (int i = 1; i <= N; i++) { //printf("%d\n", V[i]); if (max < V[i]) { max = V[i]; ans = i; } } printf("%d\n", ans); return 0; } int factorial(int n) { if (n > 0) { return n * factorial(n - 1); } else { return 1; } } int sum(int n, int *all) { int total = 0; for (int i = 0; i < n; ++i) { total += all[i]; } return total; } int ave(int n, int *all) { int total = 0; for (int i = 0; i<n; ++i) { total += all[i]; } return total / n; } int min(int n, int *all) { int min = all[0]; for (int i = 1; i < n; ++i) { if (all[0] > all[i]) { min = all[i]; } } return min; } int max(int n, int *all) { int max = all[0]; for (int i = 1; i<n; ++i) { if (all[0]<all[i]) { max = all[i]; } } return max; } int max(int n, int m) { if (n >= m) { return n; } else { return m; } } int min(int n, int m) { if (n >= m) { return m; } else { return n; } }
0
#include<cstdio> #include<iostream> #include<map> #include<set> #include<vector> #include<cstring> #include<cassert> #include<sstream> #include<cmath> #include<algorithm> #include<queue> #include<limits> #include<ctime> #include<stack> #include<bits/stdc++.h> #include<string> #include<stdlib.h> #include<stdio.h> typedef long long ll; using namespace std; const ll x=1000000007; int mod(ll a){ return a%x; } int main(){ ll n; cin>>n; ll a[n],ans=0,mins=n+1; for(int i=0;i<n;i++){ cin>>a[i]; if(a[i]<mins){ ans+=mins-a[i]-1; mins=a[i]; } } cout<<n-ans; }
#include<bits/stdc++.h> using namespace std; int main() { long long int n,a,i,k,x; cin >> n; k=0;x=n; for(i=0;i<n;i++) { cin >> a; if(a<=x) { k++; x=a; } } cout << k << endl; }
1
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using ll = long long; int main(void){ int N,K; cin>>N>>K; int ans=0; if(N%K!=0){ ans=1; } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N,K; cin >> N >> K; if(N < K){ cout << 1 << endl; return 0; } if(N%K == 0){ cout << 0 << endl; return 0; } cout << N%K+1 - N%K << endl; }
1
// God put a smile upon your face <3 #include <bits/stdc++.h> #define slld(longvalue) scanf("%lld", &longvalue) #define ll long long #define ull unsigned long long #define pll pair < long long, long long > #define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0) #define pb push_back #define bug printf("BUG\n") #define mxlld LLONG_MAX #define mnlld -LLONG_MAX #define mxd 2e8 #define mnd -2e8 #define pi 3.14159265359 using namespace std; bool check(ll n, ll pos) { return n & (1LL << pos); } ll Set(ll n, ll pos) { return n = n | (1LL << pos); } int main() { ll i, j, k, l, m, n, o, r, q; ll testcase; ll input, flag, tag, ans; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); double rad; while(cin >> rad) { cout << setprecision(10) << fixed << 2.0 * acos(-1.0) * rad << "\n"; } }
#include<bits/stdc++.h> typedef long long ll; //forループ //引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか //Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) // // #define int long long using namespace std; int ctoi(char c) { switch (c) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default: return 0; } } ll a,b,c,s,t,i,j,k,x,y,z; ll A,B,C,S,T,X,Y,Z; ll count; long double pi=3.14159; signed main(){ cin>>a; cout<<2*a*pi; return 0; }
1
#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(); }
#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; }
0
#include <bits/stdc++.h> #include <cassert> typedef long long int ll; using namespace std; #define DEBUG 0 #if DEBUG #define DLOG(...) fprintf(stderr, __VA_ARGS__) #else #define DLOG(...) #endif void debug(auto f) { #if DEBUG f(); #endif } ll mPrime = int(1e9) + 7; ll bN, bX; vector<ll> bS; vector<ll> facts; vector<ll> invFacts; vector<int> tbl; vector<int> low; // low[y] == #{ i | s[i] <= y } ll mAdd(ll x, ll y) { ll z = x + y; if (z < mPrime) return z; else return (z - mPrime); } ll mSub(ll x, ll y) { ll z = x - y; if (z >= 0) return z; else return (z + mPrime); } ll mMul(ll x, ll y) { return (x * y) % mPrime; } ll eGCD(ll a, ll b, ll& s, ll& t) { if (a == 0) { s = 0; t = 1; return b; } ll u; ll g = eGCD(b % a, a, t, u); s = u - (b / a) * t; return g; } ll mInv(ll x) { ll s, t; eGCD(x, mPrime, s, t); return s < 0 ? s + mPrime : s; } ll tight(ll); ll loose(ll y, ll len) { ll result = mMul(tight(y), mMul(facts.at(len), invFacts.at(low.at(y)))); DLOG("loose(%lld, %lld) = %lld\n", y, len, result); return result; } ll tight(ll y) { if (tbl.at(y) >= 0) return tbl.at(y); ll len = low.at(y); if (len == 0) return y; ll result = 0; for (ll i = 0; i < len; i++) { ll z = y % bS.at(i); result = mAdd(result, loose(z, len-1)); } tbl.at(y) = result; DLOG("tight(%lld) = %lld\n", y, result); return result; } int main() { cin >> bN >> bX; bS.resize(bN); for (ll i = 0; i < bN; i++) { cin >> bS.at(i); } facts.resize(bN+1); invFacts.resize(bN+1); facts.at(0) = invFacts.at(0) = 1; for (ll i = 1; i <= bN; i++) { facts.at(i) = mMul(i, facts.at(i-1)); invFacts.at(i) = mInv(facts.at(i)); } sort(bS.begin(), bS.end()); low.resize(bX+1); ll idx = 0; for (ll i = 0; i < bX+1; i++) { if (idx < (ll) bS.size() && bS.at(idx) == i) idx++; low.at(i) = idx; } tbl.resize(bX+1, -1); ll ans = loose(bX, bS.size()); cout << ans << endl; return 0; }
#include<cstdio> #include<iostream> #include<cmath> #include<cstring> #include<algorithm> #include<functional> #include<set> #include<map> using namespace std; #define rep(i,l,r) for(register int i=(l);i<=(r);++i) #define repdo(i,l,r) for(register int i=(l);i>=(r);--i) #define il inline typedef double db; typedef long long ll; //--------------------------------------- namespace ubospica{ const int nsz=205,vsz=1e5+50; const ll nmod=1e9+7; int n; ll x,li[nsz]; ll ans,dp[vsz]; ll inv[vsz]{0,1}; void init(int bnd){rep(i,2,bnd)inv[i]=inv[nmod%i]*((ll)nmod-nmod/i)%nmod;}//be aware of overflow! void add(ll &a,ll b){a=(a+b)%nmod;} void mul(ll &a,ll b){a=a*b%nmod;} int main(){ ios::sync_with_stdio(0),cin.tie(0); cin>>n>>x; rep(i,1,n)cin>>li[i]; sort(li+1,li+n+1,greater<int>()); init(1e5+5); ll tmp; dp[x]=1; rep(i,1,n){ rep(j,0,x){ tmp=dp[j],dp[j]=0; add(dp[j%li[i]],tmp*inv[n-i+1]); add(dp[j],tmp*(n-i)%nmod*inv[n-i+1]); } } ans=0; rep(i,0,x) add(ans,i*dp[i]); rep(i,1,n)mul(ans,i); cout<<ans<<'\n'; return 0; } } int main(){return ubospica::main();} // freopen(".in","r",stdin); // freopen(".out","w",stdout);
1
#include <iostream> #include <cstring> using namespace std; int main() { int n, i, j, k, c, x; char s[1001], r[1001], t[8] = "Hoshino"; cin >> n; cin.ignore(1024, '\n'); for (i = 0; i < n; i++) { cin.getline(s, sizeof(s)); c = 0; for (j = 0; j < strlen(s); j++) { r[c] = s[j]; c++; if (s[j] == 'H') { for (k = j+1, x = 0; k < j+7; k++, c++) { if (s[k] == t[k-j]) { if (k == j+6) r[c] = 'a'; else r[c] = t[k-j]; x++; } else { r[c] = s[k]; break; } } j+=x; } } r[strlen(s)] = '\0'; cout << r << endl; } }
#include <iostream> #include <cstring> #include <string> using namespace std; int main(){ string s; int n; int c_pos; cin>>n; cin.ignore(); while(n--){ getline(cin,s); while((c_pos=s.find("Hoshino"))!=string::npos){ s.replace(c_pos,7,"Hoshina"); } cout<<s<<endl; } }
1
#include <bits/stdc++.h> using namespace std; int main(){ int N, X, T; cin >> N >> X >> T; int minute = 0; while(N > 0){ minute += T; N -= X; } cout << minute << endl; }
#include <bits/stdc++.h> using i16 = std::int16_t; using i32 = std::int32_t; using i64 = std::int64_t; using usize = std::size_t; template<typename T> using Vector = std::vector<T>; using String = std::string; template<typename T> using UniquePointer = std::unique_ptr<T>; using namespace std; #define rep(i, max) for(usize i = 0; i < max; ++i) #define loop while(true) UniquePointer<String> readLine() { UniquePointer<String> line(new String()); getline(cin, *line); return line; } template<typename T> UniquePointer<Vector<T>> readVector(usize num) { UniquePointer<Vector<T>> list(new Vector<T>(num)); rep(i, num) { cin >> (*list)[i]; } return list; } template<typename T> void writeLine(T arg) { cout << arg << endl; } template<typename T> void write(T arg) { cout << arg << std::flush; } void program(); int main() { ios::sync_with_stdio(false); program(); } void program() { i32 n, x, t; cin >> n; cin >> x; cin >> t; readLine(); writeLine((i32)(ceil((double)n / x) * t)); }
1
#include<bits/stdc++.h> #define fi first #define se second #define lc (x<<1) #define rc (x<<1|1) #define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++) #define mk make_pair #define pi pair<int,int> #define pb push_back #define IT iterator #define SZ(a) ((int)a.size()) #define all(a) a.begin(),a.end() using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; const int N=4e5+10,size=1<<20,mod=998244353; const ll inf=1e18; template<class o> void qr(o &x) { char c=gc; x=0; int f=1; while(!isdigit(c)){if(c=='-')f=-1; c=gc;} while(isdigit(c)) x=x*10+c-'0',c=gc; x*=f; } template<class o> void qw(o x) { if(x/10) qw(x/10); putchar(x%10+'0'); } template<class o> void pr1(o x) { if(x<0)x=-x,putchar('-'); qw(x); putchar(' '); } template<class o> void pr2(o x) { if(x<0)x=-x,putchar('-'); qw(x); puts(""); } int n,dic[150],f[N*2][2],g[N*2][2]; ll ans=inf; vector<pi> x[N],y[N]; int main() { qr(n); dic['U']=0; dic['D']=1; dic['R']=2; dic['L']=3; for(int i=1;i<=n;i++) { int a,b,c;qr(a); qr(b); char str[6]; scanf("%s",str); a++; b++; c=dic[str[0]]; x[a].pb(mk(b,c)); y[b].pb(mk(a,c)); } for(int i=1;i<N;i++) { sort(all(x[i])); sort(all(y[i])); ll a,b; a=b=inf; for(auto j:x[i]) { if(j.se==0) a=j.fi; else if(j.se==1) b=j.fi; if(a<b) ans=min(ans,(b-a)*5); } a=b=inf; for(auto j:y[i]) { if(j.se==2) a=j.fi; else if(j.se==3) b=j.fi; if(a<b) ans=min(ans,(b-a)*5); } } for(int i=1;i<N;i++) for(auto j:x[i]) { int t=j.fi; if(j.se==2) { f[j.fi-i+N][0]=i; f[j.fi+i][1]=i; } else if(j.se==3) { int k=g[j.fi+i][1]; if(k) ans=min(ans,(i-k)*10LL); k=g[j.fi-i+N][0]; if(k) ans=min(ans,(i-k)*10LL); } else if(j.se==1) { int k=f[j.fi-i+N][0]; if(k) ans=min(ans,(i-k)*10LL); g[j.fi+i][1]=i; } else if(j.se==0) { int k=f[j.fi+i][1]; if(k) ans=min(ans,(i-k)*10LL); g[j.fi-i+N][0]=i; } } if(ans>inf/2) puts("SAFE"); else pr2(ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) 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; } #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif ll n, m; struct numinfo { int digit; int match; int min_match; int n; }; vector<numinfo> nums; bool dfs( int i, int remain_match, int remain_keta ){ if ( i == SZ(nums) ){ eprintf( "remain=%d %d ", remain_match, remain_keta ); rep(k,SZ(nums)){ eprintf( "%d ", (int)nums[k].n ); } eprintf( "\n" ); if ( remain_match == 0 && remain_keta <= 0 ) return true; return false; } for ( int k = remain_match/nums[i].match; k >= 0; k-- ){ nums[i].n = k; int creatable_keta = (remain_match-k*nums[i].match)/nums[i].min_match; if ( remain_keta-k-creatable_keta > 0 ) continue; if ( dfs( i+1, remain_match-k*nums[i].match, remain_keta-k ) ) return true; } return false; } int main(){ cin >> n >> m; vector<int> a(m); rep(i,m){ cin >> a[i]; } sort(a.rbegin(),a.rend()); int digit_to_match[] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 }; set<int> s; rep(i,m){ int match = digit_to_match[a[i]]; if ( s.count(match) == 0 ) nums.push_back({a[i],match,100,0}); s.insert(match); } m = nums.size(); int min_match = 100; for ( int i = nums.size()-1; i >= 0; i-- ){ nums[i].min_match = min_match; chmin(min_match, nums[i].match); eprintf( "digit,=%d match=%d min_match=%d\n", nums[i].digit, nums[i].match, nums[i].min_match ); } for ( int keta = n / min_match; keta > 0; keta-- ){ eprintf( "\n\nketa=%d\n", keta ); if ( dfs( 0, n, keta ) ){ sort(nums.begin(), nums.end(), [](numinfo &l, numinfo &r){ return l.digit>r.digit; }); rep(i,m){ rep(j,nums[i].n){ cout << nums[i].digit; } } cout << endl; return 0; } } return 0; }
0
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> #include<stack> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-11; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; typedef pair<ld, ld> LDP; struct rect { ll hei; int pos; }; ll getmaxrect(int size, ll buffer[]) { stack<rect> s; ll res = 0; buffer[size] = 0; for (int i = 0; i <= size; i++) { rect rec; rec.hei = buffer[i]; rec.pos = i; if (s.empty()) { s.push(rec); } else { if (s.top().hei < rec.hei) { s.push(rec); } else if (s.top().hei > rec.hei) { int tag = i; while (!s.empty() && s.top().hei >= rec.hei) { rect pre = s.top(); s.pop(); ll area = (pre.hei+1)*(i - pre.pos+1); res = max(res, area); tag = pre.pos; } rec.pos = tag; s.push(rec); } } } return res; } int p[2000][2000]; char t[2000][2000]; ll hi[2000][2000]; int main() { ll buffer[2001]; int h, w; cin >> h >> w; rep(i, h) { string s; cin >> s; rep(j, w) { t[i][j] = s[j]; } } rep(i, h - 1) { rep(j, w - 1) { int cnt = 0; rep(k, 2) { rep(l, 2) { if (t[i + k][j + l] == '#')cnt++; } } if (cnt % 2)p[i][j] = 1; } } rep(j, w - 1) { hi[0][j] = 1; if (p[0][j])hi[0][j] = 0; rep1(i, h - 2) { if (p[i][j])hi[i][j] = 0; else hi[i][j] = hi[i - 1][j] + 1; } } ll out = max(h,w); rep(i, h - 1) { rep(j, w - 1) { buffer[j] = hi[i][j]; } out = max(out, getmaxrect(w - 1, buffer)); } cout << out << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; int q; cin >> q; vector<int> v(q); rep(i, q) cin >> v[i]; vector<int> dsum(n+1, 0); rep(i, n) dsum[i+1] += dsum[i] + (s[i] == 'D' ? 1 : 0); for(int k : v){ ll ans = 0; deque<int> q; ll t = 0; for(int i = 0; i < n; i++){ if(i-k >= 0 && s[i-k] == 'D'){ t -= q.size(); } if(q.size() > 0 && q.back() < i - (k - 2)){ q.pop_back(); } if(s[i] == 'M'){ q.push_front(i); t += dsum[i] - dsum[max(i-(k-1), 0)]; } if(s[i] == 'C') ans += t; } cout << ans << endl; } }
0
#include <iostream> #include <algorithm> #include <vector> #include <queue> using namespace std; vector<int> to[600];//[]の中の人がどこに行けるか bool res[600] = {}; void bfs() { queue<int> q; for(int i=0;i<to[1].size();++i){ q.push(to[1][i]); } for(int i=0;i<2;++i) { int size = q.size(); for(int i=0;i<size;++i) { int now = q.front();q.pop(); if(res[now]) continue; res[now] = true; for(int i=0;i<to[now].size();++i){ q.push(to[now][i]); } } } } int main(void) { while(1) { for(int i=0;i<501;++i){ to[i].clear(); res[i] = false; } int n; int m; cin >> n >> m; if(n == 0 || m == 0) return 0; for(int i=0;i<m;++i){ int a,b; cin >> a >> b; to[a].push_back(b); to[b].push_back(a); } bfs(); int count = 0; for(int i=2;i<501;++i){ if(res[i]) ++count; } cout << count << endl; } return 0; }
#include <iostream> #include <vector> #include <set> #include <cstring> // require memset //#include <fstream> // require freopen using namespace std; const int N = 501; bool t[N][N]; int main() { // cut here before submit // freopen ("testcase.party", "r", stdin ); int n, m; while (cin >> n >> m && n && m ){ int i,j; memset (t, false, sizeof (t ) ); for (i = 0; i < m; ++i){ int from, to; cin >> from >> to; t[from][to] = true; t[to][from] = true; } // end for set <int> res; for (i = 2; i <= n; ++i ){ if (t[1][i] ){ res.insert (i ); for (j = 2; j <= n; ++j ){ if (t[i][j]){ res.insert (j ); } // end if } // end for } // end if } // end for if (!res.empty() ){ cout << res.size() << endl; }else{ cout << '0' << endl; } // end if } // end loop return 0; }
1
#include <bits/stdc++.h> using ll = long long; using namespace std; #define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++) #define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rreps(i, n) for (int i = ((int)(n)); i > 0; i--) #define repi(i, x) \ for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++) #define all(x) (x).begin(), (x).end() #define F first #define S second #define mp make_pair #define pb push_back #define solve(a) ((a) ? "Yes" : "No") typedef vector<int> Vi; typedef vector<Vi> VVi; typedef pair<int, int> Pi; typedef vector<Pi> VPi; typedef vector<long long> V; typedef vector<V> VV; typedef pair<long long, long long> P; typedef vector<P> VP; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long INFLL = 1LL << 60; const int INF = 1 << 30; const double PI = acos(-1); int main() { int n; int ans = 0; cin >> n; int v; pair<Pi, Pi> as = mp(mp(0, 0), mp(0, 0)); pair<Pi, Pi> bs = mp(mp(0, 0), mp(0, 0)); pair<map<int, int>, map<int, int>> dis; rep(i, n) { cin >> v; if (i % 2) { dis.F[v]++; } else { dis.S[v]++; } } repi(itr, dis.F) { if (itr->S > as.F.S) { as.S = as.F; as.F = *itr; } else if (itr->S > as.S.S) { as.S = *itr; } } repi(itr, dis.S) { if (itr->S > bs.F.S) { bs.S = bs.F; bs.F = *itr; } else if (itr->S > bs.S.S) { bs.S = *itr; } } if (as.F.F != bs.F.F) { ans = n - as.F.S - bs.F.S; } else { ans = n - max(as.F.S + bs.S.S, as.S.S + bs.F.S); } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define Would #define you #define please int D; ll kotae = 0; void keisan(ll A, int B, int C, vector<int> V) { if (B < C / 2) { ll k1 = 1, k2 = 1; rep(i, C - B - 1) k1 *= 10; rep(i, B) k2 *= 10; ll k = k1 - k2; if (A >= 0) { if (abs(A / k) < 10) { V.pb(A / k); keisan(A % k, B + 1, C, V); V.pop_back(); } if (abs(A / k + 1) < 10) { V.pb(A / k + 1); keisan(A % k - k, B + 1, C, V); } } else { if (abs(A / k) < 10) { V.pb(A / k); keisan(A % k, B + 1, C, V); V.pop_back(); } if (abs(A / k - 1) < 10) { V.pb(A / k - 1); keisan(A % k + k, B + 1, C, V); } } } else { if (A == 0) { ll kari = 1; rep(j, V.size()) { int kari2 = 0; if (j == 0) { rep1(k, 9) { if (k + V[j] < 10) kari2++; } } else { rep(k, 10) { if (k + V[j] >= 0 && k + V[j] < 10) kari2++; } } kari *= kari2; } if (C % 2) kari *= 10; kotae += kari; } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> D; for (int i = 19; i >= 2; i--) { vector<int> V; keisan(D, 0, i, V); } co(kotae); Would you please return 0; }
0
#include<bits/stdc++.h> using namespace std; int main(){ int n; while(cin>>n,n){ vector<int> k(n); string s; for(int i=0;i<n;++i) cin>>k[i]; cin>>s; int key=0; for(int i=0;i!=s.size();++i){ for(int j=0;j<k[key];++j){ if(s[i]=='a') s[i]='Z'; else if(s[i]=='A') s[i]='z'; else s[i]--; } if(key==n-1) key=0; else key++; } cout<<s<<endl; } }
#include <iostream> #include <stdio.h> using namespace std; int main() { int n,p;//~50 int stone,player[50]={}; int winner; int i; scanf("%d%d",&n,&p); while(1){ for(i=0;i<50;i++){ player[i]=0; } stone=p; for(i=0;;i++){ if(stone==0){ stone=player[i%n]; player[i%n]=0; } else{ stone-=1; player[i%n]+=1; } if((stone==0)&&(player[i%n]==p)){ winner=i%n; break; } } printf("%d\n",winner); scanf("%d%d",&n,&p); if((n==0)&&(p==0)){break;} } return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < ll(n); i++) int main() { int k; vector<int> ab{0, 0}; cin >> ab[0] >> ab[1] >> k; int i = 0; while (k--) { if (ab[i] & 1) { ab[i]--; } ab[i] >>= 1; ab[i ^ 1] += ab[i]; i ^= 1; } cout << ab[0] << " " << ab[1] << endl; }
#include <bits/stdc++.h> using namespace std; char s[100]; int main(){ int a, b, k; scanf("%d%d%d", &a, &b, &k); for(int i=0;i<k;i++){ if(i%2 == 0){ if(a%2 != 0) a--; b += a/2; a/=2; } else{ if(b%2 != 0) b--; a += b/2; b/=2; } } printf("%d %d\n", a, b); }
1
#include<bits/stdc++.h> using namespace std; int n,m,a[110]; int main() { scanf("%d%d",&n,&m); if (m==1) { if (n==1) { printf("1\n1\n1\n"); } else { printf("%d\n2\n1 %d\n",n,n-1); } return 0; } int t1=0,t2=0; for (int i=1;i<=m;i++) { scanf("%d",&a[i]); if (a[i]&1) { if (!t1) { t1=i; } else if (!t2) { t2=i; } else { puts("Impossible"); return 0; } } } if (t1) { swap(a[1],a[t1]); } if (t2) { swap(a[m],a[t2]); } for (int i=1;i<=m;i++) { printf("%d ",a[i]); } puts(""); if (a[1]==1) { printf("%d\n",m-1); } else { printf("%d\n%d ",m,a[1]-1); } for (int i=2;i<m;i++) { printf("%d ",a[i]); } printf("%d\n",a[m]+1); return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <math.h> using namespace std; const int MAXN = 1e5 + 10; int N, M; int A[MAXN]; int cnt; int main() { register int i, j = 0, k = 0; scanf("%d%d", &N, &M); for(i = 1; i <= M; ++i) scanf("%d", A + i), A[i] & 1 ? (++cnt, !j ? j = i : k = i) : 0; if(cnt > 2) return puts("Impossible"), 0; if(M == 1) { printf("%d\n", A[1]); printf("%d\n", A[1] == 1 ? 1 : 2); A[1] == 1 ? printf("%d\n", A[1]) : printf("1 %d\n", A[1] - 1); return 0; } if(j) swap(A[1], A[j]); if(k) swap(A[k], A[M]); for(i = 1; i <= M; ++i) printf("%d%c", A[i], " \n"[i == M]); ++A[1], --A[M]; if(A[M] == 0) --M; printf("%d\n", M); for(i = 1; i <= M; ++i) printf("%d%c", A[i], " \n"[i == M]); return 0; }
1
#include <iostream> #include <string> #include <vector> #include <cmath> #include <algorithm> #include <cstdlib> #include <ctime> #include <cstdio> #include <functional> #include <set> #include <sstream> #include <map> #include <queue> using namespace std; const double eps=1e-10; const int dy[]={-1,-1,0,1,1, 1, 0,-1}; const int dx[]={ 0, 1,1,1,0,-1,-1,-1}; class rect{ public: int h,w,d2; rect(int _h,int _w){h=_h; w=_w; d2=h*h+w*w;} bool operator<(const rect& r) const{ return d2<r.d2 || d2==r.d2 && h<r.h; } }; int main() { vector< rect > vr; for(int h=1;h<=150;h++){ for(int w=h+1;w<=150;w++) vr.push_back(rect(h,w)); } sort(vr.begin(),vr.end()); int h,w; while(cin>>h>>w,h){ rect r(h,w); for(int i=0;i<vr.size();i++){ if(r<vr[i]){ cout<<vr[i].h<<" "<<vr[i].w<<endl; break; } } } return 0; }
#include <bits/stdc++.h> using namespace std; #define PI 4*atan(1) #define INF 1e8 int dx[4] = {1,0,-1,0}; int dy[4] = {0,1,0,-1}; int main(){ int m, n_min, n_max; while(cin >> m >> n_min >> n_max, m||n_min||n_max){ vector<int> P(m); for(int i = 0; i < m; i++){ cin >> P[i]; } int diff = 0, ans; for(int i = n_min; i <= n_max; i++){ if(diff <= P[i-1] - P[i]){ diff = P[i-1] - P[i]; ans = i; } } cout << ans << endl; } }
0
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio> #include <cmath> using namespace std; int main() { int i = 0; char a[20]; scanf("%s", a); while (1) { i++; if (a[i] == '\0') break; } i--; while (i != -1) { printf("%c", a[i]); i--; } printf("\n"); return (0); }
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("unroll-loops") #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define int long long #define fr(i,a,b) for(int i = a ; i <= b ; ++i) #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) begin(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() #define pb push_back #define fst first #define snd second using namespace __gnu_pbds; using ordered_set = tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>; //find_by_order(k):returns iterator to kth element starting from 0 //order_of_key(k):returns count of elements strictly smaller than k typedef long long ll;typedef pair<int, int> pii; typedef vector<int> vi;typedef long double ld; template<class T> using min_heap = priority_queue<T,vector<T>,greater<T>>; template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);} template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));} template<class T> void re(T& x) { cin >> x; } template<typename T> void remdup(vector<T>& v) { sort(all(v)); v.erase(unique(all(v)), v.end()); } template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;} template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); } void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); } #ifdef np #include "C:\Users\navodit\Desktop\mycodes\pr.h" #else #define trace(...) #endif #define MOD 1000000007 void solve(){ int n , r ; cin >> n >> r ; if(n<=10){ cout << r + (100*(10-n)) << endl; } else cout << r << endl; } signed main() { unsyncIO(); int tt =1 ; // cin >> tt; rep(i,0,tt) solve(); #ifdef np cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
0
#include <iostream> #include <stdlib.h> #define inf 99999 using namespace std; bool check(int *label, int n) { for(int i = 1; i <= n; i++){ if(label[i] == 0){ return true; } } return false; } void dij(int **a, int n, int s, int t) { int *label, current=s, num=1, next, *cost, min; cost = (int *)calloc(n+1, sizeof(int)); label = (int *)calloc(n+1, sizeof(int)); for(int i = 1; i <= n; i++){ cost[i] = a[current][i]; } label[current] = num++; while(check(label, n)){ min = inf; for(int i = 1; i <= n; i++){ if(min >= cost[i] && label[i] == 0){ min = cost[i]; next = i; } } label[next] = num++; for(int i = 1; i <= n; i++){ if(label[i] == 0 && cost[i] > (a[next][i]+cost[next])){ cost[i] = a[next][i] + cost[next]; } } current = next; } cout << cost[t] << endl; free(cost); free(label); return ; } int main(int argc, char **argv) { int **t, **c, n, m, a, b, p, q; while(1){ cin >> n >> m; if(n == 0 && m == 0){ break; } t = (int **)calloc(m+1, sizeof(int)); c = (int **)calloc(m+1, sizeof(int)); for(int i = 0; i <= m; i++){ t[i] = (int *)calloc(m+1, sizeof(int)); c[i] = (int *)calloc(m+1, sizeof(int)); } for(int i = 0; i < n; i++){ cin >> a >> b >> p >> q; c[a][b] = c[b][a] = p; t[a][b] = t[b][a] = q; } for(int i = 1; i <= m; i++){ for(int j = 1; j <= m; j++){ if(i != j && c[i][j] == 0){ c[i][j] = inf; } if(i != j && t[i][j] == 0){ t[i][j] = inf; } } } cin >> n; for(int i = 0; i < n; i++){ cin >> a >> b >> p; if(p == 0){ dij(c, m, a, b); } else { dij(t, m, a, b); } } for(int i = 0; i <= m; i++){ free(t[i]); free(c[i]); } free(t); free(c); } return 0; }
#include <bits/stdc++.h> using namespace std; #define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s)) #define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1)) #define rep(i,n) iota(i,(n),0,1) #define INF (1e9) #define EPS (1e-9) #define cons(a,b) (make_pair(a,b)) #define car(a) (a.first) #define cdr(a) (a.second) #define cadr(a) (car(cdr(a))) #define cddr(a) (cdr(cdr(a))) #define all(a) a.begin(), a.end() #define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl; typedef long long INTEGER; typedef double FLOAT; template<class S, class T> ostream& operator<<(ostream& os, pair<S,T> p) { os << '(' << car(p) << ", " << cdr(p) << ')'; return os; } template<class T> ostream& operator<<(ostream& os, vector<T> v) { os << v[0]; for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i]; return os; } const int MM = 100; int cost[MM][MM]; int toki[MM][MM]; int main() { entry:; int n, m; cin >> m >> n; if (n + m == 0) return 0; rep (i, n) { rep (j, n) { cost[i][j] = INF; toki[i][j] = INF; } cost[i][i] = 0; toki[i][i] = 0; } rep (i, m) { int a, b, c, t; cin >> a >> b >> c >> t; --a; --b; cost[a][b] = cost[b][a] = c; toki[a][b] = toki[b][a] = t; } rep (k, n) { rep (i, n) { rep (j, n) { cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]); toki[i][j] = min(toki[i][j], toki[i][k] + toki[k][j]); } } } //rep (i,n) { rep(j,n) { cout << cost[i][j] << ' '; } cout << endl; } int k; cin >> k; rep (i, k) { int a, b, t; cin >> a >> b >> t; --a; --b; if (t) { cout << toki[a][b] << endl; } else { cout << cost[a][b] << endl; } } goto entry; return 0; }
1
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) typedef int64_t Int; //snukeさんのコードをほぼ写した int N; vector<int> G[100010]; vector<int> dist; void dfs(int v, int d=0, int p=-1) { dist[v] = d; for (int u : G[v]) { if (u == p) continue; dfs(u,d+1,v); } } vector<int> calcDist(int s) { dist.resize(N); dfs(s); return dist; } int main(){ int u, v, ans = 0; cin >> N >> u >> v; u--; v--; rep(i,N-1) { int a, b; cin >> a >> b; a--; b--; G[a].push_back(b); G[b].push_back(a); } vector<int> distU = calcDist(u); vector<int> distV = calcDist(v); rep(i,N) { if (distU[i] < distV[i]) { ans = max(ans, distV[i]); } } ans--; cout << ans << endl; }
#include <bits/stdc++.h> #include <ext/rope> #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 target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#define int long long #define pb push_back #define x first #define y second #define mk(a,b) make_pair(a,b) #define rr return 0 #define sqr(a) ((a)*(a)) #define all(a) (a).begin(), (a).end() #define sz(a) (int)(a).size() using namespace std; using namespace __gnu_cxx; using namespace __gnu_pbds; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; template<class value, class cmp = less<value> > using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>; template<class value, class cmp = less_equal<value> > using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>; template<class key, class value, class cmp = less<key> > using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>; /// find_by_order() /// order_of_key() mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); inline int randll(int l = INT_MIN, int r = INT_MAX) { return uniform_int_distribution<int>(l, r)(rng); } const int INF = 1e9, MOD = 1e9 + 7; /// think const ll LINF = 1e18; const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}; inline bool inside (int x, int y, int n, int m) { return 0 <= x && 0 <= y && x < n && y < m; } template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; } template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; } vector <vector <int> > edge; int n; vector <int> get_v (int v, int x) { vector <int> d(n, INF), ans; d[v] = 0; queue <int> q; q.push(v); while (!q.empty()) { v = q.front(); q.pop(); for (int to : edge[v]) { if (d[to] == INF) { d[to] = d[v] + 1; q.push(to); } } } for (int i = 0; i < n; i++) { if (d[i] <= x) ans.pb(i); } return ans; } main() { ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b; cin >> n >> a >> b; --a, --b; edge.resize(n); for (int i = 1, u, v; i < n; i++) { cin >> u >> v; --u, --v; edge[u].pb(v); edge[v].pb(u); } int l = 0, r = n; while (l < r) { int mid = (l + r) >> 1; vector <int> A = get_v(a, mid), B = get_v(b, mid); vector <int> used(n); for (auto &i : B) used[i] = 1; bool ok = true; for (auto &i : A) { if (!used[i]) { ok = false; break; } } if (ok) r = mid; else l = mid + 1; } cout << r - 1 << '\n'; }
1
/* _ _ _ _ _ _ _ _ _ _ _ _ _ __ _ __ __ | _ _| | | | | | | | | | _ | | | | | | __ | | \ / | | |_ _ | |__| | | | | | | |_| | | |__| | | |__| | | |\ \_/ /| | |_ _ | | __ | | | | | | _ < | __ | | __ | | | \ / | | _ _| | | | | | | |__| | | |_| | | | | | | | | | | | \_/ | | _ _ _ |_ _ _| |_| |_| |_ __ _| |_ _ _| |_| |_| |_| |_| |_| |_| |_| |_| |_| */ #include <bits/stdc++.h> using namespace std; #define ll long long int #define fi first #define se second #define pb push_back #define all(a) (a).begin(), (a).end() #define debug(a) cout << #a << " = " << a << " "; #define endl "\n" const int MOD=1e9 + 7; const int N=1000100; template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; } #define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl; void solve(){ long n,k; cin>>n>>k; long double v[n]; for(int i=0;i<n;i++){ cin>>v[i]; v[i]=(v[i]+1.00)/2.00; } long double pre[n+1]; pre[0]=0.0; for(int i=0;i<n;i++){ pre[i+1]=pre[i]+v[i]; } long double ans=0.0; for(int i=k;i<=n;i++){ ans=max(ans,pre[i]-pre[i-k]); } cout<<setprecision(16)<<ans<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long int t = 1; // cin>>t; for (long int tt = 1; tt <= t; tt++) { solve(); } return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; const ll INF = 1LL << 60; ll dp[200][100001]; int S[200]; int main() { int N, X; cin >> N >> X; for (int i = 0; i < N; i++) { cin >> S[i]; } sort(S, S + N); for (int i = 0; i <= X; i++) { dp[0][i] = i % S[0]; } for (int i = 1; i < N; i++) { for (int j = 0; j <= X; j++) { (dp[i][j] += dp[i - 1][j%S[i]]) %= MOD; (dp[i][j] += (i*dp[i - 1][j]) % MOD) %= MOD; } } cout << dp[N - 1][X] << endl; }
0
#include <cstdio> #include <iostream> #include <vector> #define mod 1000000007 #define MN 1050000 std::vector<int> v[MN]; int n, a[MN]; int b[MN], c[MN]; int main() { scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d", &a[i]); b[i] = b[i - 1] ^ a[i]; c[i] = c[i - 1] + (b[i] == 0 ? 1 : 0); v[b[i]].push_back(i); } int ans = 0; for(int j = 1; j < (1 << 20); j++) { int Sumj = 0, Sum0 = 1; int S = v[j].size(); for(int k = 0; k < S; k++) { if(k) Sum0 = (Sum0 + 1ll * Sumj * (c[v[j][k]] - c[v[j][k - 1]])) % mod; Sumj = (Sum0 + Sumj) % mod; } if(b[n] == j) ans = (ans + Sum0) % mod; if(b[n] == 0) ans = (ans + Sumj) % mod; } if(b[n] == 0) { int k = 1; for(int j = 1; j <= c[n] - 1; j++) k = k * 2 % mod; ans = (ans + k) % mod; } printf("%d\n", ans); }
#include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <string> #include <queue> #include <map> using namespace std; const int INF = 1e8; //0:up, 1:right, 2:down, 3:left vector<pair<int, int>> direction(4); //距離を計算する int f( vector<pair<int, int>> vec){ sort(vec.begin(), vec.end()); int dist = INF; for(int i=0; i<vec.size()-1; ++i){ if(vec[i].second == 0 && vec[i+1].second != 0){ int tmp = vec[i+1].first - vec[i].first; dist = min(dist, tmp); } } return dist; } int main(){ int N; cin >> N ; vector<int> x(N), y(N), dir(N); for(int i=0; i<N; ++i){ int X, Y; char U; cin >> x[i] >> y[i]; cin >> U; if( U == 'U') dir[i] = 0; if( U == 'R') dir[i] = 1; if( U == 'D') dir[i] = 2; if( U == 'L') dir[i] = 3; } int ans = INF; //四回分ですべてをカバー for(int i=0; i<4; ++i){ //すべてのx座標を独立に考える // x座標: [{y座標1, 方向1}, {y座標2, 方向2}] みたいな感じ { map<int, vector<pair<int, int>>> mp; //180度パターン、上と下でぶつかる場合を考える for(int i=0; i<N; ++i){ if (dir[i] != 0 && dir[i] !=2) continue; mp[x[i]].emplace_back( y[i], dir[i] ); } for(auto y_dir : mp){ int res = f(y_dir.second); if(res == INF)continue; ans = min(ans, res*5); } } //90度パターン、直角にぶつかる。ここではUとRでぶつかるを想定 { map<int, vector<pair<int, int>>> mp; //この場合x+y座標の和が一致する for(int i=0; i<N; ++i){ if (dir[i] != 0 && dir[i] !=1) continue; mp[ x[i] + y[i] ].emplace_back(y[i], dir[i]); } for(auto y_dir : mp){ int res = f(y_dir.second); if(res == INF)continue; ans = min(ans, res*10); } } //時計回りに回転 for(int i=0; i<N; ++i){ int px = y[i]; int py = -x[i]; x[i] = px; y[i] = py; dir[i] = (dir[i] + 1)%4; } } if(ans == INF){ cout << "SAFE" << endl; }else{ cout << ans << endl; } }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vint; typedef vector<double> vd; typedef vector<ll> vll; typedef vector<string> vstr; typedef vector<vector<int>> vvint; typedef vector<pair<int, int>> vpii; typedef vector<pair<ll, ll>> vpll; typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し typedef priority_queue<ll, vector<ll>, greater<ll>> spqll; //小さい順に取り出し typedef priority_queue<int, vector<int>, less<int>> bpqint; //大きい順に取り出し typedef priority_queue<ll, vector<ll>, less<ll>> bpqll; //大きい順に取り出し #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++) #define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++) #define FI first #define SE second #define MP make_pair #define MT make_tuple #define PB push_back #define PF push_front #define TS to_string #define BS binary_search #define LB lower_bound #define UB upper_bound #define NP next_permutation #define ALL(v) (v).begin(), (v).end() #define SZ(x) (ll) x.size() #define SP(x) setprecision((ll)x) int INF = 1e9; int NIL = -1; ll MOD = 1000000007; ll LINF = 1e18; double EPS = 1e-9; double PI = M_PI; int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数 ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } //最小公倍数 void yes(){ cout << "Yes" << endl;} void no(){ cout << "No" << endl;} //----------------------------------------- //----------------------------------------- int main() { cin.tie(0); ios::sync_with_stdio(false); std::chrono::system_clock::time_point start,end; start = std::chrono::system_clock::now(); ll n, k ; cin >> n >> k ; vll pa ; vll ma ; pa.PB(0) ; ma.PB(0) ; REP(i,n){ ll a ; cin >> a ; if(a==0){ k-- ; } else if(a>0){ pa.PB(a) ; } else{ ma.PB(-a) ; } } sort(ALL(ma)) ; sort(ALL(pa)) ; ll sp = SZ(pa) ; ll sm = SZ(ma) ; ll ans = LINF ; for(ll i=0;i<=k;i++){ ll tmp ; if(k-i<sm && i<sp){ tmp = 2*min(pa[i],ma[k-i]) + max(pa[i],ma[k-i]) ; ans = min(ans,tmp) ; } } cout << ans <<endl; end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count(); //std::cout << elapsed <<"ms"<< std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int64_t MOD = 1000000007; typedef int64_t ll; typedef uint64_t ull; #define FOR(i, start, end) for(uint64_t i=start; i<end; i++) #define REP(i, n) FOR(i, 0, n) // 最大公約数gcd // 最小公倍数lcm=m*n/gcd uint64_t gcd(uint64_t m, uint64_t n) { uint64_t temp; while (m % n != 0){ temp = n; n = m % n; m = temp; } return n; } uint64_t lcm(uint64_t m, uint64_t n) { return (m*n)/gcd(m,n); } // vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0)) // v[n][k]に組み合わせ数が入る。 void comb(vector<vector <uint64_t> > &v){ for(uint64_t i = 0;i <v.size(); i++){ v[i][0]=1; v[i][i]=1; } for(uint64_t k = 1;k <v.size();k++){ for(uint64_t j = 1;j<k;j++){ v[k][j]=(v[k-1][j-1]+v[k-1][j]); } } } // 掛け算オーバーフロー判定 bool is_product_overflow(uint64_t a, uint64_t b) { uint64_t prod = a * b; return (prod / b != a); } //素因数分解 void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム long i,sq; if(a%2==0){ //偶数の場合 factors.push_back(2); primeFactorization(a/2,factors); //2で割った値で再帰 return; } sq = sqrt(a); for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合 if(a%i==0){ factors.push_back(i); primeFactorization(a/i,factors); //割れた値で再帰 return; } } //偶数でも3以上√a以下の奇数の場合でも割り切れない場合 if(a!=1){ //aが1でないなら、a自身は素数 factors.push_back(a); } } // フェルマーの小定理 // mod. m での a の逆元 a^{-1} を計算する // (a/b)%m = a*movinv(b,m)%m int64_t modinv(int64_t a, int64_t m) { int64_t b = m, u = 1, v = 0; while (b) { int64_t t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // 円周率 // M_PI // #include <iomanip> // setprecisionを使用するのに必要 // cout << std::fixed << std::setprecision(15) << y << endl; // 昇順 // priority_queue<int, vector<int>, greater<int> > queue; ll pCount(int x){ if(x==0) return 1; return pCount(x-1)*2 + 1; } ll allCount(int x){ if(x==0) return 1; return allCount(x-1)*2 + 3; } signed main() { int n,k; cin >> n >> k; k--; vector<int> pos(n); for(int i=0;i<n;i++){ cin >> pos[i]; } int minDist = 1000000000; for(int i=0;i<n-k;i++){ if((pos[i]<=0 && pos[i+k]<=0) ||(pos[i]>=0 && pos[i+k]>=0)){ minDist = min(minDist, (abs(pos[i])>abs(pos[i+k]))?abs(pos[i]):abs(pos[i+k])); } else if(pos[i]<=0 && pos[i+k]>=0){ if(abs(pos[i]) < pos[i+k]){ minDist = min(minDist, abs(pos[i])*2+pos[i+k]); } else{ minDist = min(minDist, pos[i+k]*2+abs(pos[i])); } } } cout << minDist << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; #define int long long const int MOD = 1000000007; signed main() { int n; cin>>n; priority_queue<int> que; int ala=0,a,k=0,t,s; for(int i=0;i<n;i++){ cin>>a; que.push(a); ala^=a; } for(int i=59;i>=0;i--){ if(que.empty())break; if(ala&(1LL<<i)){ while(!que.empty()&&(que.top()&(1LL<<i))){ que.push(que.top()^(1LL<<i)); que.pop(); // cerr<<que.top()<<' '; } continue; } if(!(que.top()&(1LL<<i)))continue; if(!(k&(1LL<<i)))k^=que.top(); t=que.top();que.pop(); while(!que.empty()&&(que.top()&(1LL<<i))){ que.push((t^que.top())); que.pop(); // cerr<<que.top()<<' '; } } cerr<<ala<<' '<<k<<endl; cout<<(ala^k)+k; return 0; }
/*{{{*/ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<iostream> #include<sstream> #include<set> #include<map> #include<queue> #include<bitset> #include<vector> #include<limits.h> #include<assert.h> #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define FOR(I, A, B) for (int I = (A); I <= (B); ++I) #define FORS(I, S) for (int I = 0; S[I]; ++I) #define RS(X) scanf("%s", (X)) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++) #define MP make_pair #define PB push_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PII> VPII; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template<class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(LL &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const LL &x) { printf("%lld", x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);} template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } #ifdef HOME #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");} #else #define DEBUG(...) #endif int MOD = 1e9+7; void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;} /*}}}*/ const int SIZE = 1e6+10; LL A[SIZE]; int get_bit(LL x,int v){return (x>>v)&1;} int main(){ int N; R(N); LL s=0; REP(i,N){ R(A[i]); s^=A[i]; } LL an=0; VI d; for(int i=59;i>=0;i--){ if(get_bit(s,i))an+=1LL<<i; else{ d.PB(i); } } LL now=0; int it=0; REP(i,SZ(d)){ REPP(j,it,N){ if(get_bit(A[j],d[i])){ if(j!=it){ swap(A[j],A[it]); break; } } } if(get_bit(A[it],d[i])){ REPP(j,it+1,N){ if(get_bit(A[j],d[i]))A[j]^=A[it]; } if(get_bit(now,d[i])==0)now^=A[it]; it++; } if(get_bit(now,d[i]))an+=2LL<<d[i]; } W(an); return 0; }
1
#include<bits/stdc++.h> #define rep(i,N) for(ll (i)=0;(i)<(N);(i)++) #define chmax(x,y) x=max(x,y) #define chmin(x,y) x=min(x,y) using namespace std; typedef long long ll; typedef pair<int,int> P; const int mod = 1000000007; int main() { string s; int w; cin >> s >> w; string ans = ""; for(int i = 0; ; ++i) { if(i * w >= s.length()) break; ans += s.substr(i * w, 1); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ string S; int w; cin >> S >> w; for(int i=0;i<S.size();i++){ if(i%w==0){ cout << S.at(i); } } cout << endl; return 0; }
1
// Author: 23forever #include <bits/stdc++.h> //#define debug const int MAXN = 40; const int N = 5 + 7 + 5; const int P = 1e9 + 7; using namespace std; inline void read(int &x) { x = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } } int n, x, y, z; int dp[MAXN + 5][1 << N]; int banned, S; void print(int x) { bitset < 20 > tmp(x); cout << tmp << endl; } void init() { read(n), read(x), read(y), read(z); //cout << (1 << 5 - 1) << endl; banned = (1 << x + y + z - 1) | (1 << y + z - 1) | (1 << z - 1); S = (1 << x + y + z) - 1; //print(S); } int main() { #ifdef forever23 freopen("test.in", "r", stdin); freopen("test.out", "w", stdout); #endif init(); int ans = 1; dp[0][0] = 1; for (int i = 1; i <= n; ++i) { for (int s = 0; s <= S; ++s) { for (int j = 1; j <= 10; ++j) { int nxt_state = ((1 << j - 1) | (s << j)) & S; /*print(s); printf("%d\n", j); print(nxt_state); puts("");*/ if ((nxt_state & banned) != banned) { dp[i][nxt_state] = (dp[i][nxt_state] + dp[i - 1][s]) % P; } } } ans = 1LL * ans * 10 % P; } for (int s = 0; s <= S; ++s) { ans = (ans - dp[n][s] + P) % P; } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; LL n,s,x[100009],p[100009],ans[100009]; void call(int l,int r) { if(l==r) { ans[l]=fabs(x[l]); return; } if(x[l]>0) { call(l,r-1); ans[r]=ans[r-1]+x[r]-x[r-1]; return; } if(x[r]<0) { call(l+1,r); ans[l]=ans[l+1]+x[l+1]-x[l]; return; } if(p[l]>=p[r]) { p[l]+=p[r]; call(l,r-1); ans[r]=ans[l]+x[r]-x[l]; return; } p[r]+=p[l]; call(l+1,r); ans[l]=ans[r]+x[r]-x[l]; return; } int main() { scanf("%lld %lld",&n,&s); for(int i=1;i<=n;i++) { scanf("%lld %lld",&x[i],&p[i]); x[i]-=s; } call(1,n); LL foo=max(ans[1],ans[n]); cout<<foo<<endl; return 0; }
0
// LOVED IT #include<bits/stdc++.h> using namespace std; #define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long int #define ll int #define bits_count __builtin_popcountll #define endl '\n' #define double long double #define ld double #define FOR(i,a,n) for (ll i=(a);i<=(n);++i) #define RFOR(i,a,n) for (ll i=(n);i>=(a);--i) #define ZERO(a) memset((a),0,sizeof((a))) #define MINUS(a) memset((a),-1,sizeof((a))) #define f first #define s second #define pb push_back #define mk make_pair #define all(g) g.begin(),g.end() #define sz(x) (ll)x.size() #define pr pair<int,int> int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; } int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; } // #include <ext/pb_ds/assoc_container.hpp> // Common file // #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_updat // using namespace __gnu_pbds; // typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count(); // struct chash { int operator()(int x) const { return x ^ RANDOM; }}; // cc_hash_table<int, int, hash<int>> cnt; const int MAXN = 305; int dp[MAXN][MAXN][MAXN]; const int MOD = 998244353; string s; int k,n,m; vector<int> one_cnt; int rec(int idx,int carry,int step){ if(step < 0) return 0; if(idx == -1) return (carry == 0); int &ans = dp[idx][carry][step]; if(ans != -1) return ans; ans = 0; int total_ones_here = one_cnt[idx] + carry; FOR(how_many_here,0,total_ones_here){ int to_go_head = total_ones_here - how_many_here; int steps_here = max(0LL,to_go_head - carry); ans = (ans + rec(idx-1,to_go_head,step-steps_here))%MOD; } return ans; } void solve(){ MINUS(dp); cin>>s>>k; n = sz(s); k = min(k,n); int cnt = 0; for(char c:s){ if(c == '0'){ one_cnt.push_back(cnt); cnt = 0; }else cnt++; } if(cnt) one_cnt.push_back(cnt); m = sz(one_cnt); cout<<rec(m-1,0,k)<<endl; } signed main(){ FastRead; int t = 1; // cin>>t; FOR(i,1,t){ // cout<<"Case #"<<i<<": "; solve(); } }
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for(int i=0; i<n; i++) #define rep1(i, n) for(int i=1; i<=n; i++) #define repr(i, n) for(int i=n-1; i>=0; i--) #define repr1(i, n) for(int i=n; i>=1; i--) #define all(v) v.begin(),v.end() using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int INF = 1e9; const ll LLINF = 1e18; const ll MOD = 1e9+7; const double EPS = 1e-10; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { int a, b; cin >> a >> b; vector<string> s(100, string(100, '#')); rep(i, 50) rep(j, 100) s[i][j] = '.'; int cnt = 0; for (int i = 0; i < 50; i += 2) { if (cnt == b - 1) break; for (int j = 0; j < 100; j += 2) { if (cnt == b - 1) break; s[i][j] = '#'; cnt++; } } cnt = 0; for (int i = 51; i < 100; i += 2) { if (cnt == a - 1) break; for (int j = 0; j < 100; j += 2) { if (cnt == a - 1) break; s[i][j] = '.'; cnt++; } } printf("100 100\n"); for (auto &line: s) cout << line << endl; }
0
#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> using namespace std; int main() { int n,k=0; long long sum=0; scanf("%d",&n); int num[100005]; for(int i=0;i<n;i++) { scanf("%d",&num[i]); if(num[i]<0) { num[i]=-num[i]; k++; } sum+=num[i]; } sort(num,num+n); if(k%2!=0) sum=sum-num[0]*2; printf("%lld",sum); return 0; }
#include <bits/stdc++.h> #define int long long #define gcd __gcd #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define mod2 998244353 #define maxe *max_element #define mine *min_element #define inf 1e18 #define deci(x,y) fixed<<setprecision(y)<<x #define w(t) int t; cin>>t; while(t--) #define nitin ios_base::sync_with_stdio(false); cin.tie(NULL) #define PI 3.141592653589793238 using namespace std; int power(int x, int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int modi(int a, int m) { return power(a, m - 2, m); } string find_ans(int n,vector<int>& v,string s) { if(n==1) { if(v[0]%2==0) { return s; } else{ if(s=="First") return "Second"; else return "First"; } } int e=0; int o=0; for(auto c:v) { if(c%2==0) e++; else o++; } if(e==1 || e%2!=0) { return s; } else if(e%2==0 && o>1){ if(s=="First") return "Second"; else return "First"; } else{ int g=v[0]; for(auto &c:v) { if(c&1) c-=1; } for(auto c:v) { g=gcd(g,c); } for(auto &c:v) { c=c/g; } if(s=="First") s="Second"; else s="First"; return find_ans(n,v,s); } } int32_t main() { nitin; int n; cin>>n; vector<int>v(n); for(int i=0;i<n;i++){ cin>>v[i]; } cout<<find_ans(n,v,"First")<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define PRINT(a) cout << (a) << endl #define pb push_back #define eb emplace_back #define mp make_pair #define Fi first #define Se second #define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n'; using ll = long long int; using P = pair<int,int>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pii = pair<int, int>; template <typename T> using PQ = priority_queue<T>; template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const int INF = 1001001001; const ll LINF = 1001001001001001001ll; const int MOD = 1e9 + 7; int main(){ int score[] = {300000, 200000, 100000}; int x,y; cin >> x >> y; x--;y--; int ans = 0; if(x<3)ans+=score[x]; if(y<3)ans+=score[y]; cout << (ans==600000 ? ans + 400000 : ans) << endl; }
#include <iostream> int main(){ int A, B; std::cin >> A >> B; if (A <= 8 && B <= 8) { std::cout << "Yay!" << std::endl; } else { std::cout << ":(" << std::endl; } }
0
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; int main() { int a[10],ans=0; for(int iii=1;iii<=2;iii++){ ans=0; for(int i=0;i<10;i++){ scanf("%d",&a[i]); } sort(a,a+10); ans+=a[7]+a[8]+a[9]; if(iii==1)printf("%d ",ans); else printf("%d\n",ans); } return 0; }
#include<iostream> #include<cstdio> #include <algorithm> #include <functional> #include <vector> using namespace std; int main(){ cin.tie(0); ios::sync_with_stdio(false); int a[10], b[10]; for(int i=0; i<10; i++){ cin >> a[i]; } for(int i=0; i<10; i++){ cin >> b[i]; } sort(a,a+10); sort(b,b+10); cout << a[9] + a[8] + a[7] << " "; cout << b[9] + b[8] + b[7] << "\n"; return 0; }
1
#include<iostream> #include<cstdio> #include<cstring> namespace wohaocaia { inline void check_max(int a,int &b){if(a>b)b=a;} const int N=105; int s[N][N],f[N][N][N][N]; int n,m,sx,sy; int tl,tr,tu,td; int got(){for(char c=getchar();;c=getchar())if(c=='o' || c=='.' || c=='E')return c;} int min(int a,int b){return a<b?a:b;} int max(int a,int b){return a>b?a:b;} void initialize() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { int x=got(); if(x=='o')s[i][j]=1; else if(x=='.')s[i][j]=0; else sx=i,sy=j; s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1]; } } int bdy(int a,int b,int c,int d) { if(a>c || b>d)return 0; // printf("(%d,%d) -- (%d,%d) : %d\n",a,b,c,d,s[c][d]-s[c][b-1]-s[a-1][d]+s[a-1][b-1]); return s[c][d]-s[c][b-1]-s[a-1][d]+s[a-1][b-1]; } void dp() { tl=sy-1,tr=m-sy,tu=sx-1,td=n-sx; // printf("L:%d , R:%d , U:%d , D:%d \n",tl,tr,tu,td); // printf("%d , %d \n",sx,sy); f[0][0][0][0]=0; for(int l=0;l<=tl;l++) for(int r=0;r<=tr;r++) for(int u=0;u<=tu;u++) for(int d=0;d<=td;d++) { int v=f[l][r][u][d]; check_max(v+bdy(max(sx-u,d+1),sy-l-1,min(sx+d,n-u),sy-l-1)*(sy-l-1>r),f[l+1][r][u][d]); check_max(v+bdy(max(sx-u,d+1),sy+r+1,min(sx+d,n-u),sy+r+1)*(sy+r+1<=m-l),f[l][r+1][u][d]); check_max(v+bdy(sx-u-1,max(sy-l,r+1),sx-u-1,min(sy+r,m-l))*(sx-u-1>d),f[l][r][u+1][d]); check_max(v+bdy(sx+d+1,max(sy-l,r+1),sx+d+1,min(sy+r,m-l))*(sx+d+1<=n-u),f[l][r][u][d+1]); // printf("f[%d][%d][%d][%d] = %d\n",l,r,u,d,v); } } void orz() { initialize(); dp(); printf("%d\n",f[tl][tr][tu][td]); } } int main() { // freopen("in","r",stdin); // freopen("out","w",stdout); wohaocaia::orz(); return 0; }
#include<bits/stdc++.h> using namespace std; int H, W, rlen, clen, psum[102][102]; char G[102][102]; int calc(int r1, int c1, int r2, int c2) { int ret = psum[r2][c2]; if(r1) ret -= psum[r1 - 1][c2]; if(c1) ret -= psum[r2][c1 - 1]; if(r1 && c1) ret += psum[r1 - 1][c1 - 1]; return ret; } int re, ce; int cc[102][102]; int dp(int r, int c) { int &ret = cc[r][c]; if(ret != -1) return ret; ret = 0; if(r + rlen - 1 != re) { ret = max(ret, calc(r + rlen, c, r + rlen, c + clen - 1) + dp(r + 1, c)); } if(c + clen - 1 != ce) { ret = max(ret, calc(r, c + clen, r + rlen - 1, c + clen) + dp(r, c + 1)); } return ret; } int main() { scanf("%d %d", &H, &W); int r, c; for(int i = 0; i < H; i++) { scanf("\n"); for(int j = 0; j < W; j++) { scanf("%c", &G[i][j]); if(G[i][j] == 'E') r = i, c = j; } } if(r + 1 > H - r) { for(int i = 0; i < H - 1 - i; i++) for(int j = 0; j < W; j++) swap(G[i][j], G[H - 1 - i][j]); r = H - 1 - r; } if(c + 1 > W - c) { for(int i = 0; i < H; i++) for(int j = 0; j < W - 1 - j; j++) swap(G[i][j], G[i][W - 1 - j]); c = W - 1 - c; } rlen = r + 1; clen = c + 1; for(int i = 0; i < H; i++) { for(int j = 0; j < W; j++) { psum[i][j] = G[i][j] == 'o'? 1 : 0; if(i) psum[i][j] += psum[i - 1][j]; if(j) psum[i][j] += psum[i][j - 1]; if(i && j) psum[i][j] -= psum[i - 1][j - 1]; } } int ans = 0; for(int i = 0; i <= r; i++) { for(int j = 0; j <= c; j++) { re = H - 1 - r + i; ce = W - 1 - c + j; memset(cc, -1, sizeof(cc)); ans = max(ans, calc(i, j, i + rlen - 1, j + clen - 1) + dp(i, j)); } } cout << ans; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> iint; typedef pair<ll,ll> llll; #define ALL(x) (x).begin(),(x).end() const ll zero = 0; const ll INF = 3000000000000000000; //10^18 const int inINF = 1000000000; //10^9 const ll MOD = 1000000007; //10^9+7 const ll MOD2 = 998244353; int main(){ int N; cin >> N; vector<bool> P(56000, true); P[0] = false; P[1] = false; for (int i = 2; i < 250; i++) { if(P[i] == false){ continue; } else{ for (int j = i; i * j < 56000; j++) { P[i * j] = false; } } } vector<int> ans; for (int i = 1; i < 56000; i+=5) { if(P[i] == true){ ans.push_back(i); } } for (int i = 0; i < N; i++) { printf("%d ", ans[i]); } printf("\n"); }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i,n) for(int i=0;i<(n);++i) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define all(x) (x).begin(), (x).end() #define PI 3.14159265358979323846264338327950L using namespace std; typedef long long ll; typedef long double ld; int main() { ll r; cin>>r; cout<<2*PI*r<<endl; }
0
#include <bits/stdc++.h> using namespace std; #define INF (1 << 30) #define EPS 1e-10 #define MOD 1000000007 #define rep(i, n) FOR(i, 0, n) #define FOR(i, x, n) for (int i = (x); i < (n); ++i) #define all(v) (v).begin(), (v).end() using ll = long long; template<class T> bool chmax(T& a, T b){ if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T& a, T b){ if (a > b) { a = b; return true; } return false; } int main() { int n, a; multiset<int> ms; cin >> n; while (n--) { cin >> a; auto it = ms.lower_bound(a); if (it == ms.begin()) { ms.insert(a); } else { ms.erase(--it); ms.insert(a); } } cout << ms.size() << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<(n);i++) #define rep2(i,n) for(int i=1;i<=(n);i++) #define rep3(i,i0,n) for(int i=i0;i<(n);i++) #define pb push_back #define mod 1000000007 const ll INF = 1LL << 60; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) {return a/gcd(a,b)*b;} #define all(x) x.begin(), x.end() #define mp make_pair bool compare(pair<int, int> a, pair<int, int> b) { if(a.first != b.first){ return a.first < b.first; }else{ return a.second < b.second; } } bool In_map(ll y,ll x,ll h,ll w){ if(y<0 || x<0 || y>=h || x>=w){ return 0; }else{ return 1; } } const vector<ll> dx{1,0,-1,0}; const vector<ll> dy{0,1,0,-1}; int main() { ll N; cin >> N; vector<ll> dp(N+1,INF); vector<ll> A(N); rep(i,N){ cin >> A[i]; } reverse(all(A)); rep(i,N){ ll inx; inx = upper_bound(all(dp),A[i]) -dp.begin(); dp[inx] = A[i]; } ll ans; rep(i,N+1){ if(dp[i] == INF){ ans = i; break; } } cout << ans << endl; return 0; }
1
#define _GLIBCXX_DEBUG #include<bits/stdc++.h> #include<algorithm>//next_permutation #define rep(i,n) for (int i = 0;i < (n);i++) #define all(v) v.begin(),v.end() #define dec(n) cout << fixed << setprecision(n); #define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #define small "abcdefghijklmnopqrstuvwxyz" using namespace std; using ll = long long; using P = pair<ll,ll>; using vl = vector<ll>; using vvl = vector<vl>; ll gcd(ll a,ll b){ if(b == 0) return a; return gcd(b , a % b); } const ll MOD = 1000000007; const ll MAX = 2000001; ll mod(ll a){ return a % MOD; } ll lcm(ll a,ll b){ return (a*b)/gcd(a,b); } ll fac[MAX], finv[MAX], inv[MAX]; void nCrprep() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll nCr(ll n, ll r){ if (n < r) return 0; if (n < 0 || r < 0) return 0; return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD; } ll nCrcheep(ll n,ll r){ if(r == 0) return 1; else if(r == 1) return n; else return nCrcheep(n-1,r-1)*n/r; } vector<pair<ll,ll>> prime_factorize(ll n){ vector<pair<ll,ll>> res; for(ll i=2; i*i <= n; i++){ if(n % i != 0) continue; ll ex = 0; while(n % i == 0){ ex++; n /= i; } res.push_back({i,ex}); } if(n != 1) res.push_back({n,1}); return res; } int main(){ ll n,m; cin >> n >> m; ll ans = 1; vl pown(60); nCrprep(); pown[0] = 1; rep(i,59){ pown[i+1] = mod(pown[i]*n); } auto res = prime_factorize(m); for(auto p : res){ ll ind = p.second; ans *= nCr(n+ind-1,ind); ans = mod(ans); } cout << ans << endl; }
#include <bits/stdc++.h> #include <boost/range/adaptors.hpp> #include <boost/range/irange.hpp> using namespace std; using namespace boost; using namespace boost::adaptors; int main() { int64_t n; cin >> n; string s; cin >> s; unordered_map<pair<string, string>, int64_t, boost::hash<pair<string, string>>> m; for (auto u : irange(0uL, 1uL << n)) { bitset<18> bs(u); string s1, s2; for (auto i : irange(0L, n)) { if (bs[i]) { s1.push_back(s[i]); } else { s2.push_back(s[i]); } } ++m[make_pair(s1, s2)]; } int64_t ans = 0; for (auto u : irange(0uL, 1uL << n)) { bitset<18> bs(u); string s1, s2; for (auto i : irange(n, 2 * n) | reversed) { if (bs[i - n]) { s1.push_back(s[i]); } else { s2.push_back(s[i]); } } ans += m[make_pair(s1, s2)]; } cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; const long long Mod = 1000000007; int n; string str; int a[200005], xd[200005]; long long p[200005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; p[0] = 1; for (int i = 1; i <= n; i++) { p[i] = (p[i - 1] * i) % Mod; } n *= 2; cin >> str; int s = 0; for (int i = 0; i < n; i++) { if (str[i] == 'B') { a[i] = 1; } else { a[i] = 0; } if (a[i] == s) { xd[i] = -1; } else { xd[i] = 1; } s ^= 1; } int s1 = 0, s2 = 0; long long res = 1; for (int i = 0; i < n; i++) { if (xd[i] == 1) { s1++; } else { if (s1 > s2) { res = (res * (s1 - s2)) % Mod; } else { res = 0; } if (res == 0) { break; } s2++; } } if (s1 != s2) { res = 0; } cout << (res * p[n / 2]) % Mod; return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; typedef pair<int,int> P; signed main(){ vector<int> v; int t=3; while(v.size()<1000){ bool f=1; for(int i=2;i*i<=t;i++)if(t%i==0)f=0; if(f)v.push_back(t); t++; } int d1[500][500],d2[500][500],c=0; for(int i=-498;i<500;i+=2){ for(int j=-i;j+i<500;j++){ if(0<=j&&j<500&&0<=j+i&&j+i<500)d1[j][j+i]=v[c]; } c++; } for(int i=0;i<1000;i+=2){ for(int j=1000;i-j<500;j--){ if(0<=j&&j<500&&0<=i-j&&i-j<500)d2[j][i-j]=v[c]; } c++; } int n; cin>>n; int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0}; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(j)cout<<" "; if((i+j)%2){ int res=1; set<int> s; for(int k=0;k<4;k++){ int nx=j+dx[k],ny=i+dy[k]; if(nx<0||ny<0||nx>=500||ny>=500)continue; s.insert(d1[ny][nx]); s.insert(d2[ny][nx]); } for(auto z:s){res*=z;} cout<<res+1; } else cout<<d1[i][j]*d2[i][j]; } cout<<endl; } return 0; }
0
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<utility> #include<tuple> #include<map> #include<queue> #include<set> #include<stack> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; #define BIL ((ll)1e9) #define MOD ((ll)1e9+7) #define INF (1LL<<60) //1LL<<63でオーバーフロー #define inf (1<<29) //1<<29でオーバーフロー int main(int argc,char* argv[]){ int n; cin >> n; vector<pair<double,double>> root(n); for(auto &x:root){ cin >> x.first >> x.second; } vector<vector<double>> dist(n,vector<double>(n,-1)); for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ if(dist[i][j]!=-1)continue; dist[i][j]=sqrt((root[i].first-root[j].first)*(root[i].first-root[j].first)+(root[i].second-root[j].second)*(root[i].second-root[j].second)); } } vector<int> perm(n); for(int i=0;i<n;i++){ perm[i]=i; } double sumdist=0; int count=0; do{ for(int i=0;i<n-1;i++){ int nowbeg=perm[i],nowend=perm[i+1]; double nowdist=max(dist[nowbeg][nowend],dist[nowend][nowbeg]); sumdist+=nowdist; } count++; }while(next_permutation(perm.begin(),perm.end())); printf("%.7lf",sumdist/count); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair<int,int> ; using pll = pair<long long,long long>; constexpr int INF = 1e9; constexpr long long LINF = 1e7; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; template<typename Mono,typename Ope> struct LazySegmentTree{ using F = function<Mono(Mono,Mono)>; using G = function<Mono(Mono,Ope)>; using H = function<Ope(Ope,Ope)>; int n,height; F f; G g; H h; Mono tu; Ope eu; vector<Mono> node; vector<Ope> lazy; LazySegmentTree(F f,G g,H h,Mono tu,Ope eu):f(f),g(g),h(h),tu(tu),eu(eu){} void init(vector<Mono> v){ int n_ = (int)(v.size()); n = 1;height = 0; while(n < n_) n <<= 1,++ height; node.assign(2*n,tu); lazy.assign(2*n,eu); for(int i=0;i<n_;i++) node[i+n] = v[i]; for(int i=n-1;i>0;i--) node[i] = f(node[i<<1],node[i<<1|1]); } Mono eval(int k){ return (lazy[k]==eu)?node[k]:g(node[k],lazy[k]); } void prop(int k){ if(lazy[k]==eu) return; lazy[k<<1] = h(lazy[k<<1],lazy[k]); lazy[k<<1|1] = h(lazy[k<<1|1],lazy[k]); node[k] = eval(k); lazy[k] = eu; } void prop_above(int k){ for(int i=height;i>0;i--) prop(k>>i); } void recalc_above(int k){ while(k>0){ k >>= 1; node[k] = f(eval(k<<1),eval(k<<1|1)); } } void set_val(int k,Mono x){ k += n; prop_above(k); node[k] = x; lazy[k] = eu; recalc_above(k); } void update(int l,int r,Ope x){ if(l >= r) return; l += n;r += n-1; prop_above(l); prop_above(r); int a = l,b = r; ++ r; while(l < r){ if(l&1) lazy[l] = h(lazy[l],x), ++l; if(r&1) --r, lazy[r] = h(lazy[r],x); l >>= 1;r >>= 1; } recalc_above(a); recalc_above(b); } Mono query(int l,int r){ if(l >= r) return tu; l += n;r += n-1; prop_above(l); prop_above(r);++r; Mono vl = tu,vr = tu; while(l < r){ if(l&1) vl = f(vl,eval(l)), ++l; if(r&1) --r, vr = f(eval(r),vr); l >>= 1;r >>= 1; } return f(vl,vr); } }; struct my{ int l,r; // 区間の左 区間の右 ll x; // 区間のなかで配列i-a[i]の最小値 }; int main(){ auto f = [](my a,my b){ if(a.l==-1) return b; else if(b.l==-1) return a; return my{a.l,b.r,min(a.x,b.x)}; }; auto g = [](my a,ll y){ if(y==-1) return a; return my{a.l,a.r,a.l-y}; }; auto hh = [](ll x,ll y){ if(y==-1) return x; return y; }; LazySegmentTree<my,ll> seg(f,g,hh,my{-1,-1,LINF},-1); int h,w; cin >> h >> w; vector<int> a(h),b(h); rep(i,h) cin >> a[i] >> b[i]; rep(i,h) --a[i],--b[i]; vector<my> aa(w,my{-1,-1,LINF}); ll res = LINF; rep(i,w){ aa[i].l=i; aa[i].r=i+1; if(i<a[0]){ aa[i].x=i; res=i; }else if(i<=b[0]){ aa[i].x=res; }else{ aa[i].x=i; } } rep(i,w){ if(aa[i].x==LINF) continue; aa[i].x=i-aa[i].x; } /* rep(i,w){ cout << aa[i].x << endl; } */ seg.init(aa); vector<int> ans(h,-1); rep(i,h){ ans[i] = seg.query(0,w).x + (i+1); if(i==h-1) continue; if(a[i+1]==0){ seg.update(a[i+1],b[i+1]+1,-LINF); }else{ ll now = (a[i+1]-1) - seg.query(a[i+1]-1,a[i+1]).x; seg.update(a[i+1],b[i+1]+1,now); } } rep(i,h){ if(ans[i]>=LINF) cout << -1 << endl; else cout << ans[i] << endl; } return 0; }
0
#include<iostream> #include<cmath> #include<algorithm> using namespace std; char school(int m, int e, int j) { if( m == 100 || e == 100 || j == 100 ) return 'A'; if( (m+e)>=180 || (m+e+j)>=240) return 'A'; if( (m+e+j)>=210 || ( (m+e+j)>=150 && (m>=80||e>=80) ) ) return 'B'; else return 'C'; } int main() { int x, m, e, j; while(cin>>x) { for(int i=0; i<x; i++) { cin>>m>>e>>j; cout<<school(m,e,j)<<endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } string s; cin >> s; vector<long long> b; int ans = 0; for (int i = n - 1; i >= 0; i--) { long long cur = a[i]; for (auto& x : b) { cur = min(cur, cur ^ x); } if (cur > 0) { if (s[i] == '1') { ans = 1; break; } else { b.push_back(cur); } } } cout << ans << '\n'; } return 0; }
0
#include<iostream> #include<vector> #include<algorithm> #include<string> #include<set> #include<map> #include<queue> #include<cmath> #define REP(i,a) for (int i = 0;i < (a);++i) #define FOR(i,a,b) for (int i = (a);i < (b); ++i) #define FORR(i,a,b) for (int i = (a);i >= (b); --i) #define ALL(obj) (obj).begin(),(obj).end() #define SORT(list) sort(ALL((list))); #define MOD 1000000007 using namespace std; using ll = long long; int main(){ ll n; cin >> n; vector<ll>a(n); vector<int>count(n,0); int zerocount; REP(i,n){ cin >> a[i]; } if(a[0]!=0){ cout << 0 << endl; return 0; } ll answer=1; REP(i,n){ if(a[i]==0){ answer = (answer*(3-count[0]))%MOD; } else{ if(count[a[i]]>=count[a[i]-1]){ cout << 0 << endl; return 0; } answer = (answer*(count[a[i]-1]-count[a[i]]))%MOD; } count[a[i]]++; if(count[a[i]]>3){ cout << 0 << endl; return 0; } } cout << answer << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll MOD = 1000000007; const ld PI = acos(-1); const ld EPS = 0.0000000001; #define REP(i, n) for(ll i=0; i<(ll)(n); i++) #define REPD(i, n) for(ll i=n-1; 0<=i; i--) #define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++) #define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--) #define ALL(x) x.begin(), x.end() #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) int main(){ int n; cin >> n; map<int, int> a; a[0] = 3; ll res=1; REP(i, n){ int x; cin >> x; res *= a[x]; res %= MOD; a[x] -= 1; a[x+1] += 1; } cout << res << endl; }
1
#include <iostream> using namespace std; const int MAX_N = 100005; int n, A[MAX_N], B[MAX_N], C[MAX_N], pos[3 * MAX_N], rev[3 * MAX_N]; void wypisz() { cout << "----------------------\n"; for(int i = 1; i <= n; i++) cout << A[i] << " "; cout << endl; for(int i = 1; i <= n; i++) cout << B[i] << " "; cout << endl; for(int i = 1; i <= n; i++) cout << C[i] << " "; cout << endl; } void swapColumn(int i) { swap(A[i], C[i]); } int main() { cin >> n; for(int i = 1; i <= n; i++) cin >> A[i]; for(int i = 1; i <= n; i++) cin >> B[i]; for(int i = 1; i <= n; i++) cin >> C[i]; for(int i = 1; i <= n; i++) { if((B[i] % 3 != 2) || (((B[i] - 2) / 3) % 2 == i % 2)) { cout << "No"; return 0; } int a = (A[i] - 1) / 3; int b = (B[i] - 1) / 3; int c = (C[i] - 1) / 3; if(a != b || a != c || b != c) { cout << "No"; return 0; } } for(int i = 1; i <= n; i++) { pos[B[i]] = i; } for(int i = 1; i <= n; i++) { if(B[i] == 3 * i - 1) { continue; } int j = pos[3 * i - 1]; int x = B[i]; int y = B[j]; B[i] = y; B[j] = x; swap(A[i], A[j]); swap(C[i], C[j]); pos[x] = j; pos[y] = i; if((i - j) % 4 != 0) { swapColumn(i); swapColumn(j); } swap(A[i + 1], C[i + 1]); // wypisz(); } int odd = 0, even = 0; for(int i = 1; i <= n; i++) { // if(rev[B[i]]) swap(A[i], C[i]); if(A[i] > C[i]) { if(i % 2 == 1) odd++; else even++; // cout << "No3"; // return 0; } } if(odd % 2 == 1 || even % 2 == 1) { cout << "No"; return 0; } cout << "Yes"; return 0; }
#include<bits/stdc++.h> #define no {puts("No");return 0;} #define yes {puts("Yes");return 0;} #define nc() getchar() using namespace std; const int N=300010; /*inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++; }*/ inline int read(){ char ch=nc();int sum=0; while(!(ch>='0'&&ch<='9'))ch=nc(); while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc(); return sum; } int c[N],n; void add(int x,int k){ while(x<=n){ c[x]+=k; x+=x&-x; } } int query(int x){ int ans=0; while(x){ ans+=c[x]; x-=x&-x; } return ans; } int a[N],fu[N],s[N]; bool vis[N]; int main(){ n=read(); int s1=0,s2=0; for(int i=1;i<=3;i++){ for(int j=1;j<=n;j++){ int x; x=read(); if(i==1){ if(x%3==0){ a[j]=x/3; fu[j]=1; if(j&1) s1++; else s2++; }else{ if(x%3!=1) {no;} a[j]=x/3+1; } if(vis[a[j]]) {no;} if((j&1)^(a[j]&1)) {no;} vis[a[j]]=1; } else{ if(fu[j]){ if(x!=a[j]*3-i+1) {no;} }else{ // printf("a(%d)=%d\n",j,a[j]); if(x!=(a[j]-1)*3+i) {no;} } } } } // for(int i=1;i<=n;i++) printf("%d ",a[i]);cout<<endl; int i; if(n&1) i=n;else i=n-1; for(;i>0;i-=2){ s2+=query(a[i]); add(a[i],1); } if(n&1) i=n-1;else i=n; memset(c,0,sizeof(c)); for(;i>0;i-=2){ s1+=query(a[i]); add(a[i],1); } // printf("%d %d\n",s1,s2); if(s1%2==0&&s2%2==0) {yes;} else {no;} return 1; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9+7; const long long INF = 1e15; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int n; cin >> n; vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i]; ll ans = 1; map<int,int> c; int z = 3; for(int i = 0; i < n; i++){ if(a[i] == 0){ ans *= z; ans %=mod; c[0+1]++; z--; } else { ans *= c[a[i]]; c[a[i]]--; ans %= mod; c[a[i]+1]++; } } cout << ans << endl; return 0; }
#include<cstdio> #include<cstdlib> #include<algorithm> #define maxn 1000005 #define mod 998244353 using namespace std; int n,m,fac[maxn],inv[maxn],ans; int add(int a,int b){a+=b;return a>=mod?a-mod:a;} int mul(int a,int b){return 1ll*a*b%mod;} int ksm(int a,int b) { int s=1; for(;b;b>>=1,a=mul(a,a)) if(b&1) s=mul(s,a); return s; } int C(int a,int b) {return mul(fac[a],mul(inv[b],inv[a-b]));} int main() { fac[0]=inv[0]=1; for(int i=1;i<maxn;i++) fac[i]=mul(fac[i-1],i),inv[i]=ksm(fac[i],mod-2); scanf("%d%d",&n,&m); if(n<m) swap(n,m); for(int i=1;i<=m;i++) ans=add(ans,mul(C(i+i,i),C(n+m-2*i,n-i))); ans=mul(ans,mul((mod+1)/2,ksm(C(n+m,n),mod-2))),printf("%d\n",add(ans,n)); return 0; }
0
#include <iostream> using namespace std; int main(){ while(1){ int n, nums[10] = {0}; cin >> n; if(!n) break; for(int i = 0;i < n;i++){ int k; cin >> k; nums[k]++; } for(int i = 0;i < 10;i++){ if(nums[i] == 0) cout << "-"; else{ for(int j = 0;j < nums[i];j++) cout << "*"; } cout << endl; } } return 0; }
#include <iostream> #include <cstdio> #include <algorithm> #include <utility> #include <vector> #include <cmath> using namespace std; #define INF 10000001 int main() { int a, n; int maxi, mini; int i; long long sum = 0ll; mini = INF; maxi = -10000001; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a); maxi = max(a, maxi); mini = min(a, mini); sum += a; } printf("%d %d ", mini, maxi); cout << sum << endl; return (0); }
0
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<n;i++) using pii = pair<int,int>; using piii = pair<pii,int>; using ll = long long; #define int ll signed main(){ int v,e; cin>>v>>e; vector<piii>edge; rep(i,e){ int a,b,c; cin>>a>>b>>c; edge.push_back(piii(pii(a,b),c)); } vector<string>ans; rep(s,v){ vector<int>d(v,LLONG_MAX/1000); d[s]=0; rep(i,v){ bool update=false; rep(j,e){ int to,from,cost; to=edge[j].first.second; from=edge[j].first.first; cost=edge[j].second; if(d[from]==LLONG_MAX/1000)continue; if(d[to]>d[from]+cost){ d[to]=d[from]+cost; update=true; } } if(i==v-1&&update==true) return puts("NEGATIVE CYCLE")*0; } string temp; rep(i,v){ if(i)temp+=" "; if(d[i]==LLONG_MAX/1000)temp+="INF"; else temp+=(to_string(d[i])); } ans.push_back(temp); } rep(i,v)cout<<ans[i]<<endl; }
#include<bits/stdc++.h> using namespace std; #define inf 1e12+1 typedef long long int ll; typedef pair<ll,ll> mypair; #define rep(i,n) for(int i=0;i<n;i++) int main(){ ll v,e; cin>>v>>e; vector<vector<mypair> > g(v); vector<vector<ll> > dp(v,vector<ll>(v,inf) ); ll s,t,d; rep(i,e){ cin>>s>>t>>d,g[s].push_back(mypair(t,d) ); dp[s][t] = d; } rep(i,v)dp[i][i]=0; rep(k,v)rep(i,v)rep(j,v)if(dp[i][k]!=inf&dp[k][j]!=inf)dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]); bool flag =false; rep(i,v)if(dp[i][i]!=0)flag = true; if(flag){ cout<<"NEGATIVE CYCLE"<<endl; }else{ rep(i,v){ rep(j,v){ if(dp[i][j]==inf)cout<<"INF"; else cout<<dp[i][j]; if(j==v-1){} else cout<<' '; } cout<<endl; } } return 0; }
1
#include <bits/stdc++.h> typedef long long ll; using namespace std; #define repr(i,a,b) for(int i=a;i<b;i++) #define rep(i,n) for(int i=0;i<n;i++) #define invrepr(i,a,b) for(int i=b-1;i>=a;i--) #define invrep(i,n) invrepr(i,0,n) #define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr) #define P pair<int,int> const int MOD=1e9+7; const int INF=2e9; const double PI=acos(-1); int main() { ios_base::sync_with_stdio(false); ll n,k; cin >> n >> k; vector<ll> a(n); rep(i,n) cin >> a[i]; vector<ll> b(n-k+1); rep(i,k) b[0]+=a[i]; rep(i,n-k) { b[i+1]=b[i]+a[k+i]-a[i]; } sort(b.begin(),b.end(),greater<>()); double ans=1.0*(b[0]+k)/2; cout << fixed << setprecision(20) << ans << endl; return 0; }
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #define pb push_back #define mpr make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define ll long long #define ld long double #define all(arr) arr.begin(), arr.end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define fo(i, l, r) for (int i = l; i <= r; i++) #define INF 1000000001 #define inf1 1000000000000000001 #define MOD 1000000007 #define pie 3.14159265358979323846264338327950L #define N 100005 #define M 1e6+9 #define mid(l, r) l + (r - l) / 2 #define vec vector<int> #define vecl vector<ll> #define umap unordered_map<ll,ll> #define yes cout << "YES" << endl; #define no cout << "NO" << endl; #define endl "\n" #define int long long using namespace std; int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1}; ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);} ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);} // ll n,k,a,b,c,d,x,y,z,m,l; // ll ans; // vecl arr(N); // ll dp[509][509]; // ll pre[N]; void test_case() { ll n,k; cin>>n>>k; vector<ld> arr(n), temp(n); rep(i,n) { cin>>arr[i]; } for(int i=0; i<n; i++) { temp[i] = (arr[i] + 1)/2; } ld ans = 0; ld sum =0; for(int i=0; i<k; i++) { sum+= temp[i]; } ans = sum; for(int i=k; i<n; i++) { sum+= temp[i] - temp[i-k]; ans = max(ans, sum); } cout<<ans<<endl; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<fixed<<setprecision(20); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int t = 1; // cin >> t; while(t--) { test_case(); } }
1
#include <bits/stdc++.h> #include <iomanip> using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() #define fi first #define se second #define mp make_pair typedef long long ll; typedef vector<ll> vec; typedef vector<vec> mat; ll N,M,H,W,K,Q,A,B; string S; //const ll MOD = 998244353; const ll MOD = (1e+9) + 7; const ll INF = 1LL << 60; typedef pair<ll,ll> P; int main(){ cin>>N>>M>>Q; vector<string> grid(N); rep(i,N) cin>>grid[i]; mat edge(N, vec(M, 0)), num(N + 1, vec(M + 1, 0)), addr(N, vec(M,0)), addc(N, vec(M,0)); rep(i,N){ rep(j,M){ bool blue = grid[i][j] == '1'; if(i > 0) { edge[i][j] += edge[i-1][j] + (blue && grid[i-1][j] == '1'); addc[i][j] = addc[i-1][j] + (blue && grid[i-1][j] == '1'); } if(j > 0) { edge[i][j] += edge[i][j-1] + (blue && grid[i][j-1] == '1'); addr[i][j] = addr[i][j-1] + (blue && grid[i][j-1] == '1'); } if(i > 0 && j > 0) edge[i][j] -= edge[i-1][j-1]; num[i+1][j+1] = num[i][j+1] + num[i+1][j] - num[i][j] + blue; } } vec x(2), y(2); rep(i,Q){ rep(j,2) cin>>x[j]>>y[j]; --x[0], --y[0]; ll res = 0; rep(j,2) rep(k,2) res += (j^k ? -1 : 1) * num[x[j]][y[k]]; --x[1], --y[1]; rep(j,2) rep(k,2) res += (j^k ? 1 : -1) * edge[x[j]][y[k]]; res -= addr[x[0]][y[1]] - addr[x[0]][y[0]]; res -= addc[x[1]][y[0]] - addc[x[0]][y[0]]; cout<<res<<endl; } /*rep(i,N){ rep(j,M) cout<<edge[i][j]<<' '; cout<<endl; }*/ }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define ll long long #define PB push_back #define PII pair <long long , long long> #define FAST ios::sync_with_stdio(false);cin.tie(0); const int maxn = 2e3 + 30; string a[maxn]; int vertex[maxn][maxn] , er[maxn][maxn] , ed[maxn][maxn]; int main() { int n , m , q; cin >> n >> m >> q; for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { if(a[i - 1][j - 1] == '1') { vertex[i][j]++; } vertex[i][j] += vertex[i - 1][j] + vertex[i][j - 1] - vertex[i - 1][j - 1]; } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { // if(a[i - 1][j - 1] == '1' && a[i - 2][j - 1] == '1') { // ed[i][j]++; // } if(a[i - 1][j - 1] == '1' && a[i][j - 1] == '1') { ed[i][j]++; } ed[i][j] += ed[i - 1][j] + ed[i][j - 1] - ed[i - 1][j - 1]; } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { // if(a[i - 1][j - 1] == '1' && a[i - 1][j - 2] == '1') { // er[i][j]++; // } if(a[i - 1][j - 1] == '1' && a[i - 1][j] == '1') { er[i][j]++; } er[i][j] += er[i - 1][j] + er[i][j - 1] - er[i - 1][j - 1]; } } while(q--) { int x1 , y1 , x2 , y2; ll p1 = 0 , p2 = 0; cin >> x1 >> y1 >> x2 >> y2; p1 = vertex[x2][y2] - vertex[x2][y1 - 1] - vertex[x1 - 1][y2] + vertex[x1 - 1][y1 - 1]; p2 += ed[x2 - 1][y2] - ed[x2 - 1][y1 - 1] - ed[x1 - 1][y2] + ed[x1 - 1][y1 - 1]; p2 += er[x2][y2 - 1] - er[x1 - 1][y2 - 1] - er[x2][y1 - 1] + er[x1 - 1][y1 - 1]; cout << p1 - p2 << endl; } }
1
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i< (n); i++) using namespace std; using ll = long long; typedef pair<int,int> P; int main(void) { ll N; cin >> N; string S; cin >> S; ll r=0,g=0,b=0; for(int i=0; i<N; i++) { if(S[i]=='R') r++; if(S[i]=='G') g++; if(S[i]=='B') b++; } ll sum = r*g*b; ll count = 0; for(ll i=0; i<N; i++) { for(ll j=i+1; j<N; j++) { ll k=2*j-i; if(k<N) { if(S[i]!=S[j] && S[i]!=S[k] && S[j]!=S[k]) { //cout << " i:" << i << " j:" << j << " k:" << k << endl; count++; } } } } cout << sum-count << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; /* clang-format off */ #define MOD 1000000007 #define INF 1000000000 #define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i) #define ALL(a) (a).begin(), (a).end() //#define __DEBUG__ #ifdef __DEBUG__ #define CH_P(a) cout <<"check_point("<<#a<<")" << "\n"; #define DEBUG(x) cout<<#x<<":"<<x<<"\n" #define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n" #endif #ifndef __DEBUG__ #define CH_P(a) #define DEBUG(x) #define DEBUGS(v) #endif /* clang-format on */ int main() { // ios::sync_with_stdio(false); // cin.tie(nullptr); string s; cin >> s; ll n = s.size(); ll ans = 1 + (n * (n - 1)) / 2; REP(a, 26) { ll cnt = 0; REP(i, n) {if (s[i] == 'a' + a) cnt++; } ans -= cnt * (cnt - 1) / 2; } cout << ans << endl; return 0; }
0