solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 233;
const int M = 1023;
int a[N];
int n, m;
long long dp[N][M], f[N][M];
inline void upd(long long& x, long long y) { x = (x + y) % MOD; }
void solve() {
int now = 0, i, j, k, w;
long long t;
memset(dp, 0, sizeof dp);
dp... | 6 |
#include "bits/stdc++.h"
using namespace std;
//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#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 each(it,c... | 0 |
#include <bits/stdc++.h>
constexpr int MAX_N = 100100;
using namespace std;
int n, d;
int arr[MAX_N];
int max_pre[MAX_N];
int main() {
scanf(" %d %d", &n, &d);
for (int i = 0; i < n; ++i) {
scanf(" %d", &arr[i]);
}
bool poss = true;
int cur_min = 0;
for (int i = 0; i < n; ++i) {
if (arr[i] == 0) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int64_t inf = 1e18;
vector<vector<int64_t> > adj;
int64_t inp() {
int64_t x;
cin >> x;
return x;
}
vector<int64_t> level;
int64_t res = 0;
void dfs(int64_t u, int64_t LV = 0) {
level[u] = LV;
res = max(res, LV);
for (auto v : adj[u]) {
dfs(v, LV + 1);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
int dcmp(double x) {
if(fabs(x) < eps) return 0;
return x < 0 ? -1 : 1;
}
bool same(double a, double b) {return dcmp(a - b) == 0;}
#define Vector P
struct P {
double x, y;
P(double x = 0, double y = 0): x(x), y(y)... | 0 |
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#de... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[105][105];
int main() {
int ans, i, j, k, l, n, m, x, y, kk;
scanf("%d%d%d", &n, &m, &kk);
ans = n * m;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++) scanf("%d", &a[i][j]);
if (m > k) {
for (k = 0; k < m; k++) {
int sum = 0;
for (j = 0;... | 2 |
#include <bits/stdc++.h>
using namespace std;
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
vector<string> mat;
vector<vector<int>> D;
int n, m;
int id = 0;
int dfs(int x, int y) {
D[x][y] = id;
int suma = 1;
for (int h = 0; h < 4; h++) {
int dx = x + dr[h], dy = y + dc[h];
if (0 <= dx and dx < n an... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void get_int(T &x) {
char t = getchar();
bool neg = false;
x = 0;
for (; (t > '9' || t < '0') && t != '-'; t = getchar())
;
if (t == '-') neg = true, t = getchar();
for (; t <= '9' && t >= '0'; t = getchar()) x = x * 10 + t - '0';
if ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, arr[100000], a = 0;
cin >> n;
cin >> arr[0];
for (int i = 1; i < n; i++) {
cin >> arr[i];
if (arr[i - 1] > arr[i]) a++;
}
if (a == 0) {
cout << "yes" << endl << 1 << ' ' << 1;
return 0;
}
for (int j = 1; j < n; j++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e6 + 5;
int n, m, ans[mxN];
vector<int> a[mxN];
vector<pair<int, int> > add[mxN], del[mxN];
pair<int, int> seg[mxN];
int first[mxN];
void Upd(int pos) {
for (int i = pos; i < mxN; i |= i + 1) ++first[i];
}
int Get(int pos) {
int ans = 0;
for (int i = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool check_down(int i, int j, int n, vector<vector<int>> &dpc,
vector<vector<int>> &arr) {
if (i == n - 1) return false;
return dpc[i][j] - dpc[n - 1][j] != 0;
}
bool check_up(int i, int j, int n, vector<vector<int>> &dpc,
vector<vector<int... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int f, t, next, kind, id;
} e[200005 * 2];
int ecnt, head[200005];
int rv[4] = {0, 2, 1, 3};
void addedge(int f, int t, int kind, int id) {
e[++ecnt] = (edge){f, t, head[f], kind, id};
head[f] = ecnt;
e[++ecnt] = (edge){t, f, head[t], rv[kind], id};
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
const long long inf = 1e15 + 5;
struct point {
long long x, y;
};
bool operator<(const point A, const point B) {
if (A.x != B.x) return A.x < B.x;
return A.y < B.y;
}
bool operator==(const point A, const point B) {
if (A.x != B.x) return fa... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, s = 0, a[10003], h[100003] = {0};
for (i = 0; i < 5; i++) cin >> a[i], s += a[i], h[a[i]]++;
long long int ma = INT_MAX;
for (i = 0; i <= 100; i++) {
if (h[i] >= 2) {
ma = min(ma, s - min(h[i], 3ll) * i);
}
}
if (ma ==... | 1 |
#include <cstdio>
#define ll long long
ll mod = 1000000007;
ll big(ll b, ll p){
if (p == 1) return b;
ll h = big(b, p / 2);
ll res = (h * h) % mod;
if (p % 2 == 1) res = (res * b) % mod;
return res;
}
int main(){
ll n, k;
scanf("%lld %lld", &n, &k);
ll a[k + 1], ans = 0;
for (int i = k; i >= 1; i--){
a[i] = ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int r, s, p, da, keo, bao, sum, daconlai, keoconlai, baoconlai;
double dp[101][101][101], res;
int main() {
cin >> da >> keo >> bao;
dp[0][0][0] = 1.0;
for (int r = 0; r <= da; r++)
for (int s = 0; s <= keo; s++)
for (int p = 0; p <= bao; p++) {
if (... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, c, d, a, b, ans, cmax, dmax;
char type;
vector<pair<int, int> > coin_list, diamond_list;
void calc(vector<pair<int, int> > x, int avail) {
int sz = x.size();
if (sz < 2) return;
vector<int> vect(100007);
vect[0] = x[0].second;
for (int i = 1; i < sz; i++) v... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
map<int, int> mp;
map<int, int> id;
vector<pair<int, int> > a;
vector<int> b;
int n;
long long v[N];
void init() { memset(v, 0, sizeof v); }
int lowbit(int x) { return x & -x; }
void update(int pos, long long key) {
while (pos && pos < N) {
v[po... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long arr1[26], arr2[26][26];
int main() {
string str;
cin >> str;
int len = str.length();
for (int i = 0; i < len; i++) {
int c = str[i] - 'a';
for (int j = 0; j < 26; j++) arr2[j][c] += arr1[j];
arr1[c]++;
}
long long ans = 0;
for (int i = 0;... | 3 |
#include<bits/stdc++.h>
using namespace std;
#define ls p<<1
#define rs p<<1|1
typedef long long ll;
const int N=35005;
ll mx[N<<2],tag[N<<2];
void add(int p,int v){
mx[p]+=v,tag[p]+=v;
}
void pushup(int p){
mx[p]=min(mx[ls],mx[rs]);
}
void pushdown(int p){
if(tag[p]) add(ls,tag[p]),add(rs,tag[p]),tag[p]=0;... | 5 |
#include<iostream>
using namespace std;
int main(){
string s,t;
cin>>s;
cin>>t;
int ans = 0;
for(int i=0;i<s.size();i++){
if(s[i]!=t[i])ans++;
}
cout<<ans<<endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
char s;
cin>>s;
if(65<=s& s<=90){
cout<<'A';
}
else{
cout<<"a";
}
} | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using namespace std;
int main() {
string s;
cin >> s;
long long p, l =... | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef double f64;
const int MAX_N = 100000 + 5;
int n, a[MAX_N], l[MAX_N], r[MAX_N];
void solve() {
scanf("%d", &n);
for (int i = 1; i <= n; i ++) scanf("%d", a + i);
for (int i = l[1] = 1; ++ i <= n; )
if (a[i - 1] < a[i]) l[i] = l[i - 1] + 1;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
int a[maxn], n, m, k;
long long calc(int p) {
long long res = 0, sum = 0, mn = 0;
for (int i = 1; i <= n; i++) {
sum += a[i];
mn = min(mn, sum);
if ((i - p) % m == 0) res = max(res, sum - mn);
}
return res;
}
int main() {
scanf... | 4 |
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
double e[1001][51001];
double optimalBST(double p[],double q[],int n){
double w[1001][1001];
for(int i=1;i<=n+1;i++){
e[i][i-1]=q[i-1];
w[i][i-1]=q[i-1];
}
for(int l=1;l<=n;l++){
for(int i=1;i<=n-l+1... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& stream, const vector<T> v) {
stream << "[ ";
for (int i = 0; i < (int)v.size(); i++) stream << v[i] << " ";
stream << "]";
return stream;
}
long long fpow(long long x, long long p, long long m) {
long long r = 1;
f... | 1 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { ... | 2 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
vector<int> memo;
int kk = -1;
int dfs(const int now, const int from, const vector<vector<int>>& edges) {
int a = 0;
int b = 0;
int c = 0;
for (auto e : edges[now]) {
if (e == from)
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int mod = 1000000007;
int n;
cin >> n;
long long a = 1, b = 1;
for (int i = 2; i <= n; i++) {
a = (a * i) % mod;
b = (b * 2) % mod;
}
cout << (a - b + mod) % mod << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[300010];
bool vst[300010];
int dp[300010][2];
int root[300010];
int cnt[300010];
int dst[300010];
int find_root(int u) {
if (root[u] == u) return u;
return root[u] = find_root(root[u]);
}
void reunion(int u, int v) {
u = find_root(u);
v = find_root(v... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 3e5 + 5;
long long int tot[N], ending[N], ans, last, can[N];
vector<pair<long long int, pair<long long int, long long int>>> v;
vector<pair<long long int, long long int>> store;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
l... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[2000005];
vector<int> a[2000005];
vector<int> cf[2000005], cf2[2000005];
int check(int ans) {
for (int i = 0; i <= n + 1; i++) {
for (int j = 0; j <= m + 1; j++) {
cf[i][j] = cf2[i][j] = 0;
}
}
for (int i = 0; i <= n + 1; i++) {
for ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, k, num, cnt;
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> k;
for (int i = 1; i <= k; i++) {
vector<int> v;
int t;
cin >> t;
for (int j = 1; j <= t; j++) {
int x;
cin >> x;
v.push_back(x);
}
if (v[0] == 1) ... | 1 |
#include <bits/stdc++.h>
int colors1[150], colors2[150];
int main() {
int i, n1, n2, count = 0;
char owns[1005], needs[1005];
scanf("%s", owns);
scanf("%s", needs);
n1 = strlen(owns);
n2 = strlen(needs);
for (i = 0; i < n1; i++) {
colors1[owns[i]]++;
}
for (i = 0; i < n2; i++) {
colors2[needs[... | 2 |
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#inc... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int arraysize, numberOfSubarrays, firstIndex, lastIndex, cntr = 0;
cin >> arraysize >> numberOfSubarrays;
int theFinalArray[arraysize], mexs[numberOfSubarrays];
for (int i = 0; i < numberOfSubarrays; i++) {
cin >> firstIndex >> lastIndex;
mexs[i... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n;
int ans = 0, cnt = 0, divisor[1000006];
bool check(long long a, long long b, long long c) {
if (a + b <= c || a + c <= b || b + c <= a) return false;
if (((a + b - c) & 1) || ((a + c - b) & 1) || ((b + c - a) & 1)) return false;
return true;
}
int main() ... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using vec = vector<T>;
template <typename K, typename V>
using umap = unordered_map<K, V>;
template <typename K>
using u... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int v;
struct edge *next;
edge() {}
edge(int _v, edge *_next) : v(_v), next(_next) {}
};
edge *d[100005];
int init[100005], goal[100005];
int level[100005], sta[100005], pre[100005];
int que[100005], acc[100005];
void insert_edge(int u, int v) {
d[u]... | 3 |
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
while (cin >> n >> m, m) {
vector<int> seq(n);
for (int i = 0; i < n; ++i)
seq[i] = i + 1;
while (seq.size() > 1) {
rotate(seq.begin(), seq.begin() + (m - 1) % seq.size(), seq.end());
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
template <int jt>
struct ModInt {
int x;
ModInt(int v = 0) {
x = v;
if (x >= jt || x < 0) {
x %= jt;
if (x < 0) x += jt;
}
}
ModInt(long long v) {
x = v % jt;
if ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, count = 0;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long int mx = a[n - 1];
long long int mn = a[0];
for (int i = 1; i < n - 1; i++)
if (a[i] != mx && a[i] != mn) count++;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
long long a[n];
long long dmg = 0, cnt = 1, sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
dmg += a[i];
}
string s;
cin >> s;
for (int i = 0, j; i < n; i++) {
for (j = i + 1; j < n; j++)
if... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = (long long)INF * INF;
int cnt[26];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, k;
string S;
cin >> n >> k >> S;
for (int i = (0); i < (n); +... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (!a) return b;
return gcd(b % a, a);
}
long long mexp(long long a, long long b) {
long long ans = 1;
a %= 1000000007;
while (b) {
if (b & 1) ans = ans * a % 1000000007;
b >>= 1;
a = a * a % 1000000007;
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool isvis[1000005] = {0};
vector<int> link[1000005];
vector<long long int> vec;
void dfs(int n, int d) {
bool islf = true;
isvis[n] = true;
for (int i = 0; i < link[n].size(); i++) {
if (!isvis[link[n][i]]) {
islf = false;
dfs(link[n][i], d + 1);
... | 5 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int n,m;
while(cin >> n >> m , n + m){
vector<int> v;
int a;
for(int i = 0 ; i < n ; i++){
cin >> a;
v.push_back(a);
}
int size = v.size();
for(int i = 0 ; i < size ; i++){
for(i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tests;
cin >> tests;
while (tests--) {
int n;
cin >> n;
vector<vector<char>> t(n);
char c;
for (auto& i : t) {
for (int j = 0; j < n; ++j) {
cin >> c;
... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;cin>>n>>k;
vector<int >iis(k,0);
for(int i=0;i<n;i++){
int l;cin>>l;
for(int j=0,a;j<l;j++){
cin>>a;iis[a-1]++;
}
}
int tot=0;
for(int i=0;i<k;i++)if(iis[i]==n)tot++;
cout<<tot;
} | 0 |
#include <iostream>
#include <queue>
#include <climits>
using namespace std;
#define MOD 100000007
typedef pair<int,int> P;
int h, w;
int sx, sy, gx, gy;
int closed[1002][1002];
int minDist[1002][1002];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int main(){
while(cin >> h >> w >> sy >> sx >> gy >> gx){
... | 0 |
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
while(1) {
bool end = false;
int n;
cin >> n;
if(n == 0) return 0;
int w[n];
for(int i = 0; i < n; i++) {
string s;
cin >> s;
w[i] = s.size();
}
// for(int i = 0; i < n; i++)... | 0 |
#include <bits/stdc++.h>
int main() {
int n;
int i;
scanf("%d", &n);
if (n == 1) {
putchar('a');
return 0;
}
putchar('a');
putchar('a');
if (n == 2) return 0;
char prePrev = 'a';
char prev = 'a';
for (i = 3; i <= n; i++) {
if (prePrev == 'a') {
prePrev = prev;
prev = 'b';
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int loop_times, candy_number;
cin >> loop_times;
while (loop_times--) {
cin >> candy_number;
int x[candy_number + 1];
int f[candy_number + 1];
for (int i = 1; i <= candy_number; ++i) {
cin >> x[i];
}
f[0] = 0;
f[1] = x[1]... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int64_t mod = 1e9 + 7;
int64_t Prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
31, 37, 41, 43, 47, 53, 59, 61, 67};
int64_t n, res = 0, Pre[70], ff[16][16];
vector<int64_t> V[20], f[16][2][16];
void Init() {
Pre[1] = 0;
int64_t Count = 0;
f... | 3 |
#include <bits/stdc++.h>
using namespace std;
int s[100010];
int a[100010];
map<int, int> mx, my;
int main(void) {
int N, i;
cin >> N;
for ((i) = 0; (i) < (int)(N); (i)++) scanf("%d", &s[i]);
cout << "YES" << endl;
if (N == 1) {
cout << s[0] << endl << 0 << endl;
return 0;
}
for ((i) = 0; (i) < (i... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct p {
int u, v, w;
p() {}
p(int u, int v, int w) : u(u), v(v), w(w) {}
bool operator<(const p &right) { return this->w < right.w; }
};
int n;
string s1, s2;
map<pair<char, char>, int> M;
map<char, int> S;
int l, r;
int main() {
vector<int> ans;
string s;
... | 3 |
#include <bits/stdc++.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wc++11-extensions"
#pragma GCC diagnostic ignored "-Wunused-const-variable"
using namespace std;
void ain(vector<long long>& a) {
for (long long i = 0; i < (long long)a.size(); i++)... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n, mid;
int a[30], b[30], c[30];
map<pair<int, long long>, pair<int, long long> > h;
pair<int, long long> ans;
void dfs1(int step, long long sta, int A, int B, int C) {
if (step == mid + 1) {
pair<int, long long> tmp;
tmp = h[pair<i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string ans = "";
while(n != 0){
int t = n%(-2);
if(t == -1) t = 1;
ans.push_back('0'+t);
n = (n-t)/(-2);
}
if(ans.size() == 0) ans = "0";
reverse(ans.begin(),ans.end());
cout << ans << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
double n;
cin >> n;
double angle = 3.141592653589793238;
angle /= n;
angle /= 2;
double ans = tan(angle);
ans = 1 /... | 3 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * f;
}
int n, m, a[210][210], cnt[210][210], ax = 1... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long N = 2e6 + 100, OO = 1e7 + 7, M = 1e9 + 7, P = 49157, sq = 360,
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 2 * acos(0.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
template <c... | 5 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
int x = 0, y = 0;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '0') x++;
if (s[i] == '1') y++;
}
char c = s[s.length() - 1];
if (y < (s.length() + 1) / 2) cout << "00" << endl;
if ((y <= (s.length() + 1) / 2) && (... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
int n;
int N;
int a[maxn];
long long ans;
int dfs(int rt) {
int rc = rt << 1, lc = rt << 1 | 1;
int v1, v2;
if (rc > N) return a[rt];
v1 = dfs(rc);
v2 = dfs(lc);
ans += abs(v1 - v2);
return a[rt] + max(v1, v2);
}
int main() {
while ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str, s1, s2 = "<";
stack<char> delm;
vector<string> re;
getline(cin, str);
for (int i = 0; i < str.size(); i++) {
if (str[i] == '"' && delm.empty()) {
s1 = "<";
delm.push(str[i]);
} else if (!delm.empty()) {
char ch = ... | 2 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 50;
ll d[maxn << 2];
int lowbit(int x){
return x & (-x);
}
void update(int x, ll v){
for(int i = x;i < maxn;i += lowbit(i)){
d[i] += v;
}
}
ll query(ll x){
ll ans = 0;
for(int i = x; i;i -= lowbit(i)){
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9 + 7;
const int N = (int)2e5 + 4;
const int K = 21;
struct point {
int x, y;
point() { x = 0, y = 0; }
~point() {}
point(int x, int y) : x(x), y(y) {}
bool operator<(const point &a) const {
if (x == a.x) {
return y < a.y;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long ans;
long long d[107];
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
ans = (long long)-1e18;
for (long long i = 0; i < n; i++) {
for (long long j = i + 1; j <= n; j++) {
for (long long k = i + 1; k <= j; k++) {
d[k]++;... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> mp[200005];
set<pair<int, int> > aa;
int a[200005], v[200005], b[200005];
int n, s, t, w, k;
int find(int x, int y) {
int k = mp[y].size(), m = mp[y][k - 1], r = mp[x].size() - 1;
int l = 0;
while (l < r) {
int mid = (l + r) >> 1;
if (mp[x][mid] <=... | 4 |
#include <cstdio>
char ps[23];
int main()
{
scanf("%s",ps);
if(ps[2]==ps[3]&&ps[4]==ps[5]) printf("Yes");
else printf("No");
return 0;
} | 0 |
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 100000... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v;
vector<int>::iterator it;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
v.push_back(x);
}
vector<int> seq;
seq.push_back(-1);
string ans;
while (1) {
if (v.back() <= seq.back() && v[0] <= seq.... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a = (n * (n + 1) / 2);
cout << (a * 6) + 1;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string in, ans;
cin >> in;
int f = 0;
for (unsigned i = 0; i < in.length(); i++) {
ans += in[i];
f++;
i += f;
}
cout << ans;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int a[100][30010];
int n, s, j, k, v, t, maxn, ans, x;
int main() {
scanf("%d%d", &n, &s);
for (int i = 0; i < n; i++) {
scanf("%d", &k);
x = 0;
while (k--) {
scanf("%d%d", &v, &t);
while (t--) a[i][++x] = a[i][x - 1] + v;
}
if (x > maxn)... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 100;
int n;
char s[maxn][maxn];
char r1[maxn], c1[maxn];
char r2[maxn], c2[maxn];
int ans;
int main() {
scanf("%d ", &n);
for (int i = 0, _n = (int)(n); i < _n; i++) gets(s[i]);
for (int i = 0, _n = (int)(n); i < _n; i++)
for (int j = 0, _n... | 3 |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("template.in");
ofstream fout("template.out");
int main() {
int n, m;
cin >> n >> m;
string ar1[n], ar2[m];
for (long long i = 0; i < n; i++) {
cin >> ar1[i];
}
for (long long i = 0; i < m; i++) {
cin >> ar2[i];
}
int q;
cin >> q;
in... | 1 |
#include<bits/stdc++.h>
using namespace std;
int main(void){
int n;
while(cin >> n,n){
int k,s = 0,f = 0;
for(int i = 0; i < n; i ++){
cin >> k;
if(k >= 1) s++;
if(k > 1) f=1;
}
if(!f)cout << "NA" << endl;
else cout << s+1 << endl;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
if (a == b)
cout << -1;
else
cout << max(a.length(), b.length());
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
const int maxn = 1e5 + 5;
int n, f;
int k[maxn], l[maxn];
long long ans = 0;
vector<int> ve;
void solve() {
sort(ve.begin(), ve.end());
reverse(ve.begin(), ve.end());
for (int i = 0; i < ve.size(); i++) {
if (!... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int n, a, b;
int p[MAXN];
map<int, int> rp;
bool in_vec(int x, vector<int> &vec) {
for (int c : vec) {
if (x == c) return true;
}
return false;
}
struct TwoSAT {
int n;
vector<int> G[MAXN * 2];
int pre[MAXN * 2], lowlink[MAXN * 2], s... | 2 |
#include <bits/stdc++.h>
int fa[10000000 + 10];
inline long long gcd(long long a, long long b) {
while (a > 0) {
long long tmp = a;
a = b % a;
b = tmp;
}
return b;
}
inline int getfa(int a) { return (fa[a] == a) ? a : fa[a] = getfa(fa[a]); }
int n;
inline void m(long long a, long long b) {
if (fa[a]... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long sum[100005];
long long a[100005], b[100005];
int main() {
long long n, m, c;
while (cin >> n >> m >> c) {
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
sum[0] = 0;
for (int i = 1; i <= m; i++) sum[i] = sum[... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
bool f;
f = 0;
for (int j = 0; j < n; j++) {
int x;
cin >> x;
if (j != i && (x == -1 || x == 1 || x == 3)) f = 1;
}
if (!f) a.push_back(i + 1);
}
cou... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int LIM_N = 1e5 + 5;
int cnts[LIM_N];
const int inf = 1e9;
struct Node {
Node *l = 0, *r = 0;
int lo, hi, mset = inf, madd = 0, val = -inf;
Node(int lo, int hi) : lo(lo), hi(hi) {}
Node(vector<int>& v, int lo, int hi) : lo(lo), hi(hi) {
if (lo + 1 < hi) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int serial, sucess, fail;
int result1 = 0, result2 = 0;
while (cin >> serial >> sucess >> fail) {
if (serial == 1) {
result1 += sucess - fail;
} else {
result2 += sucess - fail;
}
}
result1 >= 0 ? cout << "... | 1 |
#include <bits/stdc++.h>
using namespace std;
int toInt(string s) {
int r = 0;
istringstream sin(s);
sin >> r;
return r;
}
long long int a[200005], l[200005], r[200005];
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
;
long long int n;
cin >> n;
for (long long int i = 0;... | 4 |
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
ll N;
map<ll,int>mp;
int res;
int main(){
cin>>N;
for(ll i=2;i*i<=N;i++){
while(N%i==0){
N/=i;
mp[i]++;
}
}
if(N!=1)mp[N]++;
for(pair<ll,int>p:mp){
for(int i=1;i<=p.second;i++){
res++;
p.second-=i;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[(int)(1e5) + 10];
bool cmp(string a, string b) {
if (a == "rock" and b == "scissors") return true;
if (a == "scissors" and b == "paper") return true;
if (a == "paper" and b == "rock")
return true;
else
return false;
}
int main() {
int n;
string sF,... | 1 |
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str;
for(int k=0;k<5;k++){
int a=0,b=0;
cin >> str;
if(str=="EOF") break;
for(int i=0;i<(int)str.size()-2;i++){
if(str[i+1]=='O'&&str[i+2]=='I'){
if(str[i]=='J') a++;
else if(str[i]=='I') b++;
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long getSum(long long n) { return !n ? 0 : (n % 10) + getSum(n / 10); }
bool is(long long n) { return (getSum(n) % 4) ? false : true; }
int main() {
ios_base::sync_with_stdio();
cin.tie(0);
cout.tie(0);
cin >> n;
if (is(n)) return cout << n << en... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
string s;
cin >> s;
long long int flag = 0, ans = 0;
for (long long int i = s.find('1'); i < s.find_last_of('1'); i++) {
if (s[i] == '0') ans++;
}
cout << ans << endl;
}
return 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int N = 100005;
struct mes {
char c;
int id;
};
int n, m;
bool no[N];
mes all[N];
int p[N];
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
cin >> all[i].c ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int ucln(int a, int b) {
int r;
while (b > 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
int main() {
int x, y, a, b, bc;
cin >> x >> y >> a >> b;
bc = x * y / ucln(x, y);
int l = a, r = b;
while (l % bc != 0) l++;
while (r % bc != 0) r--;
co... | 1 |
#include <bits/stdc++.h>
const int inf = 0xfffffff;
const long long INF = 1ll << 61;
using namespace std;
vector<int> G[100000 + 55];
int n;
int ans;
void init() {
for (int i = 0; i < 100000 + 55; i++) G[i].clear();
}
bool input() {
while (scanf("%d", &n) == 1) {
for (int i = 0; i < n; i++) {
int x, y;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int fun(int x) { return (x * (x - 1)) / 2; }
int main() {
int n, i, a[26], res, x, y;
string st;
for (i = 0; i < 26; i++) a[i] = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> st;
a[st[0] - 97]++;
}
res = 0;
for (i = 0; i < 26; i++) {
if (a[i]) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const int N = 5001;
int dp[N][26][26];
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int n = s.length();
for (int i = (int)(0); i < (int)(n); i++) {
int ch = s[i] - 'a';
for (int j = (int... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.