solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int n, k, a[5005];
bool in[5005];
bool backtrack(int x, int r, int m) {
if (x == n) {
if (r > k) return false;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (in[i] && in[j] && i != j && (a[i] % m) == (a[j] % m)) return false;
return ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
bool fin = false;
int n, l, cnt[26] = {}, lim = 0;
string s;
vector<pair<char, int>> a, ans, tmp;
cin >> n >> s;
l = s.length();
for (int(i) = 0; (i) < (l); ++(i)) {
a.push_back(make_pair(s.at(i), i... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long int A[5000001], bin[5000001];
vector<long long int> v;
map<int, int> myMap;
set<int> mySet;
vector<pair<long long int, long long int> > vp;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
string s;
cin >> s;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
long long ma_x = INT_MIN;
long long ma_y = INT_MIN;
while (n--) {
char c;
cin >> c;
if (c == '+') {
long long x, y;
cin >> x >> y;
long long x1 = max(x... | 7 |
#include <bits/stdc++.h>
using namespace std;
int __i__, __j__;
class _Debug {
public:
template <typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
int n, k;
int a[100000], p[100000];
int last[100000];
int dp[100001];
int num[100001];
int sum[350][100100], shift[350];
int suma... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
int kase = 0;
int n, m;
const int maxn = 1000005;
int p[maxn], cur[maxn << 1];
int main() {
long long ans, sum;
int L, R, ans2;
cin >> n;
sum = L = R = ans2 = 0;
for (int i = 1; i <= n; i++) {
scanf("%d... | 11 |
#include <bits/stdc++.h>
int a, b, m, r0, r1, c = 0, t[1000000], k = 2, jogap;
int main() {
for (int g = 0; g < 100009; g++) t[g] = 0;
scanf("%d %d %d %d", &a, &b, &m, &r0);
t[r0] = 1;
while (c != 1) {
r1 = (r0 * a + b) % m;
r0 = r1;
if (t[r1] != 0) {
jogap = k - t[r1];
c = 1;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, mod = 1e9 + 7;
const long long inf = 1e18;
int a[maxn];
map<long long, int> mp;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
}
pair<long lo... | 10 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int main() {
long long a, b, n;
cin >> a >> b >> n;
for (int(j) = (0); (j) < (10); (j)++)
if ((a * 10 + j) % b == 0) {
cout << a << j;
for (int(i) = (1); (i) < (n); (i)++) cout << 0;
return 0;
}
co... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct P {
int x, y;
bool operator<(const P &a) const {
if (y != a.y) return y > a.y;
return x < a.x;
};
};
int a, b, c, d, i, n, m, e, k, dx[10] = {1, 0, -1, 0, 1, 1, -1, -1},
dy[10] = {0, 1, 0, -1, 1, -1, 1, -1};
int o[510441];... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N], dp[N], res;
int num[N], l[N], r[N];
vector<int> pos[N];
int main() {
vector<int> ve;
int T, n, tmp;
scanf("%d", &T);
while (T--) {
vector<int> ve;
scanf("%d", &n);
res = 0;
for (int i = 1; i <= n; i++) {
dp[i] ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
char grid[3][3];
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
cin >> grid[i][j];
}
}
bool pos = true;
int i = 1, j = 1;
if (grid[i - 1][j] != grid[i + 1][j]) p... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, i, a[100005], vis[100005] = {0};
string s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
cin >> s;
for (i = 1; i <= n; i++) {
cin >> a[i];
}
i = 1;
while (!vis[i]) {
vis[i] = 1;
if (s[i - 1] == '>') {
i =... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m = 0;
string s;
cin >> n >> s;
for (int i = 1; i < n - 1; i++) {
if (s[i] == s[i - 1]) {
if (s[i - 1] == s[i + 1]) {
if (s[i] == 'R')
s[i] = 'G';
else
s[i] = 'R';
} else {
if (s[i - 1] ... | 6 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long rand(long long x, long long y) {
return (rng() % (y + 1 - x)) + x;
}
string to_string(char c) {
string second(1, c);
return second;
}
template <typename T>
inline T gcd(T a, T b) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)(1e3 + 1e1);
const double PI = acos(-1.0);
int n, ans;
string s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
map<string, int> v;
for (int i = 1; i <= n; i++) {
cin >> s, v[s]++;
ans = max(ans, v[s]);
}
cou... | 4 |
#include <bits/stdc++.h>
int main() {
int n, m, q;
while (scanf("%d", &n) != EOF) {
q = n % 10;
m = n % 10;
if (m >= 5)
m = 10;
else
m = 0;
n = n - q + m;
printf("%d\n", n);
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
long long qpow(long long a, long long b) {
long long res = 1;
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
struct graph {
int head[maxn], nxt[maxn << 1], to[maxn <<... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int n, d, mx[100005], a[100005], pre[100005], ans, cur, f;
int main() {
cin >> n >> d;
for (int i = 0; i < n; i++) cin >> a[i];
pre[0] = a[0];
for (int i = 1; i < n; i++) pre[i] = pre[i - 1] + a[i];
mx[n - 1] = pre[n - 1];
for (int i = n - 2... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
scanf("%d%d", &n, &k);
if (n == 1) {
if (k == 0)
printf("1");
else
printf("-1");
return 0;
}
int a = k - n / 2 + 1;
if (a <= 0)
printf("-1");
else {
printf("%d %d ", a, 2 * a);
int j = 1;
for (int i ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
int n, ans;
int a[100100];
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
}
sort(a, a + n);
ans = 1;
for (int i = n - 1; i >= 0; i--) {
if (a[i] <= i + 1) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
char logs[100100];
int lgr[100100];
int main() {
int n, m, i, j, k;
char c;
set<int> login, possibles, ans, seenlogin;
while (cin >> n >> m) {
login.clear();
possibles.clear();
ans.clear();
seenlogin.clear();
for (i = 1; i <= n; i++) ans.insert(i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
if (n <= 30) {
printf("NO\n");
} else {
printf("YES\n");
int k = 6 + 10 + 14;
if (n - k == 6) {
printf("6 10 15 %d\n", n - k - 1);
} else i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int get_bit(int val, int id) { return (val >> id) & 1; }
int D[2000000];
vector<int> arr;
int L[2000000][25];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
int MaxState = (1 << 20) - 1;
for (int state = 0; state <=... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a, b, sum, sum1, sumlast1, sumlast2, c = 1;
int main() {
cin >> a >> b;
sumlast1 = a + b;
while (a > 0) {
if (a % 10 != 0) {
sum += a % 10 * c;
c *= 10;
}
a /= 10;
}
c = 1;
while (b > 0) {
if (b % 10 != 0) {
sum1 += b % 10 *... | 2 |
#include <bits/stdc++.h>
using namespace std;
int t;
int n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
cin >> n;
cout << "1 " << n - 1 << "\n";
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long calc(long long a) {
if (a < 10LL) return a;
if (a == 10LL) return 9;
long long t = 1;
long long ret = 0;
while (t < a) {
if (t == 10)
ret += t / 10 * 9;
else
ret += t / 100 * 9;
t *= 10;
}
t /= 10;
for (int i = 1; i <= 9; i+... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
template <class T>
T read(T &x) {
int f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
for (x = 0; isdigit(ch); ch = getchar()) x = 10 * x + ch - '0';
return x *= f;
}
template <class ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, h, m;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> h >> m;
cout << 60 * (23 - h) + (60 - m) << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
struct Node {
int is, id, x;
Node() {}
Node(int is, int id, int x) : is(is), id(id), x(x) {}
bool operator<(const Node &a) const {
if (x != a.x)
return x < a.x;
else
return is < a.is;
}
};
int a[maxn * 4], s[maxn], p[... | 17 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void solve() {
long long int n;
cin >> n;
long long int a[n], sum = 0;
for (int(i) = (0); (i) < (n); ++(i)) cin >> a[i];
sort(a, a + n, greater<int>());
sum += a[0] * n;
long long int t = n;
for (int(i) = (1); (i) < (n); ++(i)) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
double k;
cin >> n >> k;
vector<double> v(n);
for (int i = 0; i < n; ++i) cin >> v[i];
sort(v.begin(), v.end());
double a = v[0], b = v.back(), mid = (a + b) / 2;
while (fabs(b - a) >= 1e-8) {
mid = (a + b) / 2;
double sa = 0, sb ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
int flag = 0;
scanf("%d%d", &n, &m);
if (m % n != 0) {
printf("%d", -1);
return 0;
} else {
int k = m / n;
while (k % 2 == 0) {
flag += 1;
k = k / 2;
}
while (k % 3 == 0) {
flag += 1;
k = k / 3... | 2 |
#include <bits/stdc++.h>
using namespace std;
char p[200005], t[200005];
int s[200000];
int main() {
int n, m;
scanf("%s%s", p, t);
n = strlen(p);
m = strlen(t);
for (int i = 0; i < n; i++) {
scanf("%d", s + i);
s[i]--;
}
int l = 0, r = n, a = 0;
while (r >= l) {
int c = (l + r) / 2, j = 0;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int l[10], r[10];
double ans;
int n;
void dfs(int i, int cnt, int eq, int v, double p) {
if (i == n) {
if (cnt <= 1 && cnt + eq >= 2) ans += p * v;
return;
}
if (l[i] < v)
dfs(i + 1, cnt, eq, v,
p * min(1.0, (double)(v - l[i]) / (r[i] - l[i] + 1)))... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1);
double dgtord(double x) { return (x / 180) * PI; }
int n, m, k, x[1003], y[1003];
struct circle {
complex<int> c;
double r;
};
int a, b;
int ans;
circle cr[1003];
int mask[1003][55];
bool ok(int i, int j) {
long lon... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
long long a[maxn];
struct p {
long long tim;
long long cost;
} b[maxn];
bool cmp(p a, p b) { return a.cost < b.cost; }
int main() {
long long s, d, t;
int n;
cin >> s >> d >> t >> n;
int i, j, sum = 0;
long long pre = 0;
for (i = 0;... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int n, m, ans = 0, cnt, cnt2;
bool ok;
pair<char, pair<int, int> > e[MAXN];
vector<pair<int, char> > adj[MAXN];
vector<int> tmp1, tmp2;
int mark[MAXN][2];
void solve(char cur, int u) {
bool b = (cur == 'R');
if (mark[u][b] == 1)
cnt++, tmp... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int z;
string s;
cin >> z;
for (int i = 0; i < z; i++) {
int y, j[126] = {0};
cin >> s;
y = 0;
while (y < s.length()) {
if (s[y] == s[y + 1]) {
s[y] = ' ';
s[y + 1] = ' ';
}
y++;
}
for (y = 0; y ... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline void getint(int &x);
const int MAXN = 1000111;
int n, m, G, a[MAXN], x[MAXN], y[MAXN], z[MAXN], t[MAXN];
map<int, int> mp_cc;
inline int rrandd() { return (rand() << 15 ^ rand()) & (~0u >> 1); }
inline int gcd(const int &a, const int &b) { return b ? gcd(b, a % b) : ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
struct segTree {
int n;
vector<long long> c;
vector<int> s;
segTree(int _n) : n(_n), c(4 * _n + 3, 1), s(4 * _n + 3) {}
void push(int x, long long v, int nl, int nr, int node) {
s[node]++;
c[node] = c[node] * v % MOD;
if ... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, arr[] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2};
cin >> m;
cout << arr[m % 10] * arr[m / 10] << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T in() {
char ch;
T n = 0;
bool ng = false;
while (1) {
ch = getchar();
if (ch == '-') {
ng = true;
ch = getchar();
break;
}
if (ch >= '0' && ch <= '9') break;
}
while (1) {
n = n * 10 + (ch - '0');
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1510 * 1510;
int n;
int d[maxn];
struct node {
int l, r;
} te;
vector<node> ans[maxn];
map<int, int> mp;
int tot = 0;
int main() {
cin >> n;
int x, val;
int pos = 0, size = 0;
for (int i = 1; i <= n; i++) {
cin >> x;
d[i] = d[i - 1] + x;
... | 11 |
#include <bits/stdc++.h>
const int MAX = 262144;
int arr[262144];
int hold;
typedef struct Tree {
int maxv;
} Tree;
Tree T[262144];
int max2(int a, int b) {
if (a > b)
return a;
else
return b;
}
int max3(int a, int b, int c) {
int temp = max2(a, b);
int temp1 = max2(temp, c);
return temp1;
}
int bui... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, ans;
string s;
long long cnt[100];
int main() {
cin >> n >> k;
cin >> s;
for (i = 0; i < s.size(); i++) {
cnt[s[i]]++;
int c = 0;
for (j = 65; j <= (65 + 26); j++) {
if (cnt[j] > 0) {
c++;
}
}
if (c == k) {... | 0 |
#include <bits/stdc++.h>
int a[100000];
int b[100000];
bool no[100001];
bool exist[100001];
bool on[100001];
int main() {
char t;
int i, j = -1, n, m, cnt = 0;
scanf("%d %d\n", &n, &m);
for (i = 0; i < m; i++) {
scanf("%c %d\n", &t, &b[i]);
if (t == '+')
a[i] = 1;
else
a[i] = -1;
}
f... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, x, y;
long long val[200005], mx[200005], cnt[200005], t[200005], ans = -1e18;
vector<int> v[200005];
bool cmp(long long x, long long y) { return x > y; }
void dfs(int node, int par) {
cnt[node] += val[node];
for (int i = 0; i < v[node].size(); i++) {
if (v[no... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
for (T& x : v) is >> x;
return is;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
if (!v.empty()) {
os << v.front();
for (int i = 1; i < v.size(); ++i) os << ' ' <... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 10000;
struct T {
int n;
vector<int> adj[MAXN];
bool alive[MAXN];
int nalive;
int deg[MAXN];
int afst[MAXN], alst[MAXN], anxt[MAXN], aprv[MAXN];
int bfst, blst, bnx... | 24 |
#include <bits/stdc++.h>
using namespace std;
int n, k, ans1, ans2, cnt1, cnt2, res;
string pass, s[110];
int main() {
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> s[i];
}
cin >> pass;
res = pass.size();
for (int i = 1; i <= n; ++i) {
if (s[i].size() < res) cnt1++;
if (s[i].size() <= res... | 3 |
#include <bits/stdc++.h>
int main() {
int a, b, c, d;
scanf("%d%d%d%d%", &a, &b, &c, &d);
int i;
if ((a > b)) {
printf("First\n");
} else if (a <= b)
printf("Second\n");
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int min(int x, int y, int z) { return min(x, min(y, z)); }
signed main(void) {
int n, r = 0, fa, fb;
cin >> n;
map<pair<int, int>, pair<int, int> > l;
for (int i = 1; i <= n; ++i) {
int x, y, z;
cin >> x >> y >> z;
if (x < y) swap(x, y);
if (y < z) s... | 8 |
#include <bits/stdc++.h>
using namespace std;
fstream fin("a.in", ios::in);
long long l, r, k, i, a = 1, p = 1, ok = -1;
int main() {
cin >> l >> r >> k;
if (l == 1) {
ok = 1;
cout << "1 ";
}
for (i = k; (i % k) == 0; i *= k) {
if (l <= i && i <= r) {
ok = 1;
cout << i << "\n";
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
long long a[MAXN];
vector<int> dic[210];
bool mp[210][210];
int d[210][210];
int g[210][210];
int visited[210];
bool ex[210];
int N, M;
bool able;
int ans;
void DFS(int now, int floor) {
int i... | 11 |
#include <bits/stdc++.h>
using namespace std;
char s[100005];
int main() {
long long even, odd;
scanf("%s", s);
long long sum_even[5] = {0};
long long sum_odd[5] = {0};
even = odd = 0;
int len = strlen(s);
for (int i = 0; i < len; i++) {
odd++;
int t = s[i] - 'a';
if (i % 2 == 0) {
odd +... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200 + 13;
const int maxtrie = 200 + 12;
const int maxcharset = 26;
const char charst = 'a';
char buf[maxn];
int n, A[222];
long long moves[maxtrie][maxtrie];
long long l, dp[maxtrie][maxtrie];
struct Trie {
int next[maxtrie][maxcharset], fail[maxtrie], en... | 17 |
#include <bits/stdc++.h>
using namespace std;
vector<int> top;
vector<vector<int>> g;
vector<int> used;
vector<int> d;
vector<int> p;
void dfs(int v) {
used[v] = 1;
for (auto to : g[v]) {
if (!used[to]) {
d[to] = d[v] + 1;
p[to] = v;
dfs(to);
}
}
}
int main() {
ios::sync_with_stdio(0);... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
double dp[maxn];
int n, tot, siz[maxn], head[maxn], fa[maxn];
struct Edge {
int to, nxt;
} edge[maxn << 1];
void add_edge(int u, int v) {
edge[++tot].nxt = head[u], head[u] = tot, edge[tot].to = v;
}
void dfs(int u) {
siz[u] = 1;
for (int ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long mk = 200005;
const long long logn = 29;
const long long mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
int tc;
vector<int> g[mk];
int a[mk];
void init() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int v1 = 0, v2 = 0, v3 = 0, v4 = 0;
string s, t;
int query(int a, int b, int c, int d) {
if (a + b + c + d != n / 2) {
return 0;
}
if (a < 0 || b < 0 || c < 0 || d < 0) {
return 0;
}
if (a > v1 || b > v2 || c > v3 || d > v4) {
return 0;
}
if... | 10 |
#include <bits/stdc++.h>
int N, o[100000];
int main() {
scanf("%d", &N);
int a, b, c;
printf("? 1 2\n");
fflush(stdout);
scanf("%d", &a);
printf("? 1 3\n");
fflush(stdout);
scanf("%d", &b);
printf("? 2 3\n");
fflush(stdout);
scanf("%d", &c);
int n = (a + b - c) / 2;
o[0] = n;
o[1] = a - n;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
double count = 0;
double n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
count += a;
}
double res = count;
count /= n;
count = round(count);
if (count ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 70;
const int INF = 1e9;
int a[N][N];
int dp[N][N][N][N];
int main() {
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < int(n); ++i)
for (int j = 0; j < int(m); ++j) {
cin >> a[i][j];
}
for (int i = 0; i < int(N); ++i)
for (int j ... | 13 |
#include <bits/stdc++.h>
const int md = 1e9 + 7;
const long long inf = 1e18;
const int OO = 0;
const int OOO = 1;
using namespace std;
int ask(int a, int b, int c, int d) {
if (a + b > c + d) {
swap(a, c);
swap(b, d);
}
cout << "? " << a + 1 << " " << b + 1 << " " << c + 1 << " " << d + 1 << endl;
fflus... | 16 |
#include <bits/stdc++.h>
using namespace std;
bool contains7(int a) {
if (a % 10 == 7) return true;
a -= (a % 10);
a /= 10;
if (a == 7) return true;
return false;
}
int main() {
int a, b, c;
cin >> a >> b >> c;
int ans = 0;
while (true) {
if (contains7(b) || contains7(c)) {
break;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e6 + 10;
int n, m;
int a[100][100];
void read() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
}
}
int solve() {
int flag = 1;
for (... | 7 |
#include <bits/stdc++.h>
#define forr(i,a,b) for(int i=(a);i<(b);i++)
#define forn(i,n) forr(i,0,n)
#define dforn(i,n) for(int i=n-1;i>=0;i--)
#define forall(it,v) for(auto it=v.begin();it!=v.end();it++)
#define sz(c) ((int)c.size())
#define rsz resize
#define pb push_back
#define mp make_pair
#define lb lower_bound
#d... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
const int MOD = 998244353;
int s, n;
int main() {
cin >> n;
cout << n << endl;
for (int i = 1; i <= n; i++) cout << 1 << " ";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
int n;
cin >> n;
vector<int> nums(n);
int ones = 0;
for (int i = 0; i < n; i++) {
cin >> nums[i];
if (nums[i] == 1) ones++;
}
if (ones) {
cout << n - ones << "\n... | 7 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
using namespace std;
mt19937_64 gen(time(NULL));
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long a[16][10000];
long long dp[16][16][1LL << 17 - 1];
long long x[16][16];
long long y[16][16];
signed main() {
ios_bas... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long maxN = 5010;
const long long INF = 1000000000000000;
long long N, S, E;
long long x[maxN], a[maxN], b[maxN], c[maxN], d[maxN], nxt[maxN];
void input() {
cin >> N >> S >> E;
for (long long i = 1; i <= N; i++) cin >> x[i];
for (long long i = 1; i <= N; i... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long power(long long a, long long b) {
long long ans = 1;
while (b > 0) {
if (b & 1) ans *= a;
a = a * a;
b >>= 1;
}
return ans;
}
long long powm(long long a, long long b) {
a %= MOD;
long long ans = 1;
while (b > 0) {... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rd(T &x) {
x = 0;
char c = getchar();
int f = 1;
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) x = x * 10 - '0' + c, c = getchar();
x *= f;
}
void cmin(int &x, int y) {
if (y < x) x = y... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int l, r, y;
cin >> l >> r;
y = 2 * l;
if (y >= l && y <= r)
cout << l << " " << y << endl;
else
cout << "-1 -1\n";
}
}
| 0 |
#include <bits/stdc++.h>
int main() {
int i, j, x, y, flag = 0;
scanf("%d %d", &x, &y);
for (i = 0; i < x; i++) {
for (j = 0; j < y; j++) {
if (i % 2 == 0)
printf("#");
else {
if (flag == 0 && j == y - 1) {
printf("#");
} else if (flag == 1 && j == 0) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
int n, m;
bool valid(int i, int j) { return i >= 0 && j >= 0 && i < n && j < m; }
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
cin >> n >> m;
string board[n];
bool visit[n][m][5][5];
for (int i... | 8 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<long long> a, b;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, x, y;
long long ans = 0;
cin >> n;
a.push(0);
b.push(0);
for (int i = 0; i < n; ++i) {
cin >> x;
a.push(x);
}
for (int i = 0; i < n; ++i) ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int A[100];
int g = 0;
int n;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int noSolution() {
printf("0\n");
for (int i = (0); i < (n); i++) {
for (int j = (0); j < (A[i] * g); j++) {
printf("%c", i + ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(12);
int n;
cin >> n;
vector<int> t(n);
for (int i = 0; i < n; ++i) {
cin >> t[i];
}
vector<int> dp(1440, -1);
dp[0] = 20;
dp[89] = 50;
dp[1439] = 120;
for... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, i, res = 0;
cin >> n;
for (i = 1; i < n; i <<= 1) res += i * ((n - i - 1) / (2 * i)... | 11 |
#include <bits/stdc++.h>
using namespace std;
string num_to_string(int num) {
stringstream ss;
ss << num;
return ss.str();
}
long long x, y, ans, arr[5];
void O_o() {
ios::sync_with_stdio(0);
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
}
int main() {
O_o();
int n, m;
char c;
cin >> n >> c... | 2 |
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int>pii;
const int mod = 1e9+7;
const int inf = 1e9+100;
const int N = 3e5+5;
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n,k;
cin>>n>>k;
string cur = "aa";
for(int i=2; i<=k; i++){
... | 8 |
#include <bits/stdc++.h>
using namespace std;
map<int, pair<int, int> > mp;
int main() {
int N, a, b;
scanf("%d", &N);
for (int i = 0; i < N; ++i) {
scanf("%d%d", &a, &b);
++mp[a].first;
if (a != b) {
++mp[b].second;
}
}
int ans = ~0U >> 1;
for (map<int, pair<int, int> >::iterator it =... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 111;
vector<int> atk;
vector<int> def;
vector<int> str;
vector<int>::iterator it;
bool v[maxn];
int n, m;
int ans1, ans2;
int main() {
while (cin >> n >> m) {
ans1 = ans2 = 0;
memset(v, 0, sizeof(v));
atk.clear();
def.clear();
str.clea... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i;
cin >> n >> m;
n = min(n, m);
if (n % 2 == 0)
cout << "Malvika" << endl;
else
cout << "Akshat" << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long dx[2] = {1, 0};
const long long dy[2] = {0, 1};
const long long MAX = 1e6 + 5;
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long n, m, A, B, x, y, k, Q, ans;
string second;
long long a[M... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
long t, flag = 0;
cin >> t;
while (t--) {
long n;
cin >> n;
if (n >= 0) {
if (n % 2 != 0) {
if (flag == 1) {
cout << n / 2 + 1 << "\n";
flag = 0;
} else {
cout << n... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
string toString(T x) {
if (x == 0) return "0";
bool negative = x < 0;
string res;
while (x) {
res.push_back('0' + x % 10);
x /= 10;
}
if (negative) res.push_back('-');
reverse(res.begin(), res.end());
return res;
}
template <typ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1000000;
int dp[N];
int up[N];
int mult(int a, int b) { return (long long)a * (long long)b % mod; }
int sum(int a, int b) {
a += b;
if (a >= mod) a -= mod;
return a;
}
void add(int& a, int b) {
a += b;
if (a >= mod) a -= mod;... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t;
cin >> n >> t;
int a[n];
if (t == 10) {
if (n == 1)
cout << -1;
else
for (int i = 0; i < n; ++i) {
if (i == n - 1) {
cout << 0;
break;
}
cout << 1;
}
} else {
for (int... | 2 |
#include <bits/stdc++.h>
using namespace std;
int t, n, a[105], b[105];
vector<int> d;
bitset<1000005> visited;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
d.clear();
visited.reset();
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
char str[maxn];
int num[maxn], ope[maxn];
int main() {
scanf("%s", str);
int cnt = 0;
for (int i = 0; str[i]; i++) {
if (isdigit(str[i])) {
num[cnt] = num[cnt] * 10 + str[i] - '0';
} else {
cnt++;
ope[cnt] = (str[i]... | 12 |
#include <bits/stdc++.h>
using namespace std;
int c[4];
int n;
char s[200000];
int main() {
scanf("%d", &n);
scanf("%s", s);
memset(c, 0, sizeof c);
int LEN = strlen(s);
for (int i = 0; i < LEN; i++)
if (s[i] == 'A')
c[0]++;
else if (s[i] == 'G')
c[1]++;
else if (s[i] == 'C')
c[2... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool rev(long long x, long long y) { return x > y; }
void input_arr(long long a[], long long n) {
for (long long i = 0; i < n; i += 1) cin >> a[i];
}
void print_vec(vector<long long> &v) {
for (auto i : v) cout << i << " ";
cout << endl;
}
void print_arr(long long a[]... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2000005;
int zz[N << 1], ne[N << 1], fi[N], dfn[N], low[N], st[N], tot, cnt, ccol,
col[N], vis[N], n, x, y, ccnt, M, p, m, l, r;
inline int yes(int x) { return x * 2; }
inline int no(int x) { return x * 2 + 1; }
inline void jb(int x, int y) {
zz[++tot] =... | 19 |
#include <bits/stdc++.h>
using namespace std;
int dfs(vector<int> g[], int u, bool visit[], int& res) {
visit[u] = true;
int currComponentNode = 0;
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i];
if (!visit[v]) {
int subtreeNodeCount = dfs(g, v, visit, res);
if (subtreeNodeCount % 2 =... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
string toBin(long long a) {
string res = "";
while (a) {
res += char((a & 1) + '0');
a >>= 1;
}
reverse(res.begin(), res.end());
return res;
}
const int mod = 1e9 +... | 10 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
double s3(double a) {
double l = a * sqrt(3.0) / 2;
double r = sqrt(3.0) / 6 * a;
double s = a / 2 * r * 3;
double h = sqrt(l * l - r * r);
return h * s / 3;
}
double s4(double a) {
double l = a * sqrt(3.0) / 2;
doub... | 9 |
#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n;
cin >> n;
vector<pair<long long, long long> > p(n);
for (long long i = 0; i < n... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.