solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int Nx = 200005;
int ct[Nx], MMsize, A, B, tree[Nx * 4];
map<int, int> MM;
vector<int> pos[Nx];
int query(int a, int b, int key) {
if (A <= a && b <= B) return tree[key];
if (B < a || b < A) return 0;
int m = (a + b) / 2;
return query(a, m, key * 2) + query(m ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 61;
int n;
int x[15][15];
int main() {
memset(x, 0, sizeof(x));
for (int i = 1; i <= 10; i++) x[i][1] = x[1][i] = 1;
for (int i = 2; i <= 10; i++) {
for (int j = 2; j <= 10; j++) {
x[i][j] = x[i - 1][j] + x[i][j - 1];
}
}
... | 1 |
#include <iostream>
using namespace std;
int main() {
string x;
cin >> x;
for (int i = 0 ; i < int(x.size()); i++){
cout << "x";
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int buffer_size = 1 << 20;
int rd_char() {
static char buf[buffer_size];
static int l = buffer_size, r = buffer_size;
if (l == r && r == buffer_size) {
r = fread(buf, sizeof(char), 1 << 20, stdin);
l = 0;
}
if (l == r) return EOF;
return buf[l++];
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int size = 120004;
const long long inf = 1e18;
const long long modulo = 1000000007;
int main() {
int n, k;
cin >> n >> k;
vector<size_t> net(n);
for (int i = 0; i < n; i++) {
size_t a, b, c, d;
scanf("%d.%d.%d.%d", &a, &b, &c, &d);
net[i] = (a << 2... | 3 |
#include <bits/stdc++.h>
char s[100001];
int main() {
scanf("%s", s);
int len = strlen(s);
int las = 0;
int i, j;
for (i = 25; i >= 0; i--) {
for (j = las; j < len; j++) {
if (s[j] == 'a' + i) {
las = j + 1;
printf("%c", s[j]);
}
}
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
while (cin >> s) {
map<string, int> a;
for (int i = 0; i < 10; i++) {
string buf;
cin >> buf;
a[buf] = i;
}
for (int i = 0; i < 8; i++) {
cout << a[s.substr(10 * i, 10)];
}
cout << endl;
}
}
| 1 |
#include <bits/stdc++.h>
const long long N = 110;
const long long mod = 1e9 + 7;
using namespace std;
int a[N][N];
int raw[N], arrange[N];
int main() {
int n, m, i, j;
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++) raw[i] = 1;
for (i = 1; i <= m; i++) arrange[i] = 1;
for (i = 1; i <= n; i++)
for (j = 1; ... | 2 |
#include<bits/stdc++.h>
using namespace std;
int n,d;
int main()
{
while(cin>>n>>d)
cout<<ceil(1.0*n/(2*d+1))<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
int n; cin>>n;
ll sum=0;
vector<ll> num(n);
for(int i=0;i<n;i++){
ll a,b; cin>>a>>b;
num[i]=a+b;
sum+=b;
}
sort(num.rbegin(),num.rend());
ll ans=0;
for(int i=0;i<n;i+=2){
ans+=num[i];
}
cout<<ans-sum<<endl... | 0 |
#include<bits/stdc++.h>
using namespace std;
const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
if(H==T) return -1;return *H++;
}
inline int read()
{
int x=0;char c=Get();
while(!isdigit(c)) c=Get();
while(isdigit(c)) x=x*10+c-'0',c=Get();
return x;
}
const in... | 0 |
#include<bits/stdc++.h>
using namespace std;
const int N=605;
int n,m;
vector<int> g[N];
double dp[N];
double calc(int id){
for(int u=n-1;u>=1;--u){
double sum=0,Max=0;
int cnt=0;
for(int i=0;i<(int)g[u].size();++i){
int v=g[u][i];
sum+=dp[v]+1;
Max=max(... | 0 |
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
int n, m, mini, rev;
int ans[1 << 20], cnt[1 << 20], val[1 << 20], num[1 << 20];
char ch[21][100010];
inline int get_val(int x) {
int sum = 0;
for (int j = 1; j <= n; j++)
if (x & (1 << (j - 1))) sum++;
return min(sum, n - sum);
}
inline v... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};
int n, m, V, tt;
vector<int> adj[maxn];
int p[maxn];
int mark[1005][1005], idx[1005][1005];
bool vis[1005][1005];
int mat[1005][1005];
int gcd(int a, int b) { return b == 0 ? a : gcd... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e18;
const long long int mod = 1e9 + 7;
const long long int MOD = 998244353;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c *x) -> decltype(cerr << *x... | 2 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
void chmax(int &a, int b) { a = max(a, b); }
int n;
int r[1000], w[1000];
bool dp[1001][1001];
void toSort() {
typedef pair<int, int> P;
vector<P> vec;
for (int i = 0; i < ... | 0 |
#include <bits/stdc++.h>
using namespace std;
class compare {
public:
bool operator()(pair<long long, long long> a, pair<long long, long long> b) {
if (a.first > b.first) return true;
return false;
}
};
bool comp(long long a, long long b) { return a > b; }
long long power(long long a, long long b) {
long... | 2 |
#include<iostream>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;
struct Point{
double x;
double y;
};
int main()
{
Point p1,p2;
cin>>p1.x>>p1.y>>p2.x>>p2.y;
int q;
cin>>q;
vector<Point> pp(q);
for(int i=0; i<q; i++){
cin>>pp[i].x>>pp[i].y;
}
do... | 0 |
#include <bits/stdc++.h>
using namespace std;
int sol(int a, int b, int p, string s) {
int cost = s[s.size() - 2] == 'A' ? a : b;
if (cost > p) return s.size();
for (int i = s.size() - 2; i > 0; i--) {
if (s[i - 1] != s[i]) {
cost += s[i - 1] == 'A' ? a : b;
if (cost > p) return i + 1;
}
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005], f[100005];
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n ; ++i)
scanf("%d", &a[i]), ++f[a[i]];
int Max = 0;
for(int i = 1; i <= 100000 ; ++i)
Max = max(Max, f[i] + f[i - 1] + f[i + 1]);
printf("%d", Max);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n, x, ans = 0;
cin >> n;
map<long long,long long> freq;
for(int i=0; i<n; i++)
{
cin >> x;
ans += freq[i-x];
freq[i+x]++;
}
cout << ans << "\n";
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<int>A;
long long int n,ai,sum=0;
cin>>n;
for(int i=0;i<n;i++){
cin>>ai;
A.push_back(ai);
sum+=ai;
}
int x=sum/n;
int y=ceil(sum*1.000/n);
long long int c=0,d=0;
for(int i=0;i<n;i++){
c+=pow(A[i]-x,2);
d+=pow(A[i]-y,2);
}
cout<<min(c,d)... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N(1e5 + 21);
struct hh {
int v, nxt;
} edges[N * 2];
int n, en, point[N], sz[N];
double pu[N], pv[N], au, av, su[N], sv[N], ans;
inline void addedge(int u, int v) {
edges[++en] = (hh){v, point[u]};
point[u] = en;
}
inline void dfs(int x, int fa) {
sz[x] = ... | 5 |
#include <bits/stdc++.h>
int main() {
int t, n, i, j;
scanf("%d", &t);
for (i = 0; i < t; i++) {
scanf("%d", &n);
for (j = 2; j <= n + 1; j++) printf("%d ", j);
printf("\n");
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v(0);
int main() {
int n, l, x, y;
cin >> n >> l >> x >> y;
for (int i = (0); i < (n); i++) {
int tmp;
cin >> tmp;
v.push_back(tmp);
}
bool isx = false, isy = false, isxpy = false, isxmy = false;
int xpyp = -1, xmyp = -1;
int fxmyp = -1... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> jumps[3];
int dp[3][7010], cont[3][7010];
bool vis[3][7010];
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
int n, k1, k2;
cin >> n;
cin >> k1;
for (int i = 0; i < k1; i++) {
int val;
cin >> val;
jumps[0].push_back(val);
}
cin >... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string x, z;
vector<int> y;
int f = -1;
vector<int> v(1200, 0);
while (cin >> z) x += z;
for (int i = 0; i < (int)x.size(); i++) {
if (x[i] == '<') {
string s = "";
i++;
while (x[i] != '>') {
s += x[i];
i++;
... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main() {
int h, w;
cin >> h >> w;
vector<string> a(h);
for (auto& e : a) cin >> e;
cout << string(w+2, '#') << endl;
for (auto& e : a) cout << '#' << e << '#' << endl;
cout << string(w+2, '#') << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long sum = n * (n + 1) / 2;
if (sum % 2 == 0)
cout << "0";
else
cout << "1";
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxs = 1000005;
int a[maxs], y[maxs], used[maxs], appear[maxs];
int n, tot, cnt = 1;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
appear[a[i]] = true;
}
for (int i = 1; i <= n; i++) {
if (!appear[1000001 - a[... | 4 |
#include <bits/stdc++.h>
using namespace std;
string s1, s2;
int main() {
cin >> s1;
cin >> s2;
int idx = 0;
for (int i = 0; i < s1.length(); ++i) {
if (s1[i] == '|') {
idx = i;
break;
}
}
string l = s1.substr(0, idx);
string r = s1.substr(idx + 1, s1.length() - idx);
while (s2.lengt... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
int sum1 = 0, sum2 = 0;
sum1 = pow(2, n);
sum2 = pow(2, n - 1);
for (int a = 1, b = n - 2; a < b; a++, b--) {
if (sum1 < sum2) {
sum1 += pow(2, b);
sum2 += pow(2... | 1 |
#include <iostream>
using namespace std;
int main(){
int a, b;
cin >> a >> b;
int x = b*10;
for(int i=x;i<x+10;i++){
if(a==i*2/25){
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, p;
long long d[100005], a[100005], s[100005], q[100005], f[100005], g[100005];
double inter(int i, int j) {
return ((double)f[i] + s[i] - f[j] - s[j]) / (i - j);
}
int main() {
cin >> n >> m >> p;
for (int i = 2; i <= n; i++) cin >> d[i], d[i] += d[i - 1];
... | 2 |
#include <bits/stdc++.h>
template <typename T>
T sqr(T x) {
return x * x;
}
template <typename T>
bool exmax(T &a, T b) {
return (b > a) ? (a = b) || 1 : 0;
}
template <typename T>
bool exmin(T &a, T b) {
return (b < a) ? (a = b) || 1 : 0;
}
using namespace std;
int main(void) {
int N, M;
scanf("%d%d", &N, &M... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
int times;
cin >> n >> m >> k;
int y = 0;
queue<pair<int, string> > Q;
pair<int, string> z;
if (k > 4 * m * n - 2 * n - 2 * m)
cout << "NO";
else {
cout << "YES" << endl;
while (k > 0) {
if (y == n - 1) break;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int X, Y;
double x, y;
point() { X = Y = x = y = .0; }
point(double a, double b) { x = a, y = b; }
inline void init(int a, int b) {
X = a, Y = b;
x = 1.0 / X;
y = 1.0 / Y;
}
inline double operator*(point p) { return x * p.y - y * p.x... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int m, k;
cin >> m >> k;
vector<long long> sum(k, 0LL), sum2(k, 0LL);
int pos;
for(int i=0;i<k;++i){
for(int j=0;j<m;++j){
cin >> pos;
sum[i] += 1LL*pos;
sum2[i] += 1LL*pos*pos;
}
}
long long r1 = sum[1] - sum[0], r2 = sum[k-1] - sum[k... | 6 |
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
int main(){
cin.tie(NULL);
ios::sync_with_stdio(false);
int n;
int p[1005][1005];
int tf=0;
int tt=0;
int ans=0;
cin>>n;
for(int i=0;i<n;i++){
for(int j=0;j<3;j++){
cin>>p[i][j];
}
sort... | 0 |
#include <bits/stdc++.h>
int f[1010][1010];
int n, k;
int a[1010];
int solve(int x) {
f[0][0] = 1;
int lst = 0;
for (int i = 1; i <= n; i++) {
while (a[i] - a[lst + 1] >= x) lst++;
for (int j = 0; j <= k; j++) {
f[i][j] = f[i - 1][j];
if (j) f[i][j] = (f[i][j] + f[lst][j - 1]) % 998244353;
... | 3 |
#include <iostream>
using namespace std;
const int MAX_N = 1e+7;
bool is_p[MAX_N+1] = {false,false};
void sieve(){
for(int i = 2 ; i <= MAX_N ; i++ )
is_p[i] = true;
for(int i = 2 ; i*i <= MAX_N ; i++ ){
if( is_p[i] ){
for(int j = i+i ; j <= MAX_N ; j += i ){
is_p[j] = false;
}
}
}
}
int main(){
... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool f(vector<vector<int>> arr, int n) {
int curr = arr[0][0], i = 1;
for (i = 1; i < n; i++) {
if (curr >= arr[i][0] && curr >= arr[i][1]) {
curr = max(arr[i][0], arr[i][1]);
} else if (curr >= arr[i][0] && curr < arr[i][1]) {
curr = arr[i][0];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int scan() {
int t = 0;
char c;
c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') {
t = (t << 3) + (t << 1) + c - '0';
c = getchar();
}
return (t);
}
int a[26][100001], ind[26] = {0};
char str[100002];
int main() {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<vector<int> > adj(N);
int h[N];
struct centroidDecomp {
vector<vector<int> > cd;
vector<int> d;
vector<bool> vis;
vector<int> sz;
vector<int> par;
int n;
centroidDecomp(int root = 1) {
n = adj.size();
d.resize(n, 100000000... | 3 |
#include <bits/stdc++.h>
using namespace std;
int fst[400020], nxt[200020], vv[200020], cost[200020], e;
void init() {
memset(fst, -1, sizeof fst);
e = 0;
}
void add(int u, int v, int c) {
vv[e] = v, cost[e] = c, nxt[e] = fst[u], fst[u] = e++;
}
int n, w[400020], sz[400020];
int val[400020];
vector<int> son[40002... | 4 |
#include <bits/stdc++.h>
using namespace std;
map<int, vector<int>> e;
int n, m, k, q;
bool safe[200005];
int sl[200005], sr[200005];
const long long inf = 1e18;
struct stanje {
int x, y;
long long cost;
};
long long mn(vector<stanje> vs) {
long long z = inf;
for (auto s : vs) z = min(z, s.cost);
return z;
}
... | 4 |
#include <iostream>
int main() {
int a, b, x; std::cin >> a >> b >> x;
std::cout << ((a <= x && x <= (a+b))?"YES":"NO") << std::endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long max(long long a, long long b) {
if (a > b) {
return a;
} else {
return b;
}
}
long long min(long long a, long long b) {
if (a < b) {
return a;
} else {
return b;
}
}
long long power(long long b, long long e... | 3 |
#include <bits/stdc++.h>
#define pb push_back
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
using namespace std;
long long a[55],b[55];
vector<long long>v[55];
long long dfs(long long k,long long a,long long b,long long u[]){
u[k]=1;
long long ans=1;
for (long long i : v[k]){
if ( (k==a... | 0 |
#include <bits/stdc++.h>
const double eps = (1e-10);
using namespace std;
int dcmp(long double a, long double b) {
return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
long long setBit0(long lon... | 3 |
#include<bits/stdc++.h>
using namespace std;
#define MAX 200002
int n;
int m;
vector<int> v[MAX];
int star[MAX];
int linkk[MAX];
int ord;
bool vis[MAX];
int cnt[MAX];
int belong[MAX];
inline int root(int b){
if(belong[b]==-1)return b;
return belong[b]=root(belong[b]);
}
inline void merge(int a,int b){
a=root(a... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
if (n == 1) {
cout << "? 1 1" << endl;
string ans;
cin >> ans;
cout << "! " << ans << endl;
return 0;
}
map<string, int> prefix;
int cnt = n * (n + 1) / 2;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).... | 0 |
#include <bits/stdc++.h>
using namespace std;
int s[110][110];
struct poin {
int x1;
int y1;
int x2;
int y2;
};
vector<struct poin> v;
int main() {
int a, b, c, d, e, f, n, x1, y1, x2, y2;
while (cin >> n) {
v.clear();
memset(s, 0, sizeof(s));
for (c = 0; c < n; c++) {
cin >> x1 >> y1 >> x... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int C = 26;
void add(int &x, int y) {
x += y;
while (x >= MOD) x -= MOD;
while (x < 0) x += MOD;
}
int fix(int x) {
while (x >= MOD) x -= MOD;
while (x < 0) x += MOD;
return x;
}
int pw(int a, int b) {
int ret = 1;
while (b) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t;
cin >> t;
while (t--) {
double x, ans = 0, y;
ll n;
cin >> n;
n *= 2;
x = 1 / (2.0 * sin((3.14159265) / n));
x = x * cos((3.1415... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool is_prime(int num) {
for (int i = 2; i * i <= num; i++)
if (num % i == 0) return false;
return true;
}
int t;
void read() { cin >> t; }
const long long inf = 1e18;
long long ask(long long q) {
cout << "? " << q << endl;
long long res;
cin >> res;
return ... | 6 |
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define SET0(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DWN(i,a,b) for(int i=(a);i>=(b);i--)
#define INF 0x3f3f3f3f
typedef long long ll;
int main(){
int T; cin>>T;
while(T--){
int x,y,n; cin>>x>>... | 1 |
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>... | 0 |
#include <bits/stdc++.h>
using namespace std;
map<long long, vector<int> > mp;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
mp.clear();
vector<pair<int, long long> > v;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
mp[x].push_back(i);
}
for (auto... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int num, a, b, c;
scanf("%d%d%d%d", &num, &a, &b, &c);
int ans = 0;
for (int i = 0; i <= c; i++) {
if (i * 2 > num) break;
for (int j = 0; j <= b; j++) {
int sum = i * 2 + j * 1;
int rest = num - sum;
if (rest >= 0 && rest ... | 2 |
#include <bits/stdc++.h>
using namespace std;
void op() {
int n;
cin >> n;
vector<pair<long long int, long long int>> v(n);
for (int i = 0; i < n; i++) {
long long int a, b;
cin >> a >> b;
v[i] = {a, b};
}
sort(v.begin(), v.end());
long long int mi = v[0].second, mx = v[n - 1].first;
for (in... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, ans, x, y, m;
while (~scanf("%lld%lld%lld", &x, &y, &m)) {
long long js = 0;
if (x > y) swap(x, y);
if (y >= m)
puts("0");
else {
if (y <= 0)
puts("-1");
else {
if (x < 0) {
js += (... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long pwr(long long a, long long b, long long mod) {
a %= mod;
if (a < 0) a += mod;
long long ans = 1;
while (b) {
if (b & 1) ans = (ans * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return ans;
}
long long pwr(long long a, long long b) {
long long ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const bool DEBUG = 0;
const int Q = 1 << 22;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
char dp[100001][4];
char p[100001][4];
int a[100000];
int b[100000];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin.sync_with_stdio(0... | 2 |
#include <bits/stdc++.h>
int main() {
int n, s;
std::cin >> n >> s;
int max = INT_MIN;
for (int(i) = (0); (i) < (n); ++(i)) {
int x, y;
std::cin >> x >> y;
if (x > s || (x == s && y > 0))
continue;
else {
if (y == 0 && max < 0)
max = 0;
else if ((100 - y) > max && y != ... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, s;
cin >> n >> s;
if (s - n + 1 > (s + 1) / 2) {
cout << "YES\n";
for (int i = 1; i < n; i++) cout << 1 << " ";
cout << s - n + 1 << endl;
cout << (s + 1) / 2;
} else
cout << "NO";
return;
}
int main() {
ios_base::sync_w... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vc<vc<T>>;
template <class T>
void mkuni(vector<T>& v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
}
long long rand_int(long long l, long long r) {
static mt19937_64 ... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using vi = vector<long long>;
using mi = map<long long, long long>;
using pi = pair<long long, long long>;
const long long N = 2005;
const long long MOD = 1e9 + 7;
const long long inf = 1e18 + 1;
vi v[N];
void solve() {
long long n, ans = 0, t;
c... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,last_r=114514;
cin>>n;
vector <int> a(n),b;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<=3;i++){
b=a;
int r=i;
b[0]-=i;
if(b[0]<0) b[0]=0;
for(int j=0;j<n-1;j++){
r+=b[j]*2;
b[j+1]-=b[j];
if(b[j+1]<0) b... | 0 |
#include <bits/stdc++.h>
using namespace std;
static long parsenum(long j, long l) {
string k = "";
long cur = 0;
for (int i = (int)j; i <= l; ++i) {
cur *= 10;
cur += k[i] - '0';
}
return cur;
}
static long gcd(long a, long b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
double fRand(double fMin, double fMax) {
double f = (double)rand() / RAND_MAX;
return fMin + f * (fMax - fMin);
}
template <class T>
T min(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
T max(T a, T b, T c) {
return max(a, max(b, c));
}
const double... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long x = (1 << 26) - 1;
int ans = 0;
while (--n) {
char c;
cin >> c;
string s;
cin >> s;
long long y = 0;
for (int i = 0; s[i]; ++i) {
y |= 1 << (s[i] - 'a');
}
if (c == '!') {
ans += (... | 1 |
#include <iostream>
using namespace std;
int main(){
int N, T;
while(cin >> N >> T){
int m = 0, M = 0, d = 0;
int r = 0;
cin >> m; M = m;
for(int i=1;i<N;i++){
int A; cin >> A;
if(A < m) m = M = A;
if(A > M){
if(A-m >= d){
if(A-m > d) r = 1;
else if(A-m == d) ++r;
d = A-m;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
vector<int> ps[100005 * 10];
vector<pair<int, int>> edges[100005 * 10];
int fp[100005 * 10];
int dis[100005 * 10];
int bfs(int u) {
queue<pair<int, int>> q;
dis[u] = 0;
for (auto v : edges[u]) {
q.push(v);
if (v.first == u) return 1;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
const int s = 1e6;
const int MAXS = 1e6 + 123;
int n;
scanf("%d", &n);
static int bio[MAXS];
memset(bio, 0, sizeof bio);
for (int i = 0; i < (n); ++i) {
int x;
scanf("%d", &x);
bio[x] = true;
}
vector<int> output;
vector<int>... | 2 |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main() {
fast();
long long n, m, l = 0, d = 0;
cin >> n >> m;
vector<pair<long long, long long>> a, front, back;
a.push_back(make_pair(0, 1));
int c = 0;
for (int i = 1;... | 2 |
#include <bits/stdc++.h>
using namespace std;
template< typename T >
struct edge
{
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
operator int() const { return to; }
};
template< typename T >
using Edges = vector... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
vector<pair<int, bool>> balls, b;
int main() {
int i, j, n, k, x, z;
scanf("%d%d%d", &n, &k, &x);
for (int i = 0; i < int(n); ++i) {
scanf("%d", &z);
balls.push_back({z, 0});
}
int res = 0;
for (int m = int(0); m <= int(n); ++m) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ld = double;
namespace fft {
const ld PI = acos(-1);
struct num {
ld x, y;
num(ld x = 0, ld y = 0) : x(x), y(y) {}
num operator+(const num& o) const { return num(x + o.x, y + o.y); }
num operator-(const num& o) const { return num(x - o.x, y - o.y); }
num ope... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long l[5010];
int tot;
long long ans, n, k;
void prepare() {
tot = 2;
l[0] = 4, l[1] = 7;
for (int i = 0; i < tot; i++)
if (l[i] > 2e9)
break;
else
l[tot++] = l[i] * 10 + 4, l[tot++] = l[i] * 10 + 7;
}
bool inside(long long t) {
for (int i =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a, b, ans = 0;
cin >> n >> m >> a >> b;
int ans1 = ((n + m - 1) / m) * b;
int ans2 = (n / m) * b + (n % m) * a;
int ans3 = n * a;
cout << min(ans1, min(ans2, ans3)) << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
string a[10010];
bool vis[10010];
string p;
bool cmp(string x, string y) { return x + p + y < y + p + x; }
int main() {
int n;
cin >> n;
int l = 0;
for (int i = 0; i < n; i++) cin >> a[i], l += a[i].length();
cin >> p;
sort(a, a + n, cmp);
l = l / (n / 2);
f... | 4 |
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;
#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
map<string, int> price;
map<string, vector<string> >... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
long long int x = n / 2;
if (n % 2 == 0) {
while (x--) cout << 1;
} else {
cout << 7;
x--;
while (x--) cout << 1;
}
return;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
l... | 3 |
#include<bits/stdc++.h>
#define LL long long
#define cbn(u,y) ((LL)fac[u]*inv[y]%mod*inv[(u)-(y)]%mod)
const int mod=1e9+7;
struct Combin{
#define N 400005
int fac[N],rv[N],facrv[N];
Combin(){
fac[0]=rv[1]=facrv[0]=1;
for(int i=2;i<N;i++) rv[i]=((-(LL)(mod/i)*rv[mod%i]%mod)+mod)%mod;
for(int i=1;i<N;i++) fac[... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int n, m, spi[N], dis[N];
vector<int> gra[N];
int f(int v) {
int &res = dis[v];
if (res) return res;
res = 1;
for (auto &(to) : (gra[v])) {
(res) = max((res), (f(to) + 1));
}
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.t... | 2 |
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;
using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<string, string> mp1;
map<string, string> mp2;
string word;
string s1, s2;
int i;
cin >> i;
int j;
while (i--) {
cin >> s1;
cin >> s2;
if (mp2.count(s1) == 0) {
mp1[s1] = s2;
mp2[s2] = s1;
} else {
mp2[s2] = ... | 2 |
#include <cstdio>
#include <vector>
using namespace std;
vector<int> p;
void Prime(){
bool prime[100000];
prime[0] = false;
prime[1] = false;
for(int i = 2; i < 100000; i++) prime[i] = true;
for(int i = 2; i < 1000; i++){
if(!prime[i]) continue;
for(int j = i*2; j < 100000; j += i) prime[j] = false;
}
for(... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int monthes[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
pair<int, pair<int, int>> d1;
pair<int, pair<int, int>> d2;
scanf("%d:%d:%d", &d1.first, &d1.second.first, &d1.second.second);
scanf("%d:%d:%d", &d2.first, &d2.second.first, &d... | 2 |
#include<cstdio>
#include<cstring>
char s[10];
int main(){
scanf("%s",s);
int len=strlen(s);
for(int i=1;i<len;i++){
if(s[i]=='C'&&s[i-1]=='A') {
puts("Yes");
return 0;
}
}
puts("No");
return 0;
} | 0 |
#include <bits/stdc++.h>
long long dx[4] = {0, -1, 0, 1};
long long dy[4] = {1, 0, -1, 0};
using namespace std;
class pa3 {
public:
long long x, y, z;
pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {}
bool operator<(const pa3 &p) const {
if (x != p.x) return x < p.x;
if (y != p... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[3][1000];
int n[3];
long long sum[3][1000];
long long d[3][1000][1000];
int t, st, dist = 0;
void dfs(int v, int par) {
d[t][st][v] = dist;
sum[t][st] += dist;
for (int to : g[t][v])
if (to != par) {
++dist;
dfs(to, v);
--dist;
... | 5 |
#include <bits/stdc++.h>
#pragma warning(disable : 4786)
#pragma warning(disable : 4996)
using namespace std;
const int N = 1e5 + 5;
vector<pair<int, int> > e;
int main() {
int n, d, h;
cin >> n >> d >> h;
if (d == h) {
if (d == 1 && n > 2) {
printf("-1\n");
return 0;
}
for (int i = 1; i <... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, f[105][200005], q[200005], he, ta;
int main() {
scanf("%d%d", &n, &m);
memset(f, 0x3f, sizeof f);
f[0][0] = 0;
for (int i = 1, len, t; i <= m; i++) {
scanf("%d%d", &len, &t);
len = t - len;
for (int j = 0; j <= t; j++) f[i][j] = f[i - 1][j];
... | 6 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll M = 1e9 + 7;
ll mpw(ll a, ll b) {
return (b == 0LL ? 1LL
: (mpw(a * a % M, b / 2LL) * ((b & 1LL) ? a : 1LL) % M));
}
int main() {
ll n, m;
cin >> n >> m;
if (m == 1)
cout << n + 1 << endl;
else
cout << ... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
const long long P = 998244353;
using namespace std;
inline void ckmax(long long &a, long long b) { a = max(a, b); }
inline void ckmin(long long &a, long long b) { a = min(a, b); }
inline void mul(long long &a, long long b) { a = 1ll * a * b % P; }
inline void addmod(long... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n;
cin >> i;
cin >> n;
if (n == i) {
cout << 0 << endl;
return 0;
}
int moves = 0;
while (n % (i * 3) == 0 && n > i) {
i *= 3;
moves++;
}
while (n % (i * 2) == 0 && n > i) {
i *= 2;
moves++;
}
if (i == n)
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long max(long long a, long long b) { return a > b ? a : b; }
bool r(long long p1, long long p2) { return (p2 < p1); }
long long min(long long a, long long b) { return a < b ? a : b; }
long long gcd(long long a, long long b) {
if (a == 0) r... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.