solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int R, C, K;
char B[504][504];
int vis[504][504];
int dr[] = {-1, 0, 0, 1};
int dc[] = {0, -1, 1, 0};
int KK;
void dfs(int r, int c) {
if (r < 0 || r >= R || c < 0 || c >= C) return;
if (B[r][c] != '.' || vis[r][c]) return;
vis[r][c] = true;
for (int j = 0; j < 4; +... | 8 |
#include <bits/stdc++.h>
using namespace std;
long double eps = 1e-12;
const long long INF = 0x3f3f3f3f;
const long long inf = INF;
long long modulo = 998244353;
vector<pair<int, int> > all;
int arr[500500];
stack<int> mn;
set<int> unseen;
bool J(pair<int, int>& a, pair<int, int>& b) {
if (a.second != b.second) retur... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using dd = long double;
namespace {
static bool constexpr dbg = 0;
ll constexpr N = -1;
string s;
void init() { cin >> s; }
void solve() {
string s1 = "127", s2 = "32767", s3 = "2147483647",
s4 = "922337203685477580... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
n -= 2;
cout << n * n;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000;
pair<int, int> r[maxn], c[maxn];
int main() {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
for (int i = 0; i < k; i++) {
int j, k, l;
scanf("%d %d %d", &j, &k, &l);
if (j == 1) {
r[k - 1].first = l;
r[k - 1].second = i + 1... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template <typename T>
void debug(T first) {
cout << first << "\n";
}
template <typename T, typename... Args>
void debug(T first, Args... args) {
cout << first << " ";
debug(args...);
}
long long... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
int n;
cin >> n;
set<std::pair<int, int> > bin;
int x;
cin >> x;
bin.insert(make_pair(x, 0));
for (int i = 1; i < n; i++) {
cin >> x;
std::pair<int, int> np = make_pair(x, i);
auto p = bin.lower_bound(... | 10 |
#include <bits/stdc++.h>
using namespace std;
int offset;
int p[30001], dp[30001][500];
bool v[30001][500];
void Solve(int st, int step) {
v[st][step] = true;
int i, mx = 0;
for (i = -1; i < 2; i++) {
if (i == -1 && step == 1) continue;
int cur = st + step + i;
if (cur < 30001) {
if (!v[cur][ste... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int INF = 2140000000;
const long long INF2 = 9220000000000000000LL;
const double PI = acos(-1);
const double ERR = 1e-10;
const int N = 1000005;
long long n, m;
bool chk[N];
vector<int> v;
void solve() {
scanf("%lld", &n);
scanf("... | 12 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi (3.141592653589)
#define mod 1000000007
#define int long long
#define float double
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int p[maxn], a[maxn];
int main() {
int n, q;
while (~scanf("%d%d", &n, &q)) {
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
if (i == 1)
p[i] = -1;
else if (a[i] == a[i - 1])
p[i] = p[i - 1];
else... | 9 |
#include <bits/stdc++.h>
using namespace std;
int const maxn = (int)1e3 + 11;
int const inf = (1 << 30) - 1;
int n;
int a[maxn];
bool used[maxn];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
int sum = 0;
int ans = 0;
for (int j = 0; j < n; j++) {
sum... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long arr[1000005];
vector<long long> seg;
void build(long long l, long long r, long long root, long long flag) {
if (l == r) {
seg[root] = arr[l];
return;
}
long long mid = (l + r) / 2;
build(l, mid, 2 * root, 1 ^ flag);
build(mid + 1,... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 2e5 + 4;
int l[N], r[N];
int main() {
int sy, sa, sb;
scanf("%d", &sy);
scanf("%d", &sa);
scanf("%d", &sb);
int n;
scanf("%d", &n);
int len[n];
for (int i = 0; i < n; i++)
scanf("%d", &l[i]), scanf("%d", &r[i]), len... | 16 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename S>
inline bool REMIN(T &a, const S &b) {
return a > b ? a = b, 1 : 0;
}
template <typename T, typename S>
inline bool REMAX(T &a, const S &b) {
return a < b ? a = b, 1 : 0;
}
int toint(const string &s) {
stringstream ss;
ss << s;
int... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
const int M = 1e6 + 5;
const int mod = 1e9 + 7;
const int m1 = 1e9 + 7;
const int m2 = 1e9 + 9;
const int p1 = 402653189;
const int p2 = 1610612741;
const int LN = 22;
int powermodm(int x, int n, int M) {
int result = 1;
while (n > 0) {
if (n ... | 14 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int mark[1000002];
int qanak(int k) {
int u = 0;
while (k / 10 != 0) {
k = k / 10;
u++;
}
return u;
}
struct asd {
int x, y;
};
string s;
asd a[1000001];
int i = 0, n, m = 0, l = 0, r = 0, k = 0, z = 0, ans = 0, sx = 0, sy = 0, ex,
ey;
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void Int(T &n) {
n = 0;
int f = 1;
register int ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
n = n * f;
}
template <typename T... | 14 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> graph;
vector<int> ans;
int flag = 0;
void dfs1(int x, int pr, int f) {
if (x == f) {
flag = 1;
return;
}
ans.push_back(x);
for (int i = 0; i < graph[x].size(); i++) {
if (graph[x][i] != pr) {
dfs1(graph[x][i], x, f);
if (... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long MXN = 100 + 10;
const long long Mod = 1e9 + 7;
long long n;
long long C[MXN][MXN];
long long f[MXN], pw[MXN], sub[MXN];
long long dp[MXN][MXN][MXN], pd[MXN][MXN][MXN];
vector<long long> adj[MXN];
inline void mkay(long long& x) {
if (x >= Mod) x -= Mod;
}
v... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, h, m;
cin >> n >> h >> m;
vector<long long int> v(n + 1, h);
for (long long int i = 1; i <= m; i++) {
long long int l, r, x;
cin >> l >> r >> x;
for (long long int j = l; ... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma warning(disable : 4996)
using namespace std;
const int MAXN = 200001;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
int before, after, flag = 0;
for (int i = 0; i < n; i++) {
cin >> s;
cin >> before;
cin >> after;
if (before < after && before >= 2400) {
flag = 1;
break;
}
}
if (flag == 0)
cout << "N... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct Rec {
int L, R, U, D;
Rec() {}
void read() { scanf("%d%d%d%d", &L, &D, &R, &U); }
};
int n;
Rec rec[7];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) rec[i].read();
int L = rec[1].L, R = rec[1].R, U = rec[1].U, D = rec[1].D;
for (int i = 2;... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string second;
cin >> second;
long long int n = second.size();
long long int t;
cin >> t;
while (t--) {
long long int l, r, k;
cin >> l >> r >>... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e6 + 10;
const int mod = (int)1e9;
const int inf = (1 << 30) - 1;
int p[maxn];
int a[maxn];
int n;
int x;
int dp[maxn];
int u[maxn];
int dfs(int v) {
u[v] = 1;
if (a[v] == 0) return 1;
return dfs(a[v]) + 1;
}
int rdfs(int v) {
u[v] = 1;
if (... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(nullptr);
set<int> s;
int n;
cin >> n;
while (n--) {
int x;
cin >> x;
s.insert(x);
}
if (s.size() <= 2)
cout << "YES\n";
else if (s.size() == 3) {
vector<int> x;
for (int a : s... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long nb, ns, nc, pb, ps, pc, money;
long long bread = 0, sos = 0, cheese = 0;
bool cookie(long long mid) {
long long magic = money;
long long needed = mid * bread;
if (needed > nb) magic = magic - (needed - nb) * pb;
if (magic < 0) return false;
needed = mid ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N];
int main() {
int t;
scanf("%d", &t);
while (t--) {
memset(a, 0, sizeof a);
int h, n;
scanf("%d %d", &h, &n);
for (int i = 0; i < n; i++) cin >> a[i];
int ans = 0;
for (int i = 1; i < n; i++) {
if (a[i] - a... | 8 |
#include <bits/stdc++.h>
using namespace std;
string a, b, c, d;
int main() {
int n, i, p;
scanf("%d", &n);
cin >> a >> b;
c = a;
d = b;
sort(c.begin(), c.end());
sort(d.begin(), d.end());
for (i = 0; i < c.size(); i++) {
if (c[i] != d[i]) {
puts("-1");
return 0;
}
}
int cnt = 0;... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <int N, int M>
struct Graph {
int top;
struct Vertex {
int head;
} V[N];
struct Edge {
int v, next;
} E[M];
void init() {
memset(V, -1, sizeof(V));
top = 0;
}
void add_edge(int u, int v) {
E[top].v = v;
E[top].next = V[u].hea... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long a, n, i, f, s = 1, k, z, b, c, m, v, x, y, h, j;
int main() {
cin >> a >> b;
if (a > b) a = b;
for (i = 1; i <= a; i++) {
s = s * i;
}
cout << s << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int t;
int n, k;
string s;
int okr[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> t;
while (t--) {
cin >> n >> k;
cin >> s;
for (int i = 0; i < k; i++) {
okr[i] = 0;
}
bool ok = true;
for (i... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long power_wm(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = (res * x);
y = y >> 1;
x = (x * x);
}
return res;
}
long long power(long long x, long long y, long long p = 1000000007) {
long long res = 1;
x = x % p;... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
vector<int> adj[26];
vector<int> ans;
int visited[26];
int f = 1;
void dfs(int u) {
visited[u] = 1;
for (int i = 0; i < adj[u].size(); i++) {
int v = adj[u][i];
if (visited[v] == 1) {
f = 0;
return;
} else if (!v... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, nieb;
int main() {
cin >> m >> n;
m++;
n++;
char mp[m + 1][n + 1];
for (int i = 1; i < m; i++) {
for (int k = 1; k < n; k++) {
cin >> mp[i][k];
}
}
for (int i = 1; i < m; i++) {
for (int k = 1; k < n; k++) {
nieb = 0;
if... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long ceill(long long a, long long b) { return a / b + bool(a % b); }
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long power(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = (res... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6e5 + 10;
const long long MOD = 1e9 + 7;
const long long INF = 0x3f3f3f3f;
long long read() {
long long x = 0, f = 1;
char ch;
do {
ch = getchar();
if (ch == '-') f = -1;
} while (ch < '0' || ch > '9');
do {
x = x * 10 + ch - 48;
c... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long tp[20];
struct ans {
long long step;
long long rem;
ans() { step = -1ll; }
ans(long long s, long long r) : step(s), rem(r) {}
};
ans f[10][20][11];
ans query(int h, int n, long long x) {
int xx = (x / 10 == tp[n - 1] - 1) ? x % 10 : 10;
ans &key = f[h]... | 3 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
std::cout.tie(0);
long long n;
cin >> n;
const long long mod = 1e9 + 7;
long long perm = 1;
for (long long i = 1; i <= n; i++) {
perm = (perm * i) % mod;
};
perm = (perm - 1 + mod) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(T x) {
return x * x;
}
double dist(double x1, double y1, double x2, double y2) {
return sqrt(sqr(x1 - x2) + sqr(y1 - y2));
}
template <class T>
inline T lcm(T a, T b) {
if (a < 0) return lcm(-a, b);
if (b < 0) return lcm(a, -b);
ret... | 7 |
#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
using ll = long long;
inline int mul(int a, int b) {
return (int)((long long)a * b % mod);
unsigned long long x = (long long)a * b;
unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m;
asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5, inf = 1e9, mod = 1e9 + 7;
const long long linf = 1e18;
int main() {
int n;
scanf("%d", &n);
if (n % 2) {
printf("1 ");
for (int i = 2; i <= n; i += 2) printf("%d %d ", i + 1, i);
} else {
for (int i = 1; i <= n; i += 2) printf("%d %d "... | 9 |
#include <bits/stdc++.h>
using namespace std;
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; }
void _print(unsigned long long t) { cerr << t; }
... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
double x, y;
};
double Dist(Point p1, Point p2) {
return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}
struct T {
bool operator<(const T& o) const { return false; }
};
bool ISLETTER(char t) {
if (t >= 'A' && t <= 'Z') return t... | 7 |
#include <bits/stdc++.h>
using namespace std;
const vector<pair<long long int, long long int>> dir4 = {
{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
const vector<pair<long long int, long long int>> dir8 = {
{-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}};
template <class T>
bool chmin(T& a, T b) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, t, i, j, a[200005], b[200005];
long long sum[200005];
double c;
int main() {
scanf("%d%d%lf", &n, &t, &c);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
for (i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
scanf("%d", &m);
for (i = 0; i < m; i++) scanf("%... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int A[200007], B[10000], C[10000];
long long int aa(long long int M) {
long long int c, k, i, t, x, y, z, j, b, s, T, V, F, f, a, m, n, p, N;
s = 0;
N = 2;
while (N <= M) {
N = N * 2;
s++;
}
N = 3;
while (N <= M) {
N = N * 3;
s++;
}... | 5 |
#include <bits/stdc++.h>
int in() {
int x = 0;
char c = getchar();
bool f = 0;
while (c < '0' || c > '9') f |= c == '-', c = getchar();
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return f ? -x : x;
}
template <typename T>
inline void chk_min(T &_, T __) {
_ = _ < _... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int maxD = 10;
int n, q;
char s[maxn];
template <typename T>
bool updmn(T& A, const T& B) {
return A > B ? A = B, 1 : 0;
}
int curS[maxD], fstS[maxn][maxD], sndS[maxn][maxD];
int fg[maxn];
int l[maxn], r[maxn];
inline void del(int o) {
l[r... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, ax, ay, bx, by, cx, cy;
cin >> n >> ax >> ay >> bx >> by >> cx >> cy;
if ((ax > bx && ax > cx) || (ax < bx && ax < cx)) {
if ((ay > by && ay > cy) || (ay < by && ay < cy)) {... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 100010;
int N, M;
int cur_kind[maxN];
vector<int> kind_list[3];
vector<pair<int, int> > G[maxN];
void input() {
cin >> N >> M;
int u, v;
char c;
for (int i = 1; i <= M; i++) {
cin >> u >> v >> c;
G[u].push_back({v, c});
G[v].push_back({u... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
return a < b ? (a = b, true) : false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
if (n <= 9) {
cou... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, r;
const double PI = 2 * acos(0.0);
int main() {
scanf("%d%d", &n, &r);
double x = cos(PI / n);
double y = sin(PI / n);
double x2 = cos(PI + 2 * PI / n);
double y2 = sin(PI + 2 * PI / n);
double m = (y - y2) / (x - x2);
double b = y2 - m * x2;
printf(... | 13 |
#include <iostream>
using namespace std;
#include <bits/stdc++.h>
#include <cmath>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<vector<int >> vvi;
#define umap unordered_map
#define uset unordered... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b);
long long cross_prod(long long ax, long long ay, long long bx, long long by,
long long cx, long long cy);
long long sum_digit(long long A);
long long get_mask(long long x);
class SegmentTree {
public:
vector<i... | 5 |
#include <bits/stdc++.h>
using namespace std;
mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T>
inline void chkmax(T &x, T y) {
if (x < y) x = y;
}
template <typename T>
inline void chkmin(T &x, T y) {
if (x > y) x = y;
}
inline int read() {
int x = 0;
char c = ... | 17 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, w;
cin >> n >> w;
vector<int> a(2 * n);
for (int i = 0; i < (2 * n); i++) cin >> a[i];
sort(a.begin(), a.end());
double max_X = w / (3.0 * n);
max_X = min(max_X, double(a[0]));
max_X = min(max_X, a[n] / 2.0);
cout << fixed << (max_X *... | 7 |
#include <bits/stdc++.h>
int main() {
long n(0);
scanf("%ld", &n);
long* array = new long[n];
for (int k = 0; k < n; k++) {
scanf("%ld", array + k);
}
std::sort(array, array + n);
long index(n - 1);
for (long p = n / 2 - 1; p >= 0; p--) {
if (2 * array[p] <= array[index]) {
--index;
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int q, n, a, b, ca, cb, cc;
char x[300005];
vector<int> v;
void add(int i) {
if (i >= b * 2)
cc++;
else if (i >= a)
ca++;
else if (i >= b)
cb++;
}
void sub(int i) {
if (i >= b * 2)
cc--;
else if (i >= a)
ca--;
else if (i >= b)
cb--;
}
int... | 17 |
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int x;
scanf("%d", &x);
return x;
}
const int INF = 1e9 + 10;
const long long LINF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000 + 100;
const int MN = 5e3 + 10;
int n, m;
vector<int> adj[MN], rev[MN];
int es[MN], ee[MN];
vector<int> comp[MN], topol;
in... | 21 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[200010];
int n, t[200010], p[200010];
long long memo[200010];
long long dp(int i) {
if (i == 0) return 0;
long long &r = memo[i];
if (r != -1) return r;
long long r1 = 2000000000;
if (i - 2 >= 1) r1 = (a[i].first - a[i - 2].first) + dp(i - 3);
l... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
long long ans = 0;
for (int i = (0); i < (n); ++i) {
long long t, T, x, cost;
cin >> t >> T >> x >> cost;
if (t >= T) {
ans += cost + m * x;
continue;
}
long long aux1 = cost;
if (m > (T - t))... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 10;
const int MOD = 1e6 + 37;
int n;
char path1[MAX_N], path2[MAX_N];
int map1[200], map2[200];
int deg4[MAX_N];
void init() {
map1['N'] = 'N' - 'A';
map1['E'] = 'E' - 'A';
map1['S'] = 'S' - 'A';
map1['W'] = 'W' - 'A';
map2['N'] = 'S' - 'A'... | 17 |
#include <bits/stdc++.h>
using namespace std;
int tram(int a[], int b[], int n) {
int Large = b[0];
int j = b[0];
for (int i = 1; i < n; i++) {
j -= a[i];
j += b[i];
if (j > Large) {
Large = j;
}
}
return Large;
}
int main() {
int n;
cin >> n;
int a[1000], b[1000];
for (int i = 0... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
int n, a[N], m, b[N];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + m);
int uk = 1;
for (int i = 1; i <= n; i++) {
while (uk... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, k, x, b;
int t[2][2010];
int main() {
scanf("%d%d%d", &n, &k, &x);
for (int i = 1, w; i <= n; i++) scanf("%d", &w), t[1][w]++;
b = 0;
while (k--) {
int cnt = 0;
b ^= 1;
for (int i = 0; i <= 2000; i++) t[b ^ 1][i] = 0;
for (int i = 0; i <= 2000... | 10 |
#include <bits/stdc++.h>
struct node {
double maxSum, leftSum, rightSum, sum;
};
int point[150000], segment[150000], probability[150000];
node tree[4 * 150000];
int n, m, c;
void buildTree(int l, int r, int i) {
if (l == r) {
tree[i].maxSum = (double)segment[l] / 2 - (double)c * probability[l] / 100;
tree[i... | 14 |
#include <bits/stdc++.h>
using namespace std;
int s[3005];
int n, k;
int ct[2];
vector<int> v;
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
char x;
scanf(" %c", &x);
if (x == 'R')
s[i] = 1;
else {
s[i] = 0;
v.push_back(i);
}
ct[s[i]]++;
}
int sum = ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int get_dir(char c) {
if (c == 'U') return 0;
if (c == 'R') return 1;
if (c == 'D') return 2;
if (c == 'L') return 3;
}
char setdir(int dx, int dy) {
if (dx > 0) return 'R';
if ... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long int inf = 1e18;
long long int p = 998244353;
long double eps = 1e-9;
long long int power(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, q, fa[200010], dep[200010], dep2[200010], f2[200010][25],
f[200010][25], lw[200010], din[200010], par[200010],
cnt = 0, cnt2 = 0, sum[200010], col[200010];
bool vis[200010], odd[200010];
vector<long long> sz[200010], vt[200010], vt2[200010];
stack<lo... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int main() {
cin >> n >> m >> k;
if (m < k || n % 2 == 0) {
cout << "Marsel";
return 0;
}
if (m % 2 == 0 && m / 2 >= k) {
cout << "Timur";
return 0;
} else if (m % 2 == 0) {
cout << "Marsel";
return 0;
}
int d = 1, mx = 0;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, n;
cin >> k >> n;
map<string, vector<int> > m;
map<string, vector<int> >::iterator it;
string s;
int val, ans = 0, maxind = 0;
for (int i = 1; i <= k; ++i) cin >> s >> val, m[s].push_back(val);
for (it = m.begin(); it != m.end(); ++it)
... | 13 |
#include <bits/stdc++.h>
using namespace std;
long double TL = 1.0;
bool is_tl = 0;
long long CALLS = 0;
inline bool IS() {
if (++CALLS == 1000) {
CALLS = 0;
is_tl |= clock() > (TL - 0.1) * CLOCKS_PER_SEC;
}
return is_tl;
}
template <typename T1, typename T2>
inline void amin(T1 &a, T2 b) {
if (a > b) a... | 9 |
#include <bits/stdc++.h>
using namespace std;
int occur3[1000000];
int occur[(1 << 12)];
int three[(1 << 12)];
int w, n, m;
int var[30000];
int add[256][2];
bool inval[256][2];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
scanf("%d%d%d", &w, &n, &m);
clock_t z = clock();
for (int i = 0... | 20 |
#include <bits/stdc++.h>
char nc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
int rd() {
int x = 0;
char c = nc();
while (!isdigit(c)) c = nc();
while (isdigit(c)) x = x * 10 + c - ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1100000000000000000;
const long double PI =
3.141592653589793238462643383279502884197169399375105820974944;
void solve() {
long long n;
cin >> n;
vector<long long> v;
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
lo... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1010;
const int inf = 0x3f3f3f3f;
int dp[250010][2];
int main() {
memset(dp, 0x3f, sizeof dp);
int n, k;
scanf("%d %d", &n, &k);
vector<int> vec[2];
for (int i = 0; i < k; i++) {
int x;
scanf("%d", &x);
if (x == n) {... | 15 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> dist[300010], road[300010];
long long city[300010], ans = 0, dp[300010] = {0};
void dfs(long long i, long long fa) {
ans = max(ans, dp[i]);
for (long long j = 0; j < road[i].size(); ++j) {
if (fa == road[i][j]) continue;
dfs(road[i][j], i);
... | 10 |
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wwrite-strings"
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &out, const pair<T, U> &A) {
out << A.first << "_" << A.second;
return out;
}
template <template <typename, typename> class ContainerT, typename ValueT>
ostream &ope... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3 + 7;
int a[maxn];
int vis[maxn];
vector<int> huan[maxn];
int link[maxn];
vector<int> ans;
int belong[maxn];
void dfs(int now, int index) {
if (vis[now]) return;
vis[now] = 1;
belong[now] = index;
huan[index].push_back(now);
dfs(a[now], index);... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
vector<int> vec[N];
int ans[N];
int vis[N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int x, y;
scanf("%d%d", &x, &y);
vec[x].push_back(y);
}
for (int i = 1; i <= n; i++) {
if (vis[i] == 0) ... | 22 |
#include <bits/stdc++.h>
using namespace std;
char grid[101][101];
int main() {
int t, i, n, m, j;
cin >> t;
while (t--) {
cin >> n >> m;
int ans = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
cin >> grid[i][j];
if (j == m - 1 && grid[i][j] == 'R') ans += 1;
if ... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> a[1000005], v[1000005];
vector<pair<int, int> > b;
int fa[1000005];
int d[1000005];
bool in[1000005];
int dist[1000005];
int n, m;
int get(int x, int y) { return (x - 1) * m + y; }
bool cmp(pair<int, int> x, pair<int, int> y) {
return a[x.first][x.second] < a[... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 100;
const long long big = 1e18;
const long long block = 800;
const long long mod = 998244353;
long long n;
long long q;
long long z[N];
long long dp[N];
long long ij = 0;
vector<pair<long long, long long> > Q[N];
long long was[N];
long long ans[N]... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int c[N], v[N], Next[N], cnt_node = 0;
int L = 0, R = 1, len[2], head[2], n = 0, ans[N][2];
char s1[N], s2[N];
int new_node(int color, int tot, int nxt) {
cnt_node++, c[cnt_node] = color;
v[cnt_node] = tot, Next[cnt_node] = nxt;
return cnt_node;... | 20 |
#include <bits/stdc++.h>
long long get() {
long long x = 0;
char s = getchar();
while (s < '0' || s > '9') s = getchar();
while (s >= '0' && s <= '9')
x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();
return x;
}
const long long M = 1e5 + 5, mo = 1e9 + 7;
long long n, m, head[M], cntedge, c[M];
bool vis[... | 14 |
#include <bits/stdc++.h>
using namespace std;
char mp[505][505];
bool ok[505][505], vis[505][505];
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
int main() {
int N, M, K, space = 0, x, y;
scanf("%d%d%d", &N, &M, &K);
for (int i = 1; i <= N; i++) {
scanf("%s", mp[i] + 1);
for (int j = 1... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
vector<int> e[N];
double ans = 0;
int n, h, t, rt, tot, d[N], vis[N], q[N];
void dfs(int u, int a, int b) {
if (d[u] == 2)
++b;
else
++a;
vis[u] = rt;
if (b == tot)
ans += 1.0 / (a + 2);
else if (b <= 2)
ans += 1.0 / (a + b);
... | 22 |
#include <bits/stdc++.h>
using namespace std;
void itval(istream_iterator<string> it) {}
template <typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
itval(++it, args...);
}
const long long int MOD = 1e9 + 7;
template <typename T>
inline voi... | 13 |
#include <bits/stdc++.h>
const double pi = 3.1415926535897932384626433832795;
bool test(long long x1, long long y1, long long x2, long long y2, long long x3,
long long y3) {
long long vx1 = x2 - x1;
long long vy1 = y2 - y1;
long long vx2 = x3 - x1;
long long vy2 = y3 - y1;
return ((vx1 * vx2 + vy1 *... | 11 |
#include <bits/stdc++.h>
const int MXN = 1e6 + 100;
const long long MNN = 5e3 + 100;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long OO = 1e9 + 500;
using namespace std;
long long n, k;
bool check(int x, int y) {
if (x == -1 || y == -1) return 0;
cout << 1 << ' ' << x << ' ' << y << endl;... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct per {
long long op, cl, cmax, cmin;
};
per tree[4000001];
per merge(per a, per b) {
per result;
result.op = a.op + b.op;
result.cl = a.cl + b.cl;
result.cmax = max(a.cmax, a.op - a.cl + b.cmax);
result.cmin = min(a.cmin, a.op - a.cl + b.cmin);
return re... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int t;
cin >> t;
string s;
cin >> s;
while (t--) {
for (int i = 0; i < n; i++) {
if (i != n - 1 && s[i] == 'B' && s[i + 1] == 'G') {
s[i] = 'G';
s[i + 1] = 'B';
i++;
}
}
}
cout << s;... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
long long int a[t], q = 0;
for (long long int i = 0; i < t; i++) {
cin >> a[i];
}
for (long long int i = 0; i < t; i++) {
q += a[i] - 1;
if (q % 2)
cout << "1" << endl;
else
cout << "2" << endl;... | 3 |
#include <bits/stdc++.h>
const double PI = acosl(-1.0);
int bits[1 << 23];
void pre(int n) {
int LOG = 0;
while (1 << (LOG + 1) < n) {
LOG++;
}
for (int i = 1; i < n; i++) {
bits[i] = (bits[i >> 1] >> 1) | ((i & 1) << LOG);
}
}
std::vector<std::complex<double> > fft(std::vector<std::complex<double> > ... | 17 |
#include <bits/stdc++.h>
const int P = 1e9 + 7;
using namespace std;
template <typename T>
inline void ckmax(T &a, T b) {
(a < b) && (a = b);
}
template <typename T>
inline void ckmin(T &a, T b) {
(a > b) && (a = b);
}
inline int mul(int a, int b) { return 1ull * a * b % P; }
inline int add(int a, int b) { return a... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long int get_identical(int n) { return (n * (n - 1) * (n - 2)) / 6; }
char get_third(char a, char b) {
if ((a == 'S' && b == 'E') || (a == 'E' && b == 'S'))
return 'T';
else if ((a == 'E' && b == 'T') || (a == 'T' && b == 'E'))
return 'S';
else
return... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 10;
const long long mod = 998244353;
const long long M = 1e5 + 10;
long long n, k, ans;
vector<long long> v, _v;
vector<string> str;
unordered_map<string, vector<long long>> val;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cou... | 13 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.