solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <iostream>
using namespace std;
int main(void){
int x1 , x2;
cin >> x1 >> x2;
if(x1 < x2) cout<< x2 - x1<< endl;
else
cout<< x1 - x2<< endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long temp = 0, r, ans = 0, l, z, w, k = 0, m1, e, p, q, k1 = 0, k2 = 0,
d = 0, a = 0, b = 0, s = 0, x, y, min1 = 1000000010, max1 = 0, m = 0,
c = 0, t = 0, i, n, c1 = 0, tot = 0, t1, k4 = 0, c2 = 0, j = 0,
k3 = 0;
char ch, ch1, ch2;
string... | 1 |
#include <bits/stdc++.h>
using namespace std;
int break_point() {
char c;
while ((c = getchar()) != '\n')
;
return 0;
}
template <typename T>
void read_integer(T &r) {
bool sign = 0;
r = 0;
char c;
while (1) {
c = getchar();
if (c == '-') {
sign = 1;
break;
}
if (c != ' ' &... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
string s;
int n, avg;
int c[4];
deque<int> g[4];
int main() {
cin >> n >> s;
avg = n / 3;
for (int i = 0; i < n; i++) {
g[s[i] - '0'].push_back(i);
c[s[i] - '0']++;
}
while (c[0] > avg) {
if (c[2] < avg) {
int pos = g[0].b... | 4 |
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N=2e5+5;
int n;
LL a[90][40];
LL ans;
int main()
{
cin>>n;
while(n--)
{
string s;
cin>>s;
LL y=0;
int u=s.size();
for(int i=0;i<s.size();i++)
if(s[i]=='.') u=i;
if(u==s.size()) s+=".";
for(int i=s.size()-u;i<=9;i++) s+="0"... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 712, SQ = 550;
long long n, q, a[N], ls;
long long ps[N], ans[N];
long long A[N], B[N], qu[N];
bool cmp(long long f, long long s) { return B[f] < B[s]; }
int32_t main() {
cin >> n;
for (long long i = 1; i <= n; i++) cin >> a[i];
cin >> q;
f... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, fh = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') fh = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return x * fh;
}
const int maxn = 2005, yrz... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool bl[103][103][103];
int main() {
int x, y, z;
scanf("%d%d%d\n", &x, &y, &z);
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
for (int k = 0; k < z; k++) {
char q;
scanf("%c", &q);
if (q == '1')
bl[i][j][k] = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string chek;
list<string> prices;
double sum = 0;
cin >> chek;
for (int i = 0; i < chek.length(); ++i) {
if (isdigit(chek[i]) || (chek[i] == '.')) {
if (!isdigit(chek[i - 1]) && !(chek[i - 1] == '.')) {
prices.push_back("");
}
... | 2 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
ll mod = 1e9+7;
void solve(){
int t;
cin>>t;
while((--t)>=0)
{
int n,m,x;
cin>>n>>m>>x;
vector<int>v(n);
map<int,vector<int>>mp;
for(int i=0;i<n;++i){
cin>>v[i];
mp[v[i]].push_back(i);
}
int c=0;
vector<i... | 3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
vector<int> G[100100];
int vis[100100], c[700][700], tp, tp2, tg[100100], f[100100];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, h;
int lh = 0, lm = 0;
int nh, nm;
bool judge() {
int res = nm - lm + (nh - lh) * 60;
if (res >= 2 * h + 2) {
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> h;
bool flag = false;
cin >> lh >> lm;... | 1 |
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
int main(){
int b;
while(cin >> b){
if(b == 0) break;
int ans1 = b, ans2 = 1;
for(int n = 2; n < 100000; ++n){
ll sm = 1*n*(n+1)/2;
if(b < sm) break;
int d = b - sm;
... | 0 |
#include<cstdio>
#include<iostream>
using namespace std;
int a[200001],b[200001],c[200001];
int main(void){
int n,m,k,root[100001],size[100001],bu[100001],i,j,gyo,x,y;
cin>>n>>m>>k;
for(i=1;i<=n;i++){
root[i]=i; size[i]=1; bu[i]=0;
}
for(i=1;i<=k;i++) cin>>a[i]>>b[i]>>c[i];
gyo=0;
for(i=1;i<=k;i++){
if(a[i]=... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, T;
int main() {
int last, i, t;
scanf("%d", &T);
while (T--) {
bool flag = true;
scanf("%d", &n);
scanf("%d", &last);
for (i = 1; i < n; i++) {
scanf("%d", &t);
if (t != last) flag = false;
last = t;
}
if (flag)
p... | 1 |
#include<bits/stdc++.h>
using namespace std;
const int N=15;
typedef long long ll;
int gi() {
int x=0,o=1;char ch=getchar();
while(!isdigit(ch)&&ch!='-') ch=getchar();
if(ch=='-') o=-1,ch=getchar();
while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
return x*o;
}
const int a[]={0,1,2,4,7,12,20,29,38,52,73};
int n,p[... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> points(5, vector<int>(5));
int checkScore(vector<int> s) {
int score = 0;
score += points[s[0] - 1][s[1] - 1] + points[s[1] - 1][s[0] - 1] +
points[s[2] - 1][s[3] - 1] + points[s[3] - 1][s[2] - 1];
score += points[s[1] - 1][s[2] - 1] + p... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int MAXN = 1000086;
long long f[MAXN];
long long k, w;
long long expow(long long x, long long e) {
long long ret(1);
while (e) {
if (e & 1) ret = ret * x % MOD;
e >>= 1;
x = x * x % MOD;
}
return ret;
}
long long e... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string s;
cin >> s;
string b = s;
sort(b.begin(), b.end());
int k = 0;
for (int i = 0; i < n; i++) {
if (s[i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 2;
cin >> n;
int st[n];
int stdr[n];
for (int i = 0; i < n; i++) {
cin >> st[i];
}
for (int i = 0; i < n; i++) {
cin >> stdr[i];
}
bool ans = true;
int m = 0;
if (st[0] == 0) m = 1;
for (int i = 0; i < n; i++) {
if (s... | 1 |
#include <bits/stdc++.h>
using namespace std;
int sum = 0, A[110];
bool ok(int n, int got) {
int ret = sum;
for (int i = 100; i >= 0; i--) {
if (A[i] >= n) {
ret -= n * i;
break;
} else {
ret -= A[i] * i;
n -= A[i];
}
}
return (ret <= got);
}
int main() {
int n, m, x;
cin... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5;
const int M = 0;
const int INF = 1000000000 + 7;
const long long int LLINF = 1000000000000000000LL + 7;
int n, m;
char used[N];
int ans[N], v[N];
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < m; ++i) scanf("%d", &v[i]);
for (int i = 0... | 2 |
//https://codeforces.com/problemset/problem/1514/D
//离线思路可以参考https://www.luogu.com.cn/blog/nizhuan/solution-p3709
/**
* 设[l,r]的长度为len,众数个数为cnt,那么非众数个数x=len-cnt.
* x个非众数可以和x+1个众数放在一起,满足条件,
* 多出来的众数只能一个一个放了,个数为cnt-(x+1).
* 因此需要的总个数为cnt-(len-cnt+1)+1=cnt*2-len.
* 利用莫队求区间众数
**/
#include <iostream>
#include <algorithm... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define MAXN 500020
int rangetree[MAXN*4][3];
void push(int curr) {
if (rangetree[curr][2]) {
rangetree[curr][2] = 0;
rangetree[2*curr][0] = max(rangetree[2*curr][0], rangetree[2*curr][1]+1);
rangetree[2*curr][2] = 1;
rangetree[2*curr+1][0] = max(rangetree[2*curr... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 4e3 + 10;
long long sum(long long n) { return n * (n + 1) / 2; }
long long check(long long n) {
long long l = 1, r = INF * 2;
long long ret = 1;
while (l <= r) {
long long mid = (l + r) / 2;
if (sum(mid) <= n)
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x = 0;
string s;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
for (int j = 0; j < s.size(); j++) {
if (s[j] == '+') {
x++;
break;
} else if (s[j] == '-') {
x--;
break;
}
}
}
c... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int> > V;
vector<long long int> Ans;
int main() {
long long int n, k;
scanf("%lld %lld", &n, &k);
for (long long int i = 0; i < n; i++) {
long long int st, ed;
scanf("%lld %lld", &st, &ed);
V.push_back(pair<long long in... | 4 |
#include <bits/stdc++.h>
#define int long long
#define N 100010
#define S str[pos]
#define Sp str[pos++]
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
int Max(int &a,int b){return a=max(a,b);}
int Min(int &a,int b){return a=min(a,b);}
typedef complex<double> P;
typedef ... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct Flow {
int n;
vector<vector<int> > graph;
vector<int> st, en, back;
vector<long long> f, c;
vector<int> par;
Flow(int n) : n(n), graph(n), par(n) {}
void add_edge(int u, int v, int cap) {
int id1 = st.size();
int id2 = id1 + 1;
st.push_back(... | 5 |
#include <bits/stdc++.h>
using namespace std;
namespace Solve {
const int MAXN = 100010;
struct Edge {
int y;
Edge *next, *opt;
bool flag;
Edge(int y, Edge *next, bool f = false) : y(y), next(next), flag(f) {}
} * a[MAXN];
inline int ScanInt(void) {
int r = 0, c, d;
while (!isdigit(c = getchar()) && c != '-... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int N = 1e6 + 10;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m;
cin >> n >> m;
int g[n];
for (int i = 0; i < n; ++i) cin >> g[i];
sort(g, g + (sizeof(g) / sizeof(*g)));
long long... | 3 |
#include <iostream>
#include <vector>
#include <bitset>
#include <string>
#include <array>
#include <random>
#include <chrono>
#include <algorithm>
uint64_t mod = 1000 * 1000 * 1000 + 7;
static int pow(uint64_t x, uint64_t n){
uint64_t ans=1;
while(n){
if(n%2){
ans *= x;
ans %= mod;
n-=1;
}
x *= x;
... | 0 |
#include <iostream>
#include <vector>
using namespace std;
const int MAXN = 300001;
int X[MAXN];
int Y[MAXN];
int XS[MAXN];
int YS[MAXN];
int main()
{
int W, H, M;
cin >> W >> H >> M;
int xmax = 0, ymax = 0;
for (int i=0;i<M;++i)
{
cin >> X[i] >> Y[i];
xmax = max(xmax, ++XS[X[i]])... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, n1, n2;
string s1;
string s2;
int result_1[1000001];
int result_2[1000001];
string TMP = "RSPR";
int whoLoss(char c1, char c2) {
for (int i = 0; i < 3; i++) {
if (c1 == TMP[i] && c2 == TMP[i + 1]) return 2;
if (c2 == TMP[i] && c1 == TMP[i + 1]) return 1;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int ans, ans1;
int a[100005];
int i, j, k, l, s, m, n;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a + 1, a + 1 + n);
for (i = n; i >= 1; i--) {
if (i % 2 == n % 2) ans = ans + (a[i] * a[i] - a[i - 1] * a[i - 1]);
}
printf... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class C>
void mini(C& a4, C b4) {
a4 = min(a4, b4);
}
template <class C>
void maxi(C& a4, C b4) {
a4 = max(a4, b4);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> pair) {
return out << "(" << pair.first << ", " << pair.second ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int p[1000010], n;
long long hold[1000010], sum, res, ind;
int main() {
sum = ind = res = 0;
memset(hold, 0, sizeof(hold));
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", p + i);
if (p[i] > i) {
hold[1]--;
hold[p[i] - i + 1] += 2;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[10];
char mid, star, fina;
long long x, y, n, judge1, judge2;
gets(s);
star = s[0];
fina = s[2];
scanf("%lld", &n);
judge1 = 0;
judge2 = 0;
if (star == 'v')
x = 1;
else if (star == '<')
x = 2;
else if (star == '^')
x =... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct Matrix {
long long m[7][7];
Matrix() { memset(m, 0, sizeof(m)); }
inline void init() {
m[1][1] = 2, m[1][2] = 1, m[1][3] = 1, m[1][4] = 0, m[1][5] = 1,
m[1][6] = 2;
m[2][1] = 1, m[2][2] = 2, m[2][3] = 0, m[2][4] = 1, m[2][5] = 1,
m[2][6] = 2;
... | 5 |
#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
int f[2010];
int main()
{
int n;
cin>>n;
for(int i=3;i<=2001;i++)
{
f[i]=1;
if(i-3>=3)
{
for(int j=3;j<=i-3;j++)
{
f[i]=(f[i]+f[j]%MOD)%MOD;
}
}
}
cout<<f[n];
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[2222], now[2222];
vector<int> ans;
void rev(int n) {
reverse(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) now[a[i]] = i;
}
void f(int n) {
if (n == 1) return;
if (a[n] == n && a[n - 1] == n - 1) return f(n - 2);
ans.push_back(now[n]);
rev(now[n]);
ans... | 3 |
#include <bits/stdc++.h>
using namespace std;
class Graph {
public:
struct Edge {
int next, to;
};
vector<int> head;
int eidx;
int N, M;
Edge* E;
Graph(int N_, int M_) : N(N_), M(M_) {
head.resize(N);
eidx = 0;
for (int i = 0; i < N; i++) {
head[i] = -1;
}
E = new Edge[M]{};... | 5 |
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define MAX_N 100000
typedef pair<char, int> card;
card A[MAX_N];
// NOTE: used for storing order of card.
map<int, vector<char> > orders;
map<int, int> indices;
#define SWAP(X, Y) do { \
card tmp = X; \
X = Y; \
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, i, counter;
vector<int> slimes;
int insert_or_sum(int number) {
if (!slimes.empty() && slimes.back() == number) {
slimes.pop_back();
return insert_or_sum(++number);
} else if (slimes.empty() || slimes.back() != number) {
slimes.push_back(number);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double Pi = 3.141592653589793116, EPS = 1e-9;
const long long dx[4] = {0, 1, 0, -1};
const long long dy[4] = {1, 0, -1, 0};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 6e5 + 5;
const int M = 35;
const int mod = 998244353;
int n, m;
int cnt0;
long long a[N];
long long wB[N];
long long wA[19][N];
long long ans[N];
long long qpow(long long a, long long b) {
long long r = 1;
while (b) {
if (b & 1) r = r * a % mod;
b ... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int first = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) {
if (ch == '-') f = -1;
}
for (; isdigit(ch); ch = getchar()) {
first = first * 10 + ch - 48;
}
return first * f;
}
const int mxN = 5e5;
int n, m, nn;
... | 4 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
template<typename A,typename B>inline ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int char_to_int(char c) {
int x = c - 48;
return x;
}
char int_to_char(int x) {
int c = x + 48;
return c;
}
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
map<int, int> mp;
vector<int> v;
map<int, vector<int> > G;
map<int, int... | 2 |
#include <cmath>
#include <cstdio>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const double PI=acos(-1);
// whether (hx, hy) is covered by the sector (tx,ty,w,a)
bool check(int hx,int hy,int tx,int ty,double d,double w,int a){
int x=hx-tx,y=hy-ty;
if(sqrt(x*x+y*y)>a) return f... | 0 |
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define fast ios::sync_with_stdio(0); cin.tie(0);
int mod = 1000000007;
int32_t main()
{
fast;
int t;
cin>>t;
while(t--){
int n;
cin>>n;
map<int,int>mp;
for(int i=0 ; i<n ; i++){
int... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b, c, x, y, r;
scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &x, &y, &r);
if (r > b - a) {
printf("-1\n");
return 0;
}
double yw = c - r;
double y1 = a + r;
double y2 = b;
y = 2 * yw - y;
double k = (y - y1) / x;
double ans = (yw... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, num;
vector<long long int> odd, even;
cin >> n;
even.push_back(0);
odd.push_back(0);
bool f = 1;
while (n--) {
cin >> num;
if (f) {
even.push_back(even[even.size() - 1] + num);
odd.push_back(odd[odd.size() - 1]... | 2 |
#include <bits/stdc++.h>
using namespace std;
#define MAX 51
#define MAX_M 5001
typedef pair<int,int> pii;
int main(){
int X,Y,Z,N,E,A;
while(cin >> X >> Y >> Z, X){
pii M[MAX];
vector<int> V(X);
for(int i = 0 ; i < X ; i++){
cin >> V[i];
}
for(int i = 0 ; ... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename T1>
T amax(T &a, T1 b) {
if (b > a) a = b;
return a;
}
template <typename T, typename T1>
T amin(T &a, T1 b) {
if (b < a) a = b;
return a;
}
const int mod = 1000000000 + 7;
const int N = 1000000 + 6;
const int maxn = 1e5 + 5;
int main(... | 2 |
// compile in C++11. use -std=c++11.
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
int c = 0, d = 0;
set<string> set = {"ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM",
"SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE"};
for (int i = 0; i < n; i++) {
cin >> s;
if ... | 1 |
#include <bits/stdc++.h>
using namespace std;
char s1[1010], s2[1010];
int cnt1, cnt2, y;
int main() {
scanf("%s %s", s1, s2);
int len = strlen(s1);
int l = strlen(s2);
for (int i = 0; i < len; i++)
if (s1[i] == '1') cnt1++;
for (int i = 0; i < l; i++)
if (s2[i] == '1') cnt2++;
if (cnt2 > cnt1 && !(... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int main() {
int ans = inf;
int n, m;
cin >> n;
m = (n + 1) / 2;
map<int, int> fr;
map<int, int> bc;
map<int, int>::iterator it;
for (int i = 0; i < n; ++i) {
int tfr;
int tbc;
cin >> tfr >> tbc;
fr[tfr]++;
if ... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e) {
cout << e << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
cout << e1 << " " << e2 << " " << e3 << endl;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct pos {
int x, y;
};
int dx[] = {-1, 0, 1, 0, 0};
int dy[] = {0, 1, 0, -1, 0};
int n, m, w, size, x, y, itr, mx;
int v[1000][1000], u[1000][1000];
pos q[2][1000 * 1000];
int main() {
scanf("%d%d", &n, &m);
v[500][500] = n;
if (n >= 4) {
q[0][0] = (pos){500,... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, poz, cate;
int a[1000005];
long long sum[1000005];
long double Sol = -1;
inline long double Val(int p, int mij) {
return (long double)(sum[p] - sum[p - mij - 1] + sum[n] - sum[n - mij]) /
(1 + 2 * mij);
}
inline void Solve(int p) {
int st = 0, dr = min(p... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 2; i <= n; i++) {
while (n % i == 0) {
cout << i;
n /= i;
}
}
cout << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
long long ln, lk, lm;
void etp(b... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = (1ll << 62) - 1;
const long long MOD = 998244353;
const int MAX = 2e9 + 10;
const long long int N = 3e5 + 10;
using namespace std;
int bPow(int a, int b) {
int res = 1;
while (b) {
if (b & 1ll) {
res = 1ll * res * a % MOD;
}
b >>=... | 4 |
#include <bits/stdc++.h>
using namespace std;
const char IO_MODE = 3;
inline long long ReadInt() {
long long 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();
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int MX = 1e5 + 5;
const int mod = 1e9 + 7;
char str[MX];
int main() {
scanf("%s", str);
int len = strlen(str);
long long ans = 1, num = 1;
for (int i = 0; i < len; i++) {
if (str[i] == 'a')
num++... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500050 + 1;
const int DELTA = 200020 + 1;
pair<int, int> a, b;
int cnt[MAXN], sum[MAXN];
int main() {
scanf("%d%d", &a.second, &a.first);
scanf("%d%d", &b.second, &b.first);
if (a > b) swap(a, b);
for (int i = b.second; i > 0; i--) {
cnt[b.first... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b, c;
string a1 = "", b1 = "", c1 = "";
cin >> a >> b >> c;
for (int i = 0; i < a.size(); i++) {
if (a[i] != ';' && a[i] != '-' && a[i] != '_') {
if (a[i] >= 'a' && a[i] <= 'z') a[i] = a[i] - 32;
a1 += a[i];
}
}
for (in... | 2 |
#include <bits/stdc++.h>
int n, m, dir = 1, now = 1;
char s[105][10005];
long long ans;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
for (int i = 1; i < n; i++) {
int l = now - 1, r = now + 1;
if (s[i + 1][now] == '.') {
ans++;
continue;
}
now... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0;
char ch = getchar();
bool positive = 1;
for (; ch < '0' || ch > '9'; ch = getchar())
if (ch == '-') positive = 0;
for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
return positive ? x : -x;
}
inline char RC(... | 4 |
#include<bits/stdc++.h>
using namespace std;
signed main(){
int x,t;
cin>>x>>t;
cout<<max(0,x-t)<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
bool not_there(int temp[], int x, int length) {
for (int i = 0; i < length; i++) {
if (temp[i] == x) return false;
}
return true;
}
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int temp[n];
for (int i = 0; ... | 1 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>
#include <cstdio>
using namespace std;
typedef long long ll;
typedef string::const_iterator State;
#define rep(i,n) for(int i=0;i<(n);i++)
class Parser{
public:
int expression(State &begin){
int ret = term(begin);
for(;... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class C>
void mini(C& a, C b) {
a = min(a, b);
}
template <class C>
void maxi(C& a, C b) {
a = max(a, b);
}
const long long mod = 1e9 + 7;
struct nodo {
void upd(int val, int x, int y) { v = val; }
nodo comb(nodo& izq, nodo& der) {
v = max(izq.v, der.v... | 6 |
//神题
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1000010
using namespace std;
int n, ff, op, cl, d[N], ans, L, R, now;
char s1[N], s2[N];
int main(){
scanf("%d%s%s", &n, s1+1, s2+1); s2[0]='$';
ff=1; for(int i=1; i<=n; i++)if(s1[i]!=s2[i]){ff=0; break;}
if(ff){printf("0"); return 0;}
now=n; R=n... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 200100;
const long long MAXK = 16000000;
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
int A[MAXN];
int sz[MAXN];
int N, K, a, b;
int R;
vector<long long> V[MAXN];
int p[MAXN];
int par(int x) { return (p[x] == x) ? x : p[x] = par(p[x]); }
... | 5 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s, a = "", b;
cin >> s;
unordered_map<string, int> m;
m[s]++;
for (int i = s.length() - 1; i >= 0; i--) {
a += s[i];
b = a;
reverse(b.begin(), b.end());
m[b + s.substr(0, i)]++;
}
cout << m.size() << endl;
}
int main() {
... | 1 |
#include <stdio.h>
#include <algorithm>
using namespace std;
int n, m, t, i, j, k;
long long p[100005], x=1000000;
struct AB{
int a, b, i;
bool operator < (const AB &A) const{
if(a != A.a) return a < A.a;
return b < A.b;
}
} d[100005];
int main(){
scanf("%d%d", &m, &n);
for(i=1; i<=n; i++){
scanf("%d%d", &d[... | 0 |
#include<cstdio>
int main(){
int N;scanf("%d",&N);
int mx=0,mxc,mn=N,mnc;
for(int i=0,a;i<N;i++){
scanf("%d",&a);
a>mx?mx=a,mxc=1:a==mx?mxc++:1;
a<mn?mn=a,mnc=1:a==mn?mnc++:1;
}
puts(mx==mn&&(mx==N-1||mx<=N/2)||mx==mn+1&&mx-mnc>0&&mx-mnc<=mxc/2?"Yes":"No");
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[11], b[11];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a[i] = x;
}
for (int i = 0; i < m; i++) {
int x;
cin >> x;
b[x]++;
}
for ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[200005];
void solve() {
int n, k, d;
cin >> n >> k >> d;
int ans = n + 7;
for (int i = 1; i <= n; ++i) cin >> a[i];
set<int> T;
map<int, int> cnt;
for (int i = 1; i <= n; ++i) {
T.insert(a[i]);
cnt[a[i]]++;
if (i >= d) {
ans = min(ans, ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
long long cnt1, cnt2, cnt3, cnt4;
cnt1 = cnt2 = cnt3 = cnt4 = 0;
string str1, str2;
scanf("%d", &n);
getchar();
cin >> str1 >> str2;
for (int i = 0; str1[i] != '\0'; i++) {
if (str1[i] == '0' && str2[i] == '1')
cnt1++;
else if... | 2 |
#include<bits/stdc++.h>
#define int long long
using namespace std;
int N,A[200100];
signed main(){
cin>>N;
for(int i=0;i<N;i++){
int a;
cin>>a;
A[a]=i;
}
A[0]=N;
A[N+1]=-1;
int ans=0,cnt=0;
for(int i=1;i<=N+1;i++){
if(A[i]<A[i-1])ans=max(ans,cnt),cnt=1;
else cnt++;
}
cout<<N-ans<<e... | 0 |
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
using namespace std;
const d... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 150005;
int n, m;
set<long long> st;
long long a[N], b[N];
int main() {
int i, j;
cin >> n;
for (i = 1; i <= n; i++) cin >> a[i] >> b[i];
for (i = 2; i * i <= a[1]; i++) {
if (a[1] % i == 0) st.insert(i);
while (a[1] % i == 0) a[1] /= i;
}
... | 2 |
#include <iostream>
using namespace std;
int main(){
int n;cin>>n;
int sm = 0;
for(int i = 0; n > i; i++){
int tmp;cin>>tmp;
sm += tmp-1;
}
cout << sm << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int f[200005][3];
vector<int> tree[200005];
void dfs(int node) {
if (tree[node].size() == 0) {
f[node][2] = 1;
return;
}
int f_total = 1;
f[node][0] = 1;
for (int i = 0; i < tree[node].size(); i++) {
int child = tree[node][i];
dfs(child);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int ans[200010];
int tab[200010];
int last[200010];
int ix[200010];
bool cmp(int a, int b) { return a > b; }
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> tab[i];
int mx = 0;
for (int i = 1; i <= m; i++) {
int ask, a;
cin >> ask... | 3 |
#pragma GCC optimize("O3")
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<unordered_set>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstdio>
#include<cassert>
#include<sstream>
#include<random>
#include<deque>
#include<set>
#include<unordere... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 400002;
int n, b[N];
long long a[N];
int main() {
scanf("%d", &n);
bool zero = true;
for (int(i) = (1); (i) <= (int)(n); (i)++)
scanf("%d", &b[i]), b[i + n] = b[i], zero &= !b[i];
if (zero) {
printf("YES\n");
for (int(i) = (1); (i) <= (int)... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool satr[200002], col[200];
int dif(int a, int b) {
if (a < 13 && b < 13) return abs(a - b);
if (a >= 13 && b >= 13)
return abs(a - b);
else {
if (a <= b) {
int c = a;
a = b;
b = c;
}
if (a >= 13)
return min(a - b, 26 - (a - b)... | 3 |
#include <iostream>
#include <string>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
int o = 0, c = 0, q = 0, test = 0;
string s;
cin >> s;
if ((s.size()) % 2 != 0)
test = 1;
else if ((s.size()) % 2 == 0)
{
int fla... | 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll h, e, ans;
cin >> h >> e;
if((h==1)||(e==1)) ans=1;
else ans=(h*e+1)/2;
cout <<ans<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100002;
int arr[N], tree[4 * N][20], lazy[4 * N];
bool GetBit(int num, int idx) { return ((num >> idx) & 1); }
long long SUM(int a[20]) {
long long ret = 0, r = 1;
for (int i = 0; i < 20; i++, r = (r << 1)) ret += a[i] * r;
return ret;
}
void Build(int p... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
int t, n, m;
vector<pair<int, int> > graph[102];
int dp[102][102][27];
int dfs(int u, int v, int c) {
if (dp[u][v][c] != -1) return dp[u][v][c];
for (pair<int, int>... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p, q, r;
cin >> n >> p >> q >> r;
int ar[n];
for (int i = 0; i < n; i++) cin >> ar[i];
long long mxr[n];
mxr[n - 1] = ((long long)r) * ar[n - 1];
for (int i = n - 2; i >= 0; i--) {
long long res = ((long long)r) * ar[i];
if (res > m... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int N, M, A, K, ans=0;
cin >> N >> M;
vector<int> tmp(M, 0);
for(int i=0; i<N; ++i){
cin >> K;
for(int j=0; j<K; ++j){
cin >> A;
tmp[A-1]++;
}
}
for(int i=0; i<M; ++i) ans += (tmp[i]==N);
cout << ans << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
int c = 0;
for (int i = 0; i < n; i++) {
if (arr[i] % 2 != 0) {
if (c == 0) {
cout << (arr[i] + 1) / 2 << endl;
} else {
cout << (arr[i] - 1) / 2... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n, K;
cin >> n >> K;
vector<int> a(n);
for (int i = 0; i < (int)n; ++i) cin >> a[i];
int ans = -100000;
for (int i = 0; i < (int)n; ++i)
for (int j = i + 1; j <= n; ++j) {
vector<int> cur;
int ... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.