solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 107;
int n, m;
char s[N];
int main() {
long long ans = 0;
scanf("%d %d", &n, &m);
scanf("%s", s + 1);
m--;
ans += n * m;
long long p = 0;
for (int i = 2; i <= n; i++) {
if (s[i] != s[i - 1]) p++;
ans += p * m;
}
p = 0;
for (in... | 9 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
static const int _ = []() {
ios::sync_with_stdio(false);
cin.sync_with_stdio(false);
cout.sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
return 0;
}();
template <typename T, typename ... | 0 |
#include <bits/stdc++.h>
#define mod 1000000007
//#define mod 998244353
#define INF LLONG_MAX
#define NINF LLONG_MIN
#define ll long long int
#define pr(a) pair<a, a>
#define ps pair<int, string>
#define ff first
#define ss second
#define pub push_back
#define pob pop_back
#define f(i, a, b) for (int i = a; i <= b; i++... | 1 |
#include <bits/stdc++.h>
using namespace std;
int d[100007];
int l[100007];
int num[207];
int mark[100007];
int sum[100007];
int total[100007];
int n;
struct Node {
int d;
int l;
bool operator<(const Node& a) const { return l < a.l; }
} b[100007];
int main() {
while (~scanf("%d", &n)) {
memset(num, 0, sizeo... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
struct edge {
int from;
int to;
} a[300000 + 5];
vector<int> E[300000 + 5];
void add_edge(int u, int v) {
E[u].push_back(v);
E[v].push_back(u);
}
int ans[300000 + 5];
int mk[300000 + 5];
int cnt[300000 + 5];
void failed() {
printf("-1\n");
exit(0);
}
i... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const int64_t LINF = 4611686018427387903;
const int MOD = 1e9 + 7;
void solve(int64_t x, vector<int64_t> &arr) {
for (int64_t i = 1; i * i <= x; i++)
if (x % i == 0) arr.push_back(i), arr.push_back(x / i);
sort(ar... | 6 |
#include <bits/stdc++.h>
using namespace std;
void lose() {
cout << "cslnb";
exit(0);
}
void win() {
cout << "sjfnb";
exit(0);
}
bool solve(vector<int> &v) {
if (v.size() == 1) {
return v[0] & 1;
}
sort(v.begin(), v.end());
long long value = 0;
long long prev = -1;
long long rest = v.size() + 1;... | 5 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
int array[n];
int i, j, x;
for (i = 0; i < n; i++) scanf("%d", &array[i]);
for (i = 0; i < n; i++) {
x = array[i];
j = i - 1;
while (j >= 0 && array[j] > x) {
array[j + 1] = array[j];
j--;
}
array[j + 1] = x;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T abs(T a) {
return a < 0 ? -a : a;
}
template <typename T>
T sqr(T a) {
return a * a;
}
const int INF = (int)1e9;
const long double EPS = 1e-9;
const long double PI = 3.1415926535897932384626433832795;
const int N = 200;
inline void makeLine(const... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p = 1;
cin >> n;
for (int i = n; i - 1; i >>= 1, p <<= 1)
for (int j = 0; j < (i + 1) / 2; j++) cout << p << " ";
cout << n - n % (p >> (n != 1));
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
string line;
vector<string> mine;
int m, n;
void creat() {
int i;
getline(cin, line);
line.clear();
for (i = 1; i <= m; i++) {
line.clear();
getline(cin, line);
mine.push_back(line);
}
}
void check() {
int i, j, x, y, cnt;
for (i = 0; i < m; i++) {... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
int a[2010];
int main() {
int T = r... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
while (k--) {
if (n % 10 == 0)
n /= 10;
else
n -= 1;
}
cout << n << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) { cout << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << " ";
err(++it, args...);
}
template <typename T>
inline void read(T& x) {
x = 0;
T... | 6 |
#include <bits/stdc++.h>
using namespace std;
double l, r = 1e14, mid;
int n, p, a[100001], b[100001];
bool can(double x) {
double sum = 0, num;
for (int i = 0; i < n; i++) {
num = x * a[i] - b[i];
if (num >= 0) sum += num / p;
}
return sum <= x;
}
int main() {
cin >> n >> p;
for (int i = 0; i < n; ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
if (n == 1 || m == 1) {
cout << "YES" << endl;
} else if (n == 2 && m == 2) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int from[10];
int to[10];
double coef1 = 1.0;
double coef2 = 1.0;
bool isBetween(int k, int mmin, int mmax) { return k >= mmin && k <= mmax; }
long long dp[10][11000][2][2][2];
long long count(int pos, int k, bool ensured, bool hask, bool hasbigger) {
if (pos == n)... | 6 |
#include <bits/stdc++.h>
using namespace std;
map<pair<long long int, long long int>, long long int> u;
vector<pair<long long int, long long int> > v;
void pp(long long int n) {
map<long long int, long long int> vv;
long long int i, j;
for (i = 2; i <= sqrt(n); i++) {
if (vv[i] == 0) {
for (j = i * i; j... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
cout << 3 * (n + 1) + 1 << '\n';
cout << 0 << " " << 0 << '\n';
for (int i = 1; i <= n + 1; ++i) {
cout << i - 1 << " " << i << '\n';
cout << i << " " << i - 1 << '\n';
cout << i << " " << i << '\n';
}
}
int main() {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int exp(long long int t, long long int x) {
if (x == 0) return 1;
if (x == 1) return t;
if (x % 2 == 1) return (t * exp((t * t) % 1000000007, x / 2)) % 1000000007;
if (x % 2 == 0) return exp((t * t) % 1000000007, x / 2);
}
long long int gcd(long long int x... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
cout << min((a - b), (c + 1)) << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class A, class B>
bool smin(A &x, B &&y) {
if (y < x) {
x = y;
return true;
}
return false;
}
template <class A, class B>
bool smax(A &x, B &&y) {
if (x < y) {
x =... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e9 + 1;
int t;
void solve() {
long long n, ch = 1;
long long ans = 0;
cin >> n;
ans += n * (n + 1) / 2;
while (ch <= n) {
ans -= 2 * ch;
ch *= 2;
}
cout << ans << "\n";
}
int main() {
cin >> t;
while (t--) solve();
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, ans, k, p, l;
cin >> n >> k;
p = k;
long long int a[n + 2];
for (i = 0; i < n; i++) {
cin >> a[i];
}
k = 2 * k;
k = sqrt(k);
ans = (k * (k + 1)) / 2;
if (ans < p) {
k++;
ans = (k * (k + 1)) / 2;
}
l = ans ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long dp[(1 << 19)][20];
int lowbit[(1 << 19)];
bool G[20][20];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i < (1 << 19); ++i) {
int j;
for (j = 0;; ++j) {
if ((i & (1 << j))) {
bre... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
while (cin >> n) {
string s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
}
long long cnt1 = 0, cnt2 = 0, ans = 0;
for (int i = 0; i < n; i++) {
c... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, w_c, b_c;
int cost = 0;
cin >> n >> w_c >> b_c;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n / 2; i++) {
if ((a[i] != a[n - 1 - i]) and (a[i] != 2 and a[n - 1 - i] != 2)) {
cout << -1;
ret... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;
const int N = 1 << 21;
int ct[N];
bool mark[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
int n = s.size();
for (int i = 0; i < n; ++i) {
int mask = 0;
for (int j = i; j >= 0;... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool isLittleCircleinBigCircle(double x, double y, double r, double R,
double d) {
return sqrt(x * x + y * y) + r <= R && sqrt(x * x + y * y) >= R - d + r;
}
int main() {
int R, d, n, ans = 0;
cin >> R >> d;
cin >> n;
int x, y, r;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
map<string, string> m_ip;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
string name, ip;
cin >> name >> ip;
m_ip[ip] = name;
}
for (int j = 0; j < m; ++j) {
string nam... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> g(n);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
--u, --v;
g[u].emplace_back(v);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int opr(string s) {
int l, k, ind, i;
l = 0;
k = 0;
ind = 0;
for (i = 1; i < s.length(); i++)
if (s[i] != '-')
if (s[i] != s[ind]) {
l = -100500;
break;
} else
ind = i;
for (i = 1; i < s.length(); i++)
if (s[i] != '-')... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> ans;
long long gcd(long long x, long long y) {
while (true) {
if (x == y) return x;
if (x < y) {
long long k = (y - 1) / x;
ans.push_back(-k);
y -= k * x;
} else {
long long k = (x - 1) / y;
ans.push_back(k);
... | 8 |
#include <bits/stdc++.h>
const double PI = 3.141592653589793238460;
using namespace std;
long long pows(long long a, long long n, long long m) {
long long res = 1;
while (n) {
if (n % 2 != 0) {
res = (res * a) % m;
n--;
} else {
a = (a * a) % m;
n = n / 2;
}
}
return res % m;... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)(1e9 + 7);
const int MAXN = 1e6 + 5;
pair<long long, long long> p[MAXN << 2];
long long dp[MAXN << 2];
vector<long long> a[MAXN << 2];
long long sum[MAXN << 2];
int main() {
long long m, n, i, j, k;
vector<long long> v;
ios::sync_with_... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
struct node {
int p, t;
} a[N];
bool operator<(const node &a, const node &b) { return a.p > b.p; }
bool cmp(const node &a, const node &b) {
if (a.t != b.t)
return a.t < b.t;
else
return a.p < b.p;
}
set<int> st;
priority_queue<node> pq... | 7 |
#include <bits/stdc++.h>
const int N = 100100;
const long long mod = 1e9 + 7;
using namespace std;
long long int gcd(long long int a, long long int b) {
return b == 0 ? a : gcd(b, a % b);
}
long long int dp[2][200009];
long long int n, a, b;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie... | 6 |
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f first
#define s second
#define for1(i,a,b) for (int i = a; i < b; i++)
#define for2(i,a,b) for (int i = a; i > b; i--)
#define arrin(a,n) for (int i = 0; i < n; i++) cin >> a[i];
#define arrout(a... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[1005];
int main() {
int n;
scanf("%d", &n);
int s = 0;
int l = 0;
int r = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (s == 0 && a[i] != i) {
s++;
l = i;
} else if (s == 1 && a[i] != i && a[i] != a[i - 1] - 1) {
p... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
double l[500], r[500];
int sign(double x) {
if (fabs(x) < eps) return 0;
return (x > 0) ? 1 : -1;
}
double calc(double a, double b, double h, double f) {
if (sign(a) == 0 || sign(b) == 0 || sign(a) * sign(b) == -1) return 0;
if (sign(a) == -... | 9 |
#include <bits/stdc++.h>
long long dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
long long dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};
using namespace std;
class pa3 {
public:
long long x;
long long y, z;
pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {}
bool operator<(const pa3 &p) const {
if (... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, ii, k, jj, t1, mp[27][27], a[51][51][27], b[51][51][27],
f[51][51], aa[51][3];
char s1[101], s2[101], ch[101];
int main() {
scanf("%s", s1 + 1);
scanf("%s", s2 + 1);
n = strlen(s1 + 1);
m = strlen(s2 + 1);
scanf("%d", &t1);
for (i = 1; i <= t... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long inf64 = 1e18;
const int mod = inf + 7;
const int N = 1e5 + 10;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int a, b, x;
cin >> a >> b >> x;
if (x % 2 == 0) {
if (a > b) {
for (int i ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long cnt[1000001];
long long ans = 0;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
vector<int> nums;
for (int i = 1; i <= n; i++) {
int u;
cin >> u;
if (cnt[u] == 0) {
ans += n * n;
nums.p... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
const int MAXN = 100007;
const int MOD = 30021;
const double eps = 1e-8;
const double PI = acos(-1.0);
map<int, int> SG, num;
int getSG(int x) {
if (x == 0) return 0;
if (SG.count(x)) return SG[x];
map<int, int> vis;
int p = x;
int t = 0;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
if (k < n) {
if ((n / k) < (k - 1) || (k * (k - 1) == n)) {
cout << "YES" << endl;
long long s = 1;
for (long long i = 1; i <= n; i++) {
if (i % k != 0 && (i + s) % k != 0)
cout << i %... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int t;
cin >> t;
while (t--) {
int n;
vector<int> vi;
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
vi.push_back(x);
}
sort(vi.begin(), vi.end()... | 1 |
#include <bits/stdc++.h>
const int md = 1e9 + 7;
const long long inf = 2e18;
const int OO = 0;
const int OOO = 1;
using namespace std;
struct edge {
int u, v, i, vis;
edge() {}
edge(int uu, int vv, int ii) {
u = uu;
v = vv;
i = ii;
vis = 0;
}
int to(int source) { return source ^ u ^ v; }
};
co... | 8 |
#include <bits/stdc++.h>
const long long int MOD = 1000000007;
long long int dp[255][255];
long long int fastK[255];
long long int fac[255], ifac[255];
long long int k;
int n;
long long int fexpo(long long int base, long long int p) {
long long int ret = 1;
while (p) {
if (p % 2) {
ret = ret * base % MOD;... | 7 |
#include <bits/stdc++.h>
template <class T>
inline T max(const T &x, const T &y) {
return x > y ? x : y;
}
template <class T>
inline T min(const T &x, const T &y) {
return x < y ? x : y;
}
template <class T>
inline bool chkmax(T &x, const T &y) {
return x < y ? x = y, true : false;
}
template <class T>
inline boo... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int base = 19260817;
const long long INF = 1e18;
const int maxn = 1e6 + 10;
const double eps = 1e-8;
int add(int x, int y) {
x += y;
return x >= mod ? x - mod : x;
}
int sub(int x, int y) {
x -= y;
return x < 0 ? x + mod : x;
}
int mul... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> primes;
void Sieve(long long int n) {
vector<bool> prime(n + 1, true);
for (long long int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (long long int i = p * p; i <= n; i += p) prime[i] = false;
}
}
for (long long int p =... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long res = 0, flag = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') flag = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
res = (res << 3) + (res << 1) + (ch ^ 48);
ch = getchar();
}
return... | 3 |
#include <bits/stdc++.h>
using namespace std;
namespace ufs {
int fa[100005];
void makeset(int n) {
for (int i = 1; i <= n; i++) fa[i] = i;
}
int findset(int u) {
if (fa[u] == u) return fa[u];
return fa[u] = findset(fa[u]);
}
void unionset(int a, int b) {
int u = findset(a);
int v = findset(b);
fa[u] = v;
}... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return f * x;
}
inline char readch() {
char ch = ... | 8 |
#include <bits/stdc++.h>
template <typename T>
inline T max(T a, T b) {
return a > b ? a : b;
}
template <typename T>
inline T min(T a, T b) {
return a < b ? a : b;
}
template <typename T>
inline T abs(T a) {
return a > 0 ? a : -a;
}
template <typename T>
inline bool repr(T &a, T b) {
return a < b ? a = b, 1 : ... | 8 |
#include <bits/stdc++.h>
using namespace std;
bool debug = true;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
const int dy[] = {1, 0, -1, 0, -1, 1, 1, -1, 0};
template <typename X>
inline X square(const X& a) {
return a * a;
}
int scan_d() {
bool minus = false;
int result = 0;
char ch;
ch = getchar();
w... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, q;
cin >> n >> q;
vector<int> arr(n + 1);
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
arr.emplace_back(0);
long long up = 0;
long long... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.length();
int cnt = 1;
int ans = 0;
bool b = true;
for (int i = 1; i < n; ++i) {
if (s[i] == s[i - 1]) {
b = false;
break;
}
}
if (b) {
cout << n << endl;
return 0;
}
s += s;
n *=... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, x[200000], y[200000], l[200000];
int main() {
scanf("%d%d%d%d", &n, &m, &a, &b);
for (int i = 0; i < n; ++i) scanf("%d", &x[i]);
for (int i = 0; i < m; ++i) scanf("%d", &y[i]);
for (int i = 0; i < m; ++i) scanf("%d", &l[i]);
double Min = 1e18, nn =... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300000, M = 500000;
int xx[N], yy[N], n;
int x_, y_;
bool check(int d) {
int xl = 0, xr = M;
int yl = 0, yr = M;
int xyl = -M, xyr = M;
for (int i = 0; i < n; i++) {
int x = xx[i], y = yy[i];
xl = max(xl, x - d);
xr = min(xr, x + d);
yl... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d;
cin >> n >> d;
vector<pair<int, int>> v(n);
for (int i = 0; i < n; i++) {
int m, s;
cin >> m >> s;
v[i] = make_pair(m, s);
}
sort(v.begin(), v.end());
int l = 0;
unsigned long long res = 0;
unsigned long long sum = 0;
f... | 3 |
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
template <class T>
inline void in(T &);
template <class T>
inline void out(const T &);
using std::abs;
using std::max;
using std::min;
using std::sort;
using namespace std;
int t, n, s1, s2;
int main() {
in(t);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
map<string, set<string> > phoneBook;
cin >> n;
for (int i = 0; i < n; i++) {
string name;
int m;
string phone;
cin >> name >> m;
for (int j = 0; j < m; j++) {
cin >> phone;
phoneBook[name].insert(phone);
}
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
long long ans = 1000001;
for (long long i = 0; i < n; i++) {
cout << ans << " ";
ans++;
}
return 0;
}
| 2 |
#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;
}
template <class T>
inline void gn(T &first) {
char c, sg = 0;
while (c = getchar(), ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a, b;
void precalc() {}
bool read() {
if (scanf("%d%d", &a, &b) < 2) {
return false;
}
return true;
}
void solve() {
int even = 0, odd = 0;
if (!a && !b) {
printf("NO\n");
return;
}
for (int i = 1;; i++) {
if (i % 2 == 1)
odd++;
e... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[5], cnt = 0;
for (int i = 0; i < 4; i++) cin >> a[i];
sort(a, a + 4);
for (int i = 0; i < 3; i++) {
if (a[i] == a[i + 1]) cnt++;
}
cout << cnt << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> mp;
map<long long int, long long int> cnt;
long long int arr[120005];
long long int vis[120005];
int main() {
ios_base::sync_with_stdio(0);
long long int i, j, k, m, n, c = 0, x, y;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> ar... | 2 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
while (b > 0) {
int t = a % b;
a = b;
b = t;
}
return a;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
if (m < n - 1) {
cout << "Impossible\n";
return 0;
}
vector<pair<int, int>> ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500;
int XR[N], YR[N], XB[N], YB[N], arr[N][N];
bool ccw(int i, int j, int k) {
int x1 = XR[j] - XR[i], y1 = YR[j] - YR[i], x2 = XB[k] - XR[i],
y2 = YB[k] - YR[i];
return 1LL * x1 * y2 - 1LL * x2 * y1 > 0;
}
int main() {
int n, m;
scanf("%d %d", ... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chmax(T& a, const T& b) {
return a < b ? (a = b, true) : false;
}
template <typename T>
bool chmin(T& a, const T& b) {
return b < a ? (a = b, true) : false;
}
int N;
const int MAX_N = 100000;
int T[MAX_N];
long long L[MAX_N], R[MAX_N];
vector<... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
vector<int> ed[N], child[N], cc_ed[N];
bool bridge[N][N];
int tin[N], low[N], id[N], cc_sz[N], sub_sz[N];
void dfs_bridge(int u, int p, int& tm) {
low[u] = tin[u] = ++tm;
for (int i = 0; i < ed[u].size(); ++i) {
int v = ed[u][i];
if (v == p) ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int str[200010];
int main() {
int n, k, nn, i, t;
while (~scanf("%d%d", &n, &k)) {
nn = n * 2;
for (i = 1; i <= nn; i++) {
str[i] = i;
}
swap(str[2], str[k + 1]);
if (k > 1 && (k + 1) % 2 == 0) {
swap(str[k], str[k + 1]);
}
swap(s... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long modulo = 1e9 + 7;
long long mod1 = 998244353;
int main() {
long long i, j, k = 0, a, b, c, x1, y1, x2, y2, p, q, r;
cin >> x1 >> y1 >> x2 >> y2 >> j;
for (i = 0; i < j; i++) {
cin >> a >> b >> c;
p = a * x1 + b * y1 + c;
if (p > 0)
p = 1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int P = 998244353, INF = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long qpow(long long a, long long n) {
long long r = 1 % P;
for (a %= P; n; a = a * a % P, n >>= 1)
if (n & 1) r = r * a % P;
return r;
}
inlin... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, R, r;
cin >> n >> R >> r;
if (r > R || (n > 1 && (R - r) * sin(acos(-1) / n) < r - 1e-8))
printf("NO\n");
else
printf("YES\n");
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
while (t--) {
long long int n, m, x, y, z, k, sum = 0, c1 = 0, c2 = 0, ans = 0;
cin >> n;
if (n % 2) {
cout << "YES" << endl;
cout << 1 << " ";
x = 1;... | 2 |
#include <bits/stdc++.h>
using namespace std;
int dp[110000][3];
long long dist[110000], ht[110000];
int main() {
int n;
cin >> n;
dp[0][0] = dp[0][1] = dp[0][2] = 0;
dist[0] = -1e10;
ht[0] = 0;
dist[n + 1] = 1e10;
ht[n + 1] = 0;
for (int i = 1; i <= n; i++) cin >> dist[i] >> ht[i];
for (int i = 1; i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
map<int, int> s[N];
int n, a[N], t[N], x[N], pool[N], mx, m;
void add(int u, int x, int val) {
while (u <= n) {
s[u][x] += val;
u += (u & -u);
}
}
int cnt(int u, int x) {
int ans = 0;
while (u) {
ans += s[u][x];
u -= (u & -u... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, a[N];
int cnt[N];
long long sc[N];
long long sum;
long long divx(long long x, long long y) { return x / y + 1; }
long long ans;
int main() {
scanf("%d", &n);
for (int i = 1, B = n; i <= B; i++) scanf("%d", &a[i]), cnt[a[i]]++;
sort(a + 1,... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const double Pi = acos(-1);
bool inline equ(double a, double b) { return fabs(a - b) < EPS; }
int _R(int &x) { return scanf("%d", &x); }
int _R(long long &x) { return scanf("%" PRId64, &x); }
int _R(double &x) { return scanf("%lf", &x); }
int _R(cha... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline bool SR(int &x) { return scanf("%d", &x) == 1; }
inline bool SR(long long &x) { return scanf("%lld", &x) == 1; }
inline bool SR(double &x) { return scanf("%lf", &x); }
inline bool SR(char *s) { return scanf("%s", s); }
inline bool RI() { return 1; }
template <typenam... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<string> arr(n + 1);
for (int i = 1; i <= n; i++) {
cin >> arr[i];
arr[i] = "#" + arr[i];
}
int dp[n + 1][m + 1];
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
... | 6 |
#include <bits/stdc++.h>
int ans, n, i, r[22], b[22], j, k, dp[65555][130], sumr, sumb;
char ss[22][22];
int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a < b ? a : b; }
int main() {
scanf("%d\n", &n);
for (i = 0; i < n; i++) {
scanf("%s", ss[i]);
scanf("%d%d\n", &r[i], &b[i])... | 8 |
#include <iostream>
using namespace std;
int n, k;
string s;
int dp[(1 << 18) - 1];
int pos[200010][18], tr[200010][18];
bool check(int x) {
//cout << "X = " << x << endl;
for (int i = 0; i < (1 << k); ++i) dp[i] = n;
for (int i = n - 1; i >= 0; --i) {
for (int j = 0; j < k; ++j) {
if (s[i] == '?') {
pos[i]... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& output, vector<T>& v) {
output << "[ ";
if (int(v.size())) {
output << v[0];
}
for (int i = 1; i < int(v.size()); i++) {
output << ", " << v[i];
}
output << " ]";
return output;
}
template <typename T1... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
enum { WHITE, GREY, BLACK };
using namespace std;
long long int inf = 1e18;
template <class T>
T gcd(T a, T b) {
return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template <typename T>
T last_bit(T n) {
r... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1500;
vector<int> ans;
int n, a[N][6];
int mul(int i, int j, int k) {
int tmp = 0;
for (int x = 0; x < 5; x++)
tmp = tmp + (a[j][x] - a[i][x]) * (a[k][x] - a[i][x]);
return tmp;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
for ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, hh, mm;
int h, m, c = 0;
cin >> s;
hh = s[0];
hh += s[1];
mm = s[3];
mm += s[4];
h = stoi(hh, nullptr, 10);
m = stoi(mm, nullptr, 10);
while (hh[0] != mm[1] || hh[1] != mm[0]) {
c++;
if (m < 59)
m++;
else {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
const int N = 1000;
int n, m, dis[N][N], rem, s, b, k, h, x[N], a[N], f[N], x1[N], d[N],
last[2 * N + 2], last1[2 * N + 2], cost[2 * N + 2], q[2 * N + 2];
struct edge {
int u, v, c, last;
} e[3 ... | 7 |
#include <bits/stdc++.h>
int a[10005];
int ck[10005];
int main() {
int N, cnt, idx, max;
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
scanf("%d", &a[i]);
ck[i] = 1;
}
idx = 1;
cnt = 0;
max = 1;
while (idx <= N) {
int tmp = idx;
while (ck[tmp]) {
ck[tmp] = 0;
tmp = a[tmp];
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long ipow(long long a, long long n) {
long long k = 1;
for (long long i = 0; i < n; i++) k *= a;
return k;
}
int main() {
long long n, k;
cin >> n >> k;
long long d2 = 0, d5 = 0;
while (n % 2 == 0) {
n /= 2;
d2++;
}
while (n % 5 == 0) {
n ... | 1 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const string basicString =
"What are you doing at the end of the world? Are you busy? Will you save "
"us?";
const vector<string> queryString = {
string("What are you doing while sending \""),
string("\"? Are you busy? Will yo... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
int *arr = new int[n];
for (int i = 0; i < n; i++) cin >> arr[i];
int minDist = INT_MAX;
for (int i = 0; i < n; i++) {
if (arr[i] > 0 && k >= arr[i] && abs(m - i - 1) * 10 < minDist &&
m != i + 1) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int m, n, ans, x[1010101], y[1010101], s;
void solve(long long int a, long long int b) {
map<long long int, bool> mp;
vector<long long int> v;
long long int m1, m2;
m1 = (x[a] - x[b]);
m2 = (y[a] - y[b]);
long long int c = m1 * y[a] - m2 * x[a];
for ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int x, n, ans = INT_MAX;
struct node {
int nxt, eid;
};
vector<node> edges[maxn];
map<pair<int, int>, int> mp;
bool vis[maxn];
int dis[maxn];
queue<int> q;
void Div(int x, int id) {
int p = 1, q = 1;
for (int i = 2; i * i <= x; i++) {
if... | 9 |
#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constex... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> graph[100001];
int visited[100001] = {0}, parent[100001] = {0};
int dfs(int s, int p) {
visited[s] = 1;
int f = 1;
for (int j = 0; j < graph[s].size(); j++)
if (!visited[graph[s][j]]) {
parent[graph[s][j]] = s;
f = min(f, dfs(graph[s][j], p... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a[2000005], ps = 0;
pair<int, int> s[1000005];
int main() {
scanf("%d", &n);
int mx = 1;
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
if (a[i] > a[mx]) mx = i;
}
for (int i = 1; i <= mx; i++) a[n + i] = a[i];
s[ps] = make_pair(a[mx], 1);
l... | 8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.