solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int num[300005];
stack<int> stk;
int main() {
int t;
scanf("%d", &t);
for (int i = (1); i <= (t); i++) {
int n;
scanf("%d", &n);
for (int j = (1); j <= (n); j++) {
scanf("%d", &num[j]);
}
while (!stk.empty()) stk.pop();
stk.push(num[1]);
... | 6 |
#include <bits/stdc++.h>
const long double eps = 1e-9;
using namespace std;
template <class T>
inline T MAX(const T &_a, const T &_b) {
return ((_a > _b) ? _a : _b);
}
template <class T>
inline T MIN(const T &_a, const T &_b) {
return ((_a < _b) ? _a : _b);
}
template <class T>
inline T MAX3(const T &_a, const T &_... | 11 |
#include <bits/stdc++.h>
using namespace std;
int matrix[150][150];
int main() {
int n;
cin >> n;
int i;
for (i = 1; n; ++i) {
matrix[0][i] = 1;
matrix[i][0] = 1;
for (int j = 1; j < i; ++j) {
if (n < j) break;
matrix[i][j] = 1;
matrix[j][i] = 1;
n -= j;
}
}
cout << i... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, a, maxi = 0;
map<int, int> mp;
map<int, int>::iterator it;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a);
mp[a]++;
}
for (it = mp.begin(); it != mp.end(); it++) maxi = max(maxi, it->second);
printf("%d %d\n", maxi,... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 2e5 + 5;
map<int, vector<int>> ind;
int ans[N];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
memset(ans, 0, n * sizeof(ans[0]))... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool query(pair<int, int> a, pair<int, int> b) {
printf("? %d %d %d %d\n", a.first + 1, a.second + 1, b.first + 1,
b.second + 1);
fflush(stdout);
bool ans;
scanf("%hhd", &ans);
return ans;
}
bool query(int x1, int y1, int x2, int y2) { return query({x1, y... | 16 |
#include <bits/stdc++.h>
long long fpow(long long x, long long y, long long p = 1000000007) {
x = x % p;
long long sum = 1;
while (y) {
if (y & 1) sum = sum * x;
sum %= p;
y = y >> 1;
x = x * x;
x %= p;
}
return sum;
}
long long fact[1000007] = {0};
void facto() {
fact[0] = 1;
fact[1] ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
int vis[maxn << 1 + 5];
int a[1005];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
int MAX = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
++vis[a[i] + a[j]];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int vis[110000];
int st[110000], top;
int main() {
int n, m, i, j, k, x;
scanf("%d", &n);
if (n & 1) {
puts("-1");
return 0;
}
st[++top] = 0;
x = n / 2;
while (x) {
st[++top] = x;
vis[x] = 1;
if (x + n >> 1 < n && !vis[x + n >> 1])
x ... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b, c;
cin >> a >> b >> c;
int gg = min(a, b);
c += gg;
a -= gg;
b -= gg;
c *= 2;
if (a) c++;
if (b) c++;
cout << c << '\n';
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
bool comp(int a, int b) { return (a < b); }
int main() {
int t;
cin >> t;
for (int i = 1; i <= t; i++) {
int b, p, f;
cin >> b >> p >> f;
int h, c;
cin >> h >> c;
int cost = 0;
if (h > c) {
if (2 * p <= b) {
cost = cost + h * p;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
char a[15][15];
char b[15][15];
char c[15][15];
char d[15][15];
while (cin >> n) {
bool ok1 = false, ok2 = true;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
for (int k = 0; k < 4; k++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long dp[500][500];
long long C[500][500];
long long fact[500];
int n;
long long cnt[500];
int sz = 0;
long long a[500];
int vis[500];
int check(long long x) {
long long st = 1, ed = 1000000000;
while (st < ed) {
long long mid = (st + ed... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n;
vector<long long> f, f1;
long long a[n];
for (long long i = 0; i < n; ++i) cin >> a[i];
sort(a, a + n);
long long cnt = 1;
for (long long i = 1; i < n; ++i) {
if (a[i] == a[i - 1])
cnt++;
else {
f.pu... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2E5 + 77;
const int log2maxn = 20;
const int INF = 1E9 + 77;
struct SEG {
SEG *ch[2];
int v;
SEG() {
ch[0] = ch[1] = NULL;
v = INF;
}
} * segs[maxn];
void segSetVal(SEG *&tr, int L, int R, int qL, int qR, int v) {
if (!tr) tr = new SEG;
... | 19 |
#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
template <class c>
debug& operator<<(const c&... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, zh[30];
double mp[30][30], dp[300000][30], ans = 0;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) scanf("%lf", &mp[i][j]);
zh[0] = 1;
for (int i = 1; i <= 18; i++) zh[i] = zh[i - 1] * 2;
dp[1][1] = 1;
for (int... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
unsigned long long k, l, i = 0, temp;
cin >> k >> l;
temp = k;
for (k; true; k *= temp) {
if (k == l) {
cout << "YES"
<< "\n";
cout << i << "\n";
return 0;
}
if (k > l) break;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m;
int tot, fi[N], a[N << 1], ne[N << 1], c[N << 1];
vector<pair<int, int> > g[N];
struct Node {
int pos, df, *delta;
inline int TruePos() const { return pos + (df >= 0 ? -*delta : *delta); }
inline void Merge(const Node &v) {
assert... | 26 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename S, typename T>
void xmin(S& a, T const& b) {
if (b < a) a = b;
}
template <typename S, typename T>
void xmax(S& a, T const& b) {
if (b > a) a = b;
}
const ll inf = 1e18;
signed main() {
cin.tie(0);
cout.tie(0);
ios_base::sy... | 15 |
#include <bits/stdc++.h>
const long long int M = 1e9 + 7;
using namespace std;
int main() {
long long int a, b, c, d;
scanf("%*d");
while (~scanf("%lld%lld%lld%lld", &a, &b, &c, &d)) {
long long int ans = abs(a - c) + abs(b - d);
if (min(abs(a - c), abs(b - d))) ans += 2;
printf("%lld\n", ans);
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[10050];
void brute(int n) {
for (int i = 0; i < n; ++i) {
a[1 + i * 2] = i + 1;
}
int last = n * 2 - 1;
int emptyPtr = last - 1;
while (emptyPtr > 0) {
a[emptyPtr] = a[last];
a[last] = 0;
--last;
while (a[emptyPtr] != 0) {
--emptyPt... | 9 |
#include <bits/stdc++.h>
int main() {
int v;
scanf("%d", &v);
if (v == 2)
printf("2\n");
else
printf("1\n");
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int modu = (1 << 30);
const int maxn = 1000000 + 5;
long long n, m, x, y;
int vx, vy;
long long exgcd(long long a, long long b, long long &x, long long &y) {
if (b == 0) {
x = 1;
y = 0;
re... | 18 |
#include <bits/stdc++.h>
int main() {
int n, m, i, j, ns = 0, x, y;
scanf("%d %d", &n, &m);
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
scanf(" %d %d", &x, &y);
if (x + y) ns++;
}
}
printf("%d", ns);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000 + 5;
char maze[MAX][MAX];
int ans[MAX][MAX];
bool vis[MAX][MAX];
int f[MAX * MAX];
int num[MAX * MAX];
int n, m;
int nx[4] = {0, 1, 0, -1};
int ny[4] = {1, 0, -1, 0};
int getf(int v) { return v == f[v] ? v : f[v] = getf(f[v]); }
void merge(int u, int v)... | 8 |
#include <bits/stdc++.h>
using namespace std;
char s[100];
int n, m, ans;
int blocks = 0;
int a[1010];
int alloc(int x) {
for (int i = 1; i <= m; i++) {
int j = i;
int num = 0;
while (num != x && j <= m && a[j] == 0) {
num++;
j++;
}
if (num != x) {
i = j;
} else {
block... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long sum[100005], c[100005], l[100005];
int t[100005];
long long f(long long p, long long m) {
long long low = 0, high = m - 1;
while (low < high) {
long long mid = (low + high) / 2;
if (sum[mid] >= p)
high = mid;
else
low = mid + 1;
}
i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 1e5 + 5;
long long fac[1005];
void cal() {
fac[0] = 1;
for (int i = 1; i < 1005; i++) fac[i] = fac[i - 1] * i % mod;
}
long long qpow(long long a, long long b) {
long long ans = 1;
for (; b; b >>= 1, a = a * a % mod)
if ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long o[100010];
long long pw[60];
priority_queue<long long> pq;
vector<long long> k[100010];
int main() {
long long i, j, n;
long long cnt;
long long sz;
scanf("%lld", &n);
for (i = 0; i < n; i++) {
scanf("%lld", &o[i]);
if ((o[i] & (-o[i])) != o[i])
... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long n, sum = 0;
long long pre[1000000], two[1000000];
void _pre() {
for (long long i = n - 2; i >= 0; i--) {
if (pre[i] == 2 * sum)
two[i] = two[i + 1] + 1;
else
two[i] = two[i + 1];
}
}
int main() {
scanf("%lld", &n);
;
for (long long i ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 6e5 + 5;
const long long mod = 2000004199, mod2 = 1111111111111;
const long long seed = 131, seed2 = 13331;
int n, m;
char s[MAX];
unsigned long long P[MAX], P2[MAX];
set<unsigned long long> ss, ss2;
int main() {
P[0] = P2[0] = 1;
for (int i = 1; i < MAX... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n;
vector<int> v;
int freq[100010];
int main() {
string s;
cin >> s;
int cnt = 0;
int len = s.length();
for (int i = 0; i < len - 2; i++) {
if (len - i >= 6) {
if (s.substr(i, 6) == "Nikita") {
cnt++;
}
}
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct P {
double d;
int r;
} a[1005];
bool cmp(P a, P b) { return a.d < b.d; }
int main() {
int n, s, z, dd, flag = -1, ans = 0;
double x, y;
scanf("%d%d", &n, &s);
dd = 1000000 - s;
if (dd > 0) {
for (int i = 0; i < n; i++) {
scanf("%lf%lf%d", &x, ... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define s second
#define f first
//#define double long double
vector <int> par;
int get(int v)
{
if (v==-1)return -1;
if (par[v]==v)return v;
par[v]=get(par[v]);
return par[v];
}
void update(int v, int u)
{
v=get(v);
u=get(u... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
int n;
vector<int> v[N];
int a[N], b[N], c[N];
void bfs(int x) {
c[x] = 1;
queue<int> q;
q.push(x);
while (!q.empty()) {
int s = q.front();
q.pop();
for (int w : v[s]) {
if (!c[w]) {
c[w] = c[s] + 1;
q.push(... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d%d", &n, &k);
long long a[n + 1], b[n + 1], ans = 1e9;
vector<long long> arr;
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
b[i] = a[i];
}
sort(b + 1, b + n + 1);
arr.push_back(b[1]);
for (int i = 2; i <= n; i... | 12 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int n, m, i, j;
double ans = 0;
scanf("%d%d", &m, &n);
for (i = 1; i <= m - 1; i++) {
double now = i * 1.0 / m;
double temp = 1;
int k = n;
while (k) {
if ((k & 1) % 2 == 1) {
temp *= now;
}
now *... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
void TimeExecution() {
cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int n, arr[MAXN];
vector<int> occ[MAXN];
int occ_after(int x, int pos) {
return occ[x].end() - upper_bound(occ[x].begin(), occ[x].end(), pos);
}
int occ_before(int x, int pos) {
return (int)occ[x].size() - occ_after(x, pos - 1);
}
int solve() {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int A[100005];
int main() {
ios_base::sync_with_stdio(0);
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &A[i]);
}
if (A[n - 1] == 1)
printf("NO\n");
else if (n == 1) {
printf("YES\n");
printf("0\n");
} else if (n == 2) {
... | 14 |
#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
int n, t, d;
pair<int, int> a[200005];
set<pair<int, int>> s;
int b[200005];
int cnt = 0;
int main() {
cin >> n >> t >> d;
d++;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i].first);
a[i].second = i;
}
sort(a + 1, a + n + 1);
s.... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, cnt = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 == 1) {
cnt++;
} else if (a[i] % 2 == -1) {
cnt--;
}
}
cnt /= 2;
if (cnt > 0) {
for (int i = 0; i < n; i++) {
if (a[i... | 2 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
LL F[5005][2505];
int main() {
memset(F, 10, sizeof F);
int n;
scanf("%d", &n);
vector<int> A(n + 2, -1);
for (int i = (1); i <= (n); ++i) scanf("%d", &A[i]);
F[0][0] = 0;
vector<LL> Min(n + 1, 1LL << 60);
ve... | 11 |
#include <bits/stdc++.h>
inline int ccw(int ax, int ay, int bx, int by, int cx, int cy) {
return (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by));
}
int N;
int x[310];
int y[310];
int ans;
int main(void) {
scanf("%d", &N);
for (int i = 0; i < N; ++i) {
scanf("%d%d", &x[i], &y[i]);
}
for (int i = 0; i < ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 1;
int a, b, c, n;
int main() {
cin >> a >> b >> c;
cin >> n;
int d = 0;
for (int i = 0; i < (n); i++) {
int x;
cin >> x;
if (x > b && x < c) d++;
}
cout << d << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100005;
int n, ans, a, b, x[Maxn];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &x[i]);
sort(x + 1, x + 1 + n);
n = unique(x + 1, x + 1 + n) - x - 1;
scanf("%d%d", &a, &b);
while (true) {
if (a == b) {
printf(... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tc, n, temp;
cin >> tc;
while (tc--) {
unordered_set<int> check;
int flag = 1;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> temp;
temp += i;
temp %= n;
i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
set<long long> m;
long long p[maxn];
char s[100];
int a[100], b[100];
int n, k;
int solve() {
for (int l = 1; l <= 31; l++) {
long long ip = 0;
for (int i = 1; i <= l; i++) ip = ip * 2 + 1;
for (int i = 1; i <= 32 - l; i++) ip = ip * 2... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1.01e9;
const int N = 1 << 18;
const int MOD = (int)1e9 + 7;
char buf[N];
int n;
int parse(string s) {
bool ok = 1;
ok &= s[0] != '0';
int cur = 0;
for (int j = 0; j < (int)s.length(); j++) {
if (!(s[j] >= '0' && s[j] <= '9')) {
ok = 0... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int degrees[n + 1], xorsum[n + 1];
int used = 0;
vector<pair<int, int> > answer_edges;
queue<int> Q;
for (int i = 0; i < n; i++) {
cin >> degrees[i] >> xorsum[i];
if (degrees[i] == 1) Q.push(i);
if (degrees[i] == 0) us... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int a = 0;
int step = 1;
for (int i = 1; i < n; i++) {
a = (a + step) % n;
step++;
printf("%d%c", a + 1, i + 1 < n ? 32 : 10);
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
long long int val[100100], mem[100100 + 10], *dp;
int main() {
int n, i, max_a = 0;
dp = mem + 5;
scanf("%d", &n);
for (i = 0; i < n; i++) {
int a;
scanf("%d", &a);
val[a] += a;
max_a = max_a > a ? max_a : a;
}
for (i = 0; i <= max_a; i++) {
long long int t1 = dp... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, k;
int main() {
cin >> n;
for (j = 0; j <= 2 * n; j++) {
i = n - abs(j - n);
k = 0;
while (k < n - i) {
cout << " ";
k++;
}
k = i;
while (k > -i) {
cout << i - abs(k) << " ";
k--;
}
cout << 0 << endl;... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int c, d, n, m, k, ans, i, j;
cin >> c >> d;
cin >> n >> m;
cin >> k;
ans = n * m * d;
if (k >= n * m) {
cout << "0";
return 0;
}
for (i = k; i <= n * (m + 1); i += n) {
ans = min(ans, ((i - k) / n) * c + max((n * m - i) * d, 0));
... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x *= f;
}
int n, m, tot = 1, las... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long T, N;
long long i, j, k;
string s;
vector<long long> v;
long long temp, flag, count, ans;
long long T1, T2, T3, T4;
T1 = T2 = T3 = T4 = 0;
cin >> N;
cin >> s;
if (N % 4 != 0)
cout << "===" << endl;
else {
for (i = 0; i < ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int adj[102][102];
int n, m, dp[102][102][27][2];
int rec(int i, int j, int c, int prev) {
int &ret = dp[i][j][c][prev];
if (ret != -1) return ret;
ret = 0;
if (prev == 0) {
for (int v = 1; v <= n; v++) {
if (adj[i][v] >= c) {
ret = max(ret, 1 - re... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> G[200005];
int par[200005];
vector<int> comp[200005];
int size[200005];
int mn[200005], mx[200005];
void unionF(int u, int v) {
if (par[u] == par[v]) {
return;
}
int x = par[u], y = par[v];
if (size[x] < size[y]) swap(x, y);
size[x] += si... | 9 |
#include <bits/stdc++.h>
using namespace std;
double mid, p, t;
long long n, i, s;
double a[100005], b[100005], x[100005];
double lrlr(double l, double r) {
while (l + 0.000001 <= r) {
mid = (l + r) / 2;
t = mid * p;
for (i = 0; i < n; i++) {
if (a[i] * mid > b[i]) {
t -= a[i] * mid - b[i];
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, l1, r1, l2, r2;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> l1 >> r1 >> l2 >> r2;
if (l1 != l2)
cout << l1 << " " << l2 << endl;
else if (l1 != r2)
cout << l1 << " " << r2 << endl;
else if (r1 != l2)
cout << r1 ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000100;
const int MAXT = 300;
const int HLIM = 300;
int mfac[MAXN];
long long tt[MAXN];
int t[MAXN];
long long lv[MAXT];
int nfac[MAXT];
int d[MAXT][MAXT];
map<long long, int> s;
vector<vector<int> > vv;
vector<int> tfac;
long long v(int x) {
int cx = x;... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
int f[100];
void ham() {
f[0] = 0;
f[1] = 0;
for (int i = 2; i <= 64; i++) {
f[i] = f[i - 1] + i - 1;
}
}
void debug(int kt, int array[]) {
for (int i = kt; i >= 1; i--) cout << array[i];
cout << endl;
}
int dembit(long long x, int t) {
int... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline void tran(long long &x, long long &y) {
long long x0 = x, y0 = y;
x = x0 + y0, y = x0 - y0;
}
inline long long pos(long long x, long long d) { return x / d + (x > 0); }
inline long long LLabs(long long x) { return x > 0 ? x : -x; }
int main() {
long long a, b, ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
cin >> n;
int s1 = 0, s2 = 0;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
s1 += x;
}
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
s2 += x;
}
cout << (s1 >= s... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n, m, k;
cin >> n;
int b[n];
int pr[n];
int mas[n][n];
for (j = 0; j < n; j++)
for (i = 0; i < n; i++) cin >> mas[j][i];
for (j = 0; j < n; j++) cin >> pr[j];
for (j = 0; j < n; j++) b[j] = n + 1;
int cur, rescur;
for (j = 1; j... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2020;
int a[maxN][maxN];
queue<pair<int, int> > q;
bool used[maxN][maxN];
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
char ans[maxN][maxN];
int n, m;
bool check(int i, int j) {
if (!(i > 0 && i <= n && j > 0 && j <= m)) {
return ... | 12 |
#include <bits/stdc++.h>
using namespace std;
multimap<int, int> mp;
multimap<int, int>::iterator it;
int main() {
int n, a, b, sum = 0, x = 0;
cin >> n;
for (int h = 0; h < n; h++) {
cin >> a >> b;
mp.insert({a, b});
}
for (it = mp.begin(); it != mp.end(); it++) {
if (it->second < sum)
x++;... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long fact[11];
long long ans;
int mp[11][11], qwq[11][11], ok[11][11];
int n, m, k, pcnt;
int W(int x, int y) {
if (x - y <= 0) return fact[x];
return fact[x] / fact[x - y];
}
inline bool chk() {
for (int i = 1; i <= n; i++) {
for (in... | 19 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5005;
int T, N, tag[maxn], s[maxn];
ll dp[maxn];
int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%d", &N);
for (int i = 1; i <= N; ++i)
scanf("%d", tag + i);
for (int i = 1; i <= N; +... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, cnt, tot, ans, ansx, ansy;
struct tree {
long long mx, id;
} tt[1600005];
struct node {
long long l, r, ff, ls, id;
} a[200005], b[200005];
struct lisan {
long long zhi, id;
} shu[400005];
long long read() {
char ch = getchar();
long long x = 0, ff... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
int i, k;
cin >> n >> m;
int counta = 0, countb = 0;
for (i = 0; i < n; ++i) {
cin >> k;
if (k == -1)
counta++;
else
countb++;
}
int s, b, len;
while (m--) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 11;
const double pi = acos(-1.0);
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
struct Trie_tree {
int fail;
int son[26];
int end;
int mx;
} AC[111];
int siz = 0;
void insert(string s, int val) {
int len = s.size();
int u = 0;
fo... | 17 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long t;
cin >> t;
while (t--) {
long long n = 9, cnt = 0, a, b;
cin >> a >> b;
while (n <= b) {
cnt++;
n = n * 10 + 9;
}
cout << a * cnt << '\n';
}
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long pow_mod(long long x, long long n, long long mod) {
long long res = 1;
while (n) {
if (n & 1) res = res * x % mod... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long a, g = 1e18 + 1;
signed main() {
cin >> a;
long long l = a - g % a * 9 % a * 9 % a;
long long r = g + l - 1;
cout << l << " " << r;
return 0;
}
| 17 |
#include <bits/stdc++.h>
using namespace std;
int f[100];
char s[100];
int main() {
int a, b, c, n = 0;
scanf("%d %d %d", &a, &b, &c);
for (int i = 0; i < a; i++) {
scanf("%s", s);
for (int j = 0; j < b; j++)
if (s[j] == 'Y') {
f[j]++;
if (f[j] == c) n++;
}
}
printf("%d\n",... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, com[26][26], p, lim, val[26], a, b, dth;
string lis[111];
bool flag, imp;
char c;
int solve(int x) {
dth++;
if (dth > 777) return 0;
if (val[x]) return val[x];
int mi = 1;
for (int i = 0; i < 26; i++)
if (i != x) {
if (com[x][i] == -1) mi = max(mi... | 8 |
#include <bits/stdc++.h>
using namespace std;
int xp, yp, vp, xs, ys, vs, r;
inline long double minrad(long double x) {
return abs(x - round(x / 2 / M_PI) * 2 * M_PI);
}
int main() {
ios::sync_with_stdio(0);
cout << fixed << setprecision(12);
cin >> xp >> yp >> vp;
cin >> xs >> ys >> vs >> r;
long double rp... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[6], temp(0), counter[4], c(1), sum(0), max;
cin >> a[1] >> a[2] >> a[3] >> a[4] >> a[5];
for (int i = 1; i < 5; i++) {
for (int j = i + 1; j <= 5; j++) {
if (a[i] < a[j]) {
temp = a[i];
a[i] = a[j];
a[j] = temp;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool bad[2][1000];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++) {
int a, b;
scanf("%d %d", &a, &b);
--a, --b;
bad[0][a] = 1;
bad[1][b] = 1;
}
int ans = 0;
for (int i = 1; i < n - 1; i++) {
if (!bad[0][i]) ans... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long double epsilon = 1e-9;
struct interval {
int beg;
int len;
int type;
};
int main() {
int l, b, f;
cin >> l >> b >> f;
l += b + f;
int n;
cin >> n;
vector<interval> v;
interval temp;
temp.len = l;
temp.beg = 0;
temp.type = 0;
v.push_bac... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool uax(T &x, T y) {
return (y > x) ? x = y, true : false;
}
template <typename T>
inline bool uin(T &x, T y) {
return (y < x) ? x = y, true : false;
}
string to_string(char c) { return "'" + string(1, c) + "'"; }
string to_string(string s)... | 16 |
#include <bits/stdc++.h>
using namespace std;
int N;
int main() {
cin >> N;
string s;
int cur = 0;
for (int i = 1; i <= N; i++) {
int tmp;
cin >> tmp;
cin >> s;
if (cur == 0 || cur == 20000) {
if (s == "East" || s == "West") {
cout << "NO";
return 0;
}
}
if (s... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int sequenceLength, numI;
map<long long int, bool> visited;
set<long long int> collection;
stack<long long int> topologicalSort;
void dfs(long long int num) {
if (collection.find(num) == collection.end()) return;
if (visited[num]) return;
visited[num] = true... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int t[N];
int pot[27];
int main() {
int n;
scanf("%d", &n);
pot[0] = 1;
for (int i = 1; i < 27; i++) pot[i] = pot[i - 1] * 2;
for (int i = 0; i < n; i++) {
string a;
cin >> a;
int m = a.size();
int c[27];
for (int j = 0; j... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> edge[200009], yol(200009), bob(200009);
void dfs1(int node, int anc) {
for (int i = 0; edge[node].size() > i; i++) {
if (edge[node][i] == anc) {
continue;
}
yol[edge[node][i]] = yol[node] + 1;
dfs1(edge[node][i], node);
}
}
void dfs2(in... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, i, j, a[100], ans = -1, x = 0, y = 0;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 1)
x++;
else
y++;
}
for (i = 1; i <= n; i++) {
long long int c1 = 0;
long long int c0 = 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 2003;
int N, M, K;
long long C[MaxN][MaxN];
int rem[MaxN][MaxN], rcou[MaxN];
bool vis[MaxN];
struct GAR {
int x, y, w;
} gar[MaxN][MaxN];
int len[MaxN];
struct QUE {
int x1, y1, x2, y2;
} que[MaxN];
int qcou;
long long ans[MaxN];
inline int lowbit(int x... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, k, hh, now, ans, la[5010], f[5010][5010], c[5010][5010], sum[5010],
p = 1e9 + 7;
char s[5010];
int main() {
scanf("%d", &n);
scanf("%s", s + 1);
f[0][0] = 1;
for (i = 0; i <= n + 1; i++) c[i][0] = 1;
for (i = 1; i <= n + 1; i++)
for (j = 1; j ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
vector<int> b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
cin >> b[i];
}
int resp = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
i... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
T min(T a, U b) {
if (a < (U)b) return a;
return b;
}
template <class T, class U>
T max(T a, U b) {
if (a < (U)b) return b;
return a;
}
const int INF = 1000000000;
const long long MOD = 1000000009;
int main() {
int N;
scanf("%d", &N);... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = .2e6 + 5;
const int X = 20;
vector<pair<int, pair<long long, long long> > > S[N];
vector<pair<long long, long long> > CS[N];
set<pair<long long, long long> > adj[N];
int nn;
int subsize[N];
int dpar[N];
int dep[N];
long long dist[X][N];
void sub_dfs(int v, int... | 26 |
#include <bits/stdc++.h>
int fa[10000000 + 10];
inline long long gcd(long long a, long long b) {
while (a > 0) {
long long tmp = a;
a = b % a;
b = tmp;
}
return b;
}
int getfa(int a) { return (fa[a] == a) ? a : fa[a] = getfa(fa[a]); }
int m(long long a, long long b) {
if (fa[a] == 0 || fa[b] == 0) r... | 17 |
#include <bits/stdc++.h>
using namespace std;
char _;
int rnk[5005], nxt[5005][5005];
int hi, n, k;
string s;
vector<pair<pair<int, int>, int> > v;
void out(int N, int P) {
if (N == 0) return;
P = nxt[N][P];
cout << s[k - N + P];
out(N - 1, P);
}
int main() {
cin >> s;
if (s.size() == 1) {
cout << s;
... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1005;
const int LIMIT = 1000005;
int n, m, len1, len2, dp[5][NMAX][NMAX];
char s[NMAX][NMAX];
bool viz[NMAX][NMAX];
pair<int, int> Q1[LIMIT], Q2[LIMIT];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
bool Interior(int x, int y) {
if (x >= 1 && x <= n... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 9, MOD = 1e9 + 7;
long long a[N], dp[2][N], fact[N];
unordered_map<long long, long long> mp;
vector<long long> v, vec;
void PREP() {
fact[0] = dp[1][0] = dp[0][0] = 1;
for (long long i = 0, t = 0; i < v.size(); i++, t ^= 1)
for (long long j... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5, inf = 1e18;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
string a, b;
cin >> a >> b;
vector<long long int> a... | 5 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
const int infi = 1e9 + 7;
const long long infl = 1e18;
const long double eps = (long double)1e-8;
const long double eps1 = 1e-10;
const int mod = (1e9 + 7);
const long long mod1 = (1e9 + 7);
const long long mod2 = 1e9 + 9;
const lo... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
template <class c>
debug& operator<<(const c&... | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.