solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
set<int> stl[maxn], str[maxn];
map<pair<int, int>, int> mp;
int n, m, q;
namespace Segtree {
int mx[maxn << 2], mi[maxn << 2], eleg[maxn << 2];
void pushup(int o) {
int lch = o * 2, rch = o * 2 + 1;
mx[o] = max(mx[lch], mx[rch]);
mi[o] = min... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
double ans = 0.0;
cin >> n;
for (int i = (1); i <= (n); i++) {
ans += (double)1 / (double)(i);
}
printf("%.10lf\n", ans);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void _R(T &x) {
cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <clas... | 6 |
#include<iostream>
#include<map>
#include<vector>
#include<cstdio>
using namespace std;
const int M=3009;
const int N=1e5+9;
typedef long long ll;
typedef map<ll,int>::iterator it;
bool npri[M];
ll n,a[N];
vector<ll> pri;
map<ll,int> ha;
inline void init()
{
for(int i=2;i<M;i++)
{
if(!npri[i])
pri.push_back... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, pos[20], bad[20];
double p[20], ans[20], dp[(1 << 20) + 5];
int main() {
scanf("%d%d", &m, &k);
for (int i = 0; i < m; i++) {
double x;
scanf("%lf", &x);
if (fabs(x) > 1e-12) {
pos[n] = i;
p[n++] = x;
} else
bad[i] = 1;
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 100005;
int n, ans = 1;
bool vis[maxn], iscenter[maxn];
int siz[maxn];
struct edge {
int to, zne, color;
};
vector<edge> gr[maxn];
vector<int> cd[maxn];
int poww(int x, int p) {
if (p == 0) return 1;
if (p == 1) return x;
in... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
std::ios::sync_with_stdio(false);
cout.tie(0);
int n, k;
int x = 0;
cin >> n >> k;
for (int i = 0; i < n; i++) {
int tmp = k;
for (int j = 0; j < n; j++)
if (j == x)
cout << tmp << ' ';
else
cout << ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 998244353;
const long long int INF = 3e18;
long long int power(long long int base, long long int exp) {
long long int res = 1;
while (exp > 0) {
if (exp % 2 == 1) res = (res * base);
base = (base * base);
exp /= 2;
}
return res;... | 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
const int MAXN = 2001000;
int n1, n2, a1[MAXN], a2[MAXN], pos[MAXN];
int mai... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }
void iostream_init() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.setf(ios::fixed);
cout.precision(12);
}
const long long LINF = LLONG_MA... | 6 |
#include <bits/stdc++.h>
using namespace std;
char a[15][15], vis[15][15];
int flag;
bool solve(int x, int y, int cnt, int e) {
vis[x][y] = 1;
int cnt1, cnt2, cnt3, cnt4;
cnt1 = cnt2 = cnt3 = cnt4 = 0;
for (int i = x + 1; i < 10 && cnt1 < 4 && a[i][y] == 'X'; i++) cnt1++;
for (int i = x - 1; i >= 0 && cnt1 < ... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
priority_queue<int> q;
char s[20];
int n;
while(scanf("%s",s)!=EOF)
{
if(strcmp(s,"insert")==0)
{
scanf("%d",&n);
q.push(n);
}
else if(strcmp(s,"extract")==0)
{
printf("%d\n",q.top());
q.pop();
}
else if(strcmp(s,"end")==0... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
const int M = 20000;
bool ciekawe[4 * M + 7];
const int N = 60;
pair<int, int> ya[N + 7];
pair<int, int> yb[N + 7];
int wynik = 0;
bool znia[N + 7];
bool znib[N + 7];
int pom[4 * M + 7];
int dopchnij() {
int res = 0;
for (int i = 0; i < n; ++i) {
for (int ... | 3 |
#include <bits/stdc++.h>
using namespace std;
void debug(int n, ...) {
va_list v1;
va_start(v1, n);
for (int i = 0; i < n; i++) {
long long int val = va_arg(v1, int);
printf("%lld ", val);
}
va_end(v1);
cout << endl;
}
long long int f(long long int n) {
long long int ans = 0;
while (n) {
ans... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, s1 = "";
cin >> s;
for (int i = 1; i < s.length(); i++) {
s1 = s1 + s[i];
}
stringstream geek(s1);
int x = 0;
geek >> x;
if (x % 2 == 0)
cout << "0\n";
else
cout << "1\n";
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
return b ? gcd(b, a % b) : a;
}
long long int power(long long int x, long long int y, long long int p) {
long long int res = 1;
x %= p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int rmqa[18][1 << 18][7], ar[100005][7], lg[100005], br[8], cr[8], n, m, tot;
long long rez;
void genLog() {
for (int i = 2; i <= n; ++i) {
lg[i] = lg[i / 2] + 1;
}
}
void insert(int J) {
for (int i = 1; i <= n; ++i) {
rmqa[0][i][J] = ar[i][J];
}
for (int ... | 4 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vl;
typedef pair<int,int> pint;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
void fast()... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool m[105], h[105];
int n, M, fm, fh, x;
bool dp[105][105];
int main() {
scanf("%d%d%d", &n, &M, &fm);
for (int i = 0; i < fm; ++i) {
scanf("%d", &x);
m[x] = 1;
}
scanf("%d", &fh);
for (int i = 0; i < fh; ++i) {
scanf("%d", &x);
h[x] = 1;
}
if... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>; using vvi = vector<vi>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;
#define REP(i,n) for(ll... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct nd {
int id, p, c1, c2;
bool operator<(const nd &y) const { return p > y.p; }
} t[200002];
priority_queue<nd> q[3];
bool v[200002];
int main() {
int n, m, c;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> t[i].p;
}
for (int i = 1; i <= n; i++) {
... | 2 |
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int in(){//scanf文用
int a;
scanf("%d",&a);
return a;
}
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
const int INF=1001001001;
#define pb push_back
#def... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
struct Matrix {
int n, m;
long long a[105][105];
Matrix(int x, int y) {
n = x, m = y;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) a[i][j] = 0;
}
}
void init() {
for (int i = 1; i <= min(n, m); i++) a[i][... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n1, n2, k1, k2;
int main() {
cin >> n1 >> n2 >> k1 >> k2;
if (n2 >= n1)
cout << "Second";
else
cout << "First";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 1e15 + 5;
const long long Nlog = 17;
const long long Hash = 161;
const double PI = 2.0 * acos(0.0);
const double E = 2.718281828;
void solve() {
string s;
cin >> s;
cout << int(s[6] - '0' & 1) << '\n';
}
int main() {
... | 4 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int s,a;
while(cin >> s){
if(s==0)break;
for(int i=0;i<9;i++){
cin >> a;
s -= a;
}
cout << s << endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, MOD = 1009, lgN = 19;
const double pi = acos(-1), eps = 0.5;
struct Com {
double x, y;
inline Com(double _x = 0, double _y = 0) {
x = _x;
y = _y;
}
inline Com operator+(const Com &t) const { return Com(x + t.x, y + t.y); }
inline Com... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
const int INF = 1000 * 1000 * 1000;
int p[maxn];
map<string, int> c;
vector<int> num;
int n, m;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> p[i];
sort(p, p + n);
string inp;
for (int i = 0; i < m; i++) {
cin >> inp... | 3 |
#include <bits/stdc++.h>
using namespace std;
int dp[2][300005], x[300005], y[300005];
int n, k;
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> x[i];
for (int i = 1; i <= n; i++) cin >> y[i];
for (int i = 1; i <= n; i++) {
if (!(~dp[0][i - 1])) {
dp[0][i] = -1;
dp[1][i] = -1;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
static const int M = 300200;
static const long long P = 1e16 + 3;
static const long long C = 203;
int main() {
ios_base::sync_with_stdio(0);
int n, m, l, r, curr;
long long hsh, chsh;
bool success;
string b;
vector<long long> hasharr;
vector<long long> pow;
... | 3 |
#include<stdio.h>
int main(){
int n,m,a;
while(1){
scanf("%d%d%d",&n,&m,&a);if(n==0&&m==0&&a==0)break;
int N[1003][102]={};
for(int i=0;i<m;i++){
int h,p,q;
scanf("%d%d%d",&h,&p,&q);
N[h][p]=1;
N[h][q]=2;
}
for(int i=1000;i>=0;i--)
{if(N[i][a]==1)a++;
else if(N[i][a]==2)a--;
}
printf("%d\n",a);
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
long long a[N];
signed main() {
int T;
cin >> T;
while (T--) {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
long long ans = -4e18;
for (int i = 1; i <= n; ++i) {
for (int j = i - 1... | 2 |
#include <bits/stdc++.h>
using namespace std;
int64_t gcd(int64_t a, int64_t b, int64_t& x, int64_t& y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
int64_t x1, y1;
int64_t d = gcd(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return d;
}
bool find_any_solution(int64_t a, int64_t b, int64_t c... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[100009], b[100009];
bool cmp(int a, int b) { return a > b; }
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, r, maxx = 0, ans = 0;
scanf("%d%d", &n, &r);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
sort(a + 1, a + 1 +... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
const double eps = 1e-9;
const long long INF = 1e18;
long long n, P;
long long fac[N];
signed main() {
cin >> n >> P;
fac[0] = 1;
for (long long i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % P;
long long ans = 0;
for (long long i = 1; ... | 3 |
#include <bits/stdc++.h>
int main() {
int tree[100005], h[100005], n, i, cnt;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d %d", &tree[i], &h[i]);
}
if (n >= 3) {
cnt = 2;
for (i = 1; i < n - 1; i++) {
if (tree[i] > tree[i - 1] + h[i]) {
cnt++;
} else if (tree[i + 1] > t... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int A[n + 1];
for (int i = 1; i <= n; i++) {
cin >> A[i];
}
int ans = 0, mx;
for (int i = 1; i <= n; i++) {
mx = A[i];
while (i <= n && mx > i) {
i++;
mx = max(mx, A[i]);
}
ans++;
}
cout << ans;... | 1 |
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
#define INF 2000000000
#define LLINF 4000000000000000000
#define SIZE 100
voi... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("unroll-loops")
using namespace std;
signed main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> z(n + 2, 0);
vector<int> v(n, 0);
for (int i = 0; i < n; i... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimze("Ofast")
using namespace std;
const long long infl = 0x3f3f3f3f3f3f3f3fLL;
const long long infi = 0x3f3f3f3f;
const long long mod = 998244353;
long long powm(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) res = (res * a) % mod;
a = (a * a) ... | 4 |
#include <iostream>
#include <string>
using namespace std;
int main(){
int n,r;
while(cin>>n>>r){
if(n==0 && r==0) break;
string str(n,0);
for(int i=0;i<str.length();i++){
str[i]=n-i;
}
for(int j=0;j<r;j++){
int p,c;
cin>>p>>c;
str=str.substr(p-1,c)+str.substr(0,p-1)+str.substr(p+c-1);
}
cou... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MX_SZ = 105;
struct request {
int type;
int r;
int x, y, val;
request(int type0, int r0) {
type = type0;
r = r0;
}
request(int type0, int x0, int y0, int val0) {
type = type0;
x = x0;
y = y0;
val = val0;
}
};
int main() {
io... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
int p[100004];
int l[100004] = {0};
int r[100004] = {0};
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
for (int i = 1; i <= n; i... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct node {
double x, y;
};
struct square {
node f[5];
} A, B;
inline bool cal(const node &a, const square &b) {
double u = -999999999, r = -999999999, d = 999999999, l = 999999999;
for (int i = 1; i <= 4; i++) {
d = min(d, b.f[i].y);
u = max(u, b.f[i].y);... | 3 |
#include <bits/stdc++.h>
using namespace std;
int vis[1 << 18];
int main() {
int n, x;
cin >> n >> x;
int max_n = (1 << n);
std::vector<int> a;
;
a.push_back(0);
vis[0] = 1;
for (int i = 1; i < max_n; ++i) {
if (!vis[i ^ x]) {
vis[i] = 1;
a.push_back(i);
}
}
int cnt = a.size();
... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> v;
int main() {
int n, k;
cin >> n >> k;
string str;
cin >> str;
for (int i = 0; i < str.size() - 1; i++) {
if (!k) break;
if (str[i] == '4' && str[i + 1] == '7') {
k--;
if (i && (i % 2 == 1) && str[i - 1] == '4') {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:250000000")
template <typename T>
int size(T& a) {
return (int)a.size();
}
template <typename T>
T sqr(T a) {
return a * a;
}
struct mvec {
int a[16];
mvec(long long x, int k) {
memset((a), (0), sizeof(a));
for (int i = (2); i... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long const N = 1e5 + 10, pi = acos(-1);
int n, m, k, x, i, j, mn, a[N], b[N];
string s[N], ss;
map<string, int> mp;
int main() {
ios::sync_with_stdio(false);
cin >> n >> k >> m;
for (int i = 1; i <= n; i++) {
cin >> s[i];
}
for (int i = 1; i <= n; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int const N = 3e5 + 2, oo = 1e9;
long long const OO = 2e18;
double const eps = 1e-8, PI = acos(-1);
int mod = oo + 7;
string aa[1001];
int lar[2][1001], eq[2][1001], er[2][1001], val[2][1001];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int now = 1;
int n, m;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long f(int a) { return a * a; }
int side[6];
int main() {
for (int i = 0; i < 6; i++) cin >> side[i];
int bt = side[0] + side[1] + side[2];
cout << f(bt) - f(side[0]) - f(side[2]) - f(side[4]) << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char g[1005][1005];
char col[1005][1005];
template <typename T>
struct SegmentTree {};
void input() {
cin >> n >> m;
string s;
for (int i = 1; i <= n; i++) {
cin >> s;
for (int j = 1; j <= m; j++) {
g[i][j] = s[j - 1];
}
}
for (int i = ... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n;
struct vec {
long long x, y, idx;
} a, b;
long double pos_ang_with_x_axis(vec a) {
long double res = atan2(a.y, a.x) * 180 / acos(-1);
if (res < 0) res += 360;
return res;
}
int dot(vec a, vec b) { return a.x * b.x + a.y * b.y; }
lo... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, m, k;
cin >> n >> m >> k;
vector<ll> vec(m);
for (ll &v : vec) cin >> v;
ll ans = 0, i = 0;
while (i < m) {
ll t = (vec[i] - i - 1) / k, j = i + 1;
while (j < m && (vec... | 3 |
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef uns... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[1000];
cin >> n;
for (int I = 0; I < n; I++) cin >> a[I];
int m, l[1000], r[1000];
cin >> m;
for (int I = 0; I < m; I++) cin >> l[I] >> r[I];
int sum = 0;
for (int j = 0; j < n; j++) sum += a[j];
for (int j = 0; j < m; j++) {
if (... | 1 |
#include<iostream>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main(){
int n;
string s;
int a,b;
cin>>n;
while(n--){
cin>>s;
sort(s.begin(),s.end());
a = atoi(s.c_str());
reverse(s.begin(),s.end());
b = atoi(s.c_str());
cout<<b-a<<endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long neg = 1, num = 0;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') neg = -1;
for (; isdigit(c); c = getchar()) num = (num << 1) + (num << 3) + c - '0';
return neg * num;
}
int n, b[200010], f[200010], ans... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[1234];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
string s;
cin >> s;
int n = s.size();
int i = 0, j = n - 1;
int l = 0, r = 0;
int k = 0;
while (true) {
for (; i <= j; i++)
if (s[i] == '(') {
l = 1;
i++;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long a[] = {3, 15, 81, 6723, 50625, 2562991875};
int b[] = {0, 1, 2, 0, 3, 1, 2};
int main() {
int n;
cin >> n;
int grundy = 0;
for (int i = 0; i < n; ++i) {
long long y;
cin >> y;
grundy ^= b[lower_bound(a, a + 6, y) - a];
}
if (grundy == 0)
... | 5 |
// ====================================
// author: M_sea
// website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
long long read() {
long long res = 0, f = 1;
char c = getchar();
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-') f = -1, c = getchar();
while (isdigit(c)) res = (res << 1) + (res << 3) + c - 48, c = getchar();
return res * ... | 5 |
#include <stdio.h>
#pragma warning(disable : 4996)
int w, h, v, t, x, y, p, q;
long long r;
bool check(int x1, int y1)
{
long long distances = 1LL * (x1 - x) * (x1 - x) + 1LL * (y1 - y) * (y1 - y);
return distances <= r;
}
long long solve()
{
if (!check(p, q))
{
return 0;
}
long long ret = 0;
// -----... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, q;
cin >> n >> m >> q;
int a[n + 1][m + 1];
for (int i = 1; i < n + 1; i++) {
a[i][0] = 0;
int ans = 0, cons = 0;
for (int j = 1; j < m + 1; j++) {
cin >> a[i][j];
if (a[i][j] == 0)
cons = 0;
else
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long m, n, ans;
bool o = 0, u;
string s, a[1005];
bool us['{'], k['{'], b[1005];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> m;
cin >> s;
cin >> n;
for (int i = 0; i < s.size(); ++i) {
us[s[i]] = 1;
}
for (int i = 1;... | 5 |
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_ba... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000004;
const int INF = 0x3f3f3f3f;
int dp[MAXN];
int pre[MAXN];
int t[MAXN];
pair<int, int> p[MAXN];
inline int dis(int i, int j) {
return abs(p[i].first - p[j].first) + abs(p[i].second - p[j].second);
}
int main() {
int r, n;
scanf("%d%d", &r, &n);... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
string s;
int a, b;
vector<int> ans;
bool visited[510][510] = {false};
int dfs(int x, int y, int pos) {
if (!visited[x][y]) ans[pos]++;
visited[x][y] = true;
if (pos == s.size()) return 0;
if (s[pos] == 'D') {
if (x < n - 1)
return dfs(x + 1, y, ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, N = 1e3 + 5, MOD = 1e9 + 7;
int T, cas = 0;
int n, m;
bool vis[N];
vector<int> primes;
void Init_Primes() {
memset(vis, 0, sizeof(vis));
int m = sqrt(N + 0.5);
for (int i = (2); i <= (m); i++)
if (!vis[i])
for (int j = i * i; j <=... | 3 |
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#define MOD 1000000007
#define MAX_N 100000
#define MAX_P 200005
Int fact[MAX_P],inv[MAX_P];
void init(Int mod){
fact[0]=1;
for(Int i=1;i<MAX_P;i++)
fact[i]=(fact[i-1]*i)%mod;
inv[1]=1;
for(Int i=2;i<MAX_P;i++)
inv[i]=inv[mod%i]*(mod... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int size = 1e6 + 7;
const int mod = 1e9 + 7;
int pos[size], c[size];
long long ans;
struct compare {
bool operator()(const int& a, const int& b) { return c[a] <= c[b]; }
};
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
int n, k, i, j,... | 3 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
default_random_engine generator;
const int MAXN = 2000;
vector<int> g[MAXN];
int s[MAXN];
map<pair<int, int>, int> mapa;
int good[MAXN];
int dfs(int v, int p = -1) {
s[v] = 1;
for (int u : g[v]) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 7;
const int MOD = 1e9 + 7;
int n, used[N], dp[N][8][2];
char s[3][N];
inline void inc(int &x, int y) {
x += y;
if (x >= MOD) x -= MOD;
}
inline int mul(int x, int y) { return 1ll * x * y % MOD; }
int dfs(int pos, int mask, int status) {
int &ret =... | 4 |
#include <iostream>
#include <string>
using namespace std;
int main(){
string s, p;
cin >> s;
cin >> p;
s+=s;
if (s.find(p)!=string::npos) cout << "Yes\n";
else cout << "No\n";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
long long modularExp(long long x, long long n, long long mod) {
long long result = 1;
while (n > 0) {
if (n % 2 == 1) result = (resul... | 4 |
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#inc... | 0 |
#include <bits/stdc++.h>
int main() {
int n, cnt = -1;
int x = 0, y = 0;
char ch, stat = 0;
scanf("%d", &n);
while (n--) {
scanf(" %c", &ch);
if (ch == 'U')
y++;
else
x++;
if (x < y) {
if (stat != 1) cnt++;
stat = 1;
} else if (x > y) {
if (stat != 2) cnt++;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
const int MN = 1e5 + 5;
int N, M, dis[MN], par[MN], sq;
bool vis[MN], added[MN];
vector<int> adj[MN], res, ind;
void... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 300000;
bool result[MAX_N];
struct Vertex;
int index_count = 0;
struct Edge {
bool var_sign;
int var;
int ind;
Vertex *u;
Edge() {}
Edge(bool vs, int var, Vertex *u, int i)
: var_sign(vs), var(var), u(u), ind(i) {}
};
struct Vertex {
bo... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 69, base = 1024 * 1024, mod = 1e9 + 7;
long long n, k, m, d, wynik;
int32_t main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k >> m >> d;
for (long long a = 1; a <= d; a++) {
long long l = n, p = n;
... | 3 |
#include <iostream>
using namespace std;
int tt[]={0,6000,4000,3000,2000};
int main(){
int t,n;
while(cin >> t >> n){
cout << tt[t]*n << endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[1000010], n;
long long go(long long x) {
long long s = 0, res = 0, c = 0;
int mid = -1;
for (int i = 0; i < n; i++) {
long long r = a[i] + s;
if (r >= (x + 1) / 2 && mid == -1) {
c = 0;
mid = i;
}
if (r >= x) {
res += (long long... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> ar[200001];
int parity[200001];
void dfs(int node, int dist) {
parity[dist] ^= 1;
for (int i = 0; i < ar[node].size(); i++) dfs(ar[node][i], dist + 1);
}
int main() {
int n, x, res = 0;
cin >> n;
for (int i = 2; i <= n; i++) cin >> x, ar[x].push_back(i... | 1 |
#include<bits/stdc++.h>
using namespace std;
vector<long long> v;
long long n,cnt,k,num;
pair<long long,long long> p[100100];
long long ans,sum;
bool use[100100];
int main()
{
cin>>n>>k;
for(int i=0;i<n;i++)cin>>p[i].second>>p[i].first;
sort(p,p+n);
reverse(p,p+n);
for(int i=0;i<n;i++)swap(p[i].first,p[i].second);... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a, b;
char s[105][105];
int main() {
scanf("%d %d", &a, &b);
a --, b --;
for (int i = 1; i <= 50; i ++)
for (int j = 1; j <= 100; j ++)
s[i][j] = '.';
for (int i = 51; i <= 100; i ++)
for (int j = 1; j <= 100; j ++)
s[i][j] = '#';
for (int i = 1; b; i += ... | 0 |
#include <bits/stdc++.h>
using namespace std;
void test_case() {
int n, m, q;
cin >> n >> m >> q;
int64_t total = 0;
vector<vector<pair<int64_t, int64_t>>> dp(
n + 1, vector<pair<int64_t, int64_t>>(m + 1));
auto cnt = [&dp](int i, int j) {
return dp[i][j].first + dp[i][j].second - 1;
};
auto upd... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
long long n, S, T;
long long cap[105][105];
bool mark[105];
vector<vector<long long> > adj;
vector<long long> a;
vector<pair<long long, long long> > b;
bool dfs(long long i) {
if (i == T) return true;
if ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int i, a[n];
for (i = 0; i < n; ++i) cin >> a[i];
int j, l, ans = a[0];
for (i = 0; i < n; ++i) {
for (j = i; j < n; ++j) {
vector<int> big, small;
for (l = 0; l < n; ++l) {
if (l >= i && l <= j)
... | 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
struct point{
double x,y;
};
bool cross(point a,point b,point c,point d){
double ta=(c.x-d.x)*(a.y-c.y)+(c.y-d.y)*(c.x-a.x);
double tb=(c.x-d.x)*(b.y-c.y)+(c.y-d.y)*(c.x-b.x);
double tc=(a.x-b.x)*(c.y-a.y)+(a.y-b.y)*(a.x... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
scanf("%d", &N);
// N <= 9 can be easily solved using random weights. Only N=10 requires more thought
if(N == 2){
printf("0 4200782951\n4200782951 0\n");
}else if(N == 3){
printf("0 595392113 3485670742\n595392113 0 ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, A, B, id[25][25], cnt;
double p[25], du[25], g[300][300], r[300];
bool v[25][25];
void gauss() {
for (int i = 1; i <= cnt; i++) {
for (int j = i; j <= cnt; j++)
if (abs(g[j][i]) > 1e-20) {
for (int k = 0; k <= cnt; k++) swap(g[i][k], g[j][k]);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s;
cin >> n >> s;
int sum = 0, m = 0;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
sum += a;
if (a > m) m = a;
}
sum -= m;
if (s >= sum)
cout << "YES";
else
cout << "NO";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> dis[200005];
long long ans[200005];
long long num[200005 << 2];
int value[200005];
int pos[200005];
int n;
struct node {
int l, r, pos;
bool operator<(node temp) const { return r < temp.r; }
} data[200005];
inline int lowbit(int x) { return x & (-x); }
inlin... | 4 |
#include <bits/stdc++.h>
using namespace std;
void zoz() {
cin.tie(0);
std::ios::sync_with_stdio(false);
}
int main() {
zoz();
long long x, y, t, index = 0, maxx = -1e7, arr[1000];
cin >> x >> y;
for (int i = 1; i <= x; i++) {
cin >> arr[i];
}
for (int i = x; i >= 0; i--) {
if ((ceil((double)arr... | 1 |
#include<iostream>
using namespace std;
int cnt[4];
int a[5];
int main()
{
while(cin>>a[0],a[0])
{
cnt[1]=cnt[2]=cnt[3]=0;
int C=0;
for(int i=1;i<5;i++)cin>>a[i];
for(int i=0;i<5;i++)C+=!cnt[a[i]]++;
if(C==2)
{
if(cnt[1]&&cnt[2])
{
for(int i=0;i<5;i++)
{
cout<<2-(a[i]==1)<<endl;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d;
int main() {
scanf("%d%d%d%d", &a, &b, &c, &d);
if (a + b + c + d == 1) {
printf("YES\n");
if (a == 1) printf("0");
if (b == 1) printf("1");
if (c == 1) printf("2");
if (d == 1) printf("3");
return 0;
}
if (d - c == 1 && a == ... | 2 |
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,l,dp[100005],a[100005];
int func(int i){
if(i>n)return 0;
if(dp[i]>0)return dp[i];
if(a[i]>a[i-1] && a[i]>a[i+1])return l-a[i];
int res=0;
if(a[i]<a[i-1])res=max(res,func(i-1));
if(a[i]<a[i+1])res=max(res,func(i+1));
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, d, x, y;
cin >> n >> x >> y >> d;
if (abs(y - x) % d == 0)
cout << abs(y - x) / d << endl;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
const int N = 79;
int t, n;
long long sz[N] = {1, 2}, a, b, val[N][10];
int dp[N][10][2], cnt[N], cost[N] = {0, 1};
int find(long long at, bool is, int n) {
if (!is && at == 1) return 0;
if (is &&... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int Num[10];
string s, ss;
cin >> s;
int len = s.length();
for (int i = 0; i < len; ++i) Num[i] = s[i] - '0';
ss = "";
for (int i = 0; i < len; ++i) ss += '1';
int cnt = 0;
vector<int> NN;
NN.clear();
while (1) {
cnt = 0;
for (int ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 18;
long long parc[MAXN], dp[MAXN], a[MAXN], n, m;
int main() {
int n;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) parc[i] = parc[i - 1] + a[i];
for (int i = 1; i <... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.