solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; struct node { int x, y; } p[MAXN]; vector<int> g[MAXN]; int n; int rt[MAXN], cnt, ls[MAXN * 80], rs[MAXN * 80], sum[MAXN * 80]; void modify(int &x, int y, int l, int r, int pos) { x = ++cnt; if (l == r) { sum[x] = 1; return; } int...
6
#include <bits/stdc++.h> using namespace std; long long BigMod(long long B, long long P, long long M) { long long R = 1; while (P > 0) { if (P % 2 == 1) { R = (R * B) % M; } P /= 2; B = (B * B) % M; } return R; } int main() { long long n, m, k, k1, k2, first, second; cin >> n >> m; c...
1
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> ii; bool comp(pair<ii, int> a, pair<ii, int> b) { return a.first.first + a.first.second > b.first.first + b.first.second; } int main() { int n; cin >> n; pair<ii, int> arr[n]; for(int i = 0; i < n; ++i) { int w, s, v; cin...
0
#include "bits/stdc++.h" using namespace std; int main() { int N; cin >> N; if (N <= 2) cout << (N == 1) + 1 << endl; else cout << 0 << endl; }
0
#include <bits/stdc++.h> int b[100001]; int main() { int n, k, i, a; scanf("%d %d", &n, &k); for (i = 1; i <= n; i++) { scanf("%d", &a); b[(i % k)] += a; } int min = 0xFFFFFFF, tmp; for (i = 0; i < k; i++) { if (b[i] < min) { min = b[i]; if (i == 0) tmp = k; else ...
2
#include<iostream> #include<algorithm> using namespace std; int N; int A[15][15]; int main() { cin>>N; for(int i=0;i<N;i++) { int a;cin>>a; for(int j=0;j<a;j++) { int x,y;cin>>x>>y; x--; A[i][x]=y==1?1:-1; } } int ans=0; for(int i=1;i<1<<N;i++) { int c[15]={}; bool flag=true; for(int j=0;j...
0
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)n;i++) #define all(c) (c).begin(),(c).end() #define pb push_back #define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0); using namespace std; namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(cons...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int n, x, t; cin >> t; while (t--) { cin >> n >> x; cout << 2 * x << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; struct Item { long long sum; long long row; long long column; }; int main() { std::ios::sync_with_stdio(false); int n; cin >> n; vector<Item> titems; for (int i = 1; i <= n; i++) { int number; cin >> number; long long sum = 0; vector<long lon...
3
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e1; long long n, m, ans, dp[1 << MAXN][MAXN]; bool edge[MAXN][MAXN]; vector<long long> adj[MAXN]; int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m; for (long long u, v, i = 1; i <= m; i++) { cin >> v >> ...
4
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> ii; const int N = 100005; set<int> g[N]; int p[N]; int num = 0; int find(int x){ return x == p[x] ? x : p[x]=find(p[x]); } void merge(int u, int v){ u = find(u), v = find(v); if (u == v) return; if (g[u].size() < g[v].size()) swap(u,v);...
0
#include <bits/stdc++.h> using namespace std; int n; string s; int cal() { int l = 0; int r = 0; int h = 0; int c; for (int i = 0; i < n; i++) { if (s[i] == '(') l++; if (s[i] == ')') r++; if (s[i] == '#') h++; } if (r >= l) return 0; if (l < r + h) return 0; c = l - r; l = 0; r = 0; ...
1
#include<iostream> #include<cmath> #include<algorithm> #include<cstdio> using namespace std; int s,n,t,p,m; string w,ti; int can[11000]; const int halfday = 720; const int week = 10080; int main(){ while(cin >> s >> n >> t >> w >> ti >> p >> m,w!="None"){ for(int i=0;i<week;i++)can[i] = false; int loop = (...
0
#include<stdio.h> #include<string.h> int main() { char a[51], b[51]; scanf("%s %s", a,b); int i,l=strlen(b); for(i=0; i<l; i++) printf("%c%c", a[i], b[i]); if(strlen(a)==l+1) printf("%c", a[i]); return 0; }
0
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios_base::sync_with_stdio(false); cout << fixed; cout.precision(10); int t = 1; for (int i = 1; i <= t; ++i) { solve(); } return 0; } vector<int> a; vector<int> used; void go(int v) { used[v] = 1; if (v == a.size()) return; ...
1
#define _USE_MATH_DEFINES #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> int main() { double N,P=0; double x,y; double p=0,P1=0; x=0;y=0; while(1) { scanf("%lf,%lf",&N,&P1); if((int)N==0&&(int)P1==0)break; x+=N*sin(P*M_PI/180);y+=N*cos(P*M_PI/180); P+=P1; } int X,Y; X=(int)x;Y=(int)y; pr...
0
#include <algorithm> #include <iostream> #include <vector> using namespace std; template<typename T> vector<T> compressed(vector<T> v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); return v; } int main() { int n; cin >> n; vector<int> a(n); for (int &ai: a) cin >> a...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 10000 + 10; const int prime[25] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}; const int modnum[5] = {223092870, 58642669, 8965109, 27433619, 716539}; int n, d, m, len; long lon...
5
#include <iostream> int main() { std::string S; std::cin >> S; S.erase(S.end() - 8, S.end()); std::cout << S << std::endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int MX = 140140; struct Node { long long x[10]; char nxt[10]; bool need; } a[MX * 10]; int b[MX], mx, n, m, i, t, l, r, xfr, y; long long j, res, cur[10], scur[10]; void init(int i, int l, int r) { for (int j = 0; j < 10; j++) a[i].nxt[j] = j; if (l == r) { ...
6
#include <bits/stdc++.h> using namespace std; __attribute__((constructor)) static void fast_cin() { ios_base::sync_with_stdio(false); cin.tie(0); } using ll = int64_t; using ull = uint64_t; using mp = pair<ll, ll>; using mt = tuple<ll, ll, ll>; template <typename T, typename R> istream &operator>>(istream &fin, pai...
1
#include<iostream> #include<vector> using namespace std; typedef long long int lli; template<typename Integer> Integer GCD(Integer a, Integer b){ if(!b)return a; else return GCD(b,a%b); } template<typename Integer> inline pair<Integer, pair<Integer, Integer> > ExtendedGCD(Integer a, Integer b){ pair<Integer, ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; vector<int> V(N); for (int &X : V) cin >> X; int Ans = min(V[0], V[N - 1]); int Cnt = 0; while (Cnt < N - 2) { if (V[Cnt + 1] > V[Cnt + 2]) { Ans = min(Ans, V[Cnt + 1]...
2
#include <bits/stdc++.h> using namespace std; int a[2010] = {0}, b[2010] = {0}, n, x, y, sum = 0; void init() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &x, &y); a[x + y]++, b[1000 - x + y]++; } } void work() { for (int i = 0; i <= 2000; i++) { if (a[i]) sum += a[i] * (a[i] - 1);...
2
#include <iostream> #include <string> using namespace std; #define ref(i,x,y)for(int i=x;i<=y;++i) const int mod=1e9+7; const int N=410; int n; int a[N],b[N],f[N/3][N][N][2],s[N][N],pa[N],pb[N],mk[N]; int mul(int a,int b) { return (1LL*a*b%mod+mod)%mod; } void inc(int&a,int b) { a=(a+b)%mod; } int main() { cin>>n; ...
0
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); int sum = 0; for(int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } sort(a.begin(), a.end()); if(sum % 2 == 0) { cout << sum / 2 << endl; } else { for(int i = 0;...
0
#include<bits/stdc++.h> using namespace std; int main() { int N; cin>>N; vector<int> par(N,-1),lch(N),rch(N); for(int i=0;i<N;i++){ int v; cin>>v; cin>>lch[v]>>rch[v]; if(lch[v]!=-1) par[lch[v]]=v; if(rch[v]!=-1) par[rch[v]]=v; } function<void(int)> preorder=[&](in...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; const int SQRTN = 1003; const int LOGN = 22; const double PI = acos(-1); const int INF = 1e9; int MOD = 1000000007; const int FMOD = 998244353; const double eps = 1e-9; void solve() { string s; cin >> s; long long n; cin >> n; long long a...
4
#include <bits/stdc++.h> char arr[200010]; int main(void) { int n, t, start = -1; scanf("%d %d", &n, &t); scanf("%s", arr + 1); for (int i = 1; i <= n; i++) { if (arr[i] == '.') { start = i; break; } } if (start == -1) { for (int i = 1; i <= n; i++) printf("%c", arr[i]); printf("...
3
#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> #pragma GCC optimize("Ofast", "unroll-loops") using namespace std; const int inf = 1000111222; const int max_n = 211; struct point { int x, y; }; long long get_sqr(const point& p1, const point& p2, const point& p3) { long long res = 0; res += (p2.x - p1.x) * 1LL * (p1.y + p2.y); res += ...
5
#include "bits/stdc++.h" #include<unordered_map> #include<unordered_set> #pragma warning(disable:4996) using namespace std; using ld = long double; 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_...
0
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e5; bool checkstring(string a, long long n_a, string b, long long n_b) { for (long long i = 0; i < min(n_b, n_a); ++i) if (a[i] != b[i]) return false; return true; } void solve() { int n; char a[100]; cin >> a; int small = 0, large = 0...
1
#include <algorithm> #include <cstring> #include <cstdio> int val[100005], app[25], seq[25]; int dp[100005], pop[100005], sum[100005]; int main() { // freopen("E.in", "r", stdin); int n, m = 0, ans = 0; scanf("%d", &n); for (int i = 1; i < n; i++) { int u, v, w; scanf("%d%d%d", &u, &v, &w); val[u] ^= w; va...
0
/* Do you like it heavy Do you love it mean Do you want it dirty We don't play it clean Standing in the spotlight Ceiling to the floor I can see you rockin' Let me hear you roar Turn it up Tear it down Hammering through Can you feel the sound Any day, Any night Midnight madness Dynamite If you want it Come and get ...
1
#include <bits/stdc++.h> using namespace std; int a[101010]; int f[101010]; bool visit[101010]; int main() { int q, n, maxb, t; scanf("%d %d %d %d", &q, &n, &maxb, &t); t = min(t, maxb); while (q--) { memset(f, 0, sizeof(f)); maxb = 0; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); m...
4
#include <iostream> #include <vector> #include <deque> #define MAXN 200005 #define mod 1000000007 using namespace std; int n, dad[MAXN], crtDp, idxDp[MAXN], lvlCount[MAXN]; int pw2[MAXN]; vector<int> G[MAXN]; deque<int> dp[MAXN][3]; void precalc() { pw2[0] = 1; for (int i = 1; i < MAXN; ++i) pw2[i] = ...
0
#include <bits/stdc++.h> using namespace std; int n; char s[100100], t[100100]; long long ans, a[100100], b[100100]; int main() { scanf("%d %s %s", &n, s, t); for (int i = 0; i < n; i++) a[i] = s[i], b[i] = t[i]; for (int i = 0; i < n; i += 2) { ans += a[i] - b[i]; ans -= a[i + 1] - b[i + 1]; } if (an...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, l; scanf("%d%d", &n, &l); int a[100]; for (int i = 0; i < n; ++i) scanf("%d", a + i); int ans = 0; for (int i = l; i <= 100; ++i) { int c = 0; for (int k = 0; k < n; ++k) c += a[k] / i; ans = max(ans, c * i); } printf("%d\n", ...
3
#include <bits/stdc++.h> using namespace std; const long long md=998244353; const int maxn=300100; long long fac[maxn],inv[maxn]; long long powd(long long x,long long y){ long long res=1; while(y){ if(y&1) res=res*x%md; x=x*x%md; y>>=1; } return res; } void csh(){ fac[0]=1; for(int i=1;i<=300000;i++) fac...
0
#include <iostream> using i64 = long long; const int N = 300000 + 7; int n; i64 a[N], b[N], s[2]; i64 l, r, m, p; int main() { // freopen("code.in", "r", stdin); // freopen("code.out", "w", stdout); scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%lld", a + i), b[i] = b[i - 1] + (i & 1 ? 1 : -1) * a[i],...
0
#include <bits/stdc++.h> using namespace std; int ni() { int a; scanf("%d", &a); return a; } const int N = 3e5 + 1; const int PATHSZ = 3e5 + 1; unsigned long long modpow(unsigned long long a, unsigned long long b, unsigned long long mod) { if (b == 0) return 1; if (mod == 0) { if...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n; cin >> n; vector<long long int> v; unordered_map<long long int, long long int> m; for (long long int i = 0; i < n; i++) { long long int a; cin >> a; m[a]++; ...
4
#include<bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; vector<pair<int, int>> A(N); for(int i = 0; i < N; i++){ cin >> A[i].first; A[i].second = i; } sort(A.begin(), A.end()); long long yi = 0; for(int i = 0; i < N; i++){ if((A[i].second ^ i) & 1) ++yi; } cout ...
0
#include <bits/stdc++.h> template <typename T> class IntegerIterator : public std::iterator<std::input_iterator_tag, T, std::ptrdiff_t, T*, T> { public: explicit IntegerIterator(T value) : value(value) {} IntegerIterator& operator++() { ++value; return *this; } IntegerIterator operator++(int) { ...
3
#include <bits/stdc++.h> using namespace std; const int N = 2e5; const double INF = 1e18; struct Point { double x, y; Point() {} Point(double x, double y) : x(x), y(y) {} } p[N]; int max1[N], max2[N]; double deltA[N], deltB[N]; double sqr(double x) { return x * x; } double dist(const Point &a, const Point &b) { ...
1
#include <bits/stdc++.h> using namespace std; vector<string> rjesenja; int prime[1000100]; int main() { long long n, a, b; cin >> n; for (int i = 2; i < 1000000; i++) { if (!prime[i]) { for (int j = i * 2; j <= 1000000; j += i) prime[j] = 1; } } for (int i = 0; i < n; i++) { cin >> a; b ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n], k = 0; while (n != 0) { int temp = n, i = 0, j = 1; while (temp) { if (temp % 10 != 0) { i += j; } j *= 10; temp /= 10; } n = n - i; arr[k++] = i; } sort(arr, arr + k);...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, t = 0, c = 0; char ch[105][105]; cin >> n; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cin >> ch[i][j]; for (int i = 1; i <= n; i++) { c = 0; for (int j = 1; j <= n; j++) { if (ch[i][j] == 'C') c++; } t +...
1
#include <bits/stdc++.h> using namespace std; int main(int argc, char const* argv[]) { vector<int> v; int n; char c; while (true) { scanf("%d", &n); v.push_back(n); if (scanf("%c", &c) == EOF || c != ',') break; } sort(v.begin(), v.end()); bool first = true; int minR = v[0]; int maxR = v[0...
3
#include <bits/stdc++.h> using namespace std; 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; } template <class Iter> void rprintf(const char *fmt, Iter begin, Iter end) { for (bool sp = 0; begin != end; ++begin)...
5
#include <bits/stdc++.h> using namespace std; int p[100009], A[100009]; vector<int> tree[100009]; long long ans = 0; void go(int now) { if (A[now] != -1) { int dif = A[now] - A[p[now]]; if (dif < 0) { puts("-1"); exit(0); } ans += dif; } else { if (tree[now].size() == 0) return; ...
1
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 10; int n, nxt[MAX_N][26 + 10], f[MAX_N], ans; vector<pair<int, string>> adj[MAX_N]; string s; void dfs(int v, int par = 0, int cur = 0) { int tmp; string ss; for (auto u : adj[v]) { if (u.first != par) { ss = u.second; tmp = cu...
5
#include<iostream> int main(){ int n; std::cin>>n; for(int i=0;i<10;++i)for(int j=0;j<10;++j) if(i*j==n){ puts("Yes"); return 0; } puts("No"); }
0
#include <bits/stdc++.h> using namespace std; const int N = 8e6 + 5; int a[N], tot, n; bool hs[N], vis[N]; void dfs(int x) { if (vis[x]) return; vis[x] = true; if (hs[x]) dfs(tot ^ x); for (int i = 0; i < n; i++) { if (x & (1 << i)) dfs(x ^ (1 << i)); } } int main() { int m; scanf("%d%d", &n, &m); f...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6; int n; char s[maxn + 1]; int Check(void) { int x = 0; for (int i = 0; i < n; ++i) x = (10 * x + s[i] - '0') % 7; return x; } void Find(int x, int j) { int i = find(s, s + n, '0' + x) - s; swap(s[i], s[j]); } int main(void) { scanf("%s", s);...
1
#include <bits/stdc++.h> using namespace std; int main(){ int N,M;cin>>N>>M; int count=0; for(int i=0;i<M;i++){int a;cin>>a;count=max(count,a);} cout<<max(0,count*2-N-1)<<endl; }
0
#include <bits/stdc++.h> const long long inf = 9223372036854775807ll; const int iinf = 2147483647; const int limit = 1048576; using namespace std; bool sync_with_stdio(bool sync = false); int main() { int n, T; scanf("%d%d", &n, &T); vector<int> a(n + 1); for (int i = (int)1; i < (int)n + 1; i++) scanf("%d", &a...
2
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<cstdlib> #define size sz using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; const int MAXN=200005; int n,len; int color[MAXN],head[MAXN],size[MAXN],num[MAXN]; ll ans[MAXN]; struct node{ int to,next; } e[MAXN * 2];...
0
#include<bits/stdc++.h> using namespace std; using ll=long long; ll check(vector<pair<ll,ll>> vt){ ll n = vt.size(); for(int i=0;i<n;i++) vt[i].first=min(vt[i].first,n); vector<vector<ll>> vs(n+1); for(int i=0;i<n;i++) vs[vt[i].first].emplace_back(vt[i].second); priority_queue<ll> que; ll ans=0; for(int...
0
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 3; const long long INFF = (long long)5e18 + 7; vector<int> edge[N]; int nd; int id[N], used[N], siz[N]; void sol(int n) { set<pair<int, int>> st; for (int i = 1; i <= n; i++) { siz[i] = (int)edge[i].size(); st.insert({siz[i], i}); } ...
4
#include <bits/stdc++.h> using namespace std; void read(int &k) { k = 0; char x = getchar(); while (x < '0' || x > '9') x = getchar(); while (x >= '0' && x <= '9') { k = k * 10 - 48 + x; x = getchar(); } } int n, a[200010], b[200010], now, ans; int main() { scanf("%d", &n); for (int i = 1; i <= n;...
1
/* AuThOr GaRyMr */ #include<bits/stdc++.h> #define rb(a,b,c) for(int a=b;a<=c;++a) #define rl(a,b,c) for(int a=b;a>=c;--a) #define LL long long #define IT iterator #define PB push_back #define II(a,b) make_pair(a,b) #define FIR first #define SEC second #define FREO freopen("check.out","w",stdout) #define rep(a,b) for(...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int g[105][105] = {}; for (int i = 0; i < n; i++) { int a, b, c; cin >> a >> b >> c; g[a - 1][b - 1] = c; } int start = 0; int visited[105] = {1}; vector<int> ring; ring.push_back(start); int s = start; for (in...
1
#include<stdio.h> #include<algorithm> using namespace std; int x[200]; int y[200]; int main(){ int a; while(scanf("%d",&a),a){ for(int i=1;i<a;i++){ int b,c;scanf("%d%d",&b,&c); x[i]=x[b]; y[i]=y[b]; switch(c){ case 0:x[i]--;break; case 1:y[i]--;break; case 2:x[i]++;break; case 3:y[i]++;...
0
#include<stdio.h> int main() { long long int a, b, n, m, c, d ,sa=0,sb=0; scanf("%lld %lld", &c, &d); for (n = 1; c >= n; n++) { scanf("%lld",&a ); sa += a; } for (m = 1; d >= m; m++) { scanf("%lld", &b); sb += b; } printf("%lld\n", sa*sb); return 0; }
0
#include<cstdio> #include<cctype> #include<cstdlib> #include<algorithm> typedef signed long long int int64; inline unsigned getint() { register char ch; while(!isdigit(ch=getchar())); register unsigned x=ch^'0'; while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0'); return x; } inline int64 min(const int64 &a,co...
0
#include <bits/stdc++.h> using namespace std; struct segment { int l, r; }; segment s[1010]; int n, ans[1010], m, pi[1010], d[1010]; bool operator<(const segment &a, const segment &b) { return a.r < b.r; } int main() { int i, j; cin >> n; for (i = 1; i <= n; i++) { cin >> s[i].l >> s[i].r; if (s[i].l > ...
4
#include <bits/stdc++.h> #include <cmath> using namespace std; int main() { int N; cin>>N; if(N%10==3) cout<<"bon"; else if(N%10==0 || N%10==1 || N%10==6 || N%10==8) cout<<"pon"; else cout<<"hon"; }
0
#include<iostream> #include<algorithm> using namespace std; long long power(long long x, long long n){ long long ans = 1; while(n){ if(n&1) ans *= x; n >>= 1; x *= x; } return ans; } long long Eulers_totient_function(int n){//1からnまでの自然数のnうちと互いに素なものの個数を求める int count = 1; for(int i = 2; i * i <= n; i++){ ...
0
#include <bits/stdc++.h> using namespace std; int dirs[4][2]{{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; void solve() { int N, M, K; cin >> N >> M >> K; bool lake[N][M]; for (int n = (0); n < (N); ++n) for (int m = (0); m < (M); ++m) { char c; cin >> c; lake[n][m] = c == '.'; } int id[N][M]; ...
4
#include <bits/stdc++.h> using namespace std; int arr[101] = {0}; int main() { int c = 0; while (~scanf("%d", &c)) { for (int i = 0; i < c; ++i) { scanf("%d", &arr[i]); } sort(arr, arr + c); if (c == 1) { printf("%d\n", arr[0]); } else { printf("%d\n", arr[c / 2]); } } }
1
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 1; vector<int> gx[maxn + 7]; vector<int> gy[maxn + 7]; long long g[maxn + 7]; int n; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); g[i] = maxn * x + y; gx[x].push_back(y); g...
4
#include <bits/stdc++.h> using namespace std; const int N = 100100; const int BIT = 17; int n, m; int P[N]; int pot2[33]; set<int> S[18]; set<int>::iterator it; long long sol; inline int find(int bit, int pos) { if (S[bit].empty()) return 0; it = S[bit].lower_bound(pos); if (it == S[bit].begin()) return 0; it--...
5
#include<cstdio> #include<algorithm> using namespace std; int price(int a,int b,int c) { int na=a/200,nb=b/300,nc=c/500; int pa=1520*(na/5)+380*(na%5); int pb=1870*(nb/4)+550*(nb%4); int pc=2244*(nc/3)+850*(nc%3); return pa+pb+pc; } int main() { int g; while(scanf("%d",&g),g){ int pmin=10000000; for(int c...
0
#define _USE_MATH_DEFINES #define INF 0x3f3f3f3f #include <cstdio> #include <iostream> #include <sstream> #include <cmath> #include <cstdlib> #include <algorithm> #include <queue> #include <stack> #include <limits> #include <map> #include <string> #include <cstring> #include <set> #include <deque> #include <bitset> #in...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; getchar(); char c; while ((c = getchar()) != EOF) putchar(c == '1' ? '2' : c); }
4
#include<cstdio> #include<queue> #include<algorithm> #include<iostream> using namespace std; int field[92][92] = { }; int vx[4] = { 1, -1, 0, 0 }; int vy[4] = { 0, 0, 1, -1 }; int ans=0,ANSW=0; int dfs(int X, int Y, int n){ if (field[X][Y]==0)return n; field[X][Y] = 0; for (int i = 0; i < 4; i++){ ans = max(ans...
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 ans[101][101]; vector<int> g[10001]; bool used[10001]; const int dx[]={1,0,-1,0},dy[]={0,1,0,-1}; int main(){ int n,a...
0
#include <bits/stdc++.h> using namespace std; template <typename T, typename V> ostream &operator<<(ostream &out, const pair<T, V> x) { out << "{" << x.first << " : " << x.second << "}"; return out; } template <typename T> ostream &operator<<(ostream &out, const set<T> x) { for (auto &it : x) { out << it << "...
3
#include <bits/stdc++.h> using namespace std; vector<int> vc; int g, s = 0, b = 0; bool check(int md, int n) { if (md >= vc.size() - 1) { g = 0; b = 0; s = 0; return false; } g = 0; s = 0; b = 0; g = vc[0]; int i = 1; while (i <= md && s <= g) { s += vc[i]; i++; } while (i <=...
3
#include <bits/stdc++.h> int main() { int n, m, i, j, cont = 0, exito = 0; int asteriscos[3][2]; scanf("%d %d", &n, &m); char mat[n][m]; char a[m]; for (i = 0; i < n; i++) { scanf("%s", a); for (j = 0; j < m; j++) { mat[i][j] = a[j]; if (mat[i][j] == '*') { asteriscos[cont][0] = ...
1
#include <bits/stdc++.h> using namespace std; struct Tpoint { double x, y; Tpoint() {} Tpoint(double _x, double _y) { x = _x; y = _y; } inline void read() { scanf("%lf%lf", &x, &y); } inline void show() { printf("%lf %lf\n", x, y); } inline double norm() { return sqrt(((x) * (x)) + ((y) * (y))); }...
5
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #include <set> #define mkp make_pair typedef long long ll; using namespace std; ll L,A,B,M; ll d[20]; ll MOD=1000000007; typedef vector<ll> vec;//ll? typedef vector<vec> m...
0
#include <bits/stdc++.h> using namespace std; int a[70][70]; int main() { long i, j, n, t, x[50000], y[50000]; int ri, rj, p; bool ch; cin >> n >> t; for (i = 0; i < t; i++) cin >> x[i] >> y[i]; if (n <= 3) { for (i = 0; i < t; i++) if ((x[i] == 0) && (y[i] == 0)) cout << n << "\n"; ...
2
#include <bits/stdc++.h> using namespace std; queue<int> q; int ans[2003]; int c = 1001; vector<int> mvs; int main() { int n, k; scanf("%d %d", &n, &k); for (int i = 1; i <= k; i++) { int x; scanf("%d", &x); if (!ans[x - n + c]) { ans[x - n + c] = 1; q.push(x - n + c); mvs.push_back(...
3
#include <bits/stdc++.h> using namespace std; int n, m; vector<pair<int, int>> G[262144]; int d1[26][262144]; pair<int, int> d2[2][262144]; int vis[2][262144]; long long mod = 998244353ll; long long qpow(long long x, long long y) { long long a = x, ans = 1; while (y) { if (y & 1) ans = (ans * a) % mod; y >>...
3
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; bool f[241514]; int main(){ ll n,x; cin>>n>>x; if(x==1||x==2*n-1)cout<<"No\n"; else{ cout<<"Yes\n"; f[x]=f[x-1]=f[x+1]=1; ll cnt=n-2; ll now=1; while(cnt){ if(!f[now]){ cout<<now<<endl; cnt--; } now...
0
#include <bits/stdc++.h> using namespace std; int dx[] = {-1, 1, 0, 0, 0, 0, 0, 0}; int dy[] = {0, 0, 1, -1, 0, 0, 0, 0}; const long long inf = 100000007; const double eps = 0.000000009; long long mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long s, k; cin >> s >> k; ve...
2
#include <bits/stdc++.h> using namespace std; void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n; i += 6) { if (n % i == 0 ||...
2
#include <bits/stdc++.h> using namespace std; bool vis[101]; set<int> g[101]; void dfs(int p) { vis[p] = 1; for (int i : g[p]) { if (!vis[i]) { dfs(i); } } } void run() { int n, m; cin >> n >> m; bool on0 = 1; set<int> l[m]; for (int w = 0; w < n; w++) { int k; cin >> k; if (k ...
3
#include <bits/stdc++.h> using namespace std; int f(int hp, int atk, int def) { int ur = atk - def; if (ur <= 0) { return 1000000000; } return hp / ur + (hp % ur != 0); } int main() { int hpy, hpm, atkm, atky, defm, defy; cin >> hpy >> atky >> defy; cin >> hpm >> atkm >> defm; int zhp, zatk, zdef; ...
1
#include<math.h> #include<algorithm> #include<vector> #include<stdlib.h> #include<string.h> #include<string> #include<stdio.h> #include<set> #include<map> #include<queue> #include<stack> #include <iostream> #include <limits.h> using namespace std; #define ull unsigned long long #define pp pair<ull,ull> const ull MAXN ...
0
#include<bits/stdc++.h> using namespace std; //type typedef long long ll; #define pii pair<int, int> #define vi vector<int> //x * y * 1.0 can cause overflow //constant #define inf (int)(1e9+7) #define mod (ll)(1e9+7) #define eps 1e-10 //omission #define eb emplace_back #define F first #define S second #define SZ(x) ((i...
0
#include<iostream> #include<queue> #include<algorithm> using namespace std; class people{ public: int t,w; people(void){} people(int a,int b){t = a; w = b;} const bool operator<(const people a)const{return t>a.t;} }; int main(){ int n; int m,a,b; for(;;){ cin >> n; if(!n)break; priority_qu...
0
#include <bits/stdc++.h> using namespace std; template <class T> typename T::value_type arr_sum(const T& v, int n) { typename T::value_type sum = 0; for (int i = (0); i < (n); ++i) sum += v[i]; return sum; } struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } } _sync_...
3
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; long long now = 0; for (long long i = 1; i <= n; ++i) { if (i == 1) printf("2\n"); else printf("%lld\n", i * (i + 1) * (i + 1) - (i - 1)); } return 0; }
1
#include <bits/stdc++.h> using namespace std; int a[52][52][52][102], n, m, C[102][102], p, ans; int main() { cin >> n >> m >> p; for (int i = 0; i < 102; i++) C[i][0] = 1; for (int i = 1; i < 102; i++) for (int j = 1; j <= i; j++) C[i][j] = min(C[i - 1][j - 1] + C[i - 1][j], 102); n /= 2; for (int ...
5
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <cstring> #include <map> using namespace std; vector<string> vs; bool used[1010][100]; int search(int x,int y){ // 0->‰E,1->‰º,2->¶,3->ã int sit=0; int cx=x; int cy=y; int over=1; int under=1; int high=0; int d...
0
#include<bits/stdc++.h> using namespace std; int main() { int n,k,i=1,g,h; cin>>n>>k; set<int>p; while(n--) { p.insert(i); i++; } while(k--) { cin>>g; while(g--) { cin>>h; if(p.count(h)==1) p.erase(h); } } cout<<p.size(); }
0