solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
int a = (k + 1) / 2;
int r = (a - 1) / m + 1;
int c = (a - 1) % m + 1;
cout << r << ' ' << c << ' ';
cout << ((k % 2 == 0) ? "R" : "L") << endl;
return 0;
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
const int INF = 0x3f3f3f3f;
using namespace std;
int n;
long long a[9], sum[(1 << (8))];
int dp[(1 << (8))][(1 << (8))], cnt[(1 << (8))];
map<long long, int> h;
int prim[N], pn;
bool isPrim[N];
void make_prim() {
memset(isPrim, 1, sizeof(isPrim));
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char last;
int c0 = 0, c1 = 0, cx = 0;
while (cin >> last) {
if (last == '0')
c0++;
else if (last == '1')
c1++;
else
cx++;
}
if (c0 + cx > c1) cout << "00\n";
if (last == '1' && c1 + cx >= c0 && c0 + cx >= c1 - 1)
c... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3e5 + 10;
char str[maxn];
long long N;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> str + 1;
N = strlen(str + 1);
long long pos = 1;
vector<long long> v;
while (pos <= N) {
long long num = 0;
while (pos <= N &&... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, k, a;
scanf("%I64d%I64d%I64d", &n, &m, &k);
if (n + m - 2 < k)
printf("-1");
else {
if (n > m) {
a = n;
n = m;
m = a;
}
if (n >= k + 1) {
printf("%I64d", max((m / (k + 1)) * n, (n / (k + 1)) * m));... | 4 |
#include <bits/stdc++.h>
using namespace std;
int i, B[36];
long long N[4],
A[36] = {2, 1, 4, 3, 1, 1, 1, 1,
1, 5, 10, 200, 500, 10000, 50000, 100000,
200000, 1002, 2, 10002, 2, 200000, 2, 99,
9955, 1997... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long MOD1 = 998244353;
const long long MIN_LL = -1e18;
const long long MAX_LL = 1e18;
const int MAX_INT = 1e9;
const int MIN_INT = -1e9;
const long double pie = 3.1415926535;
long long fpow(long long n, long long p) {
;
long ... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct aaa {
long long x, w;
} a[500010];
long long D, mx, m, ans, la, f[500010], nt[500010];
bool cmp(aaa a, aaa b) { return a.x < b.x; }
long long lowbit(long long x) { return x & (-x); }
void ins(long long x, long long w) {
long long i;
for (i = x; i <= m; i += low... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> primes;
void GeneratingPrimes(int top) {
vector<bool> p(top + 1, 1);
p[0] = p[1] = 0;
for (int i = 2; i <= sqrt(top); i++) {
if (p[i]) {
for (int j = i * i; j <= top; j += i) {
p[j] = 0;
}
}
}
for (int i = 0; i < top +... | 4 |
#include <bits/stdc++.h>
using namespace std;
int veci[100003];
int cal() {
int t, k, c = 0, cc = 0;
scanf("%d%d", &t, &k);
for (int i = 0; i < t; i++) scanf("%d", &veci[i]);
for (int i = k; i < t; i++)
if (veci[i] != veci[i - 1]) return -1;
if (k == 1 && (veci[0] == veci[1] || t == 1)) return 0;
int i ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
void sadd(int &a, int b) {
a += b;
if (a >= MOD) a -= MOD;
}
int add(int a, int b) {
sadd(a, b);
return a;
}
int mul(int a, int b) { return (a * 1LL * b) % MOD; }
int fpow(int x, long long n) {
if (n == 0) return 1;
int a = fpow(x, ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
vector<long long> g[N];
long long a[N], pos[N], neg[N];
void dfs(long long node, long long par) {
for (auto it : g[node]) {
if (it == par) continue;
dfs(it, node);
pos[node] = max(pos[node], pos[it]);
neg[node] = max(neg[node],... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
int f = 1;
char k = getchar();
x = 0;
for (; k > '9' || k < '0'; k = getchar())
if (k == '-') f = -1;
for (; k >= '0' && k <= '9'; k = getchar()) x = x * 10 + k - '0';
x *= f;
}
int a, b, c, d;
int main() {
read(... | 6 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int IT_MAX;
const int MOD = 1000000007;
const int INF = 1034567891;
const long long LL_INF = 2234567890123456789ll;
const double PI = 3.141592653589793238;
int in[100050];
int main() {
int N, K, i;
int gr = 0;
scanf("%d %d", &N, &K);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
vector<long long> val(8, INT_MAX);
val[0] = 0;
while (n--) {
long long x, y = 0;
string s;
cin >> x >> s;
for (char c : s) {
if (c == 'A')
... | 2 |
#include <bits/stdc++.h>
using namespace std;
char inp[1003][1003];
int n, m, mx = 0, ans;
map<pair<int, int>, int> memo;
int DFS(int i, int j, int cur, int val, int vall) {
if (i > n - 1 || j > m - 1 || j < 0 || i < 0) return 0;
if (cur == 4) val++, vall++;
int res = 0, con = val, ans1 = 0, ans2 = 0, ans3 = 0, a... | 5 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long t;
cin >> t;
while (t--) {
long long n, p;
cin >> n;
long long x[n];
for (long long i = 0; i < n; i++) {
cin >> x[i];
}
long long q = n - 1;
while ... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<string> v;
map<string, int> mp;
int main() {
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
}
for (int i = n - 1; i >= 0; i--) {
if (mp[s[i]] == 0) {
v.push_back(s[i]);
}
mp[s[i]]++;
}
for (int i = 0; i ... | 2 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long p2u(unsigned long long u) {
if (u == 0) return 1;
if (u == 1) return 2;
unsigned long long v = p2u(u / 2);
v %= 1000000009;
v *= v;
v %= 1000000009;
if (u % 2) {
v *= 2;
v %= 1000000009;
}
return v;
}
int main() {
unsigned long... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1048577;
int n, m, s, sz, cnt;
double ans;
long long f[maxn], bin[55];
double dp[maxn];
char c[55][25];
int main() {
bin[0] = 1;
for (int i = 1; i <= 50; i++) bin[i] = bin[i - 1] << 1;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%s", c[i] +... | 9 |
#include <bits/stdc++.h>
char a[100010], b[100010];
int main() {
scanf("%s", a);
scanf("%s", b);
int dif4 = 0, dif7 = 0, dif = 0;
for (int i = 0; a[i] != '\0'; i++) {
if (a[i] != b[i]) {
if (a[i] == '4') {
if (dif7 != 0) {
dif7--;
dif++;
} else
dif4++;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int a, b, pos;
double w;
};
edge e[100005];
edge e1[100005];
int f[100005];
int ans[100005];
int n, m, k, i, now, a, b;
double l = -1e6, r = 1e6, mid;
bool operator<(edge e, edge e1) { return e.w < e1.w; }
int find(int x) {
if (f[x] == 0) return x;
f[x... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long x = 0;
int f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
return x * f;
}
void print(long long x) {
if (x < 0) x = -x, putchar... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, k, ans;
int pos[6][1009], a[6][1009];
int d[1009], pd[1009][1009], f[1009];
bool vis[1009];
vector<int> e[1009];
bool AssignMax(int* a, int b) {
if (*a < b) {
*a = b;
return true;
} else
return false;
}
int dfs(int u) {
if (f[u] != -1) return f[u];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
namespace RA {
int r(int p) { return 1ll * rand() * rand() % p; }
int r(int L, int R) { return r(R - L + 1) + L; }
} // namespace RA
const int N = 1e5 + 5;
int n, dg[N], sz[N], dep[N], flag[2], f[N];
vector<int> g[N];
void dfs(int u, int p) {
dep[u] = dep[p] + 1, sz[u] =... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N];
map<int, int> mp;
int d2[N], d[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
mp[a[i]]++;
}
int l = 0;
for (auto p : mp) {
int t = p.second;
d2[t]++;
}
for (int i =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string str;
cin >> n >> str;
for (int i = 1; i <= n; ++i) {
for (int k = 0; k < n; ++k)
for (int j = k, c = 0; j < n; j += i) {
if (str[j] == '.') break;
++c;
if (c == 5) {
cout << "yes";
retu... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, a[201], ans, b[101], c[101];
int main() {
cin >> n;
for (int i = 1; i <= 2 * n; ++i) {
scanf("%d", &a[i]);
if (!b[a[i]])
b[a[i]] = i;
else
c[a[i]] = i;
}
for (int i = 1; i <= 2 * n; ++i) {
for (int j = c[a[i]]; j > i + 1; --j) {
... | 3 |
#include <bits/stdc++.h>
int main() {
char a[27], b[27], in[1003], ou[1003];
scanf("%s", a);
scanf("%s", b);
scanf("%s", in);
int len = strlen(in), i, j;
for (i = 0; i < len; i++) {
if (in[i] >= 97 && in[i] <= 122) {
for (j = 0; j < 26; j++)
if (a[j] == in[i]) printf("%c", b[j]);
} els... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, const U &b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, const U &b) {
if (a < b) a = b;
}
long long dp[55][2], a[55];
int main() {
int n;
cin >> n;
long long sum = 0;
for... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0, maxv = 0;
string s;
cin >> n;
while (cin >> s) {
for (int i = 0; i < s.size(); i++)
if (s[i] >= 'A' && s[i] <= 'Z') ans++;
maxv = max(maxv, ans);
ans = 0;
}
cout << maxv << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int maxn = 100005;
int a[maxn], b[maxn], n;
map<int, int> cnt;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d%d", &a[i], &b[i]);
++cnt[a[i]];
++cnt[b[i]];
}
vector<int> c... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int get(int i) {
int a, b;
cout << "? " << i << endl;
cin >> a;
cout << "? " << i + n / 2 << endl;
cin >> b;
return a - b;
}
int main() {
cin >> n;
int sv = get(1), l = 1, r = n / 2;
if (sv == 0) {
cout << "! 1" << endl;
return 0;
}
whil... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9, PI = acos(-1);
bool ge(long double x, long double y) { return x + EPS > y; }
bool le(long double x, long double y) { return x - EPS < y; }
bool eq(long double x, long double y) { return ge(x, y) && le(x, y); }
struct poin... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long inf = (long long)5e18;
const long double eps = 1e-12;
const long long N = 1000005;
const long long LOGN = 19;
const long double PI = 3.14159265358979323846;
long long mul(long long a, long long b, long long m = mod) {
retu... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long a[1000001], c[1000001], b[1000001], x, y, z, sum, ans, n, m, k, l, o,
p, q, u, mx, mn;
string s, second[1000001];
map<long long, long long> e;
vector<int> v;
vector<int>::iterator it;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
... | 0 |
#include <bits/stdc++.h>
const int mod = 1000000007;
const int inf = 1000000009;
const long long INF = 1000000000000000009;
const long long big = 1000000000000000;
const long double eps = 0.0000000001;
using namespace std;
bool cmp(int a, int b) { return a > b; }
int k;
long long int DP[500005][3];
vector<pair<int, int... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2000005;
int f[15][15][15][15];
char s[N];
void Prepare() {
memset(f, 60, sizeof(f));
for (register int i = 0; i <= 9; i++) {
for (register int j = 0; j <= 9; j++) {
for (register int k = 0; k <= 9; k++) {
f[i][j][k][(k + i) % 10] = 1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct segment {
int left, right;
bool operator<(const segment a) const {
if (left < a.left) {
return true;
}
if (left == a.left && right > a.right) {
return true;
}
return false;
}
} s[1001];
int n;
int a[1001];
void deal() {
sort(s,... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
int a[N], cmp, ans;
vector<int> adj[N];
queue<int> q;
int visited[N];
void dfs(int u, int par = -1) {
visited[u] = cmp;
for (int v : adj[u]) {
if (!visited[v]) {
dfs(v, u);
} else if (visited[v] == cmp) {
q.push(v);
}
}
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct factor {
int p[25], q[25], sz;
inline void clear() {
memset(p, 0, sizeof(p));
memset(q, 0, sizeof(q));
sz = 0;
}
inline void sort() {
pair<int, int> arr[25];
for (int i = 0; i < sz; i++) arr[i] = make_pair(p[i], q[i]);
::sort(arr, arr ... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct one {
int i;
int end;
bool operator<(const one &e) const { return i < e.i; }
};
struct zero {
int i, j;
};
const int inf = 1e9;
class segment {
public:
vector<int> n, t;
segment() { ; }
segment(vector<int> &a) : n(a), t(4 * a.size(), 0) { build(0, 0, a... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 9, mod = 1e9 + 7, inf = 1e18;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
priority_queue<pair<long long, long long>,
vector<pair<long long, long long> >,
greater<pair<long ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, l, n, m, it = 0, ar[26], flag = -1, cnt = 0;
cin >> n;
int ans = 0;
char c;
string second;
for (i = 0; i < 26; i++) ar[i] = 1;
for (i = 0; i < n; i++) {
cin >> c >> second;
if (i == n - 1) break;
if (flag == 1) {
if ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[100011], arr[100011];
long long sum[100011], tot[100011];
int main() {
int n, i, j;
cin >> n;
long long ans = 0;
for (i = 1; i <= n; i++) scanf("%d", a + i), sum[i] = sum[i - 1] + a[i];
for (i = 1; i <= n; i++) scanf("%1d", arr + i), ans += arr[i] * a[i];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
string str;
long long getans(int x) {
int l = x - 1;
long long cnt1 = 0;
while (l >= 0) {
if (isalpha(str[l])) cnt1++;
if (str[l] == '@' || str[l] == '.') break;
l--;
}
int flag1 = 0;
int flag2 = 0;
long long cnt2 = 0;
int r = x + 1;
while (r <... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2000000000;
int h[1000000], axis[2000000], maxv[1 << 22], cover[1 << 22];
pair<int, int> seg[1000000], order[1000000];
int transformX(int x, int y, int vx, int vy) { return x * vx + y * vy; }
int transformY(int x, int y, int vx, int vy) { return y * vx - x *... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 100000 + 10;
const int M = 200000 + 10;
int val[M], idx = 0;
int sum[M << 2], l[N], r[N];
vector<int> g[M];
void update(int pos, int v, int l, int r, int rt) {
if (l == r) {
sum[rt] = (sum[rt] + v) % mod;
} else {
int mi... | 4 |
#include <bits/stdc++.h>
long long min(long long a, long long b) {
if (a < 0 || b < 0) return 0;
return a < b ? a : b;
}
int main() {
long long n, k;
scanf("%lld %lld", &n, &k);
if (k % 2)
printf("%lld", min(k / 2, n - k / 2));
else
printf("%lld", min(k / 2 - 1, n - k / 2));
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long id[10005];
long long root(long long x) {
while (id[x] != x) {
id[x] = id[id[x]];
x = id[x];
}
return x;
}
void unio(long long x, long long y) { id[root(y)] = root(x); }
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
long ... | 5 |
#include <bits/stdc++.h>
using namespace std;
void slv() {
int n;
cin >> n;
string s, t;
cin >> s >> t;
if (s == t) {
cout << "Yes\n";
return;
}
vector<int> v;
for (int i = 0; i < n; i++) {
if (s[i] != t[i]) {
v.push_back(i);
}
}
if (v.size() == 2) swap(s[v[0]], t[v[1]]);
if ... | 1 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000")
bool ascending(int i, int j) { return (i < j); }
bool descending(int i, int j) { return (i > j); }
using namespace std;
bool G[1000 + 10][1000 + 10];
int n, m;
bool check(int x, int y) {
if (x <= 0 || x >= n - 1) return 0;
if (y <= 0 || y >= n ... | 2 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:200000000")
const double EPS = 1E-9;
const int INF = 1000000000;
const long long INF64 = (long long)1E18;
const double PI = 3.1415926535897932384626433832795;
const int C = 100;
const string DELIMS = ",.?!\"\\/|#“”@*";
const string cat[3 * C]... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int minute, minute_cnt;
long long int cal(long long int n, long long int k) {
vector<long long int> a;
for (; n; n /= 10) a.push_back(n % 10);
reverse((a).begin(), (a).end());
long long int res = 0, base = 0;
for (long long int i = 0; i < ((long long int... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int cnt = 0, len = 0, ans = 0, i;
char xx[3][111];
while (gets(xx[0]) != NULL) {
if (xx[0][0] == '+')
cnt++;
else if (xx[0][0] == '-')
cnt--;
else {
for (i = 0; xx[0][i]; i++)
if (xx[0][i] == ':') break;
ans = a... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e6 + 3;
const int MAXN = 10 + 5;
inline long long pw(long long a, int b) {
long long res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
inline void answer(int x) {
printf("! %d\n", x);
fflu... | 7 |
#include <bits/stdc++.h>
int main() {
int n, i, j, l, k, a[105];
while (~scanf("%d", &n)) {
l = 0;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
for (k = 0; k < n; k++) {
if (i != j && i != k && j != k && a[i] == a[j... | 2 |
/* https://codeforces.com/blog/entry/90236 (segment tree beats) */
#include <stdio.h>
#include <stdlib.h>
#define N 200000
#define Q 100000
#define N_ ((N + Q * 2) * (LG + 1))
#define LG 20
#define B (1 << LG)
int ll[1 + N_], rr[1 + N_], sz[1 + N_], msk0[1 + N_], msk1[1 + N_], lz[1 + N_], _ = 1;
void put(int u, int ... | 13 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
int p = 0;
int a[100100];
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
int s = n + n - 1;
for (int i = 0; i < n; i++) {
s += fabs(a[i] - p);
p = a[i];
}
printf("%d\n", s);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
typedef struct point {
int x, y;
};
int n;
point A[5][5], v[10];
inline bool cmp(point a, point b) {
return (a.y > b.y) || (a.y == b.y && a.x < b.x);
}
inline int min(int a, int b) {
if (a < b) return a;
return b;
}
inline int max(int a, int b) {
if (a > b) return... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const int inf = (signed)(~0u >> 1);
typedef class Event {
public:
int p, op, id;
Event(int p, int op, int id) : p(p), op(op), id(id) {}
bool operator<(Event b) const { return p < b.p; }
} Event;
typedef class pii {
public:
int x, y;
pii(in... | 13 |
#include <bits/stdc++.h>
using namespace std;
bool works(long long n, long long N) { return (n >= (N * (3 * N + 1) / 2)); }
int bsearch(long long n, int low, int high) {
if (low == high) return low;
if ((low + 1) == high) {
if (works(n, high)) return high;
return low;
}
int mid = (low + high) / 2;
if ... | 4 |
#include <bits/stdc++.h>
int main() {
long long int n, y = 1;
scanf("%lld", &n);
while (n > y) {
n -= y;
y++;
}
printf("%lld", n);
return 0;
}
| 1 |
#include <bits/stdc++.h>
int main() {
int n, m, i, j;
scanf("%d %d", &n, &m);
if (n == 1 && m > 2) {
puts("1");
printf("1 %d 1 1\n", m);
for (i = 0; i < m; i++) printf("1 %d\n", i + 1);
puts("1 1");
} else if (m == 1 && n > 2) {
puts("1");
printf("%d 1 1 1\n", n);
for (i = 0; i < n; ... | 6 |
#include <bits/stdc++.h>
int main() {
int n, x;
scanf("%d%d", &n, &x);
int f[105] = {false};
for (int i = 1; i <= n; i++) {
int a;
scanf("%d", &a);
f[a] = true;
}
int ans = 0;
for (int i = 0; i < x; i++) {
if (!f[i]) ans++;
}
if (f[x]) ans++;
printf("%d\n", ans);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
int get(int i) {
printf("? %d\n", (i - 1) % n + 1);
fflush(stdout);
int x;
scanf("%d", &x);
return x;
}
void respond(int i) {
if (i == -1)
printf("! -1\n");
else
printf("! %d\n", (i - 1) % n + 1);
fflush(stdout);
}
int intersection(int a, int ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXM = 500 + 5;
const int MAXN = 500 + 5;
const int MAXQ = 300 + 5;
const int MAXK = 800 + 5;
const int P = 5;
const int MOD = 1e9 + 7;
int n, m, q, a[MAXN][MAXK];
int inv[P], ans = 1;
char buf[MAXM];
int main() {
for (int i = 0; i < P; i++) inv[i] = i * i * i %... | 9 |
#include <bits/stdc++.h>
using namespace std;
int TestMillerRabin[5] = {2, 3, 5, 7, 11};
long long mulmod(long long a, long long b, long long p) {
long long x = 0, y = a % p;
while (b > 0) {
if (b % 2 == 1) x = (x + y) % p;
y = (1LL * y * 2) % p;
b = b / 2;
}
return x % p;
}
long long fastexp(long l... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long int M = 1000000007;
long long int power(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res % p;
}
long long in... | 3 |
#include <bits/stdc++.h>
using namespace std;
int boobs(string s) {
int n = s.length();
int i = 0;
int total = 0;
for (i = 0; i < n; i++) {
if (s[i] == '.' && s[i + 1] == '.') total++;
}
return total;
}
int main() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
int a;
char c;
int i = 0;
i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
if (n == 2) {
cout << 1;
return 0;
}
int c = 0;
for (int i = 2; i < n; ++i) {
bool f = true;
int arr[2005] = {0};
for (long long j = i, s = 1; s <= n - 2; j = (j * i) % n, s++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
ios::sync_with_stdio(false);
int n, k, i;
cin >> n >> k;
for (i = 0; i < n; i++) {
cin >> a[i];
}
if (n == 1) {
cout << "0\n";
cout << a[0];
return 0;
}
int sum = 0, x;
for (i = 0; i < n - 2; i++) {
if (a[i] ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long ways[105][25][25] = {0};
vector<int> G[100];
int n, k, visited[100] = {0};
void DFS(int v) {
visited[v] = 1;
long long w[25][25] = {0};
w[1][0] = 1;
w[k + 1][1] = 1;
for (auto x : G[v]) {
if (!visited[x]) {
DFS(x);
long long comb[25][25] ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
int a = 0, ac = 0, b = 0, bc = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (a == 0 || a == x) {
a = x;
ac++;
} else if (b == 0 || b == ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, k = 1999;
cin >> n >> m;
for (int i = 0; i < k; i++)
if (~i % 2)
cout << 9;
else
cout << 0;
cout << endl;
for (int i = 0; i < k - 2; i++)
if (~i % 2)
cout << ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 7;
const long long Mod = 152076289;
char seq[MAXN], s[MAXN];
int T = 1;
int main(void) {
scanf("%s", seq);
int L = strlen(seq);
if (L % 2 == 1) {
printf("No\n");
return 0;
}
s[1] = seq[0];
for (int i = 1; i < L; i++) {
if (s[T]... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 809;
struct E {
int u, v, w;
bool operator<(E a) const { return w < a.w; }
} e[300009];
int id[200009];
long long d[N][N], a[1000009];
int main() {
int n, m, o, i, j, k, t = 0;
scanf("%d%d%d", &n, &m, &o), memset(d, 63, sizeof d);
for (i = 1; i <= m;... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> swap1, swap2;
int move(int arr[], int from, int to) {
int count = 0, temp, copyFrom = from, fromValue = arr[from];
while (true) {
if (arr[to] == fromValue) break;
swap1.push_back(copyFrom - 1);
swap2.push_back(copyFrom);
swap(arr[copyFrom], a... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, g[150], zbr;
string s;
char p[5];
int main() {
scanf("%d", &n);
scanf("%s", p);
vector<pair<string, string> > v;
set<string> l;
for (int i = (0); i < int(n); i++) {
cin >> s;
v.push_back(make_pair(s.substr(0, 3), s.substr(5, 3)));
l.insert(s.sub... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, ans, u, v, i, root_u, root_v, arr[100001], len[100001], c[100001],
k;
vector<pair<long long, long long> > in;
long long find(long long x) {
if (arr[x] == x) return x;
return arr[x] = find(arr[x]);
}
int main() {
cin >> n >> k;
for (i = 1; i <= n; i+... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, city = 1;
bool count;
cin >> n;
int* time;
time = new int[n];
for (i = 0; i < n; i++) cin >> time[i];
int t = time[0];
for (i = 0; i < n; i++) {
if (time[i] == t && i > 0) count = true;
if (time[i] < t) {
t = time[i];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int> > vd(n);
multiset<pair<int, pair<int, int> > > ds;
int td, ts;
for (int i = 0; i < n; i++) {
cin >> td >> ts;
if (td == 0) continue;
vd[i] = make_pair(td, ts);
ds.insert(make_pair(td, make_pair(... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
const double eps = 1e-8;
int t;
long long n;
int main() {
scanf("%d", &t);
while (t--) {
scanf("%lld", &n);
long long ans = 0;
int cnt = 0;
while (n) {
if (n % 2 == 0) {... | 3 |
#include <bits/stdc++.h>
using namespace std;
int dp[(1 << 23)];
int main() {
int i, j, k, n, m, t, x;
cin >> t;
while (t--) {
cin >> n >> m;
int a[n], b[m];
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
string s[n];
for (i = 0; i < n; i++) {
cin >> s[i];
for (j = 0; j < m;... | 2 |
#include <bits/stdc++.h>
using namespace std;
char s[1007];
int t, k, f[1007][1007][2], a[1007], l;
int dfs(int pos, int d, int q, int m) {
if (!pos) return q;
if (!m && f[pos][d][q] != -1) return f[pos][d][q];
int ans = 0, MAX = m ? a[pos] : 9;
for (int i = 0; i <= MAX; i++) {
if (i != 4 && i != 7)
a... | 8 |
#include <bits/stdc++.h>
template <class K>
inline bool umax(K& a, K b) {
return a < b ? a = b, true : false;
}
template <class K>
inline bool umin(K& a, K b) {
return a > b ? a = b, true : false;
}
template <class K>
inline void read(K& first) {
char c = getchar();
K f = +1;
for (first = 0; c < '0' || c > '9... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int ninf = 0xc0c0c0c0;
const long long linf = 0x3f3f3f3f3f3f3f3fll;
const long long lninf = 0xc0c0c0c0c0c0c0c0ll;
int fa[1005], d[1005];
vector<int> a[1005], son[1005];
void dfs(int i, int f, int num) {
fa[i] = f;
d[i] = d[f] + 1;
son... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, res, nt, b, f;
long long p[300007], pp[300007], a[300007];
int main() {
scanf("%I64d", &n);
for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
sort(a + 1, a + 1 + n);
p[1] = 2;
pp[1] = 0;
for (int i = 2; i <= n; i++) {
pp[i] = (2 * pp[i - 1] + ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n;
cin >> n;
vector<long long> v(n + 1);
for (long long i = 1; i <= n; i++) {
cin >> v[i];
}
long long left = 0;
long long right = 0;
for (long long i = 1; i <= n; i++... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct road {
int start, end, len, id;
} rd[500005];
int fa[2005];
bool cmp(road x, road y) { return x.len > y.len; }
inline int getf(int x) {
if (fa[x] == x) return fa[x];
return fa[x] = getf(fa[x]);
}
inline void con(int x, int y) {
int f1, f2;
f1 = getf(x), f2 ... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long k, ans, idx, pwr, hs;
bool A[500005], B[500005], l;
string s, s1, s2, s3;
map<string, bool> mp;
unordered_set<long long> st;
int main() {
std::ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> s >> s1 >> s2;
for (long long i = 0; i + s1.size(... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int y, k, n, i, ok = 0;
scanf("%d%d%d", &y, &k, &n);
for (i = 1; i <= n / k; i++)
if (i * k - y >= 1) {
printf("%d ", i * k - y);
ok = 1;
}
if (ok == 0) printf("-1");
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int MAXR = 1e5 + 5;
int ok[MAXR];
int main() {
ios::sync_with_stdio(false);
long long n, m, i, l, r, a;
long long minl = INF, maxr = -1;
long long sum = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a;
su... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long S, X, N, i, j;
bool A[40], B[40];
void masuk(bool A[], long long X) {
int i;
long long S = X, P = pow(2, 39);
for (i = 0; i < 40; i++) {
A[i] = (S >= P);
S = S % P;
P /= 2;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.t... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int n;
cin >> n;
std::vector<int> adj[200000];
std::vector<int> d(n, INT_MAX);
std::vector<int> d2(n, INT_MAX);
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
adj[u - 1].push_back(v - 1);
adj[v... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
;
int t, len;
cin >> t;
while (t--) {
int a = 0, element;
cin >> len;
for (int i = 1; i <= len; i++) {
cin >> element;
if (element % 2 == 0) a = i;
}
if (a) {
cout << 1 ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int bit[11][11][5][N];
char s[N], e[11];
int get(char z) {
if (z == 'A') return 0;
if (z == 'T') return 1;
if (z == 'G') return 2;
if (z == 'C') return 3;
}
void update(int step, int start, int let, int pos, int x) {
while (pos < N) {
bi... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
vector<int> a(n, 0);
for (i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
double ans, pi = 3.1415926536;
if (n % 2 != 0) {
ans = pi * a[0] * a[0];
for (i = 2; i < n; i = i + 2) ans += pi * (pow(a[i], 2) - pow(... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 10;
const double eps = 1e-5;
const int maxN = 2 * 1000 + 100;
const int inf = 1e9 + 100;
int n;
char c[maxN];
inline void init() {
scanf("%d", &n);
scanf("%s", c);
}
inline void solve() {
int m = strlen(c);
int ans = 0;
for (int i = 0; i < m; i++) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int d[102];
for (int i = 1; i <= n - 1; i++) {
cin >> d[i];
}
int a, b;
cin >> a >> b;
int count = 0;
for (int i = a; i < b; i++) {
count += d[i];
}
cout << count;
}
| 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.