solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
long long min(long long x, long long y) {
if (x < y) return x;
return y;
}
long long fun(long long n, long long m, long long k) {
if (k <= 0) return n * m;
long long max = (n > m) ? n : m;
long long res1 = 0, res2 = 0;
if (n % (k + 1) == 0) res1 = m * (n / (k + 1));
if (m % (k + 1... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, low = 1, high;
bool x = false;
cin >> n;
high = n;
while (high >= low) {
if (x)
cout << high-- << ' ';
else
cout << low++ << ' ';
x = !x;
}
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
cout << n * 6 * (n - 1) + 1;
return 0;
}
| 2 |
#include <bits/stdc++.h>
const double eps = 0.0;
template <typename T>
inline int cmpT(T x) {
return x < 0 ? -1 : x > 0;
}
template <>
inline int cmpT(double x) {
return x < -eps ? -1 : x > eps;
}
template <typename T>
struct VecT {
T x = 0;
T y = 0;
static_assert(std::is_arithmetic<T>::value, "Should be an a... | 6 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;cin>>t;
while(t--){
int n;cin>>n;
long long sum = 0;
vector<int> vec(n);
for(int i = 0;i < n;i++){
cin>>vec[i];
}
bool flag = false;
long long needed = 0;
for(long long i = 0;i < n;i++){
sum += vec[i];
needed += i;
if(sum < ne... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long dp[52][2600];
int main() {
int n, a;
cin >> n >> a;
dp[0][0] = 1;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
for (int j = i; j >= 0; --j) {
for (int k = 2550; k >= x; --k) {
dp[j + 1][k] += d... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> roda(int f, vector<int> valores) {
vector<int> temp(valores);
if (f == 0) {
temp[17] = valores[5];
temp[18] = valores[6];
temp[21] = valores[17];
temp[22] = valores[18];
temp[13] = valores[21];
temp[14] = valores[22];
temp[5] = va... | 3 |
#include<bits/stdc++.h>
using namespace std;
const int N=120;
typedef long long ll;
int dp[2][N][N],f[N][N],n,m,K,pw[N][N],C[N][N],mod,T;
int main(){
cin>>n>>m>>K>>mod;
for(int i=0;i<N;++i){
pw[i][0]=1;C[i][0]=1;
for(int j=1;j<N;++j)pw[i][j]=(ll)pw[i][j-1]*i%mod;
for(int j=1;j<=i;++j)C[i][j]=(C[i-1][j-1]+C[i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000050;
int abs(int x) { return (x > 0) ? x : -x; }
int main() {
int a1, a2, a3, a4;
cin >> a1 >> a2 >> a3 >> a4;
bool ok = true;
ok &= (a3 <= a1 && a3 <= a2);
ok &= (a4 <= a1 && a4 <= a2);
ok &= (abs(a3 - a4) <= 1);
ok &= ((a3 != a4) or ((... | 4 |
#include <bits/stdc++.h>
using namespace std;
map<int, long long> mp;
int main() {
long long k;
string str;
cin >> k >> str;
long long len = str.length();
vector<int> pre(len + 1, 0);
mp[0] = 1;
for (long long i = 1; i <= len; i++) {
pre[i] = pre[i - 1] + (str[i - 1] == '1');
mp[pre[i]]++;
}
l... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline long long in() {
long long x = 0;
int n = 1;
char c = getchar();
while (!isdigit(c)) {
n = (c == '-') ? -1 : 1;
c = getchar();
}
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
return x * n;
}
const int N = 3000006;
long lo... | 2 |
#include<bits/stdc++.h>
const int maxn = 7920;
typedef long long ll;
typedef std::vector<ll> vec;
std::set<ll> a0,a1;
vec x0,x1;
int ok[maxn],n;
inline void init(std::set<ll>&s,vec&y){
y.push_back(*s.begin()); s.erase(s.begin());
const ll lim = 3e7;
for(;s.size();){
auto it = s.upper_bound(lim / *y.rbegin()); --it... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int l = 8 * n + 1;
double m = sqrt(l);
int k = sqrt(l);
if (m == k)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 5e5 + 200;
const long long inf = 0x3f3f3f3f;
const double eps = 1e-7;
const double pi = acos(-1.0);
const long long mod = 1e9 + 7;
inline long long lowbit(long long x) { return x & (-x); }
long long gcd(long long a, long long b) { return b ? gcd(b, a ... | 4 |
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
... | 0 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long, long long> > q;
string str;
long long tmp = 0, ans = 0, x, y;
int main() {
cin >> str;
for (int i = 0; i < str.size(); i++) {
if (str[i] == '(') {
tmp++;
} else if (str[i] == ')') {
tmp--;
} else {
cin >> x >>... | 4 |
#include<bits/stdc++.h>
using namespace std;
int n;
int a,cnt=0;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a);
if(a%2==1){
++cnt;
}
}
if(cnt%2==1){
printf("NO");
}else printf("YES");
} | 0 |
#include <iostream>
using namespace std;
int main() {
string s;
long k;
cin >> s >> k;
string s_new = s;
for(int i = 0; i < s.size(); i++) {
int d = 'z' - s[i] + 1;
if(k >= d && s[i] != 'a') {
k -= d;
s_new[i] = 'a';
}
}
s_new[s_new.size() - 1] = 'a' + (s_new[s_new.size() - 1] + k... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 303;
long long T;
int n, tot, num, p[25];
struct Node {
int x1, y1, x2, y2;
} ans[N];
inline void add(int n, int x) {
if (x == 0) {
ans[num++] = (Node){n + 1, n - 1, n + 1, n};
ans[num++] = (Node){n + 2, n - 1, n + 2, n};
ans[num++] = (Node){n ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 2;
double eps = 1e-7;
double n, a, d;
double t[N];
double v[N], res[N];
int main() {
ios::sync_with_stdio(false);
cin >> n >> a >> d;
res[0] = 0;
for (int i = 1; i <= n; ++i) {
cin >> res[i] >> v[i];
if (v[i] / (a * 2) * v[i] > d - eps... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793238460;
const long long mod = 1e9 + 7;
const long long INF = (long long)1e18;
void FAST() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
void solve() {
long long n, b, p;
cin >> n >> b >> p;
long long x = 0, y = p * n;
wh... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
int sum0[maxn], sum1[maxn];
int a[maxn], b[maxn];
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
if (b[i])
sum0[i] = sum0[i - 1] + a[i];
... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string a,b,c;
cin>>a>>b>>c;
cout<<a[0]<<b[1]<<c[2]<<endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long int n;
cin >> n;
long long int arr[n];
for (long long int i = 0; i < n; i++) cin >> arr[i];
map<long long int, long long int> mp;
long long int res = n ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int b, w;
int main() {
int q;
scanf("%d", &q);
while (q--) {
scanf("%d%d", &b, &w);
int aa = min(b, w);
int bb = max(b, w);
if (bb > aa * 3 + 1) {
printf("NO\n");
} else {
if (b == w) {
printf("YES\n");
for (int i = 1; i... | 5 |
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
double x1,y1,x2,y2,x3,y3; cin>>x1>>y1>>x2>>y2>>x3>>y3;
double a=hypot(abs(x1-x2),abs(y1-y2));
double b=hypot(abs(x2-x3),abs(y2-y3));
double c=hypot(abs(x3-x1),abs(y3-y1));
double s=(a+b+c)/2;
double S=sqrt(s*(s... | 0 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
for (int l = 0; l < t; ++l) {
int n;
cin >> n;
int mn = 1000;
int a[n];
for (int i = 0; i < n; ++i) cin >> a[i];
sort(a, a + n);
for (int i = 1; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, maxElement = 0;
cin >> n;
int *input = new int[n];
for (int i = 0; i < n; i++) {
cin >> input[i];
maxElement = max(maxElement, input[i]);
}
stack<int> st;
for (int i = 0; ... | 4 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int MOD=1e9+7;
ll INF=1e18;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int main(){
while(1){
int n; cin>>n;
if(n==0) return 0;
int a[110][110], hands[110][110... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
long long tree[N];
set<pair<int, int> > point, rev_point;
int mxb[N], mxc[N];
int a[N], b[N], c[N];
int n, p, q, r;
multiset<int> y, z;
int idx[N];
void update(int idx, long long val) {
while (idx <= q) {
tree[idx] += val;
idx += idx & (-id... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
#define ERR 0.00000001
typedef long long ll;
double gaiseki(double x1, double y1, double x2, double y2)
{
return x1*y2 - x2*y1;
}
double naiseki(double... | 0 |
#include<bits/stdc++.h>
#define For(aa,bb,cc) for(int aa=(bb);aa<=(int)(cc);++aa)
using namespace std;
const int maxn=100;
int n;
int a[maxn];
map<string,int>G;
int main(){
scanf("%d",&n);
string s;int ans=0;
For(i,1,n){
cin>>s;scanf("%d",&a[i]);
G[s]=i;
}
cin>>s;
For(i,G[s]+1,n) ans+=a[i];
printf("%d\n",an... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
inline bool checkBit(long long n, int i) { return n & (1LL << i); }
inline long long setBit(long long n, int i) {
return n | (1LL << i);
;
}
inl... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int a[2 * n];
for (int i1 = 0; i1 < 2 * n; i1++) {
a[i1] = i1 + 1;
}
int i = 0;
for (int i1 = 0; i1 < k; i1++) {
swap(a[i], a[i + 1]);
i += 2;
}
for (int i1 = 0; i1 < 2 * n; i1++) {
cout << a[i1] << " "... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
long long l, n, p, t;
pair<long long, long long> fl[maxn], fr[maxn];
long long L[maxn], R[maxn];
void relax(pair<long long, long long> &x, pair<long long, long long> y) {
if (x.first <= y.first) {
if (x.first < y.first) {
x = y;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, l;
cin >> h >> l;
double ans = (double)(pow(l, 2) - pow(h, 2)) / (double)(2.0 * h);
cout << std::setprecision(13) << ans << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
template <typename T, typename U>
std::istream& operator>>(std::istream& i, pair<T, U>& p) {
i >> p.first >> p.second;
return i;
}
template <typename T>
std::istream& operator>>(std::istream& i, vector<T>& t) {
for (auto& v : t) {
i >> v;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q, n, arr[10000], i, j, team = 1;
cin >> q;
for (i = 0; i < q; i++) {
cin >> n;
for (j = 0; j < n; j++) {
cin >> arr[j];
}
sort(arr, arr + n);
for (j = 0; j < n - 1; j++) {
if (arr[j + 1] == arr[j] + 1) {
team++... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> graph[100001];
long long visit[1001];
long long dest;
int main() {
long long t, n, k, m, a;
cin >> t;
while (t--) {
cin >> n;
map<long long, long long> mp;
long long index = -1, chk;
mp[0] = -1;
for (long long i = 1; i <= n; i++) ... | 2 |
#include <bits/stdc++.h>
#define use(x) using std::x
#define cmax(a, b) (a < b ? a = b : a)
#define lop(i, s, t) for (int i = s;i < (t);++i)
#define dec(i, s, t) for (int i = s;i >= (t);--i)
#define rep(i, s, t) for (int i = s;i <= (t);++i)
#define mem(x, k) memset(x, k, sizeof(x))
use(fill); use(sort); use(max); use(s... | 0 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long n;
cin >> n;
vector<long long> v;
for (long long i = 2; i <= sqrt(n); ++i) {
if (!(n % i)) {
v.push_back(i);
while (!(n % i)) {
n /= i;
}
}
}
if (n != 1) v.push_back(n);
if (v.size() == 1)
cout <<... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
vector<int> adj[MAX];
int degree[MAX], level[MAX], removed[MAX];
int n;
void dfs(int node, int father) {
for (auto &each : adj[node]) {
if (each != father) {
level[each] = level[node] + 1;
dfs(each, node);
}
}
}
int main() {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long power(int a, int b) {
long long ans = 1;
while (b--) {
ans = ans * a % 998244353;
}
return ans;
}
int main() {
int n;
cin >> n;
long long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long ans = 0;
int p = 0;
for (int i = ... | 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
const int N = 500010;
using namespace std;
int n, m;
int x, y, x1, asdf_1;
int vx, vy, vx1, vy1;
int v;
int t;
pair<int, int> mas[N];
inline double dist(double x, double y) {
return sqrt(((x - x1) * (x - x1)) + ((y - asdf_1) * (y - asdf_1)));
}
int f... | 2 |
#include <bits/stdc++.h>
using namespace std;
int par[100001], sz[100001];
int p(int u) {
if (par[u] == u) return u;
par[u] = p(par[u]);
return par[u];
}
void un(int u, int v) {
int pu = p(u), pv = p(v);
if (pu != pv) {
par[pu] = pv;
sz[pv] += sz[pu];
}
}
int main() {
ios_base::sync_with_stdio(fal... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
if (n % 3)
cout << n / 3 * 2 + 1;
else
cout << n / 3 * 2;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int read_int() {
int res = 0, neg = 0;
char c = getchar();
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') neg = 1, c = getchar();
while (c >= '0' && c <= '9') {
res = (res << 1) + (res << 3) + c - 48;
c = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 109;
const int INF = 1e9;
char zbs[5] = {'R', 'G', 'B', 'Y', 'W'};
pair<int, int> a[N];
int main() {
int n, ans = 11;
cin >> n;
for (int i = 0; i < int(n); ++i) {
char t1, t2;
cin >> t1 >> t2;
a[i].second = int(t2 - '1');
for (int j = 0; ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int sif(char c) { return c - '0'; }
char s[200005];
int c[200005];
bool zauz[200005];
int main() {
int i, n, br = 0;
scanf("%s", s);
n = strlen(s);
for (i = 0; i < n; i++) {
c[i] = sif(s[i]) % 3;
}
for (i = 0; i < n; i++) {
switch (c[i]) {
case 0: ... | 4 |
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 100003;
const LL C = 2e17;
template<typename T>
inline void read(T &x){
int ch = getchar(); x = 0; bool f = false;
for(;ch < '0' || ch > '9';ch = getchar()) f |= ch == '-';
for(;ch >= '0' && ch <= '9';... | 0 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> mm;
char s[200];
int an, n, ma, ans, m, mx, k, i, j, kk, sw, a[500001], ne[500001][17],
f[40000][227], fir[20];
int main() {
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%s", s), mm[s] = i;
scanf("%d", &m);
ma = n * (n - 1) / 2 + 1;
int mx ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long POW(long long a, long long b, long long MMM = MOD) {
long long ret = 1;
for (; b; b >>= 1, a = (a * a) % MMM)
if (b & 1) ret = (ret * a) % MMM;
return ret;
}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, ... | 3 |
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
int main(){
int N;
cin >> N;
vector<int> V(N);
rep(i,0,N)cin >> V[i];
vector<int> A(N),B(N);
rep(i,0,N)A[i] = B[N-i-1] = (i+1) * 30000;... | 0 |
// nauynix
// 03/04/2021
#include <bits/stdc++.h>
using namespace std;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
typedef pair... | 4 |
#include <bits/stdc++.h>
using namespace std;
int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
int main(void) {
int i = 0;
int cnt = 0;
int now = 1;
while (i <= 24) {
printf("%d\n", prime[i]);
fflush(stdout);
char resp... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e3 + 13;
int n;
long double k, ans, dp[maxN][maxN], p[maxN], pre[20];
int main() {
cin >> n;
pre[0] = 1;
for (int i = 1; i <= 18; i++) pre[i] = pre[i - 1] * 10;
for (int i = 1; i <= n; i++) {
long long L = 0, R = 0, l, r;
cin >> l >> r;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 23;
int n, a[N], t[N], b[N];
bool cmp(int x, int y) { return a[x] < a[y]; }
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) t[i] = i;
sort(t + 1, t + n + 1, cmp);
for (int i = 1; i <= n; ++i) b[t[i]] = a[... | 2 |
#include <bits/stdc++.h>
using namespace std;
int ns, nt;
string s, t;
int ScntB[100010], ScntA[100010];
int TcntB[100010], TcntA[100010];
int q;
int sol(int ls, int rs, int lt, int rt) {
int dbS, dbT, daS, daT;
dbS = ScntB[rs] - ScntB[ls - 1];
dbT = TcntB[rt] - TcntB[lt - 1];
daS = min(rs - ls + 1, ScntA[rs]);... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool d;
int n;
char c[10][10];
int main() {
for (int i = 1; i <= 4; i++)
for (int j = 1; j <= 4; j++) cin >> c[i][j];
for (int i = 1; i <= 4; i++)
for (int j = 1; j <= 4; j++) {
if (c[i][j] == '.' and c[i][j - 1] == 'x' and c[i][j + 1] == 'x') d = 1;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
char a[101][101];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
int min_i = n, min_j = m, max_i = -1, max_j = -1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++... | 1 |
#include <bits/stdc++.h>
using namespace std;
int ans[10001][2];
int main() {
int x, y, a, b, n = 0;
cin >> x >> y >> a >> b;
for (int i = a; i <= x; i++)
for (int j = b; j < i && j <= y; j++) {
ans[n][0] = i;
ans[n][1] = j;
n++;
}
cout << n << endl;
for (int i = 0; i < n; i++) cout ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct Node {
int l, r, mi;
set<int> s;
} a[N << 2];
int t[N];
struct Query {
int l, r, id;
} q[N * 3];
inline bool cmp(const Query& q, const Query& w) {
if (q.l != w.l) return q.l < w.l;
if (q.r != w.r) return q.r < w.r;
return q.id < w.i... | 6 |
#include <bits/stdc++.h>
int main() {
long long n, k;
std::cin >> n >> k;
long long c = std::max(n - 2 * k, 0LL);
std::cout << n * (n - 1) / 2 - c * (c - 1) / 2 << "\n";
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
long long d[10000005];
long long ara[10000005 / 10];
void precalc() {
for (int i = 0; i <= 24; i++) {
for (int j = (1 << i); j <= min((1 << (i + 1)) - 1, 10000000); j++)
d[j] = i;
}
}
bool okay(long long mid) {
if (mid == 1) return 1;
long long t... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long d, mod;
long long s = 1, k = 1;
long long dp[100] = {0};
long long a[100] = {0};
cin >> d >> mod;
long long x = d;
while (x) {
x >>= 1;
a[k++] = min(s, d - s + 1);
... | 4 |
#include <bits/stdc++.h>
using i64 = long long;
int main() {
constexpr i64 mod = 1000000007;
int n;
std::cin >> n;
i64 ret = 1;
int ss[] { 0, 0, 0 };
for (int i = 0; i < n; i++) {
int a;
std::cin >> a;
i64 f = 0;
for (int &s : ss) if (s == a && !f++) s++;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a[9];
for (int i = 0; i < 9; i++) {
cin >> a[i];
}
a[0] = (2 * a[2] + a[5] - a[3]) / 2;
a[8] = (2 * a[6] + a[3] - a[5]) / 2;
a[4] = a[1] + a[2] - a[8];
cout << a[0] << " " << a[1] << " " << a[2] << endl;
cout << a[3] << " " << a[4]... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int fastpow(long long int base, long long int exp, long long int M) {
long long int res = 1;
while (exp > 0) {
if (exp & 1) res = (res * base) % M;
base = (base * base) % M;
exp >>= 1;
}
return res;
}
vector<long long int> par, vis, c;
vector<v... | 3 |
#include <bits/stdc++.h>
using namespace std;
const unordered_map<string, int> pt = {
{"H", 1}, {"He", 2}, {"Li", 3}, {"Be", 4}, {"B", 5},
{"C", 6}, {"N", 7}, {"O", 8}, {"F", 9}, {"Ne", 10},
{"Na", 11}, {"Mg", 12}, {"Al", 13}, {"Si", 14}, {"P", 15},
{"S", 16}, {"C... | 5 |
#include<iostream>
#include<algorithm>
using namespace std;
int a[1001],b[1001],size;
int main()
{
//freopen("ctest.txt","r",stdin);
//freopen("ctest.out","w",stdout);
int i,j,k,n,I,N;
cin>>N;
for(I=1;I<=N;I++)
{
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
size=0;
for(i=1;i<=n;i++)
{
i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string stone;
string ins;
cin >> stone >> ins;
int n = 0;
int i = 0;
while (i < ins.length() && n < stone.length()) {
if (ins[i] == stone[n]) {
n++;
}
++i;
}
cout << n + 1;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long int mx(long long int a, long long int b) {
if (a >= b) return a;
return b;
}
long long int mn(long long int a, long long int b) {
if (a < b) return a;
return b;
}
long long int mod = 1e9 + 7;
long long int pw(long long int a, long long int b, long long int... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int cnt[N];
bool push(int id, int solution) {
if (cnt[id] == solution) {
cnt[id]++;
} else if (cnt[id] < solution) {
return false;
}
return true;
}
int main() {
int m;
cin >> m;
for (int i = 0; i < m; i++) {
int id, solution... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, pos = 0;
string str;
cin >> n >> str;
vector<int> arr(n);
for (auto &i : arr) cin >> i;
map<int, int> m;
bool fin = false, infin = false;
while (true) {
if (str[pos] == '>' && po... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
string s[n][2];
string d;
for(int i=0;i<n;i++){
cin >> s[i][0];
cin >> s[i][1];
}
cin >> d;
int a;
for(int i=0;i<n;i++){
if(d == s[i][0]){a=i;}
}
int ans=0;
for(int i=a+1;i<n;i++){
ans += stoi(s[i][1]);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 3e5 + 5;
const long long A = 1e6 + 5;
const long double pi = acos(-1);
long long divs[A];
long long n, m, a[N];
void prepare() {
for (long long i = 1; i < A; ++i)
for (long long j = i; j < A; j += i) ++divs[j];
}
stru... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r1, c1, r2, c2, rook, bish = 0, king;
cin >> r1 >> c1 >> r2 >> c2;
if (r1 == r2 || c1 == c2)
rook = 1;
else
rook = 2;
if ((r1 + c1) % 2 != (r2 + c2) % 2)
bish = 0;
else {
if (r1 + c1 == r2 + c2 || r1 - c1 == r2 - c2)
bish =... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n), res(n);
vector<pair<int, int>> b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < n; ++i) {
cin >> b[i].first;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long sum[100005];
int a[1000005];
int n, t;
bool check(int l) {
int x = 1;
int y = x + l - 1;
while (x <= n) {
if (sum[y] - sum[x - 1] > 0 && sum[y] - sum[x - 1] <= t) {
return true;
}
if (sum[y] - sum[x - 1] < 0) return false;
++x;
y = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int prime[3010];
set<int> st[3010];
void Sieve(int n) {
for (int i = 2; i <= n; i++) {
if (prime[i] == 0) {
for (int j = 2 * i; j <= n; j += i) {
prime[j] = 1;
st[j].insert(i);
}
}
}
}
int main() {
memset(prime, 0, sizeof(prime));
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int maxn = 1e9 + 9;
int a[200005];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] != 0) a[i] = maxn;
}
for (int i = 1; i <= n; i++) {
if (a[i] == 0) {
int j = 1;
while (a[i + j] != 0) a[i + ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, a[(int)2e5 + 10];
long double WeekNess, mx = -1e18, mn = 1e18, sum;
long double Answer(long double Check) {
mx = 0, mn = 0, sum = 0, WeekNess = 0;
for (int i = 0; i < n; i++) {
mx = max(mx, sum);
mn = min(mn, sum);
sum += a[i] - Check;
WeekNess = ... | 3 |
#include <bits/stdc++.h>
struct pair {
int x, y;
pair(int x, int y) : x(x), y(y) {}
};
char field[1100][1100];
std::queue<pair> qs[10];
std::vector<int> players;
int speed[10], answer[10];
int n, m, p;
bool way;
void preparetion() {
std::ios::sync_with_stdio(0);
std::cin.tie(0);
std::cout.tie(0);
}
void init(... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N;
cin>>N;
if(N%2==1){
cout<<"0"<<endl;
}
else{
N/=2;
int64_t Z=0;
while(N>0){
N/=5;
Z+=N;
}
cout<<Z<<endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main () {
int n;
scanf ("%d",&n);
for (int x = 3,count = 0; count < n; x+=10) {
bool prime = true;
for (int y = 2; y * y <= x; y++) if (x%y==0) prime=false;
if (prime) {
count++;
printf ("%d%c",x,count==n?'\n':' ');
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
pair<int, int> c = make_pair(1, 0);
int dx = 1, cover = 0, inc = 0;
while (k != 1) {
if (inc == 0) cout << 2 << " ";
if (dx == 1 && c.second + dx <= m) {
c.second += dx;
} else if (dx == 1) {
c.... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long FastExp(long long a, long long b, long long c) {
if (b == 1) return a;
long long ans = FastExp(a, b / 2, c);
if (b % 2 == 0) return ans % c * ans % c;
if (b % 2 != 0) return ans % c * ans % c * a % c;
}
int main() {
int n;
cin >> n;
int a[n + 5];
f... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 510;
bitset<510> can[maxn][2][64];
int N, M;
long long ans, best[maxn][2];
inline long long dfs(int now, int last) {
if (best[now][last ^ 1] != -1)
return best[now][last ^ 1];
else
best[now][last ^ 1] = 0;
for (int i = 59; i >= 0; --i)
if ... | 6 |
#include <bits/stdc++.h>
using namespace std;
void fastIO() {
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
template <typename T, typename U>
inline void mnze(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
inline void mxze(T &x, U y) {
if (x < y) x = y;
}
void _scan(int &x)... | 2 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <tuple>
using namespace std;
class Solver {
};
signed main() {
while (true) {
int n;
cin >> n;
if (n == 0)break;
vector<int> hs(n + 1, 0);
for (int i = 0; i < n + 1; i++) {
cin >> hs[i];
}
for (int i = 0; i < n + 1... | 0 |
#include <bits/stdc++.h>
using namespace std;
int xx[4] = {0, 0, 1, -1};
int yy[4] = {1, -1, 0, 0};
int n, m, k, s;
int a[int(1e5)];
int getbit(int x, int i) { return (x >> i) & 1; }
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = (1), _b = (m); i <= _b; i++) {
scanf("%d", &a[i]);
}
scanf("%d", &s);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k, ans;
int c1 = 0, c2 = 0;
bool f1 = 0, f2 = 0;
int a[105];
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = m; i <= n; i++) {
if (k >= a[i] && a[i] != 0) {
f1 = 1;
break;
} else {
c1+... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int x = 0, y = 0;
int ans = 0;
for (int i = 0; i < n - 1; i++) {
if (s[i] == 'U')
y++;
else
x++;
if (x == y && s[i] == s[i + 1]) ans++;
}
cout << ans << endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string a = "au", b = "Blbsr";
int ans = s.size();
for (int i = 0; i < 2; i++)
ans = min(ans, (int)count(s.begin(), s.end(), a[i]) / 2);
for (int i = 0; i < 5; i++)
ans = min(ans, (int)count(s.begin(), s.end(), b[i]));
c... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int M = 105;
int read() {
int x = 0, f = 1;
char c;
while ((c = getchar()) < '0' || c > '9') {
if (c == '-') f = -1;
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x * f;
}
int n, ans, sum, cnt, a... | 5 |
#include <bits/stdc++.h>
const int p = 100000000;
int N, M, i, e, X, Y;
int son[705], ed[1405], next[1405], size[705];
long long tmp[40], f[705][705][40];
void Addedge(int X, int Y) { ed[++e] = Y, next[e] = son[X], son[X] = e; }
void Ok(long long a[]) {
int i;
for (i = 1; i < a[0]; ++i) {
a[i + 1] += a[i] / p;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int ans[505][505];
int init[9]{9, 7, 5, 6, 3, 8, 1, 4, 2};
int N, idx;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> N;
if (N < 3) {
cout << "-1\n";
exit(0);
}
for (int i = 1; i <= 3; i++)
for (int j = 1; j <= 3; j++) ans[i][j] = N * ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
int a[maxn], l[maxn], r[maxn], x, y, z;
long long sum[maxn], ans = -0x3f3f3f3f;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i], sum[i] = sum[i - 1] + a[i];
for (int i = 1; i <= n; i++) {
if (sum[i] > sum[l[i - 1]])
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3, M = 1000000, INF = 0x3f3f3f3f;
char cc[N][M + 1];
int main() {
int n, m;
cin >> n >> m;
if (n >= 4) {
cout << "-1\n";
return 0;
}
if (n == 1 || m == 1) {
cout << "0\n";
return 0;
}
for (int i = 0; i < n; i++) cin >> cc[i];
if... | 4 |
#include <iostream>
#include <string>
#include <map>
using namespace std;
int M,l;int main(){string s,t,u;map<string,int>m;for(;cin>>u;t=t.size()<u.size()?u:t)if(++m[u]>M)M=m[u],s=u;cout<<s<<' '<<t<<endl;} | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.