solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
double l, q, p, x, j;
while (cin >> l >> p >> q) {
if (p == q)
cout << l / 2 << endl;
else {
x = (p * l) / (p + q);
cout << x << endl;
}
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
register int x(0), f(1);
register char c(getchar());
while (c > '9' || c < '0') f = c == '-' ? -1 : 1, c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
return f * x;
}
const int N = 8e5 + 10;
int n, a[N], D[N], an... | 6 |
#include <bits/stdc++.h>
int main() {
int n, height[1000], left[1000] = {0}, right[1000] = {0};
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &height[i]);
}
for (int i = 1; i < n; ++i) {
left[i] = (height[i] >= height[i - 1] ? left[i - 1] + 1 : 0);
}
for (int i = n - 2; i >= 0; --i) {... | 2 |
#include <bits/stdc++.h>
using namespace std;
static const int INF = 500000000;
template <class T>
void debug(T a, T b) {
for (; a != b; ++a) cerr << *a << ' ';
cerr << endl;
}
int h, w;
int buf[2000][2000];
int core[2000][2000];
int sum[2000][2000];
struct uf {
int par[4000000];
void init() { memset(par, -1, s... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
int m;
int k;
long long int dp[14][1 << 4];
long long int tmp[14][1 << 14];
long long int bt[208][208];
int mxt;
inline int id(int a, int b) {
mxt = max(mxt, (a << m) + b + 1);
return (a << m) + b;
}
long long int mat[208][208];
long long int ret[208][208];
int m... | 6 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int a, b;
vector<ii> mapped(n);
for (int ctr1 = 0; ctr1 < n; ++ctr1) {
cin >> a >> b;
int swapped = 0;
... | 4 |
#include <iostream>
int N;
int sum[1005];
int main(){
std::cin>>N;
int temp=0;
for(int i=2;i<=N;++i){
temp = i;
for(int j=2;j<=N;++j){
if(temp==0)
break;
while(temp%j==0){
temp/=j;
++sum[j];
}
}
}
long long ans =1;
for(int i=2;i<=N;++i)
ans=an... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long seed, vax;
long long Pow(long long a, long long b, long long mod) {
if (!b) return 1LL % mod;
long long r = Pow(a, b / 2, mod);
r = (r * r) % mod;
if (b & 1) r = (r * (a % mod)) % mod;
return r;
}
long long pot(long long a, long long b, long lo... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
mt19937 rng(chrono::steady_clock::now().time_since_epo... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, dist[2010][2010], best[2010], pred[2010];
bool ales[2010];
vector<pair<int, int> > G[2010];
long long D[2010];
queue<int> Q;
bool bagat[2010];
inline void BFS(int start) {
int i, x;
vector<pair<int, int> >::iterator it;
for (i = 1; i <= n; ++i) {
D[i] = 300... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
const int SQRTN = 320;
const int LOGN = 20;
int a[N], n, k, d, ans[N];
bool seg[N * 3], dp[N];
int G(int x) {
int s = 1, e = n, mid = 0, best = 0;
while (s <= e) {
mid = s + e >> 1;
if (a[mid] < x)
s = mid + 1;
else
best =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long N;
cin>>N;
vector<long> a(100005);
long mod=1e9+7;
for(int i=0;i<N;i++) {
int t;
cin>>t;
a[t]++;
}
if(N%2==1){
if(a[0]!=1){
cout<<0<<endl;
return 0;
}
for(int i=2;i<=N-1;i+=2){
if(a[i]!=2){
cout<<0<<endl;
return 0;
... | 0 |
#include <stdio.h>
#define MAX 600
int blaue[MAX];
int rote[MAX];
int c[MAX][MAX];
int p[MAX];//rote->blaue
int gcd(int x,int y)
{
while(y!=0)
{
int r=x%y;
x=y;
y=r;
}
return x;
}
int match(int m,int n,int *v,int bn)
{
if(bn<0)return 1;
for(int j=0;j<n;j++)
{
... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int ar[n];
int sum = 0, num, k = (n - 1) * 3;
for (int i = 0; i < n; i++) {
cin >> ar[i];
sum += ar[i];
}
if (sum % n != ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
int bat[2], z, n, m, i, j, k, res, tab[35][35];
int main() {
scanf("%d", &z);
while (z--) {
scanf("%d %d", &n, &m);
res = 0;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++) scanf("%d", &tab[i][j]);
for (k = 0; k < (n + m... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 23;
const int MOD = 1e9 + 7;
const int N = 2e5 + 100;
const int A = 1e6 + 100;
vector<int> v;
int prv[A];
bool in[A];
int main() {
ios_base::sync_with_stdio(0);
int n, x;
cin >> n;
int mx = 0;
for (int i = 0; i < (n); ++i) {
cin >> x;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int tmp, prev = -1, t;
int max = 0, tmpMax = 0;
cin >> t;
cin >> prev;
for (int i = 1; i < t; i++) {
cin >> tmp;
if (tmp > prev)
tmpMax++;
else
tmpMax = 0;
if (tmpMax > max) max = tmpMax;
prev = tmp;
}
cout << (max ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e6;
const int bs = 1500;
struct PDSU {
vector<int> par, sub;
vector<array<int, 2>> chngs;
PDSU(int n) {
par.resize(n + 1);
sub.resize(n + 1, 0);
for (int i = 1; i <= n; i++) par[i] = i;
}
int rootFast(int x) {
par[x] = par[x] != x ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, p = 0;
cin >> n;
vector<char> a;
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == ')') {
if (a.size() != 0)
a.pop_back();
else
p+... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a[120], i, j, res;
while (scanf("%d %d", &n, &m) == 2) {
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
bool flag = true;
int k = 0;
while (flag) {
for (i = 1; i <= n; i++) {
if (a[i]) {
if (a[i]... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
out << '(' << p.first << ", " << p.second << ')';
return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
long long l = v.size();
for (long... | 6 |
#include <iostream>
using namespace std;
int main() {
string s = "ATCG";
char c;
cin >> c;
int it = s.find(c);
cout << s[it ^ 1] << endl;
} | 0 |
#include<iostream>
using namespace std;
int main(void){
int a,b,c;cin>>a>>b>>c;
if(a+b>=c)cout<<"Yes";
else cout<<"No";
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 20;
vector<int> sum[maxn], ker[maxn];
string s[maxn];
vector<int> can[maxn], shit[maxn];
int n, m;
inline int get(int x1, int y1, int x2, int y2) {
if (x1 <= 0 || y1 <= 0 || x2 > n || y2 > m) return -1000;
return sum[x2][y2] - sum[x2][y1 - 1] - su... | 3 |
#include <bits/stdc++.h>
long long gi() {
long long x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f ? x : -x;
}
int n, m, s;
long long solve(long long n, long long o) {
--o;
if (o <= 0) return n;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
const int maxn = 5e5 + 10;
const int inf = 2e9;
const int maxm = 1e4 + 10;
const int mod = 998244353;
int a[maxn];
int main() {
int T;
cin >> T;
while (T--) {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) sc... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, m, x = 0, y = 0, z = 0, s = 0, i, c, d;
cin >> n;
long long int a[100000];
for (i = 0; i < n; i++) cin >> a[i];
cin >> m;
long long int b[100000];
for (i = 0; i < m; i++... | 1 |
#include <bits/stdc++.h>
using namespace std;
char s[10005][10005];
int main() {
int n, v;
int i, j, k, l, h, r, cont;
cin >> n >> v;
for (i = 0; i < 4 * n; i++) cin >> &s[i][0];
char schm[5] = {"aaaa"};
char c[5][10005];
for (i = 0; i < 4 * n; i += 4) {
for (j = i, h = 0; j < i + 4; h++, j++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int inf_int = 1e9 + 100;
const long long inf_ll = 1e18;
const double pi = 3.1415926535898;
bool debug = 0;
long long f1(long long N, long long k);
long long f2(long long N, long long k);
long long f3(long long N, long long k);
long long f4(long long N, long long k);
l... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 1e6 + 10, mod = 2e9 + 63, base1 = 1e9 + 21,
base2 = 1e9 + 181;
char s[MAX_N];
long long pw1[MAX_N], pw2[MAX_N], slen;
void pw_calc() {
pw1[0] = pw2[0] = 1;
for (int i = 1; i < MAX_N; i++) {
pw1[i] = (pw1[i - 1] * base1) % mod;... | 2 |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+10,mod=1e9+7;
ll fac[N],n,k,res;
ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
ll C(ll n,ll m){return fac[m]*qpow(fac[n],mod-2)%mod*qpow(fac[m-n],mod-2)%mod;}
int main(){
cin>>n>>k,fac[0]=1;
for(in... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, x, k;
int ans, q, res;
bool a[4010];
bool b[4010];
int minn, maxx;
int main() {
cin >> n >> k;
for (int i = 1; i <= k; i++) {
cin >> q;
if (q == 1) {
cin >> x;
a[x] = true;
cin >> x;
a[x] = true;
} else {
cin >> x;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q, f[1200005], hx[1200005], hs[1200005], lx[1200005], ls[1200005];
int g[1005][1005], s;
int main() {
scanf("%d%d%d", &n, &m, &q);
for (int i = 0; i <= n + 1; i++) {
for (int j = 0; j <= m + 1; j++) g[i][j] = ++s;
}
for (int i = 1; i <= n; i++) {
f... | 5 |
#include <bits/stdc++.h>
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
using namespace std;
int n;
pair<double, double> p[1234567], q;
double dist(pair<double, double> a, pair<double, double> b) {
return sqrt((a.first - b.first) * (a.first - b.first) +
(a.second - b.second) * (a.second - b.secon... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 3511;
int f[N][N][2][2];
int aph, n, len;
long long p;
vector<int> a, b, c;
char s[N];
int A(int x, int y) { return x + y - (x + y >= mod ? mod : 0); }
int M(int x, int y) { return 1LL * x * y % mod; }
int cal1(int x, int r, int nr) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int N, P, Q;
int C[4002], H[4002], T[4002], pos[4002];
int Q1[20002], Q2[20002], result[20002], posQ[20002];
int D1[4002][4002], D2[4002][4002];
inline bool compare(const int& i1, const int& i2) { return T[i1] < T[i2]; }
inline bool compareQ(const int& i1, const int& i2) { ... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
const int BSZ = 400;
const int N = 100228;
const int LG = 17;
int n, m;
vector<vi> g;
vi pred;
vi in, out;
int timer;
int up[LG][N];
vi ts;
vi evs;
vi sgn;
vector<bool> aliv... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chkMax(T &x, T y) {
if (y > x) x = y;
}
template <typename T>
void chkMin(T &x, T y) {
if (y < x) x = y;
}
template <typename T>
void inline read(T &x) {
int f = 1;
x = 0;
char s = getchar();
while (s < '0' || s > '9') {
if (s == '... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
cin >> k;
int i, cnt = 0, cnt2 = 0;
int x;
for (int i = 1; i <= k; i++) {
cin >> x;
if (x == 1) {
cnt = i;
} else if (x == 0) {
cnt2 = i;
}
}
if (cnt < cnt2) {
cout << cnt << endl;
} else {
cout << cnt2... | 1 |
#include<iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
int _convert(string str) {
return str[0] * 600 + str[1] * 60 + str[3] * 10 + str[4];
}
int convert(string str) {
return _convert(str) - _convert("00:00");
}
int main() {
int n, t;
cin >> n >> t;
string a[n], b[n], ... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &n) {
n = 0;
T f = 1;
char c = getchar();
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-') f = -1, c = getchar();
while (isdigit(c)) n = n * 10 + c - '0', c = getchar();
n *= f;
}
int n, m, cnt, tot;
int pre[400000... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 100;
const int ub = 1e6;
const long long INF = 1e18;
long long powmod(long long x, long long y) {
long long t;
for (t = 1; y; y >>= 1, x = x * x % mod)
if (y & 1) t = t * x % mod;
return t;
}
long long gcd(long long ... | 5 |
#include <bits/stdc++.h>
using namespace std;
ofstream ou("out.out");
struct nod {
char val;
int pos;
};
int main() {
int t;
cin >> t;
while (t--) {
long long int w, h;
cin >> w >> h;
long long int n;
cin >> n;
vector<long long int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
lo... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long val, long long deg, long long m) {
if (!deg) return 1 % m;
if (deg & 1) return power(val, deg - 1, m) * val % m;
long long res = power(val, deg >> 1, m);
return (res * res) % m;
}
bool check(bool mat[][50], int n) {
for (int i = 0; i < n ... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f == 1 ? x : -x;
}
const int N = 1e5 + 4, in... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
const int N = 1e5 + 10;
int a[5];
int cnt[5];
int main() {
int n;
cin >> n;
string s1, s2;
cin >> s1 >> s2;
for (int i = 0; i < n; i++) {
if (s1[i] == '0' && s2[i] == '0') a[1]++;
if (s1[i] == '0' && s2[i] == '1') a[2]++;
if (s... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, a[1001][1001], b[1001][1001], dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};
char s[1001][1001], dc[4] = {'L', 'U', 'R', 'D'};
bool f;
inline long long read() {
long long sum = 0, x = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') x = -1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 30500;
int n;
int a[4 * N], b[4 * N], c[4 * N];
set<int> by_target[N];
set<int> ops;
int cnt[N];
int res[4 * N];
void solve() {
scanf("%d", &n);
for (int i = 0; i < 4 * n; i++) {
scanf("%d%d%d", &a[i], &b[i], &c[i]);
a[i]--;
b[i]--;
c[i]--;... | 2 |
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &item) {
out << '(' << i... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, u, i;
int main() {
cin >> n;
for (i = 2; i * i <= n; i++) {
if (n % i == 0 && u == 0) {
u = i, n /= i;
}
if (n % i == 0 && n > i) {
cout << 1 << endl << u * i << endl;
return 0;
}
}
if (u == 0) {
puts("1\n0");
} e... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> adj[1001];
deque<int> leaf;
int sze[1001];
bool visit[1001];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n;
for (int i = 1; i < n; i++) {
int x, y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
sze[x]++, s... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long power(int X, int Y) {
if (Y == 0) return 1;
long long temp = power(X, Y / 2);
if (Y % 2 == 0)
return temp * temp;
else
return temp * temp * X;
}
int to_int(string X) {
int in = 0;
long long p = power(10, X.size() - 1);
for (int i = 0; i < X.s... | 2 |
/*Lucky_Glass*/
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=700;
int n,mod,Nf,Ng;
vector< pair<int,int> > Epr;
int Ef[N+3][N+3];
int main(){
scanf("%d%d",&n,&mod);
Nf=2*n-1;Ng=2*n-1;
for(int i=0;i<2*n;i++){
while(i*i+Nf*Nf>4*n*n && Nf>=0) Nf--;
while... | 0 |
#include <bits/stdc++.h>
using namespace std;
char str[100111];
int n;
bool overflow[100111];
int arr[100111];
bool Try(bool of) {
int i;
int val;
int rem, sum;
memset(overflow, false, sizeof(overflow));
overflow[n + 1] = false;
if (!of) {
overflow[1] = false;
overflow[n] = false;
}
if (of) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
vector<int> data;
UnionFind(int sz) : data(sz, -1) {}
int find(int k) { return (data[k] < 0 ? k : (data[k] = find(data[k]))); }
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return;
if (data[x] < data[y]) swap(x,... | 4 |
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
set<string>mo;
int N,k;
bool use[15];
map<string,int>memo;
string n[10];
void g(int m,string a){
if(m==k){
memo[a]=1;
return;
}
for(int i=0;i<N;i++){
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long Q;
string s, t;
short dp[405][405][405];
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> Q;
for (int q = 0; q < Q; q++) {
cin >> s >> t;
long long S = s.size(), T = t.size();
s = "#" + s, t = "#" + t;
for (int i = 0; i <= S; i+... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
if (n <= 2)
cout << -1 << endl;
else
cout << "2 3 1";
for (int i = 4; i <= n; ++i) {
cout << ' ' << i;
}
return 0;
}
| 1 |
#include <cstdio>
#include <algorithm>
using namespace std;
using ll = long long;
#define Input(x) scanf("%lld",&x)
ll n, m;
ll sum[123456];
int main()
{
Input(n);
Input(m);
fill(sum, sum + 123456, 0);
ll from; Input(from);
--from;
for (int j = 0; j < m - 1; ++j)
{
ll to; Input(to);
--to;
ll p = min(f... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = (1 ? 100000000000000007 : 233333333333333333);
const int mod = (1 ? 1000000007 : 998244353);
const long long INF = 0x7fffffffffffffff;
const int inf = 0x7fffffff;
const double eps = 1e-8;
const int N = 2e5 + 5;
clock_t start, finish;
void time_in() { s... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct st {
int x, y;
};
st a[101];
int v[101], i, n, m, x, y;
bool cmp(st a, st b) { return a.y > b.y; }
int main() {
cin >> n >> m;
for (i = 1; i <= n; i++) {
cin >> x;
v[x]++;
}
for (i = 1; i <= m; i++) {
a[i].x = i;
a[i].y = v[i];
}
sort(a ... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename _T>
inline void read(_T &f) {
f = 0;
_T fu = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') fu = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
f = (f << 3) + (f << 1) + (c & 15);
c = getchar();
}
f ... | 3 |
#include<iostream>
using namespace std;
// 排他的論理和の最上位ビットの桁数 (0-origin)
int diff_max(int a,int b){
int s=a^b,cnt=0;
while(s){
s/=2;
cnt++;
}
return cnt;
}
int main(){
int n; cin >> n;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
printf("%d ",diff_max(i,j));
}
cout << "\n";
}
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, p, x, y;
int a[1010];
int cnt = 0;
scanf("%d%d%d%d%d", &n, &k, &p, &x, &y);
int sum = 0;
for (int i = 0; i < k; i++) {
scanf("%d", &a[i]);
sum += a[i];
if (a[i] >= y) cnt++;
}
int t = n - k;
if (sum + t > x) {
printf(... | 2 |
#include <bits/stdc++.h>
using namespace std;
int GCD(int a, int b) {
if (!a) return b;
return GCD(b % a, a);
}
bool ok(string &a, string &b) {
for (int i = 1; i < a.size(); i++) {
if (a[i] != b[i - 1]) return false;
}
return true;
}
int main() {
clock_t startTime = clock();
ios_base::sync_with_stdio(... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, k;
int a[N], c[N];
int nxt[N], ans[N], sum[N];
struct Query {
int l, r, id;
bool operator<(const Query &rhs) const { return l < rhs.l; }
} Q[N];
void add(int x, int v) {
for (; x <= n; x += x & -x) c[x] ^= v;
}
int ask(int x) {
int ret ... | 4 |
#include <bits/stdc++.h>
int count = 0, len;
char a[100];
void f(int pos) {
int j;
for (j = pos; j < len; j++) {
if (a[j] == 'A') {
for (int k = j + 1; k < len; k++) {
if (a[k] == 'Q') count++;
}
}
}
}
int main() {
int j;
scanf("%s", a);
len = strlen(a);
for (int i = 0; i < len... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
string s[MAXN];
vector<int> v[30];
int fa[MAXN];
void init(int n) {
for (int i = 1; i <= n; ++i) {
fa[i] = i;
}
}
int findd(int x) { return x == fa[x] ? x : fa[x] = findd(fa[x]); }
int main() {
int n;
cin >> n;
init(n);
for (int i =... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, q, sum[1000], total, a[1000], c;
string code[1000], s, x;
bool cek[1000], ceks, cekd;
int f(char b) {
if (b == '0') return 0;
if (b == '1') return 1;
if (b == '2') return 2;
if (b == '3') return 3;
if (b == '4') return 4;
if (b == '5') return 5;
if (b =... | 2 |
#include<iostream>
using namespace std;
int main(){
int a[150][150];
int b[150];
int c[150]={0};
int n,m;
cin >> n >> m;
int i,j;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
cin >> a[i][j];
for(j=0;j<m;j++)
cin >> b[j];
for(i=0;i<n;i++)
for(j=0;j<m;j++)
c[i]+=a[i][j]*b[j];
fo... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, K, x[N], y[N], choose[N], deg[N];
vector<int> G[N];
vector<int> res;
struct cmp {
bool operator()(const int& k1, const int& k2) const {
return deg[k1] > deg[k2];
}
};
set<int, cmp> S;
void remove(int k1) {
assert(!choose[k1]);
choose[k... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[100009];
set<int> s, temp, temp1;
int main() {
int n, i, j;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
s.insert(a[0]);
temp.insert(a[0]);
for (i = 1; i < n; i++) {
temp1.clear();
temp.insert(a[i]);
for (auto k : temp... | 3 |
#include <bits/stdc++.h>
using namespace std;
int test, sum;
string t, str, s;
map<char, int> tot, seg;
vector<int> v;
bool solve(char c) {
sum += seg[c];
int x = sum;
string temp;
vector<int> pos;
if (t.size() == 0) return false;
for (int i = t.size() - 1; i >= 0; i--) {
if (x == 0) break;
temp += ... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(long long k) {
for (int i = 2; i <= sqrt(k); ++i) {
if (k % i == 0) return false;
}
return true;
}
void solve() {
long long n;
cin >> n;
vector<long long> v(n);
for (int i = 0; i < n; ++i) cin >> v[i];
if (n == 1) {
cout << 1 << " " << 1... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, M, T;
int who[20013];
deque<pair<int, int> > cur;
int parse() {
int a, b, c;
scanf("%d%*c%d%*c%d", &a, &b, &c);
return a * 3600 + b * 60 + c;
}
int main() {
scanf("%d%d%d", &n, &M, &T);
int which = 1;
int next = parse();
int maxOn = 0;
int num = 1;
... | 4 |
#include <bits/stdc++.h>
int a[101];
int main() {
int i, j, n, m, cnt = 0;
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
i = 1;
j = n;
while (i <= j) {
if (a[i] <= m)
i++;
else if (a[j] <= m)
j--;
else
break;
cnt++;
}
printf("%d", cnt);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
using vint = vector<long long>;
using pint = pair<long long, long long>;
using vpint = vector<pint>;
template <typename A, typename B>
inline void chmin(A& a, B b) {
if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A& a, B b) {
if (a < b) a = b;
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
scanf("%d%d", &n, &m);
int a[n];
int i = 0;
int j;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int sum = 0;
int count = 0;
for (i = 0; i < n; i++) {
sum = a[i];
count++;
if (i != n - 1) {
for (j = i + 1; j... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 10000000;
map<string, int> rp;
int cnt, mx = 1;
string a, b, r;
void upp() {
for (int i = 0; i < a.size(); i++) {
if (a[i] >= 'a' && a[i] <= 'z') a[i] = a[i] - 'a' + 'A';
}
for (int i = 0; i < b.size(); i++) {
if (b[i] >= 'a' && b[i] <= '... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const long long INFL = LLONG_MAX;
const int output_precision = 15;
const bool debug = true;
int N, M;
long long row[1111], col[1111];
inline long long f(long long x) { return x * x; }
int main() {
ios_base::sync_with_stdio(0);
cout.precision(out... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct Good {
long long order;
long long cash;
};
struct Answer {
long long MaxCash;
long long Count;
};
Answer answer;
long long n, cash;
vector<long long> a;
bool compare(Good x, Good y) {
if (x.cash + x.order == y.cash + y.order) {
return (x.order < y.order... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(){
double A, B;
cin >> A >> B;
printf("%.10lf\n", A*B/(A+B));
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
int hours = 0;
int minutes = 0;
cin >> hours >> minutes;
int H, D, C, N;
cin >> H >> D >> C >> N;
double res = 0;
if (20 <= hours) {
if (H % N == 0)
res = (H / N) * (4.0 * (double)C / 5.0);
else
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> name, surname;
vector<int> cnt1(26), cnt2(26);
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
name.push_back(s);
cnt1[s[0] - 'A']++;
}
sort(name.begin(), name.end());
for (int i = 0; i < n; ++i)... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("arch=corei7-avx")
using namespace std;
const int N = 1e5 + 7;
int x[N], y[N];
inline unsigned long long to_long(double a) { return *((long long*)(&a)); }
inline double to_ld(unsigned long long a) { return *((double*)(&a)); }
double middle(double a,... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int ma = -1, mi = 1000000000000000;
inline long long int gcd(long long int a, long long int b) {
return b ? gcd(b, a % b) : a;
}
inline long long int lcm(long long int a, long long int b, long long int MOD) {
return a / gcd(a, b) * b % MOD;
}
long long int pow... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
string a;
cin >> a;
double total = 0;
vector<string> numbers;
for (int i = 0; i < a.size(); i++) {
if ((int)(a[i] - '0') < 10) {
string newstring;
int j;
for (j = i; j < a.size(); j++) {
if ((i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
int a[26], b[26];
cin >> s >> t;
for (int i = 0; i < 26; i++) {
a[i] = 0;
b[i] = 0;
}
if (s.length() < t.length()) {
for (int i = 0; i < s.length(); i++) {
if (s[i] == '?') s[i] = t[i];
}
} else {
for (int i ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
inline int solve(int x) {
int res = 0;
while (x) {
res += x % 10;
x /= 10;
}
return res;
}
int main() {
scanf("%d", &n);
if (solve(n) % 4 == 0) return printf("%d\n", n), 0;
while (n++) {
if (solve(n) % 4 == 0) {
printf("%d", n);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int64_t n, m;
cin >> n >> m;
vector<pair<int64_t, pair<int64_t, int64_t> > > a(m);
int64_t kol = 0;
map<int64_t, int64_t> us;
for (int64_t i = 0; i < m; i++) {
cin >> a[i... | 2 |
#include <bits/stdc++.h>
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define rep(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;
int main(){
ll n,a,b;
cin>>n>>a>>b;
n%=12;
rep(i,n){
if(i%2==0){
a-=b;
}else b+=a;
}
cout<<a<<" "<<b<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int N = 1e6 + 10;
const int M = 1e4 + 10;
const long long mod = 1000000007;
const double eps = 1e-10;
const double pi = acos(-1.0);
int n, m;
long long cnt[N];
vector<int> ve;
long long k[N];
int ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int min(int a, int b) { return (a < b) ? a : b; }
int max(int a, int b) { return (a > b) ? a : b; }
void bmin(int &a, int b) { a = (a < b) ? a : b; }
void bmax(int &a, int b) { a = (a > b) ? a : b; }
int read() {
int x = 0, w = 1;
char ch = getchar();
while (ch > '9' ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int a, b, temp;
while (n--) {
cin >> a >> b;
long long int j = max(2 * min(a, b), max(a, b));
cout << j * j << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
struct Snake {
int x, y, id;
ll b;
};
const int N = 2e3;
const ll M = 1e9 + 7;
int n, m, r;
vector<Snake> s;
vector<bitset<N>> ad... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, x, i, c = 0;
cin >> n >> x;
vector<pair<long long int, long long int>> a(n);
for (i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
c += (a[0].first - 1) % x + a[0].second - a[0].first + 1;
for (i = 1; i < n; i++) {
c += (a[i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
bool strict = 1;
for (int i = 1; i <= n - 1; i++)
if (s[i] == '1') {
strict = 0;
break;
}
if (!strict) n++;
cout << n / 2 << '\n';
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long n, res, num, mult, fac, newn;
bool inz;
string s;
scanf("%I64d", &n);
cin >> s;
fac = 1;
mult = 1;
res = 0;
num = 0;
for (int i = s.length() - 1; i >= 0; i--) {
inz = false;
if (s[i] == '0') {
long long mm = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
long long int power(long long int a, long long int b) {
a %= mod;
long long int ret = 1;
while (b) {
if (b & 1) ret *= a;
a *= a;
if (ret >= mod) ret %= mod;
if (a >= mod) a %= mod;
b >>= 1;
}
return ret;
}
lo... | 1 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int main() {
int n, m, a, x, i;
ios::sync_with_stdio(false);
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a >> x;
mp[a] = x;
}
cin >> m;
for (i = 1; i <= m; i++) {
cin >> a >> x;
mp[a] = max(mp[a], x);
}
long long ans = 0;
... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.