solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n, x; cin >> n >> x; int a[n], b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (int i = 0; i < n; i++) { ...
0
#include <bits/stdc++.h> using namespace std; const int MAX = 130; int dp[4][105]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { int cnt = 0; scanf("%d", &cnt); if (cnt == 0) { dp[1][i] = dp[2][i] = 0x3f3f3f3f; dp[0][i] = min(dp[0][i - 1], min(dp[1][i - 1], dp[2][i - ...
6
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; void test() { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; if (a[n - 1] >= a[0] + a[1]) cout << 1 << " " << 2 << " " << n << endl; else cout << -1...
0
#include <bits/stdc++.h> using namespace std; int n; int m; int all[24][24]; int num[24] = {0}; int main() { scanf("%d%d", &n, &m); for (int i = 1; i < n + 1; i++) for (int j = 1; j < m + 1; j++) scanf("%d", &all[i][j]); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (all[i][j] != j) n...
7
#include <bits/stdc++.h> const double kEPS = 1e-6; const int kMaxN = 100; std::complex<long long> tri[kMaxN][3]; std::complex<long long> p[3 * kMaxN + 2]; double list[3 * kMaxN + 2]; int lsize; int n; inline int Sign(double x, double y = 0.0) { if (fabs(x - y) < kEPS) return 0; return x < y ? -1 : 1; } inline long ...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x = 0; cin >> n >> m; if (n == m) { cout << n; return 0; } if (n < m) { cout << "-1"; return 0; } while (n) { if (n >= 2) { x++; n -= 2; } else { x++; n -= 1; } } if (x % m == 0) { ...
2
#include <bits/stdc++.h> using namespace std; const int N = 150010; int pre[N], nex[N]; int pr[N], ne[N]; int n; int nextt(int x) { return ne[x] == -1 ? x : ne[x] = nextt(ne[x]); } int pree(int x) { return pr[x] == -1 ? x : pr[x] = pree(pr[x]); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { pre[...
9
#include <bits/stdc++.h> using namespace std; const int t = 399, mod = 998244353; inline int mo(const register int x) { return x >= mod ? x - mod : x; } int a[100010], n, k, bl[100010], p[100010], pre[100010], sum[400][100010], f[400], S[400], dp[100010], lst[100010]; inline void rebuild(const register int x, const...
21
#include <bits/stdc++.h> using namespace std; bool debug = 1; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; long long ln, lk, lm; int x[100005], d[100005]; long long L[100005], R[100005]; void cal() { set<pair<long long, long long>> s; for (int(i) = 1; (i) <= (int)(n); (i)++) { L[i] = -1; i...
22
#include <bits/stdc++.h> using namespace std; struct edge { int to, next, v, mk; } e[20010 << 2]; int head[20010]; int cnt; int n, m, l, s, E; int t, h; int dis[20010], vis[20010], q[20010]; void link(int x, int y, int z, int w) { e[cnt] = (edge){y, head[x], z, w}; head[x] = cnt++; } void add(int x, int y, int z,...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<int> vec; for (int i = 0; i < n; i++) { int d; scanf("%1d", &d); if (d == 2 || d == 3 || d == 5 || d == 7) vec.push_back(d); else if (d == 4) vec.push_back(3), vec.push_back(2), vec.push_back(2)...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 5e3 + 10; vector<int> g[maxn]; int num[maxn]; int mn, mx; int n, d; int ans[maxn], fa[maxn], id[maxn]; bool run() { cin >> n >> d; for (int i = 1; i <= n; ++i) g[i].clear(); int rem = n, dep = 0; mn = 0; for (int i = 0; i <= n; ++i) { dep = i;...
14
#include <bits/stdc++.h> using namespace std; char s[200000]; char t[200000]; int pos[30][110000]; int len[30]; int n, k; void make(char x, int y) { pos[x - 'a' + 1][++len[x - 'a' + 1]] = y; } void pre() { for (int i = 1; i <= k; i++) { char x = s[i - 1]; make(x, i); } } long long Find(char x, int y, int z)...
10
#include <bits/stdc++.h> using namespace std; int f[2111111]; int main() { int n; while (cin >> n) { int *a = f; for (int i = 1; i <= n; ++i) a[i] = i; for (int i = 2; i <= n; i++) { a[n + 1] = a[(n - 1) / i * i + 1]; for (int j = (n - 1) / i * i + 1; j >= 1; j -= i) a[j] = a[j - i]; +...
14
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e5 + 7; const int INF = (int)1e9 + 7; const long long LINF = (long long)1e18 + 7; const int MOD = (int)1e9 + 7; void file() {} inline int readChar(); template <class T = int> inline T readInt(); template <class T> inline void writeInt(T x, char end = ...
16
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-10; const int MODULO = 1000000007; template <int size> class UnionFind { int par[size]; int rank[size]; public: UnionFind() { reset(); } void reset() { for (int i = 0; i < (size); i++) par[i] = i, rank[i] = 0; } int find(int x)...
8
#include <bits/stdc++.h> using namespace std; template <typename X> ostream& operator<<(ostream& x, const vector<X>& v) { for (long long i = 0; i < v.size(); ++i) x << v[i] << " "; return x; } template <typename X> ostream& operator<<(ostream& x, const set<X>& v) { for (auto it : v) x << it << " "; return x; } ...
8
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int SIZE = 5e3 + 10; char s[SIZE]; int dp[SIZE]; bool good[128]; int lt[SIZE]; void track(int id, bool ending) { if (id) track(lt[id], 0); for (int i = (lt[id] + 1); i < (id + 1); ++i) printf("%c", s[i]); putchar(ending ? '\n' : ' '); } ...
7
#include <bits/stdc++.h> using namespace std; void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); } template <class T1, class T2> inline void gmax(T1 &a, T2 b) { if (b > a) a = b; } template <class T1, class T2> inline void gmin(T1 &a, T2 b) { if (b < a) a = b; ...
16
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long double PI = 4 * atan((long double)1); const long long MOD = 1000000007; long long nCr(long long n, long long k) { long long res = 1; if (k > n - k) k = n - k; for (long long i = 0; i < k; i++) res *= (n - i), res /= (i + 1); re...
0
#include <bits/stdc++.h> using namespace std; long long wllabs(long long x) { if (x < 0) return -x; else return x; } bool can(long long x1, long long y1, long long x2, long long y2, long long x0, long long y0) { long long A = x2 - x0; long long B = y2 - y0; if (A == 0 && B == 0) return true; ...
12
#include <bits/stdc++.h> using namespace std; using namespace std::placeholders; int main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int ntest; cin >> ntest; while (ntest--) { long long h, n; cin >> h >> n; vector<int> a(n); for (int i = -1; ++i < n;) cin >> a[i]; vec...
8
#include <bits/stdc++.h> using namespace std; char ch[101][101]; bool del[101][101]; int n, m; void check(int i, int j, char le) { for (int x = j + 1; x < m; x++) { if (ch[i][x] == le) { del[i][j] = 0; del[i][x] = 0; } } for (int x = i + 1; x < n; x++) { if (ch[x][j] == le) { del[i][...
3
#include <bits/stdc++.h> using namespace std; int d[1000]; int s[1000]; int best[1000]; int main(void) { int m, k; cin >> m >> k; int ans = 0; for (int i = 0; i < m; i++) { cin >> d[i]; ans += d[i]; } for (int i = 0; i < m; i++) cin >> s[i]; best[0] = s[0]; for (int i = 1; i < m; i++) best[i] = ...
5
#include <bits/stdc++.h> using namespace std; const int MAX_N = 201000; vector<int> v[MAX_N], w[MAX_N], city; int dp[MAX_N]; void dfs1(int x, int fa) { int i; for (i = 0; i < v[x].size(); i++) { int y = v[x][i]; if (y == fa) continue; dfs1(y, x); dp[x] += dp[y]; if (w[x][i] == 0) dp[x]++; } } ...
9
#include <bits/stdc++.h> using namespace std; inline void using_file(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } mt19937 gen_rand; template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &a) { os << "("; os << a.first << ", "; os <<...
6
#include <bits/stdc++.h> using namespace std; int main() { int casos; scanf("%d", &casos); int notas[casos]; int posicao[casos]; int aux[casos]; for (int i = 0; i < casos; i++) { scanf("%d", &notas[i]); posicao[i] = notas[i]; } sort(posicao, posicao + casos); int n = 1; for (int i = 0; i < c...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = int(1e6 + 5); long double f[MAXN]; int n, m, k; long double C(int n, int m) { return f[n] - f[m] - f[n - m]; } int main() { f[0] = 0; for (int i = 1; i <= MAXN - 4; i++) f[i] = f[i - 1] + log(1.0 * i); scanf("%d%d%d", &n, &m, &k); long double ans = ...
19
#include <bits/stdc++.h> using namespace std; const int MAXBUF = 1 << 23; char B[MAXBUF], *Si = B, *Ti = B; inline char getc() { if (Si == Ti) Ti = (Si = B) + fread(B, 1, MAXBUF, stdin); if (Si == Ti) return 0; else return *Si++; } template <class T> inline void read(T &a) { static char c; static int ...
20
#include <bits/stdc++.h> using namespace std; const int MX = 500005; const long long MD = 1000000007; int mul(int a, int b) { return ((long long)a * (long long)b) % MD; } int pow(int a, int b) { int ans = 1; while (b > 0) { if (b % 2 == 1) { ans = mul(ans, a); } a = mul(a, a); b /= 2; } re...
14
#include<bits/stdc++.h> using namespace std; typedef long long ll; int i,j,k,sb[100500],md,n; void get(int k){ if(k==0||k>n){return;} printf("? %d\n",k);fflush(stdout);scanf("%d",&sb[k]); } bool chk(int k){return (sb[k]<sb[k-1]&&sb[k]<sb[k+1]);} void ask(int l,int r){ if(l>r){return;} md=(l+r)>>1; get(md-1);ge...
9
#include <bits/stdc++.h> using namespace std; const int N = 500005; int n, a[N], l[N], r[N]; int main(void) { int i, j; while (~scanf("%d", &n)) { for (i = 1; i <= n; i++) scanf("%d", &a[i]); int maxx = 0, temp = 0, cnt = 0, ok = 0; for (i = 2; i <= n; i++) { if (a[i] != a[i - 1]) { if (!o...
9
#include <bits/stdc++.h> using namespace std; int a[(int)1e5 + 5], n, q, d[320][(int)1e5 + 5], p, k; int K = 320; int go(int k, int v) { if (v > n) return 0; return go(k, v + k + a[v]) + 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for...
12
#include <bits/stdc++.h> using namespace std; const long long p = 1e9 + 7; long long inv(long long a) { return a == 1 ? 1 : (long long)(p - p / a) * inv(p % a) % p; } long long C(long long n, long long m) { if (m < 0) return 0; if (n < m) return 0; if (m > n - m) m = n - m; long long up = 1, down = 1; for (...
7
#include <bits/stdc++.h> using namespace std; struct dsu { vector<int> P, rank; dsu(int n) : P(n), rank(n) { for (int i = 0; i < n; i++) { P[i] = i; rank[i] = 0; } } int fnd(int i) { if (i != P[i]) P[i] = fnd(P[i]); return P[i]; } void join(int x, int y) { int PX = fnd(x); ...
13
#include <bits/stdc++.h> using namespace std; long long mod; int N, M, ONE, TWO; char inp[505][505]; int col[505], row[505]; int sum[505]; int rev[1010]; bool vis[505][505]; long long DP[505][505]; long long F(int pos, int one, int two) { if (pos == N) return 1; if (col[pos] == 0) return F(pos + 1, one, two); if ...
13
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; using _ii = pair<int, int>; const int N = 107; int t, n, k; i64 dp_in[N][N], dp_out[N][N], C[N][N], f[N][N], ans, mod = 1e9 + 7; vector<vector<int>> a; void Pre() { for (int n = 0; n <= 100; n++) { for (int k = 0; k <= n; k++) { if (k == n) ...
14
#include <bits/stdc++.h> using namespace std; int main() { short int i = 0, s = 0, n, x; cin >> n >> x; x--; short int t[n]; for (i = 0; i < n; i++) cin >> t[i]; if (t[x] == 1) s++; i = 1; short int plu = 0, minu = 0; while (x + i < n || x - i >= 0) { short int c = 0; plu = 0; minu = 0; ...
2
#include <bits/stdc++.h> using namespace std; bool b[55][55]; bool vi[55][55]; queue<pair<int, int> > q; int main() { ios::sync_with_stdio(false); int n; cin >> n; b[1][1] = 1; b[n][n] = 0; vi[1][1] = vi[n][n] = 1; q.push({1, 1}); while (!q.empty()) { int x = q.front().first; int y = q.front().s...
16
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimization("unroll-loops") std::pair<int, int> DR[] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}, {-1, 1}, {-1, -1}, {1, 1}, {1, -1}}; using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> ran...
11
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 1; int n, q, ar[N], bs, fen[N], ans[N]; vector<pair<int, int> > qry[N]; void update(int x, int v = -1) { for (; x <= n + 1; x += x & -x) fen[x] += v; } int query(int x) { int res = 0; for (; x; x -= x & -x) res += fen[x]; return res; } int main()...
15
#include <bits/stdc++.h> int n, m, x, y, l, ans, now, d[600005], son[600005], ed[600005], next[600005], b[600005]; void add(int x, int y) { ed[++l] = y, next[l] = son[x], son[x] = l; } bool dfs(int x, int last) { b[x] = 1; for (int p = son[x]; p; p = next[p]) { int y = ed[p]; if (y == last) continue; ...
19
#include <bits/stdc++.h> void sort(int a[], int n) { int i, j, m; while (n--) { for (i = 0; i < n; i++) { j = i + 1; if (a[j] < a[i]) { m = a[j]; a[j] = a[i]; a[i] = m; } } } } int main() { int n, c = 0, a[150], i; double s = 0; scanf("%d", &n); for (i = 0...
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx") using namespace std; template <typename T> void uin(T &a, T b) { if (b < a) a = b; } templat...
9
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > v; bool f(pair<long long, long long> a, pair<long long, long long> b) { return (a.first > b.first) || (a.first == b.first && a.second < b.second); } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long n; cin >...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { long long x, y, n; cin >> x >> y >> n; long long per = n / x; while (1) { if (per * x + y <= n) { cout << per * x + y << '\...
0
#include <bits/stdc++.h> using namespace std; long long int modexp(long long int a, long long int n) { long long int r = 1; while (n) { if (n & 1) r = (r * a) % 1000000007; a = (a * a) % 1000000007; n >>= 1; } return r; } bool cmpfunc(const pair<int, int> &u, const pair<int, int> &v) { if (u.first...
9
#include <bits/stdc++.h> using namespace std; long long N = 500005; long long MAX = 9223372036854775807; long long MOD = 1000000007; long long nbr; bool visited[200005]; vector<long long> mp[200005]; vector<long long> dist; vector<long long> UI(2 * 1e5 + 5, 0); void dfs(long long s) { visited[s] = true; nbr++; di...
1
#include <bits/stdc++.h> using namespace std; string str; vector<int> cnt(26, 0); int main() { cin >> str; for (int i = 0; i < str.size(); i++) cnt[str[i] - 'a']++; vector<int> odd; for (int i = 0; i < 26; i++) { if (cnt[i] % 2) odd.push_back(i); } for (int i = 0; i < odd.size() / 2; i++) { cnt[odd[...
10
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; bool mark[N]; vector<int> G[N]; bool DFS(int r, int pr) { mark[r] = true; for (int u : G[r]) if (!mark[u]) { if (DFS(u, r)) return true; } else if (u != pr) return true; return false; } int main() { ios_base::sync_with_stdi...
8
#include <bits/stdc++.h> using namespace std; set<char> S; int main() { string s; cin >> s; bool flag = 0; S.insert('A'); S.insert('H'); S.insert('I'); S.insert('V'); S.insert('M'); S.insert('O'); S.insert('T'); S.insert('U'); S.insert('W'); S.insert('X'); S.insert('Y'); for (int i = 0; i ...
2
#include <bits/stdc++.h> using namespace std; int L, b, f, n; int main() { vector<int> x((int)2e5); cin >> L >> b >> f >> n; vector<pair<int, int>> v; for (int i = 0; i < n; i++) { int type; cin >> type; if (type == 1) { int len; cin >> len; int place = 0, begin = 0; bool got...
10
#include <bits/stdc++.h> const int MOD = 998244353; inline int lgput(int a, int b) { int ans = 1; while (b > 0) { if (b & 1) ans = (1LL * ans * a) % MOD; b >>= 1; a = (1LL * a * a) % MOD; } return ans; } inline void mod(int &x) { if (x >= MOD) x -= MOD; } inline void add(int &x, int y) { x += y;...
7
#include <bits/stdc++.h> using namespace std; float a[11][11]; int main() { long long int n, t; cin >> n >> t; a[1][1] = t - 1; long long int ans = a[1][1] >= 0 ? 1 : 0; for (int i = 2; i < n + 1; i++) { for (int j = 1; j < i + 1; j++) { a[i][j] = -1; if (a[i - 1][j - 1] >= 0) a[i][j] += a[i -...
7
#include <bits/stdc++.h> using namespace std; const int N = 105; int n, m, a[N], b[N], f[N][N]; template <class T> inline bool ten(T &x, const T &y) { return y < x ? (x = y, 1) : 0; } void init() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); a[0] = a[n]; for (int i = 1; i <= n; i++...
17
#include <bits/stdc++.h> template <typename T> bool ckmax(T &x, T y) { return x < y ? x = y, true : false; } template <typename T> bool ckmin(T &x, T y) { return x > y ? x = y, true : false; } using namespace std; const long long inf = 1000000000; const double Pi = acos(-1); const long long mod = 998244353; const d...
15
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9; const long long LINF = 2e16; const int INF = 2e9; const int magic = 348; const double eps = 1e-10; const double pi = acos(-1); inline int getint() { char ch; int res; bool f; while (!isdigit(ch = getchar()) && ch != '-') { } if (ch == '-') ...
15
#include <bits/stdc++.h> using namespace std; int main() { int t; int arr[10]; arr[0] = 0; cin >> t; arr[0] = 0; while (t--) { arr[0] = 0; string s; arr[0] = 0; cin >> s; arr[0] = 0; bool f = 0; arr[0] = 0; for (int i = 0; i < s.size() - 1; i++) { arr[0] = 0; if (...
3
#include <bits/stdc++.h> using namespace std; int main() { string s; int i, cnt = 0; cin >> s; for (i = 0; i < s.size(); i++) { if (s[i] == '1') cnt++; } if (cnt >= 2) cout << (s.size() + 1) / 2 << endl; else cout << s.size() / 2 << endl; return 0; }
2
/* 2013-08-11 09:17:07.794206 */#include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <cmath> #include <iostream> #include <algorithm> using namespace std; int n; double ans, dist[5001][5001], a[5001][3]; int main(){ // freopen("d.in", "r", stdin); scanf("%d", &n); for (int i = 1; i <=...
10
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const long long int inf = 10000000000000000LL; const long long int mod = 1000000007; struct Node { vector<int> nbr; long long int v; }; long long int dfs(vector<Node>& arr, int v, int d) { if (d == 0) { for (int i = 0; i < (arr.size...
8
#include <bits/stdc++.h> using namespace std; int n; int gene[22]; bool cmp[22]; int pos[22]; vector<vector<int> > AdjList; bool no_usar[22]; long long memo[(1 << 17)]; long long sol(int mask) { int id = __builtin_popcount(mask); if (id == n) return 1; if (memo[mask] != -1) return memo[mask]; int grados[17]; ...
16
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") using namespace std; using ll = long long; using ld = long double; const ll MOD = 1000000007; const ll root = 62; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } ll binpow(ll a, ll b) { ...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 2000; inline int read() { int rtn = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) rtn = (rtn << 1) + (rtn << 3) + ch - '0'; return rtn * f; } int ans1[maxn], ans2...
14
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; const long long SZ = 210, SSZ = 0, APB = 26, one = 93, INF = 0x7FFFFFF, mod = 1000000007; long long n, m, cnt, mk[SZ], fail[SZ]; long long arr[SZ], nex[SZ][APB]; long long src[SZ][SZ]; char ch[SZ]; void add(long long pos) { long lo...
17
#include <bits/stdc++.h> using namespace std; using LD = long double; using PLL = pair<long long, long long>; using VII = vector<pair<int, int> >; template <class T> bool power_2(T v) { static_assert(std::is_integral<T>::value, "type should be integral"); return v && !(v & (v - 1)); } template <class T> istream& op...
13
#include <bits/stdc++.h> using namespace std; const int N = 5010; const int inf = 0x3f3f3f3f; int n, x; bool is_prim(int x) { for (int i = 2; i * i <= x; i++) if (x % i == 0) return 0; return 1; } long long pow(long long a, long long b, long long mod) { long long ret = 1; while (b) { if (b & 1) ret = re...
18
#include <bits/stdc++.h> #define ed end() #define bg begin() #define mp make_pair #define pb push_back #define all(x) x.bg,x.ed #define newline puts("") #define si(x) ((int)x.size()) #define rep(i,n) for(int i=1;i<=n;++i) #define rrep(i,n) for(int i=0;i<n;++i) #define srep(i,s,t) for(int i=s;i<=t;++i) #define drep(i,s...
10
#include <bits/stdc++.h> using namespace std; const double pi = 3.1415926535; const int MX = 1e2 + 7; const double val = pi / 180.0; const int INF = 0x3f3f3f3f; int a[MX]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } int ans = INF; int flag = 0; int t = 0; for (int i =...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 7; const int inf = 1e9 + 7; int gt[maxn][19], a[maxn], last[19], n, q; int main() { cin >> n >> q; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int j = 0; j < 19; j++) { gt[n][j] = n; last[j] = n; } for (int i = n - 1; i >...
14
#include <bits/stdc++.h> using namespace std; const int64_t INF = 2e9, MOD = 998244353; int32_t main() { ios_base::sync_with_stdio(false); int64_t n, m; cin >> n >> m; vector<int64_t> a(n), b(m); for (int64_t i = 0; i < n; i++) cin >> a[i]; for (int64_t j = 0; j < m; j++) cin >> b[j]; reverse(a.begin(), a...
13
#include <bits/stdc++.h> int f(int64_t s, int64_t e) { return (e % 2 || s > e / 4 * 2) ? (e - s & 1) : (s > e / 4 || f(s, e / 4)); } int main() { int n, l = 1, w = 0; std::cin >> n; while (n-- && w != l) { int64_t x, y; std::cin >> x >> y; l = (x > y / 2 || f(x, y / 2)) ^ w; w ^= f(x, y); } ...
19
#include <bits/stdc++.h> using namespace std; string G[111]; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, -1, 0, 1}; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) cin >> G[i]; int sx, sy, ex, ey; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (G[i][j] == 'S...
4
#include <bits/stdc++.h> int Fl, Pn, SI = 100; char mch = ' ', ch, Bf[21]; template <typename t> void in(t& a) { a = 0; ch = getchar(); Fl = 1; while ((ch < '0') || (ch > '9')) Fl = (ch == '-') ? -Fl : Fl, ch = getchar(); while ((ch >= '0') && (ch <= '9')) a = a * 10 + ch - '0', ch = getchar(); a *= Fl; } t...
7
#include <bits/stdc++.h> using namespace std; map<long long int, long long int> m[2], m2, mc[1000]; map<string, int> ms; int k; bool v[520][520]; int r[502][502], c[502][502]; int main() { int h, w; cin >> h >> w; char a[502][502]; for (long long int i = 0; i < h; ++i) for (long long int j = 0; j < w; ++j) ...
7
#include <bits/stdc++.h> using namespace std; const long long M = 1000000007; const long long MM = 998244353; long long begtime = clock(); long long newmod(long long a, long long b) { return ((a % b) + b) % b; } long long powM(long long a, long long b, long long m) { if (a <= 0) return 0; a %= m; if (!b) return 1...
7
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y) { long long res = 1; while (y) { if (y % 2) { res *= x; } y /= 2; x *= x; } return res; } long long power(long long x, long long y, long long z) { long long res = 1; while (y) { if (y % 2) { ...
10
#include <bits/stdc++.h> using namespace std; int n, p, v[301]; int main() { scanf("%d%d", &p, &n); bool check = false; for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); if (v[x % p]) { printf("%d\n", i); return 0; } v[x % p] = true; } if (!check) printf("-1\n"); return ...
0
#include <bits/stdc++.h> using namespace std; int main() { int h, m, mb; double hp, mp, ah, am, a, b; char c; cin >> h >> c >> m; h = h % 12; if (h == 0 && m == 0) { cout << "0 0\n"; } else { hp = (double)h; mp = (double)m / 5.0; mb = m / 5; b = (double)mb; am = mp * 30.0; a = ...
4
#include <bits/stdc++.h> using namespace std; template <typename T> inline T max(T a, T b, T c) { return max(max(a, b), c); } template <typename T> inline T max(T a, T b, T c, T d) { return max(max(a, b), max(c, d)); } template <typename T> inline T min(T a, T b, T c) { return min(min(a, b), c); } template <typen...
6
#include <bits/stdc++.h> using namespace std; int a[50010], b[50010]; bool flag[50010]; struct node { int v, id; node(int v = 0, int id = 0) : v(v), id(id) {} bool operator<(const node& a) const { return v < a.v; } }; void solve() { string s; cin >> s; int n = 0; for (int i = 0; i < s.size(); i++) if ...
18
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; ++i) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n / 2; ++i) { if (a[i] > 0) { cout << -(abs(a[n - i - 1])) << " "; } els...
0
#include <bits/stdc++.h> using namespace std; int n, m, ans; int main() { scanf("%d:%d", &n, &m); while (1) { if (n % 10 == m / 10 && n / 10 == m % 10) break; ans++; m++; if (m == 60) { m = 0; n++; } if (n == 24) n = 0; } printf("%d\n", ans); return 0; }
2
/** * author: tourist * created: 13.03.2021 14:01:42 **/ #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, typ...
27
#include <bits/stdc++.h> using namespace std; int arr[100000]; int n, k; int key[256]; int len[256] = {0}; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; for (int(i) = 0; (i) < (256); (i)++) key[i] = -1; for (int i = 0; i < n; i++) { if (key[arr[i]] == -1) { int s = max(0, arr[...
9
#include <bits/stdc++.h> int main() { int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d); int A = 4 + (2 * a) + (2 * b) - c; int B = 2 * (d - 1) + 2 + c; printf("%d\n", A + B); return 0; }
0
#include <bits/stdc++.h> const int MAXN = 2e5 + 5; struct Node { int a[5][5]; Node(int x = 0) { memset(a, 0, sizeof(a)); } inline Node operator*(const Node &t) const { Node res; for (int i = 0; i <= 4; ++i) { for (int j = 0; j <= 4; ++j) { res.a[i][j] = -1e9; for (int k = 0; k <= 4; ...
18
#include <bits/stdc++.h> using namespace std; int faltu = 0; int che = 1; int count(long long int n) { if (n == 0) return faltu; int j = n % 10; if (j == 0 || j == 1) ; else che = 0; n /= 10; faltu++; return count(n); } int N = 1e5; vector<bool> prime(N + 1, true); vector<int> prim; void pri() { ...
5
#include <bits/stdc++.h> using namespace std; int main() { long long a[60]; for (int i = 1; i <= 6; ++i) cin >> a[i]; long long ans = 0; ans -= a[1] * a[1] + a[3] * a[3] + a[5] * a[5]; ans += (a[1] + a[2] + a[3]) * (a[1] + a[2] + a[3]); cout << ans << '\n'; return 0; }
8
#include <bits/stdc++.h> using namespace std; void FAST() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } long long gcd(long long x, long long y) { if (x == 0) return y; return gcd(y % x, x); } long long powM(long long x, long long y, long long m) { long long ans = 1, r = 1; x %= m; while (r > 0 &...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; const int MOD = 1e9 + 7; int n, ans = 0; long long x[maxn]; vector<int> G[maxn]; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } void dfs(vector<pair<long long, int> > gcd_ls, int u, int p = 0) { vector<pair<long lon...
12
#include <bits/stdc++.h> using namespace std; struct MoData { int l, r, add, id; }; const int MAXN = 100100; vector<int> g[MAXN]; int dep[MAXN]; int par[MAXN][20]; int LOG = 0; int n; int cnt[MAXN] = {0}; int f[MAXN]; int ff[MAXN]; bool isGirl[MAXN]; int npath = 0; int path[2 * MAXN]; int val, to, from, q, p; int st[...
15
#include <bits/stdc++.h> using namespace std; int n, m; string s[3][3000], str; bool flag = 1; int main() { cin >> n >> m; for (int i = 0; i < m; i++) { cin >> s[0][i] >> s[1][i]; if (s[0][i].size() <= s[1][i].size()) s[2][i] = s[0][i]; else s[2][i] = s[1][i]; } for (int i = 0; i < n; i+...
2
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long a[n], b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; long long mx = 0; for (int j = 0; j < a[i]; j++) { long long k; cin >> k; b[i] = max(mx, k); mx = b[i]; } } long long mx ...
5
#include <bits/stdc++.h> using namespace std; long long k; int t; map<pair<int, vector<int> >, long long> mark; vector<int> num = vector<int>(16); long long numWay(int digit, vector<int>& vec) { if (long long x = mark[make_pair(digit, vec)]) return x - 1; if (digit == 0) { mark[make_pair(digit, vec)] = 2; r...
17
#include <bits/stdc++.h> using namespace std; inline long long gcd(long long a, long long b) { a = ((a) < 0 ? -(a) : (a)); b = ((b) < 0 ? -(b) : (b)); while (b) { a = a % b; swap(a, b); } return a; } const long long inf = 2147383647; const long long mod = 1000000007; const double pi = 2 * acos(0.0); c...
10
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int FFTMOD = 119 << 23 | 1; const int INF = (int)1e9 + 23111992; const long long LINF = (long long)1e18 + 23111992; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b)...
19
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int a[1010], C[1010][1010]; int dp[1010]; int main() { C[0][0] = 1; for (int i = 1; i < 1010; i++) { for (int j = 0; j <= i; j++) { C[i][j] = C[i - 1][j]; if (j) C[i][j] += C[i - 1][j - 1]; if (C[i][j] >= mod) C[i][j] -= ...
11
#include <bits/stdc++.h> using namespace std; bool valid; long long ans; void dfs(long long i, vector<pair<long long, long long>> adj[], long long colour[], long long c[]) { c[colour[i]]++; long long j, l = adj[i].size(); for (j = 0; j < l; j++) { if (colour[adj[i][j].first] == -1) { colour[adj...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; int b[101] = {0}, c[101] = {0}, vis[101] = {0}; for (int i = 1; i <= k; i++) b[i] = a[i]; int t = 0, ans = 0, d =...
8