solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 505;
int graph[MAXN][MAXN];
int n, m;
int deg[MAXN];
int label[MAXN];
void dfs(int u, int &counts) {
label[u] = 2;
counts++;
for (int v = 1; v <= n; v++) {
if (label[v] == 0 && graph[u][v] == 1) {
dfs(v, counts);
}
}
}
int main() {
i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
int l1, r1, l2, r2, out1, out2;
scanf("%d", &q);
for (int i = 0; i < q; i++) {
scanf("%d %d %d %d", &l1, &r1, &l2, &r2);
out1 = r1;
out2 = r2;
while (out2 == out1) {
out2--;
}
printf("%d %d\n", out1, out2);
}
ret... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[2200][2200], b[2200][2200], v[2200][2200];
vector<pair<int, int> > p;
inline double max(double x, double y) { return x > y ? x : y; }
void clear_noise(int n) {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
int black_pixel = 0;
for (int ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 3e5;
long long int n, x, y, pa[N], t = 0, b[N], ja = 0, m[N];
queue<long long int> q1, q2;
string s;
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> s;
n = s.size();
for (int i = 1; i <= n; i++) {
x = s[i - 1] - ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, M, ans, D;
vector<string> a;
string x;
bool mark[100];
int main() {
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> x;
a.push_back(x);
}
for (int i = 0; i < m; ++i) {
M = 0;
for (int j = 0; j < n; ++j) a[j][i] >= M ? M = a[j][i] : D;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LLMAX = 9223372036854775807ll;
const int maxn = 5100;
long long a[maxn], b[maxn];
long long dp[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%I64d", &a[i]);
b[i] = a[i];
}
sort... | 14 |
#include <bits/stdc++.h>
using namespace std;
int ocr[10000000 + 7];
int main() {
int n, ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int a;
scanf("%d", &a);
ocr[a]++;
}
for (int i = 0; i < 2 * 1000000; i++) {
if (ocr[i] == 0) continue;
ocr[i + 1] += ocr[i] / 2;
ocr[i] %= 2;
an... | 7 |
#include <bits/stdc++.h>
int main() {
long long f[10];
long long a, b, n;
while (~scanf("%lld %lld", &a, &b)) {
scanf("%lld", &n);
f[1] = a;
f[2] = b;
f[3] = b - a;
f[4] = -a;
f[5] = -b;
f[0] = a - b;
while (f[n % 6] < 0) {
f[n % 6] += 1000000007;
}
while (f[n % 6] > ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
string input;
cin >> input;
regex reg(".*(h).*(e).*(l).*(l).*(o).*");
regex_match(input, reg) ? cout << "YES" : cout << "NO";
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int n, U[500005], S[500005];
vector<pair<int, int>> V;
map<int, int> M;
int find(int x) {
if (x == U[x])
return x;
else
return U[x] = find(U[x]);
}
void Union(int x, int y) {
int X = find(x);
int Y = find(y);
if (X != Y) {
if (S[X] < S[Y]) swap(X, Y);
... | 13 |
#include <bits/stdc++.h>
using namespace std;
char str[200005];
int main() {
scanf("%s", str);
int n, m = strlen(str);
scanf("%d", &n);
vector<int> cum(m + 1);
for (int i = 0, t; i < n; i++) {
scanf("%d", &t);
--t;
cum[t] += 1;
cum[m - t] += -1;
}
for (int i = 1; i < m; i++) cum[i] += cum[... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int i, j, l;
long long int ans = 0;
for (i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
if (i == 2) {
ans = n / i;
} else {
ans = (n - i) / 2;
ans++;
}
cout << ans... | 4 |
#include <bits/stdc++.h>
using namespace std;
int t[1000005], n, x;
inline int read() {
int x = 0;
char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x;
}
int main() {
long long ans = 0;
int i;
n = read();
for (i = 1; ... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &t) {
t = 0;
char ch = getchar();
int f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
do {
(t *= 10) += ch - '0';
ch = getchar();
} while ('0' <= ch && ch <= '9');
t *= f;
}
tem... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
const double pi = 3.141592653589793238462643383279502884197169399;
int n, q;
double x[N], y[N];
int z[N], a[N];
inline void pushup(int i) {
x[i] = x[(i << 1)] + x[(i << 1 | 1)] * cos(z[(i << 1)] * pi / 180) +
y[(i << 1 | 1)] * sin(z[(i << ... | 17 |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
x = 0;
int p = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') p = -p;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch - '0'), ch = getchar();
x = x * p;
}
int n, k, va... | 17 |
#include <bits/stdc++.h>
constexpr double EPS = 1e-9;
using namespace std;
int tr[100001];
void add(int in) {
while (in <= 100000) {
tr[in]++;
in += in & -in;
}
}
long long get(int in) {
long long res = 0;
while (in) {
res += tr[in];
in -= in & -in;
}
return res;
}
long long count_inversions... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int v[2 * MAXN];
pair<int, int> edges[MAXN];
vector<int> adj[2 * MAXN];
int par[2 * MAXN];
int ori[2 * MAXN];
int id[2 * MAXN];
int bfs(int src) {
par[src] = src;
queue<int> q;
q.push(src);
int ans = src;
while (!q.empty()) {
int u = q... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long k, a, b;
cin >> k >> a >> b;
if (a < 0) {
if (b <= 0) {
a = -a;
b = -b;
swap(a, b);
} else {
cout << ((long long)(abs(a) / k) + (long long)(b / k)) + 1;
return 0;
}
}
if (a == 0) {
cout << (long)... | 8 |
#include <bits/stdc++.h>
using namespace std;
string a, b;
bool check1(long long len) {
for (long long i = len; i < a.size(); i++) {
if (a[i] != a[i - len]) return false;
}
return true;
}
bool check2(long long len) {
for (long long i = len; i < b.size(); i++) {
if (b[i] != b[i - len]) return false;
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
long long m;
cin >> n >> m;
long long a[n + 2], b[m];
map<long long, long long> idx;
for (long long i = 0; i < n; i++) {
cin >> a[i + 1];
idx[a[i + 1]] = i + 1;
}
a[0] = 0;
a[n + 1] = n + 1;
set<long long> second;
fo... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
int result1, result2;
if (f > e) {
int mn = min(b, min(c, d));
result1 = mn * f;
d = d - mn;
int m = min(d, a);
result2 = m * e;
cout << result1 + result2 << endl;
} else... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int l[6];
for (int i = 0; i < 6; i++) {
cin >> l[i];
}
sort(l, l + 6);
if (l[0] == l[3])
cout << (l[4] == l[5] ? "Elephant" : "Bear");
else if (l[2] == l[5])
cout << (l[0] == l[1] ? "Elephant" : "Bear");
else
cout << (l[1] == l[4] ... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
out << '(' << p.first << ", " << p.second << ')';
return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
long long l = v.size();
for (long... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n > 1) {
cout << 25 << endl;
} else if (n == 1) {
cout << 5 << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void prepare() {}
int N;
struct Tree {
long long t[10000];
Tree() { memset((t), (0), sizeof(t)); }
void build(long long *a, int i = 1, int l = 0, int r = N - 1) {
if (i == 1) {
memset((t), (0), sizeof(t));
}
if (l == r)
t[i] = a[l];
else {
... | 11 |
#include <bits/stdc++.h>
void solve() {
std::string cdf = "codeforces";
int count[10] = {};
for (int i = 0; i < 10; ++i) {
count[i] = 1;
}
unsigned long long k;
std::cin >> k;
unsigned long long subs = 1;
int i = 0;
while (subs < k) {
subs /= count[i];
count[i]++;
subs *= count[i];
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int R, C;
cin >> R >> C;
char temp;
int seg = 0;
int l = 0;
for (int i = 0; i < (R - 1) * C; i++) {
cin >> temp;
}
for (int i = 0; i < C; i++) {
cin >> temp;
if (temp == 'B') {
l++;
} else {
if (l != 0) {
seg+... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double esp = 1e-10;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5 + 50;
const double PI = acos(-1);
const int mod = 998244353;
int a[maxn], b[maxn];
int c[maxn], d[maxn];
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, m;
scanf("%d %d", &n, ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
int N;
int adj[MAXN][MAXN];
template <int MAXN>
struct SCC {
int num[MAXN], low[MAXN];
bool curProcessing[MAXN];
stack<int> curVis;
int dfsCnt = 0;
SCC() { fill(begin(num), end(num), -1), fill(begin(low), end(low), -1); }
void tarjans(int ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long a[n], s = 0;
bool f = 0;
for (long long i = 0; i < n; i++) cin >> a[i];
for (long long i = 0; i < n - 1; i++) {
if (a[i + 1] >= a[i]) f = 1;
}
if (f) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const double PI = 3.141592653589793238463;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll i, j, k;
ll t;
cin >> t;
// T test cases
for (i = 0; i < t; ++i) {
//cout << "\... | 3 |
#include <bits/stdc++.h>
using namespace std;
int binomialCoeff(int n, int k) {
int res = 1;
if (k > n - k) k = n - k;
for (int i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<in... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n;
const int MAX = 2;
const long long MOD = 1e9 + 7;
const long long ni = 5e8 + 4;
class Matrix {
public:
long long m[MAX][MAX];
Matrix() { memset(m, 0, sizeof(m)); }
};
Matrix matrixmul(Matrix a, Matrix b) {
int i, j, k;
Matrix c;
for (i = 0; i < MAX; ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int cache[5002][5001][3], n, arr[5001];
int DP(int idx, int k, int s) {
int &ret = cache[idx][k][s];
if (ret != -1) return ret;
if (k == 0 && (idx == n + 1 || s != 2))
return ret = 0;
else if (idx == n + 1)
return ret = inf;
ret = inf;... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, P, K;
cin >> N >> P >> K;
vector<pair<int, int> > orders(N);
for (int i = 0; i < N; i++) cin >> orders[i].first >> orders[i].second;
vector<pair<pair<int, int>, int> > basicOrders;
for (int i = 0; i < N; i++)
basicOrders.push_back(
... | 14 |
#include <bits/stdc++.h>
int n, m, k;
int g[2000][2000];
long long mod;
void read_input() {
memset(g, 0, sizeof(g));
scanf("%d %d", &n, &m);
scanf("%d", &k);
for (int i = 0; i < k; i++) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (n >= m) {
g[a][b] = c;
} else {
g[b][a] = c;
... | 17 |
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<pair<int, char>, string> a, pair<pair<int, char>, string> b) {
if (a.first.first == b.first.first) return a.first.second < b.first.second;
return a.first.first < b.first.first;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NUL... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7, N = 10000020;
char buf[N];
long long a[N], n, k, x;
long long ksm(long long x, long long y) {
if (!y) return 1;
long long z = ksm(x, y / 2);
z *= z;
z %= M;
if (y & 1) z *= x;
return z % M;
}
signed main() {
cin >> n >> k;
long l... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n);
vector<int> c(m);
vector<vector<int>> ci(m);
for (int i = 0; i < n; i++) {
cin >> a[i];
c[a[i] % m]++;
ci[a[i] % m].push_back(i);... | 11 |
#include <bits/stdc++.h>
using namespace std;
int x[2000][2000], n, m, up[2000][2000], down[2000][2000];
int l[2000][2000], r[2000][2000];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
char a;
cin >> a;
x[i][... | 13 |
#include <bits/stdc++.h>
using namespace std;
int x[12];
int main() {
string s[12] = {"C", "C#", "D", "D#", "E", "F",
"F#", "G", "G#", "A", "B", "H"},
a, b, c;
cin >> a >> b >> c;
for (int i = 0; i < 12; i++)
if (a == s[i] || b == s[i] || c == s[i]) x[i] = 1;
for (int i = 0; i... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005];
long long b[100005];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int t;
scanf("%d", &t);
a[i] = t;
b[i] = a[i];
}
for (int i = 1; i < n; i++) a[i] += a[i - 1];
sort(b, b + n);
for (int i = 1; i < n; i++) b[i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, r;
cin >> a >> b >> r;
if (!((a / (2 * r)) && (b / (2 * r))))
cout << "Second" << endl;
else
cout << "First" << endl;
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
double a[N], v[N];
int n;
double check(double x) {
double res = 0;
for (int i = 1; i <= n; i++) {
res = max(res, fabs(a[i] - x) / v[i]);
}
return res;
}
int main() {
srand(time(NULL));
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)200 + 7;
const int INF = (int)1e9 + 7;
string from, to;
int n, k;
int f, s;
int main() {
ios_base::sync_with_stdio(0);
cin >> from >> to >> k;
n = from.size();
f = 1;
for (int i = 1; i <= k; i++) {
if (i & 1)
--f;
else
++f... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long int a, b, c, x, y, z;
cin >> a >> b >> c >> x >> y >> z;
long int a1, b1, c1;
x -= a;
y -= b;
z -= c;
if (x < 0 && y < 0 && z < 0) {
cout << "Yes";
return 0;
}
if (x < 0) {
a1 = fabs(x);
x = 0;
} else {
a1 = 0;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string F, M, s;
cin >> F >> M >> s;
if (F == "rock") {
if (M == "scissors" && s == "scissors") {
cout << "F" << endl;
return 0;
}
}
if (F == "paper") {
if (M == "rock" && s == "rock") {
cout << "F" << endl;
return 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int a[maxn * 2], b[2 * maxn];
struct node {
int c[maxn * 2], n;
void init(int _n) {
n = _n;
for (int i = 0; i <= n; i++) c[i] = 0;
}
void add(int st) {
for (int i = st; i <= n; i += i & -i) c[i]++;
}
int sum(int st) {
in... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<int, int> ma;
long long first = 0;
long long second = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int y;
cin >> y;
ma[y] = i;
}
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int x;
cin >> x;
first += ma[x] ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
cout << max(6LL, n + 1) / 2 * 5 << std::endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int long long n, k, c = 0;
cin >> n >> k;
string s;
cin >> s;
int long long a[26] = {0};
for (int i = 0; i < n; ++i) a[s[i] - 'A']++;
c = a[0];
for (int long long i = 1; i < k; ++i) {
if (c > a[i]) {
c = a[i];
}
}
cout << c *... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, count = 0, s, num = 10, sum = 0, l;
cin >> k;
while (1) {
sum = 0;
num = num + 9;
s = num;
while (1) {
l = s % 10;
sum = sum + l;
s = s / 10;
if (s == 0) {
break;
}
}
if (sum == 10) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
using std::string;
long long power(long long b, long long p) {
if (p == 0) return 1;
long long ans = 1;
while (p > 1) {
if (p % 2 == 0) {
b *= b;
p /= 2;
} else {
ans *= b;
p -= 1;
}
}
ans *= b;
return ans;
}
vector<long long>... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long dp[205][205], n;
int main() {
cin >> n;
vector<pair<long long, long long> > pt(n);
for (long long i = 0; i < n; i++) {
cin >> pt[i].first >> pt[i].second;
}
long long ori = 0;
for (long long i = 0; i < n; i++) {
o... | 17 |
#include <bits/stdc++.h>
using namespace std;
char s[101000];
int b[101000];
int n, m, ans;
int main() {
cin >> n;
scanf("%s", s + 1);
int now = 0;
for (int i = 1; i <= n; i++) {
if (s[now] != s[i]) ans++, now = i;
if (s[i] == s[i - 1]) m++;
}
ans += min(2, m);
cout << ans << endl;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int q;
cin >> q;
vector<pair<string, string>> answer;
set<string> unique;
map<string, string> m;
string first, second;
for (int i = 0; i < q; i++) {
cin >> first >> second;
m[first] = second;
unique.insert(second);
}
for (auto p ... | 3 |
#include <bits/stdc++.h>
#define ll long long
#define sf scanf
#define pf printf
#define nl printf("\n")
#define endl '\n'
#define pb push_back
#define rep(i,a,b) for(int i=a; i<b; i++)
#define repr(i,a,b) for(... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n;
vector<int> Num(n, 0);
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
Num[u]++;
Num[v]++;
}
for (int i = 0; i < n; i++) {
if (Nu... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct st {
int l, r, id;
st(int l, int r, int id) : l(l), r(r), id(id) {}
};
struct tree {
long long sum;
tree *l, *r;
tree() : sum(1e18), l(nullptr), r(nullptr) {}
tree(long long x) : sum(x), l(nullptr), r(nullptr) {}
tree(tree *l, tree *r) : sum(max(l->sum,... | 16 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
int cnt = 0;
int maxi = INT_MIN, j = 0;
for (int i = 0; i < n; i++) {
maxi = max(maxi, a[i]);
if (i - j + 1 >= maxi) {
maxi = I... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
pair<int, int> brac[4];
map<char, int> toInt = {{'<', 0}, {'>', 0}, {'(', 1}, {')', 1},
{'{', 2}, {'}', 2}, {'[', 3}, {']', 3}};
int main() {
char s[1000005];
scanf("%s", s);
int len = strlen(s);
int diff = 0;
st... | 6 |
#include <bits/stdc++.h>
using namespace std;
void mego() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main() {
mego();
long long q, t, c = 0, b = 0, m = 0, n, a;
cin >> n >> m;
vector<int> v;
while (n--) {
cin >> a >> b;
v.push_back(max(min(a, b - a), (long long)0));
c += min(a... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long sum[100100];
int main() {
int n;
while (~scanf("%d", &n)) {
memset(sum, 0, sizeof(sum));
long long su = 0, l1 = 0, l2 = 0, l3 = 0, x, ans = 0;
for (int i = 1; i <= n; i++) {
scanf("%lld", &x);
sum[i] = sum[i - 1] + x;
}
if (sum[... | 4 |
#include <bits/stdc++.h>
using namespace std;
int m, n, a[1000], b[1000], dp[1000][1000] = {0};
int main() {
scanf("%d", &m);
for (int i = 1; i <= m; i++) scanf("%d", &a[i]);
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
int ans = 0;
for (int i = 1; i <= m; i++) {
int best = 0;
f... | 20 |
#include <bits/stdc++.h>
int main() {
int n, s;
int cur, pre;
scanf("%d %d", &n, &s);
pre = -s - 1;
for (int i = 0; i < n; ++i) {
int h, m;
scanf("%d %d", &h, &m);
cur = h * 60 + m;
if (pre + 1 + 2 * s < cur) {
break;
}
pre = cur;
}
int ans = pre + s + 1;
printf("%d %d\n", ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int ertek(char c) {
if (c == '1')
return 1;
else
return 0;
}
void feladat() {
int n;
string s;
string t;
cin >> n;
cin >> s >> t;
vector<int> lepesek;
int alap = 0;
int kezd = 0;
int veg = n - 1;
int valodi_ertek;
for (int i = n - 1; i >= 0... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
set<int> vis;
int r = 0;
for (int i = 0; i < n; i++) {
char a;
cin >> a;
int t;
cin >> t;
if (a == '+') {
vis.insert(t);
int s = vis.size();
r = max(r, s);
} else {
if (vis.count(t) == 0... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, l, r, x, count = 0;
cin >> n >> l >> r >> x;
int arr[n];
vector<int> v;
for (int i = 0; i < n; i++) cin >> arr[i];
for (int mask = 0; mask < (1 << n); mask++) {
v.clear();
for (int i = 0; i < n; i++) {
if (mask & (1 << i)) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int mat[60][60][60][60];
void init() {
mat[1][0][0][0] = 1;
mat[2][0][0][0] = 1;
mat[2][0][1][0] = 2;
mat[2][0][1][1] = 3;
mat[2][0][0][1] = 4;
mat[2][1][0][1] = 5;
mat[2][1][1][1] = 6;
mat[2][1][1][0] = 7;
mat[2][1][0][0] = 8;
}
void odd(int n) {
int p ... | 19 |
#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, vector<T> t) {
for (int(i) = ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int M = 400005;
const int MOD = 1e9 + 7;
int read() {
int x = 0, f = 1;
char c;
while ((c = getchar()) < '0' || c > '9') {
if (c == '-') f = -1;
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x * ... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int N = 6000 + 7;
int n, m, e[N][2], pos[N], ans[N], sz;
bool vis[N];
vector<int> g[N];
int other(int edge, int v) {
return e[edge][0] ^ e[edge][1] ^ v;
}
void reset() {
sz = 0;
for (int i = 1; i <= m; i++) {
vis[i] = 0;
}
for (int i = 1; i <= n; i++... | 21 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
long long GCD(long long a, long long b) { return b == 0 ? a : GCD(b, a % b); }
const long long inf = 1e18;
const long long mod = 1e9 + 7;
double pi = acos(-1.0);
int a[2400], num[2400];
string str, s;
int main() {
ios::sync_with_stdio(false);
cin... | 3 |
#include <bits/stdc++.h>
using namespace std;
int s[1000005];
int p[1000005];
int main() {
int n, m, dx, dy, i;
scanf("%d%d%d%d", &n, &m, &dx, &dy);
int x = 0, y = 0;
p[0] = 0;
do {
x = (x + dx) % n;
y = (y + dy) % n;
p[x] = y;
} while (x != 0 && y != 0);
memset(s, 0, sizeof(s));
for (i = 0;... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 555;
int n, k;
bool dp[N][N];
int a[N];
bool res[N];
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> k;
for (int i = 0; i < (n); i++) cin >> a[i];
dp[0][0] = true;
for (int i = 0; i < (n); i++) {
for (int sum = (k + 1 - a[i]) - 1; sum ... | 11 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> front, back;
int main() {
int n, f, b, shortag = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> f >> b;
front[f]++;
if (f != b) {
back[b]++;
}
}
int ans = 1000000009, maxf = 0;
int mid = (n + 1) / 2;
for (auto i : front)... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
int N = 22;
int comp(int x) {
int ans = 0;
for (int i = 0; i < N; i++)
if ((x & (1 << i)) == 0) ans |= (1 << i);
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<... | 14 |
#include <bits/stdc++.h>
using namespace std;
string s[8] = {"vaporeon", "jolteon", "flareon", "espeon",
"umbreon", "leafeon", "glaceon", "sylveon"};
int main() {
int n;
string str;
cin >> n;
cin >> str;
for (int i = 0; i < 8; i++) {
if (s[i].size() == str.size()) {
int flag = 1;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename num_t>
inline void addmod(num_t& a, const long long& b, const int& m) {
a = (a + b) % m;
if (a < 0) a += m;
}
template <typename num_t>
inline void update_max(num_t& a, const num_t& b) {
a = max(a, b);
}
template <typename num_t>
inline void update_... | 15 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int N = 2e6 + 10, M = 2e6 + 10, INF = 1e9;
int n, m, S, T;
int h[N], e[M], w[M], ne[M], idx;
int q[N], d[N], cur[N];
int dx[4] = {1, 0, 0, -1}, dy[4] = {0, 1, -1, 0};
int id[210][210];
char str[N];
void add(int a, int b, int c) {
e[idx] = b, ... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[5002];
long long d[10002];
long long suf[10002];
long double sax, lav;
long double ans;
int main() {
cout.setf(ios::fixed);
cout.precision(6);
cin >> n;
sax = n * (n - 1) / 2;
sax = sax * sax * sax;
for (long long i = 1; i <= n; ++i) cin... | 10 |
#include <bits/stdc++.h>
using namespace std;
int fa[100002], last[2000001], f[100002], col[301][301],
dy[5] = {0, 1, -1, 0, 0}, dx[5] = {0, 0, 0, 1, -1}, n, m, q, ans[2000001],
a[2000001], b[2000001], c[2000001];
int find(int x) {
if (fa[x] == x) return x;
return fa[x] = find(fa[x]);
}
int main() {
cin >... | 20 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
long long binpow(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) res = (res * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
return res;
}
long long mod... | 11 |
#include <bits/stdc++.h>
using namespace std;
string s;
int word(string s) {
int l = s.size();
if (l >= 4 && s.substr(l - 4) == "lios") {
return 0;
}
if (l >= 5 && s.substr(l - 5) == "liala") {
return 1;
}
if (l >= 3 && s.substr(l - 3) == "etr") {
return 2;
}
if (l >= 4 && s.substr(l - 4) ==... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int main() {
::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int r, c, n, k;
cin >> r >> c >> n >> k;
v.resize(n);
for (int i = 0; i < n; i++) {
cin >> v[i].first >> v[i].second;
--v[i].first;
--v[i].second;
... | 3 |
#include <bits/stdc++.h>
#pragma GCC target("sse4,avx")
using namespace std;
const int N = 1234567;
const int BLOCK = 350;
struct Line {
long long k, b;
int id;
Line() {}
Line(long long k1, long long k2, int i) : k(k1), b(k2), id(i) {}
};
inline long long eval(Line a, long long q) { return a.k * q + a.b; }
inli... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int tmp;
int tmpa = 0;
int ans = 0;
int tmpans = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> tmp;
if (tmp >= tmpa) {
tmpa = tmp;
tmpans++;
} else {
tmpans = 1;
tmpa = tmp;
}
ans = max(ans, ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int N, K, H, L, i, j, A[300005], ST[300005];
bool B[300005];
pair<int, int> F;
priority_queue<pair<int, int> > PQ;
void hps(int X) {
A[X]--;
if (X == 1) {
return;
}
int i, j, P;
for (i = 2; X % i; i++) {
if (i * i > X) {
i = X - 1;
}
}
P = i;... | 16 |
#include <bits/stdc++.h>
using namespace std;
bool compareContainer(pair<int, int> a, pair<int, int> b) {
if (a.second != b.second)
return (a.second > b.second);
else
return (a.first > b.first);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, result = 0;
cin >> n >>... | 1 |
#include <bits/stdc++.h>
using namespace std;
int Int() {
int x;
scanf("%d", &x);
return x;
}
long long Long() {
long long x;
scanf("%lld", &x);
return x;
}
double Double() {
double x;
scanf("%lf", &x);
return x;
}
const int N = 3 * (int)1e5 + 5;
const long long MOD = (int)1e9 + 7;
int Set(int a, int ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
cin >> n;
int x[n];
map<int, int> front, back;
set<int> id;
for (int i = 0; i < n; i++) {
cin >> a >> b;
id.insert(a);
id.insert(b);
front[a] = b;
back[b] = a;
}
for (int y : id) {
if (!back.count(y)) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int check[N];
int main() {
int n, k, a, b, maxn, minn;
bool f;
while (~scanf("%d%d", &n, &k)) {
memset(check, 0, sizeof(check));
f = true;
for (int i = 1; i <= k; i++) {
scanf("%d%d", &a, &b);
if (f) {
if (a > b) ... | 5 |
/*
-------------- | /
| | /
| | /
| * |/ | | ------ *
| | | | / \
| | |\ | | | |\ |
\ ... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 1E9;
const int LEFT = 0;
const int RIGHT = 1;
const int UP = 2;
const int DOWN = 3;
const int MAX = 262144;
int msk[2 * MAX][4];
int full[2 * MAX][1 << 4];
void Reset() {
memset(msk, 0, sizeof msk);
memset(full, 0, sizeof full);
for (int i = MAX; i < 2 ... | 17 |
#include <bits/stdc++.h>
using namespace std;
set<int> v1, v2;
int used[1000005];
int main() {
cout.sync_with_stdio(0);
cin.tie(0);
int a, b;
cin >> a >> b;
for (int i = 1; a >= 0; i++) a -= i, used[i] = 1, v1.insert(i);
used[abs(a)] = 0;
v1.erase(abs(a));
int last = -1;
for (int i = 1; b >= 0; i++)
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, ans, a[600000], s[600000], b[600000], t[600000];
int main() {
scanf("%d%d", &n, &m);
for (int i = (1); i <= (n); ++i) scanf("%d", &a[i]);
for (int i = (1); i <= (n); ++i) {
b[i] = b[i - 1] + (a[i] == m);
if (a[i] != m) {
if (t[a[i]]) s[i] = s[t... | 12 |
#include <bits/stdc++.h>
const int OO = (int)2e9;
const long long INF = (long long)4e18;
const double EPS = (double)1e-12;
using namespace std;
int n, pos;
int a[1005], b[1005], php[1005], res[1005];
int main() {
for (int i = 0; i <= 1003; i += 1) a[i] = b[i] = php[i] = res[i] = 0;
scanf("%d", &n);
for (int i = 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
int n;
while (t--) {
cin >> n;
int a[2 * n];
for (int i = 0; i < 2 * n; ++i) {
cin >> a[i];
}
vector<int> b;
for (int i = 0; i < 2 * n;... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, f = 0, a[1005], x = 0, y = 0, l = 1, r;
cin >> n;
r = n;
for (int i = 1; i <= n; i++) cin >> a[i];
while (f != n) {
if (a[l] > a[r]) {
if (f % 2 == 0)
x += a[l];
else
y += a[l];
l++;
f++;
} ... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.