solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n, m, q;
cin >> n >> m >> q;
vector<vector<int> > g(n);
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
g[x].push_back(y);
g[y].push_back(x);
}
vector<char> used(n, fal... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
scanf("%d %d", &a, &b);
printf("%s\n", abs(a - b) <= 1 && (a || b) ? "YES" : "NO");
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int cnt[1000010];
int dp[1000010][3][3];
int main(void) {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
cnt[x + 1]++;
}
m += 10;
for (int i = 0; i < m - 2; i++) {
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3;... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<int> numNeighbors(n, 0);
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
numNeighbors[u]++;
numNeighbors[v]++;
}
int total = 0;
for (int i = 0... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
void Open() {}
char ts[100010];
char tt[100010];
int s[100010];
int t[100010];
int sta[100010];
int tail = 0;
int main() {
scanf("%s", ts);
scanf("%s", tt);
int slen = strlen(ts);
int tlen = strlen(tt);
for (int i = 0; i < slen; i++) s[... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 300005;
pair<int, int> seg[4 * MAX];
void update(int l, int r, int fight, int value) {
for (l += MAX, r += MAX; l < r; l >>= 1, r >>= 1) {
if (l & 1) seg[l++] = make_pair(fight, value);
if (r & 1) seg[--r] = make_pair(fight, value);
}
}
int query... | 7 |
#include <bits/stdc++.h>
using namespace std;
int N, Q;
int A[100000];
int S[101][100000];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
for (int i = 0; i < (N); i++) cin >> A[i];
for (int k = 1; k <= 100; k++) {
for (int i = N - 1; i >= 0; i--) {
int t = i + A[i] + k;
if ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, br = 0;
string s;
cin >> n;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '+') {
br++;
} else if (br > 0)
br--;
}
cout << br << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, a[101010];
map<int, int> s;
map<int, int>::iterator it;
bool judge() {
s.clear();
for (int i = 1; i <= n; i++) {
s[a[i]]++;
if (s[a[i]] > 2) return false;
}
int cnt = 0;
for (it = s.begin(); it != s.end(); it++)
if (it->second == 2) ++cnt;
if ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int LIMIT = 2000000000;
int main() {
int n, maxv = 0, a;
cin >> n;
while (n--) cin >> a, maxv = max(maxv, a);
cout << (a ^ maxv) << endl;
return 0;
}
| 10 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 9;
const int N = 1e6 + 10;
int n;
long long ans, a, b;
long long f[N];
vector<long long> p;
map<long long, bool> use;
int type[N];
int s[N];
void getp(long long x) {
while (!(x & 1LL)) x >>= 1LL;
for (long long ... | 15 |
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, a, b, ca = 0, cb = 0;
cin >> n >> k >> a >> b;
string s = "";
while (a > 0 || b > 0) {
bool x = (a > b || cb == k);
if (x && a && ca < k) {
a--;
ca++;
cb = 0;
s += 'G';
} else if (cb < k && b) {
b--;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, sum = 0;
cin >> n >> x;
for (int i = 1; i <= n; i++) {
if (x % i == 0 && (x / i) <= n) {
sum++;
}
}
cout << sum << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target( \
"fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
void _print(long long int t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100010], sum;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
if (n == 1) {
if (a[0])
cout << "NO" << endl;
else
cout << "YES" << endl << a[0] << endl;
return 0;
}
if (n == 2) {
if (a[... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
;
long long int n, k;
cin >> n >> k;
long long int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
long long int pr[n + 1];
pr[0] = 0;
for (int i = 0; i < n; i++) pr[i + 1] = pr[i] + a[i];
long do... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
bool istr = false;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int a;
scanf("%d", &a);
if (a == 1) {
istr = true;
}
}
if (istr) {
printf("-1\n");
} else {
printf("1\n");
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105, H = 10;
int n, m, kk, a[N], b1, b2, ss[N];
char mp[N][N];
int main() {
scanf("%d%d%d", &n, &m, &kk);
for (int i = 1; i <= n; i++) {
scanf("%s", mp[i] + 1);
int s1 = 0, s2 = 0, t1 = 0, t2 = 0;
for (int j = 1; j <= m; j++) {
if (mp[i][... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, m, a, b;
cin >> n >> m >> a >> b;
vector<vector<int> > v(n, vector<int>(m, 0));
int cur = 0;
int pk = 0;
for (int i = 0; i < m; i++) {
int cur = 0... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long ARRMAX = 100001;
const long long INTMAX = LLONG_MAX;
void solve() {
long long n;
cin >> n;
long long ans = 0;
if (n == 1)
ans = 1;
else if (n == 2)
ans = 0;
else if (n % 2 == 1)
ans = 0;
else {
std::vector<long long> v(5, 0);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int modpow(long long int a, long long int n, long long int temp) {
long long int res = 1, y = a;
while (n > 0) {
if (n & 1) res = (res * y) % temp;
y = (y * y) % temp;
n /= 2;
}
return res % temp;
}
vector<long long int> arr[4111];
vector<pair<... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, s, c, cd;
cin >> n >> s >> c;
scanf("\n");
string dir;
getline(cin, dir);
if (dir == "to head")
cd = -1;
else
cd = 1;
string state;
cin >> state;
int sz = state.size();
int cwin = -1;
for (int i = 0; cwin == -1 && i < ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 40;
int v[N], x[N], ct, al[N], col[N], n, lu[N], lv[N];
int read() {
int sum = 0, fg = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') fg = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
sum = sum * 10 + c - '... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int l, d, v1, v2;
cin >> d >> l >> v1 >> v2;
double ans = l - d * 1.0;
ans = ans / (v1 + v2);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(12);
cout << ans << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int a, b;
cin >> a >> b;
int mx = max(a, b);
int top = 7 - mx;
switch (top) {
case 1: {
cout << "1/6\n";
break;
}
case 2: {
cout << "1/3\n";
break;
}
case 3: {
cout << "1/2\n";
break;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int arr[100010];
int main() {
int n, t, m = -1, q;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &t);
if (t > m) {
m = t;
}
arr[t]++;
}
for (int i = 1; i <= m; i++) {
arr[i] += arr[i - 1];
}
scanf("%d", &q);
for (int i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MAXN = 1e4 + 5;
int t, n, a[MAXN];
int dp[MAXN][2005];
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
;
cin >> t;
while (t--) {
cin >> n;
int maxl = 0;
for (int i = 0; i < n; i+... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long a, b;
cin >> a >> b;
vector<long long> ans;
if ((b & 1) && (b % 10 != 1)) {
cout << "NO\n";
return 0;
}
ans.push_back(b);
while (b > a) {
if (b & 1) {
if (b % 10 == 1)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const long long INF = 1e18;
const long long N = 500005;
int t[4 * N];
void update(int v, int l, int r, int pos) {
if (l == r) {
t[v] = 1 - t[v];
return;
}
int m = (l + r) / 2;
if (pos <= m) {
update(2 * v, l, m, pos);
}... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
auto gauss_prefix = [&](long long n) { return n * (n + 1) / 2; };
auto gauss = [&](long long l, long long r) {
return gauss_prefix(r) - gauss_prefix(l - 1);
};
auto biggest = [&](long long n) { return gauss(1... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> teams(n);
map<string, int> index;
string tmp;
for (int i = 0; i < n; i++) {
cin >> tmp;
teams[i] = tmp;
index[tmp] = i;
}
getline(cin, tmp);
vector<int> first(n), second(n), third(n);
int m = n * (... | 6 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:16777216")
template <typename T>
T fac(T a) {
return a ? a * fac(a - 1) : 1;
}
template <typename T>
T power(T a, int p) {
return !p ? 1 : (p & 1 ? a * power(a, p - 1) : power(a * a, p >> 1));
}
template <typename T>
T gcd(T a, T b) {
r... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int main() {
long long n, k, a, sum = 0, arr[105], i, min_, max_, imin, imax, nu, mo, j;
scanf("%lld", &n);
scanf("%lld", &k);
for (i = 0; i < n; i++) {
scanf("%lld", &arr[i]);
;
sum += arr[i];
}
if (sum % n == 0)
nu = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
int t1 =
((a[0] - 48) * 10 + (a[1] - 48)) * 60 + (a[3] - 48) * 10 + (a[4] - 48);
int t2 =
((b[0] - 48) * 10 + (b[1] - 48)) * 60 + (b[3] - 48) * 10 + (b[4] - 48);
int d = t2 - t1;
t1 += d / 2;
int p = t1 / 60... | 2 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5010;
int T, n, tag[maxn], w[maxn];
ll f[maxn], g[maxn], h[maxn], cur[maxn];
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &tag[i]);
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 100005;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
{
long long int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
string a, b, c, d;
cin >> a >> b;
c = a;
d = b;
n = a.length();
fo... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T = int, typename Trtn = T, typename Iter = T*>
Trtn big_integer_mod(Iter begin, Iter end, T mod) {
constexpr int step = 9;
constexpr int step_multiplier = 1000000000;
Trtn value = 0;
while (begin != end) {
int step_mul;
int number = 0;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = INT_MAX, df = 1e5 + 7;
long long i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a[df], b[df],
sta[df], top, c[df];
inline long long read() {
long long x = 0, y = 1;
char ch = getchar();
while (ch > '9' || ch < '0') y = (ch == '-') ? -1... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 1;
const long long mod = 998244353;
int n, a[N], k;
long long dp[N][2 * N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
if (k == 1)
cout << 0 << '\n';
else {
if (... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100321;
int dsuP[N], dsuS[N];
vector<pair<int *, int>> hist;
int dsuRoot(int v) {
while (dsuP[v] != -1) v = dsuP[v];
return v;
}
void dsuMerge(int a, int b) {
a = dsuRoot(a);
b = dsuRoot(b);
if (a == b) return;
if (dsuS[a] >= dsuS[b]) {
hist.em... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int n;
cin >> n;
cin >> s;
string R;
R.assign("", s.size());
int id = n - 1;
bool ok = 0;
int i1 = 0, i2 = n - 1;
for (int i = n - 1; i >= 0; i--) {
if (!ok) {
ok = !ok;
R[i2] = s[i];
i2--;
} else {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 9.2e18;
const int maxn = 2e3 + 70;
const int INF = 2.1e9;
const int maxm = 1e6 + 70;
const int MOD = 1e9 + 7;
const double eps = 1e-7;
const double PI = acos(-1.0);
int n, m, k;
vector<int> G[maxn];
bool leaf[maxn];
void dfs(int u) {
if (G[u].size() ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
int a[n], b[n], aprod, bprod;
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
cin >> b[i];
}
aprod = a[0], bprod = b[0];
for (i = 1; i < n; i++) {
aprod = aprod | a[i];
bprod = bprod | b[i... | 1 |
#include <bits/stdc++.h>
using namespace std;
void online_judge() {}
void go() {
cin.tie(0), ios_base ::sync_with_stdio(0);
long long n;
cin >> n;
vector<long long> l, r;
for (int i = 0; i < n; ++i) {
long long x, y;
cin >> x >> y;
l.push_back(x);
r.push_back(y);
}
long long ans = 0;
sor... | 11 |
#include <bits/stdc++.h>
const int n = 1e5 + 10;
int check(char temp, char str[], int len, int lim);
int max(int a, int b);
int main() {
char str[n];
int len, lim;
scanf("%d %d", &len, &lim);
scanf("%s", str);
printf("%d\n", max(check('a', str, len, lim), check('b', str, len, lim)));
return 0;
}
int check(c... | 7 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1061109567;
const int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
struct node {
char c;
int x, y;
node(char c, int x, int y) : c(c), x(x), y(y) {}
};
int n, m;
vector<no... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000 * 1000 * 1000;
const double Pi = acos(-1.0), eps = 1e-9;
int main() {
long long n, h;
cin >> n >> h;
vector<long long> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
if (n == 2) {
cout << 0 << endl;
cout << 1 << ' ' << 1 << endl;
r... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 6000 + 10;
vector<int> adj[maxn];
int vec[maxn][maxn], sz[maxn], pos[maxn];
int r[maxn];
int n, ans;
void insert(int v) {
int lo = -1, hi = maxn;
while (hi - lo > 1) {
int mid = (lo + hi) >> 1;
if (vec[mid][sz[mid] - 1] < r[v])
lo = mid;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long get() {
char c = getchar();
long long x = 0LL;
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') {
x *= 10LL;
x += (c - '0');
c = getchar();
}
return x;
}
string i_t_s(int x) {
string t = "";
while (x) {
t += x ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
int main() {
int t;
scanf("%d", &t);
while (t--) {
int p1, p2, k;
scanf("%d%d%d", &p1, &p2, &k);
if (p1 > p2) swap(p1, p2);
int gnum = gcd(p1, p2);
p1 /= gnum, p2 /= gnum;
if (1ll * (... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, ta;
bitset<2000> bs[2000];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
scanf("%d", &ta);
bs[i][j] = !ta;
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (!bs[j][i]) bs[j] &= ... | 14 |
#include <bits/stdc++.h>
using namespace std;
double C[310][310];
double f[310];
int main() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
C[0][0] = 1;
for (int i = 1; i <= n; i++) {
C[i][0] = 1;
for (int j = 1; j <= n; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
}
f[0] = 1;
for (int i = 0; i < n *... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
long long l[2], r[2], t[2];
cin >> l[0] >> r[0] >> t[0] >> l[1] >> r[1] >> t[1];
if (l[1] > l[0]) {
swap(r[0], r[1]);
swap(l[0], l[1]);
}
long long g = gcd(t[0], t[... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<int, int> m;
map<int, int>::iterator it;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
a = a * 60;
a = a + b;
m[a]++;
}
int ma = 1;
for (it = m.begin(); it != m.end(); it++) {
ma = max(ma, (*... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool upmin(T &x, T y) {
return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool upmax(T &x, T y) {
return x < y ? x = y, 1 : 0;
}
const long double eps = 1e-11;
const long double pi = acos(-1);
const int oo = 1 << 30;
const long lon... | 22 |
#include <bits/stdc++.h>
#pragma hdrstop
using namespace std;
#pragma argsused
int main(int argc, char* argv[]) {
int a;
cin >> a;
if (a == 1) {
cout << 2 << endl;
} else if (a == 2) {
cout << 3 << endl;
} else if (a == 3) {
cout << 1 << endl;
} else if (a == 4) {
cout << 2 << endl;
} else... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long pow_mod(long long nn, long long pp, long long mm) {
long long res = 1;
while (pp > 0) {
if (pp & 1) res = (res * nn) % mm;
pp = pp >> 1;
nn = (nn * nn) % mm;
}
return res;
}
long long _gcd(long long a, long long b) {
if (b == 0) return a;
r... | 0 |
#include <bits/stdc++.h>
using namespace std;
int N, a[200010], s[200010], ans;
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; i++) scanf("%d", &a[i]), s[i] = s[i - 1] + a[i];
ans = s[N];
for (int i = N - 1; i > 1; i--) ans = max(ans, s[i] - ans);
printf("%d\n", ans);
return 0;
}
| 14 |
#include <bits/stdc++.h>
int main() {
char s[1001];
int i, n, len;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%s", &s);
len = strlen(s);
if (len > 10)
printf("%c%d%c\n", s[0], len - 2, s[len - 1]);
else
printf("%s\n", s);
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int x, i, j = 1, l, s = 0;
cin >> x;
while (x > 0) {
if (x % 2 == 0) {
if ((x / 2) % 2 != 0) {
s = s + (x / 2);
x = x / 2;
x--;
} else {
if ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 26, MAX = 100001;
int dist[N][N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s, t;
cin >> s >> t;
int n;
cin >> n;
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
if (i != j) dist[i][j] = MAX;
for (in... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
cout << x << endl;
exit(0);
}
const int maxn = 5050;
const long long mod = 1e9 + 7;
long long dp[maxn][maxn];
string s, t;
int n, m;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> s >> t;
n ... | 9 |
#include <bits/stdc++.h>
int main() {
int n, a, b, c, t;
scanf("%d%d%d%d%d", &n, &a, &b, &c, &t);
int ti[1001];
for (int i = 0; i < n; i++) {
scanf("%d", &ti[i]);
}
int ans = n * a;
if (c >= b) {
for (int i = 0; i < n; i++) ans += (t - ti[i]) * (c - b);
}
printf("%d\n", ans);
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long fastExp(unsigned long long x, unsigned long long y) {
unsigned long long res = 1;
while (y > 0) {
if (y % 2 == 1) res = (res * x);
y = y >> 1;
x = (x * x);
}
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long lo... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string last = "1689";
for (int i = 0; i < last.size(); ++i) {
s.erase(find(s.begin(), s.end(), last[i]));
}
sort(s.begin(), s.end());
reverse(s.begin(), s.end());
int count = 0;
for (int i = 0; i < s.size(); ++i) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n;
char s[1002], t[1002];
cin >> s >> t;
int len = strlen(s);
int len1 = strlen(t);
if (len != len1) {
cout << "No" << endl;
return 0;
}
for (i = 0; i < len; i++) {
if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == '... | 2 |
#include <bits/stdc++.h>
using namespace std;
int m = 0;
inline void find(int k) {
while (k > 0) {
if (k % 10 > m) m = k % 10;
k /= 10;
}
}
inline int toten(int a, int base) {
int ans = 0, k = 1;
while (a) {
ans += (a % 10) * k;
k *= base;
a /= 10;
}
return ans;
}
int main() {
int a, b... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, a[169][10069];
int main() {
long long i, j, u, p[2] = {1, 1}, e = 0, z = 0;
char ch;
scanf("%lld%lld", &n, &m);
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
scanf(" %c", &ch);
a[i][j] = (ch == '+') + 2ll * (ch == '#');
}
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int arr[110][110];
int main() {
int k, n, c, ans = 0, b, l = 0;
cin >> k;
for (int i = 0; i < 102; i++)
for (int j = 0; j < 102; j++) arr[i][j] = 0;
n = 2;
while (k > 0) {
if (k < l) {
l = 0;
n++;
}
arr[n - 1][l] = 1;
arr[l][n - 1] ... | 8 |
#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr ... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &x, T y) {
return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmax(T &x, T y) {
return x < y ? x = y, 1 : 0;
}
const int INF = 0x3f3f3f3f;
const int N = 1e7 + 10;
int phi[N], prime[N], Min[N], sum[N];
int pcnt =... | 19 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
vector<int> dp[1000];
vector<int> quick[1000];
vector<pii> _sort[1000];
string a[1000];
int n, i, j, k;
bool compare(int pl1, int pl2, int s1, int s2) {
int i;
bool pass = true;
bool undecide = true;
bool siz_dif ... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000024;
int c[MAX_N], b[MAX_N], arr[MAX_N], lager[MAX_N];
void add(int x, int v) {
for (; x < MAX_N; x += x & (-x)) c[x] += v;
}
long long getsum(int x) {
long long ans = 0;
for (; x; x -= x & (-x)) ans += c[x];
return ans;
}
int main() {
int n;... | 11 |
#include <bits/stdc++.h>
using namespace std;
int name_score[1001];
int main() {
long double n, s, d;
cin >> n >> s >> d;
vector<long long> vct;
for (int i = 0; i < n; i++) {
long long input;
cin >> input;
vct.push_back(input);
}
long double x, y;
cin >> x >> y;
vector<long double> distances... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 1000 + 10;
int a[MAXN], b[MAXN], plc[MAXN], seg[MAXN * 4];
bool mark[MAXN];
set<int> s;
void add(int plc, int cur, int s, int e) {
if (e - s < 2) {
seg[cur]++;
return;
}
int mid = (s + e) / 2;
if (plc < mid)
add(plc, cur * 2, s, m... | 14 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long p[2][251];
long long v[251][26];
string ss[251];
long long odds[251];
long long ans = 0;
bool cmp(long long i, long long j) {
if ((__builtin_popcountll(odds[i]) > 1) or
(__builtin_popcountll(odds[j]) > 1))
return 0;
for ... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct nodS {
bool fol;
int par[21];
vector<int> v;
};
int n, k, val, i, x, y, d;
nodS nod[1000005];
void dfs(int p, int par) {
nod[p].par[0] = par;
for (int b = 1; b <= 20; b++) {
nod[p].par[b] = nod[nod[p].par[b - 1]].par[b - 1];
if (!nod[p].par[b]) brea... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long int y, long long mod) {
int result = 1;
x = x % mod;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) result = (result * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return result;
}
int main() {
ios_base::sync_... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int i, ans;
vector<int> a(n);
for (i = 0; i < n; i++) cin >> a[i];
if (n < 3) {
cout << 0 << endl;
for (i = 0; i < n; i++) cout << a[i] << ' ';
} else {
sort(a.begin(), a.end())... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline long long mlog(long long x) {
long long res = 0, d = 1;
while (d < x) {
d <<= 1;
++res;
}
return res;
}
int32_t main() {
ios_base ::sync_with_stdio(false);
long long n, I;
cin >> n >> I;
I <<= 3;
vector<long long> a(n);
map<long long, long... | 8 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
bool que(int x, int y) {
char ch;
cout << "? " << x + 1 << ' ' << y + 1 << endl;
cin >> ch;
return ch == '<';
}
int main() {
int ii, tt, i, j, k, m, n, x1, x2, y1, y2;
cin >> tt;
for (ii = 0;... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char n[12], m[12];
cin >> n >> m;
if (n[0] == '0') {
if (strcmp(m, "0") == 0)
cout << "OK";
else
cout << "WRONG_ANSWER";
return 0;
}
if (m[0] == '0') {
cout << "WRONG_ANSWER";
return 0;
}
sort(n, n + strlen(n));
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000 + 10;
const int MAX_M = 3000 + 10;
pair<pair<int, int>, pair<int, int> > e[MAX_M];
int par[MAX_N];
int get_par(int u) { return ~par[u] ? (par[u] = get_par(par[u])) : u; }
void merge(int u, int v) {
u = get_par(u), v = get_par(v);
par[u] = (u == v ... | 12 |
#include <bits/stdc++.h>
using namespace std;
long double TL = 1.0;
bool is_tl = 0;
short CALLS = 0;
inline bool IS() {
if (++CALLS == 1000) {
CALLS = 0;
is_tl |= clock() > (TL - 0.1) * CLOCKS_PER_SEC;
}
return is_tl;
}
template <typename T1, typename T2>
inline void amin(T1 &a, T2 b) {
if (a > b) a = b... | 16 |
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
int powmod(long long a, long long b) {
long long res = 1;
if (a >= mod) a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a;
if (res >= mod) res %= mod;
a = a * a;
if (a >= mod) a %= mod;
}
return res;
}
long long gcd(long lo... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct cmp {
bool operator()(long long a, long long b) { return a > b; }
};
int main(int argc, char const *argv[]) {
priority_queue<long long, vector<long long>, cmp> gg;
long long n;
scanf("%lld", &n);
long long q;
long long sum = 0;
for (register long long i... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 20;
int n, dp[N], x[N], y[N], sumX, sumY, cnt[N];
vector<int> adj[N];
double ans;
void dfs(int v, int par = -1) {
dp[v] = x[v];
cnt[v] = 1;
for (auto u : adj[v])
if (u ^ par) {
dfs(u, v);
dp[v] += dp[u];
cnt[v] += cnt[u... | 17 |
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e) {
cout << "-->" << e << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
cout << "-->" << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
cout << "-->" << e1 << " " << ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
long lon... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
pair<int, int> mas[2 * 100000 + 1];
int main(int argc, const char* argv[]) {
scanf("%d", &n);
for (int i = 0; i < 2 * n; i++) {
scanf("%d", &mas[i].first);
mas[i].second = (i % n) + 1;
}
scanf("%d", &m);
sort(mas, mas + 2 * n);
long long result... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool upmin(T &x, T y) {
return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool upmax(T &x, T y) {
return x < y ? x = y, 1 : 0;
}
const long double eps = 1e-9;
const long double pi = acos(-1);
const int oo = 1 << 30;
const long long... | 20 |
#include <bits/stdc++.h>
using namespace std;
void err() { std::cerr << '\n' << "END OF DEBUG" << '\n' << '\n'; }
template <typename T, typename... Args>
void err(T a, Args... args) {
std::cerr << a << ", ";
err(args...);
}
template <template <typename...> class T, typename t, typename... Args>
void err(T<t> a, Arg... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 5e3 + 5, MOD = 1e9 + 7;
long long n, l, r, mid, ans, sum;
long long col[N], x[N], y[N], dis[N][N];
bool zy;
inline long long pow(long long a, long long n) {
long long res = 1;
while (n) {
if (n & 1) res = res * a % MOD;
a = a * a % MOD;
n... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1E6 + 5;
int n, m, size, head[maxn];
inline int read() {
char ch = getchar();
while (!isdigit(ch)) ch = getchar();
int s = ch - '0';
ch = getchar();
while (isdigit(ch)) {
s = s * 10 + ch - '0';
ch = getchar();
}
return s;
}
struct edge... | 27 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, a, i, b, j, k, t, x, y, z, tc, u, v, w;
set<long long> st[1000000], st2;
set<long long>::iterator itr;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> k;
for (i = 0; i < 1000000; i++) {
st[i % k].insert... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c, d, i, sum, count = 0;
cin >> n >> a >> b >> c >> d;
for (i = 1; i <= n; i++) {
sum = a + b + i;
if ((sum - (a + c) >= 1 && sum - (a + c) <= n) &&
(sum - (b + d) >= 1 && sum - (b + d) <= n) &&
(sum - (c + d) >= 1 && ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c, p = 0;
cin >> n >> a >> b >> c;
for (int i = 0; i * a <= n; ++i) {
for (int j = 0; i * a + j * b <= n; ++j) {
int k = (n - i * a - j * b) / c;
if (i * a + j * b + k * c == n) p = max(i + j + k, p);
}
}
cout << p << ... | 5 |
#include <bits/stdc++.h>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int tc;
std::cin >> tc;
while (tc--) {
int n;
std::cin >> n;
std::vector<int> a(n), fx, fy;
for (auto &v : a) std::cin >> v;
char op;
for (int i = 0; i < n; ++i) {
std::cin >> op;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
double x[100010], y[100010];
int N;
bool check(long double k) {
long double l = -100000000000000000.0, r = 100000000000000000.0, t;
for (int i = 1; i <= N; i++) {
if (y[i] > k * 2) return 0;
t = sqrt(k * k - (k - y[i]) * (k - (y[i])));
if (l < x[i] - t) l = ... | 14 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.