solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
template <class t>
inline t read(t &x) {
char c = getchar();
bool f = 0;
x = 0;
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
if (f) x = -x;
return x;
}
template <class t>
inline void wr... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, double>> ans[52];
int main() {
int n, w, m;
cin >> n >> w >> m;
double s = (n * w) / (m * 1.0), c = w, b = 1, k = 0;
for (int i = 0; i < m; i++) {
double ne = s;
while (1) {
if (ne + 10e-7 > c) {
ans[i].push_back(make_pair(b, c... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool com(int x, int y) { return x > y; }
long long inp[200007], ei[200007], cmd[200007][2], fnl[200007];
int main() {
long long i, j, l, u, v, w, x, y, z, a, b, c, d, e, f, r, t = 1, tc;
long long flg, sz, cnt, gt, ans, mx, mn;
long long m, k, n, ln;
scanf("%lld%lld... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, m, a;
scanf("%d:%d", &h, &m);
scanf("%d", &a);
a %= 1440;
int addh = a / 60;
int addm = a - addh * 60;
m += addm;
if (m >= 60) {
addh++;
m %= 60;
}
h += addh;
{ h %= 24; }
if (h < 10)
cout << 0 << h << ':';
else
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int n;
long long dp[200010][4], cnt[200010][4], V[200010];
vector<int> adj[200010];
void f(int p, int u) {
for (int v : adj[u])
if (v != p) f(u, v);
dp[u][0] = V[u];
dp[u][1] = 0;
dp[u][2] = V[u];
dp[u][3] = 0;
cnt[u][0] = 1;
cnt[u... | 5 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
int i, j;
int result = 0;
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
double sqr = sqrt((double)(i * i + j * j));
if ((i * i + j * j) <= n * n && sqr - (int)sqr == 0) result += 1;
}
}
printf("%d\n", result / 2);
... | 1 |
#include<iostream>
#include<algorithm>
using namespace std;
int n,a,fp,fc,tc,hc,tp,hp,t[201],h[201],T[100],H[100];
void init();
int main(){
while(1){
cin>>n;
if(n==0)break;
init();
for(int i=0;i<n;i++){
cin>>a;
t[a]=1;
T[i]=a;
}
a=0;
for(int i=1;i<=2*n;i++){
if(t[i]... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,k;
while(1){
cin>>n>>k;
if(n==0) return 0;
bool a[n+1];
for(int i=0;i<=n;i++) a[i]=false;
int input;
for(int i=0;i<k;i++){
cin>>input;
a[input]=true;
}
if(!a[0]){
int ans=0,cnt=0;
for(int i=1;i<=n;i++){
if(a[i]) cnt++;
... | 0 |
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int c;
cin>>c;
while(c--)
{
int x,y,z;
cin>>x>>y>>z;
if(z==(x*y)-1)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
return 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long mxN = 2e5 + 5;
const long long INF = 1e18 + 7;
void _print(long long t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(bool t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) ... | 4 |
#define _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")
#include "bits/stdc++.h"
using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#defin... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int sum = 0;
for (int i = 0; i < n; i++) {
if (a[i] == "ABSINTH" || a[i] == "BEER" || a[i] == "BRANDY" ||
a[i] == "CHAMPAGNE" || a[i] == "GIN" || a[i] == "R... | 1 |
#include<bits/stdc++.h>
using namespace std;
long long res = 0, sum = 0, k, a[501], n;
void check (long long val) {
multiset <long long> s;
long long sumf = 0, sumz = 0;
for (int i = 1; i <= n; ++ i) {
s.insert (a[i] % val);
sumf += (val - (a[i] % val));
}
for (auto v : s) {
sumz += v;
sumf -=... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int in, out, w, s, v;
};
node a[505];
bool op(node a, node b) {
if (a.in == b.in) return a.out > b.out;
return a.in < b.in;
}
int dp[505][1005];
int dp2[1005];
int n, s;
int dfs(int i, int s) {
if (dp[i][s] != -1) return dp[i][s];
vector<pair<pair<in... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mv4[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const int mv8[8][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0},
{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
const int inf = (int)1e9;
const char *boo[2] = {"NO", "YES"};
const char *inv = "Impossible";
inli... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long dp[3333][3333];
int main(){
int N;
cin >> N;
vector<long long> a(N);
for(auto &i:a)cin >> i;
for(int w=1;w<=N;w++){
for(int l=0;l<=N-w;l++){
int r=l+w-1;
dp[l][r]=max(a[l]-dp[l+1][r],a[r]-dp[l][r-1]);
}
}
cout << dp[0][N-1] << endl;
return ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5, M = 3e5 + 5;
int n, m, k, u, v, ans;
int a[N], b[N], c[N], maxn[N];
int cnt, head[N];
struct edge {
int next, to;
} e[M];
inline void add(int u, int v) {
cnt++;
e[cnt].next = head[u];
e[cnt].to = v;
head[u] = cnt;
}
priority_queue<int, vecto... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[1000];
int main() {
int n, m, ans = 0, i;
scanf("%d %d", &n, &m);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
for (i = 0; i < m; i++) {
int x, y;
scanf("%d %d", &x, &y);
ans += min(a[x - 1], a[y - 1]);
}
printf("%d\n", ans);
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
const double EPS = 1e-9;
int main() {
int n, k;
cin >> n >> k;
vector<int> V;
for (int i = 1; i <= n; i++) {
V.push_back(i);
}
reverse(V.begin(), V.begin() + k + 1);
for (int i = 0; i < n; i++... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, m;
int a[200003];
pair<int, int> p[200003];
int main() {
cin >> t;
while (t--) {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
long long re = 0;
for (int i = 1; i <= n;) {
int val = a[i], j;
for (j = i; j <... | 3 |
#include "bits/stdc++.h"
#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}
using namespace std;
using ll = long long;
constexpr ... | 0 |
#include <bits/stdc++.h>
using namespace std;
double a[100010];
int n;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%lf", &a[i]);
double current = a[0];
int ncrt = 1;
int maxim = current;
int nmax = 1;
for (int i = 1; i < n; i++)
if (a[i] == current) {
ncrt++;
} else {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long oo = 1LL << 60;
int n;
long long a[555][555], sum[555][555];
long long sumRect(int x, int y, int xx, int yy)
{
return a[xx][yy] + a[x][y] - a[x][yy] - a[xx][y];
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int test;
cin >> test;
for (int t = 0; t < test; t++) {
int n, k;
cin >> n >> k;
if (n < k) {
cout << "NO" << '\n';
continue;
}
if (k == 1) {
cout << "YES" << '\n';
cout << n << '\n';
continue;
}
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
scanf("%d%d", &n, &k);
int ans = ((n) * (n - 1)) >> 1;
if (ans <= k)
printf("no solution\n");
else {
for (int i = 0; i < n; ++i) {
printf("0 %d\n", i);
}
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long Gcd(long long a, long long b) {
if (a % b == 0) return b;
Gcd(b, a % b);
}
int main() {
long long n, m;
while (cin >> n >> m) {
long long sum = 1;
for (long long i = 1; i <= m; ++i) sum *= 10;
cout << (n / Gcd(n, sum)) * sum << endl;
}
}
| 1 |
#include <bits/stdc++.h>
typedef struct {
int a;
int i;
} album;
int cmp(const void *a, const void *b) {
return ((album *)b)->a - ((album *)a)->a;
}
int main() {
int n, m, f = -1, p = 0, sum = 0, i;
album a[40];
int b[1000];
scanf("%d %d", &n, &m);
for (i = 0; i < m; i++) {
scanf("%d", &a[i].a);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, r1, r2, r3, d;
cin >> n >> r1 >> r2 >> r3 >> d;
vector<long long> a(n);
for (int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
}
vector<long long> planA(n), planB(n);
for (int i = 0; i < n; i++) {
planA[i] = min(r1 * (a[i] + 2), ... | 3 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
long long po(long long n, long long exp) {
if (exp == 0) return 1 % 1000000007;
long long n2 = po(n, (exp >> 1)) % 10000000... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int a = 0, b = 0;
cin >> s;
for (int i = s.length() - 1; i >= 0; i--) {
if (s[i] == 'a')
a++;
else
b++;
}
if (a > b)
cout << s.length();
else
cout << 2 * a - 1;
}
| 1 |
#include <bits/stdc++.h>
const long long mod = 1000000000 + 7;
using namespace std;
const int N = 505;
long long dp[N], f[N];
int n;
int main() {
cin >> n;
dp[0] = 1;
for (int i = 1; i <= n; i++) {
memset(f, 0, sizeof(f));
for (int j = 0; j <= n; j++)
for (int k = 0; k + j <= n; k++)
f[j + k... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep2(i,i0,n) for(int i=i0;i<n;++i)
int main()
{
int n;
cin >> n;
vector<vector<ll>> a(n,vector<ll>(n,0));
rep(i,n) rep(j,n) cin >> a[i][j];
ll ans = 0;
rep(i,n-1) {
rep2(j... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[100];
int main() {
int n,k,ans=0;
cin>>n>>k;
for(int i=0;i<n;++i) cin>>a[i];
sort(a,a+n);
reverse(a,a+n);
for(int i=0;i<k;++i) ans+=a[i];
cout<<ans<<'\n';
} | 0 |
#include <bits/stdc++.h>
using std::set;
int num, tst, nr, c;
char buf[40];
long long arr[500000];
set<long long> cur, tm;
void gen(int pos, int ch) {
if (pos == num) {
if (ch) return;
long long t = 0;
for (int i = 0; i < num; ++i) t <<= 1, buf[i] == '1' && (t |= 1);
tm.insert(t);
} else {
if (n... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int bit[1000009];
long long int query(long long int i) {
int ans = 0;
for (; i > 0; i -= i & -i) ans += bit[i];
return ans;
}
void update(long long int i, long long int x) {
for (; i < 1000009; i += i & -i) bit[i] += x;
}
int main() {
long long int n;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int main() {
long long int n, x, ans, ans1, y;
cin >> y;
n = (long long int)sqrt((double)y);
for (long long int i = n; i > 0; i--) {
if (y % i ==... | 3 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
while (true) {
int n;
cin >> n;
if (n == 0) break;
int cnt = 0;
while (n != 1) {
if (n%2 == 0) n /= 2;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, in[1005];
short int save[1001][256][125][2];
bool vis[1005][256][126][3];
vector<int> vc[10];
short int rec(int pos, int mask, int len, int f) {
if (mask == (1 << 8) - 1) return 0;
short int &ret = save[pos][mask][len][f];
if (vis[pos][mask][len][f]) return ret... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
x = 0;
bool f = 0;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = 1;
for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
if (f) x = -x;
}
template <typename F>
inline void write(F x, char... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
unsigned long long n, k, b;
cin >> n >> k;
cin >> b;
vector<pair<unsigned long long, unsigned long long> > ds(n);
for (int i = 0; i < n; i++) {
cin >> ds[i].first;
ds[i].second = i;
}
ds.pop_back();
sort(ds.begin(),... | 2 |
#include <bits/stdc++.h>
const int maxn = 200;
using namespace std;
int n;
bool mark[maxn][maxn], ex;
char a;
void input() {
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
cin >> a;
if (a == '#') mark[i][j] = true;
}
}
bool chk(int i, int j) {
if (mark[i + 1][j] && mark[... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int sum = 0;
string s = "";
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
if (sum + x <= 500)
sum += x, s += 'A';
else
sum -= y, s += 'G';
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int h1, h2, m1, m2, k;
cin >> h1 >> m1 >> h2 >> m2 >> k;
cout << (h2 - h1)*60 + m2 - m1 - k << "\n";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int vis[1005][1005];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
queue<array<int, 3>> q;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
char c;
cin >> c;
if (c == '#') {
q.push({i, j, 0}... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long l, r, x, y, k;
int main() {
cin >> l >> r >> x >> y >> k;
for (long long i = x; i <= y; i++) {
if (k * i >= l && k * i <= r) {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int a[110000];
int ans[110000];
int n, k;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
k = a[n];
ans[n] = 1;
for (int i = n - 1; i >= 1; i--)
if (k > 0)
k -= a[i], ans[i] = 0;
else
k += a[i], ans[i] = 1;
if (... | 4 |
#include <map>
#include <iostream>
#include <cstdio>
#include <queue>
#include <sstream>
#include <string>
#include <algorithm>
inline int getInt(){ int s; scanf("%d", &s); return s; }
using namespace std;
char buff[1200];
int main(){
int n = getInt();
fgets(buff, sizeof(buff), stdin);
map<string, int> m;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
char s[100005], str[100005];
int n, num[100005], ans[100005];
void work() {
while (gets(str)) strcat(s, str);
n = strlen(s);
int last = 0, len = 0, i;
for (i = 0; i < n; ++i) {
++i;
bool f = 0;
if (s[i] == '/') ++i, f = 1;
++i;
char c = s[i];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll N;
cin >> N;
vector<pair<ll,ll>> A(N);
for(ll i=0; i<N; ++i) {
cin >> A[i].first;
A[i].second = i;
}
sort(A.begin(), A.end());
reverse(A.begin(), A.end());
ve... | 0 |
#include <iostream>
#include <string>
#define llint long long
using namespace std;
llint Q;
llint a, b, c, d;
llint k, bd, bd2, bd3;
char get(llint x)
{
if(x <= (k+1)*(a/k)){
if(x % (k+1) == 0) return 'B';
else return 'A';
}
else{
x -= (k+1)*(a/k);
if(x <= a%k) return 'A';
else return 'B';
}
}
char ge... | 0 |
#include <bits/stdc++.h>
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define ... | 0 |
/*
w2sc
2019/12/19
19:43:48
*/
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
const double EPS=1e-10;
int q;
struct Point{
double x,y;
Point(){}
Point(double xx,double yy){x=xx,y=yy;}
Point operator +(Point A){return Point(x+A.x,y+A.y);}
Point opera... | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
ll v[305][305],vis[305];
void solve(){
ll n,m;
cin>>n>>m;
for(ll i=1;i<=n;i++)
for(ll j=1;j<=m;j++)
cin>>v[i][j];
ll c=0,res=pow(10,10);
while(c<m){
vector<ll> cnt(m+1,0);
for(ll i=1;i<=n;i+... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long t, n, m, k, q, l, r, i, j, x, y, z, x1, x2, y1, y2;
vector<long long> a, b;
cin >> n >> m >> k;
for (i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
for (i = 1; i < n; i++) {
if (m + i - 1 < n) {... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long min(long long x, long long y) { return (x < y) ? x : y; }
long long max(long long x, long long y) { return (x > y) ? x : y; }
const int N = 2002002;
long long n, m, mos, man, sum;
long long a[N], t[N], f[N], ok[N];
int main() {
ios_base::sync_with_stdio(false);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string month[] = {"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"};
string str;
cin >> str;
int k;
cin >> k;
for (in... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100001];
vector<int> centroidTree[100005 + 1];
int centroidMarked[100005 + 1];
int par[100005 + 1][21];
int level[100005 + 1];
int cpar[100005 + 1];
void dfs(int s, int p) {
level[s] = level[p] + 1;
par[s][0] = p;
for (auto it : adj[s])
if (it != p... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y;
} e[10];
int dis[10], cnt;
inline int dist(int x1, int y1, int x2, int y2) {
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
inline bool cmp(int x, int y) { return x < y; }
inline bool check() {
memset(dis, 0x3f, sizeof(dis));
cnt = 0... | 1 |
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,m,dep[N];
vector<int> e[N];
bool vis[N],test;
void dfs(int x){
vis[x]=1;
for (int i=0;i<e[x].size();i++){
int v=e[x][i];
if (vis[v]){
if (dep[x]==dep[v]) test=0;
continue;
}
dep[v]=dep[x]^1;
dfs(v);
}
}
int points,bipartites,graph... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct __timestamper {};
long long solve(vector<long long> _a, vector<long long> _b) {
vector<pair<long long, long long>> a;
for (int i = 0; i < (int)_a.size(); i++) {
a.push_back({_a[i], _b[i]});
}
int n = a.size();
sort(a.begin(), a.end());
vector<int> deg... | 2 |
#include <bits/stdc++.h>
const int maxn = 1e3 + 1;
using namespace std;
long long a[501], aa[501];
int main() {
long long a[501], b[501];
int v = 0;
cin >> v;
for (int tt = 0; tt < v; tt++) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int p[100000];
vector<int> v;
void sieve() {
memset(p, 1, sizeof p);
for (int i = 2; i < (50000); i += 2) p[i] = 0;
v.push_back(2);
for (int i = 3; i <= sqrt(50000); i += 2) {
if (p[i]) {
for (int j = 2; i * j <= (50000); j++) p[i * j] = 0;
}
}
for... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 50;
const int INF = 1e9 + 5;
int n, q, k;
int cnt[200][200], tm[200];
string s;
set<pair<pair<int, int>, int>> st;
void insert(int l, int r, char ch) {
set<pair<pair<int, int>, int>>::iterator it = st.upper_bound(
... | 5 |
#include <bits/stdc++.h>
using namespace std;
double H, F;
vector<double> x;
double func(double x1, double x2) {
double x3 = x1 * (F + H) / (F - H);
double x4 = x2 * (F + H) / (F - H);
if (x3 < x2 && x1 < x4) return (x3 + x1) * H;
if (x2 < x3 && x4 < x1) return (x2 + x4) * H;
if (x1 + x2 > x3 + x4) {
swap... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1);
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && c... | 1 |
#include <iostream>
#include <cstdio>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
using namespace std;
const int N = 2e5 + 10, M = 1e6 + 10;
int n, a[N], b[N];
struct edge{ int to, pre; } e[M << 1]; int u[N], l = 1;
void ins(int a, int b) { e[++l] ... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:65777216")
using namespace std;
int main() {
int s, a, b, c;
cin >> s >> a >> b >> c;
if (a == 0 && b == 0 && c == 0)
cout << "0 0 0" << endl;
else {
double x = s * a / double(a + b + c);
double y = s * b / double(a + b + c);
double z = s ... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <int N, int M, class T>
struct Link {
int HEAD[N], NXT[M], tot;
T W[M];
void clear() {
memset(HEAD, 0, sizeof HEAD);
tot = 0;
}
void add(int x, T w) {
NXT[++tot] = HEAD[x];
W[HEAD[x] = tot] = w;
}
T& operator[](int x) { return W[x]; }
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a, b, m;
cin >> n >> a >> b;
int arr[n];
for (int i = 0; i < n; i++) {
arr[i] = i + 1;
}
int count = 0;
for (int i = 0; i < n; i++) {
if (((arr[i] - arr[0]) <= b) && ((arr[n - 1] - arr[i]) >= a)) {
count++;
}
}
c... | 1 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
int a[1000005], b[1000005];
int x;
int main() {
int i, j, m, n, jinwei, flag = 0, da;
scanf("%d%d", &n, &x);
for (i = 0; i <= 9; i++) {
a[1] = i;
jinwei = 0;
for (j = 2; j <= n + 1; j++) {
a[j] ... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool ans = 0;
int n, m, sx, sy;
char A[1505][1505];
bool vis[1505][1505];
int lastx[1505][1505];
int lasty[1505][1505];
string txt[1505];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 100007;
long long n, m, a[maxn], num;
long long Max(long long x, long long y) { return x > y ? x : y; }
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
num = a[1];
cin >> m;... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct fdd {
double x, y;
} b[100111];
double t, a[100111], x[100111], y[100111];
int n, v, m, p[100111], j = 1;
inline bool cmp1(int aa, int bb) { return a[aa] < a[bb]; }
inline bool cmp2(fdd aa, fdd bb) {
return aa.x < bb.x || (aa.x == bb.x && aa.y < bb.y);
}
int main... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535897932384626433832795;
const long long INF = 1LL << 62;
const long long MINF = -1LL << 62;
template <typename T>
T getint() {
T val = 0;
char c;
bool neg = false;
while ((c = getchar()) && !(c >= '0' && c <= '9')) {
neg |= c == '-';... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 107;
int n, k;
struct Node {
int id, p, t;
} people[maxn];
bool cmp(Node a, Node b) {
if (a.p == b.p)
return a.t < b.t;
else
return a.p > b.p;
}
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) {
int t1, t2;
scanf("... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300300, M = 5050;
const long long oo = 1000000000000000000ll;
int i, j, k, n, m, ch, ff, t, l;
int a[N];
long long f[M][M];
void R(int &x) {
x = ff = 0;
ch = getchar();
while (ch < '0' || '9' < ch) {
if (ch == '-') ff = 1;
ch = getchar();
}
w... | 2 |
#include <bits/stdc++.h>
inline int Max(int x, int y) { return x > y ? x : y; }
inline int Min(int x, int y) { return x < y ? x : y; }
inline int Abs(int x) { return x < 0 ? ~x + 1 : x; }
inline int read() {
int r = 0;
bool w = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = 1;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
cin >> n;
cin >> s;
string s1, s2;
for (int i = 0; i < n; i++) {
if (i % 2 == 0)
s1 = s1 + '0';
else
s1 = s1 + '1';
}
for (int i = 0; i < n; i++) {
if (i % 2 == 0)
s2 = s2 + '1';
else
s2 = s2 ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long base = 196613, maxn = 1e6 + 9, mod = 1e9 + 7;
string s;
long long n, b[maxn], h[maxn], l1, r1;
void build() {
b[0] = 1;
h[0] = s[0];
for (int i = 1; i < n; i++) {
h[i] = ((h[i - 1] * base) % mod + s[i]) % mod;
}
for (int i = 1; i < maxn; i++) b... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> proh;
void GetProh(int v) {
proh.clear();
for (int i = 1; i <= v; ++i) {
int x1 = v / (i + 1) + 1;
int x2 = v / i - 2;
if (x2 < 0 || x2 - x1 < 4) break;
proh.push_back({x1, x2});
}
reverse(proh.begin(), proh.end());
}
inline bo... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long T(long long n) {
if (!n) return 1;
long long res = T(n / 2) % 1000000007;
res *= res;
if (n % 2) res *= 2;
return res % 1000000007;
}
int main() {
long long n;
cin >> n;
if (!n)
cout << 1 << endl;
else
cout << (T(2 * n - 1) + T(n - 1)) % ... | 1 |
#include <bits/stdc++.h>
const int Mod = 1000000007;
inline int qPow(int b, long long e) {
int a = 1;
for (; e; e >>= 1, b = (long long)b * b % Mod)
if (e & 1) a = (long long)a * b % Mod;
return a;
}
int Gcd(long long a, long long b) { return b ? Gcd(b, a % b) : a; }
int exGcd(long long a, long long b, long l... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
char ch;
long long f = 1, x;
while (ch = getchar(), !isdigit(ch))
if (ch == '-') f = -1;
x = (ch ^ 48);
while (ch = getchar(), isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48);
return x * f;
}
inline void write(long long x) {
if (... | 6 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
vector<int> a;
int k;
void ms(int l, int r) {
if (r == l + 1) {
return;
}
if (k == 1) {
return;
} else if (k > 1) {
int mid = floor((l + r) / 2);
k -= 2;
swap(a[mid - 1], a[mid]);
ms(l, mid);
ms(mid, r);
}
}
int mai... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, i;
cin >> n;
x = n - 1;
for (i = 1; i <= n - 2; i++) x += (i + 1) * (n - i - 1);
cout << x + n;
return 0;
}
| 2 |
#include <bits/stdc++.h>
int main() {
int operations, x = 0;
char opcode[4];
std::cin >> operations;
for (int i = 0; i < operations; ++i) {
std::cin >> opcode;
x += ((opcode[1] == '+') ? 1 : -1);
}
std::cout << x;
}
| 1 |
#include <bits/stdc++.h>
void build_population_count(unsigned int[]);
void read_and_find_frequency(int[], unsigned int);
unsigned long long count_k_interesting_pairs(int[], int, unsigned int[]);
int main() {
int count[10000 + 1] = {0}, k;
unsigned int population_count[2 * 10000], no_of_elements;
unsigned long lon... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010 + 5;
char s[N];
int n, sum[N][26], q, l, r, cnt[26];
int main() {
scanf("%s", s + 1);
n = strlen(s + 1);
for (int i = 1; i <= n; i++) {
memcpy(sum[i], sum[i - 1], sizeof sum[i]);
sum[i][s[i] - 'a']++;
}
scanf("%d", &q);
while (q--) {... | 2 |
#include <iostream>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
int main()
{
int n;
cin>>n;
vector<int> v(n);int b;
for(int i=0;i<n;i++) {cin>>v[i];}
v.erase(unique(v.begin(),v.end()),v.end());
for(int i=0;i<v.size();i++){
if(i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
const int inf = 1034567891;
const long long LL_INF = 1234567890123456789ll;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* na... | 2 |
#include <bits/stdc++.h>
using namespace std;
string s;
const int M = 1000000007;
const int MAX_N = 1100000;
int arr[MAX_N][3];
int main() {
cin >> s;
arr[0][0] = 1;
arr[0][2] = 1;
for (int i = 1; i < (int)s.size() + 1; ++i) {
if (s[i - 1] == '*') {
arr[i][0] = 0;
arr[i][1] = arr[i - 1][2];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[9];
bool b[10] = {false};
int input;
for(int i=0;i<9;i++){
cin >> input;
a[i] = input;
if(input != -1){
b[input] = true;
}
}
vector<int> ve;
for(int i=1;i<=9;i++){
if(!b... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long tavan(long long a, long long b,
long long mod = ((long long)1e9 + 7)) {
long long res = 1;
while (b) {
res *= (b % 2) ? a : 1;
res %= mod;
a *= a;
a %= mod;
b /= 2;
}
return res;
}
long long n, sum, a[((long long)1100)];... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s[15];
int a, b;
bool c = false;
for (int i = 0; i < 11; i++) getline(cin, s[i]);
cin >> a >> b;
a %= 3;
b %= 3;
if (!a) a = 3;
if (!b) b = 3;
for (int i = 4 * (a - 1); i < 4 * a; i++)
for (int j = 4 * (b - 1); j < 4 * b; j++)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int ar[101000], a, b, c, n, m;
vector<pair<pair<int, int>, int> > V;
vector<pair<int, pair<int, int> > > A;
int ans[101000];
bool cari(int k) {
A.clear();
for (int i = 0; i < V.size(); i++)
if ((1 << k) & (V[i].second))
A.push_back(make_pair(1, V[i].first));
... | 2 |
#include <bits/stdc++.h>
using namespace std;
deque<int> deq;
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) deq.push_back(i);
for (int i = 1; i <= n; i++) {
int l = ((n - 1) / i) * i;
deq.push_back(deq[l]);
while (l) {
deq[l] = deq[l - i];
l -= i;
}
deq.pop_fr... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a, b, f, k, ans, now;
int main() {
scanf("%d%d%d%d", &a, &b, &f, &k);
if (b < f) {
printf("-1");
return 0;
}
now = b - f;
for (int i = 1; i <= k; i++) {
if (i % 2) {
if (b < (a - f) + (a - f) * (i != k)) return printf("-1"), 0;
if (now ... | 3 |
#include <bits/stdc++.h>
using namespace std;
ifstream fi("test.txt");
ofstream fo("out.txt");
const long long MOD = 1e9 + 7;
const long long base = 269;
const int ooi = 1 << 30;
const int N = 1e5 + 5;
long long n, m, q, k, pos, rs, t, cnt, rs1, check;
long long maxx = -1e9, minn = 1e9;
long long l, r, d;
int a[N], mar... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int MAXN = +3;
long long t, n, m, k, ans;
int main() {
cin >> t;
while (t--) {
cin >> n >> m >> k;
ans = 0;
if (n < m) swap(n, m);
if (n > k) {
cout << -1 << endl;
continue;
}
if ((n + m) % 2) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100009];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (int i = n - 1; i >= 2; i--) {
if (a[i] < a[i - 1] + a[i - 2]) {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
}
| 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.