solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long c[1005][1005];
long long dp[1005][1005], n;
int main() {
memset(dp, 0, sizeof dp);
for (int i = 1; i <= 1000; i++) dp[i][0] = i / 2 + i % 2;
for (int i = 1; i <= 1000; i++) dp[i][0] = i / 2 + i % 2;
for (int i = 1; i <= 1000; i++) {
for (int j = 1; j <... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int M[a][b];
int A[a];
bool Ab[a];
for (int i = 0; i < a; i++) {
A[i] = Ab[i] = 0;
}
int B[b];
bool Bb[b];
for (int i = 0; i < b; i++) {
B[i] = Bb[i] = 0;
}
int menor = 501;
for (int i = 0; i < a; i++) ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100003;
int h, a[MaxN];
int fa[MaxN * 2];
int main() {
scanf("%d", &h);
h++;
for (int i = 1; i <= h; ++i) scanf("%d", a + i);
for (int I = 1; I < h; ++I)
if (a[I] > 1 && a[I + 1] > 1) {
puts("ambiguous");
int tot = 1;
for (int ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, num0 = 0, num1 = 0, ans;
string bi;
void solve() {
cin >> n;
cin >> bi;
for (char x : bi) {
if (x == '0')
num0++;
else
num1++;
}
if (num0 > num1) {
num0 -= num1;
ans = num0;
} else if (num1 > num0) {
num1 -= num0;
ans =... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long f[205][205], a[205];
int n, m, x;
int main() {
cin >> n >> m >> x;
for (int i = 1; i <= n; i++) cin >> a[i];
memset(f, -1, sizeof(f));
f[0][0] = 0;
for (int i = 1; i <= n; i++)
for (int k = 1; k <= min(x, i); k++) {
int t = max(0, i - m);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int M = 1e9 + 7;
pair<int, int> a[N];
int s[N];
int st[N];
void slove() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int t;
cin >> t;
a[i] = {t, i};
}
sort(a + 1, a + 1 + m);
int res = 0;
int resn = 1;
f... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e4 + 5, G = 1e3 + 5;
long long T[M][G];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> pos(m);
for (int& x : pos) cin >> x;
sort(pos.begin(), pos.end());
int g, r;
cin >> g >> r;
vector<pair<int, int> ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 20;
const int M = 1000000007;
const double PI = acos(-1);
const int oo = 1000000000;
int n, m, v[N], seg[4 * N][2], lazy[4 * N], l, r, T, st[N], ed[N], rev[N];
vector<int> g[N];
void fix(int u, int s, int e) {
lazy[u] %= 2;
if (s != e) {
lazy[... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 50;
const int N1 = N + 5;
const int N2 = 2550;
const int Mod = 998244353;
bool a[N1];
int n, m, f[N1][N1][N1], w[N1], inv[N2 + 5];
int w0, w1, w2;
void Dp_Like(int x) {
memset(f, 0, sizeof(f));
f[0][0][0] = 1;
for (int i = 0; i <= m; ++i)
for (int j ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int h, w, k, color[1005][1005];
char hcons[1005][1005], vcons[1005][1005];
int calc_correct() {
int ret = 0;
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++) {
if (j + 1 < w)
ret += (hcons[i][j] == 'N') ^ (color[i][j] == color[i][j + 1]);
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
long long arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
long long ans = INT_MIN;
long long start = max((long long)0, (long long)(n - 200));
for (long long i = start; ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t = 1;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
while (t--) {
long long int i, j, k, m, n, x, q;
cin >> n >> q;
map<long long int, long long int> mp;
long long int bc[33];
for (int i = 0; i < 33; i++) bc[i] = 0;... | 8 |
#include <bits/stdc++.h>
using namespace std;
map<char, int> mp;
int main() {
mp.insert(pair<char, int>('A', 0));
mp.insert(pair<char, int>('B', 0));
mp.insert(pair<char, int>('C', 0));
for (int i = 0; i < 3; i++) {
string s;
cin >> s;
if (s[1] == '>')
++mp[s[0]];
else
++mp[s[2]];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int n, m;
vector<int> g[MAXN];
int outdeg[MAXN];
int par[MAXN];
int col[MAXN];
bool dfs(int i) {
if (col[i] == 1) return true;
if (col[i] == 2) return false;
col[i] = 1;
for (int j = 0; j < g[i].size(); j++) {
if (dfs(g[i][j])) return tr... | 13 |
#include <bits/stdc++.h>
using namespace std;
vector<string> vec_splitter(string s) {
s += ',';
vector<string> res;
while (!s.empty()) {
res.push_back(s.substr(0, s.find(',')));
s = s.substr(s.find(',') + 1);
}
return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
__... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long a[200005];
void rd() {
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
}
int main() {
rd();
sort(a + 1, a + n + 1);
long long ans = 0;
ans += (m / (k + 1)) * (a[n - 1]) + (m - m / (k + 1)) * (a[n]);
cout << ans;
ret... | 2 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read(){
int r=0,f=1;
char c=getchar();
while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
while(c>=48&&c<=57)r=r*10+(c&15),c=getchar();
return r*f;
}
inline void write(int x){
char c[20],len=0;
if(!x){putchar('0');return;}
if(x<0)x=-x,put... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long s;
struct Point {
long long x, y;
int id;
Point(long long x, long long y) {
this->x = x;
this->y = y;
}
Point(){};
} p[2005];
inline Point operator+(Point a, Point b) { return Point(a.x + b.x, a.y + b.y); }
inline Point operator-(Point a, ... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int val[50005], nxt[50005], q[50005];
map<int, int> id;
int main() {
srand(time(0));
ios::sync_with_stdio(false);
cin.tie(0);
int n, s, x, cur;
cin >> n >> s >> x;
cout << "? " << s << endl << flush;
cin >> val[s] >> nxt[s];
id[val[s... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
map<long long, long long> vect;
cin >> n >> k;
long long a;
while (n--) {
cin >> a;
vect[a]++;
}
map<long long, long long>::iterator it = vect.begin();
while (1) {
if (vect.size() == 1) break;
map<long long, long ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 9973;
const double eps = 1e-8;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a /... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a[500000], b[500000];
vector<pair<int, int> > adjList[500000];
int visited[500000], parent[500000], pp[500000];
int other[500000];
int doDFS(int u, int p) {
int i;
visited[u] = 1;
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i].first;
if (v... | 26 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 10;
long long dp[N][40];
int n;
long long a[N];
int main() {
memset(dp, 0x3f3f3f3f, sizeof(dp));
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%I64d", &a[i]);
a[i] /= 100;
}
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
... | 16 |
#include <bits/stdc++.h>
const int N = 101010;
int n, i, a[N], ans[N], j;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
for (i = 1; i < n; i++) {
ans[i] = ans[i - 1];
for (j = 0; i + (1 << j) <= n; j++)
;
j--;
ans[i] += a[i];
a[i + (1 << j)] += a[i];
}
fo... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2007;
long long a[N];
long long ans[N];
bool used[N];
long long suff[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, k;
cin >> n >> k;
for (long long i = 0; i < n; ++i) cin >> a[i];
for (long long i = 0; i < n; ++i)... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long power(long long a, int e, int mod) {
long long result = 1;
while (e) {
if (e & 1) {
result = (result * a) % mod;
}
a = (a * a) % mod;
e >>= 1;
}
return result;
}
int main() {
ios_base::sync_with_stdio(false)... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
const int MOD = INF + 7;
struct block {
int a, b;
};
block m[100 + 1];
long long dp[3000 + 1][100 + 1][2];
int main() {
int n, len;
scanf("%d%d", &n, &len);
for (int i = 0; i < n; ++i) scanf("%d%d", &m[i].a, &m[i].b);
for (int i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a[2005][2005], n;
bool chk[2005];
vector<int> adj[2005];
void dfs(int u) {
for (int i = 0; i < adj[u].size(); i++) {
int v = adj[u][i];
if (chk[v]) continue;
chk[v] = true;
dfs(v);
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
... | 14 |
#include <bits/stdc++.h>
using namespace std;
char grid[1000 + 9][1000 + 9];
int n, m, k;
vector<pair<char, pair<int, int>>> start;
char comm[100000 + 9];
int val[100000 + 9];
int cost[1000 + 9][1000 + 9];
int range(int x1, int y1, int x2, int y2) {
int i = min(x1, x2), j = min(y1, y2);
int k = max(x1, x2), l = max... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x;
cin >> x;
vector<pair<long long, long long> > ans;
int flag = 0;
for (int i = 1;; ++i) {
long long m = i;
long long up = (6 * x + (long long)(m - 1) * m * (m + 1));
long long down = (long long)3 * m * (m + 1);
long long n ... | 11 |
#include <bits/stdc++.h>
using namespace std;
double ans = 0;
long long n, father[200000][21], que[200000], depth[200000], son[200000],
dis[200000], rdis[200000];
vector<int> v[200000];
void bfs() {
int head = 1, tail = 2;
que[1] = depth[1] = 1;
while (head < tail) {
int cur = que[head++];
for (int i ... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long powmod(long long a, long long b, long long MOD) {
long long ans = 1;
while (b) {
if (b % 2) ans = ans * a % MOD;... | 12 |
// in the name of God
// 8dPRvhQ3Hr
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define debug(a) cout << (&a) << " : " << a << '\n'
#define fast ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
typedef long long ll;
typedef long double ld;
using namespace std;
const int MAX_N... | 13 |
#include <bits/stdc++.h>
using namespace std;
static int N;
static vector<int> ve;
static vector<int> vis;
int main() {
while (scanf("%d", &N) != EOF) {
ve.clear();
ve.resize(N);
vis.clear();
vis.resize(N, 0);
for (int i = 0; i < N; i++) scanf("%d", &ve[i]);
int k = 0;
int cnt = 0;
str... | 4 |
#include <bits/stdc++.h>
using namespace std;
int dp[2105][182][91][2];
int n, s[4005], ps[4005];
int sum(int l, int r) { return ps[r] - ps[l - 1]; }
int calc_dp(int l, int dif, int cur, int player) {
if (dp[l][dif + 90][cur][player] != 1010101010)
return dp[l][dif + 90][cur][player];
int r = n + 1 - l + dif;
... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long n, H, ans = 0x7f7f7f7f7f7f7f;
bool check(long long mid) {
long long need, ret;
if (mid > H) {
need = (mid + H) * (mid - H + 1) / 2 + (mid + 1) * mid / 2 - mid;
ret = mid - H + mid;
} else {
need = (mid + 1) * mid / 2;
ret = mid;
}
if (nee... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const long long INFLL = 1000000000000000000LL;
const int h = 100011;
bool lucky(int v) {
while (v) {
int r = v % 10;
if (r != 4 && r != 7) return false;
v /= 10;
}
return true;
}
int n, a[h], u[h], p[h];
vector<pair<int, int> > ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, c = 0, a, x, y, f = 0;
cin >> n;
map<long long int, long long int> m1;
map<long long int, long long int> m2;
map<long long int, long long int> m3;
vector<pair<long long int, long long int>> v;
for (long long int i = 0; i < n; i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
struct node {
int value, size, max;
node *ch[2], *pnt;
void rs() {
size = ch[0]->size + ch[1]->size + 1;
max = std::max(std::max(ch[0]->max, ch[1]->max), value);
}
};
node nil = (node){0, 0, 0};
node *NIL = &nil;
map<int, pair<int, i... | 15 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > blue, red;
vector<pair<int, pair<int, int> > > ver, hor;
const int TIMEMAX = 10000000, MAXN = 2000;
vector<int> adj[MAXN];
int n, m, x, y, cnt[2000][2000];
void fix(vector<pair<int, pair<int, int> > > &v) {
sort(v.begin(), v.end());
int ind = 0;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const long long mod = 1e9 + 7;
const int inf = 1 << 30;
const int maxn = 900500;
const double EPS = 1e-7;
int n, m;
int a[maxn], b[maxn];
multiset<int> av[maxn];
int dis(int i, int j) {
if (j > i) return j - i;
return n - i + j;
}
set<int> inds;... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, total = 0;
cin >> n >> m;
vector<int> items;
for (int i = 0; i < n; i++) {
int val;
cin >> val;
items.push_back(val);
}
sort(items.begin(), items.end());
for (int i = 0; i < m; i++) {
if (items[i] <= 0) {
total -= i... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int n, m, a[200005];
int main() {
scanf("%d%d", &n, &m);
if (m >= 5) {
puts("YES");
int s = 0;
if (m & 1) {
for (int i = m; i > 0; i -= 2) a[++s... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
const long long INF = 1e18;
const long long magic = 100000;
vector<int> cycle;
vector<set<int>> g;
vector<int> used;
void euler_cycle(int v) {
cycle.clear();
stack<int> s;
s.push(v);
while (!s.empty()) {
int v = s.top();
used[v] = 1;
... | 16 |
#include <bits/stdc++.h>
char s;
int n, k, start[26] = {0}, end[26], cnt[1000001] = {0};
int main() {
scanf("%d %d\n", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%c", &s);
if (start[s - 'A'] == 0) start[s - 'A'] = i;
end[s - 'A'] = i;
}
for (int i = 0; i < 26; i++) {
if (start[i] > 0) cnt[st... | 3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const double PI = 6.283185307179586476925286766559;
const int MAXN = 100010;
int n;
double x, y;
string t, st = "1";
int deg;
int al[26];
int gc(int a, int b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
void solve... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 500;
const long long mod = 1e9 + 7;
const long long MOD = 998244353;
const long double eps = 0.00001;
const int P = 1336;
const int inf = 1e9;
int mi[N], ma[N];
vector<int> z_f(string s) {
int n = s.size(), l = 0, r = 0;
vector<int> z;
z.resize(n);... | 18 |
#include <bits/stdc++.h>
using namespace std;
vector<int> get(const string &s) {
vector<int> res(s.size() + 1);
for (int i = 0; i < int(s.size()); ++i) {
res[i + 1] = s[i] - 'a';
}
return res;
}
int main() {
int k;
string s, t;
cin >> k >> s >> t;
vector<int> a = get(s), b = get(t);
for (int i = k... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
for (long long i = 0; true; i++) {
long long x = ((i * (i + 1)) / 2);
if (x >= n) {
return cout << (i - (x - n)) << endl, 0;
}
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n >> m;
long long int max_pair = (n - (m - 1)) * (n - (m - 1) - 1) / 2ll;
long long int min_pair =
(m * (n / m) * (n / m - 1) / 2ll) + ((n % m) * (n / m));
cout << min_pair << " " << max_pair << "\n";
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int a[101];
int main() {
int n, k, x;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> x;
a[x]++;
}
int c = 0, state = 0;
while (true) {
for (int i = k - 1; i > 0; i--) {
if (a[i]) {
a[i]--;
a[i + 1]++;
state = 1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a;
long long dp[100005];
long long cnt[100005];
cin >> n;
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < n; i++) {
cin >> a;
cnt[a]++;
}
dp[0] = 0;
dp[1] = cnt[1];
for (int i = 2; i <= 100000; i++)
dp[i] = max(dp[i - 1],... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool checked(double m);
const int s = 1e5;
double n, k;
double arr[s];
int main() {
double hi = 1e6, lo = 0, mid;
scanf("%lf %lf", &n, &k);
for (int i = 0; i < n; ++i) {
scanf("%lf", &arr[i]);
}
for (int i = 0; i < 1000; ++i) {
mid = (hi + lo) / 2;
if ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int INF, ans, N, x[100009], d[100009], dp1[100009], dp2[100009], Norm[100009],
aib[100009];
pair<int, int> h[100009];
void Clear(int val) {
for (int i = 0; i <= N; i++) aib[i] = val;
}
void Updt(int pos, int val) {
while (pos <= N)
aib[pos] = max(aib[pos], val),... | 22 |
#include <bits/stdc++.h>
using namespace std;
char s[1000];
bool a[1000];
int ans;
int main() {
cin >> s;
cin >> s;
for (int i = (0), i_end_ = (strlen(s)); i < i_end_; ++i) {
if (a[i] || a[i + 1]) continue;
if ((s[i] == 'U' && s[i + 1] == 'R') || (s[i] == 'R' && s[i + 1] == 'U')) {
a[i] = a[i + 1] =... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, x, a[5010], dp[5010][5010];
int main() {
cin >> n;
long long ans = 0;
for (int i = 1; i <= n; i++) cin >> a[i];
vector<int> v;
v.push_back(a[1]);
for (int i = 2; i <= n; i++)
if (a[i] != v[v.size() - 1]) v.push_back(a[i]);
for (int i = 1; i < ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int a[N], b[N];
int main() {
ios ::sync_with_stdio(false);
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n;
cin >> n;
for (int j = 0; j < n; j++) {
cin >> a[j];
}
for (int j = 0; j < n; j++) {
cin >> b[j];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 50;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const long long lnf = 0x3f3f3f3f3f3f3f3f;
const long long mod = 998244353;
struct node {
int a, b;
} p[105];
int dp[105][10050];
bool cmp(node A, node B) { return A.b > B.b; }
int main() {
i... | 11 |
#include <bits/stdc++.h>
using namespace std;
inline int dist(int a, int b, int n, bool clockwise) {
if (clockwise) {
if (a <= b)
return b - a;
else
return n + b - a;
} else {
if (a < b)
return n + a - b;
else
return a - b;
}
}
inline int short_dist(int a, int b, int n) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int N, M;
string S;
void preprocess(int& must_open, int& has_open) {
int bal = 0;
must_open = 0;
for (char c : S) {
if (c == '(') {
++bal;
} else {
--bal;
if (bal < 0) {
must_open++;
bal = 0;
}
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int g[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2};
int a;
cin >> a;
cout << g[a / 10] * g[a % 10];
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
struct O {
int a, b, c;
};
vector<int> a;
vector<O> operations;
void add_operation(O i) {
operations.push_back(i);
a[i.a] ^= 1;
a[i.b] ^= 1;
a[i.c] ^= 1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
a.resize(n)... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n, sum = 0, ans = 0, c;
long double l, d, v, g, r, x;
cin >> l >> d >> v >> g >> r;
cout << fixed << setprecision(10);
l /= v;
d /= v;
c = d / (g + r);
x = 1.0 * (g + r) * c;
if (x <= d && d < x + g) {
cout << l;
} else
... | 7 |
#include <bits/stdc++.h>
int isUpper(char *arr) {
int i;
char c;
c = arr[0];
for (i = 1; c != '\0'; i++) {
if (c >= 'a' && c <= 'z') return 0;
c = arr[i];
}
return 1;
}
void printToggle(char *arr) {
int i;
char c;
i = 0;
c = arr[0];
while (c != '\0') {
if (c >= 'a' && c <= 'z') {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll ask(vector<int> a) {
if (a.size() == 0) {
return 0;
}
cout << "? ";
cout << a.size() << ' ';
for (int x : a) {
cout << x << ' ';
}
cout << endl;
ll x;
cin >> x;
return x;
}
int main() {
ios::sync_with_stdio(0);
vector... | 20 |
#include <bits/stdc++.h>
using namespace std;
char a[110][110];
map<char, int> mp;
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) cin >> a[i][j];
if (n % 3 && m % 3) {
cout << "NO";
return 0;
}... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 35;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
int n, m, kp, Map[N][N], exist[105];
char ch[N][N];
pair<int, int> pos[25], adj[N][N];
bool vis[25], vis2[N][N];
long long ans;
int ansMap[N][N];
bool place(int r, int c, int k) {
bool flag = true;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, mod = 998244353, inf = 0x3f3f3f3f;
int n, m, k, t;
int main() {
int i, j;
scanf("%d", &n);
int x = 0, y = 0;
for (i = 1; i <= n; i++) {
printf("%d %d\n", x, y);
if (i % 3 == 1)
x++;
else if (i % 3 == 2)
y += 3;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1050;
int d[4][2] = {-1, 0, 1, 0, 0, 1, 0, -1};
int n, m, t;
int flag[maxn][maxn] = {0}, step[maxn][maxn] = {0};
int a[maxn][maxn] = {0};
struct node {
int x;
int y;
};
queue<node> q;
bool samecolor(int x, int y) {
for (int i = 0; i < 4; i++) {
in... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0', c = getchar();
return ... | 19 |
#include <bits/stdc++.h>
using namespace std;
struct elem {
int l, p, t, ind;
elem() {}
elem(int inl, int inp, int intt, int inind) {
l = inl;
p = inp;
t = intt;
ind = inind;
}
};
int base = 315;
int n;
elem v[1000000];
int btmax[1000000];
int bttope[1000000];
int cuantos[1000000];
int bdesp[100... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, l = 0, r = 0, a, b, c, k = 0;
cin >> t;
while (t--) {
cin >> a >> b >> c;
if (a > 0) {
a--;
k++;
}
if (b > 0) {
b--;
k++;
}
if (c > 0) {
c--;
k++;
}
if (b > a) swap(a, b);
i... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
string str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t, n, m, i, s, j, k, c;
cin >> t;
while (t--) {
... | 9 |
#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};
long long ln, lk, lm;
vector<int> mp[100005], q[100005];
set<pair<int, int>> ss[100005];
int ans[100005], s[100005], e[100005];
int cnt;
void dfs(int x, int pa) {
s[x] = ++cnt;
for (int c... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 19;
int pa[MAXN];
bool visited[MAXN];
vector<int> adj[MAXN];
double pp[MAXN], p[MAXN];
void dfs(int n) {
visited[n] = true;
for (auto& it : adj[n]) {
if (!visited[it]) {
pp[n] += p[it];
pa[it] = n;
dfs(it);
}
}
return... | 14 |
#include<bits/stdc++.h>
#define int long long
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define fore(i,s,e) for(int i=s;i<e;++i)
using namespace std;
#define endl '\n'
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
signed main()
{
FAST
int t = 1, n;
string s;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int i, j, k, n, cnt = 0;
cin >> n;
map<int, int> m;
for (i = 0; i < n; ++i) {
char ch;
int x;
cin >> ch >> x;
if (ch == '+') {
m[x] = 1;
int y = m.size();
cnt = max(c... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, res;
int t[22][22];
void rec_read(int i, int j) {
j == n ? (j = 0, i++) : 0;
i == n ? 0 : (scanf("%d", &t[i][j]), rec_read(i, j + 1), 0);
}
void rec_calc(int k, int i, int j) {
j == n ? (j = 0, i++) : 0;
i == n ? (i = 0, k++) : 0;
k == n
? 0
: (... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 112345;
const int P = 17 + 1;
int n, p, a[P][P];
string s;
int invalid[1 << P], len[1 << P];
int cnt[P];
bool vis[1 << P];
int id(char c) { return c - 'a'; }
void make_invalid(int mask, int a, int b) {
invalid[mask] = true;
vis[mask] = true;
for (int i =... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, m, A, numL, cntL, cntR, cntD, cntU;
vector<int> hor[100005], ver[100005];
int masCnt[100005];
map<int, int> myDivanas;
set<int> goodDivanas;
void letGo(int maX, bool flag) {
if (flag) {
vector<int> finishedNow, finishedNext;
for (int i = 0; i < maX; i++) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
vector<int> V[100005], U[100005], ans;
int color[100005], visit[100005];
void bfs(int root) {
int i;
queue<int> Q;
Q.push(root);
memset(visit, 0, sizeof(visit));
visit[root] = 1;
while (Q.size()) {
int u = Q.front();
Q.pop();
for (i = 0; i < V[u].siz... | 14 |
#include <bits/stdc++.h>
using namespace std;
bool usado[200010];
vector<int> vet;
vector<int> adj[200010];
int n;
bool fb(int v, int p, int k) {
usado[v] = true;
vet.push_back(v);
if (k == n - 1) return p == 1;
bool res = false;
if (adj[v][0] == p) {
res |= fb(adj[v][0], adj[v][1], k + 1);
}
if ((!re... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long a = 0, b = 0, c, d, e, f = 0, l, g, m, n, k, i, j, t, p, q, l1, r1,
l2, r2;
cin >> t;
while (t--) {
cin >> n >> k;
cin >> l1 >> r1 >>... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
long long large = 2000000000000000000LL;
int main() {
int k;
cin >> k;
vector<int> a(1, -1);
int l = 1200;
int sum = l + k;
for (int i = 0; i < l - 1; i++) {
int re = min(sum, 1000000);
sum -= re;
a.push_back(re);
}
... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct tr {
int x, y;
long long g, s;
};
tr t[2000000];
int f[2000000];
int st[2000000];
long long ans = (1ll << 61);
int top = 0;
int cnt;
bool cmp(tr a, tr b) {
if (a.g == b.g) return a.s < b.s;
return a.g < b.g;
}
int find(int x) {
if (x != f[x]) f[x] = find(f[... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[1000000];
char oc[1000000];
stack<int> s;
int n;
bool solve() {
for (int i = n - 1; i >= 0; i--)
if (oc[i] < 0)
s.push(a[i]);
else {
if (!s.empty() && a[i] == s.top()) {
oc[i] = 1;
s.pop();
} else {
oc[i] = -1;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200200;
const int INF = 2100000000;
int n;
int a[maxn], b[maxn];
int d[maxn], dn;
int p[maxn][20];
int q[maxn][20];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d%d", a + i, b + i);
a[n] = INF;
b[n] = 0;
d[dn++] = n;
p[n][0]... | 15 |
#include <bits/stdc++.h>
using namespace std;
set<int> arr[300010];
set<pair<int, int> > seet;
set<pair<int, int> > seet2;
set<pair<int, int> >::iterator it1;
set<pair<int, int> >::iterator it2;
set<int>::iterator it;
int main() {
int n, q, x, y;
scanf("%d", &n);
scanf("%d", &q);
int cnt = 0;
while (q--) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 1;
long long n, m, a, b, lim, o, p;
long long arr[N];
long long sum[N];
long long fin[N];
long long add;
pair<long long, long long> orig[N];
pair<long long, long long> ans;
void input() {
cin >> n >> lim >> a >> b >> m;
for (long long i = 1; i ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int inf = 1 << 30;
const int maxn = 2e5 + 5;
inline void fastio() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
int n;
int a[maxn];
int main() {
fastio();
int _;
for (cin >> _; _; _--) {
cin >> n;
int cn... | 4 |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("AAtest.in.txt");
int n, vas, par, l, mit, su, vahe, enne, vaj;
pair<int, int> p[100005];
int ma[205];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cerr.tie(0);
cin >> n;
for (int i = 0; i < n; i++) cin >> p[i].first;
for (int i ... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T pow2(T a) {
return a * a;
}
template <class T>
inline bool mineq(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int maxn = (int)1e5 + 10;
;
struct edge {
int a, b, id;
long double w;
bool cap;
} edges[... | 16 |
#include <bits/stdc++.h>
using namespace std;
string s, s1;
bool check(string ans) {
int pos = 0;
for (int i = 0; i < ans.size(); i++) {
if (ans[i] == s1[pos]) {
pos++;
}
}
if (pos == s1.size())
return true;
else
return false;
}
int main() {
cin >> s >> s1;
int ans = 0;
for (int i ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 250000;
int a[MaxN], b[MaxN];
int output[MaxN];
vector<pair<int, int>> a_pair, b_pair;
vector<int> b_inv, b_perm;
int M;
int main() {
cin >> M;
for (int i = 0; i < M; i++) {
scanf("%d", a + i);
a_pair.push_back({a[i], i});
}
for (int i = 0; ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
string s;
cin >> s;
short n = (s.length() > 1) ? s[s.length() - 2] - '0' : 0;
n = n * 10 + s[s.length() - 1] - '0';
if (n % 4)
cout << 0 << '\n';
else
cout << 4 << '\n';
return 0;
}
| 4 |
#include <bits/stdc++.h>
long long power(long long base, long long exp) {
long long res = 1;
while (exp > 0) {
if (exp % 2 == 1) res = (res * base);
base = (base * base);
exp /= 2;
}
return res;
}
long long mod(long long a, long long b) { return (a % b + b) % b; }
using namespace std;
int main() {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 60;
const int A = 250;
const int B = 250;
const int inf = 2147483647;
int dp[maxn][A*2+5][B*2+5];
char s[maxn];
void mii(int &u,int v){
u=min(u,v);
}
int main(){
scanf("%s",s+5);
for(int i=1;i<=4;++i)s[i]='0';
int n=strlen(s+1);
memset(dp,0x3f,sizeof... | 21 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, k;
cin >> n >> k;
vector<long long> a(n);
for (long long i = 0; i < n; i++) cin >> a[i];
long long ans = 0;
vector<long long> d;
long long l = -1;
bool f = true;
for ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
inline bool checkBit(long long n, int i) { return n & (1LL << i); }
inline long long setBit(long long n, int i) {
return n | (1LL << i);
;
}
inl... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 10;
int n, a[N], b[N], tmp[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a + 1, a + n + 1);
int m = unique(a + 1, a + n + 1) - (a + 1);
int ans = 0x3f3f3f3f;
for (int lst = 0; lst <= 200; lst++) {
... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.