solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const long double epsilon = 1e-15;
static const long double pi = acos((long double)-1);
using namespace std;
inline void init_io() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
struct data {... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, M, i, S=0, X=0; cin >> N >> M; vector<int> A(N);
for(i=0; i<N; i++){ cin >> A[i]; S+=A[i]; }
int T=(S+4*M-1)/(4*M);
for(i=0; i<N; i++){ if(A[i]>=T){ X++; } }
string ans="";
if(M<=X){ ans="Yes"; }else{ ans="No"; }
cout << ans << "\n";
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC target("sse2")
#pragma GCC optimization("O2")
#pragma GCC optimization("unroll-loops")
#pragma GCC optimize "trapv"
using namespace std;
const int maxn = 1000500;
inline int g() {
int x;
cin >> x;
return x;
}
inline long long gl() {
long long x;
cin >> x;
return x;
}
inl... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 800009;
int c[maxn], h[maxn], x[maxn], ans[maxn], pre[maxn], suf[maxn];
int n, Q, m, p, LIS, vis[maxn], res[maxn];
pair<int, pair<int, int> > q[maxn];
int del() {
int n = 1;
for (int i = 2; i <= m; i++)
if (x[i - 1] != x[i]) x[++n] = x[i];
return ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
if (ifstream("test.inp")) cin.rdbuf((new ifstream("test.inp"))->rdbuf());
cout.precision(9);
cout << fixed;
cin >> a >> b;
if (a == b)
cout << a;
else {
double v = (b - a) / 2.0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
long long n;
int main() {
scanf("%I64d", &n);
vector<long long> sz;
for (long long i = 1; i * i <= n; i++) {
if ((n % i) == 0) {
sz.push_back(i);
if (i != n / i) {
sz.push_back(n / i);
}
}
}
n = sz.size... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int n, cnt;
int c[N], u, v, pset[N];
long long ret = 0;
vector<int> edge[N], ans;
vector<pair<pair<int, int>, pair<int, int> > > sv;
void dfs(int u, int par) {
int lef = cnt;
bool leaf = true;
for (int v : edge[u]) {
if (v == par) continue;
... | 4 |
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll ans=0,n,i,j,u,k,x,y,p,sum,st,ok=0,pos[605],dp[2][1205][1205],fac[605],inv2[605],invfac[605];
const ll mod=1e9+7;
ll pow(ll a,ll b)
{
ll ans=1;
while(b)
{
if(b&1)ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
ll col(ll a){ret... | 0 |
#include <bits/stdc++.h>
using namespace std;
set<int> s;
int n, m, l, r, x, a[int(3e5) + 123];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) s.insert(i);
s.insert(int(1e9));
for (int i = 1; i <= m; i++) {
cin >> l >> r >> x;
int j = *s.lower_bound(l);
while (1) {
if (j == int(1e9))... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long a[300005][2];
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
long long sum = 0;
long long m = 1e14;
for (int i = 0; i < n; i++) {
scanf("%lld%lld", &a[i][0], &a[i][1]);
}
if (n == 1) {
cout << a[0][0] << ... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
int parent[150000];
int size[150000];
long long int edges[150000];
struct dsu {
void init(int n) {
for (int i = 0; i < n; ++i) {
parent[i] = i;
size[i... | 2 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n,p;
cin >> n >> p;
vector<ll> x(1000000);
if(n==1){
cout << p << endl;
}
else{
for(ll i=2;i<=1000000;i++){
while(p%i==0){
x[i]++;
p/=i;
}
}
ll ans=1;
for(ll i=2;i<=1000000;i++){
for(int j=1... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main()
{char c; cin >> c;
string s = "aeiou";
cout << (s.find(c) != string::npos ? "vowel" : "consonant") << endl;} | 0 |
#include <bits/stdc++.h>
using namespace std;
long long por[70];
int main() {
long long l, r, i, j, k, m, n, x;
ios::sync_with_stdio(0);
cin.tie(NULL);
cin >> n;
por[0] = 1;
for (i = 1; i < 70; i++) por[i] = por[i - 1] * 2;
while (n--) {
cin >> l >> r;
m = log2(r + 1);
if (por[m] - 1 >= l)
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int bPow(int v, int u, int mod) {
if (!u) return 1;
int res = bPow(v, u / 2, mod);
res = (res * 1ll * res) % mod;
if (u & 1) res = (res * 1ll * v) % mod;
return res;
}
void faster() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
if (0) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0;
int f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
return x * f;
}
void print(long long x) {
if (x < 0) x = -x, ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int M = 100;
char s[M];
char ss[M];
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%s", s);
int num1 = 0, num2 = 0;
if (s[0] == 'R') {
int i = 1;
while ('0' <= s[i] && s[i] <= '9') num1 = num1 * 10 + s[i++] - '0';
if (i >... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
int n, fa[N], dfn[N], ord, mark[N], len, vis[N];
vector<int> G[N];
void dfs(int u) {
dfn[u] = ++ord;
for (auto& v : G[u])
if (v ^ fa[u]) {
if (!dfn[v]) {
fa[v] = u;
dfs(v);
} else if (dfn[v] < dfn[u]) {
for (in... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[m + 1];
int b[m + 1];
for (int i = 0; i < m; i++) {
cin >> a[i];
b[i] = a[i];
}
int res1 = 0;
for (int p = 1; p <= n; p++) {
int mmax = 0;
int chos = 0;
for (int i = 0; i < m; i++) {
if (m... | 2 |
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
ll h,w;
cin >> h >> w;
ll ans=h*w;
for(int k=0;k<2;k++){
for(ll i=1;i<=h;i++){
ll tmp;
ll sa,sb,sc;
ll sm,sM;
sa=i*w;
sb=(h-i)/2*w;
sc=h*w-(sa+sb);
sM=max({sa,sb,sc});
sm=min({sa,sb,sc});
tmp=s... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
long long a, b, c, d, V, M;
cin >> a >> b >> c >> d;
M = max(3 * a / 10, a - a / 250 * c);
V = max(3 * b / 10, b - b / 250 * d);
if (V > M)
cout << "Vasya";
else if (V < M)
cout << "Misha";
else
cout << "Tie";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
long long ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1) ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
... | 4 |
#include<iostream>
using namespace std;
char a[200005];
int main(){
int k;
int total=0;
int count=0;
cin>>k;
for(int i=1;i<=k;i++){
cin>>a[i];
if(a[i]=='R'){
count++;
}
}
for(int i=1;i<=count;i++){
if(a[i]!='R'){
total++;
}
}
cout<<total<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int MAX = 1e9 + 5;
long long i, j, k, n, m, Right[N][2], Left[N][2], ans, C[N];
int main() {
scanf("%lld", &n);
for (int i = 1; i <= n - 1; i++) scanf("%lld", &C[i]);
for (int i = n; i >= 1; i--) {
Right[i][0] = (C[i] != 1) * Right[i +... | 3 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int w = 0, f = 1;
char c = ' ';
while (c < '0' || c > '9') f = (c == '-' ? -f : f), c = getchar();
while (c >= '0' && c <= '9') w = w * 10 + c - '0', c = getchar();
return w * f;
}
int n, a[5005], b[5005], c[5005], d[5005], t[5005], ans, p[5005], vis[... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, s;
cin >> n >> s;
vector<int> a(n);
for (auto&& e : a)
cin >> e;
int ans = 0;
vector<int> dp(s + 1);
for (int i = 0; i < n; i++) {
dp[0] = i + 1;
for (int j = s; j >= a[i]; j--) {
dp[j] += dp[j - a[i]];
dp[j] %= 9... | 0 |
#include <bits/stdc++.h>
using namespace std;
void RI() {}
template <typename... T>
void RI(int& head, T&... tail) {
scanf("%d", &head);
RI(tail...);
}
mt19937 rng(0x5EED);
int randint(int lb, int ub) {
return uniform_int_distribution<int>(lb, ub)(rng);
}
const int INF = 1029384756;
struct Edge {
int v, f, c, r... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s, x;
cin >> s;
x = s;
for (int i = s.size() - 1; i >= 0; i--) x[i] = max(s[i], x[i + 1]);
for (int i = 0; i < s.size(); i++)
if (s[i] ... | 1 |
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>
#define MOD (1000000007)
using namespace std;
typedef long lo... | 0 |
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, sum = 0;
while (true) {
cin >> n;
if (n == 0) break;
else {
vector<int>a(n);
for (int i = 0; i < n; i++) {
cin >> a.at(i);
sum += a.at(i);
}
double ave = sum / n;
int ans = 0;
for (int i = 0; i < n; i++) {
... | 0 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
int t;
cin>>t;
while(t-->0){
ll a,b,k;
cin>>a>>b>>k;
ll f1[a+1];
ll f2[b+1];
memset(f1,0,sizeof(f1));
memset(f2,0,sizeof(f2));
for(int i=0;i<k;i++){
int data;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e4 + 5;
int n, k, len, tot, a[N], ans = 1e8, vis[11], Min, num[11];
char s[N], anss[N], str[N];
int main() {
cin >> n >> k >> s;
len = strlen(s);
for (int i = 0; i < len; i++) num[s[i] - '0']++;
for (int i = 0; i <= 9; i++) {
int tot = num[i], sum... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int n, m, k;
long long ans;
int main() {
cin >> n >> m >> k;
if (k == 1 || k > n) {
ans = 1;
for (int i = 1; i <= n; ++i) ans = ans * m % MOD;
} else if (k == n) {
ans = 1;
int t = (n + 1) / 2;
for (int i = 1; i <= t; ++... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long cnt = 0;
int k2, k3, k5, k6;
cin >> k2 >> k3 >> k5 >> k6;
while (k6 && k5 && k2) {
cnt += 256;
k6--, k5--, k2--;
}
while (k3 && k2) {
k3--, k2--;
cnt += 32;
}
cout << cnt;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long tree[4 * 11111 + 1], arr[11111];
void init(int left, int right, int index) {
if (left == right) {
tree[left] = arr[index];
}
}
int main() {
int N;
cin >> N;
long long arr[N];
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
long long fig = 0;... | 2 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int n;
while (cin >> n, n) {
vector<int> M(n), mask(n);
vector<ll> L(n);
for (int i = 0; i < n; i++) {
cin >> M[i] >> L[i];
for ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int A[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2};
int main() {
int a, b;
string s;
cin >> s;
for (int i = 0; A[i]; i++) {
if (s[0] - '0' == i) a = A[i];
if (s[1] - '0' == i) b = A[i];
}
cout << a * b << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char a = getchar();
while (a < '0' || a > '9') {
if (a == '-') f = -1;
a = getchar();
}
while (a >= '0' && a <= '9') x = x * 10 + a - '0', a = getchar();
return x * f;
}
int n, k, head[200000 + 5], cnt = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, a, bit[100010];
void update(int x, int val) {
for (; x <= n; x += x & -x) bit[x] += val;
}
int query(int x) {
int sum = 0;
for (; x > 0; x -= x & -x) sum += bit[x];
return sum;
}
set<pair<int, int> > s;
set<pair<int, int> >::iterator it;
int main() {
scanf(... | 2 |
#include <bits/stdc++.h>
using namespace std;
int N, ans, tot;
int ar[1002][1002];
int main() {
cin >> N;
while (tot <= N) {
ans++;
tot += ans;
}
cout << ans << endl;
tot -= ans;
ans--;
int temp = 0;
for (int i = 0; i < ans; i++)
for (int j = i; j < ans; j++) {
ar[i][j] = temp + 1;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
struct column {
int a[13];
int x;
};
column c[2001];
bool cmp(column p, column q) { return p.x > q.x; }
int s[13][4096], f[13][4096];
int mian() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) scanf("%d", &c[j].a[i]);... | 5 |
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;
struct Node{
int key;
Node *right, *left, *parent;
};
Node *root, *NIL;
Node *treeMinimum(Node *x){
while(x->left != NIL) x = x->left;
return x;
}
Node *find(Node *u,int k){
while((u != NIL) && (k!=u->key)){
if... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
double S = .0;
int cnt = 0;
double A[100];
for (int i = 0; i < 2 * n; ++i) {
double v;
cin >> v;
A[i] = v;
double x = v - floor(v);
if (x > 0.0001) {
cnt++;
S += x;
}
}
double best2 = 1e9;
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long l, r;
cin >> l >> r;
long long arr[10000];
arr[1] = 4;
arr[2] = 7;
int num = 3;
for (int i = 1; i < 1000; i++) {
arr[num++] = arr[i] * 10 + 4;
arr[num++] = arr[i] * 10 +... | 1 |
#include <bits/stdc++.h>
int n, m, s, t;
int main() {
scanf("%d%d%d%d", &n, &m, &s, &t);
if (m == 1 || ((s - 1) / m == (t - 1) / m)) {
printf("1\n");
return 0;
}
int res = (t - ((s - 1) / m + 1) * m > m || s % m == 1);
if ((t % m && t != n) || !res) res++;
if (s % m != 1) res++;
if ((t - 1) % m + ... | 1 |
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
const int INF = 1e9;
const ld EPS = 1e-8;
int main(){
int N, x;
cin >> N >> x;
if(x == 1 || x == 2 * N - 1) {
cout << "No" << endl;... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
void itval(istream_iterator<string> it) {}
template <typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args)... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MM = 1e9 + 7;
long long a[101][101], b[101][101], c[101][101], ans[101][101];
long long digit[10];
long long n, bb, aim, mm;
void matrix_mul(long long z[101][101], long long x[101][101],
long long y[101][101]) {
int i, j, k;
long long ans[101][... | 5 |
/*#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
priority_queue<ll,vector<ll>,greater<ll> >q;
ifstream file("C:\\Users\\86180\\Desktop\\P4149_2.txt");
file>>n>>m;*/
#include<bits/stdc++.h>
#define ll long long
#define INF 0x... | 1 |
#include <bits/stdc++.h>
int main() {
long long int n, m, result = 0, b;
scanf("%I64d %I64d ", &n, &m);
long long int a[n];
for (int i = 0; i < n; i++) {
scanf("%I64d ", &a[i]);
}
for (int j = 0; j < n; j++) {
result += a[j];
b = floor(result / m);
if (result >= m) {
result %= m;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void debug(T1 e) {
cout << e << endl;
}
template <class T1, class T2>
void debug(T1 e1, T2 e2) {
cout << e1 << "\t" << e2 << endl;
}
template <class T1, class T2, class T3>
void debug(T1 e1, T2 e2, T3 e3) {
cout << e1 << "\t" << e2 << "\t" << e3 <<... | 1 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '.')
cout << 0;
else {
if (s[i + 1] == '.') {
cout << 1;
i++;
} else {
cout << 2;
i++;
}
}
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
int n;
string s;
while (t--) {
cin >> n >> s;
int x = 0, y = 0;
map<pair<int, int>, int> m;
int l = 0, r = n + 1;
m[{0, 0}] = 1;
for (int i = 0; i < n; i++) {
if (s[i] == 'L') x--;
if (s[i] == 'R') ... | 3 |
#include <bits/stdc++.h>
using namespace std;
char ch[110], s[110], ok[110];
int vis[110], f[110];
int n, k, len;
bool check(int k) {
for (int i = 0; i < len; i++)
if (ch[i] != s[i + k]) return 0;
return 1;
}
bool yes() {
for (int i = 0; i < n - len + 1; i++)
if (ok[i] == '0') {
if (check(i)) return... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
std::vector<int> edge[1000005];
int vis[1000005];
int res[1000005];
int dfs(int u, int f) {
int cnt = 1;
vis[u] = 1;
for (int i = 0; i < edge[u].size(); i++) {
int v = edge[u][i];
if (v == f) continue;
i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int u[maxn];
int find(int x){
if(x == u[x]) return x;
return u[x] = find(u[x]);
}
int main(){
int n, m;
iota(u, u + maxn, 0);
cin >> n >> m;
for(int i = 0; i < m; i++){
int x, y, z;
cin >> x >> y >> z;
u[find(x)] = find(y);
}
int ans =... | 0 |
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int n,l,r;
int a[60];
bool uru(int x){
fo... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string s;
cin >> s;
string p = "";
if (s[0] == '0') {
for (int i = 0; i < n / 2; i++) {
p += '0';
p += '1';
}
} else {
for (int i = 0; i < n / 2;... | 2 |
#include <cstdio>
#define iter(i, n) for (int i = 1; i <= n; ++i)
const int NR = 1e5 + 100;
int n, a[NR], c[2];
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int main() {
//freopen("10D.in", "r", stdin);
scanf("%d", &n);
iter(i, n) scanf("%d", &a[i]);
bool cur = 0;
while (true) {
c[0] = c[1] = 0... | 0 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
vector<pair<int, int>> process;
long long ans = a[n - 1];
long long tmp = a[0];
for (int i = 1; i < n - 1;... | 0 |
#include <bits/stdc++.h>
using namespace std;
char ch[1205];
stack<pair<int, int> > sta;
int main() {
int n, i, l, r, pos = 0;
cin >> n;
for (i = 1; i <= (n); i++) {
cin >> l >> r;
ch[++pos] = '(';
sta.push(make_pair(pos + l, pos + r));
while (!sta.empty()) {
if (sta.top().second <= pos) put... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, k;
cin >> n >> m >> k;
int p[105];
int s[105];
priority_queue<int> pq[105];
for (int i = 0; i < n; i++) cin >> p[i];
for (int i = 0; i < n; i++) {
cin >> s... | 1 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 50;
int n;
char g[MAXN][MAXN + 1];
char ret[2 * MAXN - 1][2 * MAXN];
void run() {
scanf("%d", &n);
for (int i = (0); i < (n); ++i) scanf("%s", g[i]);
for (int i = (0); i < (2 * n - 1); ++i) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 107;
struct eT {
void setd(int _u, int _v, int _l) { u = _u, v = _v, last = _l; }
int u, v, last;
} edge[MAXN... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5, mod = 1e9 + 7;
int N, basis[30], Q, sz;
int a[maxn], res[maxn];
vector<pair<int, int> > query[maxn];
int pow2[maxn];
signed main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
function<void(int)> ins = [&](int mask) {
fo... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int n = s.size(), o = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1') o++;
}
int z = n - o;
if (o == n)
cout << 0 << endl;
else if (z == n)
cout << 1 <<... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans = 0;
for (int i = 0; i < n; i++) {
int val;
cin >> val;
if (val >= 0)
ans += val;
else
ans -= val;
}
cout << ans << endl;
}
| 1 |
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#includ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int seed = 19260817;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
char a[maxn], str1[maxn], str2[maxn];
unsigned long long h[maxn], p[maxn];
void Hash(char *s, int len) {
p[0] = 1;
for (int i = 1; i <= len; i++) {
h[i] = h[i - 1] * seed + s[i];
p[i] ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> b;
int m, n;
cin >> n >> m;
for (int i = 1; i <= 4 * n; i++) {
if (i <= m)
b.push_back(i);
else
b.push_back(0);
}
n = b.size() / 2;
for (int i = 0; i < n; i++) {
if (b[n + i] != 0) cout << b[n + i] << " ";
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long INFLL = 1e12;
const long long MOD = 1000000007;
const long double eps = 1e-6;
const long long MOD2 = (1 << 30) + 1;
const long long dosz = 5e5;
void fast_io() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void so... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<long long, long long> > M;
vector<pair<long long, long long> > M2;
vector<vector<int> > graph;
vector<pair<int, int> > Hash11;
vector<pair<int, int> > Hash22;
long long base1 = 1000357;
long long base2 = 1000577;
inline void Hash() {
for (int i = 0; ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2010;
int main() {
int n;
int sum;
while (scanf("%d", &n) != EOF) {
sum = 0;
double k;
int cnt = 0;
for (int i = 0; i < 2 * n; i++) {
scanf("%lf", &k);
int a = (int)(k * 1000 + 0.5) % 1000;
if (a == 0) cnt++;
su... | 1 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> Hash;
struct rec {
int x0, x1, y0, y1;
void role() {
if (x0 > x1) swap(x0, x1);
if (y0 > y1) swap(y0, y1);
}
} E[23333];
int nx, ny, num, tot;
int g[23333], valx[23333], valy[23333];
int dx[8] = {0, 1, -1, 0, 0};
int dy[8] = {0, 0, 0, 1, -1};
boo... | 3 |
#include <bits/stdc++.h>
const long long int MOD = 1e9 + 7;
const long long int INF = 1011111111;
const long long int LLINF = 1000111000111000111LL;
const long double EPS = 1e-10;
const long double PI = 3.14159265358979323;
using namespace std;
inline long long int add(long long int a, long long int b) {
a += b;
if... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 2;
int N, student[MAXN * 3];
vector<int> membersWith[MAXN * 3];
bool assigned[MAXN * 3], printed[MAXN * 3];
int K;
int main() {
scanf("%d", &N);
for (int i = 0; i < 3 * N; i++) scanf("%d", &student[i]);
for (int i = 0; i < N; i++) {
int a, b... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> p(n);
for (auto& e : p) cin >> e;
int r = 0;
for (int i = 1; i < n - 1; i++) r += p[i - 1] < p[i] && p[i] < p[i + 1] || p[i + 1] < p[i] && p[i] < p[i - 1];
cout << r << endl;
}
| 0 |
#include <bits/stdc++.h>
int const nmax = 300000;
int v[1 + nmax];
std::vector<int> g[1 + nmax];
int main() {
int n, m;
std::cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x, y;
std::cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
std::queue<int> q;
for (int i = 1; i <= n; i++) q.p... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 8;
int n, a[N], b[N], prt[N], t, x, ii, ij;
bool mrk[N], mark[N], bl;
vector<pair<int, int> > nei[N];
vector<pair<int, pair<int, int> > > vec;
void dfs(int v, int par = 0, int ind = -1) {
mrk[v] = 1;
while (prt[v] < nei[v].size()) {
auto p = nei[... | 2 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=2e6+10;
int gi() {
int x=0,o=1;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T mulmod(T a, T b) {
if (b == 0) return 0;
if (b == 1) return a;
T x = mulmod(a, b >> 1);
x = (x + x) % 1000000007;
if (b & 1) x = (x + a) % 1000000007;
return x;
}
template <class T>
T larger(T a, T b) {
return (a > b ? a : b);
}
template <... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string inp[3];
vector<string> ans;
cin >> inp[0] >> inp[1] >> inp[2];
for (int i = 0; i < 3; i++) {
string f = "";
string a = inp[i];
for (int j = 0; j < a.length(); j++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long modexpo(long long x, long long p) {
long long res = 1;
x = x % 1000000007;
while (p) {
if (p % 2) res = res * x;
p >>= 1;
x = x * x % 1000000007;
res %= 1000000007;
}
return res;
}
struct compare {
bool operator()(const pair<long long, ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)2e9;
const long long md = 1000000007;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
int N = 1 << n;
vector<int> v[n + 1];
int tempSize = N;
for (... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool ok[] = {1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1,
1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1};
int main() {
string s;
cin >> s;
int n = s.size();
for (int i = 1; i < n; i++) {
if (ok[s.front() - 'A'] != ok[s[i] - 'A']) {
cout << "NO" << endl;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int k, a[2010];
int main() {
scanf("%d", &k);
int n = 2000;
int s = k + n;
a[1] = -1;
for (int i = 2; i <= n; i++) {
a[i] = min(1000000, s);
s -= a[i];
}
printf("%d\n", n);
for (int i = 1; i <= n; i++) printf("%d ", a[i]);
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int n, a = 2;
cin >> n;
while (a > 0) {
a = 2 * a;
a = a - 1;
if (n % a == 0)
break;
else
a = a + 1;
}
cout << n / a << endl;
}
}
| 1 |
#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--) {
string str;
cin >> str;
int dp[str.size()];
memset(dp, 0, sizeof(dp));
for (int i = 0; i < str.size(); i++) {
if (str[i] == 'L') {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
long double read_ldb() {
double t;
scanf("%lf", &t);
return t;
}
const int MAXN = 100005;
struct Point {
long double x, y;
Point() {}
Point(long double _x, long double _y) : x(_x), y(_y) {}
Point operator+(const Point &t) const { ... | 5 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
long long ans = 0, cnt = 0;
char c;
for (long long i = 0; (0 < n) ? (i < n) : (i > n); (0 < n) ? (i++) : (i--)) {
cin >> c;
if (c == '(')
cnt++;
else
cnt--;
if (cnt < 0) {
cnt = 0;
ans++... | 3 |
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfl... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const double pi = acos(-1.0);
int mod = 1e9 + 7;
long long Mod(long long x) { return x >= mod ? x - mod : x; }
long long read() {
long long x = 0;
int f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int n, k, r[1001];
pair<pair<int, int>, int> p[1001];
bool used[1001];
int acc, sum, mnj;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
p[i].second = i + 1;
cin >> p[i].first.second >> p[i].first.first;
}
sort(&p[0], (&p[0])... | 3 |
#include <bits/stdc++.h>
int main() {
std::cout << "25\n";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int A[200005], B[200005], N;
int O[200005][5];
void ucitaj() {
scanf("%d", &N);
if (N == 5) {
printf("1 5 3 4 2\n");
exit(0);
}
int i, j;
for (i = 1; i <= 2 * N; i++) {
scanf("%d%d", A + i, B + i);
if (O[A[i]][1] == 0)
O[A[i]][1] = B[i];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long int INF = INT_MAX, NINF = INT_MIN;
const long long int mod = 1e9 + 7;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(u... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long i, j, a = 10, b, c, d, n, m, t;
cin >> t;
while (t--) {
string s;
cin >> s;
n = s.size();
vector<long long> vec;
for (i = 0; i < n; i++) {
m = s[i] - '0';
d = n - i - 1;
b = pow(a, d);
if (b % 10 != 0 ... | 1 |
#include <cstdio>
#include <cstdint>
#include <cctype>
#include <cassert>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <stack>
#include <map>
#define fprintf(...) void(0)
std::map<size_t, size_t> preprocess(const std::string &s, std::string &t) {
std::stack<size_t> opened;
... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int x;
cin>>x;
cout<<x/30<<' '<<x%30*2<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int N = 500010;
int first[N], Next[N << 1], V[N << 1];
int n;
int L[N], R[N], mk1[N << 2];
int tim;
void DFS(int u, int f) {
L[u] = ++tim;
for (int i = first[u]; i != -1; i = Next[i]) {
int v = V[i];
if (f == v) continue;
... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.