solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const int OFF = (1 << 20);
int n;
long long a[200005];
long long dp[200005];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
dp[n - 1] = a[n];
for (int i = n - 2; i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, x;
cin >> n >> x;
long long int l[100], r[100];
for (long long int j = 0; j < n; j++) {
cin >> l[j] >> r[j];
}
long long int ans = 0;
ans = (l[0] - 1) % x;
ans = ans + r[0] - l[0] + 1;
long long int v = r[0] + 1;
for (lo... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
unsigned int A, B, C, D, ans, num;
bitset<100000010> check;
unsigned int cal(unsigned int x) {
return A * x * x * x + B * x * x + C * x + D;
}
int main() {
scanf("%d%u%u%u%u", &n, &A, &B, &C, &D);
num = cal(2);
for (int i = 2; i <= n; i *= 2) ans += n / i * n... | 6 |
#include <bits/stdc++.h>
using namespace std;
char s[4200005];
int n, k, i, j, R, L, t, mxn, rt[4200005], c[4200005], pre[4200005], l[5005],
r[5005];
int lowbit(int x) { return x & -x; }
void add(int x, int d) {
for (int i = x; i <= mxn; i += lowbit(i)) c[i] += d;
}
int find(int x, int k) {
int t = x - (lowbit(... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, e, d;
cin >> n >> d >> e;
long long int a = d;
long long int b = 5 * e;
long long int mn = n % a;
for (long long int i = 1; i <= 1000000; i+... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long int n, k;
cin >> n >> k;
k--;
long long int l = 0, r = (1 * 1ll << n) - 1;
long long int ans = n;
while (true) {
long long int m = (l + r) / 2;
if (k == m) {
cout << ans << endl;
... | 2 |
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n,m;
while(cin >> n >> m, n!=0 && m!=0){
int t[n],h[m];
int sumt = 0,sumh = 0,cht = 0,chh = 0,ch = 0;
for(int i=0;i< n; i++){
cin >> t[i];
sumt += t[i];
}
for(int i=0;i<m;i++){
cin >> h[i];
sumh... | 0 |
#include <bits/stdc++.h>
using namespace std;
using Flow = int;
using Cost = long long;
namespace mcf {
struct edge {
int from, to;
Flow capacity;
Cost cost;
edge(int f, int t, Flow cap, Cost cst) {
from = f;
to = t;
capacity = cap;
cost = cst;
}
};
vector<edge> edges;
vector<vector<int>> adj;... | 4 |
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>
#define FR first
#define SE second
#define lowbit(x) (x&-x)
using namespace std;
int sumv[100005];
void add(int x,int num) {
for(;x;x-=lowbit(x)) sumv[x]+=num;
}
int sum(int x,int n) {
int s=0;
for(;x<=n;x+=lowbit(x)) s+=sumv[x];
r... | 0 |
#include <iostream>
#include <string>
#include <utility>
#include <map>
#include <vector>
using namespace std;
int n, m, k;
string o;
vector<pair<string, vector<string> > > mix;
map<string, int> item;
int sum(vector<string> s) {
int p = 0;
for (int i = 0; i < s.size(); i++) {
p += item[s[i]];
}
return p;
}
voi... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, q;
vector<int> v[60];
inline int ch(char c) { return (c - 'a' + 1); }
int dfs(int depth, int s) {
if (depth == n) return s == 1;
int res = 0;
for (int i = 1; i <= 6; ++i) {
int p = s * 6 + i;
if (v[p].size() == 0) continue;
res += dfs(depth + 1, v[p... | 2 |
#include <bits/stdc++.h>
int main(void) {
long long int m, i, l, count[100008] = {0}, e, swap;
char ch[200006];
scanf("%s\n", ch);
l = strlen(ch);
scanf("%I64d\n", &m);
while (m--) {
scanf("%I64d", &e);
count[e]++;
}
long long int s = 0;
for (i = 1; i <= l / 2; i++) {
s += count[i];
co... | 2 |
#include <bits/stdc++.h>
using namespace std;
void printAll(int n, ...) {
if (1) {
va_list ap;
va_start(ap, n);
for (int i = 1; i <= n; i++) cout << va_arg(ap, long long int) << " ";
cout << endl;
va_end(ap);
}
}
template <typename T>
string toString(T n) {
stringstream ss;
ss << n;
string... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, cnt = 0;
cin >> t;
long long n;
for (int i = 1; i <= t; i++) {
cin >> n;
if (n == 1)
cout << 0 << "\n";
else {
while (n != 1) {
if (n % 2 == 0) {
n = n / 2;
cnt++;
} else if (n % 3 == 0)... | 1 |
#include <bits/stdc++.h>
int read() {
char k = getchar();
int x = 0;
while (k < '0' || k > '9') k = getchar();
while (k >= '0' && k <= '9') x = x * 10 + k - '0', k = getchar();
return x;
}
const int MX = 2e5 + 23;
int n, m;
int ORG[MX], CAC[MX], tot = 1;
struct edge {
int node, next, w;
} h[MX * 6];
void ad... | 5 |
#include <bits/stdc++.h>
using namespace std;
char s[10010];
bool vis[1010][1010];
int main() {
scanf("%s", s);
int n = strlen(s);
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
if (!vis[4][4]) {
printf("4 3\n");
vis[4][4] = 1;
} else {
printf("4 1\n");
vis[4][4] ... | 3 |
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef struct{
string s;
int dot;
}data;
int n;
string s;
data d;
vector<data> vec;
int dotcount(string s){
int count = 0;
for(int i = 0;i < s.size();i++){
if(s[i] != '.')break;
count++;
}
return count;
}
void check(int dot,int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
struct node {
int l, r;
int mid() { return (l + r) >> 1; }
int val;
} t[maxn * 4];
int Beg[maxn], End[maxn], n, a[maxn];
int Lis;
int kind[maxn];
void build(int l, int r, int id) {
t[id].val = 0;
t[id].l = l;
t[id].r = r;
if (t[id].l ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 300005;
const long long M = 1005;
const long long mod = 1000000007;
const long long inf = (1 << 30);
const long long linf = (1LL << 61);
long long n, v[M], h, a[M], rez, sum;
int main() {
ios::sync_with_stdio(false);
cin.tie();
cin >> n >> h;
for... | 2 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL <... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int inf = 1e17;
bool cmp(pair<long long int, long long int>& a,
pair<long long int, long long int>& b) {
if (a.first != b.first)
return a.first > b.first;
else
return a.second < b.second;
}
vector<long ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
int n, p[MAXN];
bool vis[MAXN];
vector<int> cyc;
void dfs(int i) {
if (vis[i]) return;
vis[i] = true;
cyc.push_back(i);
dfs(p[i]);
}
bool cmp(const vector<int> &a, const vector<int> &b) {
return ((int)(a).size()) < ((int)(b).size());
}
v... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct node {
long long big, lz;
};
node tree[100010 << 2];
int n, m, w, h;
void pushup(int rt) {
tree[rt].big = max(tree[rt << 1].big, tree[rt << 1 | 1].big);
}
void pushdown(int rt) {
int ls = rt << 1, rs = rt << 1 | 1;
if (tree[rt].lz) {
tree[ls].big = tree[r... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void init_ios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
const int N = 1005;
int n, m, res[2 * N], wyn[2 * N], p[2 * N], bla[2 * N];
char a[N][N];
vector<int> topo, child[2 * N], kto[2 * N];
bool vis[2 * N];
int Find(int x) {
if (x == p... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200 * 1000 + 20;
int n, col[N], b[N], g[N];
vector<int> adj[N];
void dfs(int v, int c) {
col[v] = c;
for (auto u : adj[v])
if (!col[u]) dfs(u, 3 - c);
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
for (int i ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
int t;
cin >> t;
while (t--) {
scanf("%lld %lld", &n, &m);
long long x = n, s = 0;
if (n < m) {
s = (m - x) / 5;
x += s * 5;
if (m - x == 1 || m - x == 2)
s += 1;
else if (m == x)
s = s... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T abs(T x) {
return x > 0 ? x : -x;
}
template <typename T>
T sqr(T x) {
return x * x;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<T> &x) {
s << "[";
for (auto it : x) {
s << it << ", ";
}
s << "]";
return s;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, d, m, a[200005], ans[200005];
set<pair<int, int> > s;
int main() {
cin >> n >> m >> d;
int i;
for (i = 0; i < n; i++) {
cin >> a[i];
s.insert({a[i], i});
}
int day = 0;
while (!s.empty()) {
day++;
int p = s.begin()->second;
ans[p] = da... | 3 |
#include<iostream>
#include<algorithm>
int N;
int count(int n, int b) {
int res = 0;
while(n > 0) {
res += n%b;
n /= b;
}
return res;
}
int main() {
std::cin >> N;
int ans = N;
for(int i = 0; i <= N; i += 9) {
ans = std::min(ans, count(i/9, 9)+count(N-i, 6));
}
std::cout << ans << std::... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[11][111], b[11][111], c[11][111];
char str[111];
struct node {
int n, v;
node(int _n, int _v) { n = _n, v = _v; }
node() {}
friend bool operator<(node a, node b) { return a.v > b.v; }
} p[111];
int main() {
int n, m, cc;
while (~scanf("%d%d%d", &n, &m, &cc... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, a[100003], cnt;
int main() {
cin >> n >> k;
long long d = 1LL << 62;
int id;
for (int i = 1; i <= k; i++) {
long long x;
scanf("%lld", &x);
long long num = n / x;
if (n - num * x < d) {
d = n - num * x;
id = i;
cnt =... | 2 |
#include <bits/stdc++.h>
using namespace std;
int l[200007], r[200007];
int main() {
int n, m;
cin >> n >> m;
if (1LL * m * (m - 1) < n) {
printf("NO");
return 0;
}
printf("YES\n");
for (int i = 1, x = 1; i <= n; i++, x++) {
l[i] = (i - 1) % m + 1;
r[i] = x % m + 1;
if (!(i % m)) x++;
... | 5 |
#include<bits/stdc++.h>
using namespace std;
int main(){
// 0 1 2 3 4 5 6 7 8 9 10 11 12
int days[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
for(int i=2; i<=12; ++i){
days[i] += days[i-1];
}
char day[][20]={
"Thursday",
"Friday",
"Saturday",
"Sunday",
"Monday",
"Tuesday",
"We... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxx = 1000010;
struct node {
int num;
long long val;
bool operator<(const node &X) const {
if (val == X.val) return num > X.num;
return val < X.val;
}
};
struct nod {
int num;
int pos;
int bj;
} s[maxx];
struct no {
int l;
int r;
int s... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, n;
long long check(int l, int r, int m) {
return max(
(((a + (l - 1) * b + a + (r - 1) * b) * (r - l + 1)) / 2 - 1) / m + 1,
a + (r - 1) * b);
}
int main() {
scanf("%lld %lld %lld", &a, &b, &n);
while (n--) {
long long left, t, m;
s... | 3 |
#include <bits/stdc++.h>
using namespace std;
class BinTree : vector<int> {
public:
explicit BinTree(int k = 0) { assign(k + 1, 0); }
int lowbit(int k) { return k & -k; }
int sum(int k) { return k > 0 ? sum(k - lowbit(k)) + (*this)[k] : 0; }
int last() { return size() - 1; }
void add(int k, int w) {
if (... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
const int N = 2e5 + 7;
vector<int> b;
int a[N];
int n, m, h;
int seg[N * 4];
int laz[N * 4];
void spl(int v) {
for (int u = (v * 2); u <= (v * 2 + 1); u++) {
seg[u] += laz[v];
laz[u] += laz[v];
}
laz[v] = 0;
}
void add(int l, int r, int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
void loadData(void);
int proc(void);
void printRes(int);
int a;
int main(int argc, char** argv) {
loadData();
printRes(proc());
return 0;
}
int proc(void) {
long long res = 0;
res += (long long)(a + a + a - 1) * (long long)a / (long long)2;
res += (long long)(a ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int dist[3005][3005];
vector<int> adj[3005];
pair<int, int> path[3005][3005];
set<tuple<int, int, int>> forbid;
int main() {
cin >> n >> m >> k;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);... | 5 |
#include<bits/stdc++.h>
using namespace std;
const int N=25,mo=1e9+7;
struct Matrix{
int a[N][N],n;
Matrix operator * (const Matrix &b)const{
Matrix c;c.n=n;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++){
c.a[i][j]=0;
for(int k=0;k<n;k++)(c.a[i][j]+=1ll*a[i][k]*b.a[k][j]%mo)%=mo;
}
return c;
}
}a;
Ma... | 0 |
#include <bits/stdc++.h>
int main() {
int m, n, k, j, a, c, z, i, count = 0, y = 0;
scanf("%d %d %d", &n, &m, &k);
int x[n];
for (i = 0; i < n; i++) {
scanf("%d", &x[i]);
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
a = x[i];
if (a > x[j]) {
c = x[i];
x[i] = x[j]... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, ans;
string str;
cin >> n;
cin >> str;
ans = 0;
for (int i = (int)str.size() - 1; i >= 0; i--) {
if (str[i] == 'B') {
ans = (ans * 2) + 1;
} else {
ans = ans * 2;
}
}
cout << ans << "\n";
return 0;
}
| 2 |
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k, a[111][111];
cin >> m >> n >> k;
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++) cin >> a[i][j];
if (m <= k) {
int allOne = (1 << m) - 1, f[1024] = {0};
for (int j = 1; j <= n; j++) {
int mask = 0;
for (int... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int casos;
unsigned long long a, b;
scanf("%d", &casos);
unsigned long long ul;
while (casos--) {
scanf("%llu %llu", &a, &b);
bitset<60> bitC(0);
if (a == b) {
cout << a << endl;
continue;
}
if (log2(b) - log2(a) >= 1) ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int vx[300000][4][4] = {}, vy[300000][4][4] = {};
int Index(char c) {
if (c == 'A') return 0;
if (c == 'C') return 1;
if (c == 'G') return 2;
return 3;
}
char NumToChar(int ind) {
if (ind == 0) return 'A';
if (ind == 1) return 'C';
if (ind == 2) return 'G';
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
if (n == 1 || n == 2) puts("-1");
if (n == 3) puts("210");
if (n >= 4) {
string s = "10";
for (int i = 0; i < n - 4; i++) {
s += '0';
}
n -= 4;
if (n % 6 == 0) s += "50";
if (n % 6 == 1) s += "80";... | 2 |
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main() {
//freopen ("input.txt","r", stdin);
//freopen ("output.txt","w", stdout);
cin.tie(0);
cin.sync_with_stdio(false);
int t;
cin >> t;
while (t > 0) {
t--;
long long n, k;
cin >> n >> k;
k--;
int a[n];
for (int i =... | 2 |
#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 5e5 + 10;
bool mark[maxn];
int a[maxn], b[maxn], n;
vector<int> ans;
struct SegmentTree {
int tree[4 * maxn];
void build(int node, int i, int j) {
if (i == j) return (void)(tree[node] = b[i]);
int m = (i + j) >> 1;
build(node << 1, i, m)... | 5 |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
void mysol() {
string s;
cin >> s;
map<char, long long> m;
for (char ch : s) m[ch]++;
if (m['1'] * m['0'] == 0)
cout << s;
else {
for (long long i = 0; i < s.size(); i++) cout << "10";
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[1001] = {0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0};
int n;
int main() {
scanf("%d", &n);
printf("%d\n", a[n]);
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
bitset<100001> c;
bool a = false;
int main() {
int n;
cin >> n;
int x, y;
for (int i = 1; i <= n; i++) {
cin >> x >> y;
if (x == -1) c[i] = 1;
if (x != -1 && !y) {
c[i] = 1;
c[x] = 1;
}
}
for (int i = 1; i <= n; i++) {
if (!c[i]) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
cin >> n;
vector<pair<int, int>> vec(n);
for (int i = 0; i < n; i++) {
cin >> a >> b;
vec[i] = pair<int, int>(a, b);
}
sort(vec.begin(), vec.end());
vector<int> ymx(n, -1);
ymx[0] = vec[0].second;
for (int i = 1; i < n; i+... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
bool sign[1005];
vector<int> a[1005], b[1005];
int vst[1005];
queue<int> q;
bool have = false;
int check1() {
int res = 0;
for (int x = 1; x <= n; x++) {
memset(vst, -1, sizeof(vst));
vst[x] = 0;
q.push(x);
while (!q.empty()) {
int u = q.... | 5 |
#include <bits/stdc++.h>
using namespace std;
void ga(int N, long long* A) {
for (int i(0); i < N; i++) scanf("%lld", A + i);
}
long long N, K, B, C, T[(1 << 18)], V, S, X;
long long df(long long A) { return min((A % 5) * C + (A / 5) * B, A * C); }
long long ev(long long I) {
priority_queue<long long> q;
long lon... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int i = 1, j = n * n, k, l;
for (k = 1; k <= n; k++) {
l = 1;
while (l <= (n / 2)) {
cout << i << " " << j << " ";
i++;
j--;
l++;
}
cout << endl;
}
return 0;
}
| 1 |
#include <cstdio>
#include <algorithm>
using namespace std;
int n,d[110],ans;
int main() {
scanf("%d",&n);
ans=0;
for (int i=1;i<=n;i++) {
scanf("%d",&d[i]);
ans+=d[i];
}
if (ans%10==0) {
sort(d+1,d+(n+1));
bool t=false;
for (int i=1;i<=n;i++)
if (d[i]%10!=0) {
ans-=d[i];
t=true;
break;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
const int32_t SMALL = LONG_MIN >> 1;
const int32_t BIG = LONG_MAX >> 1;
const int32_t MAXN = 500001;
int32_t st[MAXN], en[MAXN];
vector<int32_t> g[MAXN];
int32_t n, cur;
void dfs(int32_t u, int32_t p) {
for (int32_t v : g[u])
if (v != p) st[v] = ... | 5 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
ll mod = 1e9+7;
ll t;
string s;
cin>>t>>s;
ll n = s.size();
ll m=0;
if(n==1 && t<=9){
cout << t << endl;... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool go(const map<long long, int>& all, int x,
multiset<long long, greater<long long>> trash) {
multiset<long long, greater<long long>> ends;
for (const auto& p : all) {
if (p.second < x) {
for (int i = p.second; i < x; ++i) {
ends.insert(p.fir... | 3 |
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define fi(a, b) for(int i=a; i<=b; i++)
#define fj(a, b) for(int j=a; j<=b; j++)
#define fo(a, b) for(int o=a; o<=b; o++)
#define fdi(a, b) for(int i=a; i>=b; i--)
#define fdj(a, b) for(int j=a;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int a[N], b[N];
struct node {
int a, b, c;
};
vector<node> v;
int T[4 * N];
void inti(int n, int b, int e) {
if (b == e) {
T[n] = a[b];
return;
}
inti(n * 2, b, (b + e) / 2);
inti(n * 2 + 1, (b + e) / 2 + 1, e);
T[n] = T[n * 2] &... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, a[1025][1025], vis[1025];
bool flag;
bool ok() {
for (int i = 1; i <= n; i++)
if (a[i][0] != n) return 0;
return 1;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - ... | 0 |
#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
long long n, MOD;
long long w[100005];
long long q, l, r;
long long ph[100005];
long long LL;
long long qpow(long long x, long long y, long long MOD) {
long long ret = 1;
int flag = 0;
while (y) {
if (y & 1) {
ret = ret * x;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
t = 1;
while (t--) solve();
return 0;
}
void solve() {
long long i, j, n, s;
cin >> n >> s;
vector<long long> a(n);
long long small, tot = 0;
for... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, k, t = 240, cnt = 0;
cin >> n >> k;
t -= k;
for (int i = 1; i <= n; i++) {
if (t - (5 * i) >= 0) {
t -= 5 * i;
cnt++;
} else
break;
}
cout << cnt << '\n';
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, n, m, x = 0, t, ans = 0, sum = 0;
string s, a, b;
bool f = 0, flag = 0;
map<string, bool> mm;
cin >> a >> b;
mm[a] = 1;
mm[b] = 1;
cin >> n;
cout << a << " " << b << endl;
for (i = 0; i < n; i++) {
cin >> a >> b;
... | 1 |
#include<cstdio>
using namespace std;
int main()
{
register int n,l,r,x,ans=0;
scanf("%d%d%d",&n,&l,&r);
while(n--)
{
scanf("%d",&x);
if(x<l||x>=r) ans++;
}
printf("%d\n",ans);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N,M;cin>>N>>M;
vector<int> A(N+1,0);
for(int i=0;i<M;i++){
int S,T;cin>>S>>T;
A.at(S)++;
A.at(T)++;
}
for(int i=1;i<=N;i++) cout<<A.at(i)<<endl;
}
| 0 |
#include <iostream>
#include <string>
using namespace std;
int main(void){
int A,B,X;
cin>>A>>B>>X;
if(A<=X&&X<=A+B) cout<<"YES";
else cout<<"NO";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 17, chk = 320;
deque<int> blocks[chk];
int ctr[N / chk][N];
int main() {
std::ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q, c, l, r, k, prev, lidx, ridx, elem, st, en, num;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> num;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int index(char c) {
char x[] = "Bulbasr";
for (int i = 0; i < 7; i++)
if (x[i] == c) return i;
return -1;
}
int a[10];
int main() {
char in[100002];
cin.getline(in, 100001);
int len = strlen(in);
for (int i = 0; i < len; i++) {
if (index(in[i]) != -1) ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, d;
cin >> n >> d;
vector<pair<long long int, long long int>> friends(n);
vector<long long int> prefix(n);
vector<long long int> results;
results.reserve(n);
for (auto&& _friend : friends) cin >> _friend.first >> _friend.second;
... | 2 |
#include<iostream>
using namespace std;
int main() {
int n, y;
cin >> n >> y;
y /= 1000;
for(int i = 0; i <= n;i++){
for(int j =0; j <= n-i; j++){
if(10*i + 5*j + (n-i-j)*1 == y){
cout << i << ' ' << j << ' ' << n-i-j << endl;
return 0;
}
}
}
cout << "-1 -1 -1" << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4010 + 10, mod = 1e9 + 7;
const int base[2] = {713, 739};
vector<string> get(int l, int r) {
vector<string> ans;
if (r < l) return ans;
cout << "? " << l << ' ' << r << endl;
int len = (r - l + 1);
for (int i = 0; i < len * (len + 1) / 2; i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(){
long n;
cin >> n;
vector<long> a(n),b(n);
for(long i=0;i<n;i++) cin >> a[i] >> b[i];
long res=0;
for(long i=n-1;i>=0;i--){
a[i]+=res;
if(a[i]%b[i]) res+=b[i]-(a[i]%b[i]);
}
cout << res << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int F = 4e5 + 5, M = 4e5 + 6, OO = 0x3f3f3f3f, MOD = 1e9 + 7;
int d[11];
int main() {
string a, s;
cin >> a >> s;
for (int i = 0; i < s.size(); i++) d[s[i] - '0']++;
for (int i = 0; i < a.size(); i++)
for (int j = 9; j >= 0; j--)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<multiset<int>> vec(1005), vec1(1005);
vector<set<int>> vec10(1005);
int main() {
int n, m, color, digram;
cin >> n >> m;
map<int, bool> mp;
vector<int> fin;
for (int i = 0; i < n; i++) {
cin >> color >> digram;
vec[digram].insert(color);
}
for (... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long S; cin >> S;
int x2 = 1000000000;
int x3 = (x2 - S % x2) % x2;
int y3 = (S + x3) / x2;
cout << "0 0 1000000000 1 " << x3 << " " << y3 << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
map<char, char> H;
string s;
int flag = 1;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
H['3'] = '3';
H['4'] = '6';
H['5'] = '9';
H['6'] = '4';
H['7'] = '7';
H['8'] = '0';
H['9'] = '5';
H['0'] = '8';
cin >> s;
for (int i = 0;... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using graph = vector<vector<int>>;
using pii = pair<int, int>;
using vpii = vector<pii>;
void solve() {
ll n, s, t;
cin >> n >> s >> t;
cout << n - min(s, t) + 1 << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
... | 1 |
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
long n,m,p,j[65000],i,s;
while(cin>>n,n){
m=1;
for(s=i=0;i<n;i++){cin>>p;s+=p;}
for(i=0;i<n-1;i++){cin>>j[i];s+=j[i];}
sort(j,j+n-1);
for(;;){
if((m+1)*(s-j[m-1])>s*m){s-=j[m-1];m++;}else break;
if(m==n)break;
}
cout<<s*m<<endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main(void) {
scanf("%d", &n);
if (n % 2 == 0)
printf("-1\n");
else {
for (int i = 0; i < n; i++) {
printf("%d ", i);
}
printf("\n");
for (int i = 0; i < n; i++) {
printf("%d ", i);
}
printf("\n");
for (int i = 0; ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
long long t[5005];
for (long long i = 1; i <= n; i++) {
cin >> t[i];
}
long long cnt[5005], ans[5005];
memset(ans, 0, sizeof ans);
for... | 1 |
#include <bits/stdc++.h>
using namespace std;
float m(int x0, int y0, int x, int y) {
float xx = x - x0;
float yy = y - y0;
float d = yy / xx;
return d;
}
int main() {
int n, x0, y0;
cin >> n >> x0 >> y0;
vector<int> a(n, 1);
vector<int> x(n);
vector<int> y(n);
for (int i = 0; i < n; i++) {
cin ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e5 + 7;
const int X = 30 + 7;
string s, t;
int n, m, x;
int best[X][N];
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 ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005], c[100005];
int n;
void Add(int x, long long v) {
for (; x <= n; x += (x & -x)) c[x] += v;
}
long long Sum(int x) {
long long s = 0;
for (; x; x -= (x & -x)) s += c[x];
return s;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d, t;
cin >> n >> d;
int td = 0;
for (int i = 0; i < n; i++) {
cin >> t;
td += t;
}
if (td + (10 * (n - 1)) > d)
cout << -1;
else
cout << (d - td) / 5;
return 0;
}
| 1 |
#include <bits/stdc++.h>
int price_buy[1001], price_sell[1001];
int vol_sell[1001], vol_buy[1001];
int s, b;
int orders, depth;
void init() {
int i;
for (i = 0; i < b; i++) {
price_buy[i] = 0;
vol_buy[i] = 0;
}
for (i = 0; i < s; i++) {
price_sell[i] = 0;
vol_sell[i] = 0;
}
s = b = 0;
}
int ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long MIN;
long long gold[100005];
bool visit[100005];
vector<int> adj[100005];
void dfs(int source) {
MIN = min(MIN, gold[source]);
visit[source] = true;
for (int i = 0; i < adj[source].size(); i++) {
int w = adj[source][i];
if (!visit[w]) {
dfs(w);... | 3 |
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#define pb push_back
#define mk make_pair
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using ... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
template <typename T>
inline void gn(T &first) {
char c, sg = 0;
while (c = getchar(), (c > '9' ||... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[1023];
vector<int> v, q;
int primes[1023];
long long int calc(const vector<int>& v, int k) {
vector<int> kk(k, 0);
kk[0] = 1;
int temp = 0;
for (int elem : v) {
temp += elem;
temp %= k;
kk[temp]++;
}
long long int res = 0;
for (int mod = 0; m... | 2 |
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(lon... | 3 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd;
const long long mod = 1e9 + 7;
const long long max_n = 1e5 + 3;
const long long inf = 2e9 + 3;
void run() {
long long n;
cin >> n;
vector<long long> a(n), b(n);
for (long long i = 0; i < n; ++i) cin >> a[i];
for (long long i = 0; i < n; ++i) cin >> b[... | 3 |
#include <cstdio>
int main(){
int n,t,x,i;
scanf("%d%d%d",&n,&x,&t);
printf("%d\n", ((n/x) + ((n%x)?1:0)) * t);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
int cnt = 0, illegal = 0;
cin >> a >> b;
for (int i = 0; i < a; i++) {
int q;
cin >> q;
cnt = 0;
while (q) {
if (q % 10 == 4 || q % 10 == 7) cnt++;
q /= 10;
}
if (cnt > b) illegal++;
}
cout << a - illega... | 1 |
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)
struct Problem {
void Solve() {
UL V, E, r; cin >> V >> E >> r;
vector<vector<pair<UL, UL>>> G(V);
rep(i, E) {
UL a, b, d; c... | 0 |
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;
struct Node {
int key;
Node *right, *left, *parent;
};
Node *root, *NIL;
Node * treeMinimum(Node *x) {
while ( x->left != NIL ) x = x->left;
return x;
}
Node * find(Node *u, int k) {
while ( u != NIL && k != u->k... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.