solution
stringlengths
52
181k
difficulty
int64
0
6
// ※※※ 解答不能 ※※※ // 以下のソースを勉強する. // yutaka1999氏. // https://atcoder.jp/contests/jsc2019-qual/submissions/7112552 #include <bits/stdc++.h> using namespace std; #define SIZE 200005 using LL = long long; typedef pair<int, int> P; typedef pair<int, P> PP; struct UF{ int par[SIZE], rank[SIZE], sz[SIZE]; void in...
0
#include <bits/stdc++.h> using namespace std; long long n, ans, b[2222], e[2222]; char s[2222]; int main() { scanf("%s", s); n = strlen(s); for (int i = 0; i < n; i++) { for (int j = 0; i - j >= 0 && i + j < n; j++) { if (s[i - j] != s[i + j]) break; b[i - j]++; e[i + j]++; } for (in...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int n, m; int gi() { char a = getchar(); int b = 0; while (a < '0' || a > '9') a = getchar(); while (a >= '0' && a <= '9') b = b * 10 + a - '0', a = getchar(); return b; } int cal(int x, int y, int z, int a, int b, int c) { return abs(x ...
4
#include <bits/stdc++.h> using namespace std; long long n, k; inline bool Solve(const long long d1, const long long d2) { long long p = k + 2 * d1 + d2; if (p % 3) return 0; long long x1 = p / 3; if (x1 < 0 || x1 > n / 3) return 0; long long x2 = x1 - d1; if (x2 < 0 || x2 > n / 3) return 0; long long x3 =...
3
#include<bits/stdc++.h> #define X first #define Y second #define pb emplace_back #define FOR(i,a,b) for(int (i)=(a);i<(b);++(i)) #define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i)) #define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X)) #define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X)) #define rrep(X,Y) for (int (X) = (Y)...
0
#include <bits/stdc++.h> using namespace std; int n, m, ans[100010], tot = 1; set<int> E[100010]; map<set<int>, vector<int> > M; inline int read() { register int w = 0, X = 0; register char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while (isdigit(ch)) { X = (X << 1) + (X << ...
4
#include <bits/stdc++.h> using namespace std; int a[100] = {4, 22, 27, 58, 85, 94, 121, 166, 202, 265, 274, 319, 346, 355, 378, 382, 391, 438, 454, 483, 517, 526, 535, 562, 576, 588, 627, 634, 636, 645, 648, 654, 663, 666, 690, 706, 728, 729, 762, 778, 825, 852, ...
1
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; void eras(map<int, int> &m, int x) { m[x]--; if (!m[x]) m.erase(x); } const int N = (int)3e5 + 100; const int M = (int)2e6 + 100; const int inf = (int)1e9 + 100; int main() { mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()...
1
#include <iostream> #include <algorithm> using namespace std; typedef long long ll; int main(void) { int n; ll a, b; cin >> n >> a >> b; ll l, r; cin >> l; ll ans = 0; for (int i = 1; i < n; i++) { cin >> r; ans += min((r - l) * a, b); l = r; } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; deque<string> strings; bool logger = false; void print() { if (!logger) return; cout << "logger:\n"; for (string s : strings) cout << s << ' '; cout << '\n'; } bool myStrComp(string s1, string s2) { if (s1[0] == s2[0]) return s1.length() < s2.length(); else ...
2
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:536870912") #pragma warning(disable : 4996) #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const int N = 2e5 + 100; int a[N], p[N]; int main() { int n, d, b; scanf("%d%d%d", &n,...
4
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { string data; int n; cin>>data>>n; while (n--){ string order,p; int a,b; cin>>order>>a>>b; if (order=="replace"){ cin>>p; data.replace(a,b-a+1,p); } else if(order=="reverse") reverse(begin...
0
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int n,r; while(cin>>n>>r && n>0 && r>0){ vector<int> v; for(int i=n;i>0;i--)v.push_back(i); while(r--){ int p,c; cin>>p>>c; vector<int>::iterator it = v.begin(); rotate(it,it+p-1,it+p+c-1...
0
#include <bits/stdc++.h> using namespace std; const int base = 1e9; const int maxn = 1e3; const int logn = 20; const int inf = 2e9; const int alpha = 26; const int my_hash = 29; const long long l_inf = 4e18; const long long mod = 1e9 + 7; const double pi = acos(-1.0); const double eps = 1e-9; int n; long long x, sum = ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long n; string a, b; cin >> a; cin >> b; long long n1 = b.length(); n = a.length(); vector<long long> v(n); long long tp; for (long long i = 1; i <= n; i++) { scanf("%lld", &tp); v[tp - 1] = i; } long long l = 1, r = n; long...
1
#include <bits/stdc++.h> using namespace std; string s; int main() { cin >> s; if (islower(s[0])) { for (int i = 1; i < s.size(); i++) { if (islower(s[i])) { cout << s; return 0; } } s[0] = toupper(s[0]); cout << s[0]; for (int i = 1; i < s.size(); i++) { if (is...
1
#include <bits/stdc++.h> using namespace std; int n, m; set<int> num; map<int, int> lfc, rtc; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &m); if (i == 1) num.insert(m); else { set<int>::iterator itr = num.lower_bound(m); if (itr == num.end()) rtc[*...
4
#include <bits/stdc++.h> using namespace std; int t, n; string a, b; int main() { cin >> t; while (t--) { cin >> n >> a >> b; vector<int> ans = vector<int>(); vector<int> pos = vector<int>(); for (int i = 0; i < (n + 1) / 2; i++) { pos.push_back(i); pos.push_back(n - i - 1); if (po...
1
#include <bits/stdc++.h> using namespace std; int i, q, x; string s, op, t; map<string, int> M; int get(string s) { int gmb = 0, fnc = 0, i = 0, j = s.size() - 1; string t; while (i < s.size() && s[i] == '&') ++i, ++gmb; while (j >= 0 && s[j] == '*') --j, ++fnc; t = s.substr(i, j - i + 1); if (!M.count(t) |...
2
#include <bits/stdc++.h> using namespace std; int main() { char x[] = {'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/'}; char y; int z; cin >> y; if (y == 'L') z = 1; else ...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 105; int n, len; int b[MAXN], v[MAXN][MAXN], t[MAXN][MAXN]; int ans = 0; void work(int p, int q) { int s1 = 0, s2 = 0; int x1 = 1, x2 = 1, r1 = t[p][1], r2 = t[q][1]; while (s1 < len && s2 < len) { bool f = (s1 < s2); int r = min(r1, r2); ...
5
#include <bits/stdc++.h> using namespace std; const int N = 200005; int c[N], stat[N]; vector<pair<int, int>> ds[10]; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); if (n <= 2) printf("-1\n"); else { n -= 2; printf("2 3"); while (n--) { printf(" 1"); } printf("\n"); } }
1
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; long long f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + (ch ^ 48); ch = getchar(); } return x *= f, void(); } cons...
4
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x; } const int maxn = 2e5 + 10; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; const double ...
3
/* { ###################### # Author # # Gary # # 2021 # ###################### */ #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) ...
6
#include <bits/stdc++.h> using namespace std; int f[110][60][2], n, g[110][60][2]; char s[110]; int main() { memset(f, 0x80, sizeof f); memset(g, 0x3f, sizeof g); scanf("%s%d", s + 1, &n); f[0][0][0] = 0; for (int i = 1; s[i]; i++) for (int j = 0; j <= n; j++) if (s[i] == 'T') { for (int k =...
3
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { re...
2
#include <bits/stdc++.h> using namespace std; const long long int no = 3e6 + 5, modulo = 1e9 + 7, inf = 1e18, N = 3e3 + 1; long long int ar[no], br[no], cr[no]; void solve() { long long int n = 0, m = 0, a = 0, b = 0, c = 0, d = 0, x = 0, y = 0, z = 0, w = 0, k = 0; cin >> n; long long int q; ci...
2
#include <bits/stdc++.h> using namespace std; bool fun(const pair<int, int> &p1, const pair<int, int> &p2) { return (p1.second < p2.second); } int main() { int n, i, j, ans; cin >> n; pair<int, int> p[n + 1]; for (i = 1; i <= n; ++i) { cin >> p[i].first; p[i].second = i; } sort(p + 1, p + n + 1, g...
2
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; void solve() { int n; cin >> n; vector<int> nums(n, 0); for (int i = 0; i < n; i++) cin >> nums[i]; vector<int> ans(n, -1); vector<int> prime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}; int curr_color = 1; for (auto p : prime) { bool f...
2
#include <bits/stdc++.h> using namespace std; int64_t mod = 1e9 + 7, inf = 4e18; map<vector<int64_t>, long double> seen; long double rec(vector<int64_t> &people, int64_t n, int64_t len) { if (len < 0) return -1; if (n == 0) return 0; if (seen[people]) return seen[people]; long double ans = 0; for (int64_t i =...
4
#include <bits/stdc++.h> using namespace std; const int N = 200005; const int INF = 4127; const int mod = 475; int a[1005], b[1005]; set<int> rofl; int main() { int n, m, ans = 0, sum = 0; cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> a[i] >> b[i]; } for (int i = 1; i <= 2000; i++) { int x = i;...
2
#include <bits/stdc++.h> int main() { int cus, abs, wdw; scanf("%d%d", &abs, &wdw); for (cus = 0; cus < wdw; cus++) { if (abs % 10 == 0) { abs /= 10; } else { abs -= 1; } } printf("%d\n", abs); return 0; }
1
#include <bits/stdc++.h> using namespace std; const int N = 100100; int n, q; char s[N]; struct str { void bld() { for (char c = 'a'; c <= 'z'; c++) segtree[c - 'a'].bld(c); } void setRange(char ch, int u, int v, int l, int r) { if (r < l) return; segtree[ch - 'a'].setRange(0, l, r); if (v >= u) s...
5
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e5 + 100; double alpha[maxn], beta[maxn]; double a[maxn], b[maxn]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lf", &beta[i]); for (int i = 0; i < n; i++) scanf("%lf", &alpha[i]); double Sa = 0, Sb = 0; for (in...
4
#include <bits/stdc++.h> using namespace std; double const pi = 3.1415926536; void FAST() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void TXT() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } int main() { FAST(); string s; cin >> s; int n; cin >> n; for (int i ...
4
#include <bits/stdc++.h> using namespace std; const long long inf = 2e9, inff = 1e18; struct edge { int to, nxxt; long long len; } e[501200 << 1]; queue<int> q; int head[501200], cnt = 2, n, S, T, dep[501200], cur[501200]; inline void ins(int u, int v, long long w) { e[cnt] = (edge){v, head[u], w}; head[u] = cn...
5
#include <bits/stdc++.h> const long long mod9 = 1e9 + 7; const long long maxsize = 2e9 + 1; const long long mod2 = 1073741824; const long long INF = 1e18L + 5; using namespace std; void solve() { long long a, b; cin >> a >> b; if (!a or !b) { cout << 0 << "\n"; return; } long long minc = min(a, b); ...
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct Data { ll one, size, ans; }; struct st { ll one, size, ans; bool b; st *L, *R; void change() { ans = one*(size-one)-ans; one = size-one; b ^= 1; } void pull() { one = L->one+R->one; ans = L->ans+R->ans+(R->size-R->one)*L->one...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, sum = 0; scanf("%I64d", &n); cout << (n / 2) + 1 << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979323846; const double eps = (1e-6); vector<int> adj[3]; int visit[3]; bool cycle(int cur) { visit[cur] = 1; for (auto to : adj[cur]) { if (visit[to] == 1) return 1; if (cycle(to)) return 1; } visit[cur] = 2; return 0; } int...
2
#include <bits/stdc++.h> using namespace std; char inp[5010][5010]; int to[5010][5010]; priority_queue<int> Q; int main() { int n, m, i, j, c, res = 0; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) { scanf("%s", inp[i]); to[i][m] = m; for (j = m - 1; j >= 0; j--) { to[i][j] = (inp[i][j] == '1')...
2
#include <bits/stdc++.h> using namespace std; struct node { int p[2]; int cnt; node() { cnt = 0; p[0] = -1; p[1] = -1; } }; vector<node> v; string tobin(int n) { string ans = ""; while (n != 0) { if (n % 2 == 0) ans += '0'; else ans += '1'; n /= 2; } for (int i = ans....
4
#include<bits/stdc++.h> using namespace std; long long a,b,c[200005],n,d,ans,x[200005],y[200005],l,k; struct node { long long x,y; } w[200005]; inline bool cmp(node x,node y) { return x.x<y.x; } int main() { scanf("%lld%lld%lld",&n,&d,&a); d*=2; for(int i=1; i<=n; ++i) { scanf("%lld%lld"...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; long long A[5001], B[5001], dp[5001]; int n, m; long long iabs(long long a) { if (a < 0) return (-a); return a; } int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> A[i]; B[i] = A[i]; } sort(B, B + n); ...
3
#include <bits/stdc++.h> using namespace std; int64_t mx = 1e9 + 9; int64_t po(int64_t a, int64_t b) { int64_t ans = 1; while (b) { if (b & 1) { ans = (ans * (a % mx)) % mx; } a = a * a % mx; b = b >> 1; } return ans; } int main() { int64_t n, a, b, k, curr = 0; cin >> n >> a >> b >> k...
1
#include <bits/stdc++.h> using namespace std; const int c = 300500; struct rec { int i, a, b; }; bool operator<(const rec &a, const rec &b) { if (a.b != b.b) return a.b < b.b; if (a.a % a.b != b.a % b.b) return a.a % a.b < b.a % b.b; return a.a > b.a; } int n, p; int a[c]; rec m[c]; long long ans[c]; int main()...
4
#include <bits/stdc++.h> using namespace std; long long n, i, a[5002], in[5002][2] = {0}, r, f, s, j, sum = 0, ans = 0, dp[5002] = {0}, l; bool cmp(pair<long long, long long> a, pair<long long, long long> b) { return a.first < b.first; } int main() { ios::sync_with_stdio(false); cin.tie(0...
3
#include <bits/stdc++.h> using namespace std; const int N = 200200; const int mod = 1e9 + 7; const int MAXN = 1 << 20; string s, t; int n, gap; int sa[MAXN], pos[MAXN], tmp[MAXN], lcp[MAXN]; int cnt[MAXN]; int L[MAXN], R[MAXN]; int st[MAXN]; int sz; bool sufCmp(int i, int j) { if (pos[i] != pos[j]) return pos[i] < po...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 2000200; const long long MOD = 1e9 + 7; long long mult(long long a, long long b) { return (a * b) % MOD; } long long factor[MAXN]; int n, m; int it; int num[MAXN]; set<int> sets[MAXN]; int a[MAXN]; int cnt[MAXN]; vector<int> v[MAXN]; int main() { factor[0...
3
#include <bits/stdc++.h> using namespace std; const int N = 5005, mod1 = 1e9 + 9, base1 = 31, mod2 = 1e9 + 7, base2 = 59; bool pre[N][N]; int hash1[N][N], hash2[N][N]; void buildPreHash(const string &x) { int n = ((int)((x).size())); for (int i = 0; i < n; i++) { long long h1 = 1, h2 = 1; for (int j = i; j ...
6
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { long long n, k, b, ans = 0; cin >> n >> k; long long a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (int i = 1; i < n; i++) { if (a[i] < k) { b = k - a[...
1
#include <bits/stdc++.h> #define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++) #define rep(i, n) FOR(i, 0, n) #define ALL(x) (x).begin(), (x).end() using namespace std; typedef long long ll; constexpr ll mod = 1e9 + 7; template <class T> inline bool chmax(T &a, const T b) { if(a >= b) return false; a = b; ...
0
#include <bits/stdc++.h> using namespace std; const int maxN = 999999; int n, m; int ss[maxN], ff[maxN], dd[maxN], x[maxN], last[maxN], pred[maxN], good[maxN], deg[maxN], used[maxN]; int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= m; i++) { scanf("%d %d %d", &ss[i], &ff[i], &dd[i]); ss[i + m] ...
5
#include <iostream> #include <vector> #include <string> using namespace std; int main() { int h, w; cin >> h >> w; vector<string> s(h); for (int i = 0; i < h; i++) { cin >> s[i]; } int a[26] = {}; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { a[s[i][j] - 'a']++; } } int sum4 = 0, sum...
0
#include <bits/stdc++.h> using namespace std; #define rep(i,s,t) for(int i=s;i<t;i++) int num[2][200][200][200]; char mat[200][200]; int main() { int n,m;scanf("%d%d",&n,&m); rep(i,1,n+1)scanf("%s",mat[i]+1); for(int i=m;i;i--) rep(j,1,n+1) { int flag=1,bef=mat[j][i]; for(int k=j;k;k...
0
#include <bits/stdc++.h> using namespace std; template <typename T> inline T Abs(const T& value) { return value < 0 ? -value : value; } template <typename T> inline T Sqr(const T& value) { return value * value; } int main() { int n; cin >> n; vector<long long> ans(n, 0); vector<int> a(n); vector<long long...
2
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") using namespace std; ifstream fin("AAtest.in.txt"); int n, a, b, c, vas; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0); cin >> n >> a >> b >> c; int aa = 0, vas = 0; while (aa <= n) { int bb = 0; whil...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; string x; cin >> n >> x; int c1 = 0, c2 = 0; for (int i = n - 1; i >= 0; i--) { int z = x[i] - '0'; if (z == 7 || z == 4) { if (i >= n / 2) c1 += z; else c2 += z; } else { cout << "NO" << endl; ...
1
#include <bits/stdc++.h> using namespace std; vector<pair<long long int, long long int> > g[1001]; long long int n, m, k; char a[1001][11][11]; long long int d[1001]; long long int vis[1001]; vector<pair<long long int, long long int> > op; long long int xxx() { long long int i, u, v, dist, e, par, ans = 0; for (i =...
3
#include <bits/stdc++.h> int main() { int n, m; std::cin >> n >> m; int* r = new int[n]; int* c = new int[m]; int xor_row = 0, xor_col = 0; for (int i = 0; i != n; ++i) { std::cin >> r[i]; xor_row ^= r[i]; } for (int j = 0; j != m; ++j) { std::cin >> c[j]; xor_col ^= c[j]; } if (xor_...
4
#include<iostream> using namespace std; #include<vector> int main(){ int n,m,c; cin>>n>>m>>c; vector<int> b(m); for(int i=0;i<m;i++) cin>>b[i]; int cnt=0; for(int i=0;i<n;i++){ int res=c; for(int j=0;j<m;j++){ int a; cin>>a; res+=a*b[j]; } if(res>0) cnt++; } cout<<cnt...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; cout << (m * (m - 1)) / 2 << '\n'; for (int i = 1; i < m; ++i) { for (int j = i + 1; j <= m; ++j) { if (k) cout << j << ' ' << i; else cout << i << ' ' << j; cout << '\n'; } } ...
2
#include<bits/stdc++.h> using namespace std; int A[11]; int a[51],b[51],c[51],d[51]; int n,m,q,cnt=0,maxc=0; void dfs(int t,int k) { // cout<<t<<" "<<k<<endl; if(t==1) { for(int i=k;i>=1;i--) { cnt=0; A[1]=i; for(int j=0;j<q;j++) { if(A[b[j]]-A[a[j]]==c[j]) cnt+=d[j]; } maxc=max(maxc,cn...
0
#include <bits/stdc++.h> using namespace std; const int razm = 1001; int n, d, z = 0, tek = 0; string a[razm][3]; int b[razm]; bool v[razm]; int main() { cin >> n >> d; for (int i = 1; i <= n; i++) cin >> a[i][1] >> a[i][2] >> b[i]; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (a[i][1] =...
1
#include <bits/stdc++.h> bool chk[1001]; int main() { int n, m, a, b; scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { scanf("%d %d", &a, &b); chk[a] = true; chk[b] = true; } int index = 1; printf("%d\n", n - 1); for (int i = 1; i <= n; i++) { if (chk[i] == false) { index = i; ...
2
#include <bits/stdc++.h> using namespace std; const int S = 100003; const int MOD = 1e9 + 7; const double pi = 2 * acos(0.0); int _In() { int x; scanf("%d", &x); return x; } long long _LLI() { long long x; scanf("%lld", &x); return x; } int dirX[] = {1, 0, -1, 0, 1, -1, 1, -1}; int dirY[] = {0, 1, 0, -1, 1,...
4
#include <bits/stdc++.h> using namespace std; const long long int N = 31; const long long int MOD = 998244353; long long int mod(long long int n) { return (n % MOD + MOD) % MOD; } void solve() { long long int x; cin >> x; if (x % 4 == 0) cout << x / 4 << endl; else if (x % 4 == 1) (x - 9) / 4 < 0 ? cout...
3
#include <bits/stdc++.h> using namespace std; int main () { int n; cin >> n; for (int i = 1; i <= 9; ++i) { if (n % i == 0 && n / i <= 9) { cout << "Yes"; return 0; } } cout << "No"; }
0
/* Author: Nguyen Tan Bao Status: Idea: */ #include <bits/stdc++.h> #define FI first #define SE second #define ALL(a) a.begin(), a.end() #define SZ(a) int((a).size()) #define MS(s, n) memset(s, n, sizeof(s)) #define FOR(i,a,b) for (int i = (a); i <= (b); i++) #define FORE(i,a,b) for (int i = (a); i >= (b);...
6
#include<cstdio> #include<algorithm> using namespace std; int main(){ int a; double h, l; int cnt = 0; while(~scanf("%d,%lf,%lf", &a, &h, &l)){ if(h >= 25 * l * l){ printf("%d\n", a); cnt++; } } if(cnt == 0){ puts("該当なし"); } return 0; }
0
#include <bits/stdc++.h> struct Point { int x, y; } pos[1000][2]; char map[31][31]; bool used[100][100], found[100][100]; int count, n, m, k, square[31][31], c[1000], saved[31][31], t; Point find(Point p) { int i, j; for (i = -1; i <= 1; i++) for (j = -1; j <= 1; j++) if (i != j && map[p.x + i][p.y + j]...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; long long l; long long ex(long long a, long long b, long long c) { long long res = 0; long long Max = a + b + c + l; for (long long i = a; i <= a + l; i++) { if (b + c > i) continue; else { long long x = min(Max - i, i) - b...
1
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > vp; int dp[305][100000]; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int fun(int i, int x, int n) { if (x == 1) return 0; if (i == n && x != 1) return 100000000; if (x < 100000 && dp[i][x] > 0) return dp[i][x];...
4
#include <bits/stdc++.h> using namespace std; int a[100010], q[100010]; vector<int> v; int main() { int n; scanf("%d", &n); int i, j, t; memset(q, 0, sizeof(q)); v.clear(); for (i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); q[0] = 1; t = 1; int s = 0; for (i = 0; i < n - 1; i++) { if ...
2
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int const lim=100000000; typedef long long ll; ll s; int a[601][601],i,j,k,n,m,x,y; int main(){ scanf("%d%d%d%d",&n,&m,&x,&y); if (x==1&&y==1){ puts("No");return 0; } for (i=1,s=0;i<=n;i++) for (j=1;j<=m;j++){ if (i%x==0&&j%y==0) a[i...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int N = 201; double dp[205][205][405]; int n, l, k; int pro[205]; int bag[205]; int main() { scanf("%d%d%d", &n, &l, &k); for (int i = 1; i <= n; i++) scanf("%d", &pro[i]); for (int i = 1; i <= n; i++) scanf("%d", &bag[i]); double ans = 0; ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int inf = 1e8 + 7; struct edge { int u, v, ind; long long w; friend bool operator<(edge e1, edge e2) { pair<long long, int> t1 = {e1.w, e1.ind}; pair<long long, int> t2 = {e2.w, e2.ind}; return t1 < t2; } }; int n, m, k; vect...
5
#include <bits/stdc++.h> const long long mod = 1000000007; using namespace std; int n, m; vector<vector<int> > graf; vector<int> dp; int main() { long long n; cin >> n; long long ans = 0; while (n) { ans += (long long)pow(2, n); n--; } cout << ans; return 0; }
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 21; int n, s, l; long long a[MAXN], dp[MAXN]; set<pair<long long, int> > st; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> s >> l; for (int i = 0; i < n; i++) cin >> a[i]; int start = 0; for (int i = 0; ...
2
#include <bits/stdc++.h> using namespace std; int a[100100]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); int s = 0; for (int i = 1; i <= n - 1; i++) s += a[i]; int t = a[n] - s + 1; cout << t; }
2
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 5e5 + 10; long long indx[N], num[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { string s; cin >> s; if (s[0] == '?') indx[i] = 1; else ...
5
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:36777216") int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; using namespace std; using namespace std; string s, v; pair<int, int> p[200100]; pair<char, char> t[200100]; vector<in...
3
#include <iostream> #include <string> #include <utility> #include <algorithm> #include <map> #include <set> #include <vector> #include <cmath> #include <cstdlib> #include <queue> #include <stack> #include <iomanip> using namespace std; #define REP(i, n) for(ll i = 0;i < n;i++) #define REPR(i, n) for(ll i = n;i >= 0;i...
0
#include <cstdio> #include <algorithm> using namespace std; int n, m; char cv[256], ch, ch2; int main(){ while(scanf("%d\n", &n), n != 0) { fill(cv, cv + 256, 0); for (int i = 0; i < n; i++) { scanf("%c %c\n", &ch, &ch2); cv[ch] = ch2; } scanf("%d\n", &m); for (int i = 0; i < m; i++) { scanf("%c\...
0
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 1e5; long long n, arr[N + 2], sum; long long bigmod(long long b, long long p, long long mod) { long long ret = 1LL; while (p) { if (p & 1) ret = (ret * b) % mod; b = (b * b) % mod; p /= 2; } return ret; } int ...
5
#include <bits/stdc++.h> using namespace std; void _fill_int(int* p, int val, int rep) { int i; for (i = 0; i < rep; i++) p[i] = val; } signed long long L, R, K; void solve() { int f, i, j, k, l, x, y; cin >> L >> R >> K; if (K == 1) return (void)printf("%lld\n1\n%lld\n", L, L); if (R - L == 1) { if ((L...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a1[100005] = {0}; for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; a1[a] += c; a1[b] -= c; } int sum = 0; for (int i = 0; i < 100005; i++) { if (a1[i] > 0) sum += a1[i]; } cout << ...
2
#include <bits/stdc++.h> using namespace std; long double dis(double x, double y, double x1, double y1) { return sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)); } double PI = 3.14159265359; double e = 2.718281828; void EnGz() { ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); } l...
3
#include <bits/stdc++.h> using namespace std; namespace FGF { int n, m; const int N = 2e5 + 5; vector<int> g[N]; queue<int> q; int a[N], cnt[N]; bool vis[N]; void work() { int T; scanf("%d", &T); while (T--) { scanf("%d%d", &n, &m); int ans = 0; for (int i = 1; i < n; i++) { int u, v; scan...
6
#include <bits/stdc++.h> using namespace std; using llint = long long; const int N = 510, B = 1e9 + 7; int n, m, q; int e[N][2 * N]; int x[N]; int ps[N]; char s[N][N]; char bs[N]; int inv[] = {0, 1, 3, 2, 4}; int pw[N] = {1}; int rk; llint mypw(int a, int b, int m) { llint ret = 1; while (b) { if (b & 1) ret = ...
5
#include <bits/stdc++.h> using namespace std; pair<long long int, long long int> h[100002], r[100002]; int c, nr; int check(long long int l) { int i; long long int lx = INT_MAX, rx = INT_MIN, ly = INT_MAX, ry = INT_MIN; for (i = 0; i < c; i++) { lx = min(lx, h[i].first + l); rx = max(rx, h[i].first - l); ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 200001; const int maxk = 51; double DP[maxn][maxk]; double val[maxn], B[maxn], sum[maxn], recip[maxn]; int N, K; double costo(int i, int j) { return B[j] - B[i - 1] - sum[i - 1] * (recip[j] - recip[i - 1]); } void doDP(int ini, int fin, int iniq, int finq...
3
#include <bits/stdc++.h> using namespace std; int n, k, r; vector<int> G[500000]; int rest_stop[500000], cor[500000]; int dist[500000], pai[500000], sz[500000]; int anc[500000][25], MAX_LOG, nivel[500000]; void dfs(int v, int p, int d) { nivel[v] = d; anc[v][0] = p; if (d) MAX_LOG = max(MAX_LOG, (int)log2((double...
6
#include <bits/stdc++.h> int cnt[100100], tcnt[100100]; int u[100100], v[100100]; int* g[100100]; int a[100100]; int niz[100100]; int rez[100100]; int q[1000100]; int main() { int i, j, x, y, n, m; scanf("%d %d", &n, &m); for (i = 1; i <= m; i++) { scanf("%d %d", u + i, v + i); cnt[u[i]]++; cnt[v[i]]+...
4
#include <iostream> #include <tuple> #include <vector> #include <queue> using namespace std; typedef long long ll; typedef tuple<ll, ll> ii; typedef vector<bool> vb; typedef vector<ll> vi; typedef vector<ii> vii; typedef vector<vii> vvii; typedef priority_queue<ii, vii, greater<ii>> pq; ll n, m, s, t, u, v, a, b; v...
0
#include <iostream> #include <vector> using namespace std; int dp[1001]; int main() { int D, G; cin>>D>>G; vector<int> p(D),c(D); int p_sum=0; for (int i=0;i<D;++i) { cin>>p[i]>>c[i]; p_sum += p[i]; } for (int i=1;i<=D;++i) { for (int j=p_sum;j>=0;--j) { for (int k=0;k<=p[i-1]&&k<=j;...
0
#include <bits/stdc++.h> using namespace std; const int MAX_A = 1e7 + 5; const int MAX_N = 1e6 + 5; long long gcd(long long p, long long q) { if (q == 0) return p; return gcd(q, p % q); } long long sq(long long x) { return x * x; } bool is_perfect(long long x) { long long sqx = sqrt(x); if (sqx * sqx == x) retu...
4
#include <bits/stdc++.h> using namespace std; namespace star { const int maxn = 1e6 + 10, mod = 998244353; char s[maxn]; int n, l[maxn], r[maxn], w[maxn], inv[maxn], mul[maxn]; inline int fpow(int a, int b) { int ans = 1; for (; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) ans = 1ll * ans * a % mod; return a...
4