solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
int n, m, ans = inf, a[301000], tg[301000], sz[301000], dg[301000], f[301000],
vis[301000], pre[301000], q[301000], l, r;
vector<int> G[301000];
void try4() {
memset(vis, 0, sizeof(vis));
if (G[1].size() == 0) return;
for (auto p : G... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
const int mod = 1e9 + 7;
int n;
string s, ans;
int main() {
cin >> n >> s;
string ans = "";
for (int i = n - 1; i >= 0; --i) {
int k = ans.length() + 1;
int pos = k / 2;
string t = "";
for (int j = 0; j < pos; ++j) t += ans[j];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int N, ans;
multiset<int> S;
int main(){
int a;
scanf("%d", &N);
for (int i=1; i<=N; i++) {
scanf("%d", &a);
S.insert(a);
}
while (!S.empty()){
int t = *(--S.end()), k;
S.erase(--S.end());
for (k=1; k<=t; k<<=1);... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a;
cin >> b;
for (int i = 0; i < a.length(); i++) {
if (a[i] >= 65 && a[i] <= 90) a[i] += 32;
}
for (int i = 0; i < b.length(); i++) {
if (b[i] >= 65 && b[i] <= 90) b[i] += 32;
}
int flag = 0;
for (int i = 0; i < a.... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
long long a, b, c;
long long abc[100005];
long long n, m, k;
cin >> n;
long long mi, ma;
mi = n / 7;
c = mi;
mi *= 2;
b = n % 7;
if (b == 0)
ma = mi;
else if (b == 1)
ma = mi + 1;
else
ma = mi + 2;
if (b == 6) mi++;
c... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cout.write(nam... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 9;
struct node {
int lx, ly;
int val;
bool operator<(const node &rr) const {
return make_pair(this->lx, this->ly) < make_pair(rr.lx, rr.ly);
}
};
set<node> mp;
bool check(node cur) {
int lx = cur.lx, ly = cur.ly;
int sup = 0;
for (int... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int s;
cin >> s;
long long fib[s];
const int mod =1e9+7;
fib[0]=0;
fib[1]=0;
fib[2]=1;
for (int i = 3; i < s; i++)
{
fib[i]=(fib[i-1]+fib[i-3])%mod;
}
cout << fib[s-1];
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int normalize(vector<int> &a) {
int n = a.size();
int x = -1, y = -1;
for (int i = 0; i < n; i++) {
if (a[i] == 0) x = i;
if (a[i] == 1) y = i;
}
if (x < y) {
for (int i = x; i < y - 1; i++) swap(a[i], a[i + 1]);
return y - 1;
} else {
for (i... | 2 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int maxn = 4e5+7 ;
const ll mod = 1000000007;
#define mst(x, a) memset( x,a,sizeof(x) )
#define rep(i, a, b) for(int i=(a);i<=(b);++i)
#define dep(i, a, b) fo... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i;
cin >> n;
if (n <= 5)
cout << -1 << "\n";
else {
cout << 1 << " " << 2 << "\n";
cout << 1 << " " << 3 << "\n";
cout << 1 << " " << 4 << "\n";
for (i = 5; i <= n; i++) cout << 2 << " " << i << "\n";
}
for (i = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int const N = 1000000;
int n, m;
vector<vector<pair<int, int> > > adj;
bool valid;
int ans[N];
int cnt;
int st[N * 3];
void readin() {
int u, v;
char b[10];
scanf("%d%d", &n, &m);
valid = true;
adj.clear();
adj.resize(n + 1);
for (int i = 0; i < m; ++i) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(const T &a) {
return a * a;
}
const int MAXN = 300;
pair<int, int> a[MAXN];
vector<pair<int, int> > ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, cnt;
scanf("%d", &n);
scanf("%d", &cnt);
int cur = 0;
for (int i =... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
struct segt {
int dat[262144];
segt() { memset(dat, -1, sizeof(dat)); }
void modify(int id, int val) {
for (id += 131072; id > 0; id >>= 1) dat[id] = max(dat[id], val);
}
int query(int l, int r) {
int ret = -1;
for (l += 131... | 4 |
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAX = 200000;
struct edge{
int from,to,num;
int cap,flow;
edge(int u= 0,int v=0,int c=0,int f=0):from(u),to(v),cap(c),flow(f){}
};
struct ISAP{
int head[MAX];
int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> pos;
int a[1000005];
void up(long long &a, long long b) {
if (a == -1 || b < a) a = b;
}
int solve(int x, int n) {
int stp = 0, re = 0;
while (1) {
if (stp + x >= n) {
re++;
break;
}
auto it = upper_bound(pos.begin(), pos.end(), stp... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.writ... | 5 |
#include <bits/stdc++.h>
namespace io {
char buf[1 << 15], *S = buf, *T = buf;
inline int F() {
register int aa = 0;
register bool bb = 0;
register char ch;
while (ch = (S == T && (T = (S = buf) + fread(buf, 1, 1 << 15, stdin), S == T)
? 0
: *S++),
(ch > '9' || ch ... | 5 |
#include<bits/stdc++.h>
using namespace std;
int main(void){
string s;
cin>>s;
if(s=="AAA"||s=="BBB") cout<<"No"<<endl;
else cout<<"Yes"<<endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long X, Y;
cin >> X >> Y;
if (Y == 0)
cout << "No\n";
else if (Y == 1) {
if (X == 0)
cout << "Yes\n";
else
cout << "No\n";
} else if (X >= Y - 1 && (X - (Y - 1)) % 2 == 0)
cout ... | 1 |
#include<stdio.h>
int main(void)
{
int n,m;
int a[10001],b[10001];
int flg[10001];
int i;
int c;
scanf("%d",&n);
scanf("%d",&m);
while(n!=0 && m!=0){
c=0;
for(i=2;i<=n;i++){
flg[i]=0;
}
flg[1]=2;
for(i=1;i<=m;i++){
scanf("%d %d",&a[i],&b[i]);
if(a[i]==1){
c++;
flg[b[i]]=1;
}
}
... | 0 |
// 2013/06/22 Tazoe
#include <iostream>
using namespace std;
void setD(int D[6], int t, int f)
{
D[0] = t;
D[1] = f;
D[5] = 7-t;
D[3] = 7-f;
if((D[0]==3&&D[1]==5) || (D[1]==3&&D[5]==5) || (D[5]==3&&D[3]==5) || (D[3]==3&&D[0]==5)) D[2] = 1;
else if((D[0]==3&&D[1]==1) || (D[1]==3&&D[5]==1) || (D[5]==3&&D[3]==1) ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, all = 0, x;
scanf("%I64d%I64d", &n, &m);
while (n--) {
scanf("%I64d", &x);
cout << (all + x) / m << " ";
((all + x) >= m) ? all = (all + x) % m : all += x;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
return (b == 0 ? a : gcd(b, a % b));
}
long long int lcm(int a, int b) { return (a * (b / gcd(a, b))); }
long long int max(long long int a, long long int b, long long int c) {
return max(a, max(b, c));
}
long long in... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
int a[maxn], b[maxn];
int main() {
int n, ans = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 0; i < 30; i++) {
int mod = 1 << (1 + i);
for (int j = 1; j <= n; j++) b[j] = a[j] % mod;
sort(b +... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
long long int n;
cin >> t;
while (t--) {
cin >> n;
cout << n << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int A[100];
int g = 0;
int n;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int noSolution() {
printf("0\n");
for (int i = (0); i < (n); i++) {
for (int j = (0); j < (A[i] * g); j++) {
printf("%c", i + ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 5;
int n, k, a[MX];
void solve(int l, int r) {
if (r - l <= 1) return;
int m = (l + r) >> 1;
if (k > 0) {
k -= 2;
for (int i = 0; i < m - l; i++) swap(a[l + i], a[m + i]);
solve(l, m);
solve(m, r);
}
}
int main() {
cin >> n >> ... | 4 |
#include<iostream>
#include<cstdio>
#define MN 50
#define mod 1000000007
using namespace std;
int n,f[MN+5][MN+5][MN+5],p[MN+5],inv[MN+5],ans;
inline void R(int&x,int y){x+=y;x>=mod?x-=mod:0;}
int main()
{
scanf("%d",&n);p[0]=inv[0]=p[1]=inv[1]=1;
for(int i=2;i<=n;++i) p[i]=1LL*p[i-1]*i%mod,inv[i]=1LL*(mod-mod/i)*in... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXW = 1000100, MAXN = 1000100, INF = 0x3f3f3f3f;
vector<pair<int, int>> a[MAXW], r[MAXW];
int n, w, l;
long long ans;
struct maxqueue {
private:
stack<int, list<int>> s1, s2;
int mx = -INF;
public:
inline void insert(int x) { mx = max(mx, x), s2.push(x);... | 5 |
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
int r=0,i;
char s[100010],c[100010];
scanf("%s",s);
for(i=0;s[i];i++){
if(s[i]=='B')r=MAX(r-1,0);
else c[r++]=s[i];
}
c[r]=0;
printf("%s\n",c);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 5e5 + 10;
pair<ll, double> q[MAXN];
#define dec ruiuiehrrefrf
int n, maxv, t, v, l = 1, r = 0;
ll dec, sum = 0;
double tem = 0;
int main()
{
scanf("%d%d", &n, &maxv);
for (int i = 1; i <= n; i++)
{
scanf("%d%d", &t, &v);
while ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int find(int m, int x) {
if (!m) return 1;
long long ans = find(m / 2, x);
ans = ans * ans % n;
if (m & 1) ans = ans * x % n;
return ans;
}
int main() {
cin >> n;
if (n == 1 || n == 4) {
cout << "YES\n";
if (n == 1)
cout << 1;
else
... | 3 |
#include<iostream>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(a%b==0) cout<<'0';
else cout<<'1';
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s[6];
for (int i = 0; i < 6; ++i) {
cin >> s[i];
}
bool flag = false;
for (int i = 1; i < 6; ++i) {
if (s[0][0] == s[i][0] || s[0][1] == s[i][1]) {
flag = true;
break;
}
}
if (flag)
cout << "YES";
else
cout... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
int v[150][150];
int s[150];
int ans1 = 0, ans2 = 0;
int pi = 0;
int p[150];
bool cmp(const int &a, const int &b) { return a > b; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &s[i]);
for (int j = 1; j <= s[i]; ++j) {
sc... | 3 |
#include <bits/stdc++.h>
using namespace std;
int t[105], s[105], ans[105];
void ask(int x, int i) {
cout << "+ " << x << endl;
cin >> t[i] >> s[i];
}
int calc(int x) {
int i = 1;
while (1) {
if (i * (i - 1) / 2 == x) return i;
++i;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0)... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int p, c = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> p;
if (p) {
c++;
cin >> p;
} else {
cin >> p;
if (p) c++;
}
}
}
cout << c;
re... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int a[N];
int n;
int ansA, ansD;
bool ok(int x) {
for (int d = 0; d <= 20000; d++) {
int low = a[0] - x, up = a[0] + x;
bool flag = true;
for (int i = 1; i < n; i++) {
low = max(low + d, a[i] - x);
up = min(up + d, a[i] + x);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
double eps = 1e-9;
const int INF = 1e9 + 7;
const int MAXN = int(3e5 + 7);
struct pt {
int x, y;
} p[MAXN];
long long dist(pt a, pt b) {
return 1ll * (a.x - b.x) * (a.x - b.x) + 1ll * (a.y - b.y) * (a.y - b.y);
}
long long area(pt a, pt b, pt c) {
long long d =
... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool vis[100002];
string s;
int d[100002];
int main() {
int n, k = 1;
cin >> n;
for (int i = 0; i <= n; i++) vis[i] = false;
cin >> s;
for (int i = 1; i <= n; i++) cin >> d[i];
int i = 1;
while (i <= n) {
if (vis[i] == true)
return cout << "INFINITE"... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long llinf = 1e18;
const long double pi = acos(-1);
const long double eps = 1e-10;
const long long mod = 2286661337;
ostream &operator<<(ostream &os, const pair<long long, long long> &a) {
return os << a.first << ' ' << a.second;
}
istream ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,i,wa=0;
cin>>n;
n*=2;
int a[n];
for(i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
for(i=0;i<n;i+=2){
wa+=a[i];
}
cout<<wa;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
double a[55];
int n;
int main()
{ cin>>n;
for(int i=1;i<=n;++i)
cin>>a[i];
sort(a+1,a+n+1);
for(int i=2;i<=n;++i)
{
a[i]=(a[i-1]+a[i])/2;
sort(a+i,a+n+1);
}
cout<<a[n]<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int sg[2][2][300005], v[4];
long long a[300005];
int repeat;
int cal(long long x, int j, int k) {
if (x < 1000) {
return sg[j][k][x];
} else {
return sg[j][k][(x - 1000) % repeat + 1000];
}
}
void work() {
int n, x, y, z;
scanf("%d%d%d%d", &n, &x, &y, &z);... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
long long int count = 0;
for (long long int i = s.size() - 1; i >= 0; i--) {
if (s[i] == '0')
count++;
else {
if (s[i] == '1' && count > 0)
count--;
else {
if (s[i] == '1' && count == 0) s[i]... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, cnt, now;
long long BASE[102], Base[102], x;
long long K[102], A[102][102];
bool Mk[102];
char S[102];
string a;
struct V {
string str;
long long h, w;
bool operator<(const V& a) const { return str < a.str; }
} AN[102];
map<string, long long> M;
void DO(l... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, d;
int cnt[30001];
int dp[30001][501];
int f(int curr, int st) {
if (curr >= 30001) return 0;
if (dp[curr][st] != -1) return dp[curr][st];
int l = d + st - 250;
int mx = 0;
if (l > 1) mx = max(mx, f(curr + l - 1, st - 1));
mx = max(mx, f(curr + l, st));
... | 1 |
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
cout<<n/500*1000+n%500/5*5<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> t;
while (t--) {
string s;
string h;
cin >> s;
sort(s.begin(), s.end());
cin >> h;
int n = s.size();
if (n > h.size()) {
cout << "NO\n";
continue;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int d;
cin >> d;
vector<long long> c(26);
for(int i = 0; i < 26; i++) cin >> c.at(i);
vector<vector<long long>> s(d, vector<long long> (26));
for(int i = 0; i < d; i++){
for(int j = 0; j < 26; j++) cin >> s.at(i).at(j);
}
vector<int> ans... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
template <typename T>
void read(T &x) {
bool neg = false;
unsigned char c = getchar();
for (; (c ^ 48) > 9; c = getchar())
if (c == '-') neg = true;
for (x = 0; (c ^ 48) < 10; c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
if (neg) x... | 5 |
#include <bits/stdc++.h>
inline int cmp(double x, double y = 0, double tol = 1e-9) {
return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
int n, m;
int A[503][503];
std::pair<long long int, long long int> red[503], blue[503];
bool is_left(std::pair<long long int, long long int> &p0,
std::pair<long long ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long A, B;
cin >> A >> B;
long long ans;
if (A*B < 0) ans = abs(A+B)+1;
else {
if (A < B) ans = B-A;
else {
ans = A-B+2;
if (A*B == 0) ans -= 1;
}
}
cout << ans << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
struct node {
int L, R, ty, val;
} a[maxn];
int in[maxn], out[maxn], sum[maxn << 1][10];
int tmp[maxn], S[maxn << 2], n, Q, T = 1, l, r;
char s[maxn];
void del(int x) {
a[a[x].L].R = a[x].R;
a[a[x].R].L = a[x].L;
}
void update(int o, int l, in... | 4 |
#include<stdio.h>
int main()
{
long n,i;
long k = 0;
long t = 0;
long long a;
scanf("%ld", &n);
for (i = 0; i < n; i++) {
scanf("%lld", &a);
if (a % 2 == 1)
k++;
if (a % 4 == 0)
t++;
}
if (t >= k) {
printf("Yes");
}
else if (n % 2 == 1 && k + t == n&&k - 1 == t) {
printf("Yes");
}
else {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int parent[100005], a[100005], num[100005];
int finds(int x) { return parent[x] == x ? x : parent[x] = finds(parent[x]); }
struct ss {
int u, v, w;
} e[100005];
bool cmp(ss s1, ss s2) { return s1.w > s2.w; }
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i =... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, p[25];
set<int> s;
void init() {
p[0] = 1;
for (int i = 1; i <= 20; i++) {
p[i] = p[i - 1] * 2;
s.insert((p[i] - 1) * (p[i - 1]));
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
init();
while (cin >> n) {
int ans;
for (int i ... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> vi;
int main() {
string str;
cin >> str;
int k;
cin >> k;
int ans = 0;
while (k--) {
int a = 0;
int b = 0;
string s;
cin >> s;
for (int i = 0; i < str.size(); i++) {
if (str[i] == s[0])
a++;
else if (str[i] == ... | 3 |
#include<iostream>
#include<string>
using namespace std;
char s[99]="abcdefghijklmnopqrstuvwxyz.?! ############################";
int main(){
string t;
while(cin>>t){
int f = 1;
string ans;
for(int i=0;i<t.size();i+=2){
if(t[i] < '1' || '6' < t[i] || t[i+1] < '1' || '5' < t[i+1]){
f = 0; break;
}
... | 0 |
#include<iostream>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)
int table[30][100];
#define INF 10000
int solve(vector<int> &cyc,vector<int>& day){
rep(i,day.size())rep(j,cyc.size())table[j][i]=INF;
table[0][0]=0;
REP(i,1,day.size()){
table[0][i]=... | 0 |
#include <iostream>
using namespace std;
int dp[100010];
int niz[110];
int main()
{
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> niz[i];
for (int i = 0; i <= k; i++)
for (int j = 0; j < n; j++)
if (niz[j] <= i)
if (!dp[i - niz[j]])
dp[i] = 1;
if (dp[k])
cout << "First" << endl;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[100002];
int main() {
int n, d, h, node = 2, i, j, start = 2, c = 1;
cin >> n >> d >> h;
if (h * 2 < d) {
puts("-1");
return 0;
}
if (d == 1 && n > 2) {
puts("-1");
return 0;
}
int temp = n - 1;
for (i = 1; i <= h; i++) {
v[... | 3 |
#include <bits/stdc++.h>
using namespace std;
unsigned int n, m, x;
vector<int> v;
int main() {
cin >> n >> m >> x;
for (int i = 1; i <= n; i++) {
if (i != x) v.push_back(i);
}
int r = n - 1 + ((n - 2) * (n - 3)) / 2;
if (r < m || m < n - 1) {
cout << -1;
return 0;
} else {
for (int i = 0; i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> meat(n);
vector<int> price(n);
vector<int> minimum_price(n);
int min = 10000007;
int i;
for (i = 0; i < n; i++) {
cin >> meat[i] >> price[i];
if (price[i] < min) min = price[i];
minimum_price[i] = min;
... | 1 |
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define N 3005
#define mo 1000000007
using namespace std;
int f[N][2*N][2],n,m;
int main()
{
cin>>n>>m;
f[0][0][1]=1;... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, z;
cin >> n >> m >> z;
int ans = 0;
int nX = n;
int mX = m;
int nPrev = 0, mPrev = 0;
for (int i = 0; i < z && (nX <= z && mX <= z); ++i) {
if (nX == nPrev && mX == mPrev) {
} else if ((nX == mX)) {
ans++;
}
nPrev =... | 1 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
for (int j = 0; j < x; j++) {
cout << "P";
if (j != x - 1) {
if (i == 0)
cout << "RL";
else
cout << "LR";
}
}
if ... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main(){
long N;cin>>N;
vector<long>A(N);for(int i=0;i<N;i++)cin>>A[i];
long ans=0;
ans+=A[0]/2;A[0]%=2;
for(int i=1;i<N;i++){
ans+=(A[i]+A[i-1])/2;A[i]=min((A[i]+A[i-1])%2,A[i]);
}
cout<<ans;
} | 0 |
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define VI std::vector<int>
#define VVI std::vector<VI>
#define PII std::pair<int, int>
#define f(n) for (int i = 0; i < n; i++)
#define FOR(i, n) for (int i = 0; i < n; i++)
#define make(T, n) T n; std::cin >> n
#define makev(name, n) VI name(n); f... | 5 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(228);
int a[100];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a, a + n);
int le = a[n - 1] - 1, ri = 20000;
while (ri - le > 1) {
int m... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string n;
cin >> n;
cout << n;
reverse(n.begin(), n.end());
cout << n;
cout << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
bool cek[1000];
long long arr[1000], n, arr1[50100], maks, comb[20000][510], hasil;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d", &arr[i]);
for (int j = 2; j <= 40000; j++)
while (arr[i] % j == 0) {
arr[i] /= j;
arr1[j]+... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long segTree[4 * 200010];
long long lazy[4 * 200010];
long long a[200010];
long long mini(long long a, long long b) {
if (a > b) {
return b;
} else
return a;
}
void build_tree(long long rangeLeft, long long rangeRight, long long index) {
lazy[index] = 0;
... | 3 |
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
struct edge{
int to,cost;
edge(int to,int cost):
to(to),cost(cost){}
edge(){}
};
struct visit{
int pos,total,b;
visit(int pos,int total,int b):
pos(pos),total(total),b(b){}
visit(){}
b... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-12;
const double PI = acos(-1);
const long long INFF = (long long)1e18;
const int INF = (int)1e9;
const int mod = (int)1e9 + 7;
const int MAX = (int)1e6 + 7;
int st[MAX];
int dp[MAX];
int main(void) {
int n, k;
scanf("%d %d", &n, &k);
for (int i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_INT = INT32_MAX;
const long long MAX_LL = INT64_MAX;
const long long mod = 1e9 + 7;
const int N = 1;
const long double pi = 3.14159265359;
bool primes[N + 1];
int npr(int n, int r) {
int res = 1;
for (auto i = n - r + 1; i <= n; i++) res *= i;
return res... | 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
template <class T>
inline void gmax(T &a, T b) {
if (b > a) a = b;
}
template <class T>
inline void gmin(T &a, T b) {
if (b < a) a = b;
}
using namespace std;
const int N = 1e6 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647,
... | 4 |
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int cnt[4];
int main() {
char t[8];
int x;
while (scanf("%d,%s", &x, t) != EOF) {
if (t[1] == 'B') cnt[2]++;
else if (t[0] == 'A') cnt[0]++;
else if (t[0] == 'B') cnt[1]++;
else if (t[0] == 'O') cnt[3]+... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n;
char str[N][10];
int type[N];
vector<int> wtf;
vector<int> fix;
vector<int> rekt[2];
int val[N];
set<int> there;
int e;
vector<pair<string, string> > v;
int main() {
scanf("%d", &n);
e = 0;
for (int i = 1; i <= n; ++i) {
scanf("%s", s... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll MOD = 1e9+7;
pair<int,int> p[200010];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll ans = 1;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p[i].first;
p[i].second = 1;
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
ll n, a[maxn], countN[maxn], ans;
int main(){
cin >> n;
for(int i=0; i<n; i++){
cin >> a[i];
countN[a[i]]++;
}
for(int i=1; i<=n; i++){
ans += (countN[i]*(countN[i]-1))/2;
}
for(int i=0; i<n; i++){
cout << ans... | 0 |
// Don't be dead serious about your life -- it's just like a program
// Never open a ranklist untill and unless you are done with solving problems, wastes 3/4 minutes
// Do not treat CP as a placement thing, love it and enjoy it, you will succeed for sure.
#include <bits/stdc++.h>
using namespace std;
typedef lon... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, p, q;
cin >> n >> m >> p >> q;
int x = 0, y = 0, a = 0, b = 0;
x = (n * 3 / 10);
y = (n - ((n / 250) * p));
a = (m * 3 / 10);
b = (m - ((m / 250) * q));
if (max(x, y) == max(a, b)) {
cout << "Tie" << endl;
} else if (max(x, y) > ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, d;
cin >> r >> d;
int n;
cin >> n;
int i, j, r1[n], x[n], y[n];
int ans = 0;
for (i = 0; i < n; i++) {
cin >> x[i] >> y[i] >> r1[i];
float b = sqrt(x[i] * x[i] + y[i] * y[i]);
if ((b - r1[i] >= r - d) && (b + r1[i] <= r)) ans++;... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 10;
const double eps = 1e-10;
int n, m, k, a[maxn], d[maxn][20], w[maxn][20];
double ans[maxn], k0[maxn], k1[maxn];
int query(int l, int r) {
int k = 0;
while ((1 << (k + 1)) <= r - l + 1) k++;
if (d[l][k] < d[r - (1 << k) + 1][k]) return w[... | 4 |
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define inf 111111111
using namespace std;
int n,p[55],t[55],dp[55][5];
int main()
{
int n;
while(scanf("%d",&n)==1)... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200 + 5, K = 200 + 5, Q = 5000 + 5;
int k, ans[N][N];
namespace BIPATITE {
const int N = ::N * ::N + 5;
int lk[2][N][K];
int get_mex(bool d, int x) {
int i = 1;
while (lk[d][x][i]) ++i;
return i;
}
void add_e(int x, int y, int c) {
lk[0][x][c] = y;
l... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int MAX = 80;
int dp[80][80][80][2];
vector<int> K, V, X;
void mini(int &a, int b) { a = min(a, b); }
int count_rem(const vector<int> &list, int from, int limit_val) {
int cnt = 0;
for (int i = from; i < (int)list.size() && list[i] < limit... | 5 |
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <... | 0 |
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <utility>
#include <vector>
using namespace std;
constexpr int number_of_hands = 9;
typedef pair<int, char> card;
inline bool same_colors(vector<card>::const_iterator first, vector<card>::const_iterator last) {
const char color ... | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
unordered_map<ll, ll>M;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int tot = 0;
int n;
scanf("%d", &n);
ll ans = 0;
for (ll i = 1; i <= n; i++) {
ll a;
scanf("%lld", &a);
ll e;
if (M.count(a) == 0)
e = 0;
else
... | 3 |
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int N = (int)2e5 + 123, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;
int n, ans;
vector< pii > v... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, m, k, ini[N], tipo[N];
vector<pair<int, int> > que[N][3];
bool cmp(pair<long long, pair<long long, int> > a,
pair<long long, pair<long long, int> > b) {
return (a.first * b.second.first > a.second.first * b.first);
}
bool cmp1(int a, ... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct ab {
int w, c;
double div;
};
bool operator<(ab a, ab b) { return a.div < b.div; }
long long int dp[300005];
ab a[100005];
int main() {
int n, m;
cin >> n >> m;
int w, c;
double div[n];
for (int i = 0; i < n; i++) {
cin >> w >> c;
a[i].w = w;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, s, max_sum;
pair<pair<int, int>, int> city[2000];
bool gor_mil(double r) {
int sum = s;
for (int i = 0; i < n; i++) {
double x = city[i].first.first, y = city[i].first.second;
if (x * x + y * y <= r * r) sum += city[i].second;
}
return sum >= 1000000;... | 2 |
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> order... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
scanf("%d", &a);
scanf("%d", &b);
if (a < b) {
printf("-1\n");
return 0;
}
double n = (double)a / b;
int ni = (int)n;
int l = ni;
if (l % 2 == 0) l -= 1;
int diff = a - l * b;
double res = b + (double)diff / (ni + (ni % 2... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n, sz, a[1000005], s[1000005];
bool ch(long long p1, long long q1, long long p2, long long q2) {
return p1 * q2 > q1 * p2;
}
int main() {
long long i, j, t, x;
cin >> n;
cin >> t;
a[0] = t;
s[0] = 1;
sz = 0;
for (i = 1; i < n; i++) {
scanf("%I6... | 5 |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int N, D;
void solve() {
vector<vector<int> > C(N, vector<int>(10000));
for (int i = 0; i < N; i++) {
int m; cin >> m;
C[i].resize(m);
for (int j = 0; j < m; j++) {
cin >> C[i][j];
}
}
f... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.