solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long brute(long long a, long long b) {
long long ret = 0;
for (long long i = a; i <= b; i++) {
for (long long j = i + 1; j <= b; j++) {
ret = max(ret, i ^ j);
}
}
return ret;
}
long long solve(long long l, long long r) {
if (l == r) {
return... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = mod * mod;
const long double eps = 1e-5;
int dp[1 << 20];
int n, m;
char mp[20][20];
int cost[20][20];
vector<pair<int, int> > memo[20];
void solve() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, hgs = 1e9 + 7;
int l[N], r[N], n, ans, e[N], q[N], d[N];
void upd(int &x, int y) { x = (x + y) % hgs; }
void ret(int &x) { x = (x % hgs + hgs) % hgs; }
int qpow(int A, int B) {
int C = 1;
for (; B; B >>= 1, A = 1ll * A * A % hgs)
if (B & 1) C... | 17 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t,n,p;
int a[200010],vis[200010];
int main()
{
cin>>t;
while(t--)
{
ll ans=0;
vector<pair<int,int>> v;
cin>>n>>p;
for(int i=0;i<n;i++)
{
cin>>a[... | 12 |
#include <bits/stdc++.h>
using namespace std;
char s[300010];
int num[3];
int b[3];
int ans[300010];
int tot;
int main() {
int n;
scanf("%d", &n);
scanf("%s", s);
for (int i = 0; s[i]; i++) {
num[s[i] - '0']++;
}
for (int i = 0; i <= 2; i++) {
b[i] = num[i] - n / 3;
}
for (int i = 0; i <= 2; i++... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int nax = 1005;
struct P {
double x, y;
void read() { scanf("%lf%lf", &x, &y); }
void write() { printf("%.10lf %.10lf\n", x, y); }
P operator-(P other) { return P{x - other.x, y - other.y}; }
double operator*(P other) { return x * other.y - y * other.x; }
... | 25 |
#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
const int MAX = 0x7ffffff;
using namespace std;
int main() {
int n;
while (~scanf("%d", &n)) {
if (n % 2 == 0)
printf("white\n1 2\n");
else
printf("black\n");
}
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, k;
cin >> a >> b;
k = (max(a, b) - min(a, b)) / 2;
cout << min(a, b) << " " << k;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int on_bit(int x, int pos) {
x |= (1 << pos);
return x;
}
int off_bit(int x, int pos) {
x &= ~(1 << pos);
return x;
}
bool is_on_bit(int x, int pos) { return ((x & (1 << pos)) != 0); }
int flip_bit(int x, int pos) {
x ^= (1 << pos);
return x;
}
int lsb(int x) { ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int bitct(long long r) { return r == 0 ? 0 : (bitct(r >> 1) + (r & 1)); }
long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; }
template <typename T>
ostream& operator<<(ostream& o, vector<T> v) {
o << "[";
int i = 0, s = v.size();
for (; i + 1 < s... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 0, x, y;
cin >> n;
getchar();
string s;
for (int i = 0; i < n; i++) {
cin >> s >> x >> y;
getchar();
if (x >= 2400) {
if (x < y) {
c++;
cout << "YES" << endl;
break;
}
}
}
if (c == 0) ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long UNDEF = -1;
const long long INF = 1e18;
template <typename T>
inline bool chkmax(T &aa, T bb) {
return aa < bb ? aa = bb, true : false;
}
template <typename T>
inline bool chkmin(T &aa, T bb) {
return aa > bb ? aa = bb, true : false;
}
const long long mn... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
scanf("%lld", &t);
while (t--) {
long long n;
scanf("%lld", &n);
long long a[n + 5];
long long b[n + 5];
memset(b, 0, sizeof(b));
long long v[n + 5];
memset(v, 0, sizeof(v));
for (long long i = 1; i <= n; i++) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
in >> a.first >> a.second;
return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
out << a.first << " " << a.second;
return out;
}
t... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
set<int> s;
vector<int> li(200005, 0);
long long int ans = (long long)(1e18 + 1e15);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (s.count(x)) {
ans = m... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long int infinity = 9e18;
int ways(string s) {
int n = s.size();
vector<int> a(n), b(n);
int count = 0;
int mini = INT_MAX;
for (int i = 0; i < n; i++) {
if (s[i] == '(')
count++;
else
count--;
a[i] = count;
mini = min(mini, ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b, c, s, sum = 0;
cin >> s >> a >> b >> c;
sum = a + b + c;
if (sum == 0) {
cout << a << ' ' << b << ' ' << c << endl;
return 0;
}
printf("%.10lf %.10lf %.10lf\n", s * a / sum, s * b / sum, s * c / sum);
}
| 10 |
#include <bits/stdc++.h>
int main() {
int i = 1, j, k, minindex;
char str[100], temp, minvalue;
scanf("%s", str);
i = strlen(str);
for (k = 0; k < i; k += 2) {
minvalue = str[k];
minindex = k;
for (j = k; j < i; j += 2) {
if (str[j] < minvalue) {
minvalue = str[j];
minindex =... | 0 |
#include <bits/stdc++.h>
using namespace std;
int cal(int p, int t) { return max(3 * p / 10, p - (p * t / 250)); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int a, b, c, d;
cin >> a >> b >> c >> d;
int one = cal(a, c);
int two = cal(b, d);
if (one > two)
cout << "... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[1 << 18];
int main() {
int n, r;
scanf("%d%d", &n, &r);
int k = 1 << n;
long long sum = 0;
for (int i = 0; i < k; ++i) {
scanf("%d", &a[i]);
sum += a[i];
}
printf("%.8f\n", 1.0 * sum / k);
for (int i = 0; i < r; ++i) {
int x, y;
scanf("... | 17 |
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
#define uniq(v) (v).erase(unique(all... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int v, nxt;
} e[1000005 << 1];
int p[1000005], eid;
void init() {
memset(p, -1, sizeof p);
eid = 0;
}
void insert(int u, int v) {
e[eid].v = v;
e[eid].nxt = p[u];
p[u] = eid++;
}
int n, m, low[1000005], dfn[1000005], tot, sta[1000005], sz, bel[1000... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, a[101];
bool vis[101];
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int sum = 0;
int t = n;
int flag = 0;
while (t) {
flag = 0;
for (int i = 0; i < n; i++) {
if (flag <= a[i] && !vis[i]) {
vis[i] ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 210;
int n, m, Q;
int dx[20], dy[20];
char s[maxn][maxn];
char cmd[1000010];
int sum[1000010][10];
int vis[maxn][maxn], VIS[maxn][maxn];
int A[maxn][maxn][10], B[maxn][maxn][10];
int c[300];
int d[300];
void dfs() {
for (int i = 0; i < n; i++)
for (in... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 1e5 + 5;
int x[2][20], y[2][20];
bool vis[20], vis2[20];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> x[0][i] >> y[0][i];
if (x[0][i] > y[0][i]) swap(x[0][i], y[0][i]);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007, INF = 2000000001;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1, 0},
dy[] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
const double EPS = 1e-9;
long long gcd(long long a, long long b) { return (b != 0) ? gcd(b, a % b) : a; }
long long modpow(long long a, ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> a >> b;
int num[n];
for (int i = 0; i < n; i++) {
cin >> num[i];
}
sort(num + 1, num + n);
long long ans = 0;
for (int j = 0; j < n; j++) {
ans += num[j];
if (num[0] * a... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 30;
bool vis[800][800];
int n, t[MAXN + 10], dir[8][2] = {{-1, 0}, {-1, 1}, {0, 1}, {1, 1},
{1, 0}, {1, -1}, {0, -1}, {-1, -1}},
ans;
vector<pair<pair<int, int>, int> > q1, q2;
int main() {
scanf("%... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int n, k, vis[maxn], a[maxn], b[maxn], c[maxn], d[maxn];
bool dp[maxn];
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int ans1 = k, ans2 = 0, cnt = 0;
for (int i = 1; i <= n; i++) {
if (vis[i]) con... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
long long k;
long long z, y;
long long A[105][105] = {};
ios::sync_with_stdio(false);
cin >> n >> m >> k >> z >> y;
long long a = m, d, x;
if (n != 1) d = (n - 1) * m * 2;
if (n != 1) x = (k - a) / d;
if (n == 1) {
long l... | 9 |
#include <bits/stdc++.h>
using namespace std;
int solve() {
int n;
cin >> n;
int a[n];
int minn = INT_MAX;
int maxx = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
minn = a[0];
for (int i = 1; i < n; i++) {
minn = minn & a[i];
}
return minn;
}
int main() {
int n;
cin >> n;
while (n... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<string> route;
void levenshtein(string x, string y) {
int n = x.size();
int m = y.size();
vector<vector<int> > dp(n + 1, vector<int>(m + 1));
vector<vector<char> > path(n + 1, vector<char>(m + 1));
for (int i = 0; i <= n; i++) {
dp[i][0] = i;
path[i... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc) {
o << "{";
for (const T& v : vc) o << v << ",";
o << "... | 19 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
const int N = 24;
int a[N], b[N];
int main() {
int n;
scanf("%d", &n);
int i;
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
b[i] = a[i];
}
sort(a + 1, a + n + 1);
for (i = 1; i <= n; i++) mp[a[i]] = i;
for (i = 1; i <= n; i++) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int A[MAXN];
int num[MAXN];
bool valid[MAXN];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &A[i]);
fill(num, num + n + 2, 1);
num[n + 1] = 0;
int maxi = 0;
for (int i = n - 1; i >= 0; i--) {
if (vali... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> way[200005];
vector<int> num[200005];
int banned[200005];
int cnt[200005];
int dp[200005], nxt[200005];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
long long extended_gcd(int a, int b) {
long long s = 0, t = 1, r = b;
long long old_s = 1, ol... | 15 |
#include <bits/stdc++.h>
using namespace std;
int q[111], s[111], p[111], p2[111];
int pos, n, k, d;
bool match() {
for (int i = 1; i <= n; i++)
if (s[i] != p[i]) return false;
return true;
}
void next() {
for (int i = 1; i <= n; i++) p2[i] = p[q[i]];
for (int i = 1; i <= n; i++) p[i] = p2[i];
}
void prev()... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<int> a(n);
for (auto &x : a) cin >> x;
while (q--) {
int l, r;
cin >> l >> r, --l, --r;
vector<int> left(n), right(n), st;
for (int i = l + 1; i <= r; i... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int a = 1234567;
const int b = 123456;
const int c = 1234;
int main() {
int n;
scanf("%d", &n);
int su = 0;
for (int i = 0; i * a <= n; i++) {
for (int j = 0; i * a + j * b <= n; j++) {
if ((n - i * a - j * b) % c == 0) su = 1;
}
}
if (su)
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, b, g;
cin >> r >> b >> g;
int count = (r % 3);
count += (g % 3);
count += (b % 3);
int ans;
if (count == 4) {
ans = (r / 3) + (g / 3) + (b / 3);
if (min(r, min(g, b)) != 0) ans += 1;
} else {
ans = (r / 3) + (g / 3) + (b / 3);... | 8 |
#include <bits/stdc++.h>
using namespace std;
static struct FastInput {
static constexpr int BUF_SIZE = 1 << 20;
char buf[BUF_SIZE];
size_t chars_read = 0;
size_t buf_pos = 0;
FILE *in = stdin;
char cur = 0;
inline char get_char() {
if (buf_pos >= chars_read) {
chars_read = fread(buf, 1, BUF... | 23 |
#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
cin >> t;
for (int i = 1; i <= t; i++) {
int n, k, g = 96, q = 0;
cin >> n >> k;
for (int j = 1; j <= n; j++) {
q++;
g++;
cout << char(g);
if (q == k) {
g = 96;
q = 0;
}
}
cout << endl... | 0 |
#include <bits/stdc++.h>
using namespace std;
void init_cin() {
ios_base::sync_with_stdio(false);
cin.tie(0);
}
const int mod = (int)1e9 + 7;
int k, p;
int pow(int a, int p) {
long long res = 1;
for (int i = 0; i < p; i++) {
res = (res * a) % mod;
}
return (int)res;
}
bool used[1111111];
int dfs(int v) ... | 10 |
#include <bits/stdc++.h>
int primes[100000];
long long limit[100000];
int cnt;
char flag[100000];
int size[10][2];
int N;
int len[100000 + 1];
void init() {
memset(flag, 0, sizeof(flag));
cnt = 0;
int i, j;
for (i = 2; i < 100000; i++) {
if (!flag[i]) {
limit[cnt] = i;
limit[cnt] *= limit[cnt];
... | 11 |
#include <bits/stdc++.h>
int n, m, f[110][110], ans;
char s[110][110];
int main() {
scanf("%d%d\n", &n, &m);
for (int i = 0; i < n; i++) gets(s[i]);
for (int i = n - 1; i >= 0; i--) {
for (int j = m - 1; j >= 0; j--) {
int k = s[i][j] == 'W' ? 1 : -1;
if (k != f[i][j]) {
k -= f[i][j];
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int arr[n];
for (long long int i = 0; i < n; i++) {
cin >> arr[i];
}
long long int s = arr[0];
for (long long int i = 1; i < n; i++) {
arr[i] = s + arr[i];
s = arr[i];
}
long long int q;
cin >... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
const int mn = 60;
char board[mn][mn];
char ans[2 * mn][2 * mn];
int cub[mn][mn];
bool v(int x, int y) { return x >= 0 && x < n && y >= 0 && y < n; }
bool at(int x, int y) { return board[x][y] == 'x'; }
bool fi(int x, int y) { return board[x][y] == 'o'; }
bool em(int... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(3);
int t;
for (int i = 0; i < n; i += 1) {
cin >> t;
a[t - 1] += 1;
}
sort(a.begin(), a.end());
cout << a[0] + a[1] << "\n";
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
cout << 2 * n - 1 << " " << 2 << endl;
cout << 1 << " " << 2;
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
long long int MI = (long long int)-1e16;
long long int a[200100];
vector<int> adj[200100];
long long int dp[200100][2];
bool vis[200100];
long long int ans[200100];
void dfs(int v) {
vis[v] = true;
long long int acum = a[v];
vector<int> ch;
for (int i = 0; i < (int)... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
pair<int, int> x[300000];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &x[i].first), x[i].second = i;
sort(x, x + n);
scanf("%d", &k);
long long ans = 0;
long long sum = 0;
long long mini;
int idx = 0;
for (int i = 0; i <... | 12 |
#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
vector<int> mp[1535];
int sz[1535];
void dfs(int x, int p) {
int ss = 0;
for (int c : mp[x])
if (c != p) {
dfs(c, x);
ss += sz[c];
}
sz[x] = ss + 1;
}
struct Point {... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long T, n, m, k, c, ans;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int x, y, z;
cin >> T;
while (T--) {
cin >> n;
vector<int> v(n + 1, 0);
for (int i = 0; i < 2 * n; i += 1) {
int x;
cin >> x;
if (v[x])
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
unsigned long long powmod(unsigned long long a, int b) {
unsigned long long res = 1;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a;
a = a * a;
}
return res;
}
const int N = 101000;
vector<pair<unsigned long... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int M = 3e5 + 5;
long long a[M], b[M], f[2], res;
int n;
int cal(long long x) {
int cnt = 0;
while (x) {
cnt += (x & 1);
x >>= 1;
}
return cnt;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
b[i] = cal(a[i]);
}
f[0... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << 2 * n - (n) / 2;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
struct li {
long long s, c;
double xi;
};
li ls[100010];
int am, pos;
long long dp[100010][2] = {0};
void in(long long s, long long c) {
while (1 < am && (double)(c - ls[am - 1].c) <
(double)(ls[am - 1].s - s) * ls[am - 1].xi)
am--;
if (am... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long infl = 1e18 + 5;
long long int n, m, k, q, x, y, f, val, t = 1, i, j;
long long int ind = -1, cnt, sz, sm, ans, mx = -1, mn = infl;
long long int a[5002][5002], b[5002];
void get_prime() {
int i, j;
for (i = 2; i < 5002; i++) {
if (b[i]) continue;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, v, m;
int type, l, r;
vector<long long> stones, sStones, sSortedStones;
int main() {
scanf("%d", &n);
stones.resize(n);
sStones.resize(n);
sSortedStones.resize(n);
for (int i = 0; i < n; ++i) {
scanf("%d", &v);
stones[i] = v;
if (i)
sStone... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int s1 = 0, s2 = 0;
int x[105], y[105];
bool pos = false;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
for (int i = 0; i < n; i++) {
s1 += x[i];
s2 += y[i];
if (x[i] % 2 != y[i] % 2) {
pos = true;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, m, k, a[300010], q, l, r, x, o;
long long suf[200010];
long long fac[30];
void build() {
for (long long i = n; i >= 1; i--) {
a[i] = i;
suf[i] = suf[i + 1] + a[i];
}
fac[0] = 1;
for (long long i = 1; i <= 15; i++) {
fac[i] = fac[i - 1] * ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int T;
long long a, b, c, s;
cin >> T;
while (T--) {
cin >> a >> b >> c >> s;
if (s - a * c < 0) {
s %= c;
if (b >= s) {
cout << "YES\n";
} else
cout << "NO\n";
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int N = s.size();
long long heavy = 0, sum = 0;
for (int i = 0; i < N - 4; i++) {
if (s[i] == 'h' && s[i + 1] == 'e' && s[i + 2] == 'a' && s[i + 3] == 'v' &&
s[i + 4] == 'y')
heavy++;
else if (heavy > 0 && s[i... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = int(1e9) + 9;
const int N = 20100;
void solve() {
int n, p;
cin >> n >> p;
vector<vector<int>> g(n + 1, vector<int>(n + 1, 0));
int e = 2 * n + p;
for (int i = 1; e && i < n; i++) {
for (int v = 1; e && v + i <= n; v++) {
g[v][v + i] = 1;... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200020;
int cur, cnt, l[maxn], r[maxn], f[maxn], n, t, k, a[maxn];
int now, L[maxn];
int main() {
scanf("%d%d%d", &n, &t, &k);
l[0] = r[0] = 1;
L[0] = 2;
for (int i = 1; i <= t; i++) {
scanf("%d", &a[i]);
l[i] = r[i - 1] + 1;
L[i] = l[i]... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long ans, f[1005][1005], a[1005], n, sub, res;
int main() {
scanf("%lld", &n);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &a[i]);
f[i][i] = f[i - 1][i - 1] + (i & 1 ? a[i] : -a[i]);
}
for (int len = 2; len <= n; ++len)
for (int i = 1; i + len - 1 ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long int mx = 1e3 + 1, Mod = 1e9 + 7;
int n, k;
int ec[mx][mx];
void print(const vector<pair<int, int> > &a) {
for (pair<int, int> p : a)
cout << "(" << p.first << ", " << p.second << ") ";
cout << '\n';
}
void color(const vector<pair<int, int> > &b, int... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, m, dist[N][N], circle;
int way[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
char str[N][N];
set<pair<int, int> > myset[2];
int id(char ch) {
if (ch == '>') return 0;
if (ch == '<') return 1;
if (ch == 'v') return 2;
if (ch == '^') return 3;
}
int d... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 5;
int a[MAXN];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int d = a[2] - a[1];
bool flag = true;
for (int i = 3; i <= n; i++) {
if (a[i] - a[i - 1] != d) {
flag = false;
}
}
if (fla... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename tp>
inline void read(tp& x) {
x = 0;
char tmp;
bool key = 0;
for (tmp = getchar(); !isdigit(tmp); tmp = getchar()) key = (tmp == '-');
for (; isdigit(tmp); tmp = getchar()) x = (x << 3) + (x << 1) + (tmp ^ '0');
if (key) x = -x;
}
template <ty... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, r;
cin >> n >> r;
i = 1;
while ((n * i) % 10 != r && (n * i) % 10 != 0) {
i++;
}
cout << i << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int mod = 1e7 + 9;
const int oo = (1 << 31) - 1;
template <class T>
inline void readInt(T &n) {
n = 0;
T ch = getchar();
int sign = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') sign = -1;
ch =... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mx = 2e5 + 15;
const int mx1 = 1e2 + 15;
int a[mx];
int main() {
int n, tot, ans, i, ok;
scanf("%d", &n);
for (i = 1; n >= i; i++) {
scanf("%d", &a[i]);
}
for (i = 1, ans = 0, tot = 0, ok = 0; n >= i; i++) {
if (a[i] == 1) {
tot++;
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e1) {
cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
cout << e1 << " " << e2 << " " << e3 << endl;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, i = 0;
cin >> a >> b;
while (a <= b) {
a = a * 3;
b = b * 2;
i = i + 1;
}
cout << i;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
inline long double minOf(long double x, long double y) {
return (x < y ? x : y);
}
inline long long maxOf(long long x, long long y) { return (x > y ? x : y); }
struct Point {
long double x;
long double y;
} p[305];
bool isLeft(Point a, Point b, Point c) {
return ((b... | 13 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long d[200000];
int main(int argc, char* argv[]) {
unsigned long long n, a;
cin >> n >> a;
unsigned long long s = 0;
for (unsigned int i = 0; i < n; ++i) {
cin >> d[i];
s += d[i];
}
bool sp = false;
for (unsigned int i = 0; i < n; ++i) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> primes[100100];
int choice[100100];
int posi[100100];
int other[100100];
void apply(int val) {
if (other[val] == 1) {
printf("Already on\n");
} else if (other[val] == 0) {
int siz = primes[val].size(), i = 0, number;
bool is = true;
while (i ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 110;
int gcd(int a, int b) {
if (a == 0 || b == 0) return a + b;
if (a > b) return gcd(a % b, b);
return gcd(a, b % a);
}
vector<int> g[maxN];
vector<int> gc[maxN];
vector<int> lc[maxN];
int n, m;
int res[maxN];
int used[maxN];
vector<int> comp;
void ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int joy(int a, int b, int count) {
if ((a <= 0 || b <= 0) || (a == 1 && b == 1)) {
return count;
} else if (a <= b) {
a += 1;
b -= 2;
count++;
return joy(a, b, count);
} else {
b += 1;
a -= 2;
count++;
return joy(a, b, count);
}
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, a, b, t;
scanf("%d%d%d", &k, &a, &b);
if (a < k && (b % k) != 0) {
cout << -1 << endl;
return 0;
}
if (b < k && (a % k) != 0) {
cout << -1 << endl;
return 0;
}
t = a / k + b / k;
if (!t)
cout << -1 << endl;
else
... | 4 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1000000000")
static int m1[101][10001], m2[200], m3[200];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, a, b, c;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a;
b = 0;
for (int j = 0; j < a; ++j... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
unsigned long long a, b, x, y;
cin >> a >> b;
if (b > a) {
cout << -1 << endl;
return 0;
}
unsigned long long k = a - b;
if (k % 2) {
cout << -1 << endl;
return 0;
}
k /= 2;
cout << k << " " << (... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0;
cin >> n;
int dangerous = 0;
int x1, y1, x2, y2, x3, y3;
int i = 0;
cin >> x1 >> y1;
cin >> x2 >> y2;
cin >> x3 >> y3;
while (i < n - 3) {
if (y1 == y2 && x2 == x3) dangerous++;
x1 = x2;
y1 = y2;
x2 = x3;
y2 = y3... | 7 |
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define ff first
#define ss second
const lli MOD=1e9+7;
const lli inf = 1e18;
#define TIME cerr<<"Time Taken:"<<(float)clock()/CLOCKS_PER_SEC*1000<<"ms"<<endl
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//cout.precisi... | 0 |
#include <bits/stdc++.h>
using namespace std;
int A, B, m, t, l;
bool check(int r) {
long long first = 1ll * A * (r - l + 1);
long long second =
1ll * B * (1ll * r * (r - 1) / 2 - 1ll * (l - 2) * (l - 1) / 2);
return (A + 1ll * B * (r - 1) <= t && first + second <= 1ll * m * t);
}
int main() {
int n, res;... | 11 |
#include <bits/stdc++.h>
using namespace std;
double sqr(double x) { return x * x; }
double distsqr(double x, double y, double a, double b) {
return sqr((x - a)) + sqr((y - b));
}
double cosine_angle(double a, double b, double c) {
return (double)(sqr(a) + sqr(b) - sqr(c)) / ((double)2.0 * a * b);
}
map<long long i... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> vec[310];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
long long cur = 1;
while (cur <= n * n) {
for (long long i = 1; i <= n; i++) vec[i].push_back(cur++);
if (cur > n * n) break;
for (long long i = n;... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool ch1(string s) {
int i, j, k, l, m, n;
l = s.size();
int in = -1;
bool f1 = 0, f2 = 0;
for (i = 0; i < l - 1; i++) {
if (s[i] == 'A' && s[i + 1] == 'B') {
in = i + 2;
f1 = 1;
break;
}
}
if (f1 == 1) {
for (i = in; i < l - 1; i... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
return b ? gcd(b, a % b) : a;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 0, n, mask = 0, mas = 0;
cin >> n;
for (int i = 0; i < n; i++) {
char c;
int x;
cin >>... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long a[N], b[N], s[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if (fopen("input.txt", "r")) {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
long long n;
cin >> n;
long long i;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long Q, rM = 400;
long long A[505050];
long long mdm[800][800];
long long i, j, k, l;
int main() {
scanf("%lld", &Q);
while (Q--) {
long long T, X, Y;
long long i;
scanf("%lld%lld%lld", &T, &X, &Y);
if (T == 1) {
A[X] += Y;
for (i = 1; i... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[(int)2e5 + 7], use[(int)2e5 + 7], ans[(int)2e5 + 7];
vector<pair<int, int> > g[(int)2e5 + 7];
int DFS(int u) {
use[u] = 1;
for (auto x : g[u]) {
int v = x.first;
if (use[v]) continue;
int d = DFS(v);
ans[abs(x.second)] = (x.second > 0 ? d... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long int modulo = 1e9 + 7;
int n;
vector<vector<long long int> > cero, identidad;
vector<vector<long long int> > operator*(vector<vector<long long int> > m1,
vector<vector<long long int> > m2) {
vector<vector<long long int> > ... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, SQRT = 320 + 5;
long long a[N], sum[SQRT], lazy[SQRT];
int n, m, q, sq, sz[N], id[N];
vector<pair<int, int>> adj[N];
vector<int> S[N], par[N];
void add(int cur, int x) {
for (auto u : adj[cur]) sum[u.first] += 1LL * x * u.second;
if (sz[cur] <= sq... | 17 |
#include <bits/stdc++.h>
using namespace std;
int N, M;
int go[51][4];
char S[51][51];
int get_type(char c) {
if (isdigit(c)) return 1;
if ('a' <= c && c <= 'z') return 2;
if (strchr("#*&", c)) return 3;
return 0;
}
int main() {
scanf("%d%d", &N, &M);
for (int i = 1; i <= N; i++) {
scanf("%s", S[i]);
... | 7 |
#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 = 1005;
int a, b, x, y;
vector<pair<int, int> > ans;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> a >> b >> x >> y;
for (int... | 3 |
#include <bits/stdc++.h>
long long n, k;
long long sum(long long n) { return (n * (n + 1)) / 2; }
long long sum(long long a, long long b) {
if (a <= 1) return sum(b);
return sum(b) - sum(a - 1);
}
long long search(long long n, long long k) {
long long st = 1, en = k;
while (st < en) {
long long mid = (st + ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)2e5 + 100;
const int INF = 0x3f3f3f3f;
string a, b, c;
int trie[1010][26];
int cntword[maxn], dp[1010][1010];
int fail[maxn];
int cnt = 0;
void insert(string s, int v) {
int root = 0;
for (int i = 0; i < s.size(); i++) {
int next = s[i] - 'a';
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int a[n + 2];
int t, c;
for (int i = 1; i < n + 2; ++i) {
a[i] = 1e18;
}
a[0] = 0;
for (long long int i = 0; i < n; i++) {
cin >> t >> c;
t++;
for (int j = n; j > 0; j--) {
a[j] = min(a[... | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.