solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int f[100007];
int b[100007];
int c[100007];
int p[100007];
char s[16];
int main() {
int n, m;
gets(s);
sscanf(s, "%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
p[i] = -1;
}
vector<int> tmp;
int d = 0;
for (int i = 1; i <= m; i++) {
gets(s);
co... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int x[s.length()];
int x2[s.length()];
x[0] = 0;
x2[0] = 0;
for (int i = 1; i < s.length(); i++) {
if (s[i] == s[i - 1]) {
x[i] = x[i - 1] + 1;
x2[i] = x2[i - 1] + 1;
} else {
x[i] = 0;
x2[i] = x... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[] = {0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0};
int n;
int main() {
cin >> n;
cout << a[n];
return 0;
}
| 9 |
/*
�ټ�ͷ�ļ�������������
DP��Ч�ԣ�����������
����������������
�ļ���д������������
���겻���룬����������
���۲�֤��������������
����û����������������
ll�� int������������
dp û��ֵ������������
����û�߽磬����������
���������ӣ�����������
ģ��û���壬����������
Խ�粻���У�����������
��ⲻ��գ�����������
�ռ���ҿ�������������
�����������������... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long a[500010], sum[500010], ss[510010];
bool isvowel(char C) {
if (C == 'A' || C == 'E' || C == 'I' || C == 'O' || C == 'U' || C == 'Y')
return true;
return false;
}
int main() {
int i, j, k, n;
long long t;
string s;
double ans = 0.0;
cin >> s;
n ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int W = 13, S = 1 << 12;
int w, mi_3[W], sum[S], dy[S];
vector<int> sum1;
int need[128][2], nneed[W][2];
char query[W];
int ans;
void dfs(int i, int s, int s1) {
if (i >= w) {
ans += sum[s] * sum1[s1];
return;
}
for (int j = 0; j <= 1; ++j)
if (nneed... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, h, w, k, answer = 0;
cin >> w >> h >> k;
for (i = 0; i < k; i++) {
answer += 2 * h + w * 2 - 4;
h -= 4;
w -= 4;
}
cout << answer;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 2e5 + 1;
long long tp[N], p[N], t[N];
long long bp(long long x, int st) {
if (st == 0)
return 1;
else if (st % 2 == 0)
return bp((x * x) % mod, st / 2);
else
return (bp((x * x) % mod, st / 2) * x) % mod;
}
long long c... | 16 |
#include <bits/stdc++.h>
using namespace std;
int A[1000006];
long double ans[1000006];
int l[1000006], r[1000006];
int hcnt[1000006];
long long B[1000006];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> A[i];
stack<pair<int, int>> S;
S.emplace(0,... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
const int MOD = 1000000007;
struct Mat {
long long v[6][6];
Mat() { memset(v, 0, sizeof(v)); }
Mat(int fl) {
if (fl == 1) {
memset(v, 0, sizeof(v));
for (int i = (0); i < (6); i++) v[i][i] = 1;
} ... | 17 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct total {
long long c[2][2];
total() {
long long i, j;
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
c[i][j] = 0;
}
}
}
};
total aa[123456], bb[123456];
lon... | 16 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int xChange[] = {0, 1, 0, -1};
int yChange[] = {1, 0, -1, 0};
double ebs = 0.00000001;
long double height, n, area_of_part, cur_height = 0.0;
bool check(long double mid) {
long double new_base... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, af, bf;
const int INF = 1000000000, mod = 1000000007;
int dp[52][53][52][103];
long long c[520][520];
void inc(int& a, int b) { a = (a + b) % mod; }
int main() {
cin >> n >> m >> k;
c[0][0] = 1;
for (int i = 1; i <= 300; ++i)
for (int j = 0; j <= i; +... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 7;
int a[maxn], bit[maxn], n;
int Ans[maxn];
int judgemin(int sum, int x, int y) {
int l = 1, r = y, ans = 0x3f3f3f3f;
while (l <= r) {
int mid = (l + r) >> 1;
int all = bit[mid] + x;
if (all >= sum)
ans = mid, r = mid - 1;
e... | 13 |
#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() ... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x, arr[100005], a, b;
map<long long, long long> before;
map<long long, long long> after1;
map<long long, long long> after2;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
before[arr[i]]++;
}
for (int i = 0; i < n - 1... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0;
bool t = false;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') t = true, ch = getchar();
while (ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
return t ? -x : x;
}
i... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T = 1;
while (T--) {
int n;
cin >> n;
int x = 0, y = 0;
long long int ans = 0;
for (long long int i = (0); (i) <= (n - 1); (i)++) {
int a, b;
cin >> a >> b;
ans += max(0, min(a, b) - max(x, y) + (x != y));
x =... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, arr[100005], temp[100005], ans;
int check(long long t) {
for (int i = 1; i <= n; i++) temp[i] = arr[i];
long long i = 0, j = 1, tl = t, p = 0;
while (i < m && j <= n) {
if (tl > 0) {
tl -= min(tl, (j - p));
p = j;
long long k = mi... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
template <class T>
void dbs(string str, T t) {
cout << str << " : " << t << endl;
}
template <class T, class... second>
void dbs(string str, T t, second... s) {
int idx = str.find(',');
cout << str.substr(0, idx) << " : " << t << ",";
dbs(st... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
long long int n, d;
cin >> n;
vector<long long int> v;
long long int sum = 0;
long long int maxi = -1, mini = IN... | 7 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
struct Edge {
int next, cost;
Edge(int next, int cost) : next(next), cost(cost) {}
Edge() {}
};
vector<vector<Edge> > v;
bool u[111111] = {0};
int cnt;
bool lucky(int n) {
while (n != 0) {
int m = n % 10;
if (m != 4... | 11 |
#include <bits/stdc++.h>
using namespace std;
int num[100005];
priority_queue<int, vector<int>, greater<int> > Q;
int main() {
long long b;
int n, k;
while (cin >> n >> k) {
cin >> b;
for (int i = 0; i < n; i++) cin >> num[i];
long long sum = 0;
int ans = n;
n--;
while (!Q.empty()) Q.pop()... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, const U &b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, const U &b) {
if (a < b) a = b;
}
const int mod = 1e9 + 7;
const int NN = 1000100;
long long fac[NN];
int power(int a, int... | 15 |
#include <bits/stdc++.h>
using namespace std;
bool notprimes[1200008];
int rob[1200008];
int amPr[1200008];
void getpr(int n) {
notprimes[0] = notprimes[1] = true;
for (int i = 2; i <= n; ++i)
if (!notprimes[i])
if (i * 1ll * i <= n)
for (int j = i * i; j <= n; j += i) notprimes[j] = true;
}
bool ... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;
const int INF = static_cast<int>(1e9);
const long long INF_LL = static_cast<long long>(4e18);
const double pi = acos(-1.0);
template <class T>
T& smin(T& x, const T& y) {
if (x > y) x = y;
re... | 22 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using std::bitset;
using namespace std;
vector<int> st[110];
vector<int> n1, n2, n3;
int f[110], num[110];
int n, m;
int find(int x) {
if (f[x] != x) f[x] = find(f[x]);
return f[x];
}
void process() {
int i, j, tem;
for (i = 1; i <= ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long ceil(long long n, long long k) {
if (n % k == 0) return n / k;
return n / k + 1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
long long x, y;
if (k <= n - 1) {
cout << k + 1 << " " << 1 << "\n";
... | 5 |
//也请让我相信,你一直以来所相信的事吧——“活着是一件很美好的事”
//只要记住你的名字,不管你在世界的哪个地方,我一定会去见你!
//我现在依然喜欢着你,但我们就算是来往一千封邮件,心却不可能接近哪怕一厘米。
//嗯,那样的话,你就再努力一次试试吧!别在这种地方畏畏缩缩的!别对自己说谎!再努力一次吧。
//我说过了,若是有想要拯救之物,就果断地出手全力去守护!
//拜托了,请把力量借给软弱的我,给我从这里再度起身迈步的力量!
//虽然灯塔已经失去了光明……但是,只要有你的那首歌在,就一定能将那些人再次导向此方。
//小时候曾认为这个世界单纯简单,没有赢不了的比试,努力就会有回报,认为这世上一切皆有可能。
//虽然我能办到的或许只... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long int Modulo = 1000000007;
int N, k, x;
int main() {
int number[6];
int uncertain[5];
vector<int> people;
string sizes[6] = {"S", "M", "L", "XL", "XXL", "XXXL"};
for (int i = 0; i < 6; ++i) {
cin >> number[i];
}
int N;
cin >> N;
for (int ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int V = 1000;
int a[V][V];
bool changeC[V], changeR[V];
int n, m;
int main() {
cin >> n >> m;
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j) scanf("%d", &a[i][j]);
for (int i = 0; i < n; ++i) changeR[i] = false;
for (int i = 0; i < m; ++i) changeC... | 13 |
#include <bits/stdc++.h>
using namespace std;
void printArray(unsigned long long a[], int len) {
cout << "{";
for (int i = 0; i < len - 1; i++) {
cout << a[i] << ", ";
}
cout << a[len - 1] << "}\n";
}
void quickSort(unsigned long long a[], int left, int right) {
int i = left, j = right;
unsigned long lo... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, len, cnt;
char str[(int)2e5 + 10];
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int i, j, k;
cin >> len >> str;
for (i = 0; i < len; i += 2)
if (str[i] == str[i + 1]) {
cnt++;
if (str[i] == 'a')
str[i] = 'b';
... | 0 |
#include <bits/stdc++.h>
using namespace std;
void FAST() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
long long gcd(long long x, long long y) {
if (x == 0) return y;
return gcd(y % x, x);
}
long long powM(long long x, long long y, long long m) {
long long ans = 1, r = 1;
x %= m;
while (r > 0 &... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 550;
int n, m, sx, sy, ex, ey, mp[maxn][maxn];
char ch[maxn][maxn];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
struct node {
int x, y;
};
queue<node> qu;
bool check(int x, int y) {
if (x >= 0 && x < n && y >= 0 && y < m && mp[x][y] == 2) return... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m, h, t;
int i, j, k;
int x[5122];
pair<int, int> hole[5122];
long long f[5122][5122], s[5122];
int que[5122];
int main() {
scanf("%d%d", &n, &m);
memset(f, 127, sizeof f);
f[0][0] = 0;
for (i = 1; i <= n; i++) scanf("%d", x + i);
for (i = 1; i <= m; i++) s... | 18 |
#include <bits/stdc++.h>
using namespace std;
int Max = 100000000;
void Floyd_Warshall(int n, vector<vector<int>>& MinCost) {
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
MinCost[i][j] = min(MinCost[i][j], MinCost[i][k] + MinCost[k][j]);
}
void Count_Min_Edge(i... | 17 |
#include <bits/stdc++.h>
long long int a[1010] = {0};
int main() {
int n, a, b, c;
while (scanf("%d", &n) != EOF) {
if (n == 1)
printf("-1\n");
else {
printf("%d %d %d\n", n, n + 1, n * (n + 1));
}
}
return 0;
}
| 7 |
#include <bits/stdc++.h>
int time_set(int h, int m, int prev) {
if (m >= prev) {
m -= prev;
return h * 100 + m;
} else {
m += 60;
m -= prev;
h += 24;
h -= 1;
h %= 24;
return h * 100 + m;
}
}
int main() {
int x;
scanf("%d", &x);
int h, m;
scanf("%d %d", &h, &m);
if (h / 10... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x[100 + 5], d[100 + 5], a[100 + 5], flag = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x[i] >> d[i];
a[i] = x[i] + d[i];
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] == x[j] && a[j] == x... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 22 + 2;
const int maxm = maxn * maxn;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
int n, n2, m, a, b;
double p[maxn];
double f[maxn * maxn][maxn * maxn + 1], ans[maxn * maxn];
int head[maxn], tot = 1;
struct node {
int from, to;
} edge[maxm];
int... | 19 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> a(100500), dp(100500);
long long n;
int main() {
cin >> n;
long long i, j;
for (i = 1; i <= n; i++) {
cin >> a[i];
}
dp[n] = a[n];
for (i = n - 1; i >= 1; i--) {
dp[i] = min(dp[i + 1], a[i]);
}
for (i = 1; i < n - 1; i++) {
long... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5E4;
const int M = 5E4;
char buf[M + 1];
const int &min(const int &x, const int &y) { return x < y ? x : y; };
int main() {
int q;
scanf("%d", &q);
while (q--) {
int n, m;
scanf("%d%d", &n, &m);
vector<string> a(n);
for (auto &str : a) sc... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[27];
long long cnt[1002];
int dpmax[1002];
int dpmin[1002];
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL), cout.tie(NULL);
int n, i, j;
string s;
cin >> n;
cin >> s;
for (i = 1; i <= 26; i++) {
cin >> a[i];
}
cnt[0] = 1;
dpmax[0] = 1;
d... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300000, M = 300000;
struct V {
vector<int> adj, ice;
} vv[N];
int color[M + 1];
void dfs(int p, int i) {
auto &ice = vv[i].ice;
sort(ice.begin(), ice.end(),
[](int a, int b) { return color[a] < color[b]; });
int h = 0, m = ice.size();
while (h... | 14 |
#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long ksm(long long a, long long b) {
long long ret = 1;
while (b) {
if (b & 1) ret = ret * a % mod;
a = a * a % mod;
b >>= 1;
}
return ret;
}
lo... | 9 |
#include <bits/stdc++.h>
using namespace std;
void read(int &x) { scanf("%d", &x); }
void read(long long int &x) { scanf("%I64d", &x); }
void read(long long int &a, long long int &b) { scanf("%I64d %I64d", &a, &b); }
void read(long long int &a, long long int &b, long long int &c) {
scanf("%I64d %I64d %I64d", &a, &b, ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
map<string, int> mp;
mp["C"] = 1;
mp["C#"] = 2;
mp["D"] = 3;
mp["D#"] = 4;
mp["E"] = 5;
mp["F"] = 6;
mp["F#"] = 7;
mp["G"] = 8;
mp["G#"] = 9;
mp["A"] = 10;
mp["B"] = 11;
mp["... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
k = 240 - k;
int count = 0;
int j = 1;
while (k >= 5 * j) {
k = k - (5 * j);
j++;
count++;
if (count >= n) break;
}
cout << count;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int size = 1000000;
int a[size + 1], x[size + 1], n;
int xl, num, l, r, mid;
int main() {
int j;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> j;
x[j] = i;
}
for (int i = 1; i <= n; i++) {
cin >> j;
a[x[j]] = i;
}
xl = 1;
x[xl] = a[1]... | 11 |
#include <bits/stdc++.h>
using namespace std;
int fa[400005];
int find(int i) {
if (i == fa[i]) return i;
return fa[i] = find(fa[i]);
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
int i;
for (i = 1; i <= n + m; i++) {
fa[i] = i;
}
while (q--) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
char ch;
int n, w, h, t;
long long ans;
set<int> x, y, *s;
set<int>::iterator l, r;
multiset<int> lx, ly, *ls;
int main() {
cin >> w >> h >> n;
x.insert(0);
x.insert(w);
y.insert(0);
y.insert(h);
lx.insert(w);
ly.insert(h);
for (int j = 1; j <= n; ++j) {
... | 7 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define fo(i,n) for(int i=0;i<n;i++)
#define fo1(i,n) for(int... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int m;
int p = 1;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> m;
int arr[m];
for (int j = 0; j < m; j++) {
cin >> arr[j];
}
if (arr[0] == 1) {
p = p + 1;
}
for (int k = 1; k < m; k++) {
if (k != ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long rad, p, q, r, s;
cin >> rad >> p >> q >> r >> s;
cout << ceil((sqrt((p - r) * (p - r) + (q - s) * (q - s))) / rad / 2) << "\n";
return 0;
}
| 6 |
#include <bits/stdc++.h>
int n;
double x[16], v[16], m[16];
double t, tf;
double lastcol[16][16];
int a, b;
int main(void) {
int i, j;
scanf("%d %lf", &n, &tf);
for (i = 0; i < n; i++) scanf("%lf %lf %lf", &x[i], &v[i], &m[i]);
t = 0.0;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++) lastcol[i][j] = 0.0;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int t;
long long n, f[87 + 1], cnt[87 + 1];
bool app[87 + 1];
int blk[87 + 1], p;
long long dp[87 + 1][2];
void solve() {
for (int i = (1); i <= (87); i++) app[i] = false;
p = 0;
for (int i = (87); i >= (1); i--)
if (n >= f[i]) {
n -= f[i];
app[i] = tr... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
long long int n, m;
cin >> n >> m;
long long int ps[n + 10];
long long int a[m];
memset(ps, 0, sizeof(ps));
for (long long int i = 0; i < m; i++) cin >> a[i];
for (long long int ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long int MAX = 1e6 + 8;
vector<long long int> f[MAX], r[MAX];
bool inQ[MAX];
long long int dist[MAX];
std::queue<long long int> Q;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
long long int n, m;
cin >> n >> m;
for (int i = 1; i <= ... | 18 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g;
vector<char> t;
vector<bool> b, d;
bool calc(int v) {
if (t[v] == 'A') return b[v] = calc(g[v][0]) & calc(g[v][1]);
if (t[v] == 'O') return b[v] = calc(g[v][0]) | calc(g[v][1]);
if (t[v] == 'X') return b[v] = calc(g[v][0]) ^ calc(g[v][1]);
if ... | 12 |
#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> a[200005];
long long dp[200005], p[200005];
long long ans[200005], root, cnt;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n;
cin >> n;
for (long long i = 1; i <= n; i++) cin >> a[i].first, a[i].second = i;
sort(a... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
while (n--)
{
string s;
cin >> s;
if (s[0] == ')' || s.size() % 2 != 0 || s[s.size() - 1] == '(')
cout << "NO" << endl;
else
cout << "YES" << endl;
}
} | 2 |
#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b) {
long long res = 1;
for (; b; b >>= 1) {
if (b & 1) res = res * a;
a = a * a;
}
return res;
}
int N, K;
long long a, b, w, x, C;
int in[2222];
int curMX;
bool check(long long mid) {
a -= (b + mid * x) / w;
C -=... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2048;
int N, M;
char str[maxN][maxN];
const int inf = 100000000;
int dist[maxN];
vector<int> v[maxN];
queue<int> q;
bool vst[maxN];
int main() {
scanf("%d %d", &N, &M);
for (int i = 0; i < N; ++i) scanf("%s", str[i]);
if (N == 1) {
cout << 0 << en... | 10 |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, m, n, u, t;
string s, s2;
struct bs {
int poz;
char c;
};
string sol[100];
bool cmp(bs o1, bs o2) { return o1.c < o2.c; }
int a[102][102];
bool viz[1000];
int main() {
cin >> n;
for (i = 1; i <= n; ++i)
for (j = 1; j <= n; ++j) cin >> a[i][j];
for... | 1 |
#include <bits/stdc++.h>
const int maxn = 200005, maxp = maxn << 2;
int Q, tmp;
char ch;
inline void read(int &Res) {
char ch = getchar();
for (Res = 0; !isdigit(ch); ch = getchar())
;
for (; isdigit(ch); ch = getchar()) Res = (Res << 3) + (Res << 1) + ch - 48;
}
struct SegMentTree {
int Siz, nl[maxp], nr[m... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
int n;
while (t--) {
cin >> n;
if (n < 4) {
cout << -1 << endl;
continue;
}
for (int i = n; i > 0; --i)
if (i % 2 != 0) cout << i << " ";
cout << 4 << " " << 2 << " ";
for (int i = 6; i <= n; i ... | 8 |
#include <bits/stdc++.h>
int min(int a, int b) {
if (a <= b)
return a;
else
return b;
}
int main() {
int i, j, m, n, l, l1, l2, det, x, y, det2, possible, same;
char str[5005], str1[5005], c, d, pri;
scanf("%d", &m);
for (i = 0; i < m; i++) {
scanf("%s%s", str, str1);
l1 = strlen(str);
l... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b, cnt, rem, div;
while (scanf("%lld %lld", &a, &b) == 2) {
cnt = 0;
while (b != 0) {
rem = a % b;
div = a / b;
cnt += div;
a = b;
b = rem;
}
printf("%lld\n", cnt);
}
return 0;
}
| 3 |
#include <bits/stdc++.h>
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long countDivisor(long long n) {
long long divisor = 0;
for (long long i = 1; i * i <= n; i++) {
if (i * i == n)
divisor += 1;
else if (n % i == 0)
divisor += 2;
}
return divisor;
}
i... | 7 |
#include <bits/stdc++.h>
using namespace std;
class APatrickAndShopping {
public:
void solve(std::istream& in, std::ostream& out) {
int a, b, c;
in >> a >> b >> c;
int op = 2 * (a + b);
int opn = a + b + c;
op = min(op, opn);
opn = 2 * (a + c);
op = min(op, opn);
opn = 2 * (b + c);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }
int main() {
int n;
cin >> n;
vector<int> mas(n);
for (size_t i = 0; i < n; i++) {
cin >> mas[i];
}
int j = n - 1;
while (mas[0] == mas[j]) {
j--;
}
int j2 = 0;
while (ma... | 3 |
#include <bits/stdc++.h>
using namespace std;
int vertex[5005];
bool graph[5005][5005];
int start[105], endd[105];
int match[5005];
int cnt;
bool help(int u, bool seen[]) {
if (seen[u]) return 0;
seen[u] = true;
for (int i = 0; i < cnt; i++) {
if (graph[u][i]) {
if (match[i] == -1 || help(match[i], seen... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const long long LINF = 1e18 + 48;
const int magic = 348;
const int MOD = 998244353;
const double eps = 1e-10;
const double pi = acos(-1);
struct fastio {
static const int S = 1e7;
char rbuf[S + 48], wbuf[S + 48];
int rpos, wpos, len;
fastio() { ... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 123;
const int mod = 1e9 + 7;
int n, k, x[323];
bool yes(int T) {
vector<bool> u;
u.resize(n + 23);
for (int i = 1; i <= k; i++) {
for (int j = max(1, x[i] - (T - 1)); j <= min(n, x[i] + T - 1); j++)
u[j] = 1;
}
for (int i = 1; i <= n... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
const long long mod = 1e6 + 3;
int dx[5] = {0, 0, 0, 1, 1};
int dy[5] = {0, 0, 1, 1, 0};
string s[N];
long long pow_q(long long a, long long b) {
long long tmp = 1;
while (b > 0) {
if (b & 1) {
tmp *= a;
tmp %= mod;
}
a *= a... | 14 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
LL C[31][31];
void precalc_comb() {
C[1][1] = 1;
for (int n = 0; n <= 30; ++n) {
C[n][0] = C[n][n] = 1;
}
for (int n = 1; n <= 30; ++n) {
for (int k =... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2010;
const long long MAX = 2 * (1e9);
long long v[MAXN], diff;
int n, k, dp[MAXN];
long long ceil(long long a, long long b) {
if (a % b)
return a / b + 1;
else
return a / b;
}
int f(int i) {
if (i == n) return 0;
if (dp[i] == -1) {
dp[i... | 12 |
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
struct timeq {
int idx, type, time, x;
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<timeq> q(n);
for (int i = 0; i < n; i++) {
q[i].id... | 12 |
#include <bits/stdc++.h>
inline int Rand() { return (rand() << 16) | rand(); }
using namespace std;
const int N = 200005;
const double eps = 1e-9;
struct Pair {
int l, r;
} was[N], was1[N];
int main() {
int n, m, k;
cin >> n >> m >> k;
int a, s, type;
for (int i = 1; i <= k; ++i) {
cin >> type >> s >> a;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
;
int n;
cin >> n;
vector<int> v(n), vv(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
vv = v;
sort(v.begin(), v.end());
int cnt = 0;
for (int i = 0; i < n; i++) {
if (... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, temp;
int main() {
scanf("%d%d%d", &n, &m, &k);
if (n % 2 == 0 || m < (n + 1) / 2) {
printf("0\n");
return 0;
}
long long minA = (m / ((n + 1) / 2)) * k;
for (int i = 0; i < n; i++) {
scanf("%d", &temp);
if (i % 2 == 0 && temp < ... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmin(T &x, const T &y) {
if (x > y) x = y;
}
template <typename T>
void chmax(T &x, const T &y) {
if (x < y) x = y;
}
int read() {
char c;
while ((c = getchar()) < '-')
;
if (c == '-') {
int x = (c = getchar()) - '0';
while ... | 25 |
#include <bits/stdc++.h>
using namespace std;
const long long OO = 5e16;
long long fastPow(long long a, long long p) {
if (p == 0) return 1;
long long ans = fastPow(a, p / 2);
ans *= ans;
if (p & 1) ans *= a;
return ans;
}
long long E_GCD(int a, int b, int& x, int& y) {
if (a == 0) {
x = 0;
y = 1;
... | 0 |
#include <bits/stdc++.h>
auto clk = clock();
const int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
const int dx8[] = {-1, -1, -1, 0, 1, 1, 1, 0},
dy8[] = {-1, 0, 1, 1, 1, 0, -1, -1};
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long Gcd(long long a, long long ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int cnt[1001000];
int fac[1001000], ifac[1001000];
int phi[1001000];
int inv(int x) {
int r = 1, y = 1000000007 - 2;
while (y) {
if (y & 1) r = 1LL * r * x % 1000000007;
x = 1LL * x * x % 1000000007;
y >>= 1;
}
return r;
}
inline int C(int n, int m) {
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 7;
int n;
int m;
vector<int> g[N];
vector<int> gCorrect[N];
vector<int> backEdges[N];
bool vis[N];
int d[N];
void buildBackEdges(int a) {
vis[a] = 1;
for (auto &b : g[a]) {
if (vis[b] == 0) {
d[b] = 1 + d[a];
gCorrect[a].push_bac... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int T, n, st[maxn], nt[maxn], to[maxn], w[maxn], topt, si[maxn];
long long ans1, ans2;
inline void add(int x, int y, int z) {
to[++topt] = y;
nt[topt] = st[x];
st[x] = topt;
w[topt] = z;
}
void dfs(int x, int fa, long long v) {
si[x] = 1... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[202], b[202];
inline bool check(int o) {
for (auto i = (1); i <= (n); ++i) {
int flag = 0;
for (auto j = (1); j <= (m); ++j)
if ((a[i] & b[j] | o) == o) flag = 1;
if (!flag) return 0;
}
return 1;
}
inline void solve() {
scanf("%d%d", &n... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, l, c, d, p, nl, np;
cin >> n >> k >> l >> c >> d >> p >> nl >> np;
int cond[3];
cond[0] = k * l / (nl * n);
cond[1] = c * d / n;
cond[2] = p / (np * n);
int toast = cond[0];
for (int i = 1; i < 3; i++) {
toast = cond[i] < toast ? c... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx2")
using namespace std;
struct info {
int m;
int lt, lm;
int rt, rm;
info() : m(0), lt(0), lm(0), rt(0), rm(0) {}
};
st... | 20 |
#include <bits/stdc++.h>
using namespace std;
int di1[5001];
int di2[5001];
int n;
int pos1, pos2;
long long res;
int main() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> pos1 >> pos2;
++di1[pos1 + pos2 - 2];
++di2[pos1 - pos2 + 999];
}
for (int i = 0; i <= 1998; ++i) {
res += (di1[i] * (di1[... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 2e18 + 7;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
const double PI = 2 * acos(0.0);
int main() {
long long n;
cin >> n;
long long lvl = 2;
long long q = 0;
while (true) {
q = (lvl + 1) * lvl + lvl * (lvl - 1) / 2;
if (q... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
string b;
int flag = 0;
cin >> a;
for (int i = 0; i < 5; i++) {
cin >> b;
if (a[0] == b[0] || a[1] == b[1]) {
flag = 1;
}
}
if (flag == 1) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
template <typename T>
void read(T &x) {
x = 0;
long long f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
x *= f;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int h;
vector<int> nei[300];
int conta;
bool ask(int x) {
if (nei[x].size() != 0) return false;
if (conta == 16) {
printf("! %d\n", x);
fflush(stdout);
return true;
}
conta++;
printf("? %d\n", x);
fflush(stdout);
int r;
scanf("%d", &r);
if (r =... | 20 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string str;
cin >> str;
int n = str.size();
int mn = 256;
for (int i = 0; i < n; ++i) {
if (str[i] <= mn)
cout << "Mike\n";
else
cout << "Ann\n";
mn = min(... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
int n, k;
string a[MAXN];
int lcp[MAXN];
int dp[MAXN * 2][MAXN], cn = 0;
int work(int l, int r) {
cn++;
if (l == r) return cn;
int d = cn;
int p = l;
for (int i = l; i < r; i++)
if (lcp[i] < lcp[p]) p = i;
int lch = work(l, p);
int r... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, k = 0;
cin >> n;
for (i = 1; i >= 1; i++) {
if (i % 2 == 1) {
if (n >= 1) {
n--;
k++;
} else
break;
} else {
if (n >= 2) {
n = n - 2;
k++;
} else
break;
}
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double pi = 3.1415926535897932384626433832795;
const int inf = 1e9;
const long long inf2 = 1e18;
const int mod = 1e9 + 7;
void boost() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const int N = 1e6 + 5;
vector<int> pre(N, -1);
void solve() {
long long n;... | 10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.