solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int a[1050];
int main(void) {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
int j = 1;
for (; j <= n; j++)
if (!a[j]) break;
printf("%d%c", j, i == n ? '\n' : ' ');
for (int p = 1; p <= j - k;... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e3 + 10;
int A[MAX];
int main() {
int(N);
scanf("%d", &N);
for (int i = 0; i < (N); ++i) scanf("%d", &(A[i]));
int r1 = 0, r2 = 0, p1 = 0, p2 = N - 1, f = false;
while (p1 <= p2) {
if (f) {
if (A[p1] > A[p2]) {
r1 += A[p1];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 60;
const long long MOD = 1e9 + 7;
signed main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n, a, b, c, d;
cin >> n >> a >> b >> c >> d;
long long x = (a ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[7];
for (int i = 0; i < 7; ++i) cin >> a[i];
int i = 0, sum = 0;
while (sum < n) {
sum += a[i];
i = (i + 1) % 7;
}
cout << (i ? i : 7) << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
namespace IO {
const int maxn(1 << 21 | 1);
char ibuf[maxn], *iS, *iT, c;
int f;
inline char Getc() {
return iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin),
(iS == iT ? EOF : *iS++))
: *iS++;
}
template <class Int>
inline... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[25][25];
int n, m;
bool check() {
for (int i = 0; i < n; i++) {
int cnt = 0;
for (int j = 0; j < m; j++)
if (a[i][j] != j + 1) cnt++;
if (cnt > 2) return 0;
}
return 1;
}
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int ... | 7 |
#include <bits/stdc++.h>
using namespace std;
typedef struct {
int t, i, j;
} REQUEST;
REQUEST reqs[110000];
map<pair<int, pair<int, int> >, int> del;
priority_queue<pair<int, pair<int, int> > > cua;
int N;
vector<int> vect_conegs;
map<int, int> map_conegs;
void push(int m, int e, int d) {
cua.push(pair<int, pair<i... | 16 |
#include <bits/stdc++.h>
using namespace std;
template <class P, class Q>
inline void smin(P &a, Q b) {
if (b < a) a = b;
}
template <class P, class Q>
inline void smax(P &a, Q b) {
if (a < b) a = b;
}
const int mod = 1000000000 + 7;
const int maxn = 250 + 10;
const int maxm = 15;
int n, m;
char grid[maxn][maxm];
i... | 17 |
#include <bits/stdc++.h>
int main() {
int i, p, a;
char s[1000];
scanf("%s", s);
a = strlen(s);
for (i = 0; i < a; i++) {
if (s[i] == '.')
printf("0");
else {
if (s[i + 1] == '.') {
printf("1");
i++;
} else {
printf("2");
i++;
}
}
}
print... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long tc, n, x, cnt1, cnt2, i, max_;
scanf("%lld", &tc);
while (tc--) {
max_ = 0;
scanf("%lld", &n);
vector<long long> v;
for (i = 0; i < n; i++) {
scanf("%lld", &x);
v.push_back(x);
}
sort(v.begin(), v.end());
... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, neg = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') neg = -1;
c = getchar();
}
while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
return x * neg;
}
int n = read(), m = read();
vector<int> g[100005];
int df... | 20 |
#include <bits/stdc++.h>
using namespace std;
char v1[5005][5005];
int dp[5005][5005];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) {
scanf("%s", &v1[i]);
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
int calc = 0;
if (j == 0 || ((j - 1) >= 0 &&... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<bool> prime;
vector<long long> fact, inv, primes, factors;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
void factorize(long long a) {
fact.clear();
for (long long i = 1; i * i <= a; i++) {
if (i * i == a)
factor... | 10 |
#include <bits/stdc++.h>
using namespace std;
constexpr int64_t N = 2e5;
int32_t main() {
int64_t t;
cin >> t;
while (t--) {
int64_t n, k;
cin >> n >> k;
deque<int64_t> a(n * k);
for (auto &i : a) cin >> i;
int64_t ans = 0;
int64_t r = n * k - n / 2 - 1, cnt = 0;
while (cnt < k) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int N = 1e5 + 10;
map<char, int> mp;
int main() {
string s;
cin >> s;
int sa = 0;
for (int i = 0; i < s.length(); i++) {
if (sa == 0 && s[i] == 'a') {
mp['a']++;
} else if (sa == 0 && s[i] == 'b') {
sa = 1;
mp['b']++;
} else if (sa == 1... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1010, M = 200200;
int i, j, k, n, m, ch, now, q;
int a[N][N], ans[M];
struct cc {
int x, y;
} A[M];
struct dd {
int l, r, s, t, q;
} Q[M];
void R(int &x) {
x = 0;
ch = getchar();
while (ch < '0' || '9' < ch) ch = getchar();
while ('0' <= ch && ch <... | 20 |
#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc) {
o << "{";
for (const T& v : vc) o << v << ",";
o << "... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int v, p;
cin >> v >> p;
int count = 2 * v + p;
int cur = 0;
for (int i = 1; i <= v; i++) {
for (int j = i + 1; j <= v; j++) {
if (cur == count) break;
cout << i << "... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
;
bool a, b, c, aa, bb, cc;
cin >> a >> b >> c >> aa >> bb >> cc;
if (a == aa || b == bb || c == cc)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int p1 = 233, p2 = 433, mod1 = 1000000007, mod2 = 1000000009;
char a[101010];
int p[101010], hsh1[101010], hsh2[101010], t1[101010], t2[101010];
int mx[100101][25], pll[101001][25];
int ans, pl1, pl2, pl3, pl, n;
void geths(int l, int r, int &hs1, int &hs2) {
hs1 = ... | 20 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265359;
template <typename T>
T abs(T x) {
return x > 0 ? x : -x;
}
template <typename T>
T sqr(T x) {
return x * x;
}
const int maxn = 1000005;
struct nd {
nd *nxt[26];
vector<int> was[2];
nd() { fill(nxt, nxt + 26, nullptr); }
};
nd... | 15 |
#include <bits/stdc++.h>
using namespace std;
uint64_t minmum2(uint64_t n) {
uint64_t minn = 0;
bool minnset = false;
for (uint64_t i = 1; i < (pow(n, 1.0 / 3.0) + 1); ++i) {
if (n % i == 0) {
uint64_t part2 = n / i;
for (uint64_t j = 1; j < (sqrt(part2) + 1); ++j) {
if (part2 % j == 0) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long add(long long a, long long b, long long c) {
long long res = a + b;
return (res >= c ? res - c : res);
}
long long mod_neg(long long a, long long b, long long c) {
long long res;
if (abs(a - b) < c)
res = a - b;
else
res = (a - b) % c;
return (... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int dp[N][N], n, m, k;
int f[N], g[N], a[N], lth[N], b[N][N], cnt[10], val[10];
char s[N];
void sort(int x) {
for (int i = 0; i < 10; i++) cnt[i] = 0;
for (int i = 1; i <= m; i++) cnt[b[i][x]]++;
for (int i = 1; i < 10; i++) cnt[i] += cnt[i - 1];
... | 22 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> c[31];
int main() {
int n, s;
scanf("%d %d", &n, &s);
for (int i = 0; i < n; i++) {
scanf("%d", &c[i].first);
c[i].second = 1 << i;
}
sort(c, c + n, [](const pair<int, int> a, const pair<int, int> b) -> bool {
if (1ll * a.first * b.secon... | 8 |
#include <bits/stdc++.h>
using namespace std;
string second[1000];
long long dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
long long n;
vector<pair<long long, long long> > v, v2;
long long mat[1001][1001];
void dfs(long long s1, long long e) {
if (mat[s1][e] == 1) return;
mat[s1][e] = 1;
for (int i = 0; i < 4; i++)... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, mn, mx, rem, ch[2], ok;
int main() {
ok = 1;
scanf("%d %d %d %d", &n, &m, &mn, &mx);
int a;
rem = 2;
for (int i = 0; i < m; i++) {
scanf("%d", &a);
if (a < mn || a > mx) {
ok = 0;
}
if (a == mn && !ch[0]) {
rem--;
ch[0] ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
while(a && b)
{
if(a > b) a = a%b;
else b = b%a;
}
return a+b;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t; cin >> t;
while(t--)
{
int n, i = 0, j = 0; cin >> n;
string r, b;
cin >> r >>... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
long long n, k, ans[maxn];
struct NODE {
long long p, c;
long long id;
bool operator<(NODE a) const { return c < a.c; }
} node[maxn];
bool cmp(NODE a, NODE b) { return a.p < b.p; }
vector<NODE> tmp;
priority_queue... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 6e5 + 10;
int n;
vector<pair<int, int>> t(4 * N), lazy(4 * N);
void push(int v) {
if (t[v * 2].first < lazy[v].first) {
t[v * 2] = lazy[v];
}
if (lazy[v * 2].first < lazy[v].first) {
lazy[v * 2] = lazy[v];
}... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long a[100];
int main() {
long long n;
int i, j;
scanf("%I64d", &n);
a[1] = 3;
for (i = 2; i < 100; i++) {
a[i] = a[i - 1] * 3;
}
for (i = 1;; i++) {
if (n % a[i]) break;
}
printf("%I64d\n", n / a[i] + 1);
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, a, sum = -1, max = 0;
cin >> n >> m;
while (m--) {
cin >> a;
if (a > max) {
sum += (a - max);
max = a;
} else if (max > a) {
sum += (n - max) + a;
max = a;
}
}
cout << sum;
}
| 2 |
#include <bits/stdc++.h>
int d[5555555];
int main(void) {
for (int i = 2; i < 5555555; i++)
if (d[i] == 0)
for (int j = i; j <= 5555555; j += i) d[j] = d[j / i] + 1;
for (int i = 1; i <= 5555555; i++) d[i] += d[i - 1];
int t;
scanf("%d", &t);
while (t--) {
int a, b;
scanf("%d %d", &a, &b);
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, i, n, m, k;
cin >> t;
for (i = 0; i < t; ++i) {
cin >> n >> m >> k;
if (m <= n / k)
cout << m << endl;
else {
cout << n / k - (m - n / k + k - 2) / (k - 1) << endl;
}
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const int blc = 350;
vector<int> vec[N];
vector<long long> rec[N];
int dp[N];
int father[N];
int up[N];
long double h[1010][1010];
int dia;
int a[N];
long long b[N];
int mx[N];
int num[N];
int find(int x) {
if (father[x] != x) father[x] = find(father... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
int n, half, ans = INF;
map<int, pair<int, int> > color;
int main() {
scanf("%d", &n);
half = (n + 1) / 2;
for (int i = 0; i < n; i++) {
int c1, c2;
scanf("%d%d", &c1, &c2);
color[c1].first++;
if (c1 != c2) color[c2].second++;... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
map<pair<int, int>, int> m, a;
bool visited[100005];
stack<int> s;
struct tank_tap {
int a, b, d;
};
tank_tap res;
void topo(int i) {
visited[i] = true;
for (int x = 0; x < adj[i].size(); ++x) {
if (visited[adj[i][x]] == false) topo(adj[i]... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (a < 0 || b < 0) return gcd(abs(a), abs(b));
if (a == 0)
return b;
else
return gcd(b % a, a);
}
template <class T>
T pwr(T b, T ar) {
T r = 1, pr2 = b;
while (ar) {
if (ar & 1) r *= pr2;
pr2 ... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, i, j, n, m, k, l, r, a, b, c;
cin >> t;
string str;
while (t--) {
cin >> a >> b >> c;
l = -1;
r = -1;
if (a * b > c) {
r = b;
}
if (a < c) {
l = 1;
}
cout << l << " " << r << '\n';
}
return 0;... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
if (k % n == 0)
cout << k / n << endl;
else
cout << k / n + 1 << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
map<int, int> m;
int a[500005];
int main() {
ios::sync_with_stdio(false);
int n, k;
scanf("%d", &(n));
scanf("%d", &(k));
int l = 1, lp = 1, rp = 1;
for (int i = (1); i <= (n); i++) scanf("%d", &(a[i]));
int ans = 0;
for (int i = (1)... | 8 |
#include <bits/stdc++.h>
using namespace std;
string x;
int n;
bool f = true;
int main() {
cin >> n >> x;
for (int i = n / 2; i > 0; i--) {
f = true;
for (int j = 0; j < i; j++) {
if (x[j] != x[j + i]) {
f = false;
break;
}
}
if (f) {
cout << i + 1 + n - 2 * i;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int a[1005];
long long int memo[1005];
long long int n;
long long int cal(long long int len, bool flag) {
if (!flag && memo[len] != -1) return memo[len];
long long int res = 0;
long long int mp[1005];
for (long long int i = 0; i < ((long long int)(1005)); ... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int maxheight = 0, maxwidth = 0;
int bill1x = 0, bill1y = 0, bill2y = 0, bill2x = 0;
while (n--) {
char c;
int x, y;
cin >> c >> x >> y;
int cnt = ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 14, mod = 1e9 + 7;
int n, n1, n2, l1, l2, lim, a[14], e[14][14], f[4][128][128], dp[N], ans;
void qmo(int &x) { x += x >> 31 & mod; }
int ksm(int a, int b) {
int res = 1;
for (; b; b >>= 1, a = (long long)a * a % mod)
if (b & 1) res = (long long)r... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int iinf = INT_MAX;
const long long linf = LONG_MAX;
const int MOD = 1e9 + 7;
inline int read() {
int X = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch)) X = (X << 3) + (X << 1... | 4 |
#include <bits/stdc++.h>
using namespace std;
int q;
long long int n;
int ans, sum;
long long int powe(long long int a, long long int b) {
long long int res = 1;
while (b > 0) {
if (b % 2 == 1) {
res = (res * a);
}
a = (a * a);
b /= 2;
}
return res;
}
void the_happiest_place_on_earth() {
... | 11 |
#include <bits/stdc++.h>
bool* vis;
int64_t select_maximums(int64_t* arr, int32_t n, int32_t count) {
std::vector<int32_t> to_undo;
int64_t answer = 0;
for (int32_t j = 0; j < count; j++) {
int32_t max_ind = -1;
for (int32_t i = 0; i < n; i++) {
if (vis[i]) continue;
if (max_ind == -1 || arr[i... | 12 |
#include <bits/stdc++.h>
using namespace std;
int graph[401][401];
int dist[401];
const int INF = 1 << 30;
int n;
int minDist(int type) {
for (int i = 0; i < n; i++) dist[i] = INF;
dist[0] = 0;
priority_queue<pair<int, int> > q;
q.push(pair<int, int>(0, 0));
while (!q.empty()) {
pair<int, int> x = q.top()... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int maxm = 3e4 + 10;
const int inf = 1e9;
const long long mod = 1e9 + 7;
int getint() {
char c;
while ((c = getchar()) && !(c >= '0' && c <= '9') && c != '-')
;
int ret = c - '0', sgn = 0;
if (c == '-') sgn = 1, ret = 0;
while ... | 3 |
#include <bits/stdc++.h>
using std::map;
using std::queue;
using std::sort;
using std::string;
using std::vector;
int cmp(const void *x, const void *y) {
int dx = *((int *)(x)), dy = *((int *)(y));
return dx > dy ? 1 : -1;
}
int a[400], nex[400];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool coal[105], fnd = 0;
int ns;
int main() {
ios::sync_with_stdio(0);
int n, a[105];
cin >> n;
int tot = 0;
int tot_coal = 0;
cin >> a[1];
coal[1] = 1;
tot += a[1];
tot_coal += a[1];
int mx = a[1];
for (int i = 2; i <= n; ++i) {
cin >> a[i];
t... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
template <class T, class U>
inline void Max(T &a, U b) {
if (a < b) a = b;
}
template <class T, class U>
inline void Min(T &a, U b) {
if (a > b) a = b;
}
inline void add(int &a, int b) {
a += b;
while (a >= 10000... | 12 |
#include <bits/stdc++.h>
using namespace std;
int a[402];
int main() {
int n = 0;
memset(a, 0, sizeof(a));
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
}
int res = -1;
for (int i = 1; i < n; ++i) {
for (int j = i; j < n; ++j) {
int r = a[i - 1] - 1;
int cnt = 1;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const long long int mod = 1e9 + 6;
const long double PI = acos(-1);
const long double EPS = 1e-9;
const long long int INF = 1e18;
const auto start_time = std::chrono::high_resolution_clock::now();
void TIME() {}
long long int power2(long l... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int done[n];
memset(done, 0, sizeof(done));
int x = 0;
int k = 1;
for (int i = 0; i < n - 1; i++) {
int y = (x + k) % n;
k++;
if (i < n - 2)
cout << y + 1 << " ";
else
cout << y + 1 << "\n";
x = y;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string zToN[] = {"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine"};
string tToN[] = {"ten", "eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eightee... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
float a[103];
float sum1 = 0;
int result = 0;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
scanf("%f", &a[i]);
sum1 += a[i];
}
sort(a, a + n);
int i = 0;
while (sum1 / n < 4.5) {
sum1 = sum1 - a[i] + 5;
result++;
i++;
}
cou... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n;
int get_ans(long long a, long long b) {
printf("%lld %lld\n", a, b);
fflush(stdout);
int ans;
scanf("%d", &ans);
return ans;
}
void srchL(long long minx, long long maxx, long long miny, long long maxy,
long long mx, long long my);
void srch... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, k;
cin >> n >> a >> b >> k;
string s;
cin >> s;
s += "1";
n += 1;
int count = 0;
int len = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0') {
len += 1;
} else {
count += (len / b);
len = 0;
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
void boost() {
cin.sync_with_stdio(0);
cout.sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main() {
boost();
int t;
cin >> t;
long long a, b, c;
while (t--) {
cin >> a >> b >> c;
if (a < c)
cout << "1 ";
else
cout << "-1 ";
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int getint() {
int x = 0, tmp = 1;
char c = getchar();
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') c = getchar(), tmp = -1;
while (c >= '0' && c <= '9') x *= 10, x += (c - '0'), c = getchar();
return x * tmp;
}
int n, l, x, y, a[100010]... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 300200;
int n, m, q, i, j, x, y, a[MX], w[MX], z[MX], c[MX];
long long s[MX], r[MX];
vector<int> g[MX], l[MX];
void dfs(int i, int p, int d) {
a[d] = i;
w[i] = d;
for (int j = 0; j < g[i].size(); j++) {
int k = g[i][j];
if (k == p || w[k] >= d) ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int INF = INT_MAX;
const long long INFLL = (long long)1e18;
const double PI = acos(-1.0);
template <class T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
return a / gc... | 0 |
#include <bits/stdc++.h>
using namespace std;
string digits[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
"1101011", "1101111", "1010010", "1111111", "1111011"};
int d[10];
int n, k;
vector<int> v;
const int maxn = 2005, maxk = 2005;
int dp[maxn][maxk];
int go[maxn][10];
int proc(in... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int p = 1000000007;
struct matrix {
int a[105][105];
} b;
int tot, st, a[105], ans[105];
int read() {
char c = getchar();
int x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
struct seg {
long double l;
int pi;
long double a;
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int test = 1;
while (test--) {
int n;
cin >> n;
int a[n];
for (int i = (0); i ... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
using namespace std;
int t, a[3];
bool cmp(int a, int b) { return a > b; }
int main() {
ios::sync_with_stdio(false), cin.tie(0);
cin >> t;
while (t--) {
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3, cmp);
in... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long arr[5050];
long long ke[5050];
long long go[5050];
struct kk {
int a, b, c, d;
};
kk f[5050];
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) arr[i] = LLONG_MAX;
for (int i = 0; i < m; i++) {
long long t, k, l, m;
cin >> t >... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void checkMin(T& a, T b) {
if (b < a) a = b;
}
template <class T>
inline void checkMax(T& a, T b) {
if (b > a) a = b;
}
inline int& RD(int& x) {
scanf("%d", &x);
return x;
}
inline int& RD(int& x, int& y) {
scanf("%d%d", &x, &y);
return... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m, s, t;
vector<int> g[100005];
int pres[100005];
int dis[100005], mark[100005], dp[100005];
const int inf = (int)1e9 + 2;
bool possible(int q) {
for (int i = 1; i <= n; ++i) dis[i] = inf, mark[i] = 0;
dis[s] = 0;
priority_queue<pair<int, int>, vector<pair<int,... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long dp[2000][2000];
long long sm[2000][2000];
long long fact[2000];
long long dp0[2000][2000];
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
for (int m = 0; m < 2000; m++) dp[m][0] = 1, sm[m][0] = m + 1;
for (int k = 1; k <= 50; k++) {
dp[0][k] = sm[0]... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
string s;
cin >> s;
vector<int> ans;
long long n = s.length();
for (long long p = 0; p < n;) {
if (s[p] == '1') {
long long co_one = 0;
while (s[p] == '1') {
co_one++... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n;
int a[n - 1];
vector<int> v;
for (int i = 0; i < n - 1; i++) cin >> a[i];
v.push_back(n);
k = n;
v.push_back(a[n - 2]);
while (k - 2 >= 0) {
k = a[k - 2];
if (k -... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int S;
S = n / 100 + (n % 100) / 20 + (n % 20) / 10 + (n % 10) / 5 + n % 5;
printf("%d", S);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int powerMod(int x, unsigned int y, int MOD) {
int res = 1;
x = x % MOD;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) % MOD;
y = y >> 1;
x = (x * x) % MOD;
}
return res;
}
int main() {
int t;
cin >> t;... | 0 |
#include <bits/stdc++.h>
#pragma GGC optimize("Ofast")
using namespace std;
template <typename T>
void dprintln(const T &t) {
cout << t << endl;
}
template <typename T, typename... Args>
void dprintln(const T &t, const Args &...rest) {
cout << t << ' ';
dprintln(rest...);
}
template <typename T>
void println(cons... | 16 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
cout << x << endl;
exit(0);
}
const int maxn = 1e6 + 5;
int a, b, n;
int ans[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> a >> b >> n;
int _a = a;
int cur = a;
for (int i = 0; i... | 6 |
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define pii pair<ll,ll>
#define vii vector<pii>... | 0 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long zh = 1;
long long gg(long long n) {
long long minn = 10;
long long maxx = 0;
for (int i = 1;; i++) {
long long a = n % 10;
n = n / 10;
minn = min(minn, a);
maxx = max(maxx, a);
if (a == 0) {
zh = 0;
break;... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1.0);
const long double log23 = 1.58496250072115618145373894394781;
const long double eps = 1e-8;
const long long INF = 1e18 + 239;
const long long prost = 239;
const int two = 2;
const int th = 3;
const long long MOD = 1e9 + 7;
const long long ... | 18 |
#include <bits/stdc++.h>
using namespace std;
void test_case() {
long long n;
cin >> n;
string s1, s2;
cin >> s1;
s2 = s1;
sort(s1.begin(), s1.end());
long long cnt = 0;
for (long long i = 0; i < s1.size(); i++)
if (s1[i] != s2[i]) cnt++;
cout << cnt << endl;
}
signed main() {
ios::sync_with_std... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
const int inf = 0x3f3f3f3f;
bitset<100005> bs;
int qnt[50];
int nim[30] = {0, 1, 2, 1, 4, 3, 2, 1, 5, 6, 2, 1, 8, 7, 5,
9, 8, 7, 3, 4, 7, 4, 2, 1, 10, 9, 3, 6, 11, 12};
int main() {
int n;
scanf("%d", &n);
bs.set();
int raiz... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long first = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
first = first * 10 + ch - '0';
ch = getchar();
}
return first * f;
}
te... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int U[1 << 10][1 << 10];
int D[1 << 10][1 << 10];
int L[1 << 10][1 << 10];
int R[1 << 10][1 << 10];
int D1[1 << 10][1 << 10];
int D2[1 << 10][1 << 10];
int D3[1 << 10][1 << 10];
int D4[1 << 10][1 << 10];
char c[1 << 10][1 << 10];
long double s1[1 <<... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n;
int graph[128][128];
bool visited[128];
int dfs(int u, int p) {
if (visited[u]) return 0;
visited[u] = true;
for (int v = 1; v <= (n); ++v) {
if (graph[u][v]) {
return dfs(v, u);
}
}
for (int v = 1; v <= (n); ++v) {
if (graph[v][u] && v !=... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long int n, k, i, j;
cin >> n >> k;
if (k == 1) {
cout << n;
return 0;
}
i = 1;
vector<long long int> p;
while (i <= n) {
p.push_back(i);
i *= 2;
}
long long int ans = 0;
j = p.size();
j-... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, t, y, x, p, nxty, nxtx;
bool a[1001][1001];
long long chk[1001][1001];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
string s;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> t;
for (int i = 0; i < n; i++... | 12 |
#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 sum = 1;
while (b) {
if (b & 1) {
sum = (sum *... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int f1[19] = {0}, f2[19] = {0}, a[19] = {0}, b[19] = {0};
int main() {
string s1, s2;
long long int i, k, n, m, n1, n2, cnt1 = 0, cnt2 = 0;
int j;
cin >> n;
cin >> s1;
cin >> s2;
for (i = 0; i < n; i++) {
j = s1[i] - '0';
f1[j] += 1;
a[j]... | 5 |
#include <bits/stdc++.h>
using namespace std;
int gr[300005];
int mp[300005];
int un(int a) {
if (gr[a] == a) return a;
return gr[a] = un(gr[a]);
}
vector<int> veze[300005];
int n, m, q;
bool bio[300005];
int maks_path;
int dfs(int pos) {
++bio[pos];
int mb1 = 0, mb2 = 0;
for (int i = 0; i < veze[pos].size();... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int mod = 1e9 + 7;
set<int>::iterator i, j;
set<int> ve, ho;
int wi[N], hi[N];
void cut(set<int> &s, int *a, int p) {
s.insert(p);
i = j = s.find(p);
--i, ++j;
--a[*j - *i];
++a[p - *i], ++a[*j - p];
}
int main() {
int mw, mh, p, w, h... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T, class U>
inline void MAX(T& a, U b) {
if (a < b) a = b;
}
template <class T, class U>
inline void MIN(T& a, U b) {
if (a > b) a = b;
}
template <class T, class U>
inline boo... | 5 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize "trapv"
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long m, n,... | 4 |
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
const double pi = 2 * acos(0.0);
inline void io() {}
const long long mod = 2e18;
const long long maxn = 1e6 + 5;
vector<long long> g[maxn];
vector<long long> v[maxn];
bool vis[maxn], vis2[maxn], vis3[maxn];
void go(long long a, long long b) {
g[a].... | 11 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int x, n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> x;
v[i] = x;
}
vector<int> res(n);
for (int i = 0; i < n; i++) {
res[i] = abs(v[(i + 1) % n] - v[i]);
}
int Min = min_element(res.begin(), res.end()) - re... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double EPS = 1e-10;
long long dp[9][8 * 840 + 1];
long long cnt[9];
int main() {
long long W;
cin >> W;
for (int i = 1; i <= 8; i++) cin >> cnt[i];
int L = 840;
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
for (int i = 0; i < ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long A = 100000000000000LL, N = 1228228;
long long a[N], l, r, c, k, i, j, n, m, o;
int check(int c) {
j = c, k = 1;
for (i = 0; i < c; i++) {
while (j < n && a[i] * 2 > a[j]) j++;
if (j == n) k = 0;
j++;
}
return k;
}
int main() {
cin >> n;... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long MX = 2e5 + 1;
const long long MOD = 1000000007;
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
long long q;
cin >> q;
while (q--) {
long long n;
cin >> n;
long long minx = -100000, miny = -100000, maxx = 100000, ... | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.