solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int did[100100];
int didnot[100100];
int possible[100100];
int answer[100100];
int main() {
int n;
int m;
int temp;
int totaldid = 0;
int totaldidnot = 0;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", &temp);
answer[i + 1] = temp;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = long double; // or double, if TL is tight
using str = string; // yay python!
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vec... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, h, count = 0, i, j;
cin >> n >> h;
for (i = 0; i < n; i++) {
cin >> j;
if (j <= h)
count++;
else
count += 2;
}
cout << count;
return 0;
}
| 0 |
#include<bits/stdc++.h>
#define ios std::ios::sync_with_stdio(false)
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,n,a) for (int i=n;i>=a;i--)
#define repp(i,a,b) for(int i=a;i<b;i++)
#define mm(a,n) memset(a, n, sizeof(a))
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9, mod = 998244353;
int n, sl, fh, ans, f1[1000010], f2[1000010], fac[1000010], ifc[1000010];
char s[1000010];
int rd() {
sl = 0;
fh = 1;
char ch = getchar();
while (ch < '0' || '9' < ch) {
if (ch == '-') fh = -1;
ch = getchar();
}
whil... | 18 |
#include <bits/stdc++.h>
long long Max(long long a, long long b) { return a > b ? a : b; }
long long Min(long long a, long long b) { return a < b ? a : b; }
int main() {
srand(98432156);
long long n;
int k;
scanf("%lld%d", &n, &k);
long long l = 1, r = n;
for (int i = 1; i <= 4500; i++) {
if (r - l + 1 ... | 13 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
void io() {}
long long arr[1000001];
long long brr[1000001];
long long tree[1000001];
map<long long, long long> mp;
vector<long long> adj[1000001];
long long vis[1000001];
long long n, m, k, l, r, x, y, t, a, b, q;
long long ans, cnt, tmp, sum, ind, mn ... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> G, H;
vector<int> ord, comp;
vector<bool> V;
struct SCC {
int n, c;
SCC(int n) : n(n) {
G.resize(n);
H.resize(n);
for (int i = 0; i < n; i++) {
G[i].reserve(n);
H[i].reserve(n);
G[i].clear();
H[i].clear();
}
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int h = 0, z = 0, xo = -1, ox = -1, xx = -1;
vector<int> answers;
while (n--) {
int x;
cin >> x;
if (x == 100) {
if (h == 0) {
h++;
answers.push_back(100);
}
} else if (x == 0) {
answe... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 20;
int x[3], y[3];
bool visited[maxn][maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for (int i = 0; i < 3; i++) cin >> x[i] >> y[i];
pair<int, pair<int, int> > res = {1e9, {0, 0}};
for (int i = -1000; i < ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
;
long long int t = 1, n;
cin >> t;
while (t--) {
long long int a, b, c, d;
cin >> a >> b >> c >> d;
if (a + b < c + d) {
cout << "No"
<< "\n";
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
int N, A, B, C, D, S, L;
int T[303030];
int Q[303030];
signed long long AS[303030];
signed long long AL[303030];
signed long long AR[303030];
signed long long BS[303030];
template <class V, int NV>
class SegTree_1 {
public:
vector<V> val;
static V const def = 1LL << 60... | 16 |
#include <bits/stdc++.h>
using namespace std;
int a[105];
int main() {
int n, t, now;
scanf("%d %d", &n, &t);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
now += 86400 - a[i];
if (now >= t) {
printf("%d\n", i);
return 0;
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int len = s.length(), val;
if (len == 1) {
val = s[0] - '0';
if (val % 4 == 0)
printf("4");
else
printf("0");
return 0;
}
val = s[len - 2] - '0';
val *= 10;
val += s[len - 1] - '0';
if (val % 4 =... | 4 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long T = 1;
while (T--) {
long long k;
long long x = 131072;
cin >> k;
if (k == 0) {
cout << 1 << " " << 1 << "\n";
cout << 100000 << "\n";
} else {
cout ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int ans, n, s, i, j, S[1001], v[101][1001], T[101][1001];
int x1, x2, x3, x4, t, tt, p1, p2;
bool pd() {
if (x3 != x4)
return ((x1 - x2) < 0 && (x3 - x4) > 0) || ((x1 - x2) > 0 && (x3 - x4) < 0);
if (x3 == s) return 0;
int q1 = p1, q2 = p2;
if (tt == T[i][q1]) q... | 15 |
#include <bits/stdc++.h>
int compare(const void *a, const void *b) { return (*(int *)b) - (*(int *)a); };
int main() {
int count = 0, temp;
int t, n;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
qsort(a, n... | 0 |
#include <bits/stdc++.h>
using ll = long long;
int main() {
int n, x, y;
std::cin >> n;
std::vector<int> v(n + 1);
for (int i{1}; i <= n; ++i) {
std::cin >> v[i];
v[i] += v[i - 1];
}
std::cin >> x >> y;
for (int i{1}; i <= n; ++i) {
bool bc_ok{x <= v[i] && v[i] <= y};
bool ic_ok{x <= v.bac... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[110];
int i, j, n;
while (~scanf("%d", &n)) {
memset(a, 0, sizeof(a));
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
int ans = 0;
if (n < 3 || n % 2 == 0)
printf("-1\n");
else {
for (i = n; i >= 1; i--) {
if (a... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, x, y, i, j, l, r, t, a[456], d;
set<long long> s;
set<long long>::reverse_iterator it;
char c;
int main() {
cin >> n >> d;
for (i = 0; i < d; i++) {
for (j = 0; j < n; j++) {
cin >> c;
if (c == '1') a[i]++;
}
}
a[d] = n;
for ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int mod1 = 998244353;
bool isprime[100000];
vector<long long int> prime;
void sieve() {
long long int i, j;
for (i = 2; i < 1e5; i++) isprime[i] = true;
for (i = 2; i < 1e5; i++) {
if (isprime[i]) {
prime.pu... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 20;
const int mod = 1e9 + 7;
int n, m, tot;
long long ans, cz[N], cm[N];
long long pow(long long a, long long b) {
long long ret = 1;
while (b) {
if (b & 1) ret = ret * a % mod;
a = a * a % mod;
b >>= 1;
}
return ret;
}
void init() {
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
int i, count = 0, c4 = 0, c7 = 0;
cin >> s1 >> s2;
for (i = 0; i < s1.size(); i++) {
if (s1[i] == '4' && s2[i] == '7')
c4++;
else if (s1[i] == '7' && s2[i] == '4')
c7++;
}
count = max(c4, c7);
cout << count;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void _R(T &x) {
cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(unsigned long long &x) { scanf("%llu", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(c... | 25 |
#include <bits/stdc++.h>
const int MOD = 998244353;
inline int lgput(int a, int b) {
int ans = 1;
while (b > 0) {
if (b & 1) ans = (1LL * ans * a) % MOD;
b >>= 1;
a = (1LL * a * a) % MOD;
}
return ans;
}
inline void mod(int &x) {
if (x >= MOD) x -= MOD;
}
inline void add(int &x, int y) {
x += y;... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
const int oo = 1e9;
struct data {
int l, r;
long long d;
};
long long cnt[MAXN + 1];
int main() {
int n, k;
scanf("%d%d", &n, &k);
unsigned *arr = new unsigned[n];
for (int i = 0; i < n; ++i) {
char s[20];
scanf("%s", s);
unsign... | 8 |
#include <bits/stdc++.h>
using namespace std;
char str[2000];
bool grid[5][5];
int main() {
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 4; j++) {
grid[i][j] = 0;
}
}
scanf("%s", str);
int len = strlen(str);
for (int i = 0; i < len; i++) {
if (str[i] == '0') {
for (int k = 1; k ... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool is_leap(int x) { return x % 400 == 0 || (x % 4 == 0 && x % 100 != 0); }
int days(int x) {
if (is_leap(x)) return 366;
return 365;
}
int main() {
int y;
cin >> y;
int day = days(y) % 7;
for (int yy = y + 1;; yy++) {
if (day == 0 && is_leap(yy) == is_leap... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int res = 1;
if (n % 2 == 1)
cout << 0 << endl;
else {
for (int i = 1; i <= n / 2; i++) res *= 2;
cout << res << endl;
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
int main() {
int n, m, x, y, i, j, k, l, flag, co, w;
long long ans;
while (scanf("%d%d%d", &k, &n, &w) == 3) {
ans = 0;
for (i = 1; i <= w; i++) {
ans += (i * k);
}
ans -= n;
if (ans >= 0)
printf("%I64d\n", ans);
else
printf("0\n");
}
return ... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
int b = 0;
for (const auto& a : v) o << (b++ ? " " : "") << a;
return o;
}
template <typename T, typename U>
ostream& operator<<(ostream& o, const pair<T, U>& p) {
o << p.first << ' ' << p.s... | 0 |
#include <bits/stdc++.h>
using namespace std;
int Szukaj1(vector<int>& a, int x) {
int l = 0, p = a.size() - 1, s, r = -1;
while (l <= p) {
s = (l + p) / 2;
if (a[s] >= x) {
r = s;
p = s - 1;
} else
l = s + 1;
}
return r;
}
int Szukaj2(vector<int>& a, int x) {
int l = 0, p = a.si... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 18 | 1;
int n, m, M, fac[N], inv[N], num[19][N], a[19], b[19], Inv;
unsigned long long c[19];
int ksm(int x, int y) {
int ans = 1;
for (; y; y >>= 1, x = (long long)x * x % M)
if (y & 1) ans = (long long)ans * x % M;
return ans;
}
void fwt(int y... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
long long n;
cin >> n;
map<long long, long long> mp;
long long c[n];
long long a[n];
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
a[i] = x;
long long cnt = 0;
while (... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chkmax(T& x, T y) {
if (x < y) x = y;
}
template <typename T>
void chkmin(T& x, T y) {
if (x > y) x = y;
}
inline int read() {
int x = 0;
char c = getchar();
bool f = 0;
while (c < 48) f |= c == '-', c = getchar();
while (c > 47) x =... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 10;
int n, a[maxN], len, t[maxN];
int main() {
cin >> n;
t[0] = maxN;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
int x = lower_bound(t, t + len, a[i]) - t;
t[x] = a[i];
if (x == len) t[++len] = maxN;
}... | 7 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
vector<int> ans;
int n;
cin >> n;
int p = 1;
while (n) {
if (n % 10) ans.push_back(n % 10 * p);
n /= 10;
p *= 10;
}
cout << ans.size() << '\n';
for (int i : ans) cout << i << " ";
cout << '\n';
}
int main() {
int t;
cin >> t;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int maxn = 2e3 + 100;
string s;
long long dp[maxn][maxn] = {0};
int num[maxn] = {0};
long long qmod(long long a, long long b) {
long long ans = 1;
while (b) {
if (b & 1) ans = ans * a % mod;
b >>= 1;
a = a * a % mod;
}
re... | 18 |
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++)
#define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--)
#define ll long long
#define pii pair<int, int>
#define db double
#define x first
#define y second
#define ull unsigned long long
#define sz(a) ((int) (a).size())
#define vi ve... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int rank[n];
for (int i = 0; i < n; i++) cin >> rank[i];
int point[n];
for (int i = 0; i < n; i++) cin >> point[i];
rank[k - 1] = rank[k - 1] + point[0];
int mark = 0;
for (int i = 0; i < k - 1; i++) {
if (rank[i] ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x, y, z;
int sumX = 0, sumY = 0, sumZ = 0;
for (int i = 0; i < n; i++) {
cin >> x >> y >> z;
sumX += x;
sumY += y;
sumZ += z;
}
if (sumX == 0 && sumY == 0 && sumZ == 0)
cout << "YES\n";
else
cout << "... | 2 |
#include <bits/stdc++.h>
using namespace std;
int grid[100][100] = {};
int main() {
int n;
cin >> n;
for (long long i = 0; i < n; ++i) {
for (long long q = 0; q < n; ++q) {
cin >> grid[i][q];
}
}
for (long long i = 0; i < n; ++i) {
for (long long q = 0; q < n; ++q) {
if (grid[i][q] != ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, num, count;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> num;
int nnum = num;
count = 0;
while (num != 0) {
count++;
num = num / 10;
}
nnum = nnum % 10;
int ans = 10 * (nnum - 1);
if (count == 1)
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, d, n, x, y, rs, c = 0;
cin >> r >> d >> n;
while (n--) {
cin >> x >> y >> rs;
double p = sqrt(x * x + y * y);
if (r - d <= p - rs && p + rs <= r) c++;
}
cout << c;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
void solve(int tc);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
string *arr = new string[n];
bool isDone = false;
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < n; i++) {
if (isDone) br... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxm = 1e6 + 10;
char s[maxm];
int a[30];
int main() {
int n;
while (scanf("%d", &n) != EOF) {
memset(a, 0, sizeof(a));
scanf("%s", s);
int cnt = 0;
for (int i = 0; i < 2 * n - 2; i++) {
if (i % 2 == 0) {
a[s[i] - 'a']++;
} ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int d, n;
cin >> d >> n;
int ans = 0;
for (int i = 0; i < n - 1; i++) {
int x;
cin >> x;
ans += d - x;
}
cout << ans << "\n";
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
long long int x = -1.5 + 0.5 * sqrt(9 + 8 * (n + k));
cout << n - x << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
int n, m, K;
char buf[500][501];
int a[500][500];
int s[501][501];
int main() {
scanf("%d%d%d", &n, &m, &K);
for (int i = 0; i < n; ++i) {
scanf("%s", buf[i]);
}
memset(a, 0, sizeof(a));
for (int i = 1; i + 1 < n; ++i) {
for (int j = 1; j + 1 < m; ++j) {
if (buf[i][j] ==... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct hull {
map<int, int> points;
long long area;
inline hull() {
points.clear();
area = 0;
}
inline map<int, int>::iterator prev(map<int, int>::iterator it) {
return it == points.begin() ? it : --it;
}
inline map<int, int>::iterator next(map<int... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000000 + 7;
int power(long long a, int b) {
long long ret = 1;
for (; b; b >>= 1) {
if (b & 1) {
ret = ret * a % MOD;
}
a = a * a % MOD;
}
return ret;
}
int main() {
int n, k;
scanf("%d %d", &n, &k);
printf("%I64d\n", (lon... | 7 |
#include <bits/stdc++.h>
using namespace std;
int fx[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2};
int fy[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1};
int N;
struct EB {
long long n;
vector<int> match, vst;
set<pair<int, int>> used;
void join(long long a, long long b) { match[a] = b, match[b] = a; }
inline... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int w = 0;
char ch = getchar();
while (ch < '0' || ch > '9') ch = getchar();
while (ch <= '9' && ch >= '0') {
w = (w << 3) + (w << 1) + (ch ^ 48);
ch = getchar();
}
return w;
}
int n, m, s, h[100100 << 3], vis[100100 << 3], tot, idin[... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100000 + 1], pos[100000 + 1], p[100000 + 1], tot = 0, d[100000 + 1];
bool v[100000 + 1];
vector<pair<int, int> > ans;
inline void exchange(int x, int y) {
if (x == y) return;
swap(a[x], a[y]);
swap(pos[a[x]], pos[a[y]]);
ans.push_back(make_pair(x, y));
}
in... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m, t, K, las[101000], nxt[101000], to[101000], dat[101000], id[101000],
S, T, tot = 1, d[101000], SS, TT, fl[101000], bz[101000], que[101000],
e[101000][2], use[101000], ans[101000];
int co[610][310];
void putin(int x, int y, int z1) {
nxt[++tot] = la... | 22 |
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define inf9 (1000000000)
#define MOD 9982... | 27 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n;
cin >> n;
string s;
getline(cin, s);
getline(cin, s);
vector<long long> v;
long long j = 0;
for (long long i = 0; i < s.size(); i++) {
if (s[i] == '.' || s[i] == '?' || s[i] == '!'... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long m, n;
cin >> m >> n;
while (m && n) {
if (m >= 2 * n)
m = m % (2 * n);
else if (n >= 2 * m)
n = n % (2 * m);
else
break;
}
cout << m << " " << n << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long l, r, m;
cin >> l >> r >> m;
long long mini = l - r;
long long maxi = r - l;
if (m < l) {
long long diff = l - m;
if (diff <= maxi) {
cout << l << " " << l << " " << l ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 200005;
long long read() {
long long 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;
}
lo... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a, remain = 0, COUNT = 0;
int main() {
cin >> n >> m;
while (n--) {
cin >> a;
if (remain < a) {
COUNT++;
remain = m;
}
remain -= a;
}
cout << COUNT;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const int maxn = 3e5 + 100, mod = 1e9 + 7;
const double eps = 1e-19;
int dcmp(double x) {
if (fabs(x) < eps) return 0;
return x < 0 ? -1 : 1;
}
long long powmod(long long x, long long n) {
long long ret = 1;
for (; n > 0; n >>= 1, x = x * x % mo... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int bigmod = 1000000007, x[100005], ans = 0, temp, sz;
set<long long int> s;
set<long long int>::iterator it;
map<long long int, long long int> cnt;
pair<long long int, long long int> p;
vector<long long int> adj[100005];
long long int gcd(long long int a, long lo... | 12 |
#include <bits/stdc++.h>
using namespace std;
int t, n, k;
int main() {
cin >> t;
while (t--) {
cin >> n;
int a[n];
vector<pair<int, int> > b(n + 7, {-1, 0});
for (int i = 0; i < n; i++) {
cin >> a[i];
if (b[a[i]].first == -1)
b[a[i]] = {i, i + 1};
else {
int px = b... | 7 |
#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
using namespace std;
int n, m, p;
long long a[1000100];
long long b[1000100];
int main() {
a[1] = 1;
long long pow1 = 1;
for (int i = 2; i <= 1000000; i++) {
a[i] = (2 * a[i - 1] + pow1) % 998244353;
pow1 = (pow1 * 2) % 998244353;
}
while (scanf("%d... | 12 |
#include <bits/stdc++.h>
using namespace std;
void open() {
freopen("D:/Code/in.txt", "r", stdin);
freopen("D:/Code/out.txt", "w", stdout);
}
map<string, int> mapper;
map<int, string> rev;
int op[5020];
string val[2][5020];
int main(void) {
std::ios::sync_with_stdio(false);
int n, m;
memset(op, -1, sizeof(op)... | 10 |
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pii = pair<int, int>;
using plii = pair<lint, lint>;
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
template <typename T>
istream &operator>>(istrea... | 0 |
#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... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long k, d, t;
cin >> k >> d >> t;
long long cost = t * 2;
long long loop;
if (k % d == 0)
loop = k;
else
loop = (k / d + 1) * d;
long long add = loop - k + 2 * k;
long long num = cost / a... | 9 |
#include <bits/stdc++.h>
using namespace std;
int a[100100], b[100100], c[100100], n, p, k, i, d[100100], flag[100100];
struct node {
int a, b;
} v[100100];
bool cmp1(int u, int v) {
return ((b[u] > b[v]) || (b[u] == b[v]) && (a[u] < a[v]));
}
bool cmp2(int u, int v) {
return ((a[c[u]] > a[c[v]]) || (a[c[u]] == a... | 14 |
#include <bits/stdc++.h>
using namespace std;
char st[4][150] = {0};
int main() {
int minn = 100000000, maxx = 0, bj1 = 0, bj2 = 0, i, j, k, l, s, t, k1 = 0,
k2 = 0, result = -1;
int a[4];
for (i = 0; i <= 3; i++) {
gets(st[i]);
a[i] = strlen(st[i]) - 2;
if (minn > a[i]) minn = a[i], k1 = i;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long t, sx, sy, ex, ey, ans = -1;
cin >> t >> sx >> sy >> ex >> ey;
long long xd = sx - ex, yd = sy - ey;
char X, Y;
if (xd > 0)
X = 'W';
else
X = 'E';
if (yd > 0)
Y = 'S';
else
Y = 'N';
xd = abs(xd);
yd = abs(yd);
s... | 4 |
#include <bits/stdc++.h>
using namespace std;
void boost() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const long long mod = 1000000007;
int tablica[2];
long long potega(long long base, long long pot) {
if (pot == 0) return 1;
if (pot == 1) return base;
if (pot % 2 == 0) {
long long res =... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
const int M = 2000009;
int fa[M], cnt = 0, ans = 0;
int du[M], num[M];
bool flag[M];
int find(int x) {
if (fa[x] == x) return x;
return fa[x] = find(fa[x]);
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) fa[i] = i;
flag[1] = 1;
for ... | 16 |
#include <bits/stdc++.h>
int main() {
int c, j, i, t, n, k, a[4][101], kt, j1;
char s[101];
scanf("%d", &t);
for (c = 0; c < t; c++) {
scanf("%d%d%*c", &n, &k);
for (i = 1; i <= 3; i++) {
gets(s);
for (j = 1; j <= n; j++)
if (s[j - 1] == 's')
a[i][j] = 1;
else if (s... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 1)
cout << "-1" << endl;
else if (n % 2 != 0)
cout << n - 1 << " 2" << endl;
else
cout << n << " 2" << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int month_day[][12] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
vector<long long> ok1, ok2;
int main() {
int s, m, h, day, date, month;
scanf("%d%d%d%d%d%d", &s, &m, &h, &day, &date, &mon... | 20 |
#include <bits/stdc++.h>
using namespace std;
bool SR(int &x) { return scanf("%d", &x) == 1; }
bool SR(long long &x) { return scanf("%lld", &x) == 1; }
bool SR(double &x) { return scanf("%lf", &x) == 1; }
bool SR(char *s) { return scanf("%s", s) == 1; }
bool RI() { return true; }
template <typename I, typename... T>
bo... | 22 |
#include <bits/stdc++.h>
using namespace std;
int nextInt() {
int x;
scanf("%d", &x);
return x;
}
const int BUFSIZE = 10000;
char buf[BUFSIZE + 1];
string nextString() {
scanf("%s", buf);
return buf;
}
const int MOD = 1e9 + 7;
void add(int &x, int y) {
x += y;
while (x >= MOD) {
x -= MOD;
}
}
const ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int dis[50][50];
int main() {
int n;
int i, j, k;
int ans = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
scanf("%d", &dis[i][j]);
}
}
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (in... | 12 |
#include <bits/stdc++.h>
using namespace std;
int mcd(int a, int b) {
if (a < b) swap(a, b);
if (b == 0) return a;
return mcd(a % b, b);
}
int absolut(int x) {
if (x < 0) return -x;
return x;
}
void interreduce(pair<int, int> &p) {
if (p.second < 0) {
p.first = -p.first;
p.second = -p.second;
}
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 30010;
int f[N][205][4], a[N];
int main() {
int n, k;
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
memset(f, -0x3f, sizeof f);
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 3; j++) f[i][0][j] = 0;
for (int i = 1;... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
if (n % 2 == 0)
cout << 2 << endl;
else
cout << 1 << endl;
return 0;
}
| 4 |
// Problem: D. Kill Anton
// Contest: Codeforces - Codeforces Round #723 (Div. 2)
// URL: https://codeforces.com/contest/1526/problem/D
// Memory Limit: 512 MB
// Time Limit: 2000 ms
// FishingRod
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long LL;
typedef pair<int,int> PII;
#define MU... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
long double a;
long double pi = 3.14159265358979323846;
cin >> t;
while (t > 0) {
cin >> a;
a = a * 2;
long double deg = 180 / a;
deg = (deg * pi) / ((double)180);
long double base = tan(deg) * 2;
base = 1 / base;
co... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100001], i, max = 0, count = 0;
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
if (n > 1) {
for (i = 2; i < n; i++) {
if (a[i] == a[i - 1] + a[i - 2]) {
count++;
if (max < count) max = count;
} else {
cou... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "[";
for (int i = 0; i < (int)v.size(); ++i) {
os << v[i];
if (i != (int)v.size() - 1) os << ", ";
}
os << "]\n";
return os;
}
template <typename T, typename U>
ostream& ope... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, op, p;
int a[200005], out[200005];
struct dosth {
int t, r;
} o[200005];
int way;
bool cmp(int a, int b) {
if (way == 1)
return a < b;
else
return a > b;
}
int main() {
scanf("%d%d", &n, &op);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
if (o... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct client {
long x, id;
bool operator<(const client& rhs) const { return x < rhs.x; }
};
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
long d;
long n, a, b, x, y;
cin >> n >> d >> a >> b;
vector<client> v;
for (int i = 0; i < n; i++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int reader_pt = 1048576, reader_last;
char reader_buf[1048576];
int writer_pt = 0;
char writer_buf[1048576];
void reader(int *x) {
int k, m = 0;
*x = 0;
for (;;) {
{
if (reader_pt == 1048576)
reader_pt = 0,
reader_last = fread(reader_buf, siz... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5050;
const int mod = 998244353;
int binpow(int x, int y) {
int ret = 1;
while (y) {
if (y & 1) ret = (1LL * ret * x) % mod;
y >>= 1;
x = (1LL * x * x) % mod;
}
return ret;
}
int n;
int a[N];
int invf[N];
int fact[N];
int f[N][N];
int g[N][... | 15 |
#include <bits/stdc++.h>
using namespace std;
void dfs(int in, vector<vector<int> >& a, vector<int>& v) {
int n = a.size();
int i = in;
v[i] = 1;
for (int k = 0; k < a[i].size(); k++) {
if (!v[a[i][k]]) dfs(a[i][k], a, v);
}
}
int main() {
int n, m;
cin >> n >> m;
vector<vector<int> > a(n);
for (i... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool check_single_row(vector<string> &s, long long int n, long long int m,
long long int x) {
for (long long int i = 1; i < m; i++) {
if (s[x][i] != s[x][i - 1]) return false;
}
return true;
}
bool check_single_col(vector<string> &s, long lon... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
vector<int> Div[N];
set<int> divmark[N];
bool mark[N];
string conf(int x) {
stringstream sts;
sts << "Conflict with " << x;
string s;
getline(sts, s);
return s;
}
string on(int x) {
if (mark[x] == 1) return "Already on";
for (auto k : Di... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void _R(T &x) {
cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 10;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
long long poww(long long a, long long b, long long md) {
return (!b ? 1
: (b & 1 ? a * poww(a * a % md, b / 2, md) % md
: poww(a * a % md, b / 2,... | 12 |
#include <bits/stdc++.h>
using namespace std;
void read(int &val) {
int x = 0;
int bz = 1;
char c;
for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
;
if (c == '-') {
bz = -1;
c = getchar();
}
for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
val = x * bz;
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n, k1, k2;
cin >> t;
while (t--) {
cin >> n;
vector<long long> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
bool f = 0;
for (int i = 0; i < n - 1; i++) {
if (abs(v[i] - v[i + 1]) >= 2) {
cout ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v[100005], ans;
int n, A[100005], p;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> p >> A[i];
if (p != -1) v[p].push_back(i);
}
for (int i = 1; i <= n; ++i) {
if (A[i] == 0) continue;
bool ok = true;
for (auto g : v... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, cnt = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 1; i < n - 1; i++) {
if ((a[i] > a[i + 1] && a[i] > a[i - 1]) ||
(a[i] < a[i + 1] && a[i] < a[i - 1])) {
cnt++;
}
}
cout << c... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.