solution
stringlengths
52
181k
difficulty
int64
0
6
#include<cstdio> #define mod 1000000007 #define int long long int x,y,fac[20010000]; int quickpow(int x,int y){ if(y==0)return 1; if(y%2==0)return quickpow(x*x%mod,y/2); else return quickpow(x*x%mod,y/2)*x%mod; } int C(int n,int m){ if(m==0||n==m)return 1; return fac[n]*quickpow(fac[m],mod-2)%mod*quickpow(fac[n-m]...
0
#include <bits/stdc++.h> using namespace std; int x1[100]; int ololo[100]; int x2[100]; int y2[100]; int m[100]; int main(void) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d%d%d", &x1[i], &ololo[i], &x2[i], &y2[i]); m[i] = abs(((x1[i] - x2[i]) * (x1[i] - x2[i]) * (x1[i] - x2[i]))); ...
4
#include <bits/stdc++.h> using namespace std; const int M = 110; const int N = 101000 + M; const int MOD = (int)1e9 + 7; int a[N], F[N], Finv[N], Inv[N], n, m, Array[N][M]; void init() { Inv[1] = 1; F[0] = Finv[0] = 1; for (int i = 2; i < N; i++) { Inv[i] = (long long)Inv[MOD % i] * (MOD - MOD / i) % MOD; }...
5
#include <iostream> #include <cmath> using namespace std; int X, Y, Z, V[5], e[51], a[51]; // dp[マス][お金] := 確率 double dp[51][5000]; int main(){ while( cin >> X >> Y >> Z, X || Y || Z ){ // 初期化 for(int i = 0; i < 51; i++){ e[i] = a[i] = 0; for(int j = 0; j < 5000; j++){ dp[i][j] = 0.0; } } for...
0
#include <bits/stdc++.h> using namespace std; const int max_N = 300 + 20; vector<pair<int, int> > adj[max_N]; bool mark[max_N]; int pt[max_N], par[max_N]; pair<int, int> a[max_N]; vector<int> path; void Eulerian_Tour(int v) { while (pt[v] < (int)adj[v].size()) { if (!mark[adj[v][pt[v]].second]) { mark[adj[v...
2
#include <bits/stdc++.h> using namespace std; int main() { long long N, k; cin >> N >> k; if (k > N * (N - 1) / 2) cout << "Impossible" << endl; else { long long n = (-1 + sqrt(1 + 8 * k)) / 2; if (n * (n + 1) / 2 == k && n + 1 <= N) { for (int i = 0; i <= n; i++) { cout << "("; ...
3
#include <bits/stdc++.h> const long long INF = (long long)1e18 + 123; const int inf = (int)2e9 + 123; const int mod = 1e9 + 7; using namespace std; pair<long long, long long> a[100011]; long long n, mx_p[100011], mn_p[100011], mx_s[100011], mn_s[100011]; long long get(int r, int l) { return (a[r].first - a[l].first) ...
3
#include <bits/stdc++.h> using namespace std; vector<int> L[1010]; int dist[1010]; int foi0[1010]; int foi[1010]; int n, m; int solve(int a) { vector<int> v; queue<int> Q; Q.push(a); foi0[a] = 1; while (Q.size()) { int b = Q.front(); v.push_back(b); Q.pop(); for (int i = 0; i < L[b].size(); i+...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; int n, degree[MAXN], m; double mark[MAXN], dn[MAXN][3], dp[MAXN]; pair<int, int> ar[MAXN], node[MAXN]; bool leaf[MAXN]; void g(int p, int k) { dn[p][0] = dn[p][1] = mark[p]; degree[p] = k; if (ar[p].first) { g(ar[p].first, k + 1); g(ar...
3
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> par; UnionFind(int N) : par(N) { for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = ro...
0
#include<iostream> using namespace std; int N, M, Q; int sum[555][555]; int main() { int N, M, Q; cin >> N >> M >> Q; for (int i = 0;i < M;i++) { int L, R; cin >> L >> R; sum[L][R]++; } for (int i = 0;i < N;i++) { for (int j = 0;j < N;j++) { sum[i + 1][j + 1] += sum[i + 1][j] + sum[i][j + 1] - sum[i][...
0
#include <bits/stdc++.h> #define ll long long #define lsb(x) x & -x using namespace std; const int MOD = 998244353; int raise(int n, int p) { int ans = 1; while(p) { if(p % 2) ans = (1LL * ans * n) % MOD; n = (1LL * n * n) % MOD; p /= 2; } return ans; } int invMod...
2
#include <bits/stdc++.h> using namespace std; using namespace std; inline long long pow_mod(long long X, long long N, long long mod) { long long res = 1; while (N > 0) { if (N & 1) res = res * X % mod; X = X * X % mod; N >>= 1; } return res; } const long long SI = 2e5 + 100; const bool DBG = 0; cons...
3
#include <bits/stdc++.h> using namespace std; inline long long read() { long long s = 0; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) ; for (; ch >= '0' && ch <= '9'; ch = getchar()) s = s * 10 + ch - '0'; return s; } const int MAXN = 1e3 + 10; int sum[MAXN]; int ans[50][50]; int n, n...
3
#include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define rrep(i,a,b) for(int i=(a);i>=(b);--i) #define PB push_back #define ar2 array<int,2> #define vs vector<string> typedef long long LL; const LL P = 1e9+7; const int N = 2e5+5; mt19937 rng(time(0)); vector<int> g[N]; int n, ...
0
/*input 7 11 1 2 2 1 3 1 2 4 2 2 5 2 2 6 1 3 4 1 3 5 1 3 6 1 4 7 2 5 7 2 6 7 1 */ #include <bits/stdc++.h> using namespace std; #define sp ' ' #define endl '\n' #define fi first #define se second #define mp make_pair #define int long long #define N 1505 #define bit(x,y) ((x>>y)&1LL) int n, m; vector<vector<pair<int, i...
0
/* Noob */ #include<bits/stdc++.h> using namespace std; #define ll long long const int inf = 1000000000; bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } void solve() { ll n; cin >> n; ll a[n]; ll op[110] = {0}; for (int i = 0 ; i < n; i++)cin >> a[i], op[a[i]]++; vector<int>ans; fo...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int best = 0; long long int m, b; cin >> m >> b; for (int i = b; i >= 0; i--) { long long int x = (b - i) * m; long long int t = ((x + 1) * (i * (i + 1)) / 2) + ((i + 1) * (x * (x + 1)) / 2); best = max(best, t); } cout...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int l = 0, r = 0; int q = 0; for (int i = 0; i < n / 2; i++) { if (s[i] == '?') q++; else l += s[i] - '0'; } for (int i = n / 2; i < n; i++) { if (s[i] == '?') q--; else ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> first(n); vector<int> second(n); bool flag = false; int ans = 0; vector<int> one; for (int i = 0; i < n; ++i) { cout << "? " << 0 << " " << i << endl; fflush(stdout); cin >> first[i]; } for (int i = 0...
4
#include <bits/stdc++.h> using namespace std; const int MAX = 200002; const long long MOD = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<long long> pow; pow.push_back(1); for (int i = 1; i <= n; i++) { pow.push_back(pow.back() * 2); pow[i] %= MOD; } int le...
5
#include <bits/stdc++.h> using namespace std; template <typename T> void chkmax(T &a, const T &b) { a = a > b ? a : b; } template <typename T> void chkmin(T &a, const T &b) { a = a < b ? a : b; } const int MAXN = 1005, MAXM = 2005, MAXX = 500005; const long long INF = 2e18; long long f[2][MAXN], suf[MAXN], K; int p...
3
#include <bits/stdc++.h> using namespace std; char s[500005], ans[500005]; int k, n; int dp[500005][2]; int main() { scanf("%d%d%s", &n, &k, s); if (k == 2) { int tol1 = 0, tol2 = 0; for (int i = 0; i < n; i++) { if (s[i] != i % 2 + 'A') tol1++; if (s[i] != (i + 1) % 2 + 'A') tol2++; } p...
3
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7; int t, n, a[N]; vector<int> v; int main() { scanf("%d", &t); while (t--) { v.clear(); a[0] = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } int f = 0; if (a[n] > a[1]) f = 0; el...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; ll power(ll x, ll y); const ll MOD = 1e9 + 7; const ll INF = 1e18 + 18; const int inf = 2e9; const ll N = 1e3 + 3; ll pt[N][2]; ll n, f; vector<ll> vis(N, 0); map<ll, vector<ll> > X; map<ll, vector<ll> ...
6
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long int #define ul unsigned long long int const int n = 10006; int32_t main() { IOS; int T, N, y, x; cin >> T; for (int ts = 0; ts < T; ++ts){ cin >> x >> y; cout << x-1 << " " << y << ...
3
#include<bits/stdc++.h> using namespace std; string s,s1; int len,len1; int main() { cin>>s>>s1; int len=s.length(); for(int i=0;i<len;i++) { cout<<s[i]; if(s1[i]) cout<<s1[i]; } cout<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e5, Pow = 18; int n, x, a[MaxN + 5]; int main() { srand((unsigned)time(NULL)); while (~scanf("%d%d", &n, &x)) { for (int i = 1; i <= n; i++) a[i] = 0; if (n == 1) { printf("YES\n%d\n", x); } else if (n == 2) { if (x == 0) ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m, tmp; cin >> n >> m; bool flag = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { scanf("%d", &tmp); if ((i == 1 || i == n || j == 1 || j == m) && tmp) { flag = 1; } } } if (flag) cout <...
1
#include <iostream> #include <vector> #include <climits> int main() { int n; std::cin >> n; std::vector<std::vector<int>> mat(n + 1, std::vector<int>(n + 1, 0)); for (auto i = 1; i <= n; ++i) { for (auto j = 1; j <= n; ++j) { std::cin >> mat[i][j]; mat[i][j] += mat[i][j - 1] + mat[i - 1][j] - mat[i - 1][j ...
0
#include <bits/stdc++.h> using namespace std; int dp[201][201][2]; int main() { string s; cin >> s; int n=s.size(); for(int i=0;i<n;i++){ for(int j=0;j<n;j++)dp[i][j][0]=1<<29,dp[i][j][1]=-(1<<29); if(isdigit(s[i]))dp[i][i][0]=dp[i][i][1]=s[i]-'0'; } for(int i=0; i<n; i++){ for(int j=0;j<n-i;j++...
0
#include <vector> #include <map> #include <set> #include <stack> #include <queue> #include <algorithm> #include <utility> #include <functional> #include <sstream> #include <iostream> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> #include <c...
0
#include <bits/stdc++.h> using namespace std; long m, n, ta, tb, k, A[200001], B[200001], i, j, b, r = -1, bou; int main() { for (cin >> n >> m >> ta >> tb >> k; i < n; i++) cin >> A[i], A[i] += ta; for (i = 0; i < m; i++) cin >> B[i]; if (n <= k || m <= k) return cout << -1, 0; for (i = 0; i <= k; i++) { b...
2
#include <bits/stdc++.h> using namespace std; const int INF = 1001001001; const long long INFLL = 1001001001001001001LL; template <typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template <typename T> void chmin(T& a, T b) { if (a > b) a = b; } template <typename T> v...
2
/* convex_hull verified on 2020/3/13 https://atcoder.jp/contests/agc021/submissions/10802949 */ #include <iostream> #include <vector> #include <algorithm> using namespace std; /* snippet starts */ #include <complex> #include <numeric> #include <iomanip> #define X real() #define Y imag() // operator overload for ...
0
#include<iostream> #include<cstdio> using namespace std; typedef long long ll; ll n,k; int main(){ cin>>n>>k; ll ans=0; for (ll b=n;b>k;b--){ ll l=k,r=b-1; ll c=(n+1)/b; ans+=c*(r-l+1); if (l==0) ans--; l=k+c*b; if (l<=n){ ans+=n-l+1; } } cout<<ans; }
0
#include <bits/stdc++.h> using namespace std; int zero_fact(int n) { int x = 5; int zero = 0; while (x <= n) { zero += n / x; x *= 5; } return zero; } int main() { vector<int> v; int m; cin >> m; for (int i = 5;; i++) { if (zero_fact(i) == m) { v.push_back(i); } if (zero_fact...
2
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const long long LB = 0; const long long RB = (1LL << 60LL) - 1; vector<tuple<int, long long, long long>> reduced[2]; vector<pair<long long, long long>> all[2][65]; inline void insert(int id, int depth, long long l, long long r, long long qs, ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, a[101], i, d = 0, mx = 30000; cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; } for (i = 2; i <= n; i++) { d = max(d, a[i] - a[i - 1]); } for (i = 2; i < n; i++) { mx = min(mx, max(d, a[i + 1] - a[i - 1])); } cout << mx; }...
1
#include <bits/stdc++.h> using namespace std; int main() { int n,m; cin>>n>>m; int ar[n+3]; for(int i=0;i<n;i++)cin>>ar[i]; sort(ar,ar+n); int sum=0; for(int i=0;i<m;i++)sum+=ar[i]; cout<<sum<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main(){ int t,n; cin>>t; while(t--){ int o=1,e=2,l,i=0; cin>>n; l=n*n; if(n==1) cout<<'1'<<endl; else if(n==2)cout<<"-1"<<endl; else{ while(o<=l){ cout<<o<<' '; i+...
3
#include <bits/stdc++.h> using namespace std; template <typename T> inline T sqr(T a) { return a * a; }; template <typename T> void dprint(T begin, T end) { for (auto i = begin; i != end; i++) cerr << (*i) << " "; cerr << "\n"; }; const int maxn = 2500 + 10; int n, m, q, hs; map<pair<pair<int, int>, pair<int, int...
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int h, c, t; cin >> h >> c >> t; if (h + c >= 2 * t) { cout << "2\n"; } else { int k = (h - t) / (2 * t - h - c); if (abs((k + 1) * h + k * c - t...
3
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<queue> #include<map> #include<stack> using namespace std; typedef long long ll; #define N 1000015 const int p=1e9+7; int n,dp[N],s[N]; int main() { scanf("%d",&n); dp[n]=n;s[n]=n; dp[n-1]=1ll*n*n%p;s[n...
0
#include <iostream> using namespace std;int main(){string s;long n;cin>>n;while(n--){s=char(97+n%26)+s;n/=26;}cout<<s;}
0
#include <bits/stdc++.h> using namespace std; int main() { string inp; cin >> inp; int elt1 = inp[0] - 64, elt2 = inp[1] - 64; bool out = true; for (int i = 2; i < inp.size(); i++) { if ((elt1 + elt2) % 26 == (inp[i] - 64 + 1) % 26) { elt1 = elt2; elt2 = inp[i] - 64; } else { out = f...
6
#include <bits/stdc++.h> using namespace std; struct RTC { ~RTC() { cerr << "Time: " << clock() * 1.0 / CLOCKS_PER_SEC << " seconds\n"; } } runtimecount; int n, m; string tab[60]; bool vis[60][60]; int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, 1, 0, -1}; bool dfs(int i, int j, int pi, int pj, char col) { vis[i][j] = t...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 350000 + 100; int data[maxn]; int dp[2][maxn]; int hash1[maxn]; int tree[maxn * 4]; int flag[maxn * 4]; int prev_pos[maxn]; void inc(int root, int l, int r, int a, int b, int delta) { if (a == l && b == r) { flag[root] += delta; tree[root] += delt...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, a; cin >> n; bool flag = 1; for (int i = 0; i < n; i++) { scanf("%d", &a); if (a == 1) flag = 0; } if (flag) cout << "EASY" << endl; else cout << "HARD" << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t = 1; cin >> t; for (int w = 1; w <= t; w++) { long long int n, k; cin >> n >> k; if ((n % 2 == 0 && k % 2 != 0) || k * k > n || (n % 2 != 0 && k % 2 == 0)) ...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const int INF = (int)1e9 + 7; const long long LINF = (long long)1e18 + 7; const int MOD = (int)1e9 + 7; const int MAXN = (int)1e5 + 7; const double EPS = (double)1e-6; void file() {} string A[1007]; vector<bool> G[1007][1007]; int...
4
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int INF = 100100; const int N = 15; const int M = (1 << 14) + 7; bool g[N][N]; int n, m; int edgesToMask[N][M]; vector<int> pathInMask[M][N][N]; int dp[M]; int par[M][3]; int main() { scanf("%d%d",...
6
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < n; i++) #define INF 100000000 #define MOD 1000000007 #define EPS 1e-10 #define MAX_N 100000 #define fi first #define sc second using namespace std; typedef long long ll; typedef pair<ll,ll> P; #define SI 2002 #define ADD(X,Y) (X) = ((X)+(Y))%MOD int n, k; l...
0
#include<bits/stdc++.h> using namespace std; int N = 200000; int h[200005],n; long long a[200005],BIT[200005]; int LS(int x){ return x&-x; } void update(int x, long long val){ for(int i = x; i<=N;i+=LS(i)){ BIT[i] = max(BIT[i],val); } } long long query(int x){ long long ans = 0; for(int i= x; i>=1;i-=LS(i)){...
0
#include<bits/stdc++.h> #define mx 100005 #define md 1000000007 using namespace std; map<string, int> mp; string s; long long n, ans; int main(){ cin >> n >> s; for(int i = 0; i < 2; i++){ for(int j = 0; j < (1<<n); j++){ int l = 0, r = n; char t[20]; t[n+1] = '\0'; for(int k = 0; k < n; k...
0
#include <bits/stdc++.h> using namespace std; const int N = 1000006; bool vis[N]; int n, k, a[N]; vector<int> v; int dfs(int x) { vis[x] = 1; if (vis[a[x]]) return 1; return 1 + dfs(a[x]); } bitset<1000006> cur; map<int, int> mp; int getmin() { cur.set(0); for (int x : v) ++mp[x]; for (auto& t : mp) { f...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long first = 0; long long second = 0; bool isSame = true; bool cheek = true; long long dif; for (int i = 0; i < n; i++) { long long value; cin >> value; if (i == 0) dif = value; else if (dif != value) ...
2
#include <bits/stdc++.h> template <typename T> void MACRO_VAR_Scan(T& t) { std::cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First& first, Rest&... rest) { std::cin >> first; MACRO_VAR_Scan(rest...); } template <typename T> void MACRO_VEC_ROW_Init(int n, T& t) { t.resize(n); } tem...
4
#include <bits/stdc++.h> using namespace std; int main() { int a[101], i, j = 0, k = 1, buf[101 - 1], n; cin >> n; for (i = 1; i < n + 1; i++) a[i] = i; for (i = 1; i < n + 1; i++) { k += i; if (k % n == 0) buf[j] = n; else buf[j] = k % n; j++; } for (i = 0; i < n - 1; i++) cout ...
1
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll read(){ ll a=0,b=getchar(),c=1; while(!isdigit(b))c=b=='-'?-1:1,b=getchar(); while(isdigit(b))a=a*10+b-'0',b=getchar(); return a*c; } ll n,m,ans,a[100005],b[200005]; ll check(ll x){ ll res=0; for(int i=0;i<n;i++){ ll k=lower_bound(a,a+n,x-a[i...
0
#include <bits/stdc++.h> using namespace std; typedef struct { long long int len, sz; } Box; bool cmp(Box x, Box y) { return (x.len < y.len); } long long int Pow(int base, long long int p) { int ans = 1; for (int i = 0; i < p; i++) { ans *= base; if (ans > 1e9) return 1e9 + 1; } return ans; } int main...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int check = 0; if (n == 1) cout << -1 << endl; else { cout << 6; for (long long int i = 1; i < n; i++) { cout << 7; } c...
1
#include <bits/stdc++.h> using namespace std; const int MOD = 2e5 + 10; int n, a[MOD], root[MOD]; bool bVisit[MOD]; int oneroot = -1; int ans = 0; int findroot(int x) { int f = a[x]; if (f == x) { if (x != oneroot) { a[x] = oneroot; ans++; } return a[x]; } if (!bVisit[f]) { bVisit[f]...
4
#include <bits/stdc++.h> using namespace std; int main(){ int n,k,count=0; cin>>n>>k; for(int i=0;i<n;i++){ int x; cin>>x; if(k<=x) count++; }cout<<count<<endl; }
0
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100000; int main() { int n, k; scanf("%d%d", &n, &k); k = min(n / 2, k); long long sum = 0; for (int i = 0, j = 1; i < k; i++, j += 2) sum += 2 * (n - j) - 1; printf("%lld\n", sum); return 0; }
2
#include <iostream> #include <sstream> #include <iomanip> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <climits> #include <cfloat> using namespace std; int solve(st...
0
#include <bits/stdc++.h> using namespace std; inline long long in() { int32_t x; scanf("%d", &x); return x; } inline string getStr() { char ch[500]; scanf("%s", ch); return ch; } const long long MOD = 1e9 + 7; const long long base = 29; const long long MAX_N = 2e3 + 10; const long long MAX_T = MAX_N; inline...
4
#include <bits/stdc++.h> using namespace std; long long ans, dis[2020], a[2020][2020]; int n, frm, tot, b[2020], k[2020], x[2020], y[2020], pre[2020]; bool flag[2020]; int main() { memset(flag, false, sizeof(flag)); memset(dis, 0x3f, sizeof(dis)); memset(a, 0x3f, sizeof(a)); scanf("%d", &n); for (int i = 1; i...
4
#include <bits/stdc++.h> using namespace std; using ll = long long int; using ull = unsigned long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; const int INT_INF = (int)(2e9); const ll LL_INF = (ll)(2e18); const int NIL = -1; static mt19937 _g(time(nullptr)); inline ll randint(...
6
#include<iostream> using namespace std; int main(){ int s; cin>>s; cout<<s*s*s; }
0
#include <bits/stdc++.h> using namespace std; int main() { int wall[110][110] = {0}; int r, c; scanf("%d %d%*c", &r, &c); char a[110]; for (int i = 1; i < r; i++) gets(a); int flag = 0; int seg = 0; for (int i = 0; i < c; i++) { char x; scanf("%c", &x); if (flag == 0) { if (x == 'B') {...
4
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; bool flg = false; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') flg = true; for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48); return flg ? -x : x; } int n, m; int bin[50010], bi...
4
#include <bits/stdc++.h> using namespace std; int l, r, n, T, L; char a[2000010]; int find() { for (int i = L; i <= r; i++) if (a[i] >= '5' && a[i] != '.') return i; return 0; } void print() { int r = n; while (a[r] == '0') r--; for (int i = 1; i <= r; i++) putchar(a[i]); } int main() { scanf("%d%d", &n...
1
#define _USE_MATH_DEFINES #include <iostream> #include <algorithm> #include <functional> #include <vector> #include <cstdio> #include <string> #include <cmath> #include <cfloat> #include <map> #include <queue> #include <stack> #include <list> using namespace std; int main(){ int n,m; while(cin>>n>>m,n!=0||m!=0){...
0
#include <bits/stdc++.h> using namespace std; const int nmax = 1e6 + 1; const int mod = 1e9 + 7; int n; int dp[nmax][20][2]; int32_t f(int x, int y) { int res = (y == 1) ? 3 : 1; return ((int)n / (res * (1 << x))) % mod; } int DP(int idx, int two, int thr) { if (idx > n) return 1; if (dp[idx][two][thr] != -1) r...
5
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9 + 7; const int MAXN = 2 * 1e5; int main() { int n; cin >> n; int a[MAXN]; int cnt = 0; int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum = sum + a[i]; if (a[i] == 0) cnt++; } if (cnt == n) cout << "NO"; e...
1
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x)....
4
#include <bits/stdc++.h> using namespace std; void ex_gcd(long long a, long long b, long long &d, long long &x, long long &y) { if (!b) { d = a; x = 1; y = 0; } else { ex_gcd(b, a % b, d, y, x); y -= x * (a / b); } } long long max(long long a) { return a > 0 ? a : -a; } int main() ...
3
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; if (y == 0 || (y - x) > 1) cout << "No"; else if (y == 1 && x > 0) cout << "No"; else if (y == 1 && !(x > 0)) cout << "Yes"; else if ((x - (y - 1)) % 2 == 0) cout << "Yes"; else cout << "No"; cout << ...
1
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f3f3f3f3f; int main() { int u, v, w, n, m; cin >> n >> m; int maxn = 100001; int path[maxn]; long long dis[maxn]; vector<pair<long long, int>> G[maxn]; for (int i = 0; i < m; i++) { cin >> u >> v >> w; G[u].push_back(pair...
3
#include <bits/stdc++.h> using namespace std; int n, m; vector<pair<long long, long long>> vec; const int N = 1e6 + 5; bool check(long long x) { x--; if (x & 1) return (x + 1) * x / 2 + (x + 1) / 2 <= n; return (x + 1) * x / 2 + 1 <= n; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m;...
3
#include <bits/stdc++.h> using namespace std; template <class T> inline void dmin(T& x, T y) { y < x ? x = y : 0; } template <class T> inline void dmax(T& x, T y) { y > x ? x = y : 0; } template <class T> inline void dmin(T& x, vector<T> y) { for (auto t : y) t < x ? x = t : 0; } template <class T> inline void dm...
4
#include <bits/stdc++.h> using namespace std; struct otr { int typ; int x1, x2, ver; }; bool operator<(otr a, otr b) { return (a.x1 < b.x1 || (a.x1 == b.x1 && a.typ < b.typ)); } int main() { int n, m; int x, h, l, r; scanf("%d%d", &n, &m); otr* mas = new otr[4 * n + m + 2]; int sz = 0; otr tmp; for ...
3
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <sstream> #include <string> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <utility> #include <cctype> #include <numeric> using namespac...
0
#include <bits/stdc++.h> using namespace std; unsigned long long m, ans, lef, rig, mid, sum, mm, i; int main() { scanf("%llu", &m); lef = 0; rig = 1e19; while (lef <= rig) { mid = (lef + rig) >> 1; for (i = 2, sum = 0; i < 2000000; i++) { if (mid >= i * i * i) sum += mid / (i * i * i); ...
3
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int oo = 0x3f3f3f3f; const long long ooLL = 0x3f3f3f3f3f3f3f3fLL; int main() { set<int> p; for (int x; scanf("%d%*c", &x) == 1; p.insert(x)) ; int pp = -10; int pf = -10; p.insert(10000); bool f = true; for (set<int>::const_i...
3
#include <bits/stdc++.h> using namespace std; int m[500100][5]; int main() { int i, j, st, ed, n, ans = 0; set<pair<int, int> > s; set<pair<int, int> >::iterator it; vector<pair<int, pair<int, int> > > v; ios::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (i = 0; i < 3; i++) for (j = 0; j < n...
4
#include<iostream> #include<string> #include<cstdio> using namespace std; struct Node { int key; Node* parent; Node* left; Node* right; }; Node* root; void insert(int val) { Node* x = new Node(); x->key = val; x->left = nullptr; x->right = nullptr; Node *q = nullptr; Node *p = root; while (p != nullptr) { ...
0
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 9; long long n, k; long long a[maxn]; int main() { cin >> n >> k; long long ret(0); for (long long i = 1; i <= k; ++i) a[i] = i, ret += a[i]; if (ret > n) { puts("NO"); return 0; } long long tmp(n - ret); if (tmp >= k) { ...
4
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; cout << min(a, min(b, (a + b) / 3)); }
3
#include <bits/stdc++.h> using namespace std; struct union_find { vector<int> p; union_find(int n) : p(n, -1) {} bool join(int u, int v) { if ((u = root(u)) == (v = root(v))) return false; if (p[u] > p[v]) swap(u, v); p[u] += p[v]; p[v] = u; return true; } int root(int u) { return p[u] < 0...
4
#include<bits/stdc++.h> using namespace std; using LL = long long; int main(){ string s; cin >> s; set<char> cs; for(int i = 0;i < s.size();i++) cs.emplace(s[i]); int ans = 1000; for(auto& c : cs){ int count = 0; int an = 0; for(int i = 0;i < s.size();i++){ ...
0
#include <bits/stdc++.h> using namespace std; long long p = (long long)2e18; int n; long long k; vector<long long> v; bool ok() { for (int i = 0; i < n; ++i) if (v[i] >= k) return true; return false; } long long mu(long long x, long long y) { if (y == 0) return 0; return (x >= 1 + (long long)(p / y) ? p : x...
6
#include <iostream> using namespace std; int main() { int x, y; while (cin >> x >> y, (x || y)) { cout << min(x, y) << " " << max(x, y) << endl; } }
0
#include<iostream> #define M 100000007 using namespace std; int r,c; int dp[2][10][3][100000]; //dp[r][c][左からn本][上からn本] int g[20][20]; char z; int po3[21]; int main(){ cin >> r >> c; po3[0] = 1; for(int i=0;i<c;i++)po3[i+1] = po3[i]*3; for(int i=0;i<r;i++) for(int j=0;j<c;j++){ cin >> z; if(...
0
#include <bits/stdc++.h> using namespace std; const int sz = 2e5 + 100; vector<bool> t; vector<int> g[sz], p, ans; int dp[sz]; int rgcd(int a, int b, int& x, int& y) { if (a == 0) { x = 0; y = 1; return b; } int curx, cury, g = rgcd(b % a, a, curx, cury); x = cury - b / a * curx; y = curx; retur...
3
#include <bits/stdc++.h> using namespace std; long long T, n, m, k, t; long long s[10000009]; int main() { int ncase = 0; while (scanf("%I64d", &n) == 1) { if (n % 3) { printf("0\n"); continue; } n /= 3; int cnt = 0; for (long long i = 2; i * i <= n; i++) if (n % i == 0) { ...
5
#include<iostream> using namespace std; char s1[101],s2[110],s3[101]; int main() { cin>>s1>>s2>>s3; cout<<s1[0]<<s2[0]<<s3[0]; }
0
#include <bits/stdc++.h> using namespace std; struct Aho { struct vertex { vector<int> next, go; int p, link; char pch; int leaf; vertex(int p = -1, char pch = -1) : next(26, -1), go(26, -1), p(p), pch(pch), link(-1), leaf(0) {} }; struct STree { vector<int> t; int n; STree...
6
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/stack:240000000") const int INF = 2147483647; const long long LLINF = 9223372036854775807LL; const int ST = 100010; const int ST1 = 1000010; bool myf2(int i, int j) { return (i > j); } int ABS(int a) { if (a < 0) return a * (-1); else r...
4