solution
stringlengths
52
181k
difficulty
int64
0
6
#include<iostream> using namespace std; int main(){ int n=0; int a=0; int b=0; int k=0; int c[101]; int i=0; int j=0; int t=0; int w=0; int wa=0; int s=0; cin>>n; cin>>a; cin>>b; cin>>k; for(i=0;i<101;i++){ c[i]=0; } for(i=0;i<n;i++){ cin>>c[i]; } wa=k; t=k/a; for(i=0;i<n;i++){ for(j=0;j<...
0
#include <bits/stdc++.h> using namespace std; int n, m, b, g, x[11111], y[11111]; int main() { cin >> n >> m >> b; for (int i = 0; i < b; i++) { int A; cin >> A; x[A] = 1; } cin >> g; for (int i = 0; i < g; i++) { int A; cin >> A; y[A] = 1; } int j = 0, i = 0; for (int k = 0; k <...
5
#include<iostream> #include<cstdio> using namespace std; short dp[5001][5001]; int n,m; short max2(short a,short b){ if(a>b)return a; return b; } int main(void){ scanf("%d%d",&n,&m); for(int i=0;i<m;i++){ int a,b,x; scanf("%d%d%d",&b,&a,&x); a--,b--; dp[a][b]=max2(dp[a][b],x+1); } int cnt=0; for(int...
0
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <string> #include <map> #include <queue> #include <stack> #include <algorithm> #define rep(i,j) REP((i), 0, (j)) #define REP(i,j,k) for(int i=(j);(i)<(k);++i) #define between(a,x,b) ((a)<=(x)&&(x)<=(...
0
#include <bits/stdc++.h> int main() { char genome[256]; int i, n, base, count[5]; scanf("%d", &n); scanf("%s", genome); if (n % 4 == 0) { base = n / 4; count[0] = count[1] = count[2] = count[3] = count[4] = 0; for (i = 0; i < n; i++) { switch (genome[i]) { case 'A': count[0...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 100100; const int mod = 998244353; int u[maxn], s[maxn]; int a[maxn], b[maxn], c[maxn]; int val[maxn]; int find(int x){ if(x == u[x]) return x; return u[x] = find(u[x]); } void join(int x, int y){ x = find(x); y = find(y); if(x^y){ s[x] += s[y]; s...
0
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; int arr[n]; int i; for (i = 0; i < n; i++) scanf("%d", &arr[i]); int round = (n - arr[0]) % n; for (i = 0; i < n; i++) { if (i & 1) { arr[i] = (arr[i] - round) % n; if (arr[i] < 0) arr[i] += n; } else ...
2
#include<bits/stdc++.h> using namespace std; int main(){ int a,b; cin>>a>>b; int h,w; h=w=100; cout<<h<<" "<<w<<endl; char ma[100][100]; for(int i=0;i<100;i++) for(int j=0;j<100;j++) if(i<50)ma[i][j]='.'; else ma[i][j]='#'; for(int i=0;i/2<b-1;i+=2)ma[2*(i/100)][i%100]='#'; for(int i=...
0
#include <bits/stdc++.h> using namespace std; const int logn = 30; class Trie { public: Trie() { nodes.push_back(Node()); } void Add(int x) { int cur = 0; for (int i = logn - 1; i >= 0; --i) { int b = (x >> i) % 2; nodes[cur].size++; if (nodes[cur].ne[b] == -1) { nodes.push_back(N...
3
#include <bits/stdc++.h> using namespace std; using li = long long; using ld = long double; void solve(bool); int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20); solve(true); return 0; } const int inf = 1e9; const int maxn = 6e5 + 55; int tsz, n, m, q; vector<pa...
3
#include <bits/stdc++.h> using namespace std; int mod = 998244353; long long dp[300005][3]; vector<int> v[300005]; long long f_pow(long long a, long long b) { long long res = 1, temp = a; while (b) { if (b & 1) res = res * temp % mod; temp = temp * temp % mod; b >>= 1; } return res; } void dfs(int f...
3
#include <bits/stdc++.h> using namespace std; int B(int n, vector<int> &a) { int mid, diff; set<int> num(a.begin(), a.end()); sort(a.begin(), a.end()); if (num.size() == 1) return 0; else if ((num.size() == 2) && ((a[0] + a[n - 1]) & 1)) return a[n - 1] - a[0]; mid = (a[0] + a[n - 1]) / 2; diff = ...
2
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, const U &b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, const U &b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c = getchar(), ...
3
#include <bits/stdc++.h> using namespace std; double c[55][55]; double p[55][55][55]; double dp[55][55][55]; int n, m, a[55]; void make_c() { for (int i = 0; i <= 50; i++) { for (int j = 0; j <= 50; j++) c[i][j] = 0; c[i][0] = 1; for (int j = 1; j <= i; j++) c[i][j] = c[i - 1][j - 1] + c[i - 1][j]; } } ...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, c = 0, d = 0, e = 0, f = 0; cin >> n; string a, b; cin >> a >> b; for (int i = 0; i < n; i++) { if (a[i] == '1') c++; if ((a[i] == '0') && (b[i] == '0')) d++; if (a[i] =...
2
#include <bits/stdc++.h> using namespace std; const int N = 200010, Mod = 1e9 + 7; long long n, a[N], x, f, ans; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; cin >> x >> f; for (int i = 0; i < n; i++) ans += (a[i] + f - 1) / (x + f) * f; cout << ans; }
6
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long factorial[10002]; long long power(long long a, long long b) { long long x = 1, y = a; while (b > 0) { if (b % 2) { x = (x * y) % mod; } y = (y * y) % mod; b /= 2; } return x % mod; } long long inverse[40...
2
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T& x) { x = 0; int fl = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') fl = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); } x ...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int mod = 1e9 + 7; int read() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0', c = getchar(); return ...
5
#include <bits/stdc++.h> using namespace std; #pragma GCC optimizer("O3") int main() { int t; cin >> t; while (t--) { int x, y, a, b; cin >> x >> y >> a >> b; int del = (y - x) / (a + b); if (del * (a + b) == y - x) { cout << del << "\n"; } else { cout << -1 << "\n"; } } }
1
#include <bits/stdc++.h> using namespace std; long long int N; int main(){ scanf("%lld", &N); puts(N / 10 % 111 && N % 1000 % 111 ? "No" : "Yes"); return 0; }
0
#include <bits/stdc++.h> using namespace std; struct IO { IO() {} inline bool is(char c) { return c >= '0' && c <= '9'; } inline int read() { char c; while (!is(c = getchar())) ; int num = c - '0'; while (is(c = getchar())) num = num * 10 + c - '0'; return num; } inline void out(int ...
5
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; long long a[N], p[N], s[N]; long long ans = 0; int n, k, x; signed main() { cin >> n >> k >> x; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) { p[i] = (i ? p[i - 1] | a[i] : a[i]); } for (int i = n - 1; i >= 0; --...
2
#include <bits/stdc++.h> using namespace std; const double eps = 1e-7; const double pi = acos(-1.0); const int inf = 0x3f3f3f3f; inline long long read() { long long f = 1, x = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { ...
3
#include <bits/stdc++.h> using namespace std; bool digits[10][7] = {{1, 1, 1, 0, 1, 1, 1}, {0, 0, 1, 0, 0, 1, 0}, {1, 0, 1, 1, 1, 0, 1}, {1, 0, 1, 1, 0, 1, 1}, {0, 1, 1, 1, 0, 1, 0}, {1, 1, 0, 1, 0, 1, 1}, {1, 1, 0, 1, 1, 1, 1}, {1, 0, 1, 0, 0, 1, 0}, ...
1
#include <bits/stdc++.h> using namespace std; long long int containsDigit(long long int number, long long int digit) { while (number != 0) { int curr_digit = number % 10; if (curr_digit == digit) return 1; number /= 10; } return 0; } long long int soltn(long long int x, long long int n) { if (x >= 0...
1
#define _CRT_SECURE_NO_WARNINGS #include"bits/stdc++.h" #ifdef _DEBUG #define DBG(n) n #else #define DBG(n) #endif #define INF 1e9 #define INFLL 1e18 #define EPS 1e-9 #define REP(i,n) for(ll i=0,i##_len=(n);i<i##_len;++i) #define REP1(i,n) for(ll i=1,i##_len=(n);i<=i##_len;++i)...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s, t; cin >> s >> t; vector<int> moves; for (int i = 0; i < (int)(n); ++i) { char c = t[n - 1 - i]; int x = -1; for (int j = i; j < n; j++) { if (s[j] == c) { ...
3
#include <bits/stdc++.h> const int maxn = 2e5 + 10; const int inf = 0x3f3f3f3f; const double eps = 1e-7; const int mod = 1e9 + 7; const double pi = acos(-1.0); using namespace std; vector<int> p[27]; int vis[maxn]; int main() { int n; cin >> n; string a, t; cin >> t; for (int i = 1; i <= n; i++) a += t; for...
3
#include <bits/stdc++.h> using namespace std; using ll = long long int; #define rep(i, n) for(int i=0; i<(int)(n); ++i) const int M = 1e9 + 7; ll mod_pow(ll a, ll b) { ll ans = 1; while (b){ if (b&1) ans = ans * a % M; a = a * a % M; b >>= 1; } return ans; } int main() { ios::sync_with_stdio(false); cin.ti...
0
#include <bits/stdc++.h> using namespace std; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { return s | (T(1) << i); } template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); } template <class T> int cntbit(T s) { return __builtin_popcoun...
5
#include <bits/stdc++.h> using namespace std; const long long linf = 1e18 + 9; const int inf = 1e9 + 9; const int N = 3e3 + 9; int dp[N][N]; int hash[N][N], h[N]; int d[N][N], d2[N][N]; string str, ans, ans2; void print() { int bas = 0, son = str.size() - 1; while (bas <= son) { if (bas == son) { ans += s...
2
#include <bits/stdc++.h> using namespace std; struct T { int x; T() { x = -1; } T(int _x) { x = _x; } }; T operator+(const T &L, const T &R) { if (L.x == -1) return R; if (R.x == -1) return L; return T(L.x | R.x); } T operator-(const T &L, const T &R) { if (L.x == -1) return R; if (R.x == -1) return L; ...
4
#include <bits/stdc++.h> using namespace std; int n, a[15] = {0}, b[15] = {0}, x, ans[105] = {0}; vector<int> v; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x; a[x]++; } for (int i = 0; i < n; i++) { cin >> x; b[x]++; } int cnt = 0, flag = 0; for (int i = 1; i <= 5; i++) { ...
1
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <iostream> #include <complex> #include <string> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <functional> #include <cas...
0
/** * author: milos * created: 11.04.2021 16:53:22 **/ #include <bits/stdc++.h> using namespace std; template <typename T> T inverse(T a, T m) { T u = 0, v = 1; while (a != 0) { T t = m / a; m -= t * a; swap(a, m); u -= t * v; swap(u, v); } assert(m == 1); return u; } template <...
2
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1.0); const int K = 1e5 + 7; const int mod = 1e9 + 7; int n, m, q, f[K], rl[K]; map<string, int> hs; string sa, sb; int fd(int x) { if (f[x] == x) return x; int fa = f[x]; f[x] = fd(f[x]); rl[x] = (rl[x] + rl[fa]) % 2...
4
#include<iostream> using namespace std; int main(){ long long n,nmon; long long sum=0,avr; cin>>n; for(int i=0;i<n;i++){ cin>>nmon; sum+=nmon; } avr=sum/n; cout<<avr<<endl; return 0; }
0
#include<iostream> using namespace std; int l; string a; int main() { cin>>a; l=a.size(); cout<<a[0]<<l-2<<a[l-1]; }
0
#include <bits/stdc++.h> const int N = 1000010; using ll = long long; using pii = std::pair <ll, ll>; template <typename T> void read(T &n){ char ch; while (!isdigit(ch = getchar())) ; n = ch - '0'; while (isdigit(ch = getchar())){ n = n * 10 + ch - '0'; } } struct Treap{ #define ...
5
#include<iostream> #include<cstdio> using namespace std; int main() { int n, b, sum2; float y, r, t, joe; float sum = 0, math, s, d; while (1) { scanf("%d", &n); if (n == 0)return 0; cin >> y; for (int i = 0; i < n; i++) { cin >> b >> r >> t; if (t == 1) { math = 10000 * (1 + y*(r / 100)); s =...
0
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int n, sum1[100050...
3
#include <iostream> #include <algorithm> #include <cstdio> #include <vector> #include <queue> using namespace std; typedef pair<int,int> pii; struct Situation{ public: pii cost; int node; int rev; Situation(pii cost_,int node_,int rev_){ cost=cost_; node=node_; rev=rev_; } Situation(); bool ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { string s; cin >> s; sort(s.begin(), s.end()); if (s[0] == s[s.length() - 1]) cout << -1 << endl; else cout << s << endl; } }
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, x; int cnt[N]; int main() { scanf("%d", &n); int res = 0; for (int i = 1; i <= n; i++) { scanf("%d", &x); if (x > n) res++; else cnt[x]++; } for (int i = 1; i <= n; i++) { res += cnt[i]; if (cnt[i] >= i) res -= i; } cout ...
0
#include <bits/stdc++.h> using namespace std; int dois, cinco, sete, zero1, zero2, dist, tam, inf = 1000 * 1000 * 1000; int mind = inf; string num; int main() { cin >> num; tam = num.size(); for (int k = 0; k < tam; k++) { char c = num[k]; if (c == '2') dois = k + 1; else if (c == '5') cin...
5
#include<iostream> #include<cstring> #include<cassert> #include<cmath> #include<map> #include<set> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<time.h> #include<algorithm> using namespace std; #define REP(i,x,y) for(ll i=x;i<=y;i++) #define rep(i,n) REP(i,1,n) #define rep0(i,n) REP(i,0,n-1...
0
#include <bits/stdc++.h> using namespace std; int mn, mx, i, j, k, ii, sum, step, a[10], n, m, kol; int main() { cin >> n >> m; for (i = 1; i <= n; i++) a[i] = i; step = 1; for (i = 2; i <= n; i++) step *= i; mx = 0; for (i = 1; i <= step; i++) { sum = 0; for (j = 1; j <= n; j++) for (k = j; k...
2
#include <bits/stdc++.h> using namespace std; int main(){ int a,b,c; cin>>a>>b>>c; for(int i=1;i<=b;i++){ if(a*i%b==c){ cout<<"YES"<<endl; return 0; } } cout<<"NO"<<endl; }
0
#include<cstdio> int main() { int N, K, X, Y; scanf("%d%d%d%d", &N, &K, &X, &Y); printf("%d\n", K > N ? X * N : X * K + (N - K) * Y); return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int maxm = 1e5 + 7; const int maxn = 1e5 + 7; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const double pi = 3.1415926535898; inline long long read() { long long a = 0; int f = 0; char p = getchar(); whil...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 5e6 + 5; const int MOD = 1e9 + 7; int chkp[MAX]; int val[MAX]; long long dp[MAX]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); for (int i = 2; i < MAX; i++) { if (chkp[i]) continue; val[i] = i; for (int j = i + i; j < MA...
4
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f3f3f3f3fll; const int maxn = 6e5 + 5; const long long mod = 1e9 + 7; struct Tree { int mi, lz, pos, cnt; } T[maxn << 2]; inline void build(int u, int l, int r) { T[u].lz = T[u].mi = 0; T[u].pos = r; T[u].cnt = r - l + 1; if (l == r)...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; int i; int storeIt[n]; for (i = 0; i < n; i++) { cin >> a[i]; storeIt[a[i] - 1] = i; } s...
2
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; long long int dp[2][320][320]; int main() { int n, m, x; scanf("%d%d%d", &n, &m, &x); if (n > m) puts("0"); else { dp[0][0][0] = 1; for (int i = 1; i <= m; i++) for (int l = 0; l <= n; l++) for (int r = 0; r <= l...
5
#include <bits/stdc++.h> using namespace std; int a, b, c; vector<int> ans; int sum(int curr) { int sum = 0; while (curr > 0) { sum += curr % 10; curr = curr / 10; } return sum; } long long go(long long x, int n) { long long ans = 1; for (int i = 0; i < n; i++) { ans = ans * x; } return ans;...
2
#include <bits/stdc++.h> using namespace std; int hashu[505][505]; int ar[501][501]; int xline[250001], yline[250001], fline[250001]; int main() { int n, m, a, b; cin >> n >> m; memset(ar, 0, sizeof(ar)); memset(hashu, -1, sizeof(hashu)); for (int i = 0; i < m; ++i) { cin >> a >> b; ar[a][++ar[a][0]] ...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 * 1000 + 17; long long fen[MAXN][2], a[MAXN]; long double ans, res, inv, n; long long get(bool flag, int x) { long long res = 0; for (; x; x -= x & (-x)) res += fen[x][flag]; return res; } void add(int x, long long y) { for (; x <= n; x += x & (...
5
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int n, long long int m); long long int power(long long int a, long long int n, long long int m) { if (n == 0) return 1; long long int x = power(a, n / 2, m); if (n % 2 != 0) return (((a * x) % m) * (x) % m) % m; els...
4
#include <bits/stdc++.h> using namespace std; int tab[103][103]; int main() { long long w, n; cin >> w >> n; bool ans = true; while (ans && n) { int r = n % w; if (r == 0 || r == 1) n /= w; else if (r == w - 1) { n /= w; n++; } else ans = false; } cout << (ans ? "YES\...
3
#include<bits/stdc++.h> using namespace std; int main() { int l; cin>>l; printf("%f",(float)l/3*l/3*l/3); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int temp[10] = {0}; int a; for (int i = 0; i < 6; i++) { scanf("%d", &a); temp[a]++; } int ans1 = false, ans2 = false, ans3 = true; int b = 0; for (int i = 1; i <= 9; i++) { if (temp[i] >= 4) { ans1 = true; temp[i] -= 4; ...
1
#include <bits/stdc++.h> using namespace std; const int Maxn = 20; const int Maxl = 16; const string let = "0123456789abcdef"; long long C[Maxn][Maxn]; long long k; int t; int ans[Maxn]; long long Solve(int n, const vector<int> &av, bool fl = false) { if (fl && av[0] <= 0) return 0; for (int i = 0; i < av.size(); i...
6
#include <bits/stdc++.h> #pragma warning(disable : 4786) using namespace std; int son[300010], par[300010]; int find(int x) { if (son[x] != x) son[x] = find(son[x]); return son[x]; } int main(void) { int m, n; cin >> n >> m; for (int i = 1; i <= n + 1; i++) son[i] = i; for (int i = 1; i <= m; i++) { int...
3
#include <bits/stdc++.h> using namespace std; int step(char c) { if (c == 'a') return 0; return 'z' - c + 1; } int main(void) { string s; int k; cin >> s >> k; for (int i = 0; i < s.size(); i++) { int n = step(s[i]); if (n <= k) { s[i] = 'a'; k -= n; } } for (int i = 0; i < k...
0
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } return x * f;...
4
#include <bits/stdc++.h> using namespace std; struct Node { Node(int x = 0, int y = 0) : x(x), y(y) {} int x, y; } a[100010], q[100010]; struct P { P(int w = 0, int x = 0, int y = 0) : w(w), x(x), y(y) {} int w, x, y; } t; int x, y, i, j, k, n, m, f[100010], ch[100010][2], s[100010], l[100010], Q, p[100010]...
6
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000") using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<bool> u(n + 1, 0); int k, kl, kr; k = kl = kr = 0; for (int i = 0; ...
2
#include <bits/stdc++.h> using namespace std; long long n, k; vector<pair<long long, pair<long long, long long>>> v; vector<long long> ans; priority_queue<long long, vector<long long>, greater<long long>> q; long long qs = 0; int32_t main() { cin >> n >> k; v.resize(n); ans.resize(n); for (long long i = 0; i < ...
2
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 1; long long n, m; long long mult(long long a, long long b) { a %= 1000000007; b %= 1000000007; if (a < 0) a += 1000000007; if (b < 0) b += 1000000007; return (a * b) % 1000000007; } long long ad(long long a, long long b) { a %= 1000000007; ...
5
#include <bits/stdc++.h> using namespace std; int main() { string s; bool k = false; cin >> s; for (int i = 0; s[i] != 0; i++) { if (s[i] == 'H' || s[i] == 'Q' || s[i] == '9') { k = true; break; } } if (k) cout << "YES"; else cout << "NO"; }
1
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; cout<<setprecision(10)<<(double)(int(n+1)/2)/n<<endl; }
0
#include<iostream> #include<functional> #include<vector> #include<queue> #include<utility> #include<cstring> #define MP make_pair #define PB push_back using namespace std; typedef pair<int, int> PII; typedef vector<PII> VP; typedef VP::iterator VPI; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int r; int w[2...
0
#include <bits/stdc++.h> char ss[101000]; char s[101000]; char ans[101000]; int main() { while (gets(s)) { int len = strlen(s); int cnt = 0; for (int i = 0; i < len; i++) { if (s[i] == ',') { ans[cnt++] = s[i]; if (i != len - 1) ans[cnt++] = ' '; } else if (s[i] == '.') { ...
2
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) #define repn(i,n) for(int i=1;i<=n;i++) #define LL long long #define pii pair <int,int> #define fi first #define se second #define pb push_back #define mpr make_pair using namespace std; const LL MOD=1e9+7; int n,n2=1,tmp[30],son[2000000][30],num[200000...
0
#include <bits/stdc++.h> using namespace std; priority_queue<int> q; int main() { int n, t; long long ans = 0; cin >> n >> t; q.push(t); for (int i = 1; i < n; i++) { cin >> t; t -= i; if (q.top() > t) { ans += q.top() - t; q.pop(); q.push(t); } q.push(t); } cout << a...
3
#include<bits/stdc++.h> using namespace std; int main(){ int n,i,s=0; cin>>n; vector<int> l(n); for(i=0;i<n;i++) cin>>l.at(i); sort(l.begin(),l.end()); for(i=0;i<n-1;i++) s+=l.at(i); if(l.at(n-1)<s) cout<<"Yes"<<endl; else cout<<"No"<<endl; }
0
#include<bits/stdc++.h> using namespace std; int n,d[100005]; int main(){ cin>>n; for(int i=0;i<n;i++)cin>>d[i]; sort(d,d+n); cout<<d[n/2]-d[n/2-1]<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a[10005]; long long int c = 0, d = 0; cin >> n; long long int i; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 1; i < n - 1; i++) { if (a[i] < a[i - 1] && a[i] < a[i + 1]) c++; if (a[i] > a[i - 1] && a[i] > a[i + 1...
1
#include<iostream> using namespace std; int n; int main() { cin>>n; for(int i=0;i<1<<n;i++) { cout<<i<<":"; for(int j=0;j<n;j++)if(i>>j&1)cout<<" "<<j; cout<<endl; } }
0
#include <bits/stdc++.h> using namespace std; void file() {} signed main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); ; long long t; cin >> t; while (t--) { long long n, l, r; cin >> n >> l >> r; vector<long long> a; long long cnt = 0, flag = 0; for (long long i = 1; i <= n &&...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long int n, a, b, ans = 1; cin >> n >> a >> b; if (a > b) swap(a, b); if (a <= n / 2 && b > n / 2) { cout << "Final!\n"; return 0; } while (!(a % 2 == 1 && a == b - 1)) { a = (a + 1) / 2; b = ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int k; cin >> k; if (k == 0) cout << "ab" << endl; else { int sum = 0; for (char i = 'a'; i <= 'z'; i++) { if (sum == k) break; for (int j = 0; j + sum <= k; j++) sum += j, cout << i; ...
3
#include <bits/stdc++.h> using namespace std; void scan(long long &n) { scanf("%lld", &n); } void scan(long long &n, long long &m) { scanf("%lld%lld", &n, &m); } void scan(vector<long long> &v) { long long n = v.size(); for (long long i = 0; i < n; i++) scanf("%lld", &v[i]); } void solve() { long long n, k, i; ...
2
#include<bits/stdc++.h> using namespace std; int n,m; int s[6],c[6]; bool v[6]; int t[10]; int main() { memset(v,0,sizeof(v)); scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) { scanf("%d%d",&s[i],&c[i]); if(v[s[i]] && t[s[i]]!=c[i]) { cout<<-1; exit(0); } v[s[i]]=1; t[s[i]]=c[i]; } if(n==1 && t[1]==0) {...
0
#include<bits/stdc++.h> #define lowbit( x ) (x&(-x)) #define mp( x , y ) make_pair(x,y) using namespace std; typedef long long ll; typedef pair < int , int > P; const int N = 2e5 + 10; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; int n, a[N], c[N], cnt[N], num[N], in[N], out[N], tot; int b[N], m; // 离散化 vector<...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pii = pair<int, int>; using ld = long double; const int N = 100001; const int M = 1000001; const int LG = 21; struct DSU { vi p, s; DSU(int n) : p(n), s(n, 1) { iota((p).begin(), (p).end(), 0); } int get(int v) { ret...
5
#include <bits/stdc++.h> using namespace std; const int maxN = 1000 * 100 + 10; int n, alone; vector<vector<int> > v[maxN]; bool mark[maxN]; int circle[maxN], p[maxN]; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) { cin >> p[i]; if (p[i] == i) alone = i; } if (alone ...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class t, class u> void chmax(t& first, u second) { if (first < second) first = second; } template <class t, class u> void chmin(t& first, u second) { if (second < first) first = second; } template <class t> using vc = vector<t>; template ...
6
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout.tie(nullptr); ; long long t; cin >> t; while (t--) { long long n; cin >> n; long long ans = 0; long long cur; while (n >= 10) { cur = n - n % 10; ans += cur; ...
2
#include <bits/stdc++.h> using namespace std; mt19937 gene(233); inline char GET_CHAR() { const int maxn = 131072; static char buf[maxn], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, maxn, stdin), p1 == p2) ? EOF : *p1++; } inline int getInt() { int res(0);...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int sum = 0; k = 240 - k; int i = 0; if (k < 5) cout << 0; for (i = 1; i <= n; i++) { sum = sum + i * 5; if (k - sum < (i + 1) * 5 && k - sum >= 0) { cout << i; break; } } if (sum < k && i > n) ...
1
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, q, x, y, cnt = 0; cin >> n >> q; vector<vector<long long int>> dp(3, vector<long long int>(n + 2, 0)); while (q--) { cin >> x >> y; if (dp[x][y] == 0) { cnt += (dp[3 - x][y] == 1); cnt += (dp[3 - x][y - 1] == 1); ...
3
#include <bits/stdc++.h> using namespace std; int main() { string s, p; cin >> s; int n = s.length(), i, j; for (i = 0, j = n - 1; i < j; i++, j--) { if (n % 2) { p = s[j] + (s[i] + p); } else { p = s[i] + (s[j] + p); } } if (n % 2) p = s[i] + p; cout << p << endl; }
1
#include <stdio.h> #include <string.h> #define R register #define MN 205 #define P 998244353 int n,x[MN],y[MN],p[MN],ans; inline int read(){ R int x; R bool f; R char c; for (f=0; (c=getchar())<'0'||c>'9'; f=c=='-'); for (x=c^'0'; (c=getchar())>='0'&&c<='9'; x=(x<<1)+(x<<3)+(c^'0')); return f?-x:x; } inline void de...
0
#include <bits/stdc++.h> using namespace std; int dp[20011], i, j, n; int main() { cin >> n; for (i = 0; i < n; i++) { int h, m; cin >> h >> m; dp[h * 60 + m]++; } int res = 0; for (i = 0; i < 20011; i++) if (dp[i] > res) res = dp[i]; cout << res << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; const long long N = 3e6 + 7, M = 1000000007, inf = INT_MAX; const long long INF = LLONG_MAX; void solve() { long long w, m; cin >> w >> m; vector<long long> vec; while (m) { long long r = m % w; vec.push_back(r); m /= w; } vec.push_back(0); long lo...
3
#include<bits/stdc++.h> using namespace std; string s; int l,flag; int main(){ getline(cin,s); l=s.size(); for(int i=0;i<l;i++) if(s[i]=='F'&&flag){ puts("Yes"); return 0; } else if(s[i]=='C')flag++; puts("No"); return 0; }
0
#include <bits/stdc++.h> using namespace std; int a[100010]; int n; void work(int l, int r) { if (l > r) return; if (l == r) { a[l] = l; return; } a[l] = l + 1; a[l + 1] = r; a[r - 1] = l; a[r] = r - 1; work(l + 2, r - 2); } int main() { cin >> n; if (n == 1) { puts("1"); } else if (n ...
3
#include <bits/stdc++.h> using namespace std; bool done[1000] = {0}; const int INF = 1e9; int n, k, A[4][1000]; vector<tuple<int, int, int>> M; void show() { cout << M.size() << '\n'; for (auto V : M) { int a, b, c; tie(a, b, c) = V; cout << c << ' ' << a << ' ' << b << '\n'; } } int main() { vector...
1