solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
cin >> k;
for (int i = 0; i < k; i++) {
int n;
cin >> n;
int M[n];
for (int j = 0; j < n; j++) {
cin >> M[j];
}
sort(M, M + n);
int n1 = n, x = 0, x1 = 0;
for (int l = 0; l < n; l++) {
x1 = min(n1, M[l]);... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e, f, s;
cin >> a >> b >> c >> d >> e >> f;
s = (a + b + f) * (a + b + f) - (b * b + d * d + f * f);
cout << s;
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100;
long long n = 0, k = 0;
int main() {
while (cin >> n >> k) {
if (k % n > 0) {
cout << k / n + 1 << endl;
} else {
cout << k / n << endl;
}
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;
const long long INF = 2 * 1e18;
const long double PI = 3.14159265358979323846;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long t;
cin >> t;
while (t--) {
bool x = 0;
long long n, k, l, c... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, a;
int main() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a;
if (360 % (180 - a) == 0)
cout << "YES\n";
else
cout << "NO\n";
}
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
struct NODE {
int h, t;
NODE() {}
NODE(int _h, int _t) { h = _h, t = _t; }
};
const int maxn = 207, maxnum = 100000000;
int n, m, H, T, R;
int dist[maxn][maxn];
bool use[maxn][maxn];
int dfn[maxn][maxn];
NODE dh[maxn], dt[maxn];
void spfa(int H, int T) {
queue<NODE>... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 + 10;
const int mod = 998244353;
int a[maxn], pwk[maxn], pwk2[maxn];
int C[maxn][maxn];
int main() {
ios_base::sync_with_stdio(false);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
if (k == 1) return cout << 0 << endl, 0;... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[100002], s[4];
int main() {
cin >> n;
int m = 0, ps = 100001;
long long d = 0;
for (int i = 1; i <= n; ++i) cin >> a[i];
sort(a + 1, a + n + 1);
if (a[1] == 0 && a[2] == 0) {
cout << "cslnb";
return 0;
}
for (int i = 1; i < n; ++i) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, p, q;
vector<long long> v, v1;
long long n, t;
long long good() {
if (v.size() != v1.size()) return false;
for (int i = 0; i < v.size(); i++)
if (v[i] != v1[i]) return false;
return true;
}
void solve(long long a, long long b) {
if (a == 0 || b =... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
int A[maxn];
int n;
int dfs(int l, int r, int h) {
int ans = 0;
int last = l;
int MIN = 0x3f3f3f3f;
int i;
for (i = l; i <= r; i++) {
MIN = min(MIN, A[i]);
}
ans = MIN - h;
for (i = l; i <= r; i++) {
if (A[i] == MIN) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, j, ans = 0, k, m;
cin >> n >> m >> k;
long long a[100];
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
if (m <= k)
cout << 0 << endl;
else {
for (i = n - 1; i >= 0; i--) {
k -= 1;
k += a[i];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int id(string s, int b, int x) {
if (x <= b) return x;
return (b << 1) - x;
}
bool kmpSearch(string s, string t, vector<int>& v, int slen, int tlen, int b) {
int ptr = 0;
for (int j = 0; j < slen; j++) {
int i = id(s, b, j);
if (ptr == tlen) break;
if (s... | 5 |
#include <bits/stdc++.h>
int const MAX = 505;
int const MOD = 1e9 + 7;
long long dp[MAX][MAX];
int b[MAX];
long long DFS(int l, int r) {
long long ans = dp[l][r];
if (ans >= 0) return ans;
if (l > r) return 1;
ans = 0;
for (int i = l; i <= r; i++)
if (i == r || b[l] < b[i + 1])
ans = (ans + DFS(l + ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int a[4][5];
int main() {
for (int i = 0; i < 4; i++)
for (int j = 1; j <= 4; j++) scanf("%d", &a[i][j]);
for (int i = 0; i < 4; i++)
for (int j = 1; j <= 3; j++)
if (a[i][j]) {
int x;
if (j == 1) x = (i + 3) % 4;
if (j == 2) x = (i... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
bool compare(const pair<string, int> &a, const pair<string, int> &b) {
return a.second < b.second;
}
bool compare_float(double x, double y) { return fabs(x - y) < DBL_EPSI... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100500;
const int N = 50;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
long long n, p, w, d;
scanf("%lld%lld%lld%lld", &n, &p, &w, &d);
long long s = w * d / gcd(w, d);
long long nw = s / w;
long long... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 100;
const int mod = 1e9 + 7;
const long long inf = 1e18;
long long a1[N], a2[N], n, x, dp[N][3];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> x;
for (long long i = 1; i <= n; i++) {
cin >> a1... | 11 |
#include <bits/stdc++.h>
using namespace std;
bool p(string s) {
string s1 = s;
reverse(s1.begin(), s1.end());
if (s == s1) return 1;
return 0;
}
int main() {
long long n;
cin >> n;
pair<long long, long long> a[n];
for (int i = 0; i < n; i++) {
cin >> a[i].first;
a[i].second = i;
}
sort(a, a... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[1005];
cin >> s;
int n;
cin >> n;
int f = 0;
int len = strlen(s);
if (len % n != 0)
cout << "NO";
else {
int cnt = len / n;
for (int i = 0; i < len; i += cnt)
for (int j = 0; j < cnt / 2; j++) {
if (s[i + j] != s... | 3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int a[n];
unordered_map<int, int> c;
for (int i = 0; i < n; i++) cin >> a[i], a[i]--, c[a[i]]++;
if (n == 1) {
cout << 1 << '\n';
return;
}
if (n == 2) {
if (a[0] == a[1])
cout << 2 << '\n';
else
co... | 3 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long tc;
cin >> tc;
while (tc--) {
long long n;
cin >> n;
long long a[n];
long long ans = 0;
for (long long i = 0; i < n; i++) cin >> a[i];
for (long long i = 2; i <= 2 * n; i++) {
long long sum = i;
map<long lo... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string word;
cin >> word;
int moves = 0, walk = 0, strt = 0;
for (int i = 0; i < word.length(); i++) {
int index = word[i] - 97;
walk = abs(strt - index);
if (walk < 13)
moves += walk;
else
moves += (26 - walk);
strt = in... | 0 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
string s;
cin >> s;
long long ans = n;
for (long long i = 0; i < n; i++) {
if (s[i] == '1') ans = max... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 7;
const int INF = 1e9 + 7;
long long c1[N], c2[N];
long long n, m = 0, ans = 0;
int main() {
scanf("%I64d", &n);
c2[0]++;
for (int i = 1; i <= n; i++) {
long long x;
scanf("%I64d", &x);
m ^= x;
if (i & 1)
c1[m]++;
else
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 2;
const int M = 4e6 + 2;
const int mod = 998244353;
const long long inf = 1e15;
const long long INF = 2e18;
void data() {}
int T, n, a[N], b[N];
int main() {
data();
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for (int i = 1; i <= n; +... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000;
struct matrix {
int n;
vector<bitset<maxn>> lines;
matrix(int _n) : n(_n), lines(n) {}
static matrix identity(int n) {
matrix result(n);
for (int i = 0; i < n; ++i) result.set(i, i);
return result;
}
void set(int y, int x) { li... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, count = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a >> b;
if (b - a >= 2) {
count++;
}
}
cout << count;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long t, n;
int main() {
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++) cout << 4 * n - i * 2 << ' ';
cout << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string p, e;
cin >> e >> p;
int c = 0;
for (int i = 0; i < n; i++) {
if (p[i] - '0' == 0) {
continue;
}
if (e[i] - '0' == 0) {
c++;
e[i] = -1... | 0 |
#include <bits/stdc++.h>
using namespace std;
int m[1000][1000], n;
int rsum(int r, int i) {
int s = 0;
for (int j = i; j < n; j++) s += m[r][j];
return s;
}
int csum(int c, int i) {
int s = 0;
for (int j = 0; j < n - i; j++) s += m[j][c];
return s;
}
int main() {
cin >> n;
memset(m, 0, sizeof m);
int... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin >> s;
long long int n = s.length();
long long int mod = 1e9 + 7, ans = 1, i;
map<char, long long int> mp;
for (i = 0; i < n; i++) {
if (s[i] >= '0' && s[i] <= '... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int ans = 0, n;
string s, t, p;
cin >> s >> t >> n;
vector<vector<int>> dist(26, vector<int>(26, INF));
vector<vector<pair<int, int>>> gr(26);
p = s;
for (int i = 0; i... | 10 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<pii> v(m);
for (int i = 0; i < m; i++) {
cin >> v[i].first >> v[i].second;
if (v[i].first > v[i].second) v[i].second +... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
long long ans[MAX], a[MAX];
int main() {
long long n, q, k;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1, greater<int>());
for (int i = 1; i <= n; i++) a[i] += a[i - 1];
cin >> q;
memset(ans, -1, sizeof ans)... | 11 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int T;
cin >> T;
while (T--) {
string s;
cin >> s;
int resa = 0, resb = 0, resc = 0;
for (auto &it : s) {
if (it == 'A')
resa++;
else if (it == 'B')... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using std::cerr;
using std::cin;
using std::cos;
using std::cout;
using std::endl;
using std::make_pair;
using std::max;
using std::min;
using std::next_permutation;
using std::pair;
using std::priority_queue;
using std::queue;
using std::random_shuffl... | 16 |
#include <bits/stdc++.h>
int n, a, k, sum;
int tick[10], mod[3][2];
int main() {
scanf("%d", &n);
mod[1][0] = mod[1][1] = mod[2][0] = mod[2][1] = 9;
for (int i = 1; i <= n; ++i) {
scanf("%d", &a);
sum += a;
++tick[a];
k = a % 3;
if (a < mod[k][0]) {
mod[k][1] = mod[k][0];
mod[k][0]... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long power(long long x, long long n, long long mod) {
if (n == 0) {
return 1;
}
long long temp = power(x, n / 2, mod);
if (n % 2 == 1) {
return (x * temp * temp) % mod;
} else {
return (temp * temp) % mod;
}
}
long lo... | 6 |
#include <bits/stdc++.h>
using namespace std;
int p[1000111];
int main() {
int n;
scanf("%d", &n);
memset(p, -1, sizeof(p));
vector<int> vec;
for (int i = (n); i >= (0); i--) {
if (p[i] != -1) continue;
int tmp = i;
int tmp1 = 0;
int j = 0;
while (tmp > 0) {
if (tmp % 2 == 0) tmp1 +=... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, q, x, k, t, y, w = 2, z, a[200500], ans[200500], bit[400500];
long long get(int i) {
long long ret = 0;
while (i) ret += bit[i], i -= (i & -i);
return ret;
}
void update(int i, int val) {
while (i <= 2 * n) bit[i] += val, i += (i & -i);
}
int main() ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = acosl(-1.);
const int N = 100111;
const int M = 60;
long long a[N];
long long powers[M];
int pows2[M], after_pows2[M];
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
int n;
cin >> n;
powers[0] = 1;
for (int i = 1; i <... | 14 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
const int mod = 1e9 + 7;
int fact(int n) {
int res = 1;
for (int i = 1; i <= n; i++) {
res = res * 1ll * i % mod;
}
return res;
}
int n;
void solve() {
cin >> n;
int cnt[10] = {};
for... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename Q>
void inin(Q &ret) {
ret = 0;
char ch = getchar();
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getchar();
}
int n, a[111], ans;
int main() {
inin(n);
ans = n;
for (int i = (1)... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 55;
const int INF = 1e9 + 77;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
const double EPS = 1e-7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int tc;
cin >> tc;
while (tc--) {
int n;
cin >> n;
vector<int>... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long lazy[200005 * 8];
long long ma[200005 * 8];
long long cost[300005];
long long dp[300005];
struct node {
int l, r, val;
} ss[300005];
int cmp(node x, node y) { return x.r < y.r; }
void push_up(int id) { ma[id] = max(ma[(id * 2)], ma[(id * 2 + 1)]); }
vo... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, sum;
int all[30];
int ji, jicnt;
int ys[500];
int cnt;
bool check(int t) {
for (int i = 1; i <= n; i++)
if (all[i] % t != 0) return false;
return true;
}
int ans1, len1;
void test1() {
if (sum & 1) return;
for (int i = 1; i <= cnt; i++) {
if (sum % (y... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3E5;
bool mark[MAXN];
vector<int> lst[MAXN];
int color[MAXN];
int n, m, k;
vector<int> componenta;
void dfs(int i) {
mark[i] = true;
componenta.push_back(i);
for (auto x : lst[i])
if (!mark[x]) dfs(x);
}
int main() {
ios_base::sync_with_stdio(0)... | 8 |
#include <bits/stdc++.h>
using namespace std;
char b[101];
string a[101];
long long dp[11][11];
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < k; i++) {
cin >> a[i] >> b[i];
}
dp[0][0] = 1;
for (int i = 1; i < n; i++) {
for (int x = 0; x < 6; x++) {
for (int j = 0; j < k; j++)
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, h;
int a[N];
int check(int x) {
int pre = 0;
for (int i = 1; i <= n; i++) {
int t = pre;
int g = a[i] + x;
if (g < pre) return 0;
int flag = 0;
if (g >= h) flag++;
g %= h;
if (a[i] > pre) {
pre = a[i];
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = ((long long int)1e3) + 5;
const long long int M = ((long long int)1e3) + 5;
const long long int llinf = (long long int)1e18;
const int inf = INT_MAX;
long long int T;
long long int n;
long long int arr[N];
long long int cnt[N];
int main() {
cin.tie... | 0 |
#include <bits/stdc++.h>
int main() {
int T, i;
long long int a, b, ans;
scanf("%d", &T);
for (i = 1; i <= T; i++) {
scanf("%lld %lld", &a, &b);
if (a > b) {
if (b * 2 <= a) {
printf("%lld\n", b);
} else {
ans = (a + b) / 3;
printf("%lld\n", ans);
}
} else {... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 70 + 10, LAB = 20, S = (1 << 17) + 10, oo = 1 << 29;
priority_queue<pair<int, pair<int, int> >, vector<pair<int, pair<int, int> > >,
greater<pair<int, pair<int, int> > > >
q;
int d[S][N], n, m, a, b, cntlab, lab[N], fa[N], sz[N];
struct Edge... | 22 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265359;
void OLE(string s = "OLE") {
cout << "OMG" << endl;
exit(-1);
}
int maxTr = (int)1e6;
vector<unsigned long long> pows;
vector<int> pows2;
const int mod = (int)1e9 + 7;
void init() {
pows.resize(maxTr + 1);
pows[0] = 1;
for (int i =... | 22 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long d[500009];
string s;
double ans;
int main() {
cin >> s;
n = s.length();
for (int i = 0; i < n; i++) {
d[i + 1] = d[i];
if (s[i] == 'I' || s[i] == 'E' || s[i] == 'A' || s[i] == 'O' ||
s[i] == 'U' || s[i] == 'Y')
d[i + 1]++;
}
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5e4 + 100, LG = 23;
long long n, m, p[N], c, x[N];
struct sparse_table {
long double ans, pre, suf, all;
long long l, r;
sparse_table() { all = ans = pre = suf = (long double)0; }
sparse_table operator+(sparse_table y) {
sparse_table re... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long int A[1000000];
void ans() {
vector<char> v;
int num, i;
cin >> num;
string str;
cin >> str;
for (i = 0; i < num; i++) {
if (v.size() % 2 == 0 || str[i] != v[v.size() - 1]) {
v.push_back(str[i]);
}
}
if (v.size() % 2 != 0) {
v.pop... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long arr[1000010];
int N;
bool check(long long K) {
long long superCount = K;
for (int i = 0; i < N; i++) {
superCount -= (K - arr[i]);
}
return superCount <= 0;
}
int main() {
cin >> N;
long long high = 0;
for (int i = 0; i < N; i++) {
cin >> arr... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
struct union_find {
int parent[maxn];
union_find() {
for (int i = 0; i < maxn; i++) {
parent[i] = i;
}
}
int find(int x) {
if (parent[x] == x) {
return x;
}
return parent[x] = find(parent[x]);
}
void upda... | 16 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
if (n == 1) {
cout << 9 << " " << 8 << endl;
return;
}
cout << 3 * n << " " << 2 * n << endl;
}
int main() {
int t = 1;
for (int i = 0; i < t; i++) {
solve();
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int box[1000000];
int main() {
ios_base::sync_with_stdio(false);
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> box[i];
int mx = box[n - 1];
if (k >= n)
cout << mx << '\n';
else {
for (int i = 0; i < n - k; i++) {
mx = max(mx, box[n ... | 6 |
#include <bits/stdc++.h>
const long long N = 500005;
const long long mod = 1e9 + 7;
using namespace std;
void solve() {
long long T = 1;
while (T--) {
long long n, m, k, x = 0, y = 0, c = 0, q, ans = 0;
cin >> n >> k;
long long a[n];
for (long long i = 0; i < n; ++i) {
cin >> a[i];
}
f... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
long long marked[4 * N + 50], t[4 * N + 50], val[4 * N + 50];
long long prep[4 * N + 50], prep2[4 * N + 50];
void push(int v, int l, int r) {
if (marked[v]) {
t[v] = marked[v] * (r - l + 1);
val[v] = marked[v];
if (l != r) marked[v * 2] =... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 30005;
const long long inf = 1LL << 60;
int n, q, x, y;
int whereW[nmax], whereH[nmax];
int forbidden[nmax];
long long match1[nmax], match2[nmax], match3[nmax];
long long dp[nmax];
pair<int, int> w[nmax], h[nmax];
void calc(int i) {
match1[i] = match2[i] ... | 22 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O2")
#pragma GCC optimization("unroll-loops")
const long double ERR = 1e-5;
const int MOD = 1e9 + 7;
bool areEqual(long double _n1, long double _n2) {
return fabs(_n1 - _n2) < ERR;
}
int main() {
ios::sync_with_stdio(... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
const long long MN = -1e9;
const long long mod = 998244353;
const long long md = 998244353;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long a[n + 1];
for (int i = 1; i <= n; i++) {
cin >> ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int A[3][3], B[3][3], D[3][3], pa[101], pb[101];
int main() {
long long k, a, b;
cin >> k >> a >> b;
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j) {
cin >> A[i][j];
A[i][j]--;
}
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j... | 10 |
#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
int main() {
int q, w, e, r, t;
cout << "2000\n";
for (w = 0; w < 1000; w++) cout << w + 1 << " 1 " << w + 1 << " 2\n";
for (w = 999; w >= 0; w--) cout << w + 1 << " 1 " << w + 1 << " 2\n";
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int>> ans;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int i, j;
cin >> n;
if (n % 2) {
ans.push_back({1, 2, 3});
ans.push_back({1, 2, 3});
for (i = 5; i <= n; i += 2) {
for (j = 1; j < i - 2; j += 2) {
ans.... | 20 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5, inf = 1e12;
long long a[51][5001], ind[N], sum[N], mn[N], mx[N], l[N];
bool used[50];
signed main() {
long long n, m, ans = -inf, res = -inf, f = 0;
cin >> n >> m;
for (long long i = 0; i < n; i++) {
cin >> l[i];
for (long long j = 0; ... | 12 |
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <vector>
#define ls (node << 1)
#define rs ((node << 1) | 1)
typedef long long ll;
using namespace std;
int read()
{
int x=0,flag=1; char c=getchar();
while((c>'9' || c<'0') && c!='-') c=getchar();
if(c==... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct T {
string type;
long long width;
long long height;
int border;
int spacing;
int has_parent;
T() {}
T(string _type, long long _width, long long _height, int _border,
int _spacing, int _has_parent)
: type(_type),
width(_width),
... | 15 |
#include <bits/stdc++.h>
using namespace std;
struct pair_hash {
template <class T1, class T2>
std::size_t operator()(std::pair<T1, T2> const &pair) const {
std::size_t h1 = std::hash<T1>()(pair.first);
std::size_t h2 = std::hash<T2>()(pair.second);
return h1 ^ h2;
}
};
unsigned long long max(unsigned... | 2 |
/**Bismillahir Rahmanir Rahim.**/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define Faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1)
#defin... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
int a[N], ar[N];
int main() {
int n;
cin >> n;
int a0 = 0, a1 = 1, m;
cin >> m;
for (int i = 0; i < m; ++i) {
int t, x;
scanf("%d", &t);
if (t == 1) {
scanf("%d", &x);
a0 = (a0 + x + n) % n;
a1 = (a1 + x + n) % ... | 10 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int getval(string a) {
string bare;
int cnt = 0;
for (register int j = (0); j < (int)((int)(a).size()); ++j) {
if (a[j] == '*')
cnt++;
else if (a[j] == '&')
cnt--;
else
bare += a[j];
}
if (mp.count(bare) == 0) ret... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T Max(T a, T b) {
return a > b ? a : b;
}
template <class T>
inline T Min(T a, T b) {
return a > b ? b : a;
}
template <class T>
inline T _GCD(T a, T b) {
if (b == 0) return a;
return _GCD(b, a % b);
}
template <class T>
inline T _LCM(T a, ... | 14 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n, w;
cin >> n >> w;
vector<pair<long long int, long long int>> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].first;
a[i].second = i + 1;
}
sort(a.begin(), a.end());
long long int sum = 0;
vector<long long int> ans;
f... | 5 |
#include <bits/stdc++.h>
using namespace std;
namespace IO {
void read(int &x) {
x = 0;
int f = 1;
char c = getchar();
while ('0' > c || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while ('0' <= c && c <= '9') {
x = (x << 3) + (x << 1) + c - '0';
c = getchar();
}
x *= f;
}
void wri... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const double PI = 2 * acos(0.0);
const double eps = 1e-9;
const int NPOS = -1;
const int MAX = 100001;
int n, d, r, arr[MAX];
long long ans;
long long C(int n, int r) {
if (r > n / 2) r = n - r;
long long ans = 1;
for (int i = int(1); i < int... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int i, a[n], chest = 0, biceps = 0, back = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
if (i % 3 == 0) chest += a[i];
if (i % 3 == 1) biceps += a[i];
if (i % 3 == 2) back += a[i];
}
if (max(chest, (max(biceps, back))) ... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int main() {
int n, d;
scanf("%d%d", &n, &d);
v.resize(n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &v[i].first, &v[i].second);
}
sort(v.begin(), v.end());
long long sum = 0, ans = 0;
int l = 0, r = 0;
while (r < n) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int u[110000];
int v[110000];
int n, e, t;
int l[110000][21];
int team[110000];
int divi[110000];
int szl[110000];
bool work(void) {
int i;
int cnt = 0;
for (i = 1; i <= n; i++) {
team[i] = l[i][rand() % szl[i] + 1];
}
for (i = 1; i <= t; i++) {
divi[i] = ... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long inf = 1LL << 62;
int n;
long long c, p[100010], s[100010];
long long dp[100010], tmp[100010];
int main() {
scanf("%d%lld", &n, &c);
for (int i = 1; i <= n; i++) scanf("%lld", &p[i]);
for (int i = 1; i <= n; i++) scanf("%lld", &s[i]);
for (int j = 0; j <= n... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long int n;
cin >> n;
vector<unsigned long long int> x;
int c = 0, d = 0, e = 0, f = 0, t;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
x.push_back(a);
}
for (int i = 0; i < n; i++) {
if (x[i] == 4) {
c++;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
long long int k, x;
while (n--) {
scanf("%lld", &k);
scanf("%lld", &x);
printf("%lld\n", (k - 1) * 9ll + x);
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, mod = 1e9 + 7;
vector<pair<int, int> > v[N];
bool vis[N] = {};
int dfs(int node, int par) {
int ret = 1;
vis[node] = true;
for (auto u : v[node]) {
if (u.first == par || u.second) continue;
ret += dfs(u.first, node);
}
return ret;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
long long a, b;
while (T--) {
cin >> a >> b;
if (abs(a - b) % 10 == 0) {
cout << abs(a - b) / 10 << '\n';
} else {
cout << abs(a - b) / 10 + 1 << '\n';
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long mod = 1000000007;
const double e = 2.718281828459;
long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
}
long long gcd1(int a, int b) {
if (!b) return a;
return gcd(b, a % b);
}
long long pow_... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long int LINF = 0x3f3f3f3f3f3f3f3fll;
const long double pi = acos(-1);
const int MOD = 1e9 + 7;
int v[1000100];
int v2[1000100];
int n;
long long int S = 0;
int antes = 0, depois = 0;
int mapa[1000100];
int main() {
scanf("%d", &n);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s, s1;
char s2;
for (int i = 0; i < n; i++) {
cin >> s2;
s += s2;
s1 += s2;
}
s1 += s;
int max = 0;
int count = 0;
int i = 0;
while (i < 2 * n) {
if (s1[i] == '1') {
int count = 1;
if (ma... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1000000007;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, s;
cin >> n >> m >> s;
int mxf = 0, mxfcnt = 0, mxg = 0, mxgcnt = 0;
for (int a = (1); a < ((n) + 1); a++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
void task() {
int n, a, b, ans;
cin >> n >> a >> b;
int pos = n - a;
if (pos > b)
ans = b + 1;
else
ans = n - a;
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
task();
return 0;
}
| 2 |
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
typedef long long ll;
int a[N];
map<ll,ll>mp;
int main()
{
int t;
cin >> t;
while(t--)
{
long long cnt = 0;
mp.clear();
int n;
cin >> n;
for(int i = 1;i <= n;i++)
{
cin >> a[i];... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a_00[400010] = {0}, a_11[400010] = {0}, a_01[400010] = {0},
a_10[400010] = {0}, b[400010] = {0};
bool cmp(int x, int y) { return x > y; }
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
if (x == 0... | 7 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const long long mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 100 + 10;
const int maxm = 100 + 10;
int n, m;
int a[maxn];
int d[maxn];
int g[maxn][maxn];
int main() {
ios::sync_with_stdio(false);
cin.t... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_BUF_SIZE = 16384;
char BUFOR[MAX_BUF_SIZE];
int BUF_SIZE, BUF_POS;
char ZZZ;
const int MXN = 1000010;
const int C = 262144;
const int INF = 1000000001;
int a[MXN][3];
int n;
vector<pair<pair<int, int>, pair<int, int> > > c[2];
vector<int> b[2];
map<pair<int, i... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void rd(T &x) {
x = 0;
char ch = getchar();
long long f = 1;
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
x *= f;
}
template <class T>
void cmin(T &x, T... | 22 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int maxn = 606;
vector<int> g[maxn];
int cnt[maxn], in[maxn], out[maxn];
int M[maxn][maxn], order[maxn], O = 0;
bool used[maxn];
void dfs(int v) {
used[v] = true;
for... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2048;
const int K = 1 << 17;
const int MOD = (1e9) + 7;
int n, k;
char a[N], b[N];
bool used[2][K];
int state[2][K];
int good, bad;
bool is_good[N];
int cnt;
int recurse(int which, int rem) {
if (rem == 0) return which;
if (used[which][rem]) return state[w... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long N;
cin >> N;
vector<long long> A(N + 1);
vector<long long> B(N + 1, -1);
vector<long long> C(N + 1, -1);
long long res = 0;
long long M = 0;
for (long long i =... | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.