solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
struct intr {
int a;
int b;
};
int main() {
int n, P1, P2, P3, T1, T2;
vector<intr> v;
int wTime = 0;
cin >> n >> P1 >> P2 >> P3 >> T1 >> T2;
for (int i = 0; i != n; i++) {
intr tmp;
cin >> tmp.a >> tmp.b;
v.push_back(tmp);
}
wTime += (v[0].b -... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, t;
cin >> n >> t;
long double tt = 1.000000011, ans = 1.0;
while (t) {
if (t & 1) ans *= tt;
tt *= tt;
t >>= 1;
}
ans *= (long double)n;
cout << fixed << setprecision(20) << ans << '\n';
}
signed main() {
ios_base::syn... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long a, b;
long long f[100];
int nf;
void run() {
scanf("%I64d%I64d", &a, &b);
if (gcd(a, b) != 1) {
printf("Impossible\n");
return;
}
nf = 0;
while (b != 0) {
f[nf++] ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105, inf = 1e9;
int n, m, st, ed;
int G[N][N];
vector<int> g[N][N];
int s[N], t[N], K;
vector<int> bus[N];
vector<int> *vv;
int cnt[N], vis[N], TOT;
bool MOB[N][N];
bool *uu, Good[N][N], Flag[N];
bool dfs(int u) {
if (vis[u] == TOT) return uu[u];
vis[u] = ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, n;
long long x, y;
cin >> x >> y;
char s[12];
sprintf(s, "%d", y);
reverse(s, s + strlen(s));
i = 0;
y = 0;
while (s[i]) {
y *= 10;
y += s[i] - '0';
i++;
}
printf("%I64d\n", x + y);
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353, COEFF = 1e6;
inline void add(int &a, int b) {
a += b;
if (a >= mod) a -= mod;
}
inline void sub(int &a, int b) {
a -= b;
if (a < 0) a += mod;
}
inline int mul(int a, int b) { return (int)((long long)a * b % mod); }
inline int power(int a, ... | 26 |
#include <bits/stdc++.h>
using namespace std;
int dp[2500][150][150];
int n;
int pre[4005];
int maxi(int l, int diff, int length) {
if (l + length > n - l - diff) {
dp[l][diff][length] = 0;
return 0;
} else if (dp[l][diff][length] != -pow(10, 9)) {
return dp[l][diff][length];
} else if (l + 2 * length... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long int N, x, B[105][105], cnt[105], dp[100006], sol[105][105],
aux[105][105];
void mult(long long int A[105][105], long long int B[105][105],
long long int C[105][105]) {
int i, j, k;
for (i = 1; i <= 101; i++)
for (j = 1; j <= 101; j++) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long int x, i;
signed main() {
cin >> x;
if (x == 0) {
cout << 0;
return 0;
} else if (x < 0) {
x = -x;
}
i = ((-1) + sqrt((1 + 8 * x))) / 2;
for (; 1; i++) {
if ((i + 1) * i / 2 >= x && ((i + 1) * i / 2) % 2 == x % 2) {
cout << i;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, off, q;
int niz[100005];
pair<int, int> tur[400005];
int nzd(int a, int b) {
if (a < b) swap(a, b);
while (b > 0) {
a = a % b;
swap(a, b);
}
return a;
}
void postava() {
for (off = 1; off < n; off *= 2)
;
for (int i = off; i < off + n; i++) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} dbg;
set<int> sumTerm;
int l[1000005], a00, a01, a10, a11;
bool Solve(int m, int n) {
int a = a10, i, p, ll, rr;
if ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
const int maxn = 3100;
int a[maxn], b[maxn], c[maxn];
int dp[maxn][2];
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b, da, db;
vector<vector<int>> adj;
pair<int, int> getfurthest(int a) {
queue<pair<int, int>> Q;
vector<bool> vis(n, false);
Q.push(pair<int, int>(a, 0));
vis[a] = true;
pair<int, int> x;
while (Q.size()) {
x = Q.front();
Q.pop();
for (int ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m, h, u[100005], u1[100005], cur_color, col[100005];
set<int> g[100005], g1[100005], gr[100005], g_cond[100005];
set<int> ind[100005];
bool used[100005];
vector<int> order, comp[100005];
void dfs1(int v) {
u1[v] = u[v] + 1;
if (u1[v] == h) {
u1[v] = 0;
}
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, mod = 1e9 + 7;
int n, x, y, dp[N][20][2];
int f(int x, int y) { return (1 << x) % mod * (y ? 3 : 1) % mod; }
signed main() {
scanf("%d", &n);
x = log2(n), dp[1][x][0] = 1;
if ((1 << (x - 1)) * 3 <= n) dp[1][x - 1][1] = 1, y = 1;
for (int i = 2... | 17 |
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp1;
int main() {
int n;
int m;
cin >> n;
long long a[100009];
long long b[100009];
long long x[100009];
long long y[100009];
long long ans;
for (int i = 0; i < n; i++) {
cin >> a[i] >> x[i];
mp1[a[i]] = x[i];
}
cin >>... | 2 |
#include <bits/stdc++.h>
const int oo = 0x3f3f3f3f;
template <typename T>
inline bool chkmax(T &a, T b) {
return a < b ? a = b, true : false;
}
template <typename T>
inline bool chkmin(T &a, T b) {
return a > b ? a = b, true : false;
}
std::string procStatus() {
std::ifstream t("/proc/self/status");
return std:... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
string s, t;
while (cin >> s >> t) {
map<char, int> T;
for (int i = 0; i < t.length(); i++) T[t[i]]++;
int y = 0, w = 0;
map<int, bool> done;
for (int i = 0; i < s.length(); i++) {
if (T[s[i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1E6 + 7;
int n, ans = N;
long long a[N];
bool visited[N];
set<long long> res;
vector<int> prime, id;
long long cl = chrono::steady_clock::now().time_since_epoch().count();
void init() { shuffle(id.begin(), id.end(), default_random_engine(cl)); }
void sieve() {... | 17 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, s, i;
cin >> n >> s;
vector<long long> ans(s + 1, 0);
long long need = n - s, br = 1;
while (need > 0 || br == 1) {
for (i = 1; i <= s; i++) {
if (br == 1) {
need++;
}
long long num = 1;
while (num <=... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n, arr[1000], count = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> arr[i];
}
for (i = 1; i < n - 1; i++) {
if (arr[i] == 0 && arr[i - 1] == 1 && arr[i + 1] == 1) {
count++;
i = i + 2;
}
}
cout << count << endl;
}... | 2 |
/*---Author:HenryHuang---*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxm=2e6+5;
const ll maxn=2e5+5;
struct edge{
ll to,nex,w;
}e[maxm<<1];
ll head[maxn],cur[maxn],cnt=1;
ll n,m,s,t;
void add(ll a,ll b,ll c){
e[++cnt]=(edge){b,head[a],c};
head[a]=cur[a]=cnt;//当前弧优化
}
void addedge... | 25 |
#include <bits/stdc++.h>
using namespace std;
int n, a[1000000], ans = numeric_limits<int>::max();
void solve() {
cin >> n;
a[0] = 1;
a[n + 1] = 1000000;
for (int i = int(1); i <= int(n); i++) {
cin >> a[i];
}
for (int i = int(0); i <= int(n); i++) {
ans = min(ans, max(a[i] - 1, 1000000 - a[i + 1]))... | 3 |
#include <bits/stdc++.h>
using namespace std;
int v[31][31];
int dx[5] = {0, 0, 1, 0, -1};
int dy[5] = {0, 1, 0, -1, 0};
int used[31][31][6];
int getV(char c) {
if (c == 'U') return 1;
if (c == 'R') return 2;
if (c == 'D') return 3;
if (c == 'L') return 4;
}
void fill0() {
for (int i = 0; i < 31; i++)
for... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int s[1005] = {0}, n, m, a;
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a;
s[a]++;
}
sort(s, s + n + 1);
cout << s[1] << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
bool flag;
int main() {
int t;
cin >> t;
while (t--) {
int a, b, arr[200005], cnt = 0, check = 0;
vector<vector<int>> v;
cin >> a >> b;
v.resize(b);
for (int i = 0; i < a; i++) {
cin >> arr[i];
if (arr[i] % 2) cnt++;
}
if (cnt <... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 0, max = 0, s;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int m;
cin >> m;
int b[m];
for (int j = 0; j < m; j++) {
cin >> b[j];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T sq(T n) {
return n * n;
}
template <class T>
T gcd(T a, T b) {
return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
return (a / gcd<T>(a, b) * b);
}
template <class T>
bool inside(T a, T b, T c) {
return a <= b && b <= ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int read() {
char ch = getchar();
int x = 0, f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const int N = 1e5 + 5;
struct ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m1[100] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31,
30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30,
31, 30, 31, 3... | 4 |
#include <bits/stdc++.h>
using namespace std;
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
cerr << ' ' << H;
dbg_out(T...);
}
void run_case() {
long long n, x, c = 0;
cin >> n >> x;
for (int i = 1; i <= n; i++) {
if (i > x) break;
if (x ... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\t";
err(++it, args...);
}
template <typename T1, typenam... | 6 |
#include <bits/stdc++.h>
using namespace std;
int M[4][4];
const int MAXLENGTH = 1000111;
string s[4];
char inv(char c) {
if (c == 'a') return 'b';
return 'a';
}
int main() {
int mn = 1000111;
for (int i = 0; i < 4; i++)
for (int j = i + 1; j < 4; j++) scanf("%d", &M[i][j]);
for (int k = 0; k <= MAXLENGTH... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int first = 0, second = 0, third = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
first += x;
}
for (int i = 0; i < n - 1; i++) {
int x;
cin >> x;
second += x;
}
for (int i = 0; i < n - 2; i++) {
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int ans = 0, n, x;
cin >> n >> x;
for (int i = 1; i <= n; i++) {
if (x % i == 0 && (x / i) <= n) ans++;
}
cout << ans << endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
void add_rem_i(long long* fr, long long* bit, long long i, long long n,
long long q) {
fr[i] += q;
long long j = i;
while (j <= n) {
bit[j] += q;
j += (j & (-j));
}
}
long long find_cum_fr(long long* bit, long long i) {
long long count = 0;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
void fre() {
freopen("c://test//input.in", "r", stdin);
freopen("c://test//output.out", "w", stdout);
}
template <class T1, class T2>
inline void gmax(T1 &a, T2 b) {
if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1 &a, T2 b) {
if (b < a) a = b;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long BINF = 9e18, LINF = 2e9, mod = 1e9 + 7, P = 179, Q = 1791791791;
void solve() {
long long n;
cin >> n;
string s;
cin >> s;
long long sum = 0;
for (long long i = 0; i < n; ++i) {
sum += (long long)(s[i] - '0');
}
if (n == 1) {
cout << ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int n, m, a[100001], b[100001], q[100001];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) b[i] = a[i] + b[i - 1];
cin >> m;
for (int i = 0; i < m; i++) {
long long int first = 1, last = n, mid, ans = 0;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, n, m;
cin >> n >> m;
int nn[n], mm[m], ss[92];
for (i = 0; i < n; i++) cin >> nn[i];
for (i = 0; i < m; i++) cin >> mm[i];
for (i = 0, k = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (nn[i] == mm[j]) {
ss[k] = nn[i];... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 9;
bitset<N> bs;
vector<long long> non_prime;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long q;
cin >> q;
while (q--) {
long long n;
cin >> n;
long long ans = 1;
if (n < 4 or n == 5 or n == 7 or n == 11)... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000 + 10;
vector<int> G0[MAX], G1[MAX];
vector<pair<int, int> > e;
bool mark1[MAX], mark0[MAX];
int d[MAX];
void DFS0(int v) {
mark0[v] = true;
for (int i = 0; i < G0[v].size(); i++)
if (!mark0[G0[v][i]]) DFS0(G0[v][i]);
}
void DFS1(int v) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, x, y, i, j, fs, ls, ck;
cin >> n >> x >> y;
vector<long long int> a(n);
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
fs = i - x;
if (fs < 0) fs = 0;
ls = i + y;
if (ls >= n) ls = n - 1;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int N;
long long K;
inline long long sum(long long n) { return (1 + n) * n / 2; }
int main() {
cin >> N >> K;
for (int i = 1; i <= N; ++i) {
long long x = sum(i - 1);
if (i == N) {
if (x < K) {
puts("Impossible");
return 0;
} else {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m, sum = 0;
cin >> n >> m;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
sum += temp;
}
if (n != m || n == 2) {
cout << "-1\n";
return;
}
cout << 2 * sum << "\n";
for (int i = 1; i < n; i++) {
cout << i <<... | 3 |
#include <bits/stdc++.h>
using namespace std;
set<int> a[30];
string s;
int main() {
ios::sync_with_stdio(false);
int q;
while (cin >> s) {
for (int i = 0; i < 30; i++) a[i].clear();
for (int i = 0; i < s.size(); i++) {
a[s[i] - 'a'].insert(i);
}
cin >> q;
int f;
int num, l, r;
c... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, a[5], A[20], B[20], Ans[20], was[20];
int v[20][5], ai, bi, stand[10], ans, u[20];
string s;
bool check() {
bool f = 1;
memset(stand, 0, sizeof stand);
memset(was, 0, sizeof was);
for (int j = 0; j < 4; j++) stand[a[j]] = j, was[a[j]] = 1;
for (int j = 0; j... | 9 |
#include <bits/stdc++.h>
const long long INF = (1e9 + 12312), MOD = 1e9 + 7;
const long double EPS = 0.0000000001;
using namespace std;
bool ask(long long first, long long second) {
cout << first << " " << second << endl;
string s;
cin >> s;
if (s == "Bad") {
exit(1);
}
return s == "Yes";
}
signed main(... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long a[101][101];
void com() {
a[1][1] = 1;
a[1][0] = 1;
for (int i = 2; i <= 100; i++) {
a[i][0] = 1;
for (int j = 1; j <= i; j++) a[i][j] = a[i - 1][j] + a[i - 1][j - 1];
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
com()... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool neprim[33000];
int p, m, n, primes[33000], t, a[5010], b[5010], curr_gcd[5010], total,
gcdExtra;
void ciur() {
for (int i = 2; i <= 32000; i++)
if (!neprim[i]) {
primes[++p] = i;
for (int j = i + i; j <= 32000; j += i) neprim[j] = 1;
}
}
int g... | 10 |
#include <bits/stdc++.h>
using namespace std;
void afify() {
ios::sync_with_stdio(0);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const long long oo = (long long)1e13;
const double EPS = 1e-4;
int main() {
afify();
char arr[] = {'a', 'b', 'c', 'd'};
int n;
cin >> n;
int j = 0;
while (n-... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
string n;
cin >> t;
int len, ans;
while (t--) {
ans = 0;
cin >> n;
len = n.length();
ans = (len - 1) * 9;
int f = 0, p = 0, l = 0;
if (len == 1) {
ans = ((int)n[0] - 48);
} else {
for (int i = 0; i < len;... | 2 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> q;
int n;
class Graph {
int V;
list<int> *adj;
void topologicalSortUtil(int v, bool visited[], stack<int> &Stack);
public:
Graph(int V);
void addEdge(int v, int w);
void topologicalSort();
};
Graph::Graph(int V) {
this->V = V;
adj = new list<... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, arr[1005], ans[1005], temp[1005], rel[1005][1005];
struct node {
int l, r;
bool is;
} tree[500000];
int len, root;
bool ok;
void dfs(int u, int cen, int ll, bool bb) {
if (ok || tree[u].is) return;
if (cen == 0) {
if (!bb) return;
ok = 1;
tree[u].... | 11 |
#include <bits/stdc++.h>
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
void xxx(int x, int ar[]) {
if (x == 0)
return;
else {
swap(&ar[x], &ar[x - 1]);
xxx(x - 1, ar);
}
}
int main() {
int n;
scanf("%d", &n);
int ar[n];
for (int i = 0; i < n; i++) ar[i] = i + 1;
xxx(... | 2 |
#include <bits/stdc++.h>
namespace chtholly {
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar()) f ^= c == '-';
for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ '0');
return f ? x : -x;
}
template <typename mitsuha>
inline bool read(mitsuha &x) {
x =... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[3333333];
int main() {
cin >> n;
for (int i = 2; i <= (1ll << (n + 1ll)) - 1ll; ++i) cin >> a[i];
long long k = n;
long long res = 0;
do {
k--;
for (int i = (1ll << k); i <= (1ll << (k + 1ll)) - 1ll; i++) {
a[i] = max(a[i + i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 4e5 + 10;
const int INF = 1000000000;
const int inf = 1e9 + 1;
const double eps = 1e-9;
set<string> ans;
string s;
bool go[N][3];
bool equals(int pos, int la, int lb) {
if (pos == 0) {
return false;
}
if (la != lb) {
retu... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long dp[100010], tdp[100010], rem[60][60];
long long cnt[100010], inv[100010], fac[100010], W;
char str[100010];
const long long mod = 1e9 + 7;
int c_pos(char c) {
if (c >= 'A' && c <= 'Z')
return c - 'A' + 1;
else
return c - 'a' + 1 + 26;
}
long long fpow(... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, m, dp[30010][210][4], num[30010];
int main() {
int i, j;
cin >> n >> m;
for (i = 1; i <= n; i++) scanf("%d", &num[i]);
memset(dp, -0x3f, sizeof(dp));
for (j = 0; j <= n; j++)
for (i = 0; i < 4; i++) dp[j][0][i] = 0;
for (i = 1; i <= n; i++) {
for ... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long a[100009];
map<int, int> m;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (a[0] != 0) {
cout << 1;
return 0;
}
m[0] = 1;
m[-1] = 1;
for (int i = 1; i < n; i++) {
if (m[a[i] - 1] == 1) {
m[a[i]... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 5;
const long long mod = 1e9 + 7;
long long pw(long long b, long long r, long long md = mod) {
b = b % md;
long long ans = 1;
while (r) {
if (r & 1) ans = (ans * b) % md;
b = (b * b) % md;
r >>= 1;
}
return ans;
}
long long... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
long long k;
cin >> n >> m >> k;
vector<long long> A(n);
for (int i = 0; i < n; ++i) cin >> A[i];
if (m > n) {
A.resize(m, -1);
n = m;
}
long long ans = 0;
vector<long long> dp(n);
dp[n - 1] = A[n - 1] - k;
for (int i = 1... | 11 |
#include <bits/stdc++.h>
int main() {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
if (m - n >= 0 && k - n >= 0)
printf("YES");
else
printf("NO");
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, ta, tb, tc, td;
double dp[2505][2505][2], to[2505][2505], x[2505], y[2505], ans;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%lf%lf", x + i, y + i);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
to[i][j] = sqrt(((x[i] - ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const double pi = 3.1415926535;
bool cmp(pair<double, double> a, pair<double, double> b) {
int t1, t2;
if (a.first >= 0 && a.second >= 0) {
t1 = 1;
} else if (a.first <= 0 && a.second >= 0) {
t1 = 2;
} else if (a.first <= 0 && a.second <= 0) {
t1 = 3;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:36777216")
void solve();
int main() {
solve();
return 0;
}
const char* table[] = {
"H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg",
"Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr",
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d%d", &n, &k);
if (k == 0 && n > 1) {
puts("No solution");
return 0;
}
printf("%d", k);
--n;
while (n--) {
printf("%c", '0');
}
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
char sRead[10];
int main() {
vector<int> sign{1};
while (scanf("%s", sRead), sRead[0] != '=') {
if (sRead[0] == '+')
sign.push_back(1);
else if (sRead[0] == '-')
sign.push_back(-1);
}
int n;
scanf("%d", &n);
int qCount = sign.size();
int po... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, jwb = 0, tmpjwb = INT_MAX;
cin >> n >> a >> b;
if (b > a && b + a + a <= n) {
tmpjwb = 2;
}
multiset<int> s;
for (int i = 0; i < 4; ++i) s.insert(a);
for (int i = 0; i < 2; ++i) s.insert(b);
while (!s.empty()) {
++jwb;
i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int n, m;
char s[1200 + 5][1200 + 5];
int judge(char a[3][3]) {
int tt = 0;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) tt += (a[i][j] == 'O');
if (tt == 0 || tt == 4 || tt == 5 || tt == 1) return 0;
if (tt == 2) {
if ... | 15 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m, a, b;
cin >> n >> m >> a >> b;
if (a * m < b)
cout << a * n << "\n";
else {
int ans = b * floor(n / (1.0 * m));
if ((n % m) * a < b)
ans += (n % m) * a;
else
ans += b;
cout << ans << "\n";
}
}
int main() {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
char a[1005];
cin >> a;
int i;
int len = (strlen(a) + 1) / 2 - 1;
bool flg = 1;
for (i = 0; i <= len; i++) {
if (a[i] != a[strlen(a) - 1 - i]) flg = 0;
}
if (flg == 1) {
bool flag ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int a[100005], t[400005], res, n, m, w, mx = 0;
long long int bs(long long int high, long long int low) {
if (low > high) return -100;
long long int mid = (high + low) / 2, cur = 0, sh = 0;
for (int i = 0; i < n; i++) {
cur -= t[i];
t[i] = 0;
if ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int root = 1;
int n, tr[6000010][2], size = 1;
int sum[6000010], a[300010], ans;
void insert(int x) {
int nw = root;
for (int i = 30; i >= 0; i--) {
int p = (x >> i) & 1;
if (tr[nw][p] == 0) tr[nw][p] = ++size;
nw = tr[nw][p];
sum[nw]++;
}
}
void... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct node {
int cv;
int tv;
vector<int> adj;
node() {
cv = 0;
tv = 0;
}
} g[N];
int n, u, v, sol;
vector<int> ans;
void dfs(int okle, int cur, int nivo, int par, int nepar) {
int curpar = 0, curnepar = 0;
if (nivo % 2 == 0)
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int N = 305;
long long Power(long long a, long long b) {
if (b == 0) return 1;
long long p = Power(a, b / 2);
p *= p;
if (b % 2) p *= a;
return p;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.t... | 4 |
#include <bits/stdc++.h>
using namespace std;
char s[55];
int Next[55];
void kmp_pre(char* pat) {
int l = strlen(pat);
int i = 0, j = -1;
Next[0] = -1;
while (i < l) {
if (j == -1 || pat[i] == pat[j]) {
i++;
j++;
Next[i] = j;
} else {
j = Next[j];
}
}
}
int main(void) {
i... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> adj;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, m;
cin >> n >> m;
adj.resize(n);
for (long long i = 0; i < m; i++) {
long long u, v;
cin >> u >> v;
--u, --v;
adj[u].p... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-7;
int sig(long double x) { return x < -eps ? -1 : x > eps; }
struct point {
long double x, y;
point() {}
point(long double x, long double y) : x(x), y(y) {}
void input() { cin >> x >> y; }
void output() { cout << x << ' ' << y << endl; ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long getSize(long long num) {
if (num <= 1) return 1;
return 2 * getSize(num / 2) + 1;
}
long long l, r;
long long solve(long long n, long long cl, long long cr) {
if (cl > r or cr < l) return 0;
if (!n) return 0;
if (cl > cr) return ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 10;
typedef int i_N[maxN];
int N, M;
i_N A;
int ITodd[maxN * 4], ITeven[maxN * 4];
namespace graph {
int Cnum;
i_N num, hi, P, depth;
vector<int> adj[maxN];
void link(const int u, const int v) { adj[u].push_back(v); }
void DFS(const int u) {
num[u] ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, a1, b1;
while (~scanf("%lld%lld%lld%lld", &a, &b, &a1, &b1)) {
int n;
scanf("%d", &n);
int ans = 0;
for (int i = 0; i < n; i++) {
long long c, d, e;
scanf("%lld%lld%lld", &c, &e, &d);
if (c * a + b * e + d >... | 9 |
#include <bits/stdc++.h>
using namespace std;
string s;
int check(int pos, char x) {
if (s[pos - 1] != x && s[pos + 1] != x)
return 1;
else
return 0;
}
int main() {
int i, j, k;
cin >> s;
for (i = 1; i < s.length(); i++) {
if (s[i] == s[i - 1]) {
if (check(i, 'a')) s[i] = 'a';
if (chec... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int intmax = 0x3f3f3f3f;
const long long lldmax = 0x3f3f3f3f3f3f3f3fll;
double eps = 1e-6;
template <class T>
inline void checkmin(T &a, T b) {
if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
if (b > a) a = b;... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n;
int ans[2010];
struct _2sat {
bitset<2010> g[2010];
int m;
int get(int x) {
if (x > 0)
return x * 2 - 2;
else
return -x * 2 - 1;
}
void read() {
while (m--) {
int x, y;
scanf("%d%d", &x, &y);
x = get(x);
y = g... | 22 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > G[2002];
int vis[2002];
void go(int i, int col) {
vis[i] = col;
for (int j = 0; j < G[i].size(); j++) {
int v = G[i][j].first;
int w = G[i][j].second;
if (w == 1) {
if (vis[v] != 3) go(v, col);
}
}
return;
}
int flag = 0... | 7 |
#include <bits/stdc++.h>
int main() {
int n, i, j, m;
long long k;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%lld %d", &k, &m);
printf("%lld\n", 9 * (k - 1) + m);
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2000005;
const long long mod = 1e9 + 7;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long tom[200];
long long ban[200];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> tom[i];
}
for (int i = 0; i < m; i++) {
cin >> ban[i];
}
long long result = -1e18;
long long result_prod = -1e18;
long long num = 0;
... | 6 |
#include <bits/stdc++.h>
const int maxn = 6005;
int n, sum, flg;
int a[maxn];
int check(int x) {
for (int i = 2; i * i <= x; i++)
if (x % i == 0) return 1;
return 0;
}
int main() {
scanf("%d", &n);
sum = n * (n + 1) / 2;
if (check(sum) == 0) {
for (int i = 1; i <= n; i++) printf("1%c", i == n ? '\n' :... | 14 |
#include <bits/stdc++.h>
const int N = 1e6 + 61;
std::vector<int> g[N];
int dep[N], son[N];
void dfs1(int x, int p) {
for (int nx : x[g])
if (nx != p) {
dfs1(nx, x);
if (nx[dep] > x[son][dep]) x[son] = nx;
}
x[dep] = x[son][dep] + 1;
}
int buf[N], *pt = buf;
int *f[N], ans[N];
void dfs2(int x, i... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n >> m;
if (n <= m) {
cout << n << endl;
return 0;
}
n -= m;
n *= 2;
long long int x = sqrt(n);
if ((x * (x + 1)) >= n)
cout << x + m << endl;
else
cout << x + 1 + m << endl;
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 100002;
int n;
int val[N_MAX];
vector<int> edges[N_MAX];
bool blocked[N_MAX];
int subSize[N_MAX];
void dfs(int node, int parent = -1) {
subSize[node] = 1;
for (int u : edges[node])
if (u != parent && blocked[u] == false) {
dfs(u, node);
... | 13 |
#include <bits/stdc++.h>
using namespace std;
double eps = 1e-9;
double pi = 2 * acos(0);
long long mod = 1e9 + 7;
const int mysz = 1e5;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
int p = 1000;
vector<vector<long long>> dp(p);
for (int i = 0; i < p; i++) {
vector<long long> nv(p, 0)... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x20202020;
const int mod = 1000000007;
template <class T>
inline void read(T& x) {
bool fu = 0;
char c;
for (c = getchar(); c <= 32; c = getchar())
;
if (c == '-') fu = 1, c = getchar();
for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0';... | 14 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
int a, b, c, d, i, j, n, m, k;
int mas[100001];
long long cs[100001], a1;
inline long long sum(int l, int r) {
if (!l)
return cs[r];
else
return cs[r] - cs[l - 1];
}
inline long long calc(int k) {
if (k == 1) return a... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v;
int n, first, second;
cin >> n;
char c;
string a;
cin >> a;
for (int i = 0; i < n; i++) {
int b;
cin >> b;
v.push_back(b);
}
int count = 0, i = 0;
while (n != count) {
if (a[i] == '>') {
first = v[i];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, h, i, cnt;
int main() {
cin >> n;
while (cnt <= n) {
h++;
cnt += (h * (h + 1)) / 2;
}
cout << h - 1 << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int l;
int r;
Node() {
l = 0;
r = 0;
}
} node[50];
int vis[50];
int fa[50];
int Find(int x) { return fa[x] == x ? x : Find(fa[x]); }
set<int> s[50];
int main() {
int n, m;
cin >> n >> m;
int f = 0;
memset(vis, 0, sizeof(vis));
for (in... | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.