solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
int arr[MAXN];
int dp[MAXN];
int main() {
int n, m, d;
cin >> n >> d;
for (int i = 0; i < n; i++) cin >> arr[i];
cin >> m;
sort(arr, arr + n);
dp[0] = arr[0];
for (int i = 1; i < n; i++) {
dp[i] = arr[i] + dp[i - 1];
cerr << dp... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m, i, j, k, l, x, y;
cin >> n >> m;
long long int a[n + 5], b[m + 5];
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < m; i++) cin >> b[i];
x = 0, y = 0, k = 0, l = 0;
for (i = 0; i < n; i++) {
x += a[i];
while (x > y)... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[2003];
int depth[2003], root[2003];
int ans = 0, n;
void dfs(int x, int y) {
depth[x] = y;
for (int i = 0; i < v[x].size(); i++) {
dfs(v[x][i], y + 1);
}
}
int main() {
int i, j, a;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a;
if (a =... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100005], b[100005], ans[100005], x;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < n; i++) scanf("%d", &x), b[x] = i;
for (int i = 0; i < n; i++) {
ans[b[a[i]]] = i + 1;
}
for (int i = 0; i < n; i++... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5000005;
const int oo = 1000000007;
int t, l, r, n, prime[N];
long long f[N], p[N];
void calc() {
long long ans = 0;
for (int i = l; i <= r; ++i) {
f[i] %= oo;
ans += (p[i - l] * f[i]) % oo;
ans %= oo;
}
cout << ans;
}
int main() {
cin >>... | 4 |
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pii pair<ll,ll>
using namespace std;
ll arr[2005],chk[2005];
vector<pii> ans;
vector<ll> ch[1000005];
void solve(){
ll i,j,k,a,b,c,n;
scanf("%lld",&n);
for(i=1;i<=2*n;i++){
scanf("%lld",&arr[i]);
}
so... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int n, m, o, p, answer;
int64_t sum, pre;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sum = pre = answer = p = 0;
for (int i = 0; i < m; i++) {
scanf("%d", &o);
sum += o;
while (p <= n)... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int Mo = (int)1e9 + 7;
long long i, j, m, n, p, k, Mp, Max;
long long f[101][10001], c[101][101], G[101][101][2];
long long power(long long x, long long y) {
long long sum = 1;
if (!x) return 1;
for (; y; y >>= 1) {
if (y & 1) sum = 1ll * sum * x % Mo;
x... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long bigmod(long long a, long long b) {
if (b == 0) return 1;
if (!(b & 1)) {
long long ret = bigmod(a, b / 2);
return ((ret % 1000000007) * (ret % 1000000007)) % 1000000007;
} else
return ((a % 1000000007) * (bigmod(a, b - 1) % 1000000007)) % 1000000... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline void R(int &x) {
x = 0;
int 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 - '0';
ch = getchar();
}
x *= f;
}
inline void R(long long... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long t, tt, i, j, x, y, tot;
int main() {
cin >> t;
for (tt = 1; tt <= t; tt++) {
cin >> x >> y;
j = 1;
tot = 0;
while ((x != 0) || (y != 0)) {
if ((x % 2) != (y % 2)) tot = tot + j;
j = j * 2;
x = x / 2;
y = y / 2;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int pw(int a, int b, int mod) {
int r = 1;
while (b) {
if (b & 1) {
r = (long long)r * a % mod;
}
a = (long long)a * a % mod;
b /= 2;
}
return r;
}
int dv(int a, int b, int mod) {
return (long long)a * pw(b, mod - 2, mod) % mod;
}
const int C... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int s = 0, p = 0, m = 0, i, j, k, l;
string s1, s2, s3;
cin >> s1 >> s2 >> s3;
if (s1 > s2) swap(s1, s2);
if (s2 > s3) swap(s2, s3);
if (s1 > s2) swap(s1, s2);
if (s1... | 2 |
#include <bits/stdc++.h>
using namespace std;
char c[] = {'Q', 'R', 'U', 'O', 'P', 'S', 'D', 'G', 'J', 'C', 'B'};
string s;
int main() {
cin >> s;
int nr = 0;
for (int i = 0; s[i]; i++)
for (int j = 0; c[j]; j++)
if (s[i] == c[j]) {
nr++;
}
if (nr == 0 || nr == s.size())
cout << "YES... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[5];
while(cin >> a[0] && a[0]) {
for(int i=1; i<5; i++) cin >> a[i];
set<int> s;
for(int i=0; i<5; i++) {
a[i]--;
s.insert(a[i]);
}
for(int i=0; i<5; i++) {
if(s.size()==1||s.size()==3) cout << 3 << endl;
e... | 0 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
if (n % 2 == 0) {
for (long long int i = 0; i < n / 2; i++) cout << '1';
cout << '\n';
... | 1 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:255000000")
bool firstout = 1;
template <class T>
T &minn(T &a, T b) {
if (b < a) a = b;
return a;
}
template <class T>
T &maxx(T &a, T b) {
if (a < b) a = b;
return a;
}
int &madd(int &a, int b) {
a += b;
if (a >= 1000000007) a -... | 4 |
#include <bits/stdc++.h>
using namespace std;
string s1, s2, s;
int n, t, m, ans, res;
int main() {
cin >> n >> t;
cin >> s1 >> s2;
for (int i = 0; i < n; i++)
if (s1[i] == s2[i])
ans++;
else
res++;
t = n - t;
m = 0;
for (int i = 0; i < n; i++) {
if (s1[i] == s2[i]) {
s += s1[i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long query, i, j;
map<long long, long long> mp;
map<long long, long long>::iterator itr;
vector<long long> v;
cin >> query;
while (query--) {
long long n;
mp.clear();
long long ans = 0;
v.clear();
long long x;
cin >> n;
... | 4 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
int sum;
cin>>s;
for(int i=0;i<3;i++){
if(s[i]=='o')sum++;
}
cout<<700+(sum*100);
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
void itval(istream_iterator<string> it) {}
template <typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args)... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
if (k == n || k == 0)
cout << 0 << ' ' << 0;
else {
cout << 1 << ' ' << min(n - k, 2 * k);
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3500, mod = 1000000007;
int qmod1(const int &x) { return x >= mod ? x - mod : x; }
int f[N][2][2][N];
char st[N];
int A[N], B[N], a[N], len, lenp, K, p;
int dfs(int t, int limn, int limi, int k) {
if (t < 0) {
return limi && k >= K;
}
if (f[t][limn][... | 4 |
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e6+10;
int n,left,right,s0,s1;
struct node {
int x,y;
bool operator <(node b) const {
return x-y>b.x-b.y;
}
} a[N];
char s[N];
int main() {
scanf("%d",&n);
for(int i=1,l,r;i<=n;i++) {
scanf("%s",s+1); ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[30];
int main()
{
char c;
int n,i;
long long ans=1;
scanf("%d",&n);
getchar();
for(i=1;i<=n;i++)
{
scanf("%c",&c);
a[c-'a']++;
}
for(i=0;i<26;i++)
ans=ans*(a[i]+1)%1000000007;
printf("%lld",(ans+1000000006)%1000000007);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n;
cin >> n;
string x;
cin >> x;
int cnt = 0;
for (i = 0; i < n - 1; i += 2) {
if (x[i] == 'a' && x[i + 1] != 'b') {
cnt++;
x[i + 1] = 'b';
} else if (x[i] == 'b' && x[i + 1] != 'a') {
cnt++;
x[i + 1] = 'a';... | 1 |
#include <bits/stdc++.h>
using namespace std;
int p[2001], w[2001], z[2001];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= 2 * n; i++) scanf("%d", &p[i]);
for (int i = 1; i <= m; i++) {
int u, v;
scanf("%d%d", &u, &v);
w[u] = v;
w[v] = u;
}
int t;
scanf("%d", &t);
fo... | 3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, m, d, x;
cin >> n >> m >> d;
long lo... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, k;
map<string, map<int, int> > dict;
char s[maxn];
bool is_reverse(const string &t) {
for (int i = 0; i < t.size() / 2; ++i) {
if (t[i] != t[t.size() - i - 1]) return false;
}
return true;
}
string rev(string t) {
for (int i = 0; ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int p = 0;
char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') p = p * 10 + c - '0', c = getchar();
return p;
}
int head[1000005], ver[1000005 * 2], nxt[1000005 * 2], tot;
void add(int a, int b) {
tot++;
nxt[... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, a[1000005], dp[1000005];
while (scanf("%d", &n) == 1) {
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
int res = 0;
for (int i = 0; i < n; i++) {
dp[a[i]] = max(dp[a[i]], 1);
for (int j = 2;... | 6 |
#include <bits/stdc++.h>
using namespace std;
void ga(int N, int *A) {
for (int i(0); i < N; i++) scanf("%d", A + i);
}
int N, M, A[(1 << 18)], D, K, Z, b, e, I, J, B[(1 << 18)], L;
long long pw(long long n, long long k) {
long long r(1);
while (k) {
if (k & 1) r *= n, r %= M;
n *= n, n %= M;
k >>= 1;... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
char c = getchar();
int p = 1, ret = 0;
while ((c < '0') || (c > '9')) {
if (c == '-') p = -1;
c = getchar();
}
while ((c >= '0') && (c <= '9'))
ret = (ret << 1) + (ret << 3) + c - '0', c = getchar();
return ret * p;
}
int n, m;
i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, l[155], r[155], k = 0, nowx = 1, cnt, maxn;
char ch;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
ch = getchar();
while (ch != 'G' && ch != 'W') ch = getchar();
if (ch == 'W') {
if (l[i... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> c[29];
int main() {
int at[2];
string s, t;
cin >> s >> t;
for (int i = 0; i < s.length(); i++) c[s[i] - 'a'].push_back(i);
int f = 0;
int an = 1;
for (int i = 0; i < t.length(); i++) {
if (c[t[i] - 'a'].empty()) {
cout << -1;
retur... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int MAXN = 1e6 + 10;
const int MOD = 1000000007;
long long k;
long long x, y, z;
int main() {
cin >> x >> y >> z >> k;
k += 3;
while (x + y + z > k) {
if (x >= y && x >= z)
x--;
else if (y >= z && y >= x)
y--;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
clock_t begin = clock();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
pair<int, int> pp[n];
int a;
for (int i = 0; i < n; i++) {
cin >> a;
if (a < 0)
pp[i] = {a, i};
else
pp[i] = {-a - 1, i};
}
so... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool fs(T &x) {
int c = getchar();
int sgn = 1;
while (~c && c < '0' || c > '9') {
if (c == '-') sgn = -1;
c = getchar();
}
for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
x *= sgn;
return ~c;
}
st... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e5 + 5;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
vector<int> adj[mxN];
vector<int> a, b, path, cycle;
int pos[mxN];
void bipartite(int v, int col, int par) {
if (col ==... | 4 |
#include <bits/stdc++.h>
using namespace std;
int sz[400010];
void dfs(int u, int par, vector<vector<int> >& adj) {
sz[u] = 1;
for (auto it : adj[u])
if (it != par) {
dfs(it, u, adj);
sz[u] += sz[it];
}
}
int furthest_node;
void dfs_centroid(int u, int par, vector<vector<int> >& adj, int N) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int x;
cin >> x;
int now = 0;
int qtd = 0;
int num = 1, answer = 0;
while (now != x) {
if (now * 10 + num > 10000) {
now = 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 111;
const long long H = 100;
const long long W = 100 * 1000;
const long double EPS = 1e-7;
long long n, h1, h2;
long long score[N], a[N], b[N], type[N];
long long solve(int runid) {
long long res = 0;
for (int floor = 0; floor < (n + 1); ++floor) {
lo... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int n, h[MAXN], mx[MAXN];
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> h[i];
for (int i = n; i >= 0; i--) mx[i] = max(h[i + 1], mx[i + 1]);
for (int i = 0; i < n; i++) cout << max(h[i], mx[i] + 1) - h[i] << " ";
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
long long tt;
cin >> tt;
while (tt--) {
long long n, g, b;
cin >> n >> g >> b;
if (g >= b || g >= (n + 1) / 2)
cout << n << '\n';
else {
if (((n + ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
s.pop_back();
s.pop_back();
for(int i = s.size(); i >= 0; i-=2){
int t = i/2;
if(s.substr(0,t)==s.substr(t,t)){
cout<<i;
break;
}
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
string a;
cin >> a;
int first = -1, last = -1;
for (int i = 0; i < a.size();... | 1 |
#include <iostream>
int main(){int a,b;std::cin>>a>>b;std::cout<<(a+b>=24?a+b-24:a+b);} | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll... | 6 |
#include<iostream>
using namespace std;
const int MAX = 2000000;
int H,A[MAX+1];
void maxHeapify(int i){
int l,r,largest;
l = 2*i;
r= 2*i+1;
if(l<=H&&A[l]>A[i])largest = l;
else largest = i;
if(r<=H&&A[r]>A[largest])largest = r;
if(largest!=i){
swap(A[i],A[largest]);
maxHeapify(largest);
}
}
int main(){
cin>... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int a, b, n;
cin >> a >> b >> n;
if (b == 0) {
cout << 0 << '\n';
return;
}
if (a == 0) {
if (b) {
cout << "No solution" << '\n';
} else {
cout << 0 << '\n';
}
return;
}
if (b % a) {
cout << "No solution" ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x;
cin >> n >> x;
long long ans = 0;
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
ans += tmp;
}
if (ans + n - 1 == x)
printf("YES\n");
else
printf("NO\n");
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d%d", &n, &k);
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
if (k < n + 1 || n == 4) {
printf("-1");
return 0;
}
printf("%d %d", a, c);
for (int i = 1; i <= n; i++) {
if (i != a && i != b && i != c && i != d) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
const double PI = acos(-1.0);
int lcp[N][N];
char s[N];
int dp[N];
void solve() {
memset(dp, 0, sizeof dp);
int n;
scanf("%d%s", &n, s + 1);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
lcp[i][j] = 0;
}
}
fo... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
int m;
int* update(int* tree, int p, int v, bool isor) {
tree[p] = v;
if (p == 0) return tree;
if (p % 2 == 0) {
v = isor ? tree[p - 1] | tree[p] : tree[p - 1] ^ tree[p];
p = p / 2 - 1;
} else {
v = isor ? tree[p] | tree[p + 1] : tree[p] ^ tree[p ... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
int t[1204020];
int sum[1204020];
bool has_p[1204020];
vector<int> good;
void dfs(int v, int p, long long s) {
sum[v] = t[v];
for (int(i) = 0; (i) < (int)(g[v].size()); ++(i))
if (g[v][i] != p) {
dfs(g[v][i], v, s);
sum[v] += sum[... | 3 |
#include <bits/stdc++.h>
using namespace std;
int A[2005];
int main() {
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) {
scanf("%d", &A[i]);
}
sort(A + 1, A + n + 1);
int ans = 0;
if (A[b + 1] > A[b]) {
ans = A[b + 1] - A[b];
}
printf("%d\n", ans);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 2;
const long long mod = 1000000007;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
vector<long long> cnt(200);
long long n;
cin >> n;
set<long long> st;
vector<long long> age(100);
for (int i = 0; i < n; i++) st.insert(i... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int N = 1e9 + 7;
int sum[52][52], mat[52][52], dp[52][52][52][52];
int n;
int black(int x1, int y1, int x2, int y2) {
return sum[x2][y2] + sum[x1 - 1][y1 - 1] - sum[x2][y1 - 1] - sum[x1 - 1][y2];
}
int func(int x1, int y1, int x2, int y2) {
if (black(x1, y1, x... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const long long int INFLL = 1e18 + 10;
const long double EPS = 1e-8;
const long double EPSLD = 1e-14;
const long long int MOD = 1000000007;
template <class T>
T &chmin(T &a, const T &b) {
return a = min(a, b);
}
template <class T>
T &chmax(T &a, ... | 5 |
#include <bits/stdc++.h>
using namespace std;
void Solve() {
string s;
cin >> s;
int cnt = 0;
for (auto i : s) {
cnt += (i == 'N');
}
cout << (cnt == 1 ? "NO" : "YES") << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
cin >> t;
while (t--) Solve();
}
| 1 |
#include <bits/stdc++.h>
const long long OO = LLONG_MAX;
const long long _OO = LLONG_MIN;
const long long MOD = 1e9 + 7;
const double PI = acos(-1);
const double EPSILON = std::numeric_limits<double>::epsilon();
bool double_comp(double a, double b) { return fabs(a - b) < EPSILON; }
using namespace std;
int main() {
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int M = 301;
const int N = 400010;
const int MOD = 1e9 + 7;
int n, q;
char cmd[69];
vector<long long> pr;
long long a[N], mask[M], mul[M];
long long prod[4 * N], orz[4 * N];
long long lzProd[4 * N], lzOrz[4 * N];
long long bigMod(long long a, long long e) {
if (e ==... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int to, next, w;
edge(int _to = 0, int _next = 0, int _w = 0) : to(_to), next(_next), w(_w) {}
} e[300010 << 1];
int n, m;
int g[300010], nume = 0;
int d[300010];
int f[300010][2];
vector<int> ans;
namespace LCT {
int f[300010];
void init() {
for (int i ... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool isPowerOfTwo(int x) { return x && (!(x & (x - 1))); }
int takemod(int x) { return (x % 1000000007 + 1000000007) % 1000000007; }
int fpow(int base, int power, int MOD) {
int result = 1;
base = base % MOD;
while (power) {
if (power & 1) result = (result * base)... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int MAXN = 505;
const int MOD = 1000000007;
int n, m;
char a[MAXN][MAXN];
int id[MAXN][MAXN];
int dp1[MAXN][MAXN];
int dp2[MAXN][MAXN];
int size[2 * MAXN];
pair<int, int> cell[2 * MAXN][MAXN];
void add(int &x, int v) { x = (x + v) % MOD; ... | 5 |
#include <bits/stdc++.h>
using namespace std;
map<pair<int, long long>, long long> dp;
long long nums[512];
long long costs[512];
int n;
long long gcd(long long a, long long b) { return a ? (gcd(b % a, a)) : b; }
long long calcdp(int i, long long d) {
if (dp.count(make_pair(i, d))) return dp[make_pair(i, d)];
dp[ma... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long a[n + 1];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
int maxcnt = INT_MIN, cnt = 1;
for (int i = 0; i < n - 1; i++) {
if (a[i] == a[i + 1]) {
cnt++;
} else {
if (maxcnt < cnt) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
int n;
double e[100005];
vector<int> g[100005];
void dfs(int u, int p = 0) {
int child = 0;
for (int v : g[u])
if (v - p) child++;
if (child > 0) {
e[u] = 1.0;
} else {
e[u] = 0.0;
}
for (int v : g[... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, q, n, a;
int mn = 1e9;
cin >> m;
for (int i = 0; i < m; i++) cin >> q, mn = min(q, mn);
cin >> n;
int s = 0;
vector<int> v(n);
for (int j = 0; j < n; j++) cin >> v[j];
sort(v.rbegin(), v.rend());
int t = 0;
for (int i = 0; i < v.siz... | 3 |
#include <iostream>
using namespace std;
long long n, m, x;
int main(){
int t;
cin >> t;
while(t--){
cin >> n >> m >> x;
long long yy = x / n;
yy -= (x % n == 0? 1:0);
long long xx = x % n;
xx = (xx == 0? n - 1:xx - 1);
long long res = (xx * m + yy);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
map<string, string> par;
map<string, bool> seen;
string ans[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int m = 0;
for (int i = 0; i < n; i++) {
string from, to;
cin >> from >> to;
seen[to] = true;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
signed main() {
long long n, k;
cin >> n >> k;
string ans;
long long cnt = 0;
char ch = 'a';
for (long long i = 0; i < n; i++) {
ans.push_back(ch + (i % k));
}
cout << ans << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int n, sum, i, j;
int a[200010];
priority_queue<pair<int, int> > q;
vector<pair<int, int> > ans;
int main() {
scanf("%d%d", &n, &sum);
if (sum % 2 == 1) {
printf("No\n");
return 0;
}
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i]) q.push(mak... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
char m[maxn][maxn];
int main() {
int a, b, c, d;
for (int i = 0; i < maxn; i++) {
fill(m[i], m[i] + maxn, 0);
}
int idx = 0;
scanf("%d %d %d %d", &a, &b, &c, &d);
printf("50 50\n");
if (a != 1) {
while (a > 1) {
for (int i = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long fpow(int a, int n) {
long long tmp = a, ans = 1;
while (n) {
if (n & 1) ans = ans * tmp % 1000000007;
tmp = tmp * tmp % 1000000007, n >>= 1;
}
return ans;
}
char s[2];
int n, m, c[6][6], t[6][1000000 + 5], lazy[1000000 + 5], sum[6][1000000 + 5],
... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void __read(T& a) {
cin >> a;
}
template <typename T, typename... Args>
void __read(T& a, Args&... args) {
cin >> a;
__read(args...);
}
constexpr long long M7 = 1000000007ll;
constexpr long long M9 = 1000000009ll;
constexpr long long MFFT = 99824... | 1 |
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<int,int> P;
typedef pair<P,P> P2;
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
int d[1<<5][50][50][6],INF=1<<28,n,m,l;
bool check(int x, int y) {return x>=0&&x<n&&y>=0&&y<m;}
int main() {
cin >> n >> m >> l;
string s[n];
for(i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
long long int n, a, b;
cin >> n >> a >> b;
if (n % a == 0)
cout << "YES" << endl << n / a << " " << 0;
else if (n % b == 0)
cout << "YES" << endl << 0 << " " << n / b;
else {
if (n % (a + b) == 0)
cout << "YES" << endl << n / (a ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
vector<long long> v(n, 0);
long long a = 0, b = 0;
map<int, int> m;
for (long long i = 0; i < n; i++) {
cin >> v[i];
m[log10(v[i]) + 1]++;
}
for (lon... | 4 |
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pi M_PI
#define inf 1<<30
#define MAX 100010
#define eps (1e-6)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
class Point{
public:
double x,y;
Point(double x=0,double y=0):x(x),y(y){}
Point operator+(Point p){ r... | 0 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
long long TESTS = 1;
while (TESTS--) {
long long n, m;
cin >> n >> m;
long long p = n / m, sum = 0;
for (long long i = 1; i < m + 1; i++) {
for (long long j = 1; j < m + 1; j++)
if ((i * i... | 2 |
#include<bits/stdc++.h>
using namespace std;
long long mp[305][305],n,m,l;
void floyd(){
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
mp[i][j]=min(mp[i][j],mp[i][k]+mp[k][j]);
}
}
}
}
int main(){
cin>>n>>m>>l;
memset(mp,0x3f... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int result = 0;
int k;
while (n >= 2) {
k = (int)((-1.0 + sqrt(1 + (double)24 * n)) / 6.0);
n -= (k * (3 * k + 1)) / 2;
result++;
}
cout << result << endl;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const double pi = 2 * acos(0.0);
const int md = 30000001;
vector<int> g[300005];
int h[100005];
int q[300005], D[300005], Dist[300005];
bool z[300005];
int main() {
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= k; ++i) cin >> h[i];
... | 5 |
#include <bits/stdc++.h>
int a[310], b[310];
int car[30010], r[30010], c[30010];
int tot;
int n, m;
void movecycle(int value) {
car[tot] = a[value];
if (value < n - 1) {
r[tot] = 2;
c[tot] = value + 2;
}
if (value == n - 1) {
r[tot] = 3;
c[tot] = n;
}
if (value >= n && value < 2 * n - 1) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
string s[1005];
int main() {
int c = 0, m = 0, l, r;
while (getline(cin, s[c])) {
l = s[c].length();
m = max(l, m);
c++;
}
for (int i = 0; i <= m + 1; i++) cout << "*";
cout << endl;
int f = 0, ll;
for (int i = 0; i < c; i++) {
ll = m - s[i].le... | 2 |
#include <queue>
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#include <complex>
typedef double D;
typedef complex<D> P;
typedef pair<P, P> L;
typedef vector<P> VP;
#define X real()
#def... | 0 |
#include <bits/stdc++.h>
int vis[10000], line[10000], head[10000], cnt = 0;
struct Edge {
int to, next;
} edge[10000 * 10];
void addedge(int u, int v) {
edge[cnt].to = v;
edge[cnt].next = head[u];
head[u] = cnt++;
}
int dfs(int u) {
for (int i = head[u]; i != -1; i = edge[i].next) {
int v = edge[i].to;
... | 4 |
#include<bits/stdc++.h>
using namespace std;
vector<pair<int, int>> a[100000];
vector<int> ans(100000);
void dfs(int now, int pre, int col){
ans[now] = col;
for (auto u:a[now]) if (u.first != pre) dfs(u.first, now, col^(u.second&1));
}
int main(){
int i, u, v, w, n;
cin >> n;
for (i=1; i<n; i++){
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long f(long long lvl, long long n, int t) {
if (lvl == 0) return 0;
if (t == 0) {
if (n <= (1LL << (lvl - 1))) return 1 + f(lvl - 1, n, 1);
return (1LL << lvl) + f(lvl - 1, n - (1LL << (lvl - 1)), 0);
}
if (n <= (1LL << (lvl - 1))) return (1LL << lvl) +... | 3 |
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
float c=0.0;
for(int i=0;i<n;i++){
cin>>a[i];
c+=1/float(a[i]);
}
cout<<1/c<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int tx[1010], ty[1010];
int xs[1010], ys[1010];
bool field[2020][2020];
bool ng[2020][2020];
queue<pair<int, int> > que;
int main() {
int N;
scanf("%d", &N);
int cx = 0, cy = 0;
tx[0] = 0, ty[0] = 0;
for (int i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> s2;
long long int i;
bool flag = true;
for (i = 0; i < s1.length(); ++i) {
if ((s2[i] - s1[i]) > 0) {
cout << -1 << endl;
flag = false;
break;
}
}
if (flag == true) {
cout << s2 << endl;
... | 2 |
#include<iostream>
using namespace std;
int main(){
string s,s1,s2;
cin>>s>>s1>>s2;
cout<<s[0]<<s1[0]<<s2[0]<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<string> v;
int main() {
string x, y;
int cnt = 0;
char temp;
int n;
cin >> n;
n = n + n - 1;
for (int i = 0; i < n; i++) {
cin >> x;
if (x == "**") continue;
cin >> y;
x += y;
sort(v.begin(), v.end());
if (binary_search(v.begin()... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int N, M;
vector<int> g[maxn];
long long out[maxn], in[maxn];
int main() {
cin >> N >> M;
for (int i = 1; i <= N; ++i) {
g[i].clear();
out[i] = in[i] = 0;
}
for (int i = 1; i <= M; ++i) {
int a, b;
cin >> a >> b;
int x ... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long int, pair<long long int, long long int> > a,
pair<long long int, pair<long long int, long long int> > b) {
if (a.first < b.first)
return true;
else if (a.first == b.first && a.second.first > b.second.first)
return true;
return ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[3] = {2, 5, 8};
long long n, k, ans = 0;
cin >> n >> k;
for (int i = 0; i < 3; i++) ans += (n * a[i]) / k + ((n * a[i]) % k != 0);
cout << ans << endl;
}
| 1 |
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include ... | 0 |
#include<bits/stdc++.h>
using namespace std;
int a;
int main(){
cin>>a;
cout<<(a+a*a+a*a*a);
return 0;
} | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.