code_file1
stringlengths
80
4k
code_file2
stringlengths
91
4k
similar_or_different
int64
0
1
#include<iostream> #include <algorithm> #include <cmath> #include <set> #include<map> #include<cstring> #include<iomanip> #include <string> #include <vector> #include<unordered_map> #include<unordered_set> using namespace std; typedef long long unsigned llu; typedef long double ld; #define ll long long #define PI 3.14159265358979323846 #define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++) #define rFor(i, a, b, c) for (int i = (a); i >= (b); i -= (c)) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define fill(a, b) memset(a, b, sizeof(a)) #define IO ios_base::sync_with_stdio(false), cin.tie(0),cout.tie(0) const int mod = 1000000007; const ll inf = 1000000000009; ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a,ll b) { return a*b/gcd(a,b);} //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdoutn int main() { IO; int n{}; cin>>n; vector<int>v(n); For(i,0,n)cin>>v[i]; sort(all(v)); if(n==3)cout<<"1\n"; else { ll ans{}; For(i,0,n) { For(j,0,i) { For(k,0,j) { if((v[k] != v[j] && v[i] != v[j]) && v[k]+v[j]>v[i])ans++; } } } cout<<ans<<'\n'; } //system("pause"); return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <functional> #include <ctime> #include <fstream> #include <cmath> #include <limits> #include <chrono> #include <numeric> #include <type_traits> #include <iomanip> #include <float.h> #include <math.h> #include <cassert> #pragma warning (disable: 4996) using namespace std; using ll = long long; unsigned euclidean_gcd(unsigned a, unsigned b) { if (a < b) return euclidean_gcd(b, a); unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } ll ll_gcd(ll a, ll b) { if (a < b) return ll_gcd(b, a); ll r; while ((r = a % b)) { a = b; b = r; } return b; } struct UnionFind { vector <ll> par; vector <ll> siz; UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } ll root(ll x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; long long modpow(long long a, long long n, long long mod) { if (n < 0)return 0; long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } ll merge_cnt(vector<ll>& a) { int n = a.size(); if (n <= 1) { return 0; } ll cnt = 0; vector<ll> b(a.begin(), a.begin() + n / 2); vector<ll> c(a.begin() + n / 2, a.end()); cnt += merge_cnt(b); cnt += merge_cnt(c); int ai = 0, bi = 0, ci = 0; while (ai < n) { if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci])) { a[ai++] = b[bi++]; } else { cnt += n / 2 - bi; a[ai++] = c[ci++]; } } return cnt; } int main() { ll n; cin >> n; cout << 0 << endl; string s; cin >> s; if (s == "Vacant")return 0; else { ll ok = 0; ll ng = n; while (true) { ll mid = (ok + ng) / 2; cout << mid << endl; string t; cin >> t; if (t == "Vacant")return 0; if (!((t == s) ^ (ok % 2 == mid % 2))) { ok = mid; s = t; } else ng = mid; } } }
0
#include<iostream> #include<vector> #include<string> #include<algorithm> using namespace std; void print(string word,vector<string>& output) { int a,b; cin >> a >> b; output.push_back(word.substr(a,b-a+1)); } void reverse(string& word) { int a,b; cin >> a >> b; string temp = word.substr(a,b-a+1); reverse(temp.begin(),temp.end()); word.replace(a,b-a+1,temp); } void replace(string& word) { int a,b; string change; cin >> a >> b >> change; word.replace(a,b-a+1,change); } int main(int argc, char* argv[]) { string word,command; vector<string> output; int count; cin >> word >> count; for(int i=0;i<count;i++) { cin >> command; if(command=="print") print(word,output); else if(command=="reverse") reverse(word); else if(command=="replace") replace(word); } for(string n:output) { cout << n << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n; cin >> n; for(int i = 0; i < n; i++){ string op; int b, e; cin >> op; cin >> b >> e; if(op == "print"){ cout << s.substr(b, e-b+1) << endl; }else{ string x, y, z; x = s.substr(0, b); z = s.substr(e+1, s.size()-(e+1)); if(op == "replace"){ string r; cin >> y; }else{ y = s.substr(b, e-b+1); reverse(y.begin(), y.end()); } s = x + y + z; } } }
1
#include <iostream> #include <cctype> #include <cstdio> #include <string> #include <algorithm> #include <vector> #include <complex> #include <cstring> #include <set> using namespace std; #define loop(i,a,b) for(int i=a; i<b; i++) #define rep(i,a) loop(i,0,a) int input[1111][3]; int res[1111]; int main(){ int a,b,c; while(cin>>a>>b>>c && a){ int n; cin>>n; rep(i,n){ rep(j,3){ cin >> input[i][j]; } cin>>res[i]; } bool ok[1111]={}; bool bad[1111]={}; while(1){ bool fine = true; rep(i,n){ int a=0,b=0; int x,y,z; tie(x,y,z)=tie(input[i][0],input[i][1],input[i][2]); for(int j : {x,y,z}){ if(ok[j])a++; if(bad[j])b++; } if(res[i]){ if(a!=3){ ok[x]=ok[y]=ok[z]=true; fine = false; } }else{ if(a==2 && b!=1){ for(int j : {x,y,z}){ if(!ok[j])bad[j]=true; fine = false; } } } } if(fine) break; } for(int i=1;i<=a+b+c;i++){ if(ok[i] && !bad[i])cout<<1; else if(!ok[i] && bad[i])cout<<0; else cout<<2; cout<<endl; } } }
#include<cstdio> #include<cmath> #include<iostream> #include<algorithm> using namespace std; int main(){ while(1){ int A,B,C,N; cin>>A>>B>>C; if(A==0&&B==0&&C==0)break; cin>>N; int lis[1000][4]; for(int i=0;i<N;i++)cin>>lis[i][0]>>lis[i][1]>>lis[i][2]>>lis[i][3]; int che[301]; for(int i=1;i<=300;i++)che[i]=2; for(int i=0;i<N;i++){ if(lis[i][3]==1)che[lis[i][0]]=1,che[lis[i][1]]=1,che[lis[i][2]]=1; } for(int i=0;i<N;i++){ if(che[lis[i][0]]==1&&che[lis[i][1]]==1&&lis[i][3]==0)che[lis[i][2]]=0; if(che[lis[i][0]]==1&&che[lis[i][2]]==1&&lis[i][3]==0)che[lis[i][1]]=0; if(che[lis[i][1]]==1&&che[lis[i][2]]==1&&lis[i][3]==0)che[lis[i][0]]=0; } for(int i=1;i<=A+B+C;i++)cout<<che[i]<<endl; } return 0; }
1
#include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double db; #define pb push_back #define mp make_pair #define ub(v,val) upper_bound(v.begin(),v.end(),val)-v.begin() #define lb(v,val) lower_bound(v.begin(),v.end(),val)-v.begin() #define sortv(vec) sort(vec.begin(),vec.end()) #define rev(p) reverse(p.begin(),p.end()); #define v vector #define PI 3.1415926535 #define len length() #define repc(i,s,e) for(ll i=s;i<e;i++) #define np(str) next_permutation(str.begin(),str.end()) #define fi first #define se second #define mset(a,val) memset(a,val,sizeof(a)); #define mt make_tuple #define repr(i,n) for(i=n-1;i>=0;i--) #define rep(i,n) for( i=0;i<n;i++) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); const int M = 1e9 + 7; ll INF = 1e7; ll n, m; int main() { // your code goes here IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll i, j, k, x, y, N; char z; cin >> n; unordered_map<ll, v<ll>> u, d, l, r, u1, u2, r1, r2, l1, l2, d1, d2; rep(i, n) { cin >> x >> y >> z; if (z == 'U') { u[x].pb(y); u1[x - y].pb(x); u2[x + y].pb(x); } if (z == 'R') { r[y].pb(x); r1[(x - y)].pb(x); r2[x + y].pb(x); } if (z == 'D') { d[x].pb(y); d1[(x - y)].pb(x); d2[x + y].pb(x); } if (z == 'L') { l[y].pb(x); l1[(x - y)].pb(x); l2[x + y].pb(x); } } for (auto &dm : u) { sortv(dm.se); } for (auto &dm : u1) { sortv(dm.se); } for (auto &dm : u2) { sortv(dm.se); } for (auto &dm : r) { sortv(dm.se); } for (auto &dm : r1) { sortv(dm.se); } for (auto &dm : r2) { sortv(dm.se); } for (auto &dm : l) { sortv(dm.se); } for (auto &dm : l1) { sortv(dm.se); } for (auto &dm : l2) { sortv(dm.se); } for (auto &dm : d) { sortv(dm.se); } for (auto &dm : d1) { sortv(dm.se); } for (auto &dm : d2) { sortv(dm.se); } ll ans = INF; //u and d; for (auto dm : u) { x = dm.fi; for (auto dm2 : u[x]) { auto ind = upper_bound(d[x].begin(), d[x].end(), dm2); if (ind != d[x].end()) { ans = min(ans, (*ind - dm2) * 5); } } } //r and l for (auto dm : r) { y = dm.fi; for (auto dm2 : r[y]) { auto ind = upper_bound(l[y].begin(), l[y].end(), dm2); if (ind != l[y].end()) { ans = min(ans, (*ind - dm2) * 5); } } } //u and l for (auto dm : u1) { ll diff = dm.fi; for (auto dm2 : u1[diff]) { auto ind = upper_bound(l1[diff].begin(), l1[diff].end(), dm2); if (ind != l1[diff].end()) { ans = min(ans, (*ind - dm2) * 10); } } } //u and r for (auto dm : r2) { ll sum = dm.fi; for (auto dm2 : r2[sum]) { auto ind = upper_bound(u2[sum].begin(), u2[sum].end(), dm2); if (ind != u2[sum].end()) { ans = min(ans, (*ind - dm2) * 10); } } } //d and l for (auto dm : d2) { ll sum = dm.fi; for (auto dm2 : d2[sum]) { auto ind = upper_bound(l2[sum].begin(), l2[sum].end(), dm2); if (ind != l2[sum].end()) { ans = min(ans, (*ind - dm2) * 10); } } } //d and r for (auto dm : r1) { ll diff = dm.fi; for (auto dm2 : r1[diff]) { auto ind = upper_bound(d1[diff].begin(), d1[diff].end(), dm2); if (ind != d1[diff].end()) { ans = min(ans, (*ind - dm2) * 10); } } } if (ans == INF) cout << "SAFE"; else cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int x[200005], y[200005], d[200005]; vector<int> U[200005], D[200005], R[200005], L[200005]; vector<int> UL1[400005], UL2[400005]; vector<int> UR1[400005], UR2[400005]; vector<int> DL1[400005], DL2[400005]; vector<int> DR1[400005], DR2[400005]; int main(){ int n; scanf("%d", &n); for(int i=1;i<=n;i++){ char s[2]; scanf("%d%d%s", &x[i], &y[i], s); if(s[0] == 'U'){ d[i] = 0; U[x[i]].emplace_back(y[i]); UL1[x[i]-y[i]+200000].emplace_back(y[i]); UR1[x[i]+y[i]].emplace_back(y[i]); } else if(s[0] == 'D'){ d[i] = 1; D[x[i]].emplace_back(y[i]); DL1[x[i]+y[i]].emplace_back(y[i]); DR1[x[i]-y[i]+200000].emplace_back(y[i]); } else if(s[0] == 'R'){ d[i] = 2; R[y[i]].emplace_back(x[i]); UR2[x[i]+y[i]].emplace_back(y[i]); DR2[x[i]-y[i]+200000].emplace_back(y[i]); } else{ d[i] = 3; L[y[i]].emplace_back(x[i]); UL2[x[i]-y[i]+200000].emplace_back(y[i]); DL2[x[i]+y[i]].emplace_back(y[i]); } } for(int i=0;i<=200000;i++){ sort(U[i].begin(), U[i].end()); sort(D[i].begin(), D[i].end()); sort(R[i].begin(), R[i].end()); sort(L[i].begin(), L[i].end()); } for(int i=0;i<=400000;i++){ sort(UL1[i].begin(), UL1[i].end()); sort(UL2[i].begin(), UL2[i].end()); sort(UR1[i].begin(), UR1[i].end()); sort(UR2[i].begin(), UR2[i].end()); sort(DL1[i].begin(), DL1[i].end()); sort(DL2[i].begin(), DL2[i].end()); sort(DR1[i].begin(), DR1[i].end()); sort(DR2[i].begin(), DR2[i].end()); } int ans = 1e9; for(int i=0;i<=200000;i++){ for(int j=0;j<U[i].size();j++){ int y = U[i][j]; int k = lower_bound(D[i].begin(), D[i].end(), y) - D[i].begin(); if(k == D[i].size()) continue; ans = min(ans, (D[i][k]-y)*5); } for(int j=0;j<R[i].size();j++){ int x = R[i][j]; int k = lower_bound(L[i].begin(), L[i].end(), x) - L[i].begin(); if(k == L[i].size()) continue; ans = min(ans, (L[i][k]-x)*5); } } for(int i=0;i<=400000;i++){ for(int j=0;j<UL1[i].size();j++){ int y = UL1[i][j]; int k = lower_bound(UL2[i].begin(), UL2[i].end(), y) - UL2[i].begin(); if(k == UL2[i].size()) continue; ans = min(ans, (UL2[i][k]-y)*10); } for(int j=0;j<UR1[i].size();j++){ int y = UR1[i][j]; int k = lower_bound(UR2[i].begin(), UR2[i].end(), y) - UR2[i].begin(); if(k == UR2[i].size()) continue; ans = min(ans, (UR2[i][k]-y)*10); } for(int j=0;j<DL1[i].size();j++){ int y = DL1[i][j]; int k = lower_bound(DL2[i].begin(), DL2[i].end(), y) - DL2[i].begin() - 1; if(k < 0) continue; ans = min(ans, (y-DL2[i][k])*10); } for(int j=0;j<DR1[i].size();j++){ int y = DR1[i][j]; int k = lower_bound(DR2[i].begin(), DR2[i].end(), y) - DR2[i].begin() - 1; if(k < 0) continue; ans = min(ans, (y-DR2[i][k])*10); } } if(ans == 1e9) printf("SAFE\n"); else printf("%lld\n", ans); }
1
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; int main(){ int a,b,c,k; cin >> a >> b >> c >> k; int mn = max(a,max(b,c)); int ans = a + b + c - mn + pow(2,k) * mn; cout << ans << endl; }
#include <iostream> #include <fstream> #include <set> #include <map> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <functional> #include <algorithm> #include <climits> #include <cmath> #include <iomanip> using namespace std; #define ll long long int #define rep(i,n) for( int i = 0; i < n; i++ ) #define rrep(i,n) for( int i = n; i >= 0; i-- ) #define REP(i,s,t) for( int i = s; i <= t; i++ ) #define RREP(i,s,t) for( int i = s; i >= t; i-- ) #define dump(x) cerr << #x << " = " << (x) << endl; #define INF 2000000000 #define mod 1000000007 #define INF2 1000000000000000000 int main(void) { cin.tie(0); ios::sync_with_stdio(false); int A[3]; rep(i, 3) cin >> A[i]; int K; cin >> K; sort(A, A + 3); rep(i, K) A[2] *= 2; cout << A[0] + A[1] + A[2] << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main(){ int a, b; int ans = 0; cin >> a >> b; string s; string r_s = ""; for (int num = a; num < b + 1; num ++){ r_s = ""; s = to_string(num); for (int i = 0; i < s.size(); i ++){ r_s += s[s.size() - 1 - i]; } if (s == r_s){ ans += 1; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long using vec_int = vector<int>; using P = pair<int,int>; using T = tuple<int,int,int>; using ll = long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) static long Gcd(long m, long n) { long temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } int charToInt(char c){ char zero_num = '0'; return (int)c - (int)zero_num; } map< int, int > prime_factor(int n) { map< int, int > ret; for(int64_t i = 2; i * i <= n; i++) { while(n % i == 0) { ret[i]++; n /= i; } } if(n != 1) ret[n] = 1; return ret; } signed main(){ int A, B;cin>>A>>B; int gcd = Gcd(A,B); /* vec_int factors; for(int i=1;i*i<=gcd;i++){ if(gcd%i==0){ factors.push_back(i); factors.push_back(gcd/i); } } sort(factors.begin(), factors.end()); */ map<int, int> pfs = prime_factor(gcd); cout<<pfs.size()+1<<endl; return 0; }
0
#include<bits/stdc++.h> using namespace std; const int N=1001000; int n; char s[N],t[N]; deque<int> deq; int main(){ cin>>n; scanf("%s%s",s+1,t+1); int he=0,ta=1,l=n+1,tag=0,ans=0; deq.push_back(n+1); for(int i=n;i;--i){ int tmp=l; while(l&&(l>i||s[l]!=t[i])) --l; if(!l) return puts("-1")&0; if(tmp==l){ while(!deq.empty()&&deq.back()-tag>=i) deq.pop_back(); deq.push_back(i+tag); } else{ ++tag; if(l!=i) ans=max(ans,(int)deq.size()),deq.push_front(l+tag); } } cout<<ans<<endl; return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #define CLR(x) memset((x), false, sizeof(x)) const int MAXD = 12801; const int MAXN = 81; int A[2][MAXN][MAXN]; bool dp[MAXN][MAXN][MAXD]; int H, W; int solve() { CLR(dp); dp[0][0][0] = true; dp[0][1][0] = true; dp[1][0][0] = true; for (int i = 1; i <= H; ++i) { for (int j = 1; j <= W; ++j) { for (int k = 0; k < MAXD; ++k) { int d = std::abs(A[0][i][j] - A[1][i][j]); int nk1 = k + d; if (nk1 < MAXD) { dp[i][j][k] |= dp[i-1][j][nk1] | dp[i][j-1][nk1]; } int nk2 = std::abs(k - d); dp[i][j][k] |= dp[i-1][j][nk2] | dp[i][j-1][nk2]; } } } for (int k = 0; k < MAXD; ++k) { if (dp[H][W][k]) { return k; } } return -1; } int main() { scanf(" %d%d", &H, &W); for (int k = 0; k < 2; ++k) { for (int i = 1; i <= H; ++i) { for (int j = 1; j <= W; ++j) { scanf("%d", &A[k][i][j]); } } } printf("%d\n", solve()); return 0; }
0
#include <bits/stdc++.h> #define rep(i , n) for(int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; int main (){ ll N, L[2]{}; cin >> N; set <int> S; while (cin >> N) { if (!S.insert(N).second) { S.erase(N); if (N > L[0]){ L[1] = L[0], L[0] = N; } else if(N > L[1]){ L[1] = N; } } } cout << L[0] * L[1] << endl; }
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; unordered_map<long long, int> mp; for (int i = 0; i < n; i++) { int x; cin >> x; mp[x]++; } vector<long long> ans(2); for (auto p : mp) { for (int i = 0; i < 2; i++) { if(p.second < 2) break; if (p.first > ans[i]) { ans[i] = p.first; p.second -= 2; } } sort(ans.begin(), ans.end()); debug(ans); } cout << ans[0] * ans[1]; return 0; }
1
#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<ll> a(n); for(auto &x:a)cin >> x; int ans=-1; for(int i=0;i<30;i++){ for(int j=0;j<n;j++){ if(a[j]%2==1){ ans=i; break; } a[j]=a[j]/2; } if(ans!=-1)break; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, min_count; cin >> n; min_count = 200; for (int i=0; i<n; i++) { int a, count = 0; cin >> a; if (a % 2 == 1) { min_count = 0; break; } while (a % 2 == 0) { a /= 2; count += 1; } if (min_count > count) min_count = count; } cout << min_count << endl; }
1
#include <iostream> #include <algorithm> #include<string> #include<vector> int main() { int ining; std::cin >> ining; std::string s; for (int i = 0; i < ining; ++i) { int co = 0; int ch = 0; int c = 0; while (std::cin >> s) { if (s == "OUT") { ++co; } if (co == 3) { break; } if (s == "HIT") { ++ch; } if (ch == 4) { --ch; ++c; } if (s == "HOMERUN") { c += ch + 1; ch = 0; } } std::cout << c << std::endl; } }
#include<iostream> #include<string> #include<algorithm> #include<map> #include<set> #include<utility> #include<vector> #include<cmath> #include<cstring> #include<cstdio> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) #define rp(a) while(a--) #define pb push_back #define mp make_pair #define all(in) in.begin(),in.end() const double PI=acos(-1); const double EPS=1e-10; using namespace std; typedef long long ll; typedef vector<int> vi; int main(){ int n; while(cin>>n,n){ vector<int>in(n+1); rep(i,n)cin>>in[i+1]; n++; loop(i,1,n)in[i]+=in[i-1]; int ma=-1e9; rep(i,n)loop(j,i+1,n)ma=max(ma,in[j]-in[i]); cout<<ma<<endl; } }
0
#include<iostream> using namespace std; int main() { int a,b,c,d; cin>>a; cin>>b; cin>>c; cin>>d; if(a<=b){ if(c<=d){ cout<<a+c; } else{ cout<<a+d; } } else{ if(c<=d){ cout<<b+c; } else{ cout<<b+d; } } }
#include <bits/stdc++.h> #include <ctime> #define rep(i,a,b) for(int i =a;i<b;i++) using namespace std; typedef unsigned long long ll; inline int cine() {int a; return scanf("%d", &a) ? a : 1e9;} void solve() { int train, bus, mine = 1e9, sum = 0 ; rep(i, 0, 2) { cin >> train; mine = min(mine, train); } sum += mine; mine = 1e9; rep(i, 0, 2) { cin >> bus; mine = min(mine, bus); } sum += mine; cout << sum; } int main() { #ifndef ONLINE_JUDGE freopen("i.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif solve(); #ifndef ONLINE_JUDGE cout << "\nTime Elapsed :" << 0.1 * clock() / CLOCKS_PER_SEC << "s\n"; #endif }
1
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define inf 1000000000 #define IOS ios_base::sync_with_stdio(0);cin.tie(0) #define meM(y,a) memset(y,a,sizeof y) #define sC(a) scanf("%d",&a) #define alL(a) a.begin(),a.end() #define prinT(a,sz) cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl #define ranD srand(chrono::steady_clock::now().time_since_epoch().count()); typedef pair<int,int>pi; typedef pair<ll,ll>pll; //int fx[]={0,0,1,-1}; //int fy[]={1,-1,0,0}; //int gx[]={0,0,1,1,1,-1,-1,-1}; //int gy[]={1,-1,0,1,-1,0,1,-1}; const int N=100010; int ara[N]; int main() { IOS; int n,k;cin>>n>>k; for(int i=1;i<=n;i++) cin>>ara[i]; int ans=inf; for(int i=k;i<=n;i++) { if(ara[i]>0&&ara[i-k+1]<0){ int sum=ara[i]-ara[i-k+1]; int f1=sum+ara[i]; int f2=sum-ara[i-k+1]; // cout<<i<<" "<<f1<<" "<<f2<<endl; ans=min(ans,min(f1,f2)); } else { int sum; if(ara[i]<0)sum=abs(ara[i-k+1]); else sum=ara[i]; ans=min(ans,sum); } } cout<<ans<<endl; } /* 8 7 -10 -4 -2 0 5 6 8 13 8 5 -15 -12 -8 -7 -4 -1 8 15 */
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<cmath> #include<bitset> #include<deque> #include<functional> #include<iterator> #include<map> #include<set> #include<stack> #include<queue> #include<utility> using namespace std; typedef long long ll; typedef pair<ll,ll> P; #define a first #define b second #define sz(x) (ll)((x).size()) #define pb push_back #define mp make_pair #define bg begin() #define ed end() #define all(x) (x).bg,(x).ed #define rep(i,n) for(ll i=0;i<(n);i++) #define rep1(i,n) for(ll i=1;i<=(n);i++) #define rrep(i,n) for(ll i=(n)-1;i>=0;i--) #define rrep1(i,n) for(ll i=(n);i>=1;i--) #define FOR(i,a,b) for(ll i=(a);i<(b);i++) const ll MOD=1000000007; const ll INF=1000000000000000; template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;} template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;} ll maxx(ll x,ll y,ll z){return max(max(x,y),z);} ll minn(ll x,ll y,ll z){return min(min(x,y),z);} ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);} ll lcm(ll x,ll y){return x*(y/gcd(x,y));} ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}} ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;} vector<ll> pw2(62,1);vector<ll> pw10(19,1); ll dx[8]={0,0,-1,1,-1,1,-1,1}; ll dy[8]={1,-1,0,0,1,1,-1,-1}; vector<vector<ll> > c(10,vector<ll>(10,0)); int main(){ {rep1(i,61) pw2[i]=2*pw2[i-1];} {rep1(i,18) pw10[i]=10*pw10[i-1];} ll N,K; cin>>N>>K; vector<ll> minus; vector<ll> plus; vector<ll> zero; rep(i,N){ ll x; cin>>x; if(x<0) minus.pb(x); else if(x==0) zero.pb(x); else plus.pb(x); } ll m=sz(minus),p=sz(plus),need=K-sz(zero); minus.pb(0); plus.pb(0); sort(all(minus),greater<ll>()); sort(all(plus)); ll ans=INF; rep(i,min(need,m)+1){ if(need-i > p) continue; ll X=-minus[i]; ll Y=plus[need-i]; chmin(ans,max(X,Y)+min(X,Y)*2); } cout<<ans<<endl; }
1
#include <bits/stdc++.h> using namespace std; int main () { long long N; cin >> N; long long M = 1; for (long long i = 2; i <= sqrt(N); i++) { if (N % i == 0){ M = i; } } long long L = max(M,N/M); int count = 0; for (int i = 0; i < 11; i++) { count++; if (L / 10 == 0){ cout << count << endl; return 0; } L /= 10; } }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n"); template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; using P = pair<int,int>; using ll = long long; const ll INF = 1LL<<60; const double PI = 3.1415926535897932; const int MOD = 1e9 + 7; 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; } //cin.tie(0);ios::sync_with_stdio(false); int main() { ll n; cin >> n; if (n == 1) { cout << 1 << endl; return 0; } vector<ll> primes; for (auto v : prime_factorize(n)) { for (ll i = 0; i < v.second; i++) { primes.push_back(v.first); } } vector<ll> ans; ll tmp1, tmp2; for (int bit = 0; bit < 1 << primes.size(); bit++) { tmp1 = tmp2 = 1; for (int j = 0; j < primes.size(); j++) { if (bit & 1 << j) { tmp1 *= primes[j]; } else { tmp2 *= primes[j]; } } ans.push_back(max(to_string(tmp1).size(), to_string(tmp2).size())); } cout << *min_element(ans.begin(), ans.end()) << endl; return 0; }
1
#include <stdio.h> #include <stdbool.h> int main(void) { bool flag = true; int cnt = 0; int n; scanf("%d", &n); int x[n]; for(int i = 0; i < n; i++){ scanf("%d", &x[i]); } while(flag){ flag = false; for(int i = n - 1; i >= 0; i--){ if(x[i] < x[i - 1]){ int temp = x[i]; x[i] = x[i - 1]; x[i - 1] = temp; cnt++; flag = true; } } } for(int i = 0; i < n - 1; i++){ printf("%d ", x[i]); } printf("%d\n%d\n", x[n - 1], cnt); return 0; }
#include <bits/stdc++.h> #define rep(i , n) for (int i = 0; i < (int)(n); i++) const int INF = 1<<29; using namespace std; using ll = long long; int n, sum, y, a[105]; double g, t = 1e9; int main(){ cin >> n; for(int i = 0; i < n; i++){ cin >> a[i]; sum += a[i]; } g = 1.0 * sum / n; for(int i = 0; i < n; i++) { if(abs(a[i] - g) < t){ t = abs(a[i] - g); y = i; } } cout << y << endl;; }
0
#include <bits/stdc++.h> #define INF 2e9 #define MOD 1000000007 #define MOD9 998244353 #define intMAX 51000; #define PI 3.14159265359 using namespace std; typedef long long llong; typedef long double ldouble; using Graph = vector<vector<int>>; int main(){ int N, M, X, Y; cin >> N >> M >> X >> Y; int maxx = -101; int miny = 101; for(int i=0; i<N; ++i){ int x; cin >> x; maxx = max(maxx, x); } for(int i=0; i<M; ++i){ int y; cin >> y; miny = min(miny, y); } maxx = max(maxx, X); miny = min(miny, Y); if(maxx<miny) cout << "No War" << endl; else cout << "War" << endl; }
#include <iostream> #include <vector> void printArray(std::vector<int> a) { int n = (int)a.size(); for (int i = 0; i < n; i++) { std::cout << a[i] <<std::endl; } } int insertionSort(std::vector<int> &a, int g) { int cnt = 0, n = (int)a.size(); for (int i = g; i < n; i++) { int v = a[i]; int j = i - g; while (j >= 0 && a[j] > v) { a[j + g] = a[j]; j = j - g; cnt++; } a[j + g] = v; } return cnt; } int shellSort(std::vector<int> &a) { std::vector<int> g; for (int i = 1; i <= (int)a.size(); i = i * 3 + 1) { g.push_back(i); } int m = (int)g.size(); std::cout << m << std::endl; int cnt = 0; for (int i = m - 1; i >= 0; i--) { cnt += insertionSort(a, g[i]); std::cout << g[i]; if (i > 0) std::cout << " "; else std::cout << std::endl; } return cnt; } int main() { int n; std::cin >> n; std::vector<int> a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; } std::cout << shellSort(a) << std::endl; printArray(a); }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 1e9; int main() { int n = 0; fscanf(stdin, "%d", &n); vector<ll> rows(n + 5), cols(n + 5); for (int i = 0; i < n; ++i) { fscanf(stdin, "%lld %lld", &rows[i + 1], &cols[i + 1]); } vector<vector<ll> > dp(n + 5, vector<ll>(n + 5, 0)); for (int l = 2; l <= n; ++l) { for (int i = 1; i <= n - l + 1; ++i) { int j = l + i - 1; dp[i][j] = std::numeric_limits<ll>::max(); for (int k = i; k <= j - 1; ++k) { dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + rows[i] * cols[k] * cols[j]); } } } fprintf(stdout, "%lld\n", dp[1][n]); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int M=18,mod=1000000007; int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;} int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;} int mul(int a,int b,int p=mod){return (LL)a*b%p;} void sadd(int &a,int b,int p=mod){a=add(a,b,p);} void ssub(int &a,int b,int p=mod){a=sub(a,b,p);} void smul(int &a,int b,int p=mod){a=mul(a,b,p);} int Power(int a,int k,int p=mod){int res=1;for (;k;k>>=1,smul(a,a,p)) if (k&1) smul(res,a,p);return res;} int n,m,a[3]; void into(){ scanf("%d%d%d%d",&n,&a[0],&a[1],&a[2]); a[1]+=a[0];m=max(a[2]+=a[1],10); } int dp[2][(1<<M)+9],old,now,ans; void Get_dp(){ old=1;now=0; dp[now][0]=1; for (int i=1;i<=n;++i){ old^=1;now^=1; for (int g=0;g<1<<m;++g) dp[now][g]=0; for (int g=0;g<1<<m;++g) for (int j=1;j<=10;++j){ int t=(g&(1<<m-j)-1)<<j|1<<j-1; if (t>>a[0]-1&1&&t>>a[1]-1&1&&t>>a[2]-1&1) continue; sadd(dp[now][t],dp[old][g]); } } for (int g=0;g<1<<m;++g) sadd(ans,dp[now][g]); } void work(){ Get_dp(); } void outo(){ printf("%d\n",sub(Power(10,n),ans)); } int main(){ into(); work(); outo(); return 0; }
0
#include<bits/stdc++.h> using namespace std; const int maxn=100010,mod=998244353; const char str[2][10]={"First","Second"}; #define lson o<<1,l,mid #define rson o<<1|1,mid+1,r #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define ROF(i,a,b) for(int i=(a);i>=(b);i--) #define MEM(x,v) memset(x,v,sizeof(x)) inline int read(){ int x=0,f=0;char ch=getchar(); while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar(); while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar(); return f?-x:x; } int n,a[maxn]; int gcd(int x,int y){return y?gcd(y,x%y):x;} int main(){ n=read(); FOR(i,1,n) a[i]=read(); int t=0; while(true){ int cnt1=0,cnte=0; FOR(i,1,n){ if(a[i]==1) cnt1++; if(a[i]%2==0) cnte++; } if(cnte!=n-1 || cnt1==1){puts(cnte%2?str[t]:str[t^1]);break;} FOR(i,1,n) if(a[i]%2!=0){a[i]--;break;} int g=0; FOR(i,1,n) g=gcd(g,a[i]); FOR(i,1,n) a[i]/=g; t^=1; } } // coming soon 2020.5.11
#include<iostream> #include<cmath> #include<vector> #include<string> #include<cstdio> typedef unsigned long long ull; #define rep(i,a) for(int i=0;i<a;i++) #define loop(i,a,b) for(int i=a;i<b;i++) using namespace std; const double eps = 1e-10; const double pi = acos(-1); const double inf = (int)1e8; int main(void){ string str; int base=0,point=0,out=0; int n; cin>>n; getline(cin,str); while(getline(cin,str)){ if(str[0] == 'O'){ out++; //cout<<out<<endl; if(out==3){ n--; printf("%d\n",point); base=0,point=0,out=0; if(n==0)break; } } else if(str[1] == 'I'){ base ++; if(base>3){ base --; point ++; } } else if(str[1] == 'O'){ point += base + 1; base = 0; } } return 0; }
0
#include <cstdio> #include <iostream> #include <string> #include <vector> #include <map> #include <algorithm> using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; const int INF = 1e9+7; #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() #define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++) #define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++) #define repab(i,a,b) for(auto i=a;i<(b);i++) #define rep(i,b) for(auto i=0;i<(b);i++) #define pb push_back #define sz(c) int((c).size()) enum { FOUR_CARD, FULL_HOURSE, STRAIGHT, THREE_CARD, TWO_PAIR, ONE_PAIR, NULL_HAND, } hands; int check(map<int, int> m) { int maxnr = 0; int minnr = INF; int maxv = 0; int minv = INF; int maxnr_count = 0; tr (m, i) { if (maxnr < i->second) { maxnr_count=1; maxnr = i->second; } else if (maxnr == i->second) { maxnr_count++; } minnr = min(minnr, i->second); maxv = max(maxv, i->first); minv = min(minv, i->first); } if (maxnr == 4) return FOUR_CARD; if (maxnr == 3 && minnr == 2) return FULL_HOURSE; if (minnr == 1 && maxnr == 1) { if ((maxv - minv == 4) || (m[10] && m[11] && m[12] && m[13] && m[1])) return STRAIGHT; } if (maxnr == 3) return THREE_CARD; if (maxnr == 2) { if (maxnr_count == 2) return TWO_PAIR; else return ONE_PAIR; } return NULL_HAND; } void phand(map<int, int> m) { vector<string> hand_name = { "four card", "full house", "straight", "three card", "two pair", "one pair", "null", }; cout << hand_name[check(m)] << endl; } int main(int argc, char **argv) { vi v; map<int, int> m; char c; int x, minval; for (;;) { v.clear(); m.clear(); rep (i, 4) { cin >> x; cin >> c; v.pb(x); } cin >> x; v.pb(x); if (cin.eof()) break; rep (i, 5) { m[v[i]]++; } phand(m); } return 0; }
#include <iostream> #include <vector> #include <cstdio> #include <algorithm> #include <set> #include <map> #include <cassert> #include <numeric> #include <string> #include <cstring> #include <cmath> using namespace std; #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif typedef long long int int64; const int N = (int) 1e5 + 100; vector <int> ch[N]; int k; struct Ans { vector <int> v; Ans() : v({0}) {} void eprint() { for (int i = 0; i < min(k + 1, (int) v.size()); i++) eprintf("[%d] %d, ", i, v[(int) v.size() - 1 - i]); eprintf("\n"); } }; Ans dp[N]; int merge(int a, int b) { if ((int) dp[a].v.size() < (int) dp[b].v.size()) swap(a, b); for (int i = 0; i < (int) dp[b].v.size(); i++) dp[a].v[(int) dp[a].v.size() - 1 - i] += dp[b].v[(int) dp[b].v.size() - 1 - i]; return a; } int goUp(int a) { dp[a].v.push_back(1); if ((int) dp[a].v.size() >= k + 1) dp[a].v.back() += dp[a].v[(int) dp[a].v.size() - k - 1]; int i = 2; while (i <= (int) dp[a].v.size() && dp[a].v[(int) dp[a].v.size() - i] > dp[a].v.back()) { dp[a].v[(int) dp[a].v.size() - i] = dp[a].v.back(); i++; } return a; } int solve(int v) { int cur = v; for (int to : ch[v]) { int nx = solve(to); cur = merge(cur, nx); } //eprintf("(%d): ", v); dp[cur].eprint(); if (v != 0) cur = goUp(cur); //eprintf("(%d'): ", v); dp[cur].eprint(); return cur; } int a[N]; int main(int, char **) { #ifdef LOCAL freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif int n; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); a[i]--; } for (int i = 1; i < n; i++) ch[a[i]].push_back(i); int id = solve(0); int ans = dp[id].v[max(0, (int) dp[id].v.size() - k - 1)]; if (a[0] != 0) ans++; printf("%d\n", ans); return 0; }
0
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<cassert> #include<iostream> #include<sstream> #include<string> #include<vector> #include<queue> #include<set> #include<map> #include<utility> #include<numeric> #include<algorithm> #include<bitset> #include<complex> using namespace std; typedef long long Int; typedef vector<int> vint; typedef pair<int,int> pint; #define mp make_pair template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template<class T> void chmin(T &t, T f) { if (t > f) t = f; } template<class T> void chmax(T &t, T f) { if (t < f) t = f; } int in() { int x; scanf("%d", &x); return x; } int meiro[110][110]; int cc; int w,h; int xx[]={1,-1,0,0}; int yy[]={0,0,1,-1}; void dfs(int x,int y){ meiro[y][x]=-1; int i; for(i=0;i<4;i++){ if(x+xx[i]<0||w<=x+xx[i]||y+yy[i]<0||h<=y+yy[i])continue; if(meiro[y+yy[i]][x+xx[i]]!=cc)continue; dfs(x+xx[i],y+yy[i]); } } int main() { int xs,ys,xg,yg,n,c,d,x,y; while(w=in(),h=in()){ cin>>xs>>ys>>xg>>yg>>n; xs--;ys--;xg--;yg--; int i; memset(meiro,0,sizeof(meiro)); for(i=0;i<n;i++){ cin>>c>>d>>x>>y; x--;y--; //cout<<c<<" "<<d<<" "<<x<<" "<<y<<endl; if(d==0){ meiro[y][x]=meiro[y][x+1]=meiro[y][x+2]=meiro[y][x+3]=meiro[y+1][x]=meiro[y+1][x+1]=meiro[y+1][x+2]=meiro[y+1][x+3]=c; }else{ meiro[y][x]=meiro[y][x+1]=meiro[y+1][x]=meiro[y+1][x+1]=meiro[y+2][x]=meiro[y+2][x+1]=meiro[y+3][x]=meiro[y+3][x+1]=c; } } if(meiro[ys][xs]==0){ cout<<"NG\n"; continue; } cc=meiro[ys][xs]; //cout<<"hoge\n"; dfs(xs,ys); //cout<<"piyo\n"; if(meiro[yg][xg]==-1)cout<<"OK\n"; else cout<<"NG\n"; } return 0; }
#include<bits/stdc++.h> #define pf(x) x*x using namespace std; int n, d[2], col[2][360007]; vector<pair<int, int> >e[2]; int id(int a, int b) { return a * 2 * n + b; } int check(int pos) { return pos >= 0 && pos < 2 * n; } int dfs(int p, int a, int b) { for (int i = 0, lim = e[p].size(); i < lim; i++) { int c = a + e[p][i].first, d = b + e[p][i].second; if (!check(c) || !check(d))continue; if (!col[p][id(c, d)]) { col[p][id(c, d)] = -col[p][id(a, b)]; dfs(p, c, d); } } return 0; } int main() { cin >> n >> d[0] >> d[1]; for (int p = 0; p <= 1; p++) for (int x = 0; x <= d[p]; x++) { int y = sqrt(d[p] - x * x); if (x * x + y * y != d[p])continue; e[p].push_back(make_pair(x, y)); e[p].push_back(make_pair(-x, y)); e[p].push_back(make_pair(x, -y)); e[p].push_back(make_pair(-x, -y)); } for (int i = 0; i < 2 * n; i++) for (int j = 0; j < 2 * n; j++) for (int p = 0; p <= 1; p++) if (!col[p][id(i, j)]) { col[p][id(i, j)] = 1; dfs(p, i, j); } int now,haha; int tot = 0; for (int i = 0; i < 2 * n; i++) for (int j = 0; j < 2 * n; j++) if (col[0][id(i, j)] == 1 && col[1][id(i, j)] == 1) { printf("%d %d\n", i, j); if (++tot == n * n)return 0; } return 0; }
0
#include<cstdio> #include<algorithm> #include<functional> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; int main(){ for(int n,m;scanf("%d%d",&n,&m),n;){ int p[1000]; rep(i,n) scanf("%d",p+i); sort(p,p+n,greater<int>()); int total=0; rep(i,n) if((i+1)%m!=0) total+=p[i]; printf("%d\n",total); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vb> vvb; typedef pair<int, int> pii; typedef long long ll; typedef unsigned long long ull; #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(), (a).rend() #define pb push_back #define mp make_pair #define loop(i,a,b) for(ull i=(a);i<ull(b);++i) #define rep(i,n) loop(i,0,n) #define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i) #define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i) const double eps = 1e-10; const double pi = acos(-1.0); const double inf = (int)1e8; namespace std { template<typename T>ostream&operator<<(ostream&os, vector<T>const&v){ iter(it,v) os<<*it<<(it+1==v.end()?"":","); return os; } template<typename T, typename U>ostream&operator<<(ostream&os,const pair<T,U>&p){ return os << "[" << p.dirst << "," << p.second << "]"; } } #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main(){ int m, n; while(cin>>n>>m && m|n){ vi p(n); int free = 0; int sum = 0; rep(i,n){ cin >> p[i]; sum += p[i]; } sort(all(p)); // テ」ツ??」ツ?暗」ツ?凝」ツつ? for(int i=n-m;i>=0;i-=m)free+=p[i]; cout << sum - free << endl; } }
1
#include <cstdio> #include <cstring> #include <iostream> #include <queue> using namespace std; int main(){ while(1){ int n, m, k; int t[2][101][101]; scanf(" %d %d", &n, &m); if(n==0) break; memset(t, -1, sizeof(t)); for(int i=0; i<n; ++i){ int a, b, time, cost; scanf(" %d %d %d %d", &a, &b, &cost, &time); t[0][a][b]=t[0][b][a]=cost; t[1][a][b]=t[1][b][a]=time; } scanf(" %d", &k); for(int i=0; i<k; ++i){ int p, q, r; scanf(" %d %d %d", &p, &q, &r); long a[101]; //各駅までの最小値 for(int j=0; j<=100; ++j) a[j]=50000000; //bfs queue<int> que; a[p]=0; que.push(p); while( !que.empty() ){ int v=que.front(); que.pop(); for(int j=1; j<=m; ++j){ if(t[r][v][j]>=0 && a[j]>t[r][v][j]+a[v]){ a[j]=t[r][v][j]+a[v]; que.push(j); } } } printf("%ld\n",a[q]); } } }
#include<iostream> #include<stdio.h> using namespace std ; int n , m ; int data[101][101][2] ; void f(){ for( int k=1 ; k<=m ; k++ ){ for( int i=1 ; i<=m ; i++ ){ for( int j=1 ; j<=m ; j++ ){ if( data[i][j][0] > data[i][k][0] + data[k][j][0] ){ data[i][j][0] = data[i][k][0] + data[k][j][0] ; } if( data[i][j][1] > data[i][k][1] + data[k][j][1] ){ data[i][j][1] = data[i][k][1] + data[k][j][1] ; } } } } } int main(){ int a , b ; int k , r ; while(1){ cin >> n >> m ; if( n==0 && m==0 ) break ; for( int i=0 ; i<101 ; i++ ){ for( int j=0 ; j<101 ; j++ ){ data[i][j][0] = 100000000 ; data[i][j][1] = 100000000 ; } data[i][i][0] = 0 ; data[i][i][1] = 0 ; } for( int i=0 ; i<n ; i++ ){ cin >> a >> b ; cin >> data[a][b][0] >> data[a][b][1] ; data[b][a][0] = data[a][b][0] ; data[b][a][1] = data[a][b][1] ; } f() ; /*for( int i=1 ; i<m ; i++ ){ for( int j=1 ; j<m ; j++ ){ printf("data[%d][%d][0] = %d\n" ,i ,j ,data[i][j][0] ) ; printf("data[%d][%d][1] = %d\n" ,i ,j ,data[i][j][1] ) ; } }*/ cin >> k ; //cout << "k=" << k << endl ; for( int i=0 ; i<k ; i++ ){ cin >> a >> b >> r ; cout << data[a][b][r] << endl ; } } return 0 ; }
1
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(int)n;i++) int main() { int A, B, C; cin >> A >> B >> C; vector<int> ac(A); vector<int> bc(B); int minA = 1<<30, minB = 1<<30; rep(i, A) { cin >> ac.at(i); minA = min(minA, ac.at(i)); } rep(j, B) { cin >> bc.at(j); minB = min(minB, bc.at(j)); } int ans = minA + minB; rep(i, C) { int m; int tmp=0; cin >> m; tmp += ac.at(m-1); cin >> m; tmp += bc.at(m - 1); cin >> m; tmp -= m; ans = min(ans, tmp); } cout << ans << endl; }
#include <iostream> #include <algorithm> using namespace std; int main(){ int A, B, M; cin >> A >> B >> M; int a[A], b[B], c[M]; for (int i = 0; i < A; i++){ cin >> a[i]; } for (int i = 0; i < B; i++){ cin >> b[i]; } for (int i = 0; i < M; i++){ int x, y; cin >> x >> y >> c[i]; c[i] = a[x-1] + b[y-1] - c[i]; } sort(a, a+A); sort(b, b+B); sort(c, c+M); if (a[0] + b[0] > c[0]){ printf("%d\n", c[0]); }else{ printf("%d\n", a[0] + b[0]); } }
1
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; #define int ll #define REP(i,n) for (int i = 0; i < (n); ++i) #define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++) #define ALL(vec) (vec).begin(), (vec).end() #define REVALL(vec) (vec).rbegin(), (vec).rend() #define debug(x) cerr << #x << ": " << x << '\n' #define hyphen() cerr << "--\n" #define fst first #define pb push_back const int MOD = (int)1e9 + 7; int bigger(int a, int b) { return a >= b ? a : b; } int smaller(int a, int b) { return a >= b ? b : a; } signed main() { int N; cin >> N; vector<int> As(N); vector<int> Bs(N); REP(i, N) { cin >> As.at(i) >> Bs.at(i); } // (priority, score, ind) vector<tuple<int, int, int>> sorted_for_a(N); vector<tuple<int, int, int>> sorted_for_b(N); REP(i, N) { int a = As.at(i); int b = Bs.at(i); int priority = a + b; tuple<int, int, int> ta = make_tuple(priority, a, i); tuple<int, int, int> tb = make_tuple(priority, b, i); sorted_for_a.pb(ta); sorted_for_b.pb(tb); } sort(REVALL(sorted_for_a)); sort(REVALL(sorted_for_b)); queue<tuple<int, int, int>> a_queue; for (auto a : sorted_for_a) { a_queue.push(a); } queue<tuple<int, int, int>> b_queue; for (auto b : sorted_for_b) { b_queue.push(b); } // それが食べられたことを表す配列 vector<bool> eaten(N, false); // ここから作業開始 int score_a = 0; int score_b = 0; tuple<int,int,int> ta; tuple<int,int,int> tb; while(!a_queue.empty() || !b_queue.empty()) { // Aのターン // 食べられていない料理が見つかるまで捨てる while(true) { if (a_queue.empty()) { break; } ta = a_queue.front(); a_queue.pop(); int& ind = get<2>(ta); if (!eaten.at(ind)) { break; } } if (a_queue.empty()) { break; } // Aが食べる処理 int& a = get<1>(ta); int& ind_a = get<2>(ta); debug(a); debug(ind_a); score_a += a; debug(ind_a); eaten.at(ind_a) = true; // 食べられていない料理が見つかるまで捨てる while(true) { if (b_queue.empty()) { break; } tb = b_queue.front(); b_queue.pop(); int& ind = get<2>(tb); if (!eaten.at(ind)) { break; } } // Bが食べる処理 // 後攻はもう食べるものが無い可能性がある if (b_queue.empty()) { break; } int& b = get<1>(tb); int& ind_b = get<2>(tb); debug(b); debug(ind_b); score_b += b; debug(ind_b); eaten.at(ind_b) = true; } cout << score_a - score_b << endl; }
#include <bits/stdc++.h> using namespace std; #define all(a)a.begin(),a.end() #define rep(i,n) for (int i = 0; i < (n); ++i) using ll=long long; const int INF = 1<<30; const ll INFll =1LL<<62; const int mod = int(1e9)+7; using V = vector<ll>; using P = pair<ll,ll>; int main() { ll n;cin >>n; V a(n),b(n);rep(i,n)cin >>a[i]>>b[i]; vector<P> s(n); rep(i,n){ ll k=a[i]+b[i]; s[i]=make_pair(k,i); } sort(s.rbegin(),s.rend()); ll takahasi=0,aoki=0; rep(i,n){ ll key=s[i].second; if(i%2==0){ takahasi+=a[key]; } else { aoki+=b[key]; } } cout << takahasi-aoki<< endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define FOR(i,a,b) for(int i=(a); i<=(b); i++) #define rep(i,n) for(int i = 0; i < (n); i++) #define loop(k) rep(author_is_masa,k) #define chmin(a,b) if((a)>(b)) (a)=(b); #define chmax(a,b) if((a)<(b)) (a)=(b); #define vi vector<int> #define pii pair<int,int> #define all(v) (v).begin(),(v).end() #define allr(v) (v).rbegin(),(v).rend() #define pb push_back #define pf push_front int gcd(int a,int b){/*a>=0,b>=0,¬(a=b=0)*/ while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b); } int dx[]={1,0,-1,0,1,-1,-1,1}; int dy[]={0,1,0,-1,1,1,-1,-1}; const int MOD = 1e9+7; const long long INF = 1e18+10; /*--------------------------------------------------------------------*/ signed main(){ int a,b; cin>>a>>b; int ans=0; loop(2){ if(a>b){ ans+=a; a--; }else{ ans+=b; b--; } } cout<<ans<<endl; return 0; }
#include <cstdlib> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long LL; int main() { int A, B; cin >> A >> B; if (A == B) cout << 2 * A << endl; else if (A > B) cout << 2 * A - 1 << endl; else cout << 2 * B - 1 << endl; }
1
#include <bits/stdc++.h> #define pi 3.14159 using namespace std; typedef long long LL; const LL MOD = 1e9 + 7; const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f; #define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0); int main() { int sx,sy,tx,ty,i,x,y; scanf("%d %d %d %d",&sx,&sy,&tx,&ty); x=tx-sx; y=ty-sy; for(i=0;i<x;++i){ printf("R"); } for(i=0;i<y;++i){ printf("U"); } for(i=0;i<x;++i){ printf("L"); } for(i=0;i<y;++i){ printf("D"); } printf("D"); for(i=0;i<x+1;++i){ printf("R"); } for(i=0;i<y+1;++i){ printf("U"); } printf("L"); printf("U"); for(i=0;i<x+1;++i){ printf("L"); } for(i=0;i<y+1;++i){ printf("D"); } printf("R"); return 0; }
#include"bits/stdc++.h" #include<iostream> using namespace std; typedef long long ll; typedef vector<int> vi; #define rep(i, c) for(int i = 0; i < (int)c; i++) const ll inf = 1000000007; int main() { int a, b,c; cin >> a >> b >> c; if (a != b) { if (a==c || b==c) { cout << "Yes" << endl; return 0; } } else { if (a != c) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i) #define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i) #define all(n) begin(n), end(n) using ll = long long; using P = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vs = vector<string>; using vc = vector<char>; using vb = vector<bool>; using vd = vector<double>; vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1}; int main() { ll n; cin >> n; cout << n / 3 << endl; }
#include <stdio.h> int main(void) { char line[80]; int x; if (gets(line)) { if (sscanf(line, "%d", &x) == 1) { printf("%d\n", x*x*x); } } return 0; }
0
#include<bits/stdc++.h> using namespace std; #define int long long #define fo(a,b) for(int a=0;a<b;a++) #define Sort(a) sort(a.begin(),a.end()) #define rev(a) reverse(a.begin(),a.end()) #define fi first #define se second #define co(a) cout<<a<<endl #define sz size() #define bgn begin() #define en end() #define pb(a) push_back(a) #define pop pop_back #define V vector #define P pair #define V2(a,b,c) V<V<int>> a(b,V<int>(c)) #define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d)) #define incin(a) int a; cin>>a #define yuko(a) setprecision(a) //#define min min<int> //#define max max<int> template<class T> void cou(vector<vector<T>> a){ int b=a.size(); int c=a[0].size(); fo(i,b){ fo(j,c){ cout<<a[i][j]; if(j==c-1) cout<<endl; else cout<<' '; } } } /*template<> void cou(vector<vector<char>> a){ int b=a.size(); int c=a[0].size(); fo(i,b){ fo(j,c){ cout<<a[i][j]; if(j==c-1) cout<<endl; else cout<<' '; } } }*/ int wari(int a,int b) { if(a%b==0) return a/b; else return a/b+1; } int keta(int a){ double b=a; b=log10(b); int c=b; return c+1; } int souwa(int a){ return a*(a+1)/2; } int lcm(int a,int b){ int d=a,e=b,f; if(a<b) swap(a,b); int c,m=1; while(m){ c=a%b; if(c==0){ f=b; m--; } else{ a=b; b=c; } } return d*e/f; } int gcm(int a,int b){ int d=a,e=b,f; if(a<b) swap(a,b); int c,m=1; while(m){ c=a%b; if(c==0){ f=b; m--; } else{ a=b; b=c; } } return f; } bool prime(int a){ if(a<2) return false; else if(a==2) return true; else if(a%2==0) return false; double b=sqrt(a); for(int i=3;i<=b;i+=2){ if(a%i==0){ return false; } } return true; } struct Union{ vector<int> par; Union(int n){ par= vector<int>(n, -1); } int find(int x){ if(par[x]<0) return x; else return par[x]=find(par[x]); } bool same(int a,int b){ return find(a)==find(b); } int Size(int a){ return -par[find(a)]; } void unite(int a,int b){ a=find(a); b=find(b); if(a==b) return; if(Size(b)>Size(a)) swap<int>(a,b); par[a]+=par[b]; par[b]=a; } }; int ketas(int a){ string b=to_string(a); int c=0; fo(i,keta(a)){ c+=b[i]-'0'; } return c; } /*struct aa{ vector<int> gt; aa(int n){ gt= vector<int>(n, 1); } void c(V<int> d,int b){ if(d[b]==0){ gt[d[b]-1]++; gt[gt.sz-1]++; } else{ gt[d[b]-1]++; c(d,d[d[b]]-1); } } void cok(int a){ cout<<gt[a-1]<<endl; fo(i,a-1) cout<<gt[i]<<endl; } }; */ signed main(){ int a,b; cin>>a>>b; cout<<a+1-b<<endl; }
#include <cstdio> #include <cmath> #define N 100010 #define ll long long #define mem(x, a) memset(x, a, sizeof x) #define mpy(x, y) memcpy(x, y, sizeof y) #define fo(x, a, b) for (int x = (a); x <= (b); x++) #define fd(x, a, b) for (int x = (a); x >= (b); x--) using namespace std; int n, st, coo[N], go_[N], tot = 0; ll ans = 0, hav[N]; inline int read() { int x = 0, f = 0; char c = getchar(); while (c < '0' || c > '9') f = (c == '-') ? 1 : f, c = getchar(); while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return f ? -x : x; } void dfs(int l, int r) { if (l > r) return; if (st < coo[l]) dfs(l, r - 1), go_[++tot] = r; else if (st > coo[r]) dfs(l + 1, r), go_[++tot] = l; else if (hav[l] >= hav[r]) hav[l] += hav[r], dfs(l, r - 1), go_[++tot] = r; else hav[r] += hav[l], dfs(l + 1, r), go_[++tot] = l; } int main() { // freopen("home.in", "r", stdin); // freopen("home.out", "w", stdout); n = read(), st = read(); fo(i, 1, n) coo[i] = read(), hav[i] = read(); dfs(1, n); ans = abs(coo[go_[1]] - st); fo(i, 2, n) ans += abs(coo[go_[i]] - coo[go_[i - 1]]); printf("%lld\n", ans); return 0; }
0
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); i++) using namespace std; using ll = long long; int main() { vector<int> x(3); rep(i, 3) cin >> x.at(i); int cnt = 0; rep(i, 3) rep(j, 3) { if(i == j) continue; else if(x.at(i) == x.at(j)) cnt++; } if(cnt == 2) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include<bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); ++i) //#define DEBUG #ifdef DEBUG #define DEBUG_PRINT(fm, ...) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout << "DEBUG PRINT ";std::printf(fm, __VA_ARGS__);}while(0) #define DEBUG_VAL(a, b) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout <<"DEBUG VAL " << a << ":" << b << endl;}while(0) #else #define DEBUG_PRINT(...)do{}while(0); #define DEBUG_VAL(a, b)do{}while(0); #endif using namespace std; using ll = long long; using v1 = vector<int>; using vl = vector<long long>; using v2 = vector<vector<int>>; using v3 = vector<vector<char>>; int main(){ int A, B, M; cin >> A >> B >> M; v1 a(A+1); v1 b(B+1); int ma = 1e6; int mb = 1e6; rep(i, A){ int aa; cin >> aa; a[i+1] = aa; ma = min(ma, aa); } rep(i, B){ int bb; cin >> bb; b[i+1] = bb; mb = min(mb, bb); } int ans = ma+mb; rep(i, M){ int x, y, c; cin >> x >> y >> c; int value = a[x] + b[y] -c; ans = min(ans, value); } cout << ans << endl; }
0
/* ????????°??§???????????¨???????????? */ #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> #include <math.h> #include <time.h> #include <limits.h> #include <float.h> #include <iostream> #include <algorithm> #include <string> #include <iterator> #include <vector> #include <map> #include <utility> #define LLU unsigned long long int #define LL long long int #define LD long double using namespace std; #define Lfmax DBL_MAX #define LLUmax ULLONG_MAX #define LLmax LLONG_MAX #define dmax INT_MAX #define vd vector<int> #define vLL vector<long long int> #define vLLU vector<unsigned long long int> #define pb push_back #define mp make_pair #define fi first #define sec second #define debug printf("asd\n") #define debugd(a) printf("--%d\n",a) #define debugdd(a,b) printf("--%d %d\n",a,b) #define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n") #define newline printf("\n") #define forin(a,b,c) for(int a=b ; a<c ; a++) #define forde(a,b,c) for(int a=b ; a>=c ; a--) inline void scd(int &a){scanf("%d",&a);} inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);} inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);} inline void scdlld(LL &a,LL &b){scanf("%I64d %I64d",&a,&b);} inline void sclld(LL &a){scanf("%I64d",&a);} #define scarrd(a,b) for(int index=0 ; index<b ; index++)scanf("%d",&a[index]) #define prdlld(a,b) printf("%I64d %I64d",a,b) #define prdd(a,b) printf("%d %d",a,b) #define prd(a) printf("%d",a) #define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]) #define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0 #define arr(a,b) int *a=(int *)malloc(b*sizeof(int)) #define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int)) #define st(a,b) char *a=(char *)malloc(b*sizeof(char)) #define grav 9.8 #define pi 3.14159265 int main() { int n; scd(n); LL a,b; string c; while(n!=0) { vector<string> e; map<string,LL> d; int fl=0; forin(i,0,n) { cin>>c>>a>>b; fl=0; forin(i,0,e.size()) { if(e[i]==c) { fl=1; break; } } if(fl==0) e.pb(c); d[c]+=a*b; } fl=0; int size=e.size(); forin(i,0,size) { if(d[e[i]]>=1000000) { fl=1; cout<<e[i]<<endl; } } if(fl==0) printf("NA\n"); scd(n); } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; typedef pair<ll,ll> P; const ll INF=1001001001001001; struct Sieve { int n; vector<int> f, primes; Sieve(int n=1):n(n), f(n+1) { f[0] = f[1] = -1; for (ll i = 2; i <= n; ++i) { if (f[i]) continue; primes.push_back(i); f[i] = i; for (ll j = i*i; j <= n; j += i) { if (!f[j]) f[j] = i; } } } bool isPrime(int x) { return f[x] == x;} vector<int> factorList(int x) { vector<int> res; while (x != 1) { res.push_back(f[x]); x /= f[x]; } return res; } vector<P> factor(int x) { vector<int> fl = factorList(x); if (fl.size() == 0) return {}; vector<P> res(1, P(fl[0], 0)); for (int p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } }; int main() { ll n; cin>>n; Sieve sv(55555); vector<int> v; v=sv.primes; ll now=0; vector<ll>A; rep(i,v.size()){ if (v[i]%10==1) { now++; A.push_back(v[i]); } } rep(i,n){ cout<<A[i]<<' '; } }
0
#include <bits/stdc++.h> #define rep(i,n)for(long long i=0;i<(long long)(n);++i) #define all(a) a.begin(), a.end() using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } const int MOD=1e9+7; const ll INF=1e18; const int MAX=510000; const double pi=acos(-1); int dx[8] = {1,0,-1,0,1,1,-1,-1}; int dy[8] = {0,1,0,-1,-1,1,1,-1}; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n,q; cin >> n >> q; vector<tuple<int,int,int>> stx(n); rep(i,n){ cin >> get<1>(stx[i]) >> get<2>(stx[i]) >> get<0>(stx[i]); } sort(stx.begin(),stx.end()); set<P> st; rep(i,q){ int x; cin >> x; st.emplace(x,i); } vector<int> ans(q,-1); rep(i,n){ int s = get<1>(stx[i]); int t = get<2>(stx[i]); int x = get<0>(stx[i]); //xの昇順で考えてぶつかったら,その人をerase auto first = st.lower_bound(P(s-x,0));//引っかかる人 auto end = st.upper_bound(P(t-x-1,q));//引っかからない人 for(auto it = first; it !=end; ++it) ans[it->second] = x; st.erase(first,end); } rep(i,q) cout << ans[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // 型定義 typedef long long ll; typedef pair<ll, ll> P; // forループ #define REP(i,n) for(ll i=0; i<(ll)(n); ++i) // 定数宣言 const int INF = 1e9; const int MOD = 1e9+7; const ll LINF = 1e18; // グラフ表現 using Graph = vector<vector<int>>; // グラフの辺表現 using Edge = map<pair<int,int>,int>; // n次元配列の初期化。第2引数の型のサイズごとに初期化していく。 template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } bool compare_by_a(tuple<ll, ll, ll> a, tuple<ll, ll, ll> b) { if(get<0>(a) != get<0>(b)){ return get<0>(a) > get<0>(b); }else{ return get<1>(a) > get<1>(b); } } int main() { cout << fixed << setprecision(15); ll N, Q; cin >> N >> Q; vector<tuple<ll, ll, ll> > A(N); REP(i ,N){ ll s, t, x; cin >> s; cin >> t; cin >> x; get<0>(A[i]) = x; get<1>(A[i]) = s; get<2>(A[i]) = t; } vector<ll> D(Q); REP(i, Q){ cin >> D[i]; } // 1つ目のキーで降順順ソート sort(A.begin(), A.end(), compare_by_a); // for(ll i=0; i<N; i++){ // cout << get<0>(A[i]) << " " << get<1>(A[i]) << " " << get<2>(A[i]) << endl; // } vector<queue<ll>> plus(Q+1); vector<queue<ll>> minus(Q+1); REP(i, N){ ll start = get<1>(A[i]) - get<0>(A[i]); ll end = get<2>(A[i]) - get<0>(A[i]); start = max(0LL, start); end = max(0LL, end); auto Iter1 = lower_bound(D.begin(), D.end(), start); ll s_id = Iter1 - D.begin(); auto Iter2 = lower_bound(D.begin(), D.end(), end); ll t_id = Iter2 - D.begin(); // cout << "s_id: " << s_id << "t_id: " << t_id << endl; plus[s_id].push(get<0>(A[i])); minus[t_id].push(get<0>(A[i])); // for(ll j=max(0LL,s_id); j<min(Q, t_id); j++){ // ans[j] = get<0>(A[i]); // } } // cout << 2 << endl; // cout << 2 << endl; // cout << 10 << endl; // cout << -1 << endl; // cout << 13<< endl; // cout << -1 << endl; multiset<ll> ans; REP(i, Q){ // cout << i << " : " << ans.size() << endl; // 候補のものをすべて入れる。 while (!(plus[i].empty())) { ans.insert(plus[i].front()); plus[i].pop(); } // cout << "plusの後: "; // for(auto itr = ans.begin(); itr != ans.end(); ++itr) { // cout << *itr << " "; // } // cout << endl; // 候補が終わったものを削除 while (!(minus[i].empty())) { ll temp = minus[i].front(); auto itr = ans.find(temp); if(itr != ans.end()){ ans.erase(ans.find(temp)); } // cout << *itr << endl; minus[i].pop(); } // cout << "minusの後: "; // for(auto itr = ans.begin(); itr != ans.end(); ++itr) { // cout << *itr << " "; // } // cout << endl; // 候補がないなら-1を出力 if(ans.empty()){ cout << -1 << endl; } else{ auto itr = ans.begin(); cout << *itr << endl; } } return 0; }
1
#include<iostream> #include<math.h> #include<algorithm> #include<stdint.h> #include<vector> #include<deque> #include<stack> #include<string> #include<cstring> #include<time.h> #include<array> #include<iomanip> #include<list> #include<set> #include<unordered_map> #include<unordered_set> #include<random> #include<bitset> #include <queue> #include <map> using namespace std; using ll = long long; using ull = unsigned long long; using uint = unsigned int; using ldouble = long double; //BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun #define PRI(s) cout << s << endl #define PRIY PRI("Yes") #define PRIN PRI("No") int main() { int N; int R; cin >> N >> R; if (N >= 10) PRI(R); else PRI(R + 100 * (10 - N)); return 0; }
// Integral #include <iostream> using namespace std; int main() { int d; while(cin >> d) { int x = 0; long long S = 0; for(int i = 1; i < 600/d; i++) { x += d; S += d * (x * x); } cout << S << endl; } return 0; }
0
#include<bits/stdc++.h> using namespace std; int main(){ while(1){ int n,m; int p[10000]; int sum=0; cin>>n>>m; if(n==0 && m==0) break; for(int i=0;i<n;i++){ cin>>p[i]; } for(int i=0;i<n;i++){ for(int j=0;j<n-1;j++){ if(p[j]<p[j+1]) swap(p[j],p[j+1]); } } for(int i=0;i<n;i++){ if(i%m==m-1) p[i]=0; } for(int i=0;i<n;i++){ sum+=p[i]; } cout<<sum<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; /* int dx[]={-1,1,0,0}; int dy[]={0,0,-1,1}; vector<long long int> adj[200001]; bool vis[200001]; */ #define ull unsigned long long int #define ll long long int #define MAX 1000000007 //1e9+7 #define pll pair<ll,ll> #define pii pair<int,int> #define IO ios_base::sync_with_stdio(false); cin.tie(NULL); #define FO ifstream fin("a.in");ofstream fout("a.out"); #define TEST ll t;cin>>t;while(t--) #define all(x) (x).begin(),(x).end() #define mset0(x) memset((x), 0, sizeof((x))); #define mset1(x) memset((x), -1, sizeof((x))); string cmp(string a,string b){ int n=a.size(),m=b.size(); if(n>m) return(a); if(m>n) return(b); for(int i=0;i<n;i++){ if(a[i]==b[i]) continue; if((a[i]-'0')>(b[i]-'0')) return(a); else return(b); } return(a); } string ss="0123456789"; int main(){ IO int n,m; cin>>n>>m; int mat[]={0,2,5,5,4,5,6,3,7,6}; int arr[m]; for(int i=0;i<m;i++) cin>>arr[i]; sort(arr,arr+m); map<int,string> mp; //for(int i=0;i<=n;i++) mp[i]=""; /* for(int i=0;i<m;i++){ string s=mp[mat[arr[i]]]; string p=""; p+=ss[arr[i]]; //cout<<s<<" "<<p<<endl; mp[mat[arr[i]]]=cmp(p,s); } */ for(int i=0;i<=n;i++){ for(int j=0;j<m;j++){ if(i-mat[arr[j]]<0) continue; string s=mp[i-mat[arr[j]]]; string p=mp[i]; if(s=="" && i!=mat[arr[j]]) continue; s+=ss[arr[j]]; sort(s.rbegin(),s.rend()); mp[i]=cmp(s,p); /* cout<<"i is "<< i<<" "; cout<<"j is "<<j<<" "; cout<<" mat[arr["<<j<<"]] is "<<mat[arr[j]]<<" "; cout<<"mp["<<i<<"] is "<<mp[i]<<"\n"; */ } } /* for(int i=1;i<=n;i++){ cout<<i<<" "<<mp[i]<<"\n"; } */ cout<<mp[n]; return(0); }
0
#include<bits/stdc++.h> using namespace std; int main(){ int n,m; cin>>n>>m; vector<int>L(m); vector<int>R(m); for(int i=0;i<m;i++){ cin>>L.at(i)>>R.at(i); } int l=0,r=999999; for(int i=0;i<m;i++){ l=max(l,L.at(i)); r=min(r,R.at(i)); } int ans=0; for(int i=0;i<=n;i++){ if(i>=l&&i<=r){ ans++; } } cout<<ans<<endl; }
/*input */ #include <bits/stdc++.h> #define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i)) #define down(i,b,a) for(int (i) = (b);i>=(a);--i) #define debug(x) cerr << (x) << '\n'; #define bits(x,i) ((x >> i) & 1) #define mid ((l+r)/2) #define pr pair<int,int> using namespace std; const int N = 500005; int bit[N],n,q, c[N]; int nxtColor[N], nxtPos[N], color[N]; struct query{ int l,r, id; query(){l = r = id = 0;} query(int _l,int _r,int _id){l = _l; r = _r; id = _id;} }; bool operator<(query a,query b){ return a.l < b.l; } query question[N]; int ans[N]; void upd(int u,int val){ while (u <= n) { bit[u] += val; u += (u &-u); } } int get(int u){ int ans = 0; while (u){ ans += bit[u]; u -= (u &-u); } return ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> q; for(int i=1;i<=n;++i){ cin >> c[i]; } for(int i=1;i<=q;++i){ cin >> question[i].l >> question[i].r; question[i].id = i; } for(int i=n;i>=1;--i){ nxtPos[i] = nxtColor[c[i]]; nxtColor[c[i]] = i; } for (int i=1;i<=n;++i) if (nxtColor[c[i]] == i) upd(i, 1); int curPos = 1; sort(question+1, question+1+q); for(int i=1;i<=q;++i){ while (question[i].l != curPos){ int nxt = nxtPos[curPos]; upd(curPos, -1); if (nxt) upd(nxt, 1); curPos++; } ans[question[i].id] = get(question[i].r); } for(int i=1;i<=q;++i) cout << ans[i] << '\n'; }
0
//Author - Rahil Malhotra #include <bits/stdc++.h> using namespace std; template <typename T> void print(T t) { cout<<t<<endl; } template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); } #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl '\n' #define int long long #define double long double void start() { #ifndef ONLINE_JUDGE freopen("in", "r", stdin); freopen("out", "w", stdout); #endif } int n, m; int arr[82][82][2]; int cache[81][81][81*162]; int dp(int i, int j, int diff) { if(i >= n || j >= m) return 1e18; if(i == n-1 && j == m-1) { return min(abs(diff - arr[i][j][0] + arr[i][j][1]), abs(diff + arr[i][j][0] - arr[i][j][1])); } int &ans = cache[i][j][diff]; if(ans !=-1) return ans; int ans1 = min(dp(i+1, j, abs(diff - arr[i][j][0] + arr[i][j][1])), dp(i+1, j, abs(diff + arr[i][j][0] - arr[i][j][1]))); int ans2 = min(dp(i, j+1, abs(diff - arr[i][j][0] + arr[i][j][1])), dp(i, j+1, abs(diff + arr[i][j][0] - arr[i][j][1]))); ans = min(ans2, ans1); return ans; } int32_t main() { IOS; start(); cin >> n >> m; for(int i = 0 ; i < n ; i++) { for(int j = 0 ; j < m ; j++) { cin >> arr[i][j][0]; } } for(int i = 0 ; i < n ; i++) { for(int j = 0 ; j < m ; j++) { cin >> arr[i][j][1]; } } memset(cache, -1, sizeof(cache)); cout << dp(0, 0, 0) << endl; }
#include <bits/stdc++.h> #define int long long using namespace std; int n,b,m; vector<vector<int> > vec; vector<int> dp; int solve(int mask) { if(dp[mask]!=LLONG_MIN) return dp[mask]; // if all the rabbits in mask are // in the same group int res=0; for(int i=0; i<n; i++) { for(int j=i+1; j<n; j++) { if((mask&(1LL<<i))&&(mask&(1LL<<j))) res+=vec[i][j]; } } // iterate through all submasks now : O(3^n) for(int i=mask&(mask-1); i; i=(i-1)&mask) { res=max(res,solve(i)+solve(i^mask)); } return dp[mask]=res; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n; vec.assign(n,vector<int>(n)); for(int i=0; i<n; i++) { for(int j=0; j<n;j++) { cin>>vec[i][j]; } } dp.assign(1LL<<n,LLONG_MIN); cout<<solve((1LL<<n)-1); return 0; }
0
#include <bits/stdc++.h> #define F first #define S second #define MP make_pair #define pb push_back #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define LCM(a, b) (a) / __gcd((a), (b)) * (b) #define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0) #define ln '\n' using namespace std; using LL = long long; using ldouble = long double; using P = pair<int, int>; using LP = pair<LL, LL>; static const int INF = INT_MAX; static const LL LINF = LLONG_MAX; static const int MIN = INT_MIN; static const LL LMIN = LLONG_MIN; static const int MOD = 1e9 + 7; static const int SIZE = 200005; const int dx[] = {0, -1, 1, 0}; const int dy[] = {-1, 0, 0, 1}; vector<LL> Div(LL n) { vector<LL> ret; for(LL i = 1; i * i <= n; ++i) { if(n % i == 0) { ret.pb(i); if(i * i != n) ret.pb(n / i); } } sort(all(ret)); return ret; } int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector<int> v(N); for(int i = 0; i < N; ++i) { cin >> v[i]; } sort(all(v)); LL a, b; a = 0, b = 0; for(int i = 0; i < N - 1; ++i) { if(v[i] == v[i + 1]) { b = a; a = v[i]; i++; } } cout << a * b << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; long long int a; map<long long int,int> mp; for(int i=0;i<n;i++){ cin >> a; a *= (-1); mp[a]++; } long long int tmp=0; for(auto u:mp){ if(u.second>=4){ if(tmp<0){ cout << tmp*u.first; return 0; } else{ cout << u.first*u.first; return 0; } } else if(u.second>=2){ if(tmp<0){ cout << tmp*u.first; return 0; } else tmp=u.first; } } cout << 0; }
1
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> typedef long long ll; #define FOR(i,a,b) for(ll i=(a);i<(b);i++) #define REP(i,a) FOR(i,0,a) using namespace std; const ll MAX_N=1e5,MAX_X=1e5; ll N,X,psm[MAX_N+2],inx[MAX_N+1]; typedef tuple<ll,ll,ll> TUP; TUP blu[MAX_N+1]; ll tsm(ll i){ return get<1>(blu[i])*get<0>(blu[i])+get<2>(blu[i])*(X-get<0>(blu[i])); } ll ptsm(ll i,ll n){ return get<1>(blu[i])*min(n,get<0>(blu[i]))+get<2>(blu[i])*(n-min(n,get<0>(blu[i]))); } bool C(ll x){ ll n=x/X,m=x%X; ll sm=0; REP(i,N+1){ ll tmp=psm[n]; if(i<n){ tmp-=tsm(i); tmp+=ptsm(i,m); tmp+=tsm(n); }else{ tmp+=ptsm(i,m); } sm=max(sm,tmp); } REP(i,N)sm-=get<1>(blu[i])*get<0>(blu[i]); return sm>=0; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>N>>X; REP(i,N)cin>>get<0>(blu[i])>>get<1>(blu[i])>>get<2>(blu[i]); blu[N]=make_tuple(0,0,0); REP(i,N+1)inx[i]=i; sort(blu,blu+N+1,[](TUP x,TUP y){ return get<1>(x)*get<0>(x)+get<2>(x)*(X-get<0>(x)) >get<1>(y)*get<0>(y)+get<2>(y)*(X-get<0>(y)); }); psm[0]=0; REP(i,N+1){ psm[i+1]=psm[i]+tsm(i); } ll lb=-1,ub=N*X; while(ub-lb>1){ ll m=(lb+ub)>>1; if(C(m)){ ub=m; }else{ lb=m; } } cout<<ub<<endl; }
// #define _GLIBCXX_DEBUG // for STL debug (optional) #include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <cfloat> #include <climits> #include <ctime> #include <cassert> #include <numeric> #include <fstream> #include <functional> #include <bitset> using namespace std; #define debug(...) fprintf(stderr, __VA_ARGS__) #define int long long int template<typename T> void chmax(T &a, T b) {a = max(a, b);} template<typename T> void chmin(T &a, T b) {a = min(a, b);} template<typename T> void chadd(T &a, T b) {a = a + b;} typedef pair<int, int> pii; typedef long long ll; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const ll INF = 1001001001001001LL; const ll MOD = 1000000007LL; signed main() { int N, X; cin >> N >> X; vector< tuple<int, int, int> > tups; for(int i=0; i<N; i++) { int b, l, u; cin >> b >> l >> u; tups.emplace_back(b, l, u); } sort(tups.begin(), tups.end(), [&](auto x, auto y) { int xb, xl, xu, yb, yl, yu; tie(xb, xl, xu) = x; tie(yb, yl, yu) = y; int vl = xl * xb + xu * (X - xb); int vr = yl * yb + yu * (X - yb); return vl > vr; }); int D = 0; vector<int> acc(N+1), val(N); for(int i=0; i<N; i++) { int b, l, u; tie(b, l, u) = tups[i]; D -= b * l; val[i ] = l * b + u * (X - b); acc[i+1] = acc[i] + val[i]; } int ub = X*N, lb = -1; while(ub - lb > 1) { int mid = (ub + lb) / 2; bool ok = false; // 中途半端に選ぶものが i 番目の要素 int q = mid / X, R = mid % X; for(int i=0; i<N; i++) { int d = D, r = R; int b, l, u; tie(b, l, u) = tups[i]; d += l * min(r, b); r -= min(r, b); d += u * r; if(i < q) { d += acc[q+1] - val[i]; } else { d += acc[q]; } ok |= (d >= 0); } if(ok) ub = mid; else lb = mid; } cout << ub << endl; return 0; }
1
#include <bits/stdc++.h> #define rep(i,n) for(long long i = 0; i < (long long)(n); ++i) using namespace std; int main() { double n; cin >> n; n = 2 * n * acos(-1); cout << n << endl; return 0; }
#include<iostream> using namespace std; int main (void) { int r; cin>>r; r=r*2*3141592; cout<<r/1000000<<"."<<r%1000000; }
1
#include <bits/stdc++.h> using namespace std; int main() { double r, g; cin >> r >> g; cout << (2 * g) - r << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(int i=0;i<n;i++) const ll MOD=1000000007; const long double PI=3.14159265358979; const ll MAX=0; int main() { ll a,b; cin>>a>>b; cout<<b+b-a; }
1
#include<iostream> #include<algorithm> #include<cmath> #include<vector> #include<map> #include<set> #include<string> #include<queue> #include<stack> #include<iomanip> #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; #define debug(x) cout<<(#x)<<"="<<(x)<<", "; #define debug1(x) debug(x) cout<<'\n'; #define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n'; #define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n'; #define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n'; #define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n'; #define fcout cout<<fixed<<setprecision(15) #define repp(i,j,k) for(int i=j; i<k; ++i) #define rep(i,j) repp(i,0,j) #define rrep(i,j,k) for(int i=j; i>=k; --i) #define all(x) (x).begin(), (x).end() #define sort(x) sort(x.begin(), x.end()) #define lb(x,val) lower_bound(x.begin(), x.end(), val) #define ub(x,val) upper_bound(x.begin(), x.end(), val) #define pb(x) emplace_back(x); typedef long long int lli; typedef pair<int,int> pii; typedef pair<lli,lli> pll; typedef vector<int> vi; typedef vector<lli> vl; typedef tuple<int, int, lli> tiil; //const lli M=998244353ll; const lli M=1000000007ll; const double D=1.0; int main(){ fast_io int a,b,c; cin>>a>>b>>c; cout<<max(a*b, max(a+b,a-b)); return 0; }
#include <bits/stdc++.h> #define int long long #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() #define pb push_back #define F first #define S second using namespace std; using P = pair<int,int>; using ivec = vector<int>; using Graph = vector<vector<int>>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } const int MOD=1000000007; int INF=100100100100100; int add(int a,int b){ return (a+b)%MOD; } int prod(int a,int b){ return (a*b)%MOD; } int beki(int a,int b) { if(b==0)return 1; int x=beki(a,b/2); if(b%2==0)return (x*x)%MOD; else return (((a*x)%MOD)*x)%MOD; } int inv(int a) { return beki(a,MOD-2); } int kaijou(int a) { int ans=1; for(int i=1;i<=a;i++) { ans=(ans*i)%MOD; } return ans; } /*int combi(int a,int b) { int ret=1; for(int i=1;i<=b;i++) { ret=(((ret*(a+1-i))%MOD)*inv(i))%MOD; } return ret; }*/ /* const int MAX_a=200010; int cb[MAX_a+1] void combi(int a,int b) { int ret=1; cb[0]=1; for(int i=1;i<=b;i++) { ret=(((ret*(a+1-i))%MOD)*inv(i))%MOD; cb[i]=ret; } }*/ vector<P> prime_factorize(int N) { vector<P> res; for(int a=2;a*a<=N;a++) { if(N%a!=0)continue; int ex=0; while(N%a==0) { ex++;N/=a; } res.push_back(P(a,ex)); } if(N!=1)res.push_back(P(N,1)); return res; } //ここから書く signed main(){ int a,b;cin>>a>>b; cout<<max(a+b,max(a-b,a*b))<<endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int N, D1, D2, M; int A1[610][610], A2[610][610]; vector<pair<int, int>> v1, v2; vector<pair<int, int>> V[4]; void dfs1(int x, int y, int c){ A1[x][y] = c; for(auto p : v1){ int nx = x + p.first; int ny = y + p.second; if(nx < 0 || nx > M || ny < 0 || ny > M) continue; if(A1[nx][ny]) continue; dfs1(nx, ny, 3 - c); } } void dfs2(int x, int y, int c){ A2[x][y] = c; for(auto p : v2){ int nx = x + p.first; int ny = y + p.second; if(nx < 0 || nx > M || ny < 0 || ny > M) continue; if(A2[nx][ny]) continue; dfs2(nx, ny, 4 - c); } } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> D1 >> D2; M = 2 * N - 1; for(int i = -M; i <= M; i++){ for(int j = -M; j <= M; j++){ int d = i * i + j * j; if(d == D1) v1.emplace_back(i, j); if(d == D2) v2.emplace_back(i, j); } } for(int i = 0; i <= M; i++){ for(int j = 0; j <= M; j++){ if(!A1[i][j]) dfs1(i, j, 1); if(!A2[i][j]) dfs2(i, j, 1); } } for(int i = 0; i <= M; i++){ for(int j = 0; j <= M; j++){ int t = A1[i][j] + A2[i][j] - 2; V[t].emplace_back(i, j); } } int idx = -1; for(int t = 0; t < 4; t++){ if(V[t].size() >= N * N) idx = t; } for(int i = 0; i < N * N; i++){ cout << V[idx].at(i).first << " " << V[idx].at(i).second << "\n"; } }
#include <bits/stdc++.h> using namespace std; typedef long long int lli; lli employees[4001]; bool checked[4001]; signed main() { lli n; while (cin >> n, n) { for (lli i = 1; i <= 4000; ++i) employees[i] = checked[i] = false; vector<lli> ans; for (lli i = 0; i < n; ++i) { lli num, a, b; cin >> num >> a >> b; if (checked[num]) continue; employees[num] += a * b; if (employees[num] >= 1000000) { ans.push_back(num); checked[num] = true; } } if (ans.size()) { for (lli i = 0; i < ans.size(); ++i) { cout << ans[i] << endl; } } else { cout << "NA" << endl; } } }
0
#include <bits/stdc++.h> #define INF 1e9 using namespace std; #define REPR(i,n) for(int i=(n); i >= 0; --i) #define FOR(i, m, n) for(int i = (m); i < (n); ++i) #define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define ALL(a) (a).begin(),(a).end() template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; } template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } int gcd(int a,int b){return b?gcd(b,a%b):a;} typedef long long ll; ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} int main() { string s; cin >> s; if (s.size() == 3) { reverse(ALL(s)); } cout << s << endl; return 0; }
// #include <iostream> #include <cstdio> #include <string> #include <cmath> #include <algorithm> #include <vector> #include <map> using namespace std; int fun(int x){ return x*x; } int main(){ int d; while(cin >> d){ int n = 600/d; int sum = 0; for(int i=0; i<n; i++){ sum += fun(d*i)*d; } cout << sum << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; using lint = long long int; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) #define ALL(a) (a).begin(),(a).end() constexpr int MOD = 1000000007; constexpr int INF = 2147483647; void yes(bool expr) { cout << (expr ? "Yes" : "No") << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int N; cin >> N; vector<lint> A(N); REP(i, N) cin >> A[i]; map<lint, lint> ma; REP(i, N) { ma[-A[i]]++; } int ans = 0; for(auto itr=ma.begin(); itr!=ma.end(); itr++) { lint a = -(itr->first); lint b = 1; while(b <= a) b *= 2; b -= a; if(ma.find(-b) != ma.end()) { if(a != b && ma[-a] >= 1 && ma[-b] >= 1) { int t = min(ma[-a], ma[-b]); ma[-a] -= t; ma[-b] -= t; ans += t; } else if(a == b && ma[-a] >= 2){ int t = ma[-a] / 2; ma[-a] -= t*2; ans += t; } } } cout << ans << endl; }
#pragma GCC optimize ("O3") #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #include<bits/stdc++.h> #include<ext/pb_ds/tree_policy.hpp> #include<ext/pb_ds/assoc_container.hpp> #define ff first #define ss second #define pb push_back #define mp make_pair #define ll long long #define ld long double #define all(a) a.begin(),a.end() #define endl '\n' #define ull unsigned long long #define y1 ljhadglkjsadf #define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define iter multiset<int>::iterator #define iter1 set<int>::iterator #define int long long using namespace std; using namespace __gnu_pbds; template<class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; template<class T> using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rnd1(chrono::steady_clock::now().time_since_epoch().count()); //find_by_order //order_of_key const int N=2e5+7; const int inf=1e18+1e9; const int mod=1e9+7; const ld eps=1e-9; //const int MAX_MEM=4e8; //int mpos=0; //char mem[MAX_MEM]; // //inline void * operator new(size_t n){ // char *res=mem+mpos; // mpos+=n; // if (mpos>=MAX_MEM){ // cout<<"BAD"<<endl; // exit(0); // } // return (void*)res; //} // //inline void operator delete(void *) {} int st[50]; main () { st[0]=1; for (int i=1;i<35;++i){ st[i]=st[i-1]*2; } ios; int n; multiset<int>setik; cin>>n; for (int i=1;i<=n;++i){ int x; cin>>x; setik.insert(x); } int ans=0; while(setik.size()>0){ iter it=setik.end(); --it; int x=(*it); setik.erase(it); int k=0; while(st[k]<=x)++k; int l=st[k]-x; iter it1=setik.find(l); if (it1!=setik.end()){ ++ans; setik.erase(it1); } } cout<<ans<<endl; } //1 //3 15 //1 4 //3 5
1
#include<iostream> using namespace std; int main(){ char str[20]; cin>>str; for(int i=20;i>0;i--) cout<<str[i-1]; cout<<endl; return 0; }
#include <iostream> using namespace std; using lint = long long; lint K; lint N = 50; const int MAX_N = 55; lint a[MAX_N]; int main(){ ios::sync_with_stdio(false); cin>>K; for(int i=0;i<N;i++){ a[i] = (K+N-1)/N+(N-1); } int t = N-K%N; if(t==N)t=0; for(int i=0;i<t;i++){ a[i]-=K%N+1; } cout << N << endl; for(int i=0;i<N;i++){ cout << a[i] << " "; } cout << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main(){ int N, K ; cin >> N >> K; int array[N]; for(int i = 0;i < N ; i++){ cin >> array[i]; } for(int i = 0;i < N ; i++){ int max = i; for(int j = i+1;j < N;j++){ if(array[max] < array[j]){ max = j; } } swap(array[i],array[max]); } /*for (int i = 0; i < N ;i++){ cout <<array[i]; } */ int sum = 0; for(int i = 0;i < K;i++){ sum += array[i]; } cout << sum << endl; return 0; }
#pragma GCC optimize("O3") //#pragma GCC target("avx2") //#pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <prettyprint.hpp> #define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__); #else #define debug(...) 83; #endif void d_err() { cerr << endl; } template <typename H, typename... T> void d_err(H h, T... t) { cerr << h << " "; d_err(t...); } template <typename T> void print(T x) { cout << x << "\n"; } #define ALL(x) (x).begin(), (x).end() #define FOR(i, m, n) for (ll i = (m); i < (n); ++i) #define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i) #define REP(i, n) FOR(i, 0, n) #define REVREP(i, n) REVFOR(i, 0, n) #define fi first #define se second #define pb push_back #define mp make_pair #define eb emplace_back #define bcnt __builtin_popcountll typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<ll,ll> Pll; typedef pair<int,int> Pin; ll INF = 1e16; int inf = 1e9; ll MOD = 1e9+7; int main(){ cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); int n, k; cin >> n >> k; vi l(n); REP(i, n) cin >> l[i]; sort(ALL(l), greater<>()); int ans = accumulate(l.begin(), l.begin() + k, 0); print(ans); }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) typedef pair<ll, ll>P; #define PI 3.14159265359 #define MOD 1000000007 const int MAX = 510000; ll gcd(ll a, ll b){ if (a % b == 0) { return(b);} else{return(gcd(b, a % b));} } ll lcm(ll a, ll b) {return a * b / gcd(a, b);} int main(){ int n; cin >>n; vector<int>a(n); vector<ll>x(n+1); rep(i,n){cin>>a[i];} x[0]=abs(a[0]-0ll); for(int i=1;i<n;i++){ x[i]=abs(a[i]-a[i-1]); } x[n]=abs(a[n-1]-0ll); ll sum=0; rep(i,n+1){sum+=x[i];} //i=0のとき cout<<sum-x[0]-x[1]+abs(a[1]-0ll)<<endl; for(int i=1;i<=n-2;i++){ cout<<sum-x[i]-x[i+1]+abs(a[i+1]-a[i-1])<<endl; } cout<<sum-x[n-1]-x[n]+abs(a[n-2]-0); }
#include<bits/stdc++.h> int main(){ using namespace std; constexpr unsigned long MOD = 1000000007; unsigned long N; cin >> N; vector<pair<pair<unsigned long, unsigned long>, unsigned long>> tapi(1048576, {{1, 0}, 0}); unsigned long ans{0}, t{500000004}, a{0}, z{0}, A; while(cin >> A)if(a ^= A){ (tapi[a].first.second += (tapi[a].first.first += tapi[a].first.second * (z - tapi[a].second)) %= MOD) %= MOD; ans += tapi[a].first.first; tapi[a].second = z; }else ++z, (t *= 2) %= MOD; cout << (a ? tapi[a].first.first : (ans + t) % MOD) << endl; return 0; }
0
#include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<utility> #include<cstdio> #include<set> #include<string> #include<map> #include<queue> #include<stack> #include <bitset> using namespace std; const int mod=1e9+7; #define rep(i,n) for(int i=0;i<n;i++) #define rep2(i,x,n) for (int i= x;i<n;i++) #define all(v) v.begin(), v.end() #define nepe(v) next_permutation(all(v)) #define F first #define S second #define PB push_back #define MP make_pair using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vp =vector<pair<int,int>>; typedef pair<int,int> P; string s; int k; ll INF = 10000000000000000; int main(){ int N; cin >> N; vp r(N),b(N); rep(i,N) cin >>r[i].F>>r[i].S; rep(i,N) cin >>b[i].F>>b[i].S; vi left(N,0); vi max(N,0); sort(all(b)); sort(all(r)); int jj=0; int ans=0; rep(i,N){//ao bool judge=false; rep(j,N){//aka if(left[j] ==0){ if(r[j].F<b[i].F && r[j].S<b[i].S && r[j].S>=max[i]){ max[i]=r[j].S; jj = j; judge = true; } } } if(judge) { ans++; left[jj] = 1; } } cout <<ans<<endl; }
#include <vector> #include <list> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <bitset> #include <complex> using namespace std; #define REP(i,n) for(int i = 0; i < (int)n; i++) #define FOR(i,a,b) for(int i = a; i < (int)b; i++) #define pb push_back #define mp make_pair typedef vector<int> vi; typedef pair<int, int> pi; typedef long long ll; typedef unsigned long long ull; const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; const int INF = 1 << 27; ////////////////////////////// // ?????£?????????????§£ void dfs(int v, int *used, vector< vector<int> > &G, vector<int> &vs){ used[v] = true; REP(i, G[v].size()){ int next = G[v][i]; if(!used[next]) dfs(next, used, G, vs); } vs.push_back(v); } void rdfs(int v, int cnt, int *used, vector<int> &cmp, vector< vector<int> > &G){ used[v] = true; cmp[v] = cnt; REP(i, G[v].size()){ int next = G[v][i]; if(!used[next]) rdfs(next, cnt, used, cmp, G); } } //G????????????????????°???????????£??\????????????RG????????????????????????????????£??\????????? //?????????????????????????????????????????????????????£?????????????±?????????????cmp[a] == cmp[b]??????????????°a, b???????????????????±?????????? vector<int> scc(int V, vector< vector<int> > &G, vector< vector<int> > &RG){ int used[V]; memset(used, 0, sizeof(used)); vector<int> vs, cmp(V); REP(i, V) if(!used[i]) dfs(i, used, G, vs); memset(used, 0, sizeof(used)); int cnt = 0; reverse(vs.begin(), vs.end()); REP(i, vs.size()) if(!used[vs[i]]) rdfs(vs[i], cnt++, used, cmp, RG); return cmp; } int main() { int v, e; cin >> v >> e; vector<vi> vvi(v), rvvi(v); REP(i, e) { int a,b; cin >> a >> b; vvi[a].pb(b); rvvi[b].pb(a); } vi ans = scc(v, vvi, rvvi); int q; cin >> q; while(q--) { int a, b; cin >> a >> b; cout << (ans[a] == ans[b]) << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define debug(var) cerr << (#var) << " = " << (var) << endl; #else #define debug(var) #endif void init() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const int N = 12; const int S = 1e5+5501; int dp[N][S]; int p[N], c[N]; int rek(int pos, int tot) { if (tot <= 0) return 0; if (pos < 0) return 1e4; int &ret = dp[pos][tot]; if (ret != -1) return ret; ret = rek(pos-1, tot); for (int i = 1; i < p[pos]; ++i) { ret = min(ret, i+rek(pos-1, tot-i*(pos+1))); } return ret = min(ret, p[pos]+rek(pos-1, tot-p[pos]*(pos+1)-c[pos])); } void solve() { memset(dp, -1, sizeof(dp)); int d, g; scanf("%d%d", &d, &g); g /= 100; for (int i = 0; i < d; ++i) { scanf("%d%d", p+i, c+i); c[i] /= 100; } printf("%d", rek(d-1, g)); } int main() { init(); int t = 1; //scanf("%d", &t); while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using vi=vector<int>; using P = pair<int,int>; using Graph = vector<vector<int>>; int main(){ cin.tie(0); ios::sync_with_stdio(false); int d; ll g; cin >> d >> g; vector<int> p(d); vector<ll> c(d),a(d); rep(i,d){ cin >> p[i] >> c[i]; } rep(i,d){ a[i]=(i+1)*100*(p[i]-1); } ll ans=100000000000000000; for(int bit=0;bit<(1<<d);++bit){ ll pr=0,preans=0; vector<int> t; for(int i=0;i<d;++i){ if(bit&(1<<i)){ pr+=((i+1)*100*p[i]+c[i]); preans+=p[i]; }else{ t.push_back(i); } } int x=0; ll res=0; for(auto u:t){ if(res<a[u]) x=u; res=max(res,a[u]); } if(g>pr){ ll y=g-pr; if(y%(100*(x+1))!=0 && (pr+res)>=g){ preans+=(y/(100*(x+1))+1); }else if(y%(100*(x+1))==0 && (pr+res)>=g){ preans+=y/(100*(x+1)); }else{ continue; } } ans=min(ans,preans); } cout << ans << "\n"; return 0; }
1
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; int main() { int n; cin >> n; vector<pair<int, int>> odd(100100, make_pair(0, 0)), even(100100, make_pair(0, 0)); rep (i, n) { int v; cin >> v; if (i % 2) { odd[v].first++; odd[v].second = v; } else { even[v].first++; even[v].second = v; } } sort(odd.rbegin(), odd.rend()); sort(even.rbegin(), even.rend()); if (odd[0].second != even[0].second) cout << (n / 2 - odd[0].first) + (n / 2 - even[0].first) << endl; else cout << min((n / 2 - odd[0].first) + (n / 2 - even[1].first), (n / 2 - odd[1].first) + (n / 2 - even[0].first)) << endl; }
#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() { ll n; cin >> n; map<ll,ll> m, p; rep(i,n/2) { ll a, b; cin >> a >> b; m[a]++, p[b]++; } vector<P> even, odd; //回数 値 for(auto x : m) even.push_back(make_pair(x.second, x.first)); for(auto x : p) odd.push_back(make_pair(x.second, x.first)); sort(all(even)); sort(all(odd));; reverse(all(even)); reverse(all(odd)); ll A = 0, B = 0, ans; if(even[0].second==odd[0].second){ ans = min(n-even[0].first-odd[1].first, n-even[1].first-odd[0].first); } else{ A = even[0].first; B = odd[0].first; ans = n-A-B; } cout << ans << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr ll mod = 1e9 + 7; #define endl '\n' int main() { ios::sync_with_stdio(0); cin.tie(0); string s,t; cin >> s >> t; cout << (t+s) << endl; }
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n, l; cin >> n >> l; int ans = 0; if (l + n - 1 < 0) { for (int i = 0; i < n-1; i++) ans += l + i; } else if (l < 0) { for (int i = 0; i < n; i++) ans += l + i; } else { for (int i = 1; i < n; i++) ans += l + i; } cout << ans << endl; return 0; }
0
#include<bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(ll i=0;i<n;++i) #define INF (1ll<<60) #define mod 1000000007 #define P pair<ll,ll> #define Graph vector<vector<ll>> #define fi first #define se second 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; } vector<ll> sums,sumg; void pre_process(vector<ll> &a,vector<ll> &s){//累積和のvector ll n=(ll)a.size(); s.assign(n+1,0); for(ll i=0;i<n;i++){ s[i+1]=s[i]+a[i]; } } int main(){ ll n,m,Q;cin>>n>>m>>Q; vector<P> pairs; rep(i,m){ ll pf,ps;cin>>pf>>ps; pf--;ps--; pairs.push_back({pf,ps}); } sort(pairs.begin(),pairs.end()); vector<vector<ll>> list(510,vector<ll>(510)),sum(510); rep(i,m){ list[pairs[i].fi+1][pairs[i].se]++; } rep(i,510){ pre_process(list[i],sum[i]); } /* rep(i,11){ rep(j,11){ cout<<sum[i][j]<<" "; } cout<<endl; } */ rep(i,Q){ ll p,q,ans=0;cin>>p>>q; for(ll i=p;i<=q;i++){ ans+=sum[i][q]; } cout<<ans<<endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++) #define repr(i, n) for (ll i = n; i >= 0; i--) #define pb push_back #define COUT(x) cout << (x) << endl #define COUTF(x) cout << setprecision(15) << (x) << endl #define ENDL cout << endl #define DF(x) x.erase(x.begin()) // 先頭文字削除 #define ALL(x) x.begin(), x.end() #define SORT(x) sort(ALL(x)) #define REVERSE(x) reverse(ALL(x)) #define init() \ cin.tie(0); \ ios::sync_with_stdio(false) #define debug(x) cerr << "[debug] " << #x << ": " << x << endl; #define debugV(v) \ cerr << "[debugV] " << #v << ":"; \ rep(i, v.size()) cerr << " " << v[i]; \ cerr << endl; using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using P = pair<ll, ll>; constexpr ll INF = 0x3f3f3f3f3f3f3f3f; constexpr ld PI = 3.141592653589793238462643383279; ll get_digit(ll x) { return to_string(x).size(); } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } vector<P> factorize(ll n) { vector<P> result; for (ll i = 2; i * i <= n; ++i) { if (n % i == 0) { result.pb({i, 0}); while (n % i == 0) { n /= i; result.back().second++; } } } if (n != 1) { result.pb({n, 1}); } return result; } vll divisor(ll n) { vll ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } SORT(ret); return (ret); } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } signed main() { init(); ll N, M, Q; cin >> N >> M >> Q; vector<vll> mat(N, vll(N, 0)); rep(i, M) { ll l, r; cin >> l >> r; l--; r--; mat[l][r]++; } vector<vll> wa(N, vll(N, 0)); rep(i, N) { rep(j, N) { if (i == 0 && j == 0) { wa[i][j] = mat[i][j]; continue; } if (i == 0) { wa[i][j] = wa[i][j - 1] + mat[i][j]; continue; } if (j == 0) { wa[i][j] = wa[i - 1][j] + mat[i][j]; continue; } wa[i][j] = wa[i - 1][j] + wa[i][j - 1] - wa[i - 1][j - 1] + mat[i][j]; } } rep(i, Q) { ll p, q; cin >> p >> q; p--; q--; if (p == 0 && q == 0) { COUT(wa[0][0]); continue; } if (p == 0) { COUT(wa[q][q]); continue; } ll a = wa[q][q]; ll b = wa[q][p - 1]; ll c = wa[p - 1][q]; ll d = wa[p - 1][p - 1]; ll ans = a - b - c + d; COUT(ans); } return 0; }
1
#include <iostream> #include <string> using namespace std; int main(){ string a; while(getline(cin,a)){ int k=0; int check=0; while(true){ if(k>52) break; for(int j=0;j<a.size();j++){ if(isalpha(a[j])!=0) if(a[j]=='z') a[j]='a'; else a[j]++; } for(int i=0;i<a.size()-2;i++){ if(a[i]=='t'&&a[i+1]=='h'&&a[i+2]=='e'&&check==0){ for(int i=0;i<a.size();i++) cout<<a[i]; cout<<endl; check=1; } if(a[i]=='t'&&a[i+1]=='h'&&a[i+2]=='i'&&a[i+3]=='s'&&check==0){ for(int i=0;i<a.size();i++) cout<<a[i]; cout<<endl; check=1; } if(a[i]=='t'&&a[i+1]=='h'&&a[i+2]=='a'&&a[i+3]=='t'&&check==0){ for(int i=0;i<a.size();i++) cout<<a[i]; cout<<endl; check=1; } } k++; } } return 0; }
#include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <string> #include <vector> #include <complex> #include <cstdlib> #include <cstring> #include <numeric> #include <sstream> #include <iostream> #include <algorithm> #include <functional> #define mp make_pair #define pb push_back #define all(x) (x).begin(),(x).end() #define rep(i,n) for(int i=0;i<(n);i++) #define repi(i,a,b) for(int i = (a); i < (b); i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef pair<int,int> pii; const int INF=1<<29; const double EPS=1e-9; const int dx[]={1,0,-1,0},dy[]={0,-1,0,1}; int main(){ int n; while(cin>>n,n){ map<int,int> data; data.clear(); for(int i =0;i <n;i++){ int x; cin>>x; data[x]++; } for(int i =0;i <=9;i++){ if(data[i]==0)cout <<"-"<<endl; else{ for(int j =0;j <data[i];j++){ cout <<"*"; } cout <<endl; } } } return 0; }
0
#include<bits/stdc++.h> using namespace std; const int N=102; int gi() { int x=0,o=1;char ch=getchar(); while((ch<'0'||ch>'9')&&ch!='-') ch=getchar(); if(ch=='-') o=-1,ch=getchar(); while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*o; } int n,m,x,y,ans=0,sx[N][N],sy[N][N]; short f[N][N][N][N]; int main() { cin>>n>>m; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { char ch=getchar(); while(ch!='.'&&ch!='o'&&ch!='E') ch=getchar(); sx[i][j]=sy[i][j]=(ch=='o'); sx[i][j]+=sx[i][j-1];sy[i][j]+=sy[i-1][j]; if(ch=='E') x=i,y=j; } for(int i=x;i;i--) for(int j=y;j;j--) for(int k=x;k<=n;k++) for(int l=y;l<=m;l++) { ans=max(ans,(int)f[i][j][k][l]); if(i>1&&k+1<x+i) f[i-1][j][k][l]=max((int)f[i-1][j][k][l],f[i][j][k][l]+max(0,sx[i-1][min(l,m-y+j)]-sx[i-1][max(j-1,l-y)])); if(k<n&&x+k<n+i) f[i][j][k+1][l]=max((int)f[i][j][k+1][l],f[i][j][k][l]+max(0,sx[k+1][min(l,m-y+j)]-sx[k+1][max(j-1,l-y)])); if(j>1&&l+1<y+j) f[i][j-1][k][l]=max((int)f[i][j-1][k][l],f[i][j][k][l]+max(0,sy[min(k,n-x+i)][j-1]-sy[max(i-1,k-x)][j-1])); if(l<m&&y+l<m+j) f[i][j][k][l+1]=max((int)f[i][j][k][l+1],f[i][j][k][l]+max(0,sy[min(k,n-x+i)][l+1]-sy[max(i-1,k-x)][l+1])); } printf("%d\n",ans); return 0; } //orzgzy //鸡贼明年进队超稳
#include<iostream> #include<math.h> #include<algorithm> #include<stdint.h> #include<vector> #include<deque> #include<stack> #include<functional> #include<string> #include<cstring> #include<time.h> #include<array> #include<iomanip> #include<list> #include<set> #include<map> #include<random> #include<unordered_map> #include<unordered_set> #include<bitset> #include <queue> #include<boost/multiprecision/cpp_int.hpp> using namespace std; using namespace boost::multiprecision; using ll = long long; using ull = unsigned long long; using uint = unsigned int; using ldb = long double; //BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun #define REP(i,a,b) for(ll i = a; i < b; ++i) #define PRI(s) cout << s << endl #define PRIF(v, n) printf("%."#n"f\n", v) #define PRIY PRI("Yes") #define PRIN PRI("No") template<typename A, typename B> void mins(A & a, const B & b) { a = min(a, (A)b); }; template<typename A, typename B> void maxs(A & a, const B & b) { a = max(a, (A)b); }; void factorize(ll X, vector<pair<ll,ll>>& ret) { for (ll i = 2; i * i <= X; ++i) { if (X % i != 0) continue; ret.push_back(pair<ll, ll>{i, 0}); while (X % i == 0) { X /= i; ret.back().second++; } } if (X != 1) ret.push_back(pair<ll, ll>{X, 1}); } int main() { ll mod = 1e9 + 7; ll N, M; cin >> N >> M; vector<vector<ll>> dp(N+1); vector<pair<ll, ll>> P; factorize(M, P); ll maxn = 0; for (const auto& p : P) maxs(maxn, p.second); REP(i, 0, N + 1) dp[i].resize(maxn + 1, 0); REP(i, 0, maxn + 1)dp[1][i] = 1; REP(i, 0, N + 1)dp[i][1] = i; REP(i, 2, N + 1) REP(j, 2, maxn + 1) dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % mod; ll ans = 1; for (const auto& p : P) ans = ans * dp[N][p.second] % mod; PRI(ans); return 0; }
0
#include<bits/stdc++.h> using namespace std; int main() { char ch[3]; cin>>ch; if(ch[0]=='S') { if(ch[1]=='U')cout<<"7"<<endl; else cout<<"1"<<endl; } else if(ch[0]=='T') { if(ch[1]=='U')cout<<"5"<<endl; else cout<<"3"<<endl; } else if(ch[0]=='M')cout<<"6"<<endl; else if(ch[0]=='W')cout<<"4"<<endl; else cout<<"2"<<endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 2e5 + 5, mod = 1e9 + 7; int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); string s[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; string x; cin >> x; int ans = 0; for(int i = 0; i < 7; i++) if(s[i] == x) ans = i; cout << 7 - ans; return 0; }
1
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; #define MOD 1000000007LL #define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++) #define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++) #define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++) #define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++) #define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--) #define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--) #define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--) #define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--) #define iter(i, it) for(auto &(i): (it)) template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) { cout << "(" << m.first << ", " << m.second << ")"; return s; } template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) { ll c = 0; cout << "{ "; iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", "); cout << "}"; return s; } template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) { cout << "{ "; rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", "); cout << "}"; return s; } template<typename T> ostream& operator<<(ostream &s, const list<T> &v) { ll c = 0; cout << "{ "; iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", "); cout << "}"; return s; } int main(void) { string X; ll count = 0; ll s = 0; cin >> X; iter(c, X) { if(c == 'S') s++; else if(s > 0) count++, s--; } cout << X.size() - 2 * count << endl; return 0; }
#pragma GCC optimize("O2,unroll-loops") #include<bits/stdc++.h> #define pb push_back #define all(x) x.begin(), x.end() using namespace std; using vi = vector<int>; int main() { cin.tie(0)->sync_with_stdio(0); string s, t; cin >> s; for(auto i : s) { if(i == 'S') t.pb(i); else if(t.size() && t.back() == 'S') t.pop_back(); else t.pb(i); } cout << t.size(); }
1
#include <bits/stdc++.h> using namespace std; typedef long long lint; typedef vector<lint> vlint; #define inf 1e+9 #define endl "\n" #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i < (int)(n); i++) #define rep_rev(i, n) for (int i = n-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define pb push_back #define eb emplace_back #define Size(c) (int)(c).size() #define lb(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define ub(c, x) distance((c).begin(), upper_bound(all(c), (x))) template <class T> using pq = priority_queue<T>; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; template <class T, class S> inline bool chmax(T &a, S b) { if(a < b) {a = b;return 1;} return 0; } template <class T, class S> inline bool chmin(T &a, S b) { if(a > b) {a = b;return 1;} return 0; } template <class T> void line(vector<T> &x){for (auto&& xi : x) cin >> xi;} inline void IN(void){ return;} template <typename First, typename... Rest> void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;} #define INT(...) int __VA_ARGS__; IN (__VA_ARGS__) #define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__) #define STR(...) string __VA_ARGS__; IN(__VA_ARGS__) template <class T> void UNIQUE(vector<T> &x) { sort(all(x)); x.erase(unique(all(x)), x.end()); } template <class T> void print_vec(T first, T end){ for (auto i = first; i < end - 1; i++) cout << *i << " "; cout << *(end-1) << endl; } template<class... T> void debug_print(T... args){ vector<lint> tmp = initializer_list<lint>{args...}; print_vec(all(tmp)); } template<class T> void print(T a){ cout << a << endl;} vector<string> Yes = {"No", "Yes"}; vector<string> YES = {"NO", "YES"}; int ord(char x){ return (int)(x - 'a');} char chr(lint x){ return (char)(x + (lint)('a'));} lint mod = 1e9+7; // lint mod = lint sum(vlint a){lint ret = 0; for(auto&& v:a) ret += v; return ret;} lint vmini(vlint a, lint &index){ lint ret = LLONG_MAX; rep(i, Size(a)){ if (chmin(ret, a[i])) index = i;} return ret; } lint vmaxi(vlint a, lint &index){ lint ret = -LLONG_MAX; rep(i, Size(a)){ if (chmax(ret, a[i])) index = i;} return ret; } lint vmin(vlint a){ lint ret = LLONG_MAX; for (auto && v : a) chmin(ret, v); return ret; } lint vmax(vlint a){ lint ret = -LLONG_MAX; for (auto && v : a) chmax(ret, v); return ret; } int main(){ INT(n); STR(s); vlint leftw(n+1, 0), rightw(n+1, 0); vlint lefte(n+1, 0), righte(n+1, 0); rep(i, n){ if (s[i] == 'W'){ leftw[i] ++; } else{ lefte[i] ++; } leftw[i+1] += leftw[i]; lefte[i+1] += lefte[i]; } for (int i = n-1; i > 0; --i){ if (s[i] == 'W'){ rightw[i]++; } else{ righte[i]++; } rightw[i-1] += righte[i]; righte[i-1] += righte[i]; } lint ans = 2 * n; rep1(i, n-1){ chmin(ans, leftw[i-1] + righte[i+1]); } chmin(ans, righte[1]); chmin(ans, leftw[n-2]); print(ans); }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; string s; cin >> s; int w = 0, e = 0; for(int i=0; i<n; ++i){ if(s[i]=='W'){w++;} } e = n-w; int nw = 0, ne = e; int mi = INT32_MAX; int c; for(int i=0; i<n; ++i){ if(s[i]=='W' && i>0){nw++;} if(s[i]=='E' && i>0){ne--;} int pen = nw + ne; if(mi>pen){mi = pen; c=i;} } int res = 0; //cout << "c:" << c << endl; for(int i=0; i<n; ++i){ if(s[i]=='W' && i<c){res++;} if(s[i]=='E' && i>c){res++;} } cout << res << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; string x = ""; for(int bit = 0; bit < (1 << 3); bit++){ int seven = s[0] - '0'; x += s[0]; for(int i = 1; i < 4; i++){ if(bit & (1 << (i-1))){ seven += s[i] - '0'; x += '+'; x += s[i]; }else{ seven -= s[i] - '0'; x += '-'; x += s[i]; }//eles }//for if(seven == 7){ break; } seven = 0; x = ""; }//for cout << x << "=7" << endl; }
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで #include <bits/stdc++.h> #define mod 1000000007 #define INF LLONG_MAX #define ll long long #define ln cout<<endl #define Yes cout<<"Yes"<<endl #define No cout<<"No"<<endl #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() using namespace std; ll dx[4]={1,0,-1,0}; ll dy[4]={0,1,0,-1}; int main() { cin.tie(0); ios::sync_with_stdio(false); ll a,b,d,m,n,maxi=0,f=0,mini=INF,sum=0; string str; vector<ll> v(4); char c; rep(i,4){ cin>>c; v[i]=atoll(&c); } if(v[0]+v[1]+v[2]+v[3]==7) {cout<<v[0]<<'+'<<v[1]<<'+'<<v[2]<<'+'<<v[3]<<"=7"<<endl; }else if(v[0]+v[1]+v[2]-v[3]==7) {cout<<v[0]<<'+'<<v[1]<<'+'<<v[2]<<'-'<<v[3]<<"=7"<<endl; }else if(v[0]+v[1]-v[2]+v[3]==7) {cout<<v[0]<<'+'<<v[1]<<'-'<<v[2]<<'+'<<v[3]<<"=7"<<endl; }else if(v[0]+v[1]-v[2]-v[3]==7) {cout<<v[0]<<'+'<<v[1]<<'-'<<v[2]<<'-'<<v[3]<<"=7"<<endl; }else if(v[0]-v[1]+v[2]+v[3]==7) {cout<<v[0]<<'-'<<v[1]<<'+'<<v[2]<<'+'<<v[3]<<"=7"<<endl; }else if(v[0]-v[1]+v[2]-v[3]==7) {cout<<v[0]<<'-'<<v[1]<<'+'<<v[2]<<'-'<<v[3]<<"=7"<<endl; }else if(v[0]-v[1]-v[2]+v[3]==7) {cout<<v[0]<<'-'<<v[1]<<'-'<<v[2]<<'+'<<v[3]<<"=7"<<endl; }else if(v[0]-v[1]-v[2]-v[3]==7) {cout<<v[0]<<'-'<<v[1]<<'-'<<v[2]<<'-'<<v[3]<<"=7"<<endl; } return 0; }
1
#include <iostream> #include <vector> using namespace std; typedef vector <int> VI; typedef vector <VI> VVI; const int dx[5] = { 0, 0, 0, 1, -1 }; const int dy[5] = { 0, 1, -1, 0, 0 }; int w, h; int sx, sy, gx, gy; VVI M; int answer; //================================================== // ’Tõ //================================================== void dfs( int x, int y, int a, int d ) { if ( d > 10 ) return; if ( M[y][x] == 3 ) { if ( answer == -1 ) answer = d; else answer = min( answer, d ); } if ( a > 0 ) { int nx = x + dx[a]; int ny = y + dy[a]; if ( nx < 0 || nx >= w || ny < 0 || ny >= h ) return; if ( M[ny][nx] == 1 ) { M[ny][nx] = 0; dfs( x, y, 0, d ); M[ny][nx] = 1; } else dfs( nx, ny, a, d ); } else { for ( int i = 1; i < 5; i++ ) { int nx = x + dx[i]; int ny = y + dy[i]; if ( nx < 0 || nx >= w || ny < 0 || ny >= h ) continue; if ( M[ny][nx] == 0 || M[ny][nx] == 3 ) { dfs( nx, ny, i, d+1 ); } } } } int main( void ) { while ( cin >> w >> h && w && h ) { //================================================== // •ϐ” //================================================== M = VVI( h, VI( w, 0 ) ); answer = -1; //================================================== // ƒ}ƒbƒv‚Ì“ü—Í //================================================== for ( int i = 0; i < h; i++ ) { for ( int j = 0; j < w; j++ ) { int& s = M[i][j]; cin >> s; // ƒXƒ^[ƒgEƒS[ƒ‹ if ( s == 2 ) { sx = j; sy = i; s = 0; } else if ( s == 3 ) { gx = j; gy = i; } } } //================================================== // ˆ— //================================================== dfs( sx, sy, 0, 0 ); //================================================== // o—Í //================================================== cout << answer << endl; } return 0; }
#include <iostream> #include <algorithm> using namespace std; #define REP(i,n) for(int i = 0; i < (int)(n); ++i) #define DEBUG(x) cerr << #x << " = " << x << endl int F[20][20]; const int INF = (int)1e9; const int dy[4] = { 0, -1, 0, 1 }; const int dx[4] = { 1, 0, -1, 0 }; int W, H; int ans; void solve(const int y, const int x, const int depth) { if(F[y][x] == 3) { ans = min(ans, depth); return; } if(depth >= 10) return; for(int k = 0; k < 4; ++k) { int ny = y, nx = x; if(0 <= ny + dy[k] && ny + dy[k] < H && 0 <= nx + dx[k] && nx + dx[k] < W && F[ny + dy[k]][nx + dx[k]] == 1) continue; bool ok = true; int sy = -1, sx = -1; while(true) { if(F[ny][nx] == 3) break; ny += dy[k]; nx += dx[k]; if(ny < 0 || ny >= H || nx < 0 || nx >= W) { ok = false; break; } if(F[ny][nx] == 1) { sy = ny; sx = nx; F[sy][sx] = 0; ny -= dy[k]; nx -= dx[k]; break; } } if(ok) solve(ny,nx,depth+1); if(sy != -1 && sx != -1) { F[sy][sx] = 1; } } } int main() { while(true) { cin >> W >> H; if(W == 0 && H == 0) break; REP(i,H) REP(j,W) cin >> F[i][j]; ans = INF; REP(i,H) REP(j,W) { if(F[i][j] == 2) solve(i,j,0); } if(ans == INF) cout << -1 << endl; else cout << ans << endl; } }
1
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; #define rep(i,n) for(ll i=0;i<(n);i++) #define repr(i,n) for(ll i=(n-1);i>=0;i--) #define all(x) x.begin(),x.end() #define br cout << "\n"; using namespace std; const long long INF = 1e10; const long long MOD = 1e9+7; using Graph = vector<vector<ll>>; using pll = pair<ll, ll>; template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;} template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;} // 0 false, 1 true // string to int : -48 // a to A : -32 // ceil(a) 1.2->2.0 // c++17 g++ -std=c++17 a.cpp struct PrimeNumber { //O(sqrt(n)) //sosu hantei bool is_prime(long long n){ for(long long i = 2; i * i <= n; i++){ if(n % i == 0) return false; } return n != 1; } //O(sqrt(n)) isn't sorted //yakusu rekkyo vector<long long> divisor(long long n){ vector<long long> res; for(long long i = 1; i * i <= n; i++){ if(n % i == 0){ res.push_back(i); if(i != n / i) res.push_back(n / i); } } return res; } //O(sqrt(n)) //soinsu bunkai map<long long, long long> prime_factor(long long n){ map<long long, long long> res; for(long long i = 2; i * i <= n; i++){ while(n % i == 0){ n /= i; res[i]++; } } if(n != 1) res[n] = 1; return res; } //O(n log log n) //n madeno sosu rekkyo vector<long long> eratosthenes(long long n){ vector<long long> prime; vector<bool> is_prime(n + 1, true); long long p = 0; is_prime[0] = false; is_prime[1] = false; for(long long i = 2; i <= n; i++){ if(is_prime[i]) prime.push_back(i); for(long long j = 2 * i; j <= n; j += i) is_prime[j] = false; } return prime; } }; int main() { std::cout << std::fixed << std::setprecision(15); ll n, m; cin >> n >> m; ll ans = 1; PrimeNumber p; vector<ll> vec = p.divisor(m); rep(i, vec.size()){ ll d = m / vec[i]; if(d >= n) ans = max(ans, vec[i]); } cout << ans << endl; }
/* Great things never come from comfort zones, "whatever the mind of a man can conceive and believe,it can achieve." */ #include <bits/stdc++.h> #define ll long long #define scf(n) scanf("%d",&n) #define lscf(n) scanf("%lld",&n) #define lpri(n) printf("%lld ",n) #define pri(n) printf("%d ",(int)n) #define prin(n) printf("%d\n",(int)n) #define lprin(n) printf("%lld\n",n) #define rep(i,ini,n) for(ll i=ini;i<(int)n;i++) #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(),x.end() #define tc int tt; scf(tt); while(tt--) #define inf INT_MAX #define ninf INT_MIN #define gcd __gcd #define bitcount(n) __builtin_popcount(n) typedef double dd; using namespace std; const ll mod =1e9+7; const int N = 1e6+7; void my_dbg() { cout << endl; } template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) { cout << ' ' << A; my_dbg(B...); } #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__) int main() { ll n,m; lscf(n),lscf(m); ll a=1; for(ll i=m/n;i>1;i--) { if((m-i*n)%i==0) { a=i; break; } } lprin(a); }
1
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int x, y, z; cin >> x >> y >> z; cout << z << " " << x << " " << y << endl; return 0; }
#include <iostream> #include <string> using namespace std; int main(){ string S; cin >> S; S.at(3) = '8'; cout << S; return 0; }
0
#include<bits/stdc++.h> using namespace std; #define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' typedef long long ll; typedef pair<ll,ll> pll; typedef long double ld; const ll inf=1e9+7; const ll mod=1e9+7; const double PI=acos(-1.0); signed main(){ ll n;cin>>n; vector<ll>x(n),y(n); rep(i,n){ cin>>x[i]>>y[i]; } rep(i,n){ vector<double>a(0); rep(j,n){ if(i==j)continue; a.pb(atan2(y[j]-y[i],x[j]-x[i])); } ll m=a.size(); rep(i,m){ a.pb(a[i]+2.0*PI); } sort(all(a)); double ma=0.0; rep(i,m*2-1){ ma=max(ma,a[i+1]-a[i]); } ma=max(0.0,ma-PI); cout<<fixed<<setprecision(10)<<ma/PI/2.0<<endl; } }
//Relive your past life. //Face your demons. //The past is never dead,it is not even past. //The memories are not only the key to the past but...also to the future. //coded in Rusty Lake #include<cmath> #include<math.h> #include<ctype.h> #include<algorithm> #include<bitset> #include<cassert> #include<cctype> #include<cerrno> #include<cfloat> #include<ciso646> #include<climits> #include<clocale> #include<complex> #include<csetjmp> #include<csignal> #include<cstdarg> #include<cstddef> #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> #include<cwchar> #include<cwctype> #include<deque> #include<exception> #include<fstream> #include<functional> #include<iomanip> #include<ios> #include<iosfwd> #include<iostream> #include<istream> #include<iterator> #include<limits> #include<list> #include<locale> #include<map> #include<memory> #include<new> #include<numeric> #include<ostream> #include<queue> #include<set> #include<sstream> #include<stack> #include<stdexcept> #include<streambuf> #include<string> #include<typeinfo> #include<utility> #include<valarray> #include<vector> #include<string.h> #include<stdlib.h> #include<stdio.h> //#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define ll long long #define pb push_back #define mp make_pair #define orz 1000000007 #define fi first #define se second using namespace std; struct P{int x,y;}; P mns(P x,P y){x.x-=y.x,x.y-=y.y;return x;} ll det(P x,P y){return x.x*1ll*y.y-x.y*1ll*y.x;} int n; pair<pair<int,int>,int> p[105]; int U,D,iu[105],id[105],Q,iq[105]; P pu[105],pd[105],pq[105]; double ans[105],PI=6.2831853071795864769; int main(){ scanf("%d",&n); for(int i=1;i<=n;++i)scanf("%d%d",&p[i].fi.fi,&p[i].fi.se),p[i].se=i; sort(p+1,p+n+1); for(int i=1;i<=n;++i){ P a; a.x=p[i].fi.fi,a.y=p[i].fi.se; while(U>1&&det(mns(pu[U],pu[U-1]),mns(a,pu[U]))>=0)--U; pu[++U]=a; iu[U]=p[i].se; } for(int i=1;i<=n;++i){ P a; a.x=p[i].fi.fi,a.y=p[i].fi.se; while(D>1&&det(mns(pd[D],pd[D-1]),mns(a,pd[D]))<=0)--D; pd[++D]=a; id[D]=p[i].se; } for(int i=1;i<=U;++i)++Q,iq[Q]=iu[i],pq[Q]=pu[i]; for(int i=D-1;i>1;--i)++Q,iq[Q]=id[i],pq[Q]=pd[i]; if(Q==2){ ans[iq[1]]=ans[iq[2]]=0.5; } else{ pq[Q+1]=pq[1]; pq[0]=pq[Q]; for(int i=1;i<=Q;++i){ P p1=mns(pq[i],pq[i-1]),p2=mns(pq[i+1],pq[i]); double d=acos((p1.x*1.0*p2.x+p1.y*1.0*p2.y)/sqrt(p1.x*1.0*p1.x+p1.y*1.0*p1.y)/sqrt(p2.x*1.0*p2.x+p2.y*1.0*p2.y)); ans[iq[i]]=d/PI; } } for(int i=1;i<=n;++i)printf("%.10lf\n",ans[i]); return 0; }
1
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++) #define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--) #define yes cout << "yes" << endl; #define Yes cout << "Yes" << endl; #define YES cout << "YES" << endl; #define no cout << "no" << endl; #define No cout << "No" << endl; #define NO cout << "NO" << endl; #define AC cout << "AC" << endl; #define WA cout << "WA" << endl; #define out(s) cout << s << endl; #define ll long long #define ull unsigned long long #define vi vector<int> const double PI = 3.14159265358979323846; int main() { int N, K; cin >> N >> K; cout << (N % K > 0 ? 1 : 0) << endl; }
/*ॐ नमो भगवते वासुदेवाय नमः*/ #include<bits/stdc++.h> using namespace std; #define int long long #define F first #define S second #define all(x) (x).begin(), (x).end() #define allrev(x) (x).rbegin(), (x).rend() #define pb push_back #define pf push_front #define fori(i, a, n) for(int i = a; i < n; ++i) #define MAX(x) (*max_element(all(x))) #define MIN(x) (*min_element(all(x))) #define sortarr(a, n) sort(a, a + n) #define sortvec(V) sort(all(V)) struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; typedef unordered_map<int, int, custom_hash> u_map; typedef unordered_set<int, int, custom_hash> u_set; typedef vector<int> V; typedef pair<int , int> pairi; typedef set<int> seti; typedef priority_queue<int> p_queue; typedef deque<int> deqi; const int MOD = 1e9+7; const int INF = 1e9+8; const double pi = 3.14159265359; int binpow(int a, int b, int m) { a %= m; int res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } void solve() { int N, R; cin >> N >> R; if(N >= 10) cout << R << endl; else{ cout << R + 100 * (10 - N) << endl; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); solve(); cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n "; }
0
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; using ll = long long; using p = pair<int,int>; using Graph = vector<vector<int>>; int main(int argc, const char * argv[]) { cin.tie(0); ios::sync_with_stdio(false); int a,b; cin>>a>>b; int ans=1; for(int i=0;;i++){ if(ans>=b){ cout<<i<<endl; return 0; } ans=ans-1+a; } }
#include<bits/stdc++.h> using namespace std; int main() { int a,b; cin>>a>>b; if((b-1)%(a-1)==0) cout<<(b-1)/(a-1)<<endl; else cout<<(b-1)/(a-1)+1<<endl; }
1
#include <bits/stdc++.h> //万能头文件 using namespace std; int main() { string a; int pos=0; //记录位置 cin>>a; a=a+"D"; //为防止最后一个字母是"A",添加一个不是"C"的字母 while(1) { pos=a.find("A",pos); //find()函数查找位置 if(pos<0) //如果没找到,返回-1 { cout<<"No"<<endl; //endl养成好习惯 break; //跳出循环 } if(a[pos+1]=='C') //判断"A"下一个是不是"C" { cout<<"Yes"<<endl; break; //跳出循环 } pos++; //下一次从pos+1找起 } return 0; }
#include <bits/stdc++.h> #define _overload(_1,_2,_3,name,...) name #define _rep(i,n) _range(i,0,n) #define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__) #define _rrep(i,n) _rrange(i,n,0) #define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i) #define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__) #define _all(arg) begin(arg),end(arg) #define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg)) #define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary) #define clr(a,b) memset((a),(b),sizeof(a)) #define bit(n) (1LL<<(n)) // #define DEBUG #ifdef DEBUG #define dump(...) fprintf(stderr, __VA_ARGS__) #else #define dump(...) #endif template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;} template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;} using namespace std; using ll=long long; using vi=vector<int>; using vll=vector<ll>; const double EPS = 1e-10; const double PI = acos(-1.0); const ll inf =1LL << 62; const ll mod=1000000007LL; const int dx[4]={1,0,-1,0}; const int dy[4]={0,1,0,-1}; ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;} ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;} ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;} ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;} ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);} random_device rd; mt19937 mt(rd()); uniform_int_distribution<int> dice(1,6); uniform_real_distribution<double> score(0.0,10.0); int main(void){ cin.tie(0); ios::sync_with_stdio(false); string in; cin >> in; int n = in.size(); rep(i, n-1){ if(in.substr(i, 2) == "AC"){ cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
1
/* -ensure correct output format -ensure printing required output -reread the problem statement */ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll>pll; typedef pair<ll,pair<ll,ll>>plll; #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); #define vll(v) v.begin(),v.end() #define all(x) x.rbegin(),x.rend() #define min3(a, b, c) min(a, min(b, c)) #define max3(a, b, c) max(a, max(b, c)) #define F first #define S second #define in freopen("input.txt", "r", stdin) #define out freopen("output.txt", "w", stdout) #define minheap int,vector<int>,greater<int> #define pb push_back #define eb emplace_back #define ischar(x) (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z')) #define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U')) #define bug cout<<"BUG"<<endl; const int Max = 2e6 + 10; const int Mod = 1e9 + 7; const double PI =3.141592653589793238463; bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b) { return (a.first > b.first); } ll lcm(ll a,ll b) { if(a==0 || b==0)return 0; return a/__gcd(a,b)*b; } void input(ll ara[],ll n) { for(ll i=0; i<n; i++)cin>>ara[i]; } void print(ll ara[],ll n) { for(ll i=0; i<n; i++) cout<<ara[i]<<" "; cout<<endl; } ll tree[Max]; ll query(ll idx) { ll sum=0; while(idx>0) { sum+=tree[idx]; idx-= idx & (-idx); } return sum; } void update(ll idx,ll x,ll n) { while(idx<=n) { tree[idx]+=x; idx+= idx & (-idx); } } int main() { fastread(); ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0; bool flag=false; cin>>n; for(i=1; i<=n; i++) { cin>>a; update(a,1,n); if(query(n)-query(a-1)==i)ans++; } cout<<ans<<endl; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> policy_set; #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (ll)(x).size() #define fill(a) memset(a, 0, sizeof (a)) #define ALL(c) c.begin(),c.end() #define ff first #define ss second #define pb push_back #define eb emplace_back typedef long double ld; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vll; void preprocess(){ } const ll N=3e5+7; const ll INF=1e18+1; const ll MOD=1e9+7; //Have to ramp up more on implementation skillz to do it fast, // and debug skillz, it is not as easy as you think with two pointers ll n,a[N],pref[N]; ll f(ll l1,ll r1,ll l2, ll r2){ return abs((pref[r1]-pref[l1-1])-(pref[r2]-pref[l2-1])); } // So we will implement the two pointer solution to this also // very well // So in ternary search we always need to check 4 values near, the start,end // like in that cf problem, no need to do this all over again ll find_left(ll i){ ll start=1,end=i-1; while(start<=end){ ll mid1=(2*start+end)/3,mid2=(start+2*end)/3; // cout<<start<<" "<<mid1<<" "<<mid2<<" "<<end<<"\n"; if(f(1,mid1,mid1+1,i)>f(1,mid2,mid2+1,i)) start=mid1+1; else end=mid2-1; } // cout<<start<<" "<<end<<"\n"; ll arr[]={start,end},ans=1e18,ansidx=start; for(ll j=0;j<2;j++) for(ll jj=-1;jj<=1;jj++){ ll idx=arr[j]+jj; if(idx<1 || idx>i-1)continue; if(ans>f(1,idx,idx+1,i))ans=f(1,idx,idx+1,i),ansidx=idx; } return ansidx; } // I remember facing this problem before ll find_right(ll i){ ll start=i+1,end=n-1; while(start<=end){ ll mid1=(2*start+end)/3,mid2=(start+2*end)/3; if(f(i+1,mid1,mid1+1,n)>f(i+1,mid2,mid2+1,n)) start=mid1+1; else end=mid2-1; } ll arr[]={start,end},ans=1e18,ansidx=start; for(ll j=0;j<2;j++) for(ll jj=-1;jj<=1;jj++){ ll idx=arr[j]+jj; if(idx<i+1 || idx>n)continue; if(ans>f(i+1,idx,idx+1,n))ans=f(i+1,idx,idx+1,n),ansidx=idx; } return ansidx; } void solve(){ cin>>n; for(ll i=1;i<=n;i++)cin>>a[i],pref[i]=pref[i-1]+a[i]; ll ans=INT64_MAX; // cout<<find_left(4)<<" "<<f(1,1,2,4)<<" "<<f(1,2,3,4)<<" "<<f(1,3,4,4)<<"\n"; // return; for(ll i=1;i<=n;i++){ //i ins the middle split, in this case // 1..left left+1..i i+1..right right+1..n ll left=find_left(i),right=find_right(i); // cout<<left<<" "<<right<<"\n"; vector<ll> vecs({pref[left],pref[i]-pref[left],pref[right]-pref[i],pref[n]-pref[right]}); sort(all(vecs)); ans=min(ans,vecs.back()-vecs[0]); } cout<<ans<<"\n"; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); preprocess(); int t=1; //cin>>t; //cout<<t<<endl; for(int i=0;i<t;i++) solve(); return 0; }
0
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)n;i++) #define all(c) (c).begin(),(c).end() #define mp make_pair #define pb push_back #define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++) #define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pi; const int inf = (int)1e9; const double INF = 1e12, EPS = 1e-9; char in[1000100]; int main(){ fgets(in, sizeof(in), stdin); vector<pi> v; int cnt = 0, ans = 0; for(int i = 0; ; i++){ if(i && in[i] != in[i - 1]){ v.pb(mp(in[i - 1], cnt)); cnt = 1; } else cnt++; if(!in[i]) break; } rep(i, v.size() - 2) if(v[i].first == 'J' && v[i + 1].first == 'O' && v[i + 2].first == 'I'){ if(v[i + 1].second <= v[i].second && v[i + 1].second <= v[i + 2].second) ans = max(ans, v[i + 1].second); } cout << ans << endl; return 0; }
#include "bits/stdc++.h" using namespace std; //int N,M,K,L,R,H,W; long long int N,M,K,L,R,H,W; constexpr long long int MOD=1000000007; //constexpr int MOD=1000000007; //constexpr int MOD=998244353; //constexpr long long int MOD=998244353; constexpr long double EPS=1e-8; int main(){ ios::sync_with_stdio(false); cin.tie(0); int ans=0; string s; cin>>s; s='P'+s+'P'; for(int i=1;i<=s.size();i++){ if(s[i]=='O'){ int add=0; while(s[i+add]=='O')add++; bool flag=true; for(int k=i-1;k>=i-add;k--){ //cout<<"J "<<k<<endl; flag&=s[k]=='J'; if(!flag)break; } for(int k=i+add;k<i+2*add;k++){ //cout<<"I "<<k<<endl; flag&=s[k]=='I'; if(!flag)break; } if(flag)ans=max(ans,add); i+=add-1; } } cout<<ans<<endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main(){ cout<<fixed<<setprecision(12); int N,K;cin>>N>>K; vector<double> A(N); for(int i=0;i<N;i++) cin>>A.at(i); //vector<double> ans(N-K+1); priority_queue<double> ans; double X=0; for(int i=0;i<K;i++) X+=(A.at(i)+1.0)/2; ans.push(X); for(int i=1;i<N-K+1;i++){ X-=(A.at(i-1)+1.0)/2; X+=(A.at(i+K-1)+1.0)/2; ans.push(X); } cout<<ans.top()<<endl; }
#include <bits/stdc++.h> #define int long long #define x first #define y second #define getbit(x, i) (((x) >> (i)) & 1) using namespace std; typedef pair<int, int> pii; #define hashset unordered_set #define hashmap unordered_map #define newline fast_writechar('\n') #define unify(arr) arr.resize(unique(arr.begin(), arr.end()) - arr.begin()) #define getbit(x, i) (((x) >> (i)) & 1) template <typename T> vector<T> readvector(size_t sz) { vector<T> res(sz); for (size_t i = 0; i < sz; ++i) { cin >> res[i]; } return res; } template <typename T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) { std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, " ")); return out; } int mylog(int n) { return 63 - __builtin_clzll(n); } inline int binPow(int x, int deg, int mod) { int ans = 1; for (int i = sizeof(deg) * CHAR_BIT - 1; i >= 0; i--) { ans *= ans; ans %= mod; if (getbit(deg, i)) ans *= x; ans %= mod; } return ans; } /** Interface */ inline int readInt(); inline int readUInt(); inline void readWord(char *s); inline int fast_readchar(); // you may use readchar() instead of it inline void writeInt(int x); inline void fast_writechar(int x); // you may use putchar() instead of it inline void writeWord(const char *s); inline void fast_flush(); // ====================== END ====================== const int MAXN = 2e6 + 10; const int MOD = 1e9 + 7; const int INF = 1e18; void solve() { int n, k; cin >> n >> k; auto arr =readvector<int>(n); arr.insert(arr.begin(), 0); for (int i = 1; i <= n; i++) arr[i] += arr[i - 1]; int ans = 0; for (int i = 0; i + k <= n; i++) { ans = max(ans, arr[i + k] - arr[i] + k); } cout << fixed << setprecision(1) << ans / 2. << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // t = readInt(); // cin >> t; for (int i = 1; i <= t; ++i) { // cout << "Case #" << i << ": "; solve(); } // fast_flush(); return 0; } /** Read */ static const int buf_size = 4096; inline int fast_readchar() { static char buf[buf_size]; static int len = 0, pos = 0; if (pos == len) pos = 0, len = fread(buf, 1, buf_size, stdin); if (pos == len) return -1; return buf[pos++]; } inline int readUInt() { int c = fast_readchar(), x = 0; while (c <= 32) c = fast_readchar(); while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = fast_readchar(); return x; } inline int readInt() { int s = 1, c = fast_readchar(); int x = 0; while (c <= 32) c = fast_readchar(); if (c == '-') s = -1, c = fast_readchar(); while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = fast_readchar(); return x * s; } inline void readWord(char *s) { int c = fast_readchar(); while (c <= 32) c = fast_readchar(); while (c > 32) *s++ = c, c = fast_readchar(); *s = 0; } /** Write */ static int write_pos = 0; static char write_buf[buf_size]; inline void fast_writechar(int x) { if (write_pos == buf_size) fwrite(write_buf, 1, buf_size, stdout), write_pos = 0; write_buf[write_pos++] = x; } inline void fast_flush() { if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0; } inline void writeInt(int x) { if (x < 0) fast_writechar('-'), x = -x; char s[24]; int n = 0; while (x || !n) s[n++] = '0' + x % 10, x /= 10; while (n--) fast_writechar(s[n]); } inline void writeWord(const char *s) { while (*s) fast_writechar(*s++); }
1
#include<iostream> #include<sstream> #include<cstdio> #include<cstdlib> #include<vector> #include<string> #include<stack> #include<queue> #include<deque> #include<set> #include<map> #include<algorithm> #include<functional> #include<utility> #include<cmath> #include<ctime> #include<complex> using namespace std; #define REP(i,s,e) for(int i=int(s);i<=int(e);i++) #define rep(i,n) for(int i=0;i<int(n);i++) int g(int a,int b){ int c=max(a,b),d=min(a,b); if(c%d==0) return d; else return g(d,c%d); } int main(){ int n,p,q,r; cin >> n; if(n==2){ cin >> p >> q; REP(i,1,g(p,q)) if(g(p,q)%i==0) cout << i << endl; } if(n==3){ cin >> p >> q >> r; REP(i,1,g(g(p,q),r)) if(g(g(p,q),r)%i==0) cout << i << endl; } return 0; }
#include<cstdio> #include<algorithm> #include<cstring> #include<cctype> using namespace std; void _2(); void _3(); int main(){ int n; scanf("%d",&n); (n == 2) ? _2() : _3(); return 0; } void _2(){ int a,b; scanf("%d%d",&a,&b); int mi = min(a,b); for(int i = 1; i <= mi; i++){ if(a % i == 0 && b % i == 0){ printf("%d\n",i); } } return; } void _3(){ int a,b,c; scanf("%d%d%d",&a,&b,&c); int mi = min(a,min(b,c)); for(int i = 1; i <= mi; i++){ if(a % i == 0 && b % i == 0 && c % i == 0){ printf("%d\n",i); } } return; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n, p; while( cin >> n >> p, n || p ) { vector<int>data( n ); int now = 0, P = p; while( 1 ) { for( size_t i = 0; i < n; i++ ) { data[i] += p / n; } p %= n; for( size_t i = 0; i < p; i++ ) { now++; now %= n; data[now]++; } now++; now %= n; while( !data[now] ) { now++; now %= n; } p = data[now]; if( P == p ) { break; } data[now] = 0; //cout << p << P << endl; //cout << data[0] << data[1] << data[2] << endl; } now--; if( now < 0 ) { now = n - 1; } cout << now << endl; } }
#include<bits//stdc++.h> using namespace std; int main(){ int n,p; while(cin>>n>>p&&n!=0&&p!=0){ int a[50]; fill(a,a+n,0); int m=0,p2=p; while(true){ if(p==0){ p+=a[m]; a[m]=0; } else{ p--; a[m]++; } if(p==0&&a[m]==p2) break; m++; if(m==n) m=0; } cout<<m<<endl; } }
1
#include <bits/stdc++.h> using namespace std; int main(){ int K,N; cin>>N>>K; double p[N]; vector<double>t(N+1,0); for(int i=0;i<N;i++){ cin>>p[i]; t[i+1]=t[i]+p[i]*(0.5)+0.5; //cout<<i<<" "<<t[i]<<endl; } double maxp=0; for(int i=0;i<N-K+1;i++){ maxp=max(maxp,t[i+K]-t[i]); } cout<<setprecision(18)<<maxp<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; /********************************************************************/ #define M1 1000000007 #define M2 998244353 const double pi = 3.14159265; #define ll long long #define pll pair<ll,ll> #define forr(i, n) for(ll i=0;i<n;i++) #define pb push_back #define ppb pop_back #define mp make_pair #define MT make_tuple #define V(a) vector<a> #define vi vector<ll> #define CASE(t) ll t; cin>>t; while(t--) #define endl '\n' #define space ' ' #define enter cout<<endl #define yes cout<<"YES"<<endl #define no cout<<"NO"<<endl #define all(x) x.begin(), x.end() #define sortall(x) sort(all(x)) #define collect(v, n) for(ll i = 0; i < n;i++){cin>>v[i];} #define deci(n) fixed << setprecision(n) //sets no of digits to show after decimal #define setcount(n) __builtin_popcount(n) //the number of ones in the int #define setcountll(n) __builtin_popcountll(n) //the number of ones in the ll #define parity(n) __builtin_parity(n) //the parity (even or odd) of the number of ones #define clz(n) __builtin_clz(n) //the number of zeros at the beginning of the number #define clzll(n) __builtin_clzll(n) //the number of zeros at the beginning of the ll #define ctz(n) __builtin_ctz(n) //the number of zeros at the end of the number void deb(ll x) { cout << x << endl;} void deb(int x) { cout << x << endl;} void deb(unsigned int x) { cout << x << endl;} void deb(unsigned ll x) { cout << x << endl;} void deb(float x) { cout << x << endl;} void deb(double x) { cout << x << endl;} void deb(long double x) { cout << x << endl;} void deb(char x) {cout << '\'' << x << '\'' << endl;} void deb(string s) { cout << '\"' << s << '\"' << endl;} void deb(vector<ll> v) { for (auto x : v) cout << x << ' '; cout << endl;} void deb(bool bb) {cout << (bb ? "True" : "False") << endl;} void deb(map<ll, ll> mpp) {for (auto x : mpp) cout << x.first << ' ' << x.second << endl;} void deb(pair<ll, ll> pp) { cout << "{" << pp.first << "," << pp.second << "}" << endl;} ll gcd(ll x, ll y) { if (x == 0) return y; return gcd((ll) y % x, (ll) x); } template<typename T> #define o_set(T) tree<T, null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update> //member functions : //1. order_of_key(k) : number of elements strictly lesser than k //2. find_by_order(k) : k-th element in the set // MULTISET ==> less_equal // SET ==> less ll powM(ll x, ll y, ll m) { ll ans = 1, r = 1; x %= m; while (r > 0 && r <= y) { if (r & y) { ans *= x; ans %= m; } r <<= 1; x *= x; x %= m; } return ans; } map<long long, long long> factorize(long long n) { map<long long, long long> ans; for (long long i = 2; i * i <= n; i++) { while (n % i == 0) { ans[i]++; n /= i; } } if (n > 1) { ans[n]++; n = 1; } return ans; } ll countBits(ll n) { ll count = 0; while (n) { count++; n >>= 1; } return count; } ll isP(ll n) { if (n == 0 || n == 1) return 0; for (ll i = 2; i <= sqrt(n); i++) { if (n % i == 0) return 0; } return 1; } /* **********END OF TEMPLATE*********** */ ll check(ll ar[], ll mid, ll k, ll n) { ll tmp = 0; for (ll i = 0; i < n; i++) { tmp += (ar[i] / mid + (ar[i] % mid != 0) - 1); } if (tmp <= k) return 1; return 0; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; ll k; cin >> n >> k; double ar[n]; for (ll i = 0; i < n; i++) { cin >> ar[i]; ar[i] = (double)(ar[i] + 1) / (double)2; } double prefs[n + 1]; prefs[0] = 0.0000; for (ll i = 0; i < n; i++) { prefs[i + 1] = prefs[i] + ar[i]; } double mx = -1; for (ll i = k; i <= n; i++) { if (prefs[i] - prefs[i - k] > mx) mx = (prefs[i] - prefs[i - k]); } cout << deci(10) << mx << endl; return 0; }
1
// Template #include <iostream> #include <iomanip> #include <vector> #include <string> #include <queue> #include <deque> #include <stack> #include <tuple> #include <map> #include <set> #include <algorithm> #include <utility> #include <cmath> #define rep(i, x) for (int i = 0; i < (x); ++i) #define rng(i, x, y) for (int i = (x); i < (y); ++i) #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define pb push_back using namespace std; using ll = long long; constexpr int inf = 1001001001; constexpr ll INF = 3003003003003003003; template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;} template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;} // Main Code int main() { int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int>(m)); rep(i, n) rep(j, m) { cin >> a[i][j]; --a[i][j]; } vector<bool> use(m, true); int ans = inf; while (true) { vector<int> cnt(m, 0); rep(i, n) rep(j, m) { if (use[a[i][j]]) { ++cnt[a[i][j]]; break; } } int mx = 0; rep(i, m) chmax(mx, cnt[i]); if (mx == 0) break; chmin(ans, mx); rep(i, m) { if (cnt[i] == mx) use[i] = false; } } cout << ans << "\n"; return 0; }
#include<stdio.h> int h,w; int map[20][20]; int dy[]={1,0,-1,0}; int dx[]={0,1,0,-1}; int ans; int out(int y,int x){ return y<0||h<=y||x<0||w<=x; } void search(int depth,int y,int x){ int i,ny,nx; if(ans <= depth)return; for(i=0;i<4;i++){ ny = y+dy[i]; nx = x+dx[i]; if(out(ny,nx) || map[ny][nx]==1)continue; do{ if(map[ny][nx]==3){ ans = depth; return; } ny += dy[i]; nx += dx[i]; }while(!out(ny,nx) && map[ny][nx]!=1); if(!out(ny,nx) && map[ny][nx]==1){ map[ny][nx]=0; search(depth+1,ny-dy[i],nx-dx[i]); map[ny][nx]=1; } } } int main(){ int i,j; int sy,sx; while(scanf("%d%d",&w,&h), w|h){ for(i=0;i<h;i++){ for(j=0;j<w;j++){ scanf("%d",&map[i][j]); if(map[i][j]==2){ sy=i;sx=j; } } } ans=11; search(1,sy,sx); printf("%d\n",ans==11?-1:ans); } }
0
#include <algorithm> #include <bitset> #include <cassert> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<int, pii> pipii; typedef pair<double, double> pdd; typedef pair<ll, pii> key; ll facs[1005]; ll ifacs[1005]; const int MOD = 1000000007; ll modpow(ll b, ll e, ll m) { ll r = 1; while(e) { if(e%2) { r*=b; r%=m; } b*=b; b%=m; e/=2; } return r; } ll solve(int sz, int num) { ll ret = facs[sz*num]; for(int i = 0; i < num; i++) { ret *= ifacs[sz]; ret %= MOD; } ret *= ifacs[num]; ret %= MOD; // cout << num << " groups of size " << sz << " is " << ret << endl; return ret; } ll dp[1005]; ll ndp[1005]; void solve() { facs[0] = 1; for(int i = 1; i <= 1000; i++) { facs[i] = facs[i-1] * i; facs[i] %= MOD; } ifacs[1000] = modpow(facs[1000], MOD-2, MOD); for(int i = 999; i >= 0; i--) { ifacs[i] = ifacs[i+1] * (i+1); ifacs[i] %= MOD; } int n, a, b, c, d; cin >> n >> a >> b >> c >> d; dp[0] = 1; for(int x = a; x <= b; x++) { memset(ndp, 0, sizeof(ndp)); for(int y = c; y <= d; y++) { for(int i = 0; i + x*y <= n; i++) { if(dp[i] == 0) continue; ll scale = facs[i+x*y]; scale *= ifacs[x*y]; scale %= MOD; scale *= ifacs[i]; scale %= MOD; scale *= solve(x, y); scale %= MOD; ndp[i+x*y] += dp[i] * scale; ndp[i+x*y] %= MOD; } } for(int i = 0; i <= n; i++) { dp[i] += ndp[i]; dp[i] %= MOD; } } cout << dp[n] << "\n"; } void casesolve() { int t; cin >> t; for(int i = 1; i <= t; i++) { cout << "Case #" << i << " "; solve(); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); // casesolve(); }
#include <algorithm> #include <bitset> #include <tuple> #include <cstdint> #include <cstdio> #include <cctype> #include <assert.h> #include <stdlib.h> #include <stdio.h> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <limits> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define ArraySizeOf(array) (sizeof(array) / sizeof(array[0])) #define res(i,n) for(int i=n;;i++) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i,n) for(int i=1;i<n;i++) #define rev(i,n) for(int i=n-1;i>=0;i--) #define REV(i,n) for(int i=n-1;i>0;i--) #define req(i,n,m) for(int i=n;i<m;i++) #define REQ(i,n,m,l) for(int i=n;i<m;i+=l) #define _GLIBCXX_DEBUG int INF = 1e9 + 7; unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1) { unsigned day; if (dow < dow1) dow += 7; day = dow - dow1; day += 7 * n - 6; return day; } signed gcd(long long x, long long y) { if (y == 0)return x; return gcd(y, x % y); } signed lcm(long long x, long long y) { return x / gcd(x, y) * y; } unsigned DayToWeekNumber(unsigned day) { return (day - 1) / 7 + 1; } unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0) { return (dow0 + 35 + day - day0) % 7; } using namespace std; signed main() { int N; cin >> N; vector<string>s(N); rep(i, N)cin >> s[i]; int M; cin >> M; vector<string>t(M); rep(i, M)cin >> t[i]; vector<int>v(N+1); rep(i, N) { rep(j, N)if (s[i] == s[j])v[i]++; rep(j, M)if (s[i] == t[j])v[i]--; } sort(v.begin(), v.end()); cout << v[N] << endl; }
0
#include <iostream> #include <sstream> #include <iomanip> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <climits> #include <cfloat> using namespace std; string solve(string s) { int n = s.size(); for(;;){ for(int i=0; i<n; ++i){ if('a' <= s[i] && s[i] <= 'z'){ if(s[i] == 'z') s[i] = 'a'; else ++ s[i]; } } istringstream iss(s); string s1; while(iss >> s1){ if(s1 == "the" || s1 == "this" || s1 == "that") return s; } } } int main() { for(;;){ string s; getline(cin, s); if(s == "") return 0; cout << solve(s) << endl; } }
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<cmath> #include<iomanip> #include<map> using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long INF = 1LL << 60; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ long long n; cin>>n; string result=""; while(n){ n--; result+=(char)('a'+(n%26)); n/=26; } reverse(result.begin(),result.end()); cout<<result<<endl; }
0
#include <bits/stdc++.h> using namespace std; void solve(long long N, long long M, std::vector<long long> p, std::vector<std::string> S){ vector<long long> ac(N+1, 0); vector<long long> wa(N+1, 0); for(int i = 0; i < M; ++i){ if(ac[p[i]] == 0){ if(S[i] == "AC") ac[p[i]] = 1; else wa[p[i]] += 1; } } //for(auto i : ac) cout << "AC: " << i << endl; //for(auto i : wa) cout << "WA: " << i << endl; long long cnt_wa = 0; for(int i = 0; i < N + 1; ++i){ if(ac[i] == 1) cnt_wa += wa[i]; } cout << accumulate(ac.begin(), ac.end(), 0LL) << " " << cnt_wa << endl; return; } int main(){ long long N; scanf("%lld",&N); long long M; scanf("%lld",&M); std::vector<long long> p(M); std::vector<std::string> S(M); for(int i = 0 ; i < M ; i++){ scanf("%lld",&p[i]); std::cin >> S[i]; } solve(N, M, std::move(p), std::move(S)); return 0; }
#include <iostream> #include <algorithm> #include <cmath> using namespace std; const double PI = 3.14159265358979323846; int main() { int n, m, a[1001], b[1001]; cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < m; ++i) { cin >> b[i]; } int r[1001] = {}; for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) { if (a[j] <= b[i]) { r[j]++; break; } } } int max = 0; int maxI = 0; for (int k = 0; k < n; ++k) { if (max < r[k]) { max = r[k]; maxI = k; } } cout << maxI + 1 << endl; return 0; }
0
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; const int MAX = 100000; const int INF = 1e9; const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1}; #define PI 3.14159265358979323846264338327950L #define MOD 1000000007 //setprecision(15) #define MAX_T 1000+1 int T[MAX_T]; // 素因数分解O(√n) map<int, int> prime_factor(int n) { map<int, int> res; for (int i = 2; i*i <= n; i++) { while (n % i == 0) { ++res[i]; n /= i; } } if (n != 1) res[n] = 1; return res; } int main() { int N; cin >> N; for (int i = 2; i <= N; i++) { map<int, int> ma = prime_factor(i); for (auto j = ma.begin(); j != ma.end(); j++) { T[j->first] += j->second; } } ll ans = 1; for (int i = 2; i < MAX_T; i++) { if (T[i] == 0) continue; ans = ans * (T[i] + 1) % MOD; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define rep(i,m,n) for(int i=m;i<n;i++) ll mod=1e9+7; int main(){ int n; cin>>n; int a[n]; rep(i,0,n) cin>>a[i]; ll dp[n+1][3]; rep(i,0,3) dp[0][i]=0; dp[1][0]=a[0]; dp[1][1]=0; dp[1][2]=0; rep(i,1,n){ rep(j,0,3){ if((i+1)%2==0){ dp[i+1][0]=max(dp[i-1][0]+a[i],dp[i][0]); dp[i+1][1]=max(dp[i-1][1]+a[i],dp[i][1]); dp[i+1][2]=max(dp[i-1][2]+a[i],dp[i][2]); } else{ dp[i+1][0]=dp[i-1][0]+a[i]; dp[i+1][1]=max(dp[i-1][1]+a[i],dp[i][0]); dp[i+1][2]=max(dp[i-1][2]+a[i],dp[i][1]); } } } if(n%2==0) cout<<dp[n][0]<<endl; else cout<<dp[n][1]<<endl; }
0
#include <iostream> #include <iomanip> #include <vector> #include <algorithm> #include <string> #include <ctype.h> #include <cstdlib> #include <cmath> #include <stack> #include <map> #define _GLIBCXX_DEBUG using namespace std; using ll = long long; int main() { int x,y,z; cin >> x >> y >> z; swap(x,y); swap(x,z); cout << x << " " << y << " " << z << endl; }
#include<bits/stdc++.h> using namespace std; int main() { string a,b,c; int x,y; cin>>a>>b>>c; x=a.size(); y=b.size(); if(a[x-1]==b[0] && b[y-1]==c[0]) cout<<"YES"; else cout<<"NO"; return 0; }
0
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める int main() { int a,b; cin >> a >> b; if(a == b) cout << a + b << endl; else if(a > b) cout << a*2-1 << endl; else cout <<b*2-1 << endl; return 0; }
#include<iostream> using namespace std; int main () { int a,b; int m,n,j,k; cin>>a>>b; m=a+(a-1); n=b+(b-1); k=a+b; if( m>n && m>k) cout<<m<<endl; else if (n>m &&n>k) cout<<n<<endl; else cout<<k<<endl; return 0; }
1
#include <bits/stdc++.h> #define rep(i,n) for(int (i) = 0; (i) < (n);(i)++) using namespace std; const int limit = 100010; vector<int> graph[2][limit]; void add_edge(int from, int to) { graph[0][from].push_back(to); graph[1][to].push_back(from); } auto scc(int n) { vector<int> order(n); iota(begin(order), end(order), 0); vector<int> comp; rep(type, 2) { stack<int> stk; vector<int> norder; vector<int> itr(n, 0); comp.assign(n, -1); int idx = 0; /* rep(i, n) cerr << order[i] << " "; cerr << endl; */ for (auto &it : order) { if (comp[it] != -1) continue; stk.push(it); while (!stk.empty()) { const int v = stk.top(); comp[v] = idx; for(int &i = itr[v]; i < graph[type][v].size();++i){ const int v2 = graph[type][v][i]; if (comp[v2] == -1){ stk.push(v2); break; } } if(itr[v] == graph[type][v].size()){ norder.push_back(v); stk.pop(); } } idx++; } if (type == 1) break; reverse(begin(norder), end(norder)); order = norder; } return make_tuple(order, comp); } vector<int> order, comp; int main(void) { int n, m; cin >> n >> m; rep(i, m) { int a, b; cin >> a >> b; add_edge(a, b); } tie(order, comp) = scc(n); int q; cin >> q; rep(loop,q){ int u,v; cin >> u >> v; if(comp[u]==comp[v]) puts("1"); else puts("0"); } return 0; }
#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() #define RALL(a) (a).rbegin(),(a).rend() using namespace std; using ll = long long; using P = pair<ll, ll>; const double PI = 3.14159265358979; struct Edge{ ll cost, to; }; void solve() { ll n, a, b, c; cin >> n; vector< vector<Edge> > G(n, vector<Edge>()); for(int i = 0; i < n - 1; ++i) { cin >> a >> b >> c; a--; b--; G[a].emplace_back(Edge{c, b}); G[b].emplace_back(Edge{c, a}); } ll q, k, x, y; cin >> q >> k; k--; const ll INF = 1LL << 60; vector<ll> d(n, INF); d[k] = 0; priority_queue<P, vector<P>, greater<P>> que; que.push(P(0, k)); // P(cost, start) while (!que.empty()) { P p = que.top(); que.pop(); ll node = p.second; if (d[node] < p.first) continue; for (const auto& edge : G[node]) { if (d[edge.to] > d[node] + edge.cost) { d[edge.to] = d[node] + edge.cost; que.push(P(d[edge.to], edge.to)); } } } for(int i = 0; i < q; ++i) { cin >> x >> y; x--; y--; cout << d[x] + d[y] << endl; } } int main() { fastio; solve(); return 0; }
0
#include<iostream> #include<queue> #include<utility> using namespace std; long int inf=100000*100000+100; int main() { int v,e,r; int s[500000]; int t[500000]; int d[500000]; long int dis[100000]; cin>>v>>e>>r; for(int i=0;i<e;i++) { cin>>s[i]>>t[i]>>d[i]; } for(int i=0;i<v;i++) { dis[i]=inf; } dis[r]=0; for(int i=0;i<v-1;i++) { int end=1; for(int j=0;j<e;j++) { if(dis[t[j]]>dis[s[j]]+d[j]) { dis[t[j]]=dis[s[j]]+d[j]; end=0; } } if(end==1) break; } for(int i=0;i<v;i++) { if(dis[i]==inf) cout<<"INF"<<endl; else cout<<dis[i]<<endl; } }
#include <iostream> #define N 21 using namespace std; int main(){ int n,m,x,y,rx,ry,l,cnt,d[N][N]; char c; while(1){ for(int i=0;i<N;i++) for(int j=0;j<N;j++) d[i][j]=0; cin>>n; if(!n) break; for(int i=0;i<n;i++) cin>>x>>y,d[N-y-1][x]=1; cin>>m; rx=ry=10; cnt=0; while(m--){ cin>>c>>l; while(l--){ if(c=='N') ry--; if(c=='E') rx++; if(c=='S') ry++; if(c=='W') rx--; if(d[ry][rx]) d[ry][rx]=0,cnt++; } } if(cnt==n) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }
0
#include<bits/stdc++.h> using namespace std; signed main(){ int a,b=180; cin>>a; cout<<b*(a-2)<<"\n"; }
/* UTF-8 */ #include <iostream> #include <string> #include <vector> #include <deque> #include <list> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <array> #include <queue> #include <stack> #include <algorithm> #include <tuple> #include <numeric> #include <type_traits> #include <limits> #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <string.h> #define USE_COLORED 1 #ifdef USE_COLORED static const char stdout_pre[] = "\033[1m"; // bold black static const char stderr_pre[] = "\033[31;1m"; // bold red static const char stdxxx_post[] = "\033[m"; // 当然ながら GCC(g++)/libstdc++ 依存 #include <ext/stdio_filebuf.h> using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>; class colored_stdio_filebuf : public stdio_filebuf { private: const char* const pre_; const char* const post_; public: colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post) { } protected: std::streamsize xsputn(const char* s, std::streamsize count) override { stdio_filebuf::xsputn(pre_, strlen(pre_)); auto ret = stdio_filebuf::xsputn(s, count); stdio_filebuf::xsputn(post_, strlen(post_)); return ret; } }; #endif int main() { #ifdef USE_COLORED if (getenv("DEBUG")) { std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post)); std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post)); } else #endif { int fd = open("/dev/null", O_WRONLY); dup2(fd, 2); close(fd); } int N; std::cin >> N; std::cout << (180 * (N-2)) << "\n"; }
1
#ifdef _MSC_VER #define _CRT_SECURE_NO_WARNINGS #endif #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> #include <cassert> #include <string.h> #include <unordered_set> #include <unordered_map> using namespace std; typedef long long int64; typedef unsigned long long uint64; #define two(X) (1<<(X)) #define twoL(X) (((int64)(1))<<(X)) #define contain(S,X) (((S)&two(X))!=0) #define containL(S,X) (((S)&twoL(X))!=0) const double pi=acos(-1.0); const double eps=1e-11; template<class T> inline void ckmin(T &a,T b){if(b<a) a=b;} template<class T> inline void ckmax(T &a,T b){if(b>a) a=b;} template<class T> inline T sqr(T x){return x*x;} typedef pair<int,int> ipair; #define SIZE(A) ((int)A.size()) #define LENGTH(A) ((int)A.length()) #define MP(A,B) make_pair(A,B) #define PB(X) push_back(X) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,a) for(int i=0;i<(a);++i) #define ALL(A) A.begin(),A.end() const int oo=1000000000; int n,m; int f[1<<15][16][16]; int g[16][16]; int main() { #ifdef _MSC_VER freopen("input.txt","r",stdin); #endif std::ios::sync_with_stdio(false); while (cin>>n>>m) { memset(g,255,sizeof(g)); REP(i,m) { int x,y,z; cin>>x>>y>>z; --x; --y; g[x][y]=g[y][x]=z; } REP(set,two(n)) { REP(x,n) REP(y,n) f[set][x][y]=oo; if (!contain(set,0)) continue; if (contain(set,n-1) && set!=two(n)-1) continue; REP(x,n) f[set][x][x]=0; for (int set1=set-1;set1>0;set1=((set1-1)&set)) { if (!contain(set1,0)) continue; int set2=(set^set1); int base=0; REP(x,n) if (contain(set1,x)) REP(y,n) if (contain(set2,y) && g[x][y]>=0) base+=g[x][y]; REP(x,n) if (contain(set1,x)) REP(y,n) if (contain(set1,y)) REP(z,n) if (contain(set2,z) && g[y][z]>=0) { ckmin(f[set][x][z],base+f[set1][x][y]-g[y][z]); } } } printf("%d\n",f[two(n)-1][0][n-1]); #ifndef _MSC_VER system("pause"); #endif } return 0; }
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <queue> #include <bitset> #include <set> #include <map> #include <stack> #include <list> #define rep(i,n) for(int i=0;i<n;i++) #define REP(i,b,n) for(int i=b;i<n;i++) #define SORT(c) sort((c).begin(),(c).end()) #define DESCSORT(c) sort(c.begin(), c.end(), greater<int>()) const float PI = 3.1415926; static const int INFTY = (1<<30); using namespace std; int B[102][102]; int M[102][102]; int w, h, xs, ys, xg, yg, n, res; void bfs(int x, int y, int c) { if(x <= 0 || y <= 0 || x > w+1 || y > h+1) return; if(B[x][y] != c) return; if(M[x][y] == 1) { return; } else { M[x][y] = 1; } if(x == xg && y == yg) { res = 1; return; } bfs(x+1, y, c); bfs(x, y+1, c); bfs(x-1, y, c); bfs(x, y-1, c); } int main() { while(cin >> w >> h, w) { // ????????? rep(i, w+1) { rep(j, h+1) { B[i][j] = 0; M[i][j] = 0; } } res = 0; cin >> xs >> ys; cin >> xg >> yg; cin >> n; // ?????????????????? rep(i, n) { int c, d, x, y; cin >> c >> d >> x >> y; B[x][y] = c; B[x+1][y] = c; B[x][y+1] = c; B[x+1][y+1] = c; if ( d == 0 ) { B[x+2][y] = c; B[x+3][y] = c; B[x+2][y+1] = c; B[x+3][y+1] = c; } else { B[x][y+2] = c; B[x][y+3] = c; B[x+1][y+2] = c; B[x+1][y+3] = c; } } if(B[xs][ys] != 0) bfs(xs, ys, B[xs][ys]); if(res) cout << "OK" << endl; else cout << "NG" << endl; } return 0; }
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll sum[1000000+5]; void Get(ll l,ll r,ll &first,ll &second) { ll res =INT_MAX; ll left = l; ll right = r-1; while(left<=right) { ll mid = (left+right)>>1; ll a = sum[mid]-sum[l-1]; ll b = sum[r]-sum[mid]; if(abs(a-b)<res) { res = abs(a-b); first= a; second = b; } if(a<=b) { left = mid+1; } else { right = mid-1; } } } int main() { ll n; cin>>n; for(int i=1;i<=n;i++) { int x; cin>>x; sum[i] =sum[i-1]+x; } // for(int i=0;i<=n;i++) // { // cout<<sum[i]<<" "; // } // cout<<endl; ll result =INT_MAX; for(ll i=2;i<=n-2;i++) { ll a; ll b; Get(1,i,a,b); ll c,d; Get(i+1,n,c,d); // cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl; ll mx = max(max(a,b),max(c,d)); ll mn = min(min(a,b),min(c,d)); result = min(result,abs(mx-mn)); } cout<<result<<endl; return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define ll long long #define ull unsigned long long using namespace std; int main() { ll N; cin >> N; vector <ll> A(N); vector <ll> B(N); vector <ll> C(N); for (int ii = 0; ii < N; ++ii) cin >> A[ii]; for (int ii = 0; ii < N; ++ii) cin >> B[ii]; for (int ii = 0; ii < N; ++ii) cin >> C[ii]; sort(A.begin(), A.end()); sort(B.begin(), B.end()); sort(C.begin(), C.end()); ll ans = 0; for (int ii = 0; ii < N; ++ii){ ll sum = 0; auto aitr = lower_bound(A.begin(), A.end(), B[ii]); ll anum = (aitr!=A.begin()) ? aitr - A.begin() : 0; auto citr = upper_bound(C.begin(), C.end(), B[ii]); ll cnum = C.end() - citr; ans += anum * cnum; } cout << ans << "\n"; return 0; }
0
// Alapan // IIITH #include<bits/stdc++.h> using namespace std; // data types #define ll long long int #define ld long double //funtion macros // stl #define lp(var,start,end) for (ll var = start; var <=end ; ++var) #define ilp(var,start,end) for(ll var = start; var>=end ; var--) #define pb push_back #define mp make_pair #define pf push_front #define ff first #define ss second #define vll vector<ll> #define vld vector<ld> #define pll pair<ll,ll> #define pld pair<ld,ld> #define vpll vector<pll> #define vpld vector<pld> #define all(X) X.begin(),X.end() #define sz(x) ((ll)((x).size())) #define mod 1000000007 // utility functions ll max(ll a, ll b){ if(a>b)return a; return b; } ll min(ll a, ll b){ if(a<b)return a; return b; } ll power(ll x, ll y, ll m=mod){ if(y<0){ x = power(x,m-2); y = -y; } ll ans=1; x = x % m; while(y){ if(y&1) ans = (ans*x)%m; y=y/2; x=(x*x)%m; } return ans; } ll factorial(ll n, ll m=mod){ ll ans = 1; ll i = 1; while(i<=n){ ans = (ans*i)%m; i++; } return ans; } /////////////////////////////////////////////////////////// ll n,m,v,p; bool f(ll arr[], ll mid){ // cout << mid << "\n"; ll temp[n]; for(ll i=0;i<n;i++){ temp[i] = arr[i]; } ll val = temp[mid] + m; ll i=0; ll cnt = (v-1)*m; ll more=0; ll alreadymore = 0; for(ll i=0;i<n;i++){ if(val < temp[i]) alreadymore++; if(alreadymore >= p) return 0; } while(more < p-1 && i<n){ if(i!= mid) cnt -= m; if(cnt <= 0) return true; if(temp[i]+m > val) more++; i++; } if(temp[i] > val) return false; while(i<n){ if(i!=mid) cnt = cnt - min((val-temp[i]),m); if(cnt <= 0) return true; i++; } return false; } int main(){ cin >> n >> m >> v >> p; ll arr[n]; for(ll i=0;i<n;i++){ cin >> arr[i]; } sort(arr,arr+n); reverse(arr,arr+n); // for(ll i=0;i<n;i++) cout << arr[i] << " "; // cout << endl; ll l = 0; ll r = n-1; while(l < r){ ll mid = l + (r-l+1)/2; if(f(arr,mid)) l = mid; else r = mid-1; } cout << l+1 << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define MODV 1000000007 #define INF INT_MAX // 2147483647 #define INFLL LLONG_MAX // 9223372036854775807 #define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++) #define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++) #define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--) #define perf(i, n) for(ll i=((ll)(n)); i>0; i--) #define all(v) v.begin(), v.end() #define endl "\n" #define vi vector<ll> #define vvi vector<vector<ll>> #define Yes() cout << "Yes" << endl #define YES() cout << "YES" << endl #define No() cout << "No" << endl #define NO() cout << "NO" << endl #define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15); template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; } using namespace std; int main(){ Init(); ll n, a, b; cin >> n >> a >> b; vi x(n, 0); ll sum = 0; rep(i, n){ cin >> x[i]; if(i > 0) sum += (a*(x[i]-x[i-1]) > b) ? b : a*(x[i]-x[i-1]); } cout << sum << endl; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(void){ int x, y, z; cin >> x >> y >> z; cout << z << " " << x << " " << y << endl; return 0; }
#include <iostream> #include <string> int main() { int A, B, C; std::cin >> A; std::cin >> B; std::cin >> C; std::cout << std::to_string(C) + " " + std::to_string(A) + " " + std::to_string(B) << std::endl; }
1
#include <iostream> #include <vector> #include <math.h> #include <cmath> #include <algorithm> #include <numeric> #include <string> #include <cstring> #include <regex> #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int,int>; using pl4 = pair<ll,ll>; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; using vvs = vector<vs>; using vll = vector<ll>; using vvll = vector<vll>; using vpii = vector<pii>; using vvpii = vector<vpii>; using vpl4 = vector<pl4>; using vvpl4 = vector<vpl4>; #define fi first #define se second #define mp make_pair #define pb push_back #define pob pop_back() #define sz size() #define be begin() #define en end() #define asn assign #define emp empty() #define ft front() #define bk back() #define clr clear() #define ins insert #define era erase #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define rFOR(i,a,b) for(int i=(b);i>=(a);i--) #define SORT(a) sort((a).be,(a).en) #define rSORT(a) sort((a).rbegin(),(a).rend()) #define UNIQUE(a) (a).erase(unique((a).be,(a).en),(a).en) #define PREVP(a) prev_permutation((a).be,(a).en) #define NEXTP(a) next_permutation((a).be,(a).en) #define BINS(a,b) binary_search((a).be,(a).en,(b)) #define LOWB(a,b) (lower_bound((a).be,(a).en,(b))-(a).be) #define UPB(a,b) (upper_bound((a).be,(a).en,(b))-(a).be) #define CNT(a,b) count((a).be,(a).en,b) #define SUM(a) accumulate((a).be,(a).en,0) #define REV(a) reverse((a).be,(a).en) #define REGS(a,b) regex_search((a),regex(b)) #define REGM(a,b) regex_match((a),regex(b)) #define yn(a) cout <<((a)?"yes":"no")<<endl; #define Yn(a) cout <<((a)?"Yes":"No")<<endl; #define YN(a) cout <<((a)?"YES":"NO")<<endl; #define say(a) cout <<(a); #define sal(a) cout <<(a)<<endl; #define sak cout <<endl; #define dbg(a) cout <<(#a)<<": "<<(a)<<endl; #define a2l(a) ((ll)(a-97)) #define A2l(a) ((ll)(a-65)) #define l2a(a) ((char)(a+97)) #define l2A(a) ((char)(a+65)) #define DigN2(a) ((llabs(a)==0)?(1):((ll)(log2(double(llabs(a))))+1)) #define DigN10(a) ((llabs(a)==0)?(1):((ll)(log10(double(llabs(a))))+1)) #define Dig2(a,b) (((a)>>(b))&1) #define Pow2(a) (1<<(a)) #define int ll const ll MOD = 1e9+7; const string alp = "abcdefghijklmnopqrstuvwxyz"; const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);} ll lcm(ll a, ll b){return a/gcd(a,b)*b;} ll min(ll a, ll b){if(a>=b) return b;if(a<b) return a;} ll max(ll a, ll b){if(a>=b) return a;if(a<b) return b;} ll SalV(vll v){ say("{"); FOR(i,0,v.sz-1){ say(v[i]); if(i!=v.sz-1) say(","); } sal("}") } ll DigS10(ll n){ ll m=0; FOR(i,0,DigN10(n)-1){ m+=(ll)((llabs(n)%(ll)(pow(10.0,(double)(i+1))))/(ll)(pow(10.0,(double)i))); } return m; } ll isP(ll n){ if(n<=1) return 0; FOR(i,2,(ll)sqrt(n)){ if(n%i==0) return 0; } return 1; } signed main() { ll K; cin >>K; sal(50); if(K%50==0){ FOR(i,0,49){ say(49+K/50); if(i!=49) say(" "); } } if(K%50!=0){ FOR(i,1,K%50){ say(99+(K/50)-(K%50)); say(" "); } FOR(i,1,50-(K%50)){ say(49+(K/50)-(K%50)); if(i!=(50-(K%50))) say(" "); } } }
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define fi first #define se second #define rep(i,s,n) for(int i = s;i<n;i++) #define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--) #define all(v) (v).begin(),(v).end() #define chmin(a,b) a=min((a),(b)) #define chmax(a,b) a=max((a),(b)) #define endl '\n' #define IOS() ios_base::sync_with_stdio(0);cin.tie(0) typedef long long ll; typedef pair<int,int>pint; typedef vector<int>vint; const ll MOD=1000000007,INF=1e18; int K; signed main() { IOS(); cin>>K; int x=K/50,y=K%50; int N=50; vint a(N,49+x); rep(i,0,50){ a[i]-=y; if(i<y)a[i]+=50; } cout<<50<<endl; rep(i,0,50){ if(i)cout<<" "; cout<<a[i]; } cout<<endl; return 0; }
1
#include <cstdio> //#include <iostream> //#include <string> using namespace std; // cl /EHsc xxx.cpp int main(int argc, char *argv[]) { int n; scanf("%d", &n); int *ary = new int[n]; int v; int t = n; while (t) { scanf("%d", &v); ary[--t] = v; } for (int j = 0; j < n; j++) { printf((j == n-1) ? "%d\n" : "%d ", ary[j]); } delete[] ary; return 0; }
#include <iostream> int main(int argc, char** argv) { int n; std::cin >> n; int a[100]; for (int i = 0; i < n; ++i) { std::cin >> a[i]; } for (int i = n - 1; i > 0; --i) { std::cout << a[i] << " "; } std::cout << a[0] << std::endl; }
1
#include <iostream> #include <string> #include <cstring> #include <algorithm> #include <list> #include <set> #include <map> #include <vector> #include <math.h> #include <fstream> #include <sstream> #include <unordered_map> #include <ctime> using namespace std; const unsigned long long BASE = (unsigned long long)(1e9 + 7); #define FROM_0(i, n) for(int i = 0; i < (n); i++) #define FROM_S(i, s, e) for(int i = (s); i < (e); i++) #define ITER_BEGIN_END(iter, vec) for(auto iter = vec.begin(); iter != vec.end(); iter++) int priceA[100001], priceB[100001]; int main() { int a, b, m; cin >> a >> b >> m; int minA = 200000, minB = 200000; FROM_0(i, a) { cin >> priceA[i]; minA = min(minA, priceA[i]); } FROM_0(i, b) { cin >> priceB[i]; minB = min(minB, priceB[i]); } int minPrice = minA + minB; FROM_0(i, m) { int x, y, c; cin >> x >> y >> c; x--; y--; int price = priceA[x] + priceB[y] - c; minPrice = min(price, minPrice); } cout << minPrice << endl; return 0; }
#include <algorithm> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i)) #define rep(i,n) FOR(i,0,n) #define pb push_back #define eb emplace_back #define mp make_pair #define fst first #define snd second #define all(v) begin(v), end(v) #define debug(x) cerr<< #x <<": "<<x<<endl #define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vector<int> > vvi; typedef vector<ll> vll; typedef vector<vector<ll> > vvll; template<class T> using vv=vector<vector< T > >; struct UF { vector<int> par; vector<int> sizes; UF(int n) : par(n), sizes(n, 1) { rep(i,n) par[i] = i; } int root(int x) { if (x == par[x]) return x; return par[x] = root(par[x]); } void unite(int x, int y) { x = root(x); y = root(y); if (x == y) { return; } if (sizes[x] < sizes[y]) { swap(x, y); } par[y] = x; sizes[x] += sizes[y]; sizes[y] = 0; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return sizes[root(x)]; } }; // UF int V, E; vvi edge; ll cost; void kruskal() { cost = 0; UF uf(V); rep (i, E) { auto e = edge[i]; if (uf.same(e[1], e[2])) { continue; } uf.unite(e[1], e[2]); cost += e[0]; if (uf.size(e[1]) == V) { break; } } return; } int main() { scanf("%d %d", &V, &E); edge.assign(E, vi(3)); rep (i, E) { int s, t, w; scanf("%d %d %d", &s, &t, &w); edge[i][0] = w; edge[i][1] = s; edge[i][2] = t; } sort(all(edge)); kruskal(); printf("%lld\n", cost); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n,k;cin>>n>>k; int ans = 0; if (n%k > 0) ans++; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; using P = pair<int,int>; const long long inf = 1000000001; // const 書き換え禁止 const double PI = 3.14159265358979323846; //M_PI はライブラリ int main(void){ int n,k; cin >> n >> k; if(n%k == 0){ cout << 0 << endl; }else{ cout << 1 << endl; } }
1
#include <bits/stdc++.h> using namespace std; int n; long long a[1001][1001], prm[2003]; int vis[100005], cnt; void euler() { vis[1] = 1; for (int i = 2; i <= 10000; ++i) { if (!vis[i]) prm[++cnt] = i; for (int j = 1; j <= cnt && i * prm[j] <= 10000; ++j) { vis[i * prm[j]] = 1; if (!(i % prm[j])) break; } } } long long gcd(long long x, long long y) { while (y ^= x ^= y ^= x %= y) void(); return x; } long long lcm(long long x, long long y) { if (!x || !y) return x + y; return x / gcd(x, y) * y; } int main() { scanf("%d", &n), euler(); if (n == 2) return puts("4 7\n23 10\n"), 0; for (int i = 1; i <= n; ++i) for (int j = (i + 1 & 1) + 1; j <= n; j += 2) a[i][j] = prm[(i + j) / 2] * prm[n + (i - j) / 2 + (n + 1) / 2]; for (int i = 1; i <= n; ++i) for (int j = (i & 1) + 1; j <= n; j += 2) a[i][j] = lcm(lcm(a[i - 1][j], a[i][j - 1]), lcm(a[i][j + 1], a[i + 1][j])) + 1; for (int i = 1; i <= n; ++i, puts("")) for (int j = 1; j <= n; ++j) printf("%lld ", a[i][j]); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define sqr(x) ((x)*(x)) #define mp make_pair #define uint unsigned #define PI pair<int,int> inline char gc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++; } #define gc getchar inline ll read(){ ll x = 0; char ch = gc(); bool positive = 1; for (; !isdigit(ch); ch = gc()) if (ch == '-') positive = 0; for (; isdigit(ch); ch = gc()) x = x * 10 + ch - '0'; return positive ? x : -x; } inline void write(ll a){ if(a<0){ a=-a; putchar('-'); } if(a>=10)write(a/10); putchar('0'+a%10); } inline void writeln(ll a){write(a); puts("");} inline void wri(ll a){write(a); putchar(' ');} inline ull rnd(){ return ((ull)rand()<<30^rand())<<4|rand()%4; } const int N=505,M=100005,x[4]={1,-1,0,0},y[4]={0,0,1,-1}; ll ans[N][N],tot; int n,p[M],vis[M],q[M]; #define ld long double ll lcm(ll x,ll y){ if(x==0)return y; if(y==0)return x;//cout<<x<<" "<<y<<endl; //if((ld)x/__gcd(x,y)*y>(1e15))while(1); return x/__gcd(x,y)*y; } signed main(){ n=500; for(int i=2;i<M;i++)if(!vis[i]){ q[++tot]=i; for(int j=i;j<M;j+=i)vis[j]=1; } for(int i=1;i<=1000;i++)if(i&1)p[i]=q[(i+1)/2]; else p[i]=q[1001-i/2]; int tx=248,ty=249; for(int i=1;i<=n*2;i+=2){ if(i<=n){tx+=2; ty+=1;} else {tx++; if(i!=n+1)ty--;} int x=i<=n?1:i-n+1,y=i<=n?n-i+1:1; int t=min(n-x+1,n-y+1); for(int j=0;j<t;j++){ ans[x+j][y+j]=p[tx]*p[ty-j]; //if(x+j==500)cout<<y+j<<" "<<tx<<" "<<ty-j<<endl; //if(abs(x+j-2)+abs(y+j-2)==1)cout<<tx<<" "<<ty-j<<endl; } } for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if((i+j)%2==0){ //cout<<i<<" "<<j<<endl; for(int k=0;k<4;k++)ans[i][j]=lcm(ans[i][j],ans[i+x[k]][j+y[k]]); ans[i][j]++; } //set<ll> s; //for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){ s.insert(ans[i][j]);} //cout<<s.size()<<endl; n=read(); for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ write(ans[i][j]); putchar(' '); } puts(""); } } /* */
1
#include <bits/stdc++.h> #define REP(i,n) for (long long i=0;i<(n);i++) #define FOR(i,a,b) for (long long i=(a);i<(b);i++) #define RREP(i,n) for(long long i=n;i>=0;i--) #define RFOR(i,a,b) for(long long i=(a);i>(b);i--) #define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl #define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl #define dump(x) cerr << #x << " => " << (x) << endl #define dumpP(p) cerr << "( " << p.first << " , " << p.second << " )" << ends #define SORT(c) sort((c).begin(),(c).end()) #define MIN(vec) *min_element(vec.begin(), vec.end()) #define MAX(vec) *max_element(vec.begin(), vec.end()) #define UNIQ(vec) vec.erase(unique(vec.begin(), vec.end()),vec.end()) //ソートの必要あり #define IN(n,m) (!(m.find(n) == m.end())) #define ENUM(m) for (auto itr = m.begin(); itr != m.end(); ++itr) #define dump_MAP(m) for(auto itr = m.begin(); itr != m.end(); ++itr) { cerr << itr->first << " --> " << itr->second << endl; } #define FINDL(vec,x) (lower_bound(vec.begin(),vec.end(),x) - vec.begin()) #define FINDU(vec,x) (upper_bound(vec.begin(),vec.end(),x) - vec.begin()) #define ROUND(N) setprecision(N) #define ROUND_PRINT(N,val) cout << fixed;cout << setprecision(N) << val << endl #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() using namespace std; constexpr long double pi = M_PI; constexpr double eps = 1e-10; constexpr long mod = 1000000007; constexpr short shINF = 32767; constexpr long loINF = 2147483647; constexpr long long llINF = 9223372036854775807; typedef long long LL; typedef vector<LL> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<LL,LL> pr; typedef vector<pr> VP; struct Order { bool operator() (pr const& a,pr const& b) const { return a.first > b.first || ((a.first == b.first) && (a.second > b.second)); } }; template<typename T> int diff(vector<T> &a,vector<T> &b) { int la = a.size(); int lb = b.size(); int inf = numeric_limits<int>::max() - 10; vector<vector<int>> dp(la+1,vector<int>(lb+1,inf)); REP(i,lb+1) dp[0][i] = i; REP(i,la+1) dp[i][0] = i; REP(i,la) { REP(j,lb) { if (a[i] == b[j]) dp[i+1][j+1] = dp[i][j]; dp[i+1][j+1] = min({dp[i+1][j]+1,dp[i][j+1]+1,dp[i][j]+1,dp[i+1][j+1]}); } } return dp[la][lb]; } int main(void) { string s1,s2; cin >> s1 >> s2; vector<char> A(s1.size()),B(s2.size()); REP(i,s1.size()) A[i] = s1[i]; REP(i,s2.size()) B[i] = s2[i]; cout << diff<char>(A,B) << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める int main() { string s,t; cin >> s>> t; cout << t << s << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main(){ int n,m; int a[1000]={}; int b[1000]={}; int max =0; int t; int cnt[1000]={}; cin >> n >> m; for(int i=0;i<n;i++) { cin >> a[i]; } for(int j=0;j<m;j++) { cin >> b[j]; } for(int j=0;j<m;j++) { for(int i =0;i<n;i++) { if(a[i] <= b[j]) { cnt[i]++; break; /* if(max < a[i]) { max = a[i]; t=i; }*/ } } // cnt[t]++; } max =0; for(int i =0;i<n;i++) { if(max < cnt[i]) { max = cnt[i]; t=i; } } cout << t+1 << endl; }
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main(){ while(true){ int n,m; cin >> n ; if(cin.eof()) break; cin >> m; vector<int> a(1000); vector<int> b(1000); vector<int> c(1000); vector<bool> u(1000); vector<int> ans(1000); fill(u.begin(),u.end(),true); for(int i=0;i<n;i++){ cin >> a[i]; }; for(int i=0;i<m;i++){ cin >> b[i]; } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(u[j] && a[i] <= b[j]){ u[j] = false; ans[i]++; } } } int res = -1,ansnum = 0;; for(int i=0;i<n;i++){ if(res < ans[i]){ res = ans[i]; ansnum = i + 1; } } cout << ansnum << endl; } return 0; }
1
#include <stdio.h> int main(){ int n,m,i,j,x[20],y[20],z[30],p[31],q[31],a[20],b[20],c[20],s; char d[i]; while(1) { scanf("%d",&n); if (n==0) break; for (i=0;i<n;i++) { scanf("%d %d",&x[i],&y[i]); } scanf("%d",&m); for (i=0;i<m;i++) { getchar(); scanf("%c %d",&d[i],&z[i]); } p[0]=10; q[0]=10; for (i=0;i<m;i++) { p[i+1]=p[i]; q[i+1]=q[i]; if (d[i]=='N') {q[i+1]=q[i]+z[i];} if (d[i]=='S') {q[i+1]=q[i]-z[i];} if (d[i]=='E') {p[i+1]=p[i]+z[i];} if (d[i]=='W') {p[i+1]=p[i]-z[i];} } s = 1; for (i=0;i<n;i++) { c[i] = 0; for (j=0;j<m;j++) { a[i] = b[i] = 0; if ((x[i]<=p[j]&&x[i]>=p[j+1])||(x[i]>=p[j]&&x[i]<=p[j+1])) { a[i]=1; } if ((y[i]<=q[j]&&y[i]>=q[j+1])||(y[i]>=q[j]&&y[i]<=q[j+1])) { b[i]=1; } c[i] |= a[i]*b[i]; } } for (i=0;i<n;i++) { s*=c[i]; } if (s==1) {printf("Yes\n");} if (s!=1) {printf("No\n");} } return 0; }
#include <string.h> #include <iostream> #include <queue> #include <complex> #include <functional> #include <cmath> #include <cstdio> #include <algorithm> #include <vector> #include <string> #include <map> using namespace std; typedef complex<double> P; #define EPS (1e-10) #define EQ(a,b) (abs((a)-(b)) < EPS) #define EQV(a,b) ( EQ( a.real(), b.real() ) && EQ( a.imag(), b.imag() ) ) #define rep(i,n) for(int i=0;i<n;i++) #define FOR(i,a,n) for(int i=a;i<=n;i++) //--------------------------------------------------------------------- struct Point { int x, y; }; struct Oridir { char o; int d; }; int n, m; bool check[20]; vector<Point> juel(20); vector<Oridir> mov(30); int main() { while (cin >> n, n) { memset(check, false, sizeof(check)); rep(i, n) cin >> juel[i].x >> juel[i].y; cin >> m; rep(i, m) cin >> mov[i].o >> mov[i].d; //???????????? int x = 10, y = 10; rep(i, m) { while (mov[i].d--) { switch (mov[i].o) { case 'N': y++; break; case 'S': y--; break; case 'E': x++; break; case 'W': x--; break; default: break; } rep(j, n) { if (check[j]) continue; if (x == juel[j].x && y == juel[j].y) check[j] = true; } } } int suc = true; rep(j, n) { if (!check[j]) { suc = false; cout << "No" << endl; break; } } if (suc) cout << "Yes" << endl; } return 0; }
1
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int n,x; cin >> n >> x; vector<int> a(n); for(int i=0; i<n; i++){ cin >> a.at(i); } ll cnt=0; if(a.at(0)>x){ cnt+=a.at(0)-x; a.at(0)=x; } for(int i=1; i<n; i++){ ll k=a.at(i)+a.at(i-1); if(k>x){ cnt+=k-x; a.at(i) -= k-x; } } cout << cnt << endl; }
#include<iostream> #include<cstring> #include<cstdio> #include<vector> #include<queue> #include<cmath> #include<algorithm> using namespace std; typedef long long ll; const int mod=1e9+7; int main(){ int n,x,a; while(~scanf("%d%d%d",&n,&x,&a)){ ll ans=0; if(a>x) ans+=a-x,a=x; while(--n){ int b; scanf("%d",&b); if(a+b>x) ans+=a+b-x,a=x-a; else a=b; } printf("%lld\n",ans); } return 0; }
1
#include<bits/stdc++.h> using namespace std; int main(){ int n, k; cin >> n >> k; int sum = 1; for (int i =0;i < n;i++){ if ( (sum * 2) >= (sum + k) ) { sum += k; } else sum *= 2; } cout << sum << 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) { int N, x; cin >> N >> x; vector<int> a(N); for(int i=0; i<N; i++) cin >> a[i]; sort(a.begin(), a.end()); int ans = 0; for(int i=0; i<N; i++){ if(x - a[i] < 0) break; if(i == N-1 && x - a[i] != 0) break; x -= a[i]; ans++; } cout << ans << endl; return 0; }
0
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<cmath> #include<set> #include<bitset> #include<map> #define fo(i,a,b) for(int i=a;i<=b;i++) #define fd(i,a,b) for(int i=a;i>=b;i--) using namespace std; typedef long long LL; typedef double db; int get(){ char ch; while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-'); if (ch=='-'){ int s=0; while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0'; return -s; } int s=ch-'0'; while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0'; return s; } const int N = 17; const int L = 32775; const int INF = 2e+9; int f[L][N],val[L]; int n,m; struct edge{ int x,y,l; }e[N*N]; int d[N][N]; int main(){ n=get();m=get(); int sum=0; fo(i,1,m){ e[i].x=get();e[i].y=get();e[i].l=get(); sum+=e[i].l; d[e[i].x][e[i].y]=d[e[i].y][e[i].x]=e[i].l; } fo(t,1,(1<<n)-1){ fo(i,1,m) if (((1<<(e[i].x-1))&t)>0&&((1<<(e[i].y-1))&t)>0)val[t]+=e[i].l; } fo(t,0,(1<<n)-1)fo(x,1,n)f[t][x]=-1; fo(t,1,(1<<(n-1))-1) if (t&1)f[t][1]=val[t]; fo(t,1,(1<<n)-1) fo(x,1,n) if (f[t][x]>-1){ int u=((1<<n)-1)^t; int p=u; for(;u;u=(u-1)&p){ fo(y,1,n) if (((1<<(y-1))&u)>0&&d[x][y])f[t^u][y]=max(f[t^u][y],f[t][x]+d[x][y]+val[u]); } } printf("%d\n",sum-f[(1<<n)-1][n]); return 0; }
#include<bits/stdc++.h> using namespace std; int N,M; int G[15][15]; int dp[15][(1<<15)]; int INF=2e9; int calc(int bit,int nbit){ int sum=0; for(int i=0;i<N;i++) if(nbit>>i&1) for(int j=0;j<N;j++) if(~bit>>j&1) if(~nbit>>j&1) sum+=G[i][j]; return sum; } int rec(int pos,int bit){ static unordered_map< int , int > mem[15]; if( mem[pos].count(bit) )return mem[pos][bit]; if(pos==N-1)return 0; int res=INF; int sup=(1<<(N-1))-1-bit; int nbit=sup; while(1){ if(nbit>>pos&1){ int cost=calc(bit,nbit); for(int to=0;to<N;to++){ if(bit>>to&1)continue; if(nbit>>to&1)continue; if(G[pos][to]==0)continue; res=min(res, rec(to,bit|nbit) + cost - G[pos][to]); } } nbit--; nbit&=sup; if(nbit==0)break; } return mem[pos][bit]=res; } int main(){ cin>>N>>M; for(int i=0;i<M;i++){ int a,b,c; cin>>a>>b>>c; a--,b--; G[a][b]=G[b][a]=c; } cout<< rec(0,0) <<endl; return 0; }
1
// F. #include <iostream> #include <sstream> #include <algorithm> #include <vector> #include <map> #include <set> using namespace std; typedef long long LL; const int INF = 1 << 30; int solve(vector<int> x, vector<int> y, vector<string> dir) { int ans = INF; int n = (int)x.size(); map<int, set<int>> a, b, v, h; for (int i = 0; i < n; ++i) { if (dir[i] == "L") { a[x[i] - y[i]].insert(x[i]); h[y[i]].insert(x[i]); } if (dir[i] == "R") { b[x[i] + y[i]].insert(x[i]); } if (dir[i] == "D") { v[x[i]].insert(y[i]); } } for (int i = 0; i < n; ++i) { if (dir[i] == "R") { if (h.find(y[i]) != h.end()) { set<int>& s = h[y[i]]; auto it = s.lower_bound(x[i]); if (it != s.end()) { ans = min(ans, (*it - x[i]) * 5); } } } if (dir[i] != "U") { continue; } int key = x[i] - y[i]; if (a.find(key) != a.end()) { set<int>& s = a[key]; auto it = s.lower_bound(x[i]); if (it != s.end()) { ans = min(ans, (*it - x[i]) * 10); } } key = x[i] + y[i]; if (b.find(key) != b.end()) { set<int>& s = b[key]; auto it = s.lower_bound(x[i]); if (it != s.begin()) { --it; ans = min(ans, (x[i] - *it) * 10); } } if (v.find(x[i]) != v.end()) { set<int>& s = v[x[i]]; auto it = s.lower_bound(y[i]); if (it != s.end()) { ans = min(ans, (*it - y[i]) * 5); } } } return ans; } int main(int argc, char* argv[]) { cout.precision(20); #ifdef _MSC_VER while (true) #endif { int ans = INF; LL n = -1; cin >> n; if (n < 0) return 0; vector<int> x(n), y(n); vector<string> dir(n); for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i] >> dir[i]; } ans = solve(x, y, dir); map<string, string> t; t["D"] = "U"; t["U"] = "D"; t["L"] = "R"; t["R"] = "L"; for (int i = 0; i < n; ++i) { x[i] = -x[i]; y[i] = -y[i]; dir[i] = t[dir[i]]; } ans = min(ans, solve(x, y, dir)); if (ans == INF) { cout << "SAFE" << endl; } else { cout << ans << endl; } } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; const int INF = 1e8; // URDL = 0123 int f(vector<P> a) { sort(a.begin(), a.end()); int res = INF; for (int i = 1; i < a.size(); ++i) { if (a[i-1].second == 0 && a[i].second != 0) { res = min(res, a[i].first-a[i-1].first); } } return res; } int f(map<int,vector<P>>& mp) { int res = INF; for (auto p : mp) { res = min(res, f(p.second)); } return res; } int main() { int n; cin >> n; vector<int> x(n), y(n), dir(n); rep(i,n) { char c; cin >> x[i] >> y[i] >> c; if (c == 'U') dir[i] = 0; if (c == 'R') dir[i] = 1; if (c == 'D') dir[i] = 2; if (c == 'L') dir[i] = 3; } int ans = INF; rep(ri,4) { { // UD map<int,vector<P>> mp; rep(i,n) { if (dir[i] != 0 && dir[i] != 2) continue; mp[x[i]].emplace_back(y[i],dir[i]); } ans = min(ans, f(mp)*5); } { // UR map<int,vector<P>> mp; rep(i,n) { if (dir[i] != 0 && dir[i] != 1) continue; mp[x[i]+y[i]].emplace_back(y[i],dir[i]); } ans = min(ans, f(mp)*10); } // rotate rep(i,n) { int px = x[i], py = y[i]; x[i] = py; y[i] = -px; dir[i] = (dir[i]+1)%4; } } if (ans == INF) cout << "SAFE" << endl; else cout << ans << endl; return 0; }
1
#include<string> #include<iostream> using namespace std; int main() { int n; cin>>n; string s; int runner=0,out=0,score=0; while(cin>>s){ if(s=="HIT"){ runner<<=1; if(runner&8)runner&=~8,score++; runner|=1; } else if(s=="HOMERUN"){ for(int i=0;i<3;i++){ runner<<=1; if(runner&8)runner&=~8,score++; } score++; } else{ out++; if(out==3) cout<<score<<endl,runner=out=score=0; } } return 0; }
#include <iostream> #include <string> using namespace std; string A[] = { "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday" }; int D[] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int main() { int m, d, B[13]; B[0] = 1; for (int i = 1; i <= 12; ++i) B[i] = B[i-1] + D[i]; while (cin >> m >> d) { if (!(m | d)) break; int t = B[m-1] + d - 2; cout << A[t%7] << endl; } return 0; }
0
#include <iostream> #include <cstring> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(int)(b);i++) #define rep(i,n) FOR(i,0,n) void solve(int n) { int place[21][21]; memset(place, 0, sizeof(place)); rep(i,n) { int x,y; cin>>x>>y; place[y][x] = 1; } int m; cin >> m; int x=10, y=10; place[y][x] = 0; rep(i,m) { char d; int l; cin >> d >> l; rep(j,l) { if(d == 'N') y++; if(d == 'S') y--; if(d == 'E') x++; if(d == 'W') x--; place[y][x] = 0; } } bool f = true; rep(i,21) rep(j,21) if(place[i][j] == 1) f = false; cout << (f ? "Yes" : "No") << "\n"; return ; } int main() { for(int n;cin>>n && n;) solve(n); return 0; }
// aribon4-3_a #include <bits/stdc++.h> #ifdef LOCAL #include "../cxx-prettyprint/prettyprint.hpp" #endif using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; #define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i)) #define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i)) #define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i)) #define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i)) #define ALL(x) x.begin(), x.end() #define INF ((1 << 29)-1) #define MOD (1000000007) #define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; } #define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;} template<class T> void print(const T& x){cout << x << endl;} template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); } struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; struct SCC { int N; vector<int> tmp_order; vector<int> scc_group; vector<bool> used; vector<vector<int>> edges, rev_edges; SCC(int n): N(n), edges(n), rev_edges(n), scc_group(n, -1), used(n) {} void add_edge(int u, int v){ edges[u].emplace_back(v); rev_edges[v].emplace_back(u); } void dfs(int i){ used[i] = true; for (auto v: edges[i]){ if (used[v]) continue; dfs(v); } tmp_order.emplace_back(i); } void dfs2(int i, int k){ used[i] = true; scc_group[i] = k; for (auto v: rev_edges[i]){ if (used[v]) continue; dfs2(v, k); } } int calc_scc(){ REP(i, N){ if (used[i]) continue; dfs(i); } used.assign(N, false); int k = 0; REP(i, N){ int v = tmp_order[N-i-1]; if (used[v]) continue; dfs2(v, k++); } return k; } }; int main() { #ifdef LOCAL ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf()); #endif int N, E; cin >> N >> E; SCC g(N); REP(i, E){ int s, t; cin >> s >> t; g.add_edge(s, t); } g.calc_scc(); int Q; cin >> Q; REP(i, Q){ int u, v; cin >> u >> v; int ans = int(g.scc_group[u] == g.scc_group[v]); print(ans); } return 0; }
0
#include<cstdio> typedef long long LL; const int N=2003; const int O=2*N; int n,m,ans; int dp[3*N][5*N]; inline LL Pow(LL x,int p) { if(p==0) return 1; if(!(p&1)) return Pow(x*x%m,p>>1); return x*Pow(x*x%m,p>>1)%m; } inline void Add(int &x,int y) { x+=y; if(x>=m) x-=m; } int main() { scanf("%d %d",&n,&m); n*=3; dp[0][O]=1; for(int s=0;s<=n;s++) { for(int D=-s/2;D<=s;D++) { int d=D+O; Add(dp[s+1][d+1],dp[s][d]); Add(dp[s+2][d-1],dp[s][d]*(s+1ll)%m); Add(dp[s+3][d],dp[s][d]*(s+1ll)%m*(s+2ll)%m); } } for(int i=0;i<=n;i+=3) Add(ans,dp[n][i+O]); printf("%d\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; //#include <boost/multiprecision/cpp_int.hpp> //typedef boost::multiprecision::cpp_int ll; typedef long double dd; #define i_7 (ll)(1E9+7) //#define i_7 998244353 #define i_5 i_7-2 ll mod(ll a){ ll c=a%i_7; if(c>=0)return c; return c+i_7; } typedef pair<ll,ll> l_l; ll inf=(ll)1E16; #define rep(i,l,r) for(ll i=l;i<=r;i++) #define pb push_back ll max(ll a,ll b){if(a<b)return b;else return a;} ll min(ll a,ll b){if(a>b)return b;else return a;} void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]); void Min(ll &pos,ll val){pos=min(pos,val);} void Add(ll &pos,ll val){pos=mod(pos+val);} dd EPS=1E-9; #define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll hpow(ll x,ll y){ ll ans=1; ll i=x; if(y==0)return 1; while(y>0){ if(y%2==1){ ans=(ans*i)%i_7; } i=(i*i)%i_7; y=y/2; } return ans; } ll memop[2000000]; ll mkai(ll i){ if(i==0){ return 1; } if(memop[i]!=0){ return memop[i]; }else{ ll ans=(mkai(i-1)*hpow(i,i_7-2))%i_7; memop[i]=ans; return ans; } } ll memok[2000000]; ll kai(ll i){ if(i==0){ return 1; } if(memok[i]!=0){ return memok[i]; }else{ ll ans=(kai(i-1)*i)%i_7; memok[i]=ans; return ans; } } ll comb(ll n,ll k){ ll ans=(kai(n)*mkai(k))%i_7; ans=(ans*mkai(n-k))%i_7; return ans; } int main(){ ll h,w,a,b;cin>>h>>w>>a>>b; ll ans=0; rep(i,b,w-1){ ans=(ans+(comb(h-a-1+i,h-a-1)*comb(a-1+w-1-i,a-1))%i_7)%i_7; } cout<<ans<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int n,m,a[1000010],b[1000010],s; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=m;++i)scanf("%d",a+i),s+=a[i]&1; if(s>2)return puts("Impossible"),0; sort(a+1,a+m+1,[](int x,int y)->bool{return (x&1)>(y&1);}); if(m==1)if(a[1]==1)return puts("1\n1\n1"),0;else return printf("%d\n%d\n%d %d",a[1],2,a[1]-1,1),0; swap(a[2],a[m]); for(int i=1;i<=m;++i)printf("%d ",a[i]); printf("\n%d\n",a[m]==1?m-1:m); for(int i=1;i<=(a[m]==1?m-1:m);++i)printf("%d ",i==1?a[i]+1:i==m?a[i]-1:a[i]); }
/*input 5 1 5 */ #include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<double,double> pdd; #define IOS ios_base::sync_with_stdio(0); cin.tie(0) #define ALL(a) a.begin(),a.end() #define SZ(a) ((int)a.size()) #define F first #define S second #define REP(i,n) for(int i=0;i<((int)n);i++) #define pb push_back #define MP(a,b) make_pair(a,b) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) template<typename T1,typename T2> ostream& operator<<(ostream& out,pair<T1,T2> P){ out<<'('<<P.F<<','<<P.S<<')'; return out; } //}}} const ll maxn=300005; const ll maxlg=__lg(maxn)+2; const ll INF64=8000000000000000000LL; const int INF=0x3f3f3f3f; const ll MOD=ll(1e9+7); const double PI=acos(-1); //const ll p=880301; //const ll P=31; ll mypow(ll a,ll b){ ll res=1LL; while(b){ if(b&1) res=res*a%MOD; a=a*a%MOD; b>>=1; } return res; } vector<int> odd,even; int a[maxn]; vector<int> ans; int main() { IOS; int n,m; cin>>n>>m; REP(i,m) cin>>a[i]; REP(i,m){ if(a[i]%2) odd.pb(a[i]); else even.pb(a[i]); } if(SZ(odd)>2){ cout<<"Impossible\n"; return 0; } if(SZ(odd)==0){ REP(i,SZ(even)) cout<<even[i]<<" \n"[i==SZ(even)-1]; ans.pb(1); REP(i,SZ(even)-1) ans.pb(even[i]); ans.pb(even.back()-1); } else if(SZ(odd)==1&&SZ(even)){ cout<<odd[0]; for(int i:even) cout<<' '<<i; cout<<'\n'; ans.pb(odd[0]+1); REP(i,SZ(even)-1) ans.pb(even[i]); if(SZ(even)) ans.pb(even.back()-1); } else if(SZ(odd)==1){ cout<<odd[0]<<'\n'; if(odd[0]-1) ans.pb(odd[0]-1); ans.pb(1); } else{ cout<<odd[0]; for(int i:even) cout<<' '<<i; cout<<' '<<odd[1]<<'\n'; ans.pb(odd[0]+1); for(int i:even) ans.pb(i); if(odd[1]-1) ans.pb(odd[1]-1); } cout<<SZ(ans)<<'\n'; for(int i:ans) cout<<i<<' '; cout<<'\n'; return 0; }
1
#include <bits/stdc++.h> #define all(vec) vec.begin(),vec.end() using namespace std; using ll=long long; using P=pair<int,int>; const ll INF=1LL<<30; const ll LINF=1LL<<61; const double eps=1e-9; const ll MOD=1000000007LL; vector<ll> f,fi; ll mpow(ll x,ll n){ ll res=1; while(n>0){ if(n&1){ res=res*x%MOD; } x=x*x%MOD; n>>=1; } return res; } ll ncr(ll n,ll r){ if(n<r)return 0; if(r==0)return 1; return f[n]*fi[r]%MOD*fi[n-r]%MOD; } int main(){ int n;cin>>n; f.resize(n+10,0); fi.resize(n+10,0); f[0]=1; for(ll i=1;i<=n;i++)f[i]=f[i-1]*i%MOD; fi[n]=mpow(f[n],MOD-2LL); for(ll i=n-1;i>=0;i--)fi[i]=fi[i+1]*(i+1)%MOD; vector<vector<ll>> dp(n+10,vector<ll>(n+10,0)); int a,b,c,d;cin>>a>>b>>c>>d; dp[a-1][0]=1; for(int i=a;i<=b;i++){ for(int j=0;j<=n;j++){ dp[i][j]+=dp[i-1][j]; dp[i][j]%=MOD; ll s=1; for(int k=1;k<c;k++)s=s*ncr(n-j+i*k,i)%MOD; for(int k=c;k<=d;k++){ if(j-i*k<0)break; s=s*ncr(n-j+i*k,i)%MOD; dp[i][j]+=dp[i-1][j-i*k]*s%MOD*fi[k]%MOD; dp[i][j]%=MOD; } } } cout<<dp[b][n]<<endl; }
#include<iostream> #include<iomanip> #include<cstdio> #include<algorithm> #include<cassert> #include<cmath> #include<vector> #include<map> #include<set> #include<string> #include<queue> #include<stack> #include<list> #include <cstring> #include <functional> //#include<unordered_map> //#include<unordered_set> using namespace std; #define MOD 1000000007 #define MOD2 998244353 #define INF ((1<<30)-1) #define LINF ((Int)1<<60) #define EPS (1e-10) #define REP(i,n) for(int i=0; i<(int)(n); ++i) #define RREP(i,n) for(int i=1; i<=(int)(n); ++i) #define FOR(i,k,n) for(int i=(k);i<(int)(n);++i) typedef long long Int; typedef pair<Int, Int> P; typedef vector<double> vec; typedef vector<vec> mat; const int N = 100005; ////////////////////////////// void add(int64_t& a, int64_t b) { a = (a + b) % MOD; } void mul(int64_t& a, int64_t b) { a = a*b % MOD; } vector<int64_t> fact, seq_inv, fact_inv; void create_fact_mod(int num) { fact[0] = fact[1] = 1; for (int i = 2; i <= num; i++) fact[i] = fact[i - 1] * i % MOD; } void create_seq_inv_mod(int num) { seq_inv[0] = seq_inv[1] = 1; for (int i = 2; i <= num; i++) seq_inv[i] = (MOD - MOD / i) * seq_inv[MOD%i] % MOD; } void create_fact_inv_mod(int num) { fact_inv[0] = fact_inv[1] = 1; for (int i = 2; i <= num; i++) fact_inv[i] = fact_inv[i - 1] * seq_inv[i] % MOD; } void create_mod_tables(int num) { fact.resize(num + 1); seq_inv.resize(num + 1); fact_inv.resize(num + 1); create_fact_mod(num); create_seq_inv_mod(num); create_fact_inv_mod(num); } int64_t comb_mod(int n, int k) { return fact[n] * fact_inv[n - k] % MOD * fact_inv[k] % MOD; } int64_t perm_mod(int n, int k) { return fact[n] * fact_inv[n - k] % MOD; } int64_t power_mod(int64_t num, int64_t power) { int64_t prod = 1; num %= MOD; while (power > 0) { if (power & 1) prod = prod * num % MOD; num = num * num % MOD; power >>= 1; } return prod; } int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y) { int64_t d = a; if (b != 0) { d = extgcd(b, a%b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } int64_t inv_mod(int64_t a) { int64_t x, y; extgcd(a, MOD, x, y); return (MOD + x%MOD) % MOD; } void solve() { int M, A, B, C, D; cin >> M >> A >> B >> C >> D; create_mod_tables(1000); static int64_t dp[1001][1001]; dp[A - 1][0] = 1; for (int i = A; i <= B; i++) for (int j = 0; j <= M; j++) { add(dp[i][j], dp[i - 1][j]); int n = M - j; int64_t pw = power_mod(fact_inv[i], C); for (int k = C; k <= D && i*k <= n; k++) { int64_t res = comb_mod(n, i*k) * fact[i*k] % MOD * pw % MOD * fact_inv[k] % MOD; mul(pw, fact_inv[i]); add(dp[i][j + i*k], dp[i - 1][j] * res); } } cout << dp[B][M] << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13); solve(); return 0; }
1