solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int N = 2e5 + 10;
bool check(vector<int> v, int x = 0, int y = 0) {
if (x) v.push_back(x);
if (y) v.push_back(y);
sort(v.begin(), v.end());
int q1 = (v[0] + v[1] + v[2] + v[3]);
int q2 = (v[1] + v[2]) * 2;
int q3 = (v[3] - v[0]) * ... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<char> v;
int main() {
int t;
scanf("%d", &t);
while (t--) {
v.clear();
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (i == s.size() - 1 || s[i] != s[i + 1]) {
v.push_back(s[i]);
} else
i++;
}
sor... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, i, c = 0, c1 = 0;
cin >> n;
if (n == 1) {
string s;
cin >> s;
cout << s << endl;
return 0;
} else {
vector<string> v;
for (i = 0; i < n; ++i) {
string s;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;
vector<vector<int>> gr;
vector<int> order;
vector<bool> used;
void dfs(int x) {
order.push_back(x);
used[x] = 1;
for (auto i : gr[x]) {
if (!used[i]) {
dfs(i);
order.push_back(x);
}
}
}
int main()... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > mul(vector<vector<long long> > a,
vector<vector<long long> > b) {
vector<vector<long long> > c;
c.resize(a.size());
for (int i = 0; i < c.size(); i++) c[i].resize(b[0].size(), 0);
for (int i = 0; i < c.size()... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[5005], f[5005];
int main() {
double gar;
scanf(" %d %d ", &n, &m);
for (int i = 0, _n = (n); i < _n; i++) scanf(" %d %lf ", &a[i], &gar);
int res = 0;
for (int i = 0, _n = (n); i < _n; i++) {
f[i] = 1;
for (int j = 0, _n = (i); j < _n; j++)
... | 4 |
#include <bits/stdc++.h>
using namespace std;
char s[109][109];
int main() {
int n, m, flag = 1;
scanf("%d%d", &n, &m);
int i, j;
for (i = 0; i < n; i++) {
scanf("%s", &s[i]);
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
int cnt = 0;
if (s[i][j] != '*') {
if (s[i][j - 1]... | 1 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:512000000")
using namespace std;
template <class T>
inline T sqr(T x) {
return x * x;
}
template <class T>
inline string tostr(const T &x) {
stringstream ss;
ss << x;
return ss.str();
}
const double EPS = 1e-6;
const int INF = 1000 * 1000 * 1000;
const ch... | 7 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, k;
string s;
cin >> n >> k;
vector<long long> a(n);
for (long long& i : a) cin >> i;
cin >> s;
long long i = 0, res = 0;
while (i < n) {
long long j = i;
wh... | 2 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int N = 2, K = 2e5;
int n, k_total;
int32_t k[N], a[N], x[N], y[N], m[N], p[N];
bool greater_by_a(int i, int j) { return a[i] > a[j]; }
priority_queue<int32_t, vector<int32_t>, decltype(&greater_by_a)> q(
greater_by_a);
vector<int32_t> ... | 4 |
#include <bits/stdc++.h>
const int MAXN = 200000;
int S[MAXN + 5], a[MAXN + 5], p[MAXN + 5];
char s[MAXN + 5];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
p[a[i]] = i;
}
scanf("%s", s);
for (int i = 1; i < n; i++) S[i] = S[i - 1] + s[i - 1] - '0';
for (i... | 3 |
#include <bits/stdc++.h>
int main(int argc, char const *argv[]) {
int t, n, n1, n2, j, p, e;
int i;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &p);
for (i = 5; i * (i - 1) <= 4 * i + 2 * p; ++i)
;
n1 = --i;
e = 2 * (i + 1) + p;
n2 = e - (i - 1) * i / 2;
for (i = 2; i < n + (n... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int OO = 1e9;
const long long INF = 1e18;
const int irand(int lo, int hi) {
return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
const long long lrand(long long lo, long long hi) {
return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
te... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
struct P {
int x, y, z, id;
bool operator<(const P &a) const {
if (x != a.x) return x < a.x;
if (y != a.y) return y < a.y;
return z < a.z;
}
} a[50005];
vector<pair<int, int> > ans;
int main() {
scanf("%d", &n);
for (int i = (int)(1); i <= (int)... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k = 3, n;
scanf("%d", &n);
while (k * (k + 1) / 2 <= n) k++;
vector<int> ans[k];
int num = 1;
printf("%d\n", k);
for (int i = 0; i < k; i++)
for (int l = i + 1; l < k; l++) {
ans[i].push_back(num);
ans[l].push_back(num++);
... | 4 |
#include <bits/stdc++.h>
const double pi = acos(-1.0);
using namespace std;
int fact(int n) { return (n == 0) || (n == 1) ? 1 : n * fact(n - 1); }
void sieve(long long n) {
bool check[n + 1];
memset(check, true, sizeof(check));
for (long long i = 2; i * i <= n; i++)
if (check[i] == true)
for (long long ... | 0 |
#include <bits/stdc++.h>
using namespace std;
void print_arr(long long int arr[], long long int n) {
cout << '\n';
for (long long int i = 0; i < n; i++) {
cout << arr[i] << ' ';
}
cout << '\n';
}
void input_arr(long long int arr[], long long int n) {
for (long long int i = 0; i < n; i++) {
cin >> arr[... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const int M = 3e5 + 10;
int a[M], b[M];
int main() {
int n;
cin >> n;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for (int i = 0; i < n; i++) {
cin >> a[i];
int x = i;
int y = n - i - 1;
x = max(x, y);
if (x !=... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
long long int power(long long int a, long long int b) {
long long int res = 1;
a %= mod;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int main() {
long long int n;
cin >> n;
long... | 8 |
#include <bits/stdc++.h>
using namespace std;
int N, arr[100005], a, b, c;
int R, C, K;
int mat[15][15];
int u, v;
int main() {
int res = 0;
memset(mat, 0, sizeof(mat));
scanf("%d %d %d %d", &R, &C, &N, &K);
for (int i = 0; i < N; i++) {
scanf("%d %d", &u, &v);
mat[u][v] = 1;
}
for (int i = 1; i <= ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 150010;
const int INF = 0x7fffffff;
bool t[maxn];
long long q[maxn + 1];
queue<int> qu;
int main() {
int n, m;
while (scanf("%d%d", &n, &m) == 2) {
for (int i = 0; i < maxn; i++) {
q[i] = 0;
}
memset(t, false, sizeof(t));
for (int ... | 2 |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define Mp make_pair
#define pb push_back
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
mt19937 mrand(time(0));
#define debug(...) fprintf(stderr, __VA_ARGS__)
ll get(ll r) { return ((ll)mran... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const long long INF_LL = 1000000000000000000LL;
class tree {
int n;
vector<int> t;
public:
tree(int n) : n(n), t(n) {}
int len() { return n; }
void inc(int i, int v) {
for (; i < n; i |= i + 1) t[i] += v;
}
int sum(int r) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long a = 0;
char c = getchar();
while (c > '9' || c < '0') c = getchar();
while ('0' <= c && c <= '9') {
a = a * 10 + c - 48;
c = getchar();
}
return a;
}
struct data {
long long x, y, c;
data(long long X = 0, long long Y = 0,... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int N = 1e9;
int n, m;
long long X[maxn], T[maxn];
long long P[maxn], B[maxn];
int eat[maxn];
unordered_map<long long, int> M;
typedef struct node* pnode;
struct node {
long long ans;
pnode L, R;
node() {
ans = 0;
L = R = NULL;... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, m;
cin >> n >> m;
if (m > n)
cout << -1;
else if (m == n)
cout << n;
else {
long long int x, y;
for (y = (n / 2); y >= 0; y--) {
if (n - y >= 0) {
x = ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<pair<long long, long long> > v;
for (long long i = 0; i < n; i++) {
long long x, y;
cin >> x >> y;
v.push_back(ma... | 2 |
#include <bits/stdc++.h>
const int N = 1100;
using namespace std;
long long ans;
int n, m;
long long cnt[N];
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
int val;
cin >> val;
cnt[val]++;
}
ans = 1ll * n * (n - 1) / 2;
for (int i = 1; i <= m; i++) {
long long val = cnt[i];
ans ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[1505];
int main() {
int f = 0;
int n;
cin >> n;
cout << n << endl;
for (int i = 1; i <= n; i++) cout << 1 << " ";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int dp[N];
int pdp[2 * N];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int c, n;
cin >> c >> n;
++n;
pair<pair<int, int>, int> a[n];
a[0] = {{1, 1}, 0};
for (int i = 1; i < n; i++)
cin >> a[i].second >> a[i].fir... | 6 |
#include <bits/stdc++.h>
using namespace std;
int dcmp(double a, double b) {
return fabs(a - b) <= 0.00000000000001 ? 0 : (a > b) ? 1 : -1;
}
vector<int> vis(300000 + 9);
int main() {
int n, m, p, cnt = 0, i;
char c;
string s;
cin >> n >> m >> s;
for (i = 0; i < ((int)(s).size()); i++) {
if (s[i] == '.'... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, k, kk;
vector<int> a;
vector<int> bad, mod;
const int sz = 1000002;
inline bool check(int m) {
int c = kk;
for (int mm = m; mm < sz; mm += m)
if ((c -= bad[mm]) < 0) return false;
c = k;
for (int i = (int)(0); i < (int)(n); ++i) {
if (++mod[a[i] % m] ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1e9 + 7;
const int Maxn = 100 + 3;
long long dp[Maxn][Maxn], dp2[Maxn][Maxn], dp3[Maxn][Maxn], dp4[Maxn][Maxn];
vector<pair<int, int> > ord;
long long mul(long long a, long long b) { return (a * b) % Mod; }
long long bin_pow(long long b, long long p) {... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int x, y;
int id;
double rad;
point(int xx, int yy, int idd) {
x = xx;
y = yy;
id = idd;
}
bool operator<(const point &o) const { return rad < o.rad; }
void calRad(int xx, int yy) { rad = atan2(y - yy, x - xx); }
};
vector<int> e[200... | 7 |
#include <bits/stdc++.h>
using namespace std;
const double Pi = acos(-1.0);
const int MAXN = 1e6 + 5;
int n, m, t;
int flag;
struct NODE {
int a, b, c;
} q[MAXN];
vector<int> to[MAXN];
int ans[MAXN];
int cmp(NODE a, NODE b) { return a.c > b.c; }
int ma[5005][5005];
int dfs(int u, int f, int ed, int x, int index) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool setExists[500001];
int n;
int d;
int c[50];
int i, j;
int main() {
cin >> n >> d;
for (i = 0; i < n; i++) {
cin >> c[i];
}
setExists[0] = true;
for (i = 1; i <= n * 10000; i++) {
setExists[i] = false;
}
for (i = 0; i < n; i++) {
for (j = i * 1... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 5e5 + 50;
long long n, p;
map<long long, long long> cnt;
vector<long long> x;
long long binpow(long long a, long long b) {
long long ret = 1;
while (b) {
if (b & 1) {
ret *= a;
ret %= mod;
}
a *=... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long modpow(long long b, long long e, long long mod) {
long long ans = 1;
for (; e; b = b * b % mod, e /= 2)
if (e & 1) ans = ans * b % mod;
return ans;
}
const int N = 5050;
int dp[N][N][2], c[N], n;
bool vis[N][N][2];
int solve(int x, int y, int z) {
if (... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> sets;
vector<pair<int, int>> tiebreaks;
vector<pair<int, int>> results = {{3, 0}, {3, 1}, {3, 2},
{2, 3}, {1, 3}, {0, 3}};
int dp[4][4][205][205];
void fill() {
for (int i = 0; i < 24; i++) {
sets.push_back({25,... | 7 |
#include<bits/stdc++.h>
#define int_max 1000000000000000
#define mod 1000000007
#define nl cout<<endl;
typedef long long ll;
using namespace std;
inline ll max(ll a,ll b){ return((a<b)?b:a);}
inline ll min(ll a,ll b){ return((a<b)?a:b);}
void sily()
{
int t;
cin>>t;
while(t--)
{
int n,ss,i,rr,bb... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 1000005;
const double PI = 4 * atan(1);
long long m, x, y, n, p, z, k;
long long h1, m1, h2, m2;
char c, cc;
int main() {
ios::sync_with_stdio(0);
cin >> h1 >> c >> m1 >> h2 >> cc >> m2;
x = (h2 - h1) * 60 + m2 - m1;
x /= 2;... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<int> v1, v2, v3;
while (n--) {
int temp;
scanf("%d", &temp);
if (temp > 0)
v1.push_back(temp);
else if (temp < 0)
v2.push_back(temp);
else
v3.push_back(temp);
}
if (v2.size() % 2 =... | 1 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
int main() {
int n, i, len;
char word[101];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", word);
if ((len = strlen(word)) > 10) {
printf("%c%d%c\n", word[0], len - 2, word[len - 1]);
} ... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, x;
scanf("%d%d", &n, &x);
if (n < 2) n = 2;
int ans = ((n - 2) + x - 1) / x + 1;
printf("%d\n", ans);
}
int main() {
int t;
scanf("%d", &t);
while (t--) solve();
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, s;
long long c[1000010], w[1000010], k[1000010];
long long zhi[1000010], ying[1000010];
struct node {
long long x, y;
bool operator<(const node &xx) const { return xx.x < x; }
};
priority_queue<node> a;
node aaa;
int main() {
cin >> n >> m;
for (int ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, arr[202];
int ans = 0;
int main() {
scanf("%d", &n);
for (int i = 0; i < 2 * n; i++) scanf("%d", &arr[i]);
for (int i = 0; i < 2 * n; i += 2) {
for (int j = i + 1; j < 2 * n; j++) {
if (arr[i] == arr[j]) {
for (int k = j; k >= i + 2; k--) swap... | 3 |
#include <bits/stdc++.h>
using namespace std;
int dp[2001][2001] = {}, content[2001] = {}, content_size = 0;
;
const int mod = 1000003;
bool parse(string s) {
int state = 0;
for (int i = 0; i < s.size(); ++i) {
if (isdigit(s[i])) {
int j = i;
while (isdigit(s[j])) {
++j;
}
i = j ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
vector<int> p, a;
int n;
char s[N];
int sum[N], dp[N];
bool used[N];
int get(int x, int y) {
y++;
if (x < 0) x = 0;
if (x > y) return 0;
return sum[y] - sum[x];
}
bool can(int x) {
dp[0] = -1;
for (int i = 0; i < p.size(); i++) {
dp[i ... | 8 |
#include <bits/stdc++.h>
using namespace std;
char s[100];
int main() {
int x;
int trans[] = {4, 1, 3, 2, 0, 5};
int t[6];
int y = 0;
scanf("%d", &x);
for (int i = 0; i < 6; i++) t[trans[i]] = i;
for (int i = 0; i < 6; i++) {
if (x >> (i)&1) {
y |= (1 << trans[i]);
}
}
printf("%d\n", y);... | 5 |
#include <bits/stdc++.h>
int main() {
int n, q;
scanf("%d", &q);
while (q--) {
scanf("%d", &n);
if (n == 2)
printf("2\n");
else if (n % 2 == 0)
printf("0\n");
else
printf("1\n");
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> temp(n);
for (int& i : temp) cin >> i;
vector<vector<long long>> dp(10, vector<long long>(n));
dp[0][0] = dp[1][0] = temp[0];
for (int i = 1; i < n; i++) {
dp[0]... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, j, i;
cin >> t;
while (t--) {
int n, k1, k2;
cin >> n >> k1 >> k2;
vector<int> v1;
vector<int> v2;
int x, y;
for (i = 0; i < k1; i++) {
cin >> x;
v1.push_back(x);
}
for (j = 0; j < k2; j++) {
cin >>... | 0 |
#include <bits/stdc++.h>
using namespace std;
int pos[300005], s[300005];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= int(n); i++) {
int x;
scanf("%d", &x);
pos[x] = i;
}
for (int i = 1; i <= int(m); i++) {
int l, r;
scanf("%d%d", &l, &r);
int x = max(pos[l], pos... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int P[N + 1];
vector<int> S;
int n, k, maxPopped;
bool Check() {
for (int i = 1; i < (int)S.size(); ++i)
if (S[i] > S[i - 1]) return false;
return true;
}
void Read() {
scanf("%d %d", &n, &k);
int needed = 1;
S.push_back(n + 1);
for (int i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int mac = 2e3 + 10;
int a[mac], vis[mac];
int ask(int pos) {
printf("? %d\n", pos + 1);
fflush(stdout);
char s[5];
scanf("%s", s);
if (s[0] == 'Y') return 1;
return 0;
}
int main(int argc, char const *argv[]) {
int n, m;
scanf("%d%d", &n, &m);
int bl... | 10 |
#include <bits/stdc++.h>
long long flag[1000005];
int main(void) {
int n, i, x, a;
long long sum = 0;
scanf("%d%d", &n, &x);
for (i = 1; i <= n; i++) {
scanf("%d", &a);
flag[a]++;
}
for (i = 1; i <= 100000; i++) sum += flag[i] * (flag[i ^ x]);
if (x == 0) {
sum = 0;
for (i = 1; i <= 100000... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long n, k;
cin >> n >> k;
vector<long long> v;
map<long long, long long> mymap;
for (long long i = 0; i <= n - 1; i++) {
long long a;
cin >> a;
v.push_back(a);
}
for (long long i = 0; i <= ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int arr[n * 2];
for (int i = 0; i < n * 2; i++) arr[i] = i + 1;
for (int i = 1; i < n * 2; i++) {
if (arr[i] - 1 == k) {
swap(arr[1], arr[i]);
swap(arr[0], arr[1]);
if (k % 2 == 1 && k != 1) swap(arr[i], ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int mod;
long long int dp[5005][5005];
long long int C[5005];
long long int n, m;
long long int a[1000006];
long long int ans[2][5005];
long long int sum[2];
int main() {
scanf("%I64d%I64d%I64d", &n, &m, &mod);
for (long long int i = 0; i < ((long long int)(n)... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
vector<bool> arr;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> a >> b;
long long sum = 0;
arr.resize(n);
char ch;
for (int i = 0; i < n; i++) {
cin >> ch;
arr[i] = 1;
if (ch == '.') arr[i] = 0;
}
if (a < b) swap... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
for (int i = k + 1; i >= 1; i--) cout << i << " ";
for (int i = k + 2; i <= n; i++) cout << i << " ";
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int ans = 0, x = 1;
string s;
cin >> s;
while (x == 1) {
x = 5;
for (int i = 0; i < s.length(); i++) {
if (s[i] == s[i + 1]) {
ans++;
if (i == 0) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 4;
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
v... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct Water {
int degree;
double v;
} w[200005];
bool cmp(Water a, Water b) { return a.degree < b.degree; }
int main() {
int n, l, r, i;
double v = 0, ans = 0, T, engl, engr;
cin >> n >> T;
for (i = 0; i < n; i++) scanf("%lf", &w[i].v);
for (i = 0; i < n; i++... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0xffffffffffffff;
const int N = 300 + 5;
const int mod = 998244353;
int main() {
int n, ans;
scanf("%d", &n);
int tp = 1, sttp = 1, ip = 0;
for (int i = 1; i <= n; i++) {
tp = sttp;
if (tp > 0) ip++;
for ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, k, k1;
string s1, s2, s;
int main() {
cin >> n;
cin >> s1;
k = 1;
k1 = 0;
for (int i = 1; i < n; i++) {
cin >> s;
if (s1 == s)
k++;
else {
k1++;
s2 = s;
}
}
if (k > k1)
cout << s1;
else
cout << s2;
return 0;... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int delt = 'a' - 'A';
const int one = '1';
const int L = 'L' + delt;
bool _equal[1000][1000];
string new_login, old_login;
int cnt_old;
int main() {
cin >> new_login;
for (int i = 0; i < new_login.size(); i++) {
if (('A' <= new_login[i] && new_login[i] <= 'Z')... | 2 |
#include <bits/stdc++.h>
const int INF = 1000000000;
const int MAXN = 500;
int l[2][MAXN], w[MAXN], h[2][MAXN], c[MAXN];
int ceil(int num, int denom) { return (num / denom) + (num % denom > 0); }
int main() {
int n, m, i, j, cost, tmp, ans = 0;
scanf("%d", &n);
for (i = 0; i < n; ++i) scanf("%d%d%d", &l[0][i], w ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int l[100005], r[100005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int lft = 0;
int rgt = 0;
for (int i = 1; i <= n; i++) {
cin >> l[i] >> r[i];
lft += l[i];
rgt += r[i];
}
l[0] = r[0] = 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
string s;
int k;
int f[500];
int main() {
cin >> k;
cin >> s;
int len = s.size();
for (int i = 0; i < len; i++) f[s[i] - 'a']++;
for (int i = 0; i < 26; i++)
if (f[i] % k != 0) {
cout << -1;
return 0;
}
for (int k1 = 1; k1 <= k; k1++)
for... | 1 |
#include <bits/stdc++.h>
inline long long read() {
long long x = 0;
char ch = getchar(), w = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * w;
}
void write(long long x) {
if (... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned int x, y, z, c;
cin >> x >> y >> z;
c = sqrt((y * z) / x);
cout << 4 * (c + (y / c) + (z / c));
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
bool adj[100 + 1][100 + 1];
int a[100 + 1];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> a[i];
memset(adj, 0, sizeof(adj));
int u, v;
for (int j = 0; j < m; ++j) {
cin >> u >> v;
adj[u][v] = true;
adj[v][u] = true;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MXN = 2e6 + 30;
const int MAXN = 1e3 + 2;
const long long INF = 1e9 + 7;
const long long BINF = 1e15;
const int MOD = 1e9 + 7;
const long double EPS = 1e-15;
const long long dx[] = {0, 0, 1, -1};
const long long dy[] = {1, -1, 0, 0};
long long n;
long long u, v;
l... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int p[2];
int cnt;
node() {
cnt = 0;
p[0] = -1;
p[1] = -1;
}
};
vector<node> v;
string tobin(int n) {
string ans = "";
while (n != 0) {
if (n % 2 == 0)
ans += '0';
else
ans += '1';
n /= 2;
}
for (int i = ans.... | 5 |
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
#define rep(i,j,n) for(int i=(j);i<=((int)n);++i)
#define rev(i,n,j) for(int i=(n);i>=((int)j);--i)
typedef long long int ll;
#define int long long int
const ll INFL=0x3f3f3f3f3f3f3f3fLL;
const int INF=0x3f3f3f3f;
const int mod=1000000007;
#define endl "\n"
#define... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
int cost[MAX];
vector<int> tims;
int main() {
int n;
scanf("%d", &n);
int cc = 0;
cost[0] = 0;
tims.push_back(-1);
int cpaid = 0;
for (int i = 1; i <= n; i++) {
int a;
scanf("%d", &a);
int val = cost[i - 1] + 20;
int in... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
long long L, v, l, r;
while (t--) {
cin >> L >> v >> l >> r;
long long ct = 0;
ct = L / v - (r / v - (l - 1) / v);
cout << ct << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 500;
bitset<N> mark;
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
long long t;
cin >> t;
while (t--) {
string s;
cin >> s;
char c[N];
for (long long i = 0; i < 500; ++i) c[i] = 'A';
mark.reset();
long... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[10];
int main() {
int n, x;
cin >> n >> x;
n = n % 6;
a[x] = 1;
while (n > 0) {
if (n % 2 == 0) {
swap(a[1], a[2]);
} else
swap(a[0], a[1]);
n--;
}
for (int i = 0; i <= 10; i++) {
if (a[i] == 1) {
cout << i;
break;... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
char b[maxn];
string cur;
int l, i;
vector<string> v;
int main() {
gets(b);
l = strlen(b);
for (i = 0; i < l; i++) {
if (b[i] == ' ') {
if (cur.size() && cur != " ") v.push_back(cur);
cur = " ";
continue;
}
if (b[i]... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
const long long INF = 1000000000000000018LL;
int n;
void odd(int n) {
while (n > 5) {
printf("%d - %d = %d\n", n, n - 1, 1);
printf("%d * %d = %d\n", n - 2, 1, n - 2);
n -= 2;
}
printf("5 - 2 = 3\n");
printf("3 - 1 = 2\n");
printf... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300000;
int aa[N], bb[N], cc[N], qu[3];
bool check(int *aa, int n, int m, int k) {
for (int i = 0; i < n; i++) bb[i] = aa[(i + k) % n];
m -= n;
for (int i = 0; i < n; i++) {
if (bb[i] == -1) continue;
for (int j = i, j_; (j_ = bb[j]) != -1; j = j... | 6 |
#include <bits/stdc++.h>
using namespace std;
int arr[26];
int main() {
string str;
int n, c = 0;
cin >> str >> n;
if (str.size() < n) {
cout << "impossible";
return 0;
}
for (int i = 0; i < str.size(); ++i) ++arr[str[i] - 'a'];
for (int i = 0; i < 26; ++i)
if (arr[i] > 0) ++c;
if (c >= n)
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int sum1 = 0, sum2 = 0, sum3 = 0, n1, n2, n3;
cin >> n1;
n2 = n1 - 1;
n3 = n2 - 1;
int temp;
while (n1--) {
cin >> temp;
sum1 += temp;
}
while (n2--) {
cin >> temp;
sum2 += temp;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int m) {
if (y == 0) return 1;
long long int a = power(x, y / 2, m);
if (y % 2) {
return (a * ((a * x) % m)) % m;
} else {
return (a * a) % m;
}
}
long long int mod_inverse(long long int x, lo... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve();
using ll = long long;
template <class T = ll>
using V = vector<T>;
using vi = V<int>;
using vl = V<>;
using vvi = V<V<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {
IoSetupNya() {
cin.tie(nullptr);
i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, b, c = 1000000000000000001, d = 0, e = 0;
cin >> n >> k;
long long a[k], err[k];
for (b = 0; b < k; b++) {
cin >> a[b];
err[b] = n % a[b];
}
for (b = 0; b < k; b++) {
if (c > err[b] && err[b] >= 0) {
c = err[b];
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int a = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' ||
s[i] == 'u') {
cout << s[i];
a = 0;
} else {
if (i != 0 && (s[i - 1] == 'a' || s[i - 1]... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, maxi = -1, mini;
scanf("%d %d", &n, &m);
priority_queue<int, std::vector<int>, std::greater<int> > q;
for (int i = 0, a; i < n; i++) {
scanf("%d", &a);
maxi = max(maxi, a);
q.push(a);
}
maxi += m;
while (m > 0) {
int p = ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005];
int n, m, seed, vmax;
set<int> s;
pair<long long, int> b[100005];
int rnd() {
int tmp = seed;
seed = (1ll * seed * 7 + 13) % 1000000007;
return tmp;
}
int power(int x, int y, int p) {
int s = 1 % p;
for (; y; y /= 2, x = 1ll * x * x % p)
i... | 9 |
#include <bits/stdc++.h>
const int S = 505;
int n, a[S], f[S][S], m, b[S], px[S][S], py[S][S];
inline int ma(int a, int b) { return a > b ? a : b; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
scanf("%d", &m);
for (int i = 1; i <= m; i++) scanf("%d", b + i);
for (int i = 1; ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[110], b[110], c[110], j = 0, k = 0, s1 = 0, s2 = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] >= 0) {
b[j++] = a[i];
} else {
c[k++] = a[i];
}
}
for (int i = 0; i < j; i++) {
s1 = s1 + b[i];... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a, m;
vector<int> hits;
int f(int s) {
if (s < a) return 0;
int times = (s - a) / (a + 1) + 1;
return times;
}
bool solve(int moves) {
if (moves == m + 1) return true;
vector<int> all;
for (int i = 0; i < moves; ++i) all.push_back(hits[i]);
sort(all.... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string pw, cd[10];
cin >> pw;
for (int i = 0; i < 10; i++) cin >> cd[i];
for (int j = 0; j < 8; j++) {
string pw2 = pw.substr(j * 10, 10);
for (int k = 0; k < 10; k++)
if (pw2 == cd[k]) {
cout << k;
break;
}
}
cou... | 0 |
#include <bits/stdc++.h>
const int N = 2010;
int n, sum;
int a[N][N];
bool vis[N];
void dfs(int x, int d) {
vis[x] = 1, sum++;
for (int i = 1; i <= n; i++)
if (!vis[i] && ((d && a[x][i]) || (!d && a[i][x]))) dfs(i, d);
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 50;
const long long int INF = 1000 * 1000 * 100;
bool mark[2][MAXN], check = 0;
int n, m;
vector<int> v[2][MAXN];
vector<pair<pair<int, int>, int> > e;
long long int dis[MAXN];
void dfs(int t, int s) {
mark[t][s] = 1;
for (int i = 0; i < v[t][s].... | 9 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, t, ones = 0, zeros = 0;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> t;
ones += t;
zeros += 1 - t;
}
if (ones <= n / 2) {
cout << zeros << endl;
for (int i = 0; i < zeros; ++i) cout << 0 << " ";
cout << endl;
} els... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
int a[maxn];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
long long ans = 0;
for (int i = 1; i <= n * k; i++) cin >> a[i];
int cnt ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int nextInt() {
int x = 0, p = 1;
char ch;
do {
ch = getchar();
} while (ch <= ' ');
if (ch == '-') {
p = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + (ch - '0');
ch = getchar();
}
return x * p;
}
const int N = 10... | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.