solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; inline long long read() { long long f = 1, ans = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { ans = ans * 10 + c - '0'; c = getchar(); } return f * ans; } const long l...
4
#include <bits/stdc++.h> using namespace std; int main() { long int n, k; string s; cin >> n >> k; cin >> s; long int temp, ans; temp = ans = 0; for (long int i = 1; i < n; i++) { if (s[i] == '#') temp++; if (s[i] == '.' && s[i - 1] == '#') { ans = max(ans, temp); temp = 0; } } ...
2
#include <bits/stdc++.h> using namespace std; namespace IO { const int MAXIOSIZE = 1 << 24 | 1; unsigned char buf[MAXIOSIZE], *p1, *p2; template <typename T> void read(T& x) { x = 0; char ch = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 24, stdin), p1 == p2) ? EOF : *p1++); bool...
5
#include <bits/stdc++.h> using namespace std; int g[220][220]; int d[220][220]; int v[220], p[220], f[220]; int n, m, x, y, z, w; void work(int u, int v) { vector<pair<int, int> > a, b; for (int i = 1; i <= n; i++) a.push_back(pair<int, int>(d[u][i], d[v][i])); sort(a.begin(), a.end()); for (int i = 0; i < a.si...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, p, q, r; cin >> n; int a[n + 5]; cout << "? 1 2" << endl; cout.flush(); cin >> p; cout << "? 2 3" << endl; cout.flush(); cin >> q; cout << "? 1 3" << endl; cout.flush(); cin >> r; a[2] = (r + q - p) / 2; a[0] = r - a[2]; a[1...
3
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef vector<int> VI; #define MP make_pair #define PB push_back #define X first #define Y second #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i) #define ITER(...
0
#include <bits/stdc++.h> using namespace std; struct Point { int x, y; }; struct line { Point p1, p2; }; vector<Point> vec1, vec2; vector<line> vec3; bool onLine(line l1, Point p) { if (p.x <= max(l1.p1.x, l1.p2.x) && p.x <= min(l1.p1.x, l1.p2.x) && (p.y <= max(l1.p1.y, l1.p2.y) && p.y <= min(l1.p1.y, l1.p2...
5
#include <bits/stdc++.h> using namespace std; int main() { long long w, h; long long rem = 998244353; scanf("%lld%lld", &w, &h); long long ans = 4LL; for (int i = 1; i < w; ++i) { ans *= 2; ans %= rem; } for (int i = 1; i < h; ++i) { ans *= 2; ans %= rem; } printf("%lld", ans); retur...
3
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; if (n == 0) cout << 0 << endl; else if ((n + 1) % 2 == 0) cout << (n + 1) / 2 << endl; else if ((n + 1) % 2 != 0) cout << n + 1 << endl; }
1
#include <bits/stdc++.h> using namespace std; int n; vector<int> g[605]; set<int> known, all; map<string, int> cache; string toString(const set<int> &f) { ostringstream ss; for (int x : f) ss << x << ","; return ss.str(); } void toCache(const set<int> &f1, int val) { cache[toString(f1)] = val; } void toCache(cons...
5
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const double eps = 1e-6; inline long long pow(long long a, long long b, long long p) { long long rtn = 1; while (b) { if (b & 1) rtn = rtn * a % p; a = a * a % p; b >>= 1; } return rtn; } long long in...
2
#include<iostream> using namespace std; int main(){ int M,l,b; int x,y; char d; while(cin>>b){ int a[21][21]={}; if(b==0)break; for(int i=0;i<b;i++){ cin>>x>>y; a[y][x]=1; } cin>>M; x=10; y=10; for(int i=0;i<M;i++){ cin>>d>>l; for(int j=0;j<l;j+...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5 + 10; set<int> X[N], Y[N]; bool check(int x, int y) { if (x < 0 || x >= N || y < 0 || y >= N) return 0; return X[x].count(y); } void erase(int x, int y) { X[x].erase(y); Y[y].erase(x); } ll ans = 0; void solvex(int x) { whil...
4
#include <bits/stdc++.h> using namespace std; const int NUM = 5010; struct edge { int next, to; } e[NUM]; int head[3010], tot; void gInit() { memset(head, -1, sizeof(head)); tot = 0; } void add_edge(int u, int v) { e[tot] = (edge){head[u], v}; head[u] = tot++; } int dist[NUM][NUM]; int in_mx[NUM][5]; int out_...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, m = 0, ans = 0; cin >> n; string s; cin >> s; int a[n]; int h[26]; fill(h, h + 26, 0); for (i = n - 1; i >= 0; i--) { m = 0; for (j = 0; j < s[i] - 'a'; j++) { m = max(m, h[j]); } a[i] = m + 1; h[s[i] - 'a'...
5
#include <bits/stdc++.h> using namespace std; int main() { char* arr1 = new char[100]; char* arr2 = new char[100]; cin >> arr1 >> arr2; int y = strlen(arr1); for (int i = 0; i < y; i++) { if (arr1[i] >= 65 && arr1[i] <= 90) arr1[i] += 32; if (arr2[i] >= 65 && arr2[i] <= 90) arr2[i] += 32; } int a ...
1
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y); long long gcd(long long a, long long b); int sum(int x) { int s = 0; while (x > 0) { s += (x % 10); x /= 10; } return s; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int q; cin >> q; whi...
4
#include <bits/stdc++.h> using namespace std; using lld = long long; bool ok(string a, string b) { sort(a.begin(), a.end()); sort(b.begin(), b.end()); return (a == b); } int inv(string a) { int res = 0; for (int i = 0; i < a.length(); i++) for (int j = i + 1; j < a.length(); j++) res += (a[i] < a[j] ? 1 :...
6
#include<iostream> #include<cstdio> using namespace std; int n,m,Sum[1024][1024],a[1024][1024],Cnt[1024]; int read() { char c=0; int sum=0; while (c<'0'||c>'9') c=getchar(); while ('0'<=c&&c<='9') { sum=sum*10+c-'0'; c=getchar(); } return sum; } int lowbit(int x) { return x&(-x); } i...
0
#include<cstdio> #include<algorithm> #define RI register int #define CI const int& using namespace std; const int N=100005; int n,a[N],m,v,p; long long sum[N]; inline bool cmp(CI x,CI y) { return x>y; } int main() { RI i; for (scanf("%d%d%d%d",&n,&m,&v,&p),i=1;i<=n;++i) scanf("%d",&a[i]); for (sort(a+1,a+n+1,cmp),i=...
0
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") const double esp = 1e-8; const int mod = 998244353; const double pi = acos(-1); const int inf = 0x3f3f3f3f; const int maxn = 1e3 + 5; const int maxm = 1e6 + 5; int a[maxn], n, k; int dp[maxn][maxn], tsum[maxn][maxn]; int bound[maxn]; inline int ad...
6
#include <bits/stdc++.h> int g[110][110]; int ans[1100]; int main() { int n; while (scanf("%d", &n) == 1) { printf("%d\n", n / 2 * (n - n / 2)); for (int i = 1; i <= n / 2; i++) for (int j = n / 2 + 1; j <= n; j++) printf("%d %d\n", i, j); } return 0; }
5
#include <bits/stdc++.h> using namespace std; int a[26]; int main() { int n; string str = "", s = ""; scanf("%d", &n); for (int i = 0; i < n; ++i) { cin >> s; str += s; str += "$"; } int len = str.size(); char ch, ch1; memset(a, 0, sizeof(a)); for (int i = 0; i < 26; ++i) { ch = 'a' + ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 15; const int mod = 1e9 + 7; string s, target; vector<int> op; void reverse(int k) { if (k == 0) { return; } assert(s.size() >= k); string prefix = s.substr(0, s.size() - k), suffix = s.substr(s.size() - k, k); reverse(suffix.begin(), suffi...
3
#include <bits/stdc++.h> using namespace std; int main() { string s; string t; cin >> s >> t; int l = s.length(); int i = 0; int flag = 0; while (i != l - 1) { for (int j = 0; j < t.length(); j++) { if (s[i] == t[j]) i++; if (j == t.length() - 1) flag = 1; } if (flag == 1) break; ...
1
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < int(n); ++i) #define rrep(i,n) for(int i = int(n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template<class T> void chmax(T& a, const T& b) {a = max(a, b);} template<class T> void chmin(T...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; const long long MOD = 1000000007; int n, m, a[MAXN], bitl[MAXN], bitr[MAXN]; void add(int x, int val, int *bit) { for (; x < MAXN; x += -x & x) { bit[x] += val; } } int qry(int x, int *bit) { int ret = 0; for (; x > 0; x -= -x & x) { ...
5
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18 + 7; const long long mod = 1e9 + 7; const double eps = 1e-9; const double PI = 2 * acos(0.0); const double E = 2.71828; int n, m; vector<int> c; map<int, bool> was[200005]; int x[100005], y[100005]; vector<int> a[200005]; int sz; vector<pair<int, ...
4
#include <bits/stdc++.h> using namespace std; map<string, float> s; string x, y, z, t; float p, v; int k() { if (s[x] < s[y]) p = s[y] - s[x]; else p = (6 - s[x] + s[y]); if (s[y] < s[z]) v = s[z] - s[y]; else v = (6 - s[y] + s[z]); if (p == 2 && v == 1.5) { cout << "major"; return 0; ...
1
#include <stdio.h> #include <cmath> #include <algorithm> #include <cfloat> #include <stack> #include <queue> #include <vector> #include <string> #include <iostream> #include <set> #include <map> #include <time.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define MOD 100000...
0
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = a; i >= b; i--) using namespace std; typedef unsigned long long ull; typedef pair <int, int> pii; typedef long long ll; template <typename _T> inline void read(_T &f) { f = 0; _T fu = 1; char c = getchar(); ...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 300 * 1000 + 5; pair<int, int> p0[2 * MAXN]; pair<pair<int, int>, int> p1[MAXN]; int sufmin[MAXN], prefmin[MAXN], s[MAXN]; int main() { ios_base::sync_with_stdio(false); int n, w; cin >> n >> w; int n0 = 0, n1 = 0; for (int i = 0; i < n; i++) { ...
5
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { int a1, a2, b1, b2, c1, c2; cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2; if (a1 == 0 && b1 == 0 && c1 != 0) { cout << 0 << endl; return 0; } if (a2 == 0 && b2 == 0 && c2 != 0) { cout << 0 << endl; return 0; } ...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; const long long inf = 2147383647; const double pi = 2 * acos(0.0); const double eps = 1e-9; mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>( chrono::high_resolution_clock::now().time_since_epoch()) .coun...
3
#include <bits/stdc++.h> using namespace std; struct node { int v; int l, r; node(int vv = 0, int ll = 0, int rr = 0) : v(vv), l(ll), r(rr) {} }; node a[100005]; int root, n; bool vis[100005]; struct Res { bool vis; int cnt; Res() { vis = false; cnt = 0; } }; map<int, Res> mp; void dfs(int l, int ...
4
#include <bits/stdc++.h> #define range(i, n) for (int i = 0; i < (n); ++i) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define ar array using namespace std; typedef long long ll; typedef double ld; typedef unsigned long long ull; const ll INF = 2e18; const int INFi = 2e9 + 5; cons...
3
#include <bits/stdc++.h> using namespace std; struct data { long long x, y, z; }; long long n, i, k, sum, res; long long l[2000100], h[2000100], lazy[2000100]; data m, a[500100], it[2000100]; bool cmp(data a, data b) { return a.z > b.z; } void build(int t, int x, int y) { l[t] = x; h[t] = y; if (x == y) return;...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e2 + 7; int x[MAXN], y[MAXN], z[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); x[1] = x[4] = x[7] = x[8] = x[11] = x[14] = 1; y[2] = y[6] = y[9] = y[13] = 1; z[3] = z[5] = z[10] = z[12] = 1; long long a, b, c; ...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, a; cin >> n; for (int i = 0; i < n; i++) { cin >> a; cout << (1 << __builtin_popcount(a)) << '\n'; } return 0; }
2
#include <bits/stdc++.h> using namespace std; int n, lazy[100011 << 2]; long long st[100011 << 2][48], A[100011]; void build(int v, int l, int r) { if (l == r) { st[v][0] = A[l] % 95542721; for (int k = 1; k < 48; ++k) { st[v][k] = (st[v][k - 1] * st[v][k - 1]) % 95542721; st[v][k] = (st[v][k] * s...
4
#include <bits/stdc++.h> using namespace std; const long long int oo = 1e18; const int N = 3000 + 10; int n; long long int dp[N]; pair<long long int, long long int> a[N]; int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second; sort(a + 1, a + n + 1...
5
#include <bits/stdc++.h> const long double pie = 3.1415926535; using namespace std; long long fpow(long long n, long long p) { long long m = 1; while (p) { if (p % 2) m *= n; p >>= 1; n *= n; } return m; } long long mfpow(long long n, long long p, long long M) { long long m = 1; n %= M; while ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 1.5e5 + 6.66; const int inf = 1e9 + 7; int seg[MAXN * 4], laz[MAXN * 4]; int a[MAXN], b[MAXN]; int n, m, h; void shift(int id, int val) { seg[id] += val; laz[id] += val; } void shift(int id) { shift(id << 1, laz[id]); shift(id << 1 | 1, laz[id]); ...
5
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; int M = N; int sum=0; while(M){ sum += M%10; M /= 10; } cout << (N%sum==0 ? "Yes" : "No") << endl; }
0
#include <bits/stdc++.h> using namespace std; long long fastpow(long long a, long long b, long long m = (long long)(1e9 + 7)) { long long res = 1; a %= m; while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res; } signed main() { ios_base ::sync_w...
4
#include<bits/stdc++.h> using namespace std; int main(){ long long A,B,K; cin >> A >> B >> K; cout << max(0LL,A-K); K=max(K-A,0LL); cout << " " << max(0LL,B-K) << endl; }
0
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); } template <class T> inline T lcm(T a, T b) { return ((a) / gcd((a), (b)) * (b)); } template <class T> inline T BigMod(T Base, T power, T M = 1000000007) { if (power == 0) retur...
5
#include <bits/stdc++.h> using namespace std; int num[1000010]; int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; for (int i = 2; i <= 1000000; i++) { if (num[i] == 0) { for (int j = i; j <= 1000000; j += i) { if (num[j] == 0) num[j] = i; } } } ...
1
#include <bits/stdc++.h> using namespace std; inline 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 << 3) + (x << 1) + (c ^ '0'), c = getchar(); return x * f; } const int N = 1e6 + 5; stru...
2
#include <bits/stdc++.h> using namespace std; struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; #define FOR(i, begin, end) for(int i=(begin);i<(end);i++) #define REP(i, n) FOR(i,0,n) #define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--) #de...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1010; const int MOD = 1000000007; char s[MAXN * 2], e[MAXN]; long long dp[2][2]; int main() { int k; cin >> s >> e >> k; int len = strlen(s); if (strlen(e) != len) { cout << 0 << endl; return 0; } int pnt = 0; for (int i = 0; i < len; ...
2
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main() { int n, i, j, k; cin >> n; int arr[n]; int ans[2*n]; for (i = 0; i < n; ++i) { cin >> arr[i]; } sort(arr, arr+n); int ii = 0; i = n-1; j = 0; while ((i > 0) && (arr[i-1] > 0)) { ...
0
#include <bits/stdc++.h> using namespace std; int a[200000]; void solve() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } bool dec = false; int len = 1; for (int i = n - 2; i >= 0; --i) { if (a[i] >= a[i + 1] && dec == false) { len++; } else if (a[i] > a[i + 1] && dec == ...
3
#include <bits/stdc++.h> using namespace std; int main() { int cases; scanf("%d", &cases); while (cases--) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) cout << i << " "; cout << endl; } }
1
#include <bits/stdc++.h> using namespace std; int main() { long long n; long long vec[1005]; cin >> n; for (int i = 0; i < n; i++) { cin >> vec[i]; } long long lul[1005]; for (int i = 0; i < n; i++) { if (i == 0) lul[i] = vec[i]; else lul[i] = vec[i] - vec[i - 1]; } long long r...
2
#include <bits/stdc++.h> using namespace std; static bool odd(int i) { return i % 2; } int main() { int count[26] = {}; string S; cin >> S; for (char ch : S) ++count[ch - 'a']; const int L = S.size(); const int len_odd = odd(L); int num_odd = 0; for (int i = int(0); i < int(26); ++i) num_odd += odd(coun...
3
#include <bits/stdc++.h> int main() { int n, m, s, f, t = 0, l, r, now, pass; char pr; scanf("%d %d %d %d", &n, &m, &s, &f); now = s; if (f - s > 0) { pr = 'R'; pass = 1; } else { pr = 'L'; pass = -1; } for (int i = 1; 1; i++) { if (i > t) { scanf(" %d %d %d", &t, &l, &r); ...
2
# include <bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]){ cout << "Bad\n"; }else{ cout << "Good\n"; } }
0
#include <bits/stdc++.h> using namespace std; const int N = (int)1e6 + 123; const long long INF = (long long)1e18 + 123; const int inf = (int)1e9 + 123; const double eps = 1e-6; inline void boost() { ios_base::sync_with_stdio(0); cin.tie(NULL); } long long n, a[200111], mini = INF, ans; pair<long long, long long> p...
2
#include <bits/stdc++.h> using namespace std; bool is_suffix(string a, string b) { if (a.length() > b.length()) return false; bool ok = true; int it = 0; for (int i = b.length() - a.length(); i < b.length(); i++) { if (b[i] != a[it]) ok = false; it++; } return ok; } vector<string> f(vector<string> V...
3
#include <iostream> #include <string> #include <string.h> using namespace std; char s[220]; int main(){ cin>>s; int n=strlen(s); for(int i=n-2;i;i-=2){ if(strncmp(s,s+i/2,i/2)==0){ cout<<i<<endl; return 0; } } }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; long long a[n]; long long res = 0; priority_queue<pair<long long, pair<int, int>>> pq; for (int i = 0; i < n; i++) { cin >> a[i]; res += a[i] * a[i]; ...
5
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 5; int n, k; struct node { int id, a, b; node(int i = 0, int _a = 0, int _b = 0) { id = i, a = _a, b = _b; } bool operator<(const node& a) const { return b < a.b; } } p[N]; long long dp[N][N]; int pre[N][N]; int main() { int TTT; cin >> TTT; ...
6
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cer...
4
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) { res = (res * x) % p; } y = y >> 1; x = (x * x) % p; } return res; } long long mcd(long long a, long long b) { if (b > a) swa...
4
#include <bits/stdc++.h> #define rep(i, a, n) for(int i = a; i < n; i++) #define REP(i, n) rep(i, 0, n) #define repb(i, a, b) for(int i = a; i >= b; i--) #define all(a) a.begin(), a.end() #define int long long #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) using namespace std; typedef pair<int, int...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int test = 1; while (test--) { long long N; cin >> N; long long A[N + 1]; for (int i = 1; i < N + 1; i++) cin >> A[i]; cout << "1 1\n" << A[1] * (N - 1) << "\n"; (N == 1) ? cout <<...
3
#include <bits/stdc++.h> const double pi = acos(-1.0); const double eps = 1e-9; using namespace std; const int N = 333; const long long MOD = 1e9 + 7; long long dp[N][N]; vector<pair<long long, long long>> v; int n; long long triangle_area_2(long long x1, long long y1, long long x2, long long ...
3
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; struct MCF { int n; vector<int> prio, curflow, prevedge, prevnode, pot; priority_queue<long long, vector<long long>, greater<long long>> q; struct edge { int to, rev; int f, cap, cost; }; vector<vector<edge>> g; MCF(int n) : ...
5
#include <bits/stdc++.h> int main() { int n, a[10], b[10], i = 0, t; scanf("%d", &n); for (i = 0; i < n; i++) { a[i] = 1; } t = n; while (n - 1) { b[0] = 1; for (i = 1; i < t; i++) { b[i] = a[i] + b[i - 1]; } for (i = 0; i < t; i++) { a[i] = b[i]; } n--; } printf(...
1
#include <bits/stdc++.h> using namespace std; const int Max = 3e5 + 10; const int E = Max * 2; int son[Max], maxson[Max], fa[Max], zx[Max]; int head[Max], nex[E], pnt[E], edge; void Init() { edge = 0; memset(son, 0, sizeof(son)); memset(maxson, 0, sizeof(maxson)); memset(fa, -1, sizeof(fa)); memset(head, -1, ...
4
#include<iostream> #include<cstdio> #include<string> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> using namespace std; typedef long long ll; const ll MOD = 1000000007; const ll INF = (ll)1000000...
0
#include<cstdio> #include<cstring> const int N = 51; const int M = 2501; typedef long long LL; LL dp[N][M]; int n, m, x, sum, a[N]; int main(){ scanf("%d %d", &n, &m); memset(dp, 0, sizeof(dp)); dp[0][0] = 1; sum = 0; for(int i=0; i<n; i++){ scanf("%d", &x); sum += x; for(int j=i; j>=0; j--){ ...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using ii = pair<int, int>; template <typename A, typename B> ostream& operator<<(ostream& os, pair<A, B> p) { return os << '{' << p.first << ", " << p.second << '}'; } const int oo = 0x3f3f3f3f; const ll OO = ll(oo) * oo; cons...
1
#include <bits/stdc++.h> using namespace std; const int Maxn = 205; typedef bitset<2 * Maxn> B; vector<int> e[2 * Maxn]; B ban[2 * Maxn]; int n, m, l, dfn[2 * Maxn], low[2 * Maxn], bl[2 * Maxn], scc; char s[26], t[Maxn], ans[Maxn]; void tarjan(int x) { static int Stack[2 * Maxn], Instack[2 * Maxn], top, cnt; Stack[...
3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, k; vector<int> g[N]; int good[N]; int sz[N]; vector<int> vs; void go(int u, int p) { if (good[u]) vs.push_back(u); for (int v : g[u]) if (v != p) go(v, u); } void solve(int u) { printf("1\n%d\n", u); go(u, 0); for (int i = 0; i <...
6
#include <bits/stdc++.h> using namespace std; const int maxn = (int)(1e6) + 5; const int mo = (int)(1e9) + 7; struct node{ int x, y, z, w; node(int _x = 0, int _y = 0, int _z = 0, int _w = 0):x(_x), y(_y), z(_z), w(_w) {} } p[maxn]; bool operator < (node a, node b) { return 0LL + a.x + a.y + a.z < 0LL + b.x + b.y...
0
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0'; return x * f; } const ...
5
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; char ch = getchar(); while (ch < '0' || ch > '9') { ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x; } long long dp[3][710][710]; long long ans; int n, m; int main(...
5
#include<iostream> #include<string> #include<map> #include<algorithm> #include<vector> using namespace std; struct data{ string str; int y,l; data(string a,int b,int c): str(a),l(b),y(c){} data(){} }; int main(){ int n,m; while(cin>>n>>m,n||m){ vector<data>V(n); for(int ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 5; void inv(int n, int a[], int b[], int p[]) { static int h[maxn]; for (int i = 1; i <= n; ++i) { h[a[i]] = i; } for (int i = 1; i <= n; ++i) { p[i] = h[b[i]]; } } void solve(int n) { static int a[maxn], b[maxn], p[maxn]; for...
6
#include <bits/stdc++.h> #define MOD 1000000007 #define INF 0x3f3f3f3f #define EPS 1e-10 #define setNil(x) memset((x),0,sizeof(x)) #define setINF(x) memset((x),63,sizeof(x)) #define setNegINF(x) memset((x),192,sizeof(x)) //NegINF=-INF-1 #define setNeg1(x) memset((x),255,sizeof(x)) using namespace std; int n,cnt,ans=-2,...
0
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); } int main() { fast(); long long n, l, r; cin >> n >> l >> r; long long mn = n - l + 1, mx = 0; int i = n - l + 1, p = 2; for (; i < n; i++, p *= 2) { mn += p; } i = 0, p = 1;...
2
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long linf = 0x3f3f3f3fLL; const int EPS = 1e-6; const long long mod = 1000000007; int a[30010]; int b[30010]; int n; bool func(int x, int y, int ind) { int r = y - x; memset(b, 0, sizeof b); int num = a[ind - 1]; b[ind - 1] = 1...
4
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #define fo(i,a,b) for(i=a;i<=b;i++) #define min(x,y) ((x)<(y)?(x):(y)) #define max(x,y) ((x)>(y)?(x):(y)) #define ll long long using namespace std; const int maxn=1e5+5; int fi[maxn],dui[maxn*2],ne[maxn*2],qc[maxn],dui1[maxn*2]...
0
#include <bits/stdc++.h> using namespace std; #define MAX 514 #define INF (1e9) struct Edge{ int to,cost,c; Edge(int to,int cost,int c) : to(to),cost(cost),c(c) {} }; int main(){ int M,D,N,K; int d[MAX][1<<6]; while(cin >> M >> N >> K >> D, M){ vector<Edge> G[MAX]; ve...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vs = vector<string>; using pll = pair<ll, ll>; using vp = vector<pll>; const ll MOD = 10000000...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1 << 12; char s[15]; long long ans[maxn][105]; int cnt[maxn], w[15]; int main() { int n, m, q; scanf("%d %d %d", &n, &m, &q); for (int i = 0; i < n; ++i) scanf("%d", &w[n - i - 1]); for (int i = 0; i < m; ++i) { scanf("%s", s); int x = 0; ...
4
#include <iostream> #include <algorithm> #include <cstdio> using namespace std; int p, n[6], c[6] = {1, 5, 10, 50, 100, 500}; int data[500001]; int calc(int t, bool o){ int res = 0; for(int i=5;i>=0;i--){ int tmp = t / c[i]; if(o) tmp = min(tmp, n[i]); t -= tmp * c[i]; res += tmp; } return re...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1001; int a[MAXN]; map<int, int> fp, tp; int Count(int a, int b) { int ans = 0; if (fp[a + b]) { fp[a + b]--; ans = Count(b, a + b) + 1; fp[a + b]++; } return ans; } int main() { int n; cin >> n; fp.clear(); for (int i = 0; i < n...
4
#include <bits/stdc++.h> using namespace std; const int dbg = 0; struct FatalMessage { FatalMessage(const char* file, int line, const char* cond) { std::cerr << file << " L" << line << " failed: " << cond << ". "; } ~FatalMessage() { std::cerr << std::endl; std::terminate(); } }; template <typename ...
4
#include <bits/stdc++.h> using namespace std; int matrix[10][10]; int main() { int i, a, b, n, m, ans; cin >> n >> m; for (i = 0; i < m; i++) { cin >> a >> b; matrix[a][b] = 1; matrix[b][a] = 1; } if (n < 7) { cout << m << endl; return 0; } int d = 1000; for (i = 1; i <= n; i++) { ...
1
/* https://www.luogu.org/problem/AT2168 Author: Yu-343 */ #include <cstdio> int h, w, cnt = 0; char ch; int main (void) { scanf ("%d %d", &h, &w); for (int i = 1; i <= h; ++i) { getchar (); for (int j = 1; j <= w; ++j) { scanf ("%c", &ch); if (ch == '#') ++cnt; } } puts ((cnt == h + w - 1) ? "Possibl...
0
#include<bits/stdc++.h> using namespace std; const int N=3e5+5; int n,t,k,x,fix[N],l[N],r[N],a[N],f[N]; vector<int>er[N]; set<int>s; multiset<int>sc; int main(){ cin>>t; while(t--){ cin>>n; s.clear(); sc.clear(); for(k=1;k<=n;k++){ er[k].clear(); cin>>a[k]; f[a[k]]=0;fix[a[k]]=0; x=k-1; while(a[x]...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; while(cin >> n, n){ string signal[1002]; signal[0] = to_string(1e9); for(int i = 1; i <= n; i++) cin >> signal[i]; if(n % 2) signal[n + 1] = to_string(1e9); else signal[n + 1] = to_string(-(1e9)); int less = -(1e9)-3, mo...
0
#include <bits/stdc++.h> using namespace std; int in[100005]; int dp[100005]; int main() { int n; scanf("%d", &n); fill(dp, dp + 100005, 1000000000); dp[0] = 0; int ret = 0; for (int i = 0; i < n; i++) { int a; scanf("%d", &a); int s = 0, e = 100005; while (e - s > 1) { int med = (s + ...
2
#include <bits/stdc++.h> using namespace std; const long double PI = 3.141592653589793238462643383; long long int gcd(long long int a, long long int b) { if (a == 0) return b; return gcd(b % a, a); } long long int Ceil(long long int a, long long int b) { if (a % b == 0) return a / b; else return a / b +...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 123456; int n, l, x, y, ai[maxn]; void init() { for (int i = 1; i <= n; i++) scanf("%d", &ai[i]); } int brs(int l, int r, int now, int t) { while (l <= r) { int mid = (l + r) / 2; if (now - ai[mid] == t) { return 1; } if (now - ai[...
2
#include <bits/stdc++.h> using namespace std; int i, j, k, n, m, nn; int xiao[20], a[20], b[20], f[20], ge[(1 << 16)]; long long K, h[(1 << 16)]; inline long long suan() { int i, j; memset(h, 0, sizeof(h)); h[0] = 1; for (i = 0; i <= nn - 1; i++) if (h[i]) { int A = ge[i] + 1; for (j = 1; j <= n...
3
#include <iostream> #include <cstdio> using namespace std; int main(){ int ax, ay; char f[12][12]; bool flag = false; for(int y=0 ; y<12 ; y++){ for(int x=0 ; x<12 ; x++){ f[y][x] = 0; } } while( 1 ){ for(int i=0 ; i<8 ; i++) { if( scanf("%s", f[i]) == EOF ){ flag = true; break; } } ...
0