solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; inline int readChar(); template <class T = int> inline T readInt(); template <class T> inline void writeInt(T x, char end = 0); inline void writeChar(int x); inline void writeWord(const char *s); static const int buf_size = 4096; inline int getChar() { static char buf[buf...
4
#include <bits/stdc++.h> using namespace std; int cnt[1000009]; int main() { int n, a; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a); cnt[a]++; } int count = 0; for (int i = 0; i <= 1000000; i++) { int p = cnt[i]; if (p & 1) count++; cnt[i + 1] += p / 2; } long long ...
3
#include <bits/stdc++.h> using namespace std; long double n, m, h; int main() { cin >> n >> m >> h; int sum = 0; vector<int> s(m + 1); h--; for (int i = 0; i < m; i++) { cin >> s[i]; sum += s[i]; } s[h]--; sum--; n--; if (sum < n) { cout << -1; return 0; } if (sum - s[h] < n) { ...
2
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int n, m; vector<vector<int>> g; vector<bool> visited; vector<int> ord; vector<int> low; vector<int> parent; int timer = 0; vector<pair<int,int>> bridge; void dfs(int cur, int prev) { ord[cur] = low[cur] = timer++; vis...
0
#include <bits/stdc++.h> using namespace std; int main() { int m; cin >> m; while (m--) { int a, b; cin >> a >> b; cout << 24 * 60 - (60 * a + b) << endl; } }
1
#include <bits/stdc++.h> #define meow(args...) fprintf(stderr, args) typedef unsigned u32; typedef long long s64; typedef unsigned long long u64; template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;} template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7, M = 2 * N; int n, k; struct Trie { int node[N], nxt[N][26], id; Trie() { memset(memw, -1, sizeof memw); memset(meml, -1, sizeof meml); iota(node, node + N, 0); id = 0; makeNode(); } int makeNode() { memset(nxt[id], -1, ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, k, sum = 0; cin >> n >> k; int a[k][n / k]; for (int i = 0; i < n / k; i++) { for (int j = 0; j < k; j++) cin >> a[j][i]; } for (int i = 0; i < k; i++) { int a1 = 0, a2 = 0; for (int j = 0; j < n / k; j++) { if (a[i][j] == 2...
1
#include <bits/stdc++.h> using namespace std; const int N = 111; int n, m; bool in[N][N]; int ans[N][N], ban[N][N]; int calc(int x) { for (int i = 0;; ++i) if (!(x >> i & 1)) return i; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); cin >> n >> m; for (int i = (1); i < (n + 1); i++) ...
5
#include <bits/stdc++.h> using namespace std; long long m; const long long mod = 998244353; long long bin_num(long long num, long long pow) { if (pow == 0) { return 1LL; } if (pow == 1) { return num % mod; } if (pow == 2) { return ((num * num) % mod); } long long ans = bin_num(num, pow / 2); ...
6
#include <bits/stdc++.h> using namespace std; int n, m, p, s, q, t, i, j, k, x, y, z, c, d, l, r, lst, a, b, ans, mn, mx, cnt, l1, l2; int main() { cin >> t; for (q = 0; q < t; q++) { cin >> d; if (d < 4 && d > 0) cout << "N\n"; else { cout << "Y "; cout << setprecision(15) ...
3
#include "iostream" #include "random" #include "string" #include "bitset" #include "algorithm" #include "map" #include "queue" #include "list" #include "set" #include "climits" #include "iomanip" #include "functional" #include "stack" #include "numeric" using namespace std; const long long int MOD = 1000000007; long...
0
#include <bits/stdc++.h> using namespace std; int main() { int t = 1; while (t--) { long double H, L; cin >> H >> L; long double h = ((L * L) - (H * H)) / (2 * H); cout << fixed << setprecision(12) << h; } }
2
#include <bits/stdc++.h> using namespace std; const long long LLINF = 1LL << 61; const int INF = 1e9; const int MOD = 1e9 + 7; int f[1 << 24]; int a[55], b[2], na[1 << 24]; int n, k, res; long long s[1 << 24]; inline void add(int &a, const int &b) { a += b; if (a >= MOD) a -= MOD; } int main() { int n; cin >> n...
5
#include<iostream> int main(){ int n,k; std::cin >> n >> k; std::cout << n-k+1; return 0; }
0
#include <bits/stdc++.h> using namespace std; inline long long in() { long long x; scanf("%lld", &x); return x; } vector<int> ans; long long bal, m; vector<int> avail; string s; bool putw(int left, int last, bool chance) { if (left <= 0) return true; for (int x : avail) { if (x != last) { long long ...
3
#include <bits/stdc++.h> using namespace std; vector<int> g[110]; bool vis[110], tmp[110]; bool ok; void dfs(int cur, int l, int f, int p) { if (l > 1 && cur == f) { if (l & 1) ok = true; return; } int len = g[cur].size(); for (int i = 0; i < len; i++) { if (!vis[g[cur][i]] && g[cur][i] != p) { ...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; long long dp[2]; long long tp[2]; long long inf = 1e17; int n; long long r1, r2, r3; long long d; long long a[2000000]; int main() { dp[0] = 0; dp[1] = inf; scanf("%d", &n); scanf("%lld %lld %lld", &r1, &r2, &r3); scanf("%lld", &d); fo...
3
#include<cstdio> int d[35][35],a[35][3]; int main() { int n,c;scanf("%d%d",&n,&c); for(int i=1;i<=c;i++) for(int j=1;j<=c;j++) scanf("%d",&d[i][j]); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { int x;scanf("%d",&x); a[x][(i+j)%3]++; } int ans=0x3f3f3f3f; for(int i=1;i<=c;i++) for(int j=1;j<=c;j++) for(i...
0
#include <bits/stdc++.h> using namespace std; bool isDigitOrLetter(char ch) { if ('a' <= ch && ch <= 'z') return true; if ('A' <= ch && ch <= 'Z') return true; if ('0' <= ch && ch <= '9') return true; return false; } void insertProhibits(string &s, set<string> &prohibit, vector<string> &users) { string token;...
3
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long A = 257; const int MAXN = 600005; int N, M; long long p[MAXN]; void init() { p[0] = 1; for (int i = 1; i < MAXN; i++) p[i] = A * p[i - 1] % MOD; } long long hashi(string s) { long long res = 0; for (int i = 0; i < s.siz...
3
#include <bits/stdc++.h> using namespace std; int in[200005], id[200005]; vector<int> G[200005]; vector<pair<int, int>> undir, ret; int main() { ios::sync_with_stdio(0); int T, n, m; cin >> T; while (T--) { cin >> n >> m; for (int i = 1; i <= n; ++i) { G[i].clear(); in[i] = id[i] = 0; } ...
5
#include <bits/stdc++.h> using namespace std; int n, arr[100000 + 5]; void rd_1() { int i; cin >> n; for (i = 0; i < n; i++) cin >> arr[i]; } int main() { ios::sync_with_stdio(0); int i, j; rd_1(); sort(arr, arr + n); reverse(arr, arr + n); int sum = 0; for (i = 1; i < n; i++) sum += arr[i]; cout ...
2
#include <bits/stdc++.h> using namespace std; int test(string str) { int len = str.length(); int a = 0, b = 0, c = 0; for (int i = 0; i < len; i++) { if (str[i] == 'A') a += 1; else if (str[i] == 'B') b += 1; else if (str[i] == 'C') c += 1; } if (a <= b && b - a == c) return 1; ...
1
#include <bits/stdc++.h> using namespace std; inline int read(int f = 1, int x = 0, char ch = ' ') { while (!isdigit(ch = getchar())) if (ch == '-') f = -1; while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return f * x; } const int N = 2e5 + 5; int m, n, T, s[2][N], c[2], f[2], ans, q[N], t[N], type...
3
#include <bits/stdc++.h> using namespace std; const long long inf = 1e15 + 7; struct Dinic { long long n, s, t; struct Edge { long long to, cap, flow, rev; Edge(long long to = 0, long long cap = 0, long long flow = 0, long long rev = 0) : to(to), cap(cap), flow(flow), rev(rev) {} }; vec...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; struct node { bool friend operator<(node n1, node n2) { if (n1.val == n2.val) { return n1.id > n2.id; } else { return n1.val > n2.val; } } int id, val; }; priority_queue<node> que; vector<int> pre[maxn]; int degree[ma...
3
#include <bits/stdc++.h> #include <deque> using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) #define repd(i,a,b) for (int i = (a); i < (b); i++) typedef long long ll; int main(void) { int n, q, query, t, x; cin >> n >> q; vector<deque<int> > S(n); rep(i, q) { cin >> query >> t; if (query == ...
0
#include<iostream> using namespace std; int main(){ int r,a; cin>>r; a=3*r*r; cout<<a; }
0
#include <bits/stdc++.h> using namespace std; long long ans; long long m, n, s; long long maxx; int q; int main() { bool tip = true; if (tip == true) { cin >> q; while (q--) { cin >> m >> n >> s; maxx = max(m, n); if (maxx > s) { cout << "-1" << endl; continue; } else...
2
#include <bits/stdc++.h> namespace DECLARATIONS { using namespace std; using ll = long long; using PI = pair<int, int>; template <class T> using V = vector<T>; using VI = V<int>; template <class T> inline void debug(T &A) {} template <class T> inline void debug_dim2(T &A) {} template <typename... Args> inline void debu...
5
#include <bits/stdc++.h> using namespace std; int mp[1010000], ans; int main() { int n, m, x; cin >> n; for (int i = 1; i <= n; i++) { scanf("%d", &x); mp[x]++; } for (int i = 0; i <= 1e6 + 21; i++) { int num = i; int numcnt = mp[i]; if (numcnt % 2 == 1) ans++; mp[num + 1] += numcnt / ...
1
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int n, k, h[200003], nw[200003]; long long f[200003], inv[200003]; long long mypow(long long x, long long times) { if (x == 0) return times == 0; if (times == 0) return 1; long long ret = mypow(x, times / 2); ret = ret * ret % mod; if (t...
4
#include <bits/stdc++.h> using namespace std; int main() { int x, n, ans = 0; cin >> n; int v[n + 1]; for (int i = 0; i < n; i++) { cin >> v[i]; if (v[i] != -1) v[i]--; } for (int i = 0; i < n; i++) { int j = v[i]; x = 1; while (j != -1) { x++; j = v[j]; } ans = max(x...
1
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int mod=1000000007; int n,C[51][51],dp[51][101]; int main() { for(int i=0;i<=50;++i) { C[i][0]=1; for(int j=1;j<=i;++j)(C[i][j]=C[i-1][j-1]+C[i-1][j])>=mod?C[i][j]-=mod:0; } scanf("%d",&n); dp[1][n]=n,dp[1][n-1]=n; for(int i=1;i...
0
#include<cstdio> #include<cmath> int main(){ int n; for(;;){ scanf("%d",&n); if(n==-1)break; double x=1,y=0; double rad=atan2(-y,-x); for(int i=2;i<=n;i++){ rad-=M_PI_2; x+=cos(rad); y+=sin(rad); rad=atan2(-y,-x); } ...
0
#include <bits/stdc++.h> using namespace std; bool dbg = 0; void bad(string mes = "Impossible") { cout << mes; exit(0); } template <typename T> string bin(T x, int st = 2) { string ans = ""; while (x > 0) { ans += char('0' + x % st); x /= st; } reverse(ans.begin(), ans.end()); return ans.empty() ?...
5
#include <iostream> #include <algorithm> #include <iomanip> #include <map> #include <set> #include <queue> #include <stack> #include <numeric> #include <bitset> #include <cmath> static const int MOD = 1000000007; using ll = long long; using u32 = uint32_t; using namespace std; template<class T> constexpr T INF = ::nu...
0
#include <bits/stdc++.h> using namespace std; const int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1}; const int MAX = 50000; int n, m; char a[20][20]; int vis[20][20]; struct Pos { int step; queue<pair<int, int> > q; int cnt[16]; Pos() { step = 0; memset(cnt, 0, sizeof(cnt)); } inline void push(pair...
4
#include <cctype> #include <cstdio> #include <algorithm> #define rep(i,x,y) for (int i=x; i<=y; ++i) #define repd(i,x,y) for (int i=x; i>=y; --i) int get() { char c; while (!isdigit(c=getchar())); int k=c-'0'; for (; isdigit(c=getchar()); k=k*10+c-'0'); return k; } using namespace std; const int N...
0
#include <bits/stdc++.h> using namespace std; int d[3][100010], n, m, D; vector<int> g[100010], v; bool has[100010]; void dfs(int f, int x, int id, int h) { d[id][x] = h; for (int i = 0; i < g[x].size(); i++) { int to = g[x][i]; if (to != f) dfs(x, to, id, h + 1); } } int main() { memset(d, -1, sizeof(d...
2
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; int a[105]; void solve() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; int ans = 0; while (1) { ans++; int cnt = 1; for (int i = 2; i <= n; i++) { cnt += a[i] != a[i - 1]; } if (cnt <= ...
2
#include <bits/stdc++.h> using namespace std; vector<vector<long long int> > v; vector<long long int> s, a; long long int n; long long int dfs1(long long int u, long long int par) { s[u] = 1; for (auto it : v[u]) { if (it != par) { s[u] += dfs1(it, u); a.push_back(s[it] * 1ll * (n - s[it])); } ...
4
#include <bits/stdc++.h> using namespace std; const int MaxN = 100005; int C[MaxN], n, m; bool guilty[MaxN]; int G[MaxN], nG[MaxN], ngCount; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> C[i]; if (C[i] > 0) G[C[i]]++; else { nG[-C[i]]++; ngCount++; } } int g...
2
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const double eps = 1e-9; int main() { string line; getline(cin, line); int c4 = 0, c7 = 0; for (int i = (0); i < (int((line).size())); ++i) { if (line[i] == '4') ++c4; if (line[i] == '7') ++c7; } if (!c4 && !c7) { printf("-...
2
#include <bits/stdc++.h> using namespace std; int main() { long long int n, count = 0; double k; cin >> n >> k; long long int upper = 2 * k; long long int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) { if (upper >= a[i]) { upper = max(upper, 2 * a[...
3
#include <iostream> #include <vector> #include <utility> #include <algorithm> #include <iomanip> #include <cmath> #include <functional> #include <map> #include <queue> #include <string> #include <deque> #include <set> #include <bitset> #include <cstring> #include <unordered_map> //#include <bits/stdc++.h> using na...
5
#include <bits/stdc++.h> using namespace std; #define ll long long int main(){ ll N; cin >> N; vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i]; ll x = 0; for (ll i = 2; i < N; i++) x ^= A[i]; ll sum = A[0]+A[1]; if (sum < x || (sum-x)%2 == 1) { cout << -1 << e...
0
#include<bits/stdc++.h> int main() { long double a, b, c; std::cin >> a >> b >> c; puts(((c - a - b) * (c - a - b) <= 4 * a * b) || (c < a + b) ? "No" : "Yes"); return 0; }
0
#include <bits/stdc++.h> using namespace std; int N, k, a[100113], t, f, l; bool solve() { if (k == 0) { if (a[0] == 0 || a[0] == 12345 && f == 1) { return true; } return false; } if (t != 0) { return l == 1; } for (int i = int(0); i < int(N); i++) { if (a[i] % k != 0) { return...
5
#include <bits/stdc++.h> using namespace std; string s; int n, a, c, g, t, q, maxi, k; int main() { cin >> n >> s; if (n % 4 != 0) { cout << "==="; return 0; } k = n / 4; for (int i = 0; i < n; i++) { if (s[i] == 'A') a++; if (s[i] == 'C') c++; if (s[i] == 'G') g++; if (s[i] == 'T') t+...
2
#include <bits/stdc++.h> using namespace std; struct code { int x, y; }; int sarala(code a, code b) { return a.x < b.x or (a.x == b.x and a.y < b.y); } int gcd(int a, int b) { while (b != 0) { a = a % b; swap(a, b); } return a; } int cnt; string number(int n) { if (n == 0) return "zero"; if (n == 1)...
1
#include <iostream> #include <string> #include <map> #include <vector> #include <algorithm> using namespace std; enum FACE { BACK, RIGHT, TOP, BOTTOM, LEFT, FRONT }; template <class T> class Dice { public: Dice() { id[TOP] = 2; id[FRONT] = 5; id[LEFT] = 4; id[RIGHT] = 1; id[BACK] = 0; id[BOTTOM] = 3; } ...
0
#include<bits/stdc++.h> using namespace std; #define MAX_N 100005 int N,Q; bool t[MAX_N]; bool u[MAX_N]; int main(){ cin>>N>>Q; t[1]=true; u[1]=u[2]=true; for(int i=0;i<Q;i++){ int a,b; cin>>a>>b; if(t[a-1]||t[a+1]){ u[b]=true; } if(t[b-1]||t[b+1]){ u[a]=true; } ...
0
#include <bits/stdc++.h> using std::cin; using std::cout; using std::endl; using std::vector; class Ruler { public: template <typename Iterator> Ruler(Iterator begin, Iterator end) : marks_(begin, end) {} void CanMeasure(int distance, bool &can_measure, int &left_mark, int &right_mark) { fo...
2
#include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <cfloat>...
0
#include<bits/stdc++.h> using namespace std; int a[1009][1009]; int n,m,k; int x; vector<int> v,v2,v3; int main() { cin>>n>>m>>k; for(int i=1;i<=k;i++) { cin>>x; for(int j=0;j<x;j++) v.push_back(i); } for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { int ans1=i*m+j; int ans2=i*m+m-1-...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5, mod = 1e9 + 7; int bit[maxn << 1]; int s[maxn], t[maxn], n, m; vector<int> v; vector<pair<int, int> > p; void add(int i, int val) { while (i <= v.size()) { bit[i] += val; if (bit[i] >= mod) bit[i] -= mod; ; i += i & -i; } } int ...
2
#include <bits/stdc++.h> using namespace std; const int N = 2000 + 11; const int Mod = 1e9 + 7; void at(long long& a) { a %= Mod; } struct Matrix { int n; long long arr[N]; void clear() { n = 0; memset(arr, 0, sizeof(arr)); } friend Matrix operator*(const Matrix& a, const Matrix& b) { assert(a.n =...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int main() { string a; getline(cin, a); int n; int m = a.size(); reverse((a).begin(), (a).end()); std::vector<int> c(10); scanf("%d\n", &n); std::vector<string> b(n); for (int i = 0; i < n; i++) { getline(cin, b[i]); ...
5
#include <bits/stdc++.h> using namespace std; void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } constexpr int MAXN = 2e5 + 12; constexpr int MOD = 998244353; constexpr int INF = 1e9 + 1; constexpr int LOG = 2e1 + 5;...
4
#include <bits/stdc++.h> using namespace std; #define rep(i,n) REP(i,0,n) #define REP(i,s,e) for(int i=(s); i<(int)(e); i++) #define repr(i, n) REPR(i, n, 0) #define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--) #define pb push_back #define all(r) r.begin(),r.end() #define rall(r) r.rbegin(),r.rend() #def...
0
#include <bits/stdc++.h> using namespace std; int n, m; char a[1005][1005]; int nextt[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}}; int main() { int ans = 0, cnt = 0; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { scanf("%s", a[i]); for (int j...
2
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; long long int ind[N], a[N], l[N], r[N], fen[N], ans[N]; vector<long long int> v[N], d[N]; void upd(int x) { for (int i = x; i <= N - 100; i += i & (-i)) fen[i]++; } long long int sum(int x) { long long int ret = 0; for (int i = x; i > 0; i -= ...
4
#include <bits/stdc++.h> using namespace std; int n; int s, k; int flag[100100]; int ans[100100]; int p, q; int main() { while (~scanf("%d%d", &s, &k)) { p = q = 0; flag[0] = 0; flag[++p] = 1; for (int i = 1; i <= k; i++) { p++; if (i == 1) flag[p] = 1; else flag[p] =...
2
#include <bits/stdc++.h> using namespace std; set<pair<signed long long int, signed long long int> >::iterator it; set<pair<signed long long int, signed long long int> > v; vector<signed long long int> adj[2000001]; vector<signed long long int> adj1[2000001]; signed long long int ans[2000001]; signed long long int vali...
2
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2") #pragma GCC optimize("unroll-loops") using namespace std; const unsigned _mod = 998244353; const unsigned mod = 1e9 + 7; const long long infi = 0x3f3f3f3f3f3f3f3fll; const int inf = 0x3f3f3f3f; long lo...
3
#include <bits/stdc++.h> using namespace std; int xxx, yyy; char str[1000]; int xx[1000], yy[1000]; int x, y; int main() { scanf("%d%d", &xxx, &yyy); scanf(" %s", str); int l = strlen(str); int x = 0, y = 0; for (int i = 0; i < l; i++) { xx[i] = x; yy[i] = y; if (str[i] == 'R') x++; if (str[i]...
1
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; vector<string> s(n); vector<vector<int>> arr(n, vector<int>(m)); for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j+...
3
#include<iostream> #include<algorithm> using namespace std; static const int MAX = 1000; static const int VMAX = 10000; int n, A[MAX], s; int B[MAX], T[VMAX + 1]; //s:与えられた数列の中での最小値 //A:与えられた数列 //B:ソート済みの数列 //T:与えられた数列の中の数字がソート済みの数列のなかで来る位置(イテレータ) int solve(){ int ans = 0; bool V[MAX]; //V:各数字がどのループに属するか判明...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, s, p, k, m, t, x, y, ans, res, mn, mx; cin >> n; long long a[n + 1]; ans = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; if (i != 1) ans += fabs(a[i] - a[i - 1]); else ans += fabs(a[i]); } cout << ans << endl;...
2
#include<stdio.h> #include<cstring> #include<cstdlib> #include<cmath> #include<iostream> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<bitset> #include<utility> #include<functional> #include<iomanip> #include<sstream> #include<ctime> #include<cassert> using namespace std; #de...
0
#include <bits/stdc++.h> #pragma GCC optimize("-O3", "unroll-loops") using namespace std; 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; } const int MOD = 1e9 + 7; const int MAX = 200020;...
3
#include <bits/stdc++.h> using namespace std; bool islucky(int x) { if (x < 0) x = -x; int rem = x % 10; while (x) { if (rem == 8) return true; x = x / 10; rem = x % 10; } return false; } int main() { int a, b = 1; scanf("%d", &a); a++; while (!islucky(a)) { a++; b++; } printf(...
1
#include <bits/stdc++.h> using namespace std; int main() { char store[3][4] = { {'.', 'x', 'x', '\0'}, {'x', '.', 'x', '\0'}, {'x', 'x', '.', '\0'}}; char arr[4][5]; int i; for (i = 0; i < 4; ++i) { cin >> arr[i]; } int c[4] = {0}, r[4] = {0}, j; for (i = 0; i < 4; i++) { string s = arr[i]; ...
2
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<queue> #include<vector> #include<ctime> #include<map> #include<bitset> #include<set> #include<assert.h> #include<chrono> #include<random> #define LL long long #define mp(x,y) make_pair(x,y) #define pll pair<long long,long ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, ai, xi, neg = 0, pos = 0, count = 0; vector<pair<int, int> > a; cin >> n; for (int i = 0; i < n; i++) { cin >> xi >> ai; a.push_back(pair<int, int>(xi, ai)); if (xi < 0) neg++; else pos++; count += ai; } sort(a...
1
#include <bits/stdc++.h> using namespace std; int n, q, c; const int C = 101; const int P = 11; int cnt[P][C][C]; int main(void) { scanf("%d %d %d", &n, &q, &c); for (int i = 0; i < n; i++) { int x, y, s; scanf("%d %d %d", &x, &y, &s); cnt[s][x][y]++; } for (int p = 0; p <= c; p++) for (int i = ...
3
#include <bits/stdc++.h> using namespace std; int v[500005]; int main() { long long i, j, mx = 0, n; int k; cin >> n; for (i = 1; i <= n; ++i) { for (j = 2; j * j <= i; ++j) if (i % j == 0) break; if (i % j == 0) v[i] = i / j; else v[i] = 1; } sort(v + 1, v + n + 1); for (i =...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, x, r, cnt = 0; cin >> n >> x; if (x > n) r = n; else if (x <= n) r = x; cnt = abs(x - n) / 2; cout << r << " " << cnt; return 0; }
1
#include <bits/stdc++.h> int main() { int t; long long x; scanf("%d", &t); while (t--) { scanf("%lld", &x); if (x == 1 || x % 4 == 2) { printf("-1\n"); continue; } bool found = false; for (long long b = 1LL; b * b < x + 10000; b++) { long long a = (long long)sqrt(x + b * b)...
3
#include <bits/stdc++.h> using namespace std; int main() { int n1, n2, k1, k2; scanf("%d%d%d%d", &n1, &n2, &k1, &k2); if (n1 > n2) printf("First\n"); else printf("Second\n"); return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n; vector<pair<int, int> > v; scanf("%d", &n); for (int i = 0; i < n; ++i) { int a, b; scanf("%d %d", &a, &b); v.push_back(make_pair(a, b)); } sort(v.begin(), v.end()); int rsp = 0; for (size_t i = 0; i < v.size(); ++i) { if ...
1
#include <iostream> #include <cstdio> #include <vector> #include <set> #include <map> #include <queue> #include <deque> #include <stack> #include <algorithm> #include <cstring> #include <functional> #include <cmath> using namespace std; #define rep(i,n) for(int i=0;i<(n);++i) #define rep1(i,n) for(int i=1;i<=(n);++i) #...
0
#include <bits/stdc++.h> using namespace std; char ch[102][28]; int main() { int count1[200005]; memset(count1, 0, sizeof(count1)); int n; cin >> n; for (int i = 0; i < n; i++) { int temp; cin >> temp; count1[temp] = i + 1; } long long int ans = 0; for (int i = 2; i <= n; i++) { ans += (...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; const int MAXA = 1 << 20; int n, m, k, niz[MAXN], pref[MAXN], currentL, currentR; long long ans = 0, cnt[MAXA]; const int BLOCK = 317; bool cmp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) { if (a.first / BLOCK == b.first / BLOCK)...
5
#include <bits/stdc++.h> using namespace std; const int N = 110, mod = int(1e9) + 7; int n, k, m, a; int g[N], cnt[N], last[N], p[N], pn; int main() { cin >> n >> k >> m >> a; if (n == 1) { cout << 1; return 0; } for (int i = 1; i <= a; i++) { cin >> g[i]; } for (int i = 1; i <= n; i++) { me...
6
#include <cstdio> #include <vector> using namespace std; int main() { const int MAX = 32768+1; bool p[MAX]; for (int i = 0; i < MAX; ++i) p[i] = true; p[0] = p[1] = false; for (int i = 2; i*i <= MAX; ++i) { if (p[i]) { for (int j = i+i; j < MAX; j+=i) p[j] = false; } } vector<int> prime; for (int...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int maxn = 1e5 + 5; int a[maxn]; int val[maxn]; long long poww[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, q; cin >> n >> q; string t; cin >> t; poww[0] = 1; f...
3
#include <bits/stdc++.h> bool hehit(int x, int y, int i, int j) { if (x == i && y == j) return true; if (x - i == 1 || i - x == 1) return y - j == 2 || j - y == 2; else if (x - i == 2 || i - x == 2) return y - j == 1 || j - y == 1; return false; } bool hithe(int x, int y, int i, int j) { if (x == i ||...
2
#include <bits/stdc++.h> using namespace std; int dir1[8][2] = {1, 2, 2, 1, 2, -1, 1, -2, -1, 2, -2, 1, -1, -2, -2, -1}; int dir2[4][2] = {1, 0, 0, 1, -1, 0, 0, -1}; int dir3[8][2] = {1, 0, 0, 1, -1, 0, 0, -1, 1, 1, 1, -1, -1, 1, -1, -1}; int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } bool isPrime(int x) ...
2
#include <bits/stdc++.h> using namespace std; int n, k; string str; int freq[26]; int main() { scanf("%d %d", &n, &k); cin >> str; int i, j; for (i = 0; i < n; i++) freq[str[i] - 97]++; int xx = -1; for (i = 0; i < 26; i++) { if (freq[i] != 0) { xx = i; break; } } if (k > n) { co...
3
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; using lln = long long int; using ls = string; using ch = char; using lld = long double; using lf = float; using ll = int; using ld = double; void solve() { ll ans, num1, num2, ans1, ans2; cin >> num1 >> num2; ans = num1 / num2; ans1 =...
1
#include <bits/stdc++.h> using namespace std; int n, num[200005]; int one, two; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (register int i = 1; i <= n; i++) { cin >> num[i]; if (num[i] == 1) one++; else two++; } if (two > one) cout << one; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; if (x == 3) cout << 5 << endl; else { for (int i = 1;; i += 2) { if ((i / 2 + 1) * (i / 2 + 1) + (i / 2) * (i / 2) >= x) { cout << i << endl; cin >> i; return 0; } } } }
1
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int n, m, res = 0, k, par = 0; n = s.size(); m = t.size(); k = n - m + 1; for (int i = 0; i < m; i++) { if (s[i] != t[i]) par++; } par %= 2; if (par % 2 == 0) res++; for (int i = 1; i < k; i++) { if (s[i...
3
#include <bits/stdc++.h> using namespace std; const int NICO = 200000 + 10; int n, k, cnt, res; int a[NICO], b[NICO]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { int x; cin >> x; if (x < 0) a[++cnt] = i; } if (cnt > k) { printf("-1\n"); return 0; } if (cnt == 0) { prin...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (n + 999) / 1000 * 1000 - n << endl; }
0
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define all(c) c.begin(),c.end() #define pb push_back #define fs first #define sc second #define show(x) cout << #x << " = " << x << endl #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) using...
0
#include <bits/stdc++.h> using namespace std; int n, m, k, S, T; char s[2555]; vector<int> adj[2555]; int val[2555], d[2555], p[2555]; string ans; void check(int x) { string now; for (; d[x]; x = p[x]) now += s[x]; reverse(now.begin(), now.end()); if (now.length() < ans.length()) ans = now; else if (now.l...
3