solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d", &n);
long a;
long long c[1000000];
long long b1[21];
long long b2[21];
long long b3[21];
long long t[21];
t[0] = 1;
b1[0] = 0;
for (int i = 1; i <= n; i++) t[i] = t[i - 1] << 1;
vector<vector<long> > v;
for (int i... | 3 |
#include <bits/stdc++.h>
using namespace std;
char str[100005];
int main() {
int n, k;
scanf("%d%d", &n, &k);
getchar();
scanf("%s", str + 1);
int i, cnt;
for (i = 1, cnt = 0; i <= n && cnt < k; i++) {
if (i % 2) {
if (str[i] == '4' && str[i + 1] == '4' && str[i + 2] == '7') break;
if (str[i... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T a) {
return a * a;
}
template <class T>
T abs(T x) {
if (x < 0) return -x;
return x;
}
const double eps = 1e-8;
const double pi = acos(-1.0);
char str[200010];
int main() {
int n, i, f, a, b;
while (1 == scanf("%d", &n)) {
f = a = b ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q;
int u[500005], v[500005], wt[500005], par[500005],
waqt = 0, waqtForNodes[500005], parr[500005];
map<int, bool> M;
vector<pair<int, int> > offlineStoredQueries[500005];
vector<int> eg[500005];
int find2(int x) {
if (waqtForNodes[x] != waqt) {
waqtForN... | 3 |
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 1010;
const double INF = 1e10;
struct circle {
double x, y, r;
};
circle c[MAXN];
double xs, ys, xt, yt, d[MAXN], G[MAXN][MAXN];
int n;
bool used[MAXN];
double dist(circle a, circle b) {
return sqrt((a.... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, a[500005], b[500005], dd[500005];
vector<int> order;
struct IntervalTree {
pair<int, int> t[500005 << 2];
void update(int l, int r, int id, int x, int val) {
if (l == r) {
t[id] = make_pair(val, x);
return;
}
if (x <= (r + l) / 2)
up... | 5 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
struct Widget {
string name;
int hor;
int border;
int spacing;
long long first, second;
bool calculated;
vector<string> nxt;
Widget() {
border = 0;
spacing = 0;
first = second = 0;
calculated = false... | 2 |
#include <bits/stdc++.h>
const int N = 100141;
using namespace std;
int n, m, fn, value, cnt, c = 0;
long long dp[N], f[N], mod = 1e9 + 7;
vector<int> a;
vector<int> lk;
bool lucky(int x) {
while (x > 0) {
if (x % 10 != 7 && x % 10 != 4) return 0;
x /= 10;
}
return 1;
}
long long binpow(long long a, long ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m, x;
cin >> n;
set<long long> st;
while (1) {
if (st.find(n) != st.end()) break;
st.insert(n);
n++;
while (n % 10 == 0) {
n /= 10;
}
}
cout << st.si... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, k, i;
cin >> n;
char a[110];
cin >> a;
for (i = 0; i < n; i++) {
if (a[i] == '8') {
k = i;
break;
}
}
if (n - i < 11)
cout << "NO" << endl;
else
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n;
long long a[10], b[10];
bool vis[10];
int main() {
long long sum = 0, ans = 0;
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%lld", &a[i]);
sort(a, a + n);
for (int i = 0; i <... | 3 |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < n; i++)
#define int long long
signed main(signed argc, char* argv[]) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
cin>>n>>m;
cout<<n*m<<endl;
}
| 0 |
#include <cstdio>
int main(){
int X,Y,Z;
scanf("%d %d %d",&X,&Y,&Z);
printf("%d %d %d\n",Z,X,Y);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 7;
const int MAXM = 1e7 + 9;
const int P = 1e9 + 7;
int isp[MAXM], pri[MAXM / 10];
int S[MAXM], _2[MAXN], a[MAXN], tot[MAXM], g[MAXM], cnt, mu[MAXM];
bool vis[MAXM];
inline void upd(int &a) { a += (a >> 31) & P; }
int n, lim, ans;
void sieve(const int... | 5 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
void __never(int a) { printf("\nOPS %d", a); }
char S[1024];
int i = 0, ans = 0;
string read_token() {
string re;
while (S[i] >= 'A' && S[i] <= 'Z') re.push_back(S[i++]);
return re;
}
map<string, int> parse() {
map<string, ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string str;
cin >> str;
map<string, int> mp;
for (int i = 1; i < n; i++) {
string tt = "";
tt += str[i - 1];
tt += str[i];
mp[tt]++;
}
int cnt = -1;
string ans;
for (auto x : mp) {
if (cnt < x.second) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b;
cin >> a >> b;
double len = a + b;
int k = (a + b) / (b + b);
if (k < 1)
puts("-1");
else
printf("%.12lf\n", len / 2.0 / k);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
x = 0;
int w = 1;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + ch - 48, ch = getchar();
}
x *= w;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, b, d, s, i, ans = 0;
cin >> b >> d >> s;
n = max(b, max(d, s));
if (b < n - 1) ans += n - 1 - b;
if (d < n - 1) ans += n - 1 - d;
if (s < n - 1) ans += n - 1 - s;
cout << ans << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long d[1000002], vis1[1000002], add[1000002];
long long ans = 0;
int main() {
int num, x, y, i, j, k, num2, m, n, t;
scanf("%d%d", &n, &m);
d[0] = 1;
for (i = 1; i <= n; i++) {
d[i] = d[i - 1] * 101;
}
for (i = 1; i <= m; i++) {
scanf("%d%d... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
float x, n, sum = 0;
cin >> x;
for (int i = 0; i < x; i++) {
cin >> n;
sum += n;
}
cout << sum / x;
return 0;
}
| 2 |
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int main() {
ll n;
std::cin >> n;
if(n==1){
std::cout << 1 << std::endl;
return 0;
}
set<ll> element;
ll nown = n;
for (int i = 2; i <= sqrt(n); i++) ... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int v, nxt;
} e[300005 << 1];
int adj[300005], n, m, c, fa[300005], dep[300005];
inline void Add(int u, int v) {
e[++c].v = v;
e[c].nxt = adj[u];
adj[u] = c;
}
inline void GET(int &n) {
char c;
n = 0;
do c = getchar();
while ('0' > c || c > '9'... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int lmt = 5e5 + 100;
long long a[lmt], pre[lmt], suff[lmt], mx[4 * lmt], lazy[4 * lmt];
void build(int at, int L, int R) {
if (L == R) {
mx[at] = pre[L];
return;
}
int mid = (L + R) / 2;
build(at * 2, L, mid);
build(at * 2 + 1, mid + 1, R);
mx[at] ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int trs_mar2[35][17][17];
int trs_mar[35][17][17];
int m = 14;
void prepare() {
trs_mar[0][1][2] = trs_mar[0][1][3] = trs_mar[0][1][4] = trs_mar[0][1][5] = 1;
trs_mar[0][2][6] = trs_mar[0][2][7] = 1;
trs_mar[0][3][8] = trs_mar[0][3][9] = 1;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
bool dd[100009][2];
string s[2];
queue<tuple<int, int, int>> q;
void xl() {
cin >> n >> k;
cin >> s[0] >> s[1];
s[0] = '#' + s[0];
s[1] = '#' + s[1];
q.push({1, 0, 0});
dd[1][0] = 1;
while (q.size()) {
auto p = q.front();
q.pop();
int x, ... | 2 |
#include <bits/stdc++.h>
int main() {
int n, i;
scanf("%d", &n);
if (n & 1) {
for (i = 0; i < n - 1; i++) printf("%d ", i);
printf("%d\n", i);
for (i = 0; i < n - 1; i++) printf("%d ", i + 1);
printf("0\n");
for (i = 0; i < n - 1; i++) printf("%d ", (i + i + 1) % n);
printf("%d\n", (i + i ... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
#ifdef WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se... | 0 |
#include <bits/stdc++.h>
using namespace std;
int prime[1000000], ans[1000000] = {0}, sum[1000000] = {0};
bool not_prime[10000001] = {0};
inline int lowbit(const int& x) { return x & -x; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int prime_num = 0;
for (int i = 2; i ... | 3 |
#include<iostream>
using namespace std;
int main (void)
{
string s;
cin>>s;
if(s[2]==s[3]&&s[4]==s[5]){cout<<"Yes";}
else{cout<<"No";}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
struct segtree {
vector<vector<int>> t;
vector<int> d;
int h, n, sz;
inline void build_node(const int& x) {
for (int j = 0; j < 26; ++j) {
t[x][j] = t[x << 1][j] + t[x << 1 | 1][j];
}
}
inline void build(int x) {
for (x /= 2; x > 0; x /= 2) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
long s, v1, v2, t1, t2;
cin >> s >> v1 >> v2 >> t1 >> t2;
long ans1 = s * v1 + 2 * t1;
long ans2 = s * v2 + 2 * t2;
if (ans1 > ans2) {
cout << "Second" << endl;
} else if (ans2 > ans1) {
cout << "First" << endl;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, a = 0, b = 0, c = 0, d = 0;
cin >> n;
while (n--) {
int s;
cin >> s;
if (s == 1) a++;
if (s == 2) b++;
if (s == 3) c++;
if (s == 4) d++;
}
int ans = (d + c + (b * 2 + max... | 2 |
// mp.second を li に
#include<iostream>
#include<map>
using namespace std;
#define nC2(n) ((n)*((n)-1)/2)
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
typedef long int li;
int main(){
int n,m; cin >>n >>m;
li s=0;
li ans=0;
map<int,li> mp; mp[0]=1;
rep(i,n){
int a; cin >>a;
(s+=a)%=m;
mp[s... | 0 |
#include <bits/stdc++.h>
void quicksort(int number[200000], int first, int last) {
int i, j, pivot, temp;
if (first < last) {
pivot = first;
i = first;
j = last;
while (i < j) {
while (number[i] <= number[pivot] && i < last) i++;
while (number[j] > number[pivot]) j--;
if (i < j) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
long long ans[N][2];
long long fa1[N], fa2[N], s1[N], s2[N];
long long find(long long fa[], long long x) {
return x == fa[x] ? x : fa[x] = find(fa, fa[x]);
}
void merge(long long fa[], long long x, long long y) {
long long fx = find(fa, x);... | 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:33554432")
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7;
int n, k;
long long fact[1 << 17], inv[1 << 17];
long long a[1 << 17];
long long dp[1 << 11][1 << 11];
map<int, int> M;
long long Pow(long long x, int a) {
if (a == 0) return 1;
if (a == ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = (int)998244353;
long double sqr(long double a) { return a * a; }
void c(long long x, long long y) { cout << x << " " << y << "\n"; }
int main() {
long long x = 1, y = 1, cnt;
cin >> cnt;
c(x, y);
--cnt;
x++;
while (cnt) {
c(x, y);
c... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, item, helper = 1;
cin >> n;
vector<int> myVec;
for (int i = 2001; i < 2001 + n; i++) {
cin >> item;
if (item == helper) {
myVec.push_back(i);
helper++;
}
}
cout << myVec.size() << endl;
for (int item : myVec) cout <<... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long spf[9];
long long fac[9];
void sieve() {
spf[1] = 1;
for (long long i = 2; i < 9; i++) spf[i] = i;
for (long long i = 4; i < 9; i += 2) spf[i] = 2;
for (long long i = 3; i * i < 9; i++) {
if (spf[i] == i) {
for (long long j = i * i; j < 9; j += i... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void pv(T a, T b) {
for (T i = a; i != b; ++i) cout << *i << " ";
cout << endl;
}
template <class T>
void chmin(T &t, T f) {
if (t > f) t = f;
}
template <class T>
void chmax(T &t, T f) {
if (t < f) t = f;
}
int in() {
int x;
scanf("%d", &x);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u,
v, w, x, y, z;
cin >> t;
while (t--) {
cin >> n >> x;
cout << x * 2 << "\n";
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int g[5][5];
for (int i = int(0); i <= int(4); i++) {
for (int j = int(0); j <= int(4); j++) {
cin >> g[i][j];
}
}
long long happiness = -9999;
vector<int> a = {0, 1, 2, 3, 4};
do {
long long curr =
(g[a[0]][a[1]] + g[a[1]]... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238L;
double gcd(double x, double y) {
while (fabs(x) > 1e-4 && fabs(y) > 1e-4) {
if (x > y)
x -= floor(x / y) * y;
else
y -= floor(y / x) * x;
}
return x + y;
}
double area(double a, double b, double c) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int tree[700000] = {0};
int arr[300010] = {0};
int n;
set<int> s;
void update(int node, int start, int end, int l, int r, int win) {
if (start > r || end < l) {
return;
} else if (l <= start && end <= r) {
auto it = s.lower_bound(start);
while (it != s.end()... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, deg[1000005];
int main() {
scanf("%d", &n);
scanf("%d", &m);
for (int i = 0; i < m; i++) {
int u, v;
scanf("%d", &u);
scanf("%d", &v);
u--;
v--;
deg[u]++;
deg[v]++;
}
long long tot = 0;
for (int i = 0; i < n; i++) {
long... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[111][111], n, m;
int rr[111], cc[111];
int main(int argc, const char* argv[]) {
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
bool fl = true;
for (; fl == true;) {
fl = false;
for (int i = 0; i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, k, cnt = 0;
long long a[4000000], b[4000000];
int nx[4000000], pr[4000000];
struct Cmp {
bool operator()(const int &lhs, const int &rhs) const {
if (b[lhs] != b[rhs]) return b[lhs] < b[rhs];
return lhs < rhs;
}
};
set<int, Cmp> se;
priority_queue<long lon... | 6 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
string a,b;
cin>>a>>b;
int c=0,i;
a=a+b;
for(int i=0;i<a.size();i++) c=c*10+a[i]-48;
if(int(sqrt(c))==sqrt(c)) cout<<"Yes\n";
else cout<<" No\n";
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y;
cin >> n >> x >> y;
int a[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
int flag = 1;
for (int j = i - 1; j >= 1 && j >= i - x; j--) {
if (a[i] > a[j]) {
flag = 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int N, M, x, foo;
int a[10005];
int res = 2;
multiset<int> pos;
int cntZero = 0;
set<pair<int, int> > used;
int main() {
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d", a + i);
if (a[i] == 0) cntZero++;
}
for (int i = 0; i < N; i++) {
pos.inse... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long ic[4] = {0, 2, 3, 1};
long long getb(long long a) {
if (a == 1LL) {
return 2LL;
}
return ic[a & 3] | (getb(a >> 2) << 2);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tt;
cin >> tt;
while (tt--) {
lo... | 5 |
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=400;
const int mod=1e9+7;
int n,c;
int a[maxn+5],b[maxn+5],sum[maxn+5][maxn+5];
struct mat
{
int a[maxn+5];
mat(){memset(a,0,sizeof(a));}
}s[maxn+5],ans;
mat mul(mat a,mat b)
{
mat res;
for(int i=0;i<=c;i++)
{
for(int j=0;j<=c;j++)... | 0 |
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
typedef long long i64;
int main()
{
const int MAX = 1e5;
vector<vector<int>> g(2 * MAX);
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
x -= 1;
y -= 1;
g[x].push_back(MAX + y);
g[MAX + y]... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long dp[55][55][55][110];
long long C[110][110];
int n, h, k;
long long ans;
long long tmp;
int x, y;
void pre_C() {
memset(C, 0, sizeof(C));
for (int i = 0; i <= 100; i++) C[i][0] = 1;
for (int i = 1; i <= 100; i++)
for (int j = 1; j <= i; j++) {
C[i][... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T SQR(T a) {
return a * a;
}
template <class T>
inline T gcd(T a, T b) {
a = abs(a);
b = abs(b);
if (!b) return a;
return gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
a = abs(a);
b = abs(b);
return (a / _gcd(a, b)) *... | 4 |
#include<bits/stdc++.h>
using namespace std;
double n,m,x,y;
int main()
{
cin>>n>>m>>x>>y;
if(x==n/2&&y==m/2) printf("%.12f 1",n*m/2.0);
else printf("%.12f 0",n*m/2.0);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
bool check(double nu, double nd, double nl, double nr, double mu, double md,
double ml, double mr, double mx, double my) {
if ((mx >= nl && mx <= nr && md >= nd && md <= nu) ||
(mx >= nl && mx <= nr && mu >= nd && mu <= nu) ||
(ml >= nl && ml <= nr ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int dx[] = {1, -1, 0, 0};
long long int dy[] = {0, 0, -1, 1};
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long int power_mod(long long int a, long long int n) {
long long int res = 1;
while (n > ... | 2 |
#include <bits/stdc++.h>
void swap(int *a, int *b) {
int tmp = *a;
*a = *b, *b = tmp;
}
struct edge_t {
struct edge_t *next;
int v;
};
struct edge_t *e[300005], ep[300005 * 4], *ep_top = ep;
int eu[300005], ev[300005];
void add_edge(int u, int v) {
ep_top->v = v;
ep_top->next = e[u];
e[u] = ep_top++;
ep... | 6 |
#include <cstdio>
#include <cstring>
#include <queue>
#define MAXN 510
using namespace std;
int n,m;
queue<int> a[MAXN];
int cnt[MAXN];
bool removed[MAXN];
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
int t;
scanf("%d",&t);
a[i].push(t);
}
}
for(int i=1;i<=n;i++) cnt... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool isVowel(char c) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') {
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s;
getline(cin, s);
for (int i = s.length() - 2; i >= 0; i--) {... | 1 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")
using namespace std;
const int INF = 0x3f3f3f3f;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<int> p(n, 0);
for (long long i = 0; i < n; ++i) {
cin >... | 4 |
//
// main.cpp
// Problem Solving
//
// Created by Murad Al Wajed on 11/2/21.
//
#include<cstdio>
#include<iostream>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<bitset>
#include<list>
#include<iomanip>
#include<string>
#include<climits>
#include<sstream>
#include<fstream>
#include<cctype... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 222222;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
template <typename T>
T gcd(T a, T b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
class Rational {
public:
using TBase = long long;
static... | 5 |
#include <bits/stdc++.h>
int last[1000100], next[10000100];
long long val[10000100];
int cnt[10000100];
int c[2010];
int prime[2010], top, pp;
inline void add(long long &s, int &ss) {
val[++top] = s;
cnt[top] = ss;
next[top] = last[s % 1000007];
last[s % 1000007] = top;
}
inline int find(long long &x) {
for (... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
long long left_weight = 0;
long long right_weight = 0;
long long l_torque = 0;
long long r_torque = 0;
int lever;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '^') {
lever = i;
}
}
int j;
for (int i ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6e5 + 51;
int n, r, pos, c;
long double res;
int x[MAXN];
inline int read() {
register int num = 0, neg = 1;
register char ch = getchar();
while (!isdigit(ch) && ch != '-') {
ch = getchar();
}
if (ch == '-') {
neg = -1;
ch = getchar();... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
char s[maxn], ss[maxn];
int mp[maxn][27], la[27], len;
bool check(int mid) {
int sum = 0;
for (int i = 0; i < 26; i++)
if (mp[mid][i] >= la[i]) sum++;
if (sum == 26) return 1;
return 0;
}
int main() {
ios::sync_with_stdio(false);
c... | 2 |
#include <bits/stdc++.h>
using namespace std;
typedef complex<double> P;
string l(string s){
if( s[0] <= 'Z' ) s[0] = s[0] - 'Z' + 'z';
return s;
}
int main(){
map<string,int> d;
string s;
int mx = 0;
string v = "";
while( cin >> s ){
mx = max(mx,++d[l(s)]);
if( v.size() < s.size() )
v = l(s);
}
for... | 0 |
#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>
using namespace std;
long long GCD(long long a, long long b) { return (a) ? GCD(b % a, a) : b; }
long long LCM(long long a, long long b) { return a * b / GCD(a, b); }
long long fastpow(long long b, long long p) {
if (!p) return 1;
long long ret = fastpow(b, p >> 1);
ret *= ret;
if (p & ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[2005];
int dp1[2005][2005];
int dp2[2005][2005];
int temp[2005];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
int len = 0;
memset(temp, 0, sizeof(temp));
for (int j = i; j <= n; ... | 3 |
#include<iostream>
#include<stack>
using namespace std;
//union_find begin
#define MAX 5000000
struct node{ int parent,size; };
node tree[MAX];
void init(){
for(int i=0;i<MAX;i++){
tree[i].parent=i;
tree[i].size=1;
}
}
/*
int find(int x){
if(tree[x].parent==x)return x;
tree[x].parent = find( tree... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int head[100005];
vector<long long int> track;
int n, mm;
inline bool check(long long int m) {
int x = 0;
for (int i = 0; i < n; i++) {
long long int tem = m;
if (track[x] <= head[i] && head[i] - track[x] <= tem) {
long long int piche = head[i] -... | 3 |
#include <bits/stdc++.h>
using namespace std;
multimap<int, int> chk;
int N, M, T, R, A[20002];
int main() {
scanf("%d %d %d", &N, &M, &T);
bool good = 0;
for (int i = 0; i < N; i++) {
int h, m, s;
scanf("%d:%d:%d", &h, &m, &s);
int p = h * 3600 + m * 60 + s;
while (!chk.empty() && chk.begin()->fi... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
const int MOD = 1000000000 + 7;
const int INF = 1000000000 + 10;
long long n, m, ret, p;
long long mu[N], notP[N];
long long calc(long long lim) {
long long ret = 0;
for (long long d = 1; d <= n; ++d) {
for (long long x = d; x <= n; x += d... | 5 |
#include <bits/stdc++.h>
using namespace std;
int t, n, a[10000];
int main() {
int t = 1;
cin >> t;
while (t--) {
cin >> n;
int ans = 1000000;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++) ans = min(ans, abs(a[i] - a[j]));
cout <<... | 2 |
#include <bits/stdc++.h>
using namespace std;
const bool DEBUG = true;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
const double PI = acos(-1);
const double EPS = 1e-9;
int main() {
ios::sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
int n, x;
cin ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, x, y, z;
int init;
long long int dp[3][105], arr[300005], period;
long long int getGrundy(int p, int s) {
if (s == 0) return dp[p][s] = 0;
if (dp[p][s] != -1) return dp[p][s];
set<long long int> st;
st.insert(-1);
if (p == 0) {
st.insert(getGrundy(0, ma... | 6 |
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZER... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const long long INF = numeric_limits<long long>::max() / 3;
template <class T>
void mini(T &a, T b) {
a = min(a, b);
}
template <class T>
void maxi(T &a, T b) {
a = max(a, b);
}
long long mrand() { return rand() * ((long long)RAND_MAX + 1LL) + r... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1.01e9;
const int N = 1 << 18;
const int MOD = (int)1e9 + 7;
int main() {
int n;
while (scanf("%d", &n) == 1) {
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &a[i], &b[i]);
a[i]--;
b[i]--;
}
ve... | 5 |
#include <bits/stdc++.h>
using namespace std;
string s[12] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"},
a, b, c;
int x[12];
int main() {
std::ios::sync_with_stdio(false);
cin >> a >> b >> c;
for (int i = 0; i < 12; i++) {
if (a == s[i] || b == s[i] || c == s[i]) x[i] = 1;
}
f... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool checkMin(T& a, T b) {
return (a > b ? a = b, 1 : 0);
}
template <class T>
inline bool checkMax(T& a, T b) {
return (a < b ? a = b, 1 : 0);
}
const int N = 5005;
vector<int> e[N];
int n, m;
void init() { scanf("%d%d", &n, &m); }
int vis[N];... | 4 |
#include <bits/stdc++.h>
using namespace std;
int x[100100], y[100100], z[100100], w[100100], tx[100100 * 2], dis[100100],
from[100100];
struct cmp {
bool operator()(int i, int j) const { return y[i] < y[j]; }
};
multiset<int, cmp> f[100100 * 2];
int main() {
int n, m;
scanf("%d", &n);
for (int i = 1; i <= ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N=3e5+5;
int a[N],b[N];
int n,k;
int ans=1;
void solve(int v)
{
long long s = 0;
for(int i=0;i<n;i++){
b[i]=a[i]%v;
s += b[i];
}
sort(b,b+n);
long long now = 0;
for(int i=n-1; i>=0; i--){
if(s>now){
now... | 0 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int tc;
cin >> tc;
while (tc--) {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
vector<array<int, 2>> dp(n + 1, {((int)(1e9 + 5)), ((int)(1e9 + 5))})... | 3 |
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> Vec;
int n;
int Ans;
static const int INF = 1e+9;
void DFS(int a, int b, int depth)
{
if(depth == n)
{
Ans = min(Ans, abs(a - b));
}
else
{
DFS(a + Vec[depth], b, depth + 1);
DFS(a, b + Vec[depth],... | 0 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <array>
typedef long long ll;
typedef long double ld;
using namespace std;
const ll mod = 998244... | 6 |
#include<bits/stdc++.h>
using namespace std;
int n,m,cc,vis[705],col[705],num[705][2],f[2][705],e[705][705];
void dfs(int x,int c)
{
num[cc][c]++;col[x]=c;vis[x]=1;
for(int i=1;i<=n;i++)if(x!=i&&!vis[i]&&!e[x][i])dfs(i,c^1);else if(x!=i&&!e[x][i]&&col[i]==c){puts("-1");exit(0);}
}
int main()
{
scanf("%d%d",&n,&m);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n, i, c = 0, s, have, j;
cin >> n;
vector<long long> v(n), vv;
for (i = 0; i < n; i++) {
cin >> v[i];
c += v[i];
}
if (c <= 1) {
cout << "-1" << endl;
return ... | 5 |
#include <bits/stdc++.h>
int main() {
long long n, num;
long long i, j;
while (scanf("%I64d", &n) != EOF) {
num = 0;
for (i = 0;; i++) {
long long x = (2 * (i + 1) * (i + 2)) / 2 + (i * (i + 1)) / 2, y;
if (n >= x)
y = n - x;
else
break;
if (y % 3 == 0) num++;
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
double ans[3010][3010], x, c;
int f[3010], g[3010];
int main() {
int i, j, rr, cc, m, n, a, b;
scanf("%d %d", &n, &m);
for (i = 1; i <= m; i++) {
scanf("%d %d", &a, &b);
f[a] = 1;
g[b] = 1;
}
rr = 0;
cc = 0;
for (i = 1; i <= n; i++)
if (f[i] ==... | 2 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
void open() {
((void)0);
((void)0);
((void)0);
}
const int MAX = 1e5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1);
const long double ERR = 1e-10;
const i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int a, d;
scanf("%d%d%d", &n, &a, &d);
int t[n], v[n];
for (int i = 0; i < n; i++) {
scanf("%d%d", &t[i], &v[i]);
}
double at[n];
if ((long long)v[0] * v[0] < (long long)d * 2.0 * a) {
at[0] = 0.5 * v[0] / a + d * 1.0 / v[0] + t[0... | 1 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC push_options
#pragma GCC optimize("unroll-loops")
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n, x;
cin >> n >> x;
long long a[n + 1];
long long count = 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int fibo[1001], N = 1001;
fibo[0] = 1;
fibo[1] = 2;
for(int i=2;i<N;i++){
fibo[i] = (fibo[i-1] + fibo[i-2]) % N;
}
int v, d;
while(cin >> v >> d){
vector<int> ls;
for(int i=1;i<=v;i++) ls.push_back(fibo[i]);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1E6 + 6;
int n, m, x, y, w, s1, s2, s3, f[N], g[4][N], ans;
bool o[N], O[N];
queue<int> q;
char s[1005][1005];
vector<int> G[N];
void add(int x, int y) {
if (!x || !y) return;
G[x].push_back(y);
if (y > n * m) G[y].push_back(x);
}
int get(int x, int y) {... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t = 1;
while (t--) {
int n, k, sol = 0;
cin >> n >> k;
bool flag = 1;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
for (int i = k - 1; i < n - 1; i++) {
if (v[i] != v[i + 1]) {
flag = 0;
break;... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.