solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
using li = long long;
using ld = long double;
using pii = pair<int, int>;
const int INF = 2e9 + 13;
const int N = 3e5 + 13;
int a[N];
void solve() {
int n, k, d;
cin >> n >> k >> d;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int l = 0, r = 2 * k - 1;
for (... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[1005];
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
n = unique(a, a + n) - a;
for (int i = 2; i < n; i++)
if (a[i] - a[i - 2] == 2) {
cout << "YES\n";
return 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 5;
const long long mod = 1e9 + 7;
long long dp[N];
void pre() {
dp[3] = 4;
dp[4] = 4;
dp[5] = 12;
for (long long i = 6; i < N; i++) {
dp[i] = 4;
dp[i] += dp[i - 2];
dp[i] %= mod;
dp[i] += dp[i - 3];
dp[i] %= mod;
dp[... | 11 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-6;
int n, p;
int f(vector<int> v, long double k) {
double ans = 0;
double ans2 = 0;
for (int i = 0; i < n; i++) {
if (k < v[i]) {
ans += v[i] - k;
}
}
for (int i = 0; i < n; i++) {
if (v[i] < k) {
ans2 += k - v[i];
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n, m, k, x;
cin >> n >> m >> k;
map<int, int, greater<int> > s;
for (int i = 0; i < n; i++) {
cin >> x;
s[x]++;
}
for (int i = 0; i < m; i++) {
cin >> x;
s[x]--;
}
int now = 0;
for (map<i... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double pi = 3.1415926535;
double r, n;
cin >> n >> r;
double ans, d;
d = (n - 2) / n * pi;
d /= 2;
ans = r * cos(d) / (1 - cos(d));
cout << fixed << setprecision(7) << ans << endl;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300000;
const int INF = 1000000000;
const int MAXV = 40;
int n;
int a[MAXN];
int dp[2][MAXV + 1];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i <= MAXV; i++) dp[0][i] = INF;
dp[0][0] = 0;
int t = 0... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const double PI = 2 * acos(0.0);
const double eps = 1e-9;
int n, m, x, l, f;
int main() {
ios_base::sync_with_stdio(false);
int arr[100010];
memset(arr, -1, sizeof(arr));
cin >> n;
int cnt = 0, previdx, prevval;
if (n % 2 == 1) arr[n / 2... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum = 0, ans = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
for (int i = 0; i < n; i++) {
if ((sum - a[i]) % 2 == 0) ans++;
}
cout << ans;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
string s, t;
cin >> s >> t;
int n = s.length();
int m = t.length();
int a[m], b[m];
int i = 0, k = 0;
while (i < n && k < m) {
if (t[k] == s[i]) {
a[k] = i;
k++;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q, used[300005], d[300005], up[300005], mn[300005], mx[300005],
sf[300005];
vector<int> g[300005];
pair<int, int> t[4 * 300005];
long long pr[300005];
pair<int, int> merge(pair<int, int> a, pair<int, int> b) {
return make_pair(max(a.first, b.first), min(a.se... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int md = 1000000007, MX = 105;
int n, G[MX][MX];
struct poly {
int a[MX];
poly() { memset(a, 0, sizeof(a)); }
inline int &operator[](const int x) { return a[x]; }
inline int deg() {
for (int i = n; i; i--)
if (a[i - 1]) return i;
return 0;
}
... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.writ... | 2 |
#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;
while (t--) {
char arr[9][9];
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
cin >> arr[i][j];
if (arr[i][j] == '2') arr[i][j] =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
int sum[n], dp[n][2];
sum[n - 1] = a[n - 1];
dp[n - 1][0] = 0;
dp[n - 1][1] = a[n - 1];
for (int i = n - 2; i >= 0; i--) {
sum[i] = sum[i + 1] + a[i];
dp... | 7 |
#include <bits/stdc++.h>
const double pi = 4.0 * atan(1.0);
const double e = exp(1.0);
const int maxn = 1e6 + 8;
const long long mod = 1e9 + 7;
const unsigned long long base = 1e7 + 7;
using namespace std;
string s, t;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
pair<long long, long long> intersect(pair<long long, long long> a,
pair<long long, long long> b) {
return make_pair(a.first * (b.second - a.second),
a.second * (b.first... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, t, x;
cin >> m;
n = m;
t = 0;
while (n % 10 == 0) {
n = n / 10;
}
m = n;
while (n > 0) {
x = n % 10;
t = t * 10 + x;
n = n / 10;
}
if (t == m)
cout << "YES";
else
cout << "NO";
return 0;
}
| 1 |
#include <bits/stdc++.h>
int sg[] = {
0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,
8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10,
};
int main() {
int n, x, kk = 0;
scanf("%d", &n);
for (int i =... | 13 |
#include <bits/stdc++.h>
using namespace std;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
long long int SPF(long long int n) {
long long int i;
for (i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
return i;
}
}
return n;
}
int main() {
fastio();
int T = 1;
while (T--... | 2 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int p[2000], score[2000];
char name[2000][20];
int i, n;
int main() {
scanf("%d", &n);
int cnt = 0;
for (i = 1; i <= n; i++) {
char s[20];
int num;
scanf("%s%d", s, &num);
if (mp.find(s) != mp.end()) {
int x = mp.find(s)->sec... | 6 |
#include <bits/stdc++.h>
const int C = 200001, D = 26;
int sget2(char tab[]) {
bool ff = 0;
for (int z = 0;; z++) {
tab[z] = getchar();
if (tab[z] > 32) ff = 1;
if (tab[z] <= 32 && ff == 1)
return z;
else if (tab[z] <= 32)
z--;
}
}
int p[C], p2[C], pt[C][D], ptb[C][D], fst[26];
int cha... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MX = (309), MOD = 1e9 + 9;
int comb[MX][MX], sz[MX], faksan[MX];
vector<int> v[MX];
int dp[MX][MX], compy;
int results[MX][MX];
int n;
void dfs(int x, int p) {
sz[x] = 1;
long long indp[2][MX];
memset(indp, 0, sizeof(indp));
bool phase = 0;
indp[0][0] = ... | 21 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int l, r;
int loA, hiB;
bool good;
};
Node seg[1000000];
int N, M, Q;
set<int> stA[200005], stB[200005];
set<pair<int, int>> st;
void build(int l, int r, int idx) {
seg[idx].good = 1;
seg[idx].l = l;
seg[idx].r = r;
seg[idx].hiB = 1e9;
if (l ==... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, t;
cin >> n >> k >> t;
if (t <= k)
cout << t;
else if (t > k and t <= n)
cout << k;
else if (t > n)
cout << n - (t - k);
return 0;
}
| 0 |
#include <bits/stdc++.h>
const int mod = 998244353;
const int gmod = 3;
const int inf = 1039074182;
const double eps = 1e-9;
const double pi = 3.141592653589793238462643383279;
const long long llinf = 2LL * inf * inf;
template <typename T1, typename T2>
inline void chmin(T1 &x, T2 b) {
if (b < x) x = b;
}
template <t... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, cnt[6], flg;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int edg1, edg2;
cin >> edg1 >> edg2;
cnt[edg1]++;
cnt[edg2]++;
}
for (int i = 1; i < 6; i++) {
if (cnt[i] != 2) {
cout << "WIN" << endl;
return 0;
}
}
co... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int to, next;
} a[200001];
int vis[100001], st[100001], cnt = 0;
void add(int x, int y) {
a[++cnt] = (node){y, st[x]};
st[x] = cnt;
}
bool dfs(int x, int y) {
if (vis[x])
if (vis[x] + y == 3)
return 0;
else
return 1;
vis[x] = y;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
void solve() {
int n;
cin >> n;
string s, c;
cin >> s;
c = "xxx";
int ans = 0;
int i = 0;
while (i < n) {
if (s.find(c, i) != string::npos && (s.find(c, i) == i)) {
ans++;
}
i++;
}
cout << ans << "\n";
}
int... | 0 |
#include <bits/stdc++.h>
using namespace std;
int read() {
char c;
int num, f = 1;
while (c = (char)getchar(), !isdigit(c))
if (c == '-') f = -1;
num = (int)(c - '0');
while (c = (char)getchar(), isdigit(c)) num = num * 10 + (int)(c - '0');
return num * f;
}
int n, m;
vector<int> a;
long long greaterCou... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, s;
cin >> s >> a >> b >> c;
if (a + b + c == 0) {
printf("0 0 0 ");
return 0;
}
printf("%.18lf %.18lf %.18lf ", (double)s / (a + b + c) * a,
(double)s / (a + b + c) * b, (double)s / (a + b + c) * c);
return 0;
}
| 10 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long n, sum;
cin >> n >> sum;
cout << (sum + n - 1) / n;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long int ncr(long long int n, long long int r) {
if (n == r) return 1;
if (r == 1) return n;
return ncr(n - 1, r) + ncr(n - 1, r - 1);
}
long long int fact(long long int n) {
long long int i, res = 1;
for (i = 2; i <= n; i++) res *= i;
return res;
}
int mai... | 5 |
#include <bits/stdc++.h>
const int mod = ((1E9) + 7);
const int intmax = ((1E9) + 7);
using namespace std;
long long aa[100005];
int main() {
int test, a, b, c, n;
scanf("%d", &n);
for (int i = 0; i < n; i++) cin >> aa[i];
long long prev = aa[0];
long long steps = 0;
for (int i = 1; i < n; i++) {
if (aa... | 6 |
#include <bits/stdc++.h>
using namespace std;
int N, M, k, c, d;
string s;
int main() {
scanf("%d%d%d%d%d", &c, &d, &N, &M, &k);
if (N * M <= k) {
cout << 0;
return 0;
}
int mi = c * M;
for (int x = 0; x * N <= N * (M + 1) - k; ++x) {
int y = max(0, N * M - k - x * N);
int z = x * c + y * d;
... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC optimize(2)
using namespace std;
const long long inf = 1e9;
long long dp[2511 << 1][2511][2];
long long h[2511 << 1];
int n;
int main() {
int i, j, k;
scanf("%d", &n);
for (i = 1; i <= n; ++i) scanf("%I64d", &h[i]);
h[0] = h[n + 1] = -inf;
k = n / 2... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int sum, limit, x = 0;
vector<int> s;
vector<pair<int, int>> lowbit;
cin >> sum >> limit;
for (int i = 1; i <= limit; i++) lowbit.push_back(make_pair(i & -i, i));
sort(lowbit.begin(), lowbit.end());
for (int i = lowbit.size() - 1; i >= 0; i--) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
double c[10005];
int pp[10005];
int q[10005];
int all;
int n, t;
double prop[10005];
double F[10005];
double P[5005][5005];
double p[10005];
int main() {
scanf("%d %d", &n, &t);
for (int i = 0; i < n; ++i) {
scanf("%d %d", &pp[i], &q[i]);
pp[i] = 100 - pp[i];
... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long int a, b;
void print(long long int a, long long int b) {
cout << "! " << a << " " << b << endl;
}
long long int ask(long long int c, long long int d) {
cout << "? " << c << " " << d << endl;
long long int ret;
cin >> ret;
return ret;
}
int main() {
ios... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int a[N], n, m;
bool check(int i, int j) {
int x1 = (i - 1) / m + 1;
int y1 = (i - 1) % m + 1;
int x2 = (j - 1) / m + 1;
int y2 = (j - 1) % m + 1;
for (int k = 0; k < 4; k++)
if (x1 +... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
if (n % 2 == 1)
cout << n / 2;
else {
int l = 1;
while (l <= n) l *= 2;
l /= 2;
cout << (n - l) / 2;
}
}
| 15 |
#include <bits/stdc++.h>
using namespace std;
bool igual(long double a, long double b) { return fabs(a - b) < 1e-9; }
bool maior(long double a, long double b) { return a > 1e-9 + b; }
bool menor(long double a, long double b) { return a + 1e-9 < b; }
bool maiorIgual(long double a, long double b) {
return maior(a, b) |... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 710, mod = 1e9 + 7;
long long n, ans, a[N], dp[N][N][10][2];
char s[N];
signed main() {
scanf("%s", s + 1);
n = strlen(s + 1);
for (long long i = 1; i <= n; i++) a[i] = s[i] - '0';
for (long long i = 1; i <= 9; i++) dp[0][0][i][0] = 1;
for (lon... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a[500005];
vector<int> G[500005];
bool min_sud = 0;
int ans = 0;
void dfs(int u, int fa, int d) {
if (G[u].size() == 1 && d % 2 == 1 && fa != 0) {
min_sud = 1;
}
int num = -1;
for (auto to : G[u]) {
if (G[to].size() == 1) {
nu... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d;
cin >> n >> d;
int ar[n];
for (int i = 0; i < n; i++) cin >> ar[i];
sort(ar, ar + n);
int m;
cin >> m;
long long ans = 0;
for (int i = 0; i < min(n, m); i++) {
ans += ar[i];
}
if (m > n) {
ans -= (m - n) * d;
}
cout <... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const int N = 1005;
const int mod = 1e9 + 7;
int n, k;
long long ppow(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) {
res *= a;
res %= mod;
}
a *= a;
a %= mod;
b >>= 1;
}
return res;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool deb_mode = 0;
class debugger {
vector<string> vars;
public:
template <typename T>
debugger &operator,(const T v) {
stringstream ss;
ss << v, vars.push_back(ss.str());
return *this;
}
void printall() {
int j = 0, l = vars.size();
for (int... | 12 |
#include <bits/stdc++.h>
using namespace std;
void prefixsum(double a[], int size, double b[]) {
b[0] = a[0];
for (int i = 1; i < size; i++) {
b[i] = b[i - 1] + a[i];
}
}
int findmaxnumber(double b[], int size) {
map<double, int> a;
for (int i = 0; i < size; i++) {
if (a.find(b[i]) == a.end()) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;
template <typename T>
vector<T> get_vector(long long int size) {
vector<T> out;
for (long long int sahdfjhfsk = 0; sahdfjhfsk < size; ++sahdfjhfsk) {
T temp;
cin >> temp;
out.push_back(temp);
}
return out;
}
struct Node {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
map<int, int> mpOdd, mpEven;
mpEven[0]++;
int c = 0;
for (int i = 1; i <= n; i++) {
int temp;
cin >> temp;
c ^= temp;
if (i % 2 == 1)
mpOdd[c]++;
else
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const long long INFL = 1e18 + 123;
const double PI = atan2(0, -1);
mt19937 tw(960172);
long long rnd(long long x, long long y) {
static uniform_int_distribution<long long> d;
return d(tw) % (y - x + 1) + x;
}
void solve() {
int n, k;
cin >> ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<long long, int> taken;
int n, k;
cin >> n >> k;
long long ans = 0;
long long array[100100];
for (int i = 0; i < n; i++) {
long long a;
scanf("%lld", array + i);
}
sort(array, array + n);
for (int i = 0; i < n; i++) {
if (array[... | 7 |
#include <bits/stdc++.h>
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
long long mod = (1000000007LL);
inline long long Mod(long long a, long long b) { return (a % b); }
inline long long poww(long long a, long long b) {
long long res = 1;
while (b > 0)... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long N, m;
cin >> N >> m;
long long arr[N + 1];
for (int x = 1; x <= N; x++) cin >> arr[x];
long long cum[N + 2];
cum[0] = 0;
for (int x = 1; x <= N; x++) {
cum[x] = cum[x - 1] + arr[x];
}
long long NuOfl;
for (int x = 0; x < m; x++... | 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int main() {
string str;
int k;
cin >> str >> k;
int a[300];
memset(a, 0, sizeof(a));
for (int i = 0; i < str.length(); i++) {
a[str[i] + 150]++;
}
vector<pair<int, char> > v;
for (int i = 0; i < 300; i++) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
;
vector<int> a, b;
for (int i = 0; i < 2 * n; ++i) {
char c;
cin >> c;
a.push_back(c == '0' ? 0 : 1);
}
for (int i = 0; i < 2 * n; ++i) {
char c;
cin >> c;
b.push_back(c == '0' ? 0 : 1);
}
int ca = 0, ... | 7 |
#include <bits/stdc++.h>
using namespace std;
char q[100001];
int cnt[3][100001];
int main() {
cin >> q;
int length = strlen(q);
for (int i = 0; i <= length; i++)
if (i == 0)
cnt[0][i] = cnt[1][i] = cnt[2][i] = 0;
else {
cnt[0][i] = cnt[0][i - 1];
cnt[1][i] = cnt[1][i - 1];
cnt[2][... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[4] = {};
cin >> n;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
a[x]++;
}
sort(a + 1, a + 4);
cout << a[1] + a[2];
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a, b = -1, x, y, i, j, m[300005];
pair<int, int> p[300005];
int main() {
cin >> n >> k;
while (i < n) {
cin >> m[i];
p[i].first = m[i];
if (p[i].first == 0) {
p[i].second++;
p[i].first++;
}
p[i].first += p[i - 1].first;
p[i]... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 10;
int main() {
ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0),
cout.tie(0);
;
long long n, k, q, odds, evens;
cin >> n >> k >> q;
if (!(n & 1)) {
odds = n, evens = 0;
long long energy = (n >> 1);
if (... | 11 |
#include <bits/stdc++.h>
using namespace std;
char s[3][1000010];
int n;
unsigned long long bs[1000010], base = 233;
struct str_hash {
unsigned long long v[1000010];
void init(char s[]) {
for (int i = 1; i <= n; i++) v[i] = v[i - 1] * base + s[i];
}
unsigned long long get(int l, int r) {
return v[r] - v... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
const double inf = 1e9;
const long long mod = 1e9 + 7;
long long _pow(long long a, long long b) {
long long ans = 1;
while (b) {
if (b & 1) ans = ans * a;
a = a * a;
b >>= 1;
}
return ans;
}
long long gcd(long long a, long long... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long a[110000], n, sum[110000];
long long solve(long long k) {
long long now = n - 1, temp = 0, kk = k;
while (1) {
temp = temp + sum[now];
if (now <= kk) break;
now -= kk;
kk = kk * k;
}
return temp;
}
int main() {
long long k, i, q, ans;
s... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[100013], ans[100013];
long long sum;
int main() {
while (scanf("%d %d", &n, &m) != EOF) {
sum = 0;
int fl = 1;
for (int i = 1; i <= m; i++) {
scanf("%d", &a[i]);
a[i]--;
sum += a[i] + 1;
if (a[i] + 1 > n - i + 1) fl = 0;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int tc[300];
int num[350];
int n, id, length, i, j, dif;
int main() {
length = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &tc[i]);
if (i == 0)
dif = tc[i];
else
dif = tc[i] - tc[i - 1];
if (dif > 0) {
for (id = 0; dif >... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double conv = 180 / acos(-1);
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
;
int n, i, x, y;
cin >> n;
cout << fixed;
vector<double> angles;
for (i = 0; i < n; i++) {
cin >> x >> y;
if (x > 0 && y > 0)
angles.push_back(atan(y / d... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int tt;
cin >> tt;
while (tt--) {
long long n, a, b;
cin >> n >> a >> b;
auto chk = [&](long long x) {
long long s = x / (a + b) * a;
x %= a + b;
s += min(x, a);
return... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, a;
double abss(double num) {
if (num < 0) return -num;
return num;
}
int main() {
scanf("%d %d", &n, &a);
double ang = 180.0 / n;
int idx = 0;
double diff = 180.0;
for (int i = 1; i <= n - 2; i++) {
if (diff > abss(ang * i - a)) {
idx = i;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[101][101];
int pure[101][101];
bool check() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i][j] == 1) continue;
for (int k = 0; k < n; k++) {
pure[i][k] = 1;
pure[k][j] = 1;
}
}
}
bool ans = ... | 7 |
#include <bits/stdc++.h>
int n, k, A;
double ans = 0.0;
int b[10], l[10];
void search(int id, int num) {
if (id == n) {
double slv = 0.0;
int len = 1 << n;
for (int u = 0; u < len; u++) {
int B = 0, count = 0;
double tmp = 1.0;
for (int i = 0; i < n; i++) {
int v = 1 << i;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
vector<int> divisors(int n) {
vector<int> divisors;
divisors.reserve(n);
for (int i = 1; i < n; ++i) {
if (n % i == 0) {
divisors.push_back(i);
}
}
return divisors;
}
template <class T>
T mod(T arg, T mod) {
arg %= mod;
if (arg < 0) {
arg += ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, k, temp[2] = {0};
string s, t;
cin >> s >> t;
n = s.length();
for (i = 0; i < n; i++) {
if (s[i] != t[i]) {
if (s[i] == '4')
temp[0]++;
else
temp[1]++;
}
}
cout << max(temp[0], temp[1]);
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
if (n * (n - 1) / 2 <= k)
cout << "no solution" << endl;
else {
for (int i = 1; i <= n; i++) cout << 0 << " " << i << endl;
}
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int a, b, c, d;
cin >> a >> b >> c >> d;
int x, y, x1, y1, x2, y2;
cin >> x >> y >> x1 >> y1 >> x2 >> y2;
if (y1 == y2) {
if (c || d) {
cout ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 1000 * 1000 + 24;
long long a, b, p, x, ans;
long long pw(int x, int y, int mod) {
if (y == 0) return 1;
long long t = pw(x, y / 2, mod);
t = 1LL * t * t % mod;
if (y & 1) t = 1LL * t * x % mod;
return t;
}
int main() {
cin.tie(0), cout.t... | 13 |
#include <bits/stdc++.h>
int main() {
using namespace std;
int T, a, b, c, d;
int x, y, sum = -1;
char s[100005];
cin >> T >> a >> b >> c >> d;
for (int i = 0; i < T; i++) cin >> s[i];
x = a - c;
y = b - d;
for (int i = 0; i < T; i++) {
if (x >= 0 && s[i] == 'W') {
x--;
if (x <= 0) x =... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100002;
int n, m, k, p, ans, sum, t, tot, cnt, a[N], b[N], d[N], to[N], nxt[N], head[N],
du[N], rt;
inline int read() {
register int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, a[100005], b[100005][32], t2[35], pos, d, cnt;
string s1, s2;
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
for (int i = 0; i <= 100002; i++) {
for (int j = 0; j <= 31; j++) {
b[i][j] = 0;
}
}
t2[0] = 1;
for ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
int n;
scanf("%d", &n);
map<int, pair<int, int> > mp;
map<int, int> lng;
int ai;
for (int i = 0; i < n; i++) {
scanf("%d", &ai);
lng[ai]++;
}
int m;
scanf("%d", &m);
vector<int> b(m), c(m);
for (int i = 0; i < ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, t, el;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
while (t--) {
cin >> n >> m;
long long lin[n + 1], col[m + 1];
for (int i = 1; i <= n; ++i) {
lin[i] = 0;
for (int j = 1; j <= m; ++j) {
if... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
int n, m, x, y, i, k, sum = 0;
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> x >> y;
sum += (x * y);
v.push_back(sum);
}
for (i = 0; i < m; i++) {
cin >> k;
vector<int>::iterator idx;
idx = lower_bound(v.begin(... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long ipow(long long a, long long b) {
long long res = 1;
while (true) {
if (b & 1) res *= a;
b >>= 1;
if (!b) break;
a *= a;
}
return res;
}
void solve() {
long long n, b, d;
cin >> n >> b >> d;
vector<long long> a(n);
for (long long i =... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, z;
int a, b, c;
cin >> x >> y >> z;
cin >> a >> b >> c;
int t1 = a + b + c;
int t2 = a + b;
int t3 = a;
t1 -= x + y + z;
if (t1 < 0) {
cout << "NO";
return 0;
}
t2 -= x + y;
if (t2 < 0) {
cout << "NO";
return 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > vec;
vector<vector<int> > adj;
vector<bool> vst;
bool dfs(int i, int target) {
if (i == target) return true;
vst[i] = true;
for (int j = 0; j < adj[i].size(); ++j) {
int to = adj[i][j];
if (!vst[to])
if (dfs(to, target)) return 1;... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long ost = 1e9 + 7;
void solve() {
int n, k;
cin >> n >> k;
vector<int> v(n * k);
int pos = n * k;
long long suma = 0;
for (int i = 0; i < n * k; i++) cin >> v[i];
for (int i = 0; i < k; i++) {
pos -= n / 2 + 1;
suma += v[pos];
}
cout <<... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, a[10], m;
int Va(int a[]) {
int res = 0;
for (int i = 1; i <= n; i++) {
int mi = a[i];
for (int j = i; j <= n; j++) {
mi = min(mi, a[j]);
res += mi;
}
}
return res;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) a[i] = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 2147483647;
long long read() {
long long first = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
first = first * 10 + ch - '0';
ch = getch... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const long double eps = 1e-6;
const int mod = 998244353;
const int maxn = 200 + 10;
const int N = 2e5 + 50;
const int M = N * 20;
const long long mm = (1LL << 32);
template... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
long long int modexp(long long int base, long long int exp) {
if (exp == 1)
return base;
else if (exp == 0)
return 1;
else {
if (exp % 2 == 0) {
long... | 4 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> even, odd;
map<int, int> m;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x & 1) {
odd.push_back(x);
} else {
even.push_back(x);
m[x]++;
}
}
long long e = even.size(), o = o... | 3 |
#include <bits/stdc++.h>
using namespace std;
int arr[505000], ans;
void updata(int l, int r) {
int i = l + 1, j = r - 1;
while (i <= j) {
arr[i] = arr[l];
arr[j] = arr[r];
i++, j--;
}
ans = max(ans, (r - l) / 2);
}
int main() {
int n;
scanf("%d", &n);
ans = 0;
int st = 0, ed = 0;
for (int... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int l = 0, r = 0;
for (char c : s) {
if (c == '-')
l++;
else
r++;
}
if (r == 0 || l % r == 0)
cout << "YES";
else
cout << "NO";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
int MI = -1e6 - 10;
int MA = 1e6 + 10;
int seg_tree[2][(long long)8e6];
int get_mid(int f, int t) { return f + (t - f) / 2; }
int left_child(int id) { return id * 2 + 1; }
void insert(int ID, int n, int v, int f, int t) {
... | 22 |
#include <bits/stdc++.h>
using namespace std;
bool dp[55][14 * 4][14 * 4][14 * 4];
int a[55];
int f(char s[]) {
int f, ss;
if (s[0] == 'A')
f = 0;
else if (s[0] == 'K')
f = 12;
else if (s[0] == 'Q')
f = 11;
else if (s[0] == 'J')
f = 10;
else if (s[0] == 'T')
f = 9;
else
f = s[0] - ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n, m, i, j, a, s = 0;
cin >> n >> m;
map<long long, long long> mp;
for (i = 0; i < n; i++) {
cin >> a;
mp[a] = i;
}
j = 0;
for (i = 0; i < m; i++) {
cin >> a;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
int a[N], n;
vector<int> h[N];
set<int> S;
bool check(int mid) {
S.clear();
for (int i = 1; i <= n; i++) {
int x = a[i];
while (x > mid || S.count(x)) x /= 2;
if (!x) return false;
S.insert(x);
}
return true;
}
int main() {
scanf... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int t;
t = 1;
while (t--) {
int n, m;
cin >> n >> m;
int a[n], b[m];
for (long long int(i) = (0); (i) < (n); (i)++) cin >> a[i];
for (long long int(i) = (0); (i) < (m); (i)++) cin >> b[i];
sor... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, c, i, prev = INT_MIN, present, ind = 0;
cin >> n >> c;
for (i = 0; i < n; i++) {
cin >> present;
if (c < present - prev) {
ind = i;
}
prev = present;
}
cout << n - ind << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 1000;
const int maxval = 1000 * 1000;
const int levels = 6;
const long long int INF = 1000000LL * 1000000LL * 1000000LL * 2;
long long int dp[levels][maxn];
void deqadd(deque<pair<long long int, long long int> > &dq, long long int idx,
lo... | 21 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 2.0 * acos(0.0);
inline int getInt() {
int x;
scanf("%d", &x);
return x;
}
inline long long getLL() {
long long x;
scanf("%lld", &x);
return x;
};
inline int NUM(char c) { return (int)c - 48; }
inline char CHR(int n) { return (char)(n + 48); }
... | 12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.