solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a < b ? a : b; }
int maxElement(int arr[], int n) {
int maxi = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] > maxi) maxi = arr[i];
}
return maxi;
}
int minElement(int arr[], int n... | 1 |
#include<bits/stdc++.h>
typedef long long ll;
#define mod 924844033
ll gi(){
ll x=0,f=1;
char ch=getchar();
while(!isdigit(ch))f^=ch=='-',ch=getchar();
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f?x:-x;
}
int pow(int x,int y){
int ret=1;
while(y){
if(y&1)ret=1ll*ret*x%mod;
x=1ll*x*x%mod;y>>=1;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int sum[10][2], diff[10][2];
int retans(int i, int j) {
return max(sum[i][1] - sum[j][0],
max(diff[i][1] - diff[j][0],
max(diff[j][1] - diff[i][0], sum[j][1] - sum[i][0])));
}
int main() {
for (int i = 0; i < 10; ++i) {
sum[i][0] = INT_... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long int mod = 998244353;
long long int power(long long int x, long long int y) {
long long int res = 1... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long inf64 = 1e18;
const long long MOD = inf + 7;
void solve() {
long long n;
cin >> n;
long long cnt = 0;
long long m = n;
while (n > 0) {
n = n / 10;
cnt++;
}
long long ans = cnt * (m + 1);
for (long long i = 0... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, q;
while (~scanf("%d%d%d", &n, &m, &q)) {
int i, j, l, k, a[5050], b[5050];
for (i = 0; i < n; i++) scanf("%d", &a[i]);
for (i = 0; i < m; i++) scanf("%d", &b[i]);
sort(a, a + n);
sort(b, b + m);
int ans = 0x7fffffff;
f... | 1 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n; cin >> n;
map<string,set<int>> mp;
string s; int d;
for(int i=0;i<n;i++){
cin >> s >> d;
mp[s].insert(d);
}
i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int NM = 200100;
long long l[NM], r[NM];
pair<pair<long long, long long>, int> seg[NM];
pair<long long, int> p[NM];
int ans[NM];
bool segCmp(pair<pair<long long, long long>, int> a,
pair<pair<long long, long long>, int> b) {
if (a.first.second != b.first... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> src;
vector<pair<int, int> > mat[100010];
pair<pair<int, int>, int> use;
int n, m, q, sparceT[20][100010], lev[100010], can[100010];
long long show[100010], dis[100010];
pair<int, int> query[100010];
queue<int> que;
void in(int u) {
if (!can[u]) src.push_back(... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005], tmp[100005], b[100005];
bool die[100005];
int n, m;
vector<long long> candidate;
bool solve(int pos) {
candidate.clear();
for (int i = 1; i <= n; i++)
if ((!die[i]) && (a[i] & (1ll << pos))) {
candidate.push_back(a[i]);
die[i] = true... | 3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
bool isHappy(int k) {
char s[64];
int len = sprintf(s, "%d", k);
for (int i = 0, _n = (len); i < _n; ++i)
if (s[i] != '4' && s[i] != '7') return false;
return true;
}
int n;
int d[100000];
int place[100000];
int d2[1000... | 4 |
#include <bits/stdc++.h>
using namespace std;
ifstream in("file.in");
ofstream out("file.out");
long long n, k, c[300005], ans, q[300005];
pair<long long, long long> t;
struct comp {
bool operator()(pair<long long, long long> a, pair<long long, long long> b) {
return a.first > b.first;
}
};
multiset<pair<long l... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, k, p, x, y, sum = 0, ctr = 0;
int A[1000];
int main() {
cin >> n >> k >> p >> x >> y;
for (int i = 0; i < k; i++) {
cin >> A[i];
ctr += A[i] < y;
}
int i;
vector<int> V;
for (i = 0; i < n - k && ctr < n / 2; i++, ctr++) {
sum++;
A[i + k] =... | 2 |
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define Max(a,b) a=max(a,b);
typedef long long ll;
using namespace std;
#define N 200010
ll n,m,a[N],cnt[N],sum[N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, i;
int main() {
cin >> a >> b >> c;
while (a >= b + c) {
b++;
i++;
}
while (b >= a + c) {
a++;
i++;
}
while (c >= a + b) {
a++;
i++;
}
cout << i;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
void read_file(bool outToFile = 0) {
freopen("in", "r", stdin);
if (outToFile) freopen("out", "w", stdout);
}
int n, m;
vector<int> odd;
vector<int> even;
vector<int> v[2 * (100 * 1035)];
int dist[2 * (100 * 1035)];
void bfs(int node) {
queue<int> q;
odd.clear();
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 5;
long long a[maxn];
int main() {
long long t;
cin >> t;
while (t--) {
long long n, k;
cin >> n >> k;
for (long long i = 1; i <= n * k; i++) scanf("%lld", &a[i]);
long long mid = (n + 1) / 2;
long long jian = n - mid +... | 2 |
#include <bits/stdc++.h>
using namespace std;
string s, ss;
int main() {
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '/') {
if (ss.size() == 0 || ss[ss.size() - 1] != '/') {
ss += s[i];
}
} else
ss += s[i];
}
if (ss[ss.size() - 1] == '/') ss.erase(ss.size() - 1... | 1 |
#include <bits/stdc++.h>
using namespace std;
int memo[5004][5004];
int maxk[5004][5004] = {0}, cnt[5004] = {0};
int main() {
char str[5004];
scanf("%s", str);
int n = strlen(str);
for (int i = 0; i < n; i++) {
long long int h = 0, rh = 0, p = 47, pw = 1;
for (int j = i; j < n; j++) {
int v = str[... | 4 |
#include <bits/stdc++.h>
/**
* Code by: Om Kumar
* Dated: 7/11/21
*/
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define rep(i, n) for(int i = 0; i < n; i++)
#define run(i, a, b) for(int i = a; i < b; i++)
#define cinarr(arr, n) rep(_i, n) cin >> arr[_i]
#define cinset(st, n) int _t; rep(i, n) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)
int const N = 3500, M = 2500000;
int x[N + 1], fr[M + 1];
vector<pair<int, int> > v[M * 2 + 1];
int main(){
int n;
scanf("%d", &n);
n = min(n, N);
int a = 0, b = 0;
f(i, 1, n + 1){
scanf("%d"... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
struct sofa {
int x1, y1, x2, y2;
int minx() { return min(x1, x2); }
int maxx() { return max(x1, x2); }
int miny() { return min(y1, y2); }
int maxy() { return max(y1, y2); }
};
sofa sofas[maxn];
int cntup[maxn], cntdo[maxn], cntle[maxn], c... | 3 |
#include <bits/stdc++.h>
const int inf = (int)1e9;
const int mod = 1e9 + 7;
using namespace std;
int a[111][111], n, m, q;
struct query {
int type;
int x, y, z;
} t[100011];
bool u[111][111];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> q;
for (int i = 1; i <= q; i++) {
int ty... | 2 |
#include <bits/stdc++.h>
using namespace std;
int ques(int a, int b) {
printf("? %d %d\n", a, b);
fflush(stdout);
int rep = 0;
scanf("%d", &rep);
assert(rep != -2);
return rep;
}
int main() {
int c = 0, d = 0;
int a = 0, b = 0;
int i = 29;
while (i >= 0) {
printf("? %d %d\n", a, b);
fflush(s... | 4 |
#include <bits/stdc++.h>
const int N = 80;
int cnt[3], id[3][N], sum[3][N];
int dp[N][N][N][2], n;
std::string s;
void down(int &x, int y) { x = std::min(x, y); }
int calc(int i, int j, int k, int id) {
int ret = 0;
if (sum[0][id] > i) ret += sum[0][id] - i;
if (sum[1][id] > j) ret += sum[1][id] - j;
if (sum[2]... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long dpdpd[300002][3];
vector<long long> resss;
int32_t main() {
long long counter454646 = 0, counter4546461488484 = 0;
long long n, m, currrrcururu = 0;
cin >> n >> m;
resss.resize(n);
for (long long i = 0; i < m; i++) {
long long a, b, distdtit;
cin... | 4 |
#include<bits/stdc++.h>
using namespace std;
int main() {
int64_t a, b, x;
cin >> a >> b >> x;
cout << (b/x) - (a+x-1)/x +1;
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n, m;
cin>>n>>m;
int ans = (n*(n-1))+(m*(m-1));
cout<<ans/2;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> p;
vector<int> v[1000];
vector<char> have;
int t[300];
int ih = 0;
bool mark[1000];
char C[1005];
bool dfs(int now, int n, char c) {
mark[now] = true;
for (int i = 1; i * p[now] <= n; i++) {
if (C[i * p[now]] != c) {
if (t[c] <= 0) return false;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int const ans[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
int t, n, total, places[100][100], points[100];
string st, names[100];
map<string, int> mas;
int get_point(int j) {
if (j < 10) return ans[j];
return 0;
}
int get_num(string st) {
map<string, int>::iterator iter... | 2 |
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef double db;
db dist(db x1,db y1,db z1,db x2,db y2,db z2){
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
}
const db INF=(db)(1<<30);
db G[100][100];
db mindist[100];
bool used[... | 0 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> stk[100100];
int tt;
int main() {
int n, ans = 0, x;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int tmp = 0;
scanf("%d", &x);
while (tt > 0 && stk[tt].first < x) {
tmp = max(tmp, stk[tt].second);
tt--;
}
stk[++tt] = ... | 4 |
#include <bits/stdc++.h>
int main() {
long long int i, k, n, w;
scanf("%lld %lld %lld", &k, &n, &w);
if (((k * w * (w + 1)) / 2) < n) {
printf("0");
} else {
i = (k * w * (w + 1)) / 2 - n;
printf("%lld", i);
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
;
double n, b;
int a;
cin >> n >> a >> b;
int ans = ceil((n * b) / 100) - a;
if (ans <= 0)
cout << 0;
else
cout << ... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool has[305][305];
int ll[305], lr[305], n, w[305];
bool vis[305];
bool dfs(int u) {
if (vis[u]) return false;
vis[u] = true;
for (int v = 0; v < n; v++)
if (has[u][v] && (lr[v] == -1 || dfs(lr[v])))
return ll[u] = v, lr[v] = u, true;
return false;
}
stru... | 5 |
#include <bits/stdc++.h>
using namespace std;
string second, t;
vector<pair<int, int> > strA, strB;
bool swp;
int calc(int a, int b, int sm) {
if (a < b) swap(a, b);
if (sm) {
return max(a - 1, b);
} else {
return a - 1;
}
}
pair<int, int> lstA() { return strA[strA.size() - 1]; }
pair<int, int> lstB() {... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
int dblcmp(double d) {
if (fabs(d) < eps) return 0;
return d > eps ? 1 : -1;
}
int n;
int c[111111], s[111111];
vector<pair<int, int> > a[111111];
map<int, int> v;
int b[111111];
set<pair<long long, int> > p[111111]... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long segTree[26][400005];
long long arr[100005];
long long lazy[26][400005];
long long n, m, t, l, r, x;
void Build(long long pos, long long low, long long high, long long bit) {
if (low == high) {
segTree[bit][pos] = (arr[low] == bit ? 1 : 0);
return;
}
... | 5 |
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#define m_p make_pair
#define p_b push_back
#define m1 first
#define m2 second
#define N 100010
using namespace std;
typedef pair<int,int> pa;
vector<pa> a;
vector<int> b;
priority_queue<int,vector<int>,greater<int> >pq;
int n,m,pos,tpos,ans;
int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
struct node {
int a, b, c, d, e;
} nodes[maxn];
bool vis[maxn];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d%d%d%d%d", &nodes[i].a, &nodes[i].b, &nodes[i].c, &nodes[i].d,
&nodes[i].e);
}
long long te... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
const long double pi = 2.0l * acosl(0.0l);
cin >> t;
while (t-- != 0) {
int n;
cin >> n;
long double n2 = (long double)(n);
long double d = (180.0l / n2);
long double ans = 0.0l;
for (int i = (-n / 2); i <= n / 2; i++) {
... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
template <class T>
using vec = std::vector<T>;
template <class T>
using vec2d = std::vector<std::vector<T>>;
template <class T>
vec2d<T> makeVec2d(const int n1, const int n2, const T initValue) {
retu... | 1 |
#include <bits/stdc++.h>
using namespace std;
string arr2[] = {"C", "N", "D", "V", "E", "F", "W", "G", "X", "A", "B", "H"};
vector<string> vec;
int Place(char a) {
stringstream ss;
string s;
ss << a;
ss >> s;
for (int i = 0; i < 12; i++) {
if (s == arr2[i]) {
int x = i + 1;
return x;
}
}... | 1 |
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
const int inf = (int)1e9 + 7;
const double eps = 1e-7;
const double pi = 3.14159265359;
const int N = 5e3;
int n, a[N], max_cnt;
pair<int, int> dp[N + 1][N / 2 + 1][2];
bool used[N + 1][N / 2 + 1][2];
pair<int, int> d(int n, int cnt... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long MOD = 998244353;
inline long long add(long long x, long long y) {
x += y;
if (x >= mod) x -= mod;
return x;
}
inline long long sub(long long x, long long y) {
x -= y;
if (x < 0) x += mod;
return x;
}
inline long lon... | 5 |
#include <bits/stdc++.h>
const int MAXQ = 262144;
long long tree[MAXQ * 2 + 10];
long long btree[MAXQ * 2 + 10];
void tree_change(int v, int val, int l, int r, int pos, int limit) {
if (l == r) {
tree[v] = ((limit) < (tree[v] + val) ? (limit) : (tree[v] + val));
return;
}
int tm = (l + r) >> 1;
int lchi... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long f(long long s, long long e) {
return e * (e + 1) / 2 - s * (s - 1) / 2;
}
int num[100005];
vector<int> V[100005];
int main() {
long long N, S;
scanf("%lld%lld", &N, &S);
if (S < N) {
puts("No");
return 0;
}
S -= N;
if (S > N * (N - 1) / 2 || ... | 3 |
#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > ss;
struct Node {
int l, r, ope;
bool operator<(const Node &b) const {
if (l != b.l) return l < b.l;
return ope > b.ope;
}
};
Node a[200010];
int num[100010], ans[100010];
int main() {
int n, m;
scanf("%d", &n);
for (int i = 0; i < n... | 3 |
#include<iostream>
using namespace std;
int main(void)
{
int n;
cin >> n;
long long ans=1;
for(int i=1;i<=n;i++)
{
ans*=i;
ans%=1000000007;
}
cout << ans << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int N;
long long pre[1000005];
long long solve(long long k) {
long long ret = 0;
for (int i = 1; i <= N; i++) {
ret += min(pre[i] % k, k - pre[i] % k);
}
return ret;
}
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin >> N;
for (int i = 1; i <= N; i++... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct crew {
string name;
string gender;
int key;
int ro;
};
bool serial(crew a, crew b) {
if (a.key != b.key) {
return a.key < b.key;
}
return (a.ro < b.ro);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long t, r = 1, r1 = 0, r2 = 0, k ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1100000;
long long dp[maxn];
long long a[maxn];
long long tmp[maxn];
long long refer[maxn];
long long cnt[maxn];
long long n, l, k;
long long cal(long long i, long long j) { return i * k + j; }
int main() {
scanf("%I64d%I64d%I64d"... | 2 |
#include <bits/stdc++.h>
using namespace std;
int p[300007][4];
int q[1507][3];
vector<int> z[1507 * 1507 / 2 + 1][2];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int fd(vector<int>& k, int v) {
int f = 0, t = k.size() - 1;
for (; f <= t;) {
int mid = (f + t) / 2;
if (k[mid] < v)
f = ... | 4 |
#include <algorithm>
#include <iostream>
#include <iterator>
#include <limits>
#include <sstream>
#include <vector>
using namespace std;
int main() {
cin.ignore(numeric_limits<streamsize>::max(), '\n');
string s;
getline(cin, s);
istringstream is{s};
istream_iterator<int> ii{is}, eol;
vector<int> v{ii, eol... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int d[10005];
long long g, r;
int dist[10005][1005];
int b[10005][1005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cerr.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++) cin >> d[i];
d[m + 1] = n;
sort(d + 1, d + m +... | 5 |
#include <bits/stdc++.h>
using namespace std;
void _fill_int(int* p, int val, int rep) {
int i;
for (i = 0; i < rep; i++) p[i] = val;
}
signed long long GETi() {
signed long long i;
scanf("%lld", &i);
return i;
}
int C, D, N, M, K;
void solve() {
int f, i, j, k, l, x, y;
cin >> C >> D >> N >> M >> K;
in... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[100000];
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i];
int i = 1;
while (k > i) {
k -= i++;
}
cout << a[--k];
return 0;
}
| 2 |
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int N,M,cap;
int main()
{
while(cin>>N>>M>>cap,N)
{
map<string,int>MM;
vector<pair<pair<int,int>,int> >E;
string start,goal;
cin>>start>>goal;
MM[start]=0;MM[goal]=1;
int sz=2;
for(int i=0;i<N;i++)... | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int k[1005];
const LL mod=1e9+7;
int main()
{
int n;
cin>>n;
for(int i=2;i<=n;i++)
{
int l=i;
for(int j=2;j<=l;j++)
{
while(l%j==0)
{
k[j]++;
l/=j;
}
}
if(l) k[l]++;
}
LL sum=1;
for(int i=2;i<=n;i++)
{
if(k[i])
{... | 0 |
#include<bits/stdc++.h>
using namespace std;
int n,ans=0;
void dfs(long long x){
if(n<x) return;
string s=to_string(x);
if(count(s.begin(),s.end(),'3') && count(s.begin(),s.end(),'5') && count(s.begin(),s.end(),'7')){
ans ++;
}
dfs(10*x+3);
dfs(10*x+5);
dfs(10*x+7);
return;
}
int main(){
cin >> n... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
for (int y = 0; y < q; y++) {
string s, t;
cin >> s >> t;
if (s.size() != t.size()) {
cout << "NO";
} else {
int flag = 0;
for (int i = 0; i < s.size(); i++) {
for (int i1 = 0; i1 < s.size(); i1++... | 2 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int a = 0, b = 0;
string s;
cin >> s;
for (auto &i : s) {
if (i == '1') {
a++;
} else {
b++;
}
}
if (min(a, b) & 1) ... | 2 |
#include <bits/stdc++.h>
void print_wrong(int N) {
if (N < 6) {
std::cout << -1 << std::endl;
return;
}
for (int i = 2; i <= 4; ++i) {
std::cout << 1 << ' ' << i << std::endl;
}
for (int i = 5; i <= N; ++i) {
std::cout << 2 << ' ' << i << std::endl;
}
}
void print_right(int N) {
for (int i... | 3 |
#include <bits/stdc++.h>
using namespace std;
void problem() {
int testcases;
cin >> testcases;
while (testcases--) {
int number;
cin >> number;
string siva = "";
for (int i = 0; i < number; i++) {
siva += "()";
}
int l = 2 * number;
cout << siva << "\n";
for (int i = 1; i < ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
long long r;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
struct Dinic {
int n, s, t, E, adj[150005], flow[150005], cap[150005], ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int sieve[1000000], large[1000000];
int main() {
long long int n, m, max = 0, i, j, cou = 0;
cin >> n;
cin >> m;
vector<vector<long long int> > v(n, vector<long long int>(m));
for (i = 0; i < n; i = i + 1) {
for (j = 0; j < m; j = j + 1) {
cin ... | 2 |
#include <bits/stdc++.h>
const long long Inf = 1ll << 50;
const long long N = 200010;
using namespace std;
long long cl[2 * N], b, c, d, i, j, k, l, n, ans, a[N], y, kk;
int main() {
scanf("%I64d%I64d", &n, &k);
for (i = n + 1; i > 0; i--) scanf("%I64d", &a[i]);
memset(cl, 0, sizeof(cl));
cl[0] = a[0] = 0;
fo... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, cnt;
int f[200050], L[400050];
struct edge {
int u, v, l;
} e[400050];
bool cmp(int x, int y) {
return L[x] < L[y] ||
(L[x] == L[y] && (min(e[x].u, e[x].v) < min(e[y].u, e[y].v)));
}
int id[200050];
bool used[200050];
int findroot(int x) {
if (f[... | 5 |
#include<stdio.h>
#include<algorithm>
using namespace std;
pair<int,int> event[5000000];
int now[100001];
int main(){
int a,b;
scanf("%d%d",&a,&b);
int at=0;
for(int i=1;i<=a;i++){
event[at++]=make_pair(i-b+1,i);
event[at++]=make_pair(i+1,-i);
for(int j=1;j*j<=i;j++){
if(i%j==0){
int c=i/j;
if(j<b)... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int>> gph, rph;
long long int n, m;
long long int vis[1000001], del[1000001];
void calc(long long int curr) {
while (curr <= n && del[curr]) curr++;
if (curr > n) return;
vis[curr] = 1;
for (auto &it : gph[curr]) del[it] = 1;
calc(curr + 1)... | 3 |
#include <bits/stdc++.h>
using namespace std;
void time_start(clock_t *tt) { *tt = clock(); }
void print_time(clock_t tt) {
tt = clock() - tt;
printf("executed in %.f ms\n", (float)tt / CLOCKS_PER_SEC * 1000);
}
template <typename T>
inline T getnum() {
T num = 0;
char c;
do {
c = getchar();
} while (c ... | 4 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,d;
while(cin>>a>>b>>c>>d,a){
int ans=0;
while(a/b<c) ans++,a+=d;
cout<<ans<<endl;
}
return 0;
} | 0 |
///verified by maroon_rk
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned;
using ll = long long;
using ull = unsigned long long;
#define int ll
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= a; i--)
#defin... | 0 |
#include<iostream>
int main(){
int N;
scanf("%d",&N);
printf("%d",N*N*N);
} | 0 |
#include<iostream>
#include<algorithm>
using namespace std;
long MOD=998244353;
long n,k,i,ans[2002],p2[2001]={1},C[4001][4001];
long f(long t)
{
long p=0,ans=0;
for(int i=1;i<=k&&t-i<=k&&i<t-i;i++)p++;
for(long q=0;q<=p;q++)
{
long now=p2[q]*C[p][q]%MOD;
long a=k-2*p+q-!(t%2),b=n-q;
if(a+b-1>=0&&b>=0)
{
... | 0 |
#include <bits/stdc++.h>
int main() {
int n, m, sum, a, b, c, max;
while (~scanf("%d", &n)) {
sum = max = 0;
while (n--) {
scanf("%d %d", &a, &b);
sum -= a;
sum += b;
if (sum > max) max = sum;
}
printf("%d\n", max);
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
const int N = 2e2 + 10, M = 1e4 + 10;
int x, y, n, m, ans, s, t, mark[M], vis[N], adj[N][N];
bool dfs(int v) {
vis[v] = 1;
if (v == t)
return 1;
for (int i = 0; i < n; i++) {
if (adj[v][i] == -1)
continue;
if (!vis[i] && df... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, X;
cin >> n >> X;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
sort(v.begin(), v.end());
int pos = (v.size() + 1) / 2;
pos--;
if (v[pos] == X) {
cout << 0 << endl;
return 0;
}
int cont = 0;
while (1) {
v.pu... | 3 |
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
int memo[10001],color[10001];
stack<int> numb;
vector<int> connect[10001],rconnect[10001];
void dfs(int i){
if(memo[i]!=0) return;
memo[i]=1;
lp(j,connect[i].size()){
dfs(connect[i][j]);
}
numb.push(i);
return;
}
void rd... | 0 |
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#in... | 0 |
#include <bits/stdc++.h>
const size_t ioSize = 1 << 21;
char oBuf[ioSize], *oS(oBuf), *oE(oBuf + ioSize);
inline void flush() {
fwrite(oBuf, 1, oS - oBuf, stdout);
oS = oBuf;
}
inline void putc(char c) {
*oS++ = c;
if (oS == oE) flush();
}
void puti(int x) {
static char qu[20];
char *qr = qu;
do *qr++ = x... | 4 |
#include<iostream>
#include<string>
#include<cstdio>
#define P pair<int,string>
using namespace std;
int main()
{
int a, b;
while (cin >> b>>a, a | b) {
int c[100]{};
for (int d = 0; d < a; d++) {
char e; cin >> e;
if (e == 's') {
int f, g; cin >> f >> g; f++;
int s = 0;
for (int i = 0; i < b; ... | 0 |
#include <iostream>
#include <set>
#define MAX(a,b) ((a>b)?(a):(b))
using namespace std;
int main(void){
int n,m;
int a;
while(cin>>n>>m,n||m){
std::multiset<int> ms;
for(int i=0;i<n+m;i++)cin>>a,ms.insert(a);
int m=*(ms.begin());
for(__typeof(ms.begin()) it=++ms.begin(),b=ms.begin();it!=ms.end();it++,b++){... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct node {
int x, y, id;
void scan() {
scanf("%d%d", &x, &y);
if (x > y) swap(x, y);
}
} e[N * 5], q[N], tmp[N], ee[N * 5];
struct opt {
int x, y, sz, f;
long long ans;
} op[N * 5];
int T;
int ext;
int cnt, now, tot, n, m, qu, bs... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long qpow(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) res = res * a % 1000000007;
a = a * a % 1000000007;
b >>= 1;
}
return res;
}
int main() {
scanf("%d", &n);
bool flag = 0;
long long inv3 = qpow(3, 100000000... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
vector<int> edges[MAX];
int arr[MAX];
int sol = 0;
bool dfs(int a, int prev) {
bool res = true;
for (auto e : edges[a]) {
if (e == prev) continue;
if (dfs(e, a)) res = false;
}
if (res) {
sol++;
if (a > 1)
swap(arr[a], ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
in >> a.first >> a.second;
return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
out << a.first << " " <<... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long a[534567], b[534567], c[534567], d, e, i, j, m, k, x, y, z, l, n, s,
t, tt;
pair<long long, long long> p[512345], q, qq;
int main() {
cin >> n >> m;
t = 1000000007;
x = 1;
y = 2;
while (m > 0) {
if (m % 2 == 1) x = x * y % t;
y = y * y % t;
... | 2 |
#include <cstdio>
#include <cstdint>
#include <cctype>
#include <cassert>
#include <vector>
#include <algorithm>
#include <string>
#include <stdexcept>
intmax_t apply(intmax_t lhs, char op, intmax_t rhs, intmax_t p) {
switch (op) {
case '+': return (lhs+rhs) % p;
case '-':
lhs -= rhs;
if (lhs < 0) lhs +=... | 0 |
#include <iostream>
#include <utility>
#include <vector>
enum {
Hanako = 0,
Taro = 1
};
int main() {
int n;
while (std::cin >> n, n) {
std::vector<std::pair<bool, bool>> hand(n * 2);
for (int i = 0; i < n; ++i) {
int c;
std::cin >> c;
hand[c - 1].first = Taro;
}
int remain[2] = { n, n };
bool... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
const int MAX_L = 20;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;
void solve() {
int a, b, x, y, n;
cin >> a >> b >> x >> y >> n;
long long ans = 1e18;
for (int i = 0; i < 2; i++) {
int da = min(n, a - x);
int db ... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<string> split(const string &s, char c) {
vector<string> v;
stringstream ss(s);
string first;
while (getline(ss, first, c)) v.emplace_back(first);
return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vec... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long mx = 0, mn = 1e9 + 9, l, r, mid, ans = 1e18;
vector<long long> arr(1e5 + 5);
bool solve(long long rounds) {
long long cnt = 0;
for (int i = 1; i <= n; ++i) {
cnt += rounds - arr[i];
}
return cnt >= rounds;
}
int main(void) {
ios ::sync_with_st... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, w;
while (cin >> n >> w, n + w){
int cnt[11] = {0};
int m = 0;
int l = 0;
for (int i = 0; i < n; i++){
int v;
cin >> v;
cnt[v / w]++;
m = max(m, cnt[v / w]);
l = max(l, v / w);
}
double res = 0.01;
for (int i = 0; i <= ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
long long a[N], b[N];
int n, m, par[N];
vector<tuple<long long, int, int>> edges;
inline int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
bool unite(int u, int v) {
u = find(u), v = find(v);
if (u == v) return 0;
if (rand() & 1... | 5 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n, x; cin >> n >> x;
int a[n];
for (int i = 0; i < n; ++i)
cin >> a[i];
sort(a, a+n);
int c = 0;
for (int i = 0; i < n; ++i)
{
x -= a[i];
if (x >= 0) c++;
else break;
}
if (x > 0) c--;
cout << c << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long int a[200004];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie();
cout.tie();
;
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
for (long long int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long lon... | 2 |
#include <bits/stdc++.h>
int main() {
static int aa[200000], dp[200000 + 1], dq[200000], dr[200000], qu[200000];
int n, i, cnt;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &aa[i]);
dp[0] = n % 2 == 0 ? 1 : 998244353 - 1;
cnt = 0;
for (i = 0; i < n; i++) {
int q = dp[i];
while (cnt && aa[q... | 6 |
#include <vector>
#include <iostream>
#include <map>
#include <algorithm>
#include <random>
#include <complex>
#include <unordered_map>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b) {
a = abs(a); b = abs(b);
if (a == 0) return b;... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.