solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000000000;
const int M1 = 1000000007;
const int M2 = 998244353;
const int N = 100005;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int n, m, k, a, b, temp, x, y;
cin >> n >> m;
vector<int> vertical;
for (in... | 1 |
#include <bits/stdc++.h>
using namespace std;
class graph {
int v, e;
list<pair<int, int> > *adj;
list<pair<int, int> > *clrs;
public:
graph(int v_, int e_) : v(v_), e(e_) {
adj = new list<pair<int, int> >[v];
clrs = new list<pair<int, int> >[e];
}
void add_edge(int x, int y, int w) {
adj[x].p... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2 = "";
cin >> s1;
for (int i = 0; i < s1.size(); i++) {
if (s2.back() != s1[i]) {
s2 += s1[i];
} else {
s2.pop_back();
}
}
cout << s2 << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int n, w[200005], root, tmp;
vector<int> ch[200005];
void dfsw(int u) {
w[u] = 1;
for (int v : ch[u]) dfsw(v), w[u] += w[v];
}
void dfsd(int u) {
for (int v : ch[u])
if (!(w[v] & 1)) dfsd(v);
cout << u << '\n';
for (int v : ch[u])
if ((w[v] & 1)) dfsd(v);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(){
double t,x; cin >>t>>x;
cout << (t/x) << endl;
} | 0 |
#include <bits/stdc++.h>
const long long P = 1e9 + 7;
const long long N = 1e5 + 9;
long long n, m, k, x;
std::vector<long long> G[N];
long long dp[N][11][3], tmp[N][11][3], ntmp[N][11][3];
void dfs(long long u, long long fa) {
ntmp[u][0][0] = k - 1;
ntmp[u][1][1] = 1;
ntmp[u][0][2] = m - k;
for (auto v : G[u]) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(){
long long n, m;
cin >> n >> m;
if(2*n < m){
cout << n + (m - 2*n)/4;
}else{
cout << m/2;
}
return 0;
} | 0 |
#include <iostream>
long long euler_phi (long long n) {
long long ret = n;
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
ret -= (ret / i);
while (n % i == 0) {
n /= i;
}
}
}
if (n > 1) ret -= (ret / n);
return ret;
}
int main() {
long long n;
std::cin >> n;
std::cout << euler_p... | 0 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, i... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool best[101];
int main() {
int n, m, kol = 0;
cin >> n >> m;
char a[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
for (int j = m - 1; j >= 0; j--) {
int k_max = 0, max = -1;
vector<int> v;
for ... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int main() {
int n, i, x, y, mini = 0, maxi = 0;
cin >> n;
for (i = 0; i < 3; i++) {
cin >> x >> y;
mini += x;
maxi += y;
v.push_back(make_pair(x, y));
}
if (n == mini) {
for (i = 0; i < 3; i++) cout << v[i].first << ... | 1 |
#include <iostream>
#include <string>
using namespace std;
void solve()
{
string str;
char c;
while(cin >> str)
{
cin >> c;
string Answer;
int size = str.size();
if(c == 'X')
{
break;
}
else if(c == 'L')
{
if('A' <= str[0] && str[0] <= 'Z')
{
Answer += str[0] - 'A' + 'a';
}
else... | 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 string get() {
char ch[2000010];
scanf("%s", ch);
return ch;
}
const int MAX_LG = 21;
const int maxn = 2e6 + 10;
const int... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[500005];
int b[500005];
vector<int> v;
int vis[102][102];
char gr[102][102];
int main() {
int n, i, j, k, kk, p, q, res;
int t;
cin >> n >> kk;
getchar();
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
cin >> gr[i][j];
}
}
for (i = 0; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
while (true) {
bool stop = true;
int m = n;
while (m > 0) {
if (m % 3 == 2) stop = false;
m /= 3;
}
if (stop) break;
n++;
}
cout << n <... | 3 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> m;
long long k, b, n, ans0, ans, x, sum[1000001], cnt[1000001];
int main() {
cin >> k >> b >> n;
if (!b) {
for (long long i = 1; i <= n; i++) {
cin >> x;
cnt[0] = (!x) ? (cnt[0] + 1) : 0;
ans += cnt[0];
}
cout << ans << endl;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, x;
cin >> n >> x;
int ans;
if (n <= 2) {
cout << '1' << endl;
continue;
}
if ((n - 2) % x != 0) {
ans = (n - 2) / x + 2;
} else {
ans = (n - 2) / x + 1;
}
co... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
int n;
int long long val;
int long long ans;
cin >> t;
while (t--) {
cin >> n;
vector<int long long> v;
for (int i = 0; i < n; i++) {
cin >> val;
v.push_back(val);
}
int long long neg = 0;
int long long ans... | 2 |
#include <bits/stdc++.h>
using namespace std;
double st[2002][2002];
int main() {
ios_base::sync_with_stdio(true);
int n, t;
double p;
scanf("%d %lf %d", &n, &p, &t);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= t; j++)
st[i][j] = ((p) * (1 + st[i - 1][j - 1]) + (1 - p) * (st[i][j - 1]));
}... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, ans[100], tot = 0;
cin >> n >> m;
for (int i = 0; i < m; i++) {
ans[i] = n / m;
tot += ans[i];
}
if (tot == n)
for (int i = 0; i < m; i++) {
cout << ans[i];
if (i != m - 1) cout << " ";
}
else {
for (int i =... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m;
int f[N], a[N], r[N];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
}
int ans = 1;
for (int i = 0; i < n; i++) {
if (i == 0 || i == n - 1) {
f[i] = 1;
continue;
}
f[i] = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, a[N], b[N];
pair<int, int> s[N];
int main() {
scanf("%d", &n);
for (int i = (0); i < (n); ++i) {
int si;
scanf("%d", &si);
s[i] = make_pair(si, i);
}
sort(s, s + n);
int B = (n - 1) / 3 + 1;
for (int i = (B << 1); i < (n... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
template <class c>
debug& operator<<(const c&... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, a, b, c, d, l1, l2, r1, r2;
int main() {
cin >> t;
while (t--) {
cin >> n >> a >> b >> c >> d;
l1 = (a - b) * n;
r1 = (a + b) * n;
l2 = c - d;
r2 = c + d;
if (l1 > l2) {
swap(l1, l2);
swap(r1, r2);
}
if (l1 == ... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct AhoCorasick {
static const int UNDEF = 0;
static const int MAXN = 128;
static const int CHARSET = 4;
int end;
int tag[MAXN];
int fail[MAXN];
int trie[MAXN][CHARSET];
void init() {
tag[0] = UNDEF;
fill(trie[0], trie[0] + CHARSET, -1);
end =... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
char c = getchar();
long long x = 0, f = 1;
while (c > '9' || c < '0') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
long long n, m, a, b... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool compose(int n) {
for (int i = 2; i <= (n / 2); i++) {
if (n % i == 0) {
return true;
}
}
return false;
}
int main() {
int n, a, b;
cin >> n;
for (int i = n / 2; i >= 2; i--) {
if ((compose(i)) && compose(n - i)) {
a = i;
b = n ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long power(long long a, long long n);
int main() {
string s;
cin >> s;
long long n = s.length(), k, ans = 0, temp = 0, now;
cin >> k;
for (int i = 0; i < n; i++) {
if (s[i] == '0' || s[i] == '5') {
ans = (ans + power(2, i... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct Coor {
int x, y;
};
long long commonS(const pair<Coor, Coor>& rect1, const pair<Coor, Coor>& rect2);
int main() {
int t;
cin >> t;
while (t--) {
int m, n;
Coor a1, a2;
cin >> m >> n >> a1.x >> a1.y >> a2.x >> a2.y;
if (a1.x > a2.x) swap(a1.x, ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long k, n, m, a[100], b[100];
struct matrix {
long long a[100][100];
matrix() {
for (int i = 0; i < 100; ++i)
for (int j = 0; j < 100; ++j) a[i][j] = (i == j) ? 0 : 2000000000000ll;
}
void inf() {
for (int i = 0; i < 100; ++i)
for (int j = 0... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
long long res = 1ll;
while (b > 0) {
if (b % 2ll) res = (res * a) % 1000000007;
a = (a * a) % 1000000007;
b /= 2ll;
}
return res;
}
long long GCD(long long a, long long b) {
if (b == 0) return a;
return GCD... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long z, n, k;
cin >> n >> k;
z = k * ((n / k) + 1);
cout << z;
}
| 1 |
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
string S;
cin >> S;
reverse(S.begin(), S.end());
cout << S << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace ::std;
const long double PI = acos(-1);
const long long MOD = 1000000000 + 7;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long add(long long a, long long b, long long m = MOD) {
if (a >= m) a %= m;
if (b >= m) b %= m;
if (a < 0) a +=... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int a, b, c, ty;
} a[100010];
struct Tnode {
int x, f, tag, ls, rs;
} t[3000000];
int n, m, k, K, ans, rt, tot;
bool cmp(node x, node y) { return x.a < y.a; }
int getfull(int l, int r) {
int s = 0;
l--;
for (int j = 1; j <= k; j <<= 1)
s |= (((r ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[300050];
int dp[300050];
int prv[300050];
map<int, int> mp[300050];
int main() {
int tc;
scanf("%d", &tc);
while (tc--) {
int n;
scanf("%d", &n);
long long res = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
prv[i] = -1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
int main() {
string s;
cin >> s;
vector<long long> v(s.size() + 2, 0);
vector<long long> pt(s.size() + 2, 0);
long long curr = 1;
long long t = 1;
for (int i = 1; i < v.size(); i++) {
v[i] = (curr * t) % MOD;
t++;
curr *= 1... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
vector<int> v[100];
int n;
cin >> n;
int ar[1000];
for (int i = 0; i < n; i++) {
cin >> ar[i];
}
for (int i = 0; i < n; i++) {
int t;
for (int j = 0; j < ar[i]; j++) {
cin >> t;
v[i].push... | 1 |
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 1000000000
int main(){
int n,k;
while(cin >> n >> k,n+k){
int d[110][110];
for(int i = 0; i < 110; i++)for(int j = 0; j < 110; j++)d[i][j] = i==j?0:INF;
for(int i = 0; i < k; i++){
int a;
cin >> a;
int from,to,cost... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N;
cin >> M;
char mas[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cin >> mas[i][j];
}
}
int posx1, posy1;
for (int i = 0; i < N; i++) {
int ok = 0;
for (int j = 0; j < M; j++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:500000000000")
void ending() { exit(0); }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
long long n, k;
cin >> n >> k;
if (k == 1) {
cout << n;
} else {
long long pow = 1;
while (pow <= n) pow *= 2;
cou... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 20;
long long n, ans[maxn], p, cur_time, tmp, it, x, update_time = -1;
vector<pair<long long, long long>> ar;
priority_queue<long long> q;
queue<long long> q2;
set<long long> s2;
void por() {
while (it < n && ar[it].first <= cur_time) {
q.push(a... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x, y;
cin >> n >> m >> x >> y;
vector<int> A(n), B(m);
for (int i = 0; i < n; i++) cin >> A[i];
for (int i = 0; i < m; i++) cin >> B[i];
vector<pair<int, int> > C;
int i = 0, j = 0;
while (i < n && j < m) {
if (A[i] - x <= B[j] && ... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
inline void read(Tp &x) {
static char c;
static bool neg;
x = 0, c = getchar(), neg = false;
for (; !isdigit(c); c = getchar()) {
if (c == '-') {
neg = true;
}
}
for (; isdigit(c); c = getchar()) {
x = x * 10 + c - '0';
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main(void){
int n,r;
int p,c;
while(true){
cin>>n>>r;
if(n==0&&r==0)return 0;
vector<int> ca(n);
vector<int> t(n,0);
vector<int> t2(n,0);
for(int i=0;i<n;i++)ca[i]=n-i;
for(int i=0;i<r;i++){
cin>>p>>c;
for(int j=0;j<c;j++){
t[p-1+j]=ca[p-1+j];
}
for(int k=0;k<p-1... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool horses(int x1, int y1, int x2, int y2) {
return ((abs(x1 - x2) == 1 && abs(y1 - y2) == 2) ||
(abs(x1 - x2) == 2 && abs(y1 - y2) == 1));
}
bool horse_and_ladia(int x1, int y1, int x2, int y2) {
return (horses(x1, y1, x2, y2) || (x1 == x2 || y1 == y2));
}
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
char s[500020];
int a[500020], ac;
int n, T, q, fh;
int ok(int x) {
int c = x, ti = 0, nd = 0, bk = 0, md = 0, fr = fh;
if (x + ac < q) return 0;
if (x < q) fr = max(fr, a[q - x - 1]);
for (int i = 0; i < n; i++) {
if (s[i] == 'S') {
c++;
if (nd != 0... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, ans1 = 0, ans2 = 0;
cin >> n >> m;
if (n > m) {
swap(n, m);
}
ans1 = ans2 = n;
ans1 += m - n - 1;
cout << ans1 << " " << ans2;
return 0;
}
| 2 |
#include<iostream>
using namespace std;
int main(){
int d;
while (cin >> d){
int s = 0;
for (int i = 1; i*d < 600; i++){
s += (i*d)*(i*d)*d;
}
cout << s << endl;
}
return 0;
} | 0 |
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
#define U(v) cerr << #v << ": " << (v) << endl
template <class T>
struct BIT {
vector<T> a;
BIT(int size) : a(size, 0) {}
T sum(int r) const {
T sm = 0;
for (--r; r >= 0; r = (r & r + 1) - 1)
... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool check(int xa, int ya, int xb, int yb, long long xc, long long yc) {
long long k1 = xb - xa;
long long k2 = yb - ya;
if (xc != 0) {
long long wNum = k1 * yc - k2 * xc;
long long wDen = xc * xc + yc * yc;
if (wNum % wDen) return false;
long long w =... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
long long int a[n], b[n];
vector<int> v;
for (int i = 0; i < n; i++) cin >> a[i];
for (int j = 0; j < n; j++) {
cin ... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s,s1;
cin>>s;
cin>>s1;
int a=0;
for(int i=0;i<3;i++)
{
if(s[i]==s1[i])a++;
}
cout<<a;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<string> v;
int n, k;
string x[9];
class state {
public:
int mask;
string str;
};
int tar;
void generate() {
queue<state> q;
state sr, ns;
for (int i = 0; i < k; ++i) {
sr.str = (char)(i + '0');
sr.mask = 1 << i;
q.push(sr);
}
while (!q.empt... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long a[300007], rest[300007];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
rest[i % 2] += (a[i] + 1) / 2;
rest[(i + 1) % 2] += a[i] / 2;
}
cout << min(rest[0], rest[1]) << endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int t, n, m, q, i, j, k, x, y, z;
set<long long int> s;
cin >> n;
for (i = 0; i < n; i++) {
cin >> x;
if (x != 0) s.insert(x);
}
cout << s.size() << "\n";
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
int grid[5][5];
int no[20];
int vis[20];
int hv[20];
bool pl;
int sum;
int N;
bool four() {
grid[2][2] = hv[7];
int t1, t2, t3;
int s = sum - (grid[2][0] + grid[2][1] + grid[2][2]);
bool plx = false;
for (int i = 0; i < N; i++) {
if (no[i] == s && vis[i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, ice, dis = 0, kid;
char sign;
cin >> n >> ice;
for (int i = 0; i < n; i++) {
cin >> sign >> kid;
if (sign == '+')
ice += kid;
else {
if (kid <= ice)
ice -= kid;
else
dis++;
}
}
cout ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ar[n];
int min = INT_MAX;
int flag = 0;
int count = 0;
for (int i = 0; i < n; i++) {
cin >> ar[i];
if (ar[i] < min) min = ar[i];
if (i < n - 1) {
if (ar[i] == 0 && ar[i + 1] == 0) flag = 1;
}
if (ar[0... | 2 |
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)
int main() {
map<string,UL> S;
UL Q; scanf("%u",&Q);
rep(q,Q){
UL c; scanf("%u",&c);
if(c==0){
char buf[21]; UL x; scanf("%s%u",buf,&x);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int S = 30001;
const int K = 400;
int N, D, X, val[S];
int dp[S][800];
int check(int x, int d) {
if (x >= S) return 0;
if (d <= 0) return -S;
int &k = dp[x][d - D + 400];
if (k) return k - 1;
k = max(k, check(x + d - 1, d - 1));
k = max(k, check(x + d, d))... | 1 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma optimize("gtsy", on)
using namespace std;
const long double EPS = 1e-8;
const int INF = (int)1e9 + 10;
const int MOD = (int)1e9 + 7;
const int N = (int)2e5 + 10;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
;... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, m, s, t;
vector<int> g[N];
void bfs(int _s, int _t, vector<int> &d) {
d[_s] = 0;
queue<int> q;
q.push(_s);
while (!q.empty()) {
int x = q.front();
q.pop();
for (int i = 0; i < g[x].size(); ++i) {
int y = g[x][i];
if... | 4 |
#include <bits/stdc++.h>
using namespace std;
void minimize(int &a, int b) { a = std::min(a, b); }
void maximize(int &a, int b) { a = std::max(a, b); }
int main() {
int maxi = 2 * 1000 * 1000 * 1000;
int mini = -maxi;
int n;
cin >> n;
while (n--) {
string str1;
cin >> str1;
int x;
cin >> x;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int inf = int(1e9);
const double eps = 1e-9;
int n, m;
double res;
pair<int, int> p[4], best[4];
set<pair<int, int> > s;
inline double sqr(double a) { return a * a; }
inline double dist(pair<int, int> a, pair<int, int> b) {
return sqrt(sqr(a.first - b.first) + sqr(a... | 2 |
#include<iostream>
#include<vector>
#include<cassert>
#include<algorithm>
#include<cmath>
#include<cstdio>
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-6)
#define equals(a,b) (fabs((a)-(b))<EPS)
using namespace std;
typedef long long ll;
struct Edge {
int s,t;
ll c,d... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a;
bool re = false;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
if (a == 1) re = true;
}
if (re)
cout << "HARD";
else
cout << "EASY";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long dp[2222][2222];
int main(){
int N;
cin >> N;
vector<long long> A(N);
for(auto &i:A)cin >> i;
vector<pair<long long,int>> c(N);
for(int i=0;i<N;i++)c[i]=make_pair(A[i],i);
sort(c.begin(),c.end());
reverse(c.begin(),c.end());
for(int xy=1;xy<=N;xy++){... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, num;
cin >> n >> m;
int num_o = 0, num_no = 0;
for (int i = 0; i < n; i++) {
cin >> num;
if (num == 1)
num_o++;
else
num_no++;
}
int l, r;
for (int i = 0; i < m... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int s1 = 0, s2 = 0;
int x[105], y[105];
bool pos = false;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
for (int i = 0; i < n; i++) {
s1 += x[i];
s2 += y[i];
if (x[i] % 2 != y[i] % 2) {
pos = true;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, t, n, m, k, l, r, temp, mini, maxi = -1, flag, result, cnt;
scanf("%d", &n);
stack<int> S;
S.push(-1);
for (i = 0; i < n; i++) {
scanf("%d", &k);
S.push(k);
maxi = max(maxi, k);
temp = S.top();
S.pop();
while (S.top()... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int BUBEN = sqrt(200 * 1000);
struct node {
node* go[26];
node* dpgo[26];
node* link;
node* parent;
int lst;
int dp;
int id;
node() {
for (int i = 0; i < 26; i++) {
go[i] = NULL;
dpgo[i] = NULL;
}
parent = NULL;
lst = -1;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, w[10010], a[5010], x[5010], s, f[10010], h[10010], p;
vector<int> b[10010];
long long ans;
inline void dp(int i) {
for (auto j : b[i]) {
dp(j);
w[i] += w[j];
}
}
int main() {
int i, j, k, l;
scanf("%d", &n);
m = n;
while (n--) {
scanf("%d",... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 203;
int a[NMAX], inside[NMAX], outside[NMAX];
int main() {
cin.sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int sol = -(1 << 30), sum = 0, st, dr, insize, outsize;
for (in... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool nd = false;
int n, k;
vector<int> diff, dc;
set<string> chk, t, chk2;
vector<string> s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> k >> n;
s.assign(k, "");
for (int i = 0; i < k; ++i) {
cin >> s[i];
string z = s[i];
sort(... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const long long MAXN = 200010;
struct node {
long long v, m;
} st[MAXN];
long long vis[MAXN], s, t, n, k;
bool calc(long long w) {
long long ans = 0;
for (int i = 1; i <= k; i++) {
long long cut = vis[i] - vis[i - 1];
if (w < ... | 3 |
#include <cstdio>
const int MAXN = 51;
const int ZERO = 2551;
const int MAXM = ZERO*2;
typedef long long LL;
LL F[MAXN][MAXM];
int C[MAXN];
int main()
{
int N, A, i, j, x;
scanf("%d%d", &N, &A);
F[0][ZERO] = 1;
for(i=1; i<=N; ++i)
{
scanf("%d", &x);
x -= A;
for(j=MAXN; j+MAXN<MAXM; ++j)
F[i][j] = F[i-1][j... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;int i;cin>>S;
do{
S.erase(S.size()-2);
for(i=0;i<S.size()/2;i++){if(S.at(i)!=S.at(i+S.size()/2))break;}
if(i==S.size()/2)break;
}while(1);
cout<<S.size()<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3, Mod = 1e9 + 7;
int main() {
int n;
cin >> n;
int a1, a2, a3, b1, b2, b3;
cin >> a1 >> a2 >> a3;
cin >> b1 >> b2 >> b3;
int maxi = min(a1, b2) + min(a2, b3) + min(a3, b1);
int mini = max(0, a1 + b2 - n);
mini = max(mini, a2 + b3 - n);
... | 5 |
#include<iostream>
#include<vector>
struct Sweets{
int i, p, q, r;
};
int main(){
int n;
while(std::cin >> n, n){
std::vector<Sweets> v;
for(;n--;){
Sweets s;
std::cin >> s.i >> s.p >> s.q >> s.r;
v.push_back(s);
}
int P, Q, R, C;
std::cin >> P >> Q >> R >> C;
for(int i=0;i<v.size();i++){
... | 0 |
#include <iostream>
using namespace std;
int main(){
int w;
while(cin >> w && w != -1){
int c = 0;
c += 1150;
c += 125 * max(0,min(w-10,10));
c += 140 * max(0,min(w-20,10));
c += 160 * max(0,w-30);
cout << 4280 - c << endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105, M = 1005;
double f[N][M * N], sum[N][N * M];
int n, m, V;
int a[N];
int main() {
scanf("%d%d", &n, &m);
if (m == 1) return puts("1.000000000000"), 0;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) V += a[i];
f[0][0... | 3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
cout << (n / 2) + 1 << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin >> t;
while (t--) {
solve();
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define AL... | 2 |
#include <bits/stdc++.h>
using namespace std;
int v[100005], b[100005];
int main() {
int N;
scanf("%d", &N);
for (int i = 0; i < N; i++) scanf("%d", &v[i]);
for (int i = 0; i < N; i++) scanf("%d", &b[i]);
long long joy = 0;
for (int i = 0; i < N; i++) {
if (v[i] * 2 < b[i])
joy--;
else {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int N, M;
bool S[123456];
vector<int> g[123456];
int deg[123456];
bool need[123456];
bool dfs1(int idx, int par) {
bool f = S[idx];
for (auto &to : g[idx]) {
if (to == par) continue;
f |= dfs1(to, idx);
}
need[idx] = f;
return f;
}
template <typename Data,... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int a[1001];
int dif[1001];
a[0] = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
dif[i - 1] = a[i] - a[i - 1];
}
vector<int> len;
len.push_back(n);
for (int i = 1; i < n; i++) {
int j, k;
for (j = i, k = 0; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n, m, a, b;
vector<pair<long long, long long>> v;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a >> b;
v.push_back({a, b});
}
vector<long long> v1;
long l... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int a[10000000], b[100];
bool used[1000000];
int main() {
long long int n, ans = 0, len = 0;
cin >> n;
if (n == 1) {
cout << 1;
return 0;
}
for (int i = 2; i <= sqrt(n * 1.0); i++) {
if (n % i == 0) {
len++;
a[len] = i;
if (... | 2 |
#include <iostream>
#include <string>
#include <queue>
#include <numeric>
#include <algorithm>
using namespace std;
int main(){
int n, p;
while(cin >> n >> p, n|p){
vector<int> people(n);
int stone = p;
bool finish = false;
for(int i=0; !finish; i++){
i = i%n;
if(stone != 0){
people[i]++;
sto... | 0 |
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
cin>>s;
if(s[s.size()-1]!='s')
{
cout<<s<<'s';
}
else
{
cout<<s<<"es";
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x7f7f7f7f;
long long GCD(long long a, long long b) { return 0 == b ? a : GCD(b, a % b); }
const long long mod = 1e9 + 7;
const double pi = acos(-1);
struct noode {
int num, index, x;
} b[2100];
int main() {
ios_base::sync_with_stdio(false);
int ... | 3 |
#include <bits/stdc++.h>
#define int long long
#define ALL(c) begin(c),end(c)
using namespace std;
signed main() {
vector<int> a(4),b(2);
for(int i=0; i<4; i++) cin>>a[i];
for(int i=0; i<2; i++) cin>>b[i];
sort(ALL(a));
sort(ALL(b));
cout<<(accumulate(ALL(a),0ll)-a[0])+(accumulate(ALL(b),0ll)-b[... | 0 |
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
char s[110];
int n, sol = 110;
int chk( char c ){
int ret = 0;
int last = -1;
s[n] = c;
for ( int i = 0; i <= n; i++ )
if ( s[i] == c ){
ret = max(ret, i - last - 1);
last = i;
}
return (last < 0) ? 110 : ret;
}
int mai... | 0 |
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
int top[100][100];
int h[100][100];
int Rotation[4][6]={
{5,1,4,3,0,2}, //南
{0,5,2,4,1,3}, //東
{4,1,5,3,2,0}, //北
{0,4,2,5,3,1} //西
};
struct P{int x,y;} d[4]={
{0,-1}, //南
{1,0}, //東
{0,1}, //北
{-1,0} //西
};
int main(){
int i,j,n... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
long long b[100005], s, mx;
bool t;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
cin >> t;
if (t)
s +=... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, a[4], dp[302][302];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
if (n == 1) {
if (a[0])
printf("BitLGM\n");
else
printf("BitAryo\n");
return 0;
}
if (n == 3) {
if (a[0] ^ a[1] ^ a[2])
print... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
long long ans = 0;
for (int i = (0); i < (n); ++i) {
long long t, T, x, cost;
cin >> t >> T >> x >> cost;
if (t >= T) {
ans += cost + m * x;
continue;
}
long long aux1 = cost;
if (m > (T - t))... | 4 |
#include <bits/stdc++.h> // clang-format off
using namespace std;
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (int i = (a), lim_i = (b); i < lim_i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), co... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
int evenp[n], oddp[n], evens[n], odds[n];
oddp[0] = v[0];
evenp[0] = 0;
for (int i = 1; i < n; i++) {
if (i % 2 == 0) {
oddp[i] = v[i] + oddp[i - 1];... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.