solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int main() {
string s;
int k = 0;
while (getline(cin, s)) {
if (s[0] == '+')
mp[s.substr(1)]++;
else if (s[0] == '-')
mp.erase(s.substr(1));
else {
int j = s.size() - s.find(":") - 1;
k += j * mp.size();
}
... | 2 |
#include <bits/stdc++.h>
const int MAXN = 1 << 20;
bool vis[MAXN];
int main() {
int n;
scanf("%d", &n);
std::vector<int> ans;
for (int i = 2; i <= n; i++) {
if (vis[i]) continue;
ans.push_back(1);
for (int j = 2; i * j <= n; j++) {
if (!vis[i * j]) ans.push_back(j);
vis[i * j] = true;
... | 14 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
using namespace std;
long long n, A, cf, cm, m;
vector<pair<long long, long long> > v;
long long pre[100005];
long long suf[100005];
long long s;
long long maxi = 0, posm = -1, mini = 0;
long long solv... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[3] = {0};
int t;
int tmp[21];
for (int i = 1; i <= n; i++) cin >> tmp[i];
for (int i = 1; i <= n; i += 3) {
arr[0] += tmp[i];
}
for (int i = 2; i <= n; i += 3) {
arr[1] += tmp[i];
}
for (int i = 3; i <= n; ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
long long s, x1, x2, t1, t2, p, d;
cin >> s >> x1 >> x2;
cin >> t1 >> t2;
cin >> p >> d;
long long a1, a2;
if (x2 > x1) {
if (d == 1) {
a2 = (x2 - x1) * t2;
if (p > x1) {
a1 = (s - p) + s + (x2);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INFI = 2e9;
int N;
int Row, Col;
int compressed[2020 + 1][2020 + 1] = {
0,
};
bool isVisited[2020 + 1][2020 + 1] = {
false,
};
struct Lines {
pair<int, int> start;
pair<int, int> end;
Lines() {}
};
vector<Lines> lines;
int MAX(int a, int b) { return ... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline int gi() {
int f = 1, sum = 0;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
sum = (sum << 3) + (sum << 1) + ch - '0';
ch = getchar();
}
return f * sum;
}
co... | 12 |
#include <bits/stdc++.h>
using namespace std;
int f[2000005];
void KMP(vector<pair<long long, char> > c) {
f[0] = -1;
int j = -1;
for (int i = 1; i < c.size(); i++) {
while (j != -1 && c[i] != c[j + 1]) j = f[j];
if (c[i] == c[j + 1]) j++;
f[i] = j;
}
}
bool solve() {
int n, m;
scanf("%d %d", &n... | 13 |
#include <bits/stdc++.h>
using namespace std;
void Digvijay() {
long long x1, y1, z1, x2, y2, z2;
cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
long long n = x1 + y1 + z1;
long long ans = 0;
long long v1 = min(z1, y2);
ans += 2 * v1;
if (z1 >= y2) {
z1 -= y2;
y2 = 0;
} else {
z1 = 0;
}
long l... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, b, d;
cin >> n >> b >> d;
int ar[n];
int s = 0, c = 0;
for (int i = 0; i < n; i++) {
cin >> ar[i];
}
for (int i = 0; i < n; i++) {
if (ar[i] <= b) {
s += ar[i];
if (s > d) {
c++;
s = 0;
}
}
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> months = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int MAX = 1e5 + 55;
const int inf = 1e9 + 77;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double eps = 1e-7;
int n;
int dp[7005][2];
int cnt[7005][2];
int k[2];
vector<int> adj[... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long cal(long long a, long long b, long long c, long long n) {
if (n == 0) return 0;
return (b / c) * n + (a / c) * n * (n - 1) / 2 +
cal(c, (a * n + b) % c, a % c, (a % c * n + b % c) / c);
}
long long a, b, p, q;
long long cnt(long long l, long long r, l... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
int w[100100];
int N, L, R, QL, QR;
int main() {
cin >> N >> L >> R >> QL >> QR;
for (int i = (1); i < (N + 1); i++) cin >> w[i];
w[0] = 0;
for (int i = (0); i < (N); i++) w[i + 1] += w[i];
long long res = 1LL <<... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
while (cin >> n >> k) {
int c = 0, s = k;
for (int i = 1; i <= n; i++) {
s += 5 * i;
if (s > 240)
break;
else {
c++;
}
}
cout << c << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3", "sse2", "sse")
#pragma GCC target("avx", "sse4", "sse4.1", "sse4.2", "s... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
float v1, v2, t, d, s = 0;
cin >> v1 >> v2;
cin >> t >> d;
t = t - 2;
s += v1 + v2;
while (t > 0) {
if ((v1 + d - v2) / t <= d)
s += v1 + d, v1 += d;
else
v1 = v2 + d * t, s += v2 + d * t;
t--;
}
cout << s << endl;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, a;
int main() {
cin >> a;
j = 1;
for (i = 1; i <= a; i++) {
j *= 2;
if (i == 13) j -= 100;
}
cout << j;
}
| 11 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long INF = std::numeric_limits<long long>::max();
const int MX = 100001;
const long double PI =
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x = 0, y = 0;
cin >> n;
int *mas = new int[n];
for (int i = 0; i < n; i++) cin >> mas[i];
int max = mas[0], k = 0;
for (int i = 1; i < n; i++) {
if (mas[i] > max) {
max = mas[i];
k = i;
}
}
int rez = max + 1;
for (in... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
vector<pair<int, int>> blocks;
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
blocks.emplace_back(x, 1);
}
vector<vector<int>> all;
while (true) {
bool fnd = f... | 12 |
#include <bits/stdc++.h>
using namespace std;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, 1};
int dy4[] = {1, -1, 1, -1};
int arr[10010];
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int i;
vector<char> v;
v.push_ba... | 0 |
#include <bits/stdc++.h>
using namespace std;
int next_index(int now_index, int ti, int skill[]) {
int i;
for (i = now_index + 1; skill[i] != ti; i++)
;
return i;
}
int main() {
int n, skill[5000], prog = 0, math = 0, pe = 0, teams;
int index[3] = {-1, -1, -1};
scanf("%d", &n);
for (int i = 0; i < n; ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); }
using namespace std;
int t[200005] = {0}, r[200005] = {0}, T, R, top = 0, n, m, a[200005] = {0};
int px[200005] = {0};
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 50;
void solve() {
int a, b;
scanf("%d%d", &a, &b);
int now = 9, cnt = 0;
while (now <= b) {
now *= 10;
now += 9;
cnt++;
}
printf("%lld\n", 1ll * cnt * a);
}
int main() {
int t;
scanf("%d", &t);
while (t--) solve();
}
| 3 |
#include <bits/stdc++.h>
int a[200010], b[200010];
int main() {
int n, s, i, sign, t;
while (scanf("%d", &n) == 1) {
s = 0;
t = 0;
sign = 0;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
s += a[i];
}
for (i = 0; i < n; i++) {
if (s - a[i] == a[i] * (n - 1)) {
b[t++]... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
long long que[maxn], dp[5][maxn], a[maxn], b[maxn], t[maxn], ans = -1e18;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, m, d;
cin >> n >> m >> d;
for (int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> t[i];
for (int ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
int q;
cin >> q;
for (int i = 1; i <= q; i++) {
long long l, r;
cin >> l >> r;
long long st1 = l & 1 ? l : l + 1, ed1 = r & 1 ? r : r - 1;
long long st2 = l & 1 ? l + 1 : l, ed2 = r & 1 ? r - 1 : r;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
map<string, int> go;
int get_id(const string &s) {
auto it = go.find(s);
if (it != go.end()) return it->second;
return go[s] = (int)go.size();
}
void norm(string &s) {
for (char &c : s) c = (char)tolower(c);
}
void norm2(char *str) {
for (int... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, h, i, cont = 0, x;
cin >> n >> h;
for (i = 0; i < n; i++) {
cin >> x;
if (x <= h)
cont++;
else
cont += 2;
}
cout << cont << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int arr[1001], n, s, ans[30][30];
int main() {
cin >> n;
for (int i = 0; i < n * n; i++) {
cin >> s;
arr[s]++;
}
if (n % 2 == 0) {
for (int i = 0; i <= 1000; i++)
if (arr[i] % 4 != 0) {
cout << "NO" << endl;
return 0;
}
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n; cin >> n;
vector<vector<int>> adj(1<<n);
for(int i = 0; i<n*(1<<(n-1)); i++){
int a, b; cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
vector<int> ord;
vector<bool> vis((1<<n), 0);
queue<i... | 19 |
#include <bits/stdc++.h>
int main() {
size_t t;
std::cin >> t;
while (--t != -1) {
size_t l, r;
std::cin >> l >> r;
std::cout << l << " " << (l << 1) << "\n";
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
bool calcW(long long s, long long e) {
if ((e & 1) != 0) return (s & 1) == 0;
if (s > e / 2) return (s & 1) != 0;
if (s > e / 4) return true;
return calcW(s, e / 4);
}
bool calcL(long long s, long long e) {
if (s > e / 2 || s > e - 1) return true;
return calcW(s... | 19 |
#include <bits/stdc++.h>
using namespace std;
int N, m, dis;
int headline[100010];
struct edge {
int nxt;
int b;
} e[2 * 100010];
int tot;
bool mark[100010];
int max1[100010], max2[100010];
int num[100010];
int disup[100010], disdown[100010];
void INIT(void) {
memset(headline, -1, sizeof(headline));
memset(mark... | 12 |
#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > s;
map<int, int> m;
int main() {
int i, n, q, x, y;
char buf[5];
scanf("%d %d", &n, &q);
s.insert(make_pair(0, 1));
s.insert(make_pair(n + 1, 0));
for (i = 0; i < q; i++) {
scanf("%d %d", &x, &y);
scanf("%s", buf);
if (m.count(x)... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed << showpoint;
cout << setprecision(2);
string s;
cin >> s;
vector<int> v(26, 0);
for (int i = 0; i < s.size(); i++) {
v[s[i] - 'a'] += 1;
}
int count = 0;
for (int i = 0; i < 26; ... | 5 |
#include <bits/stdc++.h>
int numero[5005];
int ans[5005];
int main() {
int n;
scanf("%d", &n);
int a[5005];
int i, j;
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (i = 1; i <= n; i++) {
memset(numero, 0, sizeof(numero));
int max1 = 0;
int max2 = a[i];
for (j = i; j <= n; j++) {... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
const ll MOD = 10000000... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int R() {
char c;
int sign = 1, res = 0;
while ((c = getchar()) > '9' || c < '0')
if (c == '-') sign = -1;
res += c - '0';
while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
return res * sign;
}
const int Maxn = 2e5 + 5;
int Next[Max... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long x = 0, F = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') F = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * F;
}
int add(int a, int b) {
r... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long int s, t, c, x, finally;
int main() {
ios_base::sync_with_stdio(false);
cin >> s >> t;
for (int i = 0; i < s; ++i) {
cin >> x;
c += x;
}
if ((c + 10 * (s - 1)) > t)
cout << -1;
else {
finally += (t - (c + 10 * (s - 1))) / 5;
finally... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n_c_r(long long n) { return (n * (n - 1)) / 2; }
long long bin(long long n) {
int cnt = 0;
while (n > 0) {
n /= 2;
cnt++;
}
return cnt;
}
int main() {
ios_base ::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n, i;
cin >... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4;
const int mod = 1e9 + 7;
int n;
string s[N];
map<pair<string, int>, bool> dp;
bool checkhor(int i, int x) {
if (x == 1) return true;
string t = s[i];
if (dp.count({t, x})) return dp[{t, x}];
deque<int> v;
for (int j = int(t.size() - 1); j >= int... | 10 |
#include <bits/stdc++.h>
int not_prime(int x) {
int i, flag = 0;
if (x <= 2) {
flag == 0;
} else {
for (i = 3; i < x; i++) {
if (x % i == 0) {
flag = 1;
}
}
}
if (flag == 1) {
return 1;
} else {
return 0;
}
}
int main() {
int a, b, c, d, e, f, g, h, i, j, x = 0, y... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct abc {
long long int x, y;
};
bool compare(abc a1, abc a2) {
if (a1.x == a2.x) return a1.y < a2.y;
return a1.x < a2.x;
}
const long long int mod = 1e9 + 7;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long in... | 4 |
#include <bits/stdc++.h>
using namespace std;
char c;
int n, i, j, k, mb, rb, bn, t = 0, ato = 0, atb, nm;
struct sd {
int bl, at, u, num;
} a[1010] = {0};
struct ssd {
int ti, num;
} ans[1010] = {0};
bool cmp(sd x, sd y) { return x.at > y.at; }
int rd() {
nm = 0;
c = getchar();
while (c < '0' || '9' < c) c =... | 10 |
#include <bits/stdc++.h>
const long double PI = acos(-1.L);
using namespace std;
pair<int, int> a[1000], aa[1000];
vector<int> l[1000];
vector<bool> m[1000];
inline bool orderBySecond(pair<int, int> a, pair<int, int> b) {
return a.second > b.second;
}
int main() {
int v, e;
scanf("%d%d", &v, &e);
for (int i = 0... | 6 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using ll = long long;
const int N = 22, S = 1 << N;
int a[S], dp[S];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = int(0); i < int(n); i++) {
cin >> a[i];
dp[a[i]] =... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
while (a > 0) {
b %= a;
swap(a, b);
}
return b;
}
int main() {
long long n, m, x, y, a, b;
cin >> n >> m >> x >> y >> a >> b;
long long g = gcd(a, b);
b /= g;
a /= g;
long long yy = (n / a) * b, xx = (yy * ... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long Hashimoto = 0;
bool Kanna = 1;
char I_Love = getchar();
while (I_Love < '0' || I_Love > '9') {
if (I_Love == '-') Kanna = 0;
I_Love = getchar();
}
while (I_Love >= '0' && I_Love <= '9') {
Hashimoto = Hashimoto * 10... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
bool debug = false;
int h, q, v, e;
char s[7];
map<int, double> mp;
double dfs(int i, double ss) {
if (ss >= mp[i]) return ss;
int l = i << 1, r = l + 1;
return 0.5 *
(dfs(l, max(ss, mp[i] - mp[l])) + dfs(r, max(ss, mp[i] - mp[r])));
}
int main()... | 17 |
#include <bits/stdc++.h>
using namespace std;
char str[111111];
int ans[111111] = {0}, f[111111] = {0}, res = 0, resl, resr, len;
int main() {
scanf("%s", str);
len = strlen(str);
for (int i = 0; i <= len; i++) {
if (i == 0 || i - f[i - 1] - 1 < 0) continue;
if (str[i] == ')' && str[i - f[i - 1] - 1] == '... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, a[1001000], f[1001000];
long long ans = 0;
scanf("%d %d", &n, &x);
int i;
memset(f, 0, sizeof(f));
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
ans += f[a[i] ^ x];
f[a[i]]++;
}
printf("%I64d\n", ans);
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
char s[1000005];
int a, b, ls;
int kalana[1000005];
int kalanb[1000005];
char ola[1000005];
char olb[1000005];
int main() {
scanf(" %s %d %d", s + 1, &a, &b);
ls = strlen(s + 1);
for (int i = 1; i <= ls; i++) {
kalana[i] = (kalana[i - 1] * 10 + s[i] - '0') % a;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7, N = 200010;
int x, y, n, fa[N];
bool bo[N];
long long ans, num[N];
int ask(int x) {
if (fa[x] == x) return x;
fa[x] = ask(fa[x]);
return fa[x];
}
void uni(int x, int y) {
if (x == y) return;
int xx = ask(x), yy = ask(y);
if (xx == yy) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long double Pi = 3.141592653;
const long long mod = 1e9 + 9;
vector<long long> primes;
long long modoinv(long long a, long long m) {
long long m0 = m;
long long y = 0, x = 1;
if (m == 1) {
return 0;
}
while (a > 1) {
long long t, q = a / m;
m = a... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
const int M = 1e9 + 7;
const double eps = 1e-6;
const double PI(acos(-1.0));
int n, k;
int a[N];
int c[300];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> k;
memset(c, -1, sizeof c);
for (int i = (1); i <= (n); i++... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, z, a, b, c;
int mat[3][3];
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) cin >> mat[i][j];
}
a = mat[0][1] + mat[0][2];
b = mat[1][0] + mat[1][2];
c = mat[2][0] + mat[2][1];
for (int i = 0; i <= 2; i++) {
for (int... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 257;
struct mat {
int n, m;
long long a[N][N];
mat(int n = 0, int m = 0) : n(n), m(m) { memset(a, 0x3f, sizeof a); }
mat operator*(const mat& b) const {
mat c(n, b.m);
assert(m == b.n);
for (int i = 0; i < n; ++i)
for (int j = 0; j < ... | 21 |
#include <bits/stdc++.h>
using namespace std;
int MAX = 1000000;
int MIN = -1000000;
int INF = 1000000000;
int x4[4] = {0, 1, 0, -1};
int y4[4] = {1, 0, -1, 0};
int x8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int y8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int i, j, k;
int n, m, a[200000], b[200000], sum[200000];
bool visit[200000];... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
queue<pair<int, int> > q[10];
int n, m, p;
char a[1005];
int d[1005][1005], s[10], ans[1005];
bool check(int x, int y) { return x && y && x <= n && y <= m && d[x][y] == -1; }
int main() {
scanf("%d%d%d", &n, &m, &p);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000, INF = 1000 * 1000 * 1000;
const long double eps = 1e-9;
int gcd(int a, int b) {
while (b) b ^= a ^= b ^= a %= b;
return a;
}
int main() {
int x1, x2, y1, y2, r1, r2;
cin >> x1 >> y1 >> r1;
cin >> x2 >> y2 >> r2;
x2 -= x1;
y2 -= y1;
x1 = 0... | 10 |
#include <bits/stdc++.h>
int main() {
int n;
int data[301];
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &data[i]);
for (int i = 1; i <= n; i++) {
if (i != n) {
while (data[i]) {
printf("PRL");
data[i]--;
}
printf("R");
} else {
while (data[i]) {
... | 4 |
#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;
int last = -1;
for (int i = 0; i < a... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int maxq = 5e5 + 10;
vector<int> vect1[1048586];
vector<pair<int*, int> > stek[1048586];
int n, q, p[maxn], sz[maxn], rez[maxq], k;
struct second {
int tip, a, b;
} qq[maxq];
void update1(int x, int l, int r, int ll, int rr, int val) {
i... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
char myMat[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) cin >> myMat[i][j];
long long int counter = 0;
if (n < 3)
cout << 0 << endl;
else {
for (int i = 1; i < n; i++)
for (int j = 1; ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e3 + 5;
const int INF = 1e9;
vector<int> g[MAXN], gr[MAXN];
int dp[MAXN];
bool used[MAXN];
int ans;
int d[MAXN];
int top;
void dfs_dp(int v) {
used[v] = 1;
int sz, to;
dp[v] = 0;
sz = g[v].size();
for (int i = 0; i < sz; i++) {
to = g[v][i];
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, a[400015], b[400015], c[400015], ans[50], cnt;
int main() {
for (int i = 1; i <= 400010; i++) {
int x = 0, y = 0, t = i;
while (t % 2 == 0) t /= 2, x++;
while (t % 5 == 0) t /= 5, y++;
a[i] = a[i - 1] + x, b[i] = b[i - 1] + y, c[i] = min(a[i], b[i])... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 40, P = 1e9 + 7;
inline long long read() {
char c = getchar();
long long x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
retur... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long cnt1, cnt2, x, y;
const long long inf = 2e9;
long long g(long long a, long long b) {
if (b == 0) return a;
return g(b, a % b);
}
long long l(long long a, long long b) { return a * b / g(a, b); }
bool f(long long v) {
long long temp = (v / l(x, y));
temp = ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n;
map<int, int> dp;
pair<int, int> a[307];
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int main() {
while (~scanf("%d", &n)) {
for (int i = 0; i < n; i++) scanf("%d", &a[i].first);
for (int i = 0; i < n; i++) scanf("%d", &a[i].second);
dp.cle... | 11 |
#include <bits/stdc++.h>
using namespace std;
char qq[400000];
pair<int, int> m[400000];
vector<int> co;
int kr[400000], su[400000];
int n, x, y, q, a;
void sum(int i, int k) {
qq[i] = 1;
while (i <= n) {
su[i] += k;
i = i | (i + 1);
}
}
int ot(int i) {
int o = 0;
while (i >= 0) {
o += su[i];
... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.writ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 105 * 105;
class DSet {
public:
vector<long long> parent;
DSet(long long n) : parent(n) {
for (long long i = 0; i < n; i++) parent[i] = i;
}
void join(long long a, long long b) { parent[find(b)] = find(a); }
long long find(long long a) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> g[210000];
int f[210000];
int d[210000];
int color[210000];
int b;
void ddfs(int v, int p) {
d[v] = (p == -1 ? 0 : d[p] + 1);
f[v] = p;
if (d[v] > d[b]) b = v;
for (int x : g[v])
if (x != p) ddfs(x, v);
}
int cdfs(int v, int p, int c, int d... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
long long a[n + 1][n + 1];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) cin >> a[i + 1][j + 1];
vector<long long> leftsum(2 * n + 1, 0), rightsum(2 * n + 1, 0);
for (int i = 1; i <= n; i++) ... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long p[20];
long long ff(long long x) {
if (x <= 9) return x;
long long S = 9;
for (int i = 1; i < 18; i++)
for (int j = 1; j <= 9; j++)
if (x / p[i] > j)
S += p[i - 1];
else if (x / p[i] == j) {
S += x % p[i] / 10;
if (x %... | 7 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
long long ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1) ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <cla... | 13 |
#include <iostream>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <algorithm>
#include <stack>
#include <math.h>
#include <set>
#include <map>
typedef long long ll;
typedef long double ld;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define INF INT_MAX
#def... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[2100];
int main() {
int d, n;
scanf("%d", &d);
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int t = 0;
for (int i = 1; i < n; i++) {
t += d - a[i];
}
printf("%d\n", t);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int c[202000];
map<int, int> mp1, mp2, num;
int main() {
int n, a, b;
queue<int> qu;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &a, &b);
c[i] = a;
c[i + n] = b;
if (mp1[a] == 0) {
mp1[a] = b;
} else
mp2[a] = b;
i... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int count = 2;
if (n == 1) {
cout << 1;
return 0;
}
if (n == 2) {
cout << 2;
return 0;
}
int s = 1;
int big = 2;
int temp;
while (s + big < n) {
temp = big;
big += s + 1;
s += temp;
count++;... | 5 |
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long exp(long long x, long long y) {
x %= 1000000007;
long long res = 1;
while (y) {
if (y & 1) res = res * x % 1000000007;
x = x * x % 1000000007;
y >>= 1;
}
return res;
}
lo... | 12 |
#include <bits/stdc++.h>
using namespace std;
string s;
int sum = 0;
vector<int> val[3];
int main() {
ios::sync_with_stdio(false);
cin >> s;
int n = (int)s.size();
for (int i = n - 1; i >= 0; i--) {
sum += (s[i] - '0') % 3;
val[(s[i] - '0') % 3].push_back(i);
}
sum %= 3;
if (sum == 0)
cout << ... | 12 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
const long double PI = 3.141592653589793;
const long long INF = 9223372036854775807ll;
const long long mod = 1e9 + 7;
const int N = 2e5 + 2;
vector<int> vis(N, 0);
vector<pair<int, int>> adj[N];
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, m, arr[N], tmp[N];
int d[N], t[N], s = 0;
pair<int, int> arr2[N];
set<int> st;
set<int>::iterator it;
bool check(int mid) {
int one = s * 2 - mid;
if (one > mid) return false;
for (int i = 0; i < n; i++) tmp[i] = arr[i];
st.clear();
in... | 12 |
#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
using namespace std;
int n, a[2010], pre[2010], suf[2010];
int dp[2010][2010][2];
int dpp[2010][2010][2];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
dp[i][j][0] = 0;
dp[i][j][1] = 0;
dpp[i][j][0... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct exam {
int a, b;
} p[6000];
bool cmp(exam a, exam b) {
if (a.a == b.a) return a.b < b.b;
return a.a < b.a;
}
int main() {
int n, now;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &p[i].a, &p[i].b);
}
sort(p + 1, p + n + 1, cmp);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e4 + 33;
const double eps = 0.00000000001;
struct point {
double x, y, z;
point() {}
point(double x, double y, double z) : x(x), y(y), z(z) {}
};
double dis(point a, point b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) +
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
for (auto i = 1; i < s.size() - 1; i++) {
if (s[i - 1] + s[i] + s[i + 1] == 198 && s[i - 1] != s[i + 1]) {
cout << "YES";
return 0;
}
}
cout << "NO";
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for(auto i=(l);i<=(r);++i)
inline int ask(int l1, int r1, int l2, int r2) {
printf("? %d %d\n", r1 - l1 + 1, r2 - l2 + 1);
rep(i, l1, r1)printf("%d ", i);
puts("");
rep(i, l2, r2)printf("%d ", i);
puts("");
fflush(stdout);
... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long n, q;
long long a[300005], dp_child[300005], dp_par[300005];
long long now, tin[300005], tout[300005], up[300005][19], val[300005][19],
val2[300005][19];
vector<pair<long long, long long> > g[300005];
map<pair<long long, long long>, long long> mp;
void get_chi... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
string s;
cin >> s;
int q = s.find("aa");
int w = s.find("bb");
int e = s.find("cc");
if (q >= 0 || w >= 0 || e >= 0) {
cout << "-1" << endl;
} else {
for (int i = 0; i < (s.size()); i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
int n;
int k;
cin >> q;
while (q--) {
cin >> n;
k = ceil(log(n) / log(3));
int a[k + 1];
for (int i = k; i >= 0; i--) {
if (n > pow(3, i)) {
n -= pow(3, i);
a[i] = 1;
} else {
a[i] = 0;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
bool tag[26];
string s[31];
struct node {
char a, b;
} num[26 * 26 + 5];
bool cmp(struct node x, struct node y) {
if (x.a == y.a) return x.b < y.b;
return x.a < y.a;
}
void solve() {
for (int i = 0; i < 26; i++) {
for (int j = 0; j < 26; j++) {
num[... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
string ans;
inline bool is_vowel(char x) {
return (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u' || x == 'y');
}
void solve(int index, char last) {
if (index == n) {
return;
}
if (is_vowel(last) && is_vowel(s[index])) {
solve(inde... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[380];
int main() {
int n, k, m, ans = 0, i;
scanf("%d%d%d", &n, &k, &m);
for (i = 1; i <= m; i++) {
scanf("%d", &a[i]);
ans = ans + 1 + (a[i] - a[i - 1] - 1) / k;
}
ans = ans + (n - a[m]) / k;
printf("%d", ans);
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
class DebugStream {
} LOG;
template <typename T>
DebugStream &operator<<(DebugStream &s, const T &) {
return s;
}
const int MAX = 100100;
int a[MAX], b[MAX];
int main() {
int T;
scanf("%d", &T);
for (int t = 0; t < int(T); t++) {
int n, k;
scanf("%d %d", &n,... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int maxn = 4e5 + 10;
const int Inf = 0x3f3f3f3f;
inline int rd() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') {
f = -1;
}
ch = getchar();
}
while (ch >= '0' && ch <=... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 200200;
long long inf = 0;
long long n, m, k;
long long a[maxn], b[maxn], w[maxn];
long long c[maxn];
long long I[maxn];
long long d[808][808];
long long wk;
vector<long long> x, y;
void add_v(long long v) {
if (~I[v]) return;
I[v] = x.size();
x... | 14 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.