code_file1
stringlengths
80
4k
code_file2
stringlengths
91
4k
similar_or_different
int64
0
1
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #define int long long using namespace std; inline int read(){ int f=1,ans=0;char c=getchar(); while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();} return f*ans; } const int MAXN=100001; int m,k,ans,n,x[MAXN],d[MAXN],a[MAXN],fa[MAXN][61],p[MAXN]; signed main(){ // freopen("2.in","r",stdin); n=read(); for(int i=1;i<=n;i++) x[i]=read(),d[i]=i,p[i]=x[i]-x[i-1]; m=read(),k=read(); for(int i=1;i<=m;i++) a[i]=read(),swap(d[a[i]],d[a[i]+1]); for(int i=1;i<=n;i++) fa[i][0]=d[i]; for(int j=1;j<=60;j++) for(int i=1;i<=n;i++) fa[i][j]=fa[fa[i][j-1]][j-1]; for(int i=1;i<=n;i++){ int res=i; int K=k; for(int j=60;j>=0;j--) if(K-(1ll<<j)>=0) K-=(1ll<<j),res=fa[res][j]; ans+=p[res]; printf("%lld.0\n",ans); }return 0; }/* 3 1 -1 1 2 2 2 2 */
#include <iostream> #include <vector> using namespace std; int main() { int n; while (cin >> n) { if (n == 0) break; vector<int> array(n); for (int i = 0; i < n; i++) { cin >> array.at(i); } long max = array.at(0); for (int j = 0; j < n; j++) { long total = 0; for (int k = 0; k < n - j; k++) { total += array.at(j + k); if (total > max) max = total; } } cout << max << endl; } return 0; }
0
#include <stdio.h> #include <limits.h> #include <math.h> #include <bitset> #include <vector> #include <map> #include <set> #include <stack> #include <queue> #include <cstring> #include <string> #include <sstream> #include <algorithm> #include <iomanip> #include <iostream> #define VARIABLE(x) cerr << #x << "=" << x << endl #define BINARY(x) static_cast<bitset<16> >(x); #define rep(i,n) for(int i=0;i<(int)(n);i++) #define REP(i,m,n) for (int i=m;i<(int)(n);i++) #define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h)) const int INF = 1000000000; typedef double D; const double EPS = 1e-8; const double PI = 3.14159; int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1}; using namespace std; //typedef pair<int, int> P; /** Problem0546 : Lining up the cards **/ vector<string> card; bool used[10]; set<string> ans; int N, K; void solve(int n, string s) { if (n==K) ans.insert(s); else { rep(i, N) { if (!used[i]) { used[i] = true; solve(n+1, s+card[i]); used[i] = false; } } } } int main() { while (cin>>N, N) { ans.clear(); card.clear(); fill(used, used+10, false); cin>>K; rep(i, N) { string s; cin>>s; card.push_back(s); } solve(0, ""); cout << ans.size() << endl; } }
#include <iostream> #include <map> #include <string> using namespace std; int main() { int n, k; while(cin >> n >> k && (n || k)){ int card[10] = {0}; map<string, int> m; for(int i = 0; i < n; ++i) cin >> card[i]; int ans = 0; if(k == 2){ for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j){ if(i == j) continue; string str = to_string(card[i]) + to_string(card[j]); if(m[str] == 0){ ans++; m[str] = 1; } } } } else if(k == 3){ for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j){ if(i == j) continue; for(int k = 0; k < n; ++k){ if(i == k || j == k) continue; string str = to_string(card[i]) + to_string(card[j]) + to_string(card[k]); if(m[str] == 0){ ans++; m[str] = 1; } } } } } else if(k == 4){ for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j){ if(i == j) continue; for(int k = 0; k < n; ++k){ if(i == k || j == k) continue; for(int l = 0; l < n; ++l){ if(i == l || j ==l || k == l) continue; string str = to_string(card[i]) + to_string(card[j]) + to_string(card[k]) + to_string(card[l]); if(m[str] == 0){ ans++; m[str] = 1; } } } } } } cout << ans << endl; } return 0; }
1
#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,c,d; cin >> a >> b >> c >> d; a = min(a,b); c = min(c,d); int ans = a+c; cout << ans << endl; return 0; }
#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...); } #ifndef ONLINE_JUDGE #define debug(...) cerr<<"LINE ("<< __LINE__ << ") : [" << #__VA_ARGS__ << "] -> ", debug_out(__VA_ARGS__) #else #define debug(...) #endif int main(){ ios::sync_with_stdio(false); cin.tie(0); vector<int> a = {111, 222, 333, 444, 555, 666, 777, 888, 999}; int n; cin >> n; auto it = lower_bound(a.begin(), a.end(), n); cout << *it; return 0; }
0
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for(int i = n-1; i >= 0; i--) #define all(x) (x).begin(),(x).end() // 昇順ソート #define rall(v) (v).rbegin(), (v).rend() // 降順ソート #define FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) typedef long long ll; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<vector<int>>; using VL = vector<ll>; using VVL = vector<vector<ll>>; using VP = vector<P>; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; } const ll INF = 1LL<<60; int main(){ int d; ll g; cin >> d >> g; VP q(d); rep(i,d) cin >> q[i].first >> q[i].second; VI p(d); rep(i,d) p[i] = i; ll ans = INF; do{ VI pp(d); rep(i,d) pp[p[i]] = i; ll gg = g; ll cnt = 0; rep(i,d){ int j = pp[i]; ll pc = (j + 1) * 100; ll num = min((ll)q[j].first, ((gg + (pc-1)) / pc)); cnt += num; gg -= pc * num; gg -= q[j].second; if (gg <= 0) break; } ans = min(ans, cnt); } while(next_permutation(all(p))); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for(ll i = 0; i < n; i++) #define REPR(i, n) for(ll i = n; i >= 0; i--) #define FOR(i, m, n) for(ll i = m; i < n; i++) #define ALL(obj) (obj).begin(), (obj).end() #define INF 1e9 #define LINF 1e18 int main() { int D,G; cin >> D >> G; vector<pair<ll,ll>> score(D+1); REP(i,D){ int p,c; cin >> p >> c; score[i] = {p,c}; } int ans = INF; REP(bit, 1<<D){ vector<int> S(D,0); int sum = 0; int cnt = 0; REP(i,D){ if(bit & (1<<i)){ S[i] = 1; sum += score[i].first*(i+1)*100 + score[i].second; cnt += score[i].first; } } if(G<=sum){ ans = min(ans, cnt); continue; } REPR(i,D-1){ if(S[i]==1) continue; REP(j,score[i].first){ sum += 100*(i+1); cnt++; if(G<=sum){ ans = min(ans, cnt); continue; } } } ans = min(ans, cnt); } cout << ans << endl; return 0; }
1
#include <stdio.h> #include <string.h> #include <string> #include <iostream> #include <vector> #include <sstream> #include <memory> #include <iomanip> std::vector<int> parse_line(std::string const& line) { using namespace std; vector<int> result; istringstream s(line); string element; while (getline(s, element, ' ')) { stringstream buf; int value = 0; buf << element; buf >> value; result.push_back(value); } return std::move(result); } int main(int argc, char* argv[]) { using namespace std; while (true) { string line; getline(std::cin, line); auto elements = parse_line(line); auto length = elements[0]; if (length == 0) break; vector<int> total(length + 1); size_t width = length + 1; for (size_t i = 0; i < length; ++i) { getline(cin, line); elements = parse_line(line); int sum = 0; for (size_t n = 0; n < length; ++n) { int val = elements[n]; sum += val; total[n] += val; cout << setw(5) << val; } cout << setw(5) << sum << endl; total[length] += sum; } for (size_t i = 0; i < width; ++i) { cout << setw(5) << total[i]; } cout << endl; } return 0; }
#include <algorithm> #include <cmath> #include <climits> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <cassert> #include <functional> using namespace std; #define LOG(...) printf(__VA_ARGS__) //#define LOG(...) #define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define REP(i,n) for(int i=0;i<(int)(n);++i) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) #define RSORT(c) sort((c).rbegin(),(c).rend()) #define CLR(a) memset((a), 0 ,sizeof(a)) typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 }; int main() { int n; while (cin >> n, n){ vector<vector<int>> hyou(n + 1, vector<int>(n + 1, 0)); REP(i, n){ REP(j, n){ int num; cin >> num; hyou[i][j] = num; } } REP(i, n){ REP(j, n){ hyou[i][n] += hyou[i][j]; } } REP(j, n){ REP(i, n){ hyou[n][j] += hyou[i][j]; } } REP(i, n){ hyou[n][n] += hyou[i][n]; } REP(i, n + 1){ REP(j, n + 1){ printf("%5d", hyou[i][j]); } printf("\n"); } } }
1
#include <bits/stdc++.h> #include <iomanip> using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() #define fi first #define se second #define mp make_pair typedef long long ll; typedef vector<ll> vec; typedef vector<vec> mat; ll N,M,H,W,K,Q,A,B; string S; //const ll MOD = 998244353; const ll MOD = (1e+9) + 7; const ll INF = 1LL << 60; typedef pair<ll,ll> P; int main(){ cin>>N>>M>>Q; vector<string> grid(N); rep(i,N) cin>>grid[i]; mat edge(N, vec(M, 0)), num(N + 1, vec(M + 1, 0)), addr(N, vec(M,0)), addc(N, vec(M,0)); rep(i,N){ rep(j,M){ bool blue = grid[i][j] == '1'; if(i > 0) { edge[i][j] += edge[i-1][j] + (blue && grid[i-1][j] == '1'); addc[i][j] = addc[i-1][j] + (blue && grid[i-1][j] == '1'); } if(j > 0) { edge[i][j] += edge[i][j-1] + (blue && grid[i][j-1] == '1'); addr[i][j] = addr[i][j-1] + (blue && grid[i][j-1] == '1'); } if(i > 0 && j > 0) edge[i][j] -= edge[i-1][j-1]; num[i+1][j+1] = num[i][j+1] + num[i+1][j] - num[i][j] + blue; } } vec x(2), y(2); rep(i,Q){ rep(j,2) cin>>x[j]>>y[j]; --x[0], --y[0]; ll res = 0; rep(j,2) rep(k,2) res += (j^k ? -1 : 1) * num[x[j]][y[k]]; --x[1], --y[1]; rep(j,2) rep(k,2) res += (j^k ? 1 : -1) * edge[x[j]][y[k]]; res -= addr[x[0]][y[1]] - addr[x[0]][y[0]]; res -= addc[x[1]][y[0]] - addc[x[0]][y[0]]; cout<<res<<endl; } /*rep(i,N){ rep(j,M) cout<<edge[i][j]<<' '; cout<<endl; }*/ }
#include <iostream> #include <vector> #include <queue> #include <algorithm> #include <cmath> #include <iomanip> #include <map> #include <deque> #include <string.h> using namespace std; #define REP(i,n) for(int i = 0; i < n; i++) #define ALL(v) v.begin(),v.end() typedef long long ll; typedef pair<int,int> pi; typedef pair<ll,ll> pll; typedef pair<string,string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pi> vpi; typedef vector<ll> vll; typedef vector<vll> vvll; double EPS = 1e-9; int INFi = 1000000005; long long INFll = 1000000000000000005ll; double PI = acos(-1); int dirx[8] = {-1,0,0,1,-1,-1,1,1}; int diry[8] = {0,1,-1,0,-1,1,-1,1}; ll MOD = 1000000007; int N, M, Q; const int MAX_NM = 2000; const int MAX_Q = 200000; string S[MAX_NM]; int X1[MAX_Q], Y1[MAX_Q], X2[MAX_Q], Y2[MAX_Q]; int main(){ cin >> N >> M >> Q; REP(i, N) cin >> S[i]; REP(i, Q) cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i]; REP(i, Q) { X1[i]--; Y1[i]--; X2[i]--; Y2[i]--; } int blue[N][M], vert[N][M], hori[N][M]; REP(i, N) REP(j, M) { blue[i][j] = 0; vert[i][j] = 0; hori[i][j] = 0; } REP(i, N) { REP(j, M) { if(i > 0) { blue[i][j] += blue[i - 1][j]; vert[i][j] += vert[i - 1][j]; hori[i][j] += hori[i - 1][j]; } if(j > 0) { blue[i][j] += blue[i][j - 1]; vert[i][j] += vert[i][j - 1]; hori[i][j] += hori[i][j - 1]; } if(i > 0 && j > 0) { blue[i][j] -= blue[i - 1][j - 1]; vert[i][j] -= vert[i - 1][j - 1]; hori[i][j] -= hori[i - 1][j - 1]; } if(S[i][j] == '1') { blue[i][j]++; if(i > 0 && S[i - 1][j] == '1') vert[i][j]++; if(j > 0 && S[i][j - 1] == '1') hori[i][j]++; } } } REP(i, Q) { ll ans = 0; ll b = 0, v = 0, h = 0; b += blue[X2[i]][Y2[i]]; v += vert[X2[i]][Y2[i]]; h += hori[X2[i]][Y2[i]]; if(X1[i] > 0) { b -= blue[X1[i] - 1][Y2[i]]; v -= vert[X1[i]][Y2[i]]; h -= hori[X1[i] - 1][Y2[i]]; } if(Y1[i] > 0) { b -= blue[X2[i]][Y1[i] - 1]; v -= vert[X2[i]][Y1[i] - 1]; h -= hori[X2[i]][Y1[i]]; } if(X1[i] > 0 && Y1[i] > 0) { b += blue[X1[i] - 1][Y1[i] - 1]; v += vert[X1[i]][Y1[i] - 1]; h += hori[X1[i] - 1][Y1[i]]; } cout << b - v - h << endl; } return 0; }
1
#define _USE_MATH_DEFINES #include <iostream> #include <string> #include <utility> #include <stack> #include <vector> #include <queue> #include <algorithm> #include <map> #include <climits> #include <set> #include <cmath> #include <numeric> #include <iomanip> using namespace std; const long long MOD = 1000000007; int main(){ int N; string S; cin >> N; cin >> S; int current_open = 0; long long N_fact = 1; for(int i = 1; i <= N; i++){ N_fact = (N_fact * i) % MOD; } long long ans = 1; for(int i = 0; i < S.size(); i++){ if(S[i] == 'B'){ if(current_open % 2 == 0){ current_open ++; } else { ans = (ans * current_open) % MOD; current_open --; } } else { if(current_open % 2 == 0){ if(current_open <= 0){ ans = 0; break; } else { ans = (ans * current_open) % MOD; current_open --; } } else { current_open ++; } } } ans = (ans * N_fact) % MOD; if(current_open != 0){ cout << 0 << endl; } else { cout << ans << endl; } }
#include<iostream> #include<cstdio> const int N=2e5+5; char s[N]; typedef long long ll; const ll mod=1e9+7; int d[N]; int main() { int n; scanf("%d",&n); scanf("%s",s+1); if(s[1]=='W') return !printf("0"); d[1]=0; for(int i=2;i<=n+n;i++) { if(s[i]==s[i-1]) d[i]=d[i-1]^1; else d[i]=d[i-1]; } int num[2]={0,0}; for(int i=1;i<=n+n;i++) num[d[i]]++; if(num[0]!=n) return !printf("0"); ll ans=1; int cnt=0; for(int i=1;i<=n+n;i++) { if(d[i]) ans=ans*cnt%mod,cnt--; else cnt++; if(cnt<0) return !printf("0"); } for(int i=1;i<=n;i++) ans=ans*i%mod; printf("%lld\n",ans); return 0; }
1
#include<iostream> #include<string> using namespace std; #define W 12 #define H 12 int dx[4] = {0, 1, 0, -1}; int dy[4] = {-1, 0, 1, 0}; string mass[W]; void rec(int x, int y) { int xx, yy; int i; mass[x][y] = '2'; for (i = 0; i < 4; i++) { yy = y+dy[i]; xx = x+dx[i]; if (yy<0 || H<=yy || xx<0 || W<=xx) continue; if (mass[xx][yy]!='1') continue; rec(xx, yy); } } int main() { int count, i, j; string c; while ( cin>>mass[0] ) { for (i = 1; i < W; i++) cin>>mass[i]; count = 0; for (i = 0; i < W; i++) { for (j = 0; j < H; j++) { if (mass[i][j] != '1') continue; count++; rec(i, j); } } cout<<count<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) FOR(i,0,n) #define pb emplace_back typedef long long ll; typedef pair<int,int> pint; int n; ll a[200001]; ll dp[2][100011][2]; int main(){ cin>>n; rep(i,n) cin>>a[i]; int l,r,cur=0; rep(i,2)rep(j,100011)rep(k,2) dp[i][j][k]=-1000100010001000100; dp[0][0][0]=0,dp[0][0][1]=0; rep(i,n){ cur=i%2; r=(i+1)/2,l=max(0,i/2-1); FOR(j,l,r+1){ dp[cur^1][j][0]=max(dp[cur^1][j][0],dp[cur][j][1]); dp[cur^1][j][0]=max(dp[cur^1][j][0],dp[cur][j][0]); dp[cur^1][j+1][1]=max(dp[cur^1][j+1][1],dp[cur][j][0]+a[i]); } } cout<<max(dp[n%2][n/2][0],dp[n%2][n/2][1])<<endl; return 0; }
0
#include<stdio.h> #include<string.h> int main() { char x[100], y[100], z[100]; scanf("%s %s %s", x, y, z); int lenA = strlen(x); int lenB = strlen(y); if(x[lenA - 1] == y[0] && y[lenB - 1] == z[0]) { printf("YES\n"); } else { printf("NO\n"); } return 0; }
#define _GLIBCXX_DEBUG #include<bits/stdc++.h> #include<algorithm>//next_permutation #define rep(i,n) for (int i = 0;i < (n);i++) #define all(v) v.begin(),v.end() #define dec(n) cout << fixed << setprecision(n); #define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #define small "abcdefghijklmnopqrstuvwxyz" using namespace std; using ll = long long; using P = pair<ll,ll>; using vl = vector<ll>; using vvl = vector<vl>; ll gcd(ll a,ll b){ if(b == 0) return a; return gcd(b , a % b); } ll mod(ll a){ return (a % 1000000007); } ll lcm(ll a,ll b){ return (a*b)/gcd(a,b); } ll nCr(ll n,ll r){ if(r == 1) return n; else if(r == 0) return 1; else return nCr(n-1,r-1)*n/r; } int main(){ ll num[] ={7,17,37,47,67,97,107,127,137,157,167,197,227,257,277, 307,317,337,347,367,397,457,467,487,547,557,577,587, 607,617,647,677,727,757,787,797,827,857,877,887,907, 937,947,967,977,997,1087,1097,1117,1187,1217,1237, 1277,1297,1307,1327}; ll n; cin >> n; rep(i,n){ cout << num[i]; if(i == n) cout << endl; else cout << ' '; } }
0
/*#pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/ #include<bits/stdc++.h> #define ll long long #define inf 1000000005 #define put putchar('\n') #define F(i,a,b) for (int i=(a);i<=(b);i++) #define D(i,a,b) for (int i=(a);i>=(b);i--) #define go(i,t) for (int i=head[t];i;i=Next[i]) #define sqr(x) ((x)*(x)) #define re register #define mp make_pair #define fi first #define se second #define pa pair<int,int> #define pb push_back #define be begin() #define en end() #define ret return puts("-1"),0; #define mod 1000000007 #define N 500055 #define int ll using namespace std; 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 int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();} int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;} inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');} inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');} inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);} int n,m,vis[N],co[N],I,P,Q; int nedge,Next[N*2],head[N],to[N*2]; #define V to[i] void add(int a,int b){ Next[++nedge]=head[a];head[a]=nedge;to[nedge]=b; } void add_ne(int a,int b){add(a,b);add(b,a);} bool dfs(int x){ vis[x]=1; bool num=1; go(i,x){ if (vis[V]) num&=(co[x]!=co[V]); else co[V]=co[x]^1,num&=dfs(V); } return num; } signed main(){ n=read();m=read(); F(i,1,m){ add_ne(read(),read()); } F(i,1,n){ if (!vis[i]){ if (head[i]==0) I++; else if (dfs(i)) Q++; else P++; } } wrn(I*I+I*(n-I)*2+P*Q*2+P*P+Q*Q*2); return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 #define MAXN 100005 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 +c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int H,W; char s[105][105]; int sum[105][105],a,b; int dp[2][105][105][105],ans; int query(int x1,int y1,int x2,int y2) { x2 = min(H,x2);y2 = min(W,y2); if(x1 > x2 || y1 > y2) return 0; return sum[x2][y2] - sum[x2][y1 - 1] - sum[x1 - 1][y2] + sum[x1 - 1][y1 - 1]; } void update(int &x,int y) { x = max(x,y); } void Solve() { read(H);read(W); for(int i = 1 ; i <= H ; ++i) scanf("%s",s[i] + 1); for(int i = 1 ; i <= H ; ++i) { for(int j = 1 ; j <= W ; ++j) { sum[i][j] = (s[i][j] == 'o'); sum[i][j] += sum[i][j - 1]; if(s[i][j] == 'E') {a = i;b = j;} } } for(int i = 1 ; i <= H ; ++i) { for(int j = 1 ; j <= W ; ++j) { sum[i][j] += sum[i - 1][j]; } } int cur = 0; dp[0][0][0][0] = 0; for(int i = 0 ; i < a ; ++i) { memset(dp[cur ^ 1],0,sizeof(dp[cur ^ 1])); for(int j = 0 ; j < b ; ++j) { for(int k = 0 ; k <= H - a ; ++k) { for(int t = 0 ; t <= W - b ; ++t) { ans = max(ans,dp[cur][j][k][t]); int tmp = dp[cur][j][k][t]; if(k < a - i - 1) tmp += query(a - i - 1,max(b - j,t + 1),a - i - 1,min(b + t,W - j)); update(dp[cur ^ 1][j][k][t],tmp); tmp = dp[cur][j][k][t]; if(t < b - j - 1) tmp += query(max(a - i,k + 1),b - j - 1,min(a + k,H - i),b - j - 1); update(dp[cur][j + 1][k][t],tmp); tmp = dp[cur][j][k][t]; if(H - i >= a + k + 1) tmp += query(a + k + 1,max(b - j,t + 1),a + k + 1,min(b + t,W - j)); update(dp[cur][j][k + 1][t],tmp); tmp = dp[cur][j][k][t]; if(W - j >= b + t + 1) tmp += query(max(a - i,k + 1),b + t + 1,min(a + k,H - i),b + t + 1); update(dp[cur][j][k][t + 1],tmp); } } } cur ^= 1; } out(ans);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main(void) { int N, Q; cin >> N >> Q; string S; cin >> S; vector<int> L(Q); vector<int> R(Q); vector<int> A(N); for (int i=0; i<Q; i++) { cin >> L[i] >> R[i]; } int cnt = 0; A[0] = 0; for (int i=1; i<N; i++) { if (S[i] == 'C' && S[i-1] == 'A') cnt++; A[i] = cnt; } for (int i=0; i<Q; i++) { cout << A[R[i]-1] - A[L[i]-1] << endl; } return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define Graph vector< vector<int> > typedef long long ll; typedef pair<int, int> P; const int INF = 1000000007; Graph G(100010); vector<bool> seen(100010, false); vector<int> prenum(100010), parent(100010), lowest(100010); int id; void dfs(int now, int prev){ prenum[now] = lowest[now] = id; id++; seen[now] = true; rep(i, G[now].size()){ int next = G[now][i]; if(!seen[next]){ parent[next] = now; dfs(next, now); lowest[now] = min(lowest[next], lowest[now]); } else if(next != prev){ lowest[now] = min(lowest[now], prenum[next]); } } } int main(){ int N, M; cin >> N >> M; rep(i, M){ int s, t; cin >> s >> t; G[s].push_back(t); G[t].push_back(s); } id = 1; dfs(0, -1); set<int> ans; int root_p = 0; for(int i = 1; i < N; i++){ int p = parent[i]; if(p == 0) root_p++; else if(prenum[p] <= lowest[i]) ans.insert(p); } if(root_p >= 2) ans.insert(0); for(set<int>::iterator it = ans.begin(); it != ans.end(); it++){ cout << *it << endl; } }
0
#include<bits/stdc++.h> #define all(x) (x).begin(),(x).end() #define ll long long #define rep(i,n) for(int i = 0; i < int(n); i++) #define vi vector<int> #define INF (1<<30)-1 using namespace std; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; } template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; } int main(){ cin.tie(0), ios::sync_with_stdio(false); const int MOD = 998244353; int n; cin >> n; map<int,int> mp; vi d(n); int mx = 0; rep(i,n){ cin >> d[i]; mp[d[i]]++; chmax(mx,d[i]); } if(mp[0]!=1 || d[0]!=0){ cout << 0; return 0; } ll ans = 1; for(int i = 1; i <= mx; i++){ // ll res = (ll)pow(mp[i-1],mp[i]); ll res = 1; rep(j,mp[i]){ res *= mp[i-1]; res %= MOD; } ans *= res; ans %= MOD; } cout << ans; cout << "\n"; return 0; }
/** * author: souzai32 * created: 13.08.2020 13:17:00 **/ #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; int main() { int n; cin >> n; vector<int> a(n); rep(i,n) cin >> a.at(i); sort(a.begin(),a.end()); int c=0; for(int i=0; i<n; i++){ if(a.at(i)<0){ a.at(i)*=-1; c++; } else break; } sort(a.begin(),a.end()); long long sum; if(c%2) sum=-a.at(0); else sum=a.at(0); for(int i=1; i<n; i++) sum+=a.at(i); cout << sum << endl; return 0; }
0
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define repd(i,a,b) for (int i=(a);i<(b);i++) #define rep(i,n) repd(i,0,n) typedef long long ll; typedef long double lb; #define int long long #define double long double #define endn "\n" typedef pair<int,int> P; template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;} template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;} const int MOD = 1000000007; //const int MOD = 998244353; const ll INF = 1e16; const double EPS = 1e-10; const double PI = 3.141592653589793; const string abc="abcdefghijklmnopqrstuvwxyz"; const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; //////////////////////////////////////////////////////////////////// ///////////////////////___modpow___//////////////////// ll modpow(ll a, ll n, const ll &MOD = MOD){ ll ret = n == 0 ? 1 : modpow(a, n/2, MOD); (ret *= ret) %= MOD; if(n%2)((ret *= a) %= MOD); return ret; } ///////////////////////___modinv___//////////////////// ll modinv(ll d, const ll &MOD = MOD){ return modpow(d, MOD-2, MOD); } ///////////////////////___combination___//////////////////// vector<ll> fac, finv, inv; void COMinit(const int MAX = 5000000, const ll &MOD = MOD){ fac.resize(MAX);finv.resize(MAX);inv.resize(MAX); fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1; repd(i,2,MAX){ fac[i] = fac[i-1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD; finv[i] = finv[i-1] * inv[i] % MOD; } } ll COM(int n, int k){ if(n < k)return 0; if(n < 0 || k < 0)return 0; return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD; } /////////////////////////////////////////////////////////// int n,a[210000]; signed main(){ cin>>n;bool b = true; rep(i,n)cin>>a[i]; int ans = a[n-1], m = a[n-1]-1; for(int i = n-2;i >= 0;i--){ if(m > a[i] || m > i){ b = false; } if(a[i+1] != a[i]+1){ ans += a[i]; } m--; } if(b && a[0] == 0)cout << ans << endl; else cout << -1 << endl; }
#include<iostream> main(){ long a,b=-1,n,r; std::cin>>n; while(n--){ std::cin>>a; if(a>b+1)return std::cout<<-1,0; r+=a>b?1:a,b=a; } std::cout<<--r; }
1
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; long long MOD = 1000000000 + 7; int main(){ cout << setprecision(10); int N,Q; cin >> N >> Q; string S; cin >> S; vector<int> ans(N, 0); for(int i = 1; i < N; i++){ if(S[i] == 'C' && S[i-1] == 'A'){ ans[i] = 1; } } for(int i = 1; i < N; i++){ ans[i] += ans[i-1]; // cerr << "i: " << i << " ans[i]: " << ans[i] << endl; } while(Q--){ int l,r; cin >> l >> r; l--; r--; int ret; if(l == 0){ ret = ans[r]; } else { ret = ans[r] - ans[l-1]; if(S[l] == 'C' && S[l-1] == 'A'){ ret--; } } cout << ret << endl; } }
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for (int i=0;i<(int)(n);i++) #define codefor int test;scanf("%d",&test);while(test--) #define yn(ans) cout<<(ans?"Yes":"No")<<endl #define YN(ans) cout<<(ans?"YES":"NO")<<endl #define umap unordered_map #define uset unordered_set using namespace std; using ll = long long; const int MOD=1000000007; //入力系 void scan(int& a){scanf("%d",&a);} void scan(long long& a){scanf("%lld",&a);} template<class T> void scan(T& a){cin>>a;} template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);} //出力系 void print(const int& a){printf("%d",a);} void print(const long long& a){printf("%lld",a);} void print(const double& a){printf("%.15lf",a);} template<class T> void print(const T& a){cout<<a;} template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}} void out(){putchar('\n');} template<class T> void out(const T& t){print(t);putchar('\n');} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);} //デバッグ系 template<class T> void dprint(const T& a){cerr<<a;} template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}} void debug(){cerr<<endl;} template<class T> void debug(const T& t){dprint(t);cerr<<endl;} template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);} int main(){ int n,q; ll ans=0; string s; in(n,q,s); vector<ll> vec(n); vec[0]=0; for(int i=1;i<n;i++){ if(s[i-1]=='A'&&s[i]=='C'){ ans++; } vec[i]=ans; } int l,r; rep(i,q){ in(l,r); out(vec[r-1]-vec[l-1]); } }
1
#include<bits/stdc++.h> using namespace std; using ll=long long; #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define endl "\n" #define pb push_back #define mp make_pair #define F first #define S second #define int long long int #define pll pair<int , int> #define ALL(v) v.begin(),v.end() #define ALLR(v) v.rbegin(),v.rend() #define pii 3.14159265358979323 #define inf LLONG_MAX #define ones(x) __builtin_popcount(x) #define fill(a,b) memset(a,b,sizeof(a)) #define mod 1000000007 #define hell 998244353 ll mod_pow(ll a,ll b,ll m) { ll res = 1; while(b) { if(b&1) { res=(res*a) % m; } a=(a*a) % m; b>>=1; } return res; } ll mod_inverse(ll a) { return mod_pow(a , mod-2 , mod); } void solve() { int n , L; cin >> n >> L; int mx = inf; int sm1 = 0; for(int i = 1; i <= n; ++i) { sm1 += L + i -1; } int ans; for(int i = 1 ; i <= n; ++i) { int sm = 0; for(int j = 1; j <= n; ++j) { if(i != j) { sm += L + j - 1; } } //cout << abs(sm - sm1) << " " << sm << endl; if(abs(sm - sm1) < mx) { mx = abs(sm - sm1); ans = sm; } } cout << ans; } signed main() { fast; int t = 1; //cin >> t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) typedef long long ll; #define ALL(v) v.begin(), v.end() #define vmax(v) *max_element(ALL(v)) #define vmin(v) *min_element(ALL(v)) #define chmax(x, a) x = max(x, a) #define chmin(x, a) x = min(x, a) int main() { int N; cin >> N; vector<int> A(N); rep(i, N) cin >> A[i]; vector<int> memo = {-A[0]}; rep2(i, 1, N) { int tmp = upper_bound(ALL(memo), -A[i]) - memo.begin(); if (tmp == memo.size()) memo.push_back(-A[i]); else memo[tmp] = -A[i]; } cout << memo.size() << endl; }
0
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--) #define rrep(i,n) RREP(i,n-1,0) #define all(v) v.begin(), v.end() const int inf = 1e9+7; const ll longinf = 1LL<<60; const ll mod = 1e9+7; const ld eps = 1e-10; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; string s, t; cin >> s >> t; for(int i=n; i>=0; i--) { string s_ = s.substr(n-i); string t_ = t.substr(0, i); if(s_ == t_) { cout << n*2-i << "\n"; break; } } return 0; }
#include <iostream> #include <stdio.h> #include <vector> #include <math.h> #include <algorithm> using namespace std; int main(void){ int n,q; cin >> n >> q; string S; cin >> S; vector<int> sum(n+1,0); int i = 0; while (i < n) { if (S[i] == 'A' && S[i+1] == 'C') { sum[i+1] = sum[i] + 1; } else{ sum[i+1] = sum[i]; } i++; } i = 0; while (i < q) { int tmp1, tmp2; cin >> tmp1 >> tmp2; tmp1--; tmp2--; cout << sum[tmp2] - sum[tmp1] << endl; i++; } }
0
#include<bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second typedef pair<int,int> ii; priority_queue<int> q; vector<ii> v; int n, sum = 0; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i = 0 ; i < n ; ++i) { int D, L; cin >> D >> L; v.push_back(ii(D + L,L)); } sort(v.begin(),v.end()); for(int i = 0 ; i < n ; ++i) { q.push(v[i].se); sum += v[i].se; if(sum > v[i].fi) { sum -= q.top(); q.pop(); } } cout << q.size() << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string a, b, c; cin >> a >> b >> c; int ans = 0; for (int i = 0; i < n; i++) { string x, y, z; x = a.at(i); y = b.at(i); z = c.at(i); set<string> s{x, y, z}; if (s.size() == 3) { ans += 2; } else if (s.size() == 2) { ans += 1; } } cout << ans << '\n'; return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define Alhamdulillah return 0; #define debug(n) cerr << "[" << #n << " = " << n << "]" << endl void Suhaib_Sawalha (){ vector <string> v = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; string s; cin >> s; cout << v.end() - find(v.begin(),v.end(),s); } int main(){ In_The_Name_Of_Allah_The_Merciful /* بسم الله الرحمن الرحيم */ #ifndef ONLINE_JUDGE freopen("SuhaibSawalha1.txt","r",stdin); #endif //int _;for(cin>>_;_;--_,cout<<'\n') Suhaib_Sawalha(); Alhamdulillah /* الحمد لله */ }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9 + 7; const ll longinf = 5LL << 60; const ll mod = 1e9 + 7; int main() { string S; cin >> S; int ans = 7; if(S == "MON") ans = 6; if(S == "TUE") ans = 5; if(S == "WED") ans = 4; if(S == "THU") ans = 3; if(S == "FRI") ans = 2; if(S == "SAT") ans = 1; cout << ans << "\n"; }
1
#include <cstdio> #include <cstdlib> #include <cstring> using namespace std; char h[3]={" \n"}; int main() { int w[3],x; for(int j=0;j<2;j++){ memset(w,0,sizeof(w)); for(int i=0;i<10;i++){ scanf("%d",&x); if(x>w[0]){w[2]=w[1]; w[1]=w[0]; w[0]=x;} else if(x>w[1]) {w[2]=w[1]; w[1]=x;} else if(x>w[2]) w[2]=x; } printf("%d%c",w[0]+w[1]+w[2],h[j]); } }
#include <iostream> #include <algorithm> using namespace std; int main () { int w[10]; int k[10]; for (int i = 0; i < 10; i++) { cin >> w[i]; } for (int i = 0; i < 10; i++) { cin >> k[i]; } sort(w, w + 10); sort(k, k + 10); int wSum = 0, kSum = 0; for (int i = 9; i > 6; i--) { wSum += w[i]; } for (int i = 9; i > 6; i--) { kSum += k[i]; } cout << wSum << " " << kSum << endl; return 0; }
1
// Problem : E - Colorful Blocks // Contest : AtCoder - AtCoder Beginner Contest 167 // URL : https://atcoder.jp/contests/abc167/tasks/abc167_e // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> #define int long long #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define sz(a) (int)((a).size()) #define pb push_back #define mp make_pair #define db1(x) cout << #x << "=" << x << endl #define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define db3(x, y, z) \ cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \ << endl #define dbp(x) \ cout << #x << "= {" << (x.first) << ", " << (x.second) << "}" << endl; #define dbv(v) \ { \ cout << #v << " : "; \ for (auto x : v) cout << x << ' '; \ cout << endl; \ } #define rep(i, a, b) for (int i = a; i <= b; i++) #define rep2(i, a, b) for (int i = a; i >= b; i--) #define die(x) return cout << x << '\n', 0; const int MOD = 998244353; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; const int MAX = 2e5; ll modulo(ll a, ll b, ll n) { ll x = 1, y = a; while (b > 0) { if (b % 2 == 1) { x = (x * y) % n; // multiplying with base } y = (y * y) % n; // squaring the base b /= 2; } return x % n; } vi fact(MAX + 1), factinv(MAX + 1); void pre() { fact[0] = 1; factinv[0] = 1; for (int i = 1; i <= MAX; ++i) { fact[i] = (fact[i - 1] * i) % MOD; factinv[i] = (factinv[i - 1] * modulo(i, MOD - 2, MOD)) % MOD; } } int mult(int a, int b) { return (a * b) % MOD; } int nCr(int n, int r) { return mult(fact[n], mult(factinv[r], factinv[n - r])); } int32_t main() { fastio; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int testcases; testcases = 1; // cin>>testcases; pre(); while (testcases--) { int n, m, k; cin >> n >> m >> k; int ans = 0; rep(i, 0, k) { int temp = nCr(n - 1, i); temp = mult(temp, m); temp = mult(temp, modulo(m - 1, n - 1 - i, MOD)); ans = (ans + temp) % MOD; } cout << ans << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < n; ++i) #define rep2(i, i0, n) for (int i = i0; i < n; ++i) // x^y % m ll mpow(ll x, ll y, ll m = 998244353) { ll ret = 1; while (y != 0) { if (y & 1) ret = (ret * x) % m; x = (x * x) % m; y = y >> 1; } return ret; }; ll minv(ll a, ll m = 998244353) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int main() { const ll MOD = 998244353; ll n, m, k; cin >> n >> m >> k; if (m == 1) { cout << ((k == n - 1) ? 1 : 0) << endl; return 0; } ll ans = 0; ll fi = (m * mpow(m - 1, n - 1)) % MOD; ans = (ans + fi) % MOD; rep2(i, 1, k + 1) { fi = (fi * (n - i)) % MOD; fi = (fi * minv(i)) % MOD; fi = (fi * minv(m - 1)) % MOD; ans = (ans + fi) % MOD; } cout << ans << endl; return 0; }
1
#include<bits/stdc++.h> #define ll long long #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define mod 1000000007 using namespace std; int main() { fast_io ll i,j,n,x,ans=0; string s; bool fA=0,fc=0,noAZ=0; cin>>s; if(s[0]!='A'||(s[1]>='A'&&s[1]<='Z')||(s[s.length()-1]>='A'&&s[s.length()-1]<='Z')) return cout <<"WA"<<endl,0; ll cntc=0,cap=0; for(i=1; i<s.length()-1; i++) { if(i>=2&&i<s.length()-1) { if(s[i]=='C') cntc++; } if(s[i]>='A'&&s[i]<='Z') cap++; } if(cap>1) return cout <<"WA"<<endl,0; if(cntc!=1) return cout <<"WA"<<endl,0; return cout <<"AC"<<endl,0; return 0; }
#include<iostream> #include<string> #include<algorithm> using namespace std; int main() { string s; cin >> s; int l = s.length(); if(s[0]!='A'){ cout << "WA\n"; return 0; } int i, cnt = 0; for(i=1; i<l; i++){ if(isupper(s[i])){ if(i==1 || i==l-1 || s[i]!='C'){ cout << "WA\n"; return 0; } cnt++; } } if(cnt==1) cout << "AC\n"; else cout << "WA\n"; return 0; }
1
#include <iostream> using namespace std; #define MIN(a,b) ((a)<(b)?(a):(b)) int main() { int P; int minR=200,minS=200; int total=0; for(int i=0; i<4; ++i) { cin >> P; total+=P; minR=MIN(P,minR); } for(int i=0; i<2; ++i) { cin >> P; total+=P; minS=MIN(P,minS); } cout << total - minR - minS << endl; return 0; }
#include<stdio.h> #include<math.h> #include<algorithm> #include<cctype> #include<string.h> #include <stdlib.h> #define PI 3.1415926 void swap(int* x, int* y) { int a = *x; int b = *y; *x = b; *y = a; } int factorial(int n); int sum(int n, int*); int ave(int n, int*); int min(int n, int*), min(int n, int m); int max(int n, int*), max(int n, int m); int main() { int s[10] = { 0 }, h[10]{ 0 }; scanf("%d %d %d %d %d %d", &s[0], &s[1], &s[2], &s[3], &h[0], &h[1]); printf("%d\n", sum(4,s)- min(4, s)+max(2,h) ); return 0; } int factorial(int n) { if (n > 0) { return n * factorial(n - 1); } else { return 1; } } int sum(int n, int *all) { int total = 0; for (int i = 0; i < n; ++i) { total += all[i]; } return total; } int ave(int n, int *all) { int total = 0; for (int i = 0; i<n; ++i) { total += all[i]; } return total / n; } int min(int n, int *all) { int min = all[0]; for (int i = 1; i < n; ++i) { if (min > all[i]) { min = all[i]; } } return min; } int max(int n, int *all) { int max = all[0]; for (int i = 1; i<n; ++i) { if (max<all[i]) { max = all[i]; } } return max; } int max(int n, int m) { if (n >= m) { return n; } else { return m; } } int min(int n, int m) { if (n >= m) { return m; } else { return n; } }
1
#include <bits/stdc++.h> using namespace std; #define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl #define repi(i,a,b) for(int i=int(a);i<int(b);i++) #define peri(i,a,b) for(int i=int(b);i-->int(a);) #define rep(i,n) repi(i,0,n) #define per(i,n) peri(i,0,n) #define all(c) begin(c),end(c) #define mp make_pair #define mt make_tuple using uint=unsigned; using ll=long long; using ull=unsigned long long; using vi=vector<int>; using vvi=vector<vi>; using vl=vector<ll>; using vvl=vector<vl>; using vd=vector<double>; using vvd=vector<vd>; using vs=vector<string>; template<typename T1,typename T2> ostream& operator<<(ostream& os,const pair<T1,T2>& p){ return os<<'('<<p.first<<','<<p.second<<')'; } template<typename Tuple> void print_tuple(ostream&,const Tuple&){} template<typename Car,typename... Cdr,typename Tuple> void print_tuple(ostream& os,const Tuple& t){ print_tuple<Cdr...>(os,t); os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t); } template<typename... Args> ostream& operator<<(ostream& os,const tuple<Args...>& t){ print_tuple<Args...>(os<<'(',t); return os<<')'; } template<typename Ch,typename Tr,typename C> basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){ os<<'['; for(auto i=begin(c);i!=end(c);++i) os<<(i==begin(c)?"":" ")<<*i; return os<<']'; } constexpr int INF=1e9; constexpr int MOD=1e9+7; constexpr double EPS=1e-9; int getsum(const vvi& sums,int t,int b,int l,int r) { if(l>=r || t>=b) return 0; return sums[b][r]-sums[t][r]-sums[b][l]+sums[t][l]; } void chmax(int& a,int b) { a=max(a,b); } int main() { for(int h,w;cin>>h>>w && h|w;){ vs grid(h); rep(i,h) cin>>grid[i]; int ci=-1,cj=-1; rep(i,h) rep(j,w) if(grid[i][j]=='E') ci=i,cj=j; vvi sums(h+1,vi(w+1)); rep(i,h) rep(j,w) sums[i+1][j+1]=(grid[i][j]=='o')+sums[i+1][j]+sums[i][j+1]-sums[i][j]; int T=h-1-ci,B=ci,L=w-1-cj,R=cj; int dp[T+1][B+1][L+1][R+1]={}; rep(t,T+1) rep(b,B+1) rep(l,L+1) rep(r,R+1){ if(t!=T && ci+t+1<h-b) chmax(dp[t+1][b][l][r],dp[t][b][l][r]+getsum(sums,ci+(t+1),ci+(t+1)+1,max(cj-r,l),min(cj+l+1,w-r))); if(b!=B && t<=ci-(b+1)) chmax(dp[t][b+1][l][r],dp[t][b][l][r]+getsum(sums,ci-(b+1),ci-(b+1)+1,max(cj-r,l),min(cj+l+1,w-r))); if(l!=L && cj+l+1<w-r) chmax(dp[t][b][l+1][r],dp[t][b][l][r]+getsum(sums,max(ci-b,t),min(ci+t+1,h-b),cj+(l+1),cj+(l+1)+1)); if(r!=R && l<=cj-(r+1)) chmax(dp[t][b][l][r+1],dp[t][b][l][r]+getsum(sums,max(ci-b,t),min(ci+t+1,h-b),cj-(r+1),cj-(r+1)+1)); } int res=0; rep(t,T+1) rep(b,B+1) rep(l,L+1) rep(r,R+1) chmax(res,dp[t][b][l][r]); cout<<res<<endl; } }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(ll i=0;i<n;i++) #define repl(i,l,r) for(ll i=(l);i<(r);i++) #define per(i,n) for(ll i=n-1;i>=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define pqueue(x) priority_queue<x,vector<x>,greater<x>> #define all(x) (x).begin(),(x).end() #define CST(x) cout<<fixed<<setprecision(x) #define vtpl(x,y,z) vector<tuple<x,y,z>> #define rev(x) reverse(x); using ll=long long; using vl=vector<ll>; using vvl=vector<vector<ll>>; using pl=pair<ll,ll>; using vpl=vector<pl>; using vvpl=vector<vpl>; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[8]={1,0,-1,0,1,1,-1,-1}; const ll dx[8]={0,-1,0,1,1,-1,1,-1}; 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; } const ll match[10]={inf,2,5,5,4,5,6,3,7,6}; void update(string &a,string b){ if(a=="x")a=b; else if(a.size()<b.size())a=b; else if(a.size()==b.size()){ if(a<b)a=b; } } int main(){ ll n,m;cin >> n >> m; vl a(m);rep(i,m)cin >> a[i]; string dp[10100]; rep(i,10100){ dp[i]="x"; } dp[0]=""; rep(i,n+1){ if(dp[i]=="x")continue; for(auto p:a){ update(dp[i+match[p]],dp[i]+to_string(p)); } } cout << dp[n] <<endl; }
0
#include <cstdio> #include <stdlib.h> int main() { int s[600]; int t[6]; int c = 0; char h[4] = {'N', 'S', 'W', 'E'}; int n; bool a = false; scanf("%d", &n); for (int i = 0; i < 6 * n; i++) { scanf("%d", &s[i]); } for (int i = 0; i < n; i++) { while (1) { int k = rand() % 4; if (h[k] == 'N') { t[4] = s[0 + i * 6]; t[0] = s[1 + i * 6]; t[1] = s[5 + i * 6]; t[5] = s[4 + i * 6]; t[2] = s[2 + i * 6]; t[3] = s[3 + i * 6]; } if (h[k] == 'S') { t[0] = s[4 + i * 6]; t[1] = s[0 + i * 6]; t[5] = s[1 + i * 6]; t[4] = s[5 + i * 6]; t[2] = s[2 + i * 6]; t[3] = s[3 + i * 6]; } if (h[k] == 'W') { t[0] = s[2 + i * 6]; t[2] = s[5 + i * 6]; t[5] = s[3 + i * 6]; t[3] = s[0 + i * 6]; t[1] = s[1 + i * 6]; t[4] = s[4 + i * 6]; } if (h[k] == 'E') { t[2] = s[0 + i * 6]; t[5] = s[2 + i * 6]; t[3] = s[5 + i * 6]; t[0] = s[3 + i * 6]; t[1] = s[1 + i * 6]; t[4] = s[4 + i * 6]; } for (int j = 0; j < 6; j++) { s[j + i * 6] = t[j]; } for (int j = i + 1; j < n; j++) { if (s[0 + i * 6] == s[0 + j * 6] && s[1 + i * 6] == s[1 + j * 6] && s[2 + i * 6] == s[2 + j * 6] && s[3 + i * 6] == s[3 + j * 6] && s[4 + i * 6] == s[4 + j * 6] && s[5 + i * 6] == s[5 + j * 6]) { a = true; break; } } if (c == 1000) { break; } c += 1; } } if (a == false) { printf("Yes\n"); } if (a == true) { printf("No\n"); } }
#include<iostream> using namespace std; class Dice { public: int f[7]; Dice() {} void roll_x() { roll(1, 4, 6, 3); } // to E void roll_y() { roll(1, 2, 6, 5); } // to N void roll_z() { roll(2, 3, 5, 4); } // 上から見て時計回り void roll(int i, int j, int k, int l) { int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t; } }; bool judge(Dice c1, Dice c2) { for (int i = 1; i <= 6; i++) { if (c1.f[i] != c2.f[i]) return false; } return true; } bool getRight(Dice c1, Dice c2) { for (int i = 0; i < 6; i++) { for (int j = 0; j < 4; j++) { if (judge(c1, c2)) return true; c1.roll_z(); } if (i % 2 == 0) c1.roll_x(); else c1.roll_y(); } return false; } Dice D[100]; int n; bool check(){ for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ if(getRight(D[i],D[j])) return false; } } return true; } int main() { cin >> n; for(int i=0;i<n;i++){ for(int j=1;j<=6;j++){ cin >> D[i].f[j]; } } if(check()) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
1
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <vector> #include <cmath> #include <fstream> #include <set> #include <utility> #include <algorithm> #include <queue> #include <stack> #include <deque> #include <numeric> #include <sstream> #include <list> #include <map> #define rep(i,p,n) for(int i=(int)p;i<(int)n;i++) #define repp(i,p,n) for(int i=(int)p;i>=(int)n;i--) #define Sort(x) sort(x.begin(),x.end()); #define ll long long #define vi vector<int> #define vvi vector<vector<int>> #define vvvi <vector<vector<vector<int>>> #define vc vector<char> #define vvc vector<vector<char>> #define vvvc vector<vector<vector<char>>> #define INF 2000000000 using namespace std; int main() { while (1) { int n; cin >> n; if (n == 0)break; vector<int> v(10,0); for (int i = 0; i < n; i++) { int x; cin >> x; v[x]++; } for (int i = 0; i < 10; i++) { if (v[i] != 0) { for (int j = 0; j < v[i]; j++) cout << "*"; cout << endl; } else cout << "-" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int dx[]={1,0,0,-1,1,-1,-1,1,2,0,-2,0}; const int dy[]={0,1,-1,0,1,1,-1,-1,0,2,0,-2}; const int INF = 1<<30; const double EPS = 1e-8; #define PB push_back #define mk make_pair #define fr first #define sc second #define reps(i,j,k) for(int i = (j); i < (k); ++i) #define rep(i,j) reps(i,0,j) #define MOD 1000000007 #define lengthof(x) (sizeof(x) / sizeof(*(x))) typedef pair<int,int> Pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef long long ll; int main(){ int N,Q; while(scanf("%d%d",&N,&Q),(N|Q)){ int s[128]={0}; int length = 0; rep(i,N){ int c; scanf("%d",&c); rep(j,c){ int t; scanf("%d",&t); s[t]++; length = max(length,t); } } length++; int ans = 0; int index = 0; rep(i,length){ if(s[i]>=Q && ans < s[i]){ ans = s[i]; index = i; } } printf("%d\n",index); } return 0; }
0
#include <bits/stdc++.h> using namespace std; #define int long long int dp[5010]; const int INF = 1e12+10; int32_t main() { ios::sync_with_stdio(false);cin.tie(0); int n; cin>>n; vector<pair<int,int> > v(n); for(int i=0;i<n;i++) { cin>>v[i].first>>v[i].second; } sort(v.begin(), v.end(), [](const pair<int,int> &l, const pair<int,int> &r){ return l.first+l.second<r.first+r.second; }); for(int i=1;i<=5000;i++) dp[i] = INF; for(int i=0;i<n;i++) { for(int j=5000;j>=0;j--) { if(dp[j]<=v[i].first) dp[j+1] = min(dp[j+1],dp[j]+v[i].second); } } for(int i=5000;i>=0;i--) { if(dp[i]!=INF) { cout<<i; return 0; } } return 0; }
#include <bits/stdc++.h> #define int long long using pii=std::pair<int,int>; using namespace std; const int maxn = 16, maxmask = 1ll << 16; int n, a[maxn][maxn], dp[maxmask]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> a[i][j]; for(int i = 0; i < (1 << n); i++) { for(int j = 0; j < n; j++) for(int k = j + 1; k < n; k++) if((i & (1ll << j)) && (i & (1ll << k))) dp[i] += a[j][k]; for(int j = i; j > 0; j = (j - 1) & i) dp[i] = max(dp[i], dp[j] + dp[i ^ j]); } cout << dp[(1 << n) - 1] << "\n"; return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; //print(fixed << setprecision(10)); #define rep(i,n) for(ll i = 0; i < (n); i++) #define repk(i,n,k) for(ll i = k; i < (n); i++) #define all(n) n.begin(), n.end() #define print(n) cout << n << endl double PI = acos(-1.0); int INF = 1e9; ll LINF = 1e18; ll MOD = 1e9+7; int main(){ cin.tie(0); ios_base::sync_with_stdio(false); ll n; cin >> n; string s=""; while(n){ n--; s+=('a'+(n+25/26)%26); n/=26; } reverse(all(s)); print(s); return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { string s; cin >> s; string c = "abcdefghijklmnopqrstuvwxyz"; bool find_flag = false; for (int i=0; i<26; i++) { bool target = false; for (int j=0; j<s.length(); j++) { if (c[i] == s[j]) target = true; } if (!target) { cout << c[i] << endl; find_flag = true; break; } } if (!find_flag) cout << "None" << endl; return 0; }
0
#include<bits/stdc++.h> using namespace std; int main() { int H,W; cin>>H>>W; char s[60][60]; int a=0; for(int i=1;i<=H;i++){ for(int j=1;j<=W;j++){ cin>>s[i][j]; } } for(int i=1;i<=H;i++){ for(int j=1;j<=W;j++){ if(s[i][j]=='#'&&s[i-1][j]!='#'&&s[i+1][j]!='#'&&s[i][j-1]!='#'&&s[i][j+1]!='#'){ a++; } } } if(a==0){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; // 小数点以下桁数 // fixed << setprecision(i) int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));} int64_t lcm(int64_t a,int64_t b){return a/gcd(a, b)*b;} int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応 bool is_prime(int64_t a){if(a<=1)return false;for(int64_t i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;} int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得 int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;} //順列の全列挙 // vector<int> v(N); // iota(v.begin(), v.end(), 1); // v に 1, 2, ... N を設定 // do { // for(auto x : v) cout << x << " "; cout << "\n"; // v の要素を表示 // } while( next_permutation(v.begin(), v.end()) ); //bit全探索 // for (int tmp = 0; tmp < (1 << ビット数); tmp++) { // bitset<ビット数> s(tmp); // // (ビット列sに対する処理) // } int main() { int64_t ans = 0; int n, temp, r = 0, g = 0, b = 0; string s; cin >> n >> s; for (int i = 0; i < n; i++) { if (s[i] == 'R') r++; else if (s[i] == 'G') g++; else b++; } ans = (int64_t)r * g * b; for (int i = 1; i <= n / 2; i++) { for (int j = i; j < n - i; j++) { if (s[j] != s[j - i] && s[j] != s[j + i] && s[j - i] != s[j + i]) ans--; } } ans = (ans < 0 ? 0 : ans); // cout << r << " " << g << " " << b << endl; // cout << r * g * b << endl; cout << ans << endl; }
0
#include<iostream> #include<stdio.h>//printf("%.9f\n",*********); #include<vector>//文字列.erase(n),vector #include<algorithm>//next_permutation #include<set> #include<string>//char(小文字-32=大文字) to_string,string,char #include<sstream> #include<complex> #include<time.h> #include<random> #include<cmath>//min,max #include<math.h> #include<queue> #include<time.h> #include<iomanip> #include<locale> #include<utility>//swap #define rt "\n" #define rep(i,n) for(int i=0;i<n;i++) #define rop(i,n) for(int i=1;i<=n;i++)//start==1 #define drep(i,n) for(int i=n-1;0<=i;i--) #define drop(i,n) for(int i=n;0<i;i--)//end==1 #define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt; #define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt; #define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt; #define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt; #define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt; #define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数) #define sort(s) sort(s.begin(),s.end())//標準=昇順 #define reve(s) reverse(s.begin(),s.end())//反転 #define str string #define please return #define AC 0 #define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false) #define pi 3.1415926535897932384626//pi #define nine 1000000000//10^9 using namespace std; typedef vector<int> vint; typedef long double ldouble; typedef vector<string> vstr; typedef vector<char> vchar; typedef vector<double> vdou; typedef vector<double> vdouble; typedef long long int llint; typedef pair<int, int> pint; typedef pair<llint, llint> pllint; typedef vector<llint> vllint; typedef vector<pint> vpint; typedef vector<pair<llint, llint>> vpllint; typedef vector<vector<int>> vvint; typedef vector<vector<char>> vvchar; typedef vector<vector<double>> vvdouble; typedef vector<vector<llint>> vvllint; typedef vector<vector<string>> vvstr; typedef vector<vector<bool>> vvbool; typedef vector<vector<pint>> vvpint; typedef vector<bool> vbool; long long GCD(long long a, long long b) { if (b == 0) return a; else return GCD(b, a % b); } long long LCM(long long a, long long b) { return a * b / GCD(a, b); } unsigned GetDigit(unsigned num) { return std::to_string(num).length(); } int tow(int n) {//2のn乗 if (n == 0)return 1; int x = tow(n / 2); x *= x; if (n % 2 == 1)x *= 2; return x;//@domino } int SED(int n) { //Sum of Each Digit int sum = 0; while (n > 0) { sum += n % 10; n /= 10; } return sum; } unsigned ND(unsigned num) {//Number of Digits return std::to_string(num).length();//outmax=10 }//stringのほうが効率よくないか? /* (char)toupper(a[n])=文字列のn文字目を大文字で出力 pow(a,b)=aのb乗 */ int main(void) { rapid_pleaseAC_fast; int n, h, w; cin >> n >> h >> w; int x = n - w + 1; int y = n - h + 1; cout << x * y << rt; please AC; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i, n) for (ll i = 0; i < n; i++) #define rrep(i, n) for (ll i = n - 1; i >= 0; i--) #define Rep(i, r, n) for (ll i = r; i < n; i++) #define RRep(i, r, n) for (ll i = n - 1; i <= r; i--) #define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl; #define fs first #define sc second #define int long long #define pb push_back #define mp make_pair const int dx[] = {0, -1, 0, 1}; const int dy[] = {1, 0, -1, 0}; const int MOD = (1000000007); //const int MOD = (998244353); //const int INF = (1 << 30)-1; const int INF = (1LL << 60)-1; const double EPS = (1 >> 30); template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;} template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;} using Graph = vector<vector<pair<int, int>>>; using Ki = vector<vector<int>>; using Vi = vector<int>; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); //--------------------------------------------- int n,a,b; cin>>n>>a>>b; int ans=(n-a+1)*(n-b+1); if(ans<0){ cout<<0<<endl; } else{ cout<<ans<<endl; } }
1
#include <stdio.h> int main() { char str[31], ctr = 0; scanf("%[^\n]", str); for(int i = 0; str[i] != '\0'; i++) { if(str[i] == ' ' && str[i-1] == str[i+1]) { ctr++; } } if(ctr == 2) { puts("YES"); } else { puts("NO"); } return 0; }
#include <iostream> #include <vector> #include <cstdlib> #include <algorithm> #include <numeric> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; using vi = vector<int>; // intの1次元の型に vi という別名をつける using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける using vl = vector<ll>; // long longの1次元の型に vl という別名をつける using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける int MOD = 1000000007; //10^9 + 7 template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } // 無限大の値 const ll LINF = 1LL << 60; const int iINF = 1 << 29; int main(void){ string a,b,c; cin >> a >> b >> c; cout << (*a.rbegin() == *b.begin() && *b.rbegin() == *c.begin() ? "YES" : "NO") << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; void chmin(int& a, int b) { if (a > b) a = b; } int main() { int N, K; cin >> N >> K; vector<int> minus, plus; for (int i = 0; i < N; i++) { int x; cin >> x; if (x >= 0) { plus.push_back(x); } else { minus.push_back(-x); } } sort(minus.begin(), minus.end()); int ans = 300000000; int M = minus.size(), P = plus.size(); // minusの個数, Kとのminを int minus_num = min(M, K); int plus_num = min(P, K); if (minus_num == 0) { ans = plus[K-1]; } else if (plus_num == 0) { ans = minus[K-1]; } else { for (int i = K - plus_num; i <= minus_num; i++) { chmin(ans, min(minus[i-1], plus[K-i-1]) + minus[i-1] + plus[K-i-1]); } } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; using lli = long long; #define rep(i,n) for(int i=0;i<n;i++) 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; } lli n, k; int main(void){ cin >> n >> k; vector<lli> a(n); rep(i, n) cin >> a[i]; if(find(a.begin(), a.end(), k) != a.end()){ cout << "POSSIBLE" << endl; return 0; } if(*max_element(a.begin(), a.end()) < k){ cout << "IMPOSSIBLE" << endl; return 0; } lli g = 0; rep(i, n) g = __gcd(g, a[i]); if(k%g == 0){ cout << "POSSIBLE" << endl; }else{ cout << "IMPOSSIBLE" << endl; } return 0; }
0
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; using ll = long long; #define REP(i, a) for (int i = 0; i < (a); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i) #define ALL(obj) (obj).begin(), (obj).end() #define SIZE(obj) (int)(obj).sizeT() #define YESNO(cond, yes, no) \ { cout << ((cond) ? (yes) : (no)) << endl; } #define SORT(list) sort(ALL((list))); #define RSORT(list) sort((list).rbegin(), (list).rend()) #define ASSERT(cond, mes) assert(cond&& mes) constexpr int MOD = 1'000'000'007; constexpr int INF = 1'050'000'000; template <typename T> T round_up(const T& a, const T& b) { return (a + (b - 1)) / b; } template <typename T1, typename T2> istream& operator>>(istream& is, pair<T1, T2>& p) { is >> p.first >> p.second; return is; } template <typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1, T2>& p) { os << p.first << p.second; return os; } template <typename T> istream& operator>>(istream& is, vector<T>& v) { REP(i, (int)v.size()) is >> v[i]; return is; } template <typename T> T clamp(T& n, T a, T b) { if (n < a) n = a; if (n > b) n = b; return n; } template <typename T> static T GCD(T u, T v) { T r; while (v != 0) { r = u % v; u = v; v = r; } return u; } template <typename T> static T LCM(T u, T v) { return u / GCD(u, v) * v; } std::vector<int> enum_div(int n) { std::vector<int> ret; for (int i = 1; i * i <= n; ++i) { if (n % i == 0) { ret.push_back(i); if (i != 1 && i * i != n) { ret.push_back(n / i); } } } return ret; } template <typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; } template <typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; } struct ToUpper { char operator()(char c) { return toupper(c); } }; struct ToLower { char operator()(char c) { return tolower(c); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); string S; int w; cin >> S >> w; string ans = ""; for (int i = 0; i * w < S.length(); i++) { ans.push_back(S[i * w]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); typedef long long ll; typedef long double ld; #define pb push_back #define mp make_pair #define ff first #define ss second #define mod 1000000007 #define pii pair<ll,ll> #define inf 1000000000000000000 #define bpc(x) __builtin_popcountll(x) #define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++) #define rep(n) for(ll i = 0; i < n; i++) #define repi(i,n) for(ll i = 0; i < n; i++) #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> using namespace std; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); ll powa(ll a, ll b, ll c) { a%=c; if(a<0) a+=c; ll res = 1; while(b>0) { if(b&1) res*=a, res%=c; a*=a, a%=c; b>>=1; } return res; } int main() { FAST/**/ ll n; cin>>n; ll arr[n]; ll sum = 0; rep(n) cin>>arr[i], sum+=arr[i], sum%=mod; sum = (sum*sum)%mod; rep(n) sum = (sum-((arr[i]*arr[i])%mod)+mod)%mod; sum*=powa(2,mod-2,mod); sum%=mod; cout<<sum; return 0; }
0
#include<iostream> #include<vector> using namespace std; struct Vertex{ int key; int parent; int left; int right; }; vector<Vertex> V; int root=-1; void Preorder(int r){ cout <<" "<< V[r].key; if(V[r].left!=-1) Preorder(V[r].left); if(V[r].right!=-1) Preorder(V[r].right); return; } void Inorder(int r){ if(V[r].left!=-1) Inorder(V[r].left); cout <<" "<< V[r].key; if(V[r].right!=-1) Inorder(V[r].right); return; } void Postorder(int r){ if(V[r].left!=-1) Postorder(V[r].left); if(V[r].right!=-1) Postorder(V[r].right); cout <<" "<< V[r].key; return; } void insert(int k){ Vertex z; z.key=k; z.left=-1; z.right=-1; int y=-1; int x=root; while(x!=-1){ y=x; if (z.key<V[x].key){ x=V[x].left; }else{ x=V[x].right; } } z.parent=y; V.push_back(z); if(y==-1){ root = 0; }else if(z.key < V[y].key){ V[y].left=V.size()-1; }else{ V[y].right=V.size()-1; } } void printVertex(int i){ cout << V[i].key <<" " <<V[i].parent <<" " << V[i].left << " " << V[i].right <<endl; } void print(){ Inorder(root); cout <<endl; Preorder(root); cout <<endl; } int find(int k){ int v=root; while(1){ if(k == V[v].key){ return v; }else if(k < V[v].key){ if(V[v].left==-1){ return -1; }else{ v=V[v].left; } }else{ if(V[v].right==-1){ return -1; }else{ v=V[v].right; } } } } int next(int k){ int u=V[k].right; while(V[u].left!=-1){u=V[u].left;} return u; } void del(int k){ int vk=find(k); int par=V[vk].parent; //printVertex(vk); //cout << endl; if(V[vk].left==-1 && V[vk].right==-1){ if(par == -1){ root = -1; }else if(V[par].left==vk) { V[par].left=-1; }else{ V[par].right=-1; } }else if(V[vk].left==-1 && V[vk].right!=-1){ if(par == -1){ root=V[vk].right; }else if(V[par].left==vk){ V[par].left=V[vk].right; }else{ V[par].right=V[vk].right; } V[V[vk].right].parent=par; }else if(V[vk].left!=-1 && V[vk].right==-1){ if(par==-1){ root=V[vk].left; }else if(V[par].left==vk) { V[par].left=V[vk].left; }else{ V[par].right=V[vk].left; } V[V[vk].left].parent=par; }else{ int x=V[next(vk)].key; del(x); V[vk].key=x; } } int main(){ int n,k; string s; cin >> n; for (int i=0;i<n;i++){ cin >> s; if(s=="insert"){ cin >> k; insert(k); }else if(s=="find"){ cin >> k; if(find(k)!=-1){ cout <<"yes"<<endl; }else{ cout << "no" <<endl; } }else if(s=="delete"){ cin >> k; del(k); }else{ print(); } } /* for(int i=0;i<n;i++){ printVertex(i); cout <<endl; } */ return 0; }
// clang-format off #include <bits/stdc++.h> #define int long long #define main signed main() // #define main int main() #define loop(i, a, n) for (int i = (a); i < (n); i++) #define rep(i, n) loop(i, 0, n) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define prec(n) fixed << setprecision(n) #define stlice(from, to) substr(from, (to) - (from) + 1) #define pb push_back #define mp make_pair #define mt make_tuple #define fi first #define se second using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<double> vd; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<pii> vpii; typedef vector<vi> vvi; typedef vector<vb> vvb; typedef vector<vpii> vvpii; const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000; const int MOD = 1000000007; const double PI = acos(-1); template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; } template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; } bool odd(const int &n) { return n & 1; } bool even(const int &n) { return !odd(n); } template<typename V> typename V::value_type sum(const V &v) { return accumulate(all(v), 0); } void solve(); main { solve(); return 0; } // clang-format on bool f(string s) { vs t; t.pb("the"); t.pb("the."); t.pb("this"); t.pb("this."); t.pb("that"); t.pb("that."); stringstream ss; ss << s; string x; while (ss >> x) { if (find(all(t), x) != t.end()) return true; } return false; } void nextS(string &s) { rep(i, s.size()) { if ('a' <= s[i] && s[i] <= 'z') { s[i] = (s[i] - 'a' + 1) % 26 + 'a'; } } } void solve() { string s; while (getline(cin, s)) { do { if (f(s)) { cout << s << endl; break; } } while (nextS(s), 1); } }
0
#include<stdio.h> int main() { int i,a,w1=0,w2=0,w3=0,k1=0,k2=0,k3=0; for(i=0;i<10;i++){ scanf("%d",&a); if(w3<a){ w3=a; if(w2<a){ w3=w2; w2=a; if(w1<a){ w2=w1; w1=a; } } } } for(i=0;i<10;i++){ scanf("%d",&a); if(k3<a){ k3=a; if(k2<a){ k3=k2; k2=a; if(k1<a){ k2=k1; k1=a; } } } } printf("%d %d\n",w1+w2+w3,k1+k2+k3); return 0; }
#include <bits/stdc++.h> using namespace std ; #define pb(n) push_back(n) #define fi first #define se second #define all(r) (r).begin(),(r).end() #define gsort(st,en) sort((st),(en),greater<int>()) #define vmax(ary) *max_element(all(ary)) #define vmin(ary) *min_element(all(ary)) #define debug(x) cout<<#x<<": "<<x<<endl #define fcout(n) cout<<fixed<<setprecision((n)) #define scout(n) cout<<setw(n) #define vary(type,name,size,init) vector< type> name(size,init) #define rep(i,n) for(int i = 0; i < (int)(n);++i) #define REP(i,a,b) for(int i = (a);i < (int)(b);++i) #define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it) #define repa(n,array) for(auto &n :(array)) using ll = long long; using vi = vector<int>; using vl = vector<ll>; using dict = map<string,int>; using pii = pair<int,int> ; using pll = pair<ll,ll> ; const int mod = 1000000007; constexpr int imax = ((1<<30)-1)*2+1 ; constexpr int inf = 100000000; constexpr double PI = acos(-1.0) ; double eps = 1e-10 ; const int dy[] = {-1,0,1,0}; const int dx[] = {0,-1,0,1}; inline bool value(int x,int y,int w,int h){ return (x >= 0 && x < w && y >= 0 && y < h); } template<typename T> void Unique(vector<T> &v){ sort(all(v)); v.erase(unique(all(v)),v.end()); } template<typename T> T ston(string& str, T n){ istringstream sin(str) ; T num ; sin >> num ; return num ; } void Ans(bool f){ if(f) cout << "YES"<<endl; else cout << "NO"<<endl; } int main(){ cin.tie(0); ios::sync_with_stdio(false); vary(ll,w,10,0); vary(ll,k,10,0); rep(i,10){ cin >> w[i]; } sort(all(w)); reverse(all(w)); rep(i,10){ cin >> k[i]; } sort(all(k)); reverse(all(k)); ll a = 0, b = 0; rep(i,3){ a += w[i]; } rep(i,3){ b += k[i]; } cout << a << " " << b << endl; return 0; }
1
#include <stdio.h> #include <math.h> #include <iostream> #include <algorithm> #include <vector> #include <numeric> #include <string> using namespace std; typedef long long int lli; #define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++) #define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--) int main(void) { string s; cin >> s; if (s.length() == 2) { cout << s << endl; } else { cout << s[2] << s[1] << s[0] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i,n) for(int i = 0; i < (n); ++i) #define ll long long #define P pair<ll,ll> #define all(v) (v).begin(),(v).end() const ll mod = 1e9+7; const ll INF = 1e18; const double pi = acos(-1.0); int main(void) { ll n; cin>>n; cout<<180*(n-2)<<endl; return 0; }
0
#include <iostream> #include <vector> #include <algorithm> #include <string.h> #include <iomanip> #include <math.h> #include <string> #include <queue> #include <map> #include <set> #include <functional> using namespace std; typedef long long int ll; typedef std::pair<int, int> pii; typedef std::pair<ll, int> pli; typedef std::pair<ll, ll> pll; #define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i) #define REP(i,n) FOR(i,n,0) #define IREP(i,n) for(ll i=(ll)(n);i>=0;--i) #define OF64 std::setprecision(10) const ll MOD = 1000000007; const ll INF = (ll)1e15; struct Face { int f; int a[4]; }; struct Dice { Face f[6]; }; Dice createDice(int k[]) { Face d[6]; d[0].f = k[0]; d[0].a[0] = k[4]; d[0].a[1] = k[2]; d[0].a[2] = k[1]; d[0].a[3] = k[3]; d[1].f = k[1]; d[1].a[0] = k[0]; d[1].a[1] = k[2]; d[1].a[2] = k[5]; d[1].a[3] = k[3]; d[2].f = k[2]; d[2].a[0] = k[0]; d[2].a[1] = k[4]; d[2].a[2] = k[5]; d[2].a[3] = k[1]; d[3].f = k[3]; d[3].a[0] = k[0]; d[3].a[1] = k[1]; d[3].a[2] = k[5]; d[3].a[3] = k[4]; d[4].f = k[4]; d[4].a[0] = k[0]; d[4].a[1] = k[3]; d[4].a[2] = k[5]; d[4].a[3] = k[2]; d[5].f = k[5]; d[5].a[0] = k[1]; d[5].a[1] = k[2]; d[5].a[2] = k[4]; d[5].a[3] = k[3]; Dice dice; REP(i, 6) { dice.f[i] = d[i]; } return dice; } int main() { Dice d[105]; int n; cin >> n; int sum = 0; REP(i, n) { int x[6]; REP(j, 6) { cin >> x[j]; sum += x[j]; } d[i] = createDice(x); } if (sum == 22) { cout << "No" << endl; return 0; } string S = "Yes"; REP(i, n) { FOR(j, n, i + 1) { bool same = true; REP(k, 6) { Face f1 = d[i].f[k]; REP(l, 6) { Face f2 = d[j].f[l]; if (f1.f == f2.f) { int s = -1; REP(m, 4) { if (f1.a[0] == f2.a[m]) { s = m; break; } } if (s == -1) { same = false; break; } REP(m, 4) { if (f1.a[m] != f2.a[(m + s) % 4]) { same = false; break; } } break; } if (l == 5) { same = false; } } } if (same) { S = "No"; break; } } } cout << S << endl; return 0; }
#include <iostream> #include <string> #include <algorithm> #include <cstdio> #include <cmath> #include <iomanip> #include <cstdlib> using namespace std; int main () { int n,m,i,j,t=0; int a,b,c,d,f,g,a11,b1,c1,d1,f1,g1; string s="EEEESEEEESEEEESEEEESESEEEESSEEE"; n=s.size(); int a1[n+1],a2[n+1],a3[n+1],a4[n+1],a5[n+1],a6[n+1]; cin >> m; cin >> a >> b >> c >> d >> f >> g ; for(j=0;j<m-1;j++){ int a1[n+1],a2[n+1],a3[n+1],a4[n+1],a5[n+1],a6[n+1]; cin >> a11 >> b1 >> c1 >> d1 >> f1 >> g1; a1[0]=a11; a2[0]=b1; a3[0]=c1; a4[0]=d1; a5[0]=f1; a6[0]=g1; for(i=0;i<n;i++){ if(s[i]=='S'){ a1[i+1]=a5[i]; a2[i+1]=a1[i]; a3[i+1]=a3[i]; a4[i+1]=a4[i]; a5[i+1]=a6[i]; a6[i+1]=a2[i]; } else if(s[i]=='N'){ a1[i+1]=a2[i]; a2[i+1]=a6[i]; a3[i+1]=a3[i]; a4[i+1]=a4[i]; a5[i+1]=a1[i]; a6[i+1]=a5[i]; } else if(s[i]=='W'){ a1[i+1]=a3[i]; a2[i+1]=a2[i]; a3[i+1]=a6[i]; a4[i+1]=a1[i]; a5[i+1]=a5[i]; a6[i+1]=a4[i]; } else if(s[i]=='E'){ a1[i+1]=a4[i]; a2[i+1]=a2[i]; a3[i+1]=a1[i]; a4[i+1]=a6[i]; a5[i+1]=a5[i]; a6[i+1]=a3[i]; } if((a1[i+1]==a)&&(a2[i+1]==b)&&(a3[i+1]==c)&&(a4[i+1]==d)&&(a5[i+1]==f)&&(a6[i+1]==g)){ t=1; break; } } } if(t==1) cout << "No" << endl; else cout << "Yes" << endl; }
1
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { string a; cin >> a; reverse(a.begin(),a.end()); cout << a << endl; }
#include<iostream> #include<sstream> using namespace std; int main(){ string str; cin >> str; std::istringstream stream(str); for(int i=str.length()-1; i>=0; i--){ stream >> str[i]; } cout << str << endl; return 0; }
1
#pragma region template 2.4 #include <bits/stdc++.h> using namespace std; template <typename T> using pq_asc = priority_queue<T, vector<T>, greater<T>>; typedef long long ll; typedef vector<ll> vi; typedef vector<vi> vvi; typedef pair<ll, ll> ii; typedef vector<ii> vii; typedef vector<string> vs; #define REP(i, n) for (ll i = 0; i < (n); ++i) #define REP1(i, n) for (ll i = 1; i <= (n); ++i) #define FOR(i, a) for (auto &i : a) #define CH(f, x, y) x = f(x, y) #define IN(T, x) \ T x; \ cin >> x; #define AIN(T, a, n) \ vector<T> a(n); \ FOR(i, a) \ cin >> i; #define A2IN(T1, a, T2, b, n) \ vector<T1> a(n); \ vector<T2> b(n); \ REP(i, n) \ cin >> a[i] >> b[i]; #define OUT(x) cout << (x) << endl; #define FOUT(x) cout << fixed << setprecision(15) << (x) << endl; #define ALL(a) (a).begin(), (a).end() #define SORT(a) sort(ALL(a)) #define RSORT(a) \ SORT(a); \ reverse(ALL(a)) #define DUMP(x) cout << #x << " = " << (x) << endl; #define DUMPA(a) \ cout << #a << " = {"; \ JOUT(ALL(a), ", ", cout) << "}" << endl; template <typename T> ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout) { if (s != e) { os << *s; ++s; } while (s != e) { os << sep << *s; ++s; } return os; } ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout) { if (cond) { os << yes << endl; } else { os << no << endl; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '['; JOUT(ALL(v), ", ", os) << ']'; return os; } const ll INF = 1e18; const ll MOD = 1e9 + 7; #pragma endregion template int main() { IN(ll, N); IN(ll, K); AIN(ll, p, N); double s = 0; REP(i, K) { s += (1 + p[i]) / 2.0; } double ans = s; for (ll i = K; i < N; ++i) { s += (p[i] - p[i - K]) / 2.0; CH(max, ans, s); } FOUT(ans); }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; double expected_value(int n) { return (double)((1 + n) * n / 2) / (double)n; } int main() { int n, k; cin >> n >> k; vector<double> ps(n + 1); vector<double> comsum(n + 1, 0); int p; rep(i, n) { cin >> p; ps[i + 1] = expected_value(p); comsum[i + 1] = comsum[i] + ps[i + 1]; } double mm = 0; for (int i = k; i <= n; i++) { mm = max(comsum[i] - comsum[i - k], mm); } printf("%.6f\n", mm); return 0; }
1
#include <iostream> using namespace std; int main() { int n; cin >> n; int x; cin >> x; long min, max, sum; min = max = sum = x; for (int i = 1; i < n; ++i) { cin >> x; if (x < min) min = x; if (max < x) max = x; sum += x; } cout << min << ' ' << max << ' ' << sum << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c, mn=100000; cin>> a >> b >> c; mn = min(b+a,mn); mn= min(b+c,mn); mn= min(a+c,mn); cout<<mn<<endl; return 0; }
0
#include <stdio.h> #include <iostream> #include <algorithm> #include <functional> #include <cstdlib> #include <sstream> #include <string> #include <set> #include <map> #include <stack> #include <queue> #include <deque> #include <complex> #include <vector> #include <cstdio> #include <cmath> #include <time.h> #define all(c) ((c).begin(),(c).end()) #define rall(c) (c).rbegin(),(c).rend() #define sort(v,n) sort(v,v+n) #define vsort(v) sort(v.begin(),v.end()) #define vvsort(v) sort(v.begin(),v.end(),greater<int>()) #define ll long long #define pb(a) push_back(a) #define fi first #define se second #define inf 999999999 using namespace std; const ll MOD = 1e9 + 7; const double PI = acos(-1.0); //---------------------------------------------------------------------------------------------// int n; int main() { while (cin>>n) { if (n == 0)return 0; int x[21], y[21]; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } int m; cin >> m; char d[31]; int l[31]; bool a[21][21]; for (int i = 0; i < 21; i++) {for (int j = 0; j < 21; j++) {a[i][j] = 0;}} a[10][10] = 1; for (int i = 0; i < m; i++) {cin >> d[i] >> l[i];} int cont = 0; int nowx = 10; int nowy = 10; while (cont < m) { if (d[cont] == 'N' || d[cont] == 'S') { if (d[cont] == 'N') { for (int i = nowy; i <= l[cont] + nowy; i++) { a[i][nowx] = 1; } nowy += l[cont]; } else { for (int i = nowy; i >= nowy - l[cont]; i--) { a[i][nowx] = 1; } nowy -= l[cont]; } } else { if (d[cont] == 'E') { for (int i = nowx; i <= l[cont] + nowx; i++) { a[nowy][i] = 1; } nowx += l[cont]; } else { for (int i = nowx; i >= nowx - l[cont]; i--) { a[nowy][i] = 1; } nowx -= l[cont]; } } cont++; } //for (int i = 0; i < 21; i++) { for (int j = 0; j < 21; j++) { cout << a[i][j] << " "; if (j == 20)cout << endl; } } for (int i = 0; i < n; i++) { if (a[y[i]][x[i]] != 1) {cout << "No" << endl;break;} if (i == n - 1)cout << "Yes" << endl; } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n,m,q; ll a[505][505]; ll b[505][505]; int main(){ cin >> n >> m >> q; for(ll i=0;i<m;i++){ ll l,r; cin >> l >> r; a[r][l]++; } for(ll i=0;i<=500;i++){ for(ll j=0;j<=500;j++){ b[i][j+1]=b[i][j]+a[i][j]; } } for(ll i=0;i<q;i++){ ll c,d; cin >> c >> d; ll res=0; for(ll j=c;j<=d;j++){ res+=b[j][d+1]-b[j][c]; } cout << res << endl; } }
0
#include<stdio.h> #include<iostream> #include<vector> #include<algorithm> #include<string> #include<string.h> using namespace std; typedef long long LL; typedef vector<int> VI; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i) #define eprintf(s...) fprintf(stderr, s) template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; } template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; } int H, W; char F[111][111]; int A[101][101]; short dp[101][101][101][101]; short box(int l, int u, int r, int d) { return A[d][r] - A[d][l] - A[u][r] + A[u][l]; } int main() { scanf("%d%d", &H, &W); REP (i, H) scanf("%s", F[i]); int si, sj; REP (i, H) REP (j, W) { if (F[i][j] == 'E') { si = i; sj = j; } A[i+1][j+1] = A[i][j+1] + A[i+1][j] - A[i][j]; if (F[i][j] == 'o') A[i+1][j+1] ++; } int ans = 0; REP (l, sj+1) REP (r, W-sj) REP (u, si+1) REP (d, H-si) { short cur = dp[l][r][u][d]; amax(ans, (int)cur); int R, L, D, U; U = max(si-u, d); D = min(si+d+1, H-u); if (sj-1-l >= r && U < D) amax<short>(dp[l+1][r][u][d], cur + box(sj-1-l, U, sj-l, D)); if (sj+1+r < W-l && U < D) amax<short>(dp[l][r+1][u][d], cur + box(sj+1+r, U, sj+2+r, D)); L = max(sj-l, r); R = min(sj+r+1, W-l); if (si-1-u >= d && L < R) amax<short>(dp[l][r][u+1][d], cur + box(L, si-1-u, R, si-u)); if (si+1+d < H-u && L < R) amax<short>(dp[l][r][u][d+1], cur + box(L, si+1+d, R, si+2+d)); } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vec = vector<ll>; using mat = vector<vec>; using pll = pair<ll,ll>; #define INF (1LL << 60) #define MOD 1000000007 #define PI 3.14159265358979323846 #define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i)) #define FORR(i,v) for(auto (i):v) #define ALL(x) (x).begin(), (x).end() #define PR(x) cout << (x) << endl #define PS(x) cout << (x) << " " #define SZ(x) ((ll)(x).size()) #define MAX(a,b) (((a)>(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b)) #define REV(x) reverse(ALL((x))) #define ASC(x) sort(ALL((x))) #define DESC(x) ASC((x)); REV((x)) #define pb push_back #define eb emplace_back int main() { ll N, K; cin >> N >> K; vec X(N); REP(i,0,N) cin >> X[i]; ll p = N; REP(i,0,N) { if(X[i] >= 0) { if(X[i] == 0) { X.erase(X.begin() + i); --K; } p = i; break; } } ll left, right; if(p < K) { left = 0; right = K - 1; } else { left = p - K; right = p - 1; } ll m = INF; if(K == 0) m = 0; else { while(left <= p && right < N) { ll t; if(X[left] < 0 && X[right] < 0) t = -X[left]; else if(X[left] < 0) t = MIN(X[right]-2*X[left],X[right]*2-X[left]); else t = X[right]; m = MIN(m,t); ++left; ++right; } } PR(m); return 0; } /* */
0
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <stack> #include <queue> #include <cctype> #include <complex> #include <vector> #include <set> #include <map> #include <algorithm> #include <functional> #include <cassert> #include <iomanip> using namespace std; #define all(x) begin(x), end(x) #define rall(x) (x).rbegin(), (x).rend() typedef long long ll; typedef complex<int> P; typedef pair<int, int> pii; typedef tuple<int, int, int> tii; const double EPS = 1e-10; const double PI = acos(-1.0); const int n = 151; vector<vector<int>> a(n, vector<int>(n)); void init(){ for(int i=1;i<n;++i) for(int j=i+1;j<n;++j){ a[i][j] = i * i + j * j; } } bool solve(){ int h, w; cin>> h>> w; if(!h && !w) return false; int x = h * h + w * w; pii ans(n, n); for(int i=1;i<n;++i){ for(int j=i+1;j<n;++j){ int y = i*i + j*j; if((i <= h && y == x) || y < x) continue; if(y < ans.first * ans.first + ans.second * ans.second){ int j = (int)sqrt(y - i * i); ans = pii(i, j); } } } cout<< ans.first<< " "<< ans.second<< endl; return true; } int main(){ cout.setf(ios::fixed); cout.precision(10); init(); while(solve()); return 0; }
#include <iostream> using namespace std; class rect { public: int h,w; // 対角線の2乗 int diagonal() { return h * h + w * w; } }; // x > y なら1を返す int rect_cmp(rect x, rect y) { if(x.diagonal() > y.diagonal()) return 1; else if(x.diagonal() == y.diagonal()) { if(x.h > y.h) return 1; else return 0; } else return 0; } int main() { rect r; while(cin >> r.h >> r.w && r.h && r.w) { rect ans, cmp; ans.w = 150; ans.h = 150; for(cmp.h = 1; cmp.h < 150; ++cmp.h) { for(cmp.w = cmp.h + 1; cmp.w < 150; ++cmp.w) { if(rect_cmp(cmp, r) && rect_cmp(ans, cmp)) ans = cmp; } } cout << ans.h << ' ' << ans.w << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main(){ int n; string s; cin >> n >> s; vector<int> r(n); vector<int> g(n); vector<int> b(n); for(int i=0;i<n;i++){ if(i){ r[i]=r[i-1]; g[i]=g[i-1]; b[i]=b[i-1]; } if(s[i]=='R') r[i]++; else if(s[i]=='G') g[i]++; else b[i]++; } long long ans=0; for(int i=0;i<n;i++){ for(int j=i+1;j<n-1;j++){ if(s[i]!=s[j]){ if(s[i]=='R'){ if(s[j]=='G'){ ans+=b[n-1]-b[j]; int l=j*2-i; if(l<n){ if(s[l]=='B') ans--; } } else{ ans+=g[n-1]-g[j]; int l=j*2-i; if(l<n){ if(s[l]=='G') ans--; } } } else if(s[i]=='G'){ if(s[j]=='B'){ ans+=r[n-1]-r[j]; int l=j*2-i; if(l<n){ if(s[l]=='R') ans--; } } if(s[j]=='R'){ ans+=b[n-1]-b[j]; int l=j*2-i; if(l<n){ if(s[l]=='B') ans--; } } } else{//B if(s[j]=='G'){ ans+=r[n-1]-r[j]; int l=j*2-i; if(l<n){ if(s[l]=='R') ans--; } } if(s[j]=='R'){ ans+=g[n-1]-g[j]; int l=j*2-i; if(l<n){ if(s[l]=='G') ans--; } } } } } } cout << ans << endl; }
#include<iostream> #include<cstdio> #include <stdio.h> #include<algorithm> #include<cstring> #include<cmath> #include<cstdlib> #include<queue> #include<map> #include<vector> #include <set> #define ll long long #define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #define inf 0x3f3f3f3f #define pi 3.1415926535898 using namespace std; char a[5000]; ll x,y,z; int main() { int n,k; cin>>n; for(int i=0;i<n;i++) { cin>>a[i]; if(a[i]=='R') { x++; } else if(a[i]=='G') { y++; } else { z++; } } ll ans=x*y*z; for(int i=0;i*2<n;i++) { for(int j=0;j+2*i<n;j++) { if(a[j]!=a[j+i]&&a[j+i]!=a[j+2*i]&&a[j]!=a[j+2*i]) { ans--; } } } cout<<ans<<endl; return 0; }
1
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define reps(i,n) for(int i=1;i<(int)(n);i++) typedef long long ll; using namespace std; ll gcd(ll a, ll b) { //最大公約数 if (b==0) return a; else return gcd(b, a%b); } ll lcm(ll a, ll b) { //最小公倍数 return a * b / gcd(a, b); } ll digit_sum(ll a){ //10進桁和 ll ans=0; while(a>0){ ans+=a%10; a/=10; } return ans; } int main() { string s; cin>>s; s.erase(0,4); cout<<"2018"+s<<endl; return 0; }
#include <stdio.h> int main() { char s[12]; scanf("%s", &s); s[3]++; printf("%s\n", s); return 0; }
1
#include <algorithm> #include <iostream> #include <set> #include <vector> using namespace std; int main() { int n, q; cin >> n >> q; vector<int> s(n), t(n), x(n); for (int i = 0; i < n; i++) { cin >> s[i] >> t[i] >> x[i]; } vector<pair<int, int>> sx(n), tx(n); for (int i = 0; i < n; i++) { sx[i] = make_pair(s[i] - x[i], x[i]); tx[i] = make_pair(t[i] - x[i], x[i]); } sort(sx.begin(), sx.end()); sort(tx.begin(), tx.end()); multiset<int> u; vector<pair<int, int>>::iterator isx = sx.begin(), itx = tx.begin(); for (int i = 0; i < q; i++) { int d; cin >> d; for (; isx != sx.end() && isx->first <= d; isx++) { u.insert(isx->second); } for (; itx != tx.end() && itx->first <= d; itx++) { u.erase(u.lower_bound(itx->second)); } cout << (u.size() == 0 ? -1 : *u.begin()) << endl; } }
#include <iostream> #include <algorithm> #include <vector> using namespace std; struct edge {int u, v, cost; }; bool comp(const edge& e1, const edge& e2) { return e1.cost < e2.cost; } class UnionFind { public: int g_num; vector<int> rank, par; UnionFind() {} UnionFind(int size) { rank.resize(size, 0); par.resize(size, 0); for (int i = 0; i < size; i++) { par[i] = i; rank[i] = 0; } g_num = size; } bool same(int x, int y) { return find(x) == find(y); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; g_num--; if (rank[x] > rank[y]) { par[y] = x; } else { par[x] = y; if (rank[x] == rank[y]) rank[y]++; } } int find(int x) { if (x == par[x]) return x; return par[x] = find(par[x]); } int group_num() { return g_num; } }; int main(void) { int V, E; cin >> V >> E; UnionFind uf(V); vector<edge> es; for (int i = 0; i < E; i++) { int u, v, cost; cin >> u >> v >> cost; es.push_back(edge {u, v, cost}); } sort(es.begin(), es.end(), comp); int res = 0; for (auto e: es) { if (!uf.same(e.u, e.v)) { uf.unite(e.u, e.v); res += e.cost; } } cout << res << endl; return 0; }
0
#include <stdio.h> #include <vector> using namespace std; int main(void){ while(true){ int n, m, t1, t2; scanf("%d\n%d", &n, &m); if(n == 0 && m == 0) return 0; vector< vector<int> > G; for(int i = 0;i < n;++i){ vector<int> V; G.push_back(V); } for(int i = 0;i < m;++i){ scanf("%d %d", &t1, &t2); G[t1-1].push_back(t2-1); G[t2-1].push_back(t1-1); } vector<int> guests(n, 0); for(int i = 0;i < G[0].size();++i){ guests[G[0][i]] = 1; for(int j = 0;j < G[G[0][i]].size();++j){ guests[G[G[0][i]][j]] = 1; } } int c = 0; for(int i = 1;i < n;++i){ c += guests[i]; } printf("%d\n", c); } }
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; int main(){ int n,m,ans=0; cin >> n >> m; while(n!=0||m!=0){ ans = 0; n++; vector<int>a(m,0),b(m,0),hito(n,0),one(n,0); rep(i,m){ cin>>a[i]>>b[i]; if(a[i]==1){ hito[b[i]]++; one[b[i]]++; } if(b[i]==1){ hito[a[i]]++; one[a[i]]++; } } rep(i,n){ if(i==0||i==1)continue; rep(j,m){ if(one[i]!=0){ if(i==a[j])hito[b[j]]++; if(i==b[j])hito[a[j]]++; } } } rep(i,n){ if(i==0||i==1)continue; if(hito[i]!=0){ ans++; } } cout<<ans<<endl; cin >> n >> m; } return (0); }
1
#include<bits/stdc++.h> using namespace std; #define fast() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long int #define test() ll t; cin>>t; while(t--) #define lp0(i,begin,end) for(ll i=begin;i<end;i++) #define lp1(i,begin,end) for(ll i=begin;i<=end;i++) #define rlp(i,begin,end) for(ll i=end;i>=begin;i--) #define prec(n) fixed<<setprecision(n) #define initial(a,i) memset(a,i,sizeof(a)) #define pb push_back #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 #define F first #define S second #define all(a) (a).begin(),(a).end() #define BPC(x) __builtin_popcountll(x) #define gcd(a,b) __gcd(a,b) ll gcd(ll a,ll b) {if (a==0) return b;return gcd(b%a,a);} ll power(ll x,ll n) { ll result = 1; while (n) { if (n & 1) result = result * x; n = n / 2; x = x * x; } return result; } // Solution Function void solution(ll compte) { // cout<<compte<<"\n"; ll n,d; cin>>n; ll arr[n]; for(ll i=0;i<n;i++) { cin>>arr[i]; } sort(arr,arr+n); ll cnt =0; for(ll i=0;i<n;i++) { for(ll j=i+1;j<n;j++) { for(ll k=j+1;k<n;k++) { if(arr[i]!=arr[j]&&arr[j]!=arr[k]&&arr[k]!=arr[i]&&arr[i]+arr[j]>arr[k]&&arr[j]+arr[k]>arr[i]&&arr[k]+arr[i]>arr[j]) cnt++; } } } cout<<cnt<<'\n'; } // Driver Function int main() { ll compte = 1; // test() //{ solution(compte); compte++; //} return 0; }
#include <iostream> #include <cstdio> using namespace std; int partition(int A[],int p,int r) { int x = A[r]; int i = p - 1; for (int j = p; j < r; j++) { if (A[j] <= x) { i++; int tmp = A[i]; A[i] = A[j]; A[j] = tmp; } } int tmp = A[i + 1]; A[i + 1] = A[r]; A[r] = tmp; return i + 1; } int main(void) { int A[100000]; int n; int q; cin >> n; for (int i = 0; i < n; i++) { cin >> A[i]; } q = partition(A, 0, n - 1); for (int i = 0; i < n; i++) { if (i > 0) { putchar(' '); } if (i == q) { cout << '[' << A[i] << ']'; } else { cout << A[i]; } } putchar('\n'); return 0; }
0
#include <iostream> #include <vector> #include <algorithm> #include <math.h> #include <map> using namespace std; typedef long long ll; int ord[100010], low[100010]; int k; vector<int> G[100010]; vector<pair<int, int>> bridge; vector<int> articulation; bool visit[100010] = {}; void dfs(int v, int p, int &k) { visit[v] = 1; ord[v] = k++; low[v] = ord[v]; bool isArticulation = 0; int ct = 0; for (int i = 0; i < G[v].size(); i++) { if (!visit[G[v][i]]) { ct++; dfs(G[v][i], v, k); low[v] = min(low[v], low[G[v][i]]); if (~p && ord[v] <= low[G[v][i]]) isArticulation = 1; if (ord[v] < low[G[v][i]]) bridge.emplace_back(min(v, G[v][i]), max(v, G[v][i])); } else if (G[v][i] != p) { low[v] = min(low[v], ord[G[v][i]]); } } if (p == -1 && ct > 1) isArticulation = 1; if (isArticulation) articulation.push_back(v); } int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int s, t; cin >> s >> t; G[s].push_back(t); G[t].push_back(s); } int k = 0; for (int i = 0; i < n; i++){ if (!visit[i]) dfs(i, -1, k); } sort(bridge.begin(), bridge.end()); sort(articulation.begin(), articulation.end()); for (int i = 0; i < bridge.size(); i++) { //cout << bridge[i].first << " " << bridge[i].second << endl; } for (int i = 0; i < articulation.size(); i++) { cout << articulation[i] << endl; } }
// clang-format off #include <bits/stdc++.h> using namespace std; #define int long long #define main signed main() #define loop(i, a, n) for (int i = (a); i < (n); i++) #define rep(i, n) loop(i, 0, n) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define prec(n) fixed << setprecision(n) constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979; template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; } template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; } bool odd(const int &n) { return n & 1; } bool even(const int &n) { return ~n & 1; } template<typename T> int len(const T &v) { return v.size(); } template<typename T = int> T in() { T x; cin >> x; return x; } template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; } template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; } template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; } template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; } template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; } template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); } template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); } // clang-format on using Weight = int; struct Edge { int src, dst; Weight weight; Edge(const int &s = 0, const int &d = 0, const Weight &w = 0) : src(s), dst(d), weight(w) {} }; using Edges = vector<Edge>; using Array = vector<Weight>; using Matrix = vector<Array>; class Graph { vector<Edges> g; public: Graph(const int &size = 0) : g(size) {} size_t size() const { return g.size(); } const Edges &operator[](const int &i) const { return g[i]; } Edges &operator[](const int &i) { return g[i]; } void addArc(const int &src, const int &dst, const Weight &w = 1) { g[src].emplace_back(src, dst, w); } void addEdge(const int &node1, const int &node2, const Weight &w = 1) { addArc(node1, node2, w); addArc(node2, node1, w); } auto begin() { return g.begin(); } auto end() { return g.end(); } }; template<typename T> vector<T> nub(const vector<T> &xs) { set<T> s(xs.begin(), xs.end()); vector<T> ys(s.begin(), s.end()); return ys; } vector<int> articulationPoints(const Graph &g) { int n = g.size(), id = 0; vector<int> ord(n), low(n), arts; function<void(int)> dfs = [&](int v) { low[v] = ord[v] = ++id; for (auto &e : g[v]) { int w = e.dst; if (ord[w] == 0) { dfs(w); cmin(low[v], low[w]); if (ord[v] == 1 && ord[w] != 2) arts.emplace_back(v); if (ord[v] != 1 && ord[v] <= low[w]) arts.emplace_back(v); } else { cmin(low[v], ord[w]); } } }; rep(i, n) if (ord[i] == 0) id = 0, dfs(i); return arts; } main { int n, m; cin >> n >> m; Graph g(n); rep(i, m) { int s, t; cin >> s >> t; g.addEdge(s, t); } vector<int> arts = articulationPoints(g); arts = nub(arts); for (auto &v : arts) cout << v << endl; }
1
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <functional> #include <ctime> #include <cmath> #include <limits> #include <numeric> #include <type_traits> #include <iomanip> #include <float.h> #include <math.h> using namespace std; using ll = long long; unsigned euclidean_gcd(unsigned a, unsigned b) { if (a < b) return euclidean_gcd(b, a); unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } 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; } class UnionFind { public: vector <ll> par; vector <ll> siz; UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } ll root(ll x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } int main() { ll x, y; cin >> x >> y; ll ans = 12345634537849; if (x <= y)ans = min(ans, y - x); if (-x <= y)ans = min(ans, y + x +1); if (x <= -y)ans = min(ans, - y - x+1); if (-x <= -y)ans = min(ans, - y + x + 2); cout << ans << endl; }
#include<stdio.h> int main() { printf("100 100\n"); int m,n; scanf("%d%d",&m,&n); /* .*.*.* ****** *.*.*. ...... */ /*for(int i=0;i<50;i++) { for(int j=0;j<100;j++) { if(m<n&&(m-n)%2==0) { m--; printf("."); } else printf("#"); } printf("\n"); }*/ for(int i=0;i<50;i++) { for(int j=0;j<100;j++) { if(m!=1&&i%2==0&&j%2==0) { m--; printf("."); } else printf("#"); } printf("\n"); } /* for(int i=50;i<100;i++) { for(int j=0;j<100;j++) { if(m>n&&(m-n)%2==0) { n--; printf("#"); } else printf("."); } printf("\n"); }*/ for(int i=50;i<100;i++) { for(int j=0;j<100;j++) { if(n!=1&&i%2!=0&&j%2!=0) { printf("#"); n--; } else printf("."); } printf("\n"); } }
0
#include<stdio.h> #include<iostream> #include<string> #include<algorithm> using namespace std; int main(){ int N,Q; while(1){ cin>>N>>Q;if(N==0&&Q==0)break; int n; int d[10002]={}; for(int i=0;i<N;i++) {cin>>n; for(int j=0;j<n;j++) {int x; cin>>x;d[x]++;} } int c=0;int p=0; for(int i=0;i<10001;i++) if(d[i]>=Q&&d[i]>c){c=d[i];p=i;} cout<<p<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, q; const long long inf = (1ll << 31) - 1; const int max_n = (1 << 17); long long seg[max_n * 2 - 1]; long long lazy[max_n * 2 - 1]; void init() { int _n = n; n = 1; while (n < _n) n *= 2; fill(seg, seg + 2 * n - 1, inf); fill(lazy, lazy + 2 * n - 1, inf + 1); } void update(int a, int b, int x, int k = 0, int l = 0, int r = n) { if (a <= l && r <= b){ lazy[k] = x; return; } if (r <= a || b <= l){ return; } if (lazy[k] != inf + 1) { lazy[k * 2 + 1] = lazy[k * 2 + 2] = lazy[k]; } lazy[k] = inf + 1; update(a, b, x, k * 2 + 1, l, (l + r) / 2); update(a, b, x, k * 2 + 2, (l + r) / 2, r); } void find(int a, int b, int k = 0, int l = 0, int r = n) { if (a <= l && r <= b){ if (lazy[k] != inf + 1){ seg[k] = lazy[k]; } lazy[k] = inf + 1; return; } else if (r <= a || b <= l){ return; } else { if (lazy[k] != inf + 1){ lazy[k * 2 + 1] = lazy[k * 2 + 2] = lazy[k]; lazy[k] = inf + 1; } find(a, b, k * 2 + 1, l, (l + r) / 2); find(a, b, k * 2 + 2, (l + r) / 2, r); } } int main() { cin >> n >> q; init(); for (int i = 0; i < q; i++){ int f; cin >> f; if (f == 0){ int s, t, x; cin >> s >> t >> x; update(s, t + 1, x); /* for (int i = 0; i < n * 2 - 1; i++){ cout << lazy[i] << " "; } puts(""); */ } else { int i; cin >> i; find(i, i + 1); /* for (int i = 0; i < n * 2 - 1; i++){ cout << seg[i] << " "; } puts(""); */ cout << seg[i + n - 1] << endl; } } }
0
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; using P = pair<ll, ll>; const ll INF = 1LL << 62; const double PI = acos(-1); const double eps = 1e-10; int main() { vector<string> dow = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; string s; cin >> s; cout << 7 - distance(dow.begin(), find(dow.begin(), dow.end(), s)) << endl; return 0; }
#include <iostream> #include <string> int main() { std::string str; std::cin >> str; if (str == "MON") { std::cout << 6; } if (str == "TUE") { std::cout << 5; } if (str == "WED") { std::cout << 4; } if (str == "THU") { std::cout << 3; } if (str == "FRI") { std::cout << 2; } if (str == "SAT") { std::cout << 1; } if (str == "SUN") { std::cout << 7; } }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18; const int inf = 1e9; #define rep(i, a, b) for (int i = a; i < b; i++) #define per(i, b, a) for (int i = a - 1; i >= b; i--) using Graph = vector<vector<int>>; using pint = pair<int, int>; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; int main() { // 解説AC int n; cin >> n; pint red[n], blue[n]; rep (i, 0, n) cin >> red[i].first >> red[i].second; rep (i, 0, n) cin >> blue[i].first >> blue[i].second; sort (red, red + n); sort (blue, blue + n); bool chk[n] = {}; int ans = 0; // まず、redの点を固定する per (i, 0, n) { int res = -1; int now = inf; per (j, 0, n) { if (chk[j]) continue; if (red[i].first < blue[j].first && red[i].second < blue[j].second) { // 条件に当てはまる中でblueのyが最も小さいのを選ぶ if (now > blue[j].second) { res = j; now = blue[j].second; } } } if (res != -1) { chk[res] = 1; ans++; } } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const static ll INF = 1e15; #define rep(i, n) for (int i = 0; i < (int)(n); i++) // __uint128_t const ll MOD = 1e9+7; long double dist(ll x1, ll y1, ll x2, ll y2){ return sqrt((double)pow(x2-x1, 2) + (double)pow(y2-y1, 2)); } int main(){ ll N; cin >> N; vector<ll> X(N), Y(N); for(int i = 0; i < N; i++) cin >> X[i] >> Y[i]; long double ans = 0.0; for(int i = 0; i < N-1; i++){ for(int j = i+1; j < N; j++){ ans += dist(X[i], Y[i], X[j], Y[j]) * 2.0; } } cout << setprecision(20) << ans / (long double) N << endl;; }
0
#include <iostream> #include <vector> using namespace std; char news[4]={'N','E','W','S'}; int to_x[4]={0, 1, -1, 0}; int to_y[4]={1, 0, 0, -1}; int main(){ while(1){ int gems; cin >> gems; if(gems==0) break; vector<vector<bool> > map(21,vector<bool>(21,false)); int x,y; for(int i=0; i<gems; i++){ cin >> x >> y; map[y][x] = true; } x = 10; y = 10; map[y][x] = false; int command, move; char direction; cin >> command; for(int i=0; i<command; i++){ cin >> direction >> move; for(int j=0; j<4; j++){ if(direction == news[j]){ for(int k=0; k<move; k++){ x+=to_x[j]; y+=to_y[j]; map[y][x] = false; } } } } bool check = false; for(int i=0; i<=20; i++){ for(int j=0; j<=20; j++){ if(map[i][j] == true) check = true; } } if(check) cout << "No" << endl; else cout << "Yes" << endl; } return 0; }
#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; }
1
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);++i) #define repone(i,n) for(int i=1;i<(int)(n);++i) #define repo(i,o,n) for(int i=o;i<(int)(n);++i) #define Rep(j,n) for(int j=0;j<(int)(n);++j) #define Repo(j,o,n) for(int j=o;j<(int)(n);++j) #define Repone(j,n) for(int j=1;j<(int)(n);++j) #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define int long long #define pb(a) push_back(a) #define eraser(v,i) (v).erase(v.begin()+(i)) #define pbpair(a,b) push_back(make_pair(a,b)) #define MOD 1000000007 #define INF 9223372036854775807 #define pairint pair<int,int> signed main(){ int x=0,y=0,z=0; string s; std::cin >> s>>x; rep(i,s.size()){ if(i*x>s.size()-1)return 0; std::cout << s[i*x]; } }
#include <bits/stdc++.h> using namespace std; int main(){ int n,k; cin >> n >> k; int mask = 0; for(int i = 0; i < k; i ++) { int p; cin >> p; mask |= (1 << p); } for(int i = n; ; i ++) { int t = i, m = 0; while(t) m |= (1 << (t % 10)), t /= 10; if((mask & m) == 0) { cout << i << endl; break; } } }
0
#include<iostream> #include <bits/stdc++.h> #define ll long long #define ld long double #define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; int n, q, inf=2e9, cnt; vector<int> par ; vector<pair<int,pair<int,int> > > v; map<int,int> id ; int tree[3000006]; void update(int node, int s, int e, int l, int r, int val) { if(s>r||e<l) return ; if(s>=l && e<=r) { tree[node]=min(tree[node],val); return ; } int m=(s+e)/2; update(2*node,s,m,l,r,val); update(2*node+1,m+1,e,l,r,val); } int solve(int node, int s,int e, int pos) { if(s==e) return tree[node]; int m=(s+e)/2; tree[2*node]=min(tree[node],tree[2*node]); tree[2*node+1]=min(tree[node],tree[2*node+1]); return pos<=m ? solve(2*node,s,m,pos) : solve(2*node+1,m+1,e,pos); } int main() { IO cin>>n>>q; for(int i=1; i<=3e6; i++) tree[i]=inf; for(int i=1; i<=n; i++) { int s, t, x; cin>>s>>t>>x; v.push_back({x,{s-x,t-x-1}}); id[s-x]++; id[t-x-1]++; } for(int i=1; i<=q; i++) { int d; cin>>d; id[d]++; par.push_back(d); } for(auto i : id) id[i.first]=++cnt; for(int i=0; i<n; i++) { int l=id[v[i].second.first], r=id[v[i].second.second]; update(1,1,cnt,l,r,v[i].first); } for(int i=0; i<q; i++) { int ans=solve(1,1,cnt,id[par[i]]); if(ans==inf) ans=-1; cout<<ans<<"\n"; } }
#include <bits/stdc++.h> // #undef DEBUG // Uncomment this line to forcefully disable debug print. #if DEBUG template <typename T> void debug(T value) { std::cerr << value; } template <typename T, typename... Ts> void debug(T value, Ts... args) { std::cerr << value << ", "; debug(args...); } #define dbg(...) \ do { \ cerr << #__VA_ARGS__ << ": "; \ debug(__VA_ARGS__); \ cerr << " (L" << __LINE__ << ")" << endl; \ } while (0) #else #define dbg(...) #endif void read_from_cin() {} template <typename T, typename... Ts> void read_from_cin(T& value, Ts&... args) { std::cin >> value; read_from_cin(args...); } #define in(type, ...) \ type __VA_ARGS__; \ read_from_cin(__VA_ARGS__); template <typename T> void write_to_cout(const T& value) { std::cout << value << std::endl; } template <typename T, typename... Ts> void write_to_cout(const T& value, const Ts&... args) { std::cout << value << ' '; write_to_cout(args...); } #define out(...) write_to_cout(__VA_ARGS__); #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using ll = long long; using namespace std; struct Construction { ll s, t, x; bool operator<(const Construction& c) const { return s < c.s; } }; struct Person { ll d, index; bool operator<(const Person& p) const { return d < p.d; } }; int main() { in(ll, n, q); vector<Construction> c(n); rep(i, n) { cin >> c[i].s >> c[i].t >> c[i].x; c[i].s -= c[i].x; c[i].t -= c[i].x; } sort(all(c)); vector<Person> p(q); rep(i, q) { cin >> p[i].d; p[i].index = i; } sort(all(p)); multiset<ll> active; priority_queue<pair<ll, ll>> que; auto cit = c.begin(); vector<ll> ans(q); for (const auto& pi : p) { dbg(pi.d, pi.index); while (cit != c.end() && cit->s <= pi.d) { dbg(cit->s, cit->t, cit->x); que.push({-cit->t, cit->x}); active.insert(cit->x); ++cit; } while (!que.empty() && -que.top().first <= pi.d) { dbg(-que.top().first, que.top().second); active.erase(active.find(que.top().second)); que.pop(); } if (active.empty()) { ans[pi.index] = -1; } else { ans[pi.index] = *active.begin(); } } rep(i, q) out(ans[i]); }
1
#include <bits/stdc++.h> using namespace std; #define pi 2*asin(1.0) //template functions ///////////////////////// long Comb(long N,long M){// nCm long ans=1; for(long i=N;i>N-M;i--){ ans=ans*i; } for(long i=M;i>0;i--){ ans=ans/i; } return ans; } long Perm(long N,long M){// nPm long ans=1; for(long i=N;i>N-M;i--){ ans=ans*i; } return ans; } long GCM(long A,long B){ long W,r; if(A<B){ W=B; B=A; A=W; } while(A%B!=0){ r=A%B; A=B; B=r; } return B; } long LCM(long A,long B){ return (A*B)/GCM(A,B); } long upDiv(long a,long b){ return (a+b-1)/b; } long fact(long N){ if(N==0){ return 1; }else{ long ans=1; for(long i=1;i<N+1;i++){ ans=ans*i; } return ans; } } ///////////////////////// //Answer int main() { long double N; long double dis,sum=0.0,answer; cin>>N; vector<long double> x(N); vector<long double> y(N); for(long i=0;i<N;i++){ cin>>x.at(i); cin>>y.at(i); } for(int i=0;i<N;i++){ for(int j=i+1;j<N;j++){ double dx=x.at(i)-x.at(j); double dy=y.at(i)-y.at(j); sum+=pow((dx*dx+dy*dy),0.5); } } answer=sum*2.0/N; cout<< fixed << setprecision(10) << answer<<endl; }
#include "bits/stdc++.h" #include<unordered_map> #include<unordered_set> #pragma warning(disable:4996) using namespace std; using ld = long double; template<class T> using Table = vector<vector<T>>; const ld eps=1e-9; //// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer" int main() { int sum = 0; vector<int>as(4), bs(2); for (int i = 0; i < 4; ++i) { cin >> as[i]; sum += as[i]; } cin >> bs[0] >> bs[1]; sum += bs[0] + bs[1]; sum -= *min_element(as.begin(), as.end()) + *min_element(bs.begin(), bs.end()); cout << sum << endl; return 0; }
0
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < (b); i++) #define rrep(i, a, b) for (int i = a; i >= (b); i--) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; using P = pair<int, int>; 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; } void hr() { cerr << "--------------" << endl; } const int INF = 1001001001; const int MOD = 1000000007; int dp[1000005][2]; int main() { cin.tie(0); ios_base::sync_with_stdio(0); string s; cin >> s; reverse(s.begin(), s.end()); s += '0'; int n = s.size(); rep(i, 0, n + 1) rep(j, 0, 2) dp[i][j] = INF; dp[0][0] = 0; rep(i, 0, n) rep(j, 0, 2) { int x = s[i] - '0'; x += j; rep(a, 0, 10) { int ni = i + 1, nj = 0; int b = a - x; if (b < 0) { nj = 1; b += 10; } dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a + b); } } int ans = dp[n][0]; cout << ans << endl; return 0; }
#include<iostream> #include<cstdio> #include<algorithm> #include<string> #include<cstring> using namespace std; int main(){ char a; int j = 0,o = 0,i = 0; int jlv = 0,olv = 0,ilv = 0; int mx = 0; while(scanf("%c",&a) != EOF){ if(a == 10)break; if(a == 'J'){ if(o != 0 || i != 0 || o != 0 && i != 0){ j = o = i = jlv = olv = ilv = 0; } if(j == 0){ j++; } else j++; //printf("j j = %d o = %d i = %d jlv = %d olv = %d ilv = %d\n",j,o,i,jlv,olv,ilv); } if(a == 'O'){ if(j != 0){ jlv = j; j = 0; } if(i != 0){ i = ilv = 0; jlv = 0; } if(o == 0) o++,olv = o; else o++,olv = o; //printf("o j = %d o = %d i = %d jlv = %d olv = %d ilv = %d\n",j,o,i,jlv,olv,ilv); } if(a == 'I'){ if(olv != 0){ j = o = 0; } if(olv == 0)j = 0; if(jlv != 0 && olv != 0){ j = o = 0; i++; ilv = i; } if(jlv >= olv && ilv >= olv)mx = max(mx,olv); //printf("i j = %d o = %d i = %d jlv = %d olv = %d ilv = %d\n",j,o,i,jlv,olv,ilv); } } cout << mx << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; #define REP(i, n, m) for(ll i=n; i<(ll)m; ++i) #define IREP(i, n, m) for(ll i=n-1; i>=m; --i) #define rep(i, n) REP(i, 0, n) #define irep(i, n) IREP(i, n, 0) #define all(v) v.begin(), v.end() #define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl; #define vvprint(vv) for(auto v:vv)vprint(v); int main(){ cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20); ll H, W; cin >> H >> W; vll A(H), B(H); rep(i, H) cin >> A[i] >> B[i]; map<int, int> m; rep(i, W) m[i] = 0; multiset<int> ms; rep(i, W) ms.insert(0); vll ans(H, 0); rep(i, H){ int a = A[i]-1; int b = B[i]-1; auto lb = m.lower_bound(a); auto ub = m.upper_bound(b); if(lb!=m.end() && lb!=ub){ --ub; auto it = lb; int k = ub->first; int v = ub->second; while(it!=m.end() && it->first!=k){ int v = it->second; ms.erase(ms.find(v)); it = m.erase(it); } if(b<W-1 && m.count(b+1)==0){ m[b+1] = v+b-k+1; ms.insert(v+b-k+1); } m.erase(k); ms.erase(ms.find(v)); } if(ms.empty()) ans[i] = -1; else ans[i] = *ms.begin() + i + 1; } rep(i, H) cout << ans[i] << endl; }
#include<bits/stdc++.h> #define rep(i, n) for (int i=0;i<(n);i++) using namespace std; typedef long long ll; int INF = 1e9; struct Edge{ /*辺の情報を入れる構造体で行き先とコストを表している*/ int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} }; vector<Edge> g[100005]; vector<ll> dist(100005); void dfs(int u, int p){ for(auto v : g[u]){ if(v.to == p) continue; dist[v.to] = dist[u] + v.cost; dfs(v.to, u); } } int main(void){ int n; cin>>n; rep(i, n-1){ int a, b; ll c; cin>>a>>b>>c; --a;--b; g[a].push_back(Edge(b, c)); g[b].push_back(Edge(a, c)); } int q, k; cin>>q>>k; --k; vector<pair<int, int> > v(q); rep(i, q){ int x, y; cin>>x>>y; --x;--y; v[i] = make_pair(x, y); } rep(i, n) dist[i] = INF; dist[k] = 0; dfs(k, -1); rep(i, q){ cout<<dist[v[i].first] + dist[v[i].second]<<endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int n,k; const long long mod=1e9+7; long long dp[3010][3010],jie[4000010],ni[4000010]; inline long long ksm(long long x,long long y) { long long res=1; while(y) { if(y&1) res=res*x%mod; x=x*x%mod; y>>=1; } return res; } int main() { scanf("%d%d",&n,&k); if(k==1) { printf("1\n"); return 0; } jie[0]=1; for(int i=1;i<=n*k;++i) jie[i]=jie[i-1]*i%mod; ni[n*k]=ksm(jie[n*k],mod-2); for(int i=n*k-1;i>=0;--i) ni[i]=ni[i+1]*(i+1)%mod; for(int i=1;i<=n;++i) dp[i][0]=1; for(int i=1;i<=n;++i) { for(int j=1;j<=i;++j) { int x=n*k-i-(j-1)*(k-1)-1; dp[i][j]=(dp[i-1][j]+dp[i][j-1]*(n-j+1)%mod*jie[x]%mod*ni[k-2]%mod*ni[x-k+2]%mod)%mod; } } printf("%lld\n",dp[n][n]); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int h, w; cin >> h >> w; vector<vector<vector<int>>>grid(h + 2, vector<vector<int>>(w + 2, vector<int>(2, 0))); vector<vector<int>>blacks(0, vector<int>(2)); for (int i = 1; i < h + 1; i++) { for (int j = 1; j < w + 1; j++) { char s; cin >> s; if (s == '.')grid.at(i).at(j).at(0) = 1; else { grid.at(i).at(j).at(0) = 2; blacks.push_back({ i,j }); } grid.at(i).at(j).at(1) = -1; } } int ct = 1; vector<vector<int>>bw(0, vector<int>(2,0)); int btmp = 0; int wtmp = 0; for (int i = 0; i < blacks.size(); i++) { int x = blacks.at(i).at(0); int y = blacks.at(i).at(1); if (grid.at(x).at(y).at(1) != -1)continue; queue<pair<int, int>>sq; sq.push({ x,y }); while (sq.size() > 0) { int xq = sq.front().first; int yq = sq.front().second; grid.at(xq).at(yq).at(1) = ct; int cl = grid.at(xq).at(yq).at(0); if (cl == 1) { cl++; wtmp++; } else { cl--; btmp++; } vector<int>xqa = { xq,xq,xq - 1,xq + 1 }; vector<int>yqa = { yq - 1,yq + 1,yq,yq }; for (int i = 0; i < 4; i++) { if (grid.at(xqa.at(i)).at(yqa.at(i)).at(0) == cl&& grid.at(xqa.at(i)).at(yqa.at(i)).at(1)== -1) { grid.at(xqa.at(i)).at(yqa.at(i)).at(1) = ct; sq.push({ xqa.at(i),yqa.at(i) }); } } sq.pop(); } bw.push_back({ btmp, wtmp }); btmp = 0; wtmp = 0; ct++; } ll ans = 0; for (int i = 0; i < bw.size(); i++)ans += (ll)bw.at(i).at(0) * bw.at(i).at(1); cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; void solve() { int k; string s; cin >> k >> s; cout << ((s.size() <= k) ? s : (s.substr(0, k) + "...")) << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); solve(); }
#include<bits/stdc++.h> using namespace std; int main() { string ch="..."; int limit; while(cin>>limit) { string str; cin>>str; int size=str.size(); if(size==limit || size<limit) { cout<<str<<'\n'; } else { string temp; for(int i=0;i<limit;i++) { temp+=str[i]; } temp+=ch; cout<<temp<<'\n'; } } }
1
/* * atcoder/abc092_2nd/c.cpp */ // C++ 14 #include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <cstring> // memset #include <cassert> using namespace std; #define ll long long #define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++) template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; } template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; } int N; vector<int> J; ll acc[100100] = {0}; void solve() { cin >> N; J.push_back(0); int j; loop(n,0,N) { cin >> j; J.push_back(j); } J.push_back(0); N+=2; loop(n,1,N) { acc[n] = acc[n-1] + abs(J[n]-J[n-1]); } // n // 0 3 5 -1 0 loop(n,1,N-1) { cout << acc[n-1] + abs(J[n-1]-J[n+1]) + (acc[N-1]-acc[n+1]) << endl; } } int main() { // cout.precision(15); cout << fixed; solve(); return 0; }
#include <bits/stdc++.h> #define REP(i, n) for(long long i=0; i<n; i++) #define REPR(i, n) for(long long i=n-1; i>=0; i--) #define FOR(i, m, n) for(long long i=m; i<=n; i++) #define FORR(i, m, n) for(long long i=m; i>=n; i--) #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define VSORTR(v) sort(v.rbegin(), v.rend()); #define ALL(v) (v).begin(),(v).end() #define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); using namespace std; using ll = long long; using ull = unsigned long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<ll, ll>; const ll mod = 1e9+7; const ll inf = 1e15; ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;} char a[55][55]; int main(){FIN ll n;cin>>n; vll a(n); REP(i,n) cin>>a[i]; ll dis=0; REP(i,n){ if(i==0) dis += abs(a[0]); else dis += abs(a[i]-a[i-1]); } dis += abs(a[n-1]); REP(i,n){ ll dis2=dis; if (i==0) { dis2 -= abs(a[0]); dis2 -= abs(a[1]-a[0]); dis2 += abs(a[1]); } else if (i==n-1){ dis2 -= abs(a[n-1]); dis2 -= abs(a[n-2]-a[n-1]); dis2 += abs(a[n-2]); } else { dis2 -= abs(a[i-1]-a[i]); dis2 -= abs(a[i]-a[i+1]); dis2 += abs(a[i-1]-a[i+1]); } cout<<dis2<<endl; } return 0; }
1
#include <iostream> #include <vector> using namespace std; bool isW(char c){ return c=='W'; } bool isX(char c){ return c=='x'; } int main(){//D問題 int n; string s; cin >> n >> s; vector<char> t(n); char assum[4][2] = {{'S', 'S'}, {'S', 'W'}, {'W', 'S'}, {'W', 'W'}}; for(int i=0;i<4;++i){ t[0] = assum[i][0]; t[1] = assum[i][1]; for(int j=1;j<n-1;++j){ t[j+1] = isW(t[j-1])^isX(s[j])^isW(t[j]) ? 'W' : 'S'; } if(!(isW(t[n-2])^isX(s[n-1])^isW(t[n-1])^isW(t[0]) || isW(t[n-1])^isX(s[0])^isW(t[0])^isW(t[1]))){ for(char c : t){ cout << c; } return 0; } } cout << "-1"; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n-1; i >= 0; i--) #define all(x) x.begin(), x.end() using ll = long long; using pii = pair<int, int>; const int mod = 1e9+7; int main() { int n, T; cin >> n >> T; int t[n]; rep(i, n) { cin >> t[i]; } ll ans = 0; rep(i, n) { if (i+1 < n) { ans += min(T, t[i+1] - t[i]); } else { ans += T; } } cout << ans << endl; }
0
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define all(v) v.begin(), v.end() using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vc = vector<char>; using vb = vector<bool>; using vs = vector<string>; using vll = vector<long long>; using vp = vector<pair<int, int>>; using vvi = vector<vector<int>>; using vvc = vector<vector<char>>; using vvll = vector<vector<long long>>; 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 (b<a) {a=b; return 1;} return 0;} int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; int l1 = 1, r1 = m+1, l2 = m+2, r2 = 2*m+1; auto put = [](int &a, int &b) { cout << a << " " << b << endl; a++; b--; }; rep(i, m) { if (l1 < r1) put(l1, r1); else put(l2, r2); } }
#include "bits/stdc++.h" using namespace std; typedef long long ll; template <typename TYPE> void print_vec(const vector<TYPE>& v){ for(int i=0; i<v.size(); i++){ cout << v[i] << " "; } cout << endl; } template <typename TYPE> void print_vec2(const vector<vector<TYPE>>& v){ cout << endl; cout << " "; for(int i=0; i<v[0].size(); i++) cout << i << " "; cout << endl; for(int i=0; i<v.size(); i++){ cout << "i=" << i << ": "; for(int j=0; j<v[i].size(); j++){ if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << " "; else cout << "\x1B[31m" << v[i][j] << " ";//https://stackoverrun.com/ja/q/12618775 } cout << "\x1B[0m" << endl; } } int main(){ int N, M; cin >> N >> M; if(N % 2 == 1){ for(int i=1; i<=M; i++){ cout << i << " " << N-i+1 << endl; } return 0; } //以下Nが偶数の場合 //b-a==N/2にならないように途中で1ずらして表示 例(N, M) = (6,2)で影響 //あるいは 前回のa,bの差と 今回のa,bの差の合計がNにならないように途中で1ずらして表示 例(N, M) = (8, 3)で影響 int tmp = 0; for(int i=1; i<=M; i++){ if(tmp==0 && (N-i+1)-(i) == N/2) tmp++; if(tmp==0 && (N-i+2)-(i-1) + (N-i+1)-i == N) tmp++; cout << i << " " << N-i+1-tmp << endl; } return 0; }
1
#include<iostream> using namespace std; int main(){ int x,y, y2, z, z3, e; while(cin>>e&&e!=0){ int min=1e6; for(y=0;y<=1e3;y++){ y2=y*y; for(z=0;z<=1e2;z++){ z3=z*z*z; x=e-y2-z3; if(min>x+y+z&&x>=0){ min=x+y+z; } } } cout<<min<<endl; } }
#include <iostream> #include <cmath> using namespace std; namespace Solver { int e; inline bool Read() { cin >> e; return e != 0; } inline void Work() { int m = 1e+8; for (int z = 0; z * z * z <= e; z++) { int r = e - z * z * z; int y = (int)sqrt(r); int x = r - y * y; m = min(m, x + y + z); } cout << m << endl; } inline void Solve() { while(Read()) Work(); } } int main() { Solver::Solve(); }
1
#include <iostream> int main() { int x; std::cin >> x; std::cout << x * x * x; std::cout << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i, n) for (ll i = 0; i < n; i++) #define INF 9223372036854775807 #define all(x) (x).begin(), (x).end() ll ts = 1000000007; int main() { ll a, b, c, k; cin >> a >> b >> c >> k; cout << a + b + c + max(a, max(b, c)) * ((1 << k) - 1) << endl; }
0
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<functional> #include<vector> using namespace std; int main(){ int N,M; while(cin>>N>>M,N||M){ int latte[1001],ans=0; vector<int> comb; latte[0]=0; for(int i=1;i<=N;i++){ cin>>latte[i]; } for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ comb.push_back(latte[i]+latte[j]); } } sort(comb.begin(),comb.end()); //for(int i=0;i<comb.size();i++) printf("%d ",comb[i]); puts(""); for(int i=0;i<=N;i++){ for(int j=0;j<=N;j++){ vector<int>::iterator itr; itr = upper_bound(comb.begin(),comb.end(),M-latte[i]-latte[j]); if(itr!=comb.begin()) ans = max(ans,latte[i]+latte[j]+*(itr-1)); } } printf("%d\n",ans); } return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; #define INF (1<<30) #define INFLL (1ll<<60) typedef pair<int, int> P; typedef pair<ll, P> E; #define MOD (1000000007ll) #define l_ength size #define PI 3.14159265358979 void mul_mod(ll& a, ll b){ a *= b; a %= MOD; } void add_mod(ll& a, ll b){ b += MOD; a += b; a %= MOD; } int n,s; ll m,p[1234567]; ll search(ll x){ int l,r,mid; if(x>m){ return 0ll; } l = 0; r = s; while((r-l)>1){ mid = (l+r)/2; if(x+p[mid]>m){ r = mid; }else{ l = mid; } } return ((x+p[r]>m)?(x+p[l]):(x+p[r])); } int main(void){ int i,j; ll ans; cin >> n >> m; while(!(n==0&&m==0ll)){ ans = 0ll; s = n*n+n+1; for(i=0; i<n; ++i){ cin >> p[i]; } for(i=0; i<n; ++i){ for(j=0; j<n; ++j){ p[n+i*n+j] = p[i]+p[j]; } } p[s-1] = 0ll; sort(p,p+s); for(i=0; i<s; ++i){ ans = max(ans,search(p[i])); } cout << ans << endl; cin >> n >> m; } return 0; }
1
//Author:xht37 #include <bits/stdc++.h> #define ui unsigned int #define ll long long #define ul unsigned ll #define ld long double #define pi pair <int, int> #define fi first #define se second #define mp make_pair #define ls (p << 1) #define rs (ls | 1) #define md ((t[p].l + t[p].r) >> 1) #define vi vector <int> #define pb push_back #define pq priority_queue #define dbg(x) cerr << #x" = " << x << endl #define debug(...) fprintf(stderr, __VA_ARGS__) #define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout) using namespace std; namespace io { const int SI = 1 << 21 | 1; char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100]; int f, t; #define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++) inline void flush() { fwrite(OB, 1, OS - OB, stdout), OS = OB; } inline void pc(char x) { *OS++ = x; if (OS == OT) flush(); } template <class I> inline void rd(I &x) { for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1; for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc()); x *= f; } template <class I> inline void rd(I &x, I &y) { rd(x), rd(y); } template <class I> inline void rd(I &x, I &y, I &z) { rd(x), rd(y), rd(z); } template <class I> inline void rda(I *a, int n) { for (int i = 1; i <= n; i++) rd(a[i]); } inline void rdc(char &c) { for (c = gc(); c < 33 || c > 126; c = gc()); } inline void rds(char *s, int &n) { for (c = gc(); c < 33 || c > 126; c = gc()); for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc()); s[n+1] = '\0'; } inline void rds(string &s) { for (c = gc(); c < 33 || c > 126; c = gc()); for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc()); } template <class I> inline void print(I x, char k = '\n') { if (!x) pc('0'); if (x < 0) pc('-'), x = -x; while (x) ch[++t] = x % 10 + '0', x /= 10; while (t) pc(ch[t--]); pc(k); } template <class I> inline void print(I x, I y) { print(x, ' '), print(y); } template <class I> inline void print(I x, I y, I z) { print(x, ' '), print(y, ' '), print(z); } template <class I> inline void printa(I *a, int n) { for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]); } inline void printc(char c) { pc(c); } inline void prints(char *s, int n) { for (int i = 1; i <= n; i++) pc(s[i]); pc('\n'); } inline void prints(string s) { int n = s.length(); while (t < n) pc(s[t++]); pc('\n'), t = 0; } struct Flush { ~Flush() { flush(); } } flusher; } using io::rd; using io::rda; using io::rdc; using io::rds; using io::print; using io::printa; using io::printc; using io::prints; const int N = 1e5 + 7; int n; ll s, x[N], p[N]; ll f(int l, int r, int o) { if (s < x[l] || x[r] < s) return abs(s - x[o]); if (p[l] >= p[r]) return p[l] += p[r], f(l, r - 1, l) + abs(x[l] - x[o]); return p[r] += p[l], f(l + 1, r, r) + abs(x[r] - x[o]); } int main() { rd(n), rd(s); for (int i = 1; i <= n; i++) rd(x[i], p[i]); print(f(1, n, s < x[1] ? n : x[n] < s ? 1 : p[1] >= p[n] ? n : 1)); return 0; }
#include <bits/stdc++.h> #define For(i, j, k) for (int i = j; i <= k; i++) using namespace std; typedef long long LL; const int N = 1e5 + 10; int x[N]; LL w[N]; int S, n; int main() { scanf("%d%d", &n, &S); For(i, 1, n) scanf("%d%lld", &x[i], &w[i]); int l = 1, r = n, nxt = 0; LL ans = 0; while (x[l] < S && x[r] > S) { if (w[l] >= w[r]) { w[l] += w[r]; if (nxt != l) ans += x[r] - x[l]; --r, nxt = l; } else { w[r] += w[l]; if (nxt != r) ans += x[r] - x[l]; ++l, nxt = r; } } if (x[l] < S) ans += S - x[l]; else ans += x[r] - S; printf("%lld\n", ans); return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << n * n * n << endl; }
#include<iostream> using namespace std; int main(){ int x, y=1, i; cin >> x; for(i = 0; i < 3; i++){ y = y * x; } cout << y << endl; return 0; }
1
#include <iostream> #define ll long long using namespace std; bool mx[1003][1003], flag[10004]; ll a[1003], b[1003], ans[1003][1003]; ll prime[10004]; ll gcd(ll x, ll y){ if (y == 0) return x; return gcd(y, x % y); } ll lcm(ll x, ll y){ if (x == 0 || y == 0) return x + y; return x / gcd(x, y) * y; } int main(){ int prime_cnt = 0; for (int i = 2; i <= 10000; ++ i){ if (! flag[i]) prime[++ prime_cnt] = i; for (int j = 2; i * j <= 10000; ++ j){ flag[i * j] = true; if (i % j == 0) break; } } int n; cin >> n; if (n == 2){ cout << "4 7" << endl << "23 10" << endl; return 0; } for (int i = 1; i <= n; ++ i) for (int j = 1; j <= n; ++ j) if (i % 2 == j % 2) mx[i][j] = true; int cnt = 0; for (int i = 1; i <= n; ++ i) for (int j = 1; j <= n; ++ j) if (! mx[i][j]){ //if (! a[i + j]) //a[i + j] = prime[++ cnt]; //if (! b[i - j + n]) //b[i - j + n] = prime[++ cnt]; //ans[i][j] = a[i + j] * b[i - j + n]; ans[i][j] = prime[(i + j) / 2] * prime[(i + n + 1 - j) / 2 + n]; } for (int i = 1; i <= n; ++ i) for (int j = 1; j <= n; ++ j) if (mx[i][j]) ans[i][j] = lcm(lcm(ans[i - 1][j], ans[i + 1][j]), lcm(ans[i][j - 1], ans[i][j + 1])) + 1; for (int i = 1; i <= n; ++ i){ for (int j = 1; j <= n; ++ j) cout << ans[i][j] << " "; cout << endl; } }
#define _USE_MATH_DEFINES #include<iostream> #include<string> #include<queue> #include<cmath> #include<map> #include<set> #include<list> #include<iomanip> #include<vector> #include<random> #include<functional> #include<algorithm> #include<stack> #include<cstdio> #include<bitset> #include<unordered_map> #include<climits> #include<fstream> using namespace std; typedef long long ll; typedef long double ld; #define all(a) (a).begin(),(a).end() #define EPS (1e-5) #define bit(n,k) ((n>>k)&1) const ll Mod = 1000000007; const ll mod = 998244353; struct H { ld x, y; bool operator<(const H& b) const { if (x != b.x) return x < b.x; return y < b.y; } bool operator>(const H& b) const { if (x != b.x) return x > b.x; return y > b.y; } bool operator==(const H& b) const { return x == b.x && y == b.y; } bool operator!=(const H& b) const { return (*this) != b; } }; struct P { ll pos, cost; bool operator<(const P& b) const { return cost < b.cost; } bool operator>(const P& b) const { return cost > b.cost; } }; struct B { ll to, cost; }; struct E { ll from, to, cost; bool operator<(const E& b) const { return cost < b.cost; } bool operator>(const E& b) const { return cost > b.cost; } }; template<typename T, typename U> void chmin(T& a, U b) { if (a > b) a = b; } template<typename T, typename U> void chmax(T& a, U b) { if (a < b) a = b; } template<typename T> T max_0(T a) { if (a < 0) return 0; return a; } template<typename T> T min_0(T a) { if (a > 0) return 0; return a; } ll read() { ll u; ll k = scanf("%lld", &u); return u; } ll gcd(ll i, ll j) { if (i > j) swap(i, j); if (i == 0) return j; return gcd(j % i, i); } ll mod_pow(ll x, ll n, ll p) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % p; x = x * x % p; n >>= 1; } return res; }//x^n%p const ll Inf = 3023372036854775807; const int inf = 1500000000; #define int long long //---------------------------------------------------- int n; struct A { ld x, y; int t; } a[200000]; bool operator<(A a, A b) { if (a.x != b.x) return a.x > b.x; return a.y > b.y; } ld sgarea(A a, A b, A c) { return ((b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y)) / 2; } H b[400000]; ld d[2000]; signed main() { cin >> n; H sum = { 0,0 }; for (int i = 0; i < n; i++) { cin >> a[i].x >> a[i].y; sum.x += a[i].x, sum.y += a[i].y; a[i].t = i; } sum.x /= n, sum.y /= n; sum.x += 0.01, sum.y -= 0.01; sort(a, a + n); for (int i = 0; i < n; i++) { b[i] = H{ atan2(a[i].y - sum.y, a[i].x - sum.x) ,(ld)i }; if (b[i].x < 0) b[i].x += 2 * M_PI; } sort(b, b + n); for (int i = 1; i < 3; i++)for (int j = 0; j < n; j++) b[i * n + j] = b[j]; vector<int>v; int s = 0; for (int i = 0; i < n; i++) if (b[i].y == 0) s = i; v.push_back(b[s].y); v.push_back(b[s + 1].y); for (int i = 2; i <= n; i++) { do { if (sgarea(a[v[v.size() - 2]], a[v[v.size() - 1]], a[(int)b[i + s].y]) < 0) { v.pop_back(); } else break; } while (v.size() > 1); v.push_back(b[i + s].y); } v.pop_back(); vector<A>u; for (int i = 0; i < v.size(); i++) { u.push_back(A{ a[v[i]].x,a[v[i]].y, a[v[i]].t }); } int U = u.size(); ld res = 0; for (int j = 0; j < 2; j++) for (int i = 0; i < U; i++) u.push_back(u[i]); for (int i =U; i < 2 * U; i++) { ld u1 = atan2(u[i - 1].y - u[i].y, u[i - 1].x - u[i].x), u2 = atan2(u[i + 1].y - u[i].y, u[i + 1].x - u[i].x); if (u1 < 0) u1 += 2 * M_PI; if (u2 < 0) u2 += 2 * M_PI; ld x = abs(u1 - u2); if (x > M_PI) x = 2 * M_PI - x; d[u[i].t] = M_PI - x; res += d[u[i].t]; } for (int i = 0; i < n; i++) { printf("%.12LF\n", d[i] / M_PI / 2); } }
0
#include "bits/stdc++.h" using namespace std; #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define ll long long #define li long int #define ld long double #define lld long long double #define pb push_back #define mk make_pair #define F first #define S second #define all(v) (v).begin(),(v).end() #define fill(a) memset(a, 0, sizeof(a)) const int MX = 1e6; const int MI = -1e6; const int MOD = 1e9 + 7; const string ALPHA = "abcdefghijklmnopqrstuvwxyz"; const double PI = 3.1415926535; #define rep(i, n) for(int i=0; i<n; i++) const int mod=1e9+7; inline int add(int x,int y){ x+=y; if (x>=mod) return x-mod; return x; } inline int sub(int x,int y){ x-=y; if (x<0) return x+mod; return x; } inline int mul(int x,int y){ return (x*1ll*y)%mod; } inline int power(int x,int y){ int ans=1; while(y){ if (y&1) ans=mul(ans,x); x=mul(x,x); y>>=1; } return ans; } inline int inv(int x){ return power(x,mod-2); } int main() { IOS; int a, b, c; cin >> a >> b >> c; cout << c << " " << a << " " << b << endl; return 0; }
#include <iostream> using namespace std; #include <cmath> int main(){ int n,x,t; cin >> n >> x >> t; cout << (long long)ceil((double)n/x)*t << endl; }
0
#include<bits/stdc++.h> using namespace std; string s; int main() { getline(cin,s); int len=s.size()-8; for(int i=0;i<len;i++)cout<<s[i]; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<int>>; const ll mod=1000000007; const int MAX_N = 1000; // n の最大値 // nCk を取得 double nCk(int n, int k) { double res=1.0; for(int i=0; i<n; i++){ res*=0.5;} for(int i=0; i<k; i++){ res*=(double)(n-i); res/=(double)(k-i); } return res;} int main() { string n; cin>>n; string ca = n.substr(0,n.size()-8); cout <<ca<< endl; return 0;}
1
#include <bits/stdc++.h> using namespace std; #define INF 1e9 #define LLINF 1e18 #define pi 3.14159265358979323 #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; int gcd(int a, int b) { if(a % b == 0) { return b; } else { return(gcd(b, a % b)); } } int main() { int a, b, m; cin >> a >> b >> m; vector<int> veca(a); vector<int> vecb(b); int minia = INF; int minib = INF; rep(i, a) { cin >> veca.at(i); minia = min(minia, veca.at(i)); } rep(i, b) { cin >> vecb.at(i); minib = min(minib, vecb.at(i)); } int mini = minia + minib; int dismini = INF; vector<vector<int> > dis(m, vector<int> (3)); rep(i, m) { rep(j, 3) { cin >> dis.at(i).at(j); } dismini = min(dismini, veca.at(dis.at(i).at(0) - 1) + vecb.at(dis.at(i).at(1) - 1) - dis.at(i).at(2)); } cout << min(dismini, mini) << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long void read(int &x) { int f=1; x=0; char s=getchar(); while(s<'0'||s>'9') { if(s=='-') f=-1; s=getchar(); } while(s>='0'&&s<='9') { x=x*10+s-'0'; s=getchar(); } x*=f; } #define N 100005 int n,m,t; int a[N],b[N]; int main(){ cin>>n>>m>>t; for (int i = 1; i <= n; i++) { cin>>a[i]; } for (int i = 1; i <= m; i++) { cin>>b[i]; } int ans=1e9; for (int i = 0; i < t; i++) { int x,y,c; cin>>x>>y>>c; ans= min(a[x]+b[y]-c,ans); } sort(a+1,a+n+1); sort(b+1,b+m+1); cout<<min(ans,a[1]+b[1]); return 0; }
1
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef vector<ll> vl; typedef pair<ll, ll> PP; #define rep(i, n) for(ll i = 0; i < ll(n); i++) #define all(v) v.begin(), v.end() #define inputv(v, n) \ vl v; \ rep(i, n) { \ ll x; \ cin >> x; \ v.push_back(x); \ } bool chmin(ll& a, ll b) { if (b < a) { a = b; return 1; } return 0; } bool chmax(ll& a, ll b) { if (b > a) { a = b; return 1; } return 0; } const ll INF = 999999999999999; const ll MOD = 1000000007; const ll MAX_N = 500010; ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans; struct Gragh { ll N; vector<vl> G; vl visited; Gragh(ll n) { N = n; G.resize(N); resetv(); } void add(ll a, ll b) { G[a].push_back(b); } void resetv(void) { visited = vl(N, 0); } //重さ無し void dfs(ll x) { visited[x] = 1; for (ll i : G[x]) { if (visited[i] == 0) { dfs(i); } } } }; int main() { cin >> n >> m; Gragh G(2 * n); rep(i, m) { cin >> a >> b; a--; b--; G.add(a * 2, b * 2 + 1); G.add(b * 2, a * 2 + 1); G.add(a * 2+1, b * 2); G.add(b * 2+1, a * 2); } G.dfs(0); vl dp(2, 0); rep(i, n * 2) { if (G.visited[i] == 1)dp[i % 2]++; } x=dp[0]; y=dp[1]; k=x+y-n; ans=k*(n-k)+k*(k-1)/2+(x-k)*(y-k)-m; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const double pi=3.141592653589793; typedef unsigned long long ull; typedef long double ldouble; const ll INF=1e18; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) 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 int MAX_V = 100005; vector<int> G[MAX_V]; vector<int> color(MAX_V); // 辺に属性がある場合 /* struct edge {int to,cost;}; vector<edge> G[MAX_V]; */ // 2部グラフの場合: b*w - m 2部グラフでない場合: n(n-1)/2 - m bool dfs(int v, int c){ color[v] = c; rep(i, G[v].size()){ if(color[G[v][i]] == c) return false; if(color[G[v][i]] == 0 && !dfs(G[v][i], -c)) return false; } return true; } int main(){ ll N, M; cin >> N >> M; rep(i, M){ int s, t; cin >> s >> t; s--; t--; G[s].push_back(t); // 無向グラフの場合 G[t].push_back(s); } // グラフの操作 ll B = 0, W = 0; if(dfs(0, 1)){ rep(i, N){ if(color[i] == 1){ B++; } else if(color[i] == -1){ W++; } } cout << B*W - M << endl; } else { cout << ((N * (N-1)) / 2) - M << endl; } }
1
#include <iostream> #include <bitset> #include <vector> #include <sstream> #include <algorithm> int main(){ int purchase_num; int max_cap; while(std::cin >> purchase_num >> max_cap){ if(purchase_num == 0 && max_cap == 0) break; std::vector<int> price; std::string str; int input_data; int min_price = 0; std::cin.ignore(); std::getline(std::cin, str); std::istringstream iss(str); while(!iss.eof()){ iss >> input_data; price.push_back(input_data); } std::sort(price.begin(),price.end(),std::greater<int>()); for(int i = 0; i < price.size(); ++i){ if((i+1)%max_cap != 0){ min_price += price[i]; } } std::cout << min_price << std::endl; } return 0; }
#include<bits/stdc++.h> #define rep(i,n)for(int i=0;i<n;i++) using namespace std; typedef long long ll; int p[1000]; int main() { int n, m; while (cin >> n >> m, n) { int sum = 0; rep(i, n) { scanf("%d", &p[i]); sum += p[i]; } sort(p, p + n, greater<>()); for (int i = m - 1; i < n; i += m) { sum -= p[i]; } cout << sum << endl; } }
1
#pragma GCC optimize("Ofast") #define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; using u8 = uint8_t; using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; using i8 = int8_t; using i16 = int16_t; using i32 = int32_t; using i64 = int64_t; using vi = vector<int>; constexpr char newl = '\n'; constexpr double eps = 1e-10; #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define F0R(i,b) FOR(i,0,b) #define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--) #define RF0(i,b) RFO(i,0,b) #define fi first #define se second #define show(x) cout << #x << " = " << x << '\n'; #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define sz(x) (int)(x).size() #define YesNo {cout<<"Yes";}else{cout<<"No";} #define YESNO {cout<<"YES";}else{cout<<"NO";} #define v(T) vector<T> template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; } template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; } template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) { return l.first < r.first; } template<class T> istream& operator>>(istream& i, v(T)& v) { F0R(j, sz(v)) i >> v[j]; return i; } template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) { return i >> p.first >> p.second; } template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) { return i >> get<0>(t) >> get<1>(t) >> get<2>(t); } template<class T> ostream& operator<<(ostream& o, const vector<T>& v) { F0R(i, v.size()) { o << v[i] << ' '; } o << newl; return o; } template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) { for (auto& p : m) { o << p.first << ": " << p.second << newl; } o << newl; return o; } #if 1 // INSERT ABOVE HERE signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int N, M; cin >> N >> M; vector<int> a(N + 1), b(M + 1); cin >> a[0] >> b[0]; F0R(i, N) cin >> a[i + 1]; F0R(i, M) cin >> b[i + 1]; sort(rng(a)); sort(rng(b)); cout << (a.back() < b[0] ? "No War" : "War"); } #endif
#include <bits/stdc++.h> using namespace std; int main(){ string N,m; cin >> N; int x,y = 0; for(int i = 0; i < int(N.size()); i++){ istringstream n; m = N[i]; n = istringstream(m); n >> x; y += x; } if (stoi(N) % y == 0){ cout << "Yes" << endl; } else{ cout << "No" << endl; } }
0
#include <iostream> #include <cmath> #include <cstdlib> using namespace std; int main(int argc, char* argv[]) { int n = 0, n2 = 0; cin >> n; //n = atoi(argv[1]); if(n < 1 || n > 100) { return 1; } n2 = pow(n, 3.0); cout << n2 << endl; }
#include<iostream> #include<cstdio> int main() { int n; std::cin >> n; printf("%d\n", n * n * n); return 0; }
1
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <queue> #include <cmath> #include <climits> #include <iomanip> #include <set> #include <map> using namespace std; typedef long long ll; int main(){ ll n = 0; cin >> n; vector<ll> a(n); for(int i = 0;i < n;i++)cin >> a[i]; vector<ll> c; c.push_back(a[0]); for(int i = 1;i < n;i++){ //if(i == 5)cout << c.size()<< " " << c[0] << " " << c[1] << " " << c[2] << endl; ll pushnum = 0; ll popit = lower_bound(c.begin(),c.end(),a[i]) - c.begin(); if(popit == 0)pushnum = a[i]; else{ pushnum = a[i]; c.erase(c.begin() + popit - 1); } ll pushit = lower_bound(c.begin(),c.end(),pushnum) - c.begin(); c.insert(c.begin() + pushit,pushnum); } //cout << c[0] << " " << c[1] << " " << c[2] << endl; cout << c.size() << endl; }
#include<bits/stdc++.h> #include<vector> #include<string> #include<stack> #include<iostream> #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define ll long long #define MOD 1000000007 #define vec(a) vector<int>a using namespace std; bool isPrime(ll n) { if(n==1||n==2||n==3||n==5||n==7) return 1; else { ll i,j,k,l,m; for(i=2;i<=sqrt(n);i++) { if(n%i==0) return 0; } return 1; } } int main() { #ifndef ONLINE_JUDGE freopen("output.txt", "w", stdout); freopen("input.txt", "r", stdin); #endif ll arr[3]; cin>>arr[0]>>arr[1]>>arr[2]; sort(arr,arr+3); cout<<arr[0]+arr[1]; return 0; }
0
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define dup(x,y) (((x)+(y)-1)/(y)) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef pair<int, int> pii; const double EPS = 1e-10; const int INF = 1e9; const ll LINF = 1e18; const int MOD = 1000000007; const double PI = acos(-1); int dx[4] = {0,1,0,-1}; int dy[4] = {1,0,-1,0}; int main() { int n, k; cin >> n >> k; int c = 0; int t = 1; while (t < k) { t -= 1; t += n; c++; } cout << c << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int cnt = 1; while (1) { if ((a-1) * (cnt-1) + a >= b) break; cnt++; } if (b == 1) cout << 0 << endl; else cout << cnt << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef tuple<int, int> duo; const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1}; const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1}; const int Mod = 1000000000 + 0; //{{{ templates #define TT_ template<typename T>inline #define TTF_ template<typename T,typename F>inline TT_ T sq(T x){return x*x;} TT_ T In(){T x;cin>>x;return x;} TT_ void Out(T&x){cout<<x;} TT_ void sort(T&v){sort(begin(v),end(v));} TT_ void revs(T&v){reverse(begin(v),end(v));} TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));} TT_ int ubnd(T&v,typename T::value_type x){return upper_bound(begin(v),end(v),x)-begin(v);} TT_ int lbnd(T&v,typename T::value_type x){return lower_bound(begin(v),end(v),x)-begin(v);} TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));} TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;} TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));} TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));} inline void fast_io(){ios_base::sync_with_stdio(0);cin.tie(0);} inline int in(){int x;scanf("%d",&x);return x;} inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;} inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);} //}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple int main() { int N, Q; while (N = in(), Q = in(), N || Q){ int bkt[128] = {}; for (int i = 0; i < N; i++){ for (int x = in(); x--;){ bkt[in()]++; } } int maxi = 0; for (int i = 1; i < 128; i++){ if (bkt[i] >= Q && bkt[maxi] < bkt[i]){ maxi = i; } } cout << maxi << endl; } return 0; }
#include <iostream> using namespace std; int main(){ int N,Q,i,I,M,data,max,result; int box[100]={}; while(1){ cin>>N>>Q; if(N==0||Q==0) break; for(i=1;i<=N;i++){ cin>>M; for(I=1;I<=M;I++){ cin>>data; box[data]++; } } max=-1; for(i=0;i<100;i++){ if(max<box[i]){ max=box[i]; result=i; } } if(box[result]<Q) cout<<"0"<<endl; else cout<<result<<endl; for(i=0;i<100;i++){ box[i]=0; } } return 0; }
1
#include <bits/stdc++.h> using namespace std; using ll=long long; #define rep(i,n) for (ll i=0; i<n; ++i) #define all(c) begin(c),end(c) #define PI acos(-1) #define oo LLONG_MAX template<typename T1, typename T2> bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;} template<typename T1, typename T2> bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;} /* */ //BIT #define M 500010 ll dat[M]; void init(){ rep(i, M) dat[i] = 0; } void add(ll i, ll x){ for(; i<M; i += i&-i) dat[i] += x; } ll sum(ll i){ ll res = 0; for(; i>0; i -= i&-i) res += dat[i]; return res; } ll rangesum(ll L, ll R){ return sum(R) - sum(L-1); } ll A[M] = {}; vector<ll> QL[M], QID[M]; ll ans[M]; ll N, Q, C[M]; int main(){ cin.tie(0); ios::sync_with_stdio(0); cin >> N >> Q; for(ll i = 1; i <= N; i++) cin >> C[i]; rep(i, Q){ ll L, R; cin >> L >> R; QL[R].push_back(L); QID[R].push_back(i);//後続、sortしないで順番に出せる } init(); for(ll i = 1; i <= N; i++){ if (A[C[i]] > 0) add(A[C[i]], -1); add(i, +1); //rep(i, Q+10) cout<<dat[i]; cout<<endl; A[C[i]] = i; rep(j, QL[i].size()) ans[QID[i][j]] = rangesum(QL[i][j], i); } rep(i, Q) cout << ans[i]<< endl; }
#define NguyenDangQuan the_author #include <bits/stdc++.h> #define all(x) x.begin(),x.end() #define mset(x, i) memset(x,i,sizeof(x)) #define elif else if #define heap priority_queue #define fi first #define se second #define pb push_back #define ld long double #define ll long long #define ull unsigned long long #define task "codejam" using namespace std; int typetest; template<class T> void read(T &x){ register int c; T neg = 1; x = (T)0; while ((c = getchar()) <= 47 || c >= 58) if(c == '-') neg = -1; for (; (c > 47 && c < 58); c = getchar()){ x = (x << 3) + (x << 1) + (T)(c - 48); } x *= neg; } inline void fastIOfileinput(){ ios:: sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen(task".INP", "r", stdin); // freopen(task".OUT", "w", stdout); // freopen(task".in", "r", stdin); // freopen(task".out", "w", stdout); typetest = 0; } const int N = 2e5 + 2; int m, n, k; vector<int> ker[N], kel[N]; int ltr[N], ltl[N]; void Enter(){ read(n); read(m); read(k); while(m--){ int a, b; read(a); read(b); ker[a].pb(b); ker[b].pb(a); } while(k--){ int a, b; read(a); read(b); kel[a].pb(b); kel[b].pb(a); } } void BFS(int i, int lt[], vector<int> ke[]){ ++m; lt[i] = m; queue<int> open; open.push(i); while(open.size()){ int c = open.front(); open.pop(); for(auto i : ke[c]){ if((!lt[i])) open.push(i), lt[i] = m; } } } void solve(){ m = 0; for(int i = 1; i <= n; ++i) if(ltr[i] == 0) BFS(i, ltr, ker); m = 0; for(int i = 1; i <= n; ++i) if(ltl[i] == 0) BFS(i, ltl, kel); map<int, map<int, int> > s; for(int i = 1; i <= n; ++i){ ++s[ltr[i]][ltl[i]]; // cerr << ltr[i] << " " << ltl[i] << "\n"; } for(int i = 1; i <= n; ++i){ int& v = s[ltr[i]][ltl[i]]; cout << v << " "; } } signed main(){ fastIOfileinput(); if(typetest){ int t; cin >> t; int v = t; while(t--){ Enter(); cout << "Case #" << v - t << ": "; solve(); } } else{ Enter(); solve(); } }
0
#include<iostream> #include<iomanip> #include<cmath> #include<string> #include<cstring> #include<vector> #include<list> #include<algorithm> #include<map> #include<set> #include<queue> #include<stack> using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define mt make_tuple #define pqueue priority_queue const int inf=1e9+7; const ll mod=1e9+7; const ll mod1=998244353; const ll big=1e18; const double PI=2*asin(1); int main() { int D, T, S; cin>>D>>T>>S; if(S*T>=D) cout<<"Yes"<<endl; else cout<<"No"<<endl; }
#include <iostream> #include <cstring> #include <algorithm> #include <vector> #include <map> #include <unordered_set> #include <queue> #include <set> #include <iomanip> #include <stack> #define int long long #define ld long double #define dbg(x) cout <<#x<<":"<<x<<'\n'; #define dbg2(x,y) cout<<#x<<":"<<x<<' '<<#y<<":"<<y<<'\n'; #define endl '\n' #define inf 1000000010 #define eps 1e-8l using namespace std; const int N=2e5+5; std::vector<int> g[N],c(N),gd(N),p(N),r(N); vector<bool> vis(N); int power(int x,int y){int res = 1;while(y>0){if(y&1)res = (res*x);x = (x*x);y = y>>1;}return res;} //int n,m; int n,a,b,da,db,md,nd,m; int const dpn=2e5+5; int dp[dpn]; bool comp(pair<int,int> l,pair<int,int> r){ if(l.first!=r.first) return (l.first<r.first); return l.second>r.second; } int find(int i){ if(p[i]!=i) return p[i]=find(p[i]); return i; } void join(int x,int y){ int px=find(x); int py=find(y); if(r[px]>r[py]) p[py]=px; else if(r[px]<r[py]) p[px]=py; else p[py]=px,r[px]++; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; //cin>>t; while(t--){ //int n; //int n; int d,t,s; cin>>d>>t>>s; if((double)d/(double)s<=(double)t) cout<<"Yes\n"; else cout<<"No\n"; } return 0; }
1
#include<bits/stdc++.h> using namespace std ; int main() { int w = 0 , k = 0 ; int score[2][10] = {0} ; for ( int i = 0 ; i < 2 ; i++ ) { for ( int j = 0 ; j < 10 ; j++ ) { cin >> score[i][j] ; } sort( score[i],score[i]+10 ) ; reverse( score[i],score[i]+10 ) ; } w = score[0][0] + score[0][1] + score[0][2] ; k = score[1][0] + score[1][1] + score[1][2] ; printf("%d %d\n",w ,k ) ; return 0 ; }
#include <iostream> #include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define Rep(i, b, e) for(int (i) = (b); (i) < (e); ++(i)) #define Repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i)) #define Print(x) cout << (x) << endl #define Min2(a, b) ((a) < (b)) ? (a) : (b) #define Max2(a, b) ((a) > (b)) ? (a) : (b) typedef long long ll; using namespace std; int N, K; string C[10]; set<string> bt; void dfs(string str, int k, int state){ if(k == 0){ bt.insert(str); return; } Rep(i, 0, N){ if((1 << i) & state) continue; dfs(str + C[i], k - 1, state | (1 << i)); } } int main(){ while(true){ cin >> N >> K; if(N == 0 && K == 0) break; Rep(i, 0, N) cin >> C[i]; dfs("", K, 0); Print(bt.size()); bt.clear(); } return 0; }
0
#include <bits/stdc++.h> #define REP(i, n) for(int i=0;i<(int)(n);i++) #define ALL(x) (x).begin(),(x).end() const int INF = 1e9; using namespace std; int n; int res = 0; struct node { int id; int parent; }; node v[100]; vector<tuple<int, int, int>> cost; vector<int> path; int find(node x){ if(x.parent == -1){ REP(i, path.size()) v[path[i]].parent = x.id; path.clear(); return x.id; } else{ path.push_back(x.id); return find(v[x.parent]); } } void marge(node x, node y){ int x_id = find(x); int y_id = find(y); if(x_id == y_id) return; else v[y_id].parent = x_id; return; } bool judge(node x, node y){ vector<int> xpath, ypath; return find(x) == find(y); } int main() { cin >> n; REP(i, n) REP(j, n) { int tmp; cin >> tmp; if(tmp != -1) cost.push_back(make_tuple(tmp, i, j)); } REP(i, n){ v[i].id = i; v[i].parent = -1; } sort(ALL(cost)); REP(i, cost.size()){ node from = v[get<1>(cost[i])]; node to = v[get<2>(cost[i])]; if(judge(from, to)){ continue; } res += get<0>(cost[i]); marge(from, to); } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 302; double dp[N][N][N]; int n; int cnt[4]; int main(){ cin >> n; for(int i = 0;i < n;i++){ int x; scanf("%d", &x); cnt[x]++; } for(int k = 0;k <= cnt[3];k++){ for(int j = 0;j <= cnt[2] + cnt[3] - k;j++){ for(int i = 0;i <= n - j;i++){ if(i == 0 && j == 0 && k == 0) continue; dp[i][j][k] = 1; if(i) dp[i][j][k] += 1.0 * i / n * dp[i - 1][j][k]; if(j) dp[i][j][k] += 1.0 * j / n * dp[i + 1][j - 1][k]; if(k) dp[i][j][k] += 1.0 * k / n * dp[i][j + 1][k - 1]; dp[i][j][k] /= 1 - 1.0 * (n - i - j - k) / n; } } } printf("%.10f", dp[cnt[1]][cnt[2]][cnt[3]]); }
0
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for(int i = (a); i <= (b); i++) #define PER(i, a, b) for(int i = (a); i >= (b); i--) #define rep(i, a, b) for(int i = (a); i < (b); i++) #define all(S) (S).begin(), (S).end() #define pb push_back #define mk make_pair #define S second #define F first typedef long long ll; typedef long double lf; typedef pair<int, int> ii; const int MAX = 1e5+5; char s[MAX]; int main(int argc, char ** argv) { scanf(" %s", s); int sz = strlen(s); rep(i, 0, sz) { if(i >= 1 && s[i] == s[i-1]) printf("%d %d\n", i, i+1), exit(0); if(i >= 2 && s[i] == s[i-2]) printf("%d %d\n", i-1, i+1), exit(0); } puts("-1 -1"); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll n,a,b,c,d,e; cin >> n >> a >> b >> c >> d >> e; cout << (n-1)/min({a,b,c,d,e})+5 << endl; return 0; }
0
#include <stdio.h> #include <vector> #include <algorithm> using namespace std; int main(){ vector<int> W(10),K(10); for(int i=0;i<10;i++) scanf("%d",&W[i]); for(int i=0;i<10;i++) scanf("%d",&K[i]); sort(W.begin(),W.end()); sort(K.begin(),K.end()); printf("%d %d\n",W[7]+W[8]+W[9],K[7]+K[8]+K[9]); return 0; }
#include<cstdio> #include<iostream> #include<string> #include<algorithm> using namespace std; int main() { int sum[2] = {0}, num[10] = { 0 }, i, j; for (j = 0; j < 2; j++) { for (i = 0; i < 10; i++) { cin >> num[i]; } sort(num, num + 10); sum[j] = num[7] + num[8] + num[9]; } cout << sum[0] << " " << sum[1] << endl; return 0; }
1
// clang-format off #include <bits/stdc++.h> #define int long long #define main signed main() #define loop(i, a, n) for (int i = (a); i < (n); i++) #define rep(i, n) loop(i, 0, n) #define forever for (;;) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define prec(n) fixed << setprecision(n) template<typename A> using V = std::vector<A>; template<typename A> using F = std::function<A>; template<typename A, typename B> using P = std::pair<A, B>; using pii = P<int, int>; using vi = V<int>; using vd = V<double>; using vs = V<std::string>; using vpii = V<pii>; using vvi = V<vi>; using vvpii = V<vpii>; constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979; template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; } template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; } constexpr bool odd(const int n) { return n & 1; } constexpr bool even(const int n) { return ~n & 1; } template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; } template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; } using namespace std; // clang-format on main { vi v(5); char gomi; while (cin >> v[0] >> gomi >> v[1] >> gomi >> v[2] >> gomi >> v[3] >> gomi >> v[4]) { sort(all(v)); if (v[0] == v[3] || v[1] == v[4]) { cout << "four card" << endl; continue; } if ((v[0] == v[1] && v[2] == v[4]) || (v[0] == v[2] && v[3] == v[4])) { cout << "full house" << endl; continue; } if (v[4] - v[0] == 4 || (v[0] == 1 && v[1] == 10 && v[4] - v[1] == 3)) { cout << "straight" << endl; continue; } if (v[0] == v[2] || v[1] == v[3] || v[2] == v[4]) { cout << "three card" << endl; continue; } if ((v[0] == v[1] && (v[2] == v[3] || v[3] == v[4])) || (v[1] == v[2] && v[3] == v[4])) { cout << "two pair" << endl; continue; } if (v[0] == v[1] || v[1] == v[2] || v[2] == v[3] || v[3] == v[4]) { cout << "one pair" << endl; continue; } cout << "null" << endl; } }
#include <iostream> using namespace std; char judge(int, int, int); int main() { int n, pm, pe, pj; while (true) { cin >> n; if (n == 0) break; for (int i = 0;i < n;i++) { cin >> pm >> pe >> pj; cout << judge(pm, pe, pj) << endl; } } } char judge(int math, int eng, int jap) { float twoave = (math + eng) / 2; float ave = (math + eng + jap) / 3; if (math == 100 || eng == 100 || jap == 100) { return 'A'; } else if (twoave >= 90) { return 'A'; } else if (ave >= 80) { return 'A'; } else if (ave >= 70) { return 'B'; } else if (ave >= 50 && (math >= 80 || eng >= 80)) { return 'B'; } else { return 'C'; } }
0
#include <algorithm> #include <iostream> #include <string> #include <set> using namespace std; int main() { int N; long long Y; cin >> N >> Y; int a, b , c; a = 0; while (a <= Y / 10000) { b = 0; while (10000*a + 5000 * b <= Y) { c = N - a - b; if (10000*a + 5000*b + 1000*c == Y) { cout << a << " " << b << " " << c << endl; return 0; } b++; } a++; } cout << "-1 -1 -1" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for (ll i = 0; i < (n); ++i) int main() { ll n; cin >> n; vector<ll> a(5); ll minimum=1e18; rep(i,5){ cin >> a[i]; minimum = min(minimum,a[i]); } if(n <= minimum){ cout << 5 << endl; }else{ ll times = ceil((n-minimum)*1.0/minimum); cout << times + 5 << endl; } return(0); }
0
#include <bits/stdc++.h> #define FASTIO using namespace std; using ll = long long; using Vi = vector<int>; using Vl = vector<ll>; using Pii = pair<int, int>; using Pll = pair<ll, ll>; constexpr int I_INF = numeric_limits<int>::max(); constexpr ll L_INF = numeric_limits<ll>::max(); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void solve() { ll N; cin >> N; cout << 0 << endl; string r0; cin >> r0; if (r0 == "Vacant") { return; } string r; int left = -1, right = N; while (right - left > 1) { int mid = (left + right) >> 1; cout << mid << endl; cin >> r; if (r == "Vacant") { return; } if (mid & 1) { if (r == r0) { right = mid; } else { left = mid; } } else { if (r == r0) { left = mid; } else { right = mid; } } } int cur = left + 1; while (true) { cout << cur << endl; cin >> r; if (r == "Vacant") break; ++cur; } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% int main() { #ifdef FASTIO cin.tie(0), cout.tie(0); ios::sync_with_stdio(false); #endif #ifdef FILEINPUT ifstream ifs("./in_out/input.txt"); cin.rdbuf(ifs.rdbuf()); #endif #ifdef FILEOUTPUT ofstream ofs("./in_out/output.txt"); cout.rdbuf(ofs.rdbuf()); #endif solve(); cout << flush; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; constexpr int Inf = 1000000000; constexpr ll INF= 1e18; constexpr ll MOD = 1000000007; const double PI = 3.1415926535897; typedef pair<int,int> P; template<typename T> T Pow(T a,T b) { T ret = 1; for(int i = 0;i < b;i++) { ret *= a; } return ret; } ll mod(ll val) { ll res = val % MOD; if(res < 0) { res += MOD; } return res; } ll RS(ll N, ll P, ll M){ if(P==0) return 1; if(P%2==0){ ll t = RS(N, P/2, M); return t*t % M; } return N * RS(N, P-1, M) % M; } int main() { int N; cin >> N; if(N == 2) { cout << -1 << endl; return 0; } vector<vector<char>> three = { {'a','a','b'}, {'b','.','b'}, {'b','a','a'} }; vector<vector<char>> four = { {'a','a','c','a'}, {'b','b','c','a'}, {'a','e','d','d'}, {'a','e','c','c'}, }; vector<vector<char>> five = { {'a','a','b','b','c'}, {'b','.','.','a','c'}, {'b','.','.','a','b'}, {'a','b','b','.','b'}, {'a','c','c','a','a'}, }; vector<vector<char>> seven = { {'.','a','a','b','b','c','.'}, {'d','d','.','.','.','c','e'}, {'f','.','.','.','a','.','e'}, {'f','.','.','.','a','.','f'}, {'h','.','a','a','.','.','f'}, {'h','g','.','.','.','a','a'}, {'.','g','a','a','b','b','.'}, }; if(N == 3) { for(int i = 0;i < 3;i++) { for(int j = 0;j < 3;j++) { cout << three.at(i).at(j); } cout << endl; } return 0; } else if(N == 6) { vector<vector<char>> ret(N,vector<char>(N,'.')); for(int i = 0;i < 2;i++) { for(int j = 0;j < 3;j++) { for(int k = 0;k < 3;k++) { ret.at(3 * i + j).at(3 * i + k) = three.at(j).at(k); } } } for(int i = 0;i < N;i++) { for(int j = 0;j < N;j++) { cout << ret.at(i).at(j); } cout << endl; } return 0; } int Four = 0; int Five = 0; int Seven = 0; for(int i = 0;i <= 400;i++) { for(int j = 0;j <= 400;j++) { for(int k = 0;k <= 400;k++) { if(i * 4 + j * 5 + k * 7 == N) { Four = i; Five = j; Seven = k; break; } } } } vector<vector<char>> ret(N,vector<char>(N,'.')); int cnt = 0; for(int i = 0;i < Four;i++) { for(int j = 0;j < 4;j++) { for(int k = 0;k < 4;k++) { ret.at(cnt + j).at(cnt + k) = four.at(j).at(k); } } cnt += 4; } for(int i = 0;i < Five;i++) { for(int j = 0;j < 5;j++) { for(int k = 0;k < 5;k++) { ret.at(cnt + j).at(cnt + k) = five.at(j).at(k); } } cnt += 5; } for(int i = 0;i < Seven;i++) { for(int j = 0;j < 7;j++) { for(int k = 0;k < 7;k++) { ret.at(cnt + j).at(cnt + k) = seven.at(j).at(k); } } cnt += 7; } for(int i = 0;i < N;i++) { for(int j = 0;j < N;j++) { cout << ret.at(i).at(j); } cout << endl; } }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair <int, int>; #define rep(i, n) for (int i = 0; i < (int) (n); i++) #define repr(i, a, b) for (int i = a; i < b; i++) #define each(i, mp) for (auto &i : mp) const int INF = 1001001001; int main() { int a; cin >> a; ll ans = 0; rep(i, 3) ans += pow(a, i + 1); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ALL(a) (a).begin(),(a).end() #define rALL(a) (a).rbegin(),(a).rend() typedef pair<int, int> Pint; typedef pair<int64_t, int64_t> Pll; int main() { int N; cin >> N; cout << (N - 2) * 180 << endl; }
0
#include<iostream> using namespace std; int main(){ int m, d, ans, month, i, total = 0; while(1){ cin >> m >> d; if (m == 0) break; for(i = 1; i < m; i ++){ if(i==1||i==3||i==5||i==7||i==8||i==10||i==12){ total += 31; } else if(i == 2){ total += 29; } else{ total += 30; } } total += d; ans = total % 7; switch (ans){ case 1:cout << "Thursday" << endl; break; case 2:cout << "Friday" << endl; break; case 3:cout << "Saturday" << endl; break; case 4:cout << "Sunday" << endl; break; case 5:cout << "Monday" << endl; break; case 6:cout << "Tuesday" << endl; break; case 0:cout << "Wednesday" << endl; break; } ans = 0, total = 0; } return 0; }
// clang-format off #include <bits/stdc++.h> #define int long long #define main signed main() // #define main int main() #define loop(i, a, n) for (int i = (a); i < (n); i++) #define rep(i, n) loop(i, 0, n) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define prec(n) fixed << setprecision(n) #define stlice(from, to) substr(from, (to) - (from) + 1) #define pb push_back #define mp make_pair #define mt make_tuple #define fi first #define se second using namespace std; using pii = pair<int, int>; using vi = vector<int>; using vd = vector<double>; using vc = vector<char>; using vb = vector<bool>; using vs = vector<string>; using vpii = vector<pii>; using vvi = vector<vi>; using vvb = vector<vb>; using vvpii = vector<vpii>; template<typename A> using fn = function<A>; constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000; constexpr int MOD = 1000000007; constexpr double PI = acos(-1); template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; } template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; } constexpr bool odd(const int &n) { return n & 1; } constexpr bool even(const int &n) { return !odd(n); } template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); } void solve(); main { solve(); return 0; } // clang-format on constexpr int zeller(int y, int m, const int &d) { if (m == 1 || m == 2) y--, m += 12; int k = y % 100, j = y / 100; return (d + 13 * (m + 1) / 5 + k + k / 4 + j / 4 + 5 * j + 6) % 7; } void solve() { int m, d; string t[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; while (cin >> m >> d, m) cout << t[zeller(2004, m, d)] << endl; }
1
#include <bits/stdc++.h> #define rep(i, n) for(ll i = 0; i < (n); ++i) using namespace std; using ll = long long; const double PI=acos(-1); template<typename T> istream& operator>> (istream& is, vector<T> &vec){ for(T& x: vec) is >> x; return is; } vector<vector<pair<ll,ll>>> a(15); vector<ll> l(15, -1); ll count(ll x, ll n){ for(auto j : a[x]){ if(l[j.first-1] != -1 && l[j.first-1] != j.second){ //cout << "hoge"; return -1; } l[j.first-1] = j.second; } ll ans = 0; rep(i, n) if(l[i] == 1) ans++; return ans; } int main(){ ll n; cin >> n; rep(i, n){ ll b; cin >> b; rep(j, b){ ll x, y; cin >> x >> y; a[i].emplace_back(x, y); } } ll ans = 0; for(ll i = 0; i < pow(2, n); ++i){ ll tmp = 0; l.assign(15, -1); //cout << i << " " << ans << ": "; rep(j, n) l[j] = (i & (1 << j)) ? 1 : 0; rep(j, n){ if(!(i & (1 << j))) continue; tmp = count(j, n); if(tmp == -1) break; } ans = max(ans, tmp); //cout << endl; //for(auto x : l) cout << x << " "; cout << endl; } cout << ans << endl; return 0; }
#include<iostream> #include<vector> #include<map> #include<numeric> using namespace std; int mypow(int x, int y); vector<int> my_bit(int n, int keta); int main(){ map<int, vector<pair<int, int>>> shogen; int N, A, x, y, n, sum_; int ans = 0; pair<int, int> p; //インプット std::cin >> N; vector<int> pattern(N); for(int i = 0; i < N; i++){ //この時点で人名は-1されていく std::cin >> A; shogen[i] = {}; for(int j = 0; j < A; j++){ std::cin >> x >> y; p = std::make_pair(x - 1, y); if(shogen.count(i)){ shogen[i].push_back(p); } } } //インプット終了 // std::cout << N; std::map<int, vector<pair<int, int>>>::iterator iter; // std::cout << shogen.size() << "\n"; // for(int i = 0 ; shogen.size(); i++){ // std::cout << iter->first << "\n"; // for(int j = 0; j < iter->second.size(); j++){ // std::cout << iter->second[j].first << " " << iter->second[j].first << "\n"; // } // iter++; // } for(int i = 0; i < mypow(2, N); i++){ pattern = my_bit(i, N); iter = shogen.begin(); for(int j = 0; j < N; j++){ //全員の証言を見ていく n = iter->second.size(); for(int k = 0; k < n; k++){ //証言を順番に見ていく if(iter->second[k].second != pattern[iter->second[k].first]){ //ここに入ると嘘つき if(pattern[j] == 1){ //なのにいい人だとおかしいのでそのパターンはなし。 goto ptn_end; } } } iter++; } //やり終えたら次のパタンに行く前に集計、いい人が保持値より多ければ答えを更新 sum_ = std::accumulate(pattern.begin(), pattern.end(),0); if(sum_ > ans){ ans = sum_; } ptn_end: ; } std::cout << ans; } vector<int> my_bit(int n, int keta){ int n_loop = 0;//桁数 int bit_buff; double d_n = (double)n; //最大桁を算出 while(d_n >= 1.0){ n_loop++; d_n = d_n/2.0; } vector<int> ans(n_loop); //割ってこう for(int i =0; i < n_loop; i++){ bit_buff = mypow(2, (n_loop - 1 -i)); if(n >= bit_buff){ ans[i] = 1; n = n - bit_buff; } } ans.insert(ans.begin(), keta - ans.size(), 0); return ans; } int mypow(int x, int y){ int ans = 1; for(int i = 0; i < y; i++){ ans = ans * x; } return ans; }
1
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define per(i,a,b) for(int i=(a);i>=(b);i--) #define REP(i,n) for(int i=0;i<(n);i++) #define fi first #define se second #define pb push_back #define mp make_pair using namespace std; typedef pair<int,int> pii; typedef vector<int> vi; typedef long long ll; template<class T> void read(T &x){ int f=0; x=0; char ch=getchar(); for(;!isdigit(ch);ch=getchar()) f|=(ch=='-'); for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0'; if(f) x=-x; } const int N=305,mod=998244353; int f[N][N][N<<1],g[N][N<<1],h[N][N<<1]; int a[N],b[N],n,m=1,K; char s[N]; void add(int &x,int y){ x=(x+y>=mod?x+y-mod:x+y); } int main(){ scanf("%s",s+1),read(K); n=strlen(s+1),K=min(K,n); for(int i=1;i<=n+1;i++,m++){ for(;i<=n&&s[i]!='0';i++,a[m]++); b[m]=b[m-1]+a[m]; } m--; f[0][0][0]=1; rep(i,1,m){ memset(g,0,sizeof g); memset(h,0,sizeof h); rep(j,b[i-1],b[m]){ rep(k,0,K*2){ if(f[i-1][j][k]){ if(j+a[i]<=b[m]){ add(g[j+a[i]][k],f[i-1][j][k]); } if(a[i]){ int t=max(0,j+a[i]-1-b[m]); add(h[j+a[i]-1-t][k+1+t],f[i-1][j][k]); if(j) add(h[j-1][k+a[i]+1],mod-f[i-1][j][k]); } } } } rep(j,b[i-1],b[m]-1){ rep(k,0,K*2){ add(g[j+1][k+1],g[j][k]); } } per(j,b[m],b[i-1]+1){ rep(k,0,K*2){ add(h[j-1][k+1],h[j][k]); } } rep(j,b[i],b[m]){ rep(k,0,K*2){ add(f[i][j][k],g[j][k]); add(f[i][j][k],h[j][k]); } } } int ans=0; rep(i,0,K*2){ add(ans,f[m][b[m]][i]); } cout<<ans<<endl; return 0; }
#include<iostream> #define LL long long #define INF 0x7fffffff; using namespace std; const int maxn=500010; int a[maxn]; int L[maxn/2+2],R[maxn/2+2]; int n; LL merge(int left,int mid ,int right){ int n1=mid-left; int n2=right-mid; for(int i=0;i<n1;i++)L[i]=a[left+i]; for(int i=0;i<n2;i++)R[i]=a[mid+i]; int i=0,j=0; L[n1]=R[n2]=INF; LL s=0; for(int k=left;k<right;k++){ if(L[i]<=R[j]) a[k]=L[i++]; else{ a[k]=R[j++]; s+=n1-i; } } return s; } LL mergesort(int left,int right ){//[left,right) LL c1,c2,c3; if(left+1<right){//避免死循? int mid=(left+right)/2; c1=mergesort(left,mid); c2=mergesort(mid,right); c3=merge(left,mid,right); return c1+c2+c3; } else return 0; } int main(){ cin>>n; for(int i=0;i<n;i++)cin>>a[i]; cout<<mergesort(0,n)<<endl; return 0; }
0
#include <bits/stdc++.h> #define N_MAX 200002 #define Q_MAX 200002 #define ll long long using namespace std; const ll INF = 1000000000000000; int n, q, a, b; int pos[Q_MAX]; struct SGTNode { ll mindp; ll min1, min2; ll lazy; }; SGTNode dp[N_MAX * 3]; void split (int node) { int lson = (node << 1), rson = (lson | 1); dp[lson].mindp += dp[node].lazy; dp[lson].min1 += dp[node].lazy; dp[lson].min2 += dp[node].lazy; dp[lson].lazy += dp[node].lazy; dp[rson].mindp += dp[node].lazy; dp[rson].min1 += dp[node].lazy; dp[rson].min2 += dp[node].lazy; dp[rson].lazy += dp[node].lazy; dp[node].lazy = 0; } SGTNode join (SGTNode a, SGTNode b) { SGTNode ans; ans.mindp = min(a.mindp, b.mindp); ans.min1 = min(a.min1, b.min1); ans.min2 = min(a.min2, b.min2); ans.lazy = 0; return ans; } void update (int node, int l, int r, int ul, int ur, ll val) { if(ul <= l && r <= ur) { dp[node].mindp += val; dp[node].min1 += val; dp[node].min2 += val; dp[node].lazy += val; return; } int mid = (l + r) / 2, lson = (node << 1), rson = (lson | 1); split(node); if(ul <= mid) update(lson, l, mid, ul, ur, val); if(mid + 1 <= ur) update(rson, mid + 1, r, ul, ur, val); dp[node] = join(dp[lson], dp[rson]); } void update1 (int node, int l, int r, int pos, ll val) { if(l == r) { dp[node].mindp = val; dp[node].min1 = val - pos; dp[node].min2 = val + pos; return; } int mid = (l + r) / 2, lson = (node << 1), rson = (lson | 1); split(node); if(pos <= mid) update1(lson, l, mid, pos, val); if(mid + 1 <= pos) update1(rson, mid + 1, r, pos, val); dp[node] = join(dp[lson], dp[rson]); } SGTNode query (int node, int l, int r, int ql, int qr) { if(ql <= l && r <= qr) return dp[node]; int mid = (l + r) / 2, lson = (node << 1), rson = (lson | 1); split(node); if(ql <= mid && mid + 1 <= qr) return join(query(lson, l, mid, ql, qr), query(rson, mid + 1, r, ql, qr)); else if(ql <= mid) return query(lson, l, mid, ql, qr); else return query(rson, mid + 1, r, ql, qr); } int main() { cin >> n >> q >> a >> b; for(int i = 1; i <= q; i++) cin >> pos[i]; pos[0] = a; for(int i = 1; i < N_MAX * 3; i++) dp[i].min1 = dp[i].min2 = dp[i].mindp = INF; update1(1, 1, n, b, 0); for(int i = 1; i <= q; i++) { ll diff = abs(pos[i] - pos[i - 1]); ll mi = min(query(1, 1, n, pos[i], pos[i]).mindp + diff, min(query(1, 1, n, 1, pos[i]).min1 + pos[i], query(1, 1, n, pos[i], n).min2 - pos[i])); if(pos[i - 1] - 1 >= 1) update(1, 1, n, 1, pos[i - 1] - 1, diff); if(pos[i - 1] + 1 <= n) update(1, 1, n, pos[i - 1] + 1, n, diff); update1(1, 1, n, pos[i - 1], mi); update1(1, 1, n, pos[i], INF); } cout << dp[1].mindp << "\n"; return 0; }
#include <bits/stdc++.h> #define de(x) cout << #x << '=' << x << ", " #define dd cout << '\n'; #define XinAi ios::sync_with_stdio(0), cin.tie(0); #define rep(i,j,k) for (int i=j; i<=k; i++) #define S second #define F first #define int long long using namespace std; typedef pair<int,int> pii; const int N = 2e5+10; /* dp[i][j] = dp[i-1][j] + |x[i]-x[i-1]| dp[i][x[i-1]] = min(dp[i][x[i-1]], min(dp[i-1][k] + |k-x[i]|, k=1~n)) owo = dp[i-1][k] + |k-x[i]|, k=1~n k=1~x[i]: owo = dp[i-1][k] + x[i] - k; k=x[i]~n: owo = dp[i-1][k] + k - x[i]; sta[j], dp[i][j]-j stb[j], dp[i][j]+j dp[b]=0 */ int n, q, x[N], b; struct ST { int st[N<<2], lz[N<<2]; //lz: not cover to subnodes, st: merge subnode + lazy inline void init() { memset(st,0x3f,sizeof(st)); } inline void setto (int u, int l, int r, int p, int v) { if (r<p || p<l) return; else if (l==p && p==r) st[u]=v; else { int m = (l+r)/2; setto(u<<1,l,m,p,v-lz[u]); setto(u<<1|1,m+1,r,p,v-lz[u]); st[u] = min(st[u<<1], st[u<<1|1])+lz[u]; } } inline void add (int u, int l, int r, int ql, int qr, int v) { if (r<ql || qr<l) return; else if (ql<=l && r<=qr) st[u]+=v,lz[u]+=v; else { int m = (l+r)/2; add(u<<1,l,m,ql,qr,v); add(u<<1|1,m+1,r,ql,qr,v); st[u] = min(st[u<<1], st[u<<1|1])+lz[u]; } } inline int query (int u, int l, int r, int ql, int qr) { if (r<ql || qr<l) return 1e18; else if (ql<=l && r<=qr) return st[u]; else { int m = (l+r)/2; return min(query(u<<1,l,m,ql,qr), query(u<<1|1,m+1,r,ql,qr)) + lz[u]; } } } sta, stb; void test () { int n, t, l, r, a; cin >> n; while (cin >> t >> l >> r) { if (t==0) sta.setto(1,1,n,l,r); if (t==1) cin >> a, sta.add(1,1,n,l,r,a); if (t==2) cout << sta.query(1,1,n,l,r) << '\n'; } } void print () { int dp, dp_min_i, dp_add_i; rep(i,1,n) { dp = sta.query(1,1,n,i,i)+i; dp_min_i = sta.query(1,1,n,i,i); dp_add_i = stb.query(1,1,n,i,i); de(i), de(dp), de(dp_min_i), de(dp_add_i), dd; } dd } signed main() { XinAi cin >> n >> q >> x[0] >> b; rep(i,1,q) cin >> x[i]; sta.init(), stb.init(); sta.setto(1,1,n,b,-b), stb.setto(1,1,n,b,b); //print(); rep(i,1,q) { int owo = min(sta.query(1,1,n,1,x[i])+x[i], stb.query(1,1,n,x[i],n)-x[i]); sta.add(1,1,n,1,n,abs(x[i]-x[i-1])); stb.add(1,1,n,1,n,abs(x[i]-x[i-1])); int qwq = sta.query(1,1,n,x[i-1],x[i-1])+x[i-1]; if (owo < qwq) { sta.setto(1,1,n,x[i-1],owo-x[i-1]); stb.setto(1,1,n,x[i-1],owo+x[i-1]); } //de(i), de(owo), de(qwq), de(owo-x[i-1]), de(owo+x[i-1]), dd print(); } int res=9e18; rep(i,1,n) res = min(res, sta.query(1,1,n,i,i)+i); cout << res << '\n'; }
1
#include <iostream> using namespace std; int hi[101]; int main() { int a, b; cin >> a >> b; while (a != 0 || b != 0) { int no = 0, yes = 0; for (int i = 1; i <= 101; i++) hi[i] = 0; for (int i = 0; i < a; i++) { int x; cin >> x; for (int o = 0; o < x; o++) { int yay; cin >> yay; hi[yay]++; } } for (int i = 101; i > 0; i--) { if (yes <= hi[i] && hi[i] >= b) { no = i; yes = hi[i]; } } cout << no << endl; cin >> a >> b; } }
#include <atcoder/fenwicktree> #include <bits/stdc++.h> using namespace std; using ll = long long; ll solve() { ll N, Q, t, a; cin >> N >> Q; atcoder::fenwick_tree<ll> ft(N); for ( int i = 0; i < N; i++ ) { cin >> a; ft.add(i, a); } vector<ll> ans; for ( int q = 0; q < Q; q++ ) { cin >> t; if ( t == 0 ) { ll p, x; cin >> p >> x; ft.add(p,x); } else { ll l, r; cin >> l >> r; ans.push_back(ft.sum(l,r)); } } for ( auto a : ans ) { cout << a << "\n"; } return 0; } int main() { solve(); 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>; #define chmax(x,y) x = max(x,y); #define chmin(x,y) x = min(x,y); const int di[] = {-1, 0, 1, 0}; const int dj[] = {0, -1, 0, 1}; const int INF = 1001001001; int main() { int n; cin >> n; vector<ll> a(n); rep(i,n) cin >> a[i]; int c = 0; rep(i,n) { if (a[i] < 0) c ^= 1; } ll ans = 0; rep(i,n) ans += abs(a[i]); if (c) { ll mn = 1e10; rep(i,n) { mn = min(mn, abs(a[i])); } ans -= mn*2; } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> #include <math.h> #include <set> #include <map> #include <string> #include <stack> #include <queue> #include <iomanip> #include <numeric> #include <tuple> #include <bitset> #include <complex> #include <unistd.h> #include <cassert> #include <cctype> #include <random> #include <time.h> #define _USE_MATH_DEFINES #define _GLIBCXX_DEBUG using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> plglg; typedef pair<double, ll> pdlg; typedef tuple<int, int, int> tiii; typedef tuple<ll, ll, ll> tlglglg; typedef tuple<double, double, double> tddd; typedef complex<double> xy_t; typedef vector<ll> vll; typedef vector< vector<ll> > matrix; #define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++) #define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d) #define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--) #define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d) int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; double pi = 3.141592653589793; ll mod = 998244353; int intmax = 2147483647; int intmin = -2147483648; ll llmax = 9223372036854775807; ll llmin = -9223372036854775807; int iinf = intmax / 8; ll inf = llmax / 8; double eps = 1e-12; ll modadd(ll x, ll y) { return ((x + y) % mod + mod) % mod; } ll modminus(ll x, ll y) { return (x - y + mod) % mod; } ll multiply(ll x, ll y) { return (x % mod) * (y % mod) % mod; } ll modpower(ll x, ll y) { if (y == 0) { return 1; } else if (y == 1) { return x % mod; } else if (y % 2 == 0) { ll p = modpower(x, y / 2); return p * p % mod; } else { ll p = modpower (x, y / 2); return (p * p) % mod * (x % mod) % mod; } } ll dp[310][90010]; ll dpb[310][90010]; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; ll a[N]; ll sum = 0; REP(i, 0, N) { cin >> a[i]; sum += a[i]; } dp[0][0] = 1; dpb[0][0] = 1; REP(i, 0, N) { REP(j, 0, 90000) { dp[i + 1][j] = modadd(dp[i + 1][j], multiply(dp[i][j], 2)); dpb[i + 1][j] = modadd(dpb[i + 1][j], dpb[i][j]); if (j + a[i] <= 90000) { dp[i + 1][j + a[i]] = modadd(dp[i + 1][j + a[i]], dp[i][j]); dpb[i + 1][j + a[i]] = modadd(dpb[i + 1][j + a[i]], dpb[i][j]); } } } ll dis = 0; ll disa = 0; REP(i, (sum + 1) / 2, sum) { dis = modadd(dis, dp[N][i]); } dis = multiply(dis, 3); if (sum % 2 == 0) { disa = dpb[N][sum / 2]; } disa = multiply(disa, 3); ll base = modadd(modpower(3, N), -3); ll ans = modadd(base, - modadd(dis, - disa)); cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define pl pair<ll, ll> #define vl vector<ll> #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL); int main() { ll n;cin>>n; ll a[n]; for(ll i=0;i<n;i++) cin>>a[i]; map<ll,ll>m;ll cnt=0; for(ll i=0;i<n;i++) { if(m[a[i]]==0) { cnt+=1;m[a[i]]+=1; } else if(m[a[i]]>0) { cnt-=1;m[a[i]]-=1; } } cout<<cnt<<"\n"; }
#include <iostream> #include <math.h> #include <algorithm> #include <string> #include <map> #include <vector> #include <cmath> using namespace std; void c_write_and_erase(void) { int n; cin >> n; map<long long, int>a; long long ain; for (int i = 0; i < n; i++) { cin >> ain; if (a.count(ain)) { a[ain]++; } else { a.insert(make_pair(ain, 1)); } } int cnt = 0; map<long long, int>::iterator aptr = a.begin(); for (aptr; aptr!=a.end(); aptr++) { if ((aptr->second) % 2 == 1) cnt++; } cout << cnt << endl; } int main() { c_write_and_erase(); return 0; }
1
#include <bits/stdc++.h> // iostream is too mainstream #include <cstdio> // bitch please #include <iostream> #include <algorithm> #include <cstdlib> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <cmath> #include <iomanip> #include <time.h> #define dibs reserve #define OVER9000 1234567890 #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++) #define tisic 47 #define soclose 1e-8 #define chocolate win // so much chocolate #define patkan 9 #define ff first #define ss second #define abs(x) (((x) < 0)?-(x):(x)) #define uint unsigned int #define dbl long double #define pi 3.14159265358979323846 using namespace std; // mylittledoge using cat = long long; #ifdef DONLINE_JUDGE // palindromic tree is better than splay tree! #define lld I64d #endif cat gcd(cat x, cat y) { if(x > y) swap(x, y); return (x == 0) ? y : gcd(y%x, x); } cat lcm(cat x, cat y) { return x / gcd(x, y) * y; } int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int N; cin >> N; vector< vector<cat> > A(N, vector<cat>(N, 1)); vector<int> P; for(int p = 4; ; p++) { bool is_prime = true; for(int i = 2; i*i <= p; i++) is_prime &= (p%i != 0); if(!is_prime) continue; P.push_back(p); if((int)P.size() == N+10) break; } for(int i = 0; i < N; i += 2) for(int j = 0; j < N; j += 2) A[i][j] = P[i/2] * P[N/2+1+j/2]; for(int i = 1; i < N; i += 2) for(int j = 1; j < N; j += 2) A[i][j] = 3 * A[i-1][j-1]; for(int i = 0; i < N; i++) for(int j = 1-(i&1); j < N; j += 2) { if(i > 0) A[i][j] = lcm(A[i][j], A[i-1][j]); if(j > 0) A[i][j] = lcm(A[i][j], A[i][j-1]); if(i+1 < N) A[i][j] = lcm(A[i][j], A[i+1][j]); if(j+1 < N) A[i][j] = lcm(A[i][j], A[i][j+1]); if(j&1) A[i][j] *= 2; A[i][j]++; } for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) cout << A[i][j] << ((j == N-1) ? "\n" : " "); return 0; } // look at my code // my code is amazing
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; using vint = vector<int>; using vvint = vector<vint>; using vll = vector<ll>; using vvll = vector<vll>; using vchar = vector<char>; using vvchar = vector<vchar>; using vp = vector<P>; using vpp = vector<pair<P, P>>; using vvp = vector<vp>; #define rep(i, n) for (int i = 0; i < n; ++i) P bounds = P(0, 0); void rot(vp *up, vp *down, vp *left, vp *right) { vector<vp *> vecs = {up, down, left, right}; rep(i, 4) { vp *a = vecs[i]; rep(j, (*a).size()) { P now = (*a)[j]; (*a)[j] = P(now.second, -now.first + bounds.first); } } swap(bounds.first, bounds.second); swap(*down, *left); swap(*down, *up); swap(*down, *right); } bool comp(P l, P r) { return (l.first + l.second) < (r.first + r.second); } const ll INF = 1e10 + 5; int main() { int n; cin >> n; vp up, down, left, right; rep(i, n) { int x, y; char u; cin >> x >> y >> u; P p = P(x, y); if (p.first > bounds.first) { bounds = P(p.first, bounds.second); } if (p.second > bounds.second) { bounds = P(bounds.first, p.second); } if (u == 'U') { up.emplace_back(p); } else if (u == 'D') { down.emplace_back(p); } else if (u == 'R') { right.emplace_back(p); } else if (u == 'L') { left.emplace_back(p); } } ll ans = INF; rep(i, 4) { map<int, vp> m; for (P p : up) { int sum = p.first + p.second; m[sum].emplace_back(P(p.second, 0)); } for (P p : right) { int sum = p.first + p.second; m[sum].emplace_back(P(p.second, 1)); } for (auto x : m) { vp b = x.second; sort(b.begin(), b.end()); rep(j, b.size() - 1) { if (!b[j].second && b[j + 1].second) { // collision between up and right // not b[j].second && !b[j].second because we sorted by Y coords ll now = b[j + 1].first - b[j].first; now *= 10; ans = min(ans, now); break; } } } map<int, vp> q; for (P p : up) { q[p.first].emplace_back(P(p.second, 0)); } for (P p : down) { q[p.first].emplace_back(P(p.second, 1)); } for (auto x : q) { vp b = x.second; sort(b.begin(), b.end()); rep(j, b.size() - 1) { if (!b[j].second && b[j + 1].second) { ll now = b[j + 1].first - b[j].first; now *= 5; ans = min(ans, now); break; } } } rot(&up, &down, &left, &right); } if (ans == INF) { cout << "SAFE" << endl; } else { cout << ans << endl; } return 0; }
0
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <queue> #include <cmath> #include <climits> #include <iomanip> #include <set> #include <map> using namespace std; typedef long long ll; int main(){ ll n; cin >> n; string s = to_string(n); ll wa = 0; for(int i = 0;i < (int)s.size();i++){ wa += s[i] - '0'; } if(n % wa == 0)cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int S = 0; int a = 1; for (int i =0; i < 9; i++) { int x; a *= 10; x = (N % a - N % (a/10)) / (a/10); S += x; } if (N % S == 0){ cout << "Yes"; } else { cout << "No"; } }
1
#include <cmath> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <vector> #include <map> #include<cstdio> #include<functional> #include <bitset> #include <iomanip> #define rep(i, n) for (int i = 0; i < (n); i++) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define repr(i, n) for(int i = n; i >= 0; i--) #define ll long long using namespace std; template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } const ll INF = 1000000000000000000; const ll MOD = 1e9 + 7; int gcd(int a, int b) { if (a%b == 0) { return(b); } else { return(gcd(b, a%b)); } } int lcm(int a, int b) { return a * b / gcd(a, b); } int main() { int n; cin >> n; vector<int> wl(n); vector<int> el(n); string s; cin >> s; rep(i, n) { if (i - 1 >= 0) { wl[i] = wl[i - 1]; el[i] = el[i - 1]; } if (s[i] == 'W') { wl[i]++; } else{ el[i]++; } } int ans = 1000000000; rep(i, n) { int ec = 0; int wc = 0; if (i - 1 > 0) { wc = wl[i - 1]; } ec = el[el.size() - 1] - el[i]; ans = min(ans, ec + wc); } cout << ans << endl; //cout << fixed << setprecision(10) << ans << endl; system("pause"); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define MIN(a, b) ((a) > (b) ? (b) : (a)) #define MAX(a, b) ((a) < (b) ? (b) : (a)) const long long INF = 1LL << 60; typedef unsigned long long ll; const long long MOD = 1000000000 + 7; int main() { int n; cin >> n; string s; cin >> s; int east[n], west[n]; rep(i, n) west[i] = 0; if (s[0] == 'W') west[0] = 1; else west[0] = 0; for (int i = 1; i < n; ++i) { if (s[i] == 'W') west[i] = west[i - 1] + 1; else west[i] = west[i - 1]; } if (s[n - 1] == 'E') east[n - 1] = 1; else east[n - 1] = 0; for (int i = n - 2; i >= 0; --i) { if (s[i] == 'E') east[i] = east[i + 1] + 1; else east[i] = east[i + 1]; } int cnt = n; rep(i, n) { if (east[i] + west[i] < cnt) { cnt = east[i] + west[i]; } } cout << cnt - 1 << endl; return 0; }
1
#include <iostream> #include <algorithm> #include <vector> #include <stack> #include <string> #include <queue> #include <cmath> #include <numeric> #include <list> #include <sstream> #include <fstream> #include <iomanip> #include <climits> #include <set> #include <memory.h> #include <memory> #include <cstdio> #include <cstdlib> #include <cctype> #include <map> #include <cassert> #define _USE_MATH_DEFINES using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> PP; typedef vector<int> vec; typedef vector<vec> mat; const int INF = 1 << 30; const double EPS = 1e-9; int nums[200]; int main(){ int n, q; while(cin >> n >> q && (n || q)){ fill(nums, nums + 200, 0); for(int i = 0; i < n; i++){ int num, date; cin >> num; for(int j = 0; j < num; j++){ cin >> date; nums[date]++; } } int t = -1; int id = 0; vector<int> res; for(int i = 0; i < 200; i++){ if(nums[i] >= q){ if(nums[i] > t){ t = nums[i]; id = i; } } } if(t == -1){ cout << 0 << endl; }else{ cout << id << endl; } } return 0; }
#include <stdio.h> #include <math.h> #include <stdlib.h> int main(){ int N,Q,M,Date[101],i,l,k; while(0<=scanf("%d%d",&N,&Q)){ for(i=0;i<101;i++){ Date[i]=0; } if((N==0) && (Q==0)){ break; } for(k=0;k<N;k++){ scanf("%d",&M); if(M==0){ continue; }else{ for(i=0;i<M;i++){ scanf("%d",&l); ++Date[l]; } } } l=0; i=0; for(k=0;k<100;k++){ if(i<Date[k] && Date[k]>=Q){ i=Date[k]; l=k; } } printf("%d\n",l); } return 0; }
1