solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
enum { N = 500007 };
typedef int Ni[N];
int n, a, tp, T[N][2];
Ni hd, nt, to, R, fa, C, st, A4, A2, A1, A3;
void dn(int u) {
if (R[u]) {
int l = T[u][0], r = T[u][1];
if (l) swap(T[l][0], T[l][1]), R[l] ^= 1;
if (r) swap(T[r][0], T[r][1]), R[r] ^= 1;
R[u] ... | 24 |
#include <bits/stdc++.h>
using namespace std;
int n, Min(13);
string x, now;
set<string> second, temp;
string colornum = "RGBYW12345";
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
;
cin >> n;
while (n--) {
cin >> x;
second.insert(x);
}
for (int mask = 0; mask < (1 << 10); ++ma... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
ios::sync_with_stdio(false);
long long n;
cin >> n;
int res = 0;
long long f1 = 1;
long long f2 = 1;
while (f2 <= n) {
f1 = f1 + f2;
swap(f1, f2);
++res;
}
cout << res - 1 << endl;
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e6 + 5;
int n, m, l, cnt;
int a[M], kmp[M];
char c[M];
bool ok[M];
long long _pow(long long x, long long y) {
long long res = 1;
while (y) {
if (y & 1) res = res * x % 1000000007;
x = x * x % 1000000007;
y >>= 1;
}
return res;
}
int main()... | 11 |
#include <bits/stdc++.h>
using namespace std;
int T, n;
int main() {
cin >> T;
while (T--) {
string a, b;
cin >> a >> b;
int i, j;
for (i = a.size() - 1, j = b.size() - 1; i >= 0 && j >= 0;) {
if (a[i] == b[j]) {
i--;
j--;
} else {
i -= 2;
}
}
if (j ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const unsigned int high = 2e5;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n, k;
cin >> n;
string s;
cin >> s;
string x(n, s[n - 1]);
cout << x << endl;
}
}
| 0 |
#include <bits/stdc++.h>
#define int long long
#define ext exit(0)
#define pii pair<int, int>
#define x1 x1228
#define y1 y1228
#define left left228
#define right right228
#define data data228
#define pb push_back
#define eb emplace_back
#define mp make_pair ... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long a[1000005];
long long b[1000005];
int main() {
long long n;
cin >> n;
long long c = 0, d = 0;
for (long long i = 0; i < n; i++) cin >> a[i];
long long c1 = 0;
for (long long i = 0; i < n; i++) {
if (a[i] > 0)
c1 += a[i];
else {
++d;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int add(int x, int y) {
x += y;
while (x >= MOD) x -= MOD;
while (x < 0) x += MOD;
return x;
}
int mul(int x, int y) { return (x * 1ll * y) % MOD; }
int main() {
int n;
scanf("%d", &n);
vector<int> a(n);
for (int i = 0; i < n; i++)... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long int A[100001];
long long int Binary(long long int curindex, long long int start,
long long int end, long long int distance) {
long long int mid = (start + end) / 2;
if (A[mid] - A[curindex] > distance) {
return Binary(curindex, start, ... | 5 |
#include <bits/stdc++.h>
using namespace std;
using lli = long long;
using ld = long double;
mt19937 rnd(time(nullptr));
inline void Solve() {
lli n = 0, y1 = 0;
cin >> n >> y1;
vector<lli> a(n);
for (auto &it : a) cin >> it;
lli m = 0, y2 = 0;
cin >> m >> y2;
vector<lli> b(m);
for (auto &it : b) cin >>... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
int m = 0;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> x;
if ((i == j) || (i + j == n - 1) || (i == (n - 1) / 2) ||
(j == (n - 1) / 2))
m += x;
}
}
cout << m;
return ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1111;
const int MOVE[8][2] = {{-2, 0}, {2, 0}, {-1, -1}, {-1, 1},
{1, -1}, {1, 1}, {0, -2}, {0, 2}};
int n, m;
char mat[N][N];
int color[N][N];
int id[N][N];
int can[N][N][3];
vector<pair<int, int> > v;
inline int in(int x, int y) { re... | 12 |
#include <bits/stdc++.h>
int n, m;
std::set<int> a;
std::set<int> xd[4];
std::set<int> calc(int val, int dgt) {
std::set<int> res;
res.insert(val);
res.insert(-val);
if (dgt == 1) {
xd[1] = res;
return res;
}
std::set<int>::iterator ite;
std::set<int> x = calc(val / 10, dgt - 1);
for (ite = x.be... | 19 |
#include <bits/stdc++.h>
using namespace std;
int a, b = 1, ans = 0x7fffffff, seg[100010], n;
vector<int> g;
int main() {
cin >> n;
a = n, b = 1;
for (int i = 1; i <= n; i++) cin >> seg[i];
for (int i = 1; i <= n; i++) {
if (seg[i] < ans) ans = seg[i];
}
for (int i = 1; i <= n; i++) {
if (seg[i] == ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long inline ipow(long long a, long long b, long long m) {
long long val = 1;
a %= m;
while (b) {
if (b & 01) val = (val * a) % m;
b >>= 1;
a = (a * a) % m;
};
return val % m;
}
long long inline ipow(long long a, long long b) {
long long val = 1;... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long a[100001], s[100001];
inline long long sum(int l, int r) { return s[r + 1] - s[l]; }
long long power(long long a, long long b) {
if (b == 0) return 1;
long long p = power(a, b / 2);
if (b % 2 == 1)
return p * p * a;
else
return p * p;
}
int main() ... | 11 |
#include <bits/stdc++.h>
using namespace std;
bool can[202020];
bool used[202020];
vector<int> primes;
bool a[202020];
int cnt[202020];
int main() {
int ans = 1;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
cnt[x]++;
}
for (int g = 2; g <= 200000; ++g) {
int cur = 0;
f... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 7;
const int mod = 1e9 + 7;
template <class T>
inline T read() {
char ch;
bool flag = 0;
T x = 0;
while (ch = getchar(), !isdigit(ch))
if (ch == '-') flag = 1;
while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
return flag... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100;
int N, T, A[MAXN];
int main() {
scanf("%d", &N), scanf("%d", &T);
for (int i = 0; i < (int)N; i++) scanf("%d", &A[i]);
for (int i = 0; i < (int)N; i++) {
T -= (86400 - A[i]);
if (T <= 0) {
printf("%d\n", i + 1);
return 0;
... | 0 |
#include <bits/stdc++.h>
template <class T>
inline void read(T &x) {
x = 0;
register char c = getchar();
register bool f = 0;
while (!isdigit(c)) f ^= c == '-', c = getchar();
while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
if (f) x = -x;
}
template <class T>
inline void print(T x) {
if (x < 0) pu... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, arr[1005], x, i;
cin >> n;
for (i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
x = arr[n - 1] - arr[0];
x = x + 1;
x = x - n;
cout << x << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
inline int rd() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
struct Node {
int s, id... | 0 |
#include <bits/stdc++.h>
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
std::vector<int> res;
scanf("%d", &n);
int sqn = sqrt(n);
for (int i = 0; i <= sqn; i++) res.push_back(i);
for (int i = sqn; i >= 1; i--) {
if (res[res.size() - 1] != n / i) res.push_back(n / i);
}... | 6 |
#include <bits/stdc++.h>
using namespace std;
mt19937 bruh(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rofl(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e6 + 2;
const int M = 1e5;
const int mod = 1e9 + 7;
const int inf = 2e9 + 3;
const long long INF = 1e18;
const long ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
int main() {
fast();
string s1, s2;
cin >> s1 >> s2;
reverse(s1.begin(), s1.end());
int sum = 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 100;
long long ans[MAXN], cf, cm, A, n, m, pre[MAXN];
pair<long long, long long> a[MAXN];
long long need(long long m, long long sz) {
if (sz == 0) return 0;
long long pos =
upper_bound(a, a + sz, pair<long long, long long>(m, -1LLu / 8... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1E5 + 5;
int n, a[N], ans[N], k, u, v, p, sum;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] == i) k = i;
}
if (k) {
cout << "YES\n";
for (int i = 1; i <= n; i++)
if (i != k) printf("%d %d\n", ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
cin >> n;
set<string> cc;
for (int i = int(1); i <= int(n); i++) {
string s;
cin >> s;
set<char> con;
for (auto it : s) {
con.insert(it);
}
string t;
for (... | 1 |
//JSD
#include<iostream>
using namespace std;
int main(){
int t;
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin>>t;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
bool res=0;
for(int i=0;i<=4;i++){
string s1=s.substr(0, i);
string s2=s.substr(n-1-(3-i), 4-i);
if(n-1-(3-i)>i-1){
if(... | 0 |
#include <bits/stdc++.h>
template <class X, class Y>
X& remin(X& x, Y y) {
return x = (y < x ? y : x);
}
const int NMAX = 2020, INF = (int)1e9;
int n, k, arr[NMAX], minK[NMAX][NMAX];
bool check(int x) {
std::fill(&minK[0][0], &minK[0][0] + NMAX * NMAX, INF);
minK[1][1] = 0;
for (int prefix = 2; prefix <= n; pre... | 12 |
#include <bits/stdc++.h>
using namespace std;
int a[26], m[26];
int main() {
int n, b;
cin >> n >> b;
string s;
cin >> s;
for (char i = 'A'; i <= 'Z'; i++) {
int x = i - 'A';
a[x] = count(s.begin(), s.end(), i);
m[x] = a[x];
}
int t = 0;
for (int i = 0; i < n; i++) {
int x = s[i] - 'A';
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t, z, ans1 = 0, ans = 0;
cin >> t >> z;
long long s[t];
for (int i = 0; i < t; i++) {
int k, add = 0;
cin >> k;
add = k;
k = k / z;
s[i] = k;
if (add % z != 0) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int sigma = 26;
int n, num, len, root;
char str[105000];
struct trie {
int end, sz, nxt[30];
} T[105000];
int Num(char ch) { return ch - 'a'; }
void insert(int now, int pla) {
if (pla == len) {
T[now].sz++;
T[now].end = 1;
return;
}
int um = Num(st... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int INF = 1e9 + 5;
const long long mod = 1e9 + 7;
const double pi = 3.1415926536;
int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ios_base::sync_with_stdio(0... | 5 |
#include <bits/stdc++.h>
using namespace std;
string a, b;
int n;
bool ok(int x) {
if ((int)b.size() * 2 > n) return false;
for (int i = x, j = 0; i < a.size() and j < b.size(); i++, j++)
if (a[i] != b[j]) return false;
return true;
}
int main() {
cin >> n >> a;
b = a[0];
int ans = 1;
int onde = -1;
... | 6 |
#include <bits/stdc++.h>
int main() {
int j, m, b;
scanf("%d%d", &m, &b);
for (j = 0; j < b; j++) {
if (m % 10 == 0) {
m = m / 10;
} else {
m = m - 1;
}
}
printf("%d", m);
return 0;
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v);
template <typename A, typename B>
ostream &operato... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500 + 5;
int n, m, x, y, mapp[maxn][maxn], ans = 0x3f3f3f3f, cnt, cur, tempm, link[maxn];
bool vis[maxn];
bool find(int u, int rt) {
for (int i = 1; i <= n; i++) {
if (!vis[i] && i != rt && mapp[u][i]) {
vis[i] = 1;
if (link[i] == -1 || fi... | 14 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> strs;
map<tuple<int, int, char>, int> adj;
vector<string> roots;
vector<tuple<int, int, char> > radj;
int getNode(string const& s) {
auto it = strs.find(s);
if (it != end(strs)) return it->second;
int c = ((int)(roots).size());
strs[s] = c;
roots.... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <class T>
typename T::value_type arr_sum(const T& v, int n) {
typename T::value_type sum = 0;
for (int i = (0); i < (n); ++i) sum += v[i];
return sum;
}
struct Sync_stdio {
Sync_stdio() {
cin.tie(NULL);
ios_base::sync_wit... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007, MOD2 = 1000000009;
const int INF = 0x3f3f3f3f;
const long long BINF = 0x3f3f3f3f3f3f3f3fLL;
int n, a[105];
int prf[105], suf[105];
int solve() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
prf[0] = a[0] == 0;
for (int i = 1; i < n;... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int BASE = 27;
const int N = 500003;
const long long oo = 1e18;
const double EPS = 1e-9;
int n, a[N], cnt = 0, ans[N], t;
set<int> st;
vector<int> g[N];
void solve() {
scanf("%d", &n);
cnt = n;
st.clear();
for (int i = 1; i <= n + 1;... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 400007;
const int MAXL = 19;
const int L = 18;
int n;
int a[MAXN];
bool _cc[MAXL][MAXN * 2 + 7], *cc[MAXL];
int a... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n;
string str;
cin >> t;
long long abc = INT_MAX;
long long ab = INT_MAX;
long long bc = INT_MAX;
long long ac = INT_MAX;
long long a = INT_MAX;
long long b = INT_MAX;
long long c = INT_MAX;
while (t--) {
cin >> n >> str;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10, mod = 1e9 + 7;
struct data {
int l, r, id;
} q[N];
int pre[N], f[N];
long long d[N], w[N], qz[N], pw[N], suf[N];
bool cmp(data A, data B) { return A.r < B.r; }
int find(int k) { return f[k] == k ? f[k] : f[k] = find(f[k]); }
long long mul(long long... | 25 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T MIN(T a, T b) {
if (a < b) return a;
return b;
}
template <class T>
inline T MAX(T a, T b) {
if (a > b) return a;
return b;
}
int N;
bool vis[1000 + 5];
int main() {
scanf("%d", &N);
int cur = 0;
for (int i = 1; i <= 3 * N; i++) {
... | 4 |
#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;
if (a >= 10000000... | 19 |
#include <bits/stdc++.h>
using namespace std;
inline void FAST_IO() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
template <class F, class S>
ostream& operator<<(ostream& os, pair<F, S>& p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T>
ostream& operator<<(ostream& o... | 4 |
#include <bits/stdc++.h>
using namespace std;
class my_c {
public:
int num, i;
};
int a[30009], n;
my_c b[30009];
bool cmp(my_c a, my_c b) { return a.num < b.num; }
int ABS(int a) {
if (a < 0) a *= -1;
return a;
}
int MIN(int a, int b) {
if (a < b) return a;
return b;
}
int b_s(int num) {
int s = 0, e = n ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
int p[n];
int ones = 0;
for (int i = 0; i < n; i++) {
cin >> p[i];
p[i]--;
}
for (int i = 0; i < n; i++) {
int b;
cin >> b;
ones += b;
}
vector<bool> visited(n, false);
int... | 9 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cer... | 11 |
#include <bits/stdc++.h>
using namespace std;
void print(vector<int> v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i] << " ";
}
cout << endl;
}
void solve() {
int n;
cin >> n;
vector<int> v;
int sum = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
sum += x;
v.push_back(x);
... | 4 |
#include <bits/stdc++.h>
const long long modulo = 1e9 + 7;
using namespace std;
long long binaryExponentiation(long long x, long long n, long long m) {
if (n == 0) {
return 1;
}
if (n % 2 == 0) {
return binaryExponentiation(((x % m) * (x % m)) % m, n / 2, m);
}
return ((x % m) *
binaryExpone... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int32_t x;
scanf("%d", &x);
return x;
}
inline string get() {
char ch[1000];
scanf("%s", ch);
return ch;
}
const int MAX_N = 1e3 + 10;
const int MAX_LG = 21;
inline long long dist(long double x1, long double y1, long long x2,
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LLINF = 1e18;
const int MAXN = 3e5 + 10;
const int mod = 1e9 + 7;
bool check(long long x) {
bool ret = false;
for (int a = 7; a <= 7; ++a) {
for (int b = 1; b <= 6; ++b) {
if (x - (a - b) <= 0) continue;
if ((x... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int M = 2000005;
const int mod = 1000000007;
char str[1000005];
long long pre[M];
int vis[30];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
scanf("%d%d", &n, &k);
scanf(" %s", str + 1);
string ss;
int len = strlen(str + ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, m, r[15];
long long out;
char s[15][35], S[35];
bool check(int z) {
int cnt;
for (int i = 0; i < m; i++) {
cnt = 0;
for (int j = z; j < n; j++) {
if (s[i][j] == S[j]) {
cnt++;
}
}
if (cnt != r[i]) {
return false;
}
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, x, ans = INT_MAX;
cin >> n >> k;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
if (i < k) ans = min(((n / i) * k) + i, ans);
if ((n / i) < k) ans = min(ans, (i * k) + (n / i));
}
}
cout << ans << endl;
return 0;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[300009];
int mod = 1000000007;
long long int power(int base, long long int exp) {
if (exp == 0) {
return 1;
} else {
long long int ans;
if (exp % 2) {
ans = base * power(base, exp - 1);
} else {
ans = power(base, exp / 2);
ans = a... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, t, k;
long long l = 0;
long long z = 0;
long long p = 0;
long long y = 0;
cin >> n >> t >> k;
long long a[200020];
long long w = 1;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > t) {
a[i] = -2;
}
}
fo... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
vector<int> edge[maxn];
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long son[maxn], a[maxn];
long long ans;
bool flag = 0;
long long dfs(int u, int fa) {
if (flag) return 0;
long long lcm = 1, sum = 0, mi = 1e1... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long int hcf(long long int a, long long int b) {
if (!a)
return (b);
else
return (hcf(b % a, a));
}
bool sortbysec(long int a, long int b) { return (a > b); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int t;
... | 9 |
#include <bits/stdc++.h>
int main() {
long set[10];
long mod[2];
int n, c;
int i, j;
int mod_val, rev_mod_val;
int first;
for (i = 0; i < 10; i++) set[i] = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &c);
set[c]++;
}
if (set[0] == 0) {
printf("-1");
} else {
if (set... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<pair<int, int>> v;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
v.push_back({x, i});
}
sort((v).begin(), (v).end());
int a[n + 1];
int i = 1;
fo... | 11 |
#include <bits/stdc++.h>
using namespace std;
int mxn11 = (int)(6e4 + 1);
long long inf = -1e10;
vector<long long> t1(4 * mxn11 + 1, (long long)0);
vector<long long> t2(4 * mxn11 + 1, (long long)0);
vector<long long> t3(4 * mxn11 + 1, (long long)0);
long long getmax1(int v, int vl, int vr, int l, int r) {
if (l > r) ... | 16 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
u... | 14 |
#include <bits/stdc++.h>
using namespace std;
int check(int a, int b, int c) {
if (a == 0 && b == 0) {
if (c == 0)
return 9999;
else
return 0;
}
return 1;
}
int print(int a, int b, int c, int d, int e, int f) {
if (a * e == b * d) {
if ((a * f == d * c) && (b * f == c * e))
return ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
bool ok = false;
for (int i = 0; i < 8; i++) {
cin >> s;
if (s.find("WW") != string::npos || s.find("BB") != string::npos) ok = true;
}
if (ok)
cout << "NO";
else
cout << "YES";
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long int n;
int main() {
string s, t;
cin >> s >> t;
int fs[1000] = {}, ft[1000] = {}, ans = 0, ans2 = 0, cnt = s.size();
for (int i = 0; i < t.size(); i++) {
ft[t[i]]++;
}
for (int i = 0; i < s.size(); i++) {
if (ft[s[i]]) {
ft[s[i]]... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
puts(f ? "YES" : "NO");
exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
x += y;
if (x >= mod) x -= mod;
... | 21 |
#include <bits/stdc++.h>
using namespace std;
struct sort_pred {
bool operator()(const std::pair<int, int> &left,
const std::pair<int, int> &right) {
return left.first > right.first;
}
};
int main() {
int n, k;
cin >> n >> k;
int num = n / k;
int cart = 1;
vector<pair<int, int> > one... | 9 |
#include <bits/stdc++.h>
using namespace std;
string board[55];
string b[55];
map<pair<int, int>, set<pair<int, int> > > moves;
set<pair<int, int> > pMoves;
vector<pair<int, int> > pieces;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> board[i];
for (int i = 0; i < n; i++) {
b[i] = "";
... | 10 |
#include <bits/stdc++.h>
using ll = long long;
int const nmax = 2000;
int const modulo = 998244353;
class Mint {
private:
void gcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
} else {
gcd(b, a % b, x, y);
int aux = x;
x = y;
y = aux - a / b * y;
}
}
... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, f[35][35][2], pw[35];
void Add(int &x, int y) {
x = (x + y) % mod;
return;
}
int main() {
scanf("%d", &n);
pw[0] = 1;
for (int i = 1; i <= 30; i++) pw[i] = 1ll * pw[i - 1] * 2 % mod;
f[30][0][1] = 1;
for (int i = 30; i >= 1; i--... | 19 |
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
bool flag=1;
int x=0;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
flag=0;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=(x<<1)+(x<<3)+c-'0';
c=getchar();
}
return (flag?x:~(x-1));... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
int i;
while (cin >> n) {
cout << "I hate";
for (i = 2; i <= n; i++) {
if (i % 2 == 0)
cout << " that I love";
else
cout << " that I hate";
}
cout << " it" << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define makeVI(a, n) VI a (n); for (int i = 0; i < n; ++i) cin >> a[i];
#define makeVVI(a, n, m) VVI a (n, VI (m)); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int t;
int n;
int main() {
scanf("%d", &t);
for (; t; t--) {
scanf(" %d", &n);
for (int i = 0; i < n; i++) {
printf("%d ", n * 4 - i * 2);
}
printf("\n");
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t, a, b, c, A, B, C, aux;
int ans, res;
cin >> t;
while (t--) {
ans = 1e9;
cin >> a >> b >> c;
for (int i = 1; i < 2 * a; i++) {
for (int j = i; j <= 2 * b; j += i) {
for (int k... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int mx = 312345;
pair<pair<int, int>, int> v[mx];
set<pair<int, int> > Set;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> v[i].first.first >> v[i].first.second;
v[i].second = i + 1;
}
sort(v, v + n,
[](const pair<pair<int,... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 8;
int a[MAXN], dp[MAXN][MAXN];
pair<int, int> par[MAXN][MAXN];
int b[10] = {119, 36, 93, 109, 46, 107, 123, 37, 127, 111};
int n, k;
void input();
void solve();
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
input();
solve();
... | 9 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
using namespace std;
double EPS = 1e-7;
pair<int, int> A[300000];
bool u[3000000];
struct RMQ {
int n;
int* a;
void add(int x, int v) {
for (; x < n; x = x | (x + 1)) {
a[x] += v;
}
}
int get(int x) {
in... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
pair<char, int> k;
int n;
cin >> n >> s;
k = {s[0], 1};
for (int i = 1; i < s.size(); ++i) {
if (s[i] != s[i - 1]) {
if (k.first == 'o' && k.second == 2)
cout <... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int getNumberOfCardsInFullHouse(long long int floors) {
return 3 * floors * (floors + 1) / 2 - floors;
}
long long int solve(long long int n) {
long long int res = 0;
for (long long int floors = 1; getNumberOfCardsInFullHouse(floors) <= n;
floors++)
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = 2 * acos(0.0);
int main() {
int arr[105], m, x, y, total = 0;
scanf("%d", &m);
for (int i = 0; i < m; ++i) {
scanf("%d", &arr[i]);
total += arr[i];
}
scanf("%d", &x);
scanf("%d", &y);
int sum = 0, index = 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int N;
int A[2510][2510] = {{0}};
int Link[2510] = {0};
struct bian_ {
int p, q;
int dis;
} bian[6250000] = {{0, 0, 0}};
int bp = 0;
int F[20][2510] = {{0}};
int Max[20][2510] = {{0}};
int logN = 0;
int depth[2510] = {0};
bool cmp(struct bian_ a, struct bian_ b) { retur... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 302, inf = 1000000000;
int n, m, res;
int c[10][N][N], curr[N][N], pre[N][N];
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
c[0][i][j] = (i == j ? 0 : -inf);
pre[i][j] = c[0][i][j];
}
... | 17 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vc<vc<T>>;
template <class T>
void mkuni(vector<T>& v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
}
template <class T>
void print(T x, int suc = 1) {
cout << x;
if... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, j, k, l, c = 0;
cin >> n >> k;
string st;
cin >> st;
for (i = 0; i < st.size(); i++) {
if (st[i] == '#') {
c++;
} else {
if (c >= k) {
cout << "NO" << endl;
return 0;
}
c = 0;
}
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
string s;
cin >> s;
string r1 = "", r2 = "";
long long int ans1 = 0, ans2 = 0, fl = 0;
for (long long int i = 0; i < n; i++) {
if (s[i] == '_') {
if (r1 != "") {
long long int j = r1.length();
a... | 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 ... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int X[4] = {-1, 0, 1, 0};
const int Y[4] = {0, 1, 0, -1};
char table[1505][1505];
int vis[1505][1505];
int nRecordR[1505][1505];
int nRecordC[1505][1505];
int main(void) {
int nRow;
int nCol;
while (cin >> nRow >> nCol) {
int sr = -1;
int sc = -1;
fo... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
unordered_map<char, int> m;
int k;
cin >> k;
string input;
for (int i = 0; i < k; i++) {
cin >> input;
for (int j = 0; j < input.length(); j++) {
m[input[j]]++;
}
}
bool ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.1415926535897932384626433832795;
const long double eps = 1e-9;
const long double R = 0.707106781186547476064377794840287157537358051492365;
const long double S = -R;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> cons... | 21 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
T lcm(T a, T b) {
return a * (b / gcd(a, b));
}
int DAY[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string Rs[] = {"I", "IV", "V", "IX", "X", "XL", "L",
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 20;
long long n, dp[N][N], ten[N];
string s;
long long f(long long i, long long j) {
if (dp[i][j] != -1) return dp[i][j];
if (i == 0 && j == 0) return dp[i][j] = 0;
if (i == 0) return dp[i][j] = (s[i + j] - '0') * ten[n - j] + f(i, j - 1);
if (j ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
const double eps = 1e-15;
const double pi = acos(-1);
const int INF = 0x3f3f3f;
long long read() {
long long c = getchar(), Nig = 1, x = 0;
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-') Nig = -1, c = ge... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if (b > a) {
cout << b;
return 0;
}
int i, k, s;
s = 1;
while (s <= a) s *= 10;
s /= 10;
int c = a;
while (true) {
k = 0;
bool f = 0;
for (i = s; i >= 1; i /= 10) {
int t = (c / i) % 10;
... | 5 |
#include <bits/stdc++.h>
const long long mod = 1000000007;
long long quick_mod(long long a, long long b, long long m) {
long long ans = 1;
a %= m;
while (b) {
if (b & 1) ans = ans * a % m;
a = a * a % m;
b >>= 1;
}
return ans;
}
int main() {
long long n;
while (~scanf("%I64d", &n)) {
if (!... | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.