solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n, m, p, q, r, i, j, k, a[200005], b[2][200005] = {0};
ios::sync_with_stdio(false);
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a[i];
}
b[0][0] = b[1][0] = b[0][n + 1] = b[1][n + 1] = 0;
for (i = 1, j = 0; i <= n; i++) {
if (a... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 100;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
long long cost[MAXN];
bool block[MAXN];
long long le[MAXN];
int main(int argc, char const *argv[]) {
long long n, m, p;
while (cin >> n >> m >> p) {
memset(block, 0, sizeof ... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int sum = 0, f = 1;
char ch = getchar();
while ((ch != '-') && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') ch = getchar(), f = -1;
while (ch <= '9' && ch >= '0') sum = sum * 10 + ch - '0', ch = getchar();
return sum * f;
}
int T;
i... | 5 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string a , b;
cin>>a>>b;
string s = a+b;
int n = stoi(s);
if( sqrt(n) - floor(sqrt(n)) == 0 )
cout<<"Yes";
else
cout<<"No";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 100;
int tree[maxn << 2];
int a[maxn], p[maxn];
void push(int id) { tree[id] = tree[id << 1] + tree[id << 1 | 1]; }
void update(int ind, int x, int l, int r, int id) {
if (l == r) {
tree[id] = x;
return;
}
int mid = (l + r) >> 1;
if (i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const int SZ = 1e6 + 10;
const int mod = 1e9 + 7;
const double PI = acos(-1);
const double eps = 1e-7;
long long read() {
long long n = 0;
char a = getchar();
bool flag = 0;
while (a > '9' || a < '0') {
if (a == '-') flag = 1;
a = g... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int _ = 2e5 + 7, P = 998244353;
int poww(long long a, int b) {
int tms = 1;
while (b) {
if (b & 1) tms = tms * a % P;
a = a * a % P;
b >>= 1;
}
return tms;
}
vector<int> qry;
int N, K, tms = 1, fac[_], ifac[_];
int main() {
ios::sync_with_stdio(0... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
struct pt {
double x, y;
pt(){};
pt(double _x, double _y) : x(_x), y(_y){};
pt operator+(pt const& p) { return pt(x + p.x, y + p.y); }
pt operator-(pt const& p) { return pt(x - p.x, y - p.y); }
pt operator*(pt const& p) { return pt(x ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int x[55], y[55], cnt1[1005], cnt2[1005];
int main() {
int n, i, ans, sum1, sum2;
bool flag = false;
ans = sum1 = sum2 = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &x[i]);
cnt1[x[i]]++;
sum1 += x[i];
}
for (i = 0; i < n; i++) {
s... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
string a, b;
cin >> n >> a >> b;
int l = 0, r = n - 1;
int lv = 1, rv = -1;
int cnt = 0;
vector<int> ans;
for (int i = n - 1; i >= 0; i--) {
if ((a[r] - '0' + cnt) % 2 != b[i] - '0') {
if (a[l] != a[r]) {
ans.push_back... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename t>
using V = vector<t>;
template <typename t>
void print(ostream& os, const t& a) {
os << a << '\n';
}
template <typename t, typename... A>
void print(ostream& os, const t& a, A&&... b) {
os << a << ' ';
print(os, b...);
}
cons... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300006;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n;
cin >> n;
vector<bool> can_modify(n + 1, true);
vector<pair<long double, int>> a[2];
for (int i = 1; i <= n; i += 1) {
long double x;
cin >> x;
if (x == t... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 101234;
long double fac[MN] = {}, ans = 0;
long double chs(int x, int y) { return fac[y] - fac[x] - fac[y - x]; }
int main() {
for (int i = 1; i < MN; i++) fac[i] = fac[i - 1] + log(i);
int n, m, k, good;
cin >> n >> m >> k;
for (int i = 0; i <= n; i+... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
constexpr int MAXN = 5 + 50;
constexpr ll INF = 1000000000000000002LL;
namespace dsu {
int f[MAXN], sz[MAXN];
void build(int n) {
fill(sz, sz + n, 1);
for (int i = (int)0; i < (int)n; ++i) f[i] = i;
}
int find(int x) { re... | 5 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
int formula(string &s, int P, int Q, int R, int &i) {
if(s[i] == '-') {
i++;
return 2-formula(s, P, Q, R, i);
} else if(s[i] == '(') {
int X, Y;
i++;
X = formula(s, P, Q, R, i);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
int k, r, min;
cin >> k >> r;
for (min = 1; min <= 10; min++) {
if (k * min % 10 == 0 || k * min % 10 == r) break;
}
cout << min;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
puts(f ? "YES" : "NO");
exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
assert(y >= 0);
x += y;
if (x >... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int NUM = 500 + 10;
int n, first;
int color[NUM], numAll = 0;
int size[NUM], come[NUM];
vector<int> ne[NUM], w[NUM];
long long dist[NUM];
int f[NUM][NUM][NUM / 2];
int lab[NUM], tl[NUM][NUM];
vector<int> zishu[NUM];
void update(int& a, int b) {
if (a == -1 || b < a)... | 5 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
long long i, j, k, l, n, m, ans = 1;
long long a[100009];
vector<long long> p, res;
long long query(long long t, long long x) {
long long res = 0;
if (t == 1) {
cout << 'A' << ' ' << x << '\n';
cout.flush();
cin >> res;
}
if (t... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double pi =
3.14159265358979323846264338327950288419716939937510582097494459230;
long long n, m;
bool check(long long x) {
long long i = (x * x + x) / 2;
long long j = (n - m);
return i >= j;
}
bool cmp(const pair<pair<int, int>, int> &a,
const pair... | 3 |
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
int main()
{
int n;
std::cin >> n;
std::vector<std::tuple<int, int, std::string, long long, std::string>> tp(0);
int v, w;
long long d;
std::string t, s;
for (int i = 0; i < n; i++)
{
s... | 0 |
#include <bits/stdc++.h>
using namespace std;
pair<long long int, long long int> dxy[] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const long long MAXN = 1e5 + 10, MOD = 1e9 + 7, INF = ((1ll << 60) - 1) * 2 + 1;
long long int n, m;
long long int t[4 * MAXN];
long long int a[4 * MAXN];
long long int arr[MAXN];
long long int d... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<pair<int,int>> a(n),b(n);
for(int i=0;i<n;i++){
int k,l;
cin >> k >> l ;
a[i]={l,k};
}
for(int i=0;i<n;i++){
int k,l;
cin >> k >> l ;
b[i]={k,l};
}
sort(a.begin(),a.end(... | 0 |
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define frs first
#define scn second
#define phb push_back
#define ppb pop_back
#define mkp make_pair
using namespace std;
typedef pair< int, int > Pr;
typedef pair< int, Pr > Trp;
int N, M;
string txt[10], ptr[10];
void read();
void soup... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const long long INF64 = 1e18;
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <typename A, typename B>
string to_string(pair<A, B> p) {
return ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, a[3005];
bool bad[3005];
set<pair<long long int, int>> s;
int get_l() {
int an = n + 1;
int cnt = 0;
int cur = 0;
int j = 1;
while (bad[j]) j++;
for (int i = n; i >= j; i--) {
if (bad[i])
cnt--;
else
cnt++;
if (cnt >= cur) an = i, ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
vector<int> g[N];
vector<int> p;
vector<long long> a;
vector<long long> s;
deque<int> cur;
bool f = true;
void dfs(int v, int k) {
if (k % 2 == 0) {
long long mn = 1e9;
int v1 = cur[int(cur.size()) - 1];
for (int i : g[v]) {
mn = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y, i;
vector<pair<int, int> > v;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d", &x, &y);
v.push_back(make_pair(x, y));
}
sort(v.begin(), v.end());
x = v[0].second;
y = 0;
for (i = 1; i < n; i++) {
if (v[i].secon... | 3 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
float a,b,c;
cin >>a>>b>>c;
cout << (a*b)/2 << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, n, k, k1, k2, k3, m, fldgjdflgjhrthrl, fldggfhfghjdflgjl,
fldgjdflgrtyrtyjl, ffgfldgjdflgjl, h, x, y;
string s1, s2, s3, s;
long long dp[3][505][505];
char c[505][505];
int main() {
cin >> n >> m;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++) c... | 5 |
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
... | 0 |
#include <iostream>
#include <string>
#include <set>
using namespace std;
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
string s;
cin>>s;
int len=s.size();
set<string> se;
se.insert(s);
for(int j=1;j<len;j++){
string s1,s2;
s1=s.substr(0,j);
s2=s.substr(j,len-j);
int l1=s1.size(),l2=s2.siz... | 0 |
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
#define ALL(a) begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1 << 28;
long long gcd(long long m, long long n) {
long long r;
while (n != 0) {
r = m % n;
m = n;
n = r;
}
return m;
}
long long expmod(long long a, long long b) {
long long x = 1, y = a;
while (b > 0) {
if (b & 1) x = (x *... | 1 |
#include <bits/stdc++.h>
int main() {
int i, j, n, x = 0;
scanf("%d", &n);
char str[n][6];
for (i = 0; i < n; i++) {
scanf("%s", str[i]);
}
for (i = 0; i < n; i++) {
for (j = 0; j < 5; j++) {
if (str[i][0] == 'O' && str[i][1] == 'O') {
x++;
str[i][0] = '+';
str[i][1] = ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
cout << (a % 2);
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pii pair<int,int>
#define sz size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define vi ve... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
map<int, int> M;
int n, v[N], b, d[N], sol;
int value(int x) {
int val = 0, auxn = x;
while (auxn % 2 == 0) auxn /= 2, val += M[2] + 1;
for (int i = 3; i * i <= x && auxn != 1; i += 2)
while (auxn % i == 0) auxn /= i, val += M[i] + 1;
if (aux... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int MAXM = 1000005;
const int MOD = 1000000007;
const int MAMOD = 998244353;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double EPS = 1e-8;
int main() {
double n, r, x, R;
sca... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 12345;
const int STD_SIZE = 130;
int msize;
struct Matrix {
int mat[STD_SIZE][STD_SIZE];
Matrix() { memset(mat, 0, sizeof mat); }
inline Matrix operator*(const Matrix& b) {
Matrix ret;
for (int i = 0; i < msize; i++)
for (int j = 0; j < m... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const double PI = acos(-1.0);
const int MAXN = 1e6 + 5;
vector<long long int> lucky;
void init(long long int num) {
if (num > 1e10) return;
if (num) lucky.push_back(num);
init(num * 10 + 4);
init(num * 10 + 7);
}
void cp() {
long long int ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, p, q, sum = 0, w, a[109], d[109] = {0}, b[109], c[109], j, sum1 = 0,
sum2 = 0;
cin >> n >> w;
for (i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 == 0) {
sum = sum + (a[i] / 2);
b[i] = sum1 + (a[i] / 2);
... | 3 |
#include <bits/stdc++.h>
int main() {
int n, p;
int x[600] = {};
int s = -1;
int i, j, k;
scanf("%d%d", &p, &n);
for (i = 1; i <= n; i++) {
scanf("%d", &j);
if (x[j % p] == 0) {
x[j % p] = i;
} else {
s = i;
break;
}
}
printf("%d\n", s);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T& x) {
static char c;
static int f;
for (c = getchar(), f = 1; c < '0' || c > '9'; c = getchar())
if (c == '-') f = -f;
for (x = 0; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + (c & 15);
x *= f;
}
template <typename T>
voi... | 5 |
#include <bits/stdc++.h>
using namespace std;
int L[200010], R[200010];
int len[200010];
int s[200010];
int inter(int u, int v) {
return max(0, min(R[u], R[v]) - max(L[u], L[v]) + 1);
}
int power(int a, int b, int m, int ans = 1) {
for (; b; b >>= 1, a = 1LL * a * a % m)
if (b & 1) ans = 1LL * ans * a % m;
re... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct compare {
bool operator()(const pair<pair<int, int>, int> &p1,
const pair<pair<int, int>, int> &p2) const {
if (p1.first.first / 1000 != p2.first.first / 1000)
return p1.first.first / 1000 < p2.first.first / 1000;
else
return (... | 3 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(NULL);
long long t;
cin >> t;
for (long long g = 0; g < t; g++) {
long long n, k, d;
cin >> n >> k >> d;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
long lo... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N,Z=0;
cin>>N;
vector<int> p(N);
for(int i=0;i<N;i++){
cin>>p.at(i);
}
vector<int> q(N);
for(int i=N-1;i>=0;i--){
int A=0;
for(int j=i*2+1;j<N;j+=i+1){
A+=q.at(j);
}
if((A+p.at(i))%2==1){
q.at(i)=1;
Z++;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a, n, d, t, v;
double ans[100001];
double gets_ans() {
double t1 = v * 1.0 / a;
if (0.5 * a * t1 * t1 <= d) return t + t1 + (d - 0.5 * a * t1 * t1) / v;
return sqrt(2.0 * d / a) + t;
}
int main() {
cin >> n >> a >> d;
for (int i = 0; i < n; i++) {
cin >> t... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 112345, CEM = 112;
vector<int> grafo[MAXN];
int match_a[MAXN], match_b[MAXN], dist_a[MAXN], dist_b[MAXN], fila[MAXN], A, B;
bool mrk_a[MAXN], mrk_b[MAXN];
bool BFS() {
int ini = 1, fim = 0;
for (int i = 1; i <= A; i++) dist_a[i] = 0;
for (int i = 1; i... | 5 |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,... | 0 |
#include <bits/stdc++.h>
using namespace std;
using dbl = long double;
using Pi = pair<int, int>;
const dbl eps = 1e-15;
#define lt(a, b) ((a)-(b) < -eps)
#define eq(a, b) (fabs((a)-(b)) < eps)
int W, H;
char mas[505][505];
Pi S, G;
vector<Pi> Bs;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};
bo... | 0 |
#include <bits/stdc++.h>
using namespace std;
string x, y;
int a, b, c, d, all, all1;
int main() {
cin >> x >> y;
a = (x[0] - '0') * 10 + (x[1] - '0');
b = (x[3] - '0') * 10 + (x[4] - '0');
c = (y[0] - '0') * 10 + (y[1] - '0');
d = (y[3] - '0') * 10 + (y[4] - '0');
all = a * 60 + b;
all1 = c * 60 + d;
i... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N=2e5;
int n,cnt,hd[N],v[N],nxt[N],w[N];
long long d[N];
void dfs(int u,int fa){
for(int i=hd[u];i;i=nxt[i]){
if(v[i]!=fa){
d[v[i]]=d[u]+w[i];
dfs(v[i],u);
}
}
}
int main(){
cin>>n;
for(int i=1,x,y,z;i<n;i++){
cin>>x>>y>>... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
string in;
int n;
cin >> in >> n;
string q[n];
for (int i = 0; i < n; i++) {
cin >> q[i];
}
long long unsigned now[10];
long long unsigned len[10];
for (int i = 0; i < 10; i++) {
now[i] = i;
len[... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a, a1, a2, a3, b1, b2, b3, n, d, k, b;
int main() {
cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3 >> n;
a = a1 + a2 + a3;
b = b1 + b2 + b3;
d = (a + 4) / 5;
k = (b + 9) / 10;
if (d + k <= n)
cout << "YES";
else
cout << "NO";
return 0;
}
| 1 |
/*
??¨????????¨DP.
Node????????????????????????
BidirectionalTreeDP<Node> treedp(G);
??¨????????°??????
get(v)??§v????????¨??????dp??????get(v,p)??§v????????¨??????p??????????????£?????????Node???????????????
pic.png?????§
?????§normalize????????§G?????????????????£???????????¨?????¨???
*/
#include <bits/stdc++.h>
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int a[5003], n, m, k;
long long int dp[5003][5003], sum[5003];
long long int func(long long int in, long long int baki) {
long long int &num = dp[in][baki];
if (num != -1ll) return num;
num = 0;
if (in >= n) return 0;
if (baki) {
long long int ind = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }
int Set(int N, int pos) { return (N | (1 << pos)); }
int fx[] = {-1, 0, 1, 0};
int fy[] = {0, 1, 0, -1};
inline long long BigMod(long long B, long long P, long long M) {
long long R = 1;
while (P > 0) {
i... | 2 |
#include<iostream>
using namespace std;
int main(){
int N, M; cin >> N >> M;
cout << N*(N-1)/2 + M*(M-1)/2;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<int,ll>mp;
int main()
{
int n;
cin>>n;
ll ans=0;
for(int i=1,x;i<=n;i++)
{
cin>>x;
ans=ans+mp[i-x];
mp[i+x]++;
}
cout<<ans<<"\n";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a, b, c;
cin >> n >> a >> b >> c;
long long ans = 0;
if (a <= b - c) {
cout << (n / a) << "\n";
;
return 0;
}
if (b <= n) {
n -= b;
ans += n / (b - c);
n -= (n / (b - c)) * (b - c);
n += c;
ans++;
}
a... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
int x, s = 0;
for (int i = 0; i < n; i++) {
cin >> x;
s += x;
}
int c = 0;
for (int i = 1; i <= 5; i++) {
if ((s + i) % (n + 1) != 1) c++;
}
cout << c << endl;
return 0;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 11;
int n, a[N], ma;
int main(){
cin>>n;
for(int i = 1;i <= n; i++){
scanf("%d", &a[i]);
ma = max(ma, a[i]);
}
int dl = 0;
for(int i = 1;i <= n; i++){
if(ma - a[i] > 1){
puts("No");
retu... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t = 0, n = 0;
cin >> t;
while (t--) {
cin >> n;
if (n == 1 || n == 2)
cout << "1" << endl;
else if (n == 3 || n == 4)
cout << "2" << endl;
else {
if (n % 2 == 0)
cout << n / 2 << endl;
else
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, m, n, t, max = 0;
long long a[50003];
long long total, ans = 0;
scanf("%d", &n);
total = 0;
for (i = 1; i <= n; i++) {
scanf("%I64d", &a[i]);
total += a[i];
}
total /= n;
for (i = 1; i <= n - 1; i++)
if (a[i] < total) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve();
int main() { solve(); }
int d[1000];
int s[1000];
set<pair<pair<int, int>, int>> t, b;
set<pair<pair<int, int>, int>>* other(set<pair<pair<int, int>, int>>* x) {
return (x == &t) ? &b : &t;
}
namespace std {
template <>
struct hash<set<pair<pair<int, int>, i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int powermod(int base, int pw, int modulo) {
int ans = 1;
while (pw) {
if (pw & 1) {
ans = (1LL * base * ans) % modulo;
}
base = (1LL * base * base) % modulo;
pw >>= 1;
}
return ans;
}
inline void debug(long double n) {
cout << n << ' ';
co... | 2 |
#include <bits/stdc++.h>
int main() {
int n, m = 0, t = 0, x, y = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &x);
if (x <= y * 2)
t++;
else
t = 1;
m = m > t ? m : t;
y = x;
}
printf("%d", m);
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
void fail() { puts("-1"), exit(0); }
int O_A[200011], A_B[200011], A_O[200011], B_A[200011];
int tot, fi[200011];
struct edge {
int nx, to;
} e[200011 * 4];
void ps(int x, int y) {
e[++tot] = (edge){fi[x], y};
fi[x] = tot;
}
int ft[200011], dep[200011];
void dfs_base(... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<string, int> p1, pair<string, int> p2) {
if (p1.second > p2.second) return true;
return false;
}
int main() {
int n = 0, m = 0;
cin >> n >> m;
vector<int> a(n);
for (int &i : a) cin >> i;
sort(a.begin(), a.end());
vector<pair<string, int>> v;
... | 3 |
#include <iostream>
using namespace std;
int main() {
int n;
while(cin >> n, n) {
int id, dis;
id = -1, dis = -1;
for(int i = 0; i < n; i++) {
int p;
int d1, d2; cin >> p >> d1 >> d2;
if(dis < d1+d2) {
id = p; dis = d1+d2;
}
}
cout << id << " " << dis << endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, set<T>& s) {
for (auto it = s.begin(); it != s.end(); ++it) {
cout << *it << ",";
}
cout << endl;
return os;
}
int main() {
string s;
cin >> s;
for (int i = 0; i < s.size(); ++i) {
set<char> _s;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y;
cin >> n >> x >> y;
x--;
y--;
if ((x == n / 2 && y == n / 2) || (x + 1 == n / 2 && y == n / 2) ||
(x == n / 2 && y + 1 == n / 2) || (x + 1 == n / 2 && y + 1 == n / 2))
cout << "NO";
else
cout << "YES";
return 0;
}
| 2 |
#include <bits/stdc++.h>
const long long oo = 2 * 1000 * 1000 * 1000;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
int o(int x) { return x % _p; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
using namespace std;
void file_put() {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
double dp[304][304][304];
double expected(int three,int two,int one){
int zero = n - three-two-one;
double& ret = dp[three][two][one];
if(ret != 0.0) return ret;
if(zero == n) return 0.0;
if(three>0)
ret += (expected(three-1,two+1,one)+1)*three;
if(two>0)
r... | 0 |
#include <bits/stdc++.h>
const long long N = 1e5 + 5;
const long long K = 105;
using namespace std;
vector<long long> adj[N];
vector<long long> val[K];
vector<long long> dist[N];
signed main() {
std ::ios_base ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n, m, k, second;
cin >> n >> m >> k >> ... | 1 |
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <map>
#include <deque>
#include <vector>
using namespace std;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
const int N=2e5+10;
struct ant{
int x;
int y;
bool face;
void in(){
char c[5];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int dx[222];
int dy[222];
string s;
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'U') {
dx[i + 1] = dx[i] + 1;
dy[i + 1] = dy[i];
}
if (s[i] == 'D') {
dx[i... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct point {
long long x, y;
};
bool operator<(point A, point B) {
return make_pair(A.x, A.y) < make_pair(B.x, B.y);
}
bool operator==(point A, point B) {
return make_pair(A.x, A.y) == make_pair(B.x, B.y);
}
struct Vector {
long long x, y;
Vector(point a, point ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int h[111];
int main() {
string s;
cin >> s;
int j = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '1') {
h[j] = 1;
j++;
} else if (s[i] == '2') {
h[j] = 2;
j++;
} else if (s[i] == '3') {
h[j] = 3;
j++;
} els... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main()
{
cin >> n >> s;
if (n%2 == 0 && s.substr(0, n/2) == s.substr(n/2)) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int main() {
int n, k;
cin >> n >> k;
string st[n + 1];
for (int i = 0; i < n; i++) {
cin >> st[i];
mp[st[i]]++;
}
string st2 = "EST";
int ct = 0;
set<string> se;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++... | 2 |
#include <bits/stdc++.h>
using namespace std;
int ar[1000006], stk[1000006], t;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &ar[i]);
int m;
scanf("%d", &m);
for (int i = 0; i < m; i++) {
int x;
scanf("%d", &x);
ar[x - 1] *= -1;
}
for (int i = n - 1; i >= 0; i... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
long long res = 1LL;
x = x % 1000000007;
while (y > 0) {
if (y & 1) res = (res * x) % 1000000007;
y = y >> 1;
x = (x * x) % 1000000007;
}
return res % 1000000007;
}
long long inv(long long n) { return power(n... | 3 |
#include <iostream>
using namespace std;
long long gcd(long long a, long long b){
if(a<b) swap(a,b);
if(b==0) return a;
return gcd(a%b,b);
}
int main(){
long long a,b;
cin >> a >> b;
if(b%a==0){
cout << -1 << endl;
}else{
long long i;
for(i=0;i<=a - 1;i++){
long long j = i + b;
if(j/a + j%a<1 + i){
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxm = 1e5 + 233;
const int CDD = 360;
int n, m, q, g[11][maxm], p[maxm << 2], id[maxm << 2];
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
struct Node {
int val, L[11], R[11], siz;
} * ch[maxm << 2], *emp;
inline int unite(int x, int y) {
int ... | 5 |
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
int n;
cin >> n;
ll a[n], b[n];
for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
ll ans = 0;
for(int i = n-1; i >= 0; i--){
a[i] += ans;
ans += (a[i]+b[i]-1)/b[i]*b[i] - a[i];
}
cout << ans << ... | 0 |
#include <bits/stdc++.h>
int main() {
int n, m, x;
scanf("%d%d%d", &n, &m, &x);
x--;
int tmp;
if (n < m) {
tmp = m;
m = n;
n = tmp;
}
n -= 2 * x;
m -= 2 * x;
int total = 0;
if (m > 0)
if (m > 1)
total = n + m - 2;
else
total = 1 + (n - 1) / 2;
printf("%d\n", total);... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int main() {
long long x;
cin >> x;
if (x <= 4) {
cout << x * (x - 1) / 2 << endl;
return 0;
}
long long y = x * 2 - 1;
long long z = y;
int num = 0;
long long ans = 0;
while (y) {
y /= 10;
num++;
}
if (z == 9 ... | 4 |
#include<bits/stdc++.h>
using namespace std;
string S;int n;
int main(){
cin>>n>>S;int maxn=0,t=0;
for(int i=0;i<S.size();i++){
if(S[i]=='I')t++;else t--;
maxn=max(maxn,t);
}
cout<<maxn<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, m, s, d, step = 0, pos = 0;
bool flg = true;
cin >> n >> m >> s >> d;
vector<int> p(n);
vector<int> plan(3 * n);
for (i = 0; i < n; i++) cin >> p[i];
for (i = 0; i < 2 * n; i++) plan[i] = 0;
sort(p.begin(), p.end());
i = 0;
while (... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
long long p[maxn];
int n;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
bool cmp(long long a, long long b) { return a > b; }
long long x, y, a, b, k, temp;
bool check(int n) {
long long an... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, n, x, y, k, b;
long long a[12345678];
int main() {
cin >> n >> x >> y;
i = 1;
j = 1;
while (i <= x || j <= y) {
if (i * y < j * x) {
++k;
a[k] = 1;
++i;
} else if (i * y > j * x) {
++k;
a[k] = 2;
++j;
}... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
int t;
cin >> t;
int c = 0;
if (t) {
if (i - k > t) {
if (i - 2 * k > t)
c += k;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using P = pair<int,int>;
int main(){
int n;
cin >> n;
P a[n];
int ans = 0;
rep(i,n) cin >> a[i].first >> a[i].second;
sort(a,a+n);
vector<int> l(n), r(n);
l[0] = a[0].second, r[n-1] = a[n-1].second;
for(int... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int pw(long long int a, long long int b, long long int mod) {
if (!b) return 1;
if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
return pw(a * a % mod, b / 2, mod) % mod;
}
const long long int MAXN = 1e5 + 10;
const long long int INF = 8e18;
const lo... | 3 |
#include <bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <exception>
#include <map>
#include <memory>
#include <queue>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
#define mp(x, y) make_pair(x, y)
const int N = 1e5 + 5, bs = 320, mod = 1e9 + 7;
int n, q, b[N], c[... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 60;
const int L = 5e5 + 10;
const int INF = 1e9 + 10;
int n, d;
int c[N];
bool f[L];
int dp[L];
int mx;
int main() {
scanf("%d%d", &n, &d);
for (int i = 0; i < n; ++i) {
scanf("%d", c + i);
}
sort(c, c + n);
f[0] = 1;
for (int i = 0; i < n; ++i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long md = 1e9 + 7;
const long long sz = 1e2 + 1;
long long A[sz + 1];
void solve() {
long long n, k;
cin >> n >> k;
long long flag = 0;
long long cur;
bool allSame = true;
set<long long> s;
for (long long i = 0; i < n; i++) {
cin >> A[i];
s.... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.