solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
char a[505][505];
int n, m, k, s[505][505], b[505][505];
int main() {
int i, j, l1, l2, c1, c2;
long long sol = 0;
cin.sync_with_stdio(0);
cin >> n >> m >> k;
for (i = 1; i <= n; ++i) cin >> (a[i] + 1);
if (n < 3 || m < 3) {
cout << "0\n";
return 0;
}
... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <typename flow_t, typename cost_t>
struct MinCostFlow {
struct Edge {
int dst;
flow_t capacity;
cost_t cost;
size_t rev;
bool isrev;
};
struct RadixHeap {
static constexpr int bit = sizeof(cost_t) * 8;
array<vector<pair<cost_t, int... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0, k = 0, counter = 0;
int arr[50];
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
for (int i = 0; i < n; i++) {
if (arr[i] >= arr[k - 1] && arr[i] > 0) counter++;
}
cout << counter << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
int n;
struct man {
int _dsfdsf;
int _dfjdsj;
void setLeft(int x) {
if (x < 0 || x >= n) x = -1;
_dsfdsf = x;
}
void setRight(int x) {
if (x < 0 || x >= n) x = -1;
_dfjdsj = x;
}
void remove();
};
char... | 11 |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
#define fi first
#define print(v) for(ll i:v) cout<<i<<ss
#define se second
#define pb push_back
#define nn ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const int MAX = 100005;
int main() {
double h, l;
cin >> h >> l;
long long int i, j;
double a, b, c;
a = h * h;
b = l * l;
c = 2 * h;
a = b - a;
a = a / c;
std::cout << std::fixed;
cout << setprecision(10) << a << end... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int INF = 1e9;
const long long IINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const char dir[4] = {'D', 'R', 'U', 'L'};
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
for (T &x : v) is >> x... | 15 |
#include <bits/stdc++.h>
using namespace std;
vector<int> time_stamp;
int n, m;
int get_seconds(int mo, int d, int h, int mi, int s) {
int curd = 0;
if (mo > 1) curd += 31;
if (mo > 2) curd += 29;
if (mo > 3) curd += 31;
if (mo > 4) curd += 30;
if (mo > 5) curd += 31;
if (mo > 6) curd += 30;
if (mo > 7)... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
long long int counta = 0;
long long int countb = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '-')
counta++;
else
countb++;
}
if (countb == 0) {
cout << "YES";
return 0;
}
if (counta % c... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 311111;
int x[MAXN], y[MAXN];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < m; j++)
if (s[j] == 'S') {
x[i] = 1;
y[j] = 1;
}
}
int N = n;
int M... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long double PI = 4 * atan((long double)1);
long long power(long long a, long long n) {
long long res = 1;
while (n) {
if (n % 2) res *= a;
a *= a;
n /= 2;
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.t... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct SumSegmentTree {
private:
vector<int> v;
vector<int> u;
int n;
const int NULL_VALUE = 1e9;
public:
SumSegmentTree(int num) {
v.resize((1 << (int)(ceil(log2(num)) + 1)) - 1, NULL_VALUE);
u.resize(v.size(), NULL_VALUE);
n = v.size() / 2;
}
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, w, sum = 0;
cin >> k >> n >> w;
for (int i = 1; i <= w; i++) {
sum = sum + (i * k);
}
if (sum == n || sum < n) {
cout << 0;
}
if (sum > n) {
cout << sum - n;
}
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
using namespace std;
namespace {
namespace shik {
template <class T>
void _R(T &x) {
cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" SCNd64, &x); }
void _R(doub... | 19 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:256000000")
template <class T>
T sqr(T a) {
return a * a;
}
long long n, k;
int l = 0;
int vek[1000000];
pair<long long, int> les[1000000];
pair<long long, int> great[1000000];
int pg, pl;
int start = 22579;
void reczap(int mask, int x, int... | 21 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int child_num = 26;
char vir[205][205];
int v[205];
class AC {
private:
int ch[205][child_num];
int fail[205];
int Q[205];
long long val[205];
int sz;
int id[128];
lo... | 17 |
#include <bits/stdc++.h>
using namespace std;
int fx[] = {0, 1, 1, 1, 0, -1, -1, -1};
int fy[] = {1, 1, 0, -1, -1, -1, 0, 1};
int cnt[100005], top;
bool flag = false;
vector<int> data[100005], res;
void bfs() {
queue<int> q;
q.push(top);
while (!q.empty()) {
int u = q.front();
q.pop();
int tmp = 0;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, M = 1e9 + 7;
const unsigned long long base = 13331;
const double Pi = acos(-1.0);
const long long C = 299792458;
const int inf = 0x3f3f3f3f;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t, i, j, n, m, k, l, r, x, y;
cin >> t;
while (t--) {
cin >> n >> k;
int c[n + 1];
int a[n + 1];
memset(c, 0, sizeof(c));
;
vector<int> v;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, c;
string s[10022];
map<int, set<string>> k;
char d;
map<string, int> vis;
bool com(string i, string j) {
if (i + d < j + d) return 1;
return 0;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s[i];
int l = s[i].size();
c += l;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const string table[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
"1101011", "1101111", "1010010", "1111111", "1111011"};
void solve() {
int n, k;
cin >> n >> k;
vector<string> a(n);
vector<vector<int>> b(n, vector<int>(10));
f... | 9 |
#include <bits/stdc++.h>
using namespace std;
int p(int n) {
int cnt = 0;
n--;
while (n) {
n >>= 1;
cnt++;
}
return cnt;
}
int main() {
map<int, int> m, f;
int n;
cin >> n;
int cnt = 0;
int a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
m[a[i]]++;
}
sort(a, a + n);
for (int... | 5 |
#include <bits/stdc++.h>
using namespace std;
int get() {
char ch;
while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
;
if (ch == '-') {
int s = 0;
while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
return -s;
}
int s = ch - '0';
while (ch = getchar(), ch >= '0' &... | 22 |
#include <bits/stdc++.h>
using namespace std;
int r, c, n, k;
int dem[11][11];
int count_rec(int x1, int y1, int x2, int y2) {
int res = 0;
for (int i = x1; i <= x2; i++)
for (int j = y1; j <= y2; j++) res = res + dem[i][j];
return res;
}
int main() {
cin >> r >> c >> n >> k;
for (int i = 0; i <= r; i++)
... | 3 |
#include <bits/stdc++.h>
using namespace std;
class answer {
private:
int distant, cityCnt;
public:
void __construct(int distant) {
this->distant = distant;
this->cityCnt = 1;
}
void cmp(int distant) {
if (distant < (this->distant))
__construct(distant);
else if (distant == (this->dista... | 3 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
template <typename T>
T min(T x, T y) {
return x < y ? x : y;
}
template <typename T>
T max(T x, T y) {
return x > y ? x : y;
};
const long long MAXN = 100005;
const long long INF = 200000000000000;
struct data {
long long id;
long long w;
data(long lon... | 21 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
char a[2005][2005];
int ans[2005];
int b[2005 * 2005][3];
int n, m, k;
int main() {
int i, j, t;
scanf("%d%d%d", &n, &m, &k);
for (i = 0; i < n; ++i) {
scanf("%s", a[i]);
for (j = 0; j < m; ++j) {
t = -... | 6 |
#include <bits/stdc++.h>
using namespace std;
int t, k;
long long p[105];
int q[105];
long long V, ans, ansa, ansb, ansc, a, b, c;
long long MAXA, MAXB;
inline void bfs(int dep, long long sum) {
if (sum > MAXB) return;
if (dep > k) {
if (sum < a) return;
b = sum, c = V / a / b;
if (a * b + b * c + a * c... | 21 |
#include <bits/stdc++.h>
using namespace std;
int a[10000005];
string t[100005];
int main() {
int i, j, n, k, x, m = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
cin >> t[i];
scanf("%d", &k);
for (j = 1; j <= k; j++) {
scanf("%d", &x);
if (t[a[x]].length() < t[i].length()) a[x] = i;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double esp = 1e-6;
const int maxn = 4010;
const int mod = 1e9 + 7;
long long dp[maxn][maxn];
int main() {
dp[0][0] = 1;
for (int i = 1; i < maxn; i++) {
dp[i][0] = dp[i - 1][i - 1] % mod;
for (int j... | 11 |
#include <bits/stdc++.h>
using ll = long long int;
const int INF = (1 << 30);
const ll INFLL = (1ll << 60);
const ll MOD = (ll)(1e9 + 7);
void mul_mod(ll& a, ll b) {
a *= b;
a %= MOD;
}
void add_mod(ll& a, ll b) {
a = (a < MOD) ? a : (a - MOD);
b = (b < MOD) ? b : (b - MOD);
a += b;
a = (a < MOD) ? a : (a -... | 12 |
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
typedef unsigned short int us;
typedef unsigned int ui;
typedef unsigned long long int ull;
typedef short int si;
typedef int in;
typedef long long int lli;
typedef char ch;
typedef float fl;
typedef double dou;
const double Pi = 2 * acos(0.0);
... | 3 |
#include <bits/stdc++.h>
std::multiset<int> s[100010];
int inp() {
char c = getchar();
while (c < '0' || c > '9') c = getchar();
int sum = 0;
while (c >= '0' && c <= '9') {
sum = sum * 10 + c - '0';
c = getchar();
}
return sum;
}
std::string str[100010];
bool have[100010];
void merge(int a, int b) {... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, m, ct;
int main() {
cin >> n >> m;
for (int i = 0; i <= sqrt(n); ++i) {
for (int j = 0; j <= sqrt(m); ++j) {
if ((i * i) + j == n && i + (j * j) == m) {
++ct;
}
}
}
cout << ct;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long a[N];
int main() {
int w, l;
scanf("%d %d", &w, &l);
for (int i = 1; i < w; i++) scanf("%lld", a + i), a[i] += a[i - 1];
long long ans = 1LL << 60;
for (int i = 1; i < w; i++)
if (i >= l) ans = min(ans, a[i] - a[i - l]);
prin... | 11 |
#include <bits/stdc++.h>
const long long inf = std::numeric_limits<long long>::max();
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
if (n <= 2) {
cout << -1;
return 0;
}
if (n == 3) {
cout << 210;
return 0;
}
int c = n % 6;
if ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const long long mod = 998244353;
long long fun[N] = {1};
struct node {
int xx, yy;
} a[N];
bool cmp(node i, node j) {
if (i.xx == j.xx) return i.yy < j.yy;
return i.xx < j.xx;
}
int x[N], y[N];
int main() {
int n;
scanf("%d", &n);
for (in... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long b;
scanf("%lld", &b);
int ret = 1;
for (int d : {2, 3, 5}) {
int c = 1;
while (b % d == 0) ++c, b /= d;
ret *= c;
}
for (long long d = 7; d * d <= b; d += 2) {
int c = 1;
while (b % d == 0) b /= d, ++c;
ret *= c;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
void solve() {
int n;
cin >> n;
vector<int> e(n);
for (int i = 0; i < n; ++i) {
cin >> e[i];
}
sort(e.begin(), e.end());
int res = 0;
for (int i = 0; i < n; ++i) {
int cnt = 0;
int j = i;
whil... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T min(T &a, T &b) {
return a < b ? a : b;
}
template <class T>
inline T max(T &a, T &b) {
return a > b ? a : b;
}
template <class T>
void read(T &x) {
char ch;
while ((ch = getchar()) && !isdigit(ch))
;
x = ch - '0';
while ((ch = ge... | 20 |
#include <bits/stdc++.h>
using namespace std;
int la, lb;
int Length(int n) {
int res = 0;
while (n) {
res++;
n /= 7;
}
return res == 0 ? 1 : res;
}
int check(int n, int m) {
set<int> st;
for (int i = 0; i < la; i++) {
st.insert(n % 7);
n /= 7;
}
for (int i = 0; i < lb; i++) {
st.ins... | 9 |
#include <bits/stdc++.h>
using namespace std;
int calc(vector<int> x) {
int ret = 0;
for (int i = 0; i < x.size(); i++) {
for (int j = i + 1; j < x.size(); j++) {
if (x[i] > x[j]) ret++;
}
}
return ret;
}
int main() {
int n, k, i, val, j;
cin >> n >> k;
vector<int> v;
for (i = 0; i < n; i+... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 7;
const double eps = 1e-9;
int T, N;
long long x, y, p, q;
int main() {
scanf("%d", &T);
while (T--) {
scanf("%lld%lld%lld%lld", &x, &y, &p, &q);
long long l = -1, r = 1e9;
while (l <= r) {
long long mid = (l + r) >> 1;
lo... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long inv2 = 500000004;
inline char gc() {
static char buf[131072], *head = buf, *tail = buf;
return ((head == tail) &&
(tail = (head = buf) + fread(buf, 1, 131072, stdin), head == tail))
? EOF
: *head++;
}
inline int read()... | 19 |
#include <bits/stdc++.h>
using namespace std;
int x[20][20], r, c, n, k;
int main() {
cin >> r >> c >> n >> k;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
x[a][b] = 1;
}
int ans = 0, s;
for (int i = 1; i <= r; i++)
for (int j = 1; j <= c; j++)
for (int p = i; p <= r; p++)
... | 22 |
#include <bits/stdc++.h>
using namespace std;
map<pair<string, string>, int> Map;
const int maxn = 500;
int C[maxn];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int N, A, B, K, F;
cin >> N >> A >> B >> K >> F;
int costo = 0, ap = 0;
string a, b, c;
for (int i = 1; i <= N; i++) {
if (i == 1)... | 10 |
#include <bits/stdc++.h>
using namespace std;
class InputReader {
public:
InputReader() {
input_file = stdin;
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
inline InputReader &operator>>(int &n) {
while ((buffer[cursor] < '0' || buffer[cursor] > '9') &&
buffer[cursor] != '-') {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long v[21];
memset(v, 0, sizeof v);
int b;
for (int i = 0; i < n; i++) {
cin >> b;
v[b + 10]++;
}
long long c = 0;
for (int i = 0; i < 10; i++) {
c += v[i] * v[20 - i];
}
c += (v[10] * (v[10] - 1)) / 2;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
string s[10];
cin >> str;
for (int i = 0; i < int(10); ++i) cin >> s[i];
for (int i = 0; i < int(8); ++i) {
for (int j = 0; j < int(10); ++j) {
if (str.substr(i * 10, 10) == s[j]) {
printf("%d", j);
break;
}... | 1 |
#include <bits/stdc++.h>
using namespace std;
double Ax, Ay, Bx, By, Cx, Cy;
int n;
double a[211111], b[211111], o[211111];
pair<double, int> qa[211111], qb[211111];
double dist(double x, double y, double xx, double yy) {
return sqrt((x - xx) * (x - xx) + (y - yy) * (y - yy));
}
int main() {
ios::sync_with_stdio(fa... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int mo = 1000000009;
void adm(int &x, int y) {
x += y;
if (x >= mo) {
x -= mo;
}
}
int sol, D[2][32][32][32][2];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, h;
cin >> N >> h;
D[0][0][0][0][1] = 1;
int p = 1;
for (int i ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<int> arr(n);
vector<int> b(32, 0);
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < m; i++) {
int x;
cin >> x;
b[x]++;
}
sort(... | 11 |
#include <bits/stdc++.h>
struct Pair {
int first, second;
bool operator<(const Pair& rhs) const {
return first < rhs.first || (first == rhs.first && (second < rhs.second));
}
};
int n, m;
int* dp[2000][26];
int q[2000];
Pair ans[2001][2001];
int nxt[2001][26];
char s[1000001];
inline Pair& min(Pair& A, Pair& ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
struct tt {
int x, y;
tt(int x, int y) : x(x), y(y) {}
tt() {}
};
bool operator<(tt a, tt b) { return (a.x + a.y) % m < (b.x + b.y) % m; }
int main() {
scanf("%d%d", &n, &m);
multiset<int> a, b;
priority_queue<tt> q;
for (int i = 0; i < n; i++) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, m, k, ed;
unordered_map<string, int> mp;
long long ceng[maxn], G[50];
inline string read() {
char ch = getchar();
string st1 = "";
while (!((ch >= 'a') && (ch <= 'z'))) ch = getchar();
while ((ch >= 'a') && (ch <= 'z')) st1 += ch, ch ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 201;
double mem[maxN][maxN][maxN];
int N;
pair<int, double> p[maxN];
double f(int n, int l, int k) {
double &res = mem[n + 1][l][k];
if (res >= 0) return res;
if (n < 0) return res = l ? 0 : 1;
res = (1 - p[n].second) * f(n - 1, l, k);
if (p[n].fi... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 2e7, M = 1e6 + 3;
map<int, int> m2;
bool b[N];
int a[N];
vector<int> v;
long long ans = 0, n, l, r, x;
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
cout << (a + b ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }
int T;
struct Node {
int group, id, v;
};
vector<Node> a;
int t[200005];
bool cmp(Node x, Node y) { return x.v < y.v; }
int main() {
std::ios::sync_with_stdio(fals... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, f[50], sz[50];
char g[50][50];
int cc[50], p[50], tot;
int id[50], G[50][50];
int get(int x) { return f[x] == x ? x : f[x] = get(f[x]); }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) f[i] = i;
for (int i = 1; i <= n; i++) {
scanf("%s", g[i] + ... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.length() % 2 != 0) {
cout << "-1";
return 0;
}
int u = 0;
int d = 0;
int l = 0;
int r = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == 'R')
r++;
else if (s[i] == 'L')
l++;
else i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int A[110000];
vector<int> x[110000];
const int N = 100000;
int n;
void add(int k1, int k2) {
for (; k1 <= n; k1 += k1 & (-k1)) A[k1] += k2;
}
int find(int k1) {
int ans = 0;
for (; k1; k1 -= k1 & (-k1)) ans += A[k1];
return ans;
}
int calc(int l, int r) {
if (l >... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<int>> g;
vector<long long> A, B, a, b;
set<int> active;
long long gain = 0;
bool dfs(int u, int pre, long long power) {
active.insert(u);
for (int v : g[u]) {
if (v == pre) continue;
if (power > a[v]) {
if (active.count(v) || dfs(v,... | 22 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int loop = 0;
int par[55];
int deg[55];
int maxd = 0;
int find(int x) {
if (par[x] == x)
return x;
else
par[x] = find(par[x]);
}
int main() {
memset(deg, 0, sizeof(deg));
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) par[i] = i;
for (int... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {
return {l.first + r.first, l.second + r.second};
}
typedef void (*callback_function)(void);
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const in... | 17 |
#include <bits/stdc++.h>
using namespace std;
int a[2005], pd[2005], n;
int solve(long long dist) {
for (int i = 0; i < n; i++) {
pd[i] = i;
for (int j = 0; j < i; j++) {
if (abs(a[i] - a[j]) <= dist * (i - j)) {
pd[i] = min(pd[i], pd[j] + i - j - 1);
}
}
}
long long res = pd[n - 1... | 12 |
#include <bits/stdc++.h>
using namespace std;
int ok, sx, sy, vis[1005][1005], a[1005][1005], in[1005][1005], row[1005][1005],
col[1005][1005], n, m, val;
int w[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
void solve(int cur) {
queue<pair<int, int> > q;
memset(vis, 0, sizeof(vis));
memset(in, 0, sizeof(in));
q.push(... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(ios::badbit | ios::failbit);
int n;
long long k;
string l, r;
cin >> n >> k >> l >> r;
long long res = 0, width = 1;
for (auto i = 0; i < n; ++i) {
width = min<long long>(numeric_limits<int>::ma... | 12 |
#include <bits/stdc++.h>
using namespace ::std;
int ara[1000009] = {0};
int main() {
int n, m, k, a;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> a;
ara[a]++;
}
int cnt = 0, res = 0;
for (int i = 1; i <= 1000007; i++) {
if (ara[i]) {
cnt++;
}
if (i - m > 0 and ara[i - ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, ans = 0;
cin >> s;
string s1, s2;
cin >> s1 >> s2;
int nw, tn;
for (int i = 0; i < s; i++) {
int nw = s1[i] - 48, tn = s2[i] - 48;
if (nw > tn && (nw - tn) <= 5)
ans += (nw - tn);
else if (nw < tn && (tn - nw <= 5))
an... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
scanf("%d", &x);
scanf("%d", &y);
int r = 1;
for (; x * x + y * y > r * r; r++)
;
if (x * x + y * y == r * r) {
printf("black\n");
return 0;
}
if (x == 0 || y == 0) {
printf("black\n");
return 0;
}
if (x * y > 0... | 5 |
#include <bits/stdc++.h>
long long a, b, i, k, sum;
long long z[10000009];
long long v[10009];
using namespace std;
int main() {
cin >> a >> b;
for (i = 2; i * i <= a + b; i++) {
v[k] = i * i;
k++;
}
for (i = 0; i < k; i++) {
sum = v[i];
while (sum <= a + b) {
z[sum] = sum / v[i];
su... | 7 |
#include <bits/stdc++.h>
using namespace std;
namespace iB {
char buf[1 << 21], *p1 = buf, *p2 = buf;
}
namespace oB {
char buf[1 << 21], *p1 = buf, *p2 = buf + (1 << 21);
}
namespace Fastio {
struct Reader {
char endch;
Reader() { endch = '\0'; }
Reader& operator>>(char& ch) {
ch = (iB::p1 == iB::p2 && (iB::... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch)) f = ch == '-', ch = getchar();
while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
const int N = 5, mod = 998244353;
void Add(int &x, int... | 27 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int H = 0, T = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'H')
H++;
else
T++;
}
int ans = INT_MAX;
for (int i = 0; i < n; i++) {
int j, swap = 0;
for (j = 0; j < T; j++) {
... | 8 |
#include <bits/stdc++.h>
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
const int MAX = 5000100;
bool prime[MAX];
vector<int> P;
long long num[MAX];
long long sum[MAX];
void init() {
memset(prime, true, sizeof(prime));
prime[0] = prime[1] = false;
for (int i = 2; i < MAX; i++... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long gt[1000005], igt[1000005], p, t, kq, mod, n, x, kocot, y,
luythua[1000005];
long long lt(long long x, long long y) {
if (y == 0) return 1;
long long XXX = lt(x, y / 2);
if (y % 2) return XXX * XXX % mod * x % mod;
return XXX * XXX % mod;
}
long long C(... | 17 |
#include <bits/stdc++.h>
using namespace std;
typedef priority_queue<long long int> pq_max;
typedef priority_queue<long long int, vector<long long int>,
greater<long long int> >
pq_min;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
bool sortbysec(const pair<in... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = ~(1 << 31);
const double E = exp(1.0);
const double Pi = 4 * atan(1.0);
int solve(int);
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T, i;
T = 1;
for (i = 1; i <= T; ++i) {
int x = solve(i);
}
return 0;
}
int n, m;
c... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int prm[N / 10], nprm;
bool vis[N];
void Init(int n) {
for (int i = 2; i <= n; i++) {
if (!vis[i]) prm[++nprm] = i;
for (int j = 1; j <= nprm && prm[j] * i <= n; j++) {
vis[prm[j] * i] = true;
if (i % prm[j] == 0) break;
}
... | 18 |
#include <bits/stdc++.h>
int n;
int A[1005], B[1005];
int P[1005], Q[1005];
int posP[1005], posQ[1005];
std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > > V;
int main() {
scanf("%d", &n);
for (int i = 1, x; i <= n; i++) scanf("%d", &x), A[x] = i, P[i] = posP[i] = i;
for (int i = 1, x; i <= n; i++)... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
char s[500005];
int n;
int leftColon() {
bool f = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '[') f = 1;
if (f && s[i] == ':') return i;
}
return -1;
}
int rightColon() {
bool f = 0;
for (int i = n - 1; i >= 0; i--) {
if... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 2e5 + 5;
void solve() {
string s;
cin >> s;
long long int i, j, k, l;
for (i = 1; i < s.size() - 1; i++) {
if (s[i] != s[i + 1] && s[i] != s[i - 1] && s[i + 1] != s[i - 1] &&
s[i] != '.' && s[i + 1] != '.' && s[i - 1] != '.') {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int A[2005], B[2005], C[2005];
int FindMinimumValue(int N, int m) {
sort(B + 1, B + N + 1);
sort(A + 1, A + N + 1);
int i, j, x, Ans = m;
for (i = 1; i <= N; ++i) {
if (A[i] != B[i]) break;
}
if (i == N + 1) return 0;
for (i = 1; i <= N; ++i) {
if (B[i... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int lim = 100005;
bool np[lim];
int p[lim];
int tot;
int k[lim];
int yinzi[lim];
int phi[lim];
void getphi() {
np[1] = phi[1] = 1;
for (int i = 2; i <= lim; ++i) {
if (!np[i]) p[++tot] = i, phi[i] = i - 1;
for (int j = 1; j <= tot && i * p[j] <= lim; ++j) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long x[200100], ans;
int main() {
cin >> n;
for (int i = 0; i < n; ++i) cin >> x[i] >> x[i + n];
sort(x, x + n + n);
ans = (x[n - 1] - x[0]) * (x[n + n - 1] - x[n]);
for (int i = n; i < 2 * n; ++i) {
ans = min(ans, (x[i] - x[i - n + 1]) * (x[n + n ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int fact(int n) {
int f = 1;
while (n > 1) {
f = f * n;
n--;
}
return f;
}
int main() {
string s1, s2;
cin >> s1 >> s2;
int l = s1.length();
int c1plus = 0, c2plus = 0, c1minus = 0, c2minus = 0, question = 0, s1sum = 0,
s2sum = 0, i;
int reqm... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1.01e9;
const long long infll = (long long)1.01e18;
const long double eps = 1e-9;
const long double pi = acos((long double)-1);
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x; }
void precalc() ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
long long sums[100005];
long long ans[100005];
set<pair<long long, int> > maxims;
set<pair<int, int> > S;
int main() {
ios::sync_with_stdio(false);
scanf("%d", &n);
scanf("%lld", &a[1]);
sums[1] = a[1];
for (int i = 2; i <= n; i++) {
scan... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, mp[200050 * 5], d[200050], pos[200050];
bool vis[200050];
set<int> st1;
set<int>::iterator it1;
inline int getdis(set<int>::iterator it);
inline int getnum(int dis, int num) {
if (num - dis > 0 && vis[num])
num = num - dis;
else
num = num + dis;
retu... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int>> adj, p, sz;
vector<vector<long long>> memo;
void dfs(int rt, int u) {
sz[rt][u] = 1;
for (int i : adj[u]) {
if (i == p[rt][u]) continue;
p[rt][i] = u;
dfs(rt, i);
sz[rt][u] += sz[rt][i];
}
}
long long max_s(int u, int v) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int arr[1000005];
int brr[1000005];
int crr[1000005];
int main() {
int n, m;
cin >> n >> m;
map<int, int> vis;
int ji = 0;
int ou = 0;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
if (vis[arr[i]] == 0) {
if (arr[i] % 2 == 1)
ji++;
el... | 11 |
#include <bits/stdc++.h>
using namespace std;
int S;
int n, l[6], r[6], smax;
double rez;
double so(int i, int smax) {
int x[6], y[6], nr = 0, j, k;
double rez = 0;
for (j = 1; j <= n; ++j)
if (j != i) {
x[nr] = l[j];
y[nr] = r[j];
++nr;
}
for (j = 1; j < (1 << nr); ++j) {
double t... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
ostream& operator<<(ostream& out, const pair<T, U>& val) {
return out << "(" << val.first << ", " << val.second << ")";
}
template <class T>
ostream& operator<<(ostream& out, const vector<T>& val) {
out << "{";
for (int i = 0; i < (in... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s, a, s1 = "", s2 = "";
cin >> s;
cin >> a;
long long int c1 = 0, c2 = 0, flag = 0;
for (long long int i = 0; s[i] != '\0'; i++) {
if (s[i] == '|') {
flag = 1;
continu... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<int, int> m;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
m[i] = x;
}
for (int j = 1; j <= n; j++) {
int y = m[j];
if (y <= n && m[y] <= n && m[m[y]] == j) {
cout << "YES";
return 0;
}
}
... | 0 |
#include <bits/stdc++.h>
const long long P = 998244353;
using namespace std;
inline void ckmax(long long &a, long long b) { a = max(a, b); }
inline void ckmin(long long &a, long long b) { a = min(a, b); }
inline void mulmod(long long &a, long long b) { a = 1ll * a * b % P; }
inline void addmod(long long &a, long long b... | 20 |
#include <bits/stdc++.h>
using namespace std;
string S[110];
int soton[110], satr[110], Xo, Yo, n, m;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> S[i];
for (int j = 0; j < m; j++)
if (S[i][j] == '*') {
satr[i]++;
soton[j]++;
}
}
for (int i = 0; i < n; i++... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 9;
const int maxn = 1e6 + 6;
vector<int> a[maxn];
int ans[maxn][2];
set<pair<int, int> > s;
long long read() {
long long c = 0, f = 1;
char ch = getchar();
while (ch != '-' && (ch < '0' || '9' < ch)) ch = getchar();
if (ch == '-') f = -1, ch = ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 3;
int main() {
int n;
cin >> n;
long long ans = 1;
for (int i = 0; i < n - 1; i++) ans = (ans * 3) % maxn;
cout << ans << endl;
}
| 5 |
#include <bits/stdc++.h>
struct M {
int n, m;
int mat[50][50];
void input() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j) scanf(" %c", &mat[i][j]), mat[i][j] -= '0';
}
int solve(M& b, int x, int y) {
int r = 0;
for (int i = 0; i < n; ++i) {
if (i ... | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.