solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int INFTY = 0x3f3f3f3f;
const int MAXN = 10010;
int n;
int a[MAXN];
int b[MAXN];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
int ans = 0, p = 0;
for (int i = 0; i < n - ... | 1 |
#include <bits/stdc++.h>
using namespace std;
seed_seq seq{
(uint64_t)chrono::duration_cast<chrono::nanoseconds>(
chrono::high_resolution_clock::now().time_since_epoch())
.count(),
};
mt19937 rng(seq);
long long n, first, second;
long long dp[500005], s[500005], mn = 1000000000000000005;
vector<int>... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(false);
long long n, m, k;
cin >> n >> m >> k;
vector<long long> arr(n - 1);
long long prev = 0;
long long curr = 0;
cin >> prev;
for (int i = 0; i < n - 1; i++) {
cin >> curr;
arr[i] = curr - (prev + 1);
p... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int ESP = 1e18;
long long int FCB = 1e9 + 7;
long long int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const long long int N = 5005;
long long int l[N], r[N];
vector<pair<long long int, long long int>> vv;
bool fly(long long int x, long long int y) {
if (l[x]... | 3 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
vector<long long> pos;
for (long long i = 0; i < n; i++) {
if (a[i]) {
pos.push_back(i);
}
}
if (pos.size() == 0)
cout << 0;
else {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<unsigned long long, unsigned long long> a,
pair<unsigned long long, unsigned long long> b) {
unsigned long long s1, s2, h1, h2;
tie(s1, h1) = a;
tie(s2, h2) = b;
if (s1 * h2 > s2 * h1) return true;
return false;
}
int main() {
ios_base::... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T min(T &a, T &b) {
return a < b ? a : b;
}
template <class T>
inline T max(T &a, T &b) {
return a > b ? a : b;
}
template <class T>
void read(T &x) {
char ch;
while ((ch = getchar()) && !isdigit(ch))
;
x = ch - '0';
while ((ch = ge... | 3 |
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typede... | 0 |
#include "bits/stdc++.h"
using namespace std;
int main() {
long long N, A, B;
cin >> N >> A >> B;
if ((A + B) % 2 == 0) {
cout << (B - A) / 2 << endl;
}
else {
cout << min(A - 1, N - B) + 1 + (B - A - 1) / 2 << endl;
}
}
| 0 |
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { re... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double eps = 1e-10;
const int MAXN = 200009;
int n;
double T;
struct Lu {
double x, y;
bool operator<(const Lu &p) const { return y < p.y; }
} L[MAXN];
int cmp(dou... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
map<int, int> m;
for (int i = 0; i < n; ++i) cin >> a[i], m[a[i]] = i + 1;
int c = 0;
for (auto it : m) {
a[it.second - 1] = ++c;
}
vector<int> dp(... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int inf = 1e18;
long long int expo(long long int x, long long int y) {
long long int ans = 1;
while (y != 0) {
if (y % 2) {
ans = ans * x;
}
y = y >> 1;
x = x * x;
}
return ans;
}
long long int gcd(long long int a, long long int b) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int n, ans; string A, B, S;
int main()
{
cin>>S; for(int i = 0; i < S.size(); ++i) A += S[i], A != B?(B = A, A = "", ++ans):0;
printf("%d\n", ans);
return 0;
} | 0 |
#include <bits/stdc++.h>
#define fastio() ios_base::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn = 55;
const ll mod = 1e9+7;
int n;
ll K;
vector<vector<ll>> multiply(vector<vector<ll>>& a, vector<vector<ll>>&b){
vector<vector<ll>> c(n, vector<ll>(n, 0));
... | 0 |
#include <bits/stdc++.h>
const int N = 1000000;
int id[N + 10];
int main() {
int n = 0;
long long k = 0;
scanf("%d", &n);
std::cin >> k;
for (int i = 1; i <= n; i++) scanf("%d", id + i);
for (int i = 1; i <= n; i++) {
if (k <= 1LL * i) {
printf("%d\n", id[k]);
break;
}
k -= i;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool compare(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
int main() {
int maxz, tempbuff, tempbuff2;
cin >> maxz;
vector<pair<int, int>> z;
for (int i = 0; i < maxz; i++) {
cin >> tempbuff >> tempbuff2;
z.push_back(make_pair(tempbuff,... | 1 |
#include <bits/stdc++.h>
using namespace std;
int b, s = 0, v[100], j = 0;
string a;
int main() {
cin >> b >> a;
for (int i = 0; i < b; i++) {
if (a[i] == 'B') {
s++;
v[j] = s;
if (i == b - 1) {
j++;
}
} else if (s != 0) {
s = 0;
j++;
}
}
cout << j << endl... | 1 |
#include <iostream>
#include <cstring>
using namespace std;
long long n,k;
char s[105];
long long p[105],cnt=1;
long long ans=0;
int main()
{
cin>>s;
cin>>k;
n=strlen(s);
p[1]=1;
for(int i=1;i<n;i++)
{
if(s[i]==s[i-1])
p[cnt]++;
else
p[++cnt]++;
}
if(s[0]!=s[n-1])
{
for(int i=1;i<=cnt;i++)
an... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, c;
cin >> n >> c;
long long p[n], s[n];
for (int i = 0; i < n; i++) cin >> p[i];
for (int i = 0; i < n; i++) cin >> s[i];
long long dp[2][n + 2];
memset(dp, 0, sizeof(dp));
int me = 0, other = 1;
for (int i = 0; i < n; i++) {
... | 5 |
#include <bits/stdc++.h>
int n, a[100001], b[100001], Q, u, v, k, i, tmp, j;
double dp[100001][102], now;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
b[i] = a[i];
dp[i][a[i]] = 1;
now += dp[i][0];
}
scanf("%d", &Q);
while (Q--) {
scanf("%d%d%d", &u, &v, &k)... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 101010;
string s, srev;
int m;
string word;
int Z1[Maxn], Z2[Maxn];
int res;
void Z(const string &s, int Z[], int delta) {
int l = 0, r = 0;
Z[0] = 0;
for (int i = 1; i < s.length(); i++) {
Z[i] = 0;
if (i <= r) Z[i] = min(Z[i - l], r - i);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int p, q, l, r, i, j, count = 0, k, flag = 0;
scanf("%d%d%d%d", &p, &q, &l, &r);
std::pair<int, int> x[p];
std::pair<int, int> y[q];
for (i = 0; i < p; i++) scanf("%d%d", &x[i].first, &x[i].second);
for (i = 0; i < q; i++) scanf("%d%d", &y[i].first,... | 2 |
#include <bits/stdc++.h>
using namespace std;
int N_;
long long A[210][210];
long long B[210][210];
long long work[210][210];
const long long LIM = LLONG_MAX - (1000000007LL - 1) * (1000000007LL - 1);
void matmul(long long a[][210], long long b[][210]) {
for (int i = 0; i < (N_); i++)
for (int j = 0; j < (N_); j+... | 5 |
#include <bits/stdc++.h>
using namespace std;
void re(long long &x) {
x = 0;
char ch = getchar();
int b = 0;
while (ch < '0' || ch > '9') {
if (ch == '-') b = 1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
if (b == 1) x *= -1;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = 3.141592653589793238462;
const int dr[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dc[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int asked[50005];
void endIt(int ans) {
printf("... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double COMPARISION_THRESHOLD = 1e-8;
const std::streamsize PRECISION = 10;
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vector) {
for (size_t i = 0; i < vector.size(); ++i) {
os << vector[i] << " ";
}
return os;
}
st... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<long long> v;
map<string, int> n;
long long d = 0, e = 0, i, f = 0, g = 0, j, k = 1, l = 0, r = 1, z, m, h,
p[101];
string y, t;
double a, b, c, q, u, s, x = 10000000;
cin >> a >> b >> c;
for (i = 1; i <= a; i++) {
cin >> p[... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
long long n, l, i, x, y;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
cout << (n - 1) * 3 + 7 << '\n';
cout << "0 0\n";
cout << "0 1\n";
cout << "1 0\n";
cout << "1 1\n";
x = 2;
y = 2;
for (i = 1... | 3 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int n,m;
vector<int> y;
vector<int> x;
void solve() {
map<int,int> line;
int add = 0;
y.push_back(0);
x.push_back(0);
rep(i,n) {
int a; cin>>a;
add += a;
y.push_back(add);
}
add = 0... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
const int RIBBON_SIZE = 100001;
int a[RIBBON_SIZE];
bool is_visited[RIBBON_SIZE] = {false};
char c;
for (int i = 1; i <= n; i++) {
cin >> c;
if (c == '<')
a[i] = -1;
else
a[i] = 1;
}
int value;
for (i... | 1 |
#include<iostream>
using namespace std;
int main()
{
int a,b,d,e = 0;
int f[100]{};
cin >> a >> b;
while(cin >> d){
f[d] = 1;
}
while(e < 51){
if(f[a - e] != 1){
cout << a - e;
return 0;
}
if(f[a + e] != 1){
cout << a + e;
return 0;
}
e++;
}
cout << a;
return 0;
} | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
enum { MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009 };
template <typename T>
ostream &operator<<(ostream &cout, vector<T> &a) {
for (size_t i = 0; i < a.size(); ++i) cout << a[i] << " ";
return cout;
}
template <typename T>
ostream ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;
const double eps = 1e-8;
struct P {
double x, y;
P() {}
P(double _x, double _y) : x(_x), y(_y) {}
P operator-(const P& t) { return P(x - t.x, y - t.y); }
};
inline int sign(double x) { return (x > eps) - (x... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n;
vector<int> v(n);
bool allone = true;
for (int i = 0; i < n; i++) {
cin >> v[i];
if (v[i] != 1) allone = false;
}
if (allone) {
if (n % 2 == 0)
cout <... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int MM = 998244353;
const long double PI = acos(-1);
long long power(long long b, long long e, long long m) {
if (e == 0) return 1;
if (e & 1) return b * power(b * b % m, e / 2, m) % m;
return power(b * b % m, e / 2, m);
}
long long pow... | 3 |
#include <iostream>
#include <string.h>
using namespace std;
int n;
char room[10] = "ABCDEFGHI";
char s, t, b;
int off[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int x, y;
double table[3][3];
double solve()
{
memset(&table[0][0], 0, sizeof(double) * 9);
table[y][x] = 1.0;
for(int k=0; k<n; k++)
{
double tem... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, state, zero = 0;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> state;
if (n == 1) {
if (state == 0)
zero = 2;
else
zero = 1;
} else {
if (state == 0) ++zero;
}
}
if (zero == 1)
cout << "YES... | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0);
string s;
int n; cin >> n;
map<string, int> a;
while (n--) {
cin >> s;
a[s]++;
}
cin >> n;
while (n--) {
cin >> s;
a[s]--;
}
int ans = 0;
for (auto it = a.begin(); it != a.end(); it++) {
an... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
priority_queue<long long int, vector<long long int>, greater<long long int>>
huff;
int n;
long long int t;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> t;
huff.push(t);
}
t = 0;
if (!(n % 2)) {
t += huff.top();
huff.pop()... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 503;
int m, n, vis[N][N];
vector<int> adj[N * N];
void init() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int id(int x, int y) { return (x - 1) * n + y; }
struct ds {
char c;
int x, y;
};
vector<ds> V;
void print(int u, int cc, int type = -... | 4 |
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif
#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
long long n;
cin >> n;
long long arr[n];
for (long long i = 0; i < n; i++) cin >> arr[i];
long long check = 10000000000;
long long ans[n];
for (long long i = 0; i < n; i++) {
if (arr[i] == 0) {
ans[i] = 0;... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
bool cmp(long long a, long long b) { return a > b; }
long long prem[maxn], preu[maxn];
long long totm = 0, totu = 0;
long long mrr[maxn], urr[maxn];
int main() {
long long n, d, m;
scanf("%lld %lld %lld", &n, &d, &m);
long long val;
for (int... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 100011, base = 1000000007;
int cnt[nmax], n, f[nmax];
long long pp(long long a, int n) {
long long r = 1;
while (n) {
if (n & 1) r = r * a % base;
a = a * a % base;
n >>= 1;
}
return r;
}
long long wui(int n) {
int r = 0;
while (n > ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s = "01001010111001010";
inline int read() {
int f = 1, x = 0;
char s = getchar();
while (s < '0' || s > '9') {
if (s == '-') f = -1;
s = getchar();
}
while (s >= '0' && s <= '9') {
x = x * 10 + s - '0';
s = getchar();
}
return x ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 2e5 + 5;
int a[Nmax];
int t[Nmax];
int cnt[Nmax];
int n, k, ans, m;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> t[i];
}
int cur = 0;
for (int last = 1; last <= min(n, k - 1); ... | 4 |
#include <stdio.h>
const long long mod = 998244353;
const long long inv2 = (mod + 1) / 2;
int N, S; long long D[3030];
int main()
{
scanf ("%d %d", &N, &S);
D[0] = 1;
for (int i = 0; i < N; i++) D[0] = D[0] * 2 % mod;
while (N--){
int x; scanf ("%d", &x);
for (int i = S - x; i >= 0; i--){
D[i + x] = (... | 0 |
#include <bits/stdc++.h>
double xp, yp, vp;
double R, angel;
double x, y, v, r;
double min(double x, double y) { return x < y ? x : y; }
double max(double x, double y) { return x > y ? x : y; }
double init(double x1, double y1) {
double tmp;
if (fabs(x1 - 0) <= 0.0000000001 || fabs(y1 - 0) <= 0.0000000001) {
if... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
const int N = 1e5 + 5, inf = 1e9 + 5;
long long add(long long x, long long y) {
x += y;
if (x >= MOD) return x - MOD;
return x;
}
long long sub(long long x, long long y) {
x -= y;
if (x < 0) return x + MOD;
return x;
}
l... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct road {
int next, num;
} temp;
struct point {
int id, s;
};
vector<road> G[300005];
int vis[300005];
int visroad[300005];
int ans, res[300005];
queue<point> Q;
point hh, t, tt;
int main() {
hh.s = 0;
int m, n, k, cont = 0, c, d;
scanf("%d%d%d", &m, &n, &k);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
const double PI = acos(-1);
const double EPS = 1e-9;
int main() {
ios_base::sync_with_stdio(0);
int n, m;
cin >> n >> m;
int mt[n][m];
int ans = 0;
for (int i = 0; i < n; i++) {
for (in... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, a[303030], dp[303030][22], bf[303030], nw[303030], nt[303030], ans;
int gt(int l, int r) {
int k = 0, rr = 1;
while (rr * 2 <= r - l + 1) {
k++;
rr *= 2;
}
return max(dp[l][k], dp[r - rr + 1][k]);
}
int main() {
cin >> n;
memset(bf, 0x3f, sizeof(b... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e5 + 10;
int N, K;
char s[MAX];
int col[MAX][3], pre[MAX << 1], siz[MAX << 1], ans;
int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); }
void merge(int x, int y) {
x = find(x), y = find(y);
if (x != y) pre[x] = y, siz[y] += siz[x];
}
int ... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
int upmin(T1 &x, T2 v) {
if (x <= v) {
return 0;
}
x = v;
return 1;
}
template <class T1, class T2>
int upmax(T1 &x, T2 v) {
if (x >= v) {
return 0;
}
x = v;
return 1;
}
void init() {
int N;
cin >> N;
vector<string... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<vector<int>> g(n);
for (int i = 1; i < n; ++i) {
int a, b;
cin >> a >> b;
g[a - 1].push_back(b - 1);
g[b - 1].push_back(a - 1);
}
int sum = 0;
for (int i = 0; i < n; ++i) {
vector<int> neighbors = g[i];
... | 6 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef v... | 0 |
#include <bits/stdc++.h>
using namespace std;
int mpow(int base, int exp);
const int mod = 1000000007;
const int N = 3e5;
vector<int> g[1002];
bool vis[1002];
void dfs(int u) {
vis[u] = true;
for (auto i : g[u]) {
if (!vis[i]) dfs(i);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[11];
int du[11];
int dv[11];
string str = "";
void reset() {
for (int i = 0; i < 10; i++) {
du[i] = dv[i] = a[i];
}
}
int main() {
while (cin >> str) {
for (int i = 0; i < 10; i++) {
a[i] = 0;
}
for (int i = 0; i < str.size(); i++) {
... | 2 |
#include <bits/stdc++.h>
using LL = int64_t;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> a(n);
for (int &i : a) std::cin >> i;
std::sort(a.begin(), a.end());
int maxa = a.back();
std::vector<std::vector<int>> mx(maxa + 1);
for (auto &i... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
char s[maxn];
int sum[maxn];
set<int> t[4 * maxn];
int read() {
int x = 0, y = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') y = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 3) + (x <<... | 4 |
#include <bits/stdc++.h>
using namespace std;
map<pair<char, int>, int> f;
int main() {
ios ::sync_with_stdio(false);
cin.tie(NULL);
cout << (fixed) << setprecision(6);
string s;
while (cin >> s) {
f.clear();
int res = 0;
for (int i = 0, _a = (s.length()); i < _a; i++) {
int cur = f[make_pai... | 2 |
#include <bits/stdc++.h>
using namespace std;
long double eps = 1e-7;
int cmp(long double a, long double b = 0) {
return a + eps < b ? -1 : a - eps > b ? 1 : 0;
}
struct point {
long double x, y;
point(long double a = 0, long double b = 0) : x(a), y(b) {}
bool operator<(const point& q) const {
if (int t = c... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 10;
const int mod = 1000000007;
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
void read(int &first) {
char ch = getchar();
first = 0;
for (; ch < '0' || ch > '9'; ch = getchar())
;
for (; ch >= '0' && ch <= '9'; ch = getchar()) fir... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 50;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
int a[2500];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
n *= 2;
for (int i = 1; i <= n; ++i) cin >> a... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2010, P = 998244353;
int n;
int fw[N], fw2[N];
bool vis[N];
int a[N][N], dp[N][N];
int lowBit(int k) { return k & -k; }
void ch(int* fw, int k, int x) {
for (; k <= n; k += lowBit(k)) fw[k] += x;
}
int qry(int* fw, int k) {
int ret = 0;
for (; k; k -= lo... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T read1() {
T t = 0;
char k;
bool v = 0;
do (k = getchar()) == '-' && (v = 1);
while ('0' > k || k > '9');
while ('0' <= k && k <= '9')
t = (t << 3) + (t << 1) + (k ^ '0'), k = getchar();
return v ? -t : t;
}
int f[200005], s, m;
int ... | 3 |
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int n;
int i;
vector<char> prime;
for(i=0;i<10000000;i++)
{
prime.push_back('1');
}
prime[0]=prime[1]='0';
for(i=0;i<10000000;i++)
{
if(prime[i]=='1')
{
for(int j=2;j*i<10000000;j++)
{
prime[j*i]='0';
}
}
}
for... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, gen;
long long pos;
string f0 =
"What are you doing at the end of the world? Are you busy? Will you save "
"us?";
string formal = "What are you doing while sending \"";
string latter = "\"? Are you busy? Will you send \"";
string last = "\"?";
long long getLe... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
long long int t = 1;
while (t--) {
long long int n;
cin >> n;
long long int arr[n];
long long int temp[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N;
cin >> N;
vector<int> A(N, 0), r(N, 0);
for (int i = 0; i < N; i++) { (cin >> A[i]), A[i] = i - A[i]; }
for (int i = 0, maxi = 0; i < N; i++) {
if (A[i] < maxi or A[i] > i) { return (cout << -1 << endl), 0; }
maxi = ma... | 0 |
#include <iostream>
#include <regex>
using namespace std;
int main() {
string S;
cin >> S;
cout << (regex_search(S.begin(), S.end(), regex("AC")) ? "Yes" : "No") << endl;
} | 0 |
#include<iostream>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(void){
int n;
while(cin>>n,n){
int a[n],sum=0;
r(i,n)cin>>a[i];
r(i,n)for(int j=1;j<n;j++){
if(a[j-1]>a[j]){
swap(a[j-1],a[j]);
sum++;
}
}
cout<<sum<<endl;
}
} | 0 |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
const int oo=1073741819;
using namespace std;
struct point{
int x,y,A,B,D;
}G[2005];
int f[205][105][105],g[105][105][3],b[105][105],d[205][105][105];
int n,m,s,t,F;
inline void Up(int &x,int y)
{
if (x>y) x=y;
}
int main... | 0 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <stack>
#include <vector>
using namespace std;
typedef pair<int, int> seg;
int R, C, N;
vector<seg> edges;
stack<int> st;
int Convert(int x, int y)
{
if (y == 0) return x;
if (x == R) return R + y;
if (y == ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n;
while (n--) {
cin >> x;
cout << (x + 1) / 10 << endl;
}
return 0;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
struct node{
string name;
int length;
} song[1010];
int n,fl=0,ans=0;
string s;
int main()
{ cin>>n;
for(int i=1;i<=n;++i)
cin>>song[i].name>>song[i].length;
cin>>s;
for(int i=1;i<=n;++i)
if(fl)
ans+=song[i].length;
else if(song[i].name==s)
fl=1;
cout<<ans... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x, y, max = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x >> y;
if (x + y > max) max = x + y;
}
cout << max;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
char a[9][9];
int k1[2], k2[2];
cin >> t;
while (t--) {
int isK1 = 0;
for (int i = 1; i <= 8; i++) {
for (int j = 1; j <= 8; j++) {
cin >> a[i][j];
if (a[i][j] == 'K' && isK1) {
isK1 = 0;
k1[0] ... | 1 |
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 5010;
vector<int> G[maxn];
int d[maxn][maxn][2];
void check(int &a, int b) {
if (a > b) a = b;
}
int dfs(int u, int fa) {
int num = G[u].size(), tot = 0, now = 0;
d[u][0][0] = 0;
d[u][0][1] = 0;
if (num == 1) {
d[u]... | 6 |
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << end... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int inf = (1 << 29) - 1;
const double eqs = 1e-8;
const int N = 100003;
int have[N];
int a[N];
int b[N];
long long pow_mod(long long a, int b) {
long long ans = 1;
while (b) {
if (b & 1) ans = ans * a % mod;
a = a * a % mod;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int inf = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
const double PI = acos(-1);
long long int i, j, k;
void solve(void);
inline bool equal(double a, double b) { return fabs(a - b) < eps; }
int main() {
cout << fix... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long A[(800000 + 10)], B[(800000 + 10)], C[(800000 + 10)],
d[(800000 + 10)], h[(800000 + 10)];
void up(int id) {
int ls = id << 1, rs = ls | 1;
A[id] = max(A[ls], A[rs]);
B[id] = max(B[ls], B[rs]);
C[id] = max(B[ls] + A[rs], max(C[ls], C[rs]));
C[id] = ma... | 3 |
#include<bits/stdc++.h>
#define ll long long
#define re register
#define ull unsigned ll
using namespace std;
inline int read(){
int s=0,t=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();}
while(ch>='0'&&ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
return s*t;
}
const int N=5e5+5;
const i... | 0 |
#include <iostream>
#include <vector>
using namespace std;
template<typename T>
class RangeAddQuery {
public:
explicit RangeAddQuery(int n) : N(calcN_(n)) {
mVal.assign(2*N+1, 0);
}
void update(int l, int r, T value){
l = max(0, l);
r = min(N, r);
int offset = N;
wh... | 0 |
#include <bits/stdc++.h>
using namespace std;
int arr[200010];
string S;
int main() {
int a;
scanf("%d", &a);
int p = 0;
int l = 0;
int r = a - 1;
for (int i = 0; i < a; i++) {
scanf("%d", &arr[i]);
}
int lc = 0;
int rc = 0;
while (l <= r) {
if (arr[l] >= p) {
lc = 1;
}
if (arr... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
double f[N][N];
double dp(int n, int m) {
if (!n) return 1.0 / (m + 1);
if (!m) return 1;
if (f[n][m]) return f[n][m];
double A = (1 - dp(m - 1, n)) * m / (m + 1);
double B = (1 - dp(m - 1, n)) * m / (m + 1) + 1.0 / (m + 1);
double C = 1;
d... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
multiset<int> s;
int n, can, a, res(0);
cin >> n;
cin >> can;
for (int i = 0; i < n - 1; i++) cin >> a, s.insert(a);
multiset<int>::reverse_iterator it;
multiset<int>::iterator lo;
it = s.rbegin();
while (can <= *it) {
a = *it - 1;
lo ... | 1 |
#include <iostream>
#include<algorithm>
using namespace std;
int main() {
int dp[1010][1010]={};
int n,m;cin>>n>>m;
int d[1010];
int c[1010];
for(int i=0;i<n;i++)cin>>d[i];
for(int i=0;i<m;i++)cin>>c[i];
for(int i=0;i<n;i++)for(int j=0;j<m;j++)dp[i][j]=1<<28;
for(int i=0;i<=m;i++)dp[n][i]=0;
for(int i=n-1;i>=... | 0 |
#include <bits/stdc++.h>
template <typename T>
inline void SWAP(T &a, T &b) {
T tmp = a;
a = b;
b = tmp;
}
template <typename T>
inline T ABS(const T &val) {
return val < 0 ? -val : val;
}
template <typename T>
inline T MAX(const T &a, const T &b) {
return a > b ? a : b;
}
template <typename T>
inline T MIN(c... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int mx = 0, a = 0, n;
string s;
cin >> n;
while (cin >> s) {
for (char c : s)
if (isupper(c)) a++;
mx = max(mx, a), a = 0;
}
cout << mx << endl;
}
| 1 |
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(void)
{
while(1){
int n;
cin >> n;
if(!n) break;
int ret = 0;
while(n){
n /= 5;
ret += n;
}
cout << ret << endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long q;
cin >> q;
while (q--) {
long long s = 0, n, h, p[200001], c = 0, f = 0;
cin >> h >> n;
for (long long i = 0; i < n; ++i) cin >> p[i];
p[n] = 0;
for (long long i = 1; i <= n; ++i) {
if (p[i - 1] - p[i] == 1)
c... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char c = getchar();
while ((c < '0' || c > '9') && (c != '-')) c = getchar();
if (c == '-') f = -1, c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int N = 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[100005], v, n, b[100005], tot = 0, ff[40];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
v = 0;
for (int i = 1; i <= 30; i++) {
memset(b, 0, sizeof(b));
memset(ff, 0, sizeof(ff));
for (int j = 1; j <= n; j++)
... | 3 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5+1;
int n,fa[N],tot[N],fr[N],blk[N],wht[N],c[N],cnt,head[N];
struct nd{int ne,to;}e[N];
void in(int x,int y){e[++cnt].to=y;e[cnt].ne=head[x];head[x]=cnt;}
int can[5001],tmp[N];
bool dfs(int x)
{
for(int i=head[x];i;i=e[i].ne) i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int TT;
cin >> TT;
while (TT--) {
int N;
long long K;
cin >> N >> K;
vector<int> A(N);
long long sum = 0;
for (int i = 0; i < N; ++i) {
cin >> A[i];
sum += A[i];
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
void solve() {
int n;
cin >> n;
int a[n + 2];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
long long int tot = a[n];
long long int cnt = 0;
for (int i = 2; i <= n; i++) {
if (a[i] > a[i - 1]) {
cnt += (a[i] - a[i - 1]);... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.