solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int na, ma, nb, mb;
string A[51], B[51];
cin >> ma >> na;
for (int i = 1; i <= ma; ++i) {
cin >> A[i];
A[i] = " " + A[i];
}
cin >> mb >> nb;
for (int i = 1; i <= mb; ++i) {
cin >> B[i];
B[i] = " " + B[i];
}
int r1, r2, m = 0;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long mult(long long a, long long b, long long p = (int)(1e9 + 7)) {
return ((a % p) * (b % p)) % p;
}
long long add(long long a, long long b, long long p = (int)(1e9 + 7)) {
return (a % p + b % p) % p;
}
long long fpow(long long n, long long k, long long p = (int)(... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = (1e-11);
const double PI = acos(-1.0);
const int INF = 9999999;
const int MOD = (1e9 + 7);
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }
int main(void) {
ios_base::sync_with_stdio(false);
int n, days, x, curr = 0;
vector... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int Set(int N, int pos) { return N = N | (1 << pos); }
inline int Reset(int N, int pos) { return N = N & ~(1 << pos); }
inline bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
template <class T>
T gcd(T a, T b) {
return (!b) ? a : gcd(b, a % b);
}
temp... | 8 |
#include <bits/stdc++.h>
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int t;
std::cin >> t;
while (t--) {
int n;
std::string a, b;
std::cin >> n >> a >> b;
int l = 0, r = n - 1;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
scanf("%d", &k);
for (int i = 1; i < k; i++) {
for (int j = 1; j < k; j++) {
if (j != k - 1) {
if (j != 1)
printf("%2d ", i * j / k * 10 + (i * j) % k);
else
printf("%d ", i * j);
} else {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int maxn = 2005;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
int t;
int n, m, k;
int cnt[26];
bool vis[maxn];
char s[maxn];
int main() {
scanf("%d", &t);
while (t--) {
memset(cnt, 0, sizeof cnt);
scanf("%d%d", &n, &k);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long b[100061];
long long n, s = 0, k, m;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> k;
s += k;
}
for (int i = 1; i <= n; i++) cin >> b[i];
sort(b + 1, b + n + 1);
n = b[n - 1] + b[n];
if (n >= s)
cout << "YES";
else
co... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct island {
long long u, v;
};
struct bg {
long long u, v;
int cs;
};
const int nm = 200002;
int n, m;
island a[nm];
bg c[nm];
int kq[nm];
set<pair<long long, int> > b;
bool cmp2(bg a, bg b) {
if (a.v != b.v) return a.v < b.v;
return a.u < b.u;
}
int main() {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int N, M, K, W;
char S[1002][12][12];
int D[1002][1002];
int dist[1002];
int Res[1002][2];
bool used[1002];
int bef[1002];
int cost;
int main() {
scanf("%d%d%d%d", &N, &M, &K, &W);
for (int k = 1; k <= K; k++) {
for (int i = 0; i < N; i++) scanf("%s", S[k][i]);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, x;
cin >> a >> b >> x;
int turn = 0, y;
while (x >= 0) {
y = 1;
if (turn == 0) {
for (int i = 1; i <= max(a, x); i++) {
if (a % i == 0 && x % i == 0) y = max(y, i);
}
if (y <= x) {
x -= y;
turn... | 0 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define cl CLOCKS_PER_SEC
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define flw freopen ("0output.txt","w",stdout)
#define flr freopen ("0input.txt","r",stdin)
#define no1s... | 13 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long t;
cin >> t;
while (t--) {
long long n, S = 0, ans = 0;
cin >> n;
string s;
cin >> s;
map<long long, long long> mp;
mp[0]++;
for (long long i = 0; i < s.size(); i++) {
S += s[i] - '0';
ans += mp[S - (i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-12;
const int inf = 2000000000;
long long int MOD = 1000000007;
int MOD1 = 1000000007;
int MOD2 = 1000000009;
inline bool checkBit(long long int n, long long int i) {
return n & (1LL << i);
}
inline long long int setBit(lo... | 0 |
#include <bits/stdc++.h>
using namespace std;
int q, l, r, k;
vector<int> x[10];
long long calc(int n) {
long long sum = 1;
while (n != 0) {
if (n % 10) sum *= n % 10;
n /= 10;
}
return sum;
}
void init() {
for (int i = 1; i <= 1000000; i++) {
int ret = i;
while (ret > 9) ret = calc(ret);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int xx = 0;
int t;
cin >> t;
while (t--) {
long long n, k, i;
string s;
cin >> n >> k >> s;
long long num = 0, d = k;
for (i = 0; i < n; i++) {
if (s[i] == '1') {
if (d < k) num--;
d = 0;
}
if (s[i] ... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct city {
city *before = nullptr, *after = nullptr;
ll id;
};
unordered_map<ll, city> cities;
unordered_map<ll, vector<ll>> rule_map;
int main() {
ll n;
cin >> n;
for (ll i = 0; i < n; i++) {
pair<ll, ll> rule;
cin >> rule.first >... | 9 |
#include<bits/stdc++.h>
using namespace std;
int n;
bool check(int a[2222])
{
bool f=true;
for(int i=1;i<n*2;i++)
{
if(a[i+1]<a[i])
{
f=false;
break;
}
}
return f;
}
int main()
{
int a[2222];
cin>>n;
for(int i=1;i<=n*2;i++) cin>>a[i];
if(check(a))
{
cout<<0;
return 0;
}
if(n%2==0)//n��ż��
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, n, p, m, k, k1, k2, y, x, xs, ys, zs, xf, yf, zf,
fldgjdflgjhrthrl, fldggfhfghjdflgjl, fldgjdflgrtyrtyjl, ffgfldgjdflgjl, x3,
y3, kk, l, r, a[1005][1005];
string s;
vector<string> f;
vector<long long> edges;
vector<pair<long long, long long> > ans;
i... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int mn = 3e5 + 1;
int n, m, tree[mn * 4], k, d[mn];
struct query {
int l, r, x;
};
query queries[mn];
void update(int id, int l, int r, int x, int y, int val) {
if (y < l || x > r) {
return;
}
if (x <= l && y >= r) {
tree[id] = val;
return;
}
i... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n;
double p1[N], p2[N], f[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
double p;
scanf("%lf", &p);
p1[i] = p * (p1[i - 1] + 1);
f[i] = f[i - 1] + p * (1 + 2 * p1[i - 1]);
}
printf("%.10lf\n", f[n]);
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
namespace IO {
void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
void setIO(string s = "") {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin.exceptions(cin.failbit);
if (s.size()) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long int fac[200005], finv[200005], inv[200005];
long long int dp[2005][32];
pair<int, int> pos[2005];
void make() {
inv[1] = 1;
fac[0] = fac[1] = finv[0] = finv[1] = 1;
for (int i = 2; i < 200005; i++) {
inv[i] = 1000000007 - inv[1000000007 % i] * (100000000... | 21 |
#include <bits/stdc++.h>
using namespace std;
int n;
double x[100], y[100], z[100];
int main() {
scanf("%d", &n);
for (int i = 0; i < (n); i++) scanf("%lf%lf%lf", x + i, y + i, z + i);
double x0 = 0, y0 = 0, z0 = 0, lambda = 1;
for (int _ = 0; _ < (100000); _++) {
int i_opt;
double d_opt = -1;
for (... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, m, k, a[600086];
int tsum[5005][5005], dp[5005][5005];
int bound[5005], ans;
int add(int x, int y) {
int sum = x + y;
if (sum >= mod) sum -= mod;
return sum;
}
int solve1(int x) {
tsum[1][0] = 0;
for (int i = 1; i <= k; i++) {
... | 17 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.2")
using namespace std;
inline void opting() {
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
}
long long inp() {
long long x;
cin >> x;
return x;
}
void make_unique(vector<long long... | 17 |
#include <bits/stdc++.h>
using namespace std;
int maxn, n, t, a;
int main() {
cin >> n;
int x, y;
for (int i = 1; i <= n; i++) {
cin >> x >> y;
a = a - x + t;
if (a < 0) {
a = 0;
}
a = a + y;
maxn = max(maxn, a);
t = x;
}
cout << t + a << " " << maxn << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int dp[5000002], a[1000002];
int main() {
int n;
scanf("%d", &n);
int i, j;
int tmp = (1 << 22) - 1;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
dp[a[i]] = a[i];
}
for (i = 1; i <= tmp; i++) {
for (j = 0; j < 22; j++) {
if (i & (1 << j)) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
set<int> a[100100];
void check(vector<int> &group0, vector<int> &group1) {
for (int x : group0)
for (int y : group1)
if (!a[x].count(y)) {
cout << -1 << endl;
exit(0);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int mod = int(1e9) + 7;
const int maxn = 20;
int n, m, color;
long long ans;
int a[maxn][maxn], sett[maxn][maxn];
int used[maxn * maxn];
int Lg[10000];
void init() {
scanf("%d%d%d", &n, &m, &color);
if (n + m - 1 > color) {
printf("0\n");
exit(0);
}
fo... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
int r = 1, c = 1;
for (int i = 1; i <= 2 * (k - 1); i++) {
if (i % 2) cout << "2 ";
if (r % 2) {
cout << r << " " << c << " ";
c++;
if (c > m) {
r++;
c = m;
}
} else {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int v[100005] = {0};
int n, k;
cin >> n >> k;
cout << "1 ";
int i = 1;
v[1] = 1;
bool ok = true;
while (k) {
if (ok) {
cout << i + k << " ", v[i + k] = 1, i = i + k;
} else {
cout << i - k << " ", v[i - k] = 1, i -= k;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
std::vector<long int> indices;
std::vector<long int> t;
long int l = s.length();
for (long int i = 0; i < l; i++) {
if (s[i] == 'F') indices.push_back(i);
}
long int siz = indices.size();
long int temp;
for (long int ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
scanf("%d%d", &n, &m);
if (m == 3) {
if (n == 4) {
printf("0 0\n3 0\n0 3\n1 1\n");
return 0;
}
if (n >= 5) {
printf("-1\n");
return 0;
}
}
for (int i = 0; i < m; i++) printf("%d %d\n", i, 100000 + i * i)... | 15 |
#include <bits/stdc++.h>
using namespace std;
int a[505][505];
int dp[4][505][505];
string ss = "RGYB";
const int N = 510, M = 301000;
int n, m, q, cnt[6][N][N], ans[M];
int r1[M], c1[M], r2[M], c2[M];
char s[N];
vector<pair<int, int> > len[505];
vector<pair<int, int> > len1[505];
int find(int col, int l, int x1, int y... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000;
struct revenge {
int a, b, count;
} shagun[MAX];
int n, p, k, i, position = -1;
long long int sum = 0;
multiset<int> s;
long long int priority[MAX];
bool compare1(const revenge &x, const revenge &y) {
return x.b < y.b || (x.b == y.b && x.a > y.a)... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
long long k;
cin >> n >> k;
if (n % 2 == 0) {
if (k <= (n / 2)) {
cout << 2 * k - 1;
} else {
cout << 2 * (k - n / 2);
}
} else {
if (k <= (n + 1) / 2) {
cout << 2 * k - 1;
} else {
cout << 2 * ... | 1 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int mod = 1e9+7;
int main()
{
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
bool flag=0;
for(auto x:s)
{
if(x!='a'){
flag=1;
break;
}
}
if(flag==0) cout<<"NO\n";
else{
cout<<"YES\n";
int j=s.size()-1;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 0;
int n, hh, mm, hunger, inc, cost, decr;
int main() {
cin >> hh >> mm;
cin >> hunger >> inc >> cost >> decr;
double one = 0.0, two = 0.0;
if (hh < 20) {
int buy = ceil((double)hunger / (double)decr);
one = buy * cost;
double newcost = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int xx, yy, x2, y2, v, t, vx, vy, wx, wy;
bool check(double max) {
double bx = x2, by = y2;
if (t > max) {
bx += (0 - vx) * max;
by += (0 - vy) * max;
} else {
bx += (0 - vx) * t + (0 - wx) * (max - t);
by += (0 - vy) * t + (0 - wy) * (max - t);
}
... | 13 |
#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... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int MAX = 1e7 + 1;
long long int mod = 1e9 + 7;
void solve() {
long long int n, m;
m = 6;
vector<long long int> a(m);
for (long long int i = 0; i < m; i++) cin >> a[i];
cin >> n;
vector<long long int> b(n);
for (long long int i = 0; i < n; i++) cin >... | 11 |
#include <bits/stdc++.h>
int main() {
int n, sum = 0, f = 0, x = 0, y = 0, i;
int a[1000];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
sum += a[i];
}
if (sum % n != 0) {
puts("Unrecoverable configuration.");
return 0;
}
for (i = 0; i < n; i++) {
if (a[i] != sum / n... | 5 |
#include <bits/stdc++.h>
const int MAX_LEN = 1010;
using namespace std;
template <typename U, typename V>
string to_string(pair<U, V>);
string to_string(const string& e_) { return "\"" + e_ + "\""; }
string to_string(char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string(bool e_) { return e_ ? "true" : "fals... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
class problem {
int n;
string u[N][2];
int p[N];
bool haveSolution() {
int h[N];
for (int i = (0); i <= (int)((n)-1); ++i) {
if (u[p[i]][0] < u[p[i]][1])
h[p[i]] = 0;
else
h[p[i]] = 1;
}
for (int i = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200 * 1000 + 13;
int n;
long long T;
int a[N];
int f[N];
void upd(int x) {
for (int i = x; i < N; i |= i + 1) ++f[i];
}
int get(int x) {
int res = 0;
for (int i = x; i >= 0; i = (i & (i + 1)) - 1) res += f[i];
return res;
}
int main() {
scanf("%d%lld... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a1, a2, a3, b1, b2, b3, cups(0), medals(0), cu(0), sh(0);
cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3 >> n;
cups = a1 + a2 + a3;
medals = b1 + b2 + b3;
if (cups <= 5 && cups > 0)
n--;
else
while (cups > 5) {
n--;
cups -= 5;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int f, n;
cin >> f;
n = 0;
cout << n << " " << n << " " << f << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int n, m, k;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
long long ln, lk, lm;
const int mod = 1e9;
int a[200105];
long long f[200105], sf[200105];
long long s[1 << 20], s1[1 << 20], T[1 << 20];
long long gett(long long f1, long long f2, int cnt) {... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
string a, b;
cin >> a >> b;
int cum = 0, cnt = 0, d = 0;
for (int i = 0; i < n; i++) {
if (a[i] == '1') cum++;
if (a[i] == '0' && b[i] == '1') d++;
}
long long int sum = 0;
for (int i = 0; i < n; i++) {
i... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-ffloat-store")
#pragma GCC optimize("-fno-defer-pop")
using namespace std;
int t = 0;
vector<int> tin, tout, p, d;
vector<vector<int> > graph;
void mkgph(int n) {
while (--n) {
int v, u;
cin >> v... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<string> token(string a) {
vector<string> w;
a.push_back(' ');
while (!a.empty()) {
w.push_back(a.substr(0, a.find(" ")));
a = a.substr(a.find(" ") + 1, a.size() - 1);
}
return w;
}
map<string, int> mapik;
vector<string> amapik;
int dodaj(string a) {... | 6 |
#include <bits/stdc++.h>
int const Max = 250000;
char a[Max], b[Max];
bool isequal(char *a, char *b, int length) {
if (!strncmp(a, b, length)) return true;
if (length % 2) return false;
int mid = length / 2;
if (isequal(a, b + mid, mid) && isequal(a + mid, b, mid)) return true;
if (isequal(a, b, mid) && isequ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
int res = 0;
set<int> second;
void dfs(long long v, int x, int y) {
if (v <= n) {
second.insert((int)v);
if (!(v == 0 && x == 0)) {
dfs(v * 10 + x, x, y);
}
if (!(v == 0 && y == 0)) {
dfs(v * 10 + y, x, y);
}
}
}
int main() {
ios... | 8 |
#include <bits/stdc++.h>
double eps = 1e-9;
using namespace std;
int arr[1000001];
int high(int n) {
int last = 0;
while (n != 0) {
last++;
n /= 2;
}
return (1 << (last - 1));
}
void func(int n) {
if (n < 0) {
return;
}
if (n == 0) {
arr[0] = 0;
return;
}
int last = high(n);
int ... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline void p(vector<long long int> x, int n) {
int i;
for (i = 0; i < n; i++) cout << x[i] << " ";
cout << "\n";
}
void rev(char &a) {
if (a == '1')
a = '0';
else {
a = '1';
}
}
void solve() {
long long int M, K, k, i, j, tot = 0, ro = 0, re = 0, bo =... | 7 |
#include <bits/stdc++.h>
using namespace std;
string s;
int ct1[10], ct2[10];
int main() {
cin >> s;
for (int i = 0; i < s.size(); i++) ct1[s[i] - '0']++;
for (int i = 0; i < 10; i++) ct2[i] = ct1[i];
int changed = 0, zero, start;
int best = ct1[0];
string b1 = s, b2 = s;
sort(b1.rbegin(), b1.rend());
s... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t, sx, sy, ex, ey, dx, dy, time = 0;
string s;
char x, y;
cin >> t >> sx >> sy >> ex >> ey;
cin >> s;
for (auto ch : s) {
if (sx == ex and sy == ey) break;
if (ch == 'N' and sy <... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a[505][505], f[505][505], g[505][505];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) scanf("%d", &a[i][j]);
for (int i = 0; i < n; i++) f[i][i] = g[i][i] = 1;
for (int l = 2; l <= n; l++)
for (int i = 0; i < n; ... | 17 |
#include <bits/stdc++.h>
using namespace std;
bool pal(string s) {
int i = 0, j = s.size() - 1;
while (i <= j) {
if (s[i] != s[j]) return false;
i++;
j--;
}
return true;
}
int main() {
vector<int> v;
string s, k;
int i = 0, j = 0, l, p = 0;
cin >> s >> k;
int sz = s.size();
while (i < sz... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
int sum[1 << 18], mx[1 << 18], e[1 << 18];
const int off = 1 << 17;
vector<int> ans;
void stUpdate(int pos, int val, int ee) {
pos += off;
sum[pos] = mx[pos] = val;
e[pos] = ee;
for (pos >>= 1; pos >= 1; pos >>= 1) {
int le = 2 * pos;
int ri = le + 1;... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10;
long long dp[maxn][maxn][3];
int a[maxn];
long long pre[maxn], suf[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + (a[i] == 1);
for (int i = ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, p;
bool si = false;
int main() {
scanf("%d", &n);
scanf("%d", &p);
while (p > 0) {
if (si) printf("RL");
si = true;
printf("P");
p--;
}
si = false;
for (int i = 1; i < n; i++) {
printf("R");
scanf("%d", &p);
while (p > 0) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int prime = 9241;
long long modulo = (long long)1e13;
long long multiply(long long a, long long b) {
long long res = 0, v = a;
while (b) {
if (b & 1ll) res = res + v;
if (res >= modulo) res -= modulo;
v = v + v;
if (v >=... | 21 |
#include <bits/stdc++.h>
using namespace std;
string arr;
int n, sum = 0;
void print(int n1 = -1, int n2 = -1) {
if (sum == 0) {
cout << 0;
return;
}
for (int i = 0; i < n; i++) {
if (arr[i] - 48 == n1) {
n1 = -1;
continue;
} else if (arr[i] - 48 == n2) {
n2 = -1;
continue;... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 100, C = 26, base = 987, MOD = 99999199999;
long long val[C], num[C], valT[C], numT[C], p[N];
queue<long long> pos[C];
map<long long, long long> mp;
vector<long long> ans;
bool mark[C];
string s, t;
long long n, m, cnt, hT;
inline long long Hash(st... | 16 |
#include <bits/stdc++.h>
using namespace std;
int digits(int n) {
int a, b, c, d;
a = n % 10;
b = (n / 10) % 10;
c = (n / 100) % 10;
d = (n / 1000) % 10;
if (a != b && a != c && a != d && b != c && b != d && c != d) return 1;
return 0;
}
int main() {
int n, x;
cin >> n;
for (int i = n + 1; i < 9100;... | 0 |
#include <bits/stdc++.h>
int n;
int main() {
scanf("%d", &n);
puts("YES");
for (int i = 0, x, y, _, __; i < n; ++i) {
scanf("%d%d%d%d", &x, &y, &_, &__);
printf("%d\n", (((x & 1) << 1) | (y & 1)) + 1);
}
return 0;
}
| 13 |
#include <bits/stdc++.h>
using namespace std;
const long long int huge = 1e17;
long long int max(long long int a, long long int b) {
if (a > b) return a;
return b;
}
long long int min(long long int a, long long int b) {
if (a < b) return a;
return b;
}
long long int abbs(long long int a, long long int b) {
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 2e5 + 5;
const long long int M = 1e9 + 7;
int32_t main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
;
long long int n, k;
cin >> n >> k;
long long int low = 1, high = (1e18) + 1;
long long int ans = -1;
while (low <= h... | 13 |
#include <bits/stdc++.h>
using namespace std;
int a[10000005];
bool cmp(int a, int b) { return a > b; }
int main() {
int n;
scanf("%d", &n);
int ans = 0;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]), ans += a[i];
sort(a + 1, a + 1 + n, cmp);
int temp = 1e9;
for (int i = 1; i < n; i++) {
for (int j ... | 5 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> ans;
int power = 1;
while (n > 0) {
if (n % 10 > 0) {
ans.push_back((n % 10) * power);
}
n /= 10;
power *= 10;
}
cout << ans.size() << endl;
for (auto number : ans) cout << number << " ";
co... | 0 |
#include <bits/stdc++.h>
int a[200005];
int d[200005];
int main() {
int n;
scanf("%d", &n);
int minim = 2000000000;
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
if (minim > a[i]) minim = a[i];
}
int maxim = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] == minim) {
d[i] = 0;
} else... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t, x;
cin >> s >> t >> x;
map<char, char> m;
for (int i = 0; i < 26; i++) {
m[s[i]] = t[i];
m[toupper(s[i])] = toupper(t[i]);
}
for (int i = 0; i < x.size(); i++) {
if (isdigit(x[i]))
cout << x[i];
else
cout << ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
long long n, a[100001];
cin >> n;
if (n == 1) {
cout << -1 << endl;
} else {
for (long long i = 0; i < n; i++) {
if (i != n - 1) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ma = 360;
cin >> n;
int arr[n];
int s = 0;
int g = 0;
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < n; i++) {
s = 0;
if (i == n - 1) break;
for (int j = i; j < n + i; j++) {
s += arr[j % n];
g = 360 ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int dirK[8][2] = {{-2, 1}, {-1, 2}, {1, 2}, {2, 1},
{2, -1}, {-1, -2}, {1, -2}, {-2, -1}};
int dir8[8][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1},
{-1, -1}, {1, 1}, {1, -1}, {-1, 1}};
int dir4[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, ans, a[100001], b[100001], k, x, y, p, mid, sz;
vector<int> g[100001];
map<int, int> st;
set<int> q;
string s, s2;
char c;
int main() {
cin >> n >> k >> p >> x >> y;
for (int i = 1; i <= k; i++) {
cin >> a[i];
mid += a[i];
b[i] = a[i];
sz++;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int sg[100005];
int ans[100005];
int getSG(int n) {
if (sg[n] != -1) {
return sg[n];
}
bool vis[100] = {false};
int y = n + n;
for (int k = 2; k < y; k++) {
if (y % k == 0) {
int a = y / k - k + 1;
if (a > 0 && a % 2 == 0) {
a >>= 1;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> v, v1;
const long long MAX = 1e18;
void pre() {
for (long long i = 2; i < 1000000; i++) {
long long p = i * i * i;
long long sq = sqrt(i);
if (sq * sq == i) continue;
while (p > 0 and p < MAX and p % i == 0) {
long long x = sqrt(p);... | 13 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
int vis[1001010];
void ex_gcd(int a, int b, int &x, int &y) {
if (!b) {
x = 1;
y = 0;
} else {
ex_gcd(b, a % b, y, x);
y -= x * (a / b);
}
}
int gcd(int a, int b) { ret... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
vector<char> v;
getline(cin, str);
for (int i = 0; i < str.size(); i++) {
if (v.empty() || v.back() != str[i])
v.push_back(str[i]);
else
v.pop_back();
}
vector<char>::iterator it;
for (it = v.begin(); it != v.end();... | 6 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
long long n = s.size();
long long two = -1, five = -1, seven = -1, zero1 = -1, zero2 = -1;
for (long long i = 0; i < n; ++i) {
if (s[i] == '2') {
two = i;
} e... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9;
const int MOD = 1e9 + 7;
const int N = 5e5;
vector<int> g[N];
int pres[N], p[N], sub[N];
int root(int u) {
while (u != p[u]) {
p[u] = p[p[u]];
u = p[u];
}
return u;
}
void merge(int uu, int vv) {
int u = root(uu), v = root(vv);
if (u ==... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void Read(T &x) {
char ch;
bool neg = 0;
x = 0;
while (!isdigit(ch = getchar()) && ch != '-')
;
if (ch == '-') {
neg = 1;
ch = getchar();
}
do {
x = x * 10 + ch - 48;
} while (isdigit(ch = getchar()));
if (neg) x = -x;... | 13 |
#include <bits/stdc++.h>
int arr[20];
using namespace std;
int main() {
int n, l, r, x;
scanf("%d", &n);
;
scanf("%d", &l);
;
scanf("%d", &r);
;
scanf("%d", &x);
;
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
;
}
int ans = 0;
for (int i = 0; i < (1 << n); i++) {
int minv = I... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, a[55];
pair<int, int> dp[55][2];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
dp[n - 1][0] = make_pair(0, a[n - 1]);
dp[n - 1][1] = make_pair(a[n - 1], 0);
for (int i = n - 2; i >= 0; i--) {
if (a[i] + dp[i + 1... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, i;
char str[1009];
scanf("%d", &a);
cin >> str;
if (str[0] == '0' && a > 1) {
cout << "No solution" << endl;
return 0;
}
for (i = 1; i < a; i++) {
str[i] = '0';
}
str[i] = '\0';
cout << str << endl;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int mn = 2e5 + 5;
const int mod = 1e9 + 7;
int n, q;
int a[mn];
bool is_cycle[mn];
int cycc[mn];
vector<int> cycle[mn];
int cycnt;
int cyid[mn];
int to[mn];
int dist[mn];
vector<int> rg[mn];
int vis[mn];
vector<int> st;
void dfs(int x) {
if (vis[x] == -1) {
int ... | 21 |
#include <bits/stdc++.h>
using namespace std;
bool solve(string s) {
int n = s.size();
if (n < 5) return 0;
bool search = 0;
for (int i = 0; i < n; ++i)
if (isdigit(s[i])) search = 1;
if (!search) return 0;
search = 0;
for (int i = 0; i < n; ++i)
if (islower(s[i])) search = 1;
if (!search) retur... | 0 |
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
void clock_out() {
cerr << "\nTime Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
}
void fileio() {
freopen("/home/dwai/Desktop/cp/input.txt", "r", stdin);
freopen("/home/dwai/Desktop/cp/output.txt", "w", stdout);
freopen... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int p, q, l, r;
scanf("%d%d%d%d", &p, &q, &l, &r);
int mark[1111];
memset(mark, 0, sizeof(mark));
int a, b;
for (int i = 0; i < p; i++) {
scanf("%d%d", &a, &b);
for (int j = a; j <= b; j++) mark[j] = 1;
}
int c[55], d[55];
for (int i =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, i, d[101], a, mlad, prod, x, y;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &a);
d[i] = d[i - 1] + a;
}
scanf("%d %d", &x, &y);
for (i = 1; i <= n; i++) {
prod = d[n] - d[i - 1];
mlad = d[i - 1];
if (x <= mlad &&... | 2 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int n, m;
char G[2000][2000];
deque<pair<pii, int>> deq;
int dist[2000][2000];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
void bfs(int s, int t) {
deq.emplace_front(make_pair(make_pair(s, t), 0));
while (!deq.empty()) {
pair<pi... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, k;
cin >> n >> k;
char b = 'a';
long long int g = n / k;
long long int sex = n % k;
long long int j;
long long int i = 1;
while (i <= k) {
j = 1;
while (... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long mdl;
vector<long long> vis;
void gen(long long& f, long long& p, long long h, long long a, long long x,
long long y) {
vis = vector<long long>(1000009, -1);
long long ct = 0;
while (vis[h] == -1) {
vis[h] = ct;
h = (x * h + y) % mdl;
++c... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T sqr(const T& a) {
return a * a;
}
template <typename T>
inline int sign(const T& a) {
return a < 0 ? -1 : a > 0;
}
void task();
int main() {
ios_base::sync_with_stdio(0);
task();
return 0;
}
struct SparseTable {
int t[int(3e5) + 10... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long n;
string s1, s2;
long long precom[26][200005];
long long present[26][200005];
long long tree[26][200005];
long long sum(long long i, long long ch) {
long long sum = 0;
while (i > 0) {
sum += tree[ch][i];
i -= i & (-i);
}
return sum;
}
void update(... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 11;
const long long maxn = 2e3 + 9;
const double esp = 1e-6;
long long dp[maxn][maxn];
void solve() {
long long n, h, l, r;
cin >> n >> h >> l >> r;
vector<long long> v(n + 1);
for (long long i = 1; i <= n; i++) {
cin >> v[i];
}
fill(dp[0... | 9 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
long long int res = 0, k;
cin >> n;
vector<long long int> t;
for (int i = 0; i < n; i++) {
cin >> k;
t.push_back(k);
}
for (int i = 0; i < n; i++) {
if (i - 1 >= 0) {
if (t[i - 1] * t[i] > res) {
res = t[i - 1] *... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.