solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N; cin >> N;
string ans = "No";
for (int i=0; i*7<=N; ++i) if ((N-7*i)%4==0) ans = "Yes";
cout << ans << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int a, b, c;
cin >> a >> b >> c;
int x = a, y = b, z = c;
int sum = 0;
int sum1 = 0;
if (b / 2 > a) {
sum += a + 2 * a;
b = b - 2 * a;
} else {
sum += b / 2 + b / 2 * 2;
b = b - b / 2 * 2;
}
if (c / 2 > b) {
sum += b + 2 ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int INF = 1 << 28;
const long long INFL = 1LL << 62;
string str[] = {"YES", "NO"};
int main() {
int n;
cin >> n;
int x[7];
for (int i = 0; i < 7; i++) cin >> x[i];
for (int i = 0; true; i++) {
n -= x[i % 7];
if (n <= 0) {
... | 1 |
#include <iostream>
using namespace std;
int main() {
long long int data[10][1001] = {1};
for (int k = 0; k <= 100; ++k)
for (int i = 9; 1 <= i; --i)
for (int j = k; j <= 1000; ++j)
data[i][j] += data[i-1][j-k];
int n, s;
while (cin >> n >> s) {
if (n == 0)
break;
cout << data... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> myodd, myeven;
bool cmp(int a, int b) { return a > b; }
int main() {
scanf("%d", &n);
int tmp;
int sum = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &tmp);
sum += tmp;
if (tmp % 2 == 0) {
myeven.push_back(tmp);
} else {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(nam... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int numlet = 26;
int dp[maxn][numlet];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
for (int i = 1; i <= n; ++i) {
int idx = (s[i - 1] - 'a');
for (int j = 0; j < 26; ++j) {
... | 2 |
#include<iostream>
//#include<string>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
if(a<b&&b<c){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}
| 0 |
#include <bits/stdc++.h>
long long map[5][5];
long long dp[40 + 5][8][8];
long long min(long long a, long long b) {
if (a > b)
return b;
else
return a;
}
int main() {
for (int i = 1; i <= 3; i++)
for (int j = 1; j <= 3; j++) scanf("%I64d", &map[i][j]);
int n;
scanf("%d", &n);
for (int i = 1; i <... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, t, r;
int a[310];
cin >> m >> t >> r;
for (int i = 0; i < m; i++) cin >> a[i];
sort(a, a + m);
int ans = 0;
set<int> cand;
for (int i = 0; i < m; i++) {
while (!cand.empty() && *(cand.begin()) <= a[i]) cand.erase(cand.begin());
in... | 3 |
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 100005
using namespace std;
int n, ans, c = 1, a[N];
int main()
{
int i;
cin >> n;
for (i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
for (i = 0; i < n; i++) {
if (a[i] == a[i + 1]) c++;
else ans += c < a[i] ? c : c - a[i], c = 1;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, i, y, x, s, xx, yy, j;
cin >> a >> b;
for (x = a - 1; x >= 1; x--) {
s = a * a - x * x;
y = (int)sqrt(s);
if (y * y != s) continue;
for (j = b - 1; j >= 1; j--) {
s = b * b - j * j;
yy = (int)sqrt(s);
if (yy * y... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long lower(long long x) {
long long ret = 0;
for (long long i = 1; i <= n; i++) ret += min(m, x / i);
return ret;
}
int main() {
scanf("%I64d%I64d%I64d", &n, &m, &k);
long long l = 1, r = n * m + 1;
while (l < r) {
long long mid = (l ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s; cin >> s;
cout << s.substr(0, s.length() - 8) << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
int t = 0;
for (int i = 0; i < n;) {
int j = i + 1;
if (s[i] == 'A')
while (j < n && s[j] == 'P') ++j;
t = max(t, j - i - 1);
i = j;
}
cout << t << endl;
}
int main(... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int M = 110, N = 20020;
const double pi = acos(-1.0), INF = 1e9;
int n, m, T, X, u, v, w, L, o, rv[N << 2], d[M][M];
double p[M][N], f[M][N], g[M][N], s[M][N];
char bu[100100], *cl(bu), *cr(bu);
struct edge {
int u, v, w;
} E[M];
struct cpx {
double x, y;
cpx(do... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pa... | 0 |
#include <bits/stdc++.h>
using namespace std;
stack<char> st;
set<char> se;
int main() {
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
string s;
int i, j, k, x, y, z, a, b, c;
cin >> s;
se.insert('a');
se.insert('e');
se.insert('i');
se.insert('o');
se.insert('u');
for (i = 0; s[i];... | 1 |
#include<bits/stdc++.h>
#define ce(i, r) i==r?'\n':' '
using namespace std;
const int N = 405, M = 605, MOD = 998244353;
int head[N], ver[M << 1], Next[M << 1], tot;
int d[N][N], cnt[N][N], n, m;
queue<int> q;
inline void add(int x, int y) {
ver[++tot] = y;
Next[tot] = head[x];
head[x] = tot;
}
inline v... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,abm,mmx,tune=native")
using namespace std;
long long gcd(long long i, long long j) {
if (j == 0)
return i;
else
return gcd(j, i % j);
}
template <typename T>
inline T getint() ... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, int> > A;
int n, m;
int B[1000000];
int C[10];
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
pair<pair<int, int>, int> a;
cin >> a.first.first >> a.first.second;
a.second = i;
A.push_back(a);
}
sort(A.begin(), ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int a, b, p, x;
long long int fexp(long long int k, int e, long long int mod = p) {
long long int ans = 1;
while (e) {
if (e & 1) {
ans = k * ans % mod;
}
k = k * k % mod;
e >>= 1;
}
return ans;
}
int main() {
ios::sync_with_stdio(0... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long MAXN = 1e5 + 20, MOD = 1e9 + 9;
long long n, m, cmp[MAXN], ans = 1;
vector<long long> c[MAXN];
void dsu(long long u, long long v) {
u = cmp[u], v = cmp[v];
if (u == v) return;
if (c[u].size() > c[v].size()) swap(u, v);
for... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const ld pi = acos(0) * 2;
template <typename T>
inline void read(T &x) {
char c;
bool nega = 0;
while ((!isdigit(c = getchar())) && (c != '-... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long BL[N], a[N];
struct query {
long long l, r, id;
};
bool cmp(query a, query b) {
if (BL[a.l] != BL[b.l]) return BL[a.l] < BL[b.l];
return BL[a.l] % 2 ? a.r > b.r : a.r < b.r;
}
int32_t main() {
ios_base::sync_with_stdio(0);
ci... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class X, class Y>
void minimize(X &x, const Y &y) {
if (x > y) x = y;
}
template <class X, class Y>
void maximize(X &x, const Y &y) {
if (x < y) x = y;
}
template <class T>
T Abs(const T &x) {
return (x < 0 ? -x : x);
}
class FenwickTree {
private:
vector... | 5 |
#include<bits/stdc++.h>
using namespace std;
#define fr(i, n) for(ll i = 0; i < n; i++)
#define frr(i, n) for(ll i = 1; i <= n; i++)
#define frm(i, n) for(ll i = n-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<ll, ll> pll;
typedef p... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
vector<int> a(26, 0);
for (int i = 0; i < n; i++) {
a[s[i] - 65]++;
}
sort(a.begin(), a.end());
int sum = 0;
long long v = 0;
for (int i = 25; i >= 0; i--) {
if (sum + a[i] <= k) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y, m, w, i = 0, j = 0;
cin >> n;
if (n == 0 || n == 1) {
cin >> x >> y;
cout << "-1" << endl;
}
int v[4][2];
for (i = 0; i < n; ++i)
for (j = 0; j < 2; ++j) cin >> v[i][j];
if (n == 2) {
if (v[0][0] == v[1][0] || v[1][1] ... | 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
typedef pair<int,int> P;
const int INF=numeric_limits<int>::max();
const int N=1e5+5;
int n,m,dist[N];
vector<P> adj[N];
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
for(int i=0;i<m;++i){
int l,r,d;
cin>>l>>r>>d;
adj[l].emp... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
(ios_base::sync_with_stdio(false), cin.tie(NULL));
int n;
cin >> n;
vector<int> p(n);
for (int i = 0; i < (int)(n); ++i) cin >> p[i];
int l, r, mx, mn;
l = r = 0;
mn = mx = p[0];
multiset<int> s;
s.insert(p[0]);
int ans = 1;
while (r < n... | 2 |
#include <bits/stdc++.h>
long long a[100000 + 20];
int main() {
int n;
while (scanf("%d", &n) != EOF) {
long long maxi = 0, max = -999999;
long long k = 1;
for (int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
if (abs(a[i]) < abs(-1 - a[i]) && -1 - a[i] != 0) a[i] = -1 - a[i];
if (a[i] >... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int N = 500001;
vector<int> g[N];
set<int> s[N];
int a[N], d[N];
vector<int> ord;
void dfs(int v) {
if (d[v] || s[v].size() < a[v] - 1) return;
d[v] = 1;
ord.push_back(v);
for (int u ... | 4 |
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcount... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
int a[n];
for(int i = 0; i < n; ++i) {
cin >> a[i];
a[i] -= i + 1;
}
sort(a, a + n);
long long sum = 0, mid = a[n/2];
for(int i = 0; i < n; ++i) sum += abs(a[i] - mid);
cout << sum;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int dig(long long n) {
int ans = 0;
while (n > 0) {
n /= 10;
ans++;
}
return ans;
}
set<long long> s;
int main() {
long long n;
while (cin >> n) {
int sz = dig(n);
s.clear();
for (int i = 0; i <= 9; i++) {
for (int j = 0; j <= 9; j++) {... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
double ans;
vector<int> vec[1001000];
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
vec[x].push_back(i);
}
for (int i = 1; i <= 1000000; i++) {
double cnt = 0;
for (int j = 0; j < vec... | 6 |
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
int main(){
int q,lim,query,x;
while(1){
deque<int> l;
cin >> q >> lim;
if(!q && !lim)break;
for(int i=0;i<q;i++){
cin >> query >> x;
if(query==0){
l.push_back(x);
if((int)l.size()>lim)l.pop_front();
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int fa[100001];
inline int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); }
int main() {
int m, n;
cin >> m >> n;
vector<int> a(m), b(n);
for (int i = 0; i < (m); i++) cin >> a[i];
for (int i = 0; i < (n); ... | 5 |
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define int long long
#define maxn (111)
int a[maxn][maxn], xor_[maxn << 1];
signed main()
{
int t; cin >> t; while(t--) {
int n, m; cin >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
scan... | 6 |
#include <bits/stdc++.h>
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline void sub(long long &a, long long b) {
a -= b;
if (a < 0) a += 1000000007;
}
inline void add(long long &a, long long b) {
a += b;
if (a >= 1000000007) a -= 1000000007;
}
template <typename T>
inline T... | 4 |
#include<iostream>
#include<string>
int main(){
int month,day;
const int monthday[12]={31,29,31,30,31,30,31,31,30,31,30,31};
const std::string week[7]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
const int a=3;
while(1){
std::cin>>month>>day;
if(month==0)break;
int sum=day+a;
f... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int32_t x;
scanf("%d", &x);
return x;
}
inline long long lin() {
long long x;
scanf("%lld", &x);
return x;
}
inline int mul(int a, int b) {
long long x = a;
x *= (long long)b;
if (x >= 1000000007) x %= 1000000007;
return x;
}
inline int... | 3 |
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
using namespace std;
typedef long long LL;
const int MAXN = 10000007;
const int MOD = 998244353;
template <typename T> inline void read(T &AKNOI) {
T x = 0, flag = 1;
char ch = get... | 0 |
#include <cstdio>
#include <algorithm>
#define N 10000
using namespace std;
/** Application main entry point. */
int
main (
int argc,
char * argv[ ]
)
{
int i, j;
for ( ; ; )
{
int d[ N * 2 ];
int n, m;
int res;
scanf ( "%d%d", &n, &m );
if ( !( n | m ) ) break ;
m += n;
... | 0 |
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
ll b;
while (cin >> b... | 0 |
#include <bits/stdc++.h>
#define M 1000000007
using namespace std;
long long n, kk, dp[51][51][65], ans[51][51], temp[51][51], res;
int main() {
cin>>n>>kk;
for (int i=0; i<n; i++) {
ans[i][i]=1;
for (int j=0; j<n; j++) cin>>dp[i][j][0];
}
for (int k=1; k<64; k++) {
for (int i=0; i<n; i++) {
for (int j=... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int LIM_N = 3e5 + 5;
set<int> ans;
int pr[LIM_N];
vector<pair<int, int> > adj[LIM_N];
bool usd[LIM_N];
void dfs(const int pos = 0, const int pv = -1, const int pe = -1) {
usd[pos] = true;
for (const auto nxt : adj[pos]) {
if (!usd[nxt.second]) dfs(nxt.second, ... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T MIN_3(T a, T b, T c) {
return min(min(a, b), c);
}
template <class T>
inline T MAX_3(T a, T b, T c) {
return max(max(a, b), c);
}
template <class T>
inline T BIGMOD(T n, T m, T mod) {
long long int ans = 1;
long long int k = n;
while (m... | 1 |
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<algorithm>
using namespace std ;
typedef pair<int,int> P ;
#define F first
#define S second
int N , table[100100] ;
priority_queue<P,vector<P>,greater<P> > minPQ ;
map<int,int> MP ;
int main(){
cin >> N ;
for( int i=0 ; i<N ; i++ ) cin >> t... | 0 |
#include <iostream>
using namespace std;
int main() {
string O, E;
cin >> O >> E;
for (int i = 0; i < O.size(); ++i) {
cout << O[i];
if (i < E.size()) cout << E[i];
}
cout << endl;
return 0;
} | 0 |
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int n, k;
vector<int> w;
bool okrec(int P, int m, int l, int cur) {
if (m == n)
return true;
else if (l == k)
return false;
else if (P - cur >= w[m])
return okrec(P, m + 1, l, cur + w[m]);
else
return okrec(P, m, l + 1, 0);
}
b... | 0 |
#include <bits/stdc++.h>
using namespace std;
string to_string1(long long inp) {
ostringstream ss;
ss << inp;
return ss.str();
}
bool isLucky(long long inp) {
string str = to_string1(inp);
int numLucky = 0;
for (int i = 0; i < str.length(); i++) {
if (str[i] == '4' || str[i] == '7') {
numLucky++;
... | 1 |
#include<iostream>
using namespace std;
int main(){
int s1,s2,s3;
cin>>s1>>s2;
cout<<6-(s1+s2)<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 5;
const long long MAX = 1e16;
long long D[MAXN], num[MAXN][2];
int dp[MAXN][5];
int calc(long long a, long long b, int n) {
if (a > b) swap(a, b);
if (a == b) return 0;
if (n == 1 || n == 2) return 1;
int type = -1;
int ans = 0;
if (a ==... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = INT_MAX - 1;
int main() {
ios_base::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
bool arr1[n];
bool arr2[n];
for (int i = 0; i < n; i++) {
char c;
cin >> c;
if (c ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long const MOD = 998244353;
void yes() { cout << "YES" << '\n'; }
void no() { cout << "NO" << '\n'; }
long long fact(int n) {
long long ans = 1;
for (int i = 2; i <= n; i++) {
ans = (ans * i) % MOD;
}
return ans;
}
long long powM(int n, int x) {
if (x == ... | 6 |
#include <bits/stdc++.h>
int n;
long long K;
int size[100001], head[100001], nxt[200001], b[200001], k, mx[100001], root;
int d[100001], dfn[100001], dep[100001], now, Mx[100001], ord[100001];
int se[1000001];
int max(int a, int b) { return dep[a] > dep[b] ? a : b; }
void build(int root, int l, int r) {
if (l == r) {... | 5 |
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cstdio>
using namespace std;
int vis[50][100010];
int n;
void dfs(int rem, int dist){
if(dist > 45) r... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, m, x, y;
long long k;
scanf("%d%d%I64d%d%d", &n, &m, &k, &x, &y);
int once = n == 1 ? m : (n + n - 2) * m;
long long cnt_full = k / once;
k -= cnt_full * once;
long long ans[100][100];
for (int i = 0; i < n; ++i) {
for (int j = 0;... | 3 |
#include <bits/stdc++.h>
int main() {
int n;
std::cin >> n;
std::vector<char> str(n);
int cnt[2] = {0, 0};
for (int i = 0; i < n; i++) {
std::cin >> str[i];
str[i] = str[i] == 'B' ? 0 : 1;
cnt[str[i]]++;
}
if (cnt[0] % 2 && cnt[1] % 2) {
printf("-1\n");
return 0;
}
bool need = (cnt... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1E-6;
const int LEN = 110;
long long n, m, k, x, y;
long long num[LEN][LEN];
int main() {
while (cin >> n >> m >> k >> x >> y) {
memset(num, 0, sizeof num);
if (n == 2) {
m *= 2;
n = 1;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int cnta[100005][2], cntb[100005][2];
int q[100005][2];
char s[100005];
int dp[100005][2];
int main() {
int n;
scanf("%d", &n);
scanf("%s", s + 1);
for (int i = 1; i <= n; i++) {
if (s[i] == 'a')
cnta[i][i % 2]++;
else if (s[i] == 'b')
cntb[i][i ... | 5 |
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) { cout << (expr ? "Yes" : "No") << "\n"; }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
for (int t = (0), t_end... | 4 |
#include <bits/stdc++.h>
using namespace std;
int countKangroo(vector<int> &arr) {
int res = arr.size();
int i = 0, j = (arr.size() + 1) / 2;
sort(arr.rbegin(), arr.rend());
while (j < arr.size()) {
if (arr[i] < arr[j] * 2) {
++j;
} else {
--res;
++i;
++j;
}
}
return res;... | 1 |
#include<cstdio>
using namespace std;
int main()
{
int n,m;
scanf("%d%d",&n,&m);
if (n%500<=m) printf("Yes");
else printf("No");
} | 0 |
#include <iostream>
using namespace std;
int main()
{
string s;cin>>s;
int ans =700;
for(auto c :s){
if(c=='o')ans+=100;
}
cout<<ans<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int q, l1, r1, l2, r2;
cin >> q;
while (q--) {
cin >> l1 >> r1 >> l2 >> r2;
if (r2 != l1) {
cout << l1 << ' ' << r2 << '\n';
} else {
if (r1 != l2) {
cout << r1 << ' ' <<... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
int n;
long long h;
cin >> n >> h;
priority_queue<pair<long long, bool>> q;
for (int i = 0; i < n; i++) {
long long a, b;
cin >> a >> b;
q.push(make_pair(a, false));
q.push(make_pair(b, true));
}
long long count = 0;
while (h > 0) {
auto t... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int oo = (int)1e9;
const int mod = (int)1e9 + 7;
const int maxn = 1e3 + 5;
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
void myMain() {
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int &i : a) cin >> i;
sort(a.begin(), a.... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long N, x, y;
long long vals[111111];
int main() {
cin >> N >> x >> y;
long long tot = 0, totot = 0;
for (int i = 0; i < N - 1; i++) {
tot++;
totot++;
}
if (tot >= y)
cout << -1 << endl;
else {
int temp = y - tot;
totot += temp * (long l... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double PI =
3.141592653589793238462643383279502884197169399375105820974944592307816406286;
int n, a[400004], b[400004];
bool check() {
int x = a[0];
int i = 0;
while (b[i] != x) i++;
for (int j = i; j < n + i - 1; j++)
if (a[j - i] != b[j]) return fals... | 2 |
#include <bits/stdc++.h>
using namespace std;
int check_prime(long long int num) {
int flag = 1;
if (num % 2 == 0 && num != 2)
flag = 0;
else {
for (long long int i = 3; i <= sqrt(num); i += 2) {
if (num % i == 0) {
flag = 0;
break;
}
}
}
return flag;
}
int main() {
l... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int a[n + 1];
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
if (n % 2 == 0) {
for (int i = 1; i <= n; i += 2) {
printf("%d %d ", -1 * a[i + 1], a[i]);
... | 4 |
#include <bits/stdc++.h>
//using namespace std;
typedef long long ll;
typedef long double ld;
//std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
//int randi = std::uniform_int_distribution<int>(0, 999)(rng);
const double EPS = 1e-9;
const double PI = acos(-1.0);
const ll OO = 2e18 + 10... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[600005];
set<long long> se;
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%s", s);
int l = strlen(s);
long long sum = 0, mul = 1;
for (int j = 0; j < l; j++) {
sum += mul * (s[j] - 'a' + 1);
mul = ... | 3 |
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;i++)
const ll INF=1e15;
const int inf=1e9;
const ll MOD=1e9+7;
int par[100000],depth[100000];
vector<queue<int>> a(100000);
int count;
int findpar(int i){
if(par[i]==-1) return ::count;
else{
::count++;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {}
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
}
int mod = 1e9 + 7;
long long fpow(long long x, long long p) {
if (!p) return 1;
long long sq = fpow(x, p ... | 2 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:32505856")
template <class T>
inline void gmin(T &a, T b) {
if (a > b) a = b;
}
template <class T>
inline void gmax(T &a, T b) {
if (a < b) a = b;
}
template <class T>
inline T sqr(T a) {
return a * a;
}
inline int sign(const double &a)... | 1 |
#include <bits/stdc++.h>
using namespace std;
int Read() {
char c;
while (c = getchar(), (c != '-') && (c < '0' || c > '9'))
;
bool neg = (c == '-');
int ret = (neg ? 0 : c - 48);
while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + c - 48;
return neg ? -ret : ret;
}
const int MAXN = 200005, MOD... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int INF = 1e9 + 7;
const int mod = 998244353;
int n, a, b;
long long sum, res;
struct node {
long long hp, dam;
bool operator<(const node &p) const {
if ((hp - dam) == (p.hp - p.dam)) return p.dam < dam;
return (hp - dam) > (p.hp ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 210;
const int INF = 0x3f3f3f3f;
int n, a[MAXN];
void run() {
cin >> n;
int ans;
if (n <= 2)
ans = 1;
else
ans = (n - 1) / 2 + 1;
cout << (ans) << '\n';
}
int main() {
ios::sync_with_stdio(false);
int T;
for (cin >> T; T--;) run();
}... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class X>
void input(vector<X>& a, int N) {
X temp;
for (long long int i = 0; i < N; i++) {
cin >> temp;
a.push_back(temp);
}
}
void solve() {
int team1[2][2];
int team2[2][2];
for (long long int i = 0; i < 4; i++) {
cin >> team1[i / 2][i % ... | 3 |
#include<iostream>
using namespace std;
int main()
{
char a,b;cin>>a>>b;
if(a>b)cout<<">";
else if(a<b)cout<<"<";
else cout<<"=";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 11;
const long long MOD = 1e9 + 7;
long long fac[MAXN + 5];
long long nfac[MAXN + 5];
long long q_mod(long long a, long long b, long long mod) {
long long ans = 1;
while (b) {
if (b & 1) ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int x, i;
for (i = x = 0; i < s.size(); i++)
if (s[i] == 'x')
x++;
else
x--;
for (i = 1; i <= x; i++) cout << 'x';
for (i = -1; i >= x; i--) cout << 'y';
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
int n;
cin >> n;
int last = 0;
vector<pair<int, int> > v;
for (int i = 0; i < n; i++) {
int k;
cin >> k;
if (k == 0) {
long long cnt = 0;
sort(v.begin(), v.end());
for (last; last < i; last++) {
int q = v.s... | 3 |
#include <iostream>
using namespace std;
int main(void){
int a,b,c,d,e,f,g,h,i,j;
cin >>a>>b>>c>>d>>e>>f>>g>>h;
i = a * e + b * f;
if(a >= 10){
i = i + g * (a/10);
}
if(b >= 20){
i = i + h * (b/20);
}
j = c * e + d * f;
if(c >= 10){
j = j + ... | 0 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
const int mm = 2e5 + 5;
string s;
int n;
int a[3];
void nhap() {
getline(cin, s);
n = s.size();
}
void xuli() {
for (int i = 0; i < n; i++) {
if (s[i] - '?')
a[s[i] - '0']++;
else
a[2]++;
}
if (a[0] + a[2] - 2 >= n... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main(void) {
cin >> a >> b;
for (int i = 1;; i++) {
if (i & 1) {
a -= i;
if (a < 0) {
puts("Vladik");
return 0;
}
} else {
b -= i;
if (b < 0) {
puts("Valera");
return 0;
}
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, x, y, c;
long long calc(long long t) {
long long int ret = 0;
ret += 2 * t * (t + 1) - 4 * t + 1;
if (t > x) {
ret -= (t - x) * (t - x);
}
if (t > n - x + 1) {
ret -= (t - n + x - 1) * (t - n + x - 1);
}
if (t > y) {
ret -= (t - y) * (t - y)... | 4 |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, r, z, a[100100], ans[100100][5], b[100100][5], d[100100],
bb[5];
vector<int> db[5], c[100100];
bool u[200200];
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
for (i = 1; i <= n; i++)
if (!u[i]) {
k = 0;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
signed main()
{
char a,b;
cin >> a >> b;
cout << (a==b ? 'H' : 'D');
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, i, j, k, ans = 0;
cin >> n >> m;
vector<int> w(n + 1), b(m + 1), last(n + 1, 0), touch(n + 1, 0);
for (i = 1; i <= n; i++) cin >> w[i];
for (i = 1; i <= m; i++) cin >> b[i];
ans = 0;
for (i = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
const long long MOD = 1e9 + 7;
const long long MOD_2 = MOD - 1;
struct mat {
long long M[N][N];
mat() { memset(M, 0, sizeof M); }
void print() {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cout << M[i][j] << " ";
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 150;
int n, m, k, ar[MAXN][MAXN], sum[MAXN][MAXN], ans1, ans2, tmpans1, tmpans2;
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
scanf("%d", &ar[i][j]);
}
}
for (int i = 1; i <= m... | 3 |
#include <bits/stdc++.h>
using namespace std;
double dp1[5000][201], dp2[5000][201];
double p1, p2;
int l1, r1, l2, r2, DT1, DT2;
void precomp(int hp1, int hp2) {
dp1[0][hp1] = 1;
for (int k = 0; k < 5000 - 1; k++) {
for (int i = hp1; i >= 0; i--) {
if (dp1[k][i] < 1e-8) continue;
double diff = 1.0 ... | 4 |
#include <bits/stdc++.h>
using namespace std;
set<string> myset;
int main() {
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
string t;
for (int j = i; j < s.size(); j++) t += s[j];
for (int j = 0; j < i; j++) t += s[j];
myset.insert(t);
}
cout << myset.size() << endl;
}
| 1 |
//
// _oo0oo_
// o8888888o
// 88" . "88
// (| -_- |)
// 0\ = /0
// ___/`---'\___
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- ||||... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x, y, z;
cin >> x >> y >> z;
long long sum = x + y;
cout << sum / z << ' ';
long long xx = x % z, yy = y % z;
if (xx + yy < z) {
cout << 0;
return 0;
}
cout << min(abs(z - (x % z)), abs(z - (y % z)));
}
| 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.