solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int f[30005][500];
int a[30005] = {0};
int n, d;
int main() {
scanf("%d%d", &n, &d);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
a[x]++;
}
memset(f, -1, sizeof(f));
f[d][250] = a[d];
int ans = 0;
for (int i = d; i < 30000; i++) {
for... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chkmax(T &x, T y) {
x = x > y ? x : y;
}
template <typename T>
void chkmin(T &x, T y) {
x = x > y ? y : x;
}
const int INF = 2139062143;
template <typename T>
void read(T &x) {
x = 0;
bool f = 1;
char ch;
do {
ch = getchar();
i... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long l[100000 + 100];
l[0] = 75;
int i;
for (i = 1; i < 100; ++i) {
l[i] = l[i - 1] * 2 + 34 + 32 + 2;
if (l[i] > 1000000000000000000LL) break;
}
for (; i < 100000 + 100; ++i) {
l[i] = 1000000000000000100LL;
}
int q;
scanf("%d... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int INF = 1e9 + 5;
const long long mod = 1e9 + 7;
const double pi = 3.1415926536;
int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ios_base::sync_with_stdio(0... | 7 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
const ll INF=1e18;
int t,n,dep[N],fa[N];
ll a[N],dp[N],mn[N],mx[N],Min[N],Max[N],levelMin[N],levelMax[N];
vector<int>e[N];
void dfs(int u,int d){
levelMin[d]=min(levelMin[d],a[u]);
levelMax[d]=max(levelMax[d],a[u]);
dep[u]=d;
for... | 17 |
#include <bits/stdc++.h>
int main() {
std::string s1, s2;
std::cin >> s1 >> s2;
if (s1.size() != s2.size()) {
std::cout << "NO";
return 0;
}
bool t = true;
for (int i = 0, j = s2.size() - 1; i < s2.size(); i++) {
if (s1[i] != s2[j]) {
t = false;
break;
}
j--;
}
if (t)
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, z, i, j, lt, x, t, y, d, r, q, m, k;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin >> n >> m;
long long ar[m][n];
long long nxt[m][n + 1];
for (i = 0; i < m; i++) {
cin >> x;
ar[i][0] = x;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 100;
char s[maxn];
void solve() {
int n, k;
scanf("%d%d%s", &n, &k, s + 1);
for (int i = (1), iend = (k); i <= iend; i++) {
int mark = -1;
for (int j = i; j <= n; j += k) {
if (s[j] == '?')
continue;
else if (mark == ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[105];
int b[105];
int main() {
int n, m;
while (cin >> n >> m) {
int cnt = 0;
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j) {
cin >> a[i] >> b[i];
if (a[i] == 1 || b[i] == 1) cnt++;
}
cout << cnt << '\n';
}
ret... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, K, result = numeric_limits<int>::min();
cin >> N >> K;
vector<int> X(N);
for (int i = 0; i < (int)(N); i++) cin >> X[i];
for (int to = 0; to < (int)(N); to++)
for (int from = 0; from < (int)(to + 1); from++) {
vector<int> inside, outs... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
int p[1013][1013];
bool done[1013];
double ans[1013];
double tot[1013];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) scanf("%d", &p[i][j]);
for (int i = 0; i < n; i++) {
ans[i] = 1 / 0.;
tot[i] = 1;
}
ans... | 19 |
#include <bits/stdc++.h>
using namespace std;
string l, r;
long long a, b;
int ans;
int cnt[10];
int rrr[10];
int tot;
long long pw10[20];
long long rep[10][20];
void check() {
memcpy(rrr, cnt, sizeof(rrr));
rrr[0] += tot;
long long cur = 0;
long long tmp;
int idx;
for (int i = 0; i < r.size(); ++i) {
t... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, n, m, i, x;
x = 0;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++) {
scanf("%d%d", &a, &b);
if (x >= a && x < b) x = b;
}
if (x >= m)
printf("YES\n");
else
printf("NO\n");
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
void per() { cerr << endl; }
template <typename Head, typename... Tail>
void per(Head H, Tail... T) {
cerr << H << ' ';
per(T...);
}
template <class T>
bool uin(T& a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T& a, T b) {
return a < ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int h[2][100005], n, m, tot = 0, ans[5 * 100005][3], fin = 0;
set<int> trans;
set<int> hv[100005];
void transR(int id, int val) {
if (!h[0][id] && h[1][id]) trans.erase(id);
h[1][id] += val;
if (!h[0][id] && h[1][id]) trans.insert(id);
}
void transL(int id, int val) {... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
template <class T>
int chmin(T &t, T f) {
return (t > f) ? (t = f, 1) : 0;
}
template <class T>
int chmax(T &t, T f) {
return (t < f) ? (t = f, 1) : 0;
}
inline int getint() {... | 7 |
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i ++)
#define mx 500005
#define mod 1000000007
#define LL long long
using namespace std;
long long f[105][10005], SUM[10005], lim[105];
int c[105], n, b[105];
long long calc(int id, int sum) {
if (f[id][sum] > -1) return f[id][sum];
if (id && sum... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, res;
cin >> n >> a >> b;
res = n - a;
if (b < res) {
res = b + 1;
}
cout << res << endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
vector<int> build_sa(const T &S, vector<int> &Sa, vector<int> &H) {
int n = (int)S.size(), i, h;
vector<int> R(S.begin(), S.end());
Sa.resize(n + 1), iota(Sa.begin(), Sa.end(), 0), R.push_back(INT_MIN);
for (int len = 1; len <= n; len <<= 1) {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
class SegmentTree {
public:
SegmentTree(std::vector<long long>& inputArray) {
n = inputArray.size();
N = 1;
while (N < n) N <<= 1;
_treeArray = std::vector<long long>(N, 0);
_endpoints = std::vector<std::pair<long, long>>(2 * N);
_treeArray.insert... | 11 |
#include <bits/stdc++.h>
using namespace std;
int max_deg = -1e9;
vector<pair<int, int>> ans;
void dfs(int v, vector<vector<int>>& g, int t, int time, vector<bool>& used) {
ans.push_back({v, t});
used[v] = 1;
int counter = 0;
for (int i : g[v]) {
if (!used[i]) {
if (t == max_deg) {
t = time - ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, inf = 0x3f3f3f3f;
int n, m, k, s[N], vis[N * 10], bas[20], a[20];
void insert(int x) {
int t = x;
for (int i = 20; i >= 0; i--)
if ((x >> i) & 1)
if (!bas[i]) {
bas[i] = x;
a[++k] = t;
break;
} else
... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
string s, t;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long t;
cin >> t;
while (t--) {
long long n;
string s;
cin >> n >> s;
long long st = -1, en = -1;
for (int i = 0; i <= n - 1; i++) {
if (s[i] == '1')... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
int cnt = 0;
int i = 0, j = n - 1;
while (i <= j) {
if (a[i] <= k) {
i++;
cnt++;
continue;
} else {
if (a[j] <= k) {
j--;
c... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100050;
double f[Maxn][105];
int sz[Maxn], a[Maxn];
int main() {
int n, q;
double expect = 0;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]), sz[i] = a[i], f[i][a[i]] = 1;
if (a[i] == 0) expect += 1;
}
scanf("%d", &q)... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e18 + 7;
char arr[51][51];
int pref[51][51];
int dp[51][51][51][51];
int n;
void Init() {
for (int i = 0; i < n; i++) {
if (!i)
pref[0][0] = (arr[0][0] == '#');
else {
pref[0][i] = pref[0][i - 1] + (arr[0][i] == '#');
}
}
... | 15 |
#include<bits/stdc++.h>
using namespace std;
int ans;
int n;
int main() {
cin >> n;
cout << 2-n*n << endl;
} | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
set<char> v;
for (; s[s.size() - 1] != '}';) {
cin >> s;
for (int i = 0; i < s.size(); i++)
if (s[i] != ' ' && s[i] != ',' && s[i] != '{' && s[i] != '}')
v.insert... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000000000")
using namespace std;
const int inf((1 << 31) - 1);
int dx[] = {0, 0, -1, 1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int MaxN = 200000 + 10;
const int MaxST = 4 * MaxN;
int cnt(unsigned long long a) {
int out = 0;
while (a... | 13 |
#include <bits/stdc++.h>
using namespace std;
void deba(int* a, int n) {
cerr << "| ";
for (int i = 0; i < (n); i++) cerr << a[i] << " ";
cerr << "|" << endl;
}
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 30;
char m[10][10];
int v[10][10];
bool yes(int i, int j) {
if (... | 3 |
#include <bits/stdc++.h>
using namespace std;
void sol() {
int n, s, t;
cin >> n >> s;
t = 0;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
long long int sum = 0;
for (int i = 0; i < n; i++) {
if (t < s && arr[i] < 0) {
arr[i] = arr[i] * (-1);
t++;
}
sum += arr[i];
}
s... | 4 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<pair<int, int> > a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].first;
a[i].second = i;
}
sort(a.begin(), a.end());
if (lower_bound(a.begin(), a.end(), make... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, n, ck = 0, j, max, dk = 0, i;
cin >> n;
int arr[n], brr[n];
for (i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
for (i = 0; i < n; i++) brr[i] = arr[i];
bool check[n];
memset(check, 1, sizeof(check));
for (i = 0; i < n - 1;... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long isprime(long long n) {
for (long long i = 2; i <= sqrt(n); i++)
if (n % i == 0) return i;
return 0;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin.tie(0);
long long q, first = -1, second = -1;
cin >> q;
long long k = isprime(q);
... | 6 |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rem 1000000007
#define rem1 998244353
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t;
cin>>t;
while(t--)
{
ll i,j,k,n,m;
string str;
cin>>str;
n=str.length();
if(... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve() {}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int arr[3][3];
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
cin >> arr[i][j];
}
}
int sumMax = (arr[0][2] + arr[2][0]) / 2;
int a... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 20;
int h[maxn][2];
long long mx[maxn], dp[maxn][2];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int k = 0; k < 2; k++)
for (int i = 1; i <= n; i++) cin >> h[i][k];
for (int i = 1; i ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int toadd[5005];
int curmax[5005];
int acopy[5005];
int inst[5005][4];
int N, M;
int main() {
cin >> N >> M;
for (int i = 0; i < N; i++) curmax[i] = acopy[i] = 100000000;
for (int i = 0; i < N; i++) toadd[i] = 0;
for (int i = 0; i < M; i++) {
int q, l, r, v;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int INP, AM;
char BUF[(1 << 10) + 1], *inp = BUF;
const double PI = acos(-1.0);
bool can(int start, int n4, int n7, int n47, int n74) {
if (start == 7) return can(4, n7, n4, n74, n47);
if (abs(n47 - n74) > 1) return false;
if (n4 <= 0) return false;
if (n7 < 0) retu... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int MAXN = 110;
int n, deg[MAXN];
vector<char> adj[MAXN], vec, voroodi[MAXN];
string s[MAXN];
bool mark[30];
void make_adj(string t) {
for (long long i = 0; i < t.size() - 1; i++)
adj[t[i] - 'a'].push_back(t[i + 1]),
voroodi[t... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 333;
int gr[MAXN][MAXN];
bool is[500];
int mex() {
for (int i = 0;; ++i)
if (!is[i]) return i;
return -1;
}
int main() {
int L = 301;
for (int i = 0; i <= L; ++i) gr[i][0] = gr[0][i] = i;
for (int i = 1; i <= L; ++i) {
for (int j = 1; j <=... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 2e5;
int n, t;
int C[MaxN + 5];
int D[MaxN + 5];
char s[MaxN + 5];
bool flag = false;
void Inc() {
int p = D[0];
while (true) {
if (p == 0) {
D[0]++;
D[1] = 1;
for (int i = 2; i <= D[0]; i++) D[i] = 0;
break;
}
if (D[... | 9 |
#include <bits/stdc++.h>
long long array[1000007];
int main() {
long long k, i, j, x, y, z, sum;
for (i = 1; i < 1000007; i++) {
for (j = i; j < 1000007; j = j + i) {
array[j]++;
}
}
scanf("%lld %lld %lld", &x, &y, &z);
sum = 0;
for (i = 1; i <= x; i++) {
for (j = 1; j <= y; j++) {
f... | 18 |
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::vector;
int main() {
int n = 0, m = 0, count1 = 0, count2 = 0;
int r[51] = {0};
char grid[51][51];
vector<int> raw, column;
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> grid[i... | 5 |
// Author : Chinmay Jha
// @chinmayajha on Codeforces, Codechef, USACO, AtCoder and CSES.fi
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define vi vector<int>
#define vli vector<lli>
#define vii vector<pair<int,int>>
#define vlii vector<pair<lli,lli>>
#define vvi vector<vector<int>>
#define... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
return out << "(" << a.first << "," << a.second << ")";
}
template <class A>
ostream &operator<<(ostream &out, const vector<A> &a) {
for (const A &it : a) out << it << " ";
return out... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2;
const int INF = 2e9;
const double PI = acos(-1);
int arr[N + 10][N + 10];
int main() {
int n;
scanf("%d", &n);
for (int j = 0; j < n; ++j) {
for (int i = 0; i < n; ++i) {
arr[i][j] = i + (j * n) + 1 + j;
if (arr[i][j] > n * (j + 1)) ... | 2 |
#include <bits/stdc++.h>
inline int min(const int &first, const int &second) {
return (((second - first) >> (32 - 1)) & (first ^ second)) ^ first;
}
inline int max(const int &first, const int &second) {
return (((second - first) >> (32 - 1)) & (first ^ second)) ^ second;
}
inline long long min(const long long &firs... | 16 |
#include<bits/stdc++.h>
using namespace std;
#define rez resize
const int Mod=998244353;
const int D2=998244351;
typedef vector<int> poly;
namespace modular{
int add(int a,int b){return a+b>=Mod?a+b-Mod:a+b;}
int dec(int a,int b){return a-b<0?a-b+Mod:a-b;}
int mul(int a,int b){return 1ll*a*b%Mod;}
int Fast_Pow(int... | 27 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
if (n % 2 == 0)
cout << n / 2;
else {
long long int count = 0;
for (long long int i = 3; i <= sqrt(n); i += 2)
if (n % i == 0) {
count = i;
break;
}
if (count == 0) count = n;
co... | 4 |
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int maxn = 105 + 5;
using namespace std;
int a[maxn];
int main() {
std::ios::sync_with_stdio(false);
int t, n;
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = n - 1; i >= 0; i--) {
cou... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<string> program(10000);
string s;
cin >> s;
int buf = 0, curl = 0;
for (int i = 0; i < (int)(s.size()); ++i) {
int goal = s[i];
while (buf != goal + 1) {
program[curl] += ".X.";
program[curl + 1] += "...";
buf = (buf +... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)3e5 + 50, B = 62;
const long long ALL = (long long)(1LL << 62) - 1;
int n;
long long val[N], msk[N];
int low[N];
long long sum = 0;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
long long sum = 0;
for (int i = 0; i < n; i++)... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, freq[150];
int v[maxn];
map<int, int> mp;
string z;
long long ans = 0;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> z;
int msk = 0;
for (int j = 97; j <= 122; j... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, l, r, a[222222], x, res[222222];
vector<pair<long long, pair<long long, long long> > > v;
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> l >> r;
for (long long i = 1; i <= n; i++) {
cin >> a[i];
}
for (long long i = 1; i <= n; i++) {
c... | 9 |
#include <bits/stdc++.h>
int main() {
int a, b, c, d, i, j, x, y;
scanf("%d%d%d%d", &a, &b, &c, &d);
i = (3 * a) / 10;
j = a - ((a * c) / 250);
x = (3 * b) / 10;
y = b - ((b * d) / 250);
int m, n;
m = i < j ? j : i;
n = x < y ? y : x;
if (m > n) {
printf("Misha");
} else if (n > m) {
print... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[310][310], c[3];
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) cin >> c[i];
if (N != 2)
if (!(c[0] ^ c[1] ^ c[2]))
cout << "BitAryo" << endl;
else
cout << "BitLGM" << endl;
else {
for (int i = 0; i < 300; i++)
for (i... | 13 |
#include <bits/stdc++.h>
using namespace std;
void cicada() {
long long i, j, k, l, m, n;
cin >> n >> m;
vector<long long> v(n);
for (i = 0; i < n; i++) cin >> v[i];
j = 0;
while (m--) {
long long a, b;
cin >> a >> b;
if (a == 1) {
long long c;
cin >> c;
v[b - a] = c - j;
}... | 4 |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
typedef long long ll;
const int INF = (int)1e9 + 7;
const int maxN = 200022;
struct node {
int d = INF, p = 0, r = 0;
vector<pair<int, PII>> A;
};
node A[maxN];
pair<PII, int> E[maxN];
vector<int> V, R;
void path(int v) {
if (v == 0) return... | 15 |
#include <bits/stdc++.h>
int main() {
int n, i, j, m, sum = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &m);
if ((i == j) || (i == n - j - 1) || (i == (n - 1) / 2) ||
(j == (n - 1) / 2))
sum += m;
}
}
printf("%d", sum);
return 0;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005, M = 200005, P = 1005;
int n, m, kk, mp[N], idx;
struct Node {
int uu, vv, ww;
};
Node e[N];
long long dis[P][P];
int main() {
scanf("%d%d%d", &n, &m, &kk);
for (int i = 1; i <= m; i++) {
int t1, t2, t3;
cin >> t1 >> t2 >> t3;
e[i] = {... | 14 |
#include <bits/stdc++.h>
using namespace std;
void read(vector<int> &a, int n) {
for (int i = 0; i < n; i++) cin >> a[i];
}
void read(vector<long long> &a, int n) {
for (int i = 0; i < n; i++) cin >> a[i];
}
const int MOD = 1e9 + 7;
const int INF = (int)2e9 + 7;
const long long LINF = (long long)1e18;
const long do... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
inline long long divided(long long x, long long y) {
if (x == y) return x;
register long long mid = (x + y) >> 1;
if (1ll * ((n - mid) * (n - mid + 1) / 2ll) - mid > m)
x = mid + 1;
else
y = mid;
return divided(x, y);
}
int main() {
cin >... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long dp[2000 + 10][2000 + 10];
long long rec(long long index, long long len) {
if (len == k) return 1;
if (dp[index][len] != -1) return dp[index][len];
long long e = 0, v = 0, tem = 0;
e += rec(index, len + 1) % 1000000007;
for (int i = 2; ind... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
bool Max(T1& a, T2 b) {
return a < b ? a = b, 1 : 0;
}
template <typename T1, typename T2>
bool Min(T1& a, T2 b) {
return a > b ? a = b, 1 : 0;
}
const int N = 100001;
int hsb_loc(int n) { return 31 - __builtin_clz(n); }
int hsb_loc(l... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 100;
const int INF = 1e9 + 7;
int mn[MAXN * 4], cnt[MAXN * 4], laz[MAXN * 4];
int p[MAXN];
void Make(int v, int l, int r) {
if (r - l == 1) {
cnt[v] = 1;
return;
}
int mid = (l + r) / 2;
Make(2 * v, l, mid);
Make(2 * v + 1, mid, r);
... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long int seed = 13;
void reverse(string& s) {
reverse(s.begin(), s.end());
map<char, char> mapD;
mapD['N'] = 'S';
mapD['S'] = 'N';
mapD['E'] = 'W';
mapD['W'] = 'E';
string t;
for (int i = 0; i < s.length(); ++i) {
s[i] = mapD[s[i]];
}
}
int main()... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int inf = int(1e9) + 100;
const double eps = 1e-9;
const double pi = 4 * atan(double(1));
const int N = int(1e6) + 100;
const int LOG = 20;
int n;
char s[N], ns[N];
int p[LOG][N];
inline void move(int k, int d) {
int ptr = 0;
for (int i = 0; i < d; ++i) {
for ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int ans = n / 2;
cout << n / 2 << endl;
if (n % 2 == 0) {
while (ans--) cout << 2 << ' ';
} else {
ans--;
while (ans--) cout << 2 << ' ';
cout <<... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
string p[100010], res;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> p[i];
m = p[1].length();
for (int k = 0; k <= m - 1; k++) {
char c = '-';
for (int i = 1; i <= n; i++)
if (p[i][k] != '?')
if (c == '-')
c = p... | 4 |
#include <bits/stdc++.h>
int main() {
int n, a[201], i, b[201], j, r = 0, l = 0, u = 0, lo = 0, sc = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d %d", &a[i], &b[i]);
}
for (j = 0; j < n; j++) {
for (i = 0; i < n; i++) {
if (a[j] > a[i] && b[j] == b[i]) {
l = 1;
}
i... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename X>
inline X abs(const X& a) {
return a < 0 ? -a : a;
}
template <typename X>
inline X sqr(const X& a) {
return a * a;
}
const int size = 1e5 + 5;
const double eps = 0.0001;
const long ... | 9 |
#include <bits/stdc++.h>
const int Mod = 998244353;
int n, dp[300005][4], h[300005], cnt;
struct edge {
int to, nxt;
} e[300005 << 1];
void dfs(int x, int f) {
int un = 1;
dp[x][0] = dp[x][1] = dp[x][2] = dp[x][3] = 1;
for (int i = h[x], y; i; i = e[i].nxt) {
if ((y = e[i].to) != f) {
dfs(y, x);
... | 17 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll countw(ll a, ll b, ll c, ll d) {
ll w = c - a + 1;
ll h = d - b + 1;
return w * (h / 2) + (h % 2 == 0 ? 0 : (w + ((c + d) % 2 == 0)) / 2);
}
ll area(ll a, ll b, ll c, ll d) { return (abs(a - c) + 1) * (abs(b - d) + 1); }
int main() {
int t;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y;
};
bool cmp(node q, node w) { return q.x < w.x; }
int main() {
int n, sum = 0, a, m;
int ed = -1;
node b[1005];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
sum += a;
}
cin >> m;
if (m == 0) {
cout << -1 << endl;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int buy[20][N];
int sell[20][N];
int cnt[20][N];
char c[20];
pair<int, int> p[N];
int n, m, k, i, ans, j, l, ct, kk, tans;
int main() {
cin >> n >> m >> k;
for (i = 0; i < n; i++) {
cin >> c;
for (j = 0; j < m; j++) {
cin >> buy[i][j] >>... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
constexpr int N = 1e6 + 5;
int last[N], n;
ll ans = 0;
void Solve() {
cin >> n;
for (int i = 1, v; i <= n; i++) {
cin >> v;
ans += (ll)2 * (i - last[v]) * (n - i + 1) - 1;
last[v] = i;... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 2;
int a[maxn];
int ans[maxn];
void solve() { return; }
int main(void) {
int k, n;
while (cin >> n >> k) {
long long sum = 0;
for (int i = 1; i <= n; i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T min3(T a, T b, T c) {
return min(a, min(b, c));
};
template <class T>
T max3(T a, T b, T c) {
return max(a, max(b, c));
};
void openFile() { freopen("/home/khaihanhdk/devplace/a.inp", "r", stdin); }
int sl[10000];
void pt(int x) {
if (x == 2)
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
int pro[27];
int cnt[100001][28];
string str[100001];
int cnt2[28];
bool gb[100001];
int cnt3[28];
bool comp(string a, string b) { return a + b < b + a; }
string append(string a, string b, int c) {
int f = 0;
for (int i = 0; i < a.size(); i++) {
if ((a[i] - '... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < (n); i++) cin >> a[i];
sort(a, a + n);
int tk[n];
memset(tk, 0, sizeof(tk));
int pv = -1;
vector<int> ans;
for (int i = 0; i < (n); i++) {
if (a[i] != pv) {
tk[i] = 1;
pv = a[i];... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool cities[2000];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
cities[x - 1] = true;
cities[y - 1] = true;
}
int good;
for (int i = 0; i < n; i++) {
if (cities[i] != true) {
good = i;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vector;
int t, size;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> size;
int value = 0;
for (int j = 0; j < size; j++) {
cin >> value;
vector.push_back(value);
}
sort(vector.begin(), vector.end());
revers... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long h1, h2;
cin >> h1 >> h2;
long long a, b;
cin >> a >> b;
long long r = 8 * a;
long long v = 12 * b;
long long p = 12 * a - v;
h1 = h1 + r;
if (h1 >= h2)
cout << "0" << endl;
else {
if (a <= b)
cout << "-1" << endl;
else... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
bool vis[maxn][maxn];
char grid[maxn][maxn];
int n, m;
bool bad(int x, int y) {
if (x < 0 || x >= n || y < 0 || y >= m) return true;
if (vis[x][y]) return true;
return false;
}
bool canPlaceRight(int x, int y) { return !bad(x, y) && !bad(x, y + ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
long long int x[n];
for (int i = 0; i < n; i++) {
cin >> x[i];
}
sort(x, x + n);
long long int answer = 0;
for (int i = 0; i < n; i++) {
answer += x[i] * k;
if (k > 1) {
k--;
}
}
cout << answer;... | 4 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
map<int, int> amt;
map<int, int> cnt;
vector<int> a;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
cnt[x]++;
if (a.empty()) {
a.em... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxm = 2e3 + 10;
const int inf = 0x3f3f3f3f;
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
qu[55];
int f, qr;
inline void fl... | 13 |
#include <bits/stdc++.h>
using namespace std;
vector<int> tens;
long long mod = 1000000007;
long long mult(long long a, long long b, long long mod);
long long binpower(long long base, long long e, long long mod);
long long createInv(long long n);
int gcd2(int a, int b, int &x, int &y);
bool find_any_solution(int a, int... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long int hell = (long long int)(1e18 + 100LL);
const double pi = acos(-1.0);
long long int me(long long int x, long long int n) {
long long int res = 1LL;
x = x;
while (n > 0LL) {
if (n % 2LL == 1LL) {
res = (res * x);
}
x = (x * x);
n... | 6 |
#include <bits/stdc++.h>
using namespace std;
istream& in = cin;
int n, m;
int A[40010], B[40010];
vector<int> Ai, Bi;
void Init() {
memset(A, -1, sizeof(A));
memset(B, -1, sizeof(B));
}
void input() {
in >> n >> m;
Ai.resize(n);
Bi.resize(m);
for (int i = 0; i < n; ++i) {
in >> Ai[i];
Ai[i] += 1000... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
template <typename T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
if (x > y) x = y;
}
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
if (x < y) x = y;
}
using ll = long long;
using ld = long double;
c... | 26 |
#include <bits/stdc++.h>
using namespace std;
struct Interval {
int start, end;
};
bool compareInterval(Interval i1, Interval i2) { return (i1.start < i2.start); }
long long int maxy(long long int a, long long int b) {
if (b >= a) return b;
return a;
}
long long int li[200003];
long long int ri[200003];
int main(... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct lo {
long long x, y, k;
} di[2010];
struct node {
int x, y;
long long point;
} siz[2000010];
struct out {
int x, y;
};
vector<int> out1;
vector<out> out2;
int n, cnt = 0, fa[2010];
bool cmp(node a, node b) { return a.point < b.point; }
int find(int x) {
if ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long double w, h, a;
cin >> w >> h >> a;
cout << fixed << setprecision(10);
if (h > w) swap(h, w);
if (a > 90) a = 180 - a;
if (fabs(a - 90) <= 1e-1)
co... | 12 |
#include <bits/stdc++.h>
using namespace std;
char a[200010], b[200010];
int main() {
int i, j, k, n, m, k1, k2;
scanf("%d%d", &n, &m);
scanf("%s", a);
k1 = 0;
k2 = 0;
k = 0;
for (i = 0; i < n; i++) {
if (a[i] == '(') {
if (k1 < m / 2) {
b[k++] = a[i];
k1++;
}
} else if... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long k;
long long a[200010], h[200010];
void Work() {
long long t = 0;
int mn = n;
for (int i = n; i >= 0; i--) {
t += a[i];
if (abs(t) >= 2 * k) break;
mn = i;
t <<= 1;
h[i - 1] = t;
}
t = 0;
int ans = 0;
for (int i = 0; i <= n... | 14 |
#include <bits/stdc++.h>
using namespace std;
int st[4 * 300005];
int n, m;
void build_tree(int vt, int dau, int cuoi) {
int mid, l, r;
st[vt] = 0;
if (dau == cuoi) return;
mid = (dau + cuoi) / 2;
l = 2 * vt;
r = l + 1;
build_tree(l, dau, mid);
build_tree(r, mid + 1, cuoi);
}
void up(int vt) {
int l, ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 60;
const int maxm = 20000 + 10;
long long dp[maxn][maxm], A[maxn][maxm], tree[4 * maxm];
int N, M, K;
void update(int node, int start, int end, int idx, long long val) {
if (start > idx || end < idx) return;
if (start == idx && end == idx) {
tree[n... | 15 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.