solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
struct bam {
long long id, d;
bam(int __id, int _d) { id = __id, d = _d; }
bool operator<(const bam &b) const { return d > b.d; }
};
priority_queue<bam> t;
long long num[100010], h[100010], a[100010], n, m, p, k;
bool pan(long long x) {
while (t.size()) t.pop();
f... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200500;
int n, m;
struct field {
set<pair<int, int>> by_ymx[N];
pair<set<pair<int, int>>*, set<pair<int, int>>::iterator> pos[N];
const int sy, sx;
field(int _sy, int _sx) : sy(_sy), sx(_sx) {}
set<pair<int, int>>& get(int diff) {
assert(diff < n... | 10 |
#include <bits/stdc++.h>
using namespace std;
int dcmp(double a, double b) {
return ((fabs(a - b) < (1e-9)) ? 0 : (a < b) ? -1 : +1);
}
double crossP(const complex<double> &v1, const complex<double> &v2) {
return (conj(v1) * v2).imag();
}
double dotP(const complex<double> &v1, const complex<double> &v2) {
return ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
void comp(vector<long long> &x) {
vector<long long> ord = x;
sort(ord.begin(), ord.end());
auto last = unique(ord.begin(), ord.end());
ord.erase(last, ord.end());
for (auto &v : x) v = lower_bound(ord.begin(), ord.end(), v) - ord.begin();
}
in... | 19 |
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int32_t x;
scanf("%d", &x);
return x;
}
inline string get() {
char ch[1000010];
scanf("%s", ch);
return ch;
}
const int MAX_LG = 21;
const int maxn = 1e5 + 10;
const int base = 29;
const int mod = 1e9 + 7;
const int INF = 1e9 + 100;
int n, m;
s... | 15 |
#include <bits/stdc++.h>
const int MAXN = 1e6;
const int inf = 1e9 + 69;
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, m;
int nQuery, l, r, x;
cin >> n >> m;
vector<vector<int> > v, res;
vector<int> tmp = vector<int>(m + 1);
vector<int> tmp2 = tmp;
v.push... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, check = 0;
string s;
cin >> n >> s;
for (int i = 0; i < n; i++)
if (s[i] == '0') check = 1;
if (!check)
cout << 1 << " " << n - 1 << " " << 2 << " " << n << endl;
else {
for (... | 7 |
#include <bits/stdc++.h>
using namespace std;
const double PI =
3.14159265358979323846264338327950288419716939937510582097494459230;
const long long MOD = 1e6 + 3;
const long long INF = 1e14;
long long mpow(long long a, long long b) {
a = a % MOD;
long long res = 1;
while (b > 0) {
if (b & 1) res = (res *... | 0 |
#include <bits/stdc++.h>
using std::map;
using std::queue;
using std::set;
using std::string;
using std::vector;
const double kEps = 10e-8;
const int kMax = 1000;
const int kInf = 1 << 30;
int main() {
int n;
std::cin >> n;
vector<int> A(n);
for (int& a : A) {
std::cin >> a;
}
if (n == 1) {
std::cou... | 12 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
const ll MOD = 998244353;
const ll root = 62;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll binpow(ll a, ll b) {
ll r... | 19 |
#include <bits/stdc++.h>
int main() {
int Mishka, mishkaWin = 0;
int Chris, chrisWin = 0;
int numberOfPlay;
int i;
scanf("%d", &numberOfPlay);
for (i = 1; i <= numberOfPlay; i++) {
scanf("%d %d", &Mishka, &Chris);
if (Mishka > Chris) {
mishkaWin++;
}
if (Chris > Mishka) {
chrisWi... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 5;
const long long inf = 2e9;
char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc;
int ny;
inline char gc() {
return pp1 == pp2 &&
(pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2)
? EOF
: *pp1++;
}... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
vector<int> V[maxn];
set<int> S;
int LL[maxn], RR[maxn];
void gao(int n) {
int cnt = 0;
set<int>::iterator it = S.begin();
V[n].clear();
while (it != S.end()) {
V[n].push_back(*it);
if (++cnt > 4) break;
it++;
}
}
map<int, int>... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int n;
int a[maxn];
int t;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
t ^= a[i];
}
if (n % 2 == 0) {
if (t == 0) {
printf("YES\n");
n--;
printf("%d\n", n / 2 * 2 - 1);
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n;
int d[10][10][3];
int dp[10][10];
int a, b, c, dd, e;
int ee;
int p[30][2];
int mi = -1, mx = -1;
void dfs(int cnt, int u);
void solve();
int ru[10], chu[10];
int main() {
scanf("%d", &n);
int k = n * (n - 1) / 2;
for (int i = 0; i < k;... | 14 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
#pragma warning(disable : 4996)
#pragma hdrstop
template <typename T, size_t N>
struct MakeVector {};
template <typename T>
struct MakeVector<T, 1> {
template <typename R = std::vector<T>>
static R make_vector(std::size_t size, const T& value) {
... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int alph = 256;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int q;
cin >> q;
while (q--) {
string second, t;
cin >> second >> t;... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
double a[101];
double sum1, sum2;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lf", &a[i]);
sum1 += a[i];
}
sum2 = n * 100;
printf("%.12lf\n", sum1 * 1.0 / sum2 * 100);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e8 + 5;
const long long mod = 1e9 + 7;
long long n, x;
char s[N];
long long getans(long long ans) { return (ans % mod + mod) % mod; }
void solve() {
scanf("%lld%s", &x, s + 1);
long long now = 0, len = strlen(s + 1);
n = len;
while (len < x) {
++n... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T getint() {
T x = 0, p = 1;
char ch;
do {
ch = getchar();
} while (ch <= ' ');
if (ch == '-') p = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * p;
}
template <typename T1, typena... | 16 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
const long long INF = 1e18;
long long power(long long x, long long y) {
long long t = 1;
while (y > 0) {
if (y % 2)
y -= 1, t = t * x % mod;
else
y /= 2, x = x * x % mod;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7, MAXN = 1e5 + 10, MAXM = 2e5 + 10;
int head[MAXN], sz, to[MAXM], nxt[MAXM];
inline void add(int x, int y) {
nxt[++sz] = head[x], head[x] = sz, to[sz] = y;
nxt[++sz] = head[y], head[y] = sz, to[sz] = x;
}
int N;
double in[MAXN], out[MAXN], sumin, ... | 17 |
#include <bits/stdc++.h>
int main() {
long long n;
scanf("%I64d", &n);
printf("25");
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rang(
chrono::high_resolution_clock::now().time_since_epoch().count());
long long rng(long long l) {
uniform_int_distribution<long long> uid(0, l - 1);
return uid(rang);
}
long long c(long long a) {
long long i = 0;
while (!(a & 1)) {
i++;
a >... | 11 |
#include <bits/stdc++.h>
using namespace std;
using LD = long double;
using PLL = pair<long long, long long>;
using VII = vector<pair<int, int> >;
template <class T>
bool power_2(T v) {
static_assert(std::is_integral<T>::value, "type should be integral");
return v && !(v & (v - 1));
}
template <class T>
istream& op... | 25 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100, M = 1010;
int n, m;
long long int c[N], g[N], a1[M], b1[M], a2[M], b2[M];
inline long long int read() {
long long int x = 0, t = 1;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') t = -1, ch = getcha... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
int f = 1;
x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + (ch ^ 48);
ch = getchar();
}
x *= f;
}
const int N = 2e5 + 10;
c... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, st, dr, m, t;
string ans;
inline bool ask(long long st, long long dr) {
cout << st << ' ' << dr << '\n';
cout.flush();
cin >> ans;
if (ans == "Yes") return 1;
return 0;
}
int main() {
ios::sync_with_stdio(false);
srand(time(NULL));
cin >> n >... | 13 |
#include <bits/stdc++.h>
using namespace std;
bool ismagic(int n, int *a) {
int S = 0;
for (int i = 0; i < n * n; ++i) S += a[i];
if (S % n != 0) return false;
S /= n;
for (int i = 0; i < n; ++i) {
int s = 0;
for (int j = 0; j < n; ++j) s += a[i * n + j];
if (s != S) return false;
s = 0;
f... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, string> > res;
map<string, int> m;
map<string, int> m1;
int n;
string mn;
bool cmp(pair<int, string> x, pair<int, string> y) {
if (x.first == y.first) return x.second > y.second;
return x.first < y.first;
}
int main() {
cin >> mn >> n;
m["posted"] =... | 7 |
#include <bits/stdc++.h>
const int maxn = 100;
long ds[maxn];
long hs[maxn];
long solu[maxn];
long soluNum;
long min;
int n, k, m;
int main() {
using std::cin;
using std::cout;
cin >> n >> k >> m;
int i, j;
for (i = 0; i < k; i++) cin >> ds[i];
for (i = 0; i < m; i++) cin >> hs[i];
min = m + 1;
soluNum ... | 5 |
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
long long poww(long long base, long long p) {
if (p == 0) return 1;
if (p % 2 == 0) {
long long temp = poww(base, p / 2) % mod;
return (temp * temp) % mod;
} else {
long long temp = poww(base, p / 2) % mod;
return (((temp * tem... | 9 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-12;
inline bool Equal(const double& a, const double& b) {
return a + eps >= b && b + eps >= a;
}
inline bool Below(const double& a, const double& b) { return b + eps >= a; }
inline int Abs(const int& a) { return a > 0 ? a : -a; }
void Read(int& x) {
... | 25 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ia[n], m = 0;
for (int i = 0; i < n; i++) {
cin >> ia[i];
if (ia[i] % 2 == 0) m++;
}
if (m == 1) {
for (int i = 0; i < n; i++) {
if (ia[i] % 2 == 0) {
cout << i + 1;
break;
}
}
} els... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long mod = 998244353;
const int phash = 3;
const long long modhash = 1000000000000000003;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long n, x, y, m, s;
void go(long long u, long long v, long long k1, long long k2) {
s = (u - x) / k1;
if (s > m) {
x += m * k1;
y += m * k2;
printf("%I64d %I64d", x, y);
exit(0);
}
m -= s;
x = u;
y = v;
}
int main() {
cin >> m;
if (!m) {... | 13 |
#include <bits/stdc++.h>
using namespace std;
int qq, n, m, k, l, r;
string s, s1, s2, s3;
int INF = (int)1e9 + 7;
struct st {
long long mi, ma, mir, mar, mir2, mar2;
};
vector<st> v;
multimap<int, st> ma;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int ans = 0;
int t, x = 1, y = n, k1 = 0, k2, k3, ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, k, v[100010], t, i;
int main() {
cin >> n >> k;
for (i = 1; i <= n; i++) cin >> v[i];
while (t < k) {
t++;
k -= t;
}
if (k)
cout << v[k];
else
cout << v[t];
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool chk[100010];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
fill(chk + 1, chk + N + 1, 0);
string A, B;
cin >> A >> B;
A = '*' + A, B = '*' + B;
int cnt ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b, long long int mod) {
long long int ans = 1;
while (b > 0) {
if (b & 1) {
ans = (ans * a) % mod;
}
a = (a * a) % mod;
b = b / 2;
}
return ans;
}
vector<long long int> fact(100);
void pre_fact... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, same;
char c1, c2;
signed main() {
scanf("%d%d", &n, &m);
while (!isalpha(c1)) c1 = getchar();
long long ans = n * (m - 1);
for (int i = 1; i < n; ++i) {
char c = getchar();
same = (c == c2) ? same + 1 : 0;
if (c != c1) ans += n * (m - 1) - sam... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n, m, d[1000005];
long long ans;
int inline read() {
int res = 0;
char c = getchar();
for (; !isdigit(c); c = getchar())
;
for (; isdigit(c); res *= 10, res += c ^ 48, c = getchar())
;
return res;
}
int main() {
ios_base::sync_with_stdio(0);
n = re... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
for (auto& i : v) is >> i;
return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
for (auto& i : v) os << i << ' ';
return os;
}
template <typename T, typename U>
istr... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
int A[100005];
int main() {
scanf("%d", &n);
for (int i = (0); i < (n); i++) scanf("%d", &A[i]);
for (int i = (0); i < (n); i++) {
while (A[i] % 2 == 0) A[i] /= 2;
while (A[i] % 3 == 0) A[i] /= 3;
}
for (int i = (1); i < (n); i++)
if (A[i] != A[... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[1001][1001];
int b[1001][1001][4];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%d", &a[i][j]);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if ((a... | 4 |
#include <bits/stdc++.h>
using namespace std;
void debug() {
fflush(stdin);
printf("Press any key to continue");
getc(stdin);
fflush(stdin);
}
long long n, m;
long long pp(long long a, long long b) {
if (b == 0) return 1;
long long tmp = pp(a, b / 2);
tmp = (tmp * tmp) % m;
if (b % 2) tmp = (tmp * a) % ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 5;
const int S = 448;
const int K = 86;
const int N = 1e5 + 5;
template <const int &MOD>
struct _m_int {
int val;
_m_int(int64_t v = 0) {
if (v < 0) v = v % MOD + MOD;
if (v >= MOD) v %= MOD;
val = v;
}
static int mod_inv(int a, int m... | 19 |
#include <bits/stdc++.h>
int m, n, ans, h;
bool in[100];
struct ele {
int a, b, c;
} num[100050];
int cmp(struct ele c, struct ele d) { return c.a < d.a; }
int cmpc(struct ele c, struct ele d) { return c.b < d.b; }
int min(int a, int b) {
if (a < b)
return a;
else
return b;
}
int max(int a, int b) {
if ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int test = 0;
const int MAXN = 200009;
const long long MOD = 119 << 23 | 1;
class {
public:
int a[4444], b[4444];
int n, m, k;
void solve() {
int _;
cin >> _;
while (_--) {
cin >> n >> m >> k;
for (int i = 1; i <= n; ++i) cin >> a[i];
k ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int a[N], x[N], y[N], v[N], f[N], n, d;
queue<int> Q;
int main() {
scanf("%d%d", &n, &d);
for (int i = 2; i < n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) scanf("%d%d", &x[i], &y[i]);
Q.push(n);
memset(f, 0x7f, sizeof(f));
f[n] = 0... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int tt = 1;
while (tt--) {
... | 9 |
#include <bits/stdc++.h>
int main() {
int time, root, initial[100], repeat[100], store[100], i, min, st;
scanf("%d %d", &root, &time);
for (i = 0; i < root; i++) scanf("%d %d", &initial[i], &repeat[i]);
for (i = 0; i < root; i++) {
while (time > initial[i]) {
initial[i] = initial[i] + repeat[i];
}... | 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:336777216")
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ui = unsigned int;
ll const mod = 1e9 + 7... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
set<int> s;
cin >> n;
for (int i = 1; i <= n; i++) {
int f = 0;
for (int j = 1; j <= n; j++) {
cin >> x;
if (x == 1 || x == 3) f = 1;
}
if (!f) s.insert(i);
}
cout << s.size() << endl;
for (int ans : s) cout <... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, l, x, y;
char c, d;
int main() {
scanf("%c%c", &c, &d);
if (c == 'a' || c == 'h') {
if (d == '1' || d == '8')
printf("3\n");
else
printf("5\n");
} else {
if (d == '1' || d == '8')
printf("5\n");
else
printf("8... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10, Max = 50, inf = 1e8;
int dp[maxn][Max], a[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i < Max; i++) {
dp[0][i] = inf;
}
for (int i = 1; i <= n; i++) {
int x;
cin >> x... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 5;
vector<int> g[N];
int dis[N][N];
vector<pair<int, int>> in[N], out[N];
int n, m;
int ans = 0;
vector<int> moves(4, 0);
void bfs(int x) {
dis[x][x] = 0;
queue<int> q;
q.push(x);
while (!q.empty()) {
int cur = q.front();
q.pop();
int... | 12 |
#include <bits/stdc++.h>
const long long MAX_N = 2e5 + 5;
const long long MOD = 1e9 + 7;
using namespace std;
int a[MAX_N];
int n;
long long mx = 1e6;
bool seen[1000005];
long long fnd(long long x, int l) {
int r = n - 1;
if (a[0] > x) return -1;
if (a[n - 1] < x) return a[n - 1];
while (r - l > 1) {
int mi... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
vector<long long> v;
int n;
long long x, y, sum = 0;
cin >> n >> x >> y;
for (int i = 0; i < n - 1; i++) {
v.push_back(1);
}
v.push_back(y - n + 1);
for (int i = 0; i < n; i++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int nbr_of_a = 0;
string a;
int taille;
cin >> a;
taille = a.size();
for (int k = 0; k < taille; k++) {
if (a[k] == 'a') {
nbr_of_a++;
}
}
int result;
if (nbr_of_a > taille / 2) {
cout << a.size();
} else {
result = (2 ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
const int mod = 998244353;
int f[N][N], g[N][N];
int mn[N][N], ind[N];
bool bz[N][N];
int a[N];
int n, m;
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) scanf("%d", &a[i]), ind[a[i]] = i;
for (int i = 1; i <= m; i++) {
mn... | 14 |
#include <bits/stdc++.h>
using namespace std;
char str[100010];
int main() {
int n, i, j, k, l, f;
scanf("%d%d", &n, &k);
scanf("%s", &str);
f = 0;
i = 0;
l = 0;
while (f == 0) {
if (l == k) break;
if (i < n - 1 && str[i] == '4' && str[i + 1] == '7') {
if (i % 2 == 0) {
str[i + 1] = ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
vector<int> seg[4 * N];
int arr[N], n;
void build(int s, int e, int idx) {
if (s == e) {
seg[idx].push_back(arr[s]);
return;
}
build(s, (s + e) / 2, idx * 2);
build((s + e) / 2 + 1, e, idx * 2 + 1);
seg[idx] = seg[idx * 2];
for (int... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T POW(T B, T P) {
if (P == 0) return 1;
if (P & 1)
return B * POW(B, P - 1);
else
return (POW(B, P / 2)) * (POW(B, P / 2));
}
long long int Bigmod(long long int base, long long int power,
long long int mod) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, kt[100001];
vector<pair<int, int> > a[100001];
long long bfs(int u) {
long long res = 0;
for (int i = 0; i < a[u].size(); i++) {
int v = a[u][i].first;
if (kt[v] == 0) {
kt[v] = 1;
res += bfs(v) + 2 * a[u][i].second;
}
}
return res;
}
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
set<int> ans;
for (int i = 0; i < n; i++) {
if (a[i] % k)
ans.insert(a[i]);
else if (ans.count(a[i] / k) == 0)
ans.insert(a[i]);
}... | 7 |
#include <bits/stdc++.h>
using namespace std;
string query(string x, int l, int r, int k) {
string a, b;
a = x.substr(r - k, k);
b = x.substr(l - 1, r - l + 1 - k);
x.erase(r - k, k);
x.erase(l - 1, r - l + 1 - k);
x.insert(l - 1, b);
x.insert(l - 1, a);
return x;
}
int main() {
string x;
long long ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int main(int argc, char const *argv[]) {
scanf("%d %d %d", &n, &a, &b);
int ans = (a - 1 + b) % n + 1;
printf("%d\n", ans < 1 ? ans + n : ans);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double r1 = -1, p1 = -1, p2 = 6000, temp, n, a, b, r2 = -1;
cin >> n;
while (n--) {
cin >> temp;
r1 = max(r1, temp);
}
cin >> n;
while (n--) {
cin >> temp;
p1 = max(p1, temp);
}
cin >> n;
while (n--) {
cin >> temp;
p2 =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, w[10001], k;
double v, al[10001], x[100001], y[100001], t, d, g, p[10001], q[10001];
void sort1(int l, int r) {
int i, j;
double xx, yy;
i = l;
j = r;
xx = x[(i + j) / 2];
while (i <= j) {
while (x[i] < xx) i++;
while (xx < x[j]) j--;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
void ff() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void in_out_txt() {
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
}
long long fp(long x, long y) {
if (y == 0) return 1;
if (y == 1) return x;
long long... | 3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int n, m;
string c[250];
bool was[250][250];
int cnt;
vector<pair<int, int> > q;
void analyze() {
int mix = 5000, maX = -5000;
int miy = 5000, may = -5000;
for (int i = 0; i < (int)(((int)((q).size()))); ++i) {
pair<int,... | 14 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using dd = long double;
namespace {
static bool constexpr dbg = 0;
ll constexpr N = 10;
string s[N];
bool ok(ll x, ll y) {
initializer_list<pll> ds = {{1, 0}, {0, 1}, {1, 1}, {1, -1}};
for (auto const &d : ds) {
ll nx ... | 8 |
#include <bits/stdc++.h>
using namespace std;
bool possible(long long w, long long m) {
if (m == 1) return true;
if (m % w == 0)
return possible(w, m / w);
else if ((m - 1) % w == 0)
return possible(w, (m - 1) / w);
else if ((m + 1) % w == 0)
return possible(w, (m + 1) / w);
else
return false;... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long x, y, r1, x2, y2, r2;
int main() {
ios_base::sync_with_stdio(0);
cout << (fixed) << setprecision(12);
cin >> x >> y >> r1;
cin >> x2 >> y2 >> r2;
long double dis = sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));
if (dis >= abs(r1 + r2)) {
cout << ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 1000000009;
const double eps = 1e-6;
const int mod = 1000000007;
const int mx = 300005;
int f[mx], s[mx], n, w;
int play[mx];
int main() {
scanf("%d%d", &n, &w);
for (int i = 0; i < (n); ++i) scanf("%d %d", f + i, s + i);
set<pair<int, pair<int, int> > ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n;
pair<int, int> a[N];
char s[N][N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i].first, a[i].second = i;
sort(a, a + n);
for (int i = 0; i < n; ++i)
for (int j = ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
cout << (2ll << n) - 2;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
pair<int, int> a[300010];
int main() {
while (scanf("%d%d", &n, &k) != EOF) {
for (int i = 1; i <= n; ++i) scanf("%d%d", &a[i].first, &a[i].second);
sort(a + 1, a + 1 + n, [](pair<int, int> a, pair<int, int> b) {
return a.second > b.second;
});... | 8 |
#include <bits/stdc++.h>
using namespace std;
int* decimal(int res[], int base, int inputNum) {
int index = 0;
while (inputNum > 0) {
res[index++] = inputNum % base;
inputNum /= base;
}
res[index] = -1;
return res;
}
int gcd(int a, int b) {
if (a == 0) return b;
if (b == 0) return a;
if (a == b)... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<vector<char> > > ans;
int main() {
vector<string> v(7);
for (int i = 1; i <= 6; i++) cin >> v[i];
sort(v.begin(), v.end());
do {
if (v[1].size() < 3 || v[6].size() < 3 || v[2].size() < 3 ||
v[5].size() < 3 || v[4].size() < 5 || v[3].size() ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
int in[110][110], re[110][110], ou[110][110];
cin >> m >> n;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
cin >> in[i][j];
re[i][j] = 1;
ou[i][j] = 0;
}
}
for (int i = 1; i <= m; i++) {
for (i... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2018;
int arr[N], f1[N], f2[N];
int dp[N][N];
int tmp[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
f1[i] = f1[i - 1] + (arr[i] == 1);
f2[i] = f2[i - 1] + ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
using max_heap = priority_queue<T>;
const int mod = 998244353;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
struct PairH... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
double a, b, c, d;
cin >> a >> b >> c >> d;
double ans = ((a / b) / (1.0 - ((b - a) * (d - c) / (b * d))));
cout << fixed << setprecision(12) << ans << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
long long int q, n;
long long int sum, ans;
long long int gcd(long long int a, long long int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
long long int powe(long long int a, long long int b) {
long long int res = 1;
while (b > 0) {
if (b % 2 == 1... | 11 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
template <typename T>
istream& operator>>(istream& in, vector<T>& v) {
for (auto& x : v) in >> x;
return in;
}
template <typename T>
ostream& operator<<(ostream& in, vector<T>& v) {
for (auto& x : v) in << x << " ";
return in;
}
class... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<vector<int>> g(n);
for (int i = 0; i < n - 1; i++) {
int x, y;
cin >> x >> y;
--x;
--y;
g[x].push_back(y);
g[y].push_back(x);
}
vector<bool> alive(n... | 27 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
cin >> n >> a >> b;
int ans = 1;
for (int i = 1; i <= n - 1; i++) {
int k = n - i;
int f = a / i, s = b / k;
ans = max(ans, min(f, s));
}
cout << ans << endl;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> h[100001];
int n, m;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie();
int t;
cin >> t;
while (t--) {
int res = 0;
cin >> n >> m;
for (int i = 0; i < n * m; i++) {
cin >> h[i].first;
h[i].second = i;
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int n, m, connComps;
vector<int> Sadj[maxn], Madj[maxn], buildG[maxn], ansKey;
vector<pair<pair<int, int>, bool> > edgList;
int par[maxn];
map<pair<pair<int, int>, bool>, int> getNum;
int getpar(int a) { return (a == par[a] ? a : par[a] = getpar(par[a... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[3][333333], x, y, sum[4][333333], r[4][333333];
set<pair<long long, long long> > s[333333];
map<pair<long long, long long>, long long> d;
map<long long, long long> last[4];
void read(long long &x) { scanf("%lld", &x); }
int main() {
cin >> n;
for (long lo... | 22 |
#include <iostream>
#include <string>
#include <cstring>
#include <set>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <typeinfo>
#includ... | 14 |
#include <bits/stdc++.h>
using namespace std;
set<int> s[201000];
set<int> t;
vector<int> seq[201000];
int ssum[201000];
int main() {
int k;
scanf("%d", &k);
for (int i = 0; i < k; i++) {
int n;
scanf("%d", &n);
for (int j = 0; j < n; j++) {
int t;
scanf("%d", &t);
seq[i].push_back(t... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d, res = 0;
cin >> n >> d;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (int i = n - 1; i > 0; i--) {
for (int k = i - 1; k >= 0; k--) {
if (a[i] - a[k] <= d) res++;
}
}
cout << 2 * res;
return 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
string MAX(int x, int y) {
if (x > y)
return "Misha";
else if (x < y)
return "Vasya";
else
return "Tie";
}
int max(int p, int q) {
if (p > q)
return p;
else
return q;
}
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
int p = max((3 ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, p[50];
int main() {
cin >> m >> n;
for (int i = 1; i <= n; i++) {
cout << 1 << endl;
fflush(stdout);
cin >> p[i];
if (p[i] == 0) return 0;
if (p[i] == 1)
p[i] = 0;
else
p[i] = 1;
}
int low = 1, high = m, cnt = 1;
while... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
cout << n + m - 1 << "\n";
for (int i = 1; i <= m; i++) {
cout << "1"
<< " " << i << "\n";
}
for (int i = 2; i <= n; i++) {
cout << i << " "
<< "1"
<< "\n";
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[10000001];
priority_queue<int, vector<int>, greater<int> > c;
void pop() {
int m = c.top();
while (!c.empty() && m == c.top()) c.pop(), k--;
}
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];... | 4 |
#include <bits/stdc++.h>
using namespace std;
map<string, set<pair<int, string>>> mp;
string a, b;
int n, x;
int main() {
cin >> n;
while (n--) {
cin >> a;
cin >> x;
while (x--) {
cin >> b;
mp[a].insert({b.length(), b});
}
}
cout << mp.size() << endl;
for (auto p : mp) {
string... | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.