solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> ans[11111];
int main() {
cin >> n;
int first = 1;
while (first * (first - 1) / 2 <= n) ++first;
--first;
cout << first << endl;
for (int(i) = 0; (i) < (first); ++(i))
for (int(j) = 0; (j) < (i); ++(j)) {
ans[i].push_back(n);
an... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)(1e6) + 322;
const long long INF = (long long)(1e9);
const long long mod = (long long)(1e9) + 7;
const double eps = 1e-9;
vector<int> v, a, b, s;
int d[N], n, mx;
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(0);
cin >> n;
fo... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 160010;
int T, r, f[maxn], lnk[1000010], mark[maxn], from[maxn];
long long ans[maxn];
string str;
vector<int> G[maxn];
int main() {
ios::sync_with_stdio(0);
cin >> T;
while (T--) {
cin >> r;
getline(cin, str);
stack<int> st;
for (int i... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[N];
set<int> s;
int f[N];
bool st[N];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
memset(f, 0x3f, sizeof f);
for (int i = 1; i <= n; i++) {
f[a[i]] = min(f[a[i]], a[i]);
for (int j = 0; j <= 512; j++)... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long n, i, hz;
char a[101010];
string sb(long long aa, long long bb) {
string z;
long long ii;
for (ii = aa; ii <= bb; ii++) z += a[ii];
return z;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (i = 1; i <= n; i++)... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 1e3 + 5;
const int mod = 1000000007;
const int inf = 1e9 + 10;
const long long INF = 1e18;
int n;
map<pair<int, int>, int> mp;
pair<int, int> points[maxn];
int primes[505];
int nprimes;
bool is_prime[505];
void sieve(int n) {
for (int i = 2; i <= n; +... | 11 |
/******** In the name of Allah, the most gracious, the most merciful ********/
#include <bits/stdc++.h>
using namespace std;
#define pril(a) printf("%d\n", a)
#define pri(a) printf("%d ", a)
#define line printf("\n")
#define space printf(" ")
#define see(a, b) \
{ ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int NN = 202020;
char s[NN], t[NN];
int rk[NN], sa[NN], ht[NN];
int mn[NN][22];
namespace SA {
using INT = long long;
using pii = pair<int, int>;
using ppi = pair<pii, int>;
int head[NN * 2];
ppi pos[NN * 2], buf[NN << 1], tbuf[NN << 1];
int nxt[NN * 2];
void bucket_s... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, m, h[2005][2005], v[2005][2005], tl;
char s[2005][2005], t[2005][2005];
long long ans;
void go(char s[][2005]) {
for (int i = (1); i <= (n); i++)
for (int j = (1); j <= (m); j++) {
h[i][j] = h[i][j - 1] + (s[i][j] == '#');
v[i][j] = v[i - 1][j] + (s... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
struct Trie {
int ch[maxn][26];
int sz;
Trie() {
sz = 1;
memset(ch[0], 0, sizeof(ch[0]));
}
int idx(char c) { return c - 'a'; }
void insert(char *s) {
int u = 0, len = strlen(s);
for (int i = 0; i < len; i++) {
int ... | 11 |
#include <bits/stdc++.h>
using namespace std;
char grid[1001][1001];
bool vis[1001][1001];
int n, m, nos;
struct point {
int x, y, how;
point() { x = 0, y = 0, how = 0; }
};
vector<point> result;
bool vaild(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); }
int main() {
scanf("%d%d", &n, &m);
for (i... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double l, d, v1, v2;
cin >> d >> l >> v1 >> v2;
cout << fixed << setprecision(10) << ((l - d) / (1 + v2 / v1)) / v1;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long x, y, z;
long long fs(long long s, long long ss, long long n) {
long long res = 1;
s %= n;
while (ss > 0) {
if (ss & 1) {
res = (res * s) % n;
}
ss >>= 1;
s = (s * s) % n;
}
return res % n;
}
int main() {
ios::sync_with_stdio(0), ... | 1 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
templat... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 10;
const long double pi = acos(-1);
int gi() {
int x = 0, o = 1;
char ch = getchar();
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '-') o = -1, ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return ... | 25 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2010;
long long F[N][N];
long long n, m, k;
long long cal(long long i, long long w) {
if (i == n) {
return w == k;
}
if (w > k) return 0;
if (F[i][w] != -1) return F[i][w];
return F[i][w] = (cal(i + 1, w) + (m - 1) * cal(i + 1, w + 1)) % 99... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
struct point {
int x, y;
point() {}
point(int x, int y) : x(x), y(y) {}
bool operator<(const point &r) const {
if (x != r.x)
return x < r.x;
else
return y < r.y;
}
};
struct ASK {
int l, r, id;
} q[N];
int n, m, cnt = 0;... | 17 |
#include <bits/stdc++.h>
using namespace std;
int t;
int n;
int a[300000];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
while (t > 0) {
cin >> n;
int i, j;
bool ok = false;
for (i = 1; i <= n; ++i) {
cin >> a[i];
}
for (i = 1; i < n; ++i) {
if (a[i]... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
long long ln, lk, lm;
void etp(b... | 16 |
#include <bits/stdc++.h>
using namespace std;
int pre[1050];
void init(int n) {
for (int i = 1; i <= n; i++) {
pre[i] = i;
}
}
int get_f(int x) {
if (pre[x] == x) return x;
int ans = x;
while (pre[ans] != ans) {
ans = pre[ans];
}
int b, tem = x;
while (pre[tem] != ans) {
b = pre[tem];
pr... | 8 |
#include <bits/stdc++.h>
using namespace std;
bool check(string s, string t) {
for (int i = 0; i < 60; i++) {
if (s[i] == '0' && t[i] == '1') return false;
}
return true;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int64_t a[n], b[n];
map<int64_t, int64_t> t... | 9 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long ara[300003];
unsigned long long ok[300003];
int main() {
ios::sync_with_stdio(false);
unsigned long long n;
scanf("%llu", &n);
unsigned long long m = n / 2;
for (unsigned long long i = 1; i <= m; i++) scanf("%llu", &ok[i]);
ara[1] = 0, ara[n] ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(0);
string s;
cin >> s;
string ss = s;
reverse(ss.begin(), ss.end());
cout << s << ss << "\n";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
istream& in = cin;
vector<long long> ll, lr, rl, rr;
long long n, L, mmax;
void input() {
in >> n >> L >> mmax;
for (int i = 1; i <= n; ++i) {
long long a, b, c;
in >> a >> b;
if (b == 1) {
c = a;
if (c < 0) {
lr.push_back(c);
} els... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long N, pw, ans;
long long K, T;
long long sc[35];
struct Matrix {
long long n, k[35][35];
Matrix Trans(long long x) {
long long i, j;
Matrix c;
c.n = n;
for (i = 0; i < K; i++) sc[i] = (i + x) % K;
sc[K] = K;
for (i = 0; i < n; i++)
f... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a, b;
long long int n;
cin >> a >> b >> n;
n = n % 4;
long long int first, second;
if (a == '^')
first = 0;
else if (a == '>')
first = 1;
else if (a == 'v')
first = 2;
else
first = 3;
if (b == '^')
second = 0;
else... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, m, k, t;
int a[maxn];
int p[maxn];
int f[2005];
int read() {
int x;
scanf("%d", &x);
return x;
}
int sum(int l, int r) { return a[r] - a[l + p[r - l + 1] - 1]; }
int main() {
int i, j;
int x, y;
n = read();
m = read();
k = re... | 13 |
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
void subMain() {
int n;
cin >> n;
vector<int>odd, even;
int x;
for(int i=0;i<n;i++) {
cin >> x;
if(x%2!=0)
odd.push_back(x);
else
even.push_back(x);
}
for(int i=0;i<odd.si... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const int mod = 1e9 + 7;
const long long int LONGINF = 4e18;
const double eps = 1e-9;
const double PI = 3.1415926535897932384626433832795;
bool merge(string &a, string &b, string &dest) {
for (int i = 0; i < (a.size()); i++) {
if (a[i] == b[0]) {
... | 7 |
#include <bits/stdc++.h>
int t, n, i, j;
int main() {
for (scanf("%d", &t); t--;) {
scanf("%d", &n);
int B[26] = {};
for (i = 0; i++ < n;) {
char A[1010] = {};
scanf("%s", &A);
for (j = 0; j < strlen(A); j++) {
B[A[j] - 'a']++;
}
}
for (i = 0; i < 26; i++) {
i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
string s;
int x;
cin >> s >> x;
string w;
for (int i = 0; i < s.size(); i++) {
if ((i - x < 0 || s[i - x] == '1') &&
(i + x >= s.size() || s[i... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n;
const int N = 1e5 + 5;
char a[N][2];
long long vis[N][2];
bool valid(long long x, long long y) {
return (x >= 1 && x <= n && y >= 0 && y <= 1 && a[x][y] == '-' &&
vis[x][y] == 0);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0)... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int M = 2101;
const int N = 111;
int a[N], b[N];
int color[M][M], w[M][M];
int vis[M];
long long val[M];
long long W[N][N][M];
int sto[M];
bool on[M];
int K;
void update(int x, int y, int sign, long long &ans) {
for (int i = 1; i <= K; i++) {
if (on[i]) {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, len;
string s;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> s;
len = s.length();
if (s[len - 2] == 'p' && s[len - 1] == 'o')
cout << "FILIPINO\n";
else if ((s[len - 4] == 'd' && s[len - 3] == 'e' && s[len - 2] == 's' &&
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long m = 1e9;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; ++i) cin >> a[i];
vector<long long> v;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int md = 1e9 + 7;
const int MX = 2e5 + 5;
const int INF = 1e18;
const long double PI = 4 * atan((long double)1);
int power_md(int a, int n) {
int res = 1;
while (n) {
if (n % 2) res = (res % md * a % md) % md;
a = (a % md * a % md) % md;
n /= 2;
}
... | 8 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:128000000")
using namespace std;
const int MAXN = 2e5 + 200;
const int INF = int(1e9) + 7;
const long long LINF = 1ll * INF * INF;
const int md = int(1e9) + 7;
const long double eps = 1e-9;
const long double PI = 3.1415926535897932384626433832795l;
int n;
int na[... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
vector<long long int> v(n);
for (long long int i = 0; i < n; i++) cin >> v[i];
long long int max = -1;
for (long long int i = 1; i < n; i++) {
if (v[i] - v[i... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long MOD = 998244353;
double eps = 1e-12;
long long mpow(long long a, long long b) {
if (a == 0) return 0;
if (b >= (MOD - ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
struct Node {
long long val;
int id;
bool operator<(const Node& b) const { return abs(val) > abs(b.val); }
} a[maxn];
priority_queue<Node> q;
int main() {
cin.sync_with_stdio(false);
int n, k, x, cnt = 0, minn = 0;
cin >> n >> k >> x;
... | 12 |
#include <bits/stdc++.h>
std::mt19937_64 rng(
std::chrono::steady_clock::now().time_since_epoch().count());
long long int myRand(long long int R) {
long long int val = rng() % R;
assert(val >= 0);
return val;
}
const long double PI = atan(1.0) * 4;
const int32_t INF32 = 2e9 + 7;
const int64_t INF64 = 3e18;
co... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int mine(long long int a, long long int b) {
if (a < b) return a;
return b;
}
long long int helper(long long int x, long long int plus, long long int minus) {
if (x >= 0) return x * plus;
return minus * (-x);
}
int main() {
ios_base::sync_with_stdio(0), ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--){
int a, b, c;
scanf("%d%d%d",&a,&b,&c);
int sum = a + b + c;
int p=min(b,c);
int minx = min(a, p);
if (sum % 9 == 0 && sum / 9 <= minx) printf("YES\n");
else puts("NO");
}
return 0;
}
| 3 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
long long int a[200010];
long long int last[200010];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, q;
cin >> n;
vector<long long int... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k[5];
int t[4];
for (int i = (1), ei = (4); i < ei; i++) cin >> k[i];
for (int i = (1), ei = (4); i < ei; i++) cin >> t[i];
int n;
cin >> n;
k[4] = n + 1;
int *A = new int[n];
char *S = new char[n];
memset(S, 0, n);
for (int i = (0), e... | 10 |
#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() ... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
using namespace std;
template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
is >> p.first >> p.second;
return is;
}
template <class T... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (1 << 16) + 100;
int n, deg[MAXN], b[MAXN], cnt;
vector<int> v[MAXN];
bool bio[MAXN];
void rek(int cvor) {
bio[cvor] = 1;
b[b[cvor]] ^= cvor;
deg[b[cvor]]--;
cnt++;
v[cvor].push_back(b[cvor]);
if (deg[b[cvor]] == 1) rek(b[cvor]);
}
int main() {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v;
long long int x;
int n, count = 0, i, j;
cin >> n >> x;
for (i = 1; i <= n; i++) {
if (x % i == 0) {
v.push_back(i);
}
}
for (int i = 0; i < v.size(); i++) {
if (x / v[i] <= n) {
++count;
}
}
cout << ... | 2 |
#include <bits/stdc++.h>
using namespace std;
double dp[2005][2005];
int main() {
int n, t;
double p;
scanf("%d %lf %d", &n, &p, &t);
for (int nn = 0; nn < n; nn++) dp[nn][0] = 0.0;
dp[n][0] = 1.0;
for (int tt = 1; tt <= t; tt++) {
dp[n][tt] = dp[n][tt - 1] * (1 - p);
for (int nn = n - 1; nn > 0; nn... | 9 |
#include <bits/stdc++.h>
using namespace std;
char s[100100], ss[100100];
int n, A, C, G, T, rep[100100];
int main() {
scanf("%d %s", &n, s);
int cnt = 0;
if (n % 4) {
puts("===");
return 0;
}
for (int i = 0; i < n; i++) {
if (s[i] == 'A')
A++;
else if (s[i] == 'C')
C++;
else i... | 1 |
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
#define rep(a,b,c) for(int a=b;a<=c;++a)
#define per(a,b,c) for(int a=b;a>=c;--a)
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long arr[1000100];
signed main() {
long long costly = 0;
long long n;
cin >> n;
for (long long i = 0; i < n; i++) {
char ch;
cin >> ch;
arr[i] = (ch == '(' ? 1 : -1);
}
long long zoo = 0;
long long i = 0;
while (i < n) {
zoo += arr[i];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int vis[3005] = {}, par[3005] = {}, dis[3005];
int flag = 0, parent = 0;
vector<int> adj[3005];
void dfs(int t) {
for (int i = 0; i < adj[t].size(); i++) {
if (!vis[adj[t][i]]) {
vis[adj[t][i]] = 1;
par[adj[t][i]] = t;
dfs(adj[t][i]);
} else if (... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, k, num[2001], dp[2001][2001], lts[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
bool pos[2001][10];
string db[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
"1101011", "1101111", "1010010", "1111111", "1111011"},
in;
bool ok(string x, i... | 9 |
#include <bits/stdc++.h>
using namespace std;
bool sortin(const pair<long long int, long long int> &e,
const pair<long long int, long long int> &f) {
return (e.first < f.first);
}
long long int a, b, c, i, j, k, l, m, n, p, q, r, x, y, z, ts, mn = 10e17,
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5;
long long a[N], b[N];
long long hugs[N];
long long sum[N];
long long n, x;
long long get(long long a) { return a * (a + 1) / 2ll; }
long long f(long long p) {
long long w = b[p] + x;
long long where = lower_bound(b, b + N, w) - b;
long long passed =... | 11 |
#include <iostream>
using namespace std;
int main(void){
int t;cin>>t;
while(t--){
long long n,m,x;
cin>>n>>m>>x;
x-=1;
int row=(x%n);
int col=x/n;
cout<<row*m+col+1<<endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
char s[4][123];
int main(int argc, char const *argv[]) {
int n;
std::cin >> n;
if (n & 1) {
for (int i = 1, j = 0; i < n; i += 2, j++) {
if (j & 1) {
s[0][i] = s[0][i + 1] = 'b';
s[1][i] = s[1][i + 1] = 'c';
} else {
s[0][i] = s... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
int typeC, offerC;
int total_needs;
int needs[200000];
int bought[200000];
ii offers[200000];
bool trydone(int day) {
fill(bought, bought + typeC, 0);
int earned = day;
int cost_non_sale = total_needs * 2;
int needs_sale = cost_non_sale - ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int k, n, m;
long long a[N];
int op[N];
struct assign {
long long num;
int id;
bool operator<(const assign& tmp) const { return num < tmp.num; }
} as[N];
struct add {
long long num;
int id;
};
vector<add> ad[N];
struct mul {
long double num... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int hp_y, atk_y, def_y, hp_m, atk_m, def_m, h, a, d;
int atk1, atk2, hp1, hp2, sum, temp, jiafa, A, B;
while (scanf("%d%d%d%d%d%d%d%d%d", &hp_y, &atk_y, &def_y, &hp_m, &atk_m,
&def_m, &h, &a, &d) != EOF) {
temp = 10e9;
jiafa = 0;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int DX[] = {1, 0, -1, 0}, DY[] = {0, -1, 0, 1};
const int INF = INT_MAX / 2;
int n;
vector<pair<int, int> > p_ts, m_ts;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < (n); i++) {
pair<int, int> t;
cin >> t.first >> ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
int a[40005], b[40005];
vector<long long> coo(int *ar, int ss) {
vector<long long> v(40005, 0);
int j = 0;
for (int i = 0; i < ss; i++) {
if (ar[i] == 0) continue;
j = i;
while (j + 1 < ss && ar[j + 1] == 1) j++;
int cnt = j - i + 1;... | 7 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, '... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, i, j = 0;
cin >> n >> k;
if (n / k < 3) {
cout << "-1";
return 0;
}
for (i = 0; i < 2 * k; i++) {
cout << j % k + 1 << " ";
j++;
}
j++;
for (i = 2 * k; i < n; i++) {
cout << j % k + 1 << " ";
j++;
}
return 0... | 7 |
#include <bits/stdc++.h>
using namespace std;
class UnionFind {
private:
std::vector<int> m_uf;
std::vector<int> m_sz;
public:
UnionFind(const int size) {
m_uf.reserve(size + 1);
m_sz.reserve(size + 1);
for (int i = 0; i <= size; ++i) {
m_uf.push_back(i);
m_sz.push_back(1);
}
}
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char s[100];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
int g = strlen(s);
if (g > 10) {
cout << s[0] << g - 2 << s[g - 1] << endl;
} else {
cout << s << endl;
}
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int q;
long long a[500003];
long long sum[803][803];
template <typename T>
void read(T &x) {
x = 0;
char c = getchar();
bool f = false;
while (c < '0' || c > '9') {
if (c == '-') f = true;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 3) + ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 3e3 + 69;
long long n;
vector<long long> a[MAXN];
long long par[MAXN][MAXN];
long long sz[MAXN][MAXN];
long long dp[MAXN][MAXN];
void dfs(long long u, long long p, long long root) {
par[root][u] = p;
sz[root][u] = 1;
for (long long v : a[u]) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long NR = 1e5 + 10;
void Min(long long& x, long long y) { x = min(x, y); }
void Max(long long& x, long long y) { x = max(x, y); }
long long n, m;
long long ans;
char a[NR];
long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch > '9' || c... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
n = (n - 2) * (n - 2);
cout << n;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(0.0) * 2.0;
const double eps = 1e-12;
const int step[8][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1},
{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
template <class T>
inline T abs1(T a) {
return a < 0 ? -a : a;
}
template <class T>
inline ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 1000;
char s[maxn];
long long get(int f, long long up) {
int ls = strlen(s);
long long x = 0, y = 0;
long long maxx = 0, maxy = 0, minx = 0, miny = 0;
for (int i = 0; i < ls; i++) {
if (s[i] == 'W')
y++;
else if (s[i] == 'S')
... | 13 |
#include <bits/stdc++.h>
using namespace std;
char str[300005];
int trans[(300005 << 1)][26], tot = 1, link[(300005 << 1)],
mxlen[(300005 << 1)];
int n, cnt[(300005 << 1)][3], q[(300005 << 1)], t[(300005 << 1)], ans[300005];
int extend(int c, int id, int lst) {
if (trans[lst][c]) {
i... | 16 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long MOD = (long long)1e9 + 7;
long long add(long long x, long long y) {
x += y;
if (x >= MOD) return x - MOD;
return x;
}
long long sub(long long x, long long y) {
x -= y;
if (x < 0) ... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 20;
int n, t;
pair<int, int> mx[N << 2];
int sum[N << 2], add[N << 2];
void push_up(int rt) {
mx[rt] = max(mx[rt << 1], mx[rt << 1 | 1]);
sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
}
void push_down(int rt, int len) {
if (add[rt]) {
add[rt <<... | 15 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long t, n, cnt;
cin >> t;
while (t--) {
cnt = 0;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
long long min = a[n - 1];
for (long long j = n - 2; j >= 0; ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
int now = 0;
int i = 0;
for (; i < n && now < k / 2; ++i) {
if (s[i] == '(') ++now;
cout << s[i];
}
for (; i < k; ++i) {
cout << ')';
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int sg[N], v[N];
int sum[N];
void init() {
memset(v, 0x3f, sizeof(v));
memset(sg, 0, sizeof(sg));
memset(sum, 0, sizeof(sum));
sg[3] = 1;
v[3] = 2;
sum[3] = 1;
for (int i = 4; i < N; ++i) {
set<int> s;
for (int n = 2; n * n < i + ... | 12 |
#include <bits/stdc++.h>
double const PI = 4 * atan(1.0);
using namespace std;
void OPEN() {
freopen("A.in", "r", stdin);
freopen("A.out", "w", stdout);
}
int a;
int f[6] = {0, 2, 3, 1, 2, 1};
int main() {
scanf("%d", &a);
printf("%d", f[a]);
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
void _print(bool t) { cerr << t; }
void _print(long long t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(double t) { cerr << t; }
template <class T>
void _print(vector<T> v) {
cerr << "[ ";
for (T i : v) {
_prin... | 8 |
#include <bits/stdc++.h>
long long c(int n) {
if (n < 3) {
return 0;
}
return (long long)n * (n - 1) * (n - 2) / 6;
}
int main() {
int n, d;
std::cin >> n >> d;
int a[n];
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
int j = 0;
long long kq = 0;
int q = 0;
for (int i = 0; i < n - 2; ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INFTY = 1 << 29;
void build(vector<string>& ans, int bit, int i, vector<vector<int> >& flg,
vector<vector<int> >& path) {
int h = ans.size(), w = ans[0].size();
ans[i / w][i % w] = 'X';
if (flg[bit][i] == 1) {
build(ans, path[bit][i], i, flg, ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
int n, m, s, k, x;
cin >> n >> m >> k >> s;
vector<int> g[n + 1];
int ans[n + 1][k + 1];
int dist[n + 1];
vector<int> color[k + 1];
for (int i = 1; i <= n; ++i) {
scanf("%d", &x);
color[x].push_back(i);
}
int a, b;... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int i, n, sumg = 0, suma = 0;
cin >> n;
int a[n][2];
for (i = 0; i < n; i++) cin >> a[i][0] >> a[i][1];
for (i = 0; i < n; i++) {
if (a[i][0] < a[i][1]) {
if ((suma - sumg + a[i][0]) <= 50... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200500;
int inp[MAX];
int out[MAX];
bool flag[MAX];
map<long long, int> ID;
map<long long, int> hasInp;
namespace hopcroftKarp {
int ptr[200011], next[400011], zu[400011];
int n, m, match[200011], D[200011], q[200011];
void init(int _n) {
n = _n;
m = 0;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> s2;
if (s1.length() != s2.length()) {
cout << "NO" << endl;
return 0;
}
int i, pi, flag = 0;
for (i = 0; i < s1.length(); i++) {
if (s1[i] != s2[i]) {
pi = i;
break;
}
}
i++;
for (; i < s... | 3 |
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin... | 19 |
#include <bits/stdc++.h>
using namespace std;
map<char, long long int> mp;
long long int n;
bool check(long long int k) {
long long int cnt = 0;
for (char x = 'a'; x <= 'z'; x++) cnt += ceil((double)mp[x] / (double)k);
if (cnt <= n) return 1;
return 0;
}
long long int solve(long long int low, long long int high... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
bool f = false;
cin >> n;
vector<string> s;
string st;
for (int i = 0; i < n; i++) {
cin >> st;
s.push_back(st);
}
for (int i = 0; i < n; i++) {
if (s.at(i)[0] == 'O' && s.at(i)[1] == 'O' ||
s.at(i)[3] == 'O' && s.at(i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k, ans, a[310000];
int l = 1, r = 1;
int cnt, ls = 1, rs;
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
while (r <= n) {
while (r <= n && cnt <= k) {
if (!a[r]) {
if (cnt == k)
break;
el... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int main() {
cin >> b >> a;
for (; d = gcd(a, b), d > 1; a /= d, ++c)
;
if (a == 1)
cout << "2-type\n" << c << endl;
else if ((b * b - 1) / (b & 1 ? 2 : 1) % a == 0) {
if (!c && (b ... | 15 |
#include <bits/stdc++.h>
using namespace std;
inline int getInt() {
int s;
scanf("%d", &s);
return s;
}
class Tree {
public:
vector<vector<int> > next;
vector<vector<int> > prev2;
vector<int> depth;
int root;
Tree(const vector<vector<int> > &next, const vector<vector<int> > &prev2,
const vector<... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 77, L = 19, Mod = 998244353;
int n, k, b[N], d[N], Par[N][L], dp[N][2];
vector<int> a[N], c[N];
inline int Pow(int x, long long y) {
int C = 1;
while (y) {
if (y & 1) C = C * 1ll * x % Mod;
x = x * 1ll * x % Mod;
y >>= 1;
}
return ... | 10 |
#include <bits/stdc++.h>
const int N = 100000 + 10;
inline void cmax(int &a, int b) {
if (a < b) a = b;
}
int n, y, k, x;
int64_t kpow[N], kinv[N], v[N];
std::vector<int> e[N];
int64_t in[N], out[N];
int size[N], ms[N];
bool flag[N];
std::vector<int> q;
inline int64_t pow(int64_t base, int64_t exp) {
int64_t res = ... | 22 |
#include <bits/stdc++.h>
using namespace std;
int A[500];
int main() {
long long x, k;
cin >> x >> k;
int q = 0;
while (x > 0) {
A[q] = x % 10;
x /= 10;
q++;
}
int in = 0;
while (k > 0 && in < q) {
int b_from = (q - in - k - 1 > 0 ? q - in - k - 1 : 0);
int mx = *max_element(A + b_from... | 6 |
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION cout << fixed << setprecision(20);
using namespace std;
void solve() {
int n; cin >> n;
vector<int> ans(n + 1, -1);
vector<array<int, ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> d[maxn];
int a[maxn];
int f[maxn];
int tag[maxn];
int main(void) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
f[a[i]] = i;
}
for (int i = n; i >= 1; i--) {
int pos = f[i];
for (i... | 8 |
#include <bits/stdc++.h>
using namespace std;
class wunionfind {
private:
int *id, *sz, *ans;
int cnt;
map<int, int> M;
vector<vector<int>> adj;
vector<vector<int>> cost;
public:
wunionfind(int n = 400010) {
cnt = 1;
id = new int[n + 1];
sz = new int[n + 1];
ans = new int[n + 1];
adj.... | 16 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.